Переглянути джерело

Merge branch 'hpf' of http://47.101.143.145:8090/77975466/pco into hpf

# Conflicts:
#	sp-admin/sa-view/tb-deduction-record/tb-deduction-record-list.html
qzyReal 2 роки тому
батько
коміт
eb44f6e9f0

+ 6 - 5
sp-admin/sa-view/tb-charge-record/print-receipt.html

@@ -30,11 +30,12 @@
 		<div class="vue-box">
 			<div>
 				<input type="button" style="background: #2d8cf0;
-    color: white;
-    padding: 3px 20px;
-    border: none;
-    border-radius: 2px;
-    margin: 10px;" id="print_button" value="打印" />
+					color: white;
+					padding: 3px 20px;
+					border: none;
+					cursor: pointer;
+					border-radius: 2px;
+					margin: 10px;" id="print_button" value="打印" />
 			</div>
 			<fieldset align="">
 				<legend>打印区</legend>

+ 1 - 1
sp-admin/sa-view/tb-charge-record/tb-charge-record-list.html

@@ -178,7 +178,7 @@
 						sa.showIframe('新增数据', 'tb-charge-record-add.html?id=-1', '1000px', '90%');
 					},
 					print(data) {
-						sa.showIframe('打印充值单据', 'print-receipt.html?id=' + data.id, '1000px', '100%');
+						sa.showIframe('打印充值单据', 'print-receipt.html?id=' + data.id, '1000px', '70%');
 					},
 					//复审
 					toReview(data) {

+ 2 - 3
sp-admin/sa-view/tb-deduction-record/tb-deduction-record-list.html

@@ -67,13 +67,12 @@
 						</el-select>
 					</sa-item>
 					<el-button type="primary" icon="el-icon-search" @click="p.pageNo = 1; f5()">查询</el-button>
-					<br />
+						<sa-item type="fast-btn" show="reset" style="display: inline;"></sa-item>
 				</el-form>
 				<!-- ------------- 快捷按钮 ------------- -->
-				<sa-item type="fast-btn" show="reset"></sa-item>
 				<!-- ------------- 数据列表 ------------- -->
 				<el-table class="data-table" ref="data-table" :data="dataList" >
-					<sa-td type="selection"></sa-td>
+					<sa-td type="index" name="序号"></sa-td>
 					<sa-td name="客户名称" prop="customerName" ></sa-td>
 					<sa-td name="合作伙伴" prop="pickCustomerName" ></sa-td>
 					<sa-td name="业务单号" prop="businessNo" ></sa-td>

+ 4 - 0
sp-server/src/main/java/com/pj/api/h5/ApiController.java

@@ -155,6 +155,10 @@ public class ApiController {
         return AjaxJson.getSuccessData(apiService.getBusinessItem(so.getString("id")));
     }
 
+    /**
+     * 接单
+     * @return
+     */
     @PostMapping(value = "pickBusinessItem")
     public AjaxJson pickBusinessItem() {
         SoMap so = SoMap.getRequestSoMap();

+ 2 - 1
sp-server/src/main/java/com/pj/api/open/service/OpenService.java

@@ -104,7 +104,7 @@ public class OpenService {
             StaticLog.error("缓存入场图片:{}", carNo);
             IMAGE_CACHE.put(carNo, image);
         }
-        automaticPay.unbindRun(carNo);
+       automaticPay.unbindRun(carNo);
         TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(carNo);
         Date now = new Date();
         TbCar tbCar = tbCarService.findByCardNo(carNo);
@@ -114,6 +114,7 @@ public class OpenService {
         if (tbBusinessCar == null
                 || (tbBusinessCar.getRealInTime() != null && tbBusinessCar.getRealOutTime() != null)
                 || (tbBusinessCar.getRealInTime() != null && tbBusinessCar.getRealOutTime() == null)) {
+            //=======创建新的放行记录==========
             tbBusinessCar = new TbBusinessCar();
             tbBusinessCar.setCarNo(carNo).setPay(0).setCarSize(0D).setIsLock(0)
                     .setCarCompany(tbCar != null ? tbCar.getCustomerName() : "临时")

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

@@ -24,6 +24,8 @@ import com.pj.project.tb_costomer.TbCostomer;
 import com.pj.project.tb_costomer.TbCostomerService;
 import com.pj.project.tb_declare.TbDeclare;
 import com.pj.project.tb_declare.TbDeclareService;
+import com.pj.project.tb_deduction_record.TbDeductionRecord;
+import com.pj.project.tb_deduction_record.TbDeductionRecordService;
 import com.pj.project.tb_discount.TbDiscount;
 import com.pj.project.tb_discount.TbDiscountService;
 import com.pj.project.tb_disinfect.TbDisinfect;
@@ -86,6 +88,8 @@ public class ApiService {
     private WxConfig wxConfig;
     @Resource
     private MyConfig myConfig;
+    @Resource
+    private TbDeductionRecordService tbDeductionRecordService;
 
 
     public List<InOutRecordBO> getInOutRecord(SoMap so) {
@@ -231,13 +235,19 @@ public class ApiService {
         if (tbBusinessItem.getPick() == 1) {
             return AjaxJson.getError("您慢了一步,其他用户已接单");
         }
-        String adminId = spAdmin.getId()+"";
-        String adminName = StrUtil.isNotEmpty(spAdmin.getNickname()) ? spAdmin.getNickname():spAdmin.getName();
+        String adminId = spAdmin.getId() + "";
+        String adminName = StrUtil.isNotEmpty(spAdmin.getNickname()) ? spAdmin.getNickname() : spAdmin.getName();
         String customerId = spAdmin.getCustomerId();
         TbCostomer tbCostomer = tbCostomerService.getById(customerId);
         tbBusinessItem.setPick(1).setPickTime(new Date()).setPickCustomerId(tbCostomer.getId()).setPickCustomerName(tbCostomer.getName())
-            .setPickBy(adminName).setPickByAdminId(adminId);
+                .setPickBy(adminName).setPickByAdminId(adminId);
         tbBusinessItemService.updateById(tbBusinessItem);
+        //更新扣款记录里面的合作伙伴信息
+        TbDeductionRecord tbDeductionRecord = tbDeductionRecordService.findByBusinessItemId(tbBusinessItem.getId());
+        if (tbDeductionRecord != null) {
+            tbDeductionRecord.setPickCustomerName(tbCostomer.getName());
+            tbDeductionRecordService.updateById(tbDeductionRecord);
+        }
         //todo 通知录入人员 已接单
         List<SpAdmin> spAdminList = spAdminService.findByCustomerId(UserTypeEnum.PLATFORM_ADMIN.getCustomerId());
         TbBusiness tbBusiness = tbBusinessService.getById(tbBusinessItem.getBusinessId());

+ 161 - 138
sp-server/src/main/java/com/pj/project/tb_account/AutomaticPay.java

@@ -27,6 +27,7 @@ import com.pj.project.tb_item.TbItem;
 import com.pj.utils.AesUtil;
 import com.pj.utils.cache.RedisUtil;
 import com.pj.utils.sg.NbUtil;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
@@ -63,76 +64,85 @@ public class AutomaticPay {
     TbInvoiceOrderService invoiceOrderService;
     @Resource
     TbGoodsService tbGoodsService;
+    @Resource
+    @Lazy
+    private TbDeductionBindService tbDeductionBindService;
 
     private Integer feeType;
 
 
     /**
      * 异步扣费入口
+     *
      * @param businessId 业务id
-     * @param plate 车牌号
-     * @param feeType 收费类型,1-只收停车费、2-只收业务费,3-停车和业务费
+     * @param plate      车牌号
+     * @param feeType    收费类型,1-只收停车费、2-只收业务费,3-停车和业务费
      */
     //TODO 不要在此方法写逻辑
     @Async
     public void run(String businessId, String plate, Integer feeType) {
         this.feeType = feeType;
-        task(businessId,plate,feeType);
+        task(businessId, plate, feeType);
     }
 
     /**
      * 异步解绑入口
+     *
      * @param plate
      */
     @Async
-    public void unbindRun(String plate){
+    public void unbindRun(String plate) {
         if(isExistTask(null,plate)){
             return;
         }
         autoUnbindCarByPlate(plate);
         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)){
+    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){
+        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());
+            for (TbBusinessCar car : cars) {
+                this.doBusinessFee(businessId, car.getCarNo());
             }
-        }else if(feeType==3){
+        } else if (feeType == 3) {
             doOutFee(plate);
         }
-        delRedisTask(businessId,plate);
+        delRedisTask(businessId, plate);
     }
 
     /**
      * 收业务费
+     *
      * @param businessId
      */
-    private void doBusinessFee(String businessId,String plate){
-        if(!NumberUtil.isNumber(businessId) || NbUtil.isNull(plate)){
+    private void doBusinessFee(String businessId, String plate) {
+        if (!NumberUtil.isNumber(businessId) || NbUtil.isNull(plate)) {
             return;
         }
-        StaticLog.info("开始收取业务费:{}" , businessId);
+        StaticLog.info("开始收取业务费:{}", businessId);
         TbBusiness tbBusiness = tbBusinessService.getById(businessId);
-        if(TbBusiness.PayStatus.NO_PAY.getCode()!=tbBusiness.getPayStatus()){
-            StaticLog.info("已收取过业务费,退出收费程序:{}" , businessId);
+        if (TbBusiness.PayStatus.NO_PAY.getCode() != tbBusiness.getPayStatus()) {
+            StaticLog.info("已收取过业务费,退出收费程序:{}", businessId);
             return;
         }
-        if(!NumberUtil.isNumber(tbBusiness.getItemPrice().toString())){
-            StaticLog.info("未获取到收费总金额或收费总金额非法,退出收费程序:{}" , businessId);
+        if (!NumberUtil.isNumber(tbBusiness.getItemPrice().toString())) {
+            StaticLog.info("未获取到收费总金额或收费总金额非法,退出收费程序:{}", businessId);
             return;
         }
-        if(!deductionBindService.isBindCarByPlate(plate)){
-            StaticLog.info("业务车辆未绑定指定客户的预存款账户,退出收费程序:{}{}",businessId,tbBusiness.getCustomerName());
+        if (!deductionBindService.isBindCarByPlate(plate)) {
+            StaticLog.info("业务车辆未绑定指定客户的预存款账户,退出收费程序:{}{}", businessId, tbBusiness.getCustomerName());
             return;
         }
         List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(businessId);
@@ -143,75 +153,78 @@ public class AutomaticPay {
         BigDecimal parkingMoneyBig = new BigDecimal(0);
         BigDecimal totalMoneyBig = new BigDecimal(totalMoney);
         BigDecimal balance = totalMoneyBig.subtract(tbBusiness.getItemPrice());
-        boolean isOut = (TbGoods.DeductionTypeEnum.OUT_KK.getCode()==tbBusiness.getAutoDeductionType()) &&
-                        this.feeType==3;
-        if(isOut){
+        boolean isOut = (TbGoods.DeductionTypeEnum.OUT_KK.getCode() == 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())+":因支付账户余额不足,自动缴费失败。。");
+        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(
-                        TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode());
+                .setPayNo(no).setConfirmInput(1).setConfirmInputTime(now).setPayStatus(
+                TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode());
         tbBusiness.updateById();
         List<TbBusinessItem> businessItems = tbBusinessItemService.findByBusinessId(businessId);
-        for(TbBusinessItem businessItem:businessItems){
-            if(businessItem.getPayStatus()==1){
+        for (TbBusinessItem businessItem : businessItems) {
+            if (businessItem.getPayStatus() == 1) {
                 continue;
             }
             businessItem.setPayStatus(1).setPayTime(now);
         }
         tbBusinessItemService.updateBatchById(businessItems);
-        if(isOut){
+        if (isOut) {
             this.updateTbBusinessCars(cars);
         }
         //更新账户余额
-        tbAccount.setTotalMoney(AesUtil.encryptECB(balance.toString(),key));
+        tbAccount.setTotalMoney(AesUtil.encryptECB(balance.toString(), key));
         tbAccount.updateById();
-        deductionBindService.setDeductMoney(bind.getCustomerId(),plate,tbBusiness.getItemPrice());
+        deductionBindService.setDeductMoney(bind.getCustomerId(), plate, tbBusiness.getItemPrice());
         //生成收费明细
         List<TbFeeDetails> tbFeeDetailsList = tbFeeDetailsService.autoChargeBusinessFee(
-                businessItems,null,null,now);
+                businessItems, null, null, now);
         //生成扣费记录
-        createTbDeductionRecord(tbFeeDetailsList,tbAccount, totalMoneyBig,plate,bind.getCustomerName(),no);
+        createTbDeductionRecord(tbFeeDetailsList, tbAccount, totalMoneyBig, plate, bind.getCustomerName(), no);
         //生成开票信息
-        createTbInvoiceOrder(tbBusiness, cars, parkingMoneyBig, plate,bind.getCustomerId(),no,isOut);
-        if(isOut){
-            deductionBindService.setDeductMoney(bind.getCustomerId(),plate,parkingMoneyBig);
+        createTbInvoiceOrder(tbBusiness, cars, parkingMoneyBig, plate, bind.getCustomerId(), no, isOut);
+        if (isOut) {
+            deductionBindService.setDeductMoney(bind.getCustomerId(), plate, parkingMoneyBig);
             List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.autoChargeParkFee(
-                    cars,null,null,now);
-            createTbDeductionRecord(parkFeeDetailsList,tbAccount,
-                    totalMoneyBig.subtract(tbBusiness.getItemPrice()),plate,bind.getCustomerName(),no);
+                    cars, null, null, now);
+            createTbDeductionRecord(parkFeeDetailsList, tbAccount,
+                    totalMoneyBig.subtract(tbBusiness.getItemPrice()), plate, bind.getCustomerName(), no);
             deductionBindService.autoUnbindCar(cars);
         }
-        StaticLog.info("预充值自动缴费成功!,退出收费程序:{}{}" , businessId,tbAccount.getCustomerId());
+        StaticLog.info("预充值自动缴费成功!,退出收费程序:{}{}", businessId, tbAccount.getCustomerId());
     }
 
     /**
      * 出场所收费,根据车牌号
+     *
      * @param plate
      */
-    private void doOutFee(String plate){
-        if(NbUtil.isNull(plate)){
+    private void doOutFee(String plate) {
+        if (NbUtil.isNull(plate)) {
             return;
         }
         TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(plate);
-        if(tbBusinessCar==null){
+        if (tbBusinessCar == null) {
             return;
         }
         List<TbBusiness> businessList = tbBusinessService.findOtherBusinessByCarId(tbBusinessCar.getId());
-        if(businessList==null){return;}
-        for (TbBusiness business: businessList){
+        if (businessList == null) {
+            return;
+        }
+        for (TbBusiness business : businessList) {
             List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(business.getId());
-            if(cars==null)continue;
-            for (TbBusinessCar car:cars){
+            if (cars == null) continue;
+            for (TbBusinessCar car : cars) {
                 doBusinessFee(business.getId(), car.getCarNo());
             }
         }
@@ -220,83 +233,85 @@ public class AutomaticPay {
 
     /**
      * 收停车费,不判断免费车辆
+     *
      * @param plate
      * @param parkingFee
      */
-    private void doParkingFee(String plate, double parkingFee){
-        if(NbUtil.isNull(plate)){
+    private void doParkingFee(String plate, double parkingFee) {
+        if (NbUtil.isNull(plate)) {
             return;
         }
         TbBusinessCar car = tbBusinessCarService.findTheLastRecord(plate);
-        if(car==null){
+        if (car == null) {
             return;
         }
-        StaticLog.info("开始自动缴纳停车费:{}" , car.getCarNo());
+        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());
+        if (account == null) {
+            StaticLog.info("该车辆还未绑定客户预存款账户!,退出收费程序:{}", car.getCarNo());
             return;
         }
         BigDecimal parkFeeBig = null;
-        if(parkingFee>0){
+        if (parkingFee > 0) {
             parkFeeBig = new BigDecimal(String.valueOf(parkingFee));
-        }else {
+        } else {
             parkFeeBig = caulatePrice(car, new Date());
         }
-        if(parkFeeBig==null ||parkFeeBig.doubleValue()<=0){
-            StaticLog.info("该车辆无需缴纳停车费!,退出收费程序:{}" , car.getCarNo());
+        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())){
+        if (!NumberUtil.isNumber(account.getTotalMoney())) {
             key = AesUtil.reverse(account.getAccSalt());
-            totalBig = new BigDecimal(AesUtil.decryptECB(account.getTotalMoney(),key));
+            totalBig = new BigDecimal(AesUtil.decryptECB(account.getTotalMoney(), key));
         }
 
         BigDecimal balance = totalBig.subtract(parkFeeBig);
-        if(balance.doubleValue()<0){
-            StaticLog.info("支付账户余额不足!,退出收费程序:{}" , car.getCarNo());
+        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.setTotalMoney(AesUtil.encryptECB(balance.toString(), key));
         account.updateById();
-        deductionBindService.setDeductMoney(bind.getCustomerId(),plate,parkFeeBig);
+        deductionBindService.setDeductMoney(bind.getCustomerId(), plate, parkFeeBig);
         List<TbBusinessCar> cars = new ArrayList<TbBusinessCar>();
         cars.add(car);
         List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.autoChargeParkFee(
-                cars,null,null,new Date());
-        createTbDeductionRecord(parkFeeDetailsList,account, totalBig,plate,bind.getCustomerName(),no);
-        createTbInvoiceOrderPark(car,account.getCustomerId(),no);
+                cars, null, null, new Date());
+        createTbDeductionRecord(parkFeeDetailsList, account, totalBig, plate, bind.getCustomerName(), no);
+        createTbInvoiceOrderPark(car, account.getCustomerId(), no);
         deductionBindService.autoUnbindCar(cars);
-        StaticLog.info("停车费自动缴费成功!,退出收费程序:{}" , car.getCarNo());
+        StaticLog.info("停车费自动缴费成功!,退出收费程序:{}", car.getCarNo());
     }
 
     /**
      * 生成扣费记录
+     *
      * @param tbFeeDetailsList
      * @param tbAccount
      * @param totalMoneyBig
      */
-    private void createTbDeductionRecord(List<TbFeeDetails> tbFeeDetailsList,TbAccount tbAccount,
-                                         BigDecimal totalMoneyBig,String plate,String customerName,String no ){
-        if(tbFeeDetailsList==null)return;
+    private void createTbDeductionRecord(List<TbFeeDetails> tbFeeDetailsList, TbAccount tbAccount,
+                                         BigDecimal totalMoneyBig, String plate, String customerName, String no) {
+        if (tbFeeDetailsList == null) return;
         int i = 0;
         String tempMoney = null;
         String bindIdStr = deductionBindService.getBindId(plate);
-        for (TbFeeDetails feeDetails : tbFeeDetailsList){
-            TbDeductionRecord deductionRecord = BeanUtil.toBean(feeDetails,TbDeductionRecord.class);
+        for (TbFeeDetails feeDetails : tbFeeDetailsList) {
+            TbDeductionRecord deductionRecord = BeanUtil.toBean(feeDetails, TbDeductionRecord.class);
             String totalStr = null;
-            if(totalMoneyBig!=null && feeDetails.getNoTaxPrice()!=null){
-                if(i!=0){
+            if (totalMoneyBig != null && feeDetails.getNoTaxPrice() != null) {
+                if (i != 0) {
                     totalMoneyBig = new BigDecimal(tempMoney);
                 }
                 totalStr = totalMoneyBig.subtract(feeDetails.getItemPrice()).toString();
@@ -326,8 +341,8 @@ public class AutomaticPay {
     /**
      * 更新停车费状态
      */
-    private void updateTbBusinessCar(TbBusinessCar car){
-        if(car == null)return;
+    private void updateTbBusinessCar(TbBusinessCar car) {
+        if (car == null) return;
         car.setPay(1).setPayTime(new Date());
         car.updateById();
     }
@@ -335,19 +350,20 @@ public class AutomaticPay {
     /**
      * 更新停车费状态
      */
-    private void updateTbBusinessCars(List<TbBusinessCar> cars){
-        if(cars == null)return;
-        for (TbBusinessCar car:cars){
+    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,
-                                      String plate, String customerId, String no, boolean isOut){
+    private void createTbInvoiceOrder(TbBusiness tbBusiness, List<TbBusinessCar> cars, BigDecimal parkingFee,
+                                      String plate, String customerId, String no, boolean isOut) {
         TbInvoiceOrder invoiceOrder = new TbInvoiceOrder();
         List<String> businessNameList = new ArrayList<>();
         List<String> businessNoList = new ArrayList<>();
@@ -355,24 +371,24 @@ public class AutomaticPay {
         businessNoList.add(tbBusiness.getNo());
         carNos.add(plate);
         businessNameList.add(tbBusiness.getGoodsName());
-        if(cars!=null){
+        if (cars != null) {
             for (TbBusinessCar car : cars) {
-                if(isOut){
-                    if(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType().equals(car.getPayType())){
+                if (isOut) {
+                    if (TbBusinessCar.PayTypeEnum.FEE_TYPE.getType().equals(car.getPayType())) {
                         continue;
                     }
-                    if(!businessNameList.contains("停车费")){
+                    if (!businessNameList.contains("停车费")) {
                         businessNameList.add("停车费");
                     }
-                }else {
-                    if(NbUtil.isNull(car.getCarNo()) || !car.getCarNo().equals(plate)){
+                } else {
+                    if (NbUtil.isNull(car.getCarNo()) || !car.getCarNo().equals(plate)) {
                         continue;
                     }
                 }
-                if(!businessNoList.contains(car.getNo())){
+                if (!businessNoList.contains(car.getNo())) {
                     businessNoList.add(car.getNo());
                 }
-                if(!carNos.contains(car.getCarNo())){
+                if (!carNos.contains(car.getCarNo())) {
                     carNos.add(car.getCarNo());
                 }
             }
@@ -381,19 +397,19 @@ public class AutomaticPay {
         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){
+        if (parkingFee != null) {
             billMoney = parkingFee.add(billMoney);
         }
         invoiceOrder.setBusinessName(businessNameStr).setBusinessNo(businessNoStr).setCarNo(carNoStr)
-                    .setTransactionId(null).setBillMoney(billMoney).setBusinessId(tbBusiness.getId())
-                    .setStatus(0).setCreateTime(new Date()).setCustomerId(customerId).setPreOrderNum(no);
+                .setTransactionId(null).setBillMoney(billMoney).setBusinessId(tbBusiness.getId())
+                .setStatus(0).setCreateTime(new Date()).setCustomerId(customerId).setPreOrderNum(no);
         invoiceOrderService.save(invoiceOrder);
     }
 
     /**
      * 无业务车辆收停车费生成发票信息
      */
-    private void createTbInvoiceOrderPark(TbBusinessCar car, String customerId,String no){
+    private void createTbInvoiceOrderPark(TbBusinessCar car, String customerId, String no) {
         TbInvoiceOrder invoiceOrder = new TbInvoiceOrder();
 
         invoiceOrder.setBusinessName("停车费").setBusinessNo(car.getNo()).setCarNo(car.getCarNo())
@@ -404,12 +420,13 @@ public class AutomaticPay {
 
     /**
      * 生成停车费
+     *
      * @param tbBusinessCar
      * @param now
      * @return
      */
     private BigDecimal caulatePrice(TbBusinessCar tbBusinessCar, Date now) {
-        if(tbBusinessCar==null || now==null) new BigDecimal("0");
+        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();
@@ -421,15 +438,16 @@ public class AutomaticPay {
 
     /**
      * 获取所有停车费总和
+     *
      * @param cars
      * @return
      */
-    private BigDecimal getParkings(List<TbBusinessCar> cars){
-        if(cars==null) new BigDecimal("0");
+    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));
+        for (TbBusinessCar car : cars) {
+            value = value.add(this.caulatePrice(car, now));
             car.setPayType(TbBusinessCar.PayTypeEnum.HAS_PAY_TYPE.getType());
         }
         return value;
@@ -437,18 +455,19 @@ public class AutomaticPay {
 
     /**
      * 获取所有停车费总和,过滤免费车
+     *
      * @param cars
      * @return
      */
-    private BigDecimal getParkingsByBS(List<TbBusinessCar> cars,TbBusiness tbBusiness){
-        if(cars==null) new BigDecimal("0");
+    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())){
+        for (TbBusinessCar car : cars) {
+            if (isParkingFeeByBS(tbBusiness, car.getCarType())) {
                 car.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
-            }else {
-                value = value.add(this.caulatePrice(car,now));
+            } else {
+                value = value.add(this.caulatePrice(car, now));
                 car.setPayType(TbBusinessCar.PayTypeEnum.HAS_PAY_TYPE.getType());
             }
         }
@@ -457,9 +476,10 @@ public class AutomaticPay {
 
     /**
      * 判断有业务的车是否收停车费
+     *
      * @return true是免费
      */
-    private boolean isParkingFeeByBS(TbBusiness tbBusiness,String carType){
+    private boolean isParkingFeeByBS(TbBusiness tbBusiness, String carType) {
         if (TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType)) {
             TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
             return tbGoods.getChinaCarPay() == 1;
@@ -471,34 +491,35 @@ public class AutomaticPay {
 
     /**
      * 补录进场解绑逻辑
+     *
      * @return
      */
-    private void autoUnbindCarByPlate(String plate){
-        if(NbUtil.isNull(plate)) return;
+    private void autoUnbindCarByPlate(String plate) {
+        if (NbUtil.isNull(plate)) return;
         TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(plate);
         //离场逻辑
-        if (tbBusinessCar!=null){
-            if(doUnbindCarByPlate(tbBusinessCar)){
+        if (tbBusinessCar != null) {
+            if (doUnbindCarByPlate(tbBusinessCar)) {
                 return;
             }
         }
         //进场逻辑
         TbDeductionBind bind = deductionBindService.getOne(new LambdaQueryWrapper<TbDeductionBind>().eq(
-                TbDeductionBind::getBindCar,plate).isNull(TbDeductionBind::getUnbindTime));
-        if(bind != null){
+                TbDeductionBind::getBindCar, plate).isNull(TbDeductionBind::getUnbindTime));
+        if (bind != null) {
             TbDeductionRecord record = new TbDeductionRecord();
             Integer count = record.selectCount(new LambdaQueryWrapper<TbDeductionRecord>().like(
-                    TbDeductionRecord::getDeductionBindId,bind.getId()));
-            if(count>0){
+                    TbDeductionRecord::getDeductionBindId, bind.getId()));
+            if (count > 0) {
                 bind.setUpdateBy("预充值自动缴费解绑");
                 bind.setUpdateTime(new Date());
                 bind.setUnbindTime(new Date());
                 bind.updateById();
-            }else {
+            } else {
                 Integer buCount = tbBusinessService.count(new LambdaQueryWrapper<TbBusiness>().ne(
-                        TbBusiness::getPayStatus,1)
-                        .between(TbBusiness::getCreateTime,bind.getBindTime(),NbUtil.getNow()));
-                if(buCount>0){
+                        TbBusiness::getPayStatus, 1)
+                        .between(TbBusiness::getCreateTime, bind.getBindTime(), NbUtil.getNow()));
+                if (buCount > 0) {
                     bind.setUpdateBy("预充值自动缴费解绑");
                     bind.setUpdateTime(new Date());
                     bind.setUnbindTime(new Date());
@@ -510,17 +531,18 @@ public class AutomaticPay {
 
     /**
      * 补录出场解绑逻辑
+     *
      * @param tbBusinessCar
      */
-    private boolean doUnbindCarByPlate(TbBusinessCar tbBusinessCar){
-        if (tbBusinessCar==null || tbBusinessCar.getRealOutTime()==null){
+    private boolean doUnbindCarByPlate(TbBusinessCar tbBusinessCar) {
+        if (tbBusinessCar == null || tbBusinessCar.getRealOutTime() == null) {
             return false;
         }
         TbDeductionBind bind = deductionBindService.getOne(new LambdaQueryWrapper<TbDeductionBind>().eq(
-                TbDeductionBind::getBindCar,tbBusinessCar.getCarNo())
-                        .lt(TbDeductionBind::getBindTime,tbBusinessCar.getRealOutTime())
-                        .isNull(TbDeductionBind::getUnbindTime));
-        if(bind==null){
+                TbDeductionBind::getBindCar, tbBusinessCar.getCarNo())
+                .lt(TbDeductionBind::getBindTime, tbBusinessCar.getRealOutTime())
+                .isNull(TbDeductionBind::getUnbindTime));
+        if (bind == null) {
             return false;
         }
         bind.setUpdateBy("预充值自动缴费解绑");
@@ -532,32 +554,33 @@ public class AutomaticPay {
 
     /**
      * 缓存任务,如果存在任务不继续往下执行
+     *
      * @param businessId
      * @param plate
      * @return
      */
-    private boolean isExistTask(String businessId, String plate){
-        String key = getRedisKey(businessId,plate);
-        if(NbUtil.isNullStr(RedisUtil.get(key))){
-            RedisUtil.setByMINUTES(key,key,5);
+    private boolean isExistTask(String businessId, String plate) {
+        String key = getRedisKey(businessId, plate);
+        if (NbUtil.isNullStr(RedisUtil.get(key))) {
+            RedisUtil.setByMINUTES(key, key, 5);
             return false;
         }
         return true;
     }
 
-    private void delRedisTask(String businessId, String plate){
-        String key = getRedisKey(businessId,plate);
+    private void delRedisTask(String businessId, String plate) {
+        String key = getRedisKey(businessId, plate);
         RedisUtil.del(key);
     }
 
-    private String getRedisKey(String businessId, String plate){
-        if(NbUtil.isNullStr(businessId)){
+    private String getRedisKey(String businessId, String plate) {
+        if (NbUtil.isNullStr(businessId)) {
             businessId = "100";
         }
-        if(NbUtil.isNullStr(plate)){
+        if (NbUtil.isNullStr(plate)) {
             plate = "100";
         }
-        String key = "autoPay:"+businessId+plate;
+        String key = "autoPay:" + businessId + plate;
         return key;
     }
 }

+ 1 - 1
sp-server/src/main/java/com/pj/project/tb_account/TbAccountService.java

@@ -99,7 +99,7 @@ public class TbAccountService extends ServiceImpl<TbAccountMapper, TbAccount> im
      */
     public void recharge(SoMap so){
         String salt = so.getString("salt");
-        String preTopupMoney = so.getString("preTopupMoney");//总计充值金额
+        String preTopupMoney = so.getString("preTopupMoney");//充值金额
         String key = AesUtil.reverse(salt);
         String decTotalTopup = AesUtil.decryptECB(preTopupMoney,key);
         if(!NumberUtil.isNumber(decTotalTopup)){

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

@@ -18,6 +18,7 @@ import com.pj.project.tb_business.TbBusinessService;
 import com.pj.project.tb_business_car.statics.CarStatics;
 import com.pj.project.tb_car.TbCarService;
 import com.pj.project.tb_car_no_color.TbCarNoColorService;
+import com.pj.project.tb_deduction_bind.TbDeductionBindService;
 import com.pj.project.tb_fee_details.TbFeeDetails;
 import com.pj.project.tb_fee_details.TbFeeDetailsService;
 import com.pj.project.tb_item.TbItem;
@@ -67,13 +68,15 @@ public class TbBusinessCarService extends ServiceImpl<TbBusinessCarMapper, TbBus
     @Resource
     private UploadConfig uploadConfig;
 
-    @Resource
-    private TbCarNoColorService tbCarNoColorService;
+
     @Resource
     @Lazy
     private RelationBusinessCarService relationBusinessCarService;
     @Resource
     AutomaticPay automaticPay;
+    @Resource
+    @Lazy
+    private TbDeductionBindService tbDeductionBindService;
 
 
     /**
@@ -187,11 +190,16 @@ public class TbBusinessCarService extends ServiceImpl<TbBusinessCarMapper, TbBus
         t.setCarNo(carNo).setPay(0).setIsLock(0).setBasePartMoney(new BigDecimal("0")).setTimeUpdate(new Date())
                 .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
         this.save(t);
-        automaticPay.unbindRun(carNo);
+       // automaticPay.unbindRun(carNo);
     }
 
     public void updateCarRecord(TbBusinessCar t) throws Exception {
         TbBusinessCar db = this.getById(t.getId());
+        if (db.getRealOutTime() == null && t.getRealOutTime() != null) {
+            //补录放行记录,解绑扣费绑定
+            tbDeductionBindService.unbindByBusinessCarId(t.getId());
+            automaticPay.unbindRun(db.getCarNo());
+        }
         String oldCarNo = db.getCarNo();
         String newCarNo = t.getCarNo();
         Date now = new Date();
@@ -201,13 +209,13 @@ public class TbBusinessCarService extends ServiceImpl<TbBusinessCarMapper, TbBus
                 .setCarSize(t.getCarSize())
                 .setDriverName(t.getDriverName())
                 .setDriverPhone(t.getDriverPhone()).setTimeUpdate(now);
-        if(t.getRealOutTime() != null && db.getPay() == 0){
+        if (t.getRealOutTime() != null && db.getPay() == 0) {
             db.setPay(1).setPayType("已支付");
         }
         //车牌没改
         if (StrUtil.equals(oldCarNo, newCarNo)) {
             this.updateById(db);
-            automaticPay.unbindRun(db.getCarNo());
+
             return;
         }
         //改了车牌,看下新车牌是否被占用
@@ -247,7 +255,6 @@ public class TbBusinessCarService extends ServiceImpl<TbBusinessCarMapper, TbBus
             }
 
         }
-        automaticPay.unbindRun(db.getCarNo());
     }
 
     public List<TbBusinessCar> findTheNoBusinessCar(String carNo) {
@@ -396,5 +403,5 @@ public class TbBusinessCarService extends ServiceImpl<TbBusinessCarMapper, TbBus
         ew.eq("date_format(pay_time,'%Y-%m-%d')", day);
         return list(ew);
     }
-    
+
 }

+ 4 - 0
sp-server/src/main/java/com/pj/project/tb_deduction_bind/TbDeductionBind.java

@@ -99,4 +99,8 @@ public class TbDeductionBind extends Model<TbDeductionBind> implements Serializa
      */
     public String feeFailRecord;
 
+    /**
+     * 放行记录ID
+     */
+    private String businessCarId=null;
 }

+ 6 - 7
sp-server/src/main/java/com/pj/project/tb_deduction_bind/TbDeductionBindController.java

@@ -37,21 +37,20 @@ public class TbDeductionBindController {
     @SaCheckPermission(TbDeductionBind.PERMISSION_LIST_BIND)
     @Transactional(rollbackFor = Exception.class)
     public AjaxJson bindCar(TbDeductionBind t) {
-
-        return AjaxJson.getByBoolean(tbDeductionBindService.bindCar(t));
+        t.setCustomerId(StpUserUtil.getCustomerId());
+        tbDeductionBindService.bindCar(t);
+        return AjaxJson.getSuccess();
     }
 
     /**
      * 解绑
-     * @param t
      * @return
      */
     @RequestMapping("unbindCar")
     @SaCheckPermission(TbDeductionBind.PERMISSION_LIST_UNBIND)
-    @Transactional(rollbackFor = Exception.class)
-    public AjaxJson unbindCar(TbDeductionBind t) {
-
-        return AjaxJson.getByBoolean(tbDeductionBindService.unbindCar(t));
+    public AjaxJson unbindCar(Long id) {
+        tbDeductionBindService.unbindCar(id);
+        return AjaxJson.getSuccess();
     }
 
     /**

+ 142 - 81
sp-server/src/main/java/com/pj/project/tb_deduction_bind/TbDeductionBindService.java

@@ -1,5 +1,6 @@
 package com.pj.project.tb_deduction_bind;
 
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.json.JSONArray;
@@ -12,6 +13,7 @@ import com.pj.constants.UserTypeEnum;
 import com.pj.current.satoken.StpUserUtil;
 import com.pj.project.tb_account.AutomaticPay;
 import com.pj.project.tb_business_car.TbBusinessCar;
+import com.pj.project.tb_business_car.TbBusinessCarService;
 import com.pj.project.tb_costomer.TbCostomer;
 import com.pj.project.tb_costomer.TbCostomerService;
 import com.pj.project.tb_deduction_record.TbDeductionRecord;
@@ -22,6 +24,7 @@ import com.pj.utils.sg.AjaxJson;
 import com.pj.utils.sg.NbUtil;
 import com.pj.utils.so.SoMap;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -38,6 +41,7 @@ import java.util.Map;
  * @created: 2022/8/31 20:41
  */
 @Service
+@Transactional(rollbackFor = Exception.class)
 public class TbDeductionBindService extends ServiceImpl<TbDeductionBindMapper, TbDeductionBind> implements IService<TbDeductionBind> {
 
     /**
@@ -47,23 +51,26 @@ public class TbDeductionBindService extends ServiceImpl<TbDeductionBindMapper, T
     TbDeductionBindMapper tbDeductionBindMapper;
     @Resource
     TbCostomerService tbCostomerService;
+    @Resource
+    @Lazy
+    private TbBusinessCarService tbBusinessCarService;
 
     /**
      * 查集合 - 根据条件(参数为空时代表忽略指定条件)
      */
     public List<TbDeductionBind> getList(SoMap so) {
         String customerId = StpUserUtil.getCustomerId();
-        if(!UserTypeEnum.PLATFORM_ADMIN.getCustomerId().equals(customerId)){
-            so.put("customerId",customerId);
+        if (!UserTypeEnum.PLATFORM_ADMIN.getCustomerId().equals(customerId)) {
+            so.put("customerId", customerId);
         }
-        if(ObjectUtil.isNotEmpty(so.get("bindTime[]"))){
+        if (ObjectUtil.isNotEmpty(so.get("bindTime[]"))) {
             JSONArray jsonArray = JSONUtil.parseArray(so.getString("bindTime[]"));
-            if(jsonArray.size()==2){
-                so.put("startTime",jsonArray.get(0));
-                so.put("endTime",jsonArray.get(1));
+            if (jsonArray.size() == 2) {
+                so.put("startTime", jsonArray.get(0));
+                so.put("endTime", jsonArray.get(1));
             }
         }
-      //  return tbDeductionBindMapper.getTbDeductionBindList(so);
+        //  return tbDeductionBindMapper.getTbDeductionBindList(so);
         return tbDeductionBindMapper.getList(so);
     }
 
@@ -73,188 +80,228 @@ public class TbDeductionBindService extends ServiceImpl<TbDeductionBindMapper, T
 
     /**
      * 绑定车辆
+     *
      * @param bind
      * @return
      */
-    public boolean bindCar(TbDeductionBind bind){
-        if(bind==null) return false;
-        if(isBindCarByPlate(bind.getBindCar())){
-            throw new AjaxError(bind.getBindCar()+" 车辆已绑定!");
+    public void bindCar(TbDeductionBind bind) {
+        String carNo = bind.getBindCar().toUpperCase().trim();
+        TbDeductionBind db = findTheLastUnBindCar(carNo);
+        if (db != null) {
+            throw new AjaxError("存在未解绑车辆");
         }
-        if(bind.getBindTime()==null){
+        if (bind.getBindTime() == null) {
             throw new AjaxError("绑定时间不能为空!");
         }
-        if(NbUtil.isNullStr(bind.getBindCar())){
+        if (NbUtil.isNullStr(bind.getBindCar())) {
             throw new AjaxError("车牌号不能为空!");
         }
-        if(NbUtil.isNullStr(bind.getCustomerId())){
-            throw new AjaxError("登陆用户信息已经失效,请重新登陆!");
+        TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(carNo);
+        if (tbBusinessCar != null&&tbBusinessCar.getRealOutTime()==null) {//先录入业务未离场记录,但是没有绑定
+            TbDeductionBind bindRecord = this.findByBusinessCarId(tbBusinessCar.getId());
+            if (bindRecord == null) {
+                //绑定放行记录
+                bind.setBusinessCarId(tbBusinessCar.getId());
+            }
         }
-        bind.setBindCar(bind.getBindCar().trim().toUpperCase());
-        bind.setId(null);
+        String customerId = bind.getCustomerId();
+        TbCostomer tbCostomer = tbCostomerService.getById(customerId);
+        bind.setCustomerName(tbCostomer.getName());
+        bind.setBindCar(carNo);
         bind.setCreateBy(StpUserUtil.getLoginName());
         bind.setCreateTime(new Date());
+        save(bind);
+    }
 
-        return tbDeductionBindMapper.insert(bind)>0;
+    /**
+     * 根据放行记录ID查找
+     *
+     * @param businessCarId
+     * @return
+     */
+    private TbDeductionBind findByBusinessCarId(String businessCarId) {
+        QueryWrapper<TbDeductionBind> ew = new QueryWrapper<>();
+        ew.lambda().eq(TbDeductionBind::getBusinessCarId, businessCarId)
+                .isNull(TbDeductionBind::getUnbindTime)
+                .orderByDesc(TbDeductionBind::getId);
+        List<TbDeductionBind> list = list(ew);
+        return list.isEmpty() ? null : list.get(0);
+    }
+
+    /**
+     * 查找最后一条未解绑绑定记录
+     *
+     * @param carNo
+     * @return
+     */
+    public TbDeductionBind findTheLastUnBindCar(String carNo) {
+        QueryWrapper<TbDeductionBind> ew = new QueryWrapper<>();
+        ew.lambda().eq(TbDeductionBind::getBindCar, carNo)
+                .isNull(TbDeductionBind::getUnbindTime)
+                .orderByDesc(TbDeductionBind::getId);
+        List<TbDeductionBind> list = list(ew);
+        return list.isEmpty() ? null : list.get(0);
     }
 
     /**
      * 解绑
-     * @param unbind
+     *
+     * @param id
      * @return
      */
-    public boolean unbindCar(TbDeductionBind unbind){
-        if(unbind==null) return false;
-        if(isUnbindCarById(unbind.getId())){
-            throw new AjaxError(unbind.getBindCar()+" 车辆已解绑!");
-        }
-        if(unbind.getUnbindTime()==null){
-            throw new AjaxError("解绑时间不能为空!");
-        }
-        if(NbUtil.isNullStr(unbind.getBindCar())){
-            throw new AjaxError("车牌号不能为空!");
-        }
-        if(!checkBind(unbind.getCustomerId(),unbind.getBindCar())){
-            throw new AjaxError(unbind.getBindCar()+" 不是"+unbind.getCustomerName()+" 绑定的车辆,不能解绑!");
+    public void unbindCar(Long id) {
+        TbDeductionBind bind=this.getById(id);
+        if (bind==null){
+            throw new AjaxError("记录不存在!");
         }
-        unbind.setUpdateBy(StpUserUtil.getLoginName());
-        unbind.setUpdateTime(new Date());
-        return tbDeductionBindMapper.updateById(unbind)>0;
+        bind.setUnbindTime(new Date()).setUpdateBy(StpUserUtil.getLoginName()).setUpdateTime(new Date());
+        this.updateById(bind);
     }
 
     /**
      * 根据条件解绑
+     *
      * @param plate
      * @return
      */
-    public boolean autoUnbindCar(String plate){
-        if(NbUtil.isNull(plate)) return false;
+    public boolean autoUnbindCar(String plate) {
+        if (NbUtil.isNull(plate)) return false;
 
         TbDeductionBind bind = tbDeductionBindMapper.selectOne(new LambdaQueryWrapper<TbDeductionBind>().eq(
-                        true,TbDeductionBind::getBindCar,plate).isNull(TbDeductionBind::getUnbindTime));
-        if(bind==null)return false;
+                true, TbDeductionBind::getBindCar, plate).isNull(TbDeductionBind::getUnbindTime));
+        if (bind == null) return false;
         bind.setUpdateBy("预充值自动缴费解绑");
         bind.setUpdateTime(new Date());
         bind.setUnbindTime(new Date());
-        return tbDeductionBindMapper.updateById(bind)>0;
+        return tbDeductionBindMapper.updateById(bind) > 0;
     }
 
     /**
      * 根据条件解绑
+     *
      * @return
      */
-    public void autoUnbindCar(List<TbBusinessCar> cars){
-        if(cars==null) return;
-        for (TbBusinessCar car:cars){
+    public void autoUnbindCar(List<TbBusinessCar> cars) {
+        if (cars == null) return;
+        for (TbBusinessCar car : cars) {
             this.autoUnbindCar(car.getCarNo());
         }
     }
+
     /**
      * 设置失败原因
+     *
      * @param customerId
      * @param plate
      * @param msg
      */
-    public boolean setFeeFailRecord(String customerId, String plate, String msg){
-        if(NbUtil.isNull(customerId) || NbUtil.isNull(plate)) return false;
+    public boolean setFeeFailRecord(String customerId, String plate, String msg) {
+        if (NbUtil.isNull(customerId) || NbUtil.isNull(plate)) return false;
 
         TbDeductionBind bind = tbDeductionBindMapper.selectOne(new LambdaQueryWrapper<TbDeductionBind>().eq(
-                TbDeductionBind::getCustomerId,customerId).eq(TbDeductionBind::getBindCar,plate)
+                TbDeductionBind::getCustomerId, customerId).eq(TbDeductionBind::getBindCar, plate)
                 .isNull(TbDeductionBind::getUnbindTime));
-        if(bind==null)return false;
-        bind.setFeeFailRecord(bind.getFeeFailRecord()+msg);
-       return bind.updateById();
+        if (bind == null) return false;
+        bind.setFeeFailRecord(bind.getFeeFailRecord() + msg);
+        return bind.updateById();
     }
 
     /**
      * 更新扣除金额
+     *
      * @param customerId
      * @param plate
      * @param money
      */
-    public boolean setDeductMoney(String customerId, String plate, BigDecimal money){
-        if(NbUtil.isNull(customerId) || NbUtil.isNull(plate)) return false;
+    public boolean setDeductMoney(String customerId, String plate, BigDecimal money) {
+        if (NbUtil.isNull(customerId) || NbUtil.isNull(plate)) return false;
         TbDeductionBind bind = tbDeductionBindMapper.selectOne(new LambdaQueryWrapper<TbDeductionBind>().eq(
-                TbDeductionBind::getCustomerId,customerId).eq(
-                TbDeductionBind::getBindCar,plate).isNull(TbDeductionBind::getUnbindTime));
-        if(bind==null)return false;
-        if(NumberUtil.isNumber(AesUtil.toStr(bind.getDeductMoney()))){
+                TbDeductionBind::getCustomerId, customerId).eq(
+                TbDeductionBind::getBindCar, plate).isNull(TbDeductionBind::getUnbindTime));
+        if (bind == null) return false;
+        if (NumberUtil.isNumber(AesUtil.toStr(bind.getDeductMoney()))) {
             bind.setDeductMoney(bind.getDeductMoney().add(money));
-        }else {
+        } else {
             bind.setDeductMoney(money);
         }
-       return bind.updateById();
+        return bind.updateById();
     }
 
     /**
      * 检查车辆是否已绑定预存款账户
+     *
      * @return
      */
-    public boolean checkBind(String customerId,String plate){
-        if(NbUtil.isNull(customerId) || NbUtil.isNull(plate)) return false;
-        return  tbDeductionBindMapper.selectCount(new LambdaQueryWrapper<TbDeductionBind>().eq(
-                TbDeductionBind::getCustomerId,customerId).eq(
-                TbDeductionBind::getBindCar,plate).isNull(TbDeductionBind::getUnbindTime))>0;
+    public boolean checkBind(String customerId, String plate) {
+        if (NbUtil.isNull(customerId) || NbUtil.isNull(plate)) return false;
+        return tbDeductionBindMapper.selectCount(new LambdaQueryWrapper<TbDeductionBind>().eq(
+                TbDeductionBind::getCustomerId, customerId).eq(
+                TbDeductionBind::getBindCar, plate).isNull(TbDeductionBind::getUnbindTime)) > 0;
     }
 
     /**
-     *  根据车牌号检查车辆是否已绑定
+     * 根据车牌号检查车辆是否已绑定
+     *
      * @param plate
      * @return
      */
-    public boolean isBindCarByPlate(String plate){
-        if(NbUtil.isNull(plate)) return false;
+    public boolean isBindCarByPlate(String plate) {
+        if (NbUtil.isNull(plate)) return false;
         return tbDeductionBindMapper.selectCount(new LambdaQueryWrapper<TbDeductionBind>().eq(
-                TbDeductionBind::getBindCar,plate).isNull(TbDeductionBind::getUnbindTime))>0;
+                TbDeductionBind::getBindCar, plate).isNull(TbDeductionBind::getUnbindTime)) > 0;
     }
 
     /**
-     *  根据车牌号获取车辆绑定对象
+     * 根据车牌号获取车辆绑定对象
+     *
      * @param plate
      * @return
      */
-    public TbDeductionBind getBindCarByPlate(String plate){
-        if(NbUtil.isNull(plate)) return null;
+    public TbDeductionBind getBindCarByPlate(String plate) {
+        if (NbUtil.isNull(plate)) return null;
         return tbDeductionBindMapper.selectOne(new LambdaQueryWrapper<TbDeductionBind>().eq(
-                TbDeductionBind::getBindCar,plate).isNull(TbDeductionBind::getUnbindTime));
+                TbDeductionBind::getBindCar, plate).isNull(TbDeductionBind::getUnbindTime));
     }
 
     /**
      * 判断是否已解绑
+     *
      * @param id
      * @return
      */
-    public boolean isUnbindCarById(String id){
-        if(NbUtil.isNull(id)) return false;
+    public boolean isUnbindCarById(String id) {
+        if (NbUtil.isNull(id)) return false;
         return tbDeductionBindMapper.selectCount(new LambdaQueryWrapper<TbDeductionBind>().eq(
-                TbDeductionBind::getId,id).isNotNull(TbDeductionBind::getUnbindTime))>0;
+                TbDeductionBind::getId, id).isNotNull(TbDeductionBind::getUnbindTime)) > 0;
     }
 
     /**
      * 根据车牌,获取已绑定成功的主键Id
+     *
      * @param plate
      * @return
      */
-    public String getBindId(String plate){
-        if(NbUtil.isNull(plate)) return null;
-        Map idMap =  this.getMap(new LambdaQueryWrapper<TbDeductionBind>().select(
+    public String getBindId(String plate) {
+        if (NbUtil.isNull(plate)) return null;
+        Map idMap = this.getMap(new LambdaQueryWrapper<TbDeductionBind>().select(
                 TbDeductionBind::getId).eq(
-                TbDeductionBind::getBindCar,plate).isNull(TbDeductionBind::getUnbindTime));
-        return ObjectUtil.isNotEmpty(idMap)? AesUtil.toStr(idMap.get("id")):null;
+                TbDeductionBind::getBindCar, plate).isNull(TbDeductionBind::getUnbindTime));
+        return ObjectUtil.isNotEmpty(idMap) ? AesUtil.toStr(idMap.get("id")) : null;
     }
 
     /**
      * 根据当前登陆用户封装一个绑定对象
+     *
      * @return
      */
-    public TbDeductionBind getTbDeductionBindByLogin(){
+    public TbDeductionBind getTbDeductionBindByLogin() {
         TbDeductionBind bind = new TbDeductionBind();
         String customerId = StpUserUtil.getCustomerId();
-        if(NbUtil.isNull(customerId)){
+        if (NbUtil.isNull(customerId)) {
             throw new AjaxError("登陆用户信息已经失效,请重新登陆!");
         }
         TbCostomer tbCostomer = tbCostomerService.getById(customerId);
-        if(tbCostomer==null){
+        if (tbCostomer == null) {
             throw new AjaxError("登陆用户还没绑定客户信息,不能绑定车辆!");
         }
         bind.setBindTime(new Date());
@@ -264,4 +311,18 @@ public class TbDeductionBindService extends ServiceImpl<TbDeductionBindMapper, T
         bind.setCustomerName(tbCostomer.getName());
         return bind;
     }
+
+    /**
+     * 根据放行记录ID解绑
+     * @param businessCarId
+     */
+    public void unbindByBusinessCarId(String businessCarId){
+        QueryWrapper<TbDeductionBind> ew = new QueryWrapper<>();
+        ew.lambda().eq(TbDeductionBind::getBusinessCarId, businessCarId)
+                .isNull(TbDeductionBind::getUnbindTime)
+                .orderByDesc(TbDeductionBind::getId);
+        List<TbDeductionBind> list = list(ew);
+        list.forEach(tbDeductionBind -> tbDeductionBind.setUnbindTime(new Date()));
+        this.updateBatchById(list);
+    }
 }

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

@@ -253,4 +253,5 @@ public class TbDeductionRecord extends Model<TbDeductionRecord> implements Seria
      * 预存款自动收费订单号
      */
     private String preOrderNum;
+
 }

+ 12 - 1
sp-server/src/main/java/com/pj/project/tb_deduction_record/TbDeductionRecordService.java

@@ -3,6 +3,7 @@ package com.pj.project.tb_deduction_record;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.pj.constants.UserTypeEnum;
@@ -82,5 +83,15 @@ public class TbDeductionRecordService extends ServiceImpl<TbDeductionRecordMappe
         return TbDeductionRecordMapper.getList(so);
     }
 
-
+    /**
+     * 根据业务项id查找扣费明细
+     * @param businessItemId
+     * @return
+     */
+    public TbDeductionRecord findByBusinessItemId(Long businessItemId) {
+        QueryWrapper<TbDeductionRecord>ew=new QueryWrapper<>();
+        ew.lambda().eq(TbDeductionRecord::getBusinessItemId,businessItemId);
+        List<TbDeductionRecord>list=list(ew);
+        return list.isEmpty()?null:list.get(0);
+    }
 }