| | |
| | | package com.ruoyi.device.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.github.xiaoymin.knife4j.core.util.StrUtil; |
| | | import com.google.common.collect.Lists; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.device.dto.DeviceDefectRecordDto; |
| | | import com.ruoyi.device.dto.DeviceRepairDto; |
| | | import com.ruoyi.device.execl.DeviceRepairExeclDto; |
| | | import com.ruoyi.device.mapper.DeviceDefectRecordMapper; |
| | | import com.ruoyi.device.mapper.DeviceRepairMapper; |
| | | import com.ruoyi.device.pojo.DeviceDefectRecord; |
| | | import com.ruoyi.device.pojo.DeviceLedger; |
| | | import com.ruoyi.device.pojo.DeviceRepair; |
| | | import com.ruoyi.device.service.DeviceDefectRecordService; |
| | | import com.ruoyi.device.service.IDeviceLedgerService; |
| | | import com.ruoyi.device.service.IDeviceRepairService; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.measuringinstrumentledger.mapper.SparePartsMapper; |
| | | import com.ruoyi.measuringinstrumentledger.pojo.SpareParts; |
| | | import com.ruoyi.measuringinstrumentledger.service.SparePartsService; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.commons.lang3.tuple.Pair; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | |
| | | private DeviceRepairMapper deviceRepairMapper; |
| | | @Autowired |
| | | private IDeviceLedgerService deviceLedgerService; |
| | | @Autowired |
| | | private SparePartsMapper sparePartsMapper; |
| | | |
| | | @Override |
| | | public IPage<DeviceRepairDto> queryPage(Page page, DeviceRepairDto deviceRepairDto) { |
| | | IPage<DeviceRepairDto> deviceRepairDtoIPage = deviceRepairMapper.queryPage(page, deviceRepairDto); |
| | | |
| | | return deviceRepairMapper.queryPage(page, deviceRepairDto); |
| | | List<DeviceRepairDto> records = deviceRepairDtoIPage.getRecords(); |
| | | if (!CollectionUtils.isEmpty(records)) { |
| | | // 1. 获取所有唯一的备件ID |
| | | Set<String> allIds = records.stream() |
| | | .map(DeviceRepairDto::getSparePartsIds) |
| | | .filter(StrUtil::isNotBlank) |
| | | .flatMap(ids -> Arrays.stream(StringUtils.split(ids, ","))) |
| | | .map(String::trim) |
| | | .filter(StrUtil::isNotBlank) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | if (!allIds.isEmpty()) { |
| | | // 2. 查询并创建ID到名称的映射 |
| | | Map<Long, String> idToNameMap = sparePartsMapper.selectBatchIds(new ArrayList<>(allIds)) |
| | | .stream() |
| | | .collect(Collectors.toMap( |
| | | SpareParts::getId, |
| | | SpareParts::getName, |
| | | (v1, v2) -> v1 |
| | | )); |
| | | |
| | | // 3. 为每个记录设置备件名称 |
| | | records.forEach(record -> { |
| | | String names = Optional.ofNullable(record.getSparePartsIds()) |
| | | .filter(StrUtil::isNotBlank) |
| | | .map(ids -> Arrays.stream(StringUtils.split(ids, ",")) |
| | | .map(String::trim) |
| | | .map(Long::valueOf) |
| | | .map(idToNameMap::get) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.joining(","))) |
| | | .orElse(""); |
| | | record.setSparePartsNames(names); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | return deviceRepairDtoIPage; |
| | | } |
| | | |
| | | @Override |
| | |
| | | deviceRepair.setDeviceName(byId.getDeviceName()); |
| | | deviceRepair.setDeviceModel(byId.getDeviceModel()); |
| | | boolean save = this.save(deviceRepair); |
| | | if (save){ |
| | | if (save) { |
| | | return AjaxResult.success(); |
| | | } |
| | | return AjaxResult.error(); |
| | |
| | | deviceDefectRecordDto.setDeviceLedgerId(id); |
| | | deviceDefectRecordDto.setStatus("严重缺陷"); |
| | | List<DeviceDefectRecordDto> records = deviceDefectRecordService.listPage(new Page<>(1, -1), deviceDefectRecordDto).getRecords(); |
| | | if (!records.isEmpty()){ |
| | | if (!records.isEmpty()) { |
| | | records.forEach(deviceDefectRecord -> { |
| | | deviceDefectRecord.setStatus("正常"); |
| | | deviceDefectRecordService.updateByDDR(deviceDefectRecord); |
| | |
| | | ArrayList<DeviceRepairExeclDto> deviceLedgerExeclDtos = new ArrayList<>(); |
| | | supplierManageList.stream().forEach(deviceRepair -> { |
| | | DeviceRepairExeclDto deviceRepairExeclDto = new DeviceRepairExeclDto(); |
| | | BeanUtils.copyProperties(deviceRepair,deviceRepairExeclDto); |
| | | BeanUtils.copyProperties(deviceRepair, deviceRepairExeclDto); |
| | | deviceRepairExeclDto.setStatusStr(deviceRepair.getStatus() == 0 ? "待维修" : deviceRepair.getStatus() == 1 ? "完结" : "失败"); |
| | | |
| | | deviceLedgerExeclDtos.add(deviceRepairExeclDto); |
| | | }); |
| | | ExcelUtil<DeviceRepairExeclDto> util = new ExcelUtil<DeviceRepairExeclDto>(DeviceRepairExeclDto.class); |
| | | util.exportExcel(response, deviceLedgerExeclDtos, "设备报修导出"); |
| | | }else { |
| | | } else { |
| | | ArrayList<Long> arrayList = new ArrayList<>(); |
| | | Arrays.stream(ids).map(id -> { |
| | | return arrayList.add( id); |
| | | }); |
| | | Arrays.stream(ids).map(arrayList::add); |
| | | List<DeviceRepair> supplierManageList = deviceRepairMapper.selectBatchIds(arrayList); |
| | | ArrayList<DeviceRepairExeclDto> deviceLedgerExeclDtos = new ArrayList<>(); |
| | | supplierManageList.stream().forEach(deviceRepair -> { |
| | | DeviceRepairExeclDto deviceRepairExeclDto = new DeviceRepairExeclDto(); |
| | | BeanUtils.copyProperties(deviceRepair,deviceRepairExeclDto); |
| | | BeanUtils.copyProperties(deviceRepair, deviceRepairExeclDto); |
| | | deviceRepairExeclDto.setStatusStr(deviceRepair.getStatus() == 0 ? "待维修" : deviceRepair.getStatus() == 1 ? "完结" : "失败"); |
| | | |
| | | deviceLedgerExeclDtos.add(deviceRepairExeclDto); |