| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.device.dto.DeviceDefectRecordDto; |
| | |
| | | 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.other.service.TempFileService; |
| | | import com.ruoyi.sales.mapper.CommonFileMapper; |
| | | import com.ruoyi.sales.pojo.CommonFile; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult saveDeviceRepair(DeviceRepair deviceRepair) { |
| | | public Long saveDeviceRepair(DeviceRepair deviceRepair) { |
| | | DeviceLedger byId = deviceLedgerService.getById(deviceRepair.getDeviceLedgerId()); |
| | | if (byId == null) { |
| | | throw new ServiceException("设å¤å°è´¦ä¸åå¨"); |
| | | } |
| | | deviceRepair.setDeviceName(byId.getDeviceName()); |
| | | deviceRepair.setDeviceModel(byId.getDeviceModel()); |
| | | boolean save = this.save(deviceRepair); |
| | | if (save) { |
| | | return AjaxResult.success(); |
| | | if (!this.save(deviceRepair)) { |
| | | throw new ServiceException("æ·»å 失败"); |
| | | } |
| | | return AjaxResult.error(); |
| | | return deviceRepair.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult updateDeviceRepair(DeviceRepair deviceRepair) { |
| | | if (this.updateById(deviceRepair)) { |
| | | Long id = deviceRepair.getId(); |
| | | // |
| | | DeviceDefectRecordDto deviceDefectRecordDto = new DeviceDefectRecordDto(); |
| | | deviceDefectRecordDto.setDeviceLedgerId(id); |
| | | deviceDefectRecordDto.setStatus("严é缺é·"); |
| | | List<DeviceDefectRecordDto> records = deviceDefectRecordService.listPage(new Page<>(1, -1), deviceDefectRecordDto).getRecords(); |
| | | if (!records.isEmpty()) { |
| | | records.forEach(deviceDefectRecord -> { |
| | | deviceDefectRecord.setStatus("æ£å¸¸"); |
| | | deviceDefectRecordService.updateByDDR(deviceDefectRecord); |
| | | }); |
| | | } |
| | | return AjaxResult.success(); |
| | | public void updateDeviceRepair(DeviceRepair deviceRepair) { |
| | | DeviceRepair existing = this.getById(deviceRepair.getId()); |
| | | if (existing == null) { |
| | | throw new ServiceException("æ¥ä¿®åä¸åå¨"); |
| | | } |
| | | return AjaxResult.error(); |
| | | if (!Objects.equals(existing.getStatus(), 0)) { |
| | | throw new ServiceException("ä»
å¾
ç»´ä¿®ç¶æå¯ç¼è¾"); |
| | | } |
| | | if (!this.updateById(deviceRepair)) { |
| | | throw new ServiceException("ä¿®æ¹å¤±è´¥"); |
| | | } |
| | | clearDefectRecordsIfNeeded(deviceRepair.getId()); |
| | | } |
| | | |
| | | @Override |
| | | public void submitDeviceMaintain(DeviceRepair deviceRepair) { |
| | | if (deviceRepair == null || deviceRepair.getId() == null) { |
| | | throw new ServiceException("æ¥ä¿®åIDä¸è½ä¸ºç©º"); |
| | | } |
| | | DeviceRepair existing = this.getById(deviceRepair.getId()); |
| | | if (existing == null) { |
| | | throw new ServiceException("æ¥ä¿®åä¸åå¨"); |
| | | } |
| | | if (!Objects.equals(existing.getStatus(), 0)) { |
| | | throw new ServiceException("ä»
å¾
ç»´ä¿®ç¶æå¯æäº¤ç»´ä¿®"); |
| | | } |
| | | if (StringUtils.isEmpty(deviceRepair.getMaintenanceResult())) { |
| | | throw new ServiceException("请填åç»´ä¿®ç»æ"); |
| | | } |
| | | String loginNick = SecurityUtils.getLoginUser().getNickName(); |
| | | if (StringUtils.isEmpty(existing.getMaintenanceName())) { |
| | | throw new ServiceException("æªæå®ç»´ä¿®äººï¼æ æ³ç»´ä¿®"); |
| | | } |
| | | if (!Objects.equals(existing.getMaintenanceName(), loginNick)) { |
| | | throw new ServiceException("ä»
æå®ç维修人å¯è¿è¡ç»´ä¿®"); |
| | | } |
| | | existing.setMaintenanceResult(deviceRepair.getMaintenanceResult()); |
| | | existing.setMaintenanceTime(deviceRepair.getMaintenanceTime() != null |
| | | ? deviceRepair.getMaintenanceTime() : LocalDateTime.now()); |
| | | // 维修失败=2ï¼å¦åè¿å
¥å¾
éªæ¶=3 |
| | | if (Objects.equals(deviceRepair.getStatus(), 2)) { |
| | | existing.setStatus(2); |
| | | } else { |
| | | existing.setStatus(3); |
| | | } |
| | | if (!this.updateById(existing)) { |
| | | throw new ServiceException("æäº¤ç»´ä¿®å¤±è´¥"); |
| | | } |
| | | clearDefectRecordsIfNeeded(existing.getId()); |
| | | } |
| | | |
| | | @Override |
| | | public void acceptDeviceRepair(DeviceRepair deviceRepair) { |
| | | if (deviceRepair == null || deviceRepair.getId() == null) { |
| | | throw new ServiceException("æ¥ä¿®åIDä¸è½ä¸ºç©º"); |
| | | } |
| | | DeviceRepair existing = this.getById(deviceRepair.getId()); |
| | | if (existing == null) { |
| | | throw new ServiceException("æ¥ä¿®åä¸åå¨"); |
| | | } |
| | | if (!Objects.equals(existing.getStatus(), 3)) { |
| | | throw new ServiceException("å½åç¶æä¸å¯éªæ¶"); |
| | | } |
| | | String loginNick = SecurityUtils.getLoginUser().getNickName(); |
| | | if (StringUtils.isEmpty(existing.getAcceptanceName())) { |
| | | throw new ServiceException("æªæå®éªæ¶äººï¼æ æ³éªæ¶"); |
| | | } |
| | | if (!Objects.equals(existing.getAcceptanceName(), loginNick)) { |
| | | throw new ServiceException("ä»
æå®çéªæ¶äººå¯è¿è¡éªæ¶"); |
| | | } |
| | | if (StringUtils.isEmpty(deviceRepair.getAcceptanceRemark())) { |
| | | throw new ServiceException("请填åéªæ¶å¤æ³¨"); |
| | | } |
| | | existing.setAcceptanceTime(deviceRepair.getAcceptanceTime() != null |
| | | ? deviceRepair.getAcceptanceTime() : LocalDateTime.now()); |
| | | existing.setAcceptanceRemark(deviceRepair.getAcceptanceRemark()); |
| | | existing.setStatus(1); |
| | | if (!this.updateById(existing)) { |
| | | throw new ServiceException("éªæ¶å¤±è´¥"); |
| | | } |
| | | clearDefectRecordsIfNeeded(existing.getId()); |
| | | } |
| | | |
| | | private void clearDefectRecordsIfNeeded(Long repairId) { |
| | | DeviceDefectRecordDto deviceDefectRecordDto = new DeviceDefectRecordDto(); |
| | | deviceDefectRecordDto.setDeviceLedgerId(repairId); |
| | | deviceDefectRecordDto.setStatus("严é缺é·"); |
| | | List<DeviceDefectRecordDto> records = deviceDefectRecordService.listPage(new Page<>(1, -1), deviceDefectRecordDto).getRecords(); |
| | | if (!records.isEmpty()) { |
| | | records.forEach(deviceDefectRecord -> { |
| | | deviceDefectRecord.setStatus("æ£å¸¸"); |
| | | deviceDefectRecordService.updateByDDR(deviceDefectRecord); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | private static String statusLabel(Integer status) { |
| | | if (status == null) { |
| | | return ""; |
| | | } |
| | | switch (status) { |
| | | case 0: |
| | | return "å¾
ç»´ä¿®"; |
| | | case 1: |
| | | return "宿"; |
| | | case 2: |
| | | return "维修失败"; |
| | | case 3: |
| | | return "å¾
éªæ¶"; |
| | | default: |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | supplierManageList.stream().forEach(deviceRepair -> { |
| | | DeviceRepairExeclDto deviceRepairExeclDto = new DeviceRepairExeclDto(); |
| | | BeanUtils.copyProperties(deviceRepair, deviceRepairExeclDto); |
| | | deviceRepairExeclDto.setStatusStr(deviceRepair.getStatus() == 0 ? "å¾
ç»´ä¿®" : deviceRepair.getStatus() == 1 ? "å®ç»" : "失败"); |
| | | deviceRepairExeclDto.setStatusStr(statusLabel(deviceRepair.getStatus())); |
| | | |
| | | deviceLedgerExeclDtos.add(deviceRepairExeclDto); |
| | | }); |
| | |
| | | supplierManageList.stream().forEach(deviceRepair -> { |
| | | DeviceRepairExeclDto deviceRepairExeclDto = new DeviceRepairExeclDto(); |
| | | BeanUtils.copyProperties(deviceRepair, deviceRepairExeclDto); |
| | | deviceRepairExeclDto.setStatusStr(deviceRepair.getStatus() == 0 ? "å¾
ç»´ä¿®" : deviceRepair.getStatus() == 1 ? "å®ç»" : "失败"); |
| | | deviceRepairExeclDto.setStatusStr(statusLabel(deviceRepair.getStatus())); |
| | | |
| | | deviceLedgerExeclDtos.add(deviceRepairExeclDto); |
| | | }); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void uploadFile(MultipartFile file, Long deviceRepairId) { |
| | | public void uploadFile(MultipartFile file, Long deviceRepairId, Integer fileType) { |
| | | if (file == null || file.isEmpty()) { |
| | | throw new ServiceException("ä¸ä¼ 失败,æä»¶ä¸è½ä¸ºç©º"); |
| | | } |
| | | if (deviceRepairId == null || deviceRepairId <= 0) { |
| | | throw new ServiceException("ä¸ä¼ 失败,è®¾å¤æ¥ä¿®IDä¸è½ä¸ºç©º"); |
| | | } |
| | | int resolvedType = resolveRepairFileType(fileType); |
| | | |
| | | try { |
| | | tempFileService.uploadByCommon(file, FileNameType.EQUIPMENT_WARRANTY.getValue(), deviceRepairId); |
| | | tempFileService.uploadByCommon(file, resolvedType, deviceRepairId); |
| | | } catch (Exception e) { |
| | | throw new ServiceException("ä¸ä¼ 失败," + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** è®¾å¤æ¥ä¿®éä»¶ç±»åï¼14设å¤é®é¢ 15ç»´ä¿®å®æï¼13为åå²ç±»åå½å
¥è®¾å¤é®é¢ */ |
| | | private int resolveRepairFileType(Integer fileType) { |
| | | if (fileType == null) { |
| | | return FileNameType.EQUIPMENT_REPAIR_PROBLEM.getValue(); |
| | | } |
| | | if (Objects.equals(fileType, FileNameType.EQUIPMENT_REPAIR_PROBLEM.getValue()) |
| | | || Objects.equals(fileType, FileNameType.EQUIPMENT_REPAIR_MAINTAIN.getValue()) |
| | | || Objects.equals(fileType, FileNameType.EQUIPMENT_WARRANTY.getValue())) { |
| | | return fileType; |
| | | } |
| | | throw new ServiceException("ä¸ä¼ 失败,éä»¶ç±»åæ æ"); |
| | | } |
| | | |
| | | private List<Integer> repairFileTypes() { |
| | | return Arrays.asList( |
| | | FileNameType.EQUIPMENT_REPAIR_PROBLEM.getValue(), |
| | | FileNameType.EQUIPMENT_REPAIR_MAINTAIN.getValue(), |
| | | FileNameType.EQUIPMENT_WARRANTY.getValue() |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | return commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>() |
| | | .eq(CommonFile::getCommonId, deviceRepairId) |
| | | .eq(CommonFile::getType, FileNameType.EQUIPMENT_WARRANTY.getValue())); |
| | | .in(CommonFile::getType, repairFileTypes()) |
| | | .orderByAsc(CommonFile::getId)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | List<CommonFile> fileList = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>() |
| | | .in(CommonFile::getCommonId, ids) |
| | | .eq(CommonFile::getType, FileNameType.EQUIPMENT_WARRANTY.getValue())); |
| | | .in(CommonFile::getType, repairFileTypes())); |
| | | for (CommonFile commonFile : fileList) { |
| | | deleteFile(commonFile.getId()); |
| | | } |