|
@@ -16,6 +16,7 @@ import com.platform.dao.entity.sb.SbInfo;
|
|
|
import com.platform.dao.entity.sb.SbLocation;
|
|
|
import com.platform.dao.entity.sb.SbMeasureLog;
|
|
|
import com.platform.dao.entity.upms.SysFile;
|
|
|
+import com.platform.dao.enums.SbInfoStatusEnum;
|
|
|
import com.platform.dao.enums.SbUseType;
|
|
|
import com.platform.dao.enums.SysFileTypeEnum;
|
|
|
import com.platform.dao.enums.YesNoEnum;
|
|
@@ -137,98 +138,128 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public SbMeasureLog saveModelByDTO(SbMeasureLogDTO model) {
|
|
|
- model.setCheckUserId(SecurityUtils.getUserInfo().getUserId()); // 谁操作即是检定记录人
|
|
|
- SbMeasureLog sbMeasureLog = super.saveModelByDTO(model);
|
|
|
- model.setId(sbMeasureLog.getId());
|
|
|
// 更新设备下次检定日期
|
|
|
SbInfo sbInfo = sbInfoMapper.selectByPrimaryKey(model.getSbId());
|
|
|
SbInfo tempInfo = new SbInfo();
|
|
|
tempInfo.setId(sbInfo.getId());
|
|
|
- tempInfo.setParentId(sbInfo.getParentId());
|
|
|
- tempInfo.setPositionId(sbInfo.getPositionId());
|
|
|
- if(sbInfo.getUseType().equals(SbUseType.BGCL.getValue())){
|
|
|
- model.setType(1);
|
|
|
- }else if(sbInfo.getUseType().equals(SbUseType.BGCL.getValue())){
|
|
|
- model.setType(2);
|
|
|
- }else{
|
|
|
- throw new BusinessException("非计量和非特种的设备, 无需填报检定记录");
|
|
|
- }
|
|
|
- sbInfo.setCheckDate(model.getLastDate());
|
|
|
- Integer checkPeriod = 0;// 默认12个月
|
|
|
- if(model.getCheckPeriod() != null){
|
|
|
- checkPeriod = model.getCheckPeriod();
|
|
|
+ // 判断设备状态,如果是在库,直接修改设备状态即可
|
|
|
+ if(model.getSbStatus() == 1){
|
|
|
+ sbInfo.setStatus(SbInfoStatusEnum.IN_STORE.getValue());
|
|
|
+ String remark = "设备状态由【"+SbInfoStatusEnum.getNameByValue(sbInfo.getStatus())+"】 ---> 【";
|
|
|
+ remark += "在库】";
|
|
|
+ handleSbChangeRecord(remark,model,tempInfo,CommonConstants.CHANGE_TYPE_SB_STATUS);
|
|
|
+ return null;
|
|
|
}else{
|
|
|
- throw new BusinessException("检定设备的检定周期未设置,无法计算下次检定日期,请先设置");
|
|
|
- }
|
|
|
- sbInfo.setNextCheckDate(model.getLastDate().minusMonths(-checkPeriod).minusDays(1));
|
|
|
- sbInfo.setZaiz(model.getName());// 检定单位
|
|
|
- sbInfo.setSbdh(model.getNo());// 检定编号
|
|
|
- sbInfo.setRemark(model.getRemark());// 备注
|
|
|
- sbInfo.setDph(model.getRequirement());// 检定人
|
|
|
- sbInfo.setMeasureStatus(YesNoEnum.NO.getValue());// 每次检定后, 检定状态改为正常
|
|
|
- sbInfo.setCheckPeriod(model.getCheckPeriod()); // 检定周期
|
|
|
- // 设备位置变动
|
|
|
- boolean insertAllocate = Boolean.FALSE; // 设备位置
|
|
|
- boolean insertParent = Boolean.FALSE; // 父设备
|
|
|
- boolean insertNo = Boolean.FALSE; // 设备位号
|
|
|
- String oldPositionId = getPureString(sbInfo.getPositionId());
|
|
|
- String oldParentId = getPureString(sbInfo.getParentId());
|
|
|
- String positionId = getPureString(model.getSbPositionId());
|
|
|
- String parentId = getPureString(model.getSbParentId());
|
|
|
- String oldSbPositionNo = getPureString(sbInfo.getPositionNo()); // 设备位号
|
|
|
- String positionNo = getPureString(model.getSbPositionNo());
|
|
|
- StringBuilder remark1 = new StringBuilder();
|
|
|
- StringBuilder remark2 = new StringBuilder();
|
|
|
- StringBuilder remark3 = new StringBuilder();
|
|
|
- if(!oldPositionId.equals(positionId)){
|
|
|
- insertAllocate = Boolean.TRUE;
|
|
|
- sbInfo.setPositionId(positionId);
|
|
|
- String before = oldPositionId == "" ? oldPositionId : sbPositionMapper.selectNameById(oldPositionId);
|
|
|
- remark1.append("设备位置变动【" + before).append("】 ---> ");
|
|
|
- String after = positionId == "" ? positionId : sbPositionMapper.selectNameById(positionId);
|
|
|
- remark1.append("【" + after + "】");
|
|
|
- }
|
|
|
- if(!oldParentId.equals(parentId)){
|
|
|
- insertParent = Boolean.TRUE;
|
|
|
- sbInfo.setParentId(parentId);
|
|
|
- remark2.append("父设备变动【" + sbInfo.getName()).append("】 ---> ");
|
|
|
- String after = parentId == "" ? parentId : sbInfoMapper.selectNameById(parentId);
|
|
|
- remark2.append("【" + after + "】");
|
|
|
- }
|
|
|
- if(!oldSbPositionNo.equals(positionNo)){
|
|
|
- insertNo = Boolean.TRUE;
|
|
|
- remark3.append("设备位号变动【"+sbInfo.getPositionNo()).append("】 ---> ");
|
|
|
- remark3.append("【"+positionNo+"】");
|
|
|
- // 位号变动,父设备也有可能变动
|
|
|
- SbLocation location = new SbLocation();
|
|
|
- location.setNo(positionNo);
|
|
|
- List<SbLocation> locations = sbLocationMapper.select(location);
|
|
|
- if(locations != null && locations.size() > 0){
|
|
|
- sbInfo.setParentId(locations.get(0).getSbId());
|
|
|
+ model.setCheckUserId(SecurityUtils.getUserInfo().getUserId()); // 谁操作即是检定记录人
|
|
|
+ SbMeasureLog sbMeasureLog = super.saveModelByDTO(model);
|
|
|
+ model.setId(sbMeasureLog.getId());
|
|
|
+ tempInfo.setParentId(sbInfo.getParentId());
|
|
|
+ tempInfo.setPositionId(sbInfo.getPositionId());
|
|
|
+ if(sbInfo.getUseType().equals(SbUseType.BGCL.getValue())){
|
|
|
+ model.setType(1);
|
|
|
+ }else if(sbInfo.getUseType().equals(SbUseType.BGCL.getValue())){
|
|
|
+ model.setType(2);
|
|
|
+ }else{
|
|
|
+ throw new BusinessException("非计量和非特种的设备, 无需填报检定记录");
|
|
|
}
|
|
|
- sbInfo.setPositionNo(model.getSbPositionNo()); // 设备位号
|
|
|
- }
|
|
|
- // 保存文件
|
|
|
- sysFileService.saveFile(model.getId(), SysFileTypeEnum.Sb_MEASURE_IMGS.getValue(), model.getCheckImgList());
|
|
|
- sysFileService.saveFile(model.getId(), SysFileTypeEnum.Sb_MEASURE_FILES.getValue(), model.getCheckFileList());
|
|
|
- // 写入调拨记录
|
|
|
- if(insertAllocate){
|
|
|
- handleSbChangeRecord(remark1.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_POSITION);
|
|
|
- }
|
|
|
- if(insertParent){
|
|
|
- handleSbChangeRecord(remark2.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_PARENT);
|
|
|
- }
|
|
|
- if(insertNo){
|
|
|
- handleSbChangeRecord(remark3.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_NO);
|
|
|
+ sbInfo.setCheckDate(model.getLastDate());
|
|
|
+ Integer checkPeriod = 0;// 默认12个月
|
|
|
+ if(model.getCheckPeriod() != null){
|
|
|
+ checkPeriod = model.getCheckPeriod();
|
|
|
+ }else{
|
|
|
+ throw new BusinessException("检定设备的检定周期未设置,无法计算下次检定日期,请先设置");
|
|
|
+ }
|
|
|
+ sbInfo.setNextCheckDate(model.getLastDate().minusMonths(-checkPeriod).minusDays(1));
|
|
|
+ sbInfo.setZaiz(model.getName());// 检定单位
|
|
|
+ sbInfo.setSbdh(model.getNo());// 检定编号
|
|
|
+ sbInfo.setRemark(model.getRemark());// 备注
|
|
|
+ sbInfo.setDph(model.getRequirement());// 检定人
|
|
|
+ sbInfo.setMeasureStatus(YesNoEnum.NO.getValue());// 每次检定后, 检定状态改为正常
|
|
|
+ sbInfo.setCheckPeriod(model.getCheckPeriod()); // 检定周期
|
|
|
+ // 设备位置变动
|
|
|
+ boolean insertAllocate = Boolean.FALSE; // 设备位置
|
|
|
+ boolean insertParent = Boolean.FALSE; // 父设备
|
|
|
+ boolean insertNo = Boolean.FALSE; // 设备位号
|
|
|
+ String oldPositionId = getPureString(sbInfo.getPositionId());
|
|
|
+ String oldParentId = getPureString(sbInfo.getParentId());
|
|
|
+ String positionId = getPureString(model.getSbPositionId());
|
|
|
+ String parentId = getPureString(model.getSbParentId());
|
|
|
+ String oldSbPositionNo = getPureString(sbInfo.getPositionNo()); // 设备位号
|
|
|
+ String positionNo = getPureString(model.getSbPositionNo());
|
|
|
+ StringBuilder remark1 = new StringBuilder();
|
|
|
+ StringBuilder remark2 = new StringBuilder();
|
|
|
+ StringBuilder remark3 = new StringBuilder();
|
|
|
+ if(!oldPositionId.equals(positionId)){
|
|
|
+ insertAllocate = Boolean.TRUE;
|
|
|
+ sbInfo.setPositionId(positionId);
|
|
|
+ String before = oldPositionId == "" ? oldPositionId : sbPositionMapper.selectNameById(oldPositionId);
|
|
|
+ remark1.append("设备位置变动【" + before).append("】 ---> ");
|
|
|
+ String after = positionId == "" ? positionId : sbPositionMapper.selectNameById(positionId);
|
|
|
+ remark1.append("【" + after + "】");
|
|
|
+ }
|
|
|
+ if(!oldParentId.equals(parentId)){
|
|
|
+ insertParent = Boolean.TRUE;
|
|
|
+ sbInfo.setParentId(parentId);
|
|
|
+ remark2.append("父设备变动【" + sbInfo.getName()).append("】 ---> ");
|
|
|
+ String after = parentId == "" ? parentId : sbInfoMapper.selectNameById(parentId);
|
|
|
+ remark2.append("【" + after + "】");
|
|
|
+ }
|
|
|
+ if(!oldSbPositionNo.equals(positionNo)){
|
|
|
+ if(StringUtils.isNotBlank(sbInfo.getParentId())){
|
|
|
+ // 子设备判断,传输过来的位号,是否存在于sb_location
|
|
|
+ SbLocation location = new SbLocation();
|
|
|
+ location.setNo(positionNo);
|
|
|
+ if(sbLocationMapper.selectCount(location) == 0){
|
|
|
+ insertLocation(model.getSbPositionNo(),sbInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ insertNo = Boolean.TRUE;
|
|
|
+ remark3.append("设备位号变动【"+sbInfo.getPositionNo()).append("】 ---> ");
|
|
|
+ remark3.append("【"+positionNo+"】");
|
|
|
+ // 位号变动,父设备也有可能变动
|
|
|
+ SbLocation location = new SbLocation();
|
|
|
+ location.setNo(positionNo);
|
|
|
+ List<SbLocation> locations = sbLocationMapper.select(location);
|
|
|
+ if(locations != null && locations.size() > 0){
|
|
|
+ sbInfo.setParentId(locations.get(0).getSbId());
|
|
|
+ }
|
|
|
+ sbInfo.setPositionNo(model.getSbPositionNo()); // 设备位号
|
|
|
+ }
|
|
|
+ // 保存文件
|
|
|
+ sysFileService.saveFile(model.getId(), SysFileTypeEnum.Sb_MEASURE_IMGS.getValue(), model.getCheckImgList());
|
|
|
+ sysFileService.saveFile(model.getId(), SysFileTypeEnum.Sb_MEASURE_FILES.getValue(), model.getCheckFileList());
|
|
|
+ // 写入调拨记录
|
|
|
+ if(insertAllocate){
|
|
|
+ handleSbChangeRecord(remark1.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_POSITION);
|
|
|
+ }
|
|
|
+ if(insertParent){
|
|
|
+ handleSbChangeRecord(remark2.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_PARENT);
|
|
|
+ }
|
|
|
+ if(insertNo){
|
|
|
+ handleSbChangeRecord(remark3.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_NO);
|
|
|
+ }
|
|
|
+ sbInfoMapper.updateByPrimaryKey(sbInfo);
|
|
|
+ return sbMeasureLog;
|
|
|
}
|
|
|
- sbInfoMapper.updateByPrimaryKey(sbInfo);
|
|
|
- return sbMeasureLog;
|
|
|
}
|
|
|
|
|
|
private String getPureString(String info){
|
|
|
return StringUtils.isBlank(info) ? "" : info;
|
|
|
}
|
|
|
|
|
|
+ private void insertLocation(String sbPositionNo,SbInfo sbInfo){
|
|
|
+ SbLocation location = new SbLocation();
|
|
|
+ location.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ location.setNo(sbPositionNo);
|
|
|
+ location.setCreatedTime(LocalDateTime.now());
|
|
|
+ location.setCreatedUserId(SecurityUtils.getUserInfo().getUserId());
|
|
|
+ location.setCreatedUserName(SecurityUtils.getUserInfo().getUsername());
|
|
|
+ location.setLevel(sbInfo.getLevel());
|
|
|
+ location.setRepairDeptId(sbInfo.getRepairDeptId());
|
|
|
+ location.setSbId(sbInfo.getParentId());
|
|
|
+ sbLocationMapper.insert(location);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存变更记录
|
|
|
* @param remark
|
|
@@ -267,6 +298,8 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
|
|
|
record.setOldParentId(sb.getParentId());
|
|
|
record.setParentId(model.getSbParentId());
|
|
|
break;
|
|
|
+ case CommonConstants.CHANGE_TYPE_SB_STATUS:
|
|
|
+ break;
|
|
|
}
|
|
|
sbChangeRecordMapper.insert(record);
|
|
|
}
|