From 4eb1fe4a08e94c809ba513e0604ecd560e186f56 Mon Sep 17 00:00:00 2001
From: yxm <zhp1521624>
Date: Tue, 09 Jul 2024 17:29:54 +0800
Subject: [PATCH] 首页进度统计-列表优化v0.1

---
 skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sg/service/impl/SgProjectInfoServiceImpl.java |  134 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 132 insertions(+), 2 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 472fd06..5790a2e 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
@@ -5,11 +5,13 @@
 import cn.gistack.sm.sg.DO.SgGxStepDO;
 import cn.gistack.sm.sg.DO.SgProjectInfoDO;
 import cn.gistack.sm.sg.DTO.ProjectSearchDTO;
-import cn.gistack.sm.sg.VO.SgProjectInfoVO;
-import cn.gistack.sm.sg.VO.SgTypeVO;
+import cn.gistack.sm.sg.VO.*;
 import cn.gistack.sm.sg.excel.ProjectExcel;
 import cn.gistack.sm.sg.mapper.SgProjectInfoMapper;
 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.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
@@ -18,9 +20,11 @@
 import org.jetbrains.annotations.NotNull;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StopWatch;
 
 import java.math.BigDecimal;
+import java.math.MathContext;
 import java.math.RoundingMode;
 import java.util.*;
 import java.util.function.Function;
@@ -38,6 +42,8 @@
 public class SgProjectInfoServiceImpl extends ServiceImpl<SgProjectInfoMapper, SgProjectInfoDO> implements SgProjectInfoService {
 	@Autowired
 	private SgProjectInfoMapper sgProjectInfoMapper;
+	@Autowired
+	private IAttAdBaseService iAttAdBaseService;
 	@Override
 	public IPage<SgProjectInfoDO> queryPageList(IPage<SgProjectInfoDO> page, ProjectSearchDTO searchDTO) {
 		List<SgProjectInfoDO> sgProjectInfoDOS = baseMapper.queryPageList(page,searchDTO);
@@ -181,6 +187,130 @@
 	}
 
 	/**
+	 * 项目统计饼状图
+	 * @param code
+	 * @return
+	 */
+	@Override
+	public SgStatisticsVO getsgStatistics(String code) {
+		AttAdBase ywxtAdDetail = iAttAdBaseService.getYwxtAdDetail(code);
+
+		if (ywxtAdDetail == null){
+			return sgProjectInfoMapper.getSgstatiss("0",code);
+		}
+			return sgProjectInfoMapper.getSgstatiss(ywxtAdDetail.getAdGrad(),code);
+	}
+
+	/**
+	 * 项目统计表格
+	 * @param code
+	 * @return
+	 */
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public List<SgStatisProVO> getsgStatisticsList(String code) {
+		AttAdBase ywxtAdDetail = iAttAdBaseService.getYwxtAdDetail(code);
+		List<SgStatisProVO> sgStatisProVOS;
+
+
+		//片区
+		if (ywxtAdDetail == null) {
+			sgStatisProVOS = sgProjectInfoMapper.getsgStatisticsZero(code);
+			String getname = sgProjectInfoMapper.getname(code);
+			updateProjectProgress(sgStatisProVOS, code, getname, "2");
+		} else if (ywxtAdDetail.getAdGrad().equals("1")) {//默认
+			sgStatisProVOS = sgProjectInfoMapper.getsgStatisticsOne(code);
+			updateProjectProgress(sgStatisProVOS, ywxtAdDetail.getPAdCode(), ywxtAdDetail.getPAdName(), "0");
+		} else {//区县
+			sgStatisProVOS = sgProjectInfoMapper.getsgStatisticsList(code);
+			updateProjectProgress(sgStatisProVOS, ywxtAdDetail.getAdCode(), ywxtAdDetail.getAdName(), "3");
+		}
+		return sgStatisProVOS;
+	}
+
+	private void updateProjectProgress(List<SgStatisProVO> sgStatisProVOS, String pcode, String pname, String adGrad) {
+		ProjectSearchDTO projectSearchDTO = new ProjectSearchDTO();
+		for (SgStatisProVO s : sgStatisProVOS) {
+			if (s.getCommenceNum() == 0) {
+				s.setProjectProgress("0%");
+				s.setPcode(pcode);
+				s.setPname(pname);
+				s.setAdGrad(adGrad);
+			} else {
+				List<String> ids = sgProjectInfoMapper.getProjectId(adGrad, s.getCode());
+				List<BigDecimal> bigDecimals = new ArrayList<>();
+
+				for (String id : ids) {
+					projectSearchDTO.setProjectId(id);
+					List<SgProjectInfoVO> list = sgProjectInfoMapper.queryStepByProject(projectSearchDTO);
+					getProjectProgress(list).forEach(ss -> bigDecimals.add(ss.getProjectProgressNum()));
+				}
+
+				BigDecimal reduce = bigDecimals.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
+				String bigDecimalPercent1 = getBigDecimalPercent(reduce.divide(BigDecimal.valueOf(s.getProjectSum()), 2, RoundingMode.HALF_UP));
+				s.setProjectProgress(s.getCommenceNum() == 0? "0%" : bigDecimalPercent1);
+				s.setPcode(pcode);
+				s.setPname(pname);
+				s.setAdGrad(adGrad);
+			}
+		}
+	}
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public List<SgStatistccVO> getsgStatisticscc(String code) {
+		AttAdBase ywxtAdDetail = iAttAdBaseService.getYwxtAdDetail(code);
+
+
+		List<String> ids = sgProjectInfoMapper.getProjectId(ywxtAdDetail == null ? "0" : ywxtAdDetail.getAdGrad(), code);
+		Map<String, Integer> mun = new HashMap<>();
+		List<SgStatistccVO> sgdevices = sgProjectInfoMapper.getSgdevices(code, ywxtAdDetail == null ? "0" : ywxtAdDetail.getAdGrad());
+		sgdevices.forEach(sgStatistccVO -> {
+				mun.put(sgStatistccVO.getTypeName(), sgStatistccVO.getDeviceNum());
+			}
+		);
+		Map<String, BigDecimal> bigDecimals = new HashMap<>();
+		ProjectSearchDTO projectSearchDTO = new ProjectSearchDTO();
+		ids.forEach(id -> {
+
+			projectSearchDTO.setProjectId(id);
+			List<SgProjectInfoVO> list = sgProjectInfoMapper.queryStepByProject(projectSearchDTO);
+			List<SgProjectInfoDO> projectProgress = getProjectProgress(list);
+			projectProgress.forEach(p -> {
+
+				List<SgTypeVO> sgGxDOS = p.getSgGxDOS();
+				sgGxDOS.forEach(sgTypeVO -> {
+					String typeProgress = sgTypeVO.getTypeProgress().replace("%", "");
+					BigDecimal percentageBigDecimal = new BigDecimal(typeProgress).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
+					bigDecimals.merge(sgTypeVO.getTypeName(), percentageBigDecimal, BigDecimal::add);
+				});
+
+			});
+
+		});
+
+		for (String name : bigDecimals.keySet()) {
+
+			if (mun.containsKey(name)) {
+
+				BigDecimal bigDecimal = bigDecimals.get(name);
+				Integer intValue = mun.get(name);
+				BigDecimal result = bigDecimal.divide(new BigDecimal(intValue), 2, RoundingMode.HALF_UP);
+
+				sgdevices.forEach(sgStatistccVO -> {
+					if (sgStatistccVO.getTypeName().equals(name)) {
+						sgStatistccVO.setTypeProgress(getBigDecimalPercent(result));
+					}
+				});
+			}
+
+		}
+
+		return sgdevices;
+	}
+
+	/**
 	 * 获取百分比
 	 * @param bigDecimal
 	 * @return

--
Gitblit v1.9.3