|
@@ -1,5 +1,6 @@
|
|
|
package com.platform.service.check.impl;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.platform.common.bean.AbstractPageResultBean;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.platform.common.exception.BusinessException;
|
|
@@ -8,38 +9,37 @@ import com.platform.dao.bean.MyPage;
|
|
|
import com.platform.dao.dto.check.CheckJobDTO;
|
|
|
import com.platform.dao.dto.check.CheckStandardDTO;
|
|
|
import com.platform.dao.dto.check.CheckStandardParamDTO;
|
|
|
+import com.platform.dao.dto.check.CheckStandardSpareDTO;
|
|
|
import com.platform.dao.dto.part.PartInfoDTO;
|
|
|
import com.platform.dao.dto.sb.SbInfoDTO;
|
|
|
-import com.platform.dao.entity.check.CheckJob;
|
|
|
-import com.platform.dao.entity.check.CheckProjectStandardRelation;
|
|
|
-import com.platform.dao.entity.check.CheckStandard;
|
|
|
-import com.platform.dao.entity.check.CheckStandardParam;
|
|
|
+import com.platform.dao.dto.store.InStoreDetailDTO;
|
|
|
+import com.platform.dao.entity.check.*;
|
|
|
import com.platform.dao.entity.maintain.MaintainProjectStandardRelation;
|
|
|
import com.platform.dao.entity.maintain.MaintainStandardParam;
|
|
|
import com.platform.dao.entity.part.PartInfo;
|
|
|
+import com.platform.dao.entity.repair.RepairApplicationForm;
|
|
|
import com.platform.dao.entity.sb.SbInfo;
|
|
|
import com.platform.dao.entity.sb.SbType;
|
|
|
import com.platform.dao.entity.sqarepartmanage.SparePartInfo;
|
|
|
import com.platform.dao.entity.store.InStoreDetail;
|
|
|
import com.platform.dao.entity.upms.SysFile;
|
|
|
import com.platform.dao.entity.upms.SysUser;
|
|
|
-import com.platform.dao.enums.CheckJobStatusEnum;
|
|
|
-import com.platform.dao.enums.CheckPlanPeriodTypeEnum;
|
|
|
-import com.platform.dao.enums.SysFileTypeEnum;
|
|
|
-import com.platform.dao.mapper.check.CheckJobMapper;
|
|
|
-import com.platform.dao.mapper.check.CheckProjectStandardRelationMapper;
|
|
|
-import com.platform.dao.mapper.check.CheckStandardMapper;
|
|
|
-import com.platform.dao.mapper.check.CheckStandardParamMapper;
|
|
|
+import com.platform.dao.enums.*;
|
|
|
+import com.platform.dao.mapper.check.*;
|
|
|
import com.platform.dao.mapper.maintain.MaintainProjectStandardRelationMapper;
|
|
|
import com.platform.dao.mapper.part.PartInfoMapper;
|
|
|
import com.platform.dao.mapper.sb.SbInfoMapper;
|
|
|
import com.platform.dao.mapper.upms.SysFileMapper;
|
|
|
import com.platform.dao.mapper.upms.SysUserMapper;
|
|
|
import com.platform.dao.util.CustomExcelImportUtil;
|
|
|
+import com.platform.dao.util.MessageTemplateUtil;
|
|
|
+import com.platform.dao.vo.query.check.CheckStandardSpareVO;
|
|
|
import com.platform.dao.vo.query.check.CheckStandardVO;
|
|
|
import com.platform.dao.vo.sb.SbInfoVO;
|
|
|
import com.platform.service.check.CheckStandardParamService;
|
|
|
import com.platform.service.check.CheckStandardService;
|
|
|
+import com.platform.service.check.CheckStandardSpareService;
|
|
|
+import com.platform.service.event.WorkplaceBacklogEvent;
|
|
|
import com.platform.service.part.PartInfoService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.platform.service.base.impl.BaseServiceImpl;
|
|
@@ -55,6 +55,7 @@ import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -70,6 +71,8 @@ public class CheckStandardServiceImpl extends BaseServiceImpl<CheckStandardMappe
|
|
|
private CheckStandardParamService paramService;
|
|
|
private CheckProjectStandardRelationMapper relationMapper;
|
|
|
private CheckStandardParamMapper paramMapper;
|
|
|
+ private CheckStandardSpareMapper spareMapper;
|
|
|
+ private CheckStandardSpareService spareService;
|
|
|
private CheckJobMapper checkJobMapper;
|
|
|
private PartInfoService partInfoService;
|
|
|
private final SysFileMapper sysFileMapper;
|
|
@@ -140,6 +143,14 @@ public class CheckStandardServiceImpl extends BaseServiceImpl<CheckStandardMappe
|
|
|
model.setNo(IdGeneratorUtils.getCheckStandardNo(++count));
|
|
|
CheckStandard checkStandard = super.saveModelByDTO(model);
|
|
|
this.saveFile(model);
|
|
|
+
|
|
|
+ // 保存备件
|
|
|
+ List<CheckStandardSpareDTO> paramList = model.getDetailList();
|
|
|
+ paramList.forEach(item -> {
|
|
|
+ item.setCheckId(checkStandard.getId());
|
|
|
+ item.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ });
|
|
|
+ spareService.saveModelListByDTO(paramList);
|
|
|
// 保存参数
|
|
|
/* List<CheckStandardParamDTO> paramList = model.getParamList();
|
|
|
paramList.forEach(item -> {
|
|
@@ -160,10 +171,48 @@ public class CheckStandardServiceImpl extends BaseServiceImpl<CheckStandardMappe
|
|
|
}
|
|
|
|
|
|
super.modModelByDTO(model);
|
|
|
- // 删掉参数后插入
|
|
|
- Weekend<CheckStandardParam> weekend = new Weekend<>(CheckStandardParam.class);
|
|
|
- weekend.weekendCriteria().andEqualTo(CheckStandardParam::getStandardId, model.getId());
|
|
|
- paramMapper.deleteByExample(weekend);
|
|
|
+
|
|
|
+ // 先删后插,前端删除的不存在与ids里面,说明被删掉了,需要删除
|
|
|
+ List<CheckStandardSpareDTO> detailList = model.getDetailList();
|
|
|
+ Weekend<CheckStandardSpare> detailWeekend = new Weekend<>(CheckStandardSpare.class);
|
|
|
+ List<String> ids = detailList.stream().map(CheckStandardSpareDTO::getId).collect(Collectors.toList());
|
|
|
+ ids = ids.stream().filter(item -> StringUtils.isNotBlank(item)).collect(Collectors.toList());
|
|
|
+ if(!CollectionUtils.isEmpty(ids) && ids.size()>0) {
|
|
|
+ detailWeekend.weekendCriteria().andNotIn(CheckStandardSpare::getId, ids);
|
|
|
+ spareService.deleteByExample(detailWeekend);
|
|
|
+ }else{
|
|
|
+ // 全部刪除
|
|
|
+ detailWeekend.weekendCriteria().andEqualTo(CheckStandardSpare::getCheckId, model.getId());
|
|
|
+ spareService.deleteByExample(detailWeekend);
|
|
|
+ }
|
|
|
+ // 新增或者更新备件
|
|
|
+ List<CheckStandardSpare> updateDetailList = new ArrayList<CheckStandardSpare>();
|
|
|
+ List<CheckStandardSpare> addDetailList = new ArrayList<CheckStandardSpare>();
|
|
|
+
|
|
|
+ for(CheckStandardSpareDTO detail:detailList) {
|
|
|
+ if(ObjectUtil.isNull(detail.getId())){
|
|
|
+ detail.setCheckId(model.getId());
|
|
|
+ CheckStandardSpare realDetail = new CheckStandardSpare();
|
|
|
+ realDetail = BeanConverterUtil.copyObjectProperties(detail, CheckStandardSpare.class);
|
|
|
+ realDetail.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ realDetail.setCheckId(model.getId());
|
|
|
+ addDetailList.add(realDetail);
|
|
|
+ }else{
|
|
|
+ Weekend<CheckStandardSpare> weekend = new Weekend<>(CheckStandardSpare.class);
|
|
|
+ weekend.weekendCriteria().andEqualTo(CheckStandardSpare::getId, detail.getId());
|
|
|
+ CheckStandardSpare realDetail = spareService.selectOneByExample(weekend);
|
|
|
+ realDetail.setNum(detail.getNum());
|
|
|
+ updateDetailList.add(realDetail);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ if(!CollectionUtils.isEmpty(addDetailList)){
|
|
|
+ spareService.insertListforComplex(addDetailList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(updateDetailList)){
|
|
|
+ spareService.updateBatch(updateDetailList);
|
|
|
+ }
|
|
|
+
|
|
|
this.saveFile(model);
|
|
|
// 保存参数
|
|
|
/* List<CheckStandardParamDTO> paramList = model.getParamList();
|
|
@@ -224,6 +273,10 @@ public class CheckStandardServiceImpl extends BaseServiceImpl<CheckStandardMappe
|
|
|
});
|
|
|
checkStandard.setCheckImgList(checkImgList);
|
|
|
checkStandard.setCheckFileList(checkFileList);
|
|
|
+
|
|
|
+ // 备件列表
|
|
|
+ List<CheckStandardSpareVO> spareList = spareService.selectVOListByCheckId(checkStandard.getId());
|
|
|
+ checkStandard.setDetailList(spareList);
|
|
|
return checkStandard;
|
|
|
}
|
|
|
|
|
@@ -360,7 +413,7 @@ public class CheckStandardServiceImpl extends BaseServiceImpl<CheckStandardMappe
|
|
|
weekendCriteria.andEqualTo(SbInfo::getNo, fileSbNo).orEqualTo(SbInfo::getZbh, fileSbNo);
|
|
|
SbInfo sbInfo = sbInfoMapper.selectOneByExample(weekend);
|
|
|
if(sbInfo == null){
|
|
|
- throw new BusinessException("查不到设备,请确保编号正确" + ", 导入文件中的号:" + fileSbNo);
|
|
|
+ throw new BusinessException("新号或者旧号均查不到,请确保编号正确" + ", 导入文件中的编号:" + fileSbNo);
|
|
|
}
|
|
|
List<CheckStandard> addItems = new ArrayList<CheckStandard>();
|
|
|
List<SysUser> users = sysUserMapper.selectAll();
|
|
@@ -406,4 +459,78 @@ public class CheckStandardServiceImpl extends BaseServiceImpl<CheckStandardMappe
|
|
|
throw new BusinessException(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询备件预警
|
|
|
+ *
|
|
|
+ * @param type
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void genSpareWarnTask(int type) {
|
|
|
+ CheckStandardDTO checkStandardDTO = new CheckStandardDTO();
|
|
|
+ checkStandardDTO.setPeriodType(CheckPlanPeriodTypeEnum.YEAR.getValue());
|
|
|
+ List<CheckStandard> checkStandardList = super.getModelListByDTO(checkStandardDTO);
|
|
|
+
|
|
|
+ // 查询近六个月待执行的任务列表。
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ LocalDate afterSixMonth = DateUtils.plus(now, 6, ChronoUnit.MONTHS);
|
|
|
+ Weekend<CheckJob> weekend = new Weekend<>(CheckJob.class);
|
|
|
+ weekend.weekendCriteria().andNotEqualTo(CheckJob::getStatus, CheckJobStatusEnum.FINISHED.getValue())
|
|
|
+ .andBetween(CheckJob::getStartTime, now, afterSixMonth);
|
|
|
+ List<CheckJob> checkJobs = checkJobMapper.selectByExample(weekend);
|
|
|
+
|
|
|
+ // 获取未执行的标准id,不能用stream获取id列表,会覆盖重复的标准id(不会重复,因为一个标准对应一个任务。)
|
|
|
+ if(CollectionUtil.isNotEmpty(checkJobs)){
|
|
|
+ List<String> ids = checkJobs.stream().map(CheckJob::getStandardId).collect(Collectors.toList());
|
|
|
+ ids = ids.stream().filter(item -> StringUtils.isNotBlank(item)).collect(Collectors.toList());
|
|
|
+ if(!CollectionUtils.isEmpty(ids) && ids.size()>0) {
|
|
|
+ CheckStandardSpareDTO dto = new CheckStandardSpareDTO();
|
|
|
+ dto.setCheckIds(ids);
|
|
|
+ List<CheckStandardSpareVO> voList = spareMapper.selectSpareWarn(dto);
|
|
|
+ List<CheckStandardSpareVO> warnList = new ArrayList<CheckStandardSpareVO>();
|
|
|
+ if(CollectionUtil.isNotEmpty(voList)){
|
|
|
+ for(CheckStandardSpareVO vo: voList){
|
|
|
+ if(vo.getNum().compareTo(vo.getStoreNum())>0){
|
|
|
+ warnList.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(CollectionUtil.isNotEmpty(warnList)){
|
|
|
+ List<SysUser> users = getUsersByIdentity(Arrays.asList(new Integer[]{SysUserIdentityType.WXZG.getValue()}));
|
|
|
+ sendOverTimeNotice(users, warnList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据身份获取用户
|
|
|
+ *
|
|
|
+ * @param identities
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<SysUser> getUsersByIdentity(List<Integer> identities) {
|
|
|
+ Weekend<SysUser> w = new Weekend<>(SysUser.class);
|
|
|
+ w.weekendCriteria().andIn(SysUser::getIdentityType, identities);
|
|
|
+ return sysUserMapper.selectByExample(w);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 备件不足消息推送
|
|
|
+ *
|
|
|
+ * @param users
|
|
|
+ * @param tasks
|
|
|
+ */
|
|
|
+ private void sendOverTimeNotice(List<SysUser> users, List<CheckStandardSpareVO> tasks) {
|
|
|
+ if (CollectionUtil.isNotEmpty(users) && CollectionUtil.isNotEmpty(tasks)) {
|
|
|
+ List<String> userIds = users.stream().map(item -> item.getUserId()).collect(Collectors.toList());
|
|
|
+ List<String> mails = users.stream().map(item -> item.getEmail()).collect(Collectors.toList());
|
|
|
+ StringBuffer context = new StringBuffer();
|
|
|
+ tasks.forEach(item -> context.append(item.toString()));
|
|
|
+ SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.CHECK_SPARE_WARN.getValue(), WorkplaceBacklogDetailTypeEnum.CHECK_SPARE_WARN.getValue(),
|
|
|
+ null, MessageTemplateUtil.getSpareWarnNotic(context.toString(), tasks.size()),
|
|
|
+ null, userIds, mails));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|