shenyijian
2024-06-21 f20611265f7d34fd4fbcdfdaff6cb9cccd0b25fc
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sg/service/impl/SgProgressReportServiceImpl.java
@@ -10,6 +10,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -69,6 +70,7 @@
   public void add(SgProgressReportDO sgProgressReportDO) {
      Date now = DateUtil.now();
      sgProgressReportDO.setReportTime(now);
      sgProgressReportDO.setCreateTime(now);
      Long gxDeviceId = sgProgressReportDO.getGxDeviceId();
      Long gxStepId = sgProgressReportDO.getGxStepId();
      List<SgGxStepDO> list = sgGxStepMapper.selectByGxInfoId(gxDeviceId);
@@ -84,7 +86,7 @@
            QueryWrapper<SgProgressReportDO> wrapper1 = new QueryWrapper<>();
            wrapper1.eq("gx_step_id", gxStepDO.getId());
            SgProgressReportDO one = sgProgressReportMapper.selectOne(wrapper1);
            if (one != null && one.getStatus() != 2) {
            if (one == null || one.getStatus() != 2) {
               throw new ServiceException("请先完成" + gxStepDO.getGxStepName() + "的审批!");
            }
         }
@@ -235,20 +237,20 @@
                  List<SgDeviceGxStepDO> sgDeviceGxStepDOs = sgGxStepMapper.getDeviceGXList(sgDeviceDO.getId());
                  if (sgDeviceGxStepDOs != null) {
                     int countStatus = 0;
                     for (SgDeviceGxStepDO sgDeviceGxStepDO : sgDeviceGxStepDOs) {
                        countStatus = +sgDeviceGxStepDO.getStatus();
                     }
                     int size = sgDeviceGxStepDOs.size();
                     if (countStatus != 0 && (size * 2) / countStatus == 1) {
//                     int countStatus = 0;
//                     for (SgDeviceGxStepDO sgDeviceGxStepDO : sgDeviceGxStepDOs) {
//                        countStatus = +sgDeviceGxStepDO.getStatus();
//
//                     }
//                     int size = sgDeviceGxStepDOs.size(); //4
                     boolean allStatusesAreTwo = sgDeviceGxStepDOs.stream()
                        .allMatch(s -> s.getStatus() == 2);
                        if (allStatusesAreTwo) {
                        //如果设备下全部工序审核完成
                        sgDeviceDO.setStatus(2);
                        sgDeviceMapper.updateById(sgDeviceDO);
                        deviceFinishCount++;
                     }
                        }
                  }
               }
               if (deviceFinishCount == sgDeviceDOS.size()) {
@@ -280,7 +282,9 @@
   public Map<String, Long> countList(ProjectSearchDTO searchDTO) {
      Long userId = AuthUtil.getUserId();
      searchDTO.setUserId(userId);
      searchDTO.setApprovalStatus(0);
      Long pending = sgProgressReportMapper.countList(searchDTO);
      searchDTO.setApprovalStatus(1);
      Long over = sgProgressReportMapper.countList(searchDTO);
      Map<String, Long> map = new HashMap<>();
      map.put("pending",pending);
@@ -303,6 +307,52 @@
      map.put("reject", (long) reject.size());
      return map;
   }
   @Override
   public boolean checkStep(Long gxDeviceId, Long gxStepId) {
      List<SgGxStepDO> list = sgGxStepMapper.selectByGxInfoId(gxDeviceId);
      SgGxStepDO sgGxStepDO = sgGxStepMapper.selectById(gxStepId);
      QueryWrapper<SgProgressReportDO> wrapper = new QueryWrapper<>();
      wrapper.eq("gx_step_id", gxStepId).eq("gx_device_id",gxDeviceId);
      List<SgProgressReportDO> sgProgressReportDOS = sgProgressReportMapper.selectList(wrapper);
      if ( sgProgressReportDOS!=null && sgProgressReportDOS.size()>0){
         return false;
      }
      for (SgGxStepDO gxStepDO : list) {
         if (Integer.parseInt(sgGxStepDO.getGxStepNum()) - Integer.parseInt(gxStepDO.getGxStepNum()) == 1) {
            QueryWrapper<SgProgressReportDO> wrapper1 = new QueryWrapper<>();
            wrapper1.eq("gx_step_id", gxStepDO.getId());
            SgProgressReportDO one = sgProgressReportMapper.selectOne(wrapper1);
            if (one == null || one.getStatus() != 2) {
               return false;
            }
         }
      }
      return true;
   }
   @Override
   public IPage<SgProgressReportVO> progressPage(IPage<SgProgressReportVO> page, ProjectSearchDTO searchDTO) {
      Long userId = AuthUtil.getUserId();
      searchDTO.setUserId(userId);
      List<SgProgressReportVO> list = sgProgressReportMapper.queryList(page, searchDTO);
      return page.setRecords(list);
   }
   @Override
   public String getDeviceReport(Long gxDeviceId, Long gxStepId) {
      QueryWrapper<SgProgressReportDO> wrapper = new QueryWrapper<>();
      wrapper.eq("gx_device_id",gxDeviceId);
      if (gxStepId!=null){
         wrapper.eq("gx_step_id",gxStepId);
      }
      List<SgProgressReportDO> sgProgressReportDOS = sgProgressReportMapper.selectList(wrapper);
      if (CollectionUtils.isNotEmpty(sgProgressReportDOS)){
         sgProgressReportDOS.sort((u1, u2) -> u2.getCreateTime().compareTo(u1.getCreateTime()));
      return sgProgressReportDOS.get(0).getId().toString();
      }
      return null;
   }
}