|
@@ -14,6 +14,8 @@ import com.rongwei.zhsw.system.service.SwBillManagementUnpaidService;
|
|
|
import com.rongwei.zhsw.system.service.SwBillingRecordService;
|
|
|
import com.rongwei.zhsw.system.service.SwUserManagementService;
|
|
|
import com.rongwei.zhsw.system.utils.ZHSWCommonUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -54,6 +56,9 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
@Autowired
|
|
|
private SwUserManagementService swUserManagementService;
|
|
|
|
|
|
+ private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 缴费记录生成
|
|
@@ -64,24 +69,50 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public R windowPayment(PaymentRequestDTO paymentRequestDTO) throws Exception {
|
|
|
+ log.info("窗口缴费开始");
|
|
|
|
|
|
- List<String> ids = paymentRequestDTO.getIds();
|
|
|
- BigDecimal paidIn = paymentRequestDTO.getPaidin();
|
|
|
- String datasource = paymentRequestDTO.getDatasource();
|
|
|
+ if (paymentRequestDTO.getIds()==null){
|
|
|
|
|
|
- // 查询待缴费账单
|
|
|
- List<SwBillManagementUnpaidDo> unpaidBills = queryUnpaidBills(ids);
|
|
|
+ log.info("无账单缴费");
|
|
|
+ windowPaymentNoBill(paymentRequestDTO);
|
|
|
+ }else {
|
|
|
|
|
|
- // 校验账单数据
|
|
|
- validateBillingData(unpaidBills, ids);
|
|
|
+ log.info("有账单缴费");
|
|
|
+ windowPaymentHasBill(paymentRequestDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("窗口缴费结束");
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 有账单生成 缴费记录
|
|
|
+ *
|
|
|
+ * @param paymentRequestDTO
|
|
|
+ */
|
|
|
+ private void windowPaymentHasBill(PaymentRequestDTO paymentRequestDTO) {
|
|
|
+
|
|
|
+ List<String> ids = paymentRequestDTO.getIds();
|
|
|
+ // 查询待缴费账单
|
|
|
+ List<SwBillManagementUnpaidDo> unpaidBills = queryUnpaidBills(paymentRequestDTO.getIds());
|
|
|
|
|
|
//生成缴费记录
|
|
|
- addNewBillRecord(paidIn,datasource,unpaidBills);
|
|
|
+ addNewBillRecord(paymentRequestDTO,unpaidBills);
|
|
|
|
|
|
//删除 待收账单数据
|
|
|
deleteUnpaidBills(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 无账单生成缴费记录
|
|
|
+
|
|
|
+ */
|
|
|
+ private void windowPaymentNoBill(PaymentRequestDTO paymentRequestDTO) {
|
|
|
+
|
|
|
+
|
|
|
+ //生成缴费记录
|
|
|
+ addNewBillRecord(paymentRequestDTO,null);
|
|
|
|
|
|
- return R.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -108,19 +139,19 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
}
|
|
|
|
|
|
// 提取公共字段设置
|
|
|
- private SwBillingRecordDo buildBaseBillingRecord(List<SwBillManagementUnpaidDo> list, BigDecimal paidin, String datasource, SysUserVo currentUser) {
|
|
|
+ private SwBillingRecordDo buildBaseBillingRecord( PaymentRequestDTO paymentRequestDTO, SysUserVo currentUser, SwUserManagementDo user) {
|
|
|
SwBillingRecordDo record = new SwBillingRecordDo();
|
|
|
- SwBillManagementUnpaidDo firstBill = list.get(0);
|
|
|
+
|
|
|
|
|
|
return record.setId(SecurityUtil.getUUID())
|
|
|
.setChargedate(new Date())
|
|
|
.setPayfeesstatus(PAIDSTATUS)
|
|
|
.setYear(Calendar.getInstance().get(Calendar.YEAR))
|
|
|
- .setUsername(firstBill.getUsername())
|
|
|
- .setUsernumber(firstBill.getUsernumber())
|
|
|
- .setUsertype(firstBill.getUsertype())
|
|
|
- .setWatertype(firstBill.getWatertype())
|
|
|
- .setAddress(firstBill.getAddress())
|
|
|
+ .setUsername(user.getUsername())
|
|
|
+ .setUsernumber(user.getUsernumber())
|
|
|
+ .setUsertype(user.getUsertype())
|
|
|
+ .setWatertype(user.getWatertype())
|
|
|
+ .setAddress(user.getAddress())
|
|
|
.setTollcollectorid(currentUser.getId())
|
|
|
.setTollcollectorname(currentUser.getName())
|
|
|
.setTenantid(currentUser.getTenantid())
|
|
@@ -130,8 +161,8 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
.setModifydate(new Date())
|
|
|
.setModifyuserid(currentUser.getId())
|
|
|
.setTenantid(currentUser.getTenantid())
|
|
|
- .setDatasource(datasource)
|
|
|
- .setPaidin(paidin)
|
|
|
+ .setDatasource(paymentRequestDTO.getDatasource())
|
|
|
+ .setPaidin(paymentRequestDTO.getPaidin())
|
|
|
.setModifyusername(currentUser.getName());
|
|
|
}
|
|
|
|
|
@@ -141,17 +172,20 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
*
|
|
|
* @param paidin
|
|
|
* @param datasource
|
|
|
-
|
|
|
+ * @param paymentRequestDTO
|
|
|
+ * @param unpaidBills
|
|
|
*/
|
|
|
- private void addNewBillRecord(BigDecimal paidin, String datasource, List<SwBillManagementUnpaidDo> list) {
|
|
|
+ private void addNewBillRecord(PaymentRequestDTO paymentRequestDTO, List<SwBillManagementUnpaidDo> list) {
|
|
|
|
|
|
SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
|
|
|
|
|
|
- SwBillingRecordDo add = buildBaseBillingRecord(list,paidin,datasource,currentUser);
|
|
|
-
|
|
|
//根据户号获取 用户记录
|
|
|
SwUserManagementDo user = swUserManagementService.getBaseMapper().
|
|
|
- selectOne(new LambdaQueryWrapper<SwUserManagementDo>().eq(SwUserManagementDo::getUsernumber, add.getUsernumber()));
|
|
|
+ selectOne(new LambdaQueryWrapper<SwUserManagementDo>().eq(SwUserManagementDo::getUsernumber, paymentRequestDTO.getUsernumber()));
|
|
|
+
|
|
|
+
|
|
|
+ SwBillingRecordDo add = buildBaseBillingRecord(paymentRequestDTO,currentUser,user);
|
|
|
+
|
|
|
|
|
|
// 生成缴费编号
|
|
|
generateBillingNumber(add);
|
|
@@ -159,8 +193,13 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
// 计算费用
|
|
|
calculateFees(list, add,user);
|
|
|
|
|
|
- //生成已缴费账单
|
|
|
- createBills(list,add,currentUser);
|
|
|
+
|
|
|
+ if(list!=null){
|
|
|
+ //生成已缴费账单
|
|
|
+ createBills(list,add,currentUser);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
//更新用户余额
|
|
|
updateUserBalance(add,user);
|
|
@@ -211,24 +250,30 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
|
|
|
// 用户 账户余额
|
|
|
BigDecimal accountbalance = user.getAccountbalance()==null?BigDecimal.ZERO:user.getAccountbalance();
|
|
|
+ BigDecimal totalWaivers =BigDecimal.ZERO;
|
|
|
+ BigDecimal totalOught =BigDecimal.ZERO;
|
|
|
+ BigDecimal totalLateFees =BigDecimal.ZERO;
|
|
|
+
|
|
|
+
|
|
|
+ if (!list.isEmpty()){
|
|
|
+ // 使用Stream API进行汇总计算
|
|
|
+ totalWaivers = list.stream()
|
|
|
+ .map(SwBillManagementUnpaidDo::getFeewaiver)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ totalOught = list.stream()
|
|
|
+ .map(SwBillManagementUnpaidDo::getOughttohavepaid)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ totalLateFees = list.stream()
|
|
|
+ .map(SwBillManagementUnpaidDo::getLatefees)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- // 使用Stream API进行汇总计算
|
|
|
- BigDecimal totalWaivers = list.stream()
|
|
|
- .map(SwBillManagementUnpaidDo::getFeewaiver)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-
|
|
|
- BigDecimal totalOught = list.stream()
|
|
|
- .map(SwBillManagementUnpaidDo::getOughttohavepaid)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-
|
|
|
- BigDecimal totalLateFees = list.stream()
|
|
|
- .map(SwBillManagementUnpaidDo::getLatefees)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-
|
|
|
//总减免
|
|
|
add.setAllfeewaiver(totalWaivers);
|
|
|
//原应缴
|
|
@@ -239,15 +284,20 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
add.setAccountbalance(accountbalance);
|
|
|
//原余额(元) = 用户表 用户余额
|
|
|
add.setOriginalbalance(accountbalance);
|
|
|
- //1、当 【余额】 >=【原应缴(元)】-【总减免(元)】 -【滞纳金(元)】 时,【余额抵扣】字段=【原应缴(元)】-【总减免(元)】 -【滞纳金(元)】
|
|
|
- //2、当 【余额】 <【原应缴(元)】-【总减免(元)】 -【滞纳金(元)】 时,【余额抵扣】字段=【账户余额(元)】
|
|
|
- if(totalOught.subtract(totalWaivers).subtract(totalLateFees).compareTo(accountbalance)<0){
|
|
|
- add.setBalancededuction(totalOught.subtract(totalWaivers).subtract(totalLateFees));
|
|
|
+ //1、当 【余额】 >=【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 时,【余额抵扣】字段=【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】
|
|
|
+ //2、当 【余额】 <【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 时,【余额抵扣】字段=【账户余额(元)】
|
|
|
+ if(totalOught.subtract(totalWaivers).add(totalLateFees).compareTo(accountbalance)<0){
|
|
|
+ add.setBalancededuction(totalOught.add(totalWaivers).subtract(totalLateFees));
|
|
|
}else {
|
|
|
add.setBalancededuction(accountbalance);
|
|
|
}
|
|
|
- // 【实际应缴(元)】=【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】-【余额抵扣(元)】
|
|
|
- add.setActualdue(totalOught.subtract(totalWaivers).add(totalLateFees).subtract(add.getBalancededuction()));
|
|
|
+ // 【实际应缴(元)】 【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 >0 = 【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 else 0
|
|
|
+ BigDecimal actualdue =BigDecimal.ZERO;
|
|
|
+ if (totalOught.subtract(totalWaivers).add(totalLateFees).compareTo(BigDecimal.ZERO)>-1){
|
|
|
+ actualdue=totalOught.subtract(totalWaivers).add(totalLateFees);
|
|
|
+ }
|
|
|
+ add.setActualdue(actualdue);
|
|
|
+
|
|
|
//【实缴后余额(元)】=【账户余额】+【本次实缴(元-整)】- 原应缴 + 总减免 - 滞纳金
|
|
|
add.setAfterpaymentbalance(add.getPaidin().add(accountbalance).subtract(totalOught).add(totalWaivers).subtract(totalLateFees));
|
|
|
|
|
@@ -267,18 +317,4 @@ public class SwBillingRecordServiceImpl extends ServiceImpl<SwBillingRecordDao,
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 校验
|
|
|
- * @param list
|
|
|
- * @param ids
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- private void validateBillingData(List<SwBillManagementUnpaidDo> list, List<String> ids) throws Exception {
|
|
|
- if (list.isEmpty()) {
|
|
|
- throw new Exception( "没有待缴费账单");
|
|
|
- }
|
|
|
- if (list.size() != ids.size()) {
|
|
|
- throw new Exception("部分账单已缴费");
|
|
|
- }
|
|
|
- }
|
|
|
}
|