From a4b8b53d4b59a5f9e5c4d19e5f4db7829b81e07d Mon Sep 17 00:00:00 2001
From: shenyijian <1178253012@qq.com>
Date: Wed, 21 Aug 2024 18:46:08 +0800
Subject: [PATCH] 湖北水库:项目审批流程图多加一级

---
 skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sg/service/impl/SgProjectInfoServiceImpl.java |  113 +++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 66 insertions(+), 47 deletions(-)

diff --git a/skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sg/service/impl/SgProjectInfoServiceImpl.java b/skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sg/service/impl/SgProjectInfoServiceImpl.java
index 626a6dd..8b43a80 100644
--- a/skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sg/service/impl/SgProjectInfoServiceImpl.java
+++ b/skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sg/service/impl/SgProjectInfoServiceImpl.java
@@ -54,13 +54,13 @@
 	@Override
 	public IPage<SgProjectInfoDO> queryPageList(IPage<SgProjectInfoDO> page, ProjectSearchDTO searchDTO) {
 		List<SgProjectInfoDO> sgProjectInfoDOS = baseMapper.queryPageList(page,searchDTO);
-		List<SgProjectInfoDO> projectProgress = getProjectProgress(sgProjectInfoMapper.queryStepByProject(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);
 	}
 
@@ -90,7 +90,7 @@
 	 * @return
 	 */
 	@NotNull
-	private List<SgProjectInfoDO> getProjectProgress(List<SgProjectInfoVO> list) {
+	public List<SgProjectInfoDO> getProjectProgress(List<SgProjectInfoVO> list) {
 		//项目分组
 		Map<Long, List<SgProjectInfoVO>> projectMap = list.stream().collect(Collectors.groupingBy(SgProjectInfoVO::getId));
 		List<SgProjectInfoDO> result = new ArrayList<>();
@@ -103,54 +103,72 @@
 			}
 			SgProjectInfoVO sgProjectInfoVO = value.get(0);
 			SgProjectInfoDO sgProjectInfoDO = SgProjectInfoDO.builder().id(porId).lonLat(sgProjectInfoVO.getLonLat()).status(sgProjectInfoVO.getProjectStatus()).projectName(sgProjectInfoVO.getProjectName()).build();
-			List<SgTypeVO> sgGxDOS = new ArrayList<>();
-			//类型分组
-			Map<String, List<SgProjectInfoVO>> GxMap = value.stream().filter(s->s.getDeviceType()!=null).collect(Collectors.groupingBy(SgProjectInfoVO::getDeviceType));
-			for (Map.Entry<String, List<SgProjectInfoVO>> ty : GxMap.entrySet()) {
-				String type = ty.getKey();
-				List<SgProjectInfoVO> gxList = ty.getValue();
-				if (CollectionUtils.isEmpty(gxList)){
+			//父类型分组
+			List<PtypeVO> pTypes = new ArrayList();
+			Map<String, List<SgProjectInfoVO>> pTypeMap = value.stream().filter(s->s.getPtype()!=null).collect(Collectors.groupingBy(SgProjectInfoVO::getPtype));
+			for (Map.Entry<String, List<SgProjectInfoVO>> pty : pTypeMap.entrySet()) {
+				List<SgProjectInfoVO> ptyValue = pty.getValue();
+				if (CollectionUtils.isEmpty(ptyValue)){
 					continue;
 				}
-				SgTypeVO typeVO = SgTypeVO.builder().typeName(gxList.get(0).getTypeName()).build();
-				List<SgDeviceDO> deviceDOS = new ArrayList<>();
-				//设备分组
-				Map<Long, List<SgProjectInfoVO>> dMap = gxList.stream().collect(Collectors.groupingBy(SgProjectInfoVO::getDId));
-				for (Map.Entry<Long, List<SgProjectInfoVO>> device : dMap.entrySet()) {
-					Long dId = device.getKey();
-					List<SgProjectInfoVO> deList = device.getValue();
-					SgDeviceDO sgDeviceDO = new SgDeviceDO();
-					sgDeviceDO.setId(dId);
-					sgDeviceDO.setDeviceName(deList.get(0).getDeviceName());
-					sgDeviceDO.setStatus(	deList.get(0).getDeviceStatus());
-					List<SgGxStepDO> stepDOS = deList.stream().filter(s->s.getReportStatus()==null || s.getReportStatus()!=4).map(s -> SgGxStepDO.builder().id(s.getStepId()).gxStepNum(s.getGxStepNum()).gxStepName(s.getGxStepName()).deviceId(s.getDId()).approvalStatus(s.getReportStatus()).build()).collect(Collectors.toList());
-					List<SgGxStepDO> stepOver = stepDOS.stream().filter(s -> s.getApprovalStatus() != null && s.getApprovalStatus() == 2).collect(Collectors.toList());
-					BigDecimal stepSize = BigDecimal.valueOf(stepDOS.size());
-					BigDecimal stepOverSize = BigDecimal.ZERO;
-					if (!stepOver.isEmpty()){
-						stepOverSize = BigDecimal.valueOf(stepOver.size());
+				PtypeVO ptypeVO = PtypeVO.builder().pTypeName(ptyValue.get(0).getPtypeName()).build();
+				List<SgTypeVO> sgGxDOS = new ArrayList<>();
+				//类型分组
+				Map<String, List<SgProjectInfoVO>> GxMap = ptyValue.stream().filter(s->s.getDeviceType()!=null).collect(Collectors.groupingBy(SgProjectInfoVO::getDeviceType));
+				for (Map.Entry<String, List<SgProjectInfoVO>> ty : GxMap.entrySet()) {
+					String type = ty.getKey();
+					List<SgProjectInfoVO> gxList = ty.getValue();
+					if (CollectionUtils.isEmpty(gxList)){
+						continue;
 					}
-					BigDecimal divide = stepOverSize.divide(stepSize, 2, RoundingMode.HALF_UP);
-					sgDeviceDO.setProgress(divide.toString());
-					sgDeviceDO.setDeviceProgress(getBigDecimalPercent(divide));
-					sgDeviceDO.setStepDOList(stepDOS);
-					deviceDOS.add(sgDeviceDO);
-					allDevice.add(sgDeviceDO);
+					SgTypeVO typeVO = SgTypeVO.builder().typeName(gxList.get(0).getTypeName()).build();
+					List<SgDeviceDO> deviceDOS = new ArrayList<>();
+					//设备分组
+					Map<Long, List<SgProjectInfoVO>> dMap = gxList.stream().collect(Collectors.groupingBy(SgProjectInfoVO::getDId));
+					for (Map.Entry<Long, List<SgProjectInfoVO>> device : dMap.entrySet()) {
+						Long dId = device.getKey();
+						List<SgProjectInfoVO> deList = device.getValue();
+						SgDeviceDO sgDeviceDO = new SgDeviceDO();
+						sgDeviceDO.setId(dId);
+						sgDeviceDO.setDeviceName(deList.get(0).getDeviceName());
+						List<SgGxStepDO> stepDOS = deList.stream().filter(s->s.getReportStatus()==null || s.getReportStatus()!=4).map(s -> SgGxStepDO.builder().id(s.getStepId()).gxStepNum(s.getGxStepNum()).gxStepName(s.getGxStepName()).deviceId(s.getDId()).approvalStatus(s.getReportStatus()).build()).collect(Collectors.toList());
+						List<SgGxStepDO> stepOver = stepDOS.stream().filter(s -> s.getApprovalStatus() != null && s.getApprovalStatus() == 2).collect(Collectors.toList());
+						BigDecimal stepSize = BigDecimal.valueOf(stepDOS.size());
+						BigDecimal stepOverSize = BigDecimal.ZERO;
+						if (!stepOver.isEmpty()){
+							stepOverSize = BigDecimal.valueOf(stepOver.size());
+						}
+						BigDecimal divide = stepOverSize.divide(stepSize, 2, RoundingMode.HALF_UP);
+						sgDeviceDO.setStatus(divide.compareTo(new BigDecimal(1)) == 0?2:deList.get(0).getDeviceStatus());
+						sgDeviceDO.setProgress(divide.toString());
+						sgDeviceDO.setDeviceProgress(getBigDecimalPercent(divide));
+						sgDeviceDO.setStepDOList(stepDOS);
+						deviceDOS.add(sgDeviceDO);
+						allDevice.add(sgDeviceDO);
+					}
+					BigDecimal deviceSize = BigDecimal.valueOf(deviceDOS.size());
+					double sum = deviceDOS.stream().mapToDouble(s -> Double.parseDouble(s.getProgress())).sum();
+					BigDecimal deviceOver = BigDecimal.valueOf(sum);
+					BigDecimal divideDevice = deviceOver.divide(deviceSize, 2, RoundingMode.HALF_UP);
+					typeVO.setDeviceDOS(deviceDOS);
+					typeVO.setTypeProgress(getBigDecimalPercent(divideDevice));
+					typeVO.setProgress(divideDevice.toString());
+					sgGxDOS.add(typeVO);
 				}
-				BigDecimal deviceSize = BigDecimal.valueOf(deviceDOS.size());
-				double sum = deviceDOS.stream().mapToDouble(s -> Double.parseDouble(s.getProgress())).sum();
-				BigDecimal deviceOver = BigDecimal.valueOf(sum);
-				BigDecimal divideDevice = deviceOver.divide(deviceSize, 2, RoundingMode.HALF_UP);
-				typeVO.setDeviceDOS(deviceDOS);
-				typeVO.setTypeProgress(getBigDecimalPercent(divideDevice));
-				sgGxDOS.add(typeVO);
+				BigDecimal sgGxSize = BigDecimal.valueOf(sgGxDOS.size());
+				double sum = sgGxDOS.stream().mapToDouble(s -> Double.parseDouble(s.getProgress())).sum();
+				BigDecimal sgGxOver = BigDecimal.valueOf(sum);
+				BigDecimal divideSgGx = sgGxOver.divide(sgGxSize, 2, RoundingMode.HALF_UP);
+				ptypeVO.setPTypeProgress(getBigDecimalPercent(divideSgGx));
+				ptypeVO.setSgTypeVOS(sgGxDOS);
+				pTypes.add(ptypeVO);
 			}
 			BigDecimal allDeviceSize = BigDecimal.valueOf(allDevice.size());
 			if (!allDeviceSize.equals(BigDecimal.ZERO)){
 				double sum = allDevice.stream().mapToDouble(s -> Double.parseDouble(s.getProgress())).sum();
 				BigDecimal allDeviceOver = BigDecimal.valueOf(sum);
 				BigDecimal allDivideDevice = allDeviceOver.divide(allDeviceSize, 2, RoundingMode.HALF_UP);
-				sgProjectInfoDO.setSgGxDOS(sgGxDOS);
+				sgProjectInfoDO.setPtypeVOS(pTypes);
 				sgProjectInfoDO.setProjectProgress( getBigDecimalPercent(allDivideDevice));
 				sgProjectInfoDO.setProjectProgressNum(allDivideDevice);
 			}
@@ -163,7 +181,7 @@
 	public List<SgProjectInfoVO> progressList(ProjectSearchDTO searchDTO) {
 		List<SgProjectInfoVO> list = new ArrayList<>();
 		List<SgProjectInfoDO> projectProgress = new ArrayList<>();
-		if(!searchDTO.getAdCode().isEmpty()){
+		if(StringUtils.isNotBlank(searchDTO.getAdCode())){
 			projectProgress = getProjectProgress(sgProjectInfoMapper.queryStepByProject1(searchDTO));
 		}else {
 			 projectProgress = getProjectProgress(sgProjectInfoMapper.queryStepByProject(searchDTO));
@@ -251,7 +269,8 @@
 		//片区
 		if (ywxtAdDetail == null) {
 			sgStatisProVOS = sgProjectInfoMapper.getsgStatisticsZero(code);
-			String getname = sgProjectInfoMapper.getname(code);
+//			String getname = sgProjectInfoMapper.getname(code);
+			String getname = code;
 			updateProjectProgress(sgStatisProVOS, code, getname, "2");
 		} else if (ywxtAdDetail.getAdGrad().equals("1")) {//默认
 			sgStatisProVOS = sgProjectInfoMapper.getsgStatisticsOne(code);
@@ -313,11 +332,11 @@
 			List<SgProjectInfoDO> projectProgress = getProjectProgress(list);
 			projectProgress.forEach(p -> {
 
-				List<SgTypeVO> sgGxDOS = p.getSgGxDOS();
-				sgGxDOS.forEach(sgTypeVO -> {
-					String typeProgress = sgTypeVO.getTypeProgress().replace("%", "");
+				List<PtypeVO> ptypeVOS = p.getPtypeVOS();
+				ptypeVOS.forEach(sgTypeVO -> {
+					String typeProgress = sgTypeVO.getPTypeProgress().replace("%", "");
 					BigDecimal percentageBigDecimal = new BigDecimal(typeProgress).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
-					bigDecimals.merge(sgTypeVO.getTypeName(), percentageBigDecimal, BigDecimal::add);
+					bigDecimals.merge(sgTypeVO.getPTypeName(), percentageBigDecimal, BigDecimal::add);
 				});
 
 			});

--
Gitblit v1.9.3