Ver código fonte

生成缴费记录 代码优化

huangpeng 4 meses atrás
pai
commit
416b19530d

+ 50 - 48
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/SwBillingRecordServiceImpl.java

@@ -21,7 +21,6 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.security.SecureRandom;
 import java.security.SecureRandom;
@@ -73,47 +72,25 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
     public R windowPayment(PaymentRequestDTO paymentRequestDTO) throws Exception {
     public R windowPayment(PaymentRequestDTO paymentRequestDTO) throws Exception {
 
 
         log.info("窗口缴费开始");
         log.info("窗口缴费开始");
-        if (paymentRequestDTO.getIds()==null || paymentRequestDTO.getIds().isEmpty()){
-            log.debug("无账单缴费");
-            windowPaymentNoBill(paymentRequestDTO);
-        }else {
-            log.debug("有账单缴费");
-            windowPaymentHasBill(paymentRequestDTO);
-        }
-        log.info("窗口缴费结束");
+        if (paymentRequestDTO.getIds()!=null && !paymentRequestDTO.getIds().isEmpty()){
 
 
-        return R.ok();
-    }
+            // 查询待缴费账单
+            List<SwBillManagementUnpaidDo> unpaidBills = queryUnpaidBills(paymentRequestDTO.getIds());
 
 
-    /**
-     * 有账单生成 缴费记录
-     *
-     * @param paymentRequestDTO
-     */
-    private void windowPaymentHasBill(PaymentRequestDTO paymentRequestDTO) {
+            //生成缴费记录
+            addNewBillRecord(paymentRequestDTO,unpaidBills);
+        }else {
 
 
-        List<String> ids = paymentRequestDTO.getIds();
-        if(ids==null || ids.isEmpty()){
-            throw new CustomException("参数异常");
+            //生成缴费记录
+            addNewBillRecord(paymentRequestDTO,null);
         }
         }
-        // 查询待缴费账单
-        List<SwBillManagementUnpaidDo> unpaidBills = queryUnpaidBills(paymentRequestDTO.getIds());
 
 
-        //生成缴费记录
-        addNewBillRecord(paymentRequestDTO,unpaidBills);
+        log.info("窗口缴费结束");
 
 
-        //删除 待收账单数据
-        deleteUnpaidBills(ids);
+        return R.ok();
     }
     }
 
 
-    /**
-     * 无账单生成缴费记录
 
 
-     */
-    private void windowPaymentNoBill(PaymentRequestDTO paymentRequestDTO) {
-        //生成缴费记录
-        addNewBillRecord(paymentRequestDTO,null);
-    }
 
 
     /**
     /**
      * 删除 待收账单数据
      * 删除 待收账单数据
@@ -139,9 +116,11 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
     }
     }
 
 
     // 提取公共字段设置
     // 提取公共字段设置
-    private SwBillingRecordDo buildBaseBillingRecord( PaymentRequestDTO paymentRequestDTO, SysUserVo currentUser, SwUserManagementDo user) {
+    private SwBillingRecordDo buildBaseBillingRecord( SysUserVo currentUser, SwUserManagementDo user) {
         SwBillingRecordDo record = new SwBillingRecordDo();
         SwBillingRecordDo record = new SwBillingRecordDo();
 
 
+        //缴费编号
+        generateBillingNumber(record);
 
 
         return record.setId(SecurityUtil.getUUID())
         return record.setId(SecurityUtil.getUUID())
                 .setChargedate(new Date())
                 .setChargedate(new Date())
@@ -161,8 +140,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
                 .setModifydate(new Date())
                 .setModifydate(new Date())
                 .setModifyuserid(currentUser.getId())
                 .setModifyuserid(currentUser.getId())
                 .setTenantid(currentUser.getTenantid())
                 .setTenantid(currentUser.getTenantid())
-                .setDatasource(paymentRequestDTO.getDatasource())
-                .setPaidin(paymentRequestDTO.getPaidin())
+
                 .setModifyusername(currentUser.getName());
                 .setModifyusername(currentUser.getName());
     }
     }
 
 
@@ -179,37 +157,60 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
 
 
         SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
         SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
 
 
+        List<SwBillManagementPaidDo> bills =new ArrayList<>();
+
         //根据户号获取 用户记录
         //根据户号获取 用户记录
         SwUserManagementDo user = swUserManagementService.getBaseMapper().
         SwUserManagementDo user = swUserManagementService.getBaseMapper().
                 selectOne(new LambdaQueryWrapper<SwUserManagementDo>().eq(SwUserManagementDo::getUsernumber, paymentRequestDTO.getUsernumber()));
                 selectOne(new LambdaQueryWrapper<SwUserManagementDo>().eq(SwUserManagementDo::getUsernumber, paymentRequestDTO.getUsernumber()));
+
         if(user==null){
         if(user==null){
             throw new CustomException("户号不存在");
             throw new CustomException("户号不存在");
         }
         }
 
 
-        SwBillingRecordDo add = buildBaseBillingRecord(paymentRequestDTO,currentUser,user);
-
+        SwBillingRecordDo add = buildBaseBillingRecord(currentUser,user);
 
 
-        // 生成缴费编号
-        generateBillingNumber(add);
+        add.setDatasource(paymentRequestDTO.getDatasource());
+        add.setPaidin(paymentRequestDTO.getPaidin());
 
 
         // 计算费用
         // 计算费用
-        calculateFees(list, add,user);
-
+        calculateFees(list, add, user);
 
 
         if(list!=null){
         if(list!=null){
             //生成已缴费账单
             //生成已缴费账单
-            createBills(list,add,currentUser);
+            bills = createBills(list, add);
+
         }
         }
 
 
+        this.updateOrSaveData(add,user,bills,paymentRequestDTO.getIds());
 
 
+    }
+
+    /**
+     * 存储,修改数据
+     * @param add
+     * @param user
+     * @param bills
+     * @param ids
+     */
+
+    public void updateOrSaveData(SwBillingRecordDo add, SwUserManagementDo user, List<SwBillManagementPaidDo> bills, List<String> ids){
+        //账单缴费记录生成
+        this.baseMapper.insert(add);
+        //已缴费账单生成
+        if (!bills.isEmpty()){
+            swBillManagementPaidService.saveBatch(bills);
+        }
+        if (ids!=null && !ids.isEmpty()){
+            //删除 待收账单数据
+            deleteUnpaidBills(ids);
+        }
 
 
         //更新用户余额
         //更新用户余额
         updateUserBalance(add,user);
         updateUserBalance(add,user);
 
 
-
     }
     }
 
 
-    private void createBills(List<SwBillManagementUnpaidDo> list, SwBillingRecordDo add, SysUserVo currentUser) {
+    private List<SwBillManagementPaidDo> createBills(List<SwBillManagementUnpaidDo> list, SwBillingRecordDo add) {
         List<SwBillManagementPaidDo> paidList = new ArrayList<>();
         List<SwBillManagementPaidDo> paidList = new ArrayList<>();
         SwBillManagementPaidDo paid;
         SwBillManagementPaidDo paid;
         for (SwBillManagementUnpaidDo unpaid : list) {
         for (SwBillManagementUnpaidDo unpaid : list) {
@@ -219,11 +220,12 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
             paid.setStatus(PAIDINSTATUS)
             paid.setStatus(PAIDINSTATUS)
                     //缴费记录ID
                     //缴费记录ID
                     .setPaymentrecordid(add.getId());
                     .setPaymentrecordid(add.getId());
-            ZHSWCommonUtils.initModelGeneralParameters(paid,currentUser);
+            ZHSWCommonUtils.initModelGeneralParameters(paid,null);
             paidList.add(paid);
             paidList.add(paid);
         }
         }
         // 保存已缴费账单
         // 保存已缴费账单
-        swBillManagementPaidService.saveBatch(paidList);
+
+        return paidList;
     }
     }
 
 
     /**
     /**
@@ -295,7 +297,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
         //【实缴后余额(元)】=【账户余额】+【本次实缴(元-整)】- 原应缴 + 总减免 - 滞纳金
         //【实缴后余额(元)】=【账户余额】+【本次实缴(元-整)】- 原应缴 + 总减免 - 滞纳金
         add.setAfterpaymentbalance(add.getPaidin().add(accountbalance).subtract(totalOught).add(totalWaivers).subtract(totalLateFees));
         add.setAfterpaymentbalance(add.getPaidin().add(accountbalance).subtract(totalOught).add(totalWaivers).subtract(totalLateFees));
 
 
-        swBillingRecordService.save(add);
+
     }
     }
 
 
     /**
     /**