|
@@ -30,6 +30,7 @@ import org.apache.poi.ss.formula.functions.T;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import tk.mybatis.mapper.weekend.Weekend;
|
|
|
+import tk.mybatis.mapper.weekend.WeekendCriteria;
|
|
|
|
|
|
import javax.persistence.Id;
|
|
|
import java.lang.annotation.Annotation;
|
|
@@ -196,6 +197,190 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
|
|
|
return pageInfo;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增检定记录:不能修改出厂编号
|
|
|
+ * 1:检定:
|
|
|
+ * a:设置在库,可以修改检定记录
|
|
|
+ * b:非在库的,可以修改位置、修改父设备、修改位号(检查位号是否重复,如果重复,则提示错误信息,不能提交)
|
|
|
+ * 2:设备报废,走预报废功能,自己填写报废单据,走报废申请,不在检定功能内
|
|
|
+ *
|
|
|
+ * @param model
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public SbMeasureLog saveModelByDTO2(SbMeasureLogDTO model) {
|
|
|
+ // 更新设备下次检定日期
|
|
|
+ SbInfo sbInfo = sbInfoMapper.selectByPrimaryKey(model.getSbId());
|
|
|
+ // 判断设备状态,如果是在库,修改设备状态即可
|
|
|
+ /*if(model.getSbStatus()){
|
|
|
+ sbInfo.setStatus(SbInfoStatusEnum.IN_STORE.getValue());
|
|
|
+ return this.saveModelForIn(model);
|
|
|
+ }*/
|
|
|
+ model.setCheckUserId(SecurityUtils.getUserInfo().getUserId()); // 谁操作即是检定记录人
|
|
|
+ if (SbUseType.BGCL.getValue().equals(sbInfo.getUseType())) {
|
|
|
+ model.setType(1);
|
|
|
+ } else if (SbUseType.TZSB.getValue().equals(sbInfo.getUseType())) {
|
|
|
+ model.setType(2);
|
|
|
+ }
|
|
|
+ SbMeasureLog sbMeasureLog = super.saveModelByDTO(model);
|
|
|
+ model.setId(sbMeasureLog.getId());
|
|
|
+ sbInfo.setParentId(sbInfo.getParentId());
|
|
|
+ sbInfo.setPositionId(sbInfo.getPositionId());
|
|
|
+ sbInfo.setCheckDate(model.getLastDate());
|
|
|
+ //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(checkPeriod); // 检定周期
|
|
|
+ // 设备位置变动
|
|
|
+ boolean insertAllocate = Boolean.FALSE; // 设备位置
|
|
|
+ boolean insertParent = Boolean.FALSE; // 父设备
|
|
|
+ boolean insertNo = 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()); // 出厂编码
|
|
|
+ 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 + "】");
|
|
|
+
|
|
|
+ }
|
|
|
+ StringBuilder inRemark = new StringBuilder(); // 新增子设备记录
|
|
|
+ StringBuilder outRemark = new StringBuilder(); // 移除子设备记录
|
|
|
+ if (!oldParentId.equals(parentId)) {
|
|
|
+ insertParent = Boolean.TRUE;
|
|
|
+ sbInfo.setParentId(parentId);
|
|
|
+ String oldParentName = "无";
|
|
|
+ if(StringUtils.isNotBlank(oldParentId)){
|
|
|
+ oldParentName = sbInfoMapper.selectNameById(oldParentId);
|
|
|
+ outRemark.append("子设备【"+sbInfo.getName()+"】移出。");
|
|
|
+ }
|
|
|
+ remark2.append("父设备变动【" + oldParentName).append("】 ---> ");
|
|
|
+ String after = parentId == "" ? parentId : sbInfoMapper.selectNameById(parentId);
|
|
|
+ remark2.append("【" + after + "】");
|
|
|
+ outRemark.append("子设备【"+sbInfo.getName()+"】挂靠。");
|
|
|
+ }
|
|
|
+ /*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()); // 设备位号
|
|
|
+ }*/
|
|
|
+ /*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, sbInfo, CommonConstants.CHANGE_TYPE_SB_POSITION);
|
|
|
+ }
|
|
|
+ if (insertParent) {
|
|
|
+ model.setOldParentId(oldParentId);
|
|
|
+ handleSbChangeRecord(remark2.toString(), model, sbInfo, CommonConstants.CHANGE_TYPE_SB_PARENT);
|
|
|
+ // 旧父设备增加一条,移除记录,新父设备增加一条,新增记录
|
|
|
+ if(StringUtils.isNotBlank(oldParentId)){
|
|
|
+ // 移除记录
|
|
|
+ handleSbChangeRecord(outRemark.toString(), model, sbInfo, CommonConstants.CHANGE_TYPE_SB_OUT);
|
|
|
+ }
|
|
|
+ handleSbChangeRecord(inRemark.toString(), model, sbInfo, CommonConstants.CHANGE_TYPE_SB_IN);
|
|
|
+ }
|
|
|
+ /*if (insertNo) {
|
|
|
+ handleSbChangeRecord(remark3.toString(), model, sbInfo, CommonConstants.CHANGE_TYPE_SB_NO);
|
|
|
+ }*/
|
|
|
+ /* if (insertZzh) {
|
|
|
+ handleSbChangeRecord(remark4.toString(), model, tempInfo, CommonConstants.CHANGE_TYPE_SB_ZZH);
|
|
|
+ }*/
|
|
|
+ // 更新设备状态
|
|
|
+ if (model.getSbStatus()) {
|
|
|
+ String remark = "设备状态由【" + SbInfoStatusEnum.getNameByValue(sbInfo.getStatus()) + "】 ---> 【";
|
|
|
+ remark += "在库】";
|
|
|
+ sbInfo.setStatus(SbInfoStatusEnum.IN_STORE.getValue());
|
|
|
+ handleSbChangeRecord(remark, model, sbInfo, CommonConstants.CHANGE_TYPE_SB_STATUS);
|
|
|
+// SbInfo info = new SbInfo();
|
|
|
+// info.setId(model.getSbId());
|
|
|
+// info.setPositionNo("暂无");
|
|
|
+// sbInfoMapper.updateByPrimaryKeySelective(info);
|
|
|
+ sbInfo.setPositionNo("暂无");
|
|
|
+
|
|
|
+ SbChangeRecord record = new SbChangeRecord();
|
|
|
+ record.setSbId(model.getId());
|
|
|
+ record.setSbNoId(oldSbPositionNo);
|
|
|
+ UserInfo userInfo = SecurityUtils.getUserInfo();
|
|
|
+ record.setCreatedUserId(userInfo.getUserId());
|
|
|
+ record.setCreatedUserName(userInfo.getUsername());
|
|
|
+ record.setCreatedTime(LocalDateTime.now());
|
|
|
+ record.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ record.setActionType(2);
|
|
|
+ sbChangeRecordMapper.insert(record);
|
|
|
+
|
|
|
+ SbMeasureLogDTO dto = new SbMeasureLogDTO();
|
|
|
+ setCreateUserInfo(dto);
|
|
|
+ dto.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ SbMeasureLog log = BeanConverterUtil.copyObjectProperties(dto,SbMeasureLog.class);
|
|
|
+ sbMeasureLogMapper.insert(log);
|
|
|
+ }
|
|
|
+ sbInfoMapper.updateByPrimaryKey(sbInfo);
|
|
|
+ return sbMeasureLog;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 新增检定记录:不能修改出厂编号
|
|
|
* 1:检定:
|
|
@@ -628,6 +813,7 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
|
|
|
}
|
|
|
}
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public void saveBatchMeasureLog(BatchSbMeasureLog batchSbMeasureLog) {
|
|
|
if (batchSbMeasureLog.getSbMeasureLogDTOList() != null && batchSbMeasureLog.getSbMeasureLogDTOList().size() > 0) {
|
|
|
batchSbMeasureLog.getSbMeasureLogDTOList().forEach(item -> {
|
|
@@ -643,13 +829,86 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
|
|
|
sbChangeRecord.setCreatedUserName(userInfo.getRealName());
|
|
|
}
|
|
|
setKey(sbChangeRecord);
|
|
|
- sbChangeRecordMapper.insertSelective(sbChangeRecord);
|
|
|
item.setOtherType(SbMeasureLogOtherTypeEnum.CHECK.getValue());
|
|
|
+ System.out.println("即将执行sql");
|
|
|
+ sbChangeRecordMapper.insertSelective(sbChangeRecord);
|
|
|
this.saveModelByDTO(item);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void saveBatchMeasureLog2(BatchSbMeasureLog batchSbMeasureLog) {
|
|
|
+ if (batchSbMeasureLog.getSbMeasureLogDTOList() != null && batchSbMeasureLog.getSbMeasureLogDTOList().size() > 0) {
|
|
|
+ Weekend<SbInfo> weekend = new Weekend<>(SbInfo.class);
|
|
|
+ WeekendCriteria<SbInfo,Object> weekendCriteria = weekend.weekendCriteria();
|
|
|
+ List<String> positionNos = batchSbMeasureLog.getSbMeasureLogDTOList().stream().map(SbMeasureLogDTO::getPositionNo).collect(Collectors.toList());
|
|
|
+ weekendCriteria.andIn(SbInfo::getPositionNo,positionNos);
|
|
|
+ weekendCriteria.andEqualTo(SbInfo::getUseType,4);
|
|
|
+ List<SbInfo> queryInfos = sbInfoMapper.selectByExample(weekend);
|
|
|
+ StringBuffer sb = new StringBuffer("以下设备位号存在重复,无法通过模板导入:");
|
|
|
+ for (String positionNo:positionNos){
|
|
|
+ List<String> tempList = new ArrayList<>();
|
|
|
+ for (SbInfo sbInfo:queryInfos){
|
|
|
+ if (positionNo.equals(sbInfo.getPositionNo())){
|
|
|
+ tempList.add(positionNo);
|
|
|
+ if (tempList.size()>1){
|
|
|
+ sb.append(positionNo+",");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sb.toString().contains(",")){
|
|
|
+ throw new BusinessException(sb.toString());
|
|
|
+ }
|
|
|
+ batchSbMeasureLog.getSbMeasureLogDTOList().forEach(item -> {
|
|
|
+ SbInfo sbInfo = new SbInfo();
|
|
|
+ sbInfo.setPositionNo(item.getPositionNo());
|
|
|
+ sbInfo.setUseType(4);//仪表
|
|
|
+ List<SbInfo> sbInfos = sbInfoMapper.select(sbInfo);
|
|
|
+ item.setOtherType(SbMeasureLogOtherTypeEnum.CHECK.getValue());
|
|
|
+
|
|
|
+ if (sbInfos!=null&&sbInfos.size()==1) {
|
|
|
+ item.setLastDate(LocalDate.now());
|
|
|
+ item.setCheckPeriod(sbInfos.get(0).getCheckPeriod());
|
|
|
+ item.setSbId(sbInfos.get(0).getId());
|
|
|
+ item.setSbStatus(false);
|
|
|
+ this.saveModelByDTO2(item);
|
|
|
+ }else if (sbInfos==null||sbInfos.size()<=0){
|
|
|
+ throw new BusinessException("未找到对应位号:"+item.getPositionNo());
|
|
|
+ }
|
|
|
+
|
|
|
+ SbChangeRecord sbChangeRecord = new SbChangeRecord();
|
|
|
+ sbChangeRecord.setCreatedTime(LocalDateTime.now());
|
|
|
+ sbChangeRecord.setUpdateTime(LocalDateTime.now());
|
|
|
+ sbChangeRecord.setTransformType(SbTransFormTypeEnum.CHECK.getValue());
|
|
|
+ System.out.println("sbId===="+item.getSbId());
|
|
|
+ sbChangeRecord.setSbId(item.getSbId());
|
|
|
+ OauthUser user = SecurityUtils.getUser();
|
|
|
+ if (user != null) {
|
|
|
+ UserInfo userInfo = user.getUserInfo();
|
|
|
+ sbChangeRecord.setCreatedUserId(userInfo.getUserId());
|
|
|
+ sbChangeRecord.setCreatedUserName(userInfo.getRealName());
|
|
|
+ }
|
|
|
+ setKey(sbChangeRecord);
|
|
|
+ System.out.println("即将执行sql");
|
|
|
+ sbChangeRecordMapper.insertSelective(sbChangeRecord);
|
|
|
+
|
|
|
+
|
|
|
+// if (sbInfos!=null&&sbInfos.size()>0) {
|
|
|
+// item.setLastDate(LocalDate.now());
|
|
|
+// item.setCheckPeriod(sbInfos.get(0).getCheckPeriod());
|
|
|
+// item.setSbId(sbInfos.get(0).getId());
|
|
|
+// item.setSbStatus(false);
|
|
|
+// this.saveModelByDTO2(item);
|
|
|
+// }else {
|
|
|
+// throw new BusinessException("未找到对应位号:"+item.getPositionNo());
|
|
|
+// }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public void saveBatchIn(BatchSbMeasureLog batchSbMeasureLog) {
|