qzyReal 3 dní pred
rodič
commit
7313da22b2

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

@@ -129,20 +129,20 @@ public class OpenService {
         if (inOrOut == 1) {
             return handlerIn(carNo, channelName, image);
         }
-        ResultJson re=RESULT_JSONS.get(carNo,false);
-        if ( re!= null) {
+        ResultJson re = RESULT_JSONS.get(carNo, false);
+        if (re != null) {
             return re;
         }
         String key = "lock_out_channel";
         try {
-            boolean result=RedisUtil.tryLock(key, "1", 3, TimeUnit.SECONDS);
-            log.info("result:{},{}",carNo,result);
+            boolean result = RedisUtil.tryLock(key, "1", 3, TimeUnit.SECONDS);
+            log.info("result:{},{}", carNo, result);
             if (result) {
                 ResultJson resultJson = handlerOut(carNo, channelName, image, null);
                 RedisUtil.releaseLock(key, "1");
-                RESULT_JSONS.put(carNo,resultJson);
+                RESULT_JSONS.put(carNo, resultJson);
                 return resultJson;
-            }else {
+            } else {
                 return ResultJson.error("正在计算费用,请等待");
             }
         } finally {
@@ -339,6 +339,9 @@ public class OpenService {
         //============业务费计算是否交完
         for (TbBusiness tbBusiness : businessList) {
             List<TbBusinessItem> businessItems = tbBusinessItemService.findByBusinessId(tbBusiness.getId());
+            businessItems = businessItems.stream()
+                    .filter(tbBusinessItem -> !SystemObject.config.getEveryCarPay().contains(tbBusinessItem.getItemName()))
+                    .collect(Collectors.toList());
             if (businessItems.isEmpty()) {
                 continue;
             }
@@ -388,11 +391,13 @@ public class OpenService {
             String desc = "请缴" + total + "费用";
             TbAccount tbAccount = tbAccountService.getAccountByCustomerId(tbBusinessCar.getCustomerId());
             if (tbAccount != null) {
-                if (tbAccount.getTotalMoney().compareTo(total) > 0) {
+                BigDecimal balance = tbAccount.getTotalMoney();
+                if (balance.compareTo(total) > 0) {
                     List<TbCarWeight> finalCarWeights = carWeights;
-                    BigDecimal finalTotal = total;
+                    tbAccount.setTotalMoney(balance.subtract(total));
+                    tbAccountService.updateById(tbAccount);
                     new Thread(() -> {
-                        automaticPay.payBusinessAndPartMoney(businessList, tbBusinessCar, partMoneyRes, finalTotal, finalCarWeights, tbAccount);
+                        automaticPay.payBusinessAndPartMoney(businessList, tbBusinessCar, partMoneyRes, finalCarWeights, balance);
                     }).start();
                     log.info("预存款扣款成功,返回:{},放行", carNo);
                     freeOut(tbBusinessCar, now, channel, image);

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

@@ -133,12 +133,10 @@ public class AutomaticPay {
      */
     public boolean payBusinessAndPartMoney(List<TbBusiness> businessList,
                                            TbBusinessCar tbBusinessCar,
-                                           IOrderPriceRes partMoneyRes, BigDecimal totalMoney, List<TbCarWeight> carWeights, TbAccount tbAccount) {
+                                           IOrderPriceRes partMoneyRes, List<TbCarWeight> carWeights, BigDecimal originalMoney) {
 
         Date now = new Date();
         String customerId = tbBusinessCar.getCustomerId();
-        //原金额
-        BigDecimal originalMoney = tbAccount.getTotalMoney();
         //停车费扣除
         BigDecimal partMoney = partMoneyRes.getTotalOrderPrice();
         //过磅费
@@ -146,19 +144,6 @@ public class AutomaticPay {
         for (TbCarWeight carWeight : carWeights) {
             weightMoney = weightMoney.add(carWeight.getWeightPrice());
         }
-        if (totalMoney.compareTo(originalMoney) > 0) {
-            return false;//不够交
-        }
-        BigDecimal finalOriginalMoney2 = originalMoney;
-        new Thread(() -> {
-            //余额
-            BigDecimal balance = finalOriginalMoney2.subtract(totalMoney);
-            log.info("Balance: " + balance);
-            tbAccount.setTotalMoney(balance);
-            //更新账户余额
-            boolean flag = tbAccountService.updateById(tbAccount);
-            log.info("update result:{},{},{},{}",finalOriginalMoney2,flag,totalMoney,balance);
-        }).start();
         TbCostomer tbCostomer = tbCostomerService.getById(customerId);
         String customerName = tbCostomer.getName();
         //地磅费统计
@@ -167,14 +152,12 @@ public class AutomaticPay {
             TbItem tbItem = tbItemService.findByAliasName(SystemObject.config.getWeighbridge());
             for (TbCarWeight carWeight : carWeights) {
                 BigDecimal finalOriginalMoney = originalMoney;
-                new Thread(() -> {
-                    TbFeeDetails details = tbFeeDetailsService.saveCarWeightDetails("", carWeight.getWeightPrice(), carWeight.getCalculateId(), carWeight.getNo(), tbBusinessCar, customerName, customerName, tbItem, PayEnum.PayType.PER_PAY);
-                    createTbDeductionRecord(details, finalOriginalMoney, BigDecimal.ZERO, customerId, customerName,
-                            tbBusinessCar.getCarNo(), tbBusinessCar.getId(), FeeTypeEnum.WEIGHT_FEE);
-                    carWeight.setPayStatus(1).setPayTime(now).setPayType(PayEnum.PayType.PER_PAY.getCode());
-                    tbCarWeightService.updateById(carWeight);
-                    tbFeeDetailsService.saveInvoiceOrder(details);
-                }).start();
+                TbFeeDetails details = tbFeeDetailsService.saveCarWeightDetails("", carWeight.getWeightPrice(), carWeight.getCalculateId(), carWeight.getNo(), tbBusinessCar, customerName, customerName, tbItem, PayEnum.PayType.PER_PAY);
+                createTbDeductionRecord(details, finalOriginalMoney, BigDecimal.ZERO, customerId, customerName,
+                        tbBusinessCar.getCarNo(), tbBusinessCar.getId(), FeeTypeEnum.WEIGHT_FEE);
+                carWeight.setPayStatus(1).setPayTime(now).setPayType(PayEnum.PayType.PER_PAY.getCode());
+                tbCarWeightService.updateById(carWeight);
+                tbFeeDetailsService.saveInvoiceOrder(details);
                 originalMoney = originalMoney.subtract(carWeight.getWeightPrice());
             }
         }
@@ -212,21 +195,19 @@ public class AutomaticPay {
             List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.chargeParkFee(priceBOList, null, null, now, PayEnum.PayType.PER_PAY);
             //停车费明细
             for (TbFeeDetails tbFeeDetails : parkFeeDetailsList) {
-                BigDecimal finalOriginalMoney1 = originalMoney;
-                new Thread(() -> {
-                    tbFeeDetails.setBusinessNo(businessNo);
-                    TbDeductionRecord record = this.createTbDeductionRecord(tbFeeDetails, finalOriginalMoney1, BigDecimal.ZERO,
-                            customerId, customerName, plate, tbBusinessCar.getId(), FeeTypeEnum.PARK_FEE);
-                    invoiceOrderService.addInvoiceOrder("停车业务", businessNo, tbBusinessCar.getCarNo(), tbBusiness.getId(), tbBusinessCar.getCustomerId(), tbBusiness.getCustomerName(), tbBusiness.getCustomerName(), tbFeeDetails.getItemPrice(), tbFeeDetails, record);
-
-                }).start();
+                tbFeeDetails.setBusinessNo(businessNo);
+                TbDeductionRecord record = this.createTbDeductionRecord(tbFeeDetails, originalMoney, BigDecimal.ZERO,
+                        customerId, customerName, plate, tbBusinessCar.getId(), FeeTypeEnum.PARK_FEE);
+                invoiceOrderService.addInvoiceOrder("停车业务", businessNo, tbBusinessCar.getCarNo(), tbBusiness.getId(), tbBusinessCar.getCustomerId(), tbBusiness.getCustomerName(), tbBusiness.getCustomerName(), tbFeeDetails.getItemPrice(), tbFeeDetails, record);
                 originalMoney = originalMoney.subtract(tbFeeDetails.getItemPrice());
             }
         }
         //业务费用
         for (TbBusiness tbBusiness : businessList) {
             List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(tbBusiness.getId());
-            items = items.stream().filter(item -> item.getPayStatus() == 0).collect(Collectors.toList());
+            items = items.stream()
+                    .filter(item -> item.getPayStatus() == 0&&!SystemObject.config.getEveryCarPay().contains(item.getItemName()))
+                    .collect(Collectors.toList());
             for (TbBusinessItem item : items) {
                 if (item.getPayStatus() == 1) {//已支付的
                     continue;
@@ -248,8 +229,10 @@ public class AutomaticPay {
                     log.info("originalMoney:{}", originalMoney);
                     TbDeductionRecord record = createTbDeductionRecord(details, originalMoney, BigDecimal.ZERO, customerId, tbBusiness.getCustomerName(),
                             tbBusinessCar.getCarNo(), tbBusinessCar.getId(), feeTypeEnum);
-                    invoiceOrderService.addInvoiceOrder(tbBusiness.getGoodsName(), tbBusiness.getNo(), tbBusiness.getCarNoStr(), tbBusiness.getId(),
-                            tbBusiness.getCustomerId(), tbBusiness.getCustomerName(), tbBusiness.getCustomerName(), res.getTotalOrderPrice(), details, record);
+                    new Thread(()->{
+                        invoiceOrderService.addInvoiceOrder(tbBusiness.getGoodsName(), tbBusiness.getNo(), tbBusiness.getCarNoStr(), tbBusiness.getId(),
+                                tbBusiness.getCustomerId(), tbBusiness.getCustomerName(), tbBusiness.getCustomerName(), res.getTotalOrderPrice(), details, record);
+                    }).start();
                     originalMoney = originalMoney.subtract(details.getItemPrice());
                     log.info("after originalMoney:{}", originalMoney);
                 } else {

+ 19 - 8
sp-server/src/main/java/com/pj/project/tb_business/TbBusinessService.java

@@ -490,7 +490,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
                 String itemCode = businessItem.getItemCode();
                 IOrderItem iOrderItem = new IOrderItem();
                 String itemAlias = businessItem.getItemAlias();
-                if (StrUtil.equalsIgnoreCase(itemAlias,SystemObject.config.getPartItemAlias())){
+                if (StrUtil.equalsIgnoreCase(itemAlias, SystemObject.config.getPartItemAlias())) {
                     continue;
                 }
                 Date startTime = businessItem.getColdStartTime();
@@ -682,6 +682,10 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
             if (StrUtil.equals(SystemObject.config.getColdItemAlias(), alaisName) && StrUtil.isEmpty(startImage)) {
                 throw new AjaxError("请上传开始时间图片");
             }
+            //限制只能录入一次
+            if (SystemObject.config.getEveryCarPay().contains(itemName)) {
+                checkLimit(itemName, cars);
+            }
             TbBusinessItem item = new TbBusinessItem();
             int cabinetType = tbItem.getCabinetType();
             if (!SystemObject.config.getEmptyStoreItemAlias().equals(alaisName)
@@ -816,7 +820,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
             if (db != null && db.getRealOutTime() == null) {
                 //未离场====>检查是否录入了其他业务,需要校验其绑定的客户是否一致
                 List<TbBusiness> exitBusinessList = this.findOtherBusinessByCarId(db.getId());
-                exitBusinessList=exitBusinessList.stream().filter(exit-> !Objects.equals(exit.getId(), tbBusiness.getId())).collect(Collectors.toList());
+                exitBusinessList = exitBusinessList.stream().filter(exit -> !Objects.equals(exit.getId(), tbBusiness.getId())).collect(Collectors.toList());
                 if (!exitBusinessList.isEmpty()) {
                     TbBusiness exitBusiness = exitBusinessList.get(0);
                     String bindCustomerId = exitBusiness.getCustomerId();
@@ -836,13 +840,13 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
                 }
                 long partBusinessCount = exitBusinessList.stream().filter(busienss -> StrUtil.equals("A10006", busienss.getGoodsCode()))
                         .count();
-                String goodsNamesList=exitBusinessList.stream()
+                String goodsNamesList = exitBusinessList.stream()
                         .map(TbBusiness::getGoodsName).collect(Collectors.joining(","));
 
-                if (exitBusinessList.size() > 1 && partBusinessCount > 0&&!goodsNamesList.contains("越南车")) {
+                if (exitBusinessList.size() > 1 && partBusinessCount > 0 && !goodsNamesList.contains("越南车")) {
                     throw new AjaxError("车辆【" + carNo + "】录入停车业务的同时存在其他业务");
                 }
-                if ("A10002".equals(tbGoods.getCode())&&goodsNamesList.contains("越南车")){
+                if ("A10002".equals(tbGoods.getCode()) && goodsNamesList.contains("越南车")) {
                     throw new AjaxError("已经存在越南服务费,请勿重复录入");
                 }
             }
@@ -890,6 +894,15 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
         return tbBusiness;
     }
 
+    private void checkLimit(String itemName, List<TbBusinessCar> cars) {
+        for (TbBusinessCar car : cars) {
+            int count = tbBusinessItemService.findNotOutBusinessItem(car.getCarNo(), itemName);
+            if (count > 0) {
+                throw new AjaxError("车辆:【" + car.getCarNo() + "】," + itemName + "重复录入");
+            }
+        }
+    }
+
 
     public List<TbBusiness> getOtherBusiness(SoMap startPage) {
         return tbBusinessMapper.getOtherBusiness(startPage);
@@ -1113,9 +1126,8 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
                     tbBusinessCarService.updateById(dbBusinessCar);
                 }
             } else {
-
                 //不存在或者已经离场的
-                if (checkCar == null||checkCar.getRealOutTime()!=null) {
+                if (checkCar == null || checkCar.getRealOutTime() != null) {
                     throw new AjaxError("车辆【" + carNo + "】未入场");
                 }
                 checkCar.setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
@@ -1773,7 +1785,6 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
                         throw new AjaxError("[" + tbAccount.getCustomerName() + "]账户余额不足扣除" + item.getItemName());
                     } else {
                         tbBusinessCar.setPayUnloadMoney(1);
-
                         tbBusinessCarService.updateById(tbBusinessCar);
                         item.setPayTime(now).setPayStatus(1).setPayType(PayEnum.PayType.PER_PAY.getCode())
                                 .setPayTypeName(PayEnum.PayType.PER_PAY.getDesc());

+ 2 - 0
sp-server/src/main/java/com/pj/project/tb_business_item/TbBusinessItemMapper.java

@@ -35,4 +35,6 @@ public interface TbBusinessItemMapper extends BaseMapper<TbBusinessItem> {
     List<TbBusinessItem> getCabinetRecord(SoMap soMap);
 
     List<TbBusinessItem> findByBusinessCarId(@Param("businessCarId") String businessCarId);
+
+    int checkNotOutBusinessItem(@Param("carNo") String carNo,@Param("itemName")String itemName);
 }

+ 10 - 0
sp-server/src/main/java/com/pj/project/tb_business_item/TbBusinessItemMapper.xml

@@ -101,5 +101,15 @@
         SELECT a.* from tb_business_item a, relation_business_car b WHERE a.business_id=b.business_id and b.business_car_id=#{businessCarId}
     </select>
 
+    <select id="checkNotOutBusinessItem" resultType="int">
+        select count(a.id)
+        from tb_business_item a,
+             relation_business_car r,
+             tb_business_car c
+        where a.business_id = r.business_id
+          and r.business_car_id = c.id
+          and (c.real_out_time is null)
+        and c.car_no=#{carNo} and a.item_name=#{itemName}
+    </select>
 
 </mapper>

+ 3 - 0
sp-server/src/main/java/com/pj/project/tb_business_item/TbBusinessItemService.java

@@ -453,4 +453,7 @@ public class TbBusinessItemService extends ServiceImpl<TbBusinessItemMapper, TbB
     }
 
 
+    public int findNotOutBusinessItem(String carNo,String itemName) {
+        return tbBusinessItemMapper.checkNotOutBusinessItem(carNo,itemName);
+    }
 }

+ 2 - 2
sp-server/src/main/resources/application-dev.yml

@@ -6,7 +6,7 @@ spring:
     # 数据源配置
     datasource:
         type: com.alibaba.druid.pool.DruidDataSource
-        url: jdbc:mysql://127.0.0.1:3306/pco_pro?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
+        url: jdbc:mysql://127.0.0.1:3306/pco?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
         username: root
         password: 123456
         # 是否打开sql监控台  (生产环境请务必关闭此选项)
@@ -28,7 +28,7 @@ spring:
         # Redis服务器连接端口
         port: 6379
         # Redis服务器连接密码(默认为空)
-        password: 123456
+        password:
         # 连接超时时间(毫秒)
         timeout: 5000ms
         jedis: