浏览代码

整改清单对外接口

zhuang 11 月之前
父节点
当前提交
47e8de8528

+ 3 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxApiService.java

@@ -1,5 +1,6 @@
 package com.rongwei.bscommon.sys.service;
 
+import com.rongwei.bsentity.dto.RectifyApiDataDto;
 import com.rongwei.bsentity.vo.ZhcxOutsideInspectionVo;
 import com.rongwei.rwcommon.base.R;
 
@@ -30,4 +31,6 @@ public interface ZhcxApiService {
     Map<String, Object> getProjectStaticData(String userId);
 
     void syncBsOrgData();
+
+    List<RectifyApiDataDto> getRectifyData(Map<String, Object> map);
 }

+ 3 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxProjectManageService.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.rongwei.bsentity.dto.project.ExportProjectSummaryDto;
 import com.rongwei.bsentity.dto.project.ProjectSummaryParamExcelDto;
 import com.rongwei.bsentity.dto.project.SavePorjectSummaryDto;
+import com.rongwei.bsentity.vo.ZhcxProjectRectifyMachineVo;
 import com.rongwei.rwcommon.base.R;
 import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
 
@@ -77,4 +78,6 @@ public interface ZhcxProjectManageService extends IService<ZhcxProjectManageDo>
      * @return
      */
     List<JSONObject> getWorkshop();
+
+    List<ZhcxProjectRectifyMachineVo> getListData(Map<String, Object> map);
 }

+ 215 - 7
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxApiServiceImpl.java

@@ -7,16 +7,15 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.rongwei.bscommon.sys.dao.ZhcxApiDao;
-import com.rongwei.bscommon.sys.service.BsOrganizationService;
-import com.rongwei.bscommon.sys.service.ZhcxApiService;
-import com.rongwei.bscommon.sys.service.ZhcxSubcontractorUserService;
-import com.rongwei.bscommon.sys.service.ZhcxSupervisionCustomUserManageService;
+import com.rongwei.bscommon.sys.service.*;
 import com.rongwei.bscommon.sys.utils.CxConstants;
 import com.rongwei.bscommon.sys.utils.HwSmsUtil;
 import com.rongwei.bscommon.sys.utils.SmsCodeGenerateUtils;
-import com.rongwei.bsentity.domain.BsOrganizationDo;
-import com.rongwei.bsentity.domain.ZhcxSupervisionCustomUserManageDo;
+import com.rongwei.bsentity.domain.*;
+import com.rongwei.bsentity.dto.RectifyApiDataDto;
+import com.rongwei.bsentity.dto.RectifyDto;
 import com.rongwei.bsentity.vo.ZhcxOutsideInspectionVo;
+import com.rongwei.bsentity.vo.ZhcxProjectRectifyMachineVo;
 import com.rongwei.commonservice.service.RedisService;
 import com.rongwei.commonservice.service.SysConfigService;
 import com.rongwei.rwadmincommon.system.domain.SysUserDo;
@@ -62,7 +61,10 @@ public class ZhcxApiServiceImpl implements ZhcxApiService {
     @Autowired
     private BsOrganizationService bsOrganizationService;
 
-
+    @Autowired
+    private ZhcxProjectManageService zhcxProjectManageService;
+    @Autowired
+    private ZhcxProjectRectifyMachineService zhcxProjectRectifyMachineService;
     @Autowired
     private ZhcxSubcontractorUserService subcontractorUserService;
 
@@ -373,6 +375,212 @@ public class ZhcxApiServiceImpl implements ZhcxApiService {
         }
     }
 
+    @Override
+    public List<RectifyApiDataDto> getRectifyData(Map<String, Object> map) {
+        ZhcxProjectManageDo projectManageDo = zhcxProjectManageService.getOne(
+                Wrappers.<ZhcxProjectManageDo>lambdaQuery()
+                        .eq(ZhcxProjectManageDo::getProjectCode, map.get("projectcode"))
+                        .eq(ZhcxProjectManageDo::getDeleted, "0"));
+
+        map.clear();
+        map.put("projectId", projectManageDo.getId());
+
+        List<ZhcxProjectRectifyMachineVo> list = zhcxProjectManageService.getListData(map);
+
+        // 处理一级部门数据
+        List<RectifyApiDataDto> firstDeptRectifyList = processFirstDeptData(list, projectManageDo);
+
+        // 处理施工部门数据
+        List<RectifyApiDataDto> rectifyDtoList = processSecondaryDeptData(list, projectManageDo, firstDeptRectifyList);
+
+        // 排序
+        rectifyDtoList.sort((d1, d2) -> {
+            int machineNoCompare = compareMachineNo(d1.getMachineNo(), d2.getMachineNo());
+            if (machineNoCompare != 0) {
+                return machineNoCompare;
+            }
+
+            int firstDeptCompare = Comparator.comparing(RectifyApiDataDto::getFirstdeptsort, Comparator.nullsLast(Integer::compareTo)).compare(d1, d2);
+            if (firstDeptCompare != 0) {
+                return firstDeptCompare;
+            }
+
+            int secondDeptCompare = Comparator.comparing(RectifyApiDataDto::getDeptsort, Comparator.nullsFirst(Integer::compareTo)).compare(d1, d2);
+            return secondDeptCompare != 0 ? secondDeptCompare : Comparator.comparing(RectifyApiDataDto::getOutsidedeptsort, Comparator.nullsLast(Integer::compareTo)).compare(d1, d2);
+        });
+
+        // 处理基地内合计数据
+        rectifyDtoList.addAll(processBaseData(list, true, projectManageDo));
+
+        // 处理基地外合计数据
+        rectifyDtoList.addAll(processBaseData(list, false, projectManageDo));
+
+        // 处理总合计数据
+        rectifyDtoList.addAll(processTotalData(list, projectManageDo));
+
+
+
+        return rectifyDtoList;
+    }
+
+    private List<RectifyApiDataDto> processFirstDeptData(List<ZhcxProjectRectifyMachineVo> list, ZhcxProjectManageDo projectManageDo) {
+        Map<String, List<ZhcxProjectRectifyMachineVo>> groupFirstDeptList = list.stream()
+                .filter(e -> Objects.nonNull(e.getFirstdeptid()))
+                .collect(Collectors.groupingBy(ZhcxProjectRectifyMachineVo::getFirstdeptname));
+
+        List<RectifyApiDataDto> firstDeptRectifyList = new ArrayList<>();
+
+        groupFirstDeptList.forEach((firstDeptName, rectifyList) -> {
+            Map<String, List<ZhcxProjectRectifyMachineVo>> groupMachineNoList = rectifyList.stream()
+                    .collect(Collectors.groupingBy(ZhcxProjectRectifyMachineVo::getMachineno));
+
+            groupMachineNoList.forEach((machineNo, machineList) -> {
+                RectifyApiDataDto rectifyApiDataDto = createRectifyApiDataDto(rectifyList, machineNo, projectManageDo, true);
+                rectifyApiDataDto.setPrimarySector(firstDeptName);
+                rectifyApiDataDto.setPrimarySectorId(rectifyList.get(0).getFirstdeptid());
+                rectifyApiDataDto.setSecondarySector("");
+                processRectifyData(machineList, rectifyApiDataDto);
+                firstDeptRectifyList.add(rectifyApiDataDto);
+            });
+        });
+
+        return firstDeptRectifyList;
+    }
+
+    private List<RectifyApiDataDto> processSecondaryDeptData(List<ZhcxProjectRectifyMachineVo> list, ZhcxProjectManageDo projectManageDo, List<RectifyApiDataDto> firstDeptRectifyList) {
+        Map<String, List<ZhcxProjectRectifyMachineVo>> groupDeptList = list.stream()
+                .collect(Collectors.groupingBy(ZhcxProjectRectifyMachineVo::getDeptname));
+
+        List<RectifyApiDataDto> rectifyDtoList = new ArrayList<>();
+        Set<String> processedFirstDeptIds = new HashSet<>();
+
+        groupDeptList.forEach((deptName, rectifyList) -> {
+            String firstDeptId = rectifyList.get(0).getFirstdeptid();
+            String firstdeptname = rectifyList.get(0).getFirstdeptname();
+            String deptid = rectifyList.get(0).getDeptid();
+            String deptname = rectifyList.get(0).getDeptname();
+
+            if (processedFirstDeptIds.add(firstDeptId)) {
+                rectifyDtoList.addAll(firstDeptRectifyList.stream()
+                        .filter(ev -> ev.getPrimarySectorId().equals(firstDeptId))
+                        .collect(Collectors.toList()));
+            }
+
+            Map<String, List<ZhcxProjectRectifyMachineVo>> groupMachineNoList = rectifyList.stream()
+                    .collect(Collectors.groupingBy(ZhcxProjectRectifyMachineVo::getMachineno));
+
+            groupMachineNoList.forEach((machineNo, machineList) -> {
+                RectifyApiDataDto rectifyApiDataDto = createRectifyApiDataDto(rectifyList, machineNo, projectManageDo, false);
+                rectifyApiDataDto.setPrimarySector(StringUtils.isNotBlank(firstdeptname) ? firstdeptname : "");
+                rectifyApiDataDto.setPrimarySectorId(StringUtils.isNotBlank(firstDeptId) ? firstDeptId : "");
+                rectifyApiDataDto.setSecondarySector(StringUtils.isNotBlank(deptname) ? deptname : "");
+                rectifyApiDataDto.setSecondarySectorId(StringUtils.isNotBlank(deptid) ? deptid : "");
+                processRectifyData(machineList, rectifyApiDataDto);
+                rectifyDtoList.add(rectifyApiDataDto);
+            });
+        });
+
+        return rectifyDtoList;
+    }
+
+    private List<RectifyApiDataDto> processBaseData(List<ZhcxProjectRectifyMachineVo> list, boolean isBaseIn, ZhcxProjectManageDo projectManageDo) {
+        List<String> deptIds = Arrays.asList("b0bd3ed27bfb4af08535c39f464b3d3a", "55c58ffb9d9b486abdd0dcb073f9b451");
+
+        List<ZhcxProjectRectifyMachineVo> collect = list.stream()
+                .filter(e -> (isBaseIn && (deptIds.contains(e.getDeptid()) || Objects.nonNull(e.getFirstdeptid())))
+                        || (!isBaseIn && Objects.isNull(e.getFirstdeptid()) && !deptIds.contains(e.getDeptid())))
+                .collect(Collectors.toList());
+
+        Map<String, List<ZhcxProjectRectifyMachineVo>> baseList = collect.stream()
+                .collect(Collectors.groupingBy(ZhcxProjectRectifyMachineVo::getMachineno));
+
+        List<RectifyApiDataDto> rectifyDtoList = new ArrayList<>();
+        baseList.forEach((machineNo, machineList) -> {
+            RectifyApiDataDto rectifyApiDataDto = new RectifyApiDataDto();
+            rectifyApiDataDto.setProjectCode(projectManageDo.getProjectCode());
+            rectifyApiDataDto.setProjectName(projectManageDo.getProjectName());
+            rectifyApiDataDto.setBase(isBaseIn ? "基地内合计" : "基地外合计");
+            rectifyApiDataDto.setSecondarySector(isBaseIn ? "基地内合计" : "基地外合计");
+            rectifyApiDataDto.setPrimarySector("");
+            rectifyApiDataDto.setMachineNo(machineNo);
+            processRectifyData(machineList, rectifyApiDataDto);
+            rectifyDtoList.add(rectifyApiDataDto);
+        });
+
+        return rectifyDtoList;
+    }
+
+    private List<RectifyApiDataDto> processTotalData(List<ZhcxProjectRectifyMachineVo> list, ZhcxProjectManageDo projectManageDo) {
+        Map<String, List<ZhcxProjectRectifyMachineVo>> allBaseList = list.stream()
+                .collect(Collectors.groupingBy(ZhcxProjectRectifyMachineVo::getMachineno));
+
+        List<RectifyApiDataDto> rectifyDtoList = new ArrayList<>();
+        allBaseList.forEach((machineNo, machineList) -> {
+            RectifyApiDataDto rectifyApiDataDto = new RectifyApiDataDto();
+            rectifyApiDataDto.setProjectCode(projectManageDo.getProjectCode());
+            rectifyApiDataDto.setProjectName(projectManageDo.getProjectName());
+            rectifyApiDataDto.setBase("总合计");
+            rectifyApiDataDto.setSecondarySector("总合计");
+            rectifyApiDataDto.setPrimarySector("");
+            rectifyApiDataDto.setMachineNo(machineNo);
+            processRectifyData(machineList, rectifyApiDataDto);
+            rectifyDtoList.add(rectifyApiDataDto);
+        });
+
+        return rectifyDtoList;
+    }
+
+    private RectifyApiDataDto createRectifyApiDataDto(List<ZhcxProjectRectifyMachineVo> rectifyList, String machineNo, ZhcxProjectManageDo projectManageDo, boolean isFirstDept) {
+        RectifyApiDataDto rectifyApiDataDto = new RectifyApiDataDto();
+        rectifyApiDataDto.setProjectCode(projectManageDo.getProjectCode());
+        rectifyApiDataDto.setProjectName(projectManageDo.getProjectName());
+        rectifyApiDataDto.setMachineNo(machineNo);
+        if (isFirstDept) {
+            rectifyApiDataDto.setFirstdeptsort(Optional.ofNullable(rectifyList.get(0).getFirstdeptsort()).orElse(null));
+            if (Objects.nonNull(rectifyList.get(0).getFirstdeptid())) {
+                rectifyApiDataDto.setBase("长兴分公司");
+            }
+        } else {
+            rectifyApiDataDto.setFirstdeptsort(Optional.ofNullable(rectifyList.get(0).getFirstdeptsort()).orElse(null));
+            rectifyApiDataDto.setDeptsort(Optional.ofNullable(rectifyList.get(0).getDeptsort()).orElse(null));
+            if (Objects.nonNull(rectifyList.get(0).getFirstdeptid())) {
+                rectifyApiDataDto.setBase("长兴分公司");
+            }else{
+                rectifyApiDataDto.setBase(rectifyList.get(0).getDeptname());
+                rectifyApiDataDto.setPrimarySector("");
+            }
+        }
+        return rectifyApiDataDto;
+    }
+
+    private void processRectifyData(List<ZhcxProjectRectifyMachineVo> machineList, RectifyApiDataDto rectifyApiDataDto) {
+        List<ZhcxProjectRectifyMachineVo> distinctEntities = machineList.stream()
+                .collect(Collectors.toMap(
+                        e -> Arrays.asList(e.getRectifyid()),
+                        e -> e,
+                        (e1, e2) -> e1))
+                .values()
+                .stream()
+                .collect(Collectors.toList());
+
+        Map<String, Long> statusCount = distinctEntities.stream()
+                .collect(Collectors.groupingBy(e -> e.getStatus().trim().toLowerCase(), Collectors.counting()));
+
+        rectifyApiDataDto.setRectifyTotal(distinctEntities.size());
+        rectifyApiDataDto.setUnfinishedCount(statusCount.getOrDefault("x", 0L).intValue());
+        rectifyApiDataDto.setTbcCount(statusCount.getOrDefault("√", 0L).intValue());
+        rectifyApiDataDto.setCloseCount(statusCount.getOrDefault("ok", 0L).intValue());
+    }
+
+    private int compareMachineNo(String machineNo1, String machineNo2) {
+        String cleanedMachineNo1 = machineNo1.replace("#", "");
+        String cleanedMachineNo2 = machineNo2.replace("#", "");
+        return Integer.compare(
+                Integer.parseInt(cleanedMachineNo1),
+                Integer.parseInt(cleanedMachineNo2)
+        );
+    }
+
     private R sendSmsCode(String templateId, String redisKeyName, String mobile, String redisLabelName) {
         boolean exists = redisService.hasKey(redisKeyName);
         List<String> list = new ArrayList<>();

+ 2 - 1
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxProjectManageServiceImpl.java

@@ -338,7 +338,8 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
         return R.ok(rectifyReportDto);
     }
 
-    private List<ZhcxProjectRectifyMachineVo> getListData(Map<String, Object> map) {
+    @Override
+    public List<ZhcxProjectRectifyMachineVo> getListData(Map<String, Object> map) {
         return zhcxProjectManageDao.getListData(map);
     }
 

+ 79 - 0
business-entity/src/main/java/com/rongwei/bsentity/dto/RectifyApiDataDto.java

@@ -0,0 +1,79 @@
+package com.rongwei.bsentity.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.*;
+
+/**
+ * 整改接口数据
+ */
+@Data
+public class RectifyApiDataDto {
+    /**
+     * 项目工号
+     */
+    @ApiModelProperty("项目工号")
+    private String projectCode;
+    /**
+     * 项目名称
+     */
+    @ApiModelProperty("项目名称")
+    private String projectName;
+    /**
+     * 基地
+     */
+    @ApiModelProperty("基地")
+    private String base;
+    /**
+     * 一级部门
+     */
+    @ApiModelProperty("一级部门")
+    private String primarySector;
+    /**
+     * 一级部门id
+     */
+    @JsonIgnore
+    private String primarySectorId;
+    /**
+     * 二级部门
+     */
+    @ApiModelProperty("二级部门")
+    private String secondarySector;
+    /**
+     * 二级部门id
+     */
+    @JsonIgnore
+    private String secondarySectorId;
+    /**
+     * 机号
+     */
+    @ApiModelProperty("机号")
+    private String machineNo;
+    /**
+     * 整改总数
+     */
+    @ApiModelProperty("整改总数")
+    private Integer rectifyTotal;
+    /**
+     * 关闭数
+     */
+    @ApiModelProperty("关闭数")
+    private Integer closeCount;
+    /**
+     * 未完成数
+     */
+    @ApiModelProperty("未完成数")
+    private Integer unfinishedCount;
+    /**
+     * 待确认数
+     */
+    @ApiModelProperty("待确认数")
+    private Integer tbcCount;
+
+    @JsonIgnore
+    private Integer deptsort;
+    @JsonIgnore
+    private Integer firstdeptsort;
+    @JsonIgnore
+    private Integer outsidedeptsort;
+}

+ 15 - 0
business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxApiController.java

@@ -6,6 +6,7 @@ import com.rongwei.bscommon.sys.service.DmTableService;
 import com.rongwei.bscommon.sys.service.ZhcxApiService;
 import com.rongwei.bscommon.sys.utils.HwSmsUtil;
 import com.rongwei.bscommon.sys.utils.ZhcxCommon;
+import com.rongwei.bsentity.dto.RectifyApiDataDto;
 import com.rongwei.bsentity.vo.ZhcxOutsideInspectionVo;
 import com.rongwei.rwadmincommon.system.vo.SysUserVo;
 import com.rongwei.rwcommon.base.R;
@@ -152,4 +153,18 @@ public class ZhcxApiController {
         log.info("删除完成");
         zhcxApiService.syncBsOrgData();
     }
+
+    @PostMapping("/getRectifyData")
+    @ApiOperation("根据项目,机号查看整改数据")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "projectcode", required = true,value = "项目工号", dataType = "string"),
+            @ApiImplicitParam(name = "machineno",required = false, value = "机号", dataType = "string")
+    })
+    public R getRectifyData(@RequestBody Map<String,Object> map){
+        if(!map.containsKey("projectcode")){
+            return R.error("projectcode参数必填");
+        }
+        List<RectifyApiDataDto> list = zhcxApiService.getRectifyData(map);
+        return R.ok(list);
+    }
 }