TbBusinessService.java 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822
  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.DateUnit;
  10. import cn.hutool.core.date.DateUtil;
  11. import cn.hutool.core.util.NumberUtil;
  12. import cn.hutool.core.util.RandomUtil;
  13. import cn.hutool.core.util.StrUtil;
  14. import cn.hutool.http.HttpUtil;
  15. import cn.hutool.json.JSONObject;
  16. import cn.hutool.json.JSONUtil;
  17. import cn.hutool.log.StaticLog;
  18. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  19. import com.baomidou.mybatisplus.extension.service.IService;
  20. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  21. import com.pj.api.open.bo.ItemPriceBO;
  22. import com.pj.api.pushfee.oa.CallbackBO;
  23. import com.pj.api.wx.bo.ManagerBO;
  24. import com.pj.api.wx.bo.MsgDataBO;
  25. import com.pj.api.wx.bo.PriceBO;
  26. import com.pj.api.wx.service.WxService;
  27. import com.pj.constants.UserTypeEnum;
  28. import com.pj.constants.business.*;
  29. import com.pj.current.config.*;
  30. import com.pj.current.satoken.StpUserUtil;
  31. import com.pj.project.oa.bo.OAResultBO;
  32. import com.pj.project.oa.bo.ParamsBO;
  33. import com.pj.project.relation_business_car.RelationBusinessCar;
  34. import com.pj.project.relation_business_car.RelationBusinessCarService;
  35. import com.pj.project.sync.SyncService;
  36. import com.pj.project.sync.request.IOrderPriceReq;
  37. import com.pj.project.sync.request.item.IFactorItem;
  38. import com.pj.project.sync.request.item.IOrderItem;
  39. import com.pj.project.sync.response.IOrderPriceRes;
  40. import com.pj.project.sync.response.item.IExpenseItem;
  41. import com.pj.project.sync.response.item.PriceDetailItem;
  42. import com.pj.project.tb_account.AutomaticPay;
  43. import com.pj.project.tb_account.TbAccount;
  44. import com.pj.project.tb_account.TbAccountService;
  45. import com.pj.project.tb_business_car.TbBusinessCar;
  46. import com.pj.project.tb_business_car.TbBusinessCarService;
  47. import com.pj.project.tb_business_item.TbBusinessItem;
  48. import com.pj.project.tb_business_item.TbBusinessItemService;
  49. import com.pj.project.tb_business_people.TbBusinessPeople;
  50. import com.pj.project.tb_business_people.TbBusinessPeopleService;
  51. import com.pj.project.tb_business_sort.TbBusinessSort;
  52. import com.pj.project.tb_business_sort.TbBusinessSortService;
  53. import com.pj.project.tb_car.TbCar;
  54. import com.pj.project.tb_car.TbCarService;
  55. import com.pj.project.tb_costomer.TbCostomer;
  56. import com.pj.project.tb_costomer.TbCostomerService;
  57. import com.pj.project.tb_declare.TbDeclare;
  58. import com.pj.project.tb_declare.TbDeclareService;
  59. import com.pj.project.tb_deduction_bind.TbDeductionBind;
  60. import com.pj.project.tb_deduction_bind.TbDeductionBindService;
  61. import com.pj.project.tb_deduction_record.TbDeductionRecord;
  62. import com.pj.project.tb_driver.TbDriver;
  63. import com.pj.project.tb_driver.TbDriverService;
  64. import com.pj.project.tb_fee_details.TbFeeDetails;
  65. import com.pj.project.tb_fee_details.TbFeeDetailsService;
  66. import com.pj.project.tb_fee_statistics.TbFeeStatisticsService;
  67. import com.pj.project.tb_goods.TbGoods;
  68. import com.pj.project.tb_goods.TbGoodsService;
  69. import com.pj.project.tb_invoice_order.TbInvoiceOrder;
  70. import com.pj.project.tb_invoice_order.TbInvoiceOrderService;
  71. import com.pj.project.tb_item.TbItem;
  72. import com.pj.project.tb_item.TbItemService;
  73. import com.pj.project.tb_item_fac.TbItemFac;
  74. import com.pj.project.tb_item_fac.TbItemFacService;
  75. import com.pj.project.tb_item_type.TbItemType;
  76. import com.pj.project.tb_item_type.TbItemTypeService;
  77. import com.pj.project.tb_mild_car.TbMildCar;
  78. import com.pj.project.tb_mild_car.TbMildCarService;
  79. import com.pj.project.tb_notices.TbNoticesService;
  80. import com.pj.project.tb_sort_group.TbSortGroup;
  81. import com.pj.project.tb_sort_group.TbSortGroupService;
  82. import com.pj.project.tb_unit.TbUnit;
  83. import com.pj.project.tb_unit.TbUnitService;
  84. import com.pj.project4sp.admin.SpAdmin;
  85. import com.pj.project4sp.admin.SpAdminService;
  86. import com.pj.project4sp.global.BusinessException;
  87. import com.pj.utils.AesUtil;
  88. import com.pj.utils.cache.RedisUtil;
  89. import com.pj.utils.sg.AjaxJson;
  90. import com.pj.utils.so.SoMap;
  91. import lombok.extern.slf4j.Slf4j;
  92. import org.aspectj.weaver.loadtime.Aj;
  93. import org.springframework.beans.factory.annotation.Autowired;
  94. import org.springframework.context.annotation.Lazy;
  95. import org.springframework.stereotype.Service;
  96. import com.pj.utils.sg.*;
  97. import org.springframework.transaction.annotation.Transactional;
  98. import javax.annotation.Resource;
  99. /**
  100. * Service: tb_business -- 入境登记
  101. *
  102. * @author qzy
  103. */
  104. @Service
  105. @Transactional(rollbackFor = Exception.class)
  106. @Slf4j
  107. public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness> implements IService<TbBusiness> {
  108. /**
  109. * 底层 Mapper 对象
  110. */
  111. @Autowired
  112. TbBusinessMapper tbBusinessMapper;
  113. @Resource
  114. private TbCarService tbCarService;
  115. @Resource
  116. private TbDriverService tbDriverService;
  117. @Resource
  118. private TbCostomerService tbCostomerService;
  119. @Resource
  120. private TbItemService tbItemService;
  121. @Resource
  122. private TbItemTypeService tbItemTypeService;
  123. @Resource
  124. private TbBusinessItemService tbBusinessItemService;
  125. @Resource
  126. private PartConfig partConfig;
  127. @Resource
  128. private TbNoticesService tbNoticesService;
  129. @Resource
  130. private TbAccountService tbAccountService;
  131. @Resource
  132. TbBusinessCarService tbBusinessCarService;
  133. @Resource
  134. @Lazy
  135. TbDeclareService tbDeclareService;
  136. @Resource
  137. WxConfig wxConfig;
  138. @Resource
  139. @Lazy
  140. WxService wxService;
  141. @Resource
  142. MyConfig myConfig;
  143. @Resource
  144. private SpAdminService spAdminService;
  145. @Resource
  146. private TbBusinessSortService tbBusinessSortService;
  147. @Resource
  148. private TbSortGroupService tbSortGroupService;
  149. @Resource
  150. private TbGoodsService tbGoodsService;
  151. @Resource
  152. private RelationBusinessCarService relationBusinessCarService;
  153. @Autowired
  154. @Lazy
  155. private AutomaticPay automaticPay;
  156. @Resource
  157. private OAConfig oaConfig;
  158. @Resource
  159. private PushfeeConfig pushfeeConfig;
  160. @Resource
  161. private TbFeeDetailsService tbFeeDetailsService;
  162. @Resource
  163. private TbInvoiceOrderService tbInvoiceOrderService;
  164. @Resource
  165. @Lazy
  166. private TbFeeStatisticsService tbFeeStatisticsService;
  167. @Resource
  168. private SyncService syncService;
  169. @Resource
  170. private TbItemFacService tbItemFacService;
  171. @Resource
  172. private TbMildCarService tbMildCarService;
  173. private final List<String> CAR_LIST = StrUtil.splitTrim("浙,粤,京,津,冀,晋,蒙,辽,黑,沪,吉,苏,皖,赣,鲁,豫,鄂,湘,桂,琼,渝,川,贵,云,藏, 陕, 甘, 青, 宁", ",");
  174. public void storeMsg(String businessCustomerId, String content) {
  175. String currentCustomerId = StpUserUtil.getCustomerId();
  176. if (StrUtil.equals(currentCustomerId, UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  177. BusinessMessageManager.set(businessCustomerId, content);
  178. } else {
  179. BusinessMessageManager.set(UserTypeEnum.PLATFORM_ADMIN.getCustomerId(), content);
  180. }
  181. }
  182. /**
  183. * 查集合 - 根据条件(参数为空时代表忽略指定条件)
  184. */
  185. public List<TbBusiness> getList(SoMap so) {
  186. return tbBusinessMapper.getList(so);
  187. }
  188. public void pay(String id, String payTicket) {
  189. TbBusiness tbBusiness = this.getById(id);
  190. SpAdmin admin = StpUserUtil.getAdmin();
  191. tbBusiness.setPayStatus(2).setPayBy(admin.getName())
  192. .setPayBy(StpUserUtil.getAdmin().getName())
  193. .setPayTicket(payTicket)
  194. .setPayTime(new Date());
  195. if (StrUtil.equals(admin.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  196. tbBusiness.setAdminConfirmPay(1).setPayStatus(3)
  197. .setAdminConfirmPayBy(admin.getName()).setAdminConfirmPayTime(new Date());
  198. }
  199. this.updateById(tbBusiness);
  200. storeMsg(tbBusiness.getCustomerId(), "业务订单【" + tbBusiness.getNo() + "】已支付" + DateUtil.now() + "。");
  201. //发送消息
  202. String text = "您的费用已支付,业务单号[" + tbBusiness.getNo() + "]";
  203. tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text);
  204. }
  205. public void confirm(List<String> ids) {
  206. ids.forEach(id -> {
  207. TbBusiness business = this.getById(id);
  208. SpAdmin currAdmin = StpUserUtil.getAdmin();
  209. String adminName = StrUtil.isNotEmpty(currAdmin.getNickname()) ? currAdmin.getNickname() : currAdmin.getName();
  210. business.setConfirmInput(1).setAdminConfirmInput(1)
  211. .setConfirmInputTime(new Date())
  212. .setConfirmInputBy(StpUserUtil.getAdmin().getName())
  213. .setConfirmBy(adminName).setConfirmByAdminId(currAdmin.getId() + "");
  214. this.updateById(business);
  215. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(business.getId());
  216. String carNoStr = cars.stream().map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  217. storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】已确认" + DateUtil.now() + "。");
  218. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
  219. String messageType = business.getGoodsId();
  220. items.forEach(item -> {
  221. String businessType = item.getBusinessType();
  222. //合作伙伴创建+是否下单后付款
  223. if (!StrUtil.equals(businessType, TbCostomer.CustomerEnum.BUSINESS_TYPE.getType())) {
  224. String customerId = business.getCreateByCustomerId();
  225. List<String> customerType = new ArrayList<>();
  226. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  227. if (tbCostomer != null) {
  228. customerType = StrUtil.splitTrim(tbCostomer.getType(), ",");
  229. }
  230. if (customerType.contains(businessType)) {
  231. StaticLog.error("订单自动确认=======================" + id);
  232. MsgDataBO msgDataBO = new MsgDataBO("订单号:" + item.getNo(), "系统自动确认",
  233. DateUtil.now(),
  234. business.getGoodsName() + "(" + item.getItemTypeName() + item.getItemName() + "-" + carNoStr + ")");
  235. List<SpAdmin> spAdminList = spAdminService.findByCustomerId(customerId);
  236. Date now = new Date();
  237. item.setPickCustomerId(customerId).setPick(1)
  238. .setPickCustomerName(tbCostomer.getName()).setPickTime(now)
  239. .setConfirm(1).setConfirmTime(now);
  240. List<TbFeeDetails> feeDetailsList = tbFeeDetailsService.getByBusinessItemId(item.getId() + "");//重复交费会存在多个businessItemId
  241. if (feeDetailsList != null) {
  242. for (TbFeeDetails feeDetails : feeDetailsList) {
  243. feeDetails.setPickCustomerName(item.getPickCustomerName());
  244. tbFeeDetailsService.updateById(feeDetails);
  245. }
  246. }
  247. tbBusinessItemService.updateById(item);
  248. List<String> customerMessageType = StrUtil.splitTrim(tbCostomer.getMessageType(), ",");
  249. if (customerMessageType.contains(messageType)) {
  250. spAdminList.stream().map(SpAdmin::getOpenid).forEach(openId -> {
  251. String detailUrl = myConfig.getWebDomain() + "/pages/business-item/item-detail?itemId=" + item.getId() + "&openid=" + openId;
  252. wxService.sendTemplateMsg(wxConfig.getBusinessConfirmTemplate(), openId, msgDataBO, detailUrl);
  253. });
  254. }
  255. } else {
  256. StaticLog.error("正常流程=======================" + id);
  257. String remark = "车牌:";
  258. String carNo = business.getCardNo();
  259. String chinaCarNo = business.getChinaCarNo();
  260. if (StrUtil.isNotEmpty(carNo) && StrUtil.isNotEmpty(chinaCarNo)) {
  261. remark += carNo + "、" + chinaCarNo;
  262. }
  263. if (StrUtil.isEmpty(carNo) && StrUtil.isNotEmpty(chinaCarNo)) {
  264. remark += chinaCarNo;
  265. }
  266. if (StrUtil.isNotEmpty(carNo) && StrUtil.isEmpty(chinaCarNo)) {
  267. remark += carNo;
  268. }
  269. MsgDataBO msgDataBO = new MsgDataBO("订单号:" + item.getNo(), item.getItemTypeName(),
  270. item.getItemName(), business.getGoodsName(), DateUtil.now(), remark);
  271. List<String> openidList = tbCostomerService.findByMessageTypeOpenid(businessType, messageType);
  272. openidList.stream().filter(StrUtil::isNotEmpty).forEach(openid -> {
  273. String detailUrl = myConfig.getWebDomain() + "/pages/business-item/item-detail?itemId=" + item.getId() + "&openid=" + openid;
  274. wxService.sendTemplateMsg(wxConfig.getBusinessNoticeTemplate(), openid, msgDataBO, detailUrl);
  275. });
  276. }
  277. }
  278. });
  279. TbGoods tbGoods = tbGoodsService.getById(business.getGoodsId());
  280. //只有改业务是在确认后扣费才需要执行自动扣费
  281. if (GoodsEnum.DeductionTypeEnum.BUSINESS_OK.getCode().equals(tbGoods.getAutoDeductionType())) {
  282. //automaticPay.run(business.getId(), null, 2);
  283. }
  284. });
  285. }
  286. public void adminConfirmPay(List<String> ids, String ticket) {
  287. ids.forEach(id -> {
  288. TbBusiness business = this.getById(id);
  289. business.setAdminConfirmPayTime(new Date()).setAdminConfirmPay(1).setAdminConfirmPayBy(StpUserUtil.getAdmin().getName())
  290. .setPayStatus(3).setPayTicket(ticket);
  291. this.updateById(business);
  292. storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】已确认支付" + DateUtil.now() + "。");
  293. //发送消息
  294. String text = "您的费用已支付,业务单号[" + business.getNo() + "]";
  295. tbNoticesService.sendNotice(business.getId(), business.getNo(), business.getCustomerId(), text);
  296. });
  297. }
  298. /**
  299. * 计费系统计算停车费
  300. *
  301. * @param iTime 入场时间
  302. * @param oTime 离场时间
  303. * @return
  304. */
  305. public IOrderPriceRes getPartMoney(Date iTime, Date oTime, String carNo, String carColor) {
  306. long minutes = DateUtil.between(iTime, oTime, DateUnit.MINUTE);
  307. double hours = NumberUtil.div(minutes, 60, 1);
  308. if (hours == 0) {
  309. hours = 0.1D;
  310. }
  311. List<IOrderItem> expenses = new ArrayList<>();
  312. TbMildCar tbMildCar = tbMildCarService.findByCarNo(carNo);
  313. IOrderPriceRes res = new IOrderPriceRes();
  314. double carSize = 8D;
  315. res.setCarDesc(PartFeeEnum.MIDDLER_CAR.getDesc());
  316. res.setHourDesc(PartFeeEnum.IN_24_HOURS.getDesc());
  317. if (tbMildCar == null) {
  318. // 9.6以上
  319. carSize = 12D;
  320. res.setCarDesc(PartFeeEnum.BIG_CAR.getDesc());
  321. }
  322. if (hours > 24) {
  323. res.setOver24Hour(1);
  324. res.setHourDesc(PartFeeEnum.OUT_24_HOURS.getDesc());
  325. }
  326. TbItem partItem = tbItemService.findByAliasName(SystemObject.config.getPartItemAlias());
  327. if (partItem == null) {
  328. throw new AjaxError("未配置停车费规则");
  329. }
  330. List<TbItemFac> list = tbItemFacService.getByItemId(partItem.getId());
  331. if (list.isEmpty()) {
  332. throw new AjaxError("未配置停车费规则");
  333. }
  334. TbItemFac itemFac = list.get(0);
  335. IOrderItem orderItem = new IOrderItem();
  336. String uniqueExpenseId = itemFac.getUniqueExpenseId();
  337. orderItem.setUniqExpenseId(uniqueExpenseId).setExpenseNum(1);
  338. List<IFactorItem> factors = new ArrayList<>();
  339. for (TbItemFac fac : list) {
  340. String operator = fac.getOperator();
  341. if (StrUtil.equals(operator, "carSize")) {
  342. IFactorItem iFactorItem = new IFactorItem();
  343. iFactorItem.setFacId(fac.getFacId() + "");
  344. iFactorItem.setFacParams(carSize + "");
  345. factors.add(iFactorItem);
  346. } else if (StrUtil.equals(operator, "hour")) {
  347. IFactorItem iFactorItem = new IFactorItem();
  348. iFactorItem.setFacId(fac.getFacId() + "");
  349. iFactorItem.setFacParams(hours + "");
  350. factors.add(iFactorItem);
  351. } else if (StrUtil.equals(operator, "carColor")) {
  352. IFactorItem iFactorItem = new IFactorItem();
  353. iFactorItem.setFacId(fac.getFacId() + "");
  354. iFactorItem.setFacParams(carColor);
  355. factors.add(iFactorItem);
  356. }
  357. }
  358. orderItem.setFactors(factors);
  359. expenses.add(orderItem);
  360. IOrderPriceRes orderPriceRes = syncService.orderPriceCal(expenses);
  361. res.setCalculateId(orderPriceRes.getCalculateId())
  362. .setUniqueExpenseId(uniqueExpenseId)
  363. .setFireResult(orderPriceRes.getFireResult())
  364. .setTotalOrderPrice(orderPriceRes.getTotalOrderPrice());
  365. log.info("part money resp:{}", JSONUtil.toJsonStr(res));
  366. return res;
  367. }
  368. /**
  369. * 微信端获取缴费信息
  370. *
  371. * @param businessCarId
  372. * @param channel
  373. * @return
  374. */
  375. public Map<String, Object> getBusinessMoney(String businessCarId, String channel) {
  376. Map<String, Object> result = new HashMap<>();
  377. //对应的业务
  378. List<TbBusiness> businessList = this.findOtherBusinessByCarId(businessCarId);
  379. //是否需要交停车费---->业务车都要交
  380. // boolean needPayPartMoney = !businessList.isEmpty();
  381. TbBusinessCar tbBusinessCar = tbBusinessCarService.getById(businessCarId);
  382. String carNo = tbBusinessCar.getCarNo();
  383. businessList = businessList.stream().filter(tbBusiness -> {
  384. TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
  385. Integer payStep = tbGoods.getPayStep();
  386. //确认订单后方可缴费
  387. return GoodsEnum.PayStep.AFTER_CONFIRM.getCode().equals(payStep) && tbBusiness.getAdminConfirmInput() == 1
  388. //或者下单后可缴费
  389. || GoodsEnum.PayStep.BEFORE_CONFIRM.getCode().equals(payStep) && tbBusiness.getAdminConfirmInput() >= 0;
  390. }).collect(Collectors.toList());
  391. List<String> businessIdList = businessList.stream().map(TbBusiness::getId).collect(Collectors.toList());
  392. String businessIds = StrUtil.join(",", businessIdList);
  393. long judgeCount = businessList.stream().filter(tbBusiness -> tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()).count();
  394. int size = businessList.size();
  395. result.put("showPay", true);
  396. result.put("businessId", businessIds);
  397. result.put("noJudgeCount", judgeCount == size ? 0 : 1);
  398. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessIdList(businessIdList);
  399. Date inTime = tbBusinessCar.getRealInTime();
  400. int pay = tbBusinessCar.getPay();
  401. Map<String, Object> carMap = new HashMap<>();
  402. carMap.put("price", 0);
  403. List<String> carCalculateIds = new ArrayList<>();
  404. //停车费
  405. if (inTime != null) {
  406. Date outTime = tbBusinessCar.getRealOutTime();
  407. String cacheCarNo = RedisUtil.get(channel);
  408. if (outTime == null && StrUtil.isNotEmpty(cacheCarNo) && StrUtil.equals(carNo.trim().toUpperCase(), cacheCarNo.trim().toUpperCase())) {
  409. outTime = new Date();
  410. }
  411. if (outTime != null) {
  412. //默认需要缴费--->
  413. BigDecimal partMoney = new BigDecimal("1");
  414. if (StrUtil.isNotEmpty(tbBusinessCar.getColor()) && tbBusinessCar.getCarSize() != null) {
  415. String freeColor = partConfig.getFreeColor();
  416. //4.2米以下蓝色车辆
  417. if (tbBusinessCar.getColor().contains(freeColor)) {
  418. partMoney = new BigDecimal("0");
  419. }
  420. }
  421. if (CarEnum.PayTypeEnum.FEE_TYPE.getType().equals(tbBusinessCar.getPayType())) {
  422. partMoney = new BigDecimal("0");
  423. }
  424. if (CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType().equals(tbBusinessCar.getPayType())) {
  425. inTime = tbBusinessCar.getPayTime();
  426. }
  427. if (partMoney.doubleValue() == 1) {
  428. IOrderPriceRes partPriceRes = getPartMoney(inTime, outTime, tbBusinessCar.getCarNo(), tbBusinessCar.getColor());
  429. BigDecimal partPrice = partPriceRes.getTotalOrderPrice();
  430. carCalculateIds.add(partPriceRes.getCalculateId());
  431. partMoney = partPrice;
  432. if (partPrice.doubleValue() > 0) {
  433. carMap.put("uniqExpenseId", partPriceRes.getFireResult().get(0).getUniqExpenseId());
  434. carMap.put("carDesc", partPriceRes.getCarDesc());
  435. carMap.put("calculateId;", partPriceRes.getCalculateId());
  436. carMap.put("hourDesc", partPriceRes.getHourDesc());
  437. carMap.put("over24Hour", partPriceRes.getOver24Hour());
  438. List<PriceDetailItem> detailItemList = partPriceRes.getFireResult().get(0)
  439. .getPriceDetail();
  440. detailItemList.forEach(obj -> carMap.put(obj.getKey(), obj.getValue()));
  441. }
  442. //todo 计算停车费
  443. }
  444. carMap.put("price", partMoney);
  445. }
  446. }
  447. carMap.put("id", tbBusinessCar.getId());
  448. carMap.put("carNo", tbBusinessCar.getCarNo());
  449. carMap.put("pay", pay);
  450. carMap.put("no", tbBusinessCar.getNo());
  451. result.put("carList", Collections.singleton(carMap));
  452. BigDecimal itemsPrice = new BigDecimal("0");
  453. List<Map<String, Object>> itemList = new ArrayList<>();
  454. if (!items.isEmpty()) {
  455. //未支付的
  456. List<IOrderItem> expenses = new ArrayList<>();
  457. items = items.stream().filter(item -> item.getPayStatus() == 0).collect(Collectors.toList());
  458. for (TbBusinessItem businessItem : items) {
  459. String num = businessItem.getNum();
  460. String itemCode = businessItem.getItemCode();
  461. IOrderItem iOrderItem = new IOrderItem();
  462. String itemAlias = businessItem.getItemAlias();
  463. Date startTime = businessItem.getColdStartTime();
  464. Date endTime = businessItem.getColdEndTime();
  465. iOrderItem.setExpenseNum(Integer.parseInt(num)).setUniqExpenseId(itemCode);
  466. if (StrUtil.equals(itemAlias, SystemObject.config.getColdItemAlias())) {
  467. tbBusinessItemService.buildColdFceItem(businessItem, iOrderItem, startTime, endTime);
  468. //充电打冷--->按小时计费
  469. } else if (StrUtil.equals(itemAlias, SystemObject.config.getHeavyStoreItemAlias())
  470. || StrUtil.equals(itemAlias, SystemObject.config.getEmptyStoreItemAlias())) {
  471. //空柜堆存、重箱堆存--->按天算
  472. //如果存柜的话则不收费
  473. if (businessItem.getCabinetType() == 0) {
  474. continue;
  475. }
  476. tbBusinessItemService.buildDaysFceItem(businessItem, iOrderItem, startTime, endTime);
  477. } else if (StrUtil.equals(itemAlias, SystemObject.config.getBigHeadCar())
  478. || StrUtil.equals(itemAlias, SystemObject.config.getCabinetCar())) {
  479. //大车头、柜车、栏车
  480. tbBusinessItemService.buildDaysFceItem(businessItem, iOrderItem, startTime, endTime);
  481. //不收停车费
  482. carMap.put("price", 0);
  483. }
  484. expenses.add(iOrderItem);
  485. }
  486. result.put("carList", Collections.singleton(carMap));
  487. if (!expenses.isEmpty()) {
  488. IOrderPriceRes orderPriceRes = syncService.orderPriceCal(expenses);
  489. BigDecimal totalPrice = orderPriceRes.getTotalOrderPrice();
  490. carCalculateIds.add(orderPriceRes.getCalculateId());
  491. for (TbBusinessItem item : items) {
  492. BigDecimal itemPrice = item.getItemPrice().multiply(new BigDecimal(item.getNum()));
  493. itemsPrice = itemsPrice.add(itemPrice);
  494. Map<String, Object> itemMap = new HashMap<>();
  495. itemMap.put("id", item.getId());
  496. itemMap.put("name", item.getItemName() + "(" + item.getItemTypeName() + ")");
  497. itemMap.put("price", itemPrice);
  498. itemMap.put("pay", item.getPayStatus());
  499. orderPriceRes.getFireResult().stream().filter(priceItem -> StrUtil.equals(item.getItemCode(), priceItem.getUniqExpenseId()))
  500. .findAny().ifPresent(priceItem -> {
  501. BigDecimal price = priceItem.getFirePrice().multiply(new BigDecimal(item.getNum()));
  502. //柜车、栏车只有离场才知道多少钱
  503. if (StrUtil.equals(item.getItemAlias(),SystemObject.config.getCabinetCar())){
  504. TbBusiness tbBusiness = this.getById(item.getBusinessId());
  505. tbBusiness.setItemPrice(price);
  506. item.setTotal(price);
  507. tbBusinessItemService.updateById(item);
  508. this.updateById(tbBusiness);
  509. }
  510. itemMap.put("price", price);
  511. });
  512. itemList.add(itemMap);
  513. TbBusinessSort tbBusinessSort = tbBusinessSortService.findByItemTypeId(item.getItemTypeId());
  514. if (tbBusinessSort != null) {
  515. TbSortGroup sortGroup = tbSortGroupService.getById(tbBusinessSort.getGroupId());
  516. if (sortGroup.getCompletePay().equals(1) && sortGroup.getStatus().equals(1)) {
  517. List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sortGroup.getId());
  518. for (TbBusinessSort sort : sorts) {
  519. long count = items.stream().filter(tbBusinessItem -> StrUtil.equals(sort.getTypeId(), tbBusinessItem.getItemTypeId()))
  520. .count();
  521. if (count == 0) {
  522. result.put("showPay", false);
  523. }
  524. }
  525. }
  526. }
  527. }
  528. result.put("itemsPrice", totalPrice);
  529. }
  530. }
  531. result.put("itemList", itemList);
  532. result.put("calculateId", String.join(",", carCalculateIds));
  533. result.put("businessNo", businessList.stream().map(TbBusiness::getNo).distinct().collect(Collectors.joining("、")));
  534. result.put("goodsName", businessList.stream().map(TbBusiness::getGoodsName).distinct().collect(Collectors.joining("、")));
  535. return result;
  536. }
  537. public List<TbBusiness> findOtherBusinessByCarId(String businessCarId) {
  538. return tbBusinessMapper.findOtherBusinessByCarId(businessCarId);
  539. }
  540. public void uploadReport(TbBusiness tbBusiness) {
  541. this.updateById(tbBusiness);
  542. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
  543. tbBusinessCarService.updateBatchById(cars);
  544. }
  545. public List<CarDisincle> getCarDisincleList(SoMap soMap) {
  546. return tbBusinessMapper.getCarDisincleList(soMap);
  547. }
  548. public TbBusiness getOtherBusinessById(String id) {
  549. TbBusiness tbBusiness = this.getById(id);
  550. List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findByBusinessId(id);
  551. tbBusiness.setItems(tbBusinessItems);
  552. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(id);
  553. tbBusiness.setCars(cars);
  554. return tbBusiness;
  555. }
  556. /**
  557. * 获取业务信息,但只取装卸类型的收费项
  558. */
  559. public TbBusiness getZxBusinessById(String id) {
  560. TbBusiness tbBusiness = this.getById(id);
  561. List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findZxByBusinessId(id);
  562. tbBusiness.setItems(tbBusinessItems);
  563. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(id);
  564. tbBusiness.setCars(cars);
  565. return tbBusiness;
  566. }
  567. public void deleteOtherBusiness(String id) {
  568. TbBusiness db = super.getById(id);
  569. String declareNo = db.getDeclareNo();
  570. if (StrUtil.isNotEmpty(declareNo)) {
  571. tbDeclareService.rebackDeclareNo(declareNo);
  572. }
  573. this.removeById(id);
  574. //删除响应业务项
  575. tbBusinessItemService.removeByBusinessId(id);
  576. //检查是否删除车辆
  577. List<TbBusinessCar> tbBusinessCarList = tbBusinessCarService.findOtherBusinessCar(id);
  578. tbBusinessCarList.forEach(tbBusinessCar -> {
  579. //未入场
  580. if (tbBusinessCar.getRealInTime() == null) {
  581. List<RelationBusinessCar> relationBusinessCars = relationBusinessCarService.findByBusinessCarId(tbBusinessCar.getId());
  582. //无关联业务==>删除
  583. if (relationBusinessCars.size() == 1) {
  584. tbBusinessCarService.removeById(tbBusinessCar.getId());
  585. }
  586. }
  587. });
  588. //删除关系
  589. relationBusinessCarService.removeByBusinessId(id);
  590. }
  591. public int checkCarBusinessType(String typeId, String carNo, String operateTime, int before) {
  592. return tbBusinessMapper.checkCarBusinessType(typeId, carNo, operateTime, before);
  593. }
  594. public int checkCarBusinessType(String typeId, String carNo, String timeStart, String timeEnd, String businessId) {
  595. return tbBusinessMapper.checkCarBusinessTypeByTime(typeId, carNo, timeStart, timeEnd, businessId);
  596. }
  597. public void unBindCar(String id, String businessCarId) {
  598. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  599. ew.eq("id", id).eq("business_car_id", businessCarId);
  600. TbBusiness db = getOne(ew);
  601. if (db == null) {
  602. throw new BusinessException("业务单不存在");
  603. }
  604. tbBusinessMapper.unBindCar(id);
  605. }
  606. public TbBusiness addOtherBusiness(OtherBusinessBO otherBusinessBO) {
  607. List<TbItem> tbItems = otherBusinessBO.getItems();
  608. if (tbItems.isEmpty()) {
  609. throw new BusinessException("请选择明细");
  610. }
  611. List<TbBusinessCar> cars = otherBusinessBO.getCars();
  612. if (cars.isEmpty()) {
  613. throw new BusinessException("作业车辆不能为空");
  614. }
  615. Date now = new Date();
  616. TbGoods tbGoods = tbGoodsService.getById(otherBusinessBO.getGoodsId());
  617. TbBusiness tbBusiness = new TbBusiness();
  618. String customerId = otherBusinessBO.getCustomerId();
  619. tbBusiness.setAutoDeductionType(tbGoods.getAutoDeductionType());
  620. tbBusiness.setCreateBy(StpUserUtil.getAdmin().getName());
  621. tbBusiness.setPayStep(tbGoods.getPayStep());
  622. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  623. if (tbCostomer != null) {
  624. tbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
  625. }
  626. BigDecimal price = new BigDecimal("0");
  627. List<TbBusinessItem> itemList = new ArrayList<>();
  628. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
  629. String pickCustomerId = otherBusinessBO.getPickCustomerId();
  630. TbCostomer partner = null;
  631. if (StrUtil.isNotEmpty(pickCustomerId)) {
  632. partner = tbCostomerService.getById(pickCustomerId);
  633. tbBusiness.setPickCustomerId(pickCustomerId).setPickCustomerName(partner.getName());
  634. }
  635. int index = 1;
  636. int size = cars.size();
  637. String goodsName = tbGoods.getName();
  638. for (TbItem tbItem : tbItems) {
  639. TbItem db = tbItemService.getById(tbItem.getId());
  640. String itemName = db.getItemName();
  641. goodsName = goodsName + "—" + itemName;
  642. String alaisName = db.getItemAlias();
  643. String startImage = tbItem.getStartImage();
  644. if (StrUtil.equals(SystemObject.config.getColdItemAlias(), alaisName) && StrUtil.isEmpty(startImage)) {
  645. throw new AjaxError("请上传开始时间图片");
  646. }
  647. TbBusinessItem item = new TbBusinessItem();
  648. int cabinetType = tbItem.getCabinetType();
  649. if (!SystemObject.config.getEmptyStoreItemAlias().equals(alaisName)
  650. && !SystemObject.config.getHeavyStoreItemAlias().equals(alaisName)) {
  651. cabinetType = -1;
  652. }
  653. int num = tbItem.getNum();
  654. String typeId = tbItem.getTypeId();
  655. TbItemType tbItemType = tbItemTypeService.getById(typeId);
  656. BigDecimal unitPrice = db.getPrice();
  657. unitPrice = StrUtil.equals(db.getPattern(), "RULES") ? BigDecimal.ZERO : unitPrice;
  658. BigDecimal itemTotalPrice = unitPrice.multiply(new BigDecimal(num));
  659. item.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName())
  660. .setPayType(db.getPayType())
  661. .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2));
  662. item.setItemCode(db.getItemCode()).setNum(num + "")
  663. .setItemId(db.getId()).setCabinetType(cabinetType)
  664. .setCabinetNo(tbItem.getCabinetNo()).setColdStartTime(tbItem.getColdStartTime())
  665. .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
  666. .setItemTypeId(typeId).setItemTypeName(tbItemType.getName()).setItemAlias(tbItem.getItemAlias())
  667. .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now)
  668. .setColdStartTime(tbItem.getColdStartTime()).setStartImage(startImage);
  669. if (partner != null) {
  670. item.setPick(1).setPickCustomerId(pickCustomerId).setPickCustomerName(partner.getName())
  671. .setPickBy(StpUserUtil.getCreateBy()).setPickTime(now);
  672. }
  673. if (SystemObject.config.getEveryCarPay().contains(itemName)) {
  674. itemTotalPrice = itemTotalPrice.multiply(BigDecimal.valueOf(size));
  675. }
  676. //堆存业务
  677. if (SystemObject.config.getEmptyStoreItemAlias().equals(alaisName)
  678. || SystemObject.config.getHeavyStoreItemAlias().equals(alaisName)) {
  679. //取柜--->根据柜号查询上一个存柜时间
  680. TbBusinessItem tbBusinessItem = tbBusinessItemService.findTheLastRecordByCabinetNo(tbItem.getCabinetNo());
  681. //堆存---》取柜
  682. if (cabinetType == 1) {
  683. goodsName = goodsName + "(取柜)";
  684. if (tbBusinessItem == null) {
  685. throw new AjaxError("根据柜号" + tbItem.getCabinetNo() + "找不到堆存记录");
  686. }
  687. //已经取走
  688. if (tbBusinessItem.getCabinetStatus() == 1) {
  689. throw new AjaxError("柜号" + tbItem.getCabinetNo() + "已取走");
  690. }
  691. Date endTime = tbItem.getColdStartTime();
  692. if (endTime == null) {
  693. throw new AjaxError("请输入取柜时间");
  694. }
  695. item.setColdStartTime(tbBusinessItem.getColdStartTime())
  696. .setParentCabinetId(tbBusinessItem.getId())
  697. .setColdEndTime(endTime)
  698. .setCabinetStatus(1);
  699. tbBusinessItem.setColdEndTime(endTime)
  700. .setCabinetStatus(1);
  701. //计算金额
  702. Date startTime = tbBusinessItem.getColdStartTime();
  703. if (startTime != null) {
  704. List<IOrderItem> expenses = new ArrayList<>();
  705. tbBusinessItemService.buildExpenses(Collections.singletonList(item), expenses);
  706. if (!expenses.isEmpty()) {
  707. IOrderPriceRes res = syncService.orderPriceCal(expenses);
  708. BigDecimal itemPrice = res.getTotalOrderPrice();
  709. item.setTotal(itemPrice);
  710. itemTotalPrice = itemPrice;
  711. }
  712. }
  713. tbBusinessItemService.updateById(tbBusinessItem);
  714. } else {
  715. goodsName = goodsName + "(存柜)";
  716. //存柜
  717. if (tbBusinessItem != null && tbBusinessItem.getCabinetStatus() == 0) {
  718. throw new AjaxError("柜号" + tbItem.getCabinetNo() + "已存柜未取柜");
  719. }
  720. Date endTime = tbItem.getColdStartTime();
  721. if (endTime == null) {
  722. throw new AjaxError("请输入存柜时间");
  723. }
  724. //业务费xxx都为0;
  725. BigDecimal zero = BigDecimal.ZERO;
  726. item.setColdStartTime(endTime).setItemPrice(zero)
  727. .setTotal(zero).setPayStatus(1);
  728. //无需支付
  729. item.setPayStatus(3);
  730. itemTotalPrice = zero;
  731. }
  732. }
  733. Date startTime = item.getColdStartTime();
  734. Date endTime = item.getColdEndTime();
  735. if (startTime != null && endTime != null) {
  736. List<IOrderItem> expenses = new ArrayList<>();
  737. tbBusinessItemService.buildExpenses(Collections.singletonList(item), expenses);
  738. IOrderPriceRes res = syncService.orderPriceCal(expenses);
  739. item.setTotal(res.getTotalOrderPrice());
  740. }
  741. price = price.add(itemTotalPrice);
  742. itemList.add(item);
  743. index++;
  744. }
  745. String declareNo = otherBusinessBO.getDeclareNo();
  746. tbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
  747. .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
  748. .setNo(no).setGoodsName(goodsName).setGoodsId(otherBusinessBO.getGoodsId()).setGoodsCode(tbGoods.getCode())
  749. .setBusinessGoodsName(otherBusinessBO.getBusinessGoodsName()).setBusinessGoodsNum(otherBusinessBO.getBusinessGoodsNum())
  750. .setPayStep(tbGoods.getPayStep()).setDeclareNo(declareNo).setCardNo(otherBusinessBO.getCardNo());
  751. tbBusiness.setCreateTime(now).setCreateByCustomerId(StpUserUtil.getCustomerId())
  752. .setItemPrice(price).setTotalMoney(price).setOwner(otherBusinessBO.getOwner());
  753. tbBusiness.setChinaCarNo(otherBusinessBO.getChinaCarNo());
  754. this.save(tbBusiness);
  755. String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
  756. for (TbBusinessCar car : cars) {
  757. String carNo = car.getCarNo().trim().toUpperCase();
  758. String carType = car.getCarType();
  759. if (StrUtil.isEmpty(carType)) {
  760. throw new BusinessException(carNo + "类型不能为空");
  761. }
  762. List<TbBusinessCar> notOutRecords = tbBusinessCarService.findNotOutCar(carNo);
  763. if (notOutRecords.size() > 1) {
  764. throw new BusinessException(carNo + "有多个未出场记录,请先处理");
  765. }
  766. //最新一条记录
  767. TbBusinessCar db = tbBusinessCarService.findTheLastRecord(carNo);
  768. if (!tbGoods.getName().contains("整车")) {
  769. //记录不存在或者已离场
  770. if (db == null || db.getRealOutTime() != null) {
  771. throw new BusinessException("车辆【" + carNo + "】未入场,无法录入业务");
  772. }
  773. }
  774. //不存在,或者已离场记录--->新建记录;
  775. if (db == null || db.getRealInTime() != null && db.getRealOutTime() != null) {
  776. db = new TbBusinessCar();
  777. db.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
  778. }
  779. for (TbBusinessItem item : itemList) {
  780. if (StrUtil.isNotEmpty(otherBusinessBO.getOperateTime())) {
  781. checkOtherBusiness(item.getItemTypeId(), otherBusinessBO.getOperateTime(), tbBusiness.getId(), carNo);
  782. }
  783. }
  784. db.setPayType(CarEnum.PayTypeEnum.NO_PAY_TYPE.getType());
  785. TbCar tbCar = tbCarService.findByCardNo(carNo);
  786. if (tbCar != null) {
  787. db.setCarCompany(tbCar.getCustomerName());
  788. if (!TbCar.CarTypeEnum.BUSINESS_CAR.getType().equals(tbCar.getCarType())) {
  789. db.setPayType(CarEnum.PayTypeEnum.FEE_TYPE.getType());
  790. }
  791. }
  792. db.setCarNo(carNo).setIsLock(0).setBusinessType(CarEnum.BusinessTypeEnum.BUSINESS_CAR.getType());
  793. db.setCarSize(car.getCarSize()).setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode())//业务车都是未审核状态
  794. .setTimeUpdate(now).setCarType(car.getCarType())
  795. .setDriverName(car.getDriverName()).setDriverPhone(car.getDriverPhone())
  796. .setNetWeight(car.getNetWeight()).setColor(car.getColor())
  797. .setCustomerId(customerId)
  798. .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  799. tbBusinessCarService.saveOrUpdate(db);
  800. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  801. relationBusinessCar.setBusinessId(tbBusiness.getId()).setBusinessCarId(db.getId());
  802. relationBusinessCarService.save(relationBusinessCar);
  803. }
  804. if (StrUtil.isNotEmpty(declareNo)) {
  805. TbDeclare declare = tbDeclareService.findByDeclareNo(declareNo);
  806. declare.setBusinessId(tbBusiness.getId());
  807. tbDeclareService.updateById(declare);
  808. }
  809. itemList.forEach(tbBusinessItem -> tbBusinessItem.setBusinessId(tbBusiness.getId()));
  810. tbBusinessItemService.saveBatch(itemList);
  811. return tbBusiness;
  812. }
  813. public List<TbBusiness> getOtherBusiness(SoMap startPage) {
  814. return tbBusinessMapper.getOtherBusiness(startPage);
  815. }
  816. public void editOtherBusiness(OtherBusinessBO otherBusinessBO) {
  817. String id = otherBusinessBO.getId();
  818. TbBusiness dbBusiness = this.getById(id);
  819. if (dbBusiness == null) {
  820. throw new AjaxError("记录不存在");
  821. }
  822. if (dbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
  823. throw new AjaxError("业务已审核,请驳回后修改");
  824. }
  825. List<TbItem> tbItems = otherBusinessBO.getItems();
  826. if (tbItems.isEmpty()) {
  827. throw new AjaxError("请选择收费明细");
  828. }
  829. List<TbBusinessCar> cars = otherBusinessBO.getCars();
  830. if (cars.isEmpty()) {
  831. throw new AjaxError("作业车辆不能为空");
  832. }
  833. Date now = new Date();
  834. List<RelationBusinessCar> relationBusinessCars = relationBusinessCarService.findByBusinessId(id);
  835. List<String> businessCarIds = cars.stream().filter(tbBusinessCar -> StrUtil.isNotEmpty(tbBusinessCar.getId()))
  836. .map(TbBusinessCar::getId).collect(Collectors.toList());
  837. List<String> removeIds = relationBusinessCars.stream()
  838. .filter(relationBusinessCar -> !businessCarIds.contains(relationBusinessCar.getBusinessCarId()))
  839. .map(RelationBusinessCar::getId)
  840. .collect(Collectors.toList());
  841. if (!removeIds.isEmpty()) {
  842. relationBusinessCarService.removeByIds(removeIds);
  843. }
  844. TbGoods tbGoods = tbGoodsService.getById(otherBusinessBO.getGoodsId());
  845. String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
  846. String goodsName = tbGoods.getName();
  847. List<TbBusinessItem> itemList = new ArrayList<>();
  848. if (PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode() != dbBusiness.getPayStatus()) {
  849. List<TbBusinessItem> businessItemList = tbBusinessItemService.findByBusinessId(id);
  850. //变成未取柜状态
  851. businessItemList.stream().filter(item -> item.getParentCabinetId() != null).forEach(item -> {
  852. TbBusinessItem tbBusinessItem = tbBusinessItemService.getById(item.getParentCabinetId());
  853. tbBusinessItem.setCabinetStatus(0).setColdEndTime(null);
  854. tbBusinessItemService.updateById(tbBusinessItem);
  855. });
  856. tbBusinessItemService.removeByBusinessId(id);
  857. BigDecimal price = new BigDecimal("0");
  858. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
  859. int index = 1;
  860. String pickCustomerId = otherBusinessBO.getPickCustomerId();
  861. TbCostomer partner = null;
  862. if (StrUtil.isNotEmpty(pickCustomerId)) {
  863. partner = tbCostomerService.getById(pickCustomerId);
  864. dbBusiness.setPickCustomerId(pickCustomerId).setPickCustomerName(partner.getName());
  865. }
  866. int size = cars.size();
  867. for (TbItem tbItem : tbItems) {
  868. TbItem db = tbItemService.getById(tbItem.getId());
  869. String alaisName = db.getItemAlias();
  870. String itemName = db.getItemName();
  871. goodsName = goodsName + "—" + itemName;
  872. String endImage = tbItem.getEndImage();
  873. if (StrUtil.equals(SystemObject.config.getColdItemAlias(), alaisName) && StrUtil.isEmpty(endImage)) {
  874. throw new AjaxError("请上传结束时间图片");
  875. }
  876. int cabinetType = tbItem.getCabinetType();
  877. //如果不是正面吊--->则取/存操作设置为-1
  878. if (!SystemObject.config.getEmptyStoreItemAlias().equals(alaisName)
  879. && !SystemObject.config.getHeavyStoreItemAlias().equals(alaisName)) {
  880. cabinetType = -1;
  881. }
  882. TbBusinessItem item = new TbBusinessItem();
  883. int num = tbItem.getNum();
  884. TbItemType tbItemType = tbItemTypeService.getById(tbItem.getTypeId());
  885. BigDecimal unitPrice = db.getPrice();
  886. unitPrice = StrUtil.equals(db.getPattern(), "RULES") ? BigDecimal.ZERO : unitPrice;
  887. BigDecimal itemTotalPrice = unitPrice.multiply(new BigDecimal(num));
  888. item.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
  889. .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2));
  890. item.setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId()).setBusinessId(dbBusiness.getId())
  891. .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
  892. .setItemTypeId(tbItem.getTypeId()).setItemTypeName(tbItemType.getName())
  893. .setCabinetNo(tbItem.getCabinetNo()).setItemAlias(tbItem.getItemAlias())
  894. .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now)
  895. .setCabinetType(cabinetType).setEndImage(endImage).setStartImage(tbItem.getStartImage())
  896. .setColdStartTime(tbItem.getColdStartTime()).setColdEndTime(tbItem.getColdEndTime());
  897. if (partner != null) {
  898. item.setPick(1).setPickCustomerId(pickCustomerId).setPickCustomerName(partner.getName())
  899. .setPickBy(StpUserUtil.getCreateBy()).setPickTime(now);
  900. }
  901. //装卸-->x车辆数量
  902. if (SystemObject.config.getEveryCarPay().contains(itemName)) {
  903. itemTotalPrice = itemTotalPrice.multiply(BigDecimal.valueOf(size));
  904. item.setTotal(itemTotalPrice);
  905. }
  906. Date startTime = item.getColdStartTime();
  907. Date endTime = item.getColdEndTime();
  908. if (startTime != null && endTime != null) {
  909. List<IOrderItem> expenses = new ArrayList<>();
  910. tbBusinessItemService.buildExpenses(Collections.singletonList(item), expenses);
  911. if (!expenses.isEmpty()) {
  912. IOrderPriceRes res = syncService.orderPriceCal(expenses);
  913. BigDecimal itemPrice = res.getTotalOrderPrice();
  914. item.setTotal(itemPrice);
  915. itemTotalPrice = itemPrice;
  916. }
  917. }
  918. //正面吊堆存业务
  919. if (SystemObject.config.getEmptyStoreItemAlias().equals(alaisName)
  920. || SystemObject.config.getHeavyStoreItemAlias().equals(alaisName)) {
  921. //取柜--->根据柜号查询上一个存柜时间
  922. TbBusinessItem tbBusinessItem = tbBusinessItemService.findTheLastRecordByCabinetNo(tbItem.getCabinetNo());
  923. //堆存
  924. if (cabinetType == 1) {//取柜
  925. if (tbBusinessItem == null) {
  926. throw new AjaxError("根据柜号" + tbItem.getCabinetNo() + "找不到堆存记录");
  927. }
  928. if (endTime == null) {
  929. throw new AjaxError("请输入取柜时间");
  930. }
  931. goodsName = goodsName + "(取柜)";
  932. item.setColdStartTime(tbBusinessItem.getColdStartTime())
  933. .setParentCabinetId(tbBusinessItem.getId())
  934. .setColdEndTime(endTime);
  935. tbBusinessItem.setColdEndTime(endTime)
  936. .setCabinetStatus(1);
  937. tbBusinessItemService.updateById(tbBusinessItem);
  938. } else {
  939. if (startTime == null) {
  940. throw new AjaxError("请输入存柜时间");
  941. }
  942. String businessItemId = tbItem.getBusinessItemId();
  943. if (StrUtil.isNotEmpty(businessItemId)
  944. && tbBusinessItem != null
  945. && !StrUtil.equals(businessItemId, tbBusinessItem.getId() + "")
  946. && tbBusinessItem.getColdEndTime() == null) {
  947. throw new AjaxError("箱规未取走,不能存入");
  948. }
  949. goodsName = goodsName + "(存柜)";
  950. //业务费xxx都为0;
  951. BigDecimal zero = BigDecimal.ZERO;
  952. item.setColdStartTime(endTime).setItemPrice(zero)
  953. .setTotal(zero).setPayStatus(1).setPayTime(now);
  954. itemTotalPrice = zero;
  955. item.setColdStartTime(startTime);
  956. //无需支付
  957. item.setPayStatus(3);
  958. }
  959. }
  960. price = price.add(itemTotalPrice);
  961. itemList.add(item);
  962. index++;
  963. }
  964. dbBusiness.setItemPrice(price).setTotalMoney(price);
  965. tbBusinessItemService.saveBatch(itemList);
  966. }
  967. for (TbBusinessCar tbBusinessCar : cars) {
  968. String businessCarId = tbBusinessCar.getId();
  969. String carNo = tbBusinessCar.getCarNo();
  970. if (StrUtil.isNotEmpty(businessCarId)) {
  971. //原来已存在的
  972. TbBusinessCar dbBusinessCar = tbBusinessCarService.getById(businessCarId);
  973. //如果修改了车牌号
  974. String dbCarNo = dbBusinessCar.getCarNo();
  975. if (!dbCarNo.equals(carNo)) {
  976. //把关联删除掉,然后添加新的关联
  977. relationBusinessCarService.removeByBusinessIdAndCarId(dbBusiness.getId(), businessCarId);
  978. TbBusinessCar otherCar = tbBusinessCarService.findTheLastRecord(carNo);
  979. if (otherCar == null) {
  980. throw new AjaxError("车辆【" + carNo + "】未入场");
  981. } else {
  982. List<TbBusiness> tbBusinessList = this.findOtherBusinessByCarId(businessCarId);
  983. if (tbBusinessList.size() == 1 && dbBusinessCar.getRealInTime() == null) {
  984. tbBusinessCarService.removeById(businessCarId);
  985. }
  986. }
  987. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  988. relationBusinessCar.setBusinessId(dbBusiness.getId()).setBusinessCarId(otherCar.getId());
  989. relationBusinessCarService.save(relationBusinessCar);
  990. } else {
  991. dbBusinessCar.setNetWeight(tbBusinessCar.getNetWeight()).setNetWeight(tbBusinessCar.getNetWeight())
  992. .setCarSize(tbBusinessCar.getCarSize()).setCarType(tbBusinessCar.getCarType())
  993. .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode());
  994. tbBusinessCarService.updateById(dbBusinessCar);
  995. }
  996. } else {
  997. TbBusinessCar checkCar = tbBusinessCarService.findTheLastRecord(carNo);
  998. //不存在或者已经离场的
  999. if (checkCar == null) {
  1000. throw new AjaxError("车辆【" + carNo + "】未入场");
  1001. }
  1002. checkCar.setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
  1003. .setNetWeight(tbBusinessCar.getNetWeight()).setCustomerId(dbBusiness.getCustomerId())
  1004. .setTimeUpdate(now).setIsLock(0).setCarType(tbBusinessCar.getCarType()).setBusinessType(1)
  1005. .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode());
  1006. tbBusinessCarService.saveOrUpdate(checkCar);
  1007. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  1008. relationBusinessCar.setBusinessId(dbBusiness.getId()).setBusinessCarId(checkCar.getId());
  1009. relationBusinessCarService.save(relationBusinessCar);
  1010. }
  1011. }
  1012. if (!StrUtil.equals(dbBusiness.getGoodsId(), otherBusinessBO.getGoodsId())) {
  1013. dbBusiness.setGoodsId(otherBusinessBO.getGoodsId())
  1014. .setGoodsName(goodsName).setPayStep(tbGoods.getPayStep());
  1015. }
  1016. String customerId = otherBusinessBO.getCustomerId();
  1017. if (StrUtil.isNotEmpty(customerId)) {
  1018. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  1019. dbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
  1020. }
  1021. String pickCustomerId = otherBusinessBO.getPickCustomerId();
  1022. if (StrUtil.isNotEmpty(pickCustomerId)) {
  1023. TbCostomer tbCostomer = tbCostomerService.getById(pickCustomerId);
  1024. dbBusiness.setPickCustomerId(pickCustomerId).setPickCustomerName(tbCostomer.getName());
  1025. }
  1026. dbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
  1027. .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
  1028. .setGoodsId(otherBusinessBO.getGoodsId()).setGoodsCode(tbGoods.getCode()).setGoodsName(goodsName)
  1029. .setOwner(otherBusinessBO.getOwner()).setBusinessGoodsName(otherBusinessBO.getBusinessGoodsName())
  1030. .setBusinessGoodsNum(otherBusinessBO.getBusinessGoodsNum())
  1031. .setCardNo(otherBusinessBO.getCardNo());
  1032. String chinaCar = cars.stream().filter(tbBusinessCar -> CAR_LIST.contains(StrUtil.sub(tbBusinessCar.getCarNo(), 0, 1)))
  1033. .map(TbBusinessCar::getCarNo).collect(Collectors.joining("、")).toUpperCase();
  1034. dbBusiness.setChinaCarNo(chinaCar);
  1035. this.updateById(dbBusiness);
  1036. if (dbBusiness.getConfirmInput() == 1) {
  1037. this.confirm(Collections.singletonList(dbBusiness.getId()));
  1038. }
  1039. }
  1040. public void bindOtherBusinessCar(String businessId, List<String> businessCarIdList) {
  1041. TbBusiness tbBusiness = this.getById(businessId);
  1042. if (tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
  1043. throw new AjaxError("业务已审核,请先驳回");
  1044. }
  1045. List<TbBusinessCar> list = tbBusinessCarService.findOtherBusinessCar(businessId);
  1046. list.stream().filter(tbBusinessCar -> !businessCarIdList.contains(tbBusinessCar.getId()) && tbBusinessCar.getRealInTime() == null)
  1047. .forEach(tbBusinessCar -> tbBusinessCarService.removeById(tbBusinessCar.getId()));
  1048. relationBusinessCarService.removeByBusinessId(businessId);
  1049. List<TbBusinessCar> carList = tbBusinessCarService.listByIds(businessCarIdList);
  1050. String chinaCarNo = carList.stream().filter(tbBusinessCar -> {
  1051. String carNo = tbBusinessCar.getCarNo();
  1052. String carStr = StrUtil.sub(carNo, 0, 1);
  1053. return CAR_LIST.contains(carStr);
  1054. }).map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  1055. String yueCarNo = carList.stream().filter(tbBusinessCar -> {
  1056. String carNo = tbBusinessCar.getCarNo();
  1057. String carStr = StrUtil.sub(carNo, 0, 1);
  1058. return !CAR_LIST.contains(carStr);
  1059. }).map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  1060. tbBusiness.setChinaCarNo(chinaCarNo);
  1061. tbBusiness.setCardNo(yueCarNo);
  1062. this.updateById(tbBusiness);
  1063. businessCarIdList.forEach(businessCarId -> {
  1064. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  1065. relationBusinessCar.setBusinessCarId(businessCarId).setBusinessId(businessId);
  1066. relationBusinessCarService.save(relationBusinessCar);
  1067. });
  1068. }
  1069. private void checkOtherBusiness(String itemTypeId, String operateTimeStr, String businessId, String carNo) {
  1070. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  1071. TbBusinessSort sort = tbBusinessSortService.findByItemTypeId(itemTypeId);
  1072. if (sort == null) {
  1073. return;
  1074. }
  1075. List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sort.getGroupId());
  1076. LocalDateTime operateTime = LocalDateTime.parse(operateTimeStr, formatter);
  1077. int i = 0;
  1078. for (TbBusinessSort tbBusinessSort : sorts) {
  1079. if (i == 0 && StrUtil.equals(tbBusinessSort.getTypeId(), itemTypeId) && sorts.size() > 1) {
  1080. TbBusinessSort afterItem = sorts.get(i + 1);
  1081. String typeId = afterItem.getTypeId();
  1082. Integer interval = afterItem.getIntervalTime();
  1083. LocalDateTime endTime = operateTime.plusMinutes(interval);
  1084. if (afterItem.getIntervalTime() > 0) {
  1085. int count = this.checkCarBusinessType(typeId, carNo, endTime.format(formatter), 1);
  1086. if (count > 0) {
  1087. throw new BusinessException("车辆:[" + carNo + "]" + tbBusinessSort.getTypeName() + "后" + afterItem.getIntervalTime() + "分钟才可以执行" + afterItem.getTypeName());
  1088. }
  1089. }
  1090. }
  1091. if (i > 0 && StrUtil.equals(tbBusinessSort.getTypeId(), itemTypeId)) {
  1092. TbBusinessSort beforeItem = sorts.get(i - 1);
  1093. String typeId = beforeItem.getTypeId();
  1094. Integer interval = tbBusinessSort.getIntervalTime();
  1095. LocalDateTime endTime = operateTime.minusMinutes(interval);
  1096. if (tbBusinessSort.getIntervalTime() > 0) {
  1097. int count = this.checkCarBusinessType(typeId, carNo, endTime.format(formatter), 0);
  1098. if (count > 0) {
  1099. throw new BusinessException("车辆:[" + carNo + "]" + beforeItem.getTypeName() + "后" + tbBusinessSort.getIntervalTime() + "分钟才可以执行" + tbBusinessSort.getTypeName());
  1100. }
  1101. }
  1102. }
  1103. Integer singleIntervalTime = tbBusinessSort.getSingleIntervalTime();
  1104. String timeStart = operateTime.minusHours(singleIntervalTime).format(formatter);
  1105. String timeEnd = operateTime.plusHours(singleIntervalTime).format(formatter);
  1106. int count = this.checkCarBusinessType(itemTypeId, carNo, timeStart, timeEnd, businessId);
  1107. if (count > 0) {
  1108. throw new BusinessException("车辆:[" + carNo + "]" + singleIntervalTime + "小时内已有相同作业");
  1109. }
  1110. i++;
  1111. }
  1112. }
  1113. public TbBusiness findByDeclareNo(String declareNo) {
  1114. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  1115. ew.eq("declare_no", declareNo).orderByDesc("id");
  1116. List<TbBusiness> list = this.list(ew);
  1117. return list.isEmpty() ? null : list.get(0);
  1118. }
  1119. /**
  1120. * 选择异常单发送
  1121. *
  1122. * @param errorBusinessBO
  1123. * @param isAdmin 是否管理员
  1124. */
  1125. public void selectErrorBusiness(ErrorBusinessBO errorBusinessBO, boolean isAdmin) {
  1126. log.info("is admin :{}", isAdmin);
  1127. TbBusiness tbBusiness = getById(errorBusinessBO.getId());
  1128. if (tbBusiness == null) {
  1129. throw new AjaxError("业务已被删除");
  1130. }
  1131. String businessId = tbBusiness.getId();
  1132. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(businessId);
  1133. tbBusiness.setPayStatus(errorBusinessBO.getPayStatus())
  1134. .setSupplement(1)
  1135. .setSupplementBy(errorBusinessBO.getSupplementBy())
  1136. .setSupplementTime(new Date())
  1137. .setSupplementReason(errorBusinessBO.getSupplementReason());
  1138. if (PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode() == errorBusinessBO.getPayStatus()) {
  1139. tbBusiness.setPayMoney(tbBusiness.getItemPrice())
  1140. .setPayTime(errorBusinessBO.getPayTime());
  1141. items.forEach(item -> item.setPayTime(errorBusinessBO.getPayTime()).setPayStatus(1));
  1142. tbBusinessItemService.updateBatchById(items);
  1143. }
  1144. List<TbBusinessCar> tbBusinessCars = errorBusinessBO.getCars();
  1145. tbBusinessCars.forEach(this::handlerCarPay);
  1146. tbBusinessCarService.updateBatchById(tbBusinessCars);
  1147. if (isAdmin) {
  1148. //发起审批
  1149. sendOA(tbBusiness, items, tbBusinessCars, errorBusinessBO.getSupplementBy());
  1150. }
  1151. this.updateById(tbBusiness);
  1152. }
  1153. /**
  1154. * 处理车辆支付
  1155. *
  1156. * @param tbBusinessCar
  1157. */
  1158. private void handlerCarPay(TbBusinessCar tbBusinessCar) {
  1159. String carNo = tbBusinessCar.getCarNo();
  1160. String payType = tbBusinessCar.getPayType();
  1161. Date payTime = tbBusinessCar.getPayTime();
  1162. Date inTime = tbBusinessCar.getRealInTime();
  1163. if (inTime == null) {
  1164. throw new AjaxError(carNo + "入场时间不能为空");
  1165. }
  1166. Date outTime = tbBusinessCar.getRealOutTime();
  1167. if (outTime == null) {
  1168. throw new AjaxError(carNo + "离场时间不能为空");
  1169. }
  1170. if (payType.equals(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType())) {
  1171. if (payTime == null) {
  1172. throw new AjaxError(carNo + "支付时间不能为空");
  1173. }
  1174. outTime = payTime;
  1175. }
  1176. //计算停车费
  1177. IOrderPriceRes parkMoney = this.getPartMoney(inTime, outTime, tbBusinessCar.getCarNo(), tbBusinessCar.getColor());
  1178. tbBusinessCar.setMoney(parkMoney.getTotalOrderPrice());
  1179. }
  1180. /**
  1181. * 发起流程审批
  1182. *
  1183. * @param tbBusiness
  1184. * @param items
  1185. * @param tbBusinessCars
  1186. * @param sendBy
  1187. */
  1188. private void sendOA(TbBusiness tbBusiness, List<TbBusinessItem> items, List<TbBusinessCar> tbBusinessCars, String sendBy) {
  1189. if (!oaConfig.isEnable()) {
  1190. return;
  1191. }
  1192. ParamsBO paramsBO = buildParams(tbBusiness, items, tbBusinessCars);
  1193. String json = JSONUtil.toJsonStr(paramsBO);
  1194. log.info("构建流程表单数据:{}", json);
  1195. String resp = HttpUtil.createPost(oaConfig.getUrl())
  1196. .timeout(2000).setReadTimeout(3000).body(json)
  1197. .execute().body();
  1198. log.info("请求返回:{}", resp);
  1199. OAResultBO oaResultBO = JSONUtil.toBean(resp, OAResultBO.class);
  1200. if (oaResultBO.getSuccess() && oaResultBO.getCode() == 200) {
  1201. String fdId = oaResultBO.getData().getFdId();
  1202. if (StrUtil.isEmpty(fdId)) {
  1203. throw new BusinessException("流程发起失败");
  1204. }
  1205. tbBusiness.setSendOa(1).setOaResult(OAResultEnum.JUDGE_ING.getCode())
  1206. .setSendTime(new Date()).setSendBy(sendBy)
  1207. .setOaFdId(fdId);
  1208. this.updateById(tbBusiness);
  1209. } else {
  1210. throw new BusinessException(oaResultBO.getMessage());
  1211. }
  1212. }
  1213. /**
  1214. * 构建表单数据
  1215. *
  1216. * @param tbBusiness
  1217. * @param items
  1218. * @param tbBusinessCars
  1219. * @return
  1220. */
  1221. private ParamsBO buildParams(TbBusiness tbBusiness, List<TbBusinessItem> items, List<TbBusinessCar> tbBusinessCars) {
  1222. String operator = tbBusiness.getSupplementBy();
  1223. String reason = tbBusiness.getSupplementReason();
  1224. ParamsBO paramsBO = new ParamsBO();
  1225. paramsBO.setRequestId(System.currentTimeMillis() + "")
  1226. .setBusinessSystemCode(oaConfig.getSystemCode());
  1227. ParamsBO.DataBO dataBO = new ParamsBO.DataBO();
  1228. String project = tbBusiness.getGoodsName();
  1229. JSONObject docCreator = new JSONObject();
  1230. docCreator.set("PersonNo", oaConfig.getPersonNo());
  1231. dataBO.setOperationalProject(project)
  1232. .setOperationalPerson(operator).setOperationalReason(reason)
  1233. .setDocSubject(project + "补单流程").setFdTemplateId(oaConfig.getTemplateId()).setDocCreator(JSONUtil.toJsonStr(docCreator));
  1234. //基础信息
  1235. JSONObject formValues = buildFormValues(tbBusiness);
  1236. //车辆信息
  1237. buildCarParams(tbBusinessCars, formValues);
  1238. //业务项信息
  1239. buildItemPrams(items, formValues);
  1240. dataBO.setFormValues(formValues.toJSONString(0));
  1241. paramsBO.setData(dataBO);
  1242. return paramsBO;
  1243. }
  1244. /**
  1245. * 构建业务项
  1246. *
  1247. * @param items
  1248. * @return
  1249. */
  1250. private void buildItemPrams(List<TbBusinessItem> items, JSONObject formValues) {
  1251. List<String> itemTypeNameList = new ArrayList<>();
  1252. List<String> itemNameList = new ArrayList<>();
  1253. List<String> itemPriceList = new ArrayList<>();
  1254. List<String> unitList = new ArrayList<>();
  1255. List<String> numList = new ArrayList<>();
  1256. List<String> payStatusList = new ArrayList<>();
  1257. List<String> payTimeList = new ArrayList<>();
  1258. List<String> remarkList = new ArrayList<>();
  1259. double total = items.stream().collect(Collectors.summarizingDouble(item -> item.getItemPrice().doubleValue())).getSum();
  1260. items.forEach(item -> {
  1261. itemTypeNameList.add(item.getItemTypeName());
  1262. itemNameList.add(item.getItemName());
  1263. itemPriceList.add(item.getItemPrice().toString());
  1264. unitList.add(item.getUnit());
  1265. numList.add(item.getNum());
  1266. payStatusList.add(item.getPayStatus() == 1 ? "已支付" : "未支付");
  1267. payTimeList.add(item.getPayTime() == null ? "" : DateUtil.format(item.getPayTime(), "yyyy-MM-dd HH:mm:ss"));
  1268. remarkList.add(StrUtil.isEmpty(item.getRemark()) ? "-" : item.getRemark());
  1269. });
  1270. formValues
  1271. .set("specificBusinessItems.chargingItem", itemTypeNameList)
  1272. .set("specificBusinessItems.chargeDetail", itemNameList)
  1273. .set("specificBusinessItems.unitPrice", itemPriceList)
  1274. .set("specificBusinessItems.chargingStandard", unitList)
  1275. .set("specificBusinessItems.quantity", numList)
  1276. .set("specificBusinessItems.payoutStatus", payStatusList)
  1277. .set("specificBusinessItems.payTime", payTimeList)
  1278. .set("specificBusinessItems.total", Collections.singleton(total))
  1279. .set("specificBusinessItems.note", remarkList);
  1280. }
  1281. /**
  1282. * 构建基础信息
  1283. *
  1284. * @param tbBusiness
  1285. * @return
  1286. */
  1287. private JSONObject buildFormValues(TbBusiness tbBusiness) {
  1288. ParamsBO.DataBO.FormValuesBO formValuesBO = new ParamsBO.DataBO.FormValuesBO();
  1289. String project = tbBusiness.getGoodsName();
  1290. formValuesBO.setOperationalProject(project).setWorkingTime(tbBusiness.getOperateTime()).setCustomerName(tbBusiness.getCustomerName())
  1291. .setOperatingOutlay(tbBusiness.getItemPrice().toString()).setAmount(tbBusiness.getItemPrice())
  1292. .setPaymentTime(tbBusiness.getPayTime() == null ? "" : DateUtil.format(tbBusiness.getPayTime(), "yyyy-MM-dd HH:mm:ss")).setCargoOwner(tbBusiness.getOwner()).setOperationNo(tbBusiness.getNo())
  1293. .setRecordingTime(DateUtil.format(tbBusiness.getCreateTime(), "yyyy-MM-dd HH:mm:ss")).setRecorder(tbBusiness.getCreateBy())
  1294. .setIsPay(PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode() == tbBusiness.getPayStatus() ? "已支付" : "未支付");
  1295. return JSONUtil.parseObj(formValuesBO);
  1296. }
  1297. /**
  1298. * 构建车辆表单
  1299. *
  1300. * @param tbBusinessCars
  1301. * @return
  1302. */
  1303. private void buildCarParams(List<TbBusinessCar> tbBusinessCars, JSONObject jsonObject) {
  1304. List<String> carNoList = new ArrayList<>();
  1305. List<String> typeList = new ArrayList<>();
  1306. List<String> loadList = new ArrayList<>();
  1307. List<String> unitsList = new ArrayList<>();
  1308. List<String> payStatusList = new ArrayList<>();
  1309. List<String> carStatusList = new ArrayList<>();
  1310. List<String> feeList = new ArrayList<>();
  1311. List<String> inList = new ArrayList<>();
  1312. List<String> outList = new ArrayList<>();
  1313. tbBusinessCars.forEach(tbBusinessCar -> {
  1314. carNoList.add(tbBusinessCar.getCarNo());
  1315. typeList.add(tbBusinessCar.getCarType());
  1316. loadList.add(tbBusinessCar.getNetWeight());
  1317. Double carSize = tbBusinessCar.getCarSize();
  1318. unitsList.add(carSize == null ? "-" : carSize.toString());
  1319. payStatusList.add(tbBusinessCar.getPayType());
  1320. carStatusList.add(tbBusinessCar.getIsLock() == 1 ? "正常" : "锁定");
  1321. feeList.add(tbBusinessCar.getMoney() == null ? "-" : tbBusinessCar.getMoney().toString());
  1322. inList.add(tbBusinessCar.getRealInTime() == null ? "-" : DateUtil.format(tbBusinessCar.getRealInTime(), "yyyy-MM-dd HH:mm:ss"));
  1323. outList.add(tbBusinessCar.getRealOutTime() == null ? "-" : DateUtil.format(tbBusinessCar.getRealOutTime(), "yyyy-MM-dd HH:mm:ss"));
  1324. });
  1325. jsonObject
  1326. .set("vehicleInfo.licenseNo", carNoList)
  1327. .set("vehicleInfo.type", typeList)
  1328. .set("vehicleInfo.load", loadList)
  1329. .set("vehicleInfo.specifications", unitsList)
  1330. .set("vehicleInfo.paymentStatus", payStatusList)
  1331. .set("vehicleInfo.vehicleState", carStatusList)
  1332. .set("vehicleInfo.parkingFee", feeList)
  1333. .set("vehicleInfo.entryTime", inList)
  1334. .set("vehicleInfo.departureTime", outList);
  1335. }
  1336. //添加异常单
  1337. public void addErrorBusiness(ErrorBusinessBO errorBusinessBO, boolean isAdmin) {
  1338. List<TbItem> tbItems = errorBusinessBO.getItems();
  1339. if (tbItems.isEmpty()) {
  1340. throw new BusinessException("请选择明细");
  1341. }
  1342. List<TbBusinessCar> cars = errorBusinessBO.getCars();
  1343. if (cars.isEmpty()) {
  1344. throw new BusinessException("作业车辆不能为空");
  1345. }
  1346. Date now = new Date();
  1347. if (errorBusinessBO.getCreateTime() != null) {
  1348. now = errorBusinessBO.getCreateTime();
  1349. }
  1350. TbGoods tbGoods = tbGoodsService.getById(errorBusinessBO.getGoodsId());
  1351. TbBusiness tbBusiness = new TbBusiness();
  1352. String customerId = errorBusinessBO.getCustomerId();
  1353. tbBusiness.setCreateBy(StpUserUtil.getCreateBy())
  1354. .setPayStep(tbGoods.getPayStep());
  1355. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  1356. if (tbCostomer != null) {
  1357. tbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
  1358. }
  1359. boolean businessIsPay = PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode() == errorBusinessBO.getPayStatus();
  1360. Date businessPayTime = errorBusinessBO.getPayTime();
  1361. BigDecimal price = new BigDecimal("0");
  1362. List<TbBusinessItem> itemList = new ArrayList<>();
  1363. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
  1364. if (StrUtil.isNotEmpty(errorBusinessBO.getNo())) {
  1365. no = errorBusinessBO.getNo();
  1366. }
  1367. int index = 1;
  1368. //作业项目
  1369. for (TbItem tbItem : tbItems) {
  1370. TbItem db = tbItemService.getById(tbItem.getId());
  1371. TbBusinessItem tbBusinessItem = new TbBusinessItem();
  1372. int num = tbItem.getNum();
  1373. String typeId = tbItem.getTypeId();
  1374. TbItemType tbItemType = tbItemTypeService.getById(typeId);
  1375. BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
  1376. tbBusinessItem.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
  1377. .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2))
  1378. .setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId())
  1379. .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
  1380. .setItemTypeId(typeId).setItemTypeName(tbItemType.getName())
  1381. .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
  1382. price = price.add(itemTotalPrice);
  1383. if (businessIsPay) {
  1384. tbBusinessItem.setPayTime(businessPayTime)
  1385. .setPayStatus(1);
  1386. }
  1387. itemList.add(tbBusinessItem);
  1388. index++;
  1389. }
  1390. String declareNo = errorBusinessBO.getDeclareNo();
  1391. tbBusiness.setCardSize(errorBusinessBO.getCarSize()).setNetWeight(errorBusinessBO.getNetWeight()).setTransactionId(errorBusinessBO.getTransactionId())
  1392. .setOperator(errorBusinessBO.getOperator()).setOperateTime(errorBusinessBO.getOperateTime())
  1393. .setNo(no).setGoodsName(tbGoods.getName()).setGoodsId(errorBusinessBO.getGoodsId())
  1394. .setSupplementReason(errorBusinessBO.getSupplementReason()).setSupplementTime(now)
  1395. .setSupplementBy(errorBusinessBO.getSupplementBy()).setSupplement(1).setPayStatus(errorBusinessBO.getPayStatus())
  1396. .setPayStep(tbGoods.getPayStep()).setDeclareNo(declareNo).setCardNo(errorBusinessBO.getCardNo());
  1397. tbBusiness.setCreateTime(now).setCreateByCustomerId(StpUserUtil.getCustomerId())
  1398. .setItemPrice(price).setTotalMoney(price).setOwner(errorBusinessBO.getOwner());
  1399. tbBusiness.setChinaCarNo(errorBusinessBO.getChinaCarNo());
  1400. if (businessIsPay) {//如果已支付
  1401. tbBusiness.setPayMoney(tbBusiness.getItemPrice())
  1402. .setPayTime(businessPayTime);
  1403. }
  1404. this.save(tbBusiness);
  1405. String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
  1406. //业务车
  1407. for (TbBusinessCar car : cars) {
  1408. String carNo = car.getCarNo().trim().toUpperCase();
  1409. String carType = car.getCarType();
  1410. if (StrUtil.isEmpty(carType)) {
  1411. throw new BusinessException(carNo + "类型不能为空");
  1412. }
  1413. car.setCreateTime(now).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
  1414. TbCar tbCar = tbCarService.findByCardNo(carNo);
  1415. if (tbCar != null) {
  1416. car.setCarCompany(tbCar.getCustomerName());
  1417. if (!TbCar.CarTypeEnum.BUSINESS_CAR.getType().equals(tbCar.getCarType())) {
  1418. car.setPayType(CarEnum.PayTypeEnum.FEE_TYPE.getType());
  1419. }
  1420. }
  1421. car.setCarNo(carNo).setIsLock(0);
  1422. car.setCarSize(car.getCarSize())
  1423. .setTimeUpdate(now).setCarType(car.getCarType())
  1424. .setNetWeight(car.getNetWeight())
  1425. .setCustomerId(customerId)
  1426. .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  1427. //新增放行记录
  1428. tbBusinessCarService.save(car);
  1429. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  1430. relationBusinessCar.setBusinessId(tbBusiness.getId()).setBusinessCarId(car.getId());
  1431. relationBusinessCarService.save(relationBusinessCar);
  1432. }
  1433. if (StrUtil.isNotEmpty(declareNo)) {
  1434. TbDeclare declare = tbDeclareService.findByDeclareNo(declareNo);
  1435. declare.setBusinessId(tbBusiness.getId());
  1436. tbDeclareService.updateById(declare);
  1437. }
  1438. itemList.forEach(tbBusinessItem -> tbBusinessItem.setBusinessId(tbBusiness.getId()));
  1439. tbBusinessItemService.saveBatch(itemList);
  1440. if (isAdmin) {
  1441. sendOA(tbBusiness, itemList, cars, errorBusinessBO.getSupplementBy());
  1442. }
  1443. }
  1444. /**
  1445. * 单独发起审批
  1446. *
  1447. * @param id
  1448. */
  1449. public void applyOA(String id, String sendBy) {
  1450. log.info("发起流程:{},{}", id, sendBy);
  1451. TbBusiness tbBusiness = this.getById(id);
  1452. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
  1453. List<TbBusinessCar> tbBusinessCars = tbBusinessCarService.findOtherBusinessCar(id);
  1454. sendOA(tbBusiness, items, tbBusinessCars, sendBy);
  1455. this.updateById(tbBusiness);
  1456. }
  1457. /**
  1458. * 编辑异常单
  1459. *
  1460. * @param errorBusinessBO
  1461. */
  1462. public void editErrorBusiness(ErrorBusinessBO errorBusinessBO) {
  1463. String id = errorBusinessBO.getId();
  1464. TbBusiness dbBusiness = this.getById(id);
  1465. if (dbBusiness == null) {
  1466. throw new BusinessException("记录不存在");
  1467. }
  1468. if (!(dbBusiness.getSendOa() == 0 || OAResultEnum.NO_PASS.getCode().equals(dbBusiness.getOaResult()))) {
  1469. throw new BusinessException("业务单正在审核,无法修改");
  1470. }
  1471. List<TbItem> tbItems = errorBusinessBO.getItems();
  1472. if (tbItems.isEmpty()) {
  1473. throw new BusinessException("请选择收费明细");
  1474. }
  1475. List<TbBusinessCar> cars = errorBusinessBO.getCars();
  1476. if (cars.isEmpty()) {
  1477. throw new BusinessException("作业车辆不能为空");
  1478. }
  1479. this.removeById(id);
  1480. tbBusinessItemService.removeByBusinessId(id);
  1481. tbBusinessCarService.removeByBusinessId(id);
  1482. relationBusinessCarService.removeByBusinessId(id);
  1483. errorBusinessBO.setNo(dbBusiness.getNo()).setCreateTime(dbBusiness.getCreateTime());
  1484. this.addErrorBusiness(errorBusinessBO, false);
  1485. }
  1486. /**
  1487. * oa审批回调
  1488. *
  1489. * @param callbackBO
  1490. */
  1491. public void approveCallback(CallbackBO callbackBO) {
  1492. String fdId = callbackBO.getFdId();
  1493. TbBusiness tbBusiness = this.findByFdId(fdId);
  1494. if (tbBusiness == null) {
  1495. throw new AjaxError("流程不存在");
  1496. }
  1497. String result = callbackBO.getAuditResult();
  1498. tbBusiness.setOaResult(callbackBO.getAuditResult()).setOaContent(callbackBO.getRefuseReason())
  1499. .setOaJudgeTime(new Date());
  1500. this.updateById(tbBusiness);
  1501. String businessId = tbBusiness.getId();
  1502. if (StrUtil.contains(result, "通过") && pushfeeConfig.isEnable()) {
  1503. //todo 审批通过-==>已支付的生成明细===>推送订单到计费系统
  1504. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(businessId);
  1505. String transactionId = tbBusiness.getTransactionId();
  1506. Date payTime = tbBusiness.getPayTime();
  1507. String outTradeNo = "of" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
  1508. //已经支付了的
  1509. List<PriceBO> priceBOList = cars.stream().filter(tbBusinessCar -> tbBusinessCar.getPayTime() != null).
  1510. map(tbBusinessCar -> {
  1511. PriceBO priceBO = new PriceBO();
  1512. priceBO.setId(tbBusinessCar.getId()).setP(tbBusinessCar.getMoney());
  1513. return priceBO;
  1514. }).
  1515. collect(Collectors.toList());
  1516. if (!priceBOList.isEmpty()) {
  1517. tbFeeDetailsService.chargeParkFee(priceBOList, transactionId, outTradeNo, payTime, PayEnum.PayType.OFF_LINE_PAY);//添加cars的收费明细
  1518. }
  1519. if (tbBusiness.getPayStatus() == PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode()) {
  1520. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(businessId);
  1521. tbFeeDetailsService.chargeBusinessFee(items, transactionId, outTradeNo, payTime, PayEnum.PayType.OFF_LINE_PAY);//添加items的收费明细
  1522. }
  1523. }
  1524. }
  1525. /**
  1526. * 根据流程ID查询
  1527. *
  1528. * @param fdId
  1529. * @return
  1530. */
  1531. private TbBusiness findByFdId(String fdId) {
  1532. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  1533. ew.lambda().eq(TbBusiness::getOaFdId, fdId);
  1534. return getOne(ew);
  1535. }
  1536. public TbBusiness findByNo(String no) {
  1537. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  1538. ew.eq("no", no);
  1539. return this.getOne(ew);
  1540. }
  1541. /**
  1542. * 额外添加车牌
  1543. *
  1544. * @param tbBusinessCar
  1545. */
  1546. public void addBusinessCar(TbBusinessCar tbBusinessCar) {
  1547. String businessId = tbBusinessCar.getBusinessId();
  1548. TbBusiness tbBusiness = this.getById(businessId);
  1549. if (tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
  1550. throw new AjaxError("业务已审核,不能绑定新车辆");
  1551. }
  1552. String carNo = tbBusinessCar.getCarNo().trim().toUpperCase();
  1553. TbBusinessCar lastRecord = tbBusinessCarService.findTheLastRecord(carNo);
  1554. String businessCarId;
  1555. Date now = new Date();
  1556. if (lastRecord == null || lastRecord.getRealOutTime() != null) {
  1557. //不存在或者已经离场
  1558. tbBusinessCar
  1559. .setBusinessType(CarEnum.BusinessTypeEnum.BUSINESS_CAR.getType())
  1560. .setCarNo(carNo).setPay(0).setIsLock(0).setPayUnloadMoney(0)
  1561. .setPayType(CarEnum.PayTypeEnum.NO_PAY_TYPE.getType()).setPay(0)
  1562. .setCreateTime(now).setCarType(CarEnum.CarTypeEnum.EMPTY_TYPE.getType())
  1563. .setTimeUpdate(now)
  1564. .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_NEED_JUDGE.getCode())
  1565. .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  1566. tbBusinessCarService.save(tbBusinessCar);
  1567. businessCarId = tbBusinessCar.getId();
  1568. } else {
  1569. businessCarId = lastRecord.getId();
  1570. lastRecord.setPayType(CarEnum.PayTypeEnum.NO_PAY_TYPE.getType())
  1571. .setCustomerId(tbBusiness.getCustomerId())
  1572. .setCarNo(carNo).setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode())
  1573. .setPayUnloadMoney(lastRecord.getPayUnloadMoney())
  1574. .setTimeUpdate(now)
  1575. .setBusinessType(CarEnum.BusinessTypeEnum.BUSINESS_CAR.getType());
  1576. tbBusinessCarService.updateById(lastRecord);
  1577. }
  1578. tbBusiness.setCardNo(tbBusiness.getCardNo() + "、" + carNo);
  1579. this.updateById(tbBusiness);
  1580. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  1581. relationBusinessCar.setBusinessId(businessId).setBusinessCarId(businessCarId);
  1582. relationBusinessCarService.save(relationBusinessCar);
  1583. }
  1584. /**
  1585. * 删除业务车
  1586. *
  1587. * @param carId
  1588. * @param businessId
  1589. */
  1590. public void deleteBusinessCar(String carId, String businessId) {
  1591. relationBusinessCarService.removeByBusinessIdAndCarId(businessId, carId);
  1592. List<RelationBusinessCar> list = relationBusinessCarService.findByBusinessCarId(carId);
  1593. if (list.isEmpty()) {
  1594. TbBusinessCar db = tbBusinessCarService.getById(carId);
  1595. if (db.getRealInTime() == null) {
  1596. tbBusinessCarService.removeById(carId);
  1597. }
  1598. }
  1599. }
  1600. /**
  1601. * 审核通过
  1602. *
  1603. * @param id
  1604. */
  1605. public void confirmJudgePass(String id) {
  1606. TbBusiness tbBusiness = this.getById(id);
  1607. if (tbBusiness == null) {
  1608. throw new AjaxError("业务不存在");
  1609. }
  1610. Date now = new Date();
  1611. List<TbBusinessCar> tbBusinessCars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
  1612. //审核
  1613. List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findByBusinessId(tbBusiness.getId());
  1614. String customerId = tbBusiness.getPickCustomerId();
  1615. TbAccount tbAccount = tbAccountService.getAccountByCustomerId(customerId);
  1616. for (TbBusinessCar tbBusinessCar : tbBusinessCars) {
  1617. for (TbBusinessItem item : tbBusinessItems) {
  1618. String itemName = item.getItemName();
  1619. // todo 扣除 人工、机械装卸车辆---->每辆车都要支付----->
  1620. if (SystemObject.config.getEveryCarPay().contains(itemName) && tbBusinessCar.getPayUnloadMoney() == 0) {
  1621. List<IOrderItem> expenses = new ArrayList<>();
  1622. IOrderItem orderItem = new IOrderItem();
  1623. orderItem.setExpenseNum(Integer.parseInt(item.getNum()))
  1624. .setUniqExpenseId(item.getItemCode());
  1625. expenses.add(orderItem);
  1626. IOrderPriceRes res = syncService.orderPriceCal(expenses);
  1627. BigDecimal price = res.getTotalOrderPrice();
  1628. BigDecimal balance = tbAccount.getTotalMoney();
  1629. if (price.compareTo(balance) > 0) {
  1630. throw new AjaxError("[" + tbAccount.getCustomerName() + "]账户余额不足扣除" + item.getItemName());
  1631. } else {
  1632. tbBusinessCar.setPayUnloadMoney(1);
  1633. tbBusinessCarService.updateById(tbBusinessCar);
  1634. item.setPayTime(now).setPayStatus(1).setPayType(PayEnum.PayType.PER_PAY.getCode())
  1635. .setPayTypeName(PayEnum.PayType.PER_PAY.getDesc());
  1636. tbBusinessItemService.updateById(item);
  1637. tbBusiness.setPayMoney(price.add(tbBusiness.getPayMoney())).setPayTime(now);
  1638. BigDecimal afterBalance = balance.subtract(price);
  1639. tbAccount.setTotalMoney(afterBalance);//增加累计扣款
  1640. tbAccountService.updateById(tbAccount);
  1641. TbFeeDetails details = tbFeeDetailsService.savePrePayDetails(res, item, tbBusinessCar, tbBusiness, FeeTypeEnum.STEVEDORE_FEE);
  1642. tbFeeStatisticsService.addOrUpdateStatistic(now, PayEnum.PayType.PER_PAY.getCode());//更新当前日期的日统计
  1643. TbDeductionRecord record = automaticPay.createTbDeductionRecord(details, balance, afterBalance, tbBusiness.getPickCustomerId(), tbBusiness.getPickCustomerName(), tbBusinessCar.getCarNo(), tbBusinessCar.getId(), FeeTypeEnum.STEVEDORE_FEE);
  1644. addInvoiceOrder(tbBusiness, res.getTotalOrderPrice(), details, record);
  1645. }
  1646. }
  1647. }
  1648. }
  1649. //其他费项 装卸业务管理费” 进行预存款扣除
  1650. for (TbBusinessItem item : tbBusinessItems) {
  1651. String aliasName = item.getItemAlias();
  1652. //充电打冷,正面吊(取柜)必须得有开始时间+结束时间
  1653. if (StrUtil.equals(aliasName, SystemObject.config.getColdItemAlias())
  1654. || (StrUtil.equals(aliasName, SystemObject.config.getEmptyStoreItemAlias())
  1655. && item.getCabinetType() == 1)
  1656. || (StrUtil.equals(aliasName, SystemObject.config.getHeavyStoreItemAlias())
  1657. && item.getCabinetType() == 1)
  1658. ) {
  1659. if (item.getColdStartTime() == null || item.getColdEndTime() == null) {
  1660. throw new AjaxError("请先点击【修改】,然后录入业务开始/结束时间");
  1661. }
  1662. }
  1663. //业务类型是装卸业务管理费且未支付的进行扣款
  1664. if (item.getPayStatus() == 0 && SystemObject.config.getUnLoadItem().contains(item.getItemTypeName())) {
  1665. List<IOrderItem> expenses = new ArrayList<>();
  1666. IOrderItem orderItem = new IOrderItem();
  1667. orderItem.setExpenseNum(Integer.parseInt(item.getNum()))
  1668. .setUniqExpenseId(item.getItemCode());
  1669. expenses.add(orderItem);
  1670. IOrderPriceRes res = syncService.orderPriceCal(expenses);
  1671. BigDecimal price = res.getTotalOrderPrice();
  1672. BigDecimal balance = tbAccount.getTotalMoney();
  1673. if (price.compareTo(balance) > 0) {
  1674. throw new AjaxError("[" + tbAccount.getCustomerName() + "]账户余额不足扣除" + item.getItemName());
  1675. } else {
  1676. BigDecimal afterBalance = balance.subtract(price);
  1677. tbAccount.setTotalMoney(afterBalance);//增加累计扣款
  1678. tbAccountService.updateById(tbAccount);
  1679. item.setPayTime(now).setPayStatus(1).setPayType(PayEnum.PayType.PER_PAY.getCode())
  1680. .setPayTypeName(PayEnum.PayType.PER_PAY.getDesc());
  1681. tbBusinessItemService.updateById(item);
  1682. tbBusiness.setPayMoney(price.add(tbBusiness.getPayMoney())).setPayTime(now);
  1683. //查找越南车--->统计以--->重车对集装箱吊装 (重 柜 ) =====空车 vs 集装箱吊装 (空 柜 )
  1684. String itemAlias = item.getItemAlias();
  1685. TbBusinessCar tbBusinessCar = tbBusinessCars.stream().filter(car -> car.getCarType().equals(CarEnum.CarTypeEnum.EMPTY_TYPE.getType()))
  1686. .findAny().orElse(tbBusinessCars.get(0));
  1687. if (StrUtil.equals(itemAlias, SystemObject.config.getHeavyCondoleItemAlias())) {
  1688. tbBusinessCar = tbBusinessCars.stream().filter(car -> car.getCarType().equals(CarEnum.CarTypeEnum.WEIGHT_TYPE.getType()))
  1689. .findAny().orElse(tbBusinessCars.get(0));
  1690. }
  1691. TbFeeDetails details = tbFeeDetailsService.savePrePayDetails(res, item, tbBusinessCar, tbBusiness, FeeTypeEnum.STEVEDORE_FEE);
  1692. tbFeeStatisticsService.addOrUpdateStatistic(now, PayEnum.PayType.PER_PAY.getCode());//更新当前日期的日统计
  1693. TbDeductionRecord record = automaticPay.createTbDeductionRecord(details, balance, afterBalance, tbBusiness.getPickCustomerId(), tbBusiness.getPickCustomerName(), tbBusinessCar.getCarNo(), tbBusinessCar.getId(), FeeTypeEnum.STEVEDORE_FEE);
  1694. addInvoiceOrder(tbBusiness, res.getTotalOrderPrice(), details, record);
  1695. }
  1696. }
  1697. }
  1698. tbBusiness.setConfirmJudgeTime(now).setConfirmJudgeContent("审核通过")
  1699. .setConfirmJudge(CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode())
  1700. .setJudgeBy(StpUserUtil.getCreateBy());
  1701. this.updateById(tbBusiness);
  1702. }
  1703. /**
  1704. * 添加开票订单
  1705. *
  1706. * @param tbBusiness
  1707. * @param billMoney
  1708. */
  1709. private void addInvoiceOrder(TbBusiness tbBusiness, BigDecimal billMoney, TbFeeDetails details, TbDeductionRecord record) {
  1710. TbInvoiceOrder t = new TbInvoiceOrder();
  1711. t.setBusinessName(tbBusiness.getGoodsName())
  1712. .setBusinessNo(tbBusiness.getNo())
  1713. .setCarNo(tbBusiness.getCarNoStr())
  1714. .setBusinessId(tbBusiness.getId())
  1715. .setCustomerId(tbBusiness.getCustomerId())
  1716. .setBillMoney(billMoney).setDetailId(details.getId())
  1717. .setPreOrderNum(details.getPreOrderNum())
  1718. .setDeductionRecordId(record.getId())
  1719. .setStatus(0).setCreateTime(new Date());
  1720. tbInvoiceOrderService.save(t);
  1721. }
  1722. /**
  1723. * 审核驳回
  1724. *
  1725. * @param id
  1726. * @param judgeContent
  1727. */
  1728. public void callback(String id, String judgeContent) {
  1729. TbBusiness db = this.getById(id);
  1730. db.setConfirmJudge(CarEnum.ConfirmJudgeEnum.CALL_BACK.getCode())
  1731. .setConfirmJudgeContent(judgeContent).setConfirmJudgeTime(new Date())
  1732. .setJudgeBy(StpUserUtil.getCreateBy());
  1733. this.updateById(db);
  1734. }
  1735. }