浏览代码

feature 催缴单格式修改 账单减免费用异常bug

xiahan 4 月之前
父节点
当前提交
28f1ae946d

+ 20 - 10
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/BillGenerationServiceImpl.java

@@ -24,7 +24,10 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
+import java.time.YearMonth;
+import java.time.ZoneId;
 import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAccessor;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -102,7 +105,10 @@ public class BillGenerationServiceImpl {
                                 (a, b) -> a != null ? a : b // 合并规则:保留第一个非 null 元素
                         )));
 
-        collect.forEach(swWaterUsageEntry -> {
+
+        SwUserManagementDo swUserManagementDo;
+        SwBillManagementUnpaidDo swBillManagementUnpaidDo = null;
+        for (SwWaterUsageEntryDo swWaterUsageEntry : collect) {
             String usernumber = swWaterUsageEntry.getUsernumber();
             // 本次抄表日期
             Date currentreadingdate = swWaterUsageEntry.getCurrentreadingdate();
@@ -111,7 +117,7 @@ public class BillGenerationServiceImpl {
                 log.error("当前用户:{},时间:{}的抄表记录已生成账单信息", usernumber, currentreadingdate);
                 return;
             }
-            SwUserManagementDo swUserManagementDo = userMap.getOrDefault(swWaterUsageEntry.getUsernumber(), null);
+            swUserManagementDo = userMap.getOrDefault(swWaterUsageEntry.getUsernumber(), null);
 
             SwWaterUsageEntryDo usageEntryDo = new SwWaterUsageEntryDo();
             usageEntryDo.setId(swWaterUsageEntry.getId());
@@ -129,7 +135,7 @@ public class BillGenerationServiceImpl {
                 saveUsageEntryList.add(usageEntryDo);
                 return;
             }
-            SwBillManagementUnpaidDo swBillManagementUnpaidDo = null;
+
             try {
                 // 生成代缴费账单
                 swBillManagementUnpaidDo = produceBill(swUserManagementDo, swWaterUsageEntry);
@@ -150,7 +156,8 @@ public class BillGenerationServiceImpl {
             }
             userSaveList.add(swUserManagementDo);
             saveUsageEntryList.add(usageEntryDo);
-        });
+        }
+        ;
         dataSave(saveList, saveUsageEntryList, userSaveList);
     }
 
@@ -268,10 +275,12 @@ public class BillGenerationServiceImpl {
         if (swBillManagementUnpaidDo.getLastmeterreadingdate() == null) {
             monthDiff = 1L;
         } else {
-            LocalDate localDate1 = swBillManagementUnpaidDo.getLastmeterreadingdate().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
-            LocalDate localDate2 = swBillManagementUnpaidDo.getThismeterreadingdate().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
+
+            YearMonth localDate1 = YearMonth.from(swBillManagementUnpaidDo.getLastmeterreadingdate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
+            YearMonth localDate2 = YearMonth.from(swBillManagementUnpaidDo.getThismeterreadingdate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
             // 计算月份差(不考虑天数)
-            monthDiff =  ChronoUnit.MONTHS.between(localDate1, localDate2);
+            monthDiff = ChronoUnit.MONTHS.between(localDate1, localDate2);
+            log.error("时间区间为:{}-{}", localDate1, localDate2);
         }
 
 
@@ -284,8 +293,8 @@ public class BillGenerationServiceImpl {
             exemptionAmount = BigDecimal.ZERO;
             exemptionWater = BigDecimal.ZERO;
         } else {
-            exemptionAmount=exemptionAmount.multiply(BigDecimal.valueOf(monthDiff));
-            exemptionWater=exemptionWater.multiply(BigDecimal.valueOf(monthDiff));
+            exemptionAmount = exemptionAmount.multiply(BigDecimal.valueOf(monthDiff));
+            exemptionWater = exemptionWater.multiply(BigDecimal.valueOf(monthDiff));
             // 优先金额减免
             if (exemptionAmount.compareTo(BigDecimal.ZERO) > 0) {
                 // 计算减免用水
@@ -294,7 +303,8 @@ public class BillGenerationServiceImpl {
                 exemptionAmount = exemptionWater.multiply(waterprice);
             }
         }
-
+        log.debug("用户 {} 的减免计算:monthDiff={}, exemptionAmount={}, exemptionWater={}",
+                swUserManagementDo.getUsernumber(), monthDiff, exemptionAmount, exemptionWater);
         swBillManagementUnpaidDo.setReducedwateruse(exemptionWater);
         swBillManagementUnpaidDo.setFeewaiver(exemptionAmount);
         swBillManagementUnpaidDo.setOughttohavepaid(waterprice.multiply(waterConsumption));

+ 7 - 7
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/PrintServiceImpl.java

@@ -123,13 +123,13 @@ public class PrintServiceImpl implements PrintService {
             for (SwBillManagementPaidDo swBillManagementPaidDo : swBillManagementPaidDoList) {
                 // 账单对应的用水信息
                 listData.add(sdf.format(swBillManagementPaidDo.getThismeterreadingdate()));
-                listData.add(swBillManagementPaidDo.getLastmeterreading().stripTrailingZeros());
-                listData.add(swBillManagementPaidDo.getThismeterreading().stripTrailingZeros());
-                listData.add(swBillManagementPaidDo.getCurrentwateruse().stripTrailingZeros());
-                listData.add(swBillManagementPaidDo.getUnitprice().stripTrailingZeros());
-                listData.add(swBillManagementPaidDo.getOughttohavepaid().stripTrailingZeros());
-                listData.add(swBillManagementPaidDo.getFeewaiver().stripTrailingZeros());
-                listData.add(swBillManagementPaidDo.getLatefees().stripTrailingZeros());
+                listData.add(swBillManagementPaidDo.getLastmeterreading().stripTrailingZeros().toPlainString());
+                listData.add(swBillManagementPaidDo.getThismeterreading().stripTrailingZeros().toPlainString());
+                listData.add(swBillManagementPaidDo.getCurrentwateruse().stripTrailingZeros().toPlainString());
+                listData.add(swBillManagementPaidDo.getUnitprice().stripTrailingZeros().toPlainString());
+                listData.add(swBillManagementPaidDo.getOughttohavepaid().stripTrailingZeros().toPlainString());
+                listData.add(swBillManagementPaidDo.getFeewaiver().stripTrailingZeros().toPlainString());
+                listData.add(swBillManagementPaidDo.getLatefees().stripTrailingZeros().toPlainString());
             }
             listData.add(NumberToChineseUppercaseUtils.convert(swBillingRecordDo.getPaidin()));
             listData.add(swBillingRecordDo.getPaidin());

+ 42 - 12
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwCollectionNoticeServiceImpl.java

@@ -1,8 +1,8 @@
 package com.rongwei.zhsw.system.service.impl;
 
-import com.aspose.words.ImportFormatMode;
-import com.aspose.words.SaveFormat;
+import com.aspose.words.*;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.google.common.collect.Lists;
 import com.rongwe.zhsw.system.domain.SwBusinesshallDo;
 import com.rongwe.zhsw.system.domain.SwEnterpriseConfigInfoDo;
 import com.rongwei.rwcommon.base.BaseDo;
@@ -14,6 +14,7 @@ import com.rongwei.zhsw.system.service.SwCollectionNoticeService;
 import com.rongwei.zhsw.system.service.SwEnterpriseConfigInfoService;
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.Units;
+import org.apache.poi.xwpf.usermodel.BreakType;
 import org.apache.poi.xwpf.usermodel.*;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
 import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.*;
@@ -28,6 +29,7 @@ import org.springframework.stereotype.Service;
 import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.text.SimpleDateFormat;
+import java.util.List;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -318,12 +320,13 @@ public class SwCollectionNoticeServiceImpl implements SwCollectionNoticeService
         }
     }
 
+
     @Override
     public void generatePdf(List<Map<String, String>> dataList, HttpServletResponse response) {
 
         SwEnterpriseConfigInfoDo swEnterpriseConfigInfoDo = swEnterpriseConfigInfoService.getOne(new LambdaQueryWrapper<SwEnterpriseConfigInfoDo>()
-                .eq(BaseDo::getDeleted,"0"));
-        if(swEnterpriseConfigInfoDo==null){
+                .eq(BaseDo::getDeleted, "0"));
+        if (swEnterpriseConfigInfoDo == null) {
             throw new CustomException("无法获取企业配置信息");
         }
         String tempName = swEnterpriseConfigInfoDo.getTempName();
@@ -338,7 +341,7 @@ public class SwCollectionNoticeServiceImpl implements SwCollectionNoticeService
         String addresStr = list.stream().map(data -> data.getAddress()).collect(Collectors.joining("\n"));
 
         ClassPathResource classPathResource = new ClassPathResource("temp/" + tempName);
-        try(InputStream templateStream = classPathResource.getInputStream()) {
+        try (InputStream templateStream = classPathResource.getInputStream()) {
             Date now = new Date();
             Calendar instance = Calendar.getInstance();
             instance.setTime(now);
@@ -346,17 +349,35 @@ public class SwCollectionNoticeServiceImpl implements SwCollectionNoticeService
             SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
             String dateStr = formatter.format(instance.getTime());
             String nowStr = formatter.format(now);
-            // 模板
-            com.aspose.words.Document temp = new com.aspose.words.Document(templateStream);
+
             // 合并的word
             com.aspose.words.Document mergedDoc = null;
 
-            for (Map<String, String> dataMapp : dataList) {
+            com.aspose.words.Document temp = new com.aspose.words.Document(templateStream);
+            List<List<Map<String, String>>> partition = Lists.partition(dataList, 2);
+            Map<String, String> secondMap;
+            for (List<Map<String, String>> dataMapp : partition) {
                 com.aspose.words.Document currentDoc = temp.deepClone(); // 深拷贝模板
-                currentDoc.getMailMerge().execute(new String[]{"USERNAME", "USERNUMBER", "YEAR", "QYMC", "RQ","sfdt"},
-                        new Object[]{dataMapp.getOrDefault("USERNAME", ""),
-                                dataMapp.getOrDefault("USERNUMBER", ""), dateStr,
-                                swEnterpriseConfigInfoDo.getEnterprisename(), nowStr,addresStr});
+                Map<String, String> firstMap = dataMapp.get(0);
+
+                if (dataMapp.size() > 1) {
+                    secondMap = dataMapp.get(1);
+                } else {
+                    secondMap = new HashMap<>();
+                }
+                currentDoc.getMailMerge().execute(new String[]{"USERNAME", "USERNUMBER", "YEAR", "QYMC", "RQ", "sfdt", "GZHMC",
+                                "USERNAME2", "USERNUMBER2",
+                        },
+                        new Object[]{firstMap.getOrDefault("USERNAME", ""),
+                                firstMap.getOrDefault("USERNUMBER", ""), dateStr,
+                                swEnterpriseConfigInfoDo.getEnterprisename(), nowStr, addresStr,
+                                swEnterpriseConfigInfoDo.getGzhmc(),
+                                secondMap.getOrDefault("USERNAME", ""),
+                                secondMap.getOrDefault("USERNUMBER", "")
+                        });
+                currentDoc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);
+                currentDoc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_TABLE_ROWS);
+                currentDoc.getMailMerge().deleteFields();
                 if (mergedDoc == null) {
                     mergedDoc = currentDoc;
                 } else {
@@ -370,6 +391,15 @@ public class SwCollectionNoticeServiceImpl implements SwCollectionNoticeService
             // for (com.aspose.words.Document doc : docList) {
             //     finalDoc.appendDocument(doc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
             // }
+            // SaveOptions options = new PdfSaveOptions();
+            // options.setSaveFormat(com.aspose.words.SaveFormat.PDF);
+            // 删除所有分页符
+            NodeCollection<Paragraph> pageBreaks = mergedDoc.getChildNodes(NodeType.PARAGRAPH, true);
+            for (Paragraph para : pageBreaks) {
+                if (para.getParagraphFormat().getPageBreakBefore()) {
+                    para.getParagraphFormat().setPageBreakBefore(false);
+                }
+            }
 
             response.setContentType("application/octet-stream;charset=ISO8859-1");
             response.setHeader("Content-Disposition", "inline; filename=");

+ 2 - 0
zhsw-entity/src/main/java/com/rongwe/zhsw/system/domain/SwEnterpriseConfigInfoDo.java

@@ -129,4 +129,6 @@ public class SwEnterpriseConfigInfoDo extends BaseDo implements Serializable {
     private String tempName;
 
     private int notificationdays;
+
+    private String gzhmc;
 }

二进制
zhsw-server/src/main/resources/temp/徐州大吴水务催缴单.docx