소스 검색

feature 事务注解失效的问题

xiahan 3 주 전
부모
커밋
fa6d434abc

+ 1 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/config/TtlThreadPoolConfig.java

@@ -29,6 +29,7 @@ public class TtlThreadPoolConfig {
         executor.setTaskDecorator(new TtlTaskDecorator());
         // executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
         executor.initialize();
+        executor.setWaitForTasksToCompleteOnShutdown(true);
         return executor;
     }
 

+ 1 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/MeterReadingServiceImpl.java

@@ -68,6 +68,7 @@ public class MeterReadingServiceImpl implements MeterReadingService {
                     .eq(SwUserManagementDo::getUsernumber,userNumber)
                     .set(SwUserManagementDo::getLastmeterreaddate,swWaterUsageEntryDo.getLastreadingdate())
                     .set(SwUserManagementDo::getLastmeterreading,swWaterUsageEntryDo.getLastreading()));
+            swWaterUsageEntryService.removeById(id);
             return R.ok("该抄表记录已删除");
         }
         // 未缴账单

+ 3 - 59
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwBillManagementUnpaidServiceImpl.java

@@ -50,14 +50,14 @@ public class SwBillManagementUnpaidServiceImpl extends ServiceImpl<SwBillManagem
     @Autowired
     SwBillManagementUnpaidService swBillManagementUnpaidService;
 
-    @Autowired
-    SwBillManagementPaidServiceImpl swBillManagementPaidService;
 
     @Autowired
     SwMeterReadingCorrectionService swMeterReadingCorrectionService;
 
     @Autowired
     private SwBillingRecordServiceImpl swBillingRecordService;
+    @Autowired
+    private TransactionControlServiceImpl transactionControlService;
 
 
     private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
@@ -133,7 +133,6 @@ public class SwBillManagementUnpaidServiceImpl extends ServiceImpl<SwBillManagem
      * @return
      */
     @Override
-    @Transactional
     public R transferAccount(Map<String, Object> map) {
         try {
             long startTime = System.currentTimeMillis();
@@ -153,7 +152,7 @@ public class SwBillManagementUnpaidServiceImpl extends ServiceImpl<SwBillManagem
             processUserBills(billGroups, userGroups, transferAccountDo, currentUser, swBillingRecordDoList);
             log.info("账单数据处理耗时: {}ms,生成的账单数量为:{}",  System.currentTimeMillis() - startTime, billGroups.size());
             // 保存处理结果
-            saveProcessedData(transferAccountDo, swBillingRecordDoList);
+            transactionControlService.saveProcessedData(transferAccountDo, swBillingRecordDoList);
 
         } catch (Exception e) {
             log.error("转正式账单数据保存失败 {}", e.getMessage());
@@ -382,60 +381,5 @@ public class SwBillManagementUnpaidServiceImpl extends ServiceImpl<SwBillManagem
 
     }
 
-    /**
-     * 保存数据
-     *
-     * @param transferAccountDo
-     */
-    public void saveProcessedData(TransferAccountDo transferAccountDo, List<SwBillingRecordDo> swBillingRecordDoList) {
-        /**
-         *  缴费记录 生成
-         */
-        long startTime = System.currentTimeMillis();
-        if (!swBillingRecordDoList.isEmpty()) {
-            for (List<SwBillingRecordDo> swBillingRecordDos : Lists.partition(swBillingRecordDoList, 5000)) {
-                swBillingRecordService.getBaseMapper().insertBatchSomeColumn(swBillingRecordDos);
-            }
-        }
-        log.error("数据1保存耗时: {}ms",  System.currentTimeMillis() - startTime);
-        startTime = System.currentTimeMillis();
-        //转正式账单生成
-        if (!transferAccountDo.getOfficeIds().isEmpty()) {
-            swBillManagementUnpaidService.update(new LambdaUpdateWrapper<SwBillManagementUnpaidDo>().in(SwBillManagementUnpaidDo::getId, transferAccountDo.getOfficeIds()).set(SwBillManagementUnpaidDo::getStatus, PENDINGSTATUS));
-        }
-        log.error("数据2保存耗时: {}ms",  System.currentTimeMillis() - startTime);
-        startTime = System.currentTimeMillis();
-        List<String> delUnpaidIds = transferAccountDo.getDelUnpaidIds();
-        //删除 待收账单数据
-        if (!delUnpaidIds.isEmpty()) {
-            List<List<String>> partition = Lists.partition(delUnpaidIds, 5000);
-            for (List<String> datas : partition) {
-                swBillingRecordService.deleteUnpaidBills(datas);
-            }
-        }
-        log.error("数据3保存耗时: {}ms",  System.currentTimeMillis() - startTime);
-        startTime = System.currentTimeMillis();
-        //生成已缴费账单
-        if (!transferAccountDo.getPaidDoList().isEmpty()) {
-            for (List<SwBillManagementPaidDo> managementPaidDos : Lists.partition(transferAccountDo.getPaidDoList(), 5000)) {
-                swBillManagementPaidService.getBaseMapper().insertBatchSomeColumn(transferAccountDo.getPaidDoList());
-            }
-        }
-        log.error("数据4保存耗时: {}ms",  System.currentTimeMillis() - startTime);
-        startTime = System.currentTimeMillis();
-        // 更新 用户余额
-        if (!transferAccountDo.getUserBalanceList().isEmpty()) {
-            swUserManagementService.batchUpdateUserBalances(transferAccountDo.getUserBalanceList());
-        }
-        log.error("数据5保存耗时: {}ms",  System.currentTimeMillis() - startTime);
-        startTime = System.currentTimeMillis();
-        //生成缴费
-        if (!transferAccountDo.getRecordDoList().isEmpty()) {
-            for (List<SwBillingRecordDo> swBillingRecordDos : Lists.partition(transferAccountDo.getRecordDoList(), 5000)) {
-                swBillingRecordService.getBaseMapper().insertBatchSomeColumn(swBillingRecordDos);
-            }
 
-        }
-        log.error("数据6保存耗时: {}ms",  System.currentTimeMillis() - startTime);
-    }
 }

+ 33 - 57
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwBillingRecordServiceImpl.java

@@ -24,7 +24,6 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.security.SecureRandom;
@@ -61,6 +60,8 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
 
     @Autowired
     private RedisServiceImpl redisService;
+    @Autowired
+    private TransactionControlServiceImpl transactionControlService;
 
 
     private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
@@ -74,29 +75,22 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
      * @throws Exception
      */
     @Override
-    @Transactional
-    public R windowPayment(PaymentRequestDTO paymentRequestDTO)  {
-        String billRecordId="";
+    public R windowPayment(PaymentRequestDTO paymentRequestDTO) {
+        String billRecordId = "";
         try {
             log.info("窗口缴费开始");
             if (paymentRequestDTO.getIds() != null && !paymentRequestDTO.getIds().isEmpty()) {
-
                 // 查询待缴费账单
                 List<SwBillManagementUnpaidDo> unpaidBills = queryUnpaidBills(paymentRequestDTO.getIds());
-
                 //生成缴费记录
-                billRecordId=  addNewBillRecord(paymentRequestDTO, unpaidBills);
-
+                billRecordId = addNewBillRecord(paymentRequestDTO, unpaidBills);
             } else {
-
                 //生成缴费记录
-                billRecordId=  addNewBillRecord(paymentRequestDTO, new ArrayList<>());
+                billRecordId = addNewBillRecord(paymentRequestDTO, new ArrayList<>());
             }
-
             log.info("窗口缴费结束");
-
-        }catch (Exception e){
-            e.printStackTrace();
+        } catch (Exception e) {
+            log.error("窗口缴费失败 - 原因: {} | 异常类型: {}", e.getMessage(), e.getClass().getSimpleName(), e);
             return R.error("窗口缴费失败");
         }
         R ok = R.ok();
@@ -106,6 +100,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
 
     /**
      * 删除
+     *
      * @param id
      * @return
      */
@@ -174,8 +169,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
      *
      * @return
      */
-    private String addNewBillRecord(PaymentRequestDTO paymentRequestDTO, List<SwBillManagementUnpaidDo> list)
-    {
+    public String addNewBillRecord(PaymentRequestDTO paymentRequestDTO, List<SwBillManagementUnpaidDo> list) {
 
         SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
 
@@ -205,8 +199,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
         }
 
         // 保存处理结果
-        saveProcessedData(billingRecordDo, user, bills, paymentRequestDTO.getIds());
-
+        transactionControlService.saveProcessedData(billingRecordDo, user, bills, paymentRequestDTO.getIds());
         return billingRecordDo.getId();
     }
 
@@ -219,22 +212,6 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
      * @param ids
      */
 
-    public void saveProcessedData(SwBillingRecordDo billingRecordDo, SwUserManagementDo user, List<SwBillManagementPaidDo> bills, List<String> ids) {
-        //账单缴费记录生成
-        this.baseMapper.insert(billingRecordDo);
-        //已缴费账单生成
-        if (!bills.isEmpty()) {
-            swBillManagementPaidService.saveBatch(bills);
-        }
-        if (ids != null && !ids.isEmpty()) {
-            //删除 待收账单数据
-            deleteUnpaidBills(ids);
-        }
-
-        //更新用户余额
-        updateUserBalance(billingRecordDo, user);
-
-    }
 
     public List<SwBillManagementPaidDo> createBills(List<SwBillManagementUnpaidDo> list, SwBillingRecordDo add) {
         if (list == null || list.isEmpty()) {
@@ -250,8 +227,8 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
             paid.setStatus(PAIDINSTATUS)
                     //缴费记录ID
                     .setPaymentrecordid(add.getId())
-                            .setPaymentdate(now);
-       //     ZHSWCommonUtils.initModelGeneralParameters(paid, null);
+                    .setPaymentdate(now);
+            //     ZHSWCommonUtils.initModelGeneralParameters(paid, null);
             paid.setDeleted("0");
             paid.setCreatedate(now);
             paid.setCreateuserid(unpaid.getCreateuserid());
@@ -275,7 +252,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
     private void updateUserBalance(SwBillingRecordDo add, SwUserManagementDo user) {
         BigDecimal balanceChange = add.getAfterpaymentbalance().subtract(user.getAccountbalance());
         log.debug("开始更新当前用户的余额信息!用户:{}的原余额为:{},缴费金额为:{},实际应缴为:{},金额变化:{}", user.getUsernumber(),
-                user.getAccountbalance(),add.getPaidin(),add.getActualdue(),balanceChange);
+                user.getAccountbalance(), add.getPaidin(), add.getActualdue(), balanceChange);
         swUserManagementService.balanceAdd(user.getId(), balanceChange);
     }
 
@@ -300,7 +277,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
         BigDecimal totalOught = BigDecimal.ZERO;
         // 实际的滞纳金
         BigDecimal totalLateFees = BigDecimal.ZERO;
-        BigDecimal actualAmount=BigDecimal.ZERO;
+        BigDecimal actualAmount = BigDecimal.ZERO;
         /**
          * 开始进行账单的余额划扣逻辑
          * 按照抄表日期对账单从
@@ -314,48 +291,47 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
             BigDecimal currentLateFeeAmount = swBillManagementUnpaidDo.getLatefees();
             // 实际等于=原应缴+滞纳金-减免金额
             BigDecimal currentActualAmount = swBillManagementUnpaidDo.getActualdue();
-            actualAmount=actualAmount.add(currentActualAmount);
+            actualAmount = actualAmount.add(currentActualAmount);
             // 求和实际减免
-            totalWaivers= totalWaivers.add(currentReductionAmount.compareTo(currentPayableAmount.add(currentLateFeeAmount))>0?
-                    currentPayableAmount.add(currentLateFeeAmount):currentReductionAmount);
+            totalWaivers = totalWaivers.add(currentReductionAmount.compareTo(currentPayableAmount.add(currentLateFeeAmount)) > 0 ?
+                    currentPayableAmount.add(currentLateFeeAmount) : currentReductionAmount);
             // 滞纳金求和
-            totalLateFees=totalLateFees.add(currentLateFeeAmount);
+            totalLateFees = totalLateFees.add(currentLateFeeAmount);
             // 原应缴
-            totalOught= totalOught.add(currentPayableAmount);
+            totalOught = totalOught.add(currentPayableAmount);
 
             // 实缴小于等于0
-            if(currentActualAmount.compareTo(BigDecimal.ZERO)<=0){
+            if (currentActualAmount.compareTo(BigDecimal.ZERO) <= 0) {
                 swBillManagementUnpaidDo.setBalancedebitamount(BigDecimal.ZERO);
-            }else {
+            } else {
                 // 优先使用余额划扣
-                if(accountbalance.compareTo(BigDecimal.ZERO)>0){
-                    if(accountbalance.compareTo(currentActualAmount)>=0){
+                if (accountbalance.compareTo(BigDecimal.ZERO) > 0) {
+                    if (accountbalance.compareTo(currentActualAmount) >= 0) {
                         // 账户余额大于等于本次实缴
                         swBillManagementUnpaidDo.setBalancedebitamount(currentActualAmount);
-                        accountbalance=accountbalance.subtract(currentActualAmount);
-                        currentActualAmount=BigDecimal.ZERO;
-                    }else{
+                        accountbalance = accountbalance.subtract(currentActualAmount);
+                        currentActualAmount = BigDecimal.ZERO;
+                    } else {
                         // 账户余额小于本次实缴
                         swBillManagementUnpaidDo.setBalancedebitamount(accountbalance);
                         // 修改本次实缴
-                        currentActualAmount=currentActualAmount.subtract(accountbalance);
-                        accountbalance=BigDecimal.ZERO;
+                        currentActualAmount = currentActualAmount.subtract(accountbalance);
+                        accountbalance = BigDecimal.ZERO;
                     }
                 }
                 // 余额划扣结束且本次实际应缴大于0时 使用缴费金额 扣除
-                if(currentActualAmount.compareTo(BigDecimal.ZERO)>0){
-                    paidin=paidin.subtract(currentActualAmount);
+                if (currentActualAmount.compareTo(BigDecimal.ZERO) > 0) {
+                    paidin = paidin.subtract(currentActualAmount);
                 }
             }
         }
         // 如果本次账单划扣结束后 实缴金额小于0 则用户缴费金额小于实际划扣金额
-        if(paidin.compareTo(BigDecimal.ZERO)<0){
+        if (paidin.compareTo(BigDecimal.ZERO) < 0) {
             log.error("用户缴费金额小于等于实缴金额");
-            throw new CustomException("户号:"+user.getUsernumber()+"的缴费金额小于实际应缴金额");
+            throw new CustomException("户号:" + user.getUsernumber() + "的缴费金额小于实际应缴金额");
         }
 
 
-
         //总减免
         billingRecordDo.setAllfeewaiver(totalWaivers);
         //原应缴

+ 1 - 1
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwRefundRequestRecordServiceImpl.java

@@ -112,7 +112,7 @@ public class SwRefundRequestRecordServiceImpl extends ServiceImpl<SwRefundReques
         swRefundRequestRecordService.update(lambdaUpdateWrapper);
     }
 
-    @Transactional(propagation = Propagation.REQUIRES_NEW)
+
     public void processRefundFailed(SwRefundRequestRecordDO refundRequestRecordDO, SysUserVo currentUser,  String refundstatus) {
         // 退款记录表更新 实退金额 退款操作人,操作时间
         swRefundRequestRecordService.update(new LambdaUpdateWrapper<SwRefundRequestRecordDO>()

+ 151 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/TransactionControlServiceImpl.java

@@ -0,0 +1,151 @@
+package com.rongwei.zhsw.system.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.google.common.collect.Lists;
+import com.rongwe.zhsw.system.domain.SwBillManagementPaidDo;
+import com.rongwe.zhsw.system.domain.SwBillManagementUnpaidDo;
+import com.rongwe.zhsw.system.domain.SwBillingRecordDo;
+import com.rongwe.zhsw.system.domain.SwUserManagementDo;
+import com.rongwe.zhsw.system.dto.TransferAccountDo;
+import com.rongwei.zhsw.system.dao.SwBillingRecordDao;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static com.rongwei.zhsw.system.utils.SaveConstans.billInfo.PENDINGSTATUS;
+
+/**
+ * TransactionControlServiceImpl class
+ *
+ * @author XH
+ * @date 2025/07/12
+ */
+@Service
+public class TransactionControlServiceImpl {
+    @Autowired
+    private SwBillingRecordDao swBillingRecordDao;
+    @Autowired
+    private SwBillManagementPaidServiceImpl swBillManagementPaidService;
+    @Autowired
+    private SwBillManagementUnpaidServiceImpl swBillManagementUnpaidService;
+    @Autowired
+    private SwUserManagementServiceImpl swUserManagementService;
+    @Autowired
+    private SwBillingRecordServiceImpl swBillingRecordService;
+
+    private static final Logger log = LoggerFactory.getLogger(TransactionControlServiceImpl.class);
+
+    /**
+     * 生成缴费记录已经更新用户余额
+     *
+     * @param billingRecordDo
+     * @param user
+     * @param bills
+     * @param ids
+     */
+    @Transactional
+    public void saveProcessedData(SwBillingRecordDo billingRecordDo, SwUserManagementDo user, List<SwBillManagementPaidDo> bills, List<String> ids) {
+        //账单缴费记录生成
+        swBillingRecordDao.insert(billingRecordDo);
+        //已缴费账单生成
+        if (!bills.isEmpty()) {
+            swBillManagementPaidService.saveBatch(bills);
+        }
+        if (ids != null && !ids.isEmpty()) {
+            //删除 待收账单数据
+            swBillManagementUnpaidService.getBaseMapper().deleteByIds(ids);
+        }
+
+        //更新用户余额
+        BigDecimal balanceChange = billingRecordDo.getAfterpaymentbalance().subtract(user.getAccountbalance());
+        log.debug("开始更新当前用户的余额信息!用户:{}的原余额为:{},缴费金额为:{},实际应缴为:{},金额变化:{}", user.getUsernumber(),
+                user.getAccountbalance(), billingRecordDo.getPaidin(), billingRecordDo.getActualdue(), balanceChange);
+        swUserManagementService.balanceAdd(user.getId(), balanceChange);
+
+    }
+
+    /**
+     * 转正式账单
+     *
+     * @param transferAccountDo
+     * @param swBillingRecordDoList
+     */
+    @Transactional
+    public void saveProcessedData(TransferAccountDo transferAccountDo, List<SwBillingRecordDo> swBillingRecordDoList) {
+        /**
+         *  缴费记录 生成
+         */
+        long startTime = System.currentTimeMillis();
+        if (!swBillingRecordDoList.isEmpty()) {
+            for (List<SwBillingRecordDo> swBillingRecordDos : Lists.partition(swBillingRecordDoList, 5000)) {
+                swBillingRecordService.getBaseMapper().insertBatchSomeColumn(swBillingRecordDos);
+            }
+        }
+        log.error("数据1保存耗时: {}ms", System.currentTimeMillis() - startTime);
+        startTime = System.currentTimeMillis();
+        //转正式账单生成
+        if (!transferAccountDo.getOfficeIds().isEmpty()) {
+            swBillManagementUnpaidService.update(new LambdaUpdateWrapper<SwBillManagementUnpaidDo>().in(SwBillManagementUnpaidDo::getId, transferAccountDo.getOfficeIds()).set(SwBillManagementUnpaidDo::getStatus, PENDINGSTATUS));
+        }
+        log.error("数据2保存耗时: {}ms", System.currentTimeMillis() - startTime);
+        startTime = System.currentTimeMillis();
+        List<String> delUnpaidIds = transferAccountDo.getDelUnpaidIds();
+        //删除 待收账单数据
+        if (!delUnpaidIds.isEmpty()) {
+            List<List<String>> partition = Lists.partition(delUnpaidIds, 5000);
+            for (List<String> datas : partition) {
+                swBillingRecordService.deleteUnpaidBills(datas);
+            }
+        }
+        log.error("数据3保存耗时: {}ms", System.currentTimeMillis() - startTime);
+        startTime = System.currentTimeMillis();
+        //生成已缴费账单
+        if (!transferAccountDo.getPaidDoList().isEmpty()) {
+            for (List<SwBillManagementPaidDo> managementPaidDos : Lists.partition(transferAccountDo.getPaidDoList(), 5000)) {
+                swBillManagementPaidService.getBaseMapper().insertBatchSomeColumn(managementPaidDos);
+            }
+        }
+        log.error("数据4保存耗时: {}ms", System.currentTimeMillis() - startTime);
+        startTime = System.currentTimeMillis();
+        // 更新 用户余额
+        if (!transferAccountDo.getUserBalanceList().isEmpty()) {
+            swUserManagementService.batchUpdateUserBalances(transferAccountDo.getUserBalanceList());
+        }
+        log.error("数据5保存耗时: {}ms", System.currentTimeMillis() - startTime);
+        startTime = System.currentTimeMillis();
+        //生成缴费
+        if (!transferAccountDo.getRecordDoList().isEmpty()) {
+            for (List<SwBillingRecordDo> swBillingRecordDos : Lists.partition(transferAccountDo.getRecordDoList(), 5000)) {
+                swBillingRecordService.getBaseMapper().insertBatchSomeColumn(swBillingRecordDos);
+            }
+
+        }
+        log.error("数据6保存耗时: {}ms", System.currentTimeMillis() - startTime);
+    }
+
+    /**
+     * 数据更新
+     */
+
+    public void dataUpdate(SwBillingRecordDo swBillingRecordDo, SwUserManagementDo swUserManagementDo, List<SwBillManagementPaidDo> bills,
+                           List<SwBillManagementUnpaidDo> unpaidDoList) {
+        BigDecimal balanceChange = swBillingRecordDo.getAfterpaymentbalance().subtract(swUserManagementDo.getAccountbalance());
+        log.debug("开始更新当前用户的余额信息!用户:{}的原余额为:{},缴费金额为:{},实际应缴为:{},金额变化:{}", swUserManagementDo.getUsernumber(),
+                swUserManagementDo.getAccountbalance(), swBillingRecordDo.getPaidin(), swBillingRecordDo.getActualdue(), balanceChange);
+        swUserManagementService.balanceAdd(swUserManagementDo.getId(), balanceChange);
+        swBillingRecordService.save(swBillingRecordDo);
+        if (!bills.isEmpty()) {
+            swBillManagementPaidService.saveBatch(bills);
+        }
+        if (!unpaidDoList.isEmpty()) {
+            swBillManagementUnpaidService.getBaseMapper().deleteByIds(unpaidDoList.stream().map(SwBillManagementUnpaidDo::getId).collect(Collectors.toList()));
+        }
+
+    }
+}

+ 21 - 46
zhsw-common/src/main/java/com/rongwei/zhsw/system/wechat/impl/PaymentRecordServiceImpl.java

@@ -11,10 +11,7 @@ import com.rongwei.rwcommon.base.BaseDo;
 import com.rongwei.rwcommon.base.R;
 import com.rongwei.rwcommon.base.exception.CustomException;
 import com.rongwei.rwcommon.utils.SecurityUtil;
-import com.rongwei.zhsw.system.service.impl.SwBillManagementPaidServiceImpl;
-import com.rongwei.zhsw.system.service.impl.SwBillManagementUnpaidServiceImpl;
-import com.rongwei.zhsw.system.service.impl.SwBillingRecordServiceImpl;
-import com.rongwei.zhsw.system.service.impl.SwUserManagementServiceImpl;
+import com.rongwei.zhsw.system.service.impl.*;
 import com.rongwei.zhsw.system.utils.WeChatUtils;
 import com.rongwei.zhsw.system.wechat.PaymentRecordService;
 import org.apache.commons.lang.StringUtils;
@@ -46,6 +43,9 @@ public class PaymentRecordServiceImpl implements PaymentRecordService {
     @Autowired
     private SwBillManagementUnpaidServiceImpl swBillManagementUnpaidService;
 
+    @Autowired
+    private TransactionControlServiceImpl transactionControlService;
+
     /**
      * 获取缴费记录及其对应的所有账单
      *
@@ -130,59 +130,34 @@ public class PaymentRecordServiceImpl implements PaymentRecordService {
     @Override
     @Transactional
     public R createRecord(CreatePaymentRecordVo createPaymentRecordVo) {
-        try {
-        // 微信的openId
-        String currentWeChatOpenId = WeChatUtils.getCurrentWeChatOpenId();
-        String userNUMBER = createPaymentRecordVo.getUserNumber();
-        if (StringUtils.isBlank(userNUMBER)) {
-            log.error("参数错误,户号为空");
-            throw new CustomException("户号为空");
-        }
-        SwUserManagementDo swUserManagementDo = swUserManagementService.getOne(new LambdaQueryWrapper<SwUserManagementDo>()
-                .eq(SwUserManagementDo::getUsernumber, userNUMBER)
-                .eq(BaseDo::getDeleted, "0"));
-        List<SwBillManagementUnpaidDo> unpaidDoList = new ArrayList<>();
+        String userNumber = createPaymentRecordVo.getUserNumber();
         String zdId = createPaymentRecordVo.getZdId();
-        if (StringUtils.isNotBlank(zdId)) {
-            unpaidDoList = swBillManagementUnpaidService.getBaseMapper().selectBatchIds(Arrays.asList(zdId.split(",")));
-        }
-
-
-
+        try {
+            // 微信的openId
+            String currentWeChatOpenId = WeChatUtils.getCurrentWeChatOpenId();
+            if (StringUtils.isBlank(userNumber)) {
+                log.error("参数错误,户号为空");
+                throw new CustomException("户号为空");
+            }
+            SwUserManagementDo swUserManagementDo = swUserManagementService.getOne(new LambdaQueryWrapper<SwUserManagementDo>()
+                    .eq(SwUserManagementDo::getUsernumber, userNumber)
+                    .eq(BaseDo::getDeleted, "0"));
+            List<SwBillManagementUnpaidDo> unpaidDoList = new ArrayList<>();
+            if (StringUtils.isNotBlank(zdId)) {
+                unpaidDoList = swBillManagementUnpaidService.getBaseMapper().selectBatchIds(Arrays.asList(zdId.split(",")));
+            }
             // 生成缴费记录
             SwBillingRecordDo swBillingRecordDo = generateRecord(swUserManagementDo, unpaidDoList, createPaymentRecordVo.getPaymentAmount(),
                     createPaymentRecordVo.getOrderNo(), currentWeChatOpenId);
             // 待缴账单转为已缴账单
             List<SwBillManagementPaidDo> bills = swBillingRecordService.createBills(unpaidDoList, swBillingRecordDo);
-            dataUpdate(swBillingRecordDo, swUserManagementDo, bills, unpaidDoList);
+            transactionControlService.dataUpdate(swBillingRecordDo, swUserManagementDo, bills, unpaidDoList);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("缴费记录生成失败原因为:{}",e.getMessage());
+            log.error("缴费记录生成失败 户号:{},账单:{},金额:{} - 原因: {} | 异常类型: {}", userNumber, zdId, createPaymentRecordVo.getPaymentAmount(), e.getMessage(), e.getClass().getSimpleName(), e);
         }
-
         return R.ok();
     }
 
-    /**
-     * 数据更新
-     */
-
-    public void dataUpdate(SwBillingRecordDo swBillingRecordDo, SwUserManagementDo swUserManagementDo, List<SwBillManagementPaidDo> bills,
-                           List<SwBillManagementUnpaidDo> unpaidDoList) {
-        BigDecimal balanceChange = swBillingRecordDo.getAfterpaymentbalance().subtract(swUserManagementDo.getAccountbalance());
-        log.debug("开始更新当前用户的余额信息!用户:{}的原余额为:{},缴费金额为:{},实际应缴为:{},金额变化:{}", swUserManagementDo.getUsernumber(),
-                swUserManagementDo.getAccountbalance(),swBillingRecordDo.getPaidin(),swBillingRecordDo.getActualdue(),balanceChange);
-        swUserManagementService.balanceAdd(swUserManagementDo.getId(), balanceChange);
-        swBillingRecordService.save(swBillingRecordDo);
-        if (!bills.isEmpty()) {
-            swBillManagementPaidService.saveBatch(bills);
-        }
-        if (!unpaidDoList.isEmpty()) {
-            swBillManagementUnpaidService.getBaseMapper().deleteByIds(unpaidDoList.stream().map(SwBillManagementUnpaidDo::getId).collect(Collectors.toList()));
-        }
-
-    }
-
 
     public SwBillingRecordDo generateRecord(SwUserManagementDo swUserManagementDo, List<SwBillManagementUnpaidDo> unpaidDoList,
                                             BigDecimal paymentAmount, String orderNo, String openId) {

+ 10 - 4
zhsw-server/src/main/java/com/rongwei/zhsw/system/controller/SwBillingRecordController.java

@@ -3,7 +3,12 @@ package com.rongwei.zhsw.system.controller;
 import com.rongwe.zhsw.system.dto.PaymentRequestDTO;
 import com.rongwei.rwcommon.base.R;
 import com.rongwei.zhsw.system.service.SwBillingRecordService;
-import org.springframework.web.bind.annotation.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+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 javax.annotation.Resource;
 
@@ -21,12 +26,13 @@ public class SwBillingRecordController {
      */
     @Resource
     private SwBillingRecordService swBillingRecordService;
-
+    private static final Logger log = LoggerFactory.getLogger(SwBillingRecordController.class);
 
 
     @PostMapping("/windowPayment")
-    public R windowPayment(@RequestBody PaymentRequestDTO paymentRequestDTO){
-           return  swBillingRecordService.windowPayment(paymentRequestDTO);
+    public R windowPayment(@RequestBody PaymentRequestDTO paymentRequestDto) {
+        log.info("窗口缴费开始参数为:{}", paymentRequestDto);
+        return swBillingRecordService.windowPayment(paymentRequestDto);
     }
 }
 

+ 8 - 17
zhsw-server/src/main/java/com/rongwei/zhsw/system/controller/SwMonthlyMeterReadingRecordController.java

@@ -1,21 +1,15 @@
 package com.rongwei.zhsw.system.controller;
-import com.rongwe.zhsw.system.domain.SwMonthlyMeterReadingRecordDo;
+
 import com.rongwe.zhsw.system.dto.ReceiveMonthlyMeterReadingDTO;
 import com.rongwei.rwcommon.base.R;
-import com.rongwei.rwcommon.base.exception.CustomException;
 import com.rongwei.zhsw.system.service.SwMonthlyMeterReadingRecordService;
-import com.rongwei.zhsw.system.service.SwWaterUsageEntryService;
-import io.protostuff.Request;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
-import javax.validation.Valid;
 import java.util.HashMap;
-import java.util.List;
 
 
 @RestController
@@ -30,24 +24,21 @@ public class SwMonthlyMeterReadingRecordController {
     SwMonthlyMeterReadingRecordService swMonthlyMeterReadingRecordService;
 
     @PostMapping("/receiveMonthlyMeterReading")
-    public R receiveMonthlyMeterReading(
-            @RequestBody ReceiveMonthlyMeterReadingDTO receiveMonthlyMeterReadingDTO,
-            HttpServletRequest request
-    ) throws Exception {
-            log.info("接受抄表数据开始");
-            log.info("入参 {}",receiveMonthlyMeterReadingDTO.toString());
-            return swMonthlyMeterReadingRecordService.receiveMonthlyMeterReading(receiveMonthlyMeterReadingDTO, request);
-
+    public R receiveMonthlyMeterReading(@RequestBody ReceiveMonthlyMeterReadingDTO receiveMonthlyMeterReadingDTO,
+                                        HttpServletRequest request) throws Exception {
+        log.info("接受抄表数据开始");
+        log.info("入参 {}", receiveMonthlyMeterReadingDTO.toString());
+        return swMonthlyMeterReadingRecordService.receiveMonthlyMeterReading(receiveMonthlyMeterReadingDTO, request);
     }
 
 
     @PostMapping("/receiveswbookmanagement")
     @ResponseBody
-    public R receiveswbookmanagement(@RequestBody HashMap<String,String> map, HttpServletRequest request
+    public R receiveswbookmanagement(@RequestBody HashMap<String, String> map, HttpServletRequest request
     ) throws Exception {
         log.info("接受册号数据开始");
 
-            return swMonthlyMeterReadingRecordService.receiveswbookmanagement(map,request);
+        return swMonthlyMeterReadingRecordService.receiveswbookmanagement(map, request);
 
 
     }