|
@@ -17,10 +17,8 @@ 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;
|
|
|
+import com.platform.dao.entity.upms.SysRole;
|
|
|
+import com.platform.dao.enums.*;
|
|
|
import com.platform.dao.mapper.sb.*;
|
|
|
import com.platform.dao.vo.query.sb.SbMeasureLogVO;
|
|
|
import com.platform.dao.vo.report.MeasureLogReportVO;
|
|
@@ -31,13 +29,14 @@ import com.platform.service.upms.SysFileService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import tk.mybatis.mapper.weekend.Weekend;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description 点检标准 service 实现类
|
|
@@ -137,13 +136,25 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
|
|
|
return pageInfo;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增检定记录:不能修改出厂编号
|
|
|
+ * 1:检定:
|
|
|
+ * a:设置在库,可以修改检定记录
|
|
|
+ * b:非在库的,可以修改位置、修改父设备、修改位号(检查位号是否重复,如果重复,则提示错误信息,不能提交)
|
|
|
+ * 2:设备报废,走预报废功能,自己填写报废单据,走报废申请,不在检定功能内
|
|
|
+ *
|
|
|
+ * @param model
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public SbMeasureLog saveModelByDTO(SbMeasureLogDTO model) {
|
|
|
+ // 在库走在库流程
|
|
|
+ if(model.getSbStatus()){
|
|
|
+ return this.saveModelForIn(model);
|
|
|
+ }
|
|
|
// 更新设备下次检定日期
|
|
|
SbInfo sbInfo = sbInfoMapper.selectByPrimaryKey(model.getSbId());
|
|
|
- SbInfo tempInfo = new SbInfo();
|
|
|
- tempInfo.setId(sbInfo.getId());
|
|
|
// 判断设备状态,如果是在库,修改设备状态即可
|
|
|
model.setCheckUserId(SecurityUtils.getUserInfo().getUserId()); // 谁操作即是检定记录人
|
|
|
if (SbUseType.BGCL.getValue().equals(sbInfo.getUseType())) {
|
|
@@ -153,40 +164,50 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
|
|
|
}
|
|
|
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);
|
|
|
- }
|
|
|
+ sbInfo.setParentId(sbInfo.getParentId());
|
|
|
+ sbInfo.setPositionId(sbInfo.getPositionId());
|
|
|
sbInfo.setCheckDate(model.getLastDate());
|
|
|
- Integer checkPeriod = 0;// 默认12个月
|
|
|
+ sbInfo.setPositionNo(model.getSbPositionNo());
|
|
|
+ Integer checkPeriod = 12;// 默认12个月
|
|
|
if (model.getCheckPeriod() != null) {
|
|
|
checkPeriod = model.getCheckPeriod();
|
|
|
} else {
|
|
|
throw new BusinessException("检定设备的检定周期未设置,无法计算下次检定日期,请先设置");
|
|
|
}
|
|
|
+
|
|
|
+ // 判断位号是否已经存在,且是否是被设备,如果不是则弹出提示
|
|
|
+ if(StringUtils.isNotBlank(model.getSbPositionNo())){
|
|
|
+ List<SbInfo> checkSbInfo = sbInfoMapper.selectByPositionNo(model.getSbPositionNo());
|
|
|
+ if(!CollectionUtils.isEmpty(checkSbInfo)){
|
|
|
+ if(checkSbInfo.size()>1){
|
|
|
+ throw new BusinessException("位号重复,有" + checkSbInfo.size() + "设备位号一样,请用位号查询并修改重复位号,同时只能存在一个位号:" + model.getSbPositionNo());
|
|
|
+ }
|
|
|
+ if(!checkSbInfo.get(0).getId().equals(model.getSbId())){
|
|
|
+ throw new BusinessException("该位号已经绑定到其他设备,出厂编号为:" + checkSbInfo.get(0).getZzh() + "请先将该设备置为在库");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
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()); // 检定周期
|
|
|
+ sbInfo.setCheckPeriod(checkPeriod); // 检定周期
|
|
|
// 设备位置变动
|
|
|
boolean insertAllocate = Boolean.FALSE; // 设备位置
|
|
|
boolean insertParent = Boolean.FALSE; // 父设备
|
|
|
boolean insertNo = Boolean.FALSE; // 设备位号
|
|
|
- boolean insertZzh = Boolean.FALSE; // 出厂编码
|
|
|
+ // boolean insertZzh = 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());
|
|
|
- String oldZzh = getPureString(sbInfo.getZzh()); // 原出厂编码
|
|
|
- String zzh = getPureString(model.getZzh()); // 出厂编码
|
|
|
+ // String oldZzh = getPureString(sbInfo.getZzh()); // 原出厂编码
|
|
|
+ // String zzh = getPureString(model.getZzh()); // 出厂编码
|
|
|
StringBuilder remark1 = new StringBuilder();
|
|
|
StringBuilder remark2 = new StringBuilder();
|
|
|
StringBuilder remark3 = new StringBuilder();
|
|
@@ -226,35 +247,35 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
|
|
|
}
|
|
|
sbInfo.setPositionNo(model.getSbPositionNo()); // 设备位号
|
|
|
}
|
|
|
- StringBuilder remark4 = new StringBuilder();
|
|
|
+ /*StringBuilder remark4 = new StringBuilder();
|
|
|
if (!oldZzh.equals(zzh)) {
|
|
|
insertZzh = Boolean.TRUE;
|
|
|
remark4.append("设备原号变动【" + oldZzh).append("】 ---> ");
|
|
|
remark4.append("【" + zzh + "】");
|
|
|
sbInfo.setZzh(zzh);
|
|
|
- }
|
|
|
+ }*/
|
|
|
// 保存文件
|
|
|
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);
|
|
|
+ handleSbChangeRecord(remark1.toString(), model, sbInfo, CommonConstants.CHANGE_TYPE_SB_POSITION);
|
|
|
}
|
|
|
if (insertParent) {
|
|
|
- handleSbChangeRecord(remark2.toString(), model, tempInfo, CommonConstants.CHANGE_TYPE_SB_PARENT);
|
|
|
+ handleSbChangeRecord(remark2.toString(), model, sbInfo, CommonConstants.CHANGE_TYPE_SB_PARENT);
|
|
|
}
|
|
|
if (insertNo) {
|
|
|
- handleSbChangeRecord(remark3.toString(), model, tempInfo, CommonConstants.CHANGE_TYPE_SB_NO);
|
|
|
+ handleSbChangeRecord(remark3.toString(), model, sbInfo, CommonConstants.CHANGE_TYPE_SB_NO);
|
|
|
}
|
|
|
- if (insertZzh) {
|
|
|
+ /* if (insertZzh) {
|
|
|
handleSbChangeRecord(remark4.toString(), model, tempInfo, CommonConstants.CHANGE_TYPE_SB_ZZH);
|
|
|
- }
|
|
|
+ }*/
|
|
|
// 更新设备状态
|
|
|
if (model.getSbStatus()) {
|
|
|
sbInfo.setStatus(SbInfoStatusEnum.IN_STORE.getValue());
|
|
|
String remark = "设备状态由【" + SbInfoStatusEnum.getNameByValue(sbInfo.getStatus()) + "】 ---> 【";
|
|
|
remark += "在库】";
|
|
|
- handleSbChangeRecord(remark, model, tempInfo, CommonConstants.CHANGE_TYPE_SB_STATUS);
|
|
|
+ handleSbChangeRecord(remark, model, sbInfo, CommonConstants.CHANGE_TYPE_SB_STATUS);
|
|
|
}
|
|
|
sbInfoMapper.updateByPrimaryKey(sbInfo);
|
|
|
return sbMeasureLog;
|
|
@@ -473,6 +494,10 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * *
|
|
|
+ * @param batchSbMeasureLog
|
|
|
+ */
|
|
|
@Override
|
|
|
public void saveBatchMeasureLog(BatchSbMeasureLog batchSbMeasureLog) {
|
|
|
if (batchSbMeasureLog.getSbMeasureLogDTOList() != null && batchSbMeasureLog.getSbMeasureLogDTOList().size() > 0) {
|
|
@@ -484,8 +509,10 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
|
|
|
|
|
|
@Override
|
|
|
public void saveBatchIn(BatchSbMeasureLog batchSbMeasureLog) {
|
|
|
- if (batchSbMeasureLog.getSbIds() != null && batchSbMeasureLog.getSbIds().size() > 0) {
|
|
|
- batchSbMeasureLog.getSbIds().forEach(item -> {
|
|
|
+ if (batchSbMeasureLog.getSbMeasureLogDTOList() != null && batchSbMeasureLog.getSbMeasureLogDTOList().size() > 0) {
|
|
|
+ List<String> sbIds = batchSbMeasureLog.getSbMeasureLogDTOList().stream().map(SbMeasureLogDTO::getSbId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ batchSbMeasureLog.getSbMeasureLogDTOList().forEach(item -> {
|
|
|
this.saveModelForIn(item);
|
|
|
});
|
|
|
}
|
|
@@ -517,25 +544,53 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 入库
|
|
|
- * @param sbId
|
|
|
+ * 批量入库:type在前端传递过来
|
|
|
+ * *
|
|
|
+ * @param sbMeasureLogDTO
|
|
|
*/
|
|
|
- private void saveModelForIn(String sbId){
|
|
|
- SbInfo sbInfo = sbInfoMapper.selectByPrimaryKey(sbId);
|
|
|
+ private SbMeasureLog saveModelForIn(SbMeasureLogDTO sbMeasureLogDTO){
|
|
|
+ SbInfo sbInfo = sbInfoMapper.selectByPrimaryKey(sbMeasureLogDTO.getSbId());
|
|
|
+ if (SbUseType.BGCL.getValue().equals(sbInfo.getUseType())) {
|
|
|
+ sbMeasureLogDTO.setType(1);
|
|
|
+ } else if (SbUseType.TZSB.getValue().equals(sbInfo.getUseType())) {
|
|
|
+ sbMeasureLogDTO.setType(2);
|
|
|
+ }
|
|
|
+ Integer checkPeriod = 12;// 默认12个月
|
|
|
+ if (sbMeasureLogDTO.getCheckPeriod() != null) {
|
|
|
+ checkPeriod = sbMeasureLogDTO.getCheckPeriod();
|
|
|
+ } else {
|
|
|
+ throw new BusinessException("检定设备的检定周期未设置,无法计算下次检定日期,请先设置");
|
|
|
+ }
|
|
|
+ SbMeasureLog sbMeasureLog = super.saveModelByDTO(sbMeasureLogDTO);
|
|
|
String oldPositionId = getPureString(sbInfo.getPositionId());
|
|
|
// 修改设备状态,【位号、父位号、设备位置清空】
|
|
|
-
|
|
|
- SbMeasureLogDTO dto = new SbMeasureLogDTO();
|
|
|
// 记录位号
|
|
|
String remark1 = "设备位号变动【" + sbInfo.getPositionNo() + "】 ---> 【无】";
|
|
|
- handleSbChangeRecord(remark1,dto,sbInfo,CommonConstants.CHANGE_TYPE_SB_NO);
|
|
|
+ handleSbChangeRecord(remark1,sbMeasureLogDTO,sbInfo,CommonConstants.CHANGE_TYPE_SB_NO);
|
|
|
// 记录父位号
|
|
|
String remark2 = "设备父位号变动【" + sbInfo.getPpNo() + "】 ---> 【无】";
|
|
|
- handleSbChangeRecord(remark2,dto,sbInfo,CommonConstants.CHANGE_TYPE_SB_PPNO);
|
|
|
+ handleSbChangeRecord(remark2,sbMeasureLogDTO,sbInfo,CommonConstants.CHANGE_TYPE_SB_PPNO);
|
|
|
// 记录设备位置
|
|
|
String before = oldPositionId == "" ? oldPositionId : sbPositionMapper.selectNameById(oldPositionId);
|
|
|
String remark3 = "设备位置变动【" + before + "】 ---> 【无】";
|
|
|
- handleSbChangeRecord(remark3,dto,sbInfo,CommonConstants.CHANGE_TYPE_SB_POSITION);
|
|
|
+ handleSbChangeRecord(remark3,sbMeasureLogDTO,sbInfo,CommonConstants.CHANGE_TYPE_SB_POSITION);
|
|
|
+ // 更新设备信息,设备状态在库,位号等数据清空?
|
|
|
+ sbInfo.setMeasureStatus(YesNoEnum.NO.getValue());
|
|
|
+ sbInfo.setParentId(null);
|
|
|
+ sbInfo.setPositionId(null);
|
|
|
+ sbInfo.setPositionNo(null);
|
|
|
+ sbInfo.setZaiz(sbMeasureLogDTO.getName());// 检定单位
|
|
|
+ sbInfo.setSbdh(sbMeasureLogDTO.getNo());// 检定编号
|
|
|
+ sbInfo.setRemark(sbMeasureLogDTO.getRemark());// 备注
|
|
|
+ sbInfo.setDph(sbMeasureLogDTO.getRequirement());// 检定人
|
|
|
+ sbInfo.setMeasureStatus(YesNoEnum.NO.getValue());// 每次检定后, 检定状态改为正常
|
|
|
+ sbInfo.setCheckPeriod(checkPeriod); // 检定周期
|
|
|
+ sbInfo.setCheckPeriod(sbMeasureLogDTO.getCheckPeriod());
|
|
|
+ sbInfo.setCheckDate(sbMeasureLogDTO.getLastDate());
|
|
|
+ sbInfo.setNextCheckDate(DateUtils.plus(sbMeasureLogDTO.getLastDate(), sbMeasureLogDTO.getCheckPeriod(), ChronoUnit.MONTHS));
|
|
|
+ sbInfo.setStatus(SbInfoStatusEnum.IN_STORE.getValue());
|
|
|
+ sbInfoMapper.updateByPrimaryKey(sbInfo);
|
|
|
+ return sbMeasureLog;
|
|
|
}
|
|
|
|
|
|
/*@Override
|