浏览代码

自动缴费部分代码优化

qzyReal 2 年之前
父节点
当前提交
97221f6f12

+ 0 - 281
sp-server/src/main/java/com/pj/project/tb_account/AutomaticPay.java

@@ -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;
-        }
-    }
 
     /**
      * 补录进场解绑逻辑

+ 6 - 37
sp-server/src/main/java/com/pj/project/tb_business/TbBusinessService.java

@@ -74,6 +74,8 @@ import com.pj.project.tb_item_fac.TbItemFac;
 import com.pj.project.tb_item_fac.TbItemFacService;
 import com.pj.project.tb_item_type.TbItemType;
 import com.pj.project.tb_item_type.TbItemTypeService;
+import com.pj.project.tb_mild_car.TbMildCar;
+import com.pj.project.tb_mild_car.TbMildCarService;
 import com.pj.project.tb_notices.TbNoticesService;
 import com.pj.project.tb_sort_group.TbSortGroup;
 import com.pj.project.tb_sort_group.TbSortGroupService;
@@ -423,40 +425,6 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
     }
 
 
-    public BigDecimal calculationPartMoney(Date iTime, Date oTime, double carSize) {
-        BigDecimal zero = new BigDecimal("0");
-        if (iTime == null || oTime == null) {
-            return zero;
-        }
-        LocalDateTime inDayTime = iTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
-        LocalDateTime outDayTime = oTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
-        long minutes = ChronoUnit.MINUTES.between(inDayTime, outDayTime);
-        if (minutes < 0 || minutes < partConfig.getFreeMinutes()) {
-            return zero;
-        }
-        BigDecimal extraPrice = partConfig.getExtraPrice();
-        BigDecimal basePrice = partConfig.getBasePrice();
-        BigDecimal uniPrice = basePrice.add(extraPrice);//超过24小时之后每24个小时收费金额
-        //4.2~9.6
-        if (carSize <= partConfig.getMildCarLength() && carSize > partConfig.getFreeCarLength()) {
-            basePrice = partConfig.getMildCarBasePrice();
-            uniPrice = basePrice.add(extraPrice);
-        }
-        //间隔小时
-        long hours = ChronoUnit.HOURS.between(inDayTime, outDayTime);
-        final int hoursOf24 = 24;
-        //24小时内只用交20或者30元
-        if (hours < hoursOf24) {
-            return basePrice;
-        }
-        //24小时个数
-        long count = hours / hoursOf24;
-        //超过24小时总停车费
-        BigDecimal price = new BigDecimal(count).multiply(uniPrice);
-        return price.add(basePrice);
-
-    }
-
 
     /**
      * 微信端获取缴费信息
@@ -775,7 +743,8 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
                 Date realInTime = tbBusinessCar.getRealInTime();
                 Date realOutTime = tbBusinessCar.getRealOutTime();
                 if (realInTime != null && realOutTime != null) {
-                    BigDecimal price = calculationPartMoney(realInTime, realOutTime, tbBusinessCar.getCarSize());
+                    IOrderPriceRes orderPriceRes = getPartMoney(realInTime, realOutTime, tbBusinessCar.getCarNo(),tbBusinessCar.getColor());
+                    BigDecimal price=orderPriceRes.getTotalOrderPrice();
                     if (price.doubleValue() > 0) {
                         PriceBO priceBO = new PriceBO();
                         priceBO.setId(tbBusinessCar.getId()).setP(price);
@@ -1284,8 +1253,8 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
             outTime = payTime;
         }
         //计算停车费
-        BigDecimal parkMoney = this.calculationPartMoney(inTime, outTime, tbBusinessCar.getCarSize());
-        tbBusinessCar.setMoney(parkMoney);
+        IOrderPriceRes parkMoney = this.getPartMoney(inTime, outTime, tbBusinessCar.getCarNo(),tbBusinessCar.getColor());
+        tbBusinessCar.setMoney(parkMoney.getTotalOrderPrice());
     }
 
     /**

+ 1 - 1
sp-server/src/main/java/com/pj/project/tb_business_car/TbBusinessCarService.java

@@ -256,7 +256,7 @@ public class TbBusinessCarService extends ServiceImpl<TbBusinessCarMapper, TbBus
         }
         if (t.getRealInTime() != null && t.getRealOutTime() != null
                 && StrUtil.equals(db.getPayType(), CarEnum.PayTypeEnum.NO_PAY_TYPE.getType())) {
-            BigDecimal money = tbBusinessService.calculationPartMoney(t.getRealInTime(), t.getRealOutTime(), t.getCarNo());
+            BigDecimal money = tbBusinessService.getPartMoney(t.getRealInTime(), t.getRealOutTime(), t.getCarNo(),t.getColor()).getTotalOrderPrice();
             t.setMoney(money);
             db.setMoney(money);
         }