yxm
2024-07-15 eb0760c36778d07c0d13d917c0db30dfa03aa0fd
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sg/service/impl/SgProgressReportServiceImpl.java
@@ -4,6 +4,7 @@
import cn.gistack.sm.sg.DTO.ApprovalDTO;
import cn.gistack.sm.sg.DTO.ProjectSearchDTO;
import cn.gistack.sm.sg.VO.SgProgressReportVO;
import cn.gistack.sm.sg.VO.SgReportVO;
import cn.gistack.sm.sg.VO.SgStepReportVO;
import cn.gistack.sm.sg.mapper.*;
import cn.gistack.sm.sg.service.SgProgressReportService;
@@ -83,6 +84,19 @@
      if(sgProgressReportDO.getStatus()==4){
         sgProgressReportMapper.insert(sgProgressReportDO);
         return;
      }
      QueryWrapper<SgProgressReportDO> wrappers = new QueryWrapper<>();
      wrappers.eq("profram_id", sgProgressReportDO.getProframId()).ne("status", 4).eq("gx_step_name", "施工准备");
      List<SgProgressReportDO> sgProgressReportDOS1 = sgProgressReportMapper.selectList(wrappers);
      if (sgProgressReportDOS1!= null && sgProgressReportDOS1.size() > 0) {
         for (SgProgressReportDO sgProgressReportDO1 : sgProgressReportDOS1) {
            if (sgProgressReportDO1.getStatus()!= 2) {
               throw new ServiceException("请先完成施工准备的审批!");
            }
         }
      } else if (sgProgressReportDOS1 == null || (!sgProgressReportDO.getGxStepName().equals("施工准备"))) {
         throw new ServiceException("请先发起施工准备的审批!");
      }
      Long gxDeviceId = sgProgressReportDO.getGxDeviceId();
      Long gxStepId = sgProgressReportDO.getGxStepId();
@@ -412,6 +426,72 @@
      }
      return null;
   }
   @Override
   public SgReportVO getDeviceReportcopy(Long deviceId, Long stepId) {
      SgReportVO sgReportVO = new SgReportVO();
      QueryWrapper<SgProgressReportDO> wrapper = new QueryWrapper<>();
      wrapper.eq("gx_device_id", deviceId).ne("status", 4);
      if (stepId!= null) {
         wrapper.eq("gx_step_id", stepId);
      }
      List<SgProgressReportDO> sgProgressReportDOS = sgProgressReportMapper.selectList(wrapper);
      // 先检查列表是否为空,进行后续操作
      if (CollectionUtils.isNotEmpty(sgProgressReportDOS)) {
         sgProgressReportDOS.sort((u1, u2) -> u2.getCreateTime().compareTo(u1.getCreateTime()));
         SgProgressReportDO firstReport = sgProgressReportDOS.get(0);
            sgReportVO.setGxDeviceId(deviceId);
            sgReportVO.setGxStepId(firstReport.getGxStepId());
            sgReportVO.setId(firstReport.getId());
            sgReportVO.setProframId(firstReport.getProframId());
      } else {
         QueryWrapper<SgProgressReportDO> wrappers = new QueryWrapper<>();
         wrappers.eq("gx_device_id", deviceId).ne("status", 4).orderByDesc("create_time");
         sgProgressReportDOS = sgProgressReportMapper.selectList(wrappers);
         QueryWrapper<SgGxStepDO> wrapperss = new QueryWrapper<>();
         if (CollectionUtils.isNotEmpty(sgProgressReportDOS)) {
            sgProgressReportDOS.sort((u1, u2) -> u2.getCreateTime().compareTo(u1.getCreateTime()));
            SgProgressReportDO firstReport = sgProgressReportDOS.get(0);
            SgGxStepDO sgGxStepDO = sgGxStepMapper.selectOne(wrapperss.eq("id", stepId));
            List<SgGxStepDO> sgGxStepDOS = sgGxStepMapper.selectList(
               new QueryWrapper<SgGxStepDO>()
                  .lt("id", stepId)
                  .eq("gx_info_id", sgGxStepDO.getGxInfoId())
                  .orderByDesc("gx_step_num"));
            if (!sgGxStepDOS.isEmpty()) {
               if (sgGxStepDOS.get(0).getGxStepName().equals(firstReport.getGxStepName())&&firstReport.getStatus().equals(2)) {
                  sgReportVO.setGxDeviceId(deviceId);
                  sgReportVO.setGxStepId(sgGxStepDO.getId());
                  sgReportVO.setProframId(firstReport.getProframId());
               }else {
                  throw new ServiceException("请完成上一步工序!");
               }
            }
         }else {
            if (stepId!=null) {
               SgGxStepDO sg = sgGxStepMapper.selectOne(wrapperss.eq("id", stepId));
               if (sg.getGxStepNum().equals("01")) {
                  sgReportVO.setGxDeviceId(deviceId);
                  sgReportVO.setGxStepId(sg.getId());
                  sgReportVO.setProframId(sgProgressReportMapper.selectProframId(deviceId));
               }
               throw new ServiceException("第一工序未进行审批!");
            }
            sgReportVO.setProframId(sgProgressReportMapper.selectProframId(deviceId));
            sgReportVO.setGxStepId(sgGxStepMapper.queryStepList(deviceId.toString()).get(0).getId());
            sgReportVO.setGxDeviceId(deviceId);
         }
      }
      return sgReportVO;
   }
}