|
@@ -2,8 +2,12 @@ package com.rongwei.zhsw.system.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.rongwe.zhsw.system.domain.*;
|
|
|
+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.PaymentRequestDTO;
|
|
|
+import com.rongwei.commonservice.service.impl.RedisServiceImpl;
|
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
import com.rongwei.rwcommon.base.exception.CustomException;
|
|
@@ -57,31 +61,33 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
@Autowired
|
|
|
private SwUserManagementService swUserManagementService;
|
|
|
|
|
|
- private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
|
|
|
|
|
|
+ private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 缴费记录生成
|
|
|
+ *
|
|
|
* @param paymentRequestDTO
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public R windowPayment(PaymentRequestDTO paymentRequestDTO) throws Exception {
|
|
|
|
|
|
log.info("窗口缴费开始");
|
|
|
- if (paymentRequestDTO.getIds()!=null && !paymentRequestDTO.getIds().isEmpty()){
|
|
|
+ if (paymentRequestDTO.getIds() != null && !paymentRequestDTO.getIds().isEmpty()) {
|
|
|
|
|
|
// 查询待缴费账单
|
|
|
List<SwBillManagementUnpaidDo> unpaidBills = queryUnpaidBills(paymentRequestDTO.getIds());
|
|
|
|
|
|
//生成缴费记录
|
|
|
- addNewBillRecord(paymentRequestDTO,unpaidBills);
|
|
|
- }else {
|
|
|
+ addNewBillRecord(paymentRequestDTO, unpaidBills);
|
|
|
+ } else {
|
|
|
|
|
|
//生成缴费记录
|
|
|
- addNewBillRecord(paymentRequestDTO,null);
|
|
|
+ addNewBillRecord(paymentRequestDTO, null);
|
|
|
}
|
|
|
|
|
|
log.info("窗口缴费结束");
|
|
@@ -90,9 +96,9 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 删除 待收账单数据
|
|
|
+ *
|
|
|
* @param ids
|
|
|
*/
|
|
|
public void deleteUnpaidBills(List<String> ids) {
|
|
@@ -101,7 +107,8 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 根据户号查询 待缴费 状态 无缴费记录的 的待缴费账单
|
|
|
+ * 根据户号查询 待缴费 状态 无缴费记录的 的待缴费账单
|
|
|
+ *
|
|
|
* @param ids
|
|
|
* @return
|
|
|
*/
|
|
@@ -117,29 +124,29 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
// 提取公共字段设置
|
|
|
public SwBillingRecordDo buildBaseBillingRecord( SysUserVo currentUser, SwUserManagementDo user) {
|
|
|
SwBillingRecordDo record = new SwBillingRecordDo();
|
|
|
-
|
|
|
//缴费编号
|
|
|
generateBillingNumber(record);
|
|
|
-
|
|
|
- return record.setChargedate(new Date())
|
|
|
- .setPayfeesstatus(PAIDSTATUS)
|
|
|
- .setYear(Calendar.getInstance().get(Calendar.YEAR))
|
|
|
- .setUsername(user.getUsername())
|
|
|
- .setUsernumber(user.getUsernumber())
|
|
|
- .setUsertype(user.getUsertype())
|
|
|
- .setWatertype(user.getWatertype())
|
|
|
- .setAddress(user.getAddress())
|
|
|
- .setTollcollectorid(currentUser.getId())
|
|
|
- .setTollcollectorname(currentUser.getName())
|
|
|
- .setTenantid(currentUser.getTenantid())
|
|
|
- .setCreateuserid(currentUser.getId())
|
|
|
- .setCreateusername(currentUser.getName())
|
|
|
- .setCreatedate(new Date())
|
|
|
- .setModifydate(new Date())
|
|
|
- .setModifyuserid(currentUser.getId())
|
|
|
- .setTenantid(currentUser.getTenantid())
|
|
|
-
|
|
|
- .setModifyusername(currentUser.getName());
|
|
|
+ record.setId(SecurityUtil.getUUID());
|
|
|
+ record.setChargedate(new Date());
|
|
|
+ record.setPayfeesstatus(PAIDSTATUS);
|
|
|
+ record.setYear(Calendar.getInstance().get(Calendar.YEAR));
|
|
|
+ record.setUsername(user.getUsername());
|
|
|
+ record.setUsernumber(user.getUsernumber());
|
|
|
+ record.setUsertype(user.getUsertype());
|
|
|
+ record.setWatertype(user.getWatertype());
|
|
|
+ record.setAddress(user.getAddress());
|
|
|
+ record.setTollcollectorid(currentUser.getId());
|
|
|
+ record.setTollcollectorname(currentUser.getName());
|
|
|
+ record.setTenantid(currentUser.getTenantid());
|
|
|
+ record.setCreateuserid(currentUser.getId());
|
|
|
+ record.setCreateusername(currentUser.getName());
|
|
|
+ record.setCreatedate(new Date());
|
|
|
+ record.setModifydate(new Date());
|
|
|
+ record.setModifyuserid(currentUser.getId());
|
|
|
+ record.setTenantid(currentUser.getTenantid());
|
|
|
+ record.setModifyusername(currentUser.getName());
|
|
|
+
|
|
|
+ return record;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -155,13 +162,13 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
|
|
|
SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
|
|
|
|
|
|
- List<SwBillManagementPaidDo> bills =new ArrayList<>();
|
|
|
+ List<SwBillManagementPaidDo> bills = new ArrayList<>();
|
|
|
|
|
|
//根据户号获取 用户记录
|
|
|
SwUserManagementDo user = swUserManagementService.getBaseMapper().
|
|
|
selectOne(new LambdaQueryWrapper<SwUserManagementDo>().eq(SwUserManagementDo::getUsernumber, paymentRequestDTO.getUsernumber()));
|
|
|
|
|
|
- if(user==null){
|
|
|
+ if (user == null) {
|
|
|
throw new CustomException("户号不存在");
|
|
|
}
|
|
|
|
|
@@ -175,7 +182,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
// 计算费用
|
|
|
calculateFees(list, add, user);
|
|
|
|
|
|
- if(list!=null){
|
|
|
+ if (list != null) {
|
|
|
//生成已缴费账单
|
|
|
bills = createBills(list, add);
|
|
|
|
|
@@ -195,6 +202,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
|
|
|
/**
|
|
|
* 存储,修改数据
|
|
|
+ *
|
|
|
* @param add
|
|
|
* @param user
|
|
|
* @param bills
|
|
@@ -206,20 +214,20 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
//账单缴费记录生成
|
|
|
this.baseMapper.insert(add);
|
|
|
//已缴费账单生成
|
|
|
- if (!bills.isEmpty()){
|
|
|
+ if (!bills.isEmpty()) {
|
|
|
swBillManagementPaidService.saveBatch(bills);
|
|
|
}
|
|
|
- if (ids!=null && !ids.isEmpty()){
|
|
|
+ if (ids != null && !ids.isEmpty()) {
|
|
|
//删除 待收账单数据
|
|
|
deleteUnpaidBills(ids);
|
|
|
}
|
|
|
|
|
|
//更新用户余额
|
|
|
- updateUserBalance(add,user);
|
|
|
+ updateUserBalance(add, user);
|
|
|
|
|
|
}
|
|
|
|
|
|
- private List<SwBillManagementPaidDo> createBills(List<SwBillManagementUnpaidDo> list, SwBillingRecordDo add) {
|
|
|
+ public List<SwBillManagementPaidDo> createBills(List<SwBillManagementUnpaidDo> list, SwBillingRecordDo add) {
|
|
|
List<SwBillManagementPaidDo> paidList = new ArrayList<>();
|
|
|
SwBillManagementPaidDo paid;
|
|
|
for (SwBillManagementUnpaidDo unpaid : list) {
|
|
@@ -229,7 +237,7 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
paid.setStatus(PAIDINSTATUS)
|
|
|
//缴费记录ID
|
|
|
.setPaymentrecordid(add.getId());
|
|
|
- ZHSWCommonUtils.initModelGeneralParameters(paid,null);
|
|
|
+ ZHSWCommonUtils.initModelGeneralParameters(paid, null);
|
|
|
paidList.add(paid);
|
|
|
}
|
|
|
// 保存已缴费账单
|
|
@@ -248,31 +256,35 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
swUserManagementService.balanceAdd(user.getId(), balanceChange);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 设置减免金额 原应缴 滞纳金 账户余额 原余额 余额抵扣 实际应缴 缴费后余额
|
|
|
+ * @param list
|
|
|
+ * @param add
|
|
|
+ * @param user
|
|
|
+ */
|
|
|
public void calculateFees(List<SwBillManagementUnpaidDo> list, SwBillingRecordDo add, SwUserManagementDo user) {
|
|
|
|
|
|
|
|
|
// 用户 账户余额
|
|
|
- BigDecimal accountbalance = user.getAccountbalance()==null?BigDecimal.ZERO:user.getAccountbalance();
|
|
|
- BigDecimal totalWaivers =BigDecimal.ZERO;
|
|
|
- BigDecimal totalOught =BigDecimal.ZERO;
|
|
|
- BigDecimal totalLateFees =BigDecimal.ZERO;
|
|
|
+ BigDecimal accountbalance = user.getAccountbalance() == null ? BigDecimal.ZERO : user.getAccountbalance();
|
|
|
+ BigDecimal totalWaivers = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalOught = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalLateFees = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
|
- if (list!=null){
|
|
|
+ if (list != null) {
|
|
|
// 使用Stream API进行汇总计算
|
|
|
- totalWaivers = list.stream()
|
|
|
+ totalWaivers = list.stream()
|
|
|
.map(SwBillManagementUnpaidDo::getFeewaiver)
|
|
|
.filter(Objects::nonNull)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
- totalOught = list.stream()
|
|
|
+ totalOught = list.stream()
|
|
|
.map(SwBillManagementUnpaidDo::getOughttohavepaid)
|
|
|
.filter(Objects::nonNull)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
- totalLateFees = list.stream()
|
|
|
+ totalLateFees = list.stream()
|
|
|
.map(SwBillManagementUnpaidDo::getLatefees)
|
|
|
.filter(Objects::nonNull)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
@@ -291,15 +303,15 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
add.setOriginalbalance(accountbalance);
|
|
|
//1、当 【余额】 >=【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 时,【余额抵扣】字段=【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】
|
|
|
//2、当 【余额】 <【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 时,【余额抵扣】字段=【账户余额(元)】
|
|
|
- if(totalOught.subtract(totalWaivers).add(totalLateFees).compareTo(accountbalance)<0){
|
|
|
+ if (totalOught.subtract(totalWaivers).add(totalLateFees).compareTo(accountbalance) < 0) {
|
|
|
add.setBalancededuction(totalOught.add(totalWaivers).subtract(totalLateFees));
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
add.setBalancededuction(accountbalance);
|
|
|
}
|
|
|
// 【实际应缴(元)】 【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 >0 = 【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 else 0
|
|
|
- BigDecimal actualdue =BigDecimal.ZERO;
|
|
|
- if (totalOught.subtract(totalWaivers).add(totalLateFees).compareTo(BigDecimal.ZERO)>-1){
|
|
|
- actualdue=totalOught.subtract(totalWaivers).add(totalLateFees);
|
|
|
+ BigDecimal actualdue = BigDecimal.ZERO;
|
|
|
+ if (totalOught.subtract(totalWaivers).add(totalLateFees).compareTo(BigDecimal.ZERO) > -1) {
|
|
|
+ actualdue = totalOught.subtract(totalWaivers).add(totalLateFees);
|
|
|
}
|
|
|
add.setActualdue(actualdue);
|
|
|
|
|
@@ -311,9 +323,10 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
|
|
|
/**
|
|
|
* 年月日 +
|
|
|
+ *
|
|
|
* @param add 3位数 随机数
|
|
|
*/
|
|
|
- private void generateBillingNumber(SwBillingRecordDo add) {
|
|
|
+ public void generateBillingNumber(SwBillingRecordDo add) {
|
|
|
SecureRandom random = new SecureRandom();
|
|
|
int randomNumber = random.nextInt(1000);
|
|
|
String randomStr = String.format("%03d", randomNumber);
|