|
@@ -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);
|
|
|
+ }
|
|
|
+}
|