Browse Source

feature 票据打印数据获取

xiahan 4 months ago
parent
commit
b637aa78e1

+ 15 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/PrintService.java

@@ -0,0 +1,15 @@
+package com.rongwei.zhsw.system.service;
+
+import com.rongwei.rwcommon.base.R;
+
+import java.util.List;
+
+/**
+ * PrintService class
+ *
+ * @author XH
+ * @date 2025/03/20
+ */
+public interface PrintService {
+    R printReceipt(List<String> ids);
+}

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

@@ -0,0 +1,118 @@
+package com.rongwei.zhsw.system.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.rongwe.zhsw.system.domain.SwBillManagementPaidDo;
+import com.rongwe.zhsw.system.domain.SwBillingRecordDo;
+import com.rongwe.zhsw.system.domain.SwUserManagementDo;
+import com.rongwe.zhsw.system.vo.PrintReceiptVo;
+import com.rongwei.rwcommon.base.BaseDo;
+import com.rongwei.rwcommon.base.R;
+import com.rongwei.rwcommon.base.exception.CustomException;
+import com.rongwei.zhsw.system.service.PrintService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static com.rongwei.zhsw.system.utils.SaveConstans.billReccord.FULLREFUNDSTATUS;
+
+/**
+ * PrintServiceImpl class
+ *
+ * @author XH
+ * @date 2025/03/20
+ */
+@Slf4j
+@Service
+public class PrintServiceImpl implements PrintService {
+    @Autowired
+    private SwBillingRecordServiceImpl swBillingRecordService;
+    @Autowired
+    private SwUserManagementServiceImpl swUserManagementService;
+    @Autowired
+    private SwBillManagementPaidServiceImpl swBillManagementPaidService;
+
+    @Override
+    public R printReceipt(List<String> ids) {
+        if (ids == null || ids.isEmpty()) {
+            throw new CustomException("参数异常");
+        }
+        List<SwBillingRecordDo> swBillingRecordDos = swBillingRecordService.getBaseMapper().selectBatchIds(ids);
+        if (swBillingRecordDos.isEmpty()) {
+            throw new CustomException("无法找到开票记录信息");
+        }
+        boolean b = swBillingRecordDos.stream().anyMatch(data -> FULLREFUNDSTATUS.equals(data.getPayfeesstatus()));
+        if (b) {
+            throw new CustomException("存在全额退款记录,不可打印票据");
+        }
+        // 户号
+        List<String> accountList = swBillingRecordDos.stream().map(SwBillingRecordDo::getUsernumber).collect(Collectors.toList());
+        // 用户信息
+        List<SwUserManagementDo> swUserManagementDos = swUserManagementService.list(new LambdaQueryWrapper<SwUserManagementDo>()
+                .eq(BaseDo::getDeleted, "0")
+                .in(SwUserManagementDo::getUsernumber, accountList));
+        // 获取缴费记录对应的账单信息
+        List<SwBillManagementPaidDo> managementPaidDos = swBillManagementPaidService.list(new LambdaQueryWrapper<SwBillManagementPaidDo>()
+                .eq(SwBillManagementPaidDo::getDeleted, "0")
+                .in(SwBillManagementPaidDo::getUsernumber, accountList)
+                .in(SwBillManagementPaidDo::getPaymentrecordid, ids));
+        List<PrintReceiptVo> receiptVoList = new ArrayList<>();
+        Date date = new Date();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        String dateStr = sdf.format(date);
+        // 生成票据导出所需要的数据
+        PrintReceiptVo printReceiptVo;
+        // 用户信息
+        SwUserManagementDo swUserManagementDo;
+        // 用水信息
+        PrintReceiptVo.WaterUsageInfo waterUsageInfo;
+
+        // 账单信息
+        List<SwBillManagementPaidDo> swBillManagementPaidDoList;
+        for (SwBillingRecordDo swBillingRecordDo : swBillingRecordDos) {
+            printReceiptVo = new PrintReceiptVo();
+            swUserManagementDo = swUserManagementDos.stream()
+                    .filter(data -> data.getUsernumber().equals(swBillingRecordDo.getUsernumber()))
+                    .findFirst()
+                    .orElse(null);
+            if (swUserManagementDo == null) {
+                log.error("户号:{}不存在", swBillingRecordDo.getUsernumber());
+                throw new CustomException("以下户号: " + swBillingRecordDo.getUsernumber() + "不存在");
+            }
+            printReceiptVo.setPrintDateStr(dateStr);
+            printReceiptVo.setAccount(swUserManagementDo.getUsernumber());
+            printReceiptVo.setName(swUserManagementDo.getUsername());
+            printReceiptVo.setUserType(swUserManagementDo.getUsertype());
+            printReceiptVo.setAddress(swUserManagementDo.getAddress());
+            printReceiptVo.setBalance(swUserManagementDo.getAccountbalance().stripTrailingZeros());
+            swBillManagementPaidDoList = managementPaidDos.stream()
+                    .filter(info -> swBillingRecordDo.getId().equals(info.getPaymentrecordid()) &&
+                    swBillingRecordDo.getUsernumber().equals(info.getUsernumber()))
+                    .sorted(Comparator.comparing(SwBillManagementPaidDo::getThismeterreadingdate))
+                    .collect(Collectors.toList());
+            List<PrintReceiptVo.WaterUsageInfo> waterUsageInfoList = new ArrayList<>();
+            for (SwBillManagementPaidDo swBillManagementPaidDo : swBillManagementPaidDoList) {
+                // 账单对应的用水信息
+                waterUsageInfo = new PrintReceiptVo.WaterUsageInfo();
+                waterUsageInfo.setMeterReadingDate(sdf.format(swBillManagementPaidDo.getThismeterreadingdate()));
+                waterUsageInfo.setPreviousReading(swBillManagementPaidDo.getLastmeterreading().stripTrailingZeros());
+                waterUsageInfo.setCurrentReading(swBillManagementPaidDo.getThismeterreading().stripTrailingZeros());
+                waterUsageInfo.setWaterUsage(swBillManagementPaidDo.getCurrentwateruse().stripTrailingZeros());
+                waterUsageInfo.setUnitPrice(swBillManagementPaidDo.getUnitprice().stripTrailingZeros());
+                waterUsageInfo.setTotalPrice(swBillManagementPaidDo.getOughttohavepaid().stripTrailingZeros());
+                waterUsageInfo.setReliefAmount(swBillManagementPaidDo.getFeewaiver().stripTrailingZeros());
+                waterUsageInfo.setPenalty(swBillManagementPaidDo.getLatefees().stripTrailingZeros());
+                waterUsageInfoList.add(waterUsageInfo);
+            }
+            printReceiptVo.setWaterUsageInfos(waterUsageInfoList);
+            receiptVoList.add(printReceiptVo);
+        }
+        return R.ok(receiptVoList);
+    }
+}

+ 1 - 1
zhsw-entity/src/main/java/com/rongwe/zhsw/system/domain/SwUserWechatDo.java

@@ -56,7 +56,7 @@ public class SwUserWechatDo  extends BaseDo {
     /**
      * 当前unionid对应的手机号
      */
-    private Integer phone;
+    private String phone;
 
     /**
      * 当前户主所属的分组(,逗号分隔)

+ 51 - 0
zhsw-entity/src/main/java/com/rongwe/zhsw/system/vo/PrintReceiptVo.java

@@ -0,0 +1,51 @@
+package com.rongwe.zhsw.system.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * PrintReceiptVo class
+ *
+ * @author XH
+ * @date 2025/03/20
+ */
+@Data
+public class PrintReceiptVo {
+    // 开票日期
+    private String printDateStr;
+    // 户号
+    private String account;
+    // 户名
+    private String name;
+    // 用户类型
+    private String userType;
+    // 地址
+    private String address;
+    // BigDecimal
+    private BigDecimal balance;
+
+    private List<WaterUsageInfo> waterUsageInfos;
+
+    @Data
+    public  static class WaterUsageInfo{
+        // 抄表日期
+        private String meterReadingDate;
+        // 上次读数
+        private BigDecimal previousReading;
+        //本次读数
+        private BigDecimal currentReading;
+        // 用水量
+        private BigDecimal waterUsage;
+        // 单价
+        private BigDecimal unitPrice;
+        // 金额
+        private BigDecimal totalPrice;
+        // 减免金额
+        private BigDecimal reliefAmount;
+        // 违约金
+        private BigDecimal penalty;
+    }
+
+}

+ 39 - 0
zhsw-server/src/main/java/com/rongwei/zhsw/system/controller/PrintController.java

@@ -0,0 +1,39 @@
+package com.rongwei.zhsw.system.controller;
+
+import com.rongwei.rwcommon.base.R;
+import com.rongwei.zhsw.system.service.impl.PrintServiceImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * PrintController class
+ *
+ * @author XH
+ * @date 2025/03/20
+ */
+@RestController
+@RequestMapping("/print")
+public class PrintController {
+    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
+
+    @Autowired
+    private PrintServiceImpl printService;
+
+    /**
+     * 打印缴费单据所需要的数据
+     *
+     * @param ids
+     * @return
+     */
+    @PostMapping("/receipt")
+    private R receipt(@RequestBody List<String> ids){
+        return printService.printReceipt(ids);
+    }
+}