|
@@ -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);
|
|
|
//原应缴
|