| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean upgradeMaintenanceStandard(EamMaintenanceStandardRequest standardRequest) { |
| | | EamMaintenanceStandard entity = eamMaintenanceStandardMapper.selectById(standardRequest.getId()); |
| | | if(entity == null){ |
| | | throw new JeecgBootException("编辑的数据已删除,请刷新重试!"); |
| | | } |
| | | entity.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name()); |
| | | //原来的作废 |
| | | eamMaintenanceStandardMapper.updateById(entity); |
| | | |
| | | //新增一个版本 |
| | | EamMaintenanceStandard newEntity = new EamMaintenanceStandard(); |
| | | newEntity.setStandardCode(standardRequest.getStandardCode()); |
| | | newEntity.setStandardName(standardRequest.getStandardName()); |
| | | newEntity.setMaintenanceCategory(standardRequest.getMaintenanceCategory()); |
| | | newEntity.setMaintenancePeriod(standardRequest.getMaintenancePeriod()); |
| | | newEntity.setInitialDate(standardRequest.getInitialDate()); |
| | | newEntity.setFileCode(standardRequest.getFileCode()); |
| | | newEntity.setStandardStatus(MaintenanceStandardStatusEnum.NORMAL.name()); |
| | | //版本递增 |
| | | newEntity.setStandardVersion(entity.getStandardVersion() + 1); |
| | | //设备处理 |
| | | newEntity.setEquipmentId(standardRequest.getEquipmentId()); |
| | | //删除标记 |
| | | newEntity.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | //重复性校验 |
| | | EamMaintenanceStandard exist = checkDuplicate(newEntity.getEquipmentId(), newEntity.getMaintenanceCategory()); |
| | | if(exist != null){ |
| | | throw new JeecgBootException("设备标准已存在,不能重复添加!"); |
| | | } |
| | | //处理附件 |
| | | if(CollectionUtil.isNotEmpty(standardRequest.getFileList())) { |
| | | FileUploadResult fileUploadResult = standardRequest.getFileList().get(0); |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | try { |
| | | String referenceFile = mapper.writeValueAsString(fileUploadResult); |
| | | newEntity.setReferenceFile(referenceFile); |
| | | } catch (JsonProcessingException e) { |
| | | log.error("JSON转换失败:" + e.getMessage(), e); |
| | | } |
| | | } |
| | | eamMaintenanceStandardMapper.insert(newEntity); |
| | | //处理明细数据 |
| | | if(CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) { |
| | | standardRequest.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setId(null); |
| | | tableDetail.setCreateBy(null); |
| | | tableDetail.setUpdateBy(null); |
| | | tableDetail.setCreateTime(null); |
| | | tableDetail.setUpdateTime(null); |
| | | tableDetail.setStandardId(newEntity.getId()); |
| | | }); |
| | | eamMaintenanceStandardDetailService.saveBatch(standardRequest.getTableDetailList()); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public EamMaintenanceStandard checkDuplicate(String equipmentId, String maintenanceCategory) { |
| | | LambdaQueryWrapper<EamMaintenanceStandard> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(EamMaintenanceStandard::getEquipmentId, equipmentId); |