|
@@ -0,0 +1,192 @@
|
|
|
+package com.platform.service.sb.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.platform.common.bean.AbstractPageResultBean;
|
|
|
+import com.platform.common.exception.BusinessException;
|
|
|
+import com.platform.common.util.BeanConverterUtil;
|
|
|
+import com.platform.common.util.DateUtils;
|
|
|
+import com.platform.common.util.IdGeneratorUtils;
|
|
|
+import com.platform.common.util.ListUtils;
|
|
|
+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.part.PartInfoDTO;
|
|
|
+import com.platform.dao.dto.sb.SbMeasureLogDTO;
|
|
|
+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.entity.part.PartInfo;
|
|
|
+import com.platform.dao.entity.sb.SbInfo;
|
|
|
+import com.platform.dao.entity.sb.SbMeasureLog;
|
|
|
+import com.platform.dao.entity.upms.SysFile;
|
|
|
+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.mapper.sb.SbInfoMapper;
|
|
|
+import com.platform.dao.mapper.sb.SbMeasureLogMapper;
|
|
|
+import com.platform.dao.mapper.upms.SysFileMapper;
|
|
|
+import com.platform.dao.vo.query.check.CheckStandardVO;
|
|
|
+import com.platform.dao.vo.query.sb.SbMeasureLogVO;
|
|
|
+import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
+import com.platform.service.check.CheckStandardParamService;
|
|
|
+import com.platform.service.check.CheckStandardService;
|
|
|
+import com.platform.service.part.PartInfoService;
|
|
|
+import com.platform.service.sb.SbMeasureLogService;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import tk.mybatis.mapper.weekend.Weekend;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description 点检标准 service 实现类
|
|
|
+ * @Author liuyu
|
|
|
+ * @Date 2020-05-28 17:23:30
|
|
|
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
|
|
|
+ */
|
|
|
+@AllArgsConstructor
|
|
|
+@Service("sbMeasureLogService")
|
|
|
+public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper, SbMeasureLog, SbMeasureLogDTO> implements SbMeasureLogService {
|
|
|
+ private SbInfoMapper sbInfoMapper;
|
|
|
+ private final SysFileMapper sysFileMapper;
|
|
|
+ @Override
|
|
|
+ public boolean cascadingDeleteByKey(String id) {
|
|
|
+ int result = mapper.deleteByPrimaryKey(id);
|
|
|
+ Weekend<CheckProjectStandardRelation> weekend = new Weekend<>(CheckProjectStandardRelation.class);
|
|
|
+ weekend.weekendCriteria().andEqualTo(CheckProjectStandardRelation::getStandardId,id);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public int batchDelete(List<String> ids) {
|
|
|
+
|
|
|
+ ids.forEach(id -> {
|
|
|
+ cascadingDeleteByKey(id);
|
|
|
+ });
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SbMeasureLogVO> selectList(SbMeasureLogDTO record) {
|
|
|
+ return mapper.selectList(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AbstractPageResultBean<SbMeasureLog> selectPageInfo(SbMeasureLogDTO record, int pageNum, int pageSize) {
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ AbstractPageResultBean<SbMeasureLog> pageInfo = new MyPage(mapper.selectList(record));
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public SbMeasureLog saveModelByDTO(SbMeasureLogDTO model) {
|
|
|
+ SbMeasureLog sbMeasureLog = super.saveModelByDTO(model);
|
|
|
+
|
|
|
+ // 更新设备下次检定日期
|
|
|
+ SbInfo sbInfo = sbInfoMapper.selectByPrimaryKey(model.getSbId());
|
|
|
+ sbInfo.setCheckDate(model.getLastDate());
|
|
|
+ Integer checkPeriod = 45;
|
|
|
+ if(sbInfo.getCheckPeriod() != null){
|
|
|
+ checkPeriod = sbInfo.getCheckPeriod();
|
|
|
+ }
|
|
|
+ sbInfo.setNextCheckDate(model.getLastDate().minusMonths(-checkPeriod));
|
|
|
+ sbInfoMapper.updateByPrimaryKey(sbInfo);
|
|
|
+
|
|
|
+ // 保存文件
|
|
|
+ this.saveFile(model);
|
|
|
+ // 保存参数
|
|
|
+ /* List<CheckStandardParamDTO> paramList = model.getParamList();
|
|
|
+ paramList.forEach(item -> {
|
|
|
+ item.setStandardId(checkStandard.getId());
|
|
|
+ });
|
|
|
+ paramService.saveModelListByDTO(paramList);*/
|
|
|
+ return sbMeasureLog;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void modModelByDTO(SbMeasureLogDTO model) {
|
|
|
+ super.modModelByDTO(model);
|
|
|
+ // 更新设备下次检定日期
|
|
|
+ SbInfo sbInfo = sbInfoMapper.selectByPrimaryKeyForUpdate(model.getSbId());
|
|
|
+ sbInfo.setCheckDate(model.getLastDate());
|
|
|
+ sbInfo.setNextCheckDate(model.getLastDate().minusDays(sbInfo.getCheckPeriod()));
|
|
|
+ sbInfoMapper.updateByPrimaryKey(sbInfo);
|
|
|
+
|
|
|
+ // 保存文件
|
|
|
+ this.saveFile(model);
|
|
|
+ // 保存参数
|
|
|
+ /* List<CheckStandardParamDTO> paramList = model.getParamList();
|
|
|
+ paramList.forEach(item -> {
|
|
|
+ item.setStandardId(model.getId());
|
|
|
+ });
|
|
|
+ paramService.saveModelListByDTO(paramList);*/
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveFile(SbMeasureLogDTO model) {
|
|
|
+ Weekend<SysFile> weekend = new Weekend<>(SysFile.class);
|
|
|
+ weekend.weekendCriteria().andEqualTo(SysFile::getTargetId, model.getId());
|
|
|
+ sysFileMapper.deleteByExample(weekend);
|
|
|
+ List<SysFile> checkImgList = model.getCheckImgList();
|
|
|
+ List<SysFile> checkFileList = model.getCheckFileList();
|
|
|
+ List<SysFile> list = ListUtils.newArrayList();
|
|
|
+ if (CollectionUtil.isNotEmpty(checkImgList)) {
|
|
|
+ checkImgList.forEach(item -> {
|
|
|
+ item.setType(SysFileTypeEnum.Sb_MEASURE_IMGS.getValue());
|
|
|
+ item.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ item.setTargetId(model.getId());
|
|
|
+ list.add(item);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isNotEmpty(checkFileList)) {
|
|
|
+ checkFileList.forEach(item -> {
|
|
|
+ item.setType(SysFileTypeEnum.Sb_MEASURE_FILES.getValue());
|
|
|
+ item.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ item.setTargetId(model.getId());
|
|
|
+ list.add(item);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
+ sysFileMapper.insertListforComplex(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SbMeasureLog getModelById(Object id) {
|
|
|
+ SbMeasureLog checkStandard = super.getModelById(id);
|
|
|
+ /* Weekend<CheckStandardParam> weekend = new Weekend<>(CheckStandardParam.class);
|
|
|
+ weekend.weekendCriteria().andEqualTo(CheckStandardParam::getStandardId, id);
|
|
|
+ List<CheckStandardParam> paramList = paramMapper.selectByExample(weekend);
|
|
|
+ checkStandard.setParamList(paramList);*/
|
|
|
+
|
|
|
+ Weekend<SysFile> weekendFile = new Weekend<>(SysFile.class);
|
|
|
+ weekendFile.weekendCriteria().andEqualTo(SysFile::getTargetId, checkStandard.getId());
|
|
|
+ List<SysFile> sysFiles = sysFileMapper.selectByExample(weekendFile);
|
|
|
+ List<SysFile> checkImgList = ListUtils.newArrayList();
|
|
|
+ List<SysFile> checkFileList = ListUtils.newArrayList();
|
|
|
+ sysFiles.forEach(item -> {
|
|
|
+ if (item.getType().equals( SysFileTypeEnum.Sb_MEASURE_IMGS.getValue())) {
|
|
|
+ checkImgList.add(item);
|
|
|
+ }
|
|
|
+ if (item.getType().equals( SysFileTypeEnum.Sb_MEASURE_FILES.getValue())) {
|
|
|
+ checkFileList.add(item);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ checkStandard.setCheckImgList(checkImgList);
|
|
|
+ checkStandard.setCheckFileList(checkFileList);
|
|
|
+ return checkStandard;
|
|
|
+ }
|
|
|
+}
|