Pārlūkot izejas kodu

结算前4张表

qianxb 1 gadu atpakaļ
vecāks
revīzija
296b5d21ed

+ 140 - 83
blade-service/blade-land/src/main/java/org/springblade/land/service/impl/ClearingAgreementInfoServiceImpl.java

@@ -131,11 +131,11 @@ public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAg
         }
         //循环结算协议的统计字段,把补偿协议统计出来的字段设置到结算协议
         //生成封面
-//        buildPdf1(linkTables.get(0), info.getStage());
+        buildPdf1(linkTables.get(0), info.getStage());
         //生成补偿结算表
-//        buildPdf2(linkTables.get(1),info.getAreaId());
+        buildPdf2(linkTables.get(1),info.getAreaId());
         //生成补偿费发放统计表
-//        buildPdf3(linkTables.get(2),ids);
+        buildPdf3(linkTables.get(2),ids);
         //生成补偿费明细表
         buildPdf4(linkTables.get(3),ids,info.getStage());
         //生成补偿资金数量分配表
@@ -158,7 +158,7 @@ public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAg
             //周期格式
             stage = stage.substring(1,stage.length()-1);
             //获取项目名称
-            String projectName = jdbcTemplate.queryForObject("select project_name from m_project_info where id = " + linkTable.getProjectId(), new BeanPropertyRowMapper<>(String.class));
+            String projectName = jdbcTemplate.queryForObject("select project_name from m_project_info where id = " + linkTable.getProjectId(), String.class);
             List<WbsFormElement> list = baseMapper.getTableElement(linkTable.getTableId());
             Map<Long,Map<String, Object>> dataInfos = new LinkedHashMap<>();
             //获取所有的补偿协议映射表中的发放表
@@ -222,8 +222,6 @@ public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAg
                 Map<Long,BigDecimal> big3 = new HashMap<>();
                 //时段奖总和
                 Map<Long,BigDecimal> big4 = new HashMap<>();
-                //当前数据有多少行
-                Integer rows = 0;
                 //当前数据的第一行
                 Integer oneRows = 0;
                 //生成结算表有多少行,用于跨页后复制表单
@@ -248,7 +246,6 @@ public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAg
                         oneRows = vos.get(0).getDictRow();
                         data.addAll(vos.stream().map(l -> l.getTabVal()).collect(Collectors.toList()));
                     }
-                    rows = data.size();
                     //取出位置集合
                     List<TableDataVO> voList2 = listMap2.get(nameDict);
                     List<String> keys = new ArrayList<>();
@@ -291,8 +288,10 @@ public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAg
                 }else {
                     compensationInfoService.getBussPdfInfo(linkTable.getId(), null);
                 }
+                //先设置批量字段,最后设置统计字段
                 for (Integer dict : elementMap.keySet()) {
                     if (batchKey2.contains(dict)) {
+                        List<Object> values = new ArrayList<>();
                         if (dict.equals(400)) {
                             //单独处理青苗+地面
                             //取出83(青苗)数据集合
@@ -310,7 +309,6 @@ public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAg
                             //重置数据顺序,先按表单分组,再按照行顺序重新装入集合
                             Map<Long, List<TableDataVO>> map2 = voList2.stream().collect(Collectors.groupingBy(TableDataVO::getPKeyId));
                             //根据总行数和起始位置,生成青苗+地面的集合
-                            List<Object> values = new ArrayList<>();
                             for (Long aLong : tableRows.keySet()) {
                                 Integer ro = tableRows.get(aLong);
                                 //获取当前表青苗集合,并且按照行转换为map
@@ -339,36 +337,14 @@ public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAg
                                     values.add(value);
                                 }
                             }
-
-                            //取出位置集合
-                            List<TableDataVO> voList3 = listMap2.get(dict);
-                            List<String> keys = new ArrayList<>();
-                            //重置key位置,按照行从小到大
-                            keys.addAll(voList3.stream().sorted(Comparator.comparing(TableDataVO::getDictRow)).map(l -> l.getTabKey()).collect(Collectors.toList()));
-                            //
-                            List<List<Object>> lists = CommonUtils.splitList(values, oneTableRows);
-                            //多页分开存入
-                            for (int i = 0; i < tableTotal; i++) {
-                                Map<String, Object> DataInfo = dataInfos.get(tableIds.get(i));
-                                List<Object> data2 = lists.get(i);
-                                BigDecimal decimal = new BigDecimal(0);
-                                for (int j = 0; j < data2.size(); j++) {
-                                    DataInfo.put(keys.get(j), data2.get(j));
-                                    decimal = decimal.add(new BigDecimal(data2.get(i) + ""));
-                                }
-                                big3.put(tableIds.get(i),decimal);
-                            }
-
                         } else {
                             //取出数据
                             List<TableDataVO> voList = new ArrayList<>();
-                            if (listMap.get(dict) != null){
+                            if (listMap.get(dict) != null) {
                                 voList = listMap.get(dict);
                             }
                             //重置数据顺序,先按表单分组,再按照行顺序重新装入集合
                             Map<Long, List<TableDataVO>> map = voList.stream().collect(Collectors.groupingBy(TableDataVO::getPKeyId));
-                            //根据总行数和起始位置,生成青苗+地面的集合
-                            List<Object> values = new ArrayList<>();
                             for (Long aLong : tableRows.keySet()) {
                                 Integer ro = tableRows.get(aLong);
                                 //获取当前表青苗集合,并且按照行转换为map
@@ -380,44 +356,42 @@ public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAg
                                         Collectors.mapping(l -> new BigDecimal(l.getTabVal()), Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
                                 for (int i = oneRows; i < (oneRows + ro); i++) {
                                     BigDecimal value = new BigDecimal(0);
-                                    if (map3.size() != 0 &&  map3.get(i) != null) {
+                                    if (map3.size() != 0 && map3.get(i) != null) {
                                         value = value.add(map3.get(i));
                                     }
                                     values.add(value);
                                 }
                             }
-                            //取出位置集合
-                            List<TableDataVO> voList3 = listMap2.get(dict);
-                            List<String> keys = new ArrayList<>();
-                            keys.addAll(voList3.stream().sorted(Comparator.comparing(TableDataVO::getDictRow)).map(l -> l.getTabKey()).collect(Collectors.toList()));
-                            //判断数据长度是否超过单表总行数
-                            List<List<Object>> lists = CommonUtils.splitList(values, oneTableRows);
-                            //多页分开存入
-                            for (int i = 0; i < tableTotal; i++) {
-                                Map<String, Object> DataInfo = dataInfos.get(tableIds.get(i));
-                                List<Object> data2 = lists.get(i);
-                                BigDecimal decimal = new BigDecimal(0);
-                                for (int j = 0; j < data2.size(); j++) {
-                                    DataInfo.put(keys.get(j), data2.get(j));
-                                    if (batchKey3.contains(dict)){
-                                        decimal = decimal.add(new BigDecimal(data2.get(j)+""));
-                                    }
-                                }
-                                if (dict == 82) {
-                                    //土地
-                                    big2.put(tableIds.get(i),decimal);
-                                }
-                                if (dict == 85) {
-                                    //时段
-                                    big4.put(tableIds.get(i),decimal);
-                                }
-                                //如果是合计的就要添加进总合计
-                                if (dict == 86) {
-                                    big.put(tableIds.get(i),decimal);
-                                }
+                        }
+                        //取出位置集合
+                        List<TableDataVO> voList3 = listMap2.get(dict);
+                        List<String> keys = new ArrayList<>();
+                        keys.addAll(voList3.stream().sorted(Comparator.comparing(TableDataVO::getDictRow)).map(l -> l.getTabKey()).collect(Collectors.toList()));
+                        //判断数据长度是否超过单表总行数
+                        List<List<Object>> lists = CommonUtils.splitList(values, oneTableRows);
+                        //多页分开存入
+                        for (int i = 0; i < tableTotal; i++) {
+                            Map<String, Object> DataInfo = dataInfos.get(tableIds.get(i));
+                            List<Object> data2 = lists.get(i);
+                            for (int j = 0; j < data2.size(); j++) {
+                                DataInfo.put(keys.get(j), data2.get(j));
+                            }
+                            if (dict == 82) {
+                                //土地
+                                big2.put(tableIds.get(i),data2.stream().map(l -> new BigDecimal(l + "")).reduce(BigDecimal.valueOf(0), BigDecimal::add));
+                            }
+                            if (dict == 400) {
+                                big3.put(tableIds.get(i),data2.stream().map(l -> new BigDecimal(l + "")).reduce(BigDecimal.valueOf(0), BigDecimal::add));
+                            }
+                            if (dict == 85) {
+                                //时段
+                                big4.put(tableIds.get(i),data2.stream().map(l -> new BigDecimal(l + "")).reduce(BigDecimal.valueOf(0), BigDecimal::add));
+                            }
+                            //如果是合计的就要添加进总合计
+                            if (dict == 86) {
+                                big.put(tableIds.get(i),data2.stream().map(l -> new BigDecimal(l + "")).reduce(BigDecimal.valueOf(0), BigDecimal::add));
                             }
                         }
-//                        elementMap.remove(dict);
                     }
                 }
                 for (Integer dict : elementMap.keySet()) {
@@ -473,22 +447,24 @@ public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAg
 
     private void buildPdf3(AgreementLinkTable linkTable,List<Long> ids) {
         try {
+            //获取项目名称
+            String projectName = jdbcTemplate.queryForObject("select project_name from m_project_info where id = " + linkTable.getProjectId(), String.class);
             List<WbsFormElement> list = baseMapper.getTableElement(linkTable.getTableId());
-            Map<String, Object> DataInfo = new HashMap<>();
+            Map<Long,Map<String, Object>> dataInfos = new LinkedHashMap<>();
             //获取所有的补偿协议映射表中的发放表
             List<AgreementLinkTable> assignTable = baseMapper.getAllAssignTable(ids, "发放表");
             List<Long> longs = assignTable.stream().map(l -> l.getTableDataId()).collect(Collectors.toList());
             //获取发放表的配置
             List<WbsFormElement> dataElements = baseMapper.getTableElement(assignTable.get(0).getTableId());
             if (dataElements == null || dataElements.size() == 0){
-                compensationInfoService.getBussPdfInfo(linkTable.getId(), DataInfo);
+                compensationInfoService.getBussPdfInfo(linkTable.getId(), null);
             }
             Map<String, Integer> dataMap = dataElements.stream().collect(Collectors.toMap(WbsFormElement::getEKey, WbsFormElement::getDynamicDict));
             //获取所有补偿费发放表中的数据
             List<TableDataVO> dataVOS = compensationInfoMapper.getBussDataInfoByDataIds(longs);
             dataVOS = dataVOS.stream().filter(l -> dataMap.get(l.getDictKey()) != null).collect(Collectors.toList());
             if (dataVOS.size() == 0){
-                compensationInfoService.getBussPdfInfo(linkTable.getId(), DataInfo);
+                compensationInfoService.getBussPdfInfo(linkTable.getId(), null);
             }
             dataVOS.stream().forEach(l->l.setDictValue(dataMap.get(l.getDictKey())));
             Map<Integer, List<TableDataVO>> listMap = dataVOS.stream().collect(Collectors.groupingBy(TableDataVO::getDictValue));
@@ -517,14 +493,79 @@ public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAg
                 }).collect(Collectors.toList());
                 allKey = allKey.stream().filter(l -> overMap.get(l.getDictKey()) != null).collect(Collectors.toList());
                 if (allKey.size() == 0){
-                    compensationInfoService.getBussPdfInfo(linkTable.getId(), DataInfo);
+                    compensationInfoService.getBussPdfInfo(linkTable.getId(), null);
                 }
                 allKey.stream().forEach(l->l.setDictValue(overMap.get(l.getDictKey())));
                 Map<Integer, List<TableDataVO>> listMap2 = allKey.stream().collect(Collectors.groupingBy(TableDataVO::getDictValue));
+                //确定长度的key的字典,因为其他字段可能为空,姓名不为空,所以通过姓名获取数据长度
+                Integer nameDict = 80;
                 //重复key的字典
                 List<Integer> batchKey = Arrays.asList(80, 81, 86, 87);
+                //当前数据的第一行
+                Integer oneRows = 0;
+                //生成结算表有多少行,用于跨页后复制表单
+                Integer oneTableRows = 0;
+                //判断每一张表有多少行,合并表时用于填充统计
+                Map<Long,Integer> tableRows = new LinkedHashMap<>();
+                //一共需要多少表
+                Integer tableTotal = 0;
                 //统计补偿总和
-                BigDecimal big = new BigDecimal(0);
+                Map<Long,BigDecimal> big = new HashMap<>();
+                //表单id,按顺序
+                LinkedList<Long> tableIds = new LinkedList<>();
+                //先设置姓名,查看一共有多少条数据
+                if (listMap.get(nameDict) != null && listMap.get(nameDict).size() > 0) {
+                    List<TableDataVO> voList = listMap.get(nameDict);
+                    //重置数据顺序,先按表单分组,再按照行顺序重新装入集合
+                    Map<Long, List<TableDataVO>> map = voList.stream().collect(Collectors.groupingBy(TableDataVO::getPKeyId));
+                    List<Long> collect = map.keySet().stream().sorted().collect(Collectors.toList());
+                    List<Object> data = new ArrayList<>();
+                    for (Long aLong : collect) {
+                        List<TableDataVO> vos = map.get(aLong);
+                        tableRows.put(aLong, vos.size());
+                        vos = vos.stream().sorted(Comparator.comparing(TableDataVO::getDictRow)).collect(Collectors.toList());
+                        oneRows = vos.get(0).getDictRow();
+                        data.addAll(vos.stream().map(l -> l.getTabVal()).collect(Collectors.toList()));
+                    }
+                    //取出位置集合
+                    List<TableDataVO> voList2 = listMap2.get(nameDict);
+                    List<String> keys = new ArrayList<>();
+                    voList2 = voList2.stream().sorted(Comparator.comparing(TableDataVO::getDictRow)).collect(Collectors.toList());
+                    keys.addAll(voList2.stream().map(l -> l.getTabKey()).collect(Collectors.toList()));
+                    //单表总行数
+                    oneTableRows = keys.size();
+                    //判断数据长度是否超过单表总行数
+                    List<List<Object>> lists = CommonUtils.splitList(data, oneTableRows);
+                    tableTotal = lists.size();
+                    for (int i = 0; i < tableTotal; i++) {
+                        Map<String, Object> DataInfo = new HashMap<>();
+                        if (i == 0){
+                            dataInfos.put(linkTable.getId(),DataInfo);
+                            tableIds.add(linkTable.getId());
+                        }else {
+                            //复制表,返回表id
+                            Long aLong = this.copyTable(linkTable);
+                            dataInfos.put(aLong,DataInfo);
+                            tableIds.add(aLong);
+                        }
+                    }
+                    //为多表的统计字段设置默认值
+                    for (Long id : tableIds) {
+                        big.put(id,new BigDecimal(0));
+                    }
+
+                    //多页分开存入
+                    for (int i = 0; i < tableTotal; i++) {
+                        Map<String, Object> DataInfo = dataInfos.get(tableIds.get(i));
+                        List<Object> data2 = lists.get(i);
+                        for (int j = 0; j < data2.size(); j++) {
+                            DataInfo.put(keys.get(j), data2.get(j));
+                        }
+                    }
+                    elementMap.remove(nameDict);
+                }else {
+                    compensationInfoService.getBussPdfInfo(linkTable.getId(), null);
+                }
                 for (Integer dict : elementMap.keySet()) {
                     if (batchKey.contains(dict)) {
                         //取出数据集合
@@ -541,35 +582,49 @@ public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAg
                         List<TableDataVO> voList2 = listMap2.get(dict);
                         List<String> keys = new ArrayList<>();
                         keys.addAll(voList2.stream().sorted(Comparator.comparing(TableDataVO::getDictRow)).map(l -> l.getTabKey()).collect(Collectors.toList()));
-                        //重置key位置,按照行从小到大
-                        //!!暂时没判断多页,到时候要分隔集合
-                        for (int i = 0; i < data.size(); i++) {
-                            DataInfo.put(keys.get(i), data.get(i));
+                        //判断数据长度是否超过单表总行数
+                        List<List<Object>> lists = CommonUtils.splitList(data, oneTableRows);
+                        //多页分开存入
+                        for (int i = 0; i < tableTotal; i++) {
+                            Map<String, Object> DataInfo = dataInfos.get(tableIds.get(i));
+                            List<Object> data2 = lists.get(i);
+                            for (int j = 0; j < data2.size(); j++) {
+                                DataInfo.put(keys.get(j), data2.get(j));
+                            }
                             //如果是合计的就要添加进总合计
                             if (dict == 86) {
-                                big = big.add(new BigDecimal(data.get(i) + ""));
+                                big.put(tableIds.get(i),data2.stream().map(l -> new BigDecimal(l + "")).reduce(BigDecimal.valueOf(0), BigDecimal::add));
                             }
                         }
                     }
                 }
                 for (Integer dict : elementMap.keySet()) {
                     if (!batchKey.contains(dict)) {
-                        TableDataVO vo = listMap2.get(dict).get(0);
-                        switch (dict) {
-                            case 301:
-                                //合计补偿总计
-                                DataInfo.put(vo.getTabKey(), big);
-                                break;
-                            case 300:
-                                //统计员
-                                DataInfo.put(vo.getTabKey(), "王文");
-                                break;
+                        for (int i = 0; i < tableTotal; i++) {
+                            Map<String, Object> DataInfo = dataInfos.get(tableIds.get(i));
+                            TableDataVO vo = listMap2.get(dict).get(0);
+                            switch (dict) {
+                                case 301:
+                                    //合计补偿总计
+                                    DataInfo.put(vo.getTabKey(), big.get(tableIds.get(i)));
+                                    break;
+                                case 300:
+                                    //统计员
+                                    DataInfo.put(vo.getTabKey(), "王文");
+                                    break;
+                                case 197:
+                                    //项目名称
+                                    DataInfo.put(vo.getTabKey(), projectName);
+                                    break;
+                            }
                         }
                     }
                 }
 
             }
-            compensationInfoService.getBussPdfInfo(linkTable.getId(), DataInfo);
+            for (Long aLong : dataInfos.keySet()) {
+                compensationInfoService.getBussPdfInfo(aLong, dataInfos.get(aLong));
+            }
         } catch (Exception e) {
             throw new ServiceException("补偿费发放统计表生成失败");
         }
@@ -648,6 +703,8 @@ public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAg
      * @param stage              第几期
      */
     private void buildPdf1(AgreementLinkTable linkTable, String stage) {
+        //周期格式
+        stage = stage.substring(1,stage.length()-1);
         List<WbsFormElement> list = baseMapper.getTableElement(linkTable.getTableId());
         Map<String, Object> DataInfo = new HashMap<>();
         try {