| | |
| | | import com.ruoyi.device.service.IDeviceLedgerService; |
| | | import com.ruoyi.device.service.IDeviceRepairService; |
| | | import com.ruoyi.device.vo.DeviceRepairVo; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.measuringinstrumentledger.mapper.SparePartsMapper; |
| | | import com.ruoyi.project.system.service.ISysNoticeService; |
| | | import com.ruoyi.measuringinstrumentledger.pojo.SpareParts; |
| | | import com.ruoyi.measuringinstrumentledger.pojo.SparePartsRequisitionRecord; |
| | | import com.ruoyi.measuringinstrumentledger.service.SparePartsRequisitionRecordService; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.compress.utils.Lists; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | private final SparePartsMapper sparePartsMapper; |
| | | private final SparePartsRequisitionRecordService sparePartsRequisitionRecordService; |
| | | private final FileUtil fileUtil; |
| | | private final ISysNoticeService sysNoticeService; |
| | | |
| | | private static final int STATUS_PENDING_REPAIR = 0; |
| | | private static final int STATUS_COMPLETED = 1; |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R<?> saveDeviceRepair(DeviceRepairDto deviceRepairDto) { |
| | | public AjaxResult saveDeviceRepair(DeviceRepairDto deviceRepairDto) { |
| | | DeviceLedger byId = deviceLedgerService.getById(deviceRepairDto.getDeviceLedgerId()); |
| | | deviceRepairDto.setDeviceName(byId.getDeviceName()); |
| | | deviceRepairDto.setDeviceModel(byId.getDeviceModel()); |
| | | deviceRepairDto.setAreaId(byId.getAreaId()); |
| | | if (deviceRepairDto.getStatus() == null) { |
| | | deviceRepairDto.setStatus(STATUS_PENDING_REPAIR); |
| | | } |
| | |
| | | if (save) { |
| | | // 处理图片上传 |
| | | fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("file", RecordTypeEnum.DEVICE_REPAIR, deviceRepairDto.getId(), deviceRepairDto.getStorageBlobDTOs()); |
| | | return R.ok(); |
| | | return AjaxResult.success(); |
| | | } |
| | | return R.fail("保存失败"); |
| | | return AjaxResult.error("保存失败"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R<?> updateDeviceRepair(DeviceRepairDto deviceRepairDto) { |
| | | public AjaxResult updateDeviceRepair(DeviceRepairDto deviceRepairDto) { |
| | | DeviceRepair oldDeviceRepair = this.getById(deviceRepairDto.getId()); |
| | | if (oldDeviceRepair == null) { |
| | | return R.fail("报修记录不存在"); |
| | | return AjaxResult.error("报修记录不存在"); |
| | | } |
| | | Long effectiveDeviceLedgerId = deviceRepairDto.getDeviceLedgerId() != null |
| | | ? deviceRepairDto.getDeviceLedgerId() |
| | | : oldDeviceRepair.getDeviceLedgerId(); |
| | | DeviceLedger byId = deviceLedgerService.getById(effectiveDeviceLedgerId); |
| | | if (byId != null) { |
| | | deviceRepairDto.setDeviceName(byId.getDeviceName()); |
| | | deviceRepairDto.setDeviceModel(byId.getDeviceModel()); |
| | | deviceRepairDto.setAreaId(byId.getAreaId()); |
| | | } |
| | | if (deviceRepairDto.getStatus() != null |
| | | && deviceRepairDto.getStatus() == STATUS_COMPLETED |
| | | && (oldDeviceRepair.getStatus() == null |
| | | || oldDeviceRepair.getStatus() != STATUS_COMPLETED)) { |
| | | return R.fail("请先提交验收审批,验收通过后才可完结"); |
| | | return AjaxResult.error("请先提交验收审批,验收通过后才可完结"); |
| | | } |
| | | // 处理备件使用情况 |
| | | if (CollectionUtils.isNotEmpty(deviceRepairDto.getSparePartsUseList())) { |
| | |
| | | sparePartsMapper.updateById(spareParts); |
| | | sparePartIds.add(sparePartUse.getId()); |
| | | |
| | | // 库存预警通知 |
| | | if (spareParts.getWarnNum() != null && spareParts.getNotifyPersonId() != null |
| | | && spareParts.getQuantity().compareTo(spareParts.getWarnNum()) < 0) { |
| | | sysNoticeService.simpleNoticeByUser( |
| | | "备件库存预警", |
| | | "备件【" + spareParts.getName() + "】当前库存(" + spareParts.getQuantity() |
| | | + ")已低于预警数量(" + spareParts.getWarnNum() + "),请及时采购补充。", |
| | | List.of(spareParts.getNotifyPersonId()), |
| | | "/equipmentManagement/spareParts"); |
| | | } |
| | | |
| | | // 创建备件领用记录 |
| | | SparePartsRequisitionRecord record = new SparePartsRequisitionRecord(); |
| | | record.setSourceType(0); // 0 维修 |
| | |
| | | record.setQuantity(sparePartUse.getQuantity()); |
| | | sparePartsRequisitionRecordService.save(record); |
| | | } else { |
| | | return R.fail("备件 " + spareParts.getName() + " 数量不足"); |
| | | return AjaxResult.error("备件 " + spareParts.getName() + " 数量不足"); |
| | | } |
| | | } |
| | | } |
| | |
| | | if (deviceRepairDto.getStorageBlobDTOs() != null) { |
| | | fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("file", RecordTypeEnum.DEVICE_REPAIR, id, deviceRepairDto.getStorageBlobDTOs()); |
| | | } |
| | | return R.ok(); |
| | | return AjaxResult.success(); |
| | | } |
| | | return R.fail(); |
| | | return AjaxResult.error(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R<?> confirmRepair(DeviceRepairDto deviceRepairDto) { |
| | | public AjaxResult confirmRepair(DeviceRepairDto deviceRepairDto) { |
| | | DeviceRepair oldDeviceRepair = this.getById(deviceRepairDto.getId()); |
| | | if (oldDeviceRepair == null) { |
| | | return R.fail("报修记录不存在"); |
| | | return AjaxResult.error("报修记录不存在"); |
| | | } |
| | | if (oldDeviceRepair.getStatus() != null && oldDeviceRepair.getStatus() == STATUS_COMPLETED) { |
| | | return R.fail("该报修已完结,不能重复确认维修"); |
| | | return AjaxResult.error("该报修已完结,不能重复确认维修"); |
| | | } |
| | | if (oldDeviceRepair.getStatus() != null && oldDeviceRepair.getStatus() == STATUS_PENDING_ACCEPTANCE) { |
| | | return R.fail("该报修已提交验收审批"); |
| | | return AjaxResult.error("该报修已提交验收审批"); |
| | | } |
| | | deviceRepairDto.setStatus(STATUS_PENDING_ACCEPTANCE); |
| | | return updateDeviceRepair(deviceRepairDto); |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R<?> approveRepairAcceptance(DeviceRepairDto deviceRepairDto) { |
| | | public AjaxResult approveRepairAcceptance(DeviceRepairDto deviceRepairDto) { |
| | | if (deviceRepairDto.getId() == null) { |
| | | return R.fail("报修记录id不能为空"); |
| | | return AjaxResult.error("报修记录id不能为空"); |
| | | } |
| | | DeviceRepair oldDeviceRepair = this.getById(deviceRepairDto.getId()); |
| | | if (oldDeviceRepair == null) { |
| | | return R.fail("报修记录不存在"); |
| | | return AjaxResult.error("报修记录不存在"); |
| | | } |
| | | if (oldDeviceRepair.getStatus() == null || oldDeviceRepair.getStatus() != STATUS_PENDING_ACCEPTANCE) { |
| | | return R.fail("该报修未进入待验收状态,不能审批"); |
| | | return AjaxResult.error("该报修未进入待验收状态,不能审批"); |
| | | } |
| | | if (StringUtils.isBlank(deviceRepairDto.getAcceptanceName())) { |
| | | return R.fail("验收人不能为空"); |
| | | return AjaxResult.error("验收人不能为空"); |
| | | } |
| | | if (deviceRepairDto.getAcceptanceTime() == null) { |
| | | return R.fail("验收时间不能为空"); |
| | | return AjaxResult.error("验收时间不能为空"); |
| | | } |
| | | if (StringUtils.isBlank(deviceRepairDto.getAcceptanceRemark())) { |
| | | return R.fail("验收备注不能为空"); |
| | | return AjaxResult.error("验收备注不能为空"); |
| | | } |
| | | |
| | | DeviceRepair update = new DeviceRepair(); |
| | |
| | | update.setAcceptanceRemark(deviceRepairDto.getAcceptanceRemark()); |
| | | update.setStatus(STATUS_COMPLETED); |
| | | if (this.updateById(update)) { |
| | | return R.ok(); |
| | | return AjaxResult.success(); |
| | | } |
| | | return R.fail("验收审批失败"); |
| | | return AjaxResult.error("验收审批失败"); |
| | | } |
| | | |
| | | @Override |