Browse Source

停车费对接----

qzyReal 2 years ago
parent
commit
0a8b3c4d34
24 changed files with 241 additions and 549 deletions
  1. 1 1
      app-ui/manifest.json
  2. 8 2
      app-ui/pages/wx/pay.vue
  3. 2 2
      app-ui/utils/request.js
  4. 3 11
      sp-admin/sa-view/tb-item-type/tb-item-list.html
  5. 1 1
      sp-admin/static/sa.js
  6. 14 24
      sp-server/src/main/java/com/pj/api/open/service/OpenService.java
  7. 3 3
      sp-server/src/main/java/com/pj/api/service/ApiService.java
  8. 22 3
      sp-server/src/main/java/com/pj/api/wx/bo/PriceBO.java
  9. 3 2
      sp-server/src/main/java/com/pj/api/wx/service/WxService.java
  10. 2 2
      sp-server/src/main/java/com/pj/constants/business/PartFeeEnum.java
  11. 4 4
      sp-server/src/main/java/com/pj/project/sync/api/AsyncApi.java
  12. 8 1
      sp-server/src/main/java/com/pj/project/sync/response/IOrderPriceRes.java
  13. 6 0
      sp-server/src/main/java/com/pj/project/sync/response/item/OrderPriceResultItem.java
  14. 11 0
      sp-server/src/main/java/com/pj/project/sync/response/item/PriceDetailItem.java
  15. 54 18
      sp-server/src/main/java/com/pj/project/tb_account/AutomaticPay.java
  16. 49 21
      sp-server/src/main/java/com/pj/project/tb_business/TbBusinessService.java
  17. 0 432
      sp-server/src/main/java/com/pj/project/tb_business_item/PayTask.java
  18. 5 0
      sp-server/src/main/java/com/pj/project/tb_deduction_record/TbDeductionRecord.java
  19. 1 1
      sp-server/src/main/java/com/pj/project/tb_fee_details/TbFeeDetails.java
  20. 1 0
      sp-server/src/main/java/com/pj/project/tb_fee_details/TbFeeDetailsMapper.xml
  21. 25 19
      sp-server/src/main/java/com/pj/project/tb_fee_details/TbFeeDetailsService.java
  22. 2 2
      sp-server/src/main/java/com/pj/project/tb_item/TbItem.java
  23. 15 0
      sp-server/src/main/java/com/pj/project/tb_item/TbItemService.java
  24. 1 0
      sp-server/src/main/java/com/pj/project/tb_item_type/TbItemTypeService.java

+ 1 - 1
app-ui/manifest.json

@@ -83,7 +83,7 @@
     "vueVersion" : "2",
     "h5" : {
         "router" : {
-            "base" : "/h5/",
+            "base" : "/test/",
             "mode" : "history"
         },
         "devServer" : {

+ 8 - 2
app-ui/pages/wx/pay.vue

@@ -191,7 +191,7 @@
 					}).then(resp => {
 						let data = resp.data;
 						if (data.cars && data.cars.length > 0) {
-							this.cars = data.cars;
+							// this.cars = data.cars;
 							let carId = [data.cars[0].id];
 							this.carsSelect = carId;
 							this.groupChange(carId)
@@ -233,7 +233,13 @@
 						return {
 							id: obj.id,
 							p: obj.price,
-							uniqExpenseId:obj.uniqExpenseId
+							uniqExpenseId:obj.uniqExpenseId,
+							carDesc:obj.carDesc,
+							hourDesc:obj.hourDesc,
+							standard:obj.standard,
+							over24Hour:obj.over24Hour,
+							extraPrice:obj.extraPrice,
+							calculateId:obj.calculateId
 						}
 					})),
 					money: this.total,

+ 2 - 2
app-ui/utils/request.js

@@ -1,5 +1,5 @@
-const server = 'http://127.0.0.1:8099/pro';
-// const server = 'https://pco.aseanbusiness.cn/pro';
+// const server = 'http://127.0.0.1:8099/pro';
+const server = 'https://pco.aseanbusiness.cn/pro';
 
 
 // const server = 'https://dxkaa1.gxbtka.com/pro';

+ 3 - 11
sp-admin/sa-view/tb-item-type/tb-item-list.html

@@ -33,23 +33,15 @@
 				<el-table class="data-table" ref="data-table" :data="dataList">
 					<el-table-column type="index" width="50">
 					</el-table-column>
-					<sa-td name="车型" prop="itemName" width="300px"></sa-td>
+					<sa-td name="车型" prop="itemName" width="200px"></sa-td>
+					<sa-td name="业务类型" prop="typeName" width="300px"></sa-td>
 					<sa-td name="通知类型" prop="businessTypeName"></sa-td>
 					<sa-td name="空车/载重" prop="itemType"></sa-td>
 					<sa-td name="统计类型" prop="payTypeName"></sa-td>
 					<sa-td name="价格" prop="price"></sa-td>
 					<sa-td name="计价单位" prop="unit"></sa-td>
 					<sa-td name="税率(%)" prop="taxRate"></sa-td>
-					<sa-td name="适合规格(米)" width="120">
-						<template slot-scope="s">
-							<label>{{s.row.minLength}}—{{s.row.carLength}}</label>
-						</template>
-					</sa-td>
-					<sa-td name="适合载重(kg)" width="120">
-						<template slot-scope="s">
-							<label>{{s.row.minWeight}}—{{s.row.maxWeight}}</label>
-						</template>
-					</sa-td>
+
 					<el-table-column label="操作" fixed="right" width="240px">
 						<template slot-scope="s">
 							<el-button class="c-btn" type="success" icon="el-icon-view" @click="get(s.row)">查看

+ 1 - 1
sp-admin/static/sa.js

@@ -22,7 +22,7 @@ var sa = {
 		api_url: 'https://dxkaa1.gxbtka.com/pro',
 		web_url: 'http://www.baidu.com'
 	}
-	sa.cfg = cfg_dev; // 最终环境 , 上线前请选择正确的环境
+	sa.cfg = cfg_test; // 最终环境 , 上线前请选择正确的环境
 })();
 
 

+ 14 - 24
sp-server/src/main/java/com/pj/api/open/service/OpenService.java

@@ -201,19 +201,22 @@ public class OpenService {
         String carType = tbBusinessCar.getCarType();
         BigDecimal yueCarMoney = new BigDecimal(0);
         BigDecimal chinaCarMoney = new BigDecimal(0);
+        IOrderPriceRes yueRes=new IOrderPriceRes();
+        IOrderPriceRes chinaRes=new IOrderPriceRes();
+        IOrderPriceRes businessRes=new IOrderPriceRes();
+        List<IOrderItem> expenses = new ArrayList<>();
         List<TbBusiness> businessList = tbBusinessService.findOtherBusinessByCarId(businessCarId);
         int payPart = tbBusinessCar.getPay();
         businessList = businessList.stream().filter(tbBusiness -> tbBusiness.getPayStatus() != PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode()).collect(Collectors.toList());
         if (businessList.isEmpty()) {//无业务车辆===>计算停车费
             //如果已经支付过,则从支付时间算起,重新计算停车费
-            IOrderPriceRes res = tbBusinessService.getPartMoney(tbBusinessCar.getRealInTime(), now, tbBusinessCar.getCarSize(), tbBusinessCar.getColor());
+            IOrderPriceRes res = tbBusinessService.getPartMoney(tbBusinessCar.getRealInTime(), now, carNo, tbBusinessCar.getColor());
             double dif = res.getTotalOrderPrice().doubleValue();
-            // double dif = tbBusinessService.calculationPartMoney(tbBusinessCar.getRealInTime(), now, tbBusinessCar.getCarSize()).doubleValue();
             if (dif > 0 && payPart == 0) {
                 RedisUtil.setByMINUTES(channel, carNo, 5);
                 log.error("请求返回:请缴停车费:{},{}元", carNo, dif);
                 //是否可以预充值缴费 true扣款成功 false否
-                boolean flag = automaticPay.payPartMoney(tbBusinessCar, dif, now);
+                boolean flag = automaticPay.payPartMoney(tbBusinessCar, res, now);
                 if (flag) {
                     tbBusinessCar.setMoney(new BigDecimal(dif));
                     freeOut(tbBusinessCar, now, channel, image);
@@ -240,13 +243,13 @@ public class OpenService {
                     return tbGoods.getChinaCarPay() == 1;
                 });
                 if (chinaCarPay && payPart == 0) {
-                    IOrderPriceRes res = tbBusinessService.getPartMoney(tbBusinessCar.getRealInTime(), now, tbBusinessCar.getCarSize(), tbBusinessCar.getColor());
+                    IOrderPriceRes res = tbBusinessService.getPartMoney(tbBusinessCar.getRealInTime(), now,carNo, tbBusinessCar.getColor());
                     double dif = res.getTotalOrderPrice().doubleValue();
-                    // double dif = tbBusinessService.calculationPartMoney(tbBusinessCar.getRealInTime(), now, tbBusinessCar.getCarSize()).doubleValue();
                     if (dif > 0) {
                         RedisUtil.setByMINUTES(channel, carNo, 5);
                         log.error("中国车停车费:{},{}元", carNo, dif);
                         chinaCarMoney = new BigDecimal(dif);
+                        chinaRes=res;
                         //  return ResultJson.error("请缴停车费" + dif + "元");
                     } else {
                         if (tbBusinessCar.getPayTime() == null) {
@@ -260,14 +263,13 @@ public class OpenService {
                     return tbGoods.getVietnamCarPay() == 1;
                 });
                 if (vietnamCarPay && payPart == 0) {
-                    IOrderPriceRes res = tbBusinessService.getPartMoney(tbBusinessCar.getRealInTime(), now, tbBusinessCar.getCarSize(), tbBusinessCar.getColor());
+                    IOrderPriceRes res = tbBusinessService.getPartMoney(tbBusinessCar.getRealInTime(), now, carNo, tbBusinessCar.getColor());
                     double dif = res.getTotalOrderPrice().doubleValue();
-                    // double dif = tbBusinessService.calculationPartMoney(tbBusinessCar.getRealInTime(), now, tbBusinessCar.getCarSize()).doubleValue();
                     if (dif > 0) {
                         RedisUtil.setByMINUTES(channel, carNo, 5);
                         log.error("越南车停车费:{},{}元", carNo, dif);
                         yueCarMoney = new BigDecimal(dif);
-                        //  return ResultJson.error("请缴停车费" + dif + "元");
+                        yueRes=res;
                     } else {
                         if (tbBusinessCar.getPayTime() == null) {
                             tbBusinessCar.setPayType(CarEnum.PayTypeEnum.FEE_TYPE.getType()).setPay(1);
@@ -277,12 +279,7 @@ public class OpenService {
             }
         }
         //============业务费计算是否交完
-        BigDecimal businessMoney = BUSINESS_MONEY_CACHE.get(carNo);
-        if (businessMoney == null) {
-            businessMoney = new BigDecimal("0");
-        }
         int autoPayCount = 0;
-        List<IOrderItem> expenses = new ArrayList<>();
         List<String> businessIds = businessList.stream().map(TbBusiness::getId).collect(Collectors.toList());
         List<TbBusinessItem> businessItems = tbBusinessItemService.findByBusinessId(businessIds);
 
@@ -311,20 +308,18 @@ public class OpenService {
                     RedisUtil.setByMINUTES(channel, carNo, 5);
                     tbBusinessItemService.buildExpenses(businessItems, expenses);
 //                    businessMoney = businessMoney.add(tbBusiness.getItemPrice());
-                    log.error("需要缴纳业务费用:{},{}", carNo, businessMoney.toString());
+//                    log.error("需要缴纳业务费用:{},{}", carNo, businessMoney.toString());
                     // return ResultJson.error("请缴纳业务费用");
                 }
             }
         }
         if (!expenses.isEmpty()) {
-            IOrderPriceRes res = syncService.orderPriceCal(expenses);
-            businessMoney = res.getTotalOrderPrice();
-            BUSINESS_MONEY_CACHE.put(carNo, businessMoney);
+            businessRes = syncService.orderPriceCal(expenses);
         }
         if (autoPayCount == businessList.size()) {
             log.info("车辆到达卡口进行扣停车费和业务费:{}", carNo);
             //自动缴费
-            boolean flag = automaticPay.payBusinessAndPartMoney(businessList, businessMoney, tbBusinessCar, chinaCarMoney, yueCarMoney);
+            boolean flag = automaticPay.payBusinessAndPartMoney(businessList, businessRes, tbBusinessCar, chinaRes, yueRes);
             if (flag) {
                 tbDeductionBindService.autoUnbindCar(tbBusinessCar.getCarNo());
                 freeOut(tbBusinessCar, now, channel, image);
@@ -332,6 +327,7 @@ public class OpenService {
             }
         }
         BigDecimal carMoney = chinaCarMoney.add(yueCarMoney);
+        BigDecimal businessMoney=businessRes.getTotalOrderPrice();
         BigDecimal total = businessMoney.add(carMoney);
         if (total.doubleValue() > 0) {
             String desc = "请缴";
@@ -351,12 +347,6 @@ public class OpenService {
 
 
     private void freeOut(TbBusinessCar tbBusinessCar, Date now, String outChannel, String base64Image) {
-        if (StrUtil.equals(tbBusinessCar.getPayType(), CarEnum.PayTypeEnum.NO_PAY_TYPE.getType())) {
-            BigDecimal partMoney = tbBusinessService.calculationPartMoney(tbBusinessCar.getRealInTime(), now, tbBusinessCar.getCarSize());
-            if (partMoney.doubleValue() <= 0) {
-                tbBusinessCar.setPayType(CarEnum.PayTypeEnum.FEE_TYPE.getType());
-            }
-        }
         tbBusinessCar.setRealOutTime(now).setTimeUpdate(now).setOutChannel(outChannel);
         if (tbBusinessCar.getPay() == 0) {
             tbBusinessCar.setPay(1);

+ 3 - 3
sp-server/src/main/java/com/pj/api/service/ApiService.java

@@ -158,12 +158,12 @@ public class ApiService {
         if (tbBusinessCar.getPayTime() != null) {
             startTime = tbBusinessCar.getPayTime();
         }
-        BigDecimal price = tbBusinessService.calculationPartMoney(startTime, now, tbBusinessCar.getCarSize());
+//        BigDecimal price = tbBusinessService.calculationPartMoney(startTime, now, tbBusinessCar.getCarSize());
         Map<String, Object> car = new HashMap<>();
         car.put("id", tbBusinessCar.getId());
         car.put("carNo", tbBusinessCar.getCarNo());
-        car.put("price", price);
-        result.put("total", price);
+//        car.put("price", price);
+//        result.put("total", price);
         result.put("cars", Collections.singleton(car));
         return result;
     }

+ 22 - 3
sp-server/src/main/java/com/pj/api/wx/bo/PriceBO.java

@@ -9,10 +9,29 @@ import java.math.BigDecimal;
 
 @Data
 @Accessors(chain = true)
-@AllArgsConstructor
-@NoArgsConstructor
+
 public class PriceBO {
     private String id;
-    private String uniqExpenseId;
     private BigDecimal p;
+    private String uniqExpenseId;
+    private String calculateId;
+    private String carDesc;
+    private String hourDesc;
+    //24小时内费用
+    private BigDecimal standard;
+    /**
+     * 额外
+     */
+    private BigDecimal extraPrice;
+
+    public PriceBO() {
+    }
+
+    public PriceBO(String id, BigDecimal p, String uniqExpenseId, String carDesc, String hourDesc) {
+        this.id = id;
+        this.p = p;
+        this.uniqExpenseId = uniqExpenseId;
+        this.carDesc = carDesc;
+        this.hourDesc = hourDesc;
+    }
 }

+ 3 - 2
sp-server/src/main/java/com/pj/api/wx/service/WxService.java

@@ -261,7 +261,8 @@ public class WxService {
                 items = items.stream().filter(item -> item.getPayStatus() == 0).collect(Collectors.toList());
                 for (TbBusiness tbBusiness : businessList) {
                     tbBusiness.setPayTime(payTime).setPayType(PayEnum.PayType.WX_PAY.getCode()).setConfirmInput(1).setConfirmInputTime(payTime)
-                            .setPayMoney(tbBusiness.getItemPrice()).setPayOpenid(payopenid).setCalculateId(tbOrder.getCalculateId())
+                            .setPayMoney(tbBusiness.getItemPrice()).setPayOpenid(payopenid)
+                            .setCalculateId(tbOrder.getCalculateId())
                             .setPayNo(transactionId).setOutTradeNo(outTradeNo);
                     tbBusiness.setPayStatus(PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode());
                     tbBusinessService.updateById(tbBusiness);
@@ -277,8 +278,8 @@ public class WxService {
                         }
                     });
                 }
+                items.forEach(tbBusinessItem -> tbBusinessItem.setPayStatus(1).setPayTime(finalPayTime).setCalculateId(tbOrder.getCalculateId()));
                 tbFeeDetailsService.chargeBusinessFee(items, transactionId, outTradeNo, payTime, PayEnum.PayType.WX_PAY);//添加items的收费明细
-                items.forEach(tbBusinessItem -> tbBusinessItem.setPayStatus(1).setPayTime(finalPayTime));
                 tbBusinessItemService.updateBatchById(items);
             }
             tbFeeStatisticsService.addOrUpdateStatistic(payTime);//更新当前日期的日统计

+ 2 - 2
sp-server/src/main/java/com/pj/constants/business/PartFeeEnum.java

@@ -10,10 +10,10 @@ import java.util.Arrays;
 @Getter
 @AllArgsConstructor
 public enum PartFeeEnum {
-    DAY_PART("1", "白天停车"),
-    NIGHT_PART("2", "夜间停车"),
     IN_24_HOURS("3","24小时内停车服务收费"),
     OUT_24_HOURS("4","停放超24小时停车服务收费"),
+    BIG_CAR("5","大型货车(含9.6米以上货车)"),
+    MIDDLER_CAR("6","中小型货车(9.6米以下货车)"),
     UNKNOW("-1", "未知"),
     ;
     private String no;

+ 4 - 4
sp-server/src/main/java/com/pj/project/sync/api/AsyncApi.java

@@ -34,15 +34,15 @@ public class AsyncApi {
      * @return
      */
     @PostMapping("item-type")
-    public AjaxJson syncItemType(@RequestBody String request) {
+    public int syncItemType(@RequestBody String request) {
         log.info("sync 业务类型:{}", request);
         tbItemTypeService.receive(request);
-        return AjaxJson.get(1, "成功");
+        return 1;
     }
     @PostMapping("item-detail")
-    public AjaxJson syncItemDetail(@RequestBody String request) {
+    public int syncItemDetail(@RequestBody String request) {
         log.info("sync 费项详情:{}", request);
         tbItemService.receive(request);
-        return AjaxJson.get(1, "成功");
+        return 1;
     }
 }

+ 8 - 1
sp-server/src/main/java/com/pj/project/sync/response/IOrderPriceRes.java

@@ -4,6 +4,7 @@ import cn.com.btxc.micro.uni.openapi.inter.OpenApi;
 import com.pj.project.sync.response.item.OrderPriceResultItem;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
@@ -12,6 +13,7 @@ import java.util.List;
 @Data
 @OpenApi(apiName = "REQ_006")
 @NoArgsConstructor
+@Accessors(chain = true)
 public class IOrderPriceRes implements Serializable {
 
     /**
@@ -22,7 +24,7 @@ public class IOrderPriceRes implements Serializable {
     /**
      * 订单应支付的总金额
      */
-    private BigDecimal totalOrderPrice;
+    private BigDecimal totalOrderPrice=BigDecimal.valueOf(0);
 
     /**
      * 单价命中结果
@@ -30,5 +32,10 @@ public class IOrderPriceRes implements Serializable {
     private List<OrderPriceResultItem> fireResult;
 
 
+    private String hourDesc;
+
+    private String carDesc;
+    private int over24Hour;
+    private String uniqueExpenseId;
 
 }

+ 6 - 0
sp-server/src/main/java/com/pj/project/sync/response/item/OrderPriceResultItem.java

@@ -5,6 +5,7 @@ import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
+import java.util.List;
 
 @NoArgsConstructor
 @Data
@@ -19,4 +20,9 @@ public class OrderPriceResultItem implements Serializable {
      * 命中价格(单价)
      */
     protected BigDecimal firePrice;
+    /**
+     * 公式计算中间变量(仅公式价格返回)
+     */
+    private List<PriceDetailItem> priceDetail;
+
 }

+ 11 - 0
sp-server/src/main/java/com/pj/project/sync/response/item/PriceDetailItem.java

@@ -0,0 +1,11 @@
+package com.pj.project.sync.response.item;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class PriceDetailItem implements Serializable {
+    private String key;
+    private String value;
+}

+ 54 - 18
sp-server/src/main/java/com/pj/project/tb_account/AutomaticPay.java

@@ -4,12 +4,15 @@ package com.pj.project.tb_account;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.log.StaticLog;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.pj.api.wx.bo.PriceBO;
 import com.pj.constants.business.CarEnum;
 import com.pj.constants.business.GoodsEnum;
 import com.pj.constants.business.PayEnum;
+import com.pj.project.sync.response.IOrderPriceRes;
+import com.pj.project.sync.response.item.PriceDetailItem;
 import com.pj.project.tb_business.TbBusiness;
 import com.pj.project.tb_business.TbBusinessService;
 import com.pj.project.tb_business_car.TbBusinessCar;
@@ -587,11 +590,10 @@ public class AutomaticPay {
      * 支付停车费
      *
      * @param tbBusinessCar
-     * @param partMoney
      * @param now
      * @return
      */
-    public boolean payPartMoney(TbBusinessCar tbBusinessCar, double partMoney, Date now) {
+    public boolean payPartMoney(TbBusinessCar tbBusinessCar, IOrderPriceRes orderPriceRes, Date now) {
         String carNo = tbBusinessCar.getCarNo();
         TbDeductionBind bind = tbDeductionBindService.getBindCarByPlate(carNo);
         //未绑定
@@ -602,15 +604,30 @@ public class AutomaticPay {
         String key = AesUtil.reverse(tbAccount.getAccSalt());
         BigDecimal balance = new BigDecimal(tbAccount.getTotalMoney());
         //不足
-        if (balance.doubleValue() < partMoney) {
+        BigDecimal partMoney = orderPriceRes.getTotalOrderPrice();
+        if (balance.compareTo(partMoney) < 0) {
             return false;
         }
-        balance = balance.subtract(new BigDecimal(partMoney));
+        balance = balance.subtract(partMoney);
         tbAccount.setTotalMoney(AesUtil.encryptECB(balance.toString(), key));
         tbAccountService.updateById(tbAccount);
-        tbBusinessCar.setMoney(new BigDecimal(partMoney)).setPayType(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType()).setPayTime(now);
+        tbBusinessCar.setMoney(partMoney).setPayType(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType()).setPayTime(now);
+        //todo 自动扣款修改
+        PriceBO priceBO = new PriceBO();
+        priceBO.setId(tbBusinessCar.getId()).setHourDesc(orderPriceRes.getHourDesc()).setCarDesc(orderPriceRes.getCarDesc())
+                .setCalculateId(orderPriceRes.getCalculateId()).setP(orderPriceRes.getTotalOrderPrice());
+        List<PriceDetailItem> priceDetailItems = orderPriceRes.getFireResult().get(0).getPriceDetail();
+        for (PriceDetailItem priceDetailItem : priceDetailItems) {
+            String k = StrUtil.trim(priceDetailItem.getKey()).toLowerCase();
+            String v = priceDetailItem.getValue();
+            if (k.equals("standard")) {
+                priceBO.setStandard(new BigDecimal(v));
+            } else if (k.equals("extraPrice")) {
+                priceBO.setExtraPrice(new BigDecimal(v));
+            }
+        }
         List<PriceBO> priceBOList = new ArrayList<PriceBO>() {{
-            add(new PriceBO(tbBusinessCar.getId(), tbBusinessCar.getMoney()));
+            add(priceBO);
         }};
         String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
         //车辆的扣费记录
@@ -625,17 +642,13 @@ public class AutomaticPay {
      * 支付停车费和业务费
      *
      * @param businessList
-     * @param businessMoney
-     * @param tbBusinessCar
-     * @param chinaCarMoney
-     * @param yueCarMoney
      * @return
      */
     public boolean payBusinessAndPartMoney(List<TbBusiness> businessList,
-                                           BigDecimal businessMoney,
+                                           IOrderPriceRes businessRes,
                                            TbBusinessCar tbBusinessCar,
-                                           BigDecimal chinaCarMoney,
-                                           BigDecimal yueCarMoney) {
+                                           IOrderPriceRes chinaCarRes,
+                                           IOrderPriceRes yueCarRes) {
         Date now = new Date();
         TbDeductionBind bind = null;
         for (TbBusiness tbBusiness : businessList) {
@@ -652,6 +665,9 @@ public class AutomaticPay {
         if (bind == null) {
             return false;
         }
+        BigDecimal businessMoney = businessRes.getTotalOrderPrice();
+        BigDecimal chinaCarMoney = chinaCarRes.getTotalOrderPrice();
+        BigDecimal yueCarMoney = yueCarRes.getTotalOrderPrice();
         BigDecimal totalMoney = businessMoney.add(chinaCarMoney).add(yueCarMoney).add(chinaCarMoney);
         TbAccount tbAccount = tbAccountService.getByCustomerId(bind.getCustomerId());
         String key = AesUtil.reverse(tbAccount.getAccSalt());
@@ -663,20 +679,40 @@ public class AutomaticPay {
         balance = balance.subtract(totalMoney);
         tbAccount.setTotalMoney(AesUtil.encryptECB(balance.toString(), key));
         tbAccountService.updateById(tbAccount);
+        String businessCalculateId = businessRes.getCalculateId();
         businessList.forEach(tbBusiness -> {
-            tbBusiness.setPayStatus(PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode())
+            tbBusiness.setPayStatus(PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode()).setCalculateId(businessCalculateId)
                     .setPayMoney(tbBusiness.getItemPrice()).setTotalMoney(tbBusiness.getItemPrice());
         });
         tbBusinessService.updateBatchById(businessList);
         List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findByBusinessIdList(businessList.stream().map(TbBusiness::getId).collect(Collectors.toList()));
-        tbBusinessItems.parallelStream().forEach(item -> item.setPayStatus(1).setPayTime(now));
+        tbBusinessItems.parallelStream().forEach(item -> item.setPayStatus(1).setPayTime(now).setCalculateId(businessCalculateId));
         tbBusinessItemService.updateBatchById(tbBusinessItems);
         tbBusinessCar.setPay(1).setPayType(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType())
                 .setPayTime(now);
         tbBusinessCarService.updateById(tbBusinessCar);
-        List<PriceBO> priceBOList = new ArrayList<PriceBO>() {{
-            add(new PriceBO(tbBusinessCar.getId(), tbBusinessCar.getMoney()));
-        }};
+        //todo 构造统计数据
+        BigDecimal p = chinaCarRes.getTotalOrderPrice();
+        String uniqExpenseId = chinaCarRes.getUniqueExpenseId();
+        String calculateId = chinaCarRes.getCalculateId();
+        String carDesc = chinaCarRes.getCarDesc();
+        String hourDesc = chinaCarRes.getHourDesc();
+        List<PriceDetailItem> items = chinaCarRes.getFireResult().get(0).getPriceDetail();
+        if (yueCarRes.getTotalOrderPrice().intValue() > 0) {
+            items = yueCarRes.getFireResult().get(0).getPriceDetail();
+        }
+        PriceBO priceBO = new PriceBO();
+        List<PriceBO> priceBOList = new ArrayList<>();
+        priceBO.setId(tbBusinessCar.getId()).setP(p).setCalculateId(calculateId)
+                .setCarDesc(carDesc).setHourDesc(hourDesc)
+                .setUniqExpenseId(uniqExpenseId);
+        for (PriceDetailItem item : items) {
+            if (item.getKey().toLowerCase().trim().equals("standard")) {
+                priceBO.setStandard(new BigDecimal(item.getValue()));
+            } else if (item.getKey().toLowerCase().trim().equals("extraPrice")) {
+                priceBO.setStandard(new BigDecimal(item.getValue()));
+            }
+        }
         String plate = tbBusinessCar.getCarNo();
         String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
         List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.chargeParkFee(priceBOList, null, null, now, PayEnum.PayType.PER_PAY);

+ 49 - 21
sp-server/src/main/java/com/pj/project/tb_business/TbBusinessService.java

@@ -27,10 +27,7 @@ import com.pj.api.wx.bo.MsgDataBO;
 import com.pj.api.wx.bo.PriceBO;
 import com.pj.api.wx.service.WxService;
 import com.pj.constants.UserTypeEnum;
-import com.pj.constants.business.CarEnum;
-import com.pj.constants.business.GoodsEnum;
-import com.pj.constants.business.OAResultEnum;
-import com.pj.constants.business.PayEnum;
+import com.pj.constants.business.*;
 import com.pj.current.config.*;
 import com.pj.current.satoken.StpUserUtil;
 import com.pj.project.oa.bo.OAResultBO;
@@ -44,6 +41,7 @@ import com.pj.project.sync.request.item.IFactorItem;
 import com.pj.project.sync.request.item.IOrderItem;
 import com.pj.project.sync.response.IOrderPriceRes;
 import com.pj.project.sync.response.item.IExpenseItem;
+import com.pj.project.sync.response.item.PriceDetailItem;
 import com.pj.project.tb_account.AutomaticPay;
 import com.pj.project.tb_account.TbAccount;
 import com.pj.project.tb_account.TbAccountService;
@@ -76,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;
@@ -184,6 +184,8 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
     private SyncService syncService;
     @Resource
     private TbItemFacService tbItemFacService;
+    @Resource
+    private TbMildCarService tbMildCarService;
 
     private final List<String> CAR_LIST = StrUtil.splitTrim("浙,粤,京,津,冀,晋,蒙,辽,黑,沪,吉,苏,皖,赣,鲁,豫,鄂,湘,桂,琼,渝,川,贵,云,藏, 陕, 甘, 青, 宁", ",");
 
@@ -301,7 +303,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
             TbGoods tbGoods = tbGoodsService.getById(business.getGoodsId());
             //只有改业务是在确认后扣费才需要执行自动扣费
             if (GoodsEnum.DeductionTypeEnum.BUSINESS_OK.getCode().equals(tbGoods.getAutoDeductionType())) {
-                automaticPay.run(business.getId(), null, 2);
+                //automaticPay.run(business.getId(), null, 2);
             }
         });
     }
@@ -322,25 +324,38 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
     /**
      * 计费系统计算停车费
      *
-     * @param iTime   入场时间
-     * @param oTime   离场时间
-     * @param carSize 车长
+     * @param iTime 入场时间
+     * @param oTime 离场时间
      * @return
      */
-    public IOrderPriceRes getPartMoney(Date iTime, Date oTime, double carSize, String carColor) {
+    public IOrderPriceRes getPartMoney(Date iTime, Date oTime, String carNo, String carColor) {
         long minutes = DateUtil.between(iTime, oTime, DateUnit.MINUTE);
         double hours = NumberUtil.div(minutes, 60, 1);
         List<IOrderItem> expenses = new ArrayList<>();
-        TbItemFac tbItemFac = tbItemFacService.getPartFac(carSize);
-        if (tbItemFac == null) {
+        TbMildCar tbMildCar = tbMildCarService.findByCarNo(carNo);
+        IOrderPriceRes res = new IOrderPriceRes();
+        double carSize = 8D;
+        res.setCarDesc(PartFeeEnum.MIDDLER_CAR.getDesc());
+        res.setHourDesc(PartFeeEnum.IN_24_HOURS.getDesc());
+        if (tbMildCar == null) {
+            // 9.6以上
+            carSize = 13D;
+            res.setCarDesc(PartFeeEnum.BIG_CAR.getDesc());
+        }
+        if (hours > 24) {
+            res.setOver24Hour(1);
+            res.setHourDesc(PartFeeEnum.OUT_24_HOURS.getDesc());
+        }
+        List<TbItemFac> list = tbItemFacService.list();
+        if (list.isEmpty()) {
             throw new AjaxError("未配置停车费规则");
         }
-        TbItem tbItem = tbItemService.getById(tbItemFac.getItemId());
+        TbItemFac itemFac = list.get(0);
         IOrderItem orderItem = new IOrderItem();
-        orderItem.setUniqExpenseId(tbItem.getItemCode()).setExpenseNum(1);
-        List<TbItemFac> facList = tbItemFacService.getByItemId(tbItem.getId());
+         String uniqueExpenseId=itemFac.getUniqueExpenseId();
+        orderItem.setUniqExpenseId(uniqueExpenseId).setExpenseNum(1);
         List<IFactorItem> factors = new ArrayList<>();
-        facList.forEach(fac -> {
+        for (TbItemFac fac : list) {
             String operator = fac.getOperator();
             if (StrUtil.equals(operator, "carSize")) {
                 IFactorItem iFactorItem = new IFactorItem();
@@ -358,10 +373,16 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
                 iFactorItem.setFacParams(carColor);
                 factors.add(iFactorItem);
             }
-        });
+        }
         orderItem.setFactors(factors);
         expenses.add(orderItem);
-        return syncService.orderPriceCal(expenses);
+        IOrderPriceRes orderPriceRes = syncService.orderPriceCal(expenses);
+        res.setCalculateId(orderPriceRes.getCalculateId())
+                .setUniqueExpenseId(uniqueExpenseId)
+                .setFireResult(orderPriceRes.getFireResult())
+                .setTotalOrderPrice(orderPriceRes.getTotalOrderPrice());
+        log.info("part money resp:{}",JSONUtil.toJsonStr(res));
+        return res;
     }
 
     /**
@@ -438,6 +459,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
 
     }
 
+
     /**
      * 微信端获取缴费信息
      *
@@ -524,12 +546,18 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
                     partMoney = new BigDecimal("0");
                 }
                 if (partMoney.doubleValue() == 1) {
-                    IOrderPriceRes partPriceRes = getPartMoney(inTime, outTime, tbBusinessCar.getCarSize(), tbBusinessCar.getColor());
-                   BigDecimal partPrice=partPriceRes.getTotalOrderPrice();
+                    IOrderPriceRes partPriceRes = getPartMoney(inTime, outTime, tbBusinessCar.getCarNo(), tbBusinessCar.getColor());
+                    BigDecimal partPrice = partPriceRes.getTotalOrderPrice();
                     carCalculateIds.add(partPriceRes.getCalculateId());
-                    partMoney =partPrice;
-                    if (partPrice.doubleValue()>0){
+                    partMoney = partPrice;
+                    if (partPrice.doubleValue() > 0) {
                         carMap.put("uniqExpenseId", partPriceRes.getFireResult().get(0).getUniqExpenseId());
+                        carMap.put("carDesc", partPriceRes.getCarDesc());
+                        carMap.put("calculateId;", partPriceRes.getCalculateId());
+                        carMap.put("hourDesc", partPriceRes.getHourDesc());
+                        carMap.put("over24Hour", partPriceRes.getOver24Hour());
+                        partPriceRes.getFireResult().get(0)
+                                .getPriceDetail().forEach(obj->carMap.put(obj.getKey(), obj.getValue()));
                     }
                     //todo 计算停车费
                 }

+ 0 - 432
sp-server/src/main/java/com/pj/project/tb_business_item/PayTask.java

@@ -1,432 +0,0 @@
-package com.pj.project.tb_business_item;
-
-
-import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.codec.Base64;
-import cn.hutool.core.util.NumberUtil;
-import cn.hutool.core.util.ObjectUtil;
-import cn.hutool.core.util.RandomUtil;
-import cn.hutool.core.util.StrUtil;
-import cn.hutool.extra.spring.SpringUtil;
-import cn.hutool.log.StaticLog;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.pj.api.wx.bo.PriceBO;
-import com.pj.constants.business.CarEnum;
-import com.pj.constants.business.GoodsEnum;
-import com.pj.constants.business.PayEnum;
-import com.pj.current.task.Task;
-import com.pj.project.tb_account.TbAccount;
-import com.pj.project.tb_account.TbAccountService;
-import com.pj.project.tb_business.TbBusiness;
-import com.pj.project.tb_business.TbBusinessService;
-import com.pj.project.tb_business_car.TbBusinessCar;
-import com.pj.project.tb_business_car.TbBusinessCarService;
-import com.pj.project.tb_deduction_bind.TbDeductionBind;
-import com.pj.project.tb_deduction_bind.TbDeductionBindService;
-import com.pj.project.tb_deduction_record.TbDeductionRecord;
-import com.pj.project.tb_fee_details.TbFeeDetails;
-import com.pj.project.tb_fee_details.TbFeeDetailsService;
-import com.pj.project.tb_goods.TbGoods;
-import com.pj.project.tb_invoice_order.TbInvoiceOrder;
-import com.pj.project.tb_invoice_order.TbInvoiceOrderService;
-import com.pj.project.tb_pay_record.TbPayRecord;
-import com.pj.project.tb_pay_record.TbPayRecordService;
-import com.pj.utils.AesUtil;
-import com.pj.utils.sg.NbUtil;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.transaction.interceptor.TransactionAspectSupport;
-
-import java.math.BigDecimal;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-
-public class PayTask extends Task {
-
-    private String businessId;
-    private String customerId;
-    private String plate;
-
-    public PayTask(String businessId, long delayInMilliseconds, String customerId, String plate) {
-        super(businessId, delayInMilliseconds);
-        this.businessId = businessId;
-        this.customerId = customerId;
-        this.plate = plate;
-    }
-
-    @Override
-    @Transactional(rollbackFor={RuntimeException.class, Exception.class})
-    public void run() {
-//        StaticLog.info("开始执行自动扣款业务:{},{}", customerId, businessId);
-//        TbAccountService tbAccountService = SpringUtil.getBean(TbAccountService.class);
-//        TbAccount tbAccount = tbAccountService.getByCustomerId(customerId);
-//        if (tbAccount == null) {
-//            StaticLog.info("该客户还未开通存款账户,退出扣款程序:{}", customerId);
-//            return;
-//        }
-//        String totalMoney = AesUtil.decryptECB(tbAccount.getTotalMoney(),AesUtil.reverse(tbAccount.getAccSalt()));
-//        BigDecimal money = new BigDecimal(0);
-//        if (NumberUtil.isNumber(totalMoney)) {
-//            money = new BigDecimal(totalMoney);
-//        }
-//        chargeBusinessFee(null,null);
-//       // BigDecimal money = new BigDecimal(Base64.decodeStr(totalMoney));
-//        TbBusinessService tbBusinessService = SpringUtil.getBean(TbBusinessService.class);
-//        TbBusiness tbBusiness = tbBusinessService.getById(businessId);
-//        TbBusinessItemService tbBusinessItemService = SpringUtil.getBean(TbBusinessItemService.class);
-//        List<TbBusinessItem> list = tbBusinessItemService.findByBusinessId(businessId);
-//        List<TbBusinessItem> allList = list;
-//        long notConfirmCount = list.stream()
-//                .filter(tbBusinessItem -> tbBusinessItem.getConfirm() == 0 && !StrUtil.equals(tbBusinessItem.getBusinessType(), "0"))
-//                .count();
-//        Date now = new Date();
-//        if (notConfirmCount == 0) {
-//            BigDecimal shouldPay = new BigDecimal("0");
-//            list = allList.stream().filter(tbBusinessItem -> tbBusinessItem.getPayStatus() == 0).collect(Collectors.toList());
-//            for (TbBusinessItem tbBusinessItem : list) {
-//                tbBusinessItem.setPayStatus(1).setPayTime(now);
-//                shouldPay = shouldPay.add(tbBusinessItem.getItemPrice());
-//            }
-//
-//            TbBusinessCarService tbBusinessCarService = SpringUtil.getBean(TbBusinessCarService.class);
-//            List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(businessId);
-//            cars = cars.stream().filter(tbBusinessCar -> tbBusinessCar.getPay() == 0).collect(Collectors.toList());
-//            for (TbBusinessCar tbBusinessCar : cars) {
-//                shouldPay = shouldPay.add(tbBusinessCar.getBasePartMoney());
-//                tbBusinessCar.setPayTime(now).setPay(1);
-//            }
-//            if (shouldPay.subtract(money).doubleValue() > 0) {
-//                StaticLog.error("账户支付余额不足");
-//                return;
-//            }
-//            String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
-//            tbBusiness.setPayMoney(tbBusiness.getPayMoney().add(shouldPay)).setPayTime(now)
-//                    .setPayNo(no);
-//            tbBusiness.setPayStatus(tbBusiness.getPayMoney().equals(tbBusiness.getTotalMoney()) ? 3 : 4);
-//            tbBusinessItemService.updateBatchById(list);
-//            tbBusinessService.updateById(tbBusiness);
-//            tbBusinessCarService.updateBatchById(cars);
-//            BigDecimal leftMoney = money.subtract(shouldPay);
-//            tbAccount.setTotalMoney(Base64.encode(leftMoney.toString()));
-//            tbAccountService.updateById(tbAccount);
-//            TbPayRecord payRecord = new TbPayRecord();
-//            TbPayRecordService tbPayRecordService = SpringUtil.getBean(TbPayRecordService.class);
-//            payRecord.setCreateTime(now)
-//                    .setOutTradeNo(no)
-//                    .setTransactionId(no)
-//                    .setPayMoney(shouldPay)
-//                    .setCustomerId(tbBusiness.getCustomerId()).setCustomerName(tbBusiness.getCustomerName());
-//            tbPayRecordService.save(payRecord);
-//        }
-        try {
-             TbBusinessCarService tbBusinessCarService = SpringUtil.getBean(TbBusinessCarService.class);
-        if(!NbUtil.isNull(this.businessId) && NbUtil.isNull(this.plate)){
-          List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(this.businessId);
-             for (TbBusinessCar car : cars){
-              this.doBusinessFee(this.businessId,car.getCarNo());
-          }
-           }else {
-                    doOutFee(this.plate);
-            }
-        }catch (RuntimeException e){
-
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-
-        }
-
-
-    }
-
-    /**
-     * 收业务费
-     * @param businessId
-     */
-    private void doBusinessFee(String businessId,String plate){
-        if(!NumberUtil.isNumber(businessId) || NbUtil.isNull(plate)){
-            return;
-        }
-        StaticLog.info("开始收取业务费:{}" , businessId);
-        TbBusinessService tbBusinessService = SpringUtil.getBean(TbBusinessService.class);
-        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;
-        }
-        TbDeductionBindService deductionBindService = SpringUtil.getBean(TbDeductionBindService.class);
-        if(!deductionBindService.checkBind(tbBusiness.getCustomerId(),plate)){
-            StaticLog.info("业务车辆未绑定指定客户的预存款账户,退出收费程序:{}{}",businessId,tbBusiness.getCustomerName());
-            return;
-        }
-        TbBusinessCarService tbBusinessCarService = SpringUtil.getBean(TbBusinessCarService.class);
-        List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(businessId);
-        TbAccountService tbAccountService = SpringUtil.getBean(TbAccountService.class);
-        TbAccount tbAccount = tbAccountService.getByCustomerId(tbBusiness.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()==tbBusiness.getAutoDeductionType())&&NbUtil.isNull(this.plate);
-        if(isOut){
-            parkingMoneyBig = getParkings(cars);
-            balance = balance.subtract(parkingMoneyBig);
-        }
-        if(balance.doubleValue()<0){
-            StaticLog.info("支付账户余额不足!,退出收费程序:{}" , businessId);
-            deductionBindService.setFeeFailRecord(tbBusiness.getCustomerId(),plate,
-                    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();
-        TbBusinessItemService tbBusinessItemService = SpringUtil.getBean(TbBusinessItemService.class);
-        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(tbBusiness.getCustomerId(),plate,tbBusiness.getItemPrice());
-        //生成收费明细
-        TbFeeDetailsService tbFeeDetailsService = SpringUtil.getBean(TbFeeDetailsService.class);
-        List<TbFeeDetails> tbFeeDetailsList = tbFeeDetailsService.autoChargeBusinessFee(
-                businessItems,null,null,now);
-        //生成扣费记录
-        createTbDeductionRecord(tbFeeDetailsList,deductionBindService,tbFeeDetailsService,tbAccount,
-                tbBusiness,totalMoneyBig,plate);
-        //生成开票信息
-        createTbInvoiceOrder(tbBusiness,cars,parkingMoneyBig);
-        if(isOut){
-            List<PriceBO> priceBOList=cars.stream().map(tbBusinessCar -> new PriceBO(tbBusinessCar.getId(),tbBusinessCar.getMoney())).collect(Collectors.toList());
-            List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.chargeParkFee(
-                    priceBOList,null,null,now,PayEnum.PayType.PER_PAY);
-            createTbDeductionRecord(parkFeeDetailsList,deductionBindService,tbFeeDetailsService,tbAccount,
-                    tbBusiness,totalMoneyBig,plate);
-            deductionBindService.autoUnbindCar(cars);
-        }
-        StaticLog.info("预充值自动缴费成功!,退出收费程序:{}{}" , businessId,tbAccount.getCustomerId());
-    }
-
-    /**
-     * 出场所收费,根据车牌号
-     * @param plate
-     */
-    private void doOutFee(String plate){
-        if(NbUtil.isNull(plate)){
-            return;
-        }
-        TbBusinessCarService tbBusinessCarService = SpringUtil.getBean(TbBusinessCarService.class);
-        TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(plate);
-        if(tbBusinessCar==null){
-            return;
-        }
-        TbBusinessService tbBusinessService = SpringUtil.getBean(TbBusinessService.class);
-        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());
-            }
-        }
-
-    }
-
-
-    private void doParkingFee(TbBusinessCar car, double parkingFee){
-        if(car==null)return;
-        StaticLog.info("开始自动缴纳停车费:{}" , car.getCarNo());
-        if(car.getPay()==1 || car.getPayTime()!=null){
-            StaticLog.info("该车辆已缴纳过停车费!,退出收费程序:{}" , car.getCarNo());
-            return;
-        }
-        TbAccountService tbAccountService = SpringUtil.getBean(TbAccountService.class);
-        TbAccount account = tbAccountService.getTbAccountByPlate(car.getCarNo());
-        if (account==null){
-            StaticLog.info("该车辆还未绑定客户预存款账户!,退出收费程序:{}" , car.getCarNo());
-            return;
-        }
-        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 parkFeeBig = null;
-        if(parkingFee>0){
-            parkFeeBig = new BigDecimal(String.valueOf(parkingFee));
-        }else {
-            TbBusinessService tbBusinessService = SpringUtil.getBean(TbBusinessService.class);
-            parkFeeBig = caulatePrice(car, new Date(), tbBusinessService);
-        }
-        BigDecimal balance = totalBig.subtract(parkFeeBig);
-        if(balance.doubleValue()<0){
-            StaticLog.info("支付账户余额不足!,退出收费程序:{}" , car.getCarNo());
-            return;
-        }
-        car.setMoney(parkFeeBig);
-        updateTbBusinessCar(car);
-        account.setTotalMoney(AesUtil.encryptECB(balance.toString(),key));
-        account.updateById();
-//        List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.autoChargeParkFee(
-//                cars,null,null,now);
-//        createTbDeductionRecord(parkFeeDetailsList,deductionBindService,tbFeeDetailsService,tbAccount,
-//                tbBusiness,totalMoneyBig,plate);
-//        deductionBindService.autoUnbindCar(cars);
-        StaticLog.info("停车费自动缴费成功!,退出收费程序:{}" , car.getCarNo());
-    }
-
-    /**
-     * 生成扣费记录
-     * @param tbFeeDetailsList
-     * @param deductionBindService
-     * @param tbFeeDetailsService
-     * @param tbAccount
-     * @param tbBusiness
-     * @param totalMoneyBig
-     */
-    private void createTbDeductionRecord(List<TbFeeDetails> tbFeeDetailsList,TbDeductionBindService deductionBindService,
-                                         TbFeeDetailsService tbFeeDetailsService,TbAccount tbAccount,
-                                         TbBusiness tbBusiness,BigDecimal totalMoneyBig,String plate){
-        if(tbFeeDetailsList==null)return;
-        int i = 0;
-        for (TbFeeDetails feeDetails : tbFeeDetailsList){
-            TbDeductionRecord deductionRecord = BeanUtil.toBean(feeDetails,TbDeductionRecord.class);
-            if(GoodsEnum.DeductionTypeEnum.BUSINESS_OK.getCode()==tbBusiness.getAutoDeductionType()){
-                String bindIdStr = deductionBindService.getBindId(plate);
-                deductionRecord.setDeductionBindId(bindIdStr);
-            }
-            String totalStr = null;
-//            if(!NbUtil.isNull(totalStr) && !NumberUtil.isNumber(totalStr)){
-//                totalStr = AesUtil.decryptECB(totalStr,AesUtil.reverse(tbAccount.getAccSalt()));
-//            }
-            if(totalMoneyBig!=null && feeDetails.getNoTaxPrice()!=null){
-                if(i!=0){
-                    totalMoneyBig = new BigDecimal(deductionRecord.getTotalMoney());
-                }
-                totalStr = totalMoneyBig.subtract(feeDetails.getNoTaxPrice()).toString();
-            }
-            deductionRecord.setId(null);
-            deductionRecord.setCustomerId(tbAccount.getCustomerId());
-            deductionRecord.setFeeDetailsId(feeDetails.getId());
-            deductionRecord.setOriginalMoney(totalMoneyBig.toString());
-            deductionRecord.setDeductMoney(feeDetails.getNoTaxPrice());
-            deductionRecord.setTotalMoney(totalStr);
-            deductionRecord.setReviewStatus(0);
-            deductionRecord.setCarNo(plate);
-            deductionRecord.insert();
-            feeDetails.setCarNo(plate);
-            feeDetails.setCustomerId(tbAccount.getCustomerId());
-            tbFeeDetailsService.updateById(feeDetails);
-            i++;
-        }
-    }
-
-    /**
-     * 更新停车费状态
-     */
-    private void updateTbBusinessCar(TbBusinessCar car){
-        if(car == null)return;
-        car.setPay(1).setMoney(car.getMoney()).setPayTime(new Date()).setPayType(
-                    CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType());
-        car.updateById();
-    }
-
-    /**
-     * 更新停车费状态
-     */
-    private void updateTbBusinessCars(List<TbBusinessCar> cars){
-        if(cars == null)return;
-        for (TbBusinessCar car:cars){
-            updateTbBusinessCar(car);
-        }
-    }
-
-    /**
-     * 生成开票订单信息
-     * @param tbBusiness
-     */
-    private void createTbInvoiceOrder(TbBusiness tbBusiness,List<TbBusinessCar> cars, BigDecimal parkingFee){
-        TbInvoiceOrder invoiceOrder = new TbInvoiceOrder();
-        List<String> businessNameList = new ArrayList<>();
-        List<String> businessNoList = new ArrayList<>();
-        List<String> carNos = new ArrayList<>();
-        businessNoList.add(tbBusiness.getNo());
-        carNos.add(tbBusiness.getCardNo());
-        businessNameList.add(tbBusiness.getGoodsName());
-        if(cars!=null && (GoodsEnum.DeductionTypeEnum.OUT_KK.getCode()==tbBusiness.getAutoDeductionType()) &&
-                NbUtil.isNull(this.plate)){
-            businessNameList.add("停车费");
-            for (TbBusinessCar car : cars) {
-                businessNoList.add(car.getNo());
-                carNos.add(car.getCarNo());
-            }
-        }
-        String businessNameStr = businessNameList.stream().map(String::valueOf).collect(Collectors.joining(","));
-        String businessNoStr = businessNoList.stream().map(String::valueOf).collect(Collectors.joining(","));
-        String carNoStr = carNos.stream().map(String::valueOf).collect(Collectors.joining(","));
-        BigDecimal billMoney = tbBusiness.getItemPrice();
-        if(parkingFee!=null){
-            billMoney = parkingFee.add(billMoney);
-        }
-        invoiceOrder.setBusinessName(businessNameStr).setBusinessNo(businessNoStr).setCarNo(carNoStr)
-                    .setTransactionId(null).setBillMoney(billMoney)
-                    .setStatus(0).setCreateTime(new Date()).setCustomerId(tbBusiness.getCustomerId());
-        TbInvoiceOrderService invoiceOrderService = SpringUtil.getBean(TbInvoiceOrderService.class);
-        invoiceOrderService.save(invoiceOrder);
-    }
-
-    /**
-     * 生成停车费
-     * @param tbBusinessCar
-     * @param now
-     * @return
-     */
-    private BigDecimal caulatePrice(TbBusinessCar tbBusinessCar, Date now, TbBusinessService tbBusinessService) {
-        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.getCarSize());
-        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");
-        TbBusinessService tbBusinessService = SpringUtil.getBean(TbBusinessService.class);
-        for (TbBusinessCar tbBusinessCar:cars){
-            value = value.add(this.caulatePrice(tbBusinessCar,now,tbBusinessService));
-        }
-        return value;
-    }
-}

+ 5 - 0
sp-server/src/main/java/com/pj/project/tb_deduction_record/TbDeductionRecord.java

@@ -253,4 +253,9 @@ public class TbDeductionRecord extends Model<TbDeductionRecord> implements Seria
      */
     private String preOrderNum;
 
+    /**
+     * 统计非中心ID
+     */
+    private String calculateId;
+
 }

+ 1 - 1
sp-server/src/main/java/com/pj/project/tb_fee_details/TbFeeDetails.java

@@ -139,7 +139,7 @@ public class TbFeeDetails implements Serializable {
      * 开票主体
      */
     private String entityName;
-
+    private String calculateId;
 
     /**
      * 不含税款

+ 1 - 0
sp-server/src/main/java/com/pj/project/tb_fee_details/TbFeeDetailsMapper.xml

@@ -75,6 +75,7 @@
         <where>
             <if test=' this.has("id") '>and id = #{id}</if>
             <if test=' this.has("businessId") '>and business_id = #{businessId}</if>
+            <if test=' this.has("transactionId") '>and transaction_id = #{transactionId}</if>
             <if test=' this.has("businessNo") '>and (business_no like concat('%',#{businessNo},'%')
                                                     or business_car_no like concat('%',#{businessNo},'%'))</if>
             <if test=' this.has("carNo") '>and car_no like concat('%',#{carNo},'%')</if>

+ 25 - 19
sp-server/src/main/java/com/pj/project/tb_fee_details/TbFeeDetailsService.java

@@ -46,6 +46,10 @@ import com.pj.project.tb_fee_statistics.TbFeeStatistics;
 import com.pj.project.tb_fee_statistics.TbFeeStatisticsService;
 import com.pj.project.tb_goods.TbGoods;
 import com.pj.project.tb_goods.TbGoodsService;
+import com.pj.project.tb_item.TbItem;
+import com.pj.project.tb_item.TbItemService;
+import com.pj.project.tb_item_fac.TbItemFac;
+import com.pj.project.tb_item_fac.TbItemFacService;
 import com.pj.project4sp.admin.SpAdmin;
 import com.pj.project4sp.global.BusinessException;
 import com.pj.project4sp.role.SpRole;
@@ -102,6 +106,10 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
     TaskService taskService;
     @Resource
     private TbFeeItemService tbFeeItemService;
+    @Resource
+    private TbItemFacService tbItemFacService;
+    @Resource
+    private TbItemService tbItemService;
 
     /**
      * 增
@@ -168,6 +176,9 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
      */
     public List<TbFeeDetails> chargeParkFee(List<PriceBO> cars, String transactionId, String outTradeNo, Date now, PayEnum.PayType payType) {
         List<TbFeeDetails> details = new ArrayList<>();
+        String uniqExpenseId = cars.get(0).getUniqExpenseId();
+        TbItem tbItem = tbItemService.findByCode(uniqExpenseId);
+        BigDecimal taxRate=BigDecimal.valueOf(tbItem.getTaxRate()).divide(BigDecimal.valueOf(100),2,BigDecimal.ROUND_UP);
         for (PriceBO bo1 : cars) {
             //本次支付的停车费金额
             BigDecimal payPrice = bo1.getP();
@@ -180,21 +191,14 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
                 bindIdStr = tbDeductionBindService.getBindId(car.getCarNo());
             }
             //24小时内的停车费
-            BigDecimal in24Price = partConfig.getBasePrice();
+            BigDecimal in24Price = bo1.getStandard();
             TbFeeDetails in24Detail = new TbFeeDetails();
-            TbFeeDetails out24Details = new TbFeeDetails();
-            in24Detail.setItemName("大型货车(含9.6米以上货车)");
-            out24Details.setItemName("大型货车(含9.6米以上货车)");
-            //4.2~9.6
-            if (car.getCarSize() <= partConfig.getMildCarLength() && car.getCarSize() > partConfig.getFreeCarLength()) {
-                in24Price = partConfig.getMildCarBasePrice();
-                in24Detail.setItemName("中小型货车(9.6米以下货车)");
-                out24Details.setItemName("中小型货车(9.6米以下货车)");
-            }
+            in24Detail.setItemName(bo1.getCarDesc());
+
             //24小时内的停车费
-            in24Detail.setNum(1).setItemTypeName(PartFeeEnum.IN_24_HOURS.getDesc())
+            in24Detail.setNum(1).setItemTypeName(bo1.getHourDesc()).setCalculateId(bo1.getCalculateId())
                     .setUnitPrice(in24Price).setItemPrice(in24Price).setModule(payType.getDesc()).setBusinessId(bindIdStr);
-            setFee(in24Detail, car, transactionId, outTradeNo, now);
+            setFee(taxRate, in24Detail, car, transactionId, outTradeNo, now);
             String type = StrUtil.isEmpty(in24Detail.getId()) ? SyncTypeEnum.INSERT.getCode() : SyncTypeEnum.UPDATE.getCode();
             saveOrUpdate(in24Detail);
             details.add(in24Detail);
@@ -202,11 +206,13 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
             //24小时外的停车费
             BigDecimal out24Price = payPrice.subtract(in24Price);
             if (out24Price.compareTo(BigDecimal.valueOf(0)) > 0) {
-                BigDecimal unitPrice = in24Price.add(partConfig.getExtraPrice());
+                TbFeeDetails out24Details = new TbFeeDetails();
+                out24Details.setItemName(bo1.getCarDesc());
+                BigDecimal unitPrice = bo1.getExtraPrice();
                 int num = out24Price.divide(unitPrice, BigDecimal.ROUND_UP, 0).intValue();
                 out24Details.setNum(num).setItemTypeName(PartFeeEnum.OUT_24_HOURS.getDesc())
                         .setUnitPrice(unitPrice).setItemPrice(out24Price).setModule(payType.getDesc()).setBusinessId(bindIdStr);
-                setFee(out24Details, car, transactionId, outTradeNo, now);
+                setFee(taxRate, out24Details, car, transactionId, outTradeNo, now);
                 type = StrUtil.isEmpty(out24Details.getId()) ? SyncTypeEnum.INSERT.getCode() : SyncTypeEnum.UPDATE.getCode();
                 saveOrUpdate(out24Details);
                 taskService.addTask(new FeeDetailSyncTask(RandomUtil.randomNumbers(10), 1000, out24Details.getId(), type, payType));
@@ -216,11 +222,11 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
         return details;
     }
 
-    private void setFee(TbFeeDetails parkFee, TbBusinessCar car, String transactionId, String outTradeNo, Date now) {
+    private void setFee(BigDecimal taxRate, TbFeeDetails parkFee, TbBusinessCar car, String transactionId, String outTradeNo, Date now) {
         String nowStr = DateUtil.format(now, "yyyy-MM-dd HH:mm:ss");
         String toDay = DateUtil.format(now, "yyyy-MM-dd");
-        parkFee.setTaxRate(partConfig.getTaxRate());
-        BigDecimal taxPrice = parkFee.getItemPrice().divide(BigDecimal.valueOf(1).add(parkFee.getTaxRate()), 2, BigDecimal.ROUND_HALF_UP).multiply(parkFee.getTaxRate());
+        parkFee.setTaxRate(taxRate);
+        BigDecimal taxPrice = parkFee.getItemPrice().divide(BigDecimal.valueOf(1).add(taxRate), 2, BigDecimal.ROUND_HALF_UP).multiply(taxRate);
         taxPrice = taxPrice.setScale(2, BigDecimal.ROUND_HALF_UP);
         BigDecimal noTaxPrice = parkFee.getItemPrice().subtract(taxPrice);
         noTaxPrice = noTaxPrice.setScale(2, BigDecimal.ROUND_HALF_UP);
@@ -291,7 +297,7 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
             businessCarNos = StrUtil.sub(businessCarNos, 0, businessCarNos.length() - 1);
             businessFeeDetail.setBusinessId(item.getBusinessId()).setBusinessNo(business.getNo())
                     .setBusinessItemNo(item.getNo()).setBusinessCarId(businessCarIds).setBusinessCarNo(businessCarNos)
-                    .setCarNo(carNo)
+                    .setCarNo(carNo).setCalculateId(item.getCalculateId())
                     .setItemPrice(item.getTotal()).setUnitPrice(item.getItemPrice()).setNoTaxPrice(noTaxPrice).setTaxPrice(taxPrice)
                     .setFeeType(feeType)
                     .setItemTypeId(item.getItemTypeId()).setItemTypeName(item.getItemTypeName())
@@ -468,7 +474,7 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
         List<ExportFeeDetailDTO> printList = new ArrayList<>();
         Integer index = 1;
         for (TbFeeDetails feeDetails : feeDetaillist) {
-            TbFeeItem tbFeeItem=tbFeeItemService.getById(feeDetails.getFeeType());
+            TbFeeItem tbFeeItem = tbFeeItemService.getById(feeDetails.getFeeType());
             ExportFeeDetailDTO detailDTO = new ExportFeeDetailDTO();
             detailDTO.setBusinessNo(feeDetails.getBusinessNo()).setCarNo(feeDetails.getCarNo())
                     .setFeeType(tbFeeItem.getName()).setItemTypeName(feeDetails.getItemTypeName())

+ 2 - 2
sp-server/src/main/java/com/pj/project/tb_item/TbItem.java

@@ -83,6 +83,7 @@ public class TbItem extends Model<TbItem> implements Serializable {
     private String payTypeName;
     private String itemType;
     private Double taxRate;
+    private String typeName;
 
     @TableField(exist = false)
     private List<TbItemFac> facList = new ArrayList<>();
@@ -91,8 +92,7 @@ public class TbItem extends Model<TbItem> implements Serializable {
     @TableField(exist = false)
     private String remark;
 
-    @TableField(exist = false)
-    private String typeName;
+
 
     @TableField(exist = false)
     private Integer need;

+ 15 - 0
sp-server/src/main/java/com/pj/project/tb_item/TbItemService.java

@@ -25,6 +25,7 @@ import com.pj.project.tb_item_type.TbItemTypeService;
 import com.pj.utils.so.SoMap;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -229,4 +230,18 @@ public class TbItemService extends ServiceImpl<TbItemMapper, TbItem> implements
         ew.lambda().eq(TbItem::getItemCode, uniqueExpenseId);
         this.remove(ew);
     }
+
+    /**
+     * 查找停车费项
+     *
+     * @param itemTypeNameKeyword
+     * @param itemNameKeyword
+     * @return
+     */
+    public TbItem findByTypeNameAndItemName(String itemTypeNameKeyword, String itemNameKeyword) {
+        QueryWrapper<TbItem> ew = new QueryWrapper<>();
+        ew.lambda().like(TbItem::getTypeName, itemTypeNameKeyword).like(TbItem::getItemName, itemNameKeyword);
+        List<TbItem> list = list(ew);
+        return list.isEmpty() ? null : list.get(0);
+    }
 }

+ 1 - 0
sp-server/src/main/java/com/pj/project/tb_item_type/TbItemTypeService.java

@@ -28,6 +28,7 @@ import com.pj.utils.so.SoMap;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;