|
@@ -5,20 +5,16 @@ import java.io.InputStreamReader;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.ConcurrentMap;
|
|
|
import java.util.function.ToDoubleFunction;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.alibaba.excel.util.StringUtils;
|
|
|
+import com.rtrh.projects.modules.projects.po.SubIndu;
|
|
|
+import com.rtrh.projects.modules.projects.vo.*;
|
|
|
+import com.rtrh.projects.modules.system.service.ISubInduService;
|
|
|
import com.rtrh.projects.modules.utils.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -31,8 +27,6 @@ import com.rtrh.projects.modules.projects.dao.SubInfoDao;
|
|
|
import com.rtrh.projects.modules.projects.enums.ProjectStatusEnum;
|
|
|
import com.rtrh.projects.modules.projects.mapper.StaticsMapper;
|
|
|
import com.rtrh.projects.modules.projects.service.StaticsService;
|
|
|
-import com.rtrh.projects.modules.projects.vo.HistoryVO;
|
|
|
-import com.rtrh.projects.modules.projects.vo.NewTouzVO;
|
|
|
import com.rtrh.projects.modules.projects.vo.report.ReportVO;
|
|
|
import com.rtrh.projects.modules.projects.vo.report.StaticsAmtDataVO;
|
|
|
import com.rtrh.projects.modules.system.enums.SysTableKind;
|
|
@@ -57,6 +51,8 @@ public class StaticsServiceImpl implements StaticsService {
|
|
|
private SubInfoDao subInfoDao;
|
|
|
@Autowired
|
|
|
private TSysTableService tSysTableService;
|
|
|
+ @Autowired
|
|
|
+ private ISubInduService subInduService;
|
|
|
|
|
|
@Override
|
|
|
public List<Map<String, Object>> HYFL(String year, String type, String orderNum, String kind, String loginName,
|
|
@@ -982,4 +978,249 @@ public class StaticsServiceImpl implements StaticsService {
|
|
|
List<Map<String, Object>> list = (List<Map<String, Object>>)subInfoDao.queryForObjListBySql(sql.toString());
|
|
|
return CollectionUtil.isNotEmpty(list) ? list.get(0) : new HashMap<>();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SubInfoTjfxVo getTjfxData(TzfxDataQueryVO queryVO) {
|
|
|
+
|
|
|
+
|
|
|
+ Integer startMoney = null;
|
|
|
+ Integer endMoney = null;
|
|
|
+ //判断是否有规模搜索条件
|
|
|
+ if (StringUtils.isNotBlank(queryVO.getKey())) {
|
|
|
+ //金额100亿以上,数据库单位是万元
|
|
|
+ if ("1".equals(queryVO.getKey())){
|
|
|
+ startMoney = 1000000;
|
|
|
+ }else if ("2".equals(queryVO.getKey())){
|
|
|
+ //金额50-100亿元
|
|
|
+ startMoney = 500000;
|
|
|
+ endMoney = 1000000;
|
|
|
+ }else if ("3".equals(queryVO.getKey())){
|
|
|
+ //金额10-50亿元
|
|
|
+ startMoney = 100000;
|
|
|
+ endMoney = 500000;
|
|
|
+ }else if ("4".equals(queryVO.getKey())){
|
|
|
+ //10亿元一下
|
|
|
+ endMoney = 100000;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //区域条件
|
|
|
+ List<String> subjectIds = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotBlank(queryVO.getSubjectId())){
|
|
|
+ subjectIds = Arrays.asList(queryVO.getSubjectId().split(","));
|
|
|
+ }
|
|
|
+
|
|
|
+ //行业条件
|
|
|
+ List<String> codeList = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotBlank(queryVO.getIndusKind())){
|
|
|
+ //因为行业都是父行业,所以需要根据父行业查询所有子行业code
|
|
|
+ List<String> indusKinds = Arrays.asList(queryVO.getIndusKind().split(","));
|
|
|
+ codeList = subInduService.selectChildrenCodesByCode(indusKinds);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取行业信息
|
|
|
+ List<SubIndu> subInduList = subInduService.selectAllSubIndu();
|
|
|
+
|
|
|
+ //性质条件
|
|
|
+ List<String> propKinds = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotBlank(queryVO.getPropKind())){
|
|
|
+ propKinds = Arrays.asList(queryVO.getPropKind().split(","));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SubInfoTjfxDataVo> dataList = staticsMapper.getTjfxData(queryVO.getYear(), startMoney, endMoney, subjectIds, codeList, propKinds);
|
|
|
+
|
|
|
+ //最终返回数据
|
|
|
+ SubInfoTjfxVo subInfoTjfxVo = new SubInfoTjfxVo(0, 0, 0, 0, 0, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(dataList)){
|
|
|
+ //收集dataList集合中的id为集合
|
|
|
+ List<String> idList = dataList.stream().map(SubInfoTjfxDataVo::getId).collect(Collectors.toList());
|
|
|
+ //查询这些项目年度金额是多少钱
|
|
|
+ List<SubInfoTjfxDataVo> yearMoneyList = staticsMapper.getTjfxYearMoneyBySubIds(idList, queryVO.getYear());
|
|
|
+ //查询这些项目上一年度金额是多少钱
|
|
|
+ List<SubInfoTjfxDataVo> lastYearMoneyList = staticsMapper.getTjfxYearMoneyBySubIds(idList, String.valueOf(Integer.parseInt(queryVO.getYear()) - 1));
|
|
|
+
|
|
|
+ //将yearMoneyList变为map,key=id,value=amt
|
|
|
+ Map<String, BigDecimal> yearMoneyMap = yearMoneyList.stream()
|
|
|
+ .filter(item -> item.getAmt() != null) // 过滤掉 amt 为 null 的项
|
|
|
+ .collect(Collectors.toMap(SubInfoTjfxDataVo::getId, SubInfoTjfxDataVo::getAmt));
|
|
|
+
|
|
|
+ //将lastYearMoneyList变为map,key=id,value=amt
|
|
|
+ Map<String, BigDecimal> lastYearMoneyMap = lastYearMoneyList.stream()
|
|
|
+ .filter(item -> item.getAmt() != null) // 过滤掉 amt 为 null 的项
|
|
|
+ .collect(Collectors.toMap(SubInfoTjfxDataVo::getId, SubInfoTjfxDataVo::getAmt));
|
|
|
+
|
|
|
+ for (SubInfoTjfxDataVo data : dataList) {
|
|
|
+ if (yearMoneyMap.containsKey(data.getId())){
|
|
|
+ if (yearMoneyMap.get(data.getId()) != null){
|
|
|
+ data.setAmt(yearMoneyMap.get(data.getId()));
|
|
|
+ }else {
|
|
|
+ data.setAmt(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ data.setAmt(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lastYearMoneyMap.containsKey(data.getId())){
|
|
|
+ if (lastYearMoneyMap.get(data.getId()) != null){
|
|
|
+ data.setLastAmt(lastYearMoneyMap.get(data.getId()));
|
|
|
+ }else {
|
|
|
+ data.setLastAmt(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ data.setLastAmt(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.isEmpty(data.getIndusKind())){
|
|
|
+ data.setIndusKind("未知行业");
|
|
|
+ }else {
|
|
|
+ //将二级行业code设置为一级行业id
|
|
|
+ Map<String, String> hyMap = subInduList.stream().filter(item -> item.getParentTitle() != null).collect(Collectors.toMap(SubIndu::getCode, SubIndu::getParentTitle));
|
|
|
+ data.setIndusKind(hyMap.getOrDefault(data.getIndusKind(), "未知行业"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ subInfoTjfxVo.setTotalNumber(dataList.size());
|
|
|
+ //找到dataList中status=1的个数
|
|
|
+ long cbNumber = dataList.stream().filter(data -> "1".equals(data.getStatus())).count();
|
|
|
+ subInfoTjfxVo.setCbNumber((int) cbNumber);
|
|
|
+ //找到dataList中status=2的个数
|
|
|
+ long xjNumber = dataList.stream().filter(data -> "2".equals(data.getStatus())).count();
|
|
|
+ subInfoTjfxVo.setXjNumber((int) xjNumber);
|
|
|
+ //找到dataList中status=3的个数
|
|
|
+ long zjNumber = dataList.stream().filter(data -> "3".equals(data.getStatus())).count();
|
|
|
+ subInfoTjfxVo.setZjNumber((int) zjNumber);
|
|
|
+ //找到dataList中status=9的个数
|
|
|
+ long tcNumber = dataList.stream().filter(data -> "9".equals(data.getStatus())).count();
|
|
|
+ subInfoTjfxVo.setTcNumber((int) tcNumber);
|
|
|
+ //计算出所有金额,由万元转换为亿元为单位
|
|
|
+ subInfoTjfxVo.setAmtTotal(
|
|
|
+ dataList.stream()
|
|
|
+ .map(item -> Optional.ofNullable(item.getAmtTotal()).orElse(BigDecimal.ZERO)) // 处理 null 值,替换为 BigDecimal.ZERO
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP) // 除以 10000,保留两位小数
|
|
|
+ );
|
|
|
+ //计算出年度金额,由万元转换为亿元为单位
|
|
|
+ subInfoTjfxVo.setYearAmtTotal(
|
|
|
+ dataList.stream()
|
|
|
+ .map(item -> Optional.ofNullable(item.getAmt()).orElse(BigDecimal.ZERO)) // 处理 null 值,替换为 BigDecimal.ZERO
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP) // 除以 10000,保留两位小数
|
|
|
+ );
|
|
|
+ //计算出上一个年度金额,由万元转换为亿元为单位
|
|
|
+ subInfoTjfxVo.setLastYearAmtTotal(
|
|
|
+ dataList.stream()
|
|
|
+ .map(item -> Optional.ofNullable(item.getLastAmt()).orElse(BigDecimal.ZERO)) // 处理 null 值,替换为 BigDecimal.ZERO
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP) // 除以 10000,保留两位小数
|
|
|
+ );
|
|
|
+
|
|
|
+ //区域占比数据
|
|
|
+ List<SubInfoTjfxTableVo> areaData = new ArrayList<>();
|
|
|
+ //获取地区信息
|
|
|
+ List<TSystable> areaList = tSysTableService.getByKind(SysTableKind.JSDD);
|
|
|
+ //将areaList转换为map,key=code,value=title
|
|
|
+ Map<String, String> areaMap = areaList.stream().collect(Collectors.toMap(TSystable::getCode, TSystable::getTitle));
|
|
|
+ //将dataList根据subjectId分组
|
|
|
+ Map<String, List<SubInfoTjfxDataVo>> subjectIdList = dataList.stream().collect(Collectors.groupingBy(SubInfoTjfxDataVo::getSubjectId));
|
|
|
+ for (Map.Entry<String, List<SubInfoTjfxDataVo>> entry : subjectIdList.entrySet()) {
|
|
|
+ SubInfoTjfxTableVo subInfoTjfxTableVo = new SubInfoTjfxTableVo();
|
|
|
+ //设置numbers为1开始的序号
|
|
|
+ subInfoTjfxTableVo.setNumbers(areaData.size() + 1);
|
|
|
+ subInfoTjfxTableVo.setKindDesc(areaMap.get(entry.getKey()));
|
|
|
+ subInfoTjfxTableVo.setAmtJh(entry.getValue().stream().map(SubInfoTjfxDataVo::getAmt).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //进度占比=(年度金额/所有金额)*100
|
|
|
+ BigDecimal yearAmtTotal = subInfoTjfxVo.getYearAmtTotal();
|
|
|
+ if (yearAmtTotal.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ subInfoTjfxTableVo.setNumBZb(subInfoTjfxTableVo.getAmtJh().divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP).divide(yearAmtTotal, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")));
|
|
|
+ } else {
|
|
|
+ subInfoTjfxTableVo.setNumBZb(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ //上一年度进度占比=(上一年度金额/所有金额)*100
|
|
|
+ BigDecimal lastYearAmtTotal = subInfoTjfxVo.getLastYearAmtTotal();
|
|
|
+ subInfoTjfxTableVo.setLastAmtJh(entry.getValue().stream().map(SubInfoTjfxDataVo::getLastAmt).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ if (lastYearAmtTotal.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ //需要计算当前年度占比
|
|
|
+ subInfoTjfxTableVo.setNumBl(subInfoTjfxTableVo.getNumBZb().subtract(subInfoTjfxTableVo.getLastAmtJh().divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP).divide(lastYearAmtTotal, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))));
|
|
|
+ } else {
|
|
|
+ subInfoTjfxTableVo.setNumBl(subInfoTjfxTableVo.getNumBZb());
|
|
|
+ }
|
|
|
+ //同比增长 TODO
|
|
|
+ areaData.add(subInfoTjfxTableVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ //行业占比数据
|
|
|
+ List<SubInfoTjfxTableVo> hyData = new ArrayList<>();
|
|
|
+ //将dataList根据indusKind分组
|
|
|
+ Map<String, List<SubInfoTjfxDataVo>> indusKindList = dataList.stream().collect(Collectors.groupingBy(SubInfoTjfxDataVo::getIndusKind));
|
|
|
+ for (Map.Entry<String, List<SubInfoTjfxDataVo>> entry : indusKindList.entrySet()) {
|
|
|
+ SubInfoTjfxTableVo subInfoTjfxTableVo = new SubInfoTjfxTableVo();
|
|
|
+ //设置numbers为1开始的序号
|
|
|
+ subInfoTjfxTableVo.setNumbers(hyData.size() + 1);
|
|
|
+ subInfoTjfxTableVo.setKindDesc(entry.getKey());
|
|
|
+ subInfoTjfxTableVo.setAmtJh(entry.getValue().stream().map(SubInfoTjfxDataVo::getAmt).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //进度占比=(年度金额/所有金额)*100
|
|
|
+ BigDecimal yearAmtTotal = subInfoTjfxVo.getYearAmtTotal();
|
|
|
+ if (yearAmtTotal.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ subInfoTjfxTableVo.setNumBZb(subInfoTjfxTableVo.getAmtJh().divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP).divide(yearAmtTotal, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")));
|
|
|
+ } else {
|
|
|
+ subInfoTjfxTableVo.setNumBZb(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ //上一年度进度占比=(上一年度金额/所有金额)*100
|
|
|
+ BigDecimal lastYearAmtTotal = subInfoTjfxVo.getLastYearAmtTotal();
|
|
|
+ subInfoTjfxTableVo.setLastAmtJh(entry.getValue().stream().map(SubInfoTjfxDataVo::getLastAmt).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ if (lastYearAmtTotal.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ //需要计算当前年度占比
|
|
|
+ subInfoTjfxTableVo.setNumBl(subInfoTjfxTableVo.getNumBZb().subtract(subInfoTjfxTableVo.getLastAmtJh().divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP).divide(lastYearAmtTotal, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))));
|
|
|
+ } else {
|
|
|
+ subInfoTjfxTableVo.setNumBl(subInfoTjfxTableVo.getNumBZb());
|
|
|
+ }
|
|
|
+ //同比增长 TODO
|
|
|
+ hyData.add(subInfoTjfxTableVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ //建设性质占比数据
|
|
|
+ List<SubInfoTjfxTableVo> jsData = new ArrayList<>();
|
|
|
+ //获取建设性质信息
|
|
|
+ List<TSystable> jsList = tSysTableService.getByKind(SysTableKind.JSXZ);
|
|
|
+ //将jsList转换为map,key=code,value=title
|
|
|
+ Map<String, String> jsMap = jsList.stream().collect(Collectors.toMap(TSystable::getCode, TSystable::getTitle));
|
|
|
+ //将dataList根据status分组
|
|
|
+ Map<String, List<SubInfoTjfxDataVo>> statusList = dataList.stream().collect(Collectors.groupingBy(SubInfoTjfxDataVo::getStatus));
|
|
|
+ for (Map.Entry<String, List<SubInfoTjfxDataVo>> entry : statusList.entrySet()) {
|
|
|
+ SubInfoTjfxTableVo subInfoTjfxTableVo = new SubInfoTjfxTableVo();
|
|
|
+ //设置numbers为1开始的序号
|
|
|
+ subInfoTjfxTableVo.setNumbers(jsData.size() + 1);
|
|
|
+ subInfoTjfxTableVo.setKindDesc(jsMap.get(entry.getKey()));
|
|
|
+ subInfoTjfxTableVo.setAmtJh(entry.getValue().stream().map(SubInfoTjfxDataVo::getAmt).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //进度占比=(年度金额/所有金额)*100
|
|
|
+ BigDecimal yearAmtTotal = subInfoTjfxVo.getYearAmtTotal();
|
|
|
+ if (yearAmtTotal.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ subInfoTjfxTableVo.setNumBZb(subInfoTjfxTableVo.getAmtJh().divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP).divide(yearAmtTotal, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")));
|
|
|
+ } else {
|
|
|
+ subInfoTjfxTableVo.setNumBZb(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ //上一年度进度占比=(上一年度金额/所有金额)*100
|
|
|
+ BigDecimal lastYearAmtTotal = subInfoTjfxVo.getLastYearAmtTotal();
|
|
|
+ subInfoTjfxTableVo.setLastAmtJh(entry.getValue().stream().map(SubInfoTjfxDataVo::getLastAmt).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ if (lastYearAmtTotal.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ //需要计算当前年度占比
|
|
|
+ subInfoTjfxTableVo.setNumBl(subInfoTjfxTableVo.getNumBZb().subtract(subInfoTjfxTableVo.getLastAmtJh().divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP).divide(lastYearAmtTotal, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))));
|
|
|
+ } else {
|
|
|
+ subInfoTjfxTableVo.setNumBl(subInfoTjfxTableVo.getNumBZb());
|
|
|
+ }
|
|
|
+ //同比增长 TODO
|
|
|
+ jsData.add(subInfoTjfxTableVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ subInfoTjfxVo.setAreaData(areaData);
|
|
|
+ subInfoTjfxVo.setHyData(hyData);
|
|
|
+ subInfoTjfxVo.setJsData(jsData);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return subInfoTjfxVo;
|
|
|
+ }
|
|
|
}
|