AutomaticPay.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. package com.pj.project.tb_account;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.util.NumberUtil;
  4. import cn.hutool.core.util.RandomUtil;
  5. import cn.hutool.extra.spring.SpringUtil;
  6. import cn.hutool.log.StaticLog;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.pj.api.open.ResultJson;
  9. import com.pj.project.tb_business.TbBusiness;
  10. import com.pj.project.tb_business.TbBusinessService;
  11. import com.pj.project.tb_business_car.TbBusinessCar;
  12. import com.pj.project.tb_business_car.TbBusinessCarService;
  13. import com.pj.project.tb_business_item.TbBusinessItem;
  14. import com.pj.project.tb_business_item.TbBusinessItemService;
  15. import com.pj.project.tb_deduction_bind.TbDeductionBind;
  16. import com.pj.project.tb_deduction_bind.TbDeductionBindService;
  17. import com.pj.project.tb_deduction_record.TbDeductionRecord;
  18. import com.pj.project.tb_fee_details.TbFeeDetails;
  19. import com.pj.project.tb_fee_details.TbFeeDetailsService;
  20. import com.pj.project.tb_goods.TbGoods;
  21. import com.pj.project.tb_goods.TbGoodsService;
  22. import com.pj.project.tb_invoice_order.TbInvoiceOrder;
  23. import com.pj.project.tb_invoice_order.TbInvoiceOrderService;
  24. import com.pj.project.tb_item.TbItem;
  25. import com.pj.utils.AesUtil;
  26. import com.pj.utils.cache.RedisUtil;
  27. import com.pj.utils.sg.NbUtil;
  28. import org.springframework.scheduling.annotation.Async;
  29. import org.springframework.stereotype.Component;
  30. import org.springframework.transaction.annotation.Transactional;
  31. import javax.annotation.Resource;
  32. import java.math.BigDecimal;
  33. import java.time.LocalDateTime;
  34. import java.time.format.DateTimeFormatter;
  35. import java.util.ArrayList;
  36. import java.util.Date;
  37. import java.util.List;
  38. import java.util.stream.Collectors;
  39. /**
  40. * 预充值自动缴费
  41. */
  42. @Component
  43. @Transactional
  44. public class AutomaticPay {
  45. @Resource
  46. TbBusinessCarService tbBusinessCarService;
  47. @Resource
  48. TbBusinessService tbBusinessService;
  49. @Resource
  50. TbDeductionBindService deductionBindService;
  51. @Resource
  52. TbBusinessItemService tbBusinessItemService;
  53. @Resource
  54. TbFeeDetailsService tbFeeDetailsService;
  55. @Resource
  56. TbAccountService tbAccountService;
  57. @Resource
  58. TbInvoiceOrderService invoiceOrderService;
  59. @Resource
  60. TbGoodsService tbGoodsService;
  61. private Integer feeType;
  62. /**
  63. * 异步扣费入口
  64. * @param businessId 业务id
  65. * @param plate 车牌号
  66. * @param feeType 收费类型,1-只收停车费、2-只收业务费,3-停车和业务费
  67. */
  68. //TODO 不要在此方法写逻辑
  69. @Async
  70. public void run(String businessId, String plate, Integer feeType) {
  71. this.feeType = feeType;
  72. task(businessId,plate,feeType);
  73. }
  74. /**
  75. * 异步解绑入口
  76. * @param plate
  77. */
  78. @Async
  79. public void unbindRun(String plate){
  80. if(isExistTask(null,plate)){
  81. return;
  82. }
  83. autoUnbindCarByPlate(plate);
  84. delRedisTask(null,plate);
  85. }
  86. /**
  87. * 分配任务
  88. */
  89. private void task(String businessId, String plate, Integer feeType){
  90. if(isExistTask(businessId,plate)){
  91. return;
  92. }
  93. if(feeType==1){
  94. doParkingFee(plate,0.0);
  95. }else if(feeType==2){
  96. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(businessId);
  97. for (TbBusinessCar car : cars){
  98. this.doBusinessFee(businessId,car.getCarNo());
  99. }
  100. }else if(feeType==3){
  101. doOutFee(plate);
  102. }
  103. delRedisTask(businessId,plate);
  104. }
  105. /**
  106. * 收业务费
  107. * @param businessId
  108. */
  109. private void doBusinessFee(String businessId,String plate){
  110. if(!NumberUtil.isNumber(businessId) || NbUtil.isNull(plate)){
  111. return;
  112. }
  113. StaticLog.info("开始收取业务费:{}" , businessId);
  114. TbBusiness tbBusiness = tbBusinessService.getById(businessId);
  115. if(TbBusiness.PayStatus.NO_PAY.getCode()!=tbBusiness.getPayStatus()){
  116. StaticLog.info("已收取过业务费,退出收费程序:{}" , businessId);
  117. return;
  118. }
  119. if(!NumberUtil.isNumber(tbBusiness.getItemPrice().toString())){
  120. StaticLog.info("未获取到收费总金额或收费总金额非法,退出收费程序:{}" , businessId);
  121. return;
  122. }
  123. if(!deductionBindService.isBindCarByPlate(plate)){
  124. StaticLog.info("业务车辆未绑定指定客户的预存款账户,退出收费程序:{}{}",businessId,tbBusiness.getCustomerName());
  125. return;
  126. }
  127. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(businessId);
  128. TbDeductionBind bind = deductionBindService.getBindCarByPlate(plate);
  129. TbAccount tbAccount = tbAccountService.getByCustomerId(bind.getCustomerId());
  130. String key = AesUtil.reverse(tbAccount.getAccSalt());
  131. String totalMoney = tbAccount.getTotalMoney();
  132. BigDecimal parkingMoneyBig = new BigDecimal(0);
  133. BigDecimal totalMoneyBig = new BigDecimal(totalMoney);
  134. BigDecimal balance = totalMoneyBig.subtract(tbBusiness.getItemPrice());
  135. boolean isOut = (TbGoods.DeductionTypeEnum.OUT_KK.getCode()==tbBusiness.getAutoDeductionType()) &&
  136. this.feeType==3;
  137. if(isOut){
  138. parkingMoneyBig = getParkings(cars);
  139. balance = balance.subtract(parkingMoneyBig);
  140. }
  141. if(balance.doubleValue()<0){
  142. StaticLog.info("支付账户余额不足!,退出收费程序:{}" , businessId);
  143. deductionBindService.setFeeFailRecord(bind.getCustomerId(),plate,
  144. AesUtil.toStr(tbBusiness.getGoodsName())+":因支付账户余额不足,自动缴费失败。。");
  145. return;
  146. }
  147. Date now = new Date();
  148. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
  149. tbBusiness.setPayMoney(tbBusiness.getItemPrice()).setPayTime(now).setPayType(5)
  150. .setPayNo(no).setConfirmInput(1).setConfirmInputTime(now).setPayStatus(
  151. TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode());
  152. tbBusiness.updateById();
  153. List<TbBusinessItem> businessItems = tbBusinessItemService.findByBusinessId(businessId);
  154. for(TbBusinessItem businessItem:businessItems){
  155. if(businessItem.getPayStatus()==1){
  156. continue;
  157. }
  158. businessItem.setPayStatus(1).setPayTime(now);
  159. }
  160. tbBusinessItemService.updateBatchById(businessItems);
  161. if(isOut){
  162. this.updateTbBusinessCars(cars);
  163. }
  164. //更新账户余额
  165. tbAccount.setTotalMoney(AesUtil.encryptECB(balance.toString(),key));
  166. tbAccount.updateById();
  167. deductionBindService.setDeductMoney(bind.getCustomerId(),plate,tbBusiness.getItemPrice());
  168. //生成收费明细
  169. List<TbFeeDetails> tbFeeDetailsList = tbFeeDetailsService.autoChargeBusinessFee(
  170. businessItems,null,null,now);
  171. //生成扣费记录
  172. createTbDeductionRecord(tbFeeDetailsList,tbAccount, totalMoneyBig,plate,bind.getCustomerName(),no);
  173. //生成开票信息
  174. createTbInvoiceOrder(tbBusiness, cars, parkingMoneyBig, plate,bind.getCustomerId(),no,isOut);
  175. if(isOut){
  176. deductionBindService.setDeductMoney(bind.getCustomerId(),plate,parkingMoneyBig);
  177. List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.autoChargeParkFee(
  178. cars,null,null,now);
  179. createTbDeductionRecord(parkFeeDetailsList,tbAccount,
  180. totalMoneyBig.subtract(tbBusiness.getItemPrice()),plate,bind.getCustomerName(),no);
  181. deductionBindService.autoUnbindCar(cars);
  182. }
  183. StaticLog.info("预充值自动缴费成功!,退出收费程序:{}{}" , businessId,tbAccount.getCustomerId());
  184. }
  185. /**
  186. * 出场所收费,根据车牌号
  187. * @param plate
  188. */
  189. private void doOutFee(String plate){
  190. if(NbUtil.isNull(plate)){
  191. return;
  192. }
  193. TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(plate);
  194. if(tbBusinessCar==null){
  195. return;
  196. }
  197. List<TbBusiness> businessList = tbBusinessService.findOtherBusinessByCarId(tbBusinessCar.getId());
  198. if(businessList==null){return;}
  199. for (TbBusiness business: businessList){
  200. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(business.getId());
  201. if(cars==null)continue;
  202. for (TbBusinessCar car:cars){
  203. doBusinessFee(business.getId(), car.getCarNo());
  204. }
  205. }
  206. }
  207. /**
  208. * 收停车费,不判断免费车辆
  209. * @param plate
  210. * @param parkingFee
  211. */
  212. private void doParkingFee(String plate, double parkingFee){
  213. if(NbUtil.isNull(plate)){
  214. return;
  215. }
  216. TbBusinessCar car = tbBusinessCarService.findTheLastRecord(plate);
  217. if(car==null){
  218. return;
  219. }
  220. StaticLog.info("开始自动缴纳停车费:{}" , car.getCarNo());
  221. // if(car.getPay()==1 || car.getPayTime()!=null){
  222. // StaticLog.info("该车辆已缴纳过停车费!,退出收费程序:{}" , car.getCarNo());
  223. // return;
  224. // }
  225. TbAccount account = tbAccountService.getTbAccountByPlate(car.getCarNo());
  226. if (account==null){
  227. StaticLog.info("该车辆还未绑定客户预存款账户!,退出收费程序:{}" , car.getCarNo());
  228. return;
  229. }
  230. BigDecimal parkFeeBig = null;
  231. if(parkingFee>0){
  232. parkFeeBig = new BigDecimal(String.valueOf(parkingFee));
  233. }else {
  234. parkFeeBig = caulatePrice(car, new Date());
  235. }
  236. if(parkFeeBig==null ||parkFeeBig.doubleValue()<=0){
  237. StaticLog.info("该车辆无需缴纳停车费!,退出收费程序:{}" , car.getCarNo());
  238. return;
  239. }
  240. TbDeductionBind bind = deductionBindService.getBindCarByPlate(plate);
  241. BigDecimal totalBig = new BigDecimal("0");
  242. String key = null;
  243. if(!NumberUtil.isNumber(account.getTotalMoney())){
  244. key = AesUtil.reverse(account.getAccSalt());
  245. totalBig = new BigDecimal(AesUtil.decryptECB(account.getTotalMoney(),key));
  246. }
  247. BigDecimal balance = totalBig.subtract(parkFeeBig);
  248. if(balance.doubleValue()<0){
  249. StaticLog.info("支付账户余额不足!,退出收费程序:{}" , car.getCarNo());
  250. return;
  251. }
  252. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
  253. car.setMoney(parkFeeBig);
  254. updateTbBusinessCar(car);
  255. account.setTotalMoney(AesUtil.encryptECB(balance.toString(),key));
  256. account.updateById();
  257. deductionBindService.setDeductMoney(bind.getCustomerId(),plate,parkFeeBig);
  258. List<TbBusinessCar> cars = new ArrayList<TbBusinessCar>();
  259. cars.add(car);
  260. List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.autoChargeParkFee(
  261. cars,null,null,new Date());
  262. createTbDeductionRecord(parkFeeDetailsList,account, totalBig,plate,bind.getCustomerName(),no);
  263. createTbInvoiceOrderPark(car,account.getCustomerId(),no);
  264. deductionBindService.autoUnbindCar(cars);
  265. StaticLog.info("停车费自动缴费成功!,退出收费程序:{}" , car.getCarNo());
  266. }
  267. /**
  268. * 生成扣费记录
  269. * @param tbFeeDetailsList
  270. * @param tbAccount
  271. * @param totalMoneyBig
  272. */
  273. private void createTbDeductionRecord(List<TbFeeDetails> tbFeeDetailsList,TbAccount tbAccount,
  274. BigDecimal totalMoneyBig,String plate,String customerName,String no ){
  275. if(tbFeeDetailsList==null)return;
  276. int i = 0;
  277. String tempMoney = null;
  278. String bindIdStr = deductionBindService.getBindId(plate);
  279. for (TbFeeDetails feeDetails : tbFeeDetailsList){
  280. TbDeductionRecord deductionRecord = BeanUtil.toBean(feeDetails,TbDeductionRecord.class);
  281. String totalStr = null;
  282. if(totalMoneyBig!=null && feeDetails.getNoTaxPrice()!=null){
  283. if(i!=0){
  284. totalMoneyBig = new BigDecimal(tempMoney);
  285. }
  286. totalStr = totalMoneyBig.subtract(feeDetails.getItemPrice()).toString();
  287. tempMoney = totalStr;
  288. }
  289. deductionRecord.setId(null);
  290. deductionRecord.setDeductionBindId(bindIdStr);
  291. deductionRecord.setCustomerId(tbAccount.getCustomerId());
  292. deductionRecord.setCustomerName(customerName);
  293. deductionRecord.setFeeDetailsId(feeDetails.getId());
  294. deductionRecord.setOriginalMoney(totalMoneyBig.toString());
  295. deductionRecord.setDeductMoney(feeDetails.getItemPrice());
  296. deductionRecord.setTotalMoney(totalStr);
  297. deductionRecord.setReviewStatus(0);
  298. deductionRecord.setCarNo(plate);
  299. deductionRecord.setPreOrderNum(no);
  300. deductionRecord.insert();
  301. feeDetails.setCarNo(plate);
  302. feeDetails.setPreOrderNum(no);
  303. feeDetails.setCustomerId(tbAccount.getCustomerId());
  304. feeDetails.setCustomerName(customerName);
  305. tbFeeDetailsService.updateById(feeDetails);
  306. i++;
  307. }
  308. }
  309. /**
  310. * 更新停车费状态
  311. */
  312. private void updateTbBusinessCar(TbBusinessCar car){
  313. if(car == null)return;
  314. car.setPay(1).setPayTime(new Date());
  315. car.updateById();
  316. }
  317. /**
  318. * 更新停车费状态
  319. */
  320. private void updateTbBusinessCars(List<TbBusinessCar> cars){
  321. if(cars == null)return;
  322. for (TbBusinessCar car:cars){
  323. updateTbBusinessCar(car);
  324. }
  325. }
  326. /**
  327. * 生成开票订单信息
  328. * @param tbBusiness
  329. */
  330. private void createTbInvoiceOrder(TbBusiness tbBusiness,List<TbBusinessCar> cars, BigDecimal parkingFee,
  331. String plate, String customerId, String no, boolean isOut){
  332. TbInvoiceOrder invoiceOrder = new TbInvoiceOrder();
  333. List<String> businessNameList = new ArrayList<>();
  334. List<String> businessNoList = new ArrayList<>();
  335. List<String> carNos = new ArrayList<>();
  336. businessNoList.add(tbBusiness.getNo());
  337. carNos.add(plate);
  338. businessNameList.add(tbBusiness.getGoodsName());
  339. if(cars!=null){
  340. for (TbBusinessCar car : cars) {
  341. if(isOut){
  342. if(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType().equals(car.getPayType())){
  343. continue;
  344. }
  345. if(!businessNameList.contains("停车费")){
  346. businessNameList.add("停车费");
  347. }
  348. }else {
  349. if(NbUtil.isNull(car.getCarNo()) || !car.getCarNo().equals(plate)){
  350. continue;
  351. }
  352. }
  353. if(!businessNoList.contains(car.getNo())){
  354. businessNoList.add(car.getNo());
  355. }
  356. if(!carNos.contains(car.getCarNo())){
  357. carNos.add(car.getCarNo());
  358. }
  359. }
  360. }
  361. String businessNameStr = businessNameList.stream().map(String::valueOf).collect(Collectors.joining(","));
  362. String businessNoStr = businessNoList.stream().map(String::valueOf).collect(Collectors.joining(","));
  363. String carNoStr = carNos.stream().map(String::valueOf).collect(Collectors.joining(","));
  364. BigDecimal billMoney = tbBusiness.getItemPrice();
  365. if(parkingFee!=null){
  366. billMoney = parkingFee.add(billMoney);
  367. }
  368. invoiceOrder.setBusinessName(businessNameStr).setBusinessNo(businessNoStr).setCarNo(carNoStr)
  369. .setTransactionId(null).setBillMoney(billMoney).setBusinessId(tbBusiness.getId())
  370. .setStatus(0).setCreateTime(new Date()).setCustomerId(customerId).setPreOrderNum(no);
  371. invoiceOrderService.save(invoiceOrder);
  372. }
  373. /**
  374. * 无业务车辆收停车费生成发票信息
  375. */
  376. private void createTbInvoiceOrderPark(TbBusinessCar car, String customerId,String no){
  377. TbInvoiceOrder invoiceOrder = new TbInvoiceOrder();
  378. invoiceOrder.setBusinessName("停车费").setBusinessNo(car.getNo()).setCarNo(car.getCarNo())
  379. .setTransactionId(null).setBillMoney(car.getMoney()).setBusinessId(null)
  380. .setStatus(0).setCreateTime(new Date()).setCustomerId(customerId).setPreOrderNum(no);
  381. invoiceOrderService.save(invoiceOrder);
  382. }
  383. /**
  384. * 生成停车费
  385. * @param tbBusinessCar
  386. * @param now
  387. * @return
  388. */
  389. private BigDecimal caulatePrice(TbBusinessCar tbBusinessCar, Date now) {
  390. if(tbBusinessCar==null || now==null) new BigDecimal("0");
  391. Date inTime = tbBusinessCar.getRealInTime();
  392. if (tbBusinessCar.getPay() == 1 && tbBusinessCar.getRealOutTime() == null && tbBusinessCar.getPayTime() != null) {
  393. inTime = tbBusinessCar.getPayTime();
  394. }
  395. BigDecimal price = tbBusinessService.calculationPartMoney(inTime, now);
  396. tbBusinessCar.setMoney(price);
  397. return price;
  398. }
  399. /**
  400. * 获取所有停车费总和
  401. * @param cars
  402. * @return
  403. */
  404. private BigDecimal getParkings(List<TbBusinessCar> cars){
  405. if(cars==null) new BigDecimal("0");
  406. Date now = new Date();
  407. BigDecimal value = new BigDecimal("0");
  408. for (TbBusinessCar car:cars){
  409. value = value.add(this.caulatePrice(car,now));
  410. car.setPayType(TbBusinessCar.PayTypeEnum.HAS_PAY_TYPE.getType());
  411. }
  412. return value;
  413. }
  414. /**
  415. * 获取所有停车费总和,过滤免费车
  416. * @param cars
  417. * @return
  418. */
  419. private BigDecimal getParkingsByBS(List<TbBusinessCar> cars,TbBusiness tbBusiness){
  420. if(cars==null) new BigDecimal("0");
  421. Date now = new Date();
  422. BigDecimal value = new BigDecimal("0");
  423. for (TbBusinessCar car:cars){
  424. if(isParkingFeeByBS(tbBusiness,car.getCarType())){
  425. car.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
  426. }else {
  427. value = value.add(this.caulatePrice(car,now));
  428. car.setPayType(TbBusinessCar.PayTypeEnum.HAS_PAY_TYPE.getType());
  429. }
  430. }
  431. return value;
  432. }
  433. /**
  434. * 判断有业务的车是否收停车费
  435. * @return true是免费
  436. */
  437. private boolean isParkingFeeByBS(TbBusiness tbBusiness,String carType){
  438. if (TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType)) {
  439. TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
  440. return tbGoods.getChinaCarPay() == 1;
  441. } else {//越南车=重车
  442. TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
  443. return tbGoods.getVietnamCarPay() == 1;
  444. }
  445. }
  446. /**
  447. * 补录进场解绑逻辑
  448. * @return
  449. */
  450. private void autoUnbindCarByPlate(String plate){
  451. if(NbUtil.isNull(plate)) return;
  452. TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(plate);
  453. //离场逻辑
  454. if (tbBusinessCar!=null){
  455. if(doUnbindCarByPlate(tbBusinessCar)){
  456. return;
  457. }
  458. }
  459. //进场逻辑
  460. TbDeductionBind bind = deductionBindService.getOne(new LambdaQueryWrapper<TbDeductionBind>().eq(
  461. TbDeductionBind::getBindCar,plate).isNull(TbDeductionBind::getUnbindTime));
  462. if(bind != null){
  463. TbDeductionRecord record = new TbDeductionRecord();
  464. Integer count = record.selectCount(new LambdaQueryWrapper<TbDeductionRecord>().like(
  465. TbDeductionRecord::getDeductionBindId,bind.getId()));
  466. if(count>0){
  467. bind.setUpdateBy("预充值自动缴费解绑");
  468. bind.setUpdateTime(new Date());
  469. bind.setUnbindTime(new Date());
  470. bind.updateById();
  471. }else {
  472. Integer buCount = tbBusinessService.count(new LambdaQueryWrapper<TbBusiness>().ne(
  473. TbBusiness::getPayStatus,1)
  474. .between(TbBusiness::getCreateTime,bind.getBindTime(),NbUtil.getNow()));
  475. if(buCount>0){
  476. bind.setUpdateBy("预充值自动缴费解绑");
  477. bind.setUpdateTime(new Date());
  478. bind.setUnbindTime(new Date());
  479. bind.updateById();
  480. }
  481. }
  482. }
  483. }
  484. /**
  485. * 补录出场解绑逻辑
  486. * @param tbBusinessCar
  487. */
  488. private boolean doUnbindCarByPlate(TbBusinessCar tbBusinessCar){
  489. if (tbBusinessCar==null || tbBusinessCar.getRealOutTime()==null){
  490. return false;
  491. }
  492. TbDeductionBind bind = deductionBindService.getOne(new LambdaQueryWrapper<TbDeductionBind>().eq(
  493. TbDeductionBind::getBindCar,tbBusinessCar.getCarNo())
  494. .lt(TbDeductionBind::getBindTime,tbBusinessCar.getRealOutTime())
  495. .isNull(TbDeductionBind::getUnbindTime));
  496. if(bind==null){
  497. return false;
  498. }
  499. bind.setUpdateBy("预充值自动缴费解绑");
  500. bind.setUpdateTime(new Date());
  501. bind.setUnbindTime(new Date());
  502. bind.updateById();
  503. return true;
  504. }
  505. /**
  506. * 缓存任务,如果存在任务不继续往下执行
  507. * @param businessId
  508. * @param plate
  509. * @return
  510. */
  511. private boolean isExistTask(String businessId, String plate){
  512. String key = getRedisKey(businessId,plate);
  513. if(NbUtil.isNullStr(RedisUtil.get(key))){
  514. RedisUtil.setByMINUTES(key,key,5);
  515. return false;
  516. }
  517. return true;
  518. }
  519. private void delRedisTask(String businessId, String plate){
  520. String key = getRedisKey(businessId,plate);
  521. RedisUtil.del(key);
  522. }
  523. private String getRedisKey(String businessId, String plate){
  524. if(NbUtil.isNullStr(businessId)){
  525. businessId = "100";
  526. }
  527. if(NbUtil.isNullStr(plate)){
  528. plate = "100";
  529. }
  530. String key = "autoPay:"+businessId+plate;
  531. return key;
  532. }
  533. }