|
@@ -77,18 +77,6 @@ public class AutomaticPay {
|
|
|
private Integer feeType;
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 异步扣费入口
|
|
|
- *
|
|
|
- * @param businessId 业务id
|
|
|
- * @param plate 车牌号
|
|
|
- * @param feeType 收费类型,1-只收停车费、2-只收业务费,3-停车和业务费
|
|
|
- */
|
|
|
- //TODO 不要在此方法写逻辑
|
|
|
- public void run(String businessId, String plate, Integer feeType) {
|
|
|
- this.feeType = feeType;
|
|
|
- task(businessId, plate, feeType);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 异步解绑入口
|
|
@@ -104,210 +92,9 @@ public class AutomaticPay {
|
|
|
delRedisTask(null, plate);
|
|
|
// TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(plate);
|
|
|
// TbDeductionBind bind = tbDeductionBindService.findTheLastUnBindCar(plate);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 分配任务
|
|
|
- */
|
|
|
- private void task(String businessId, String plate, Integer feeType) {
|
|
|
- if (isExistTask(businessId, plate)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (feeType == 1) {
|
|
|
- doParkingFee(plate, 0.0);
|
|
|
- } else if (feeType == 2) {
|
|
|
- List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(businessId);
|
|
|
- for (TbBusinessCar car : cars) {
|
|
|
- this.doBusinessFee(businessId, car.getCarNo());
|
|
|
- }
|
|
|
- } else if (feeType == 3) {
|
|
|
- doOutFee(plate);
|
|
|
- }
|
|
|
- delRedisTask(businessId, plate);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 收业务费
|
|
|
- *
|
|
|
- * @param businessId
|
|
|
- */
|
|
|
- private void doBusinessFee(String businessId, String plate) {
|
|
|
- if (!NumberUtil.isNumber(businessId) || NbUtil.isNull(plate)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- StaticLog.info("开始收取业务费:{}", businessId);
|
|
|
- TbBusiness tbBusiness = tbBusinessService.getById(businessId);
|
|
|
- if (PayEnum.PayStatusEnum.NO_PAY.getCode() != tbBusiness.getPayStatus()) {
|
|
|
- StaticLog.info("已收取过业务费,退出收费程序:{}", businessId);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!NumberUtil.isNumber(tbBusiness.getItemPrice().toString())) {
|
|
|
- StaticLog.info("未获取到收费总金额或收费总金额非法,退出收费程序:{}", businessId);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!deductionBindService.isBindCarByPlate(plate)) {
|
|
|
- StaticLog.info("业务车辆未绑定指定客户的预存款账户,退出收费程序:{}{}", businessId, tbBusiness.getCustomerName());
|
|
|
- return;
|
|
|
- }
|
|
|
- List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(businessId);
|
|
|
- TbDeductionBind bind = deductionBindService.getBindCarByPlate(plate);
|
|
|
- TbAccount tbAccount = tbAccountService.getByCustomerId(bind.getCustomerId());
|
|
|
- String key = AesUtil.reverse(tbAccount.getAccSalt());
|
|
|
- String totalMoney = tbAccount.getTotalMoney();
|
|
|
- BigDecimal parkingMoneyBig = new BigDecimal(0);
|
|
|
- BigDecimal totalMoneyBig = new BigDecimal(totalMoney);
|
|
|
- BigDecimal balance = totalMoneyBig.subtract(tbBusiness.getItemPrice());
|
|
|
- //是否离场支付
|
|
|
- boolean isOut = (GoodsEnum.DeductionTypeEnum.OUT_KK.getCode().equals(tbBusiness.getAutoDeductionType())) &&
|
|
|
- this.feeType == 3;
|
|
|
- if (isOut) {
|
|
|
- parkingMoneyBig = getParkings(cars);
|
|
|
- balance = balance.subtract(parkingMoneyBig);
|
|
|
- }
|
|
|
- if (balance.doubleValue() < 0) {
|
|
|
- StaticLog.info("支付账户余额不足!,退出收费程序:{}", businessId);
|
|
|
- deductionBindService.setFeeFailRecord(bind.getCustomerId(), plate,
|
|
|
- AesUtil.toStr(tbBusiness.getGoodsName()) + ":因支付账户余额不足,自动缴费失败。。");
|
|
|
- return;
|
|
|
- }
|
|
|
- Date now = new Date();
|
|
|
- String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
|
|
|
- tbBusiness.setPayMoney(tbBusiness.getItemPrice()).setPayTime(now).setPayType(5)
|
|
|
- .setPayNo(no).setConfirmInput(1).setConfirmInputTime(now).setPayStatus(
|
|
|
- PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode());
|
|
|
- tbBusiness.updateById();
|
|
|
- List<TbBusinessItem> businessItems = tbBusinessItemService.findByBusinessId(businessId);
|
|
|
- for (TbBusinessItem businessItem : businessItems) {
|
|
|
- if (businessItem.getPayStatus() == 1) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- businessItem.setPayStatus(1).setPayTime(now);
|
|
|
- }
|
|
|
- tbBusinessItemService.updateBatchById(businessItems);
|
|
|
- if (isOut) {
|
|
|
- this.updateTbBusinessCars(cars);
|
|
|
- }
|
|
|
- //更新账户余额
|
|
|
- tbAccount.setTotalMoney(AesUtil.encryptECB(balance.toString(), key));
|
|
|
- tbAccount.updateById();
|
|
|
- deductionBindService.setDeductMoney(bind.getCustomerId(), plate, tbBusiness.getItemPrice());
|
|
|
- //生成收费明细
|
|
|
- List<TbFeeDetails> tbFeeDetailsList = tbFeeDetailsService.autoChargeBusinessFee(
|
|
|
- businessItems, null, null, now);
|
|
|
- //生成扣费记录
|
|
|
- createTbDeductionRecord(tbFeeDetailsList, tbAccount, plate, bind.getCustomerName(), no);
|
|
|
- //生成开票信息
|
|
|
- createTbInvoiceOrder(tbBusiness, cars, parkingMoneyBig, plate, bind.getCustomerId(), no, isOut);
|
|
|
- if (isOut) {//离场缴费
|
|
|
- List<PriceBO> priceBOList = new ArrayList<>();
|
|
|
- cars.forEach(tbBusinessCar -> {
|
|
|
- PriceBO bo = new PriceBO();
|
|
|
- bo.setId(tbBusinessCar.getId()).setP(tbBusinessCar.getMoney());
|
|
|
- priceBOList.add(bo);
|
|
|
- });
|
|
|
- deductionBindService.setDeductMoney(bind.getCustomerId(), plate, parkingMoneyBig);
|
|
|
- List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.chargeParkFee(
|
|
|
- priceBOList, null, null, now, PayEnum.PayType.PER_PAY);
|
|
|
- createTbDeductionRecord(parkFeeDetailsList, tbAccount, plate, bind.getCustomerName(), no);
|
|
|
-
|
|
|
- }
|
|
|
- StaticLog.info("预充值自动缴费成功!,退出收费程序:{}{}", businessId, tbAccount.getCustomerId());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 出场所收费,根据车牌号
|
|
|
- *
|
|
|
- * @param plate
|
|
|
- */
|
|
|
- private void doOutFee(String plate) {
|
|
|
- if (NbUtil.isNull(plate)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(plate);
|
|
|
- if (tbBusinessCar == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- List<TbBusiness> businessList = tbBusinessService.findOtherBusinessByCarId(tbBusinessCar.getId());
|
|
|
- if (businessList == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- for (TbBusiness business : businessList) {
|
|
|
- List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(business.getId());
|
|
|
- if (cars == null) continue;
|
|
|
- for (TbBusinessCar car : cars) {
|
|
|
- doBusinessFee(business.getId(), car.getCarNo());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 收停车费,不判断免费车辆
|
|
|
- *
|
|
|
- * @param plate
|
|
|
- * @param parkingFee
|
|
|
- */
|
|
|
- private void doParkingFee(String plate, double parkingFee) {
|
|
|
- if (NbUtil.isNull(plate)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- TbBusinessCar car = tbBusinessCarService.findTheLastRecord(plate);
|
|
|
- if (car == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- StaticLog.info("开始自动缴纳停车费:{}", car.getCarNo());
|
|
|
-// if(car.getPay()==1 || car.getPayTime()!=null){
|
|
|
-// StaticLog.info("该车辆已缴纳过停车费!,退出收费程序:{}" , car.getCarNo());
|
|
|
-// return;
|
|
|
-// }
|
|
|
- TbAccount account = tbAccountService.getTbAccountByPlate(car.getCarNo());
|
|
|
- if (account == null) {
|
|
|
- StaticLog.info("该车辆还未绑定客户预存款账户!,退出收费程序:{}", car.getCarNo());
|
|
|
- return;
|
|
|
- }
|
|
|
- BigDecimal parkFeeBig = null;
|
|
|
- if (parkingFee > 0) {
|
|
|
- parkFeeBig = new BigDecimal(String.valueOf(parkingFee));
|
|
|
- } else {
|
|
|
- parkFeeBig = caulatePrice(car, new Date());
|
|
|
- }
|
|
|
- if (parkFeeBig == null || parkFeeBig.doubleValue() <= 0) {
|
|
|
- StaticLog.info("该车辆无需缴纳停车费!,退出收费程序:{}", car.getCarNo());
|
|
|
- return;
|
|
|
- }
|
|
|
- TbDeductionBind bind = deductionBindService.getBindCarByPlate(plate);
|
|
|
- BigDecimal totalBig = new BigDecimal("0");
|
|
|
- String key = null;
|
|
|
- if (!NumberUtil.isNumber(account.getTotalMoney())) {
|
|
|
- key = AesUtil.reverse(account.getAccSalt());
|
|
|
- totalBig = new BigDecimal(AesUtil.decryptECB(account.getTotalMoney(), key));
|
|
|
- }
|
|
|
|
|
|
- BigDecimal balance = totalBig.subtract(parkFeeBig);
|
|
|
- if (balance.doubleValue() < 0) {
|
|
|
- StaticLog.info("支付账户余额不足!,退出收费程序:{}", car.getCarNo());
|
|
|
- return;
|
|
|
- }
|
|
|
- String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
|
|
|
- car.setMoney(parkFeeBig);
|
|
|
- updateTbBusinessCar(car);
|
|
|
- account.setTotalMoney(AesUtil.encryptECB(balance.toString(), key));
|
|
|
- account.updateById();
|
|
|
- deductionBindService.setDeductMoney(bind.getCustomerId(), plate, parkFeeBig);
|
|
|
- List<TbBusinessCar> cars = new ArrayList<TbBusinessCar>();
|
|
|
- cars.add(car);
|
|
|
- List<PriceBO> priceBOList = new ArrayList<>();
|
|
|
- PriceBO bo = new PriceBO();
|
|
|
- bo.setId(car.getId()).setP(car.getMoney());
|
|
|
- priceBOList.add(bo);
|
|
|
- List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.chargeParkFee(
|
|
|
- priceBOList, null, null, new Date(), PayEnum.PayType.PER_PAY);
|
|
|
- createTbDeductionRecord(parkFeeDetailsList, account, plate, bind.getCustomerName(), no);
|
|
|
- createTbInvoiceOrderPark(car, account.getCustomerId(), no);
|
|
|
- deductionBindService.autoUnbindCar(cars);
|
|
|
- StaticLog.info("停车费自动缴费成功!,退出收费程序:{}", car.getCarNo());
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 生成扣费记录
|
|
@@ -420,76 +207,8 @@ public class AutomaticPay {
|
|
|
invoiceOrderService.save(invoiceOrder);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 生成停车费
|
|
|
- *
|
|
|
- * @param tbBusinessCar
|
|
|
- * @param now
|
|
|
- * @return
|
|
|
- */
|
|
|
- private BigDecimal caulatePrice(TbBusinessCar tbBusinessCar, Date now) {
|
|
|
- if (tbBusinessCar == null || now == null) new BigDecimal("0");
|
|
|
- Date inTime = tbBusinessCar.getRealInTime();
|
|
|
- if (tbBusinessCar.getPay() == 1 && tbBusinessCar.getRealOutTime() == null && tbBusinessCar.getPayTime() != null) {
|
|
|
- inTime = tbBusinessCar.getPayTime();
|
|
|
- }
|
|
|
- BigDecimal price = tbBusinessService.calculationPartMoney(inTime, now, tbBusinessCar.getCarNo());
|
|
|
- tbBusinessCar.setMoney(price);
|
|
|
- return price;
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 获取所有停车费总和
|
|
|
- *
|
|
|
- * @param cars
|
|
|
- * @return
|
|
|
- */
|
|
|
- private BigDecimal getParkings(List<TbBusinessCar> cars) {
|
|
|
- if (cars == null) new BigDecimal("0");
|
|
|
- Date now = new Date();
|
|
|
- BigDecimal value = new BigDecimal("0");
|
|
|
- for (TbBusinessCar car : cars) {
|
|
|
- value = value.add(this.caulatePrice(car, now));
|
|
|
- car.setPayType(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType());
|
|
|
- }
|
|
|
- return value;
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 获取所有停车费总和,过滤免费车
|
|
|
- *
|
|
|
- * @param cars
|
|
|
- * @return
|
|
|
- */
|
|
|
- private BigDecimal getParkingsByBS(List<TbBusinessCar> cars, TbBusiness tbBusiness) {
|
|
|
- if (cars == null) new BigDecimal("0");
|
|
|
- Date now = new Date();
|
|
|
- BigDecimal value = new BigDecimal("0");
|
|
|
- for (TbBusinessCar car : cars) {
|
|
|
- if (isParkingFeeByBS(tbBusiness, car.getCarType())) {
|
|
|
- car.setPayType(CarEnum.PayTypeEnum.FEE_TYPE.getType());
|
|
|
- } else {
|
|
|
- value = value.add(this.caulatePrice(car, now));
|
|
|
- car.setPayType(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType());
|
|
|
- }
|
|
|
- }
|
|
|
- return value;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 判断有业务的车是否收停车费
|
|
|
- *
|
|
|
- * @return true是免费
|
|
|
- */
|
|
|
- private boolean isParkingFeeByBS(TbBusiness tbBusiness, String carType) {
|
|
|
- if (CarEnum.CarTypeEnum.EMPTY_TYPE.getType().equals(carType)) {
|
|
|
- TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
|
|
|
- return tbGoods.getChinaCarPay() == 1;
|
|
|
- } else {//越南车=重车
|
|
|
- TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
|
|
|
- return tbGoods.getVietnamCarPay() == 1;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 补录进场解绑逻辑
|