TbBusinessService.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. package com.pj.project.tb_business;
  2. import java.math.BigDecimal;
  3. import java.time.LocalDate;
  4. import java.time.LocalDateTime;
  5. import java.time.LocalTime;
  6. import java.time.ZoneId;
  7. import java.time.format.DateTimeFormatter;
  8. import java.time.temporal.ChronoUnit;
  9. import java.util.*;
  10. import java.util.stream.Collectors;
  11. import cn.hutool.core.bean.BeanUtil;
  12. import cn.hutool.core.date.DateUtil;
  13. import cn.hutool.core.util.NumberUtil;
  14. import cn.hutool.core.util.RandomUtil;
  15. import cn.hutool.core.util.StrUtil;
  16. import cn.hutool.json.JSONUtil;
  17. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  18. import com.baomidou.mybatisplus.extension.service.IService;
  19. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  20. import com.pj.api.wx.bo.MsgDataBO;
  21. import com.pj.api.wx.service.WxService;
  22. import com.pj.constants.UserTypeEnum;
  23. import com.pj.current.config.CarConfig;
  24. import com.pj.current.config.MyConfig;
  25. import com.pj.current.config.PartConfig;
  26. import com.pj.current.config.WxConfig;
  27. import com.pj.current.satoken.StpUserUtil;
  28. import com.pj.project.tb_business_car.TbBusinessCar;
  29. import com.pj.project.tb_business_car.TbBusinessCarService;
  30. import com.pj.project.tb_business_item.TbBusinessItem;
  31. import com.pj.project.tb_business_item.TbBusinessItemService;
  32. import com.pj.project.tb_business_people.TbBusinessPeople;
  33. import com.pj.project.tb_business_people.TbBusinessPeopleService;
  34. import com.pj.project.tb_car.TbCar;
  35. import com.pj.project.tb_car.TbCarService;
  36. import com.pj.project.tb_costomer.TbCostomer;
  37. import com.pj.project.tb_costomer.TbCostomerService;
  38. import com.pj.project.tb_declare.TbDeclare;
  39. import com.pj.project.tb_declare.TbDeclareService;
  40. import com.pj.project.tb_driver.TbDriver;
  41. import com.pj.project.tb_driver.TbDriverService;
  42. import com.pj.project.tb_goods.TbGoods;
  43. import com.pj.project.tb_goods.TbGoodsService;
  44. import com.pj.project.tb_item.TbItem;
  45. import com.pj.project.tb_item.TbItemService;
  46. import com.pj.project.tb_item_type.TbItemType;
  47. import com.pj.project.tb_item_type.TbItemTypeService;
  48. import com.pj.project.tb_notices.TbNoticesMapper;
  49. import com.pj.project.tb_notices.TbNoticesService;
  50. import com.pj.project.tb_pass_record.TbPassRecord;
  51. import com.pj.project.tb_pass_record.TbPassRecordService;
  52. import com.pj.project.tb_unit.TbUnit;
  53. import com.pj.project.tb_unit.TbUnitService;
  54. import com.pj.project4sp.admin.SpAdmin;
  55. import com.pj.project4sp.global.BusinessException;
  56. import com.pj.project4sp.role.SpRoleUtil;
  57. import com.pj.project4sp.role4permission.SpRolePermissionService;
  58. import com.pj.utils.so.SoMap;
  59. import org.aspectj.weaver.loadtime.Aj;
  60. import org.omg.CORBA.OBJ_ADAPTER;
  61. import org.springframework.beans.factory.annotation.Autowired;
  62. import org.springframework.beans.factory.annotation.Value;
  63. import org.springframework.context.annotation.Lazy;
  64. import org.springframework.scheduling.annotation.Async;
  65. import org.springframework.stereotype.Service;
  66. import com.pj.utils.sg.*;
  67. import org.springframework.transaction.annotation.Transactional;
  68. import javax.annotation.Resource;
  69. /**
  70. * Service: tb_business -- 入境登记
  71. *
  72. * @author qzy
  73. */
  74. @Service
  75. @Transactional
  76. public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness> implements IService<TbBusiness> {
  77. /**
  78. * 底层 Mapper 对象
  79. */
  80. @Autowired
  81. TbBusinessMapper tbBusinessMapper;
  82. @Resource
  83. private TbCarService tbCarService;
  84. @Resource
  85. private TbDriverService tbDriverService;
  86. @Resource
  87. private TbCostomerService tbCostomerService;
  88. @Resource
  89. private TbItemService tbItemService;
  90. @Resource
  91. private TbItemTypeService tbItemTypeService;
  92. @Resource
  93. private TbBusinessItemService tbBusinessItemService;
  94. @Resource
  95. TbUnitService tbUnitService;
  96. @Resource
  97. TbBusinessPeopleService tbBusinessPeopleService;
  98. @Resource
  99. private PartConfig partConfig;
  100. @Resource
  101. private CarConfig carConfig;
  102. @Resource
  103. private TbNoticesService tbNoticesService;
  104. @Resource
  105. TbBusinessCarService tbBusinessCarService;
  106. @Resource
  107. @Lazy
  108. TbDeclareService tbDeclareService;
  109. @Resource
  110. WxConfig wxConfig;
  111. @Resource
  112. @Lazy
  113. WxService wxService;
  114. @Resource
  115. MyConfig myConfig;
  116. public TbBusiness checkCarNo(String carNo) {
  117. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  118. ew.eq("card_no", carNo)
  119. .eq("admin_confirm_out", 0);
  120. return this.getOne(ew);
  121. }
  122. /**
  123. * 增
  124. */
  125. public AjaxJson addOrUpdate(TbBusiness t) {
  126. if (StrUtil.isNotEmpty(t.getId()) && StrUtil.isNotEmpty(t.getDeclareNo())) {
  127. TbBusiness db = this.getById(t.getId());
  128. if (!StrUtil.equals(db.getDeclareNo(), t.getDeclareNo())) {
  129. TbDeclare tbDeclare = tbDeclareService.findByDeclareNo(db.getDeclareNo());
  130. if (tbDeclare != null) {
  131. tbDeclare.setBusinessId("");
  132. tbDeclareService.updateById(tbDeclare);
  133. }
  134. }
  135. }
  136. Double carSize = t.getCardSize();
  137. if (carSize != null && carSize > carConfig.getMaxLength()) {
  138. return AjaxJson.getError("车辆规格不能大于" + carConfig.getMaxLength());
  139. }
  140. Double netWeight = t.getNetWeight();
  141. if (netWeight != null && netWeight > carConfig.getMaxWeight()) {
  142. return AjaxJson.getError("车辆载重不能大于" + carConfig.getMaxWeight());
  143. }
  144. t.setCreateBy(StpUserUtil.getAdmin().getName());
  145. createCarUnit(t);
  146. String customerId = t.getCustomerId();
  147. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  148. t.setCustomerName(tbCostomer.getName()).setCustomerType(tbCostomer.getPayType());
  149. if (StrUtil.equals(customerId, UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  150. t.setConfirmInputBy(StpUserUtil.getAdmin().getName())
  151. .setConfirmInput(1)
  152. .setConfirmInputTime(new Date());
  153. }
  154. if (StrUtil.isEmpty(t.getId())) {
  155. t.setCreateTime(new Date());
  156. t.setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  157. storeMsg(t.getCustomerId(), "新增一条业务数据:【" + t.getNo() + "】" + DateUtil.now() + "。");
  158. } else {
  159. storeMsg(t.getCustomerId(), "业务订单:【" + t.getNo() + "】数据发生更改," + DateUtil.now() + "。");
  160. }
  161. saveOrUpdate(t);
  162. createBusinessPeople(t);
  163. tbBusinessItemService.removeByBusinessId(t.getId());
  164. BigDecimal price = new BigDecimal(0);
  165. List<TbBusinessItem> items = JSONUtil.toList(t.getItemJson(), TbBusinessItem.class);
  166. int index = 1;
  167. for (TbBusinessItem item : items) {
  168. Double num = NumberUtil.parseDouble(item.getNum());
  169. TbItem tbItem = tbItemService.getById(item.getItemId());
  170. String typeId = tbItem.getTypeId();
  171. price = price.add(NumberUtil.mul(num, tbItem.getPrice()));
  172. TbItemType tbItemType = tbItemTypeService.getById(typeId);
  173. item.setBusinessId(t.getId()).setItemCode(tbItem.getItemCode())
  174. .setItemName(tbItem.getItemName()).setItemPrice(tbItem.getPrice())
  175. .setItemTypeId(typeId).setItemTypeName(tbItemType.getName()).setBusinessType(tbItemType.getBusinessType())
  176. .setUnit(tbItem.getUnit()).setTotal(NumberUtil.mul(num, tbItem.getPrice())).setCreateTime(new Date())
  177. .setNo(t.getNo() + "0" + index);
  178. tbBusinessItemService.save(item);
  179. String businessType = tbItemType.getBusinessType();
  180. if (!StrUtil.equals(businessType, TbCostomer.CustomerEnum.BUSINESS_TYPE.getType())) {
  181. String remark = "车牌:" + t.getCardNo();
  182. if (StrUtil.isNotEmpty(t.getChinaCarNo())) {
  183. remark += "、" + t.getChinaCarNo();
  184. }
  185. MsgDataBO msgDataBO = new MsgDataBO("订单号:"+item.getNo(), tbItemType.getName(), tbItem.getItemName(), t.getGoodsName(), DateUtil.now(), remark);
  186. StrUtil.splitTrim(businessType, ",").forEach(type -> {
  187. List<String> openidList = tbCostomerService.findByBusinessTypeOpenid(type);
  188. openidList.forEach(openid -> {
  189. String detailUrl = myConfig.getWebDomain() + "/pages/business-item/item-detail?itemId=" + item.getId() + "&openid=" + openid;
  190. wxService.sendTemplateMsg(wxConfig.getBusinessNoticeTemplate(), openid, msgDataBO, detailUrl);
  191. });
  192. });
  193. }
  194. index++;
  195. }
  196. List<TbBusinessCar> carList = JSONUtil.toList(t.getCarJson(), TbBusinessCar.class);
  197. String chinaCarNo = carList.stream().map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  198. t.setChinaCarNo(StrUtil.isNotEmpty(chinaCarNo) ? chinaCarNo.toUpperCase() : "");
  199. carList.forEach(tbBusinessCar -> {
  200. String carNo = tbBusinessCar.getCarNo().toUpperCase();
  201. TbBusinessCar db = tbBusinessCarService.findByBusinessIdAndCarNo(t.getId(), carNo);
  202. if (db != null) {
  203. tbBusinessCar.setId(db.getId());
  204. }
  205. TbBusinessCar car = tbBusinessCarService.findInAndNoBusinessCar(carNo);
  206. if (car != null) {
  207. tbBusinessCar.setId(car.getId()).setRealInTime(car.getRealInTime());
  208. }
  209. tbBusinessCar.setBusinessId(t.getId());
  210. tbBusinessCar.setCarNo(carNo);
  211. tbBusinessCar.setBusinessId(t.getId()).setCustomerId(t.getCustomerId());
  212. });
  213. String yueCarNo = t.getCardNo().toUpperCase();
  214. TbBusinessCar yueCar = tbBusinessCarService.findInAndNoBusinessCar(yueCarNo);
  215. if (yueCar == null) {
  216. yueCar = tbBusinessCarService.findByBusinessIdAndCarNo(t.getId(), yueCarNo);
  217. if (yueCar == null) {
  218. yueCar = new TbBusinessCar();
  219. }
  220. }
  221. yueCar.setBusinessId(t.getId()).setCarSize(t.getCardSize()).setCarNo(yueCarNo).setCustomerId(t.getCustomerId());
  222. carList.add(yueCar);
  223. tbBusinessCarService.saveOrUpdateBatch(carList);
  224. BigDecimal initCarPartMoney = partConfig.getBasePrice();
  225. t.setItemPrice(price)
  226. .setTotalMoney(price.add(initCarPartMoney.multiply(new BigDecimal(carList.size()))))
  227. .setChinaPartMoney(initCarPartMoney.multiply(new BigDecimal(carList.size() - 1)))
  228. .setPartMoney(initCarPartMoney);
  229. this.saveOrUpdate(t);
  230. if (StrUtil.isNotEmpty(t.getDeclareNo())) {
  231. TbDeclare tbDeclare = tbDeclareService.findByDeclareNo(t.getDeclareNo());
  232. tbDeclare.setBusinessId(t.getId());
  233. tbDeclareService.updateById(tbDeclare);
  234. }
  235. return AjaxJson.getSuccess();
  236. }
  237. public void storeMsg(String businessCustomerId, String content) {
  238. String currentCustomerId = StpUserUtil.getCustomerId();
  239. if (StrUtil.equals(currentCustomerId, UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  240. BusinessMessageManager.set(businessCustomerId, content);
  241. } else {
  242. BusinessMessageManager.set(UserTypeEnum.PLATFORM_ADMIN.getCustomerId(), content);
  243. }
  244. }
  245. private void createBusinessPeople(TbBusiness t) {
  246. tbBusinessPeopleService.removeByBusinessId(t.getId());
  247. List<TbBusinessPeople> peopleList = JSONUtil.toList(t.getPeopleJson(), TbBusinessPeople.class);
  248. peopleList.forEach(tbBusinessPeople -> tbBusinessPeople.setBusinessId(t.getId()).setCreateTime(new Date()));
  249. tbBusinessPeopleService.saveBatch(peopleList);
  250. }
  251. private void createCarUnit(TbBusiness t) {
  252. TbUnit tbUnit = tbUnitService.findByUnit(t.getCardSize());
  253. if (tbUnit == null) {
  254. tbUnit = new TbUnit();
  255. tbUnit.setUnit(t.getCardSize() + "");
  256. tbUnitService.save(tbUnit);
  257. }
  258. }
  259. private TbDriver createDriver(TbBusiness business) {
  260. TbDriver tbDriver = tbDriverService.findByIdCardNo(business.getCardNo());
  261. if (tbDriver == null) {
  262. tbDriver = new TbDriver();
  263. tbDriver.setCreateTime(new Date()).setIdCard(business.getCardNo())
  264. .setName(business.getDriverName()).setPhone(business.getDriverPhone());
  265. tbDriverService.save(tbDriver);
  266. }
  267. return tbDriver;
  268. }
  269. private TbCar createCar(TbBusiness business) {
  270. String cardNo = business.getCardNo();
  271. TbCar tbCar = tbCarService.findByCardNo(cardNo);
  272. if (tbCar == null) {
  273. tbCar = new TbCar();
  274. }
  275. tbCar.setCardNo(cardNo)
  276. .setCardSize(business.getCardSize())
  277. .setCountryName(business.getCountryName())
  278. .setLastGoodsName(business.getGoodsName())
  279. .setLastNetWeight(business.getNetWeight());
  280. tbCarService.saveOrUpdate(tbCar);
  281. return tbCar;
  282. }
  283. /**
  284. * 查集合 - 根据条件(参数为空时代表忽略指定条件)
  285. */
  286. public List<TbBusiness> getList(SoMap so) {
  287. return tbBusinessMapper.getList(so);
  288. }
  289. public void pay(String id, String payTicket) {
  290. TbBusiness tbBusiness = this.getById(id);
  291. SpAdmin admin = StpUserUtil.getAdmin();
  292. tbBusiness.setPayStatus(2).setPayBy(admin.getName())
  293. .setPayBy(StpUserUtil.getAdmin().getName())
  294. .setPayTicket(payTicket)
  295. .setPayTime(new Date());
  296. if (StrUtil.equals(admin.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  297. tbBusiness.setAdminConfirmPay(1).setPayStatus(3)
  298. .setAdminConfirmPayBy(admin.getName()).setAdminConfirmPayTime(new Date());
  299. }
  300. this.updateById(tbBusiness);
  301. storeMsg(tbBusiness.getCustomerId(), "业务订单【" + tbBusiness.getNo() + "】已支付" + DateUtil.now() + "。");
  302. //发送消息
  303. String text = "您的费用已支付,业务单号[" + tbBusiness.getNo() + "]";
  304. tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text);
  305. }
  306. public void confirm(List<String> ids) {
  307. ids.forEach(id -> {
  308. TbBusiness business = this.getById(id);
  309. business.setConfirmInput(1).setConfirmInputTime(new Date()).setConfirmInputBy(StpUserUtil.getAdmin().getName());
  310. this.updateById(business);
  311. storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】已确认" + DateUtil.now() + "。");
  312. });
  313. }
  314. public void adminConfirmPay(List<String> ids, String ticket) {
  315. ids.forEach(id -> {
  316. TbBusiness business = this.getById(id);
  317. business.setAdminConfirmPayTime(new Date()).setAdminConfirmPay(1).setAdminConfirmPayBy(StpUserUtil.getAdmin().getName())
  318. .setPayStatus(3).setPayTicket(ticket);
  319. this.updateById(business);
  320. storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】已确认支付" + DateUtil.now() + "。");
  321. //发送消息
  322. String text = "您的费用已支付,业务单号[" + business.getNo() + "]";
  323. tbNoticesService.sendNotice(business.getId(), business.getNo(), business.getCustomerId(), text);
  324. });
  325. }
  326. public TbBusiness findCarTheNewRecord(String carNo, int inOrOut) {
  327. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  328. ew.eq("card_no", carNo);
  329. if (inOrOut == 1) {
  330. ew.eq("admin_confirm_in", 0).isNull("in_channel");
  331. } else {
  332. ew.eq("admin_confirm_out", 0).isNull("out_channel").isNotNull("real_in_time");
  333. }
  334. return getOne(ew);
  335. }
  336. @Deprecated
  337. public void adminConfirmIn(String id, String inChannel) {
  338. TbBusiness tbBusiness = this.getById(id);
  339. tbBusiness.setRealInTime(new Date()).setInChannel(inChannel);
  340. this.updateById(tbBusiness);
  341. //更新境外车入场记录
  342. //更新中国车入场记录
  343. //发送消息
  344. String text = "您的车辆已入场,业务单号[" + tbBusiness.getNo() + "]";
  345. tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text);
  346. }
  347. public void adminOut(String id, Date outDayTime, String outChannel, String carType) {
  348. TbBusiness tbBusiness = this.getById(id);
  349. tbBusiness.setOutDayTime(outDayTime).setOutChannel(outChannel);
  350. calculationPartMoney(carType, tbBusiness);
  351. this.updateById(tbBusiness);
  352. //更新境外车出场记录
  353. //更新中国车出场记录
  354. //发送消息
  355. String text = "您的车辆已离场,业务单号[" + tbBusiness.getNo() + "]";
  356. tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text);
  357. }
  358. @Async
  359. public void calculationPartMoney(String itemType, TbBusiness tbBusiness) {
  360. Date iTime = tbBusiness.getRealInTime();
  361. Date oTime = tbBusiness.getOutDayTime();
  362. if (itemType.contains("中国")) {
  363. iTime = tbBusiness.getChinaCarInTime();
  364. oTime = tbBusiness.getChinaCarOutTime();
  365. }
  366. BigDecimal price = calculationPartMoney(iTime, oTime);
  367. if (itemType.contains("中国")) {
  368. int len = tbBusiness.getCardNo().split(" ").length;
  369. tbBusiness.setChinaPartMoney(price.multiply(new BigDecimal(len)));
  370. } else {
  371. tbBusiness.setPartMoney(price);
  372. }
  373. tbBusiness.setTotalMoney(tbBusiness.getItemPrice().add(tbBusiness.getChinaPartMoney()).add(tbBusiness.getPartMoney()));
  374. }
  375. public BigDecimal calculationPartMoney(Date iTime, Date oTime) {
  376. LocalDateTime inDayTime = iTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
  377. LocalDateTime outDayTime = oTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
  378. long minutes = ChronoUnit.MINUTES.between(inDayTime, outDayTime);
  379. BigDecimal zero = new BigDecimal("0");
  380. if (minutes < 0) {
  381. return zero;
  382. }
  383. long days = ChronoUnit.DAYS.between(inDayTime.toLocalDate(), outDayTime.toLocalDate());
  384. long hour = ChronoUnit.HOURS.between(inDayTime, outDayTime);
  385. BigDecimal basePrice = partConfig.getBasePrice();
  386. BigDecimal extraPrice = partConfig.getExtraPrice();
  387. return basePrice.add(basePrice.multiply(new BigDecimal(hour / 24))).add(new BigDecimal(days).multiply(extraPrice));
  388. }
  389. /**
  390. * @param carNo
  391. * @param inOrOut 1入 2出
  392. * @return
  393. */
  394. public TbBusiness findByChinaCarNo(String carNo, int inOrOut) {
  395. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  396. ew.like("china_car_no", carNo);
  397. if (inOrOut == 1) {
  398. ew.eq("admin_confirm_in", 0).isNull("china_car_in_channel");
  399. } else {
  400. ew.eq("admin_confirm_out", 0)
  401. .isNull("china_car_out_channel")
  402. .isNotNull("china_car_in_time");
  403. }
  404. return this.getOne(ew);
  405. }
  406. public TbBusiness finByNo(String no) {
  407. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  408. ew.eq("no", no);
  409. return getOne(ew);
  410. }
  411. public Map<String, Object> getBusinessMoney(String carId, String state) {
  412. Map<String, Object> result = new HashMap<>();
  413. TbBusinessCar car = tbBusinessCarService.getById(carId);
  414. String businessId = car.getBusinessId();
  415. result.put("businessId", businessId);
  416. List<TbBusinessCar> cars = tbBusinessCarService.findByBusinessId(businessId);
  417. Date now = new Date();
  418. List<Map<String, Object>> carsList = new ArrayList<>();
  419. for (TbBusinessCar tbBusinessCar : cars) {
  420. double partMoney = tbBusinessCar.getBasePartMoney().doubleValue();
  421. if (!StrUtil.equals("STATE", state)) {
  422. Date inTime = tbBusinessCar.getRealInTime();
  423. if (inTime != null) {
  424. BigDecimal price = this.calculationPartMoney(inTime, now);
  425. BigDecimal money = tbBusinessCar.getMoney();
  426. BigDecimal basePrice = tbBusinessCar.getBasePartMoney();
  427. partMoney = money == null ? price.subtract(basePrice).doubleValue() : price.subtract(money).doubleValue();
  428. } else {
  429. partMoney = 0D;
  430. }
  431. }
  432. Map<String, Object> carMap = new HashMap<>();
  433. carMap.put("price", partMoney);
  434. carMap.put("id", tbBusinessCar.getId());
  435. carMap.put("carNo", tbBusinessCar.getCarNo());
  436. carMap.put("pay", tbBusinessCar.getPay());
  437. carsList.add(carMap);
  438. }
  439. result.put("carList", carsList);
  440. TbBusiness tbBusiness = this.getById(businessId);
  441. if (tbBusiness != null && tbBusiness.getPayStatus() != TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode()) {
  442. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(businessId);
  443. result.put("itemsPrice", tbBusiness.getItemPrice());
  444. result.put("businessId", businessId);
  445. List<Map<String, Object>> itemList = new ArrayList<>();
  446. for (TbBusinessItem item : items) {
  447. Map<String, Object> itemMap = new HashMap<>();
  448. itemMap.put("id", item.getId());
  449. itemMap.put("name", item.getItemName());
  450. itemMap.put("price", item.getItemPrice());
  451. itemMap.put("pay", item.getPayStatus());
  452. itemList.add(itemMap);
  453. }
  454. result.put("itemList", itemList);
  455. }
  456. return result;
  457. }
  458. public void uploadReport(TbBusiness tbBusiness) {
  459. this.updateById(tbBusiness);
  460. List<TbBusinessCar> cars = tbBusinessCarService.findByBusinessId(tbBusiness.getId());
  461. cars.forEach(tbBusinessCar -> tbBusinessCar.setIsLock(0));
  462. tbBusinessCarService.updateBatchById(cars);
  463. }
  464. }