OpenService.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. package com.pj.api.open.service;
  2. import cn.hutool.cache.CacheUtil;
  3. import cn.hutool.cache.impl.TimedCache;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.core.util.NumberUtil;
  6. import cn.hutool.core.util.RandomUtil;
  7. import cn.hutool.core.util.StrUtil;
  8. import cn.hutool.json.JSONUtil;
  9. import cn.hutool.log.StaticLog;
  10. import com.alibaba.druid.sql.visitor.functions.If;
  11. import com.pj.api.open.ResultJson;
  12. import com.pj.api.open.bo.CheckCarNumberBO;
  13. import com.pj.api.open.bo.InRecordBO;
  14. import com.pj.api.wx.bo.ManagerBO;
  15. import com.pj.constants.business.CarEnum;
  16. import com.pj.constants.business.GoodsEnum;
  17. import com.pj.constants.business.PayEnum;
  18. import com.pj.current.config.PartConfig;
  19. import com.pj.current.config.SystemObject;
  20. import com.pj.current.task.TaskService;
  21. import com.pj.project.sync.SyncService;
  22. import com.pj.project.sync.request.item.IOrderItem;
  23. import com.pj.project.sync.response.IOrderPriceRes;
  24. import com.pj.project.tb_account.AutomaticPay;
  25. import com.pj.project.tb_business.TbBusiness;
  26. import com.pj.project.tb_business.TbBusinessService;
  27. import com.pj.project.tb_business_car.TbBusinessCar;
  28. import com.pj.project.tb_business_car.TbBusinessCarService;
  29. import com.pj.project.tb_business_item.TbBusinessItem;
  30. import com.pj.project.tb_business_item.TbBusinessItemService;
  31. import com.pj.project.tb_car.TbCar;
  32. import com.pj.project.tb_car.TbCarService;
  33. import com.pj.project.tb_car_weight.TbCarWeight;
  34. import com.pj.project.tb_car_weight.TbCarWeightService;
  35. import com.pj.project.tb_channel_config.TbChannelConfig;
  36. import com.pj.project.tb_channel_config.TbChannelConfigService;
  37. import com.pj.project.tb_deduction_bind.TbDeductionBindService;
  38. import com.pj.project.tb_goods.TbGoods;
  39. import com.pj.project.tb_goods.TbGoodsService;
  40. import com.pj.project.tb_item.TbItem;
  41. import com.pj.project.tb_item.TbItemService;
  42. import com.pj.project.tb_mild_car.TbMildCar;
  43. import com.pj.project.tb_mild_car.TbMildCarService;
  44. import com.pj.utils.cache.RedisUtil;
  45. import lombok.extern.slf4j.Slf4j;
  46. import org.springframework.context.annotation.Lazy;
  47. import org.springframework.scheduling.annotation.Async;
  48. import org.springframework.stereotype.Service;
  49. import org.springframework.transaction.annotation.Transactional;
  50. import javax.annotation.Resource;
  51. import java.math.BigDecimal;
  52. import java.math.RoundingMode;
  53. import java.time.LocalDateTime;
  54. import java.time.format.DateTimeFormatter;
  55. import java.util.*;
  56. import java.util.stream.Collectors;
  57. @Service
  58. @Transactional
  59. @Slf4j
  60. public class OpenService {
  61. @Resource
  62. @Lazy
  63. private TbBusinessService tbBusinessService;
  64. @Resource
  65. @Lazy
  66. private TbBusinessCarService tbBusinessCarService;
  67. @Resource
  68. private TbCarService tbCarService;
  69. @Resource
  70. TaskService taskService;
  71. @Resource
  72. private TbGoodsService tbGoodsService;
  73. @Resource
  74. @Lazy
  75. AutomaticPay automaticPay;
  76. @Resource
  77. private TbChannelConfigService tbChannelConfigService;
  78. @Resource
  79. private PartConfig partConfig;
  80. @Resource
  81. private TbMildCarService tbMildCarService;
  82. @Resource
  83. private TbBusinessItemService tbBusinessItemService;
  84. @Resource
  85. private SyncService syncService;
  86. @Resource
  87. private TbCarWeightService tbCarWeightService;
  88. @Resource
  89. private TbItemService tbItemService;
  90. public ResultJson checkCarNumber(CheckCarNumberBO checkCarNumberBO) {
  91. String carNo = checkCarNumberBO.getCarNumber();
  92. int inOrOut = checkCarNumberBO.getInOrOut();
  93. String image = checkCarNumberBO.getImageData();
  94. if (inOrOut == 1) {
  95. return handlerIn(carNo, checkCarNumberBO.getChannelName(), image);
  96. }
  97. return handlerOut(carNo, checkCarNumberBO.getChannelName(), image);
  98. }
  99. private ResultJson handlerIn(String carNo, String channel, String image) {
  100. carNo = carNo.toUpperCase();
  101. if (StrUtil.isNotEmpty(image)) {
  102. StaticLog.error("缓存入场图片:{}", carNo);
  103. IMAGE_CACHE.put(carNo, image);
  104. }
  105. List<TbBusinessCar> notOutList = tbBusinessCarService.findNotOutCar(carNo);
  106. if (!notOutList.isEmpty()) {
  107. String msg = "车辆有" + notOutList.size() + "条未离场记录";
  108. log.error("入场返回:{}", msg);
  109. return ResultJson.error(msg);
  110. }
  111. TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(carNo);
  112. Date now = new Date();
  113. TbCar tbCar = tbCarService.findByCardNo(carNo);
  114. //1、记录不存在;
  115. // 2、已离场重新入场;
  116. if (tbBusinessCar == null
  117. || (tbBusinessCar.getRealInTime() != null && tbBusinessCar.getRealOutTime() != null)
  118. ) {
  119. //=======创建新的放行记录==========
  120. tbBusinessCar = new TbBusinessCar();
  121. tbBusinessCar.setCarNo(carNo).setPay(0).setCarSize(0D).setIsLock(0).setPayType(CarEnum.PayTypeEnum.NO_PAY_TYPE.getType())
  122. .setPay(0)
  123. .setCarCompany(tbCar != null ? tbCar.getCustomerName() : "临时").setCreateTime(now)
  124. .setInChannel(channel).setRealInTime(now).setCarType(CarEnum.CarTypeEnum.EMPTY_TYPE.getType())
  125. .setBasePartMoney(new BigDecimal("0")).setTimeUpdate(now).setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_NEED_JUDGE.getCode())
  126. .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  127. tbBusinessCarService.save(tbBusinessCar);
  128. CoverBase64ToUrl(image, tbBusinessCar.getId(), carNo, 1);
  129. String msg = "无业务车辆";
  130. log.error("入场返回:{}", JSONUtil.toJsonStr(ResultJson.success(msg, msg)));
  131. return ResultJson.success(msg, msg);
  132. }
  133. tbBusinessCar.setRealInTime(now).setInChannel(channel).setTimeUpdate(now)
  134. .setCarCompany(tbCar != null ? tbCar.getCustomerName() : "临时");
  135. tbBusinessCarService.saveOrUpdate(tbBusinessCar);
  136. CoverBase64ToUrl(image, tbBusinessCar.getId(), carNo, 1);
  137. return ResultJson.success();
  138. }
  139. private void CoverBase64ToUrl(String base64image, String carId, String carNo, int inOrOut) {
  140. String cacheBase64 = IMAGE_CACHE.get(carNo);
  141. if (StrUtil.isEmpty(base64image)) {
  142. base64image = cacheBase64;
  143. }
  144. if (StrUtil.isEmpty(base64image)) {
  145. log.error("无出场图片:{}", carNo);
  146. return;
  147. }
  148. taskService.addTask(new CoverBase64ToImageTask("=======" + carId + "", 2000, carId, base64image, inOrOut));
  149. IMAGE_CACHE.remove(carNo);
  150. }
  151. final TimedCache<String, String> IMAGE_CACHE = CacheUtil.newTimedCache(30 * 60 * 1000);
  152. /**
  153. * 离场处理逻辑
  154. *
  155. * @param carNo
  156. * @param channel
  157. * @param image
  158. * @return
  159. */
  160. private ResultJson handlerOut(String carNo, String channel, String image) {
  161. carNo = carNo.toUpperCase();
  162. TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(carNo);
  163. if (tbBusinessCar == null || tbBusinessCar.getRealInTime() == null || tbBusinessCar.getRealOutTime() != null) {
  164. log.error("请求返回【未查询到入场记录】:{}", carNo);
  165. return ResultJson.error("未查询到入场记录");
  166. }
  167. Date now = new Date();
  168. Date realInTime = tbBusinessCar.getRealInTime();
  169. if (now.getTime() / 1000 - realInTime.getTime() / 1000 < partConfig.getMinSeconds()) {
  170. log.error("请求返回【无效离场记录,返回到设备端为:“未查询到入场记录”让其停止轮询】:{}", carNo);
  171. return ResultJson.error("无效离场记录");
  172. }
  173. if (StrUtil.isNotEmpty(image)) {
  174. StaticLog.error("缓存离场图片,{}", carNo);
  175. IMAGE_CACHE.put(carNo, image);
  176. }
  177. //判断是否4.2米以下蓝色车牌===免停车费
  178. if (StrUtil.isNotEmpty(tbBusinessCar.getColor())) {
  179. String freeColor = partConfig.getFreeColor();
  180. //4蓝色车辆
  181. if (tbBusinessCar.getColor().contains(freeColor)) {
  182. log.error("请求返回【蓝牌未备案车辆,放行】:{},{}", carNo, ResultJson.success());
  183. List<TbCarWeight> carWeights = tbCarWeightService.findByBusinessCarId(tbBusinessCar.getId());
  184. carWeights = carWeights.stream().filter(tbCarWeight -> tbCarWeight.getPayStatus() == 0).collect(Collectors.toList());
  185. BigDecimal weightMoney = BigDecimal.ZERO;
  186. if (!carWeights.isEmpty()) {
  187. for (TbCarWeight carWeight : carWeights) {
  188. weightMoney = carWeight.getWeightPrice().add(weightMoney);
  189. }
  190. }
  191. double wMoney = weightMoney.doubleValue();
  192. if (wMoney > 0) {
  193. log.info("请求返回【蓝牌车过磅费】,{},{}", carNo, wMoney);
  194. return ResultJson.error("过磅费" + wMoney);
  195. }
  196. freeOut(tbBusinessCar, now, channel, image);
  197. return ResultJson.success();
  198. }
  199. }
  200. //是否行政车辆=====
  201. if (checkFree(carNo, 2, now)) {
  202. freeOut(tbBusinessCar, now, channel, image);
  203. return ResultJson.success();
  204. }
  205. String businessCarId = tbBusinessCar.getId();
  206. String carType = tbBusinessCar.getCarType();
  207. IOrderPriceRes partMoneyRes;
  208. IOrderPriceRes businessRes = new IOrderPriceRes();
  209. List<IOrderItem> expenses = new ArrayList<>();
  210. List<TbBusiness> businessList = tbBusinessService.findOtherBusinessByCarId(businessCarId);
  211. long judgeCount = businessList.stream().filter(tbBusiness -> tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()).count();
  212. int size = businessList.size();
  213. if (size > judgeCount) {
  214. //业务未审核完
  215. log.error("请求返回【业务未审核】:{}", carNo);
  216. return ResultJson.error("业务未审核");
  217. }
  218. if (businessList.isEmpty()) {
  219. //地磅费--->无业务地磅费
  220. List<TbCarWeight> carWeights = tbCarWeightService.findByBusinessCarId(tbBusinessCar.getId());
  221. carWeights = carWeights.stream().filter(tbCarWeight -> tbCarWeight.getPayStatus() == 0).collect(Collectors.toList());
  222. BigDecimal weightMoney = BigDecimal.ZERO;
  223. if (!carWeights.isEmpty()) {
  224. for (TbCarWeight carWeight : carWeights) {
  225. weightMoney = carWeight.getWeightPrice().add(weightMoney);
  226. }
  227. }
  228. double wMoney = weightMoney.doubleValue();
  229. //无业务车辆===>计算停车费
  230. //如果已经支付过,则从支付时间算起,重新计算停车费
  231. Date inTime = tbBusinessCar.getRealInTime();
  232. if (CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType().equals(tbBusinessCar.getPayType()) && tbBusinessCar.getPayTime() != null) {
  233. inTime = tbBusinessCar.getPayTime();
  234. }
  235. IOrderPriceRes res = tbBusinessService.getPartMoney(inTime, now, carNo, tbBusinessCar.getColor());
  236. double dif = res.getTotalOrderPrice().subtract(tbBusinessCar.getMoney()).doubleValue();
  237. double total = NumberUtil.add(dif, wMoney);
  238. if (total > 0) {
  239. String desc = "请缴费用" + total + "元";
  240. log.error("请求返回:{},{}", carNo, desc);
  241. return ResultJson.error(desc);
  242. }
  243. //无需交停车费,又没有支付的--->设置成免费车辆
  244. if (tbBusinessCar.getPayTime() == null) {
  245. tbBusinessCar.setPayType(CarEnum.PayTypeEnum.FEE_TYPE.getType()).setPay(1);
  246. }
  247. freeOut(tbBusinessCar, now, channel, image);
  248. return ResultJson.success();
  249. } else {
  250. //有业务的车--->都要交停车费====>除了大头车,拦车
  251. //该车所有的业务都是到达卡口才进行扣费才会进入自动扣费
  252. Date inTime = tbBusinessCar.getRealInTime();
  253. if (CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType().equals(tbBusinessCar.getPayType()) && tbBusinessCar.getPayTime() != null) {
  254. inTime = tbBusinessCar.getPayTime();
  255. }
  256. partMoneyRes = tbBusinessService.getPartMoney(inTime, now, carNo, tbBusinessCar.getColor());
  257. double dif = partMoneyRes.getTotalOrderPrice().doubleValue();
  258. if (dif > 0) {
  259. log.error("停车费:{},{}元", carNo, dif);
  260. } else {
  261. if (tbBusinessCar.getPayTime() == null) {
  262. tbBusinessCar.setPayType(CarEnum.PayTypeEnum.FEE_TYPE.getType()).setPay(1);
  263. }
  264. }
  265. }
  266. //============业务费计算是否交完
  267. for (TbBusiness tbBusiness : businessList) {
  268. List<TbBusinessItem> businessItems = tbBusinessItemService.findByBusinessId(tbBusiness.getId());
  269. if (businessItems.isEmpty()) {
  270. continue;
  271. }
  272. //是否支付完
  273. boolean pay = businessItems.stream().noneMatch(item -> item.getPayStatus() == 0);
  274. TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
  275. //重车离场限制
  276. int weiCarLeave = tbGoods.getVietnamCarLeave();
  277. //空车离场限制
  278. int emptyCarLeave = tbGoods.getChinaCarLeave();
  279. //需要交业务费
  280. if (CarEnum.CarTypeEnum.WEIGHT_TYPE.getType().equals(carType)) {//==重车
  281. if (GoodsEnum.LeaveEnum.PART_MONEY.getCode() != weiCarLeave
  282. && !pay) {
  283. RedisUtil.setByMINUTES(channel, carNo, 5);
  284. tbBusinessItemService.buildExpenses(businessItems, expenses);
  285. log.error("==重车:缴纳业务费用:{}", carNo);
  286. }
  287. } else {
  288. if (GoodsEnum.LeaveEnum.PART_MONEY.getCode() != emptyCarLeave
  289. && !pay) {
  290. RedisUtil.setByMINUTES(channel, carNo, 5);
  291. tbBusinessItemService.buildExpenses(businessItems, expenses);
  292. }
  293. }
  294. }
  295. if (!expenses.isEmpty()) {
  296. businessRes = syncService.orderPriceCal(expenses);
  297. }
  298. BigDecimal carMoney = partMoneyRes.getTotalOrderPrice();
  299. BigDecimal businessMoney = businessRes.getTotalOrderPrice();
  300. BigDecimal total = businessMoney.add(carMoney);
  301. //地磅费
  302. List<TbCarWeight> carWeights = tbCarWeightService.findByBusinessCarId(tbBusinessCar.getId());
  303. //未支付的过磅费用
  304. carWeights = carWeights.stream().filter(tbCarWeight -> tbCarWeight.getPayStatus() == 0).collect(Collectors.toList());
  305. BigDecimal weightMoney = BigDecimal.ZERO;
  306. if (!carWeights.isEmpty()) {
  307. for (TbCarWeight carWeight : carWeights) {
  308. weightMoney = carWeight.getWeightPrice().add(weightMoney);
  309. }
  310. total = total.add(weightMoney);
  311. }
  312. if (total.doubleValue() > 0) {
  313. String desc = "请缴"+total+"费用";
  314. boolean flag = automaticPay.payBusinessAndPartMoney(businessList, tbBusinessCar, partMoneyRes, businessRes, carWeights);
  315. if (flag) {
  316. log.error("预存款扣款成功,返回:{},{}", carNo, desc);
  317. freeOut(tbBusinessCar, now, channel, image);
  318. return ResultJson.success();
  319. }
  320. log.error("请求返回:{},{}", carNo, desc);
  321. return ResultJson.error(desc);
  322. }
  323. freeOut(tbBusinessCar, now, channel, image);
  324. return ResultJson.success();
  325. }
  326. private void freeOut(TbBusinessCar tbBusinessCar, Date now, String outChannel, String base64Image) {
  327. tbBusinessCar.setRealOutTime(now).setTimeUpdate(now).setOutChannel(outChannel);
  328. if (tbBusinessCar.getPay() == 0) {
  329. tbBusinessCar.setPay(1);
  330. }
  331. tbBusinessCarService.updateById(tbBusinessCar);
  332. String carNo = tbBusinessCar.getCarNo();
  333. CoverBase64ToUrl(base64Image, tbBusinessCar.getId(), carNo, 2);
  334. RedisUtil.del(outChannel);
  335. log.error("请求返回【放行】:{}", carNo);
  336. }
  337. private boolean checkFree(String carNo, int inOrOut, Date now) {
  338. TbCar tbCar = tbCarService.findByCardNo(carNo);
  339. if (tbCar != null) {
  340. if (inOrOut == 1) {
  341. tbCar.setLastInTime(now);
  342. } else {
  343. tbCar.setLastOutTime(now);
  344. }
  345. tbCarService.updateById(tbCar);
  346. }
  347. return tbCar != null && !TbCar.CarTypeEnum.BUSINESS_CAR.getType().equals(tbCar.getCarType());
  348. }
  349. @Async
  350. public void handlerInRecord(InRecordBO inRecordBO) {
  351. String carNo = inRecordBO.getCarNumber().trim().toUpperCase();
  352. // 入场==>取车牌颜色
  353. TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(carNo);
  354. if (tbBusinessCar != null) {
  355. String color = inRecordBO.getCarColor();
  356. TbMildCar tbMildCar = tbMildCarService.findByCarNo(carNo);
  357. if (tbMildCar != null) {//车长
  358. tbBusinessCar.setCarSize(tbMildCar.getCarLength());
  359. }
  360. //蓝牌 4.2米以及以下
  361. if (color.contains(partConfig.getFreeColor())) {
  362. if (tbMildCar == null) {
  363. tbBusinessCar.setPayType(CarEnum.PayTypeEnum.FEE_TYPE.getType()).setPay(1);
  364. }
  365. }
  366. TbCar tbCar = tbCarService.findByCardNo(tbBusinessCar.getCarNo());
  367. if (tbCar != null && !TbCar.CarTypeEnum.BUSINESS_CAR.getType().equals(tbCar.getCarType())) {
  368. tbBusinessCar.setPayType(CarEnum.PayTypeEnum.FEE_TYPE.getType());
  369. List<TbBusiness> businessList = tbBusinessService.findOtherBusinessByCarId(tbBusinessCar.getId());
  370. if (businessList.isEmpty()) {
  371. //无业务&免费车===>无需审核
  372. tbBusinessCar.setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_NEED_JUDGE.getCode());
  373. }
  374. }
  375. tbBusinessCar.setColor(color);
  376. tbBusinessCarService.updateById(tbBusinessCar);
  377. }
  378. }
  379. final TimedCache<String, String> WEIGHT_IMAGE_CACHE = CacheUtil.newTimedCache(30 * 60 * 1000);
  380. final TimedCache<String, Integer> REQ_CACHE = CacheUtil.newTimedCache(60 * 1000);
  381. /**
  382. * @param checkCarNumberBO
  383. * @return
  384. */
  385. public ResultJson reqWeighbridge(CheckCarNumberBO checkCarNumberBO) {
  386. String carNo = checkCarNumberBO.getCarNumber();
  387. String channel = checkCarNumberBO.getChannelName();
  388. TbChannelConfig tbChannelConfig = tbChannelConfigService.findByName(channel);
  389. if (tbChannelConfig == null) {
  390. StaticLog.error("通道未配置,{}", channel);
  391. return ResultJson.error("通道未配置");
  392. }
  393. Integer weight = WEIGHT_CACHE.get(tbChannelConfig.getMatchChannelName());
  394. String image = checkCarNumberBO.getImageData();
  395. if (StrUtil.isNotEmpty(image)) {
  396. StaticLog.error("缓存称重图片,{}", carNo);
  397. WEIGHT_IMAGE_CACHE.put(carNo, image);
  398. }
  399. if (weight == null) {
  400. log.error("车辆未过磅:{},{}", channel, carNo);
  401. return ResultJson.error("请先过磅");
  402. }
  403. Integer hasRecord = REQ_CACHE.get(carNo, false);
  404. if (hasRecord != null) {
  405. log.info("重复识别,已过磅:{}", carNo);
  406. return ResultJson.error("已过磅");
  407. }
  408. TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(carNo);
  409. //--------------------------------------------这个地方会出问题,如果车辆离场了再称重------------------
  410. if (tbBusinessCar == null || tbBusinessCar.getRealOutTime() != null) {
  411. log.error("未找到有效入场记录:{},{}", channel, carNo);
  412. return ResultJson.error("未找到有效入场记录");
  413. }
  414. Date now = new Date();
  415. double weighbridge = NumberUtil.div(Double.valueOf(weight).doubleValue(), 1000, 2);
  416. tbBusinessCar.setNetWeight(weighbridge + "");
  417. TbItem tbItem = tbItemService.findByAliasName(SystemObject.config.getWeighbridge());
  418. IOrderItem iOrderItem = new IOrderItem();
  419. iOrderItem.setUniqExpenseId(tbItem.getItemCode()).setExpenseNum(weighbridge + "");
  420. IOrderPriceRes res = syncService.orderPriceCal(Collections.singletonList(iOrderItem));
  421. BigDecimal weightMoney = res.getTotalOrderPrice();
  422. tbBusinessCar.setNetweightMoney(weightMoney.add(tbBusinessCar.getNetweightMoney()));
  423. tbBusinessCarService.updateById(tbBusinessCar);
  424. WEIGHT_CACHE.remove(channel);
  425. TbCarWeight carWeight = new TbCarWeight();
  426. String no = DateUtil.format(now, "yyyyMMddHHmm") + RandomUtil.randomLong(1000, 9999);
  427. carWeight.setCarNo(carNo).setTotalWeight(BigDecimal.valueOf(weighbridge)).setCalculateId(res.getCalculateId())
  428. .setChannelName(channel).setCreateTime(now).setInTime(now).setOutTime(now).setCustomerId(tbBusinessCar.getCustomerId())
  429. .setBusinessCarId(tbBusinessCar.getId()).setNo(no).setWeightPrice(weightMoney);
  430. tbCarWeightService.save(carWeight);
  431. taskService.addTask(new CoverWeightBase64ToImageTask("=======" + carWeight.getId() + "", 2000, carWeight.getId(), WEIGHT_IMAGE_CACHE.get(carNo)));
  432. WEIGHT_CACHE.remove(carNo);
  433. REQ_CACHE.put(carNo, 1);
  434. if (tbChannelConfig.getHandlerUp() == 1) {
  435. return ResultJson.success(tbBusinessCar.getNetWeight());
  436. } else {
  437. return ResultJson.error("过磅完成" + tbBusinessCar.getNetWeight());
  438. }
  439. }
  440. private final TimedCache<String, Integer> WEIGHT_CACHE = CacheUtil.newTimedCache(120000);
  441. /**
  442. * 缓存地磅数据
  443. *
  444. * @param channel
  445. * @param weight kg====>
  446. */
  447. public void cacheWeighbridge(String channel, Integer weight) {
  448. WEIGHT_CACHE.put(channel, weight);
  449. }
  450. /**
  451. * 清除缓存
  452. *
  453. * @param channel
  454. */
  455. public void cleanWeighbridge(String channel) {
  456. WEIGHT_CACHE.remove(channel);
  457. }
  458. }