shenyijian
2024-08-30 44d30cbd79df473dbdf6d28decde2bbc931c0821
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sg/service/impl/SgProjectInfoServiceImpl.java
@@ -10,23 +10,18 @@
import cn.gistack.sm.sg.service.SgProjectInfoService;
import cn.gistack.sm.sjztmd.entity.AttAdBase;
import cn.gistack.sm.sjztmd.service.IAttAdBaseService;
import cn.hutool.core.lang.copier.Copier;
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.service.impl.ServiceImpl;
import org.jetbrains.annotations.NotNull;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StopWatch;
import javax.security.auth.login.LoginContext;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.*;
import java.util.function.Function;
@@ -54,18 +49,86 @@
   private SgGxStepMapper sgGxStepMapper;
   @Override
   public IPage<SgProjectInfoDO> queryPageList(IPage<SgProjectInfoDO> page, ProjectSearchDTO searchDTO) {
   public Object queryPageList(IPage<SgProjectInfoDO> page, ProjectSearchDTO searchDTO) {
      List<String> sgCodeS = getSgCodeByUser();
      searchDTO.setSgCodeS(sgCodeS);
      List<SgProjectInfoDO> sgProjectInfoDOS = baseMapper.queryPageList(page,searchDTO);
      List<SgProjectInfoDO> projectProgress = getProjectProgress(sgProjectInfoMapper.queryStepByProject(searchDTO));
      if (CollectionUtils.isNotEmpty(projectProgress)){
         Map<Long, String> progressMap = projectProgress.stream().filter(s->s.getProjectProgress()!=null).collect(Collectors.toMap(SgProjectInfoDO::getId, SgProjectInfoDO::getProjectProgress));
      Boolean isPage = searchDTO.getIsPage();
      if (isPage==null) isPage = true;
      if (isPage ){
         List<SgProjectInfoDO> sgProjectInfoDOS = baseMapper.queryPageList(page,searchDTO);
         List<SgProjectInfoDO> projectProgress = getProjectProgress(sgProjectInfoMapper.queryStepByProject(searchDTO));
         if (CollectionUtils.isNotEmpty(projectProgress)){
            Map<Long, String> progressMap = projectProgress.stream().filter(s->s.getProjectProgress()!=null).collect(Collectors.toMap(SgProjectInfoDO::getId, SgProjectInfoDO::getProjectProgress));
            sgProjectInfoDOS.forEach(s->{
               s.setProjectProgress(progressMap.get(s.getId()));
            });
         }
         return page.setRecords(sgProjectInfoDOS);
      }else {
         List<SgAllDeptOrUser> allDepts = sgProjectInfoMapper.queryDept();
         Map<Long, String> deptMap = allDepts.stream().collect(Collectors.toMap(SgAllDeptOrUser::getId, SgAllDeptOrUser::getName));
         List<SgAllDeptOrUser> allUser = sgProjectInfoMapper.queryUser();
         Map<Long, String> userMap = allUser.stream().collect(Collectors.toMap(SgAllDeptOrUser::getId, SgAllDeptOrUser::getName));
         List<SgProjectInfoDO> sgProjectInfoDOS = baseMapper.queryPageList(null,searchDTO);
         List<SgProjectInfoDO> projectProgress = getProjectProgress(sgProjectInfoMapper.queryStepByProject(searchDTO));
         if (CollectionUtils.isNotEmpty(projectProgress)){
            Map<Long, String> progressMap = projectProgress.stream().filter(s->s.getProjectProgress()!=null).collect(Collectors.toMap(SgProjectInfoDO::getId, SgProjectInfoDO::getProjectProgress));
            sgProjectInfoDOS.forEach(s->{
               s.setProjectProgress(progressMap.get(s.getId()));
            });
         }
         sgProjectInfoDOS.forEach(s->{
            s.setProjectProgress(progressMap.get(s.getId()));
            //土建
            if (StringUtils.isNotBlank(s.getConstructionUnit())){
               s.setConstructionUnit(deptMap.get(Long.valueOf(s.getConstructionUnit())));
            }
            s.setConstructionPerson(getUserNames(userMap, s.getConstructionPerson()));
            //设备
            if (StringUtils.isNotBlank(s.getSelfUnit())){
               s.setSelfUnit(deptMap.get(Long.valueOf(s.getSelfUnit())));
            }
            s.setSelfPerson(getUserNames(userMap, s.getSelfPerson()));
            //设计
            if (StringUtils.isNotBlank(s.getDesignUnit())){
               s.setDesignUnit(deptMap.get(Long.valueOf(s.getDesignUnit())));
            }
            s.setDesignPerson(getUserNames(userMap, s.getDesignPerson()));
            //监理
            if (StringUtils.isNotBlank(s.getControlUnit())){
               s.setControlUnit(deptMap.get(Long.valueOf(s.getControlUnit())));
            }
            s.setControlPerson(getUserNames(userMap, s.getControlPerson()));
            //检测
            if (StringUtils.isNotBlank(s.getAcceptanceUnit())){
               s.setAcceptanceUnit(deptMap.get(Long.valueOf(s.getAcceptanceUnit())));
            }
            s.setAcceptancePerson(getUserNames(userMap, s.getAcceptancePerson()));
         });
         return sgProjectInfoDOS;
      }
      return page.setRecords(sgProjectInfoDOS);
   }
   /**
    * 获取用户姓名
    * @param userMap
    * @return
    */
   private  String getUserNames(Map<Long, String> userMap,String person ) {
      String userNames = "";
      if (StringUtils.isNotBlank(person)){
         // 使用Stream API来处理分割和映射
          userNames = Arrays.stream(person.split(",")) // 将字符串按逗号分割成数组,并转为Stream
            .map(Long::valueOf) // 将每个字符串元素转换为Long
            .map(userMap::get) // 使用userMap将Long映射为对应的用户名
            .collect(Collectors.joining(",")); // 使用逗号将用户名拼接成一个字符串
         return userNames;
      }
      return userNames;
   }
   /**
@@ -251,6 +314,8 @@
   @Override
   public List<SgProjectInfoDO> listAll(ProjectSearchDTO searchDTO) {
      List<String> sgCodeS = getSgCodeByUser();
      searchDTO.setSgCodeS(sgCodeS);
      return sgProjectInfoMapper.queryPageList(null,searchDTO);
   }
@@ -280,8 +345,6 @@
   public List<SgStatisProVO> getsgStatisticsList(String code) {
      AttAdBase ywxtAdDetail = iAttAdBaseService.getYwxtAdDetail(code);
      List<SgStatisProVO> sgStatisProVOS;
      //片区
      if (ywxtAdDetail == null) {
         sgStatisProVOS = sgProjectInfoMapper.getsgStatisticsZero(code);
@@ -291,6 +354,7 @@
         updateProjectProgress(sgStatisProVOS, code, getname, "2");
      } else if (ywxtAdDetail.getAdGrad().equals("1")) {//默认
         sgStatisProVOS = sgProjectInfoMapper.getsgStatisticsOne(code);
         sgStatisProVOS = getSgStatisProVOS(sgStatisProVOS);
         getDeviceTypes(sgStatisProVOS);
         updateProjectProgress(sgStatisProVOS, ywxtAdDetail.getPAdCode(), ywxtAdDetail.getPAdName(), "0");
      } else {//区县
@@ -298,6 +362,33 @@
         getDeviceTypes(sgStatisProVOS);
         updateProjectProgress(sgStatisProVOS, ywxtAdDetail.getAdCode(), ywxtAdDetail.getAdName(), "3");
      }
      return sgStatisProVOS;
   }
   /**
    * 标段排序
    * @param sgStatisProVOS
    * @return
    */
   private  List<SgStatisProVO> getSgStatisProVOS(List<SgStatisProVO> sgStatisProVOS) {
      sgStatisProVOS = sgStatisProVOS.stream()
         .sorted(Comparator.comparing(s -> {
            String scode = s.getCode();
            if (scode.equals("第一标段")) {
               return 1;
            } else if (scode.equals("第二标段")) {
               return 2;
            } else if (scode.equals("第三标段")) {
               return 3;
            } else if (scode.equals("第四标段")) {
               return 4;
            } else if (scode.equals("第五标段")) {
               return 5;
            } else {
               return Integer.MAX_VALUE;
            }
         }))
         .collect(Collectors.toList());
      return sgStatisProVOS;
   }
@@ -490,10 +581,16 @@
   private  PreAcceVO handleQuery( int stepIdForNull, Long programId) {
      QueryWrapper<SgProgressReportDO> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("gx_step_id", stepIdForNull)
         .ne("status",3)
         .eq("profram_id", programId);
      SgProgressReportDO sgProgressReportDO = sgProgressReportMapper.selectOne(queryWrapper);
      SgProgressReportDO sgProgressReportDO = null;
      List<SgProgressReportDO> sgProgressReportDOS = sgProgressReportMapper.selectList(queryWrapper);
      if (CollectionUtils.isNotEmpty(sgProgressReportDOS)) {
         List<SgProgressReportDO> collect = sgProgressReportDOS.stream().filter(s -> s.getStatus() == null || (s.getStatus() != 4 && !(s.getStatus() == 3 && s.getResubmit() != 0))).collect(Collectors.toList());
        if (!collect.isEmpty()){
           sgProgressReportDO = collect.get(0);
        }
      }
      PreAcceVO preAcceVO = new PreAcceVO();
      if (sgProgressReportDO!= null) {
         preAcceVO.setId(sgProgressReportDO.getId().toString());
@@ -514,4 +611,69 @@
   }
   @Override
   public List<SgProjectTreeVO> projectTree(ProjectSearchDTO dto) {
      List<SgProjectTreeVO> list =    sgProjectInfoMapper.projectTree(dto);
      if (CollectionUtils.isNotEmpty(list)){
      // 按省、市、县分组
      Map<String, Map<String, Map<String, List<SgProjectTreeVO>>>> groupedProjects = list.stream()
         .collect(Collectors.groupingBy(SgProjectTreeVO::getProvinceNm,
            Collectors.groupingBy(SgProjectTreeVO::getCityNm,
               Collectors.groupingBy(SgProjectTreeVO::getCountyNm))));
      // 构建树结构
      List<SgProjectTreeVO> result = new ArrayList<>();
      for (Map.Entry<String, Map<String, Map<String, List<SgProjectTreeVO>>>> provinceEntry : groupedProjects.entrySet()) {
         String province = provinceEntry.getKey();
         Map<String, Map<String, List<SgProjectTreeVO>>> cityMap = provinceEntry.getValue();
         SgProjectTreeVO provinceNode = new SgProjectTreeVO();
         provinceNode.setProvinceNm(province);
         provinceNode.setId(UUID.randomUUID().toString().replace("-",""));
         provinceNode.setRegionName(province);
         provinceNode.setChildList(new ArrayList<>());
         long provinceNum = 0;
         for (Map.Entry<String, Map<String, List<SgProjectTreeVO>>> cityEntry : cityMap.entrySet()) {
            String city = cityEntry.getKey();
            Map<String, List<SgProjectTreeVO>> countyMap = cityEntry.getValue();
            SgProjectTreeVO cityNode = new SgProjectTreeVO();
            List<String> cityIds = new ArrayList<>();
            cityNode.setCityNm(city);
            cityNode.setId(UUID.randomUUID().toString().replace("-",""));
            cityNode.setRegionName(city);
            cityNode.setChildList(new ArrayList<>());
            for (Map.Entry<String, List<SgProjectTreeVO>> countyEntry : countyMap.entrySet()) {
               String county = countyEntry.getKey();
               List<SgProjectTreeVO> countyProjects = countyEntry.getValue();
               for (SgProjectTreeVO countyProject : countyProjects) {
                  countyProject.setRegionName(countyProject.getResNm());
               }
               SgProjectTreeVO countyNode = new SgProjectTreeVO();
               countyNode.setCountyNm(county);
               countyNode.setRegionName(county);
               countyNode.setId(UUID.randomUUID().toString().replace("-",""));
               countyNode.setChildList(new ArrayList<>(countyProjects));
               countyNode.setChildNum((long) countyProjects.size());
               countyNode.setProjectIds(countyProjects.stream().map(SgProjectTreeVO::getId).collect(Collectors.toList()));
               cityIds.addAll(countyNode.getProjectIds());
               cityNode.getChildList().add(countyNode);
            }
            cityNode.setChildNum((long) cityIds.size());
            cityNode.setProjectIds(cityIds);
            provinceNode.getChildList().add(cityNode);
            provinceNum+= (long) cityIds.size();
         }
         provinceNode.setChildNum(provinceNum);
         result.add(provinceNode);
      }
      return result;
      }
      return new ArrayList<>();
   }
}