TbBusinessService.java 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. package com.pj.project.tb_business;
  2. import java.math.BigDecimal;
  3. import java.time.LocalDateTime;
  4. import java.time.ZoneId;
  5. import java.time.format.DateTimeFormatter;
  6. import java.time.temporal.ChronoUnit;
  7. import java.util.*;
  8. import java.util.stream.Collectors;
  9. import cn.hutool.core.date.DateUtil;
  10. import cn.hutool.core.util.NumberUtil;
  11. import cn.hutool.core.util.RandomUtil;
  12. import cn.hutool.core.util.StrUtil;
  13. import cn.hutool.json.JSONUtil;
  14. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  15. import com.baomidou.mybatisplus.extension.service.IService;
  16. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  17. import com.pj.api.bo.OtherBusinessEditBO;
  18. import com.pj.api.wx.bo.MsgDataBO;
  19. import com.pj.api.wx.service.WxService;
  20. import com.pj.constants.UserTypeEnum;
  21. import com.pj.current.config.CarConfig;
  22. import com.pj.current.config.MyConfig;
  23. import com.pj.current.config.PartConfig;
  24. import com.pj.current.config.WxConfig;
  25. import com.pj.current.satoken.StpUserUtil;
  26. import com.pj.project.relation_business_car.RelationBusinessCar;
  27. import com.pj.project.relation_business_car.RelationBusinessCarService;
  28. import com.pj.project.relation_goods_type.RelationGoodsTypeService;
  29. import com.pj.project.relation_type_item.RelationTypeItem;
  30. import com.pj.project.relation_type_item.RelationTypeItemService;
  31. import com.pj.project.tb_business_car.TbBusinessCar;
  32. import com.pj.project.tb_business_car.TbBusinessCarService;
  33. import com.pj.project.tb_business_item.TbBusinessItem;
  34. import com.pj.project.tb_business_item.TbBusinessItemService;
  35. import com.pj.project.tb_business_people.TbBusinessPeople;
  36. import com.pj.project.tb_business_people.TbBusinessPeopleService;
  37. import com.pj.project.tb_business_sort.TbBusinessSort;
  38. import com.pj.project.tb_business_sort.TbBusinessSortService;
  39. import com.pj.project.tb_car.TbCar;
  40. import com.pj.project.tb_car.TbCarService;
  41. import com.pj.project.tb_car_no_color.TbCarNoColor;
  42. import com.pj.project.tb_car_no_color.TbCarNoColorService;
  43. import com.pj.project.tb_costomer.TbCostomer;
  44. import com.pj.project.tb_costomer.TbCostomerService;
  45. import com.pj.project.tb_declare.TbDeclare;
  46. import com.pj.project.tb_declare.TbDeclareService;
  47. import com.pj.project.tb_driver.TbDriver;
  48. import com.pj.project.tb_driver.TbDriverService;
  49. import com.pj.project.tb_goods.TbGoods;
  50. import com.pj.project.tb_goods.TbGoodsService;
  51. import com.pj.project.tb_item.TbItem;
  52. import com.pj.project.tb_item.TbItemService;
  53. import com.pj.project.tb_item_type.TbItemType;
  54. import com.pj.project.tb_item_type.TbItemTypeService;
  55. import com.pj.project.tb_notices.TbNoticesService;
  56. import com.pj.project.tb_sort_group.TbSortGroup;
  57. import com.pj.project.tb_sort_group.TbSortGroupService;
  58. import com.pj.project.tb_unit.TbUnit;
  59. import com.pj.project.tb_unit.TbUnitService;
  60. import com.pj.project4sp.admin.SpAdmin;
  61. import com.pj.project4sp.admin.SpAdminService;
  62. import com.pj.project4sp.global.BusinessException;
  63. import com.pj.utils.so.SoMap;
  64. import org.springframework.beans.factory.annotation.Autowired;
  65. import org.springframework.context.annotation.Lazy;
  66. import org.springframework.scheduling.annotation.Async;
  67. import org.springframework.stereotype.Service;
  68. import com.pj.utils.sg.*;
  69. import org.springframework.transaction.annotation.Transactional;
  70. import javax.annotation.Resource;
  71. /**
  72. * Service: tb_business -- 入境登记
  73. *
  74. * @author qzy
  75. */
  76. @Service
  77. @Transactional(rollbackFor = Exception.class)
  78. public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness> implements IService<TbBusiness> {
  79. /**
  80. * 底层 Mapper 对象
  81. */
  82. @Autowired
  83. TbBusinessMapper tbBusinessMapper;
  84. @Resource
  85. private TbCarService tbCarService;
  86. @Resource
  87. private TbDriverService tbDriverService;
  88. @Resource
  89. private TbCostomerService tbCostomerService;
  90. @Resource
  91. private TbItemService tbItemService;
  92. @Resource
  93. private TbItemTypeService tbItemTypeService;
  94. @Resource
  95. private TbBusinessItemService tbBusinessItemService;
  96. @Resource
  97. TbUnitService tbUnitService;
  98. @Resource
  99. TbBusinessPeopleService tbBusinessPeopleService;
  100. @Resource
  101. private PartConfig partConfig;
  102. @Resource
  103. private CarConfig carConfig;
  104. @Resource
  105. private TbNoticesService tbNoticesService;
  106. @Resource
  107. private TbCarNoColorService tbCarNoColorService;
  108. @Resource
  109. TbBusinessCarService tbBusinessCarService;
  110. @Resource
  111. @Lazy
  112. TbDeclareService tbDeclareService;
  113. @Resource
  114. WxConfig wxConfig;
  115. @Resource
  116. @Lazy
  117. WxService wxService;
  118. @Resource
  119. MyConfig myConfig;
  120. @Resource
  121. private SpAdminService spAdminService;
  122. @Resource
  123. private TbBusinessSortService tbBusinessSortService;
  124. @Resource
  125. private TbSortGroupService tbSortGroupService;
  126. @Resource
  127. private TbGoodsService tbGoodsService;
  128. @Resource
  129. private RelationTypeItemService relationTypeItemService;
  130. @Resource
  131. private RelationBusinessCarService relationBusinessCarService;
  132. private final List<String> CAR_LIST = StrUtil.splitTrim("浙,粤,京,津,冀,晋,蒙,辽,黑,沪,吉,苏,皖,赣,鲁,豫,鄂,湘,桂,琼,渝,川,贵,云,藏, 陕, 甘, 青, 宁", ",");
  133. /**
  134. * 增
  135. */
  136. public AjaxJson addOrUpdate(TbBusiness t) {
  137. t.setBusinessType(TbBusiness.BusinessType.HOLD_CAR.getCode());
  138. if (StrUtil.isEmpty(t.getDeclareNo())) {
  139. throw new BusinessException("请选择申报单");
  140. }
  141. if (StrUtil.isNotEmpty(t.getId()) && StrUtil.isNotEmpty(t.getDeclareNo())) {
  142. TbBusiness db = this.getById(t.getId());
  143. if (!StrUtil.equals(db.getDeclareNo(), t.getDeclareNo())) {
  144. TbDeclare tbDeclare = tbDeclareService.findByDeclareNo(db.getDeclareNo());
  145. if (tbDeclare != null) {
  146. tbDeclare.setBusinessId("");
  147. tbDeclareService.updateById(tbDeclare);
  148. }
  149. }
  150. }
  151. Double carSize = t.getCardSize();
  152. if (carSize != null && carSize > carConfig.getMaxLength()) {
  153. return AjaxJson.getError("车辆规格不能大于" + carConfig.getMaxLength());
  154. }
  155. Double netWeight = t.getNetWeight();
  156. if (netWeight != null && netWeight > carConfig.getMaxWeight()) {
  157. return AjaxJson.getError("车辆载重不能大于" + carConfig.getMaxWeight());
  158. }
  159. t.setCreateBy(StpUserUtil.getAdmin().getName());
  160. createCarUnit(t);
  161. String customerId = t.getCustomerId();
  162. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  163. t.setCustomerName(tbCostomer.getName()).setCustomerType(tbCostomer.getPayType());
  164. if (StrUtil.equals(customerId, UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  165. t.setConfirmInputBy(StpUserUtil.getAdmin().getName())
  166. .setConfirmInput(1)
  167. .setConfirmInputTime(new Date());
  168. }
  169. if (StrUtil.isEmpty(t.getId())) {
  170. t.setCreateTime(new Date());
  171. t.setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  172. storeMsg(t.getCustomerId(), "新增一条业务数据:【" + t.getNo() + "】" + DateUtil.now() + "。");
  173. } else {
  174. storeMsg(t.getCustomerId(), "业务订单:【" + t.getNo() + "】数据发生更改," + DateUtil.now() + "。");
  175. }
  176. saveOrUpdate(t);
  177. createBusinessPeople(t);
  178. tbBusinessItemService.removeByBusinessId(t.getId());
  179. BigDecimal price = new BigDecimal(0);
  180. List<TbBusinessItem> items = JSONUtil.toList(t.getItemJson(), TbBusinessItem.class);
  181. int index = 1;
  182. for (TbBusinessItem item : items) {
  183. Double num = NumberUtil.parseDouble(item.getNum());
  184. TbItem tbItem = tbItemService.getById(item.getItemId());
  185. String typeId = tbItem.getTypeId();
  186. price = price.add(NumberUtil.mul(num, tbItem.getPrice()));
  187. TbItemType tbItemType = tbItemTypeService.getById(typeId);
  188. item.setBusinessId(t.getId()).setItemCode(tbItem.getItemCode()).setBusinessType(tbItem.getBusinessType())
  189. .setPayType(tbItem.getPayType()).setPayTypeName(tbItem.getPayTypeName())
  190. .setItemName(tbItem.getItemName()).setItemPrice(tbItem.getPrice())
  191. .setTaxRate(NumberUtil.div(tbItem.getTaxRate().doubleValue(), 100D, 2))
  192. .setItemTypeId(typeId).setItemTypeName(tbItemType.getName()).setBusinessType(tbItemType.getBusinessType())
  193. .setUnit(tbItem.getUnit()).setTotal(NumberUtil.mul(num, tbItem.getPrice())).setCreateTime(new Date())
  194. .setNo(t.getNo() + "0" + index);
  195. tbBusinessItemService.save(item);
  196. index++;
  197. }
  198. List<TbBusinessCar> carList = JSONUtil.toList(t.getCarJson(), TbBusinessCar.class);
  199. String chinaCarNo = carList.stream().map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  200. t.setChinaCarNo(StrUtil.isNotEmpty(chinaCarNo) ? chinaCarNo.toUpperCase() : "");
  201. carList.forEach(tbBusinessCar -> {
  202. tbBusinessCar.setIsLock(0);
  203. String carNo = tbBusinessCar.getCarNo().toUpperCase();
  204. TbBusinessCar db = tbBusinessCarService.findByBusinessIdAndCarNo(t.getId(), carNo);
  205. if (db != null) {
  206. tbBusinessCar.setId(db.getId()).setIsLock(db.getIsLock());
  207. }
  208. TbBusinessCar car = tbBusinessCarService.findInAndNoBusinessCar(carNo);
  209. if (car != null) {
  210. tbBusinessCar.setId(car.getId()).setRealInTime(car.getRealInTime()).setIsLock(car.getIsLock());
  211. }
  212. TbCar tbCar = tbCarService.findByCardNo(carNo);
  213. tbBusinessCar.setBusinessId(t.getId());
  214. tbBusinessCar.setCarNo(carNo).setCarCompany(tbCar != null ? tbCar.getCustomerName() : "临时");
  215. tbBusinessCar.setBusinessId(t.getId()).setCustomerId(t.getCustomerId());
  216. if (StrUtil.isEmpty(tbBusinessCar.getNo())) {
  217. tbBusinessCar.setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  218. }
  219. });
  220. String yueCarNo = t.getCardNo().toUpperCase();
  221. TbBusinessCar yueCar = tbBusinessCarService.findInAndNoBusinessCar(yueCarNo);
  222. if (yueCar == null) {
  223. yueCar = tbBusinessCarService.findByBusinessIdAndCarNo(t.getId(), yueCarNo);
  224. if (yueCar == null) {
  225. yueCar = new TbBusinessCar();
  226. yueCar.setIsLock(0);
  227. }
  228. }
  229. yueCar.setBusinessId(t.getId()).setCarSize(t.getCardSize()).setCarNo(yueCarNo).setCustomerId(t.getCustomerId());
  230. if (StrUtil.isEmpty(yueCar.getNo())) {
  231. yueCar.setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  232. }
  233. carList.add(yueCar);
  234. tbBusinessCarService.saveOrUpdateBatch(carList);
  235. t.setItemPrice(price)
  236. .setTotalMoney(price);
  237. this.saveOrUpdate(t);
  238. if (StrUtil.isNotEmpty(t.getDeclareNo())) {
  239. TbDeclare tbDeclare = tbDeclareService.findByDeclareNo(t.getDeclareNo());
  240. tbDeclare.setBusinessId(t.getId());
  241. tbDeclareService.updateById(tbDeclare);
  242. }
  243. return AjaxJson.getSuccess();
  244. }
  245. public void storeMsg(String businessCustomerId, String content) {
  246. String currentCustomerId = StpUserUtil.getCustomerId();
  247. if (StrUtil.equals(currentCustomerId, UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  248. BusinessMessageManager.set(businessCustomerId, content);
  249. } else {
  250. BusinessMessageManager.set(UserTypeEnum.PLATFORM_ADMIN.getCustomerId(), content);
  251. }
  252. }
  253. private void createBusinessPeople(TbBusiness t) {
  254. tbBusinessPeopleService.removeByBusinessId(t.getId());
  255. List<TbBusinessPeople> peopleList = JSONUtil.toList(t.getPeopleJson(), TbBusinessPeople.class);
  256. peopleList.forEach(tbBusinessPeople -> tbBusinessPeople.setBusinessId(t.getId()).setCreateTime(new Date()));
  257. tbBusinessPeopleService.saveBatch(peopleList);
  258. }
  259. private void createCarUnit(TbBusiness t) {
  260. TbUnit tbUnit = tbUnitService.findByUnit(t.getCardSize());
  261. if (tbUnit == null) {
  262. tbUnit = new TbUnit();
  263. tbUnit.setUnit(t.getCardSize() + "");
  264. tbUnitService.save(tbUnit);
  265. }
  266. }
  267. private TbDriver createDriver(TbBusiness business) {
  268. TbDriver tbDriver = tbDriverService.findByIdCardNo(business.getCardNo());
  269. if (tbDriver == null) {
  270. tbDriver = new TbDriver();
  271. tbDriver.setCreateTime(new Date()).setIdCard(business.getCardNo())
  272. .setName(business.getDriverName()).setPhone(business.getDriverPhone());
  273. tbDriverService.save(tbDriver);
  274. }
  275. return tbDriver;
  276. }
  277. private TbCar createCar(TbBusiness business) {
  278. String cardNo = business.getCardNo();
  279. TbCar tbCar = tbCarService.findByCardNo(cardNo);
  280. if (tbCar == null) {
  281. tbCar = new TbCar();
  282. }
  283. tbCar.setCardNo(cardNo)
  284. .setCardSize(business.getCardSize())
  285. .setCountryName(business.getCountryName())
  286. .setLastGoodsName(business.getGoodsName())
  287. .setLastNetWeight(business.getNetWeight());
  288. tbCarService.saveOrUpdate(tbCar);
  289. return tbCar;
  290. }
  291. /**
  292. * 查集合 - 根据条件(参数为空时代表忽略指定条件)
  293. */
  294. public List<TbBusiness> getList(SoMap so) {
  295. return tbBusinessMapper.getList(so);
  296. }
  297. public void pay(String id, String payTicket) {
  298. TbBusiness tbBusiness = this.getById(id);
  299. SpAdmin admin = StpUserUtil.getAdmin();
  300. tbBusiness.setPayStatus(2).setPayBy(admin.getName())
  301. .setPayBy(StpUserUtil.getAdmin().getName())
  302. .setPayTicket(payTicket)
  303. .setPayTime(new Date());
  304. if (StrUtil.equals(admin.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  305. tbBusiness.setAdminConfirmPay(1).setPayStatus(3)
  306. .setAdminConfirmPayBy(admin.getName()).setAdminConfirmPayTime(new Date());
  307. }
  308. this.updateById(tbBusiness);
  309. storeMsg(tbBusiness.getCustomerId(), "业务订单【" + tbBusiness.getNo() + "】已支付" + DateUtil.now() + "。");
  310. //发送消息
  311. String text = "您的费用已支付,业务单号[" + tbBusiness.getNo() + "]";
  312. tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text);
  313. }
  314. public void confirm(List<String> ids) {
  315. ids.forEach(id -> {
  316. TbBusiness business = this.getById(id);
  317. business.setConfirmInput(1).setAdminConfirmInput(1)
  318. .setConfirmInputTime(new Date())
  319. .setConfirmInputBy(StpUserUtil.getAdmin().getName());
  320. this.updateById(business);
  321. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(business.getId());
  322. String carNoStr = cars.stream().map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  323. storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】已确认" + DateUtil.now() + "。");
  324. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
  325. Integer bigBusinessType = business.getBusinessType();
  326. items.forEach(item -> {
  327. String businessType = item.getBusinessType();
  328. if (!StrUtil.equals(businessType, TbCostomer.CustomerEnum.BUSINESS_TYPE.getType())) {
  329. String customerId = business.getCustomerId();
  330. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  331. String customerType = tbCostomer.getType();
  332. if (StrUtil.equals(businessType, customerType)) {
  333. MsgDataBO msgDataBO = new MsgDataBO("订单号:" + item.getNo(), "系统自动确认",
  334. DateUtil.now(),
  335. business.getGoodsName() + "(" + item.getItemTypeName() + item.getItemName() + "-" + carNoStr + ")");
  336. List<SpAdmin> spAdminList = spAdminService.findByCustomerId(customerId);
  337. Date now = new Date();
  338. item.setPickCustomerId(customerId).setPick(1)
  339. .setPickCustomerName(tbCostomer.getName()).setPickTime(now)
  340. .setConfirm(1).setConfirmTime(now);
  341. tbBusinessItemService.updateById(item);
  342. spAdminList.stream().map(SpAdmin::getOpenid).forEach(openId -> {
  343. String detailUrl = myConfig.getWebDomain() + "/pages/business-item/item-detail?itemId=" + item.getId() + "&openid=" + openId;
  344. wxService.sendTemplateMsg(wxConfig.getBusinessConfirmTemplate(), openId, msgDataBO, detailUrl);
  345. });
  346. } else {
  347. String remark = "车牌:";
  348. String carNo = business.getCardNo();
  349. String chinaCarNo = business.getChinaCarNo();
  350. if (StrUtil.isNotEmpty(carNo) && StrUtil.isNotEmpty(chinaCarNo)) {
  351. remark += carNo + "、" + chinaCarNo;
  352. }
  353. if (StrUtil.isEmpty(carNo) && StrUtil.isNotEmpty(chinaCarNo)) {
  354. remark += chinaCarNo;
  355. }
  356. if (StrUtil.isNotEmpty(carNo) && StrUtil.isEmpty(chinaCarNo)) {
  357. remark += carNo;
  358. }
  359. MsgDataBO msgDataBO = new MsgDataBO("订单号:" + item.getNo(), item.getItemTypeName(),
  360. item.getItemName(), business.getGoodsName(), DateUtil.now(), remark);
  361. List<String> openidList = tbCostomerService.findByBusinessTypeOpenid(businessType, bigBusinessType);
  362. openidList.forEach(openid -> {
  363. String detailUrl = myConfig.getWebDomain() + "/pages/business-item/item-detail?itemId=" + item.getId() + "&openid=" + openid;
  364. wxService.sendTemplateMsg(wxConfig.getBusinessNoticeTemplate(), openid, msgDataBO, detailUrl);
  365. });
  366. }
  367. }
  368. });
  369. });
  370. }
  371. public void adminConfirmPay(List<String> ids, String ticket) {
  372. ids.forEach(id -> {
  373. TbBusiness business = this.getById(id);
  374. business.setAdminConfirmPayTime(new Date()).setAdminConfirmPay(1).setAdminConfirmPayBy(StpUserUtil.getAdmin().getName())
  375. .setPayStatus(3).setPayTicket(ticket);
  376. this.updateById(business);
  377. storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】已确认支付" + DateUtil.now() + "。");
  378. //发送消息
  379. String text = "您的费用已支付,业务单号[" + business.getNo() + "]";
  380. tbNoticesService.sendNotice(business.getId(), business.getNo(), business.getCustomerId(), text);
  381. });
  382. }
  383. @Deprecated
  384. public void adminConfirmIn(String id, String inChannel) {
  385. TbBusiness tbBusiness = this.getById(id);
  386. tbBusiness.setRealInTime(new Date()).setInChannel(inChannel);
  387. this.updateById(tbBusiness);
  388. //更新境外车入场记录
  389. //更新中国车入场记录
  390. //发送消息
  391. String text = "您的车辆已入场,业务单号[" + tbBusiness.getNo() + "]";
  392. tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text);
  393. }
  394. public void adminOut(String id, Date outDayTime, String outChannel, String carType) {
  395. TbBusiness tbBusiness = this.getById(id);
  396. tbBusiness.setOutDayTime(outDayTime).setOutChannel(outChannel);
  397. calculationPartMoney(carType, tbBusiness);
  398. this.updateById(tbBusiness);
  399. //更新境外车出场记录
  400. //更新中国车出场记录
  401. //发送消息
  402. String text = "您的车辆已离场,业务单号[" + tbBusiness.getNo() + "]";
  403. tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text);
  404. }
  405. @Async
  406. @Deprecated
  407. public void calculationPartMoney(String itemType, TbBusiness tbBusiness) {
  408. Date iTime = tbBusiness.getRealInTime();
  409. Date oTime = tbBusiness.getOutDayTime();
  410. if (itemType.contains("中国")) {
  411. iTime = tbBusiness.getChinaCarInTime();
  412. oTime = tbBusiness.getChinaCarOutTime();
  413. }
  414. BigDecimal price = calculationPartMoney(iTime, oTime);
  415. if (itemType.contains("中国")) {
  416. int len = tbBusiness.getCardNo().split(" ").length;
  417. tbBusiness.setChinaPartMoney(price.multiply(new BigDecimal(len)));
  418. } else {
  419. tbBusiness.setPartMoney(price);
  420. }
  421. tbBusiness.setTotalMoney(tbBusiness.getItemPrice().add(tbBusiness.getChinaPartMoney()).add(tbBusiness.getPartMoney()));
  422. }
  423. public BigDecimal calculationPartMoney(Date iTime, Date oTime) {
  424. BigDecimal zero = new BigDecimal("0");
  425. if (iTime == null || oTime == null) {
  426. return zero;
  427. }
  428. LocalDateTime inDayTime = iTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
  429. LocalDateTime outDayTime = oTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
  430. long minutes = ChronoUnit.MINUTES.between(inDayTime, outDayTime);
  431. if (minutes < 0) {
  432. return zero;
  433. }
  434. long days = ChronoUnit.DAYS.between(inDayTime.toLocalDate(), outDayTime.toLocalDate());
  435. BigDecimal p = partConfig.getBasePrice();//乘积因子
  436. BigDecimal extraPrice = partConfig.getExtraPrice();
  437. int unit = (int) Math.ceil(NumberUtil.div(minutes, 24 * 60));
  438. if (minutes < partConfig.getFreeMinutes()) {
  439. unit = 0;
  440. }
  441. return p.multiply(new BigDecimal(unit)).add(new BigDecimal(days).multiply(extraPrice));
  442. }
  443. public Map<String, Object> getBusinessMoney(String businessCarId, String state) {
  444. Map<String, Object> result = new HashMap<>();
  445. List<TbBusiness> businessList = this.findOtherBusinessByCarId(businessCarId);
  446. List<TbBusinessCar> cars = new ArrayList<>();
  447. //越南车是否需要支付
  448. int vietnamCarPay = businessList.stream().anyMatch(tbBusiness -> {
  449. TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
  450. return tbGoods.getVietnamCarPay() == 1;
  451. }) ? 1 : 0;
  452. //中国车是否需要支付
  453. int chinaCarPay = businessList.stream().anyMatch(tbBusiness -> {
  454. TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
  455. return tbGoods.getChinaCarPay() == 1;
  456. }) ? 1 : 0;
  457. //无业务的车辆,中国车和越南车都需要支付
  458. if (businessList.isEmpty()) {
  459. vietnamCarPay = 1;
  460. chinaCarPay = 1;
  461. cars.add(tbBusinessCarService.getById(businessCarId));
  462. }
  463. businessList = businessList.stream().filter(tbBusiness -> {
  464. Integer payStep = tbBusiness.getPayStep();
  465. //确认订单后方可缴费
  466. return TbGoods.PayStep.AFTER_CONFIRM.getCode().equals(payStep) && tbBusiness.getAdminConfirmInput() == 1
  467. //或者下单后可缴费
  468. || TbGoods.PayStep.BEFORE_CONFIRM.getCode().equals(payStep);
  469. }).collect(Collectors.toList());
  470. businessList.forEach(tbBusiness -> {
  471. List<TbBusinessCar> businessCars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
  472. cars.addAll(businessCars);
  473. });
  474. List<String> businessIdList = businessList.stream().map(TbBusiness::getId).collect(Collectors.toList());
  475. String businessIds = StrUtil.join(",", businessIdList);
  476. // result.put("type", businessType);
  477. result.put("showPay", true);
  478. result.put("businessId", businessIds);
  479. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessIdList(businessIdList);
  480. Date now = new Date();
  481. List<Map<String, Object>> carsList = new ArrayList<>();
  482. for (TbBusinessCar tbBusinessCar : cars) {
  483. Date inTime = tbBusinessCar.getRealInTime();
  484. BigDecimal partMoney = new BigDecimal("0");
  485. String carNo = tbBusinessCar.getCarNo().substring(0, 1);
  486. if (inTime != null && tbBusinessCar.getRealOutTime() == null) {
  487. if (tbBusinessCar.getPay() == 1 && tbBusinessCar.getPayTime() != null) {
  488. inTime = tbBusinessCar.getPayTime();
  489. }
  490. partMoney = this.calculationPartMoney(inTime, now);
  491. }
  492. if (StrUtil.isNotEmpty(tbBusinessCar.getColor())) {//蓝色车辆免费
  493. List<TbCarNoColor> freeList = tbCarNoColorService.getFreeColor();
  494. List<String> colorList = freeList.stream().map(f -> f.getCarNoColor().substring(0, 1)).collect(Collectors.toList());
  495. String color = tbBusinessCar.getColor().substring(0, 1);
  496. if (colorList.contains(color)) {
  497. partMoney = new BigDecimal("0");
  498. }
  499. }
  500. //越南车牌,是否免费
  501. if (!CAR_LIST.contains(carNo) && vietnamCarPay == 0) {
  502. partMoney = new BigDecimal("0");
  503. }
  504. //中国车,是否免费
  505. if (CAR_LIST.contains(carNo) && chinaCarPay == 0) {
  506. partMoney = new BigDecimal("0");
  507. }
  508. Map<String, Object> carMap = new HashMap<>();
  509. carMap.put("price", partMoney);
  510. carMap.put("id", tbBusinessCar.getId());
  511. carMap.put("carNo", tbBusinessCar.getCarNo());
  512. carMap.put("pay", tbBusinessCar.getPay());
  513. if (TbBusinessCar.PayTypeEnum.FEE_TYPE.getType().equals(tbBusinessCar.getPayType())) {
  514. carMap.put("price", 0);
  515. }
  516. carsList.add(carMap);
  517. }
  518. result.put("carList", carsList);
  519. BigDecimal itemsPrice = new BigDecimal("0");
  520. List<Map<String, Object>> itemList = new ArrayList<>();
  521. for (TbBusinessItem item : items) {
  522. BigDecimal itemPrice = item.getItemPrice().multiply(new BigDecimal(item.getNum()));
  523. itemsPrice = itemsPrice.add(itemPrice);
  524. Map<String, Object> itemMap = new HashMap<>();
  525. itemMap.put("id", item.getId());
  526. itemMap.put("name", item.getItemName() + "(" + item.getItemTypeName() + ")");
  527. itemMap.put("price", itemPrice);
  528. itemMap.put("pay", item.getPayStatus());
  529. itemList.add(itemMap);
  530. TbBusinessSort tbBusinessSort = tbBusinessSortService.findByItemTypeId(item.getItemTypeId());
  531. if (tbBusinessSort != null) {
  532. TbSortGroup sortGroup = tbSortGroupService.getById(tbBusinessSort.getGroupId());
  533. if (sortGroup.getCompletePay().equals(1) && sortGroup.getStatus().equals(1)) {
  534. List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sortGroup.getId());
  535. if (sorts.size() > items.size()) {
  536. result.put("showPay", false);
  537. }
  538. }
  539. }
  540. }
  541. result.put("itemsPrice", itemsPrice);
  542. result.put("itemList", itemList);
  543. return result;
  544. }
  545. public List<TbBusiness> findOtherBusinessByCarId(String businessCarId) {
  546. return tbBusinessMapper.findOtherBusinessByCarId(businessCarId);
  547. }
  548. public void uploadReport(TbBusiness tbBusiness) {
  549. this.updateById(tbBusiness);
  550. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
  551. tbBusinessCarService.updateBatchById(cars);
  552. }
  553. public List<CarDisincle> getCarDisincleList(SoMap soMap) {
  554. return tbBusinessMapper.getCarDisincleList(soMap);
  555. }
  556. public TbBusiness getOtherBusinessById(String id) {
  557. TbBusiness tbBusiness = this.getById(id);
  558. List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findByBusinessId(id);
  559. tbBusiness.setItems(tbBusinessItems);
  560. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(id);
  561. tbBusiness.setCars(cars);
  562. return tbBusiness;
  563. }
  564. public void deleteOtherBusiness(String id) {
  565. TbBusiness db = super.getById(id);
  566. String declareNo = db.getDeclareNo();
  567. if (StrUtil.isNotEmpty(declareNo)) {
  568. tbDeclareService.rebackDeclareNo(declareNo);
  569. }
  570. this.removeById(id);
  571. //删除响应业务项
  572. tbBusinessItemService.removeByBusinessId(id);
  573. //检查是否删除车辆
  574. List<TbBusinessCar> tbBusinessCarList = tbBusinessCarService.findOtherBusinessCar(id);
  575. tbBusinessCarList.forEach(tbBusinessCar -> {
  576. //未入场
  577. if (tbBusinessCar.getRealInTime() == null) {
  578. List<RelationBusinessCar> relationBusinessCars = relationBusinessCarService.findByBusinessCarId(tbBusinessCar.getId());
  579. //无关联业务==>删除
  580. if (relationBusinessCars.size() == 1) {
  581. tbBusinessCarService.removeById(tbBusinessCar.getId());
  582. }
  583. }
  584. });
  585. //删除关系
  586. relationBusinessCarService.removeByBusinessId(id);
  587. }
  588. public int checkCarBusinessType(String typeId, String carNo, String operateTime, int before) {
  589. return tbBusinessMapper.checkCarBusinessType(typeId, carNo, operateTime, before);
  590. }
  591. public int checkCarBusinessType(String typeId, String carNo, String timeStart, String timeEnd, String businessId) {
  592. return tbBusinessMapper.checkCarBusinessTypeByTime(typeId, carNo, timeStart, timeEnd, businessId);
  593. }
  594. public void manualConfirmPay(String id, List<TbBusinessCar> cars, String remark) {
  595. TbBusiness db = this.getById(id);
  596. if (db == null) {
  597. throw new BusinessException("业务不存在");
  598. }
  599. Date now = new Date();
  600. db.setPayStatus(3).setPayMoney(db.getItemPrice()).setPayTime(now);
  601. this.updateById(db);
  602. cars.forEach(tbBusinessCar -> {
  603. Date realInTime = tbBusinessCar.getRealInTime();
  604. Date realOutTime = tbBusinessCar.getRealOutTime();
  605. if (realInTime != null && realOutTime != null) {
  606. BigDecimal price = calculationPartMoney(realInTime, realOutTime);
  607. tbBusinessCar.setMoney(price);
  608. }
  609. tbBusinessCar.setPay(1).setPayTime(now);
  610. tbBusinessCarService.updateById(tbBusinessCar);
  611. });
  612. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
  613. items.forEach(tbBusinessItem -> tbBusinessItem
  614. .setPayStatus(1).setPayTime(now)
  615. .setRemark(StrUtil.isEmpty(remark) ? "手动确认" : remark)
  616. );
  617. tbBusinessItemService.updateBatchById(items);
  618. }
  619. public void unBindCar(String id, String businessCarId) {
  620. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  621. ew.eq("id", id).eq("business_car_id", businessCarId);
  622. TbBusiness db = getOne(ew);
  623. if (db == null) {
  624. throw new BusinessException("业务单不存在");
  625. }
  626. tbBusinessMapper.unBindCar(id);
  627. }
  628. public void addOtherBusiness(OtherBusinessBO otherBusinessBO) {
  629. List<TbItem> tbItems = otherBusinessBO.getItems();
  630. if (tbItems.isEmpty()) {
  631. throw new BusinessException("请选择明细");
  632. }
  633. List<TbBusinessCar> cars = otherBusinessBO.getCars();
  634. if (cars.isEmpty()) {
  635. throw new BusinessException("作业车辆不能为空");
  636. }
  637. Date now = new Date();
  638. TbGoods tbGoods = tbGoodsService.getById(otherBusinessBO.getGoodsId());
  639. TbBusiness tbBusiness = new TbBusiness();
  640. String customerId = otherBusinessBO.getCustomerId();
  641. tbBusiness.setCreateBy(StpUserUtil.getAdmin().getName());
  642. tbBusiness.setPayStep(tbGoods.getPayStep());
  643. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  644. if (tbCostomer != null) {
  645. tbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
  646. }
  647. BigDecimal price = new BigDecimal("0");
  648. List<TbBusinessItem> itemList = new ArrayList<>();
  649. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
  650. int index = 1;
  651. for (TbItem tbItem : tbItems) {
  652. TbItem db = tbItemService.getById(tbItem.getId());
  653. TbBusinessItem item = new TbBusinessItem();
  654. int num = tbItem.getNum();
  655. String typeId = tbItem.getTypeId();
  656. TbItemType tbItemType = tbItemTypeService.getById(typeId);
  657. BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
  658. item.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
  659. .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2));
  660. item.setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId())
  661. .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
  662. .setItemTypeId(typeId).setItemTypeName(tbItemType.getName())
  663. .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
  664. price = price.add(itemTotalPrice);
  665. itemList.add(item);
  666. index++;
  667. }
  668. String declareNo = otherBusinessBO.getDeclareNo();
  669. tbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
  670. .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
  671. .setNo(no).setGoodsName(tbGoods.getName()).setGoodsId(otherBusinessBO.getGoodsId())
  672. .setPayStep(tbGoods.getPayStep()).setDeclareNo(declareNo).setCardNo(otherBusinessBO.getCardNo());
  673. tbBusiness.setCreateTime(now).setBusinessType(TbBusiness.BusinessType.CAR_DISINCLE.getCode())
  674. .setItemPrice(price).setTotalMoney(price);
  675. tbBusiness.setChinaCarNo(otherBusinessBO.getChinaCarNo());
  676. this.save(tbBusiness);
  677. Integer chinaCarPay = tbGoods.getChinaCarPay();
  678. Integer vietnamCarPay = tbGoods.getVietnamCarPay();
  679. String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
  680. for (TbBusinessCar car : cars) {
  681. String carNo = car.getCarNo().trim().toUpperCase();
  682. String carPrefix = StrUtil.sub(carNo, 0, 1);
  683. //最新一条记录
  684. TbBusinessCar db = tbBusinessCarService.findTheLastRecord(carNo);
  685. //不存在,或者已离场记录--->新建记录;
  686. if (db == null || db.getRealInTime() != null && db.getRealOutTime() != null) {
  687. db = new TbBusinessCar();
  688. db.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
  689. }
  690. for (TbBusinessItem item : itemList) {
  691. checkOtherBusiness(item.getItemTypeId(), otherBusinessBO.getOperateTime(), tbBusiness.getId(), carNo);
  692. }
  693. if ((CAR_LIST.contains(carPrefix) && chinaCarPay == 0) || (!CAR_LIST.contains(carPrefix) && vietnamCarPay == 0)) {
  694. db.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
  695. }
  696. TbCar tbCar = tbCarService.findByCardNo(carNo);
  697. if (tbCar!=null){
  698. db.setCarCompany(tbCar.getCustomerName());
  699. if (!TbCar.CarTypeEnum.BUSINESS_CAR.getType().equals(tbCar.getCarType())){
  700. db.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
  701. }
  702. }
  703. db.setCarNo(carNo).setIsLock(0);
  704. db.setCarSize(car.getCarSize())
  705. .setTimeUpdate(now).setCarType(car.getCarType())
  706. .setNetWeight(car.getNetWeight())
  707. .setCustomerId(customerId)
  708. .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  709. tbBusinessCarService.saveOrUpdate(db);
  710. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  711. relationBusinessCar.setBusinessId(tbBusiness.getId()).setBusinessCarId(db.getId());
  712. relationBusinessCarService.save(relationBusinessCar);
  713. }
  714. if (StrUtil.isNotEmpty(declareNo)) {
  715. TbDeclare declare = tbDeclareService.findByDeclareNo(declareNo);
  716. declare.setBusinessId(tbBusiness.getId());
  717. }
  718. itemList.forEach(tbBusinessItem -> tbBusinessItem.setBusinessId(tbBusiness.getId()));
  719. tbBusinessItemService.saveBatch(itemList);
  720. }
  721. public List<TbBusiness> getOtherBusiness(SoMap startPage) {
  722. return tbBusinessMapper.getOtherBusiness(startPage);
  723. }
  724. public void editOtherBusiness(OtherBusinessBO otherBusinessBO) {
  725. String id = otherBusinessBO.getId();
  726. TbBusiness dbBusiness = this.getById(id);
  727. if (dbBusiness == null) {
  728. throw new BusinessException("记录不存在");
  729. }
  730. List<TbItem> tbItems = otherBusinessBO.getItems();
  731. if (tbItems.isEmpty()) {
  732. throw new BusinessException("请选择明细");
  733. }
  734. List<TbBusinessCar> cars = otherBusinessBO.getCars();
  735. if (cars.isEmpty()) {
  736. throw new BusinessException("作业车辆不能为空");
  737. }
  738. tbBusinessItemService.removeByBusinessId(id);
  739. Date now = new Date();
  740. List<RelationBusinessCar> relationBusinessCars = relationBusinessCarService.findByBusinessId(id);
  741. List<String> businessCarIds = cars.stream().filter(tbBusinessCar -> StrUtil.isNotEmpty(tbBusinessCar.getId()))
  742. .map(TbBusinessCar::getId).collect(Collectors.toList());
  743. List<String> removeIds = relationBusinessCars.stream()
  744. .filter(relationBusinessCar -> !businessCarIds.contains(relationBusinessCar.getBusinessCarId()))
  745. .map(RelationBusinessCar::getId)
  746. .collect(Collectors.toList());
  747. if (!removeIds.isEmpty()) {
  748. relationBusinessCarService.removeByIds(removeIds);
  749. }
  750. TbGoods tbGoods = tbGoodsService.getById(otherBusinessBO.getGoodsId());
  751. Integer chinaCarPay = tbGoods.getChinaCarPay();
  752. Integer vietnamCarPay = tbGoods.getVietnamCarPay();
  753. String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
  754. BigDecimal price = new BigDecimal("0");
  755. List<TbBusinessItem> itemList = new ArrayList<>();
  756. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
  757. int index = 1;
  758. for (TbItem tbItem : tbItems) {
  759. TbItem db = tbItemService.getById(tbItem.getId());
  760. TbBusinessItem item = new TbBusinessItem();
  761. int num = tbItem.getNum();
  762. TbItemType tbItemType = tbItemTypeService.getById(tbItem.getTypeId());
  763. BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
  764. item.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
  765. .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2));
  766. item.setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId()).setBusinessId(dbBusiness.getId())
  767. .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
  768. .setItemTypeId(tbItem.getTypeId()).setItemTypeName(tbItemType.getName())
  769. .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
  770. price = price.add(itemTotalPrice);
  771. itemList.add(item);
  772. index++;
  773. }
  774. dbBusiness.setItemPrice(price).setTotalMoney(price);
  775. tbBusinessItemService.saveBatch(itemList);
  776. for (TbBusinessCar tbBusinessCar : cars) {
  777. String businessCarId = tbBusinessCar.getId();
  778. String carNo = tbBusinessCar.getCarNo();
  779. for (TbBusinessItem item : itemList) {
  780. checkOtherBusiness(item.getItemTypeId(), otherBusinessBO.getOperateTime(), dbBusiness.getId(), carNo);
  781. }
  782. String carPrefix = StrUtil.sub(carNo, 0, 1);
  783. if (StrUtil.isNotEmpty(businessCarId)) {
  784. TbBusinessCar dbBusinessCar = tbBusinessCarService.getById(businessCarId);
  785. dbBusinessCar.setNetWeight(tbBusinessCar.getNetWeight()).setCarType(tbBusinessCar.getCarType())
  786. .setCarSize(tbBusinessCar.getCarSize()).setCarNo(carNo);
  787. tbBusinessCarService.updateById(dbBusinessCar);
  788. } else {
  789. TbBusinessCar checkCar = tbBusinessCarService.findTheLastRecord(carNo);
  790. if (checkCar == null ||
  791. (checkCar.getRealInTime() != null && checkCar.getRealOutTime() != null)) {
  792. checkCar = new TbBusinessCar();
  793. checkCar.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
  794. }
  795. checkCar.setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
  796. .setNetWeight(tbBusinessCar.getNetWeight()).setCustomerId(dbBusiness.getCustomerId())
  797. .setTimeUpdate(now).setIsLock(0);
  798. if ((CAR_LIST.contains(carPrefix) && chinaCarPay == 1) || (!CAR_LIST.contains(carPrefix) && vietnamCarPay == 1)) {
  799. checkCar.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
  800. }
  801. tbBusinessCarService.saveOrUpdate(checkCar);
  802. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  803. relationBusinessCar.setBusinessId(dbBusiness.getId()).setBusinessCarId(checkCar.getId());
  804. relationBusinessCarService.save(relationBusinessCar);
  805. }
  806. }
  807. if (!StrUtil.equals(dbBusiness.getGoodsId(), otherBusinessBO.getGoodsId())) {
  808. dbBusiness.setGoodsId(otherBusinessBO.getGoodsId())
  809. .setGoodsName(tbGoods.getName()).setPayStep(tbGoods.getPayStep());
  810. }
  811. String declareNo = otherBusinessBO.getDeclareNo();
  812. if (!StrUtil.equals(declareNo, dbBusiness.getDeclareNo())) {
  813. tbDeclareService.rebackDeclareNo(dbBusiness.getDeclareNo());
  814. }
  815. dbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
  816. .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
  817. .setNo(no).setGoodsId(otherBusinessBO.getGoodsId())
  818. .setDeclareNo(declareNo).setCardNo(otherBusinessBO.getCardNo());
  819. dbBusiness.setBusinessType(TbBusiness.BusinessType.CAR_DISINCLE.getCode())
  820. .setItemPrice(price).setTotalMoney(price);
  821. dbBusiness.setChinaCarNo(otherBusinessBO.getChinaCarNo());
  822. this.updateById(dbBusiness);
  823. }
  824. public void bindOtherBusinessCar(String businessId, List<String> businessCarIdList) {
  825. TbBusiness tbBusiness = this.getById(businessId);
  826. relationBusinessCarService.removeByBusinessId(businessId);
  827. List<TbBusinessCar> carList = tbBusinessCarService.listByIds(businessCarIdList);
  828. String chinaCarNo = carList.stream().filter(tbBusinessCar -> {
  829. String carNo = tbBusinessCar.getCarNo();
  830. String carStr = StrUtil.sub(carNo, 0, 1);
  831. return CAR_LIST.contains(carStr);
  832. }).map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  833. String yueCarNo = carList.stream().filter(tbBusinessCar -> {
  834. String carNo = tbBusinessCar.getCarNo();
  835. String carStr = StrUtil.sub(carNo, 0, 1);
  836. return !CAR_LIST.contains(carStr);
  837. }).map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  838. tbBusiness.setChinaCarNo(chinaCarNo);
  839. tbBusiness.setCardNo(yueCarNo);
  840. this.updateById(tbBusiness);
  841. businessCarIdList.forEach(businessCarId -> {
  842. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  843. relationBusinessCar.setBusinessCarId(businessCarId).setBusinessId(businessId);
  844. relationBusinessCarService.save(relationBusinessCar);
  845. });
  846. }
  847. private void checkOtherBusiness(String itemTypeId, String operateTimeStr, String businessId, String carNo) {
  848. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  849. TbBusinessSort sort = tbBusinessSortService.findByItemTypeId(itemTypeId);
  850. List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sort.getGroupId());
  851. LocalDateTime operateTime = LocalDateTime.parse(operateTimeStr, formatter);
  852. int i = 0;
  853. for (TbBusinessSort tbBusinessSort : sorts) {
  854. if (i == 0 && StrUtil.equals(tbBusinessSort.getTypeId(), itemTypeId) && sorts.size() > 1) {
  855. TbBusinessSort afterItem = sorts.get(i + 1);
  856. String typeId = afterItem.getTypeId();
  857. Integer interval = afterItem.getIntervalTime();
  858. LocalDateTime endTime = operateTime.plusMinutes(interval);
  859. if (afterItem.getIntervalTime() > 0) {
  860. int count = this.checkCarBusinessType(typeId, carNo, endTime.format(formatter), 1);
  861. if (count > 0) {
  862. throw new BusinessException("车辆:[" + carNo + "]" + tbBusinessSort.getTypeName() + "后" + afterItem.getIntervalTime() + "分钟才可以执行" + afterItem.getTypeName());
  863. }
  864. }
  865. }
  866. if (i > 0 && StrUtil.equals(tbBusinessSort.getTypeId(), itemTypeId)) {
  867. TbBusinessSort beforeItem = sorts.get(i - 1);
  868. String typeId = beforeItem.getTypeId();
  869. Integer interval = tbBusinessSort.getIntervalTime();
  870. LocalDateTime endTime = operateTime.minusMinutes(interval);
  871. if (tbBusinessSort.getIntervalTime() > 0) {
  872. int count = this.checkCarBusinessType(typeId, carNo, endTime.format(formatter), 0);
  873. if (count > 0) {
  874. throw new BusinessException("车辆:[" + carNo + "]" + beforeItem.getTypeName() + "后" + tbBusinessSort.getIntervalTime() + "分钟才可以执行" + tbBusinessSort.getTypeName());
  875. }
  876. }
  877. }
  878. Integer singleIntervalTime = tbBusinessSort.getSingleIntervalTime();
  879. String timeStart = operateTime.minusHours(singleIntervalTime).format(formatter);
  880. String timeEnd = operateTime.plusHours(singleIntervalTime).format(formatter);
  881. int count = this.checkCarBusinessType(itemTypeId, carNo, timeStart, timeEnd, businessId);
  882. if (count > 0) {
  883. throw new BusinessException("车辆:[" + carNo + "]" + singleIntervalTime + "小时内已有相同作业");
  884. }
  885. i++;
  886. }
  887. }
  888. }