|
@@ -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<>();
|