TbBusinessService.java 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  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. List<TbItemFac> list = tbItemFacService.list();
  327. if (list.isEmpty()) {
  328. throw new AjaxError("未配置停车费规则");
  329. }
  330. TbItemFac itemFac = list.get(0);
  331. IOrderItem orderItem = new IOrderItem();
  332. String uniqueExpenseId = itemFac.getUniqueExpenseId();
  333. orderItem.setUniqExpenseId(uniqueExpenseId).setExpenseNum(1);
  334. List<IFactorItem> factors = new ArrayList<>();
  335. for (TbItemFac fac : list) {
  336. String operator = fac.getOperator();
  337. if (StrUtil.equals(operator, "carSize")) {
  338. IFactorItem iFactorItem = new IFactorItem();
  339. iFactorItem.setFacId(fac.getFacId() + "");
  340. iFactorItem.setFacParams(carSize + "");
  341. factors.add(iFactorItem);
  342. } else if (StrUtil.equals(operator, "hour")) {
  343. IFactorItem iFactorItem = new IFactorItem();
  344. iFactorItem.setFacId(fac.getFacId() + "");
  345. iFactorItem.setFacParams(hours + "");
  346. factors.add(iFactorItem);
  347. } else if (StrUtil.equals(operator, "carColor")) {
  348. IFactorItem iFactorItem = new IFactorItem();
  349. iFactorItem.setFacId(fac.getFacId() + "");
  350. iFactorItem.setFacParams(carColor);
  351. factors.add(iFactorItem);
  352. }
  353. }
  354. orderItem.setFactors(factors);
  355. expenses.add(orderItem);
  356. IOrderPriceRes orderPriceRes = syncService.orderPriceCal(expenses);
  357. res.setCalculateId(orderPriceRes.getCalculateId())
  358. .setUniqueExpenseId(uniqueExpenseId)
  359. .setFireResult(orderPriceRes.getFireResult())
  360. .setTotalOrderPrice(orderPriceRes.getTotalOrderPrice());
  361. log.info("part money resp:{}", JSONUtil.toJsonStr(res));
  362. return res;
  363. }
  364. /**
  365. * 停车费因子构建
  366. * qzyReal:
  367. * 时长---hour;车长--carSize
  368. * qzyReal:
  369. * 颜色--carColor
  370. *
  371. * @param iTime
  372. * @param oTime
  373. * @param carSize
  374. * @return
  375. */
  376. public List<IOrderItem> getPartExpenses(Date iTime, Date oTime, double carSize) {
  377. long minutes = DateUtil.between(iTime, oTime, DateUnit.MINUTE);
  378. double hours = NumberUtil.div(minutes, 60, 1);
  379. List<IOrderItem> expenses = new ArrayList<>();
  380. TbItem tbItem = tbItemService.getPartItem();
  381. if (tbItem == null) {
  382. throw new AjaxError("未配置停车费规则");
  383. }
  384. IOrderItem orderItem = new IOrderItem();
  385. orderItem.setUniqExpenseId(tbItem.getItemCode()).setExpenseNum(1);
  386. List<TbItemFac> facList = tbItemFacService.getByItemId(tbItem.getId());
  387. List<IFactorItem> factors = new ArrayList<>();
  388. facList.forEach(tbItemFac -> {
  389. String operator = tbItemFac.getOperator();
  390. IFactorItem iFactorItem = new IFactorItem();
  391. iFactorItem.setFacId(tbItemFac.getId());
  392. if (StrUtil.equals(operator, "carSize")) {
  393. iFactorItem.setFacParams(carSize + "");
  394. } else if (StrUtil.equals(operator, "hour")) {
  395. iFactorItem.setFacParams(hours + "");
  396. }
  397. factors.add(iFactorItem);
  398. });
  399. orderItem.setFactors(factors);
  400. return expenses;
  401. }
  402. /**
  403. * 微信端获取缴费信息
  404. *
  405. * @param businessCarId
  406. * @param channel
  407. * @return
  408. */
  409. public Map<String, Object> getBusinessMoney(String businessCarId, String channel) {
  410. Map<String, Object> result = new HashMap<>();
  411. //对应的业务
  412. List<TbBusiness> businessList = this.findOtherBusinessByCarId(businessCarId);
  413. //是否需要交停车费---->业务车都要交
  414. // boolean needPayPartMoney = !businessList.isEmpty();
  415. TbBusinessCar tbBusinessCar = tbBusinessCarService.getById(businessCarId);
  416. String carNo = tbBusinessCar.getCarNo();
  417. businessList = businessList.stream().filter(tbBusiness -> {
  418. TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
  419. Integer payStep = tbGoods.getPayStep();
  420. //确认订单后方可缴费
  421. return GoodsEnum.PayStep.AFTER_CONFIRM.getCode().equals(payStep) && tbBusiness.getAdminConfirmInput() == 1
  422. //或者下单后可缴费
  423. || GoodsEnum.PayStep.BEFORE_CONFIRM.getCode().equals(payStep) && tbBusiness.getAdminConfirmInput() >= 0;
  424. }).collect(Collectors.toList());
  425. List<String> businessIdList = businessList.stream().map(TbBusiness::getId).collect(Collectors.toList());
  426. String businessIds = StrUtil.join(",", businessIdList);
  427. long judgeCount = businessList.stream().filter(tbBusiness -> tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()).count();
  428. int size = businessList.size();
  429. result.put("showPay", true);
  430. result.put("businessId", businessIds);
  431. result.put("noJudgeCount", judgeCount == size ? 0 : 1);
  432. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessIdList(businessIdList);
  433. Date inTime = tbBusinessCar.getRealInTime();
  434. int pay = tbBusinessCar.getPay();
  435. Map<String, Object> carMap = new HashMap<>();
  436. carMap.put("price", 0);
  437. List<String> carCalculateIds = new ArrayList<>();
  438. //停车费
  439. if (inTime != null) {
  440. Date outTime = tbBusinessCar.getRealOutTime();
  441. String cacheCarNo = RedisUtil.get(channel);
  442. if (outTime == null && StrUtil.isNotEmpty(cacheCarNo) && StrUtil.equals(carNo.trim().toUpperCase(), cacheCarNo.trim().toUpperCase())) {
  443. outTime = new Date();
  444. }
  445. if (outTime != null) {
  446. //默认需要缴费--->
  447. BigDecimal partMoney = new BigDecimal("1");
  448. if (StrUtil.isNotEmpty(tbBusinessCar.getColor()) && tbBusinessCar.getCarSize() != null) {
  449. String freeColor = partConfig.getFreeColor();
  450. //4.2米以下蓝色车辆
  451. if (tbBusinessCar.getColor().contains(freeColor)) {
  452. partMoney = new BigDecimal("0");
  453. }
  454. }
  455. if (CarEnum.PayTypeEnum.FEE_TYPE.getType().equals(tbBusinessCar.getPayType())) {
  456. partMoney = new BigDecimal("0");
  457. }
  458. if (partMoney.doubleValue() == 1) {
  459. IOrderPriceRes partPriceRes = getPartMoney(inTime, outTime, tbBusinessCar.getCarNo(), tbBusinessCar.getColor());
  460. BigDecimal partPrice = partPriceRes.getTotalOrderPrice();
  461. carCalculateIds.add(partPriceRes.getCalculateId());
  462. partMoney = partPrice;
  463. if (partPrice.doubleValue() > 0) {
  464. carMap.put("uniqExpenseId", partPriceRes.getFireResult().get(0).getUniqExpenseId());
  465. carMap.put("carDesc", partPriceRes.getCarDesc());
  466. carMap.put("calculateId;", partPriceRes.getCalculateId());
  467. carMap.put("hourDesc", partPriceRes.getHourDesc());
  468. carMap.put("over24Hour", partPriceRes.getOver24Hour());
  469. List<PriceDetailItem> detailItemList = partPriceRes.getFireResult().get(0)
  470. .getPriceDetail();
  471. detailItemList.forEach(obj -> carMap.put(obj.getKey(), obj.getValue()));
  472. }
  473. //todo 计算停车费
  474. }
  475. carMap.put("price", partMoney);
  476. }
  477. }
  478. carMap.put("id", tbBusinessCar.getId());
  479. carMap.put("carNo", tbBusinessCar.getCarNo());
  480. carMap.put("pay", pay);
  481. carMap.put("no", tbBusinessCar.getNo());
  482. result.put("carList", Collections.singleton(carMap));
  483. BigDecimal itemsPrice = new BigDecimal("0");
  484. List<Map<String, Object>> itemList = new ArrayList<>();
  485. if (!items.isEmpty()) {
  486. //未支付的
  487. List<IOrderItem> expenses = new ArrayList<>();
  488. items = items.stream().filter(item -> item.getPayStatus() == 0).collect(Collectors.toList());
  489. //如果不需要支付,则过滤掉入场管理费
  490. // ManagerBO dto = needPayManagerMoney(carNo, businessCarId, items);
  491. // if (dto.isNeed()) {
  492. // result.put("manager", dto);
  493. // }
  494. items.forEach(item -> {
  495. String num = item.getNum();
  496. String itemCode = item.getItemCode();
  497. IOrderItem iOrderItem = new IOrderItem();
  498. iOrderItem.setExpenseNum(Integer.parseInt(num)).setUniqExpenseId(itemCode);
  499. expenses.add(iOrderItem);
  500. });
  501. if (!expenses.isEmpty()) {
  502. IOrderPriceRes orderPriceRes = syncService.orderPriceCal(expenses);
  503. BigDecimal totalPrice = orderPriceRes.getTotalOrderPrice();
  504. carCalculateIds.add(orderPriceRes.getCalculateId());
  505. for (TbBusinessItem item : items) {
  506. BigDecimal itemPrice = item.getItemPrice().multiply(new BigDecimal(item.getNum()));
  507. itemsPrice = itemsPrice.add(itemPrice);
  508. Map<String, Object> itemMap = new HashMap<>();
  509. itemMap.put("id", item.getId());
  510. itemMap.put("name", item.getItemName() + "(" + item.getItemTypeName() + ")");
  511. itemMap.put("price", itemPrice);
  512. itemMap.put("pay", item.getPayStatus());
  513. orderPriceRes.getFireResult().stream().filter(priceItem -> StrUtil.equals(item.getItemCode(), priceItem.getUniqExpenseId()))
  514. .findAny().ifPresent(priceItem -> {
  515. itemMap.put("price", priceItem.getFirePrice().multiply(new BigDecimal(item.getNum())));
  516. });
  517. itemList.add(itemMap);
  518. TbBusinessSort tbBusinessSort = tbBusinessSortService.findByItemTypeId(item.getItemTypeId());
  519. if (tbBusinessSort != null) {
  520. TbSortGroup sortGroup = tbSortGroupService.getById(tbBusinessSort.getGroupId());
  521. if (sortGroup.getCompletePay().equals(1) && sortGroup.getStatus().equals(1)) {
  522. List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sortGroup.getId());
  523. for (TbBusinessSort sort : sorts) {
  524. long count = items.stream().filter(tbBusinessItem -> StrUtil.equals(sort.getTypeId(), tbBusinessItem.getItemTypeId()))
  525. .count();
  526. if (count == 0) {
  527. result.put("showPay", false);
  528. }
  529. }
  530. }
  531. }
  532. }
  533. result.put("itemsPrice", totalPrice);
  534. }
  535. }
  536. result.put("itemList", itemList);
  537. result.put("calculateId", String.join(",", carCalculateIds));
  538. result.put("businessNo", businessList.stream().map(TbBusiness::getNo).distinct().collect(Collectors.joining("、")));
  539. result.put("goodsName", businessList.stream().map(TbBusiness::getGoodsName).distinct().collect(Collectors.joining("、")));
  540. return result;
  541. }
  542. /**
  543. * 是否需要交入场管理费
  544. *
  545. * @param carNo
  546. * @return
  547. */
  548. public ManagerBO needPayManagerMoney(String carNo, String carId, List<TbBusinessItem> items) {
  549. ManagerBO dto = new ManagerBO();
  550. List<String> needItemTypeList = SystemObject.config.getManagerItemType();
  551. //是否有相关业务,,,没有的话直接不用交入场管理费
  552. boolean before = items.stream().anyMatch(item -> needItemTypeList.contains(item.getItemTypeName()));
  553. if (!before) {
  554. return dto;
  555. }
  556. String carPrefix = StrUtil.sub(carNo, 0, 1);
  557. boolean isvietnamCar = !CAR_LIST.contains(carPrefix);
  558. List<Integer> managerList = SystemObject.config.getManagerMoney();
  559. //越南车是否需要支付
  560. boolean verNeePay = managerList.contains(ManagerEnum.VER_PAY.getType());
  561. //中国车是否需要支付
  562. boolean chinaNeePay = managerList.contains(ManagerEnum.CHINA_PAY.getType());
  563. //是否需要支付入场管理费
  564. boolean need = isvietnamCar && verNeePay || !isvietnamCar && chinaNeePay;
  565. dto.setNeed(need);
  566. if (need) {
  567. //查询出对应的费项
  568. TbItem tbItem = tbItemService.findByName(SystemObject.config.getManagerWord());
  569. if (tbItem != null) {
  570. List<IOrderItem> itemList = new ArrayList<>();
  571. IOrderItem iOrderItem = new IOrderItem();
  572. iOrderItem.setExpenseNum(1).setUniqExpenseId(tbItem.getItemCode());
  573. itemList.add(iOrderItem);
  574. IOrderPriceRes managerPriceRes = syncService.orderPriceCal(itemList);
  575. dto.setCalculateId(managerPriceRes.getCalculateId())
  576. .setPrice(managerPriceRes.getTotalOrderPrice())
  577. .setCarNo(carNo).setId(tbItem.getId())
  578. .setLabel(tbItem.getItemName() + "(入场管理费)")
  579. .setName(tbItem.getItemName()).setCarId(carId);
  580. }
  581. }
  582. return dto;
  583. }
  584. public List<TbBusiness> findOtherBusinessByCarId(String businessCarId) {
  585. return tbBusinessMapper.findOtherBusinessByCarId(businessCarId);
  586. }
  587. public void uploadReport(TbBusiness tbBusiness) {
  588. this.updateById(tbBusiness);
  589. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
  590. tbBusinessCarService.updateBatchById(cars);
  591. }
  592. public List<CarDisincle> getCarDisincleList(SoMap soMap) {
  593. return tbBusinessMapper.getCarDisincleList(soMap);
  594. }
  595. public TbBusiness getOtherBusinessById(String id) {
  596. TbBusiness tbBusiness = this.getById(id);
  597. List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findByBusinessId(id);
  598. tbBusiness.setItems(tbBusinessItems);
  599. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(id);
  600. tbBusiness.setCars(cars);
  601. return tbBusiness;
  602. }
  603. /**
  604. * 获取业务信息,但只取装卸类型的收费项
  605. */
  606. public TbBusiness getZxBusinessById(String id) {
  607. TbBusiness tbBusiness = this.getById(id);
  608. List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findZxByBusinessId(id);
  609. tbBusiness.setItems(tbBusinessItems);
  610. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(id);
  611. tbBusiness.setCars(cars);
  612. return tbBusiness;
  613. }
  614. public void deleteOtherBusiness(String id) {
  615. TbBusiness db = super.getById(id);
  616. String declareNo = db.getDeclareNo();
  617. if (StrUtil.isNotEmpty(declareNo)) {
  618. tbDeclareService.rebackDeclareNo(declareNo);
  619. }
  620. this.removeById(id);
  621. //删除响应业务项
  622. tbBusinessItemService.removeByBusinessId(id);
  623. //检查是否删除车辆
  624. List<TbBusinessCar> tbBusinessCarList = tbBusinessCarService.findOtherBusinessCar(id);
  625. tbBusinessCarList.forEach(tbBusinessCar -> {
  626. //未入场
  627. if (tbBusinessCar.getRealInTime() == null) {
  628. List<RelationBusinessCar> relationBusinessCars = relationBusinessCarService.findByBusinessCarId(tbBusinessCar.getId());
  629. //无关联业务==>删除
  630. if (relationBusinessCars.size() == 1) {
  631. tbBusinessCarService.removeById(tbBusinessCar.getId());
  632. }
  633. }
  634. });
  635. //删除关系
  636. relationBusinessCarService.removeByBusinessId(id);
  637. }
  638. public int checkCarBusinessType(String typeId, String carNo, String operateTime, int before) {
  639. return tbBusinessMapper.checkCarBusinessType(typeId, carNo, operateTime, before);
  640. }
  641. public int checkCarBusinessType(String typeId, String carNo, String timeStart, String timeEnd, String businessId) {
  642. return tbBusinessMapper.checkCarBusinessTypeByTime(typeId, carNo, timeStart, timeEnd, businessId);
  643. }
  644. public void unBindCar(String id, String businessCarId) {
  645. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  646. ew.eq("id", id).eq("business_car_id", businessCarId);
  647. TbBusiness db = getOne(ew);
  648. if (db == null) {
  649. throw new BusinessException("业务单不存在");
  650. }
  651. tbBusinessMapper.unBindCar(id);
  652. }
  653. public TbBusiness addOtherBusiness(OtherBusinessBO otherBusinessBO) {
  654. List<TbItem> tbItems = otherBusinessBO.getItems();
  655. if (tbItems.isEmpty()) {
  656. throw new BusinessException("请选择明细");
  657. }
  658. List<TbBusinessCar> cars = otherBusinessBO.getCars();
  659. if (cars.isEmpty()) {
  660. throw new BusinessException("作业车辆不能为空");
  661. }
  662. Date now = new Date();
  663. TbGoods tbGoods = tbGoodsService.getById(otherBusinessBO.getGoodsId());
  664. TbBusiness tbBusiness = new TbBusiness();
  665. String customerId = otherBusinessBO.getCustomerId();
  666. tbBusiness.setAutoDeductionType(tbGoods.getAutoDeductionType());
  667. tbBusiness.setCreateBy(StpUserUtil.getAdmin().getName());
  668. tbBusiness.setPayStep(tbGoods.getPayStep());
  669. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  670. if (tbCostomer != null) {
  671. tbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
  672. }
  673. BigDecimal price = new BigDecimal("0");
  674. List<TbBusinessItem> itemList = new ArrayList<>();
  675. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
  676. String pickCustomerId = otherBusinessBO.getPickCustomerId();
  677. TbCostomer partner = null;
  678. if (StrUtil.isNotEmpty(pickCustomerId)) {
  679. partner = tbCostomerService.getById(pickCustomerId);
  680. tbBusiness.setPickCustomerId(pickCustomerId).setPickCustomerName(partner.getName());
  681. }
  682. int index = 1;
  683. int size = cars.size();
  684. for (TbItem tbItem : tbItems) {
  685. TbItem db = tbItemService.getById(tbItem.getId());
  686. String itemName = db.getItemName();
  687. TbBusinessItem item = new TbBusinessItem();
  688. int num = tbItem.getNum();
  689. String typeId = tbItem.getTypeId();
  690. TbItemType tbItemType = tbItemTypeService.getById(typeId);
  691. BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
  692. item.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
  693. .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2));
  694. item.setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId()).setCabinetNo(tbItem.getCabinetNo())
  695. .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
  696. .setItemTypeId(typeId).setItemTypeName(tbItemType.getName())
  697. .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
  698. if (partner != null) {
  699. item.setPick(1).setPickCustomerId(pickCustomerId).setPickCustomerName(partner.getName())
  700. .setPickBy(StpUserUtil.getCreateBy()).setPickTime(now);
  701. }
  702. if (SystemObject.config.getEveryCarPay().contains(itemName)) {
  703. itemTotalPrice = itemTotalPrice.multiply(BigDecimal.valueOf(size));
  704. }
  705. price = price.add(itemTotalPrice);
  706. itemList.add(item);
  707. index++;
  708. }
  709. String declareNo = otherBusinessBO.getDeclareNo();
  710. tbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
  711. .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
  712. .setNo(no).setGoodsName(tbGoods.getName()).setGoodsId(otherBusinessBO.getGoodsId())
  713. .setBusinessGoodsName(otherBusinessBO.getBusinessGoodsName()).setBusinessGoodsNum(otherBusinessBO.getBusinessGoodsNum())
  714. .setPayStep(tbGoods.getPayStep()).setDeclareNo(declareNo).setCardNo(otherBusinessBO.getCardNo());
  715. tbBusiness.setCreateTime(now).setCreateByCustomerId(StpUserUtil.getCustomerId())
  716. .setItemPrice(price).setTotalMoney(price).setOwner(otherBusinessBO.getOwner());
  717. tbBusiness.setChinaCarNo(otherBusinessBO.getChinaCarNo());
  718. this.save(tbBusiness);
  719. String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
  720. for (TbBusinessCar car : cars) {
  721. String carNo = car.getCarNo().trim().toUpperCase();
  722. String carType = car.getCarType();
  723. if (car.getCarSize() == null || car.getCarSize() <= 0) {
  724. throw new AjaxError(carNo + "规格不正确");
  725. }
  726. if (StrUtil.isEmpty(carType)) {
  727. throw new BusinessException(carNo + "类型不能为空");
  728. }
  729. List<TbBusinessCar> notOutRecords = tbBusinessCarService.findNotOutCar(carNo);
  730. if (notOutRecords.size() > 1) {
  731. throw new BusinessException(carNo + "有多个未出场记录,请先处理");
  732. }
  733. //最新一条记录
  734. TbBusinessCar db = tbBusinessCarService.findTheLastRecord(carNo);
  735. if (!tbGoods.getName().contains("整车")) {
  736. //记录不存在或者已离场
  737. if (db == null || db.getRealOutTime() != null) {
  738. throw new BusinessException("车辆【" + carNo + "】未入场,无法录入业务");
  739. }
  740. }
  741. //不存在,或者已离场记录--->新建记录;
  742. if (db == null || db.getRealInTime() != null && db.getRealOutTime() != null) {
  743. db = new TbBusinessCar();
  744. db.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
  745. }
  746. for (TbBusinessItem item : itemList) {
  747. if (StrUtil.isNotEmpty(otherBusinessBO.getOperateTime())) {
  748. checkOtherBusiness(item.getItemTypeId(), otherBusinessBO.getOperateTime(), tbBusiness.getId(), carNo);
  749. }
  750. }
  751. db.setPayType(CarEnum.PayTypeEnum.NO_PAY_TYPE.getType());
  752. TbCar tbCar = tbCarService.findByCardNo(carNo);
  753. if (tbCar != null) {
  754. db.setCarCompany(tbCar.getCustomerName());
  755. if (!TbCar.CarTypeEnum.BUSINESS_CAR.getType().equals(tbCar.getCarType())) {
  756. db.setPayType(CarEnum.PayTypeEnum.FEE_TYPE.getType());
  757. }
  758. }
  759. db.setCarNo(carNo).setIsLock(0).setBusinessType(CarEnum.BusinessTypeEnum.BUSINESS_CAR.getType());
  760. db.setCarSize(car.getCarSize()).setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode())//业务车都是未审核状态
  761. .setTimeUpdate(now).setCarType(car.getCarType())
  762. .setNetWeight(car.getNetWeight()).setColor(car.getColor())
  763. .setCustomerId(customerId)
  764. .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  765. tbBusinessCarService.saveOrUpdate(db);
  766. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  767. relationBusinessCar.setBusinessId(tbBusiness.getId()).setBusinessCarId(db.getId());
  768. relationBusinessCarService.save(relationBusinessCar);
  769. }
  770. if (StrUtil.isNotEmpty(declareNo)) {
  771. TbDeclare declare = tbDeclareService.findByDeclareNo(declareNo);
  772. declare.setBusinessId(tbBusiness.getId());
  773. tbDeclareService.updateById(declare);
  774. }
  775. itemList.forEach(tbBusinessItem -> tbBusinessItem.setBusinessId(tbBusiness.getId()));
  776. tbBusinessItemService.saveBatch(itemList);
  777. return tbBusiness;
  778. }
  779. public List<TbBusiness> getOtherBusiness(SoMap startPage) {
  780. return tbBusinessMapper.getOtherBusiness(startPage);
  781. }
  782. public void editOtherBusiness(OtherBusinessBO otherBusinessBO) {
  783. String id = otherBusinessBO.getId();
  784. TbBusiness dbBusiness = this.getById(id);
  785. if (dbBusiness == null) {
  786. throw new AjaxError("记录不存在");
  787. }
  788. if (dbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
  789. throw new AjaxError("业务已审核,请驳回后修改");
  790. }
  791. List<TbItem> tbItems = otherBusinessBO.getItems();
  792. if (tbItems.isEmpty()) {
  793. throw new AjaxError("请选择收费明细");
  794. }
  795. List<TbBusinessCar> cars = otherBusinessBO.getCars();
  796. if (cars.isEmpty()) {
  797. throw new AjaxError("作业车辆不能为空");
  798. }
  799. Date now = new Date();
  800. List<RelationBusinessCar> relationBusinessCars = relationBusinessCarService.findByBusinessId(id);
  801. List<String> businessCarIds = cars.stream().filter(tbBusinessCar -> StrUtil.isNotEmpty(tbBusinessCar.getId()))
  802. .map(TbBusinessCar::getId).collect(Collectors.toList());
  803. List<String> removeIds = relationBusinessCars.stream()
  804. .filter(relationBusinessCar -> !businessCarIds.contains(relationBusinessCar.getBusinessCarId()))
  805. .map(RelationBusinessCar::getId)
  806. .collect(Collectors.toList());
  807. if (!removeIds.isEmpty()) {
  808. relationBusinessCarService.removeByIds(removeIds);
  809. }
  810. TbGoods tbGoods = tbGoodsService.getById(otherBusinessBO.getGoodsId());
  811. String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
  812. List<TbBusinessItem> itemList = new ArrayList<>();
  813. if (PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode() != dbBusiness.getPayStatus()) {
  814. tbBusinessItemService.removeByBusinessId(id);
  815. BigDecimal price = new BigDecimal("0");
  816. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
  817. int index = 1;
  818. String pickCustomerId = otherBusinessBO.getPickCustomerId();
  819. TbCostomer partner = null;
  820. if (StrUtil.isNotEmpty(pickCustomerId)) {
  821. partner = tbCostomerService.getById(pickCustomerId);
  822. dbBusiness.setPickCustomerId(pickCustomerId).setPickCustomerName(partner.getName());
  823. }
  824. int size = cars.size();
  825. for (TbItem tbItem : tbItems) {
  826. TbItem db = tbItemService.getById(tbItem.getId());
  827. String itemName = db.getItemName();
  828. TbBusinessItem item = new TbBusinessItem();
  829. int num = tbItem.getNum();
  830. TbItemType tbItemType = tbItemTypeService.getById(tbItem.getTypeId());
  831. BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
  832. item.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
  833. .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2));
  834. item.setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId()).setBusinessId(dbBusiness.getId())
  835. .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
  836. .setItemTypeId(tbItem.getTypeId()).setItemTypeName(tbItemType.getName())
  837. .setCabinetNo(tbItem.getCabinetNo())
  838. .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
  839. if (partner != null) {
  840. item.setPick(1).setPickCustomerId(pickCustomerId).setPickCustomerName(partner.getName())
  841. .setPickBy(StpUserUtil.getCreateBy()).setPickTime(now);
  842. }
  843. if (SystemObject.config.getEveryCarPay().contains(itemName)) {
  844. itemTotalPrice = itemTotalPrice.multiply(BigDecimal.valueOf(size));
  845. }
  846. price = price.add(itemTotalPrice);
  847. itemList.add(item);
  848. index++;
  849. }
  850. dbBusiness.setItemPrice(price).setTotalMoney(price);
  851. tbBusinessItemService.saveBatch(itemList);
  852. }
  853. for (TbBusinessCar tbBusinessCar : cars) {
  854. String businessCarId = tbBusinessCar.getId();
  855. String carNo = tbBusinessCar.getCarNo();
  856. for (TbBusinessItem item : itemList) {
  857. checkOtherBusiness(item.getItemTypeId(), otherBusinessBO.getOperateTime(), dbBusiness.getId(), carNo);
  858. }
  859. if (StrUtil.isNotEmpty(businessCarId)) {
  860. //原来已存在的
  861. TbBusinessCar dbBusinessCar = tbBusinessCarService.getById(businessCarId);
  862. //如果修改了车牌号
  863. String dbCarNo = dbBusinessCar.getCarNo();
  864. if (!dbCarNo.equals(carNo)) {
  865. //把关联删除掉,然后添加新的关联
  866. relationBusinessCarService.removeByBusinessIdAndCarId(dbBusiness.getId(), businessCarId);
  867. TbBusinessCar otherCar = tbBusinessCarService.findTheLastRecord(carNo);
  868. if (otherCar == null ||//不存在或者已离场===>新建
  869. (otherCar.getRealInTime() != null && otherCar.getRealOutTime() != null)) {
  870. otherCar = new TbBusinessCar();
  871. otherCar.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4))
  872. .setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
  873. .setNetWeight(tbBusinessCar.getNetWeight()).setCustomerId(dbBusiness.getCustomerId())
  874. .setTimeUpdate(now).setIsLock(0).setCarType(tbBusinessCar.getCarType())
  875. .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode());
  876. tbBusinessCarService.save(otherCar);
  877. } else {
  878. List<TbBusiness> tbBusinessList = this.findOtherBusinessByCarId(businessCarId);
  879. if (tbBusinessList.size() == 1 && dbBusinessCar.getRealInTime() == null) {
  880. tbBusinessCarService.removeById(businessCarId);
  881. }
  882. }
  883. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  884. relationBusinessCar.setBusinessId(dbBusiness.getId()).setBusinessCarId(otherCar.getId());
  885. relationBusinessCarService.save(relationBusinessCar);
  886. } else {
  887. dbBusinessCar.setNetWeight(tbBusinessCar.getNetWeight()).setNetWeight(tbBusinessCar.getNetWeight())
  888. .setCarSize(tbBusinessCar.getCarSize()).setCarType(tbBusinessCar.getCarType())
  889. .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode());
  890. tbBusinessCarService.updateById(dbBusinessCar);
  891. }
  892. } else {
  893. TbBusinessCar checkCar = tbBusinessCarService.findTheLastRecord(carNo);
  894. //不存在或者已经离场的
  895. if (checkCar == null ||
  896. (checkCar.getRealInTime() != null && checkCar.getRealOutTime() != null)) {
  897. checkCar = new TbBusinessCar();
  898. checkCar.setCreateTime(now).setPay(0).setBusinessType(1)
  899. .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode())
  900. .setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
  901. }
  902. checkCar.setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
  903. .setNetWeight(tbBusinessCar.getNetWeight()).setCustomerId(dbBusiness.getCustomerId())
  904. .setTimeUpdate(now).setIsLock(0).setCarType(tbBusinessCar.getCarType()).setBusinessType(1)
  905. .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode());
  906. tbBusinessCarService.saveOrUpdate(checkCar);
  907. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  908. relationBusinessCar.setBusinessId(dbBusiness.getId()).setBusinessCarId(checkCar.getId());
  909. relationBusinessCarService.save(relationBusinessCar);
  910. }
  911. }
  912. if (!StrUtil.equals(dbBusiness.getGoodsId(), otherBusinessBO.getGoodsId())) {
  913. dbBusiness.setGoodsId(otherBusinessBO.getGoodsId())
  914. .setGoodsName(tbGoods.getName()).setPayStep(tbGoods.getPayStep());
  915. }
  916. String customerId = otherBusinessBO.getCustomerId();
  917. if (StrUtil.isNotEmpty(customerId)) {
  918. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  919. dbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
  920. }
  921. String pickCustomerId = otherBusinessBO.getPickCustomerId();
  922. if (StrUtil.isNotEmpty(pickCustomerId)) {
  923. TbCostomer tbCostomer = tbCostomerService.getById(pickCustomerId);
  924. dbBusiness.setPickCustomerId(pickCustomerId).setPickCustomerName(tbCostomer.getName());
  925. }
  926. dbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
  927. .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
  928. .setGoodsId(otherBusinessBO.getGoodsId())
  929. .setOwner(otherBusinessBO.getOwner()).setBusinessGoodsName(otherBusinessBO.getBusinessGoodsName())
  930. .setBusinessGoodsNum(otherBusinessBO.getBusinessGoodsNum())
  931. .setCardNo(otherBusinessBO.getCardNo());
  932. String chinaCar = cars.stream().filter(tbBusinessCar -> CAR_LIST.contains(StrUtil.sub(tbBusinessCar.getCarNo(), 0, 1)))
  933. .map(TbBusinessCar::getCarNo).collect(Collectors.joining("、")).toUpperCase();
  934. dbBusiness.setChinaCarNo(chinaCar);
  935. this.updateById(dbBusiness);
  936. if (dbBusiness.getConfirmInput() == 1) {
  937. this.confirm(Collections.singletonList(dbBusiness.getId()));
  938. }
  939. }
  940. public void bindOtherBusinessCar(String businessId, List<String> businessCarIdList) {
  941. TbBusiness tbBusiness = this.getById(businessId);
  942. if (tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
  943. throw new AjaxError("业务已审核,请先驳回");
  944. }
  945. List<TbBusinessCar> list = tbBusinessCarService.findOtherBusinessCar(businessId);
  946. list.stream().filter(tbBusinessCar -> !businessCarIdList.contains(tbBusinessCar.getId()) && tbBusinessCar.getRealInTime() == null)
  947. .forEach(tbBusinessCar -> tbBusinessCarService.removeById(tbBusinessCar.getId()));
  948. relationBusinessCarService.removeByBusinessId(businessId);
  949. List<TbBusinessCar> carList = tbBusinessCarService.listByIds(businessCarIdList);
  950. String chinaCarNo = carList.stream().filter(tbBusinessCar -> {
  951. String carNo = tbBusinessCar.getCarNo();
  952. String carStr = StrUtil.sub(carNo, 0, 1);
  953. return CAR_LIST.contains(carStr);
  954. }).map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  955. String yueCarNo = carList.stream().filter(tbBusinessCar -> {
  956. String carNo = tbBusinessCar.getCarNo();
  957. String carStr = StrUtil.sub(carNo, 0, 1);
  958. return !CAR_LIST.contains(carStr);
  959. }).map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  960. tbBusiness.setChinaCarNo(chinaCarNo);
  961. tbBusiness.setCardNo(yueCarNo);
  962. this.updateById(tbBusiness);
  963. businessCarIdList.forEach(businessCarId -> {
  964. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  965. relationBusinessCar.setBusinessCarId(businessCarId).setBusinessId(businessId);
  966. relationBusinessCarService.save(relationBusinessCar);
  967. });
  968. }
  969. private void checkOtherBusiness(String itemTypeId, String operateTimeStr, String businessId, String carNo) {
  970. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  971. TbBusinessSort sort = tbBusinessSortService.findByItemTypeId(itemTypeId);
  972. if (sort == null) {
  973. return;
  974. }
  975. List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sort.getGroupId());
  976. LocalDateTime operateTime = LocalDateTime.parse(operateTimeStr, formatter);
  977. int i = 0;
  978. for (TbBusinessSort tbBusinessSort : sorts) {
  979. if (i == 0 && StrUtil.equals(tbBusinessSort.getTypeId(), itemTypeId) && sorts.size() > 1) {
  980. TbBusinessSort afterItem = sorts.get(i + 1);
  981. String typeId = afterItem.getTypeId();
  982. Integer interval = afterItem.getIntervalTime();
  983. LocalDateTime endTime = operateTime.plusMinutes(interval);
  984. if (afterItem.getIntervalTime() > 0) {
  985. int count = this.checkCarBusinessType(typeId, carNo, endTime.format(formatter), 1);
  986. if (count > 0) {
  987. throw new BusinessException("车辆:[" + carNo + "]" + tbBusinessSort.getTypeName() + "后" + afterItem.getIntervalTime() + "分钟才可以执行" + afterItem.getTypeName());
  988. }
  989. }
  990. }
  991. if (i > 0 && StrUtil.equals(tbBusinessSort.getTypeId(), itemTypeId)) {
  992. TbBusinessSort beforeItem = sorts.get(i - 1);
  993. String typeId = beforeItem.getTypeId();
  994. Integer interval = tbBusinessSort.getIntervalTime();
  995. LocalDateTime endTime = operateTime.minusMinutes(interval);
  996. if (tbBusinessSort.getIntervalTime() > 0) {
  997. int count = this.checkCarBusinessType(typeId, carNo, endTime.format(formatter), 0);
  998. if (count > 0) {
  999. throw new BusinessException("车辆:[" + carNo + "]" + beforeItem.getTypeName() + "后" + tbBusinessSort.getIntervalTime() + "分钟才可以执行" + tbBusinessSort.getTypeName());
  1000. }
  1001. }
  1002. }
  1003. Integer singleIntervalTime = tbBusinessSort.getSingleIntervalTime();
  1004. String timeStart = operateTime.minusHours(singleIntervalTime).format(formatter);
  1005. String timeEnd = operateTime.plusHours(singleIntervalTime).format(formatter);
  1006. int count = this.checkCarBusinessType(itemTypeId, carNo, timeStart, timeEnd, businessId);
  1007. if (count > 0) {
  1008. throw new BusinessException("车辆:[" + carNo + "]" + singleIntervalTime + "小时内已有相同作业");
  1009. }
  1010. i++;
  1011. }
  1012. }
  1013. public TbBusiness findByDeclareNo(String declareNo) {
  1014. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  1015. ew.eq("declare_no", declareNo).orderByDesc("id");
  1016. List<TbBusiness> list = this.list(ew);
  1017. return list.isEmpty() ? null : list.get(0);
  1018. }
  1019. /**
  1020. * 选择异常单发送
  1021. *
  1022. * @param errorBusinessBO
  1023. * @param isAdmin 是否管理员
  1024. */
  1025. public void selectErrorBusiness(ErrorBusinessBO errorBusinessBO, boolean isAdmin) {
  1026. log.info("is admin :{}", isAdmin);
  1027. TbBusiness tbBusiness = getById(errorBusinessBO.getId());
  1028. if (tbBusiness == null) {
  1029. throw new AjaxError("业务已被删除");
  1030. }
  1031. String businessId = tbBusiness.getId();
  1032. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(businessId);
  1033. tbBusiness.setPayStatus(errorBusinessBO.getPayStatus())
  1034. .setSupplement(1)
  1035. .setSupplementBy(errorBusinessBO.getSupplementBy())
  1036. .setSupplementTime(new Date())
  1037. .setSupplementReason(errorBusinessBO.getSupplementReason());
  1038. if (PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode() == errorBusinessBO.getPayStatus()) {
  1039. tbBusiness.setPayMoney(tbBusiness.getItemPrice())
  1040. .setPayTime(errorBusinessBO.getPayTime());
  1041. items.forEach(item -> item.setPayTime(errorBusinessBO.getPayTime()).setPayStatus(1));
  1042. tbBusinessItemService.updateBatchById(items);
  1043. }
  1044. List<TbBusinessCar> tbBusinessCars = errorBusinessBO.getCars();
  1045. tbBusinessCars.forEach(this::handlerCarPay);
  1046. tbBusinessCarService.updateBatchById(tbBusinessCars);
  1047. if (isAdmin) {
  1048. //发起审批
  1049. sendOA(tbBusiness, items, tbBusinessCars, errorBusinessBO.getSupplementBy());
  1050. }
  1051. this.updateById(tbBusiness);
  1052. }
  1053. /**
  1054. * 处理车辆支付
  1055. *
  1056. * @param tbBusinessCar
  1057. */
  1058. private void handlerCarPay(TbBusinessCar tbBusinessCar) {
  1059. String carNo = tbBusinessCar.getCarNo();
  1060. String payType = tbBusinessCar.getPayType();
  1061. Date payTime = tbBusinessCar.getPayTime();
  1062. Date inTime = tbBusinessCar.getRealInTime();
  1063. if (inTime == null) {
  1064. throw new AjaxError(carNo + "入场时间不能为空");
  1065. }
  1066. Date outTime = tbBusinessCar.getRealOutTime();
  1067. if (outTime == null) {
  1068. throw new AjaxError(carNo + "离场时间不能为空");
  1069. }
  1070. if (payType.equals(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType())) {
  1071. if (payTime == null) {
  1072. throw new AjaxError(carNo + "支付时间不能为空");
  1073. }
  1074. outTime = payTime;
  1075. }
  1076. //计算停车费
  1077. IOrderPriceRes parkMoney = this.getPartMoney(inTime, outTime, tbBusinessCar.getCarNo(), tbBusinessCar.getColor());
  1078. tbBusinessCar.setMoney(parkMoney.getTotalOrderPrice());
  1079. }
  1080. /**
  1081. * 发起流程审批
  1082. *
  1083. * @param tbBusiness
  1084. * @param items
  1085. * @param tbBusinessCars
  1086. * @param sendBy
  1087. */
  1088. private void sendOA(TbBusiness tbBusiness, List<TbBusinessItem> items, List<TbBusinessCar> tbBusinessCars, String sendBy) {
  1089. if (!oaConfig.isEnable()) {
  1090. return;
  1091. }
  1092. ParamsBO paramsBO = buildParams(tbBusiness, items, tbBusinessCars);
  1093. String json = JSONUtil.toJsonStr(paramsBO);
  1094. log.info("构建流程表单数据:{}", json);
  1095. String resp = HttpUtil.createPost(oaConfig.getUrl())
  1096. .timeout(2000).setReadTimeout(3000).body(json)
  1097. .execute().body();
  1098. log.info("请求返回:{}", resp);
  1099. OAResultBO oaResultBO = JSONUtil.toBean(resp, OAResultBO.class);
  1100. if (oaResultBO.getSuccess() && oaResultBO.getCode() == 200) {
  1101. String fdId = oaResultBO.getData().getFdId();
  1102. if (StrUtil.isEmpty(fdId)) {
  1103. throw new BusinessException("流程发起失败");
  1104. }
  1105. tbBusiness.setSendOa(1).setOaResult(OAResultEnum.JUDGE_ING.getCode())
  1106. .setSendTime(new Date()).setSendBy(sendBy)
  1107. .setOaFdId(fdId);
  1108. this.updateById(tbBusiness);
  1109. } else {
  1110. throw new BusinessException(oaResultBO.getMessage());
  1111. }
  1112. }
  1113. /**
  1114. * 构建表单数据
  1115. *
  1116. * @param tbBusiness
  1117. * @param items
  1118. * @param tbBusinessCars
  1119. * @return
  1120. */
  1121. private ParamsBO buildParams(TbBusiness tbBusiness, List<TbBusinessItem> items, List<TbBusinessCar> tbBusinessCars) {
  1122. String operator = tbBusiness.getSupplementBy();
  1123. String reason = tbBusiness.getSupplementReason();
  1124. ParamsBO paramsBO = new ParamsBO();
  1125. paramsBO.setRequestId(System.currentTimeMillis() + "")
  1126. .setBusinessSystemCode(oaConfig.getSystemCode());
  1127. ParamsBO.DataBO dataBO = new ParamsBO.DataBO();
  1128. String project = tbBusiness.getGoodsName();
  1129. JSONObject docCreator = new JSONObject();
  1130. docCreator.set("PersonNo", oaConfig.getPersonNo());
  1131. dataBO.setOperationalProject(project)
  1132. .setOperationalPerson(operator).setOperationalReason(reason)
  1133. .setDocSubject(project + "补单流程").setFdTemplateId(oaConfig.getTemplateId()).setDocCreator(JSONUtil.toJsonStr(docCreator));
  1134. //基础信息
  1135. JSONObject formValues = buildFormValues(tbBusiness);
  1136. //车辆信息
  1137. buildCarParams(tbBusinessCars, formValues);
  1138. //业务项信息
  1139. buildItemPrams(items, formValues);
  1140. dataBO.setFormValues(formValues.toJSONString(0));
  1141. paramsBO.setData(dataBO);
  1142. return paramsBO;
  1143. }
  1144. /**
  1145. * 构建业务项
  1146. *
  1147. * @param items
  1148. * @return
  1149. */
  1150. private void buildItemPrams(List<TbBusinessItem> items, JSONObject formValues) {
  1151. List<String> itemTypeNameList = new ArrayList<>();
  1152. List<String> itemNameList = new ArrayList<>();
  1153. List<String> itemPriceList = new ArrayList<>();
  1154. List<String> unitList = new ArrayList<>();
  1155. List<String> numList = new ArrayList<>();
  1156. List<String> payStatusList = new ArrayList<>();
  1157. List<String> payTimeList = new ArrayList<>();
  1158. List<String> remarkList = new ArrayList<>();
  1159. double total = items.stream().collect(Collectors.summarizingDouble(item -> item.getItemPrice().doubleValue())).getSum();
  1160. items.forEach(item -> {
  1161. itemTypeNameList.add(item.getItemTypeName());
  1162. itemNameList.add(item.getItemName());
  1163. itemPriceList.add(item.getItemPrice().toString());
  1164. unitList.add(item.getUnit());
  1165. numList.add(item.getNum());
  1166. payStatusList.add(item.getPayStatus() == 1 ? "已支付" : "未支付");
  1167. payTimeList.add(item.getPayTime() == null ? "" : DateUtil.format(item.getPayTime(), "yyyy-MM-dd HH:mm:ss"));
  1168. remarkList.add(StrUtil.isEmpty(item.getRemark()) ? "-" : item.getRemark());
  1169. });
  1170. formValues
  1171. .set("specificBusinessItems.chargingItem", itemTypeNameList)
  1172. .set("specificBusinessItems.chargeDetail", itemNameList)
  1173. .set("specificBusinessItems.unitPrice", itemPriceList)
  1174. .set("specificBusinessItems.chargingStandard", unitList)
  1175. .set("specificBusinessItems.quantity", numList)
  1176. .set("specificBusinessItems.payoutStatus", payStatusList)
  1177. .set("specificBusinessItems.payTime", payTimeList)
  1178. .set("specificBusinessItems.total", Collections.singleton(total))
  1179. .set("specificBusinessItems.note", remarkList);
  1180. }
  1181. /**
  1182. * 构建基础信息
  1183. *
  1184. * @param tbBusiness
  1185. * @return
  1186. */
  1187. private JSONObject buildFormValues(TbBusiness tbBusiness) {
  1188. ParamsBO.DataBO.FormValuesBO formValuesBO = new ParamsBO.DataBO.FormValuesBO();
  1189. String project = tbBusiness.getGoodsName();
  1190. formValuesBO.setOperationalProject(project).setWorkingTime(tbBusiness.getOperateTime()).setCustomerName(tbBusiness.getCustomerName())
  1191. .setOperatingOutlay(tbBusiness.getItemPrice().toString()).setAmount(tbBusiness.getItemPrice())
  1192. .setPaymentTime(tbBusiness.getPayTime() == null ? "" : DateUtil.format(tbBusiness.getPayTime(), "yyyy-MM-dd HH:mm:ss")).setCargoOwner(tbBusiness.getOwner()).setOperationNo(tbBusiness.getNo())
  1193. .setRecordingTime(DateUtil.format(tbBusiness.getCreateTime(), "yyyy-MM-dd HH:mm:ss")).setRecorder(tbBusiness.getCreateBy())
  1194. .setIsPay(PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode() == tbBusiness.getPayStatus() ? "已支付" : "未支付");
  1195. return JSONUtil.parseObj(formValuesBO);
  1196. }
  1197. /**
  1198. * 构建车辆表单
  1199. *
  1200. * @param tbBusinessCars
  1201. * @return
  1202. */
  1203. private void buildCarParams(List<TbBusinessCar> tbBusinessCars, JSONObject jsonObject) {
  1204. List<String> carNoList = new ArrayList<>();
  1205. List<String> typeList = new ArrayList<>();
  1206. List<String> loadList = new ArrayList<>();
  1207. List<String> unitsList = new ArrayList<>();
  1208. List<String> payStatusList = new ArrayList<>();
  1209. List<String> carStatusList = new ArrayList<>();
  1210. List<String> feeList = new ArrayList<>();
  1211. List<String> inList = new ArrayList<>();
  1212. List<String> outList = new ArrayList<>();
  1213. tbBusinessCars.forEach(tbBusinessCar -> {
  1214. carNoList.add(tbBusinessCar.getCarNo());
  1215. typeList.add(tbBusinessCar.getCarType());
  1216. loadList.add(tbBusinessCar.getNetWeight());
  1217. Double carSize = tbBusinessCar.getCarSize();
  1218. unitsList.add(carSize == null ? "-" : carSize.toString());
  1219. payStatusList.add(tbBusinessCar.getPayType());
  1220. carStatusList.add(tbBusinessCar.getIsLock() == 1 ? "正常" : "锁定");
  1221. feeList.add(tbBusinessCar.getMoney() == null ? "-" : tbBusinessCar.getMoney().toString());
  1222. inList.add(tbBusinessCar.getRealInTime() == null ? "-" : DateUtil.format(tbBusinessCar.getRealInTime(), "yyyy-MM-dd HH:mm:ss"));
  1223. outList.add(tbBusinessCar.getRealOutTime() == null ? "-" : DateUtil.format(tbBusinessCar.getRealOutTime(), "yyyy-MM-dd HH:mm:ss"));
  1224. });
  1225. jsonObject
  1226. .set("vehicleInfo.licenseNo", carNoList)
  1227. .set("vehicleInfo.type", typeList)
  1228. .set("vehicleInfo.load", loadList)
  1229. .set("vehicleInfo.specifications", unitsList)
  1230. .set("vehicleInfo.paymentStatus", payStatusList)
  1231. .set("vehicleInfo.vehicleState", carStatusList)
  1232. .set("vehicleInfo.parkingFee", feeList)
  1233. .set("vehicleInfo.entryTime", inList)
  1234. .set("vehicleInfo.departureTime", outList);
  1235. }
  1236. //添加异常单
  1237. public void addErrorBusiness(ErrorBusinessBO errorBusinessBO, boolean isAdmin) {
  1238. List<TbItem> tbItems = errorBusinessBO.getItems();
  1239. if (tbItems.isEmpty()) {
  1240. throw new BusinessException("请选择明细");
  1241. }
  1242. List<TbBusinessCar> cars = errorBusinessBO.getCars();
  1243. if (cars.isEmpty()) {
  1244. throw new BusinessException("作业车辆不能为空");
  1245. }
  1246. Date now = new Date();
  1247. if (errorBusinessBO.getCreateTime() != null) {
  1248. now = errorBusinessBO.getCreateTime();
  1249. }
  1250. TbGoods tbGoods = tbGoodsService.getById(errorBusinessBO.getGoodsId());
  1251. TbBusiness tbBusiness = new TbBusiness();
  1252. String customerId = errorBusinessBO.getCustomerId();
  1253. tbBusiness.setCreateBy(StpUserUtil.getCreateBy())
  1254. .setPayStep(tbGoods.getPayStep());
  1255. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  1256. if (tbCostomer != null) {
  1257. tbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
  1258. }
  1259. boolean businessIsPay = PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode() == errorBusinessBO.getPayStatus();
  1260. Date businessPayTime = errorBusinessBO.getPayTime();
  1261. BigDecimal price = new BigDecimal("0");
  1262. List<TbBusinessItem> itemList = new ArrayList<>();
  1263. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
  1264. if (StrUtil.isNotEmpty(errorBusinessBO.getNo())) {
  1265. no = errorBusinessBO.getNo();
  1266. }
  1267. int index = 1;
  1268. //作业项目
  1269. for (TbItem tbItem : tbItems) {
  1270. TbItem db = tbItemService.getById(tbItem.getId());
  1271. TbBusinessItem tbBusinessItem = new TbBusinessItem();
  1272. int num = tbItem.getNum();
  1273. String typeId = tbItem.getTypeId();
  1274. TbItemType tbItemType = tbItemTypeService.getById(typeId);
  1275. BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
  1276. tbBusinessItem.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
  1277. .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2))
  1278. .setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId())
  1279. .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
  1280. .setItemTypeId(typeId).setItemTypeName(tbItemType.getName())
  1281. .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
  1282. price = price.add(itemTotalPrice);
  1283. if (businessIsPay) {
  1284. tbBusinessItem.setPayTime(businessPayTime)
  1285. .setPayStatus(1);
  1286. }
  1287. itemList.add(tbBusinessItem);
  1288. index++;
  1289. }
  1290. String declareNo = errorBusinessBO.getDeclareNo();
  1291. tbBusiness.setCardSize(errorBusinessBO.getCarSize()).setNetWeight(errorBusinessBO.getNetWeight()).setTransactionId(errorBusinessBO.getTransactionId())
  1292. .setOperator(errorBusinessBO.getOperator()).setOperateTime(errorBusinessBO.getOperateTime())
  1293. .setNo(no).setGoodsName(tbGoods.getName()).setGoodsId(errorBusinessBO.getGoodsId())
  1294. .setSupplementReason(errorBusinessBO.getSupplementReason()).setSupplementTime(now)
  1295. .setSupplementBy(errorBusinessBO.getSupplementBy()).setSupplement(1).setPayStatus(errorBusinessBO.getPayStatus())
  1296. .setPayStep(tbGoods.getPayStep()).setDeclareNo(declareNo).setCardNo(errorBusinessBO.getCardNo());
  1297. tbBusiness.setCreateTime(now).setCreateByCustomerId(StpUserUtil.getCustomerId())
  1298. .setItemPrice(price).setTotalMoney(price).setOwner(errorBusinessBO.getOwner());
  1299. tbBusiness.setChinaCarNo(errorBusinessBO.getChinaCarNo());
  1300. if (businessIsPay) {//如果已支付
  1301. tbBusiness.setPayMoney(tbBusiness.getItemPrice())
  1302. .setPayTime(businessPayTime);
  1303. }
  1304. this.save(tbBusiness);
  1305. String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
  1306. //业务车
  1307. for (TbBusinessCar car : cars) {
  1308. String carNo = car.getCarNo().trim().toUpperCase();
  1309. String carType = car.getCarType();
  1310. if (StrUtil.isEmpty(carType)) {
  1311. throw new BusinessException(carNo + "类型不能为空");
  1312. }
  1313. car.setCreateTime(now).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
  1314. TbCar tbCar = tbCarService.findByCardNo(carNo);
  1315. if (tbCar != null) {
  1316. car.setCarCompany(tbCar.getCustomerName());
  1317. if (!TbCar.CarTypeEnum.BUSINESS_CAR.getType().equals(tbCar.getCarType())) {
  1318. car.setPayType(CarEnum.PayTypeEnum.FEE_TYPE.getType());
  1319. }
  1320. }
  1321. car.setCarNo(carNo).setIsLock(0);
  1322. car.setCarSize(car.getCarSize())
  1323. .setTimeUpdate(now).setCarType(car.getCarType())
  1324. .setNetWeight(car.getNetWeight())
  1325. .setCustomerId(customerId)
  1326. .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  1327. //新增放行记录
  1328. tbBusinessCarService.save(car);
  1329. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  1330. relationBusinessCar.setBusinessId(tbBusiness.getId()).setBusinessCarId(car.getId());
  1331. relationBusinessCarService.save(relationBusinessCar);
  1332. }
  1333. if (StrUtil.isNotEmpty(declareNo)) {
  1334. TbDeclare declare = tbDeclareService.findByDeclareNo(declareNo);
  1335. declare.setBusinessId(tbBusiness.getId());
  1336. tbDeclareService.updateById(declare);
  1337. }
  1338. itemList.forEach(tbBusinessItem -> tbBusinessItem.setBusinessId(tbBusiness.getId()));
  1339. tbBusinessItemService.saveBatch(itemList);
  1340. if (isAdmin) {
  1341. sendOA(tbBusiness, itemList, cars, errorBusinessBO.getSupplementBy());
  1342. }
  1343. }
  1344. /**
  1345. * 单独发起审批
  1346. *
  1347. * @param id
  1348. */
  1349. public void applyOA(String id, String sendBy) {
  1350. log.info("发起流程:{},{}", id, sendBy);
  1351. TbBusiness tbBusiness = this.getById(id);
  1352. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
  1353. List<TbBusinessCar> tbBusinessCars = tbBusinessCarService.findOtherBusinessCar(id);
  1354. sendOA(tbBusiness, items, tbBusinessCars, sendBy);
  1355. this.updateById(tbBusiness);
  1356. }
  1357. /**
  1358. * 编辑异常单
  1359. *
  1360. * @param errorBusinessBO
  1361. */
  1362. public void editErrorBusiness(ErrorBusinessBO errorBusinessBO) {
  1363. String id = errorBusinessBO.getId();
  1364. TbBusiness dbBusiness = this.getById(id);
  1365. if (dbBusiness == null) {
  1366. throw new BusinessException("记录不存在");
  1367. }
  1368. if (!(dbBusiness.getSendOa() == 0 || OAResultEnum.NO_PASS.getCode().equals(dbBusiness.getOaResult()))) {
  1369. throw new BusinessException("业务单正在审核,无法修改");
  1370. }
  1371. List<TbItem> tbItems = errorBusinessBO.getItems();
  1372. if (tbItems.isEmpty()) {
  1373. throw new BusinessException("请选择收费明细");
  1374. }
  1375. List<TbBusinessCar> cars = errorBusinessBO.getCars();
  1376. if (cars.isEmpty()) {
  1377. throw new BusinessException("作业车辆不能为空");
  1378. }
  1379. this.removeById(id);
  1380. tbBusinessItemService.removeByBusinessId(id);
  1381. tbBusinessCarService.removeByBusinessId(id);
  1382. relationBusinessCarService.removeByBusinessId(id);
  1383. errorBusinessBO.setNo(dbBusiness.getNo()).setCreateTime(dbBusiness.getCreateTime());
  1384. this.addErrorBusiness(errorBusinessBO, false);
  1385. }
  1386. /**
  1387. * oa审批回调
  1388. *
  1389. * @param callbackBO
  1390. */
  1391. public void approveCallback(CallbackBO callbackBO) {
  1392. String fdId = callbackBO.getFdId();
  1393. TbBusiness tbBusiness = this.findByFdId(fdId);
  1394. if (tbBusiness == null) {
  1395. throw new AjaxError("流程不存在");
  1396. }
  1397. String result = callbackBO.getAuditResult();
  1398. tbBusiness.setOaResult(callbackBO.getAuditResult()).setOaContent(callbackBO.getRefuseReason())
  1399. .setOaJudgeTime(new Date());
  1400. this.updateById(tbBusiness);
  1401. String businessId = tbBusiness.getId();
  1402. if (StrUtil.contains(result, "通过") && pushfeeConfig.isEnable()) {
  1403. //todo 审批通过-==>已支付的生成明细===>推送订单到计费系统
  1404. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(businessId);
  1405. String transactionId = tbBusiness.getTransactionId();
  1406. Date payTime = tbBusiness.getPayTime();
  1407. String outTradeNo = "of" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
  1408. //已经支付了的
  1409. List<PriceBO> priceBOList = cars.stream().filter(tbBusinessCar -> tbBusinessCar.getPayTime() != null).
  1410. map(tbBusinessCar -> {
  1411. PriceBO priceBO = new PriceBO();
  1412. priceBO.setId(tbBusinessCar.getId()).setP(tbBusinessCar.getMoney());
  1413. return priceBO;
  1414. }).
  1415. collect(Collectors.toList());
  1416. if (!priceBOList.isEmpty()) {
  1417. tbFeeDetailsService.chargeParkFee(priceBOList, transactionId, outTradeNo, payTime, PayEnum.PayType.OFF_LINE_PAY);//添加cars的收费明细
  1418. }
  1419. if (tbBusiness.getPayStatus() == PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode()) {
  1420. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(businessId);
  1421. tbFeeDetailsService.chargeBusinessFee(items, transactionId, outTradeNo, payTime, PayEnum.PayType.OFF_LINE_PAY);//添加items的收费明细
  1422. }
  1423. }
  1424. }
  1425. /**
  1426. * 根据流程ID查询
  1427. *
  1428. * @param fdId
  1429. * @return
  1430. */
  1431. private TbBusiness findByFdId(String fdId) {
  1432. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  1433. ew.lambda().eq(TbBusiness::getOaFdId, fdId);
  1434. return getOne(ew);
  1435. }
  1436. public TbBusiness findByNo(String no) {
  1437. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  1438. ew.eq("no", no);
  1439. return this.getOne(ew);
  1440. }
  1441. /**
  1442. * 额外添加车牌
  1443. *
  1444. * @param tbBusinessCar
  1445. */
  1446. public void addBusinessCar(TbBusinessCar tbBusinessCar) {
  1447. String businessId = tbBusinessCar.getBusinessId();
  1448. TbBusiness tbBusiness = this.getById(businessId);
  1449. if (tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
  1450. throw new AjaxError("业务已审核,不能绑定新车辆");
  1451. }
  1452. String carNo = tbBusinessCar.getCarNo().trim().toUpperCase();
  1453. TbBusinessCar lastRecord = tbBusinessCarService.findTheLastRecord(carNo);
  1454. String businessCarId;
  1455. Date now = new Date();
  1456. if (lastRecord == null || lastRecord.getRealOutTime() != null) {
  1457. //不存在或者已经离场
  1458. tbBusinessCar
  1459. .setBusinessType(CarEnum.BusinessTypeEnum.BUSINESS_CAR.getType())
  1460. .setCarNo(carNo).setPay(0).setIsLock(0).setPayUnloadMoney(0)
  1461. .setPayType(CarEnum.PayTypeEnum.NO_PAY_TYPE.getType()).setPay(0)
  1462. .setCreateTime(now).setCarType(CarEnum.CarTypeEnum.EMPTY_TYPE.getType())
  1463. .setTimeUpdate(now)
  1464. .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_NEED_JUDGE.getCode())
  1465. .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  1466. tbBusinessCarService.save(tbBusinessCar);
  1467. businessCarId = tbBusinessCar.getId();
  1468. } else {
  1469. businessCarId = lastRecord.getId();
  1470. lastRecord.setPayType(CarEnum.PayTypeEnum.NO_PAY_TYPE.getType())
  1471. .setCustomerId(tbBusiness.getCustomerId())
  1472. .setCarNo(carNo).setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode())
  1473. .setPayUnloadMoney(lastRecord.getPayUnloadMoney())
  1474. .setTimeUpdate(now)
  1475. .setBusinessType(CarEnum.BusinessTypeEnum.BUSINESS_CAR.getType());
  1476. tbBusinessCarService.updateById(lastRecord);
  1477. }
  1478. tbBusiness.setCardNo(tbBusiness.getCardNo() + "、" + carNo);
  1479. this.updateById(tbBusiness);
  1480. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  1481. relationBusinessCar.setBusinessId(businessId).setBusinessCarId(businessCarId);
  1482. relationBusinessCarService.save(relationBusinessCar);
  1483. }
  1484. /**
  1485. * 删除业务车
  1486. *
  1487. * @param carId
  1488. * @param businessId
  1489. */
  1490. public void deleteBusinessCar(String carId, String businessId) {
  1491. relationBusinessCarService.removeByBusinessIdAndCarId(businessId, carId);
  1492. List<RelationBusinessCar> list = relationBusinessCarService.findByBusinessCarId(carId);
  1493. if (list.isEmpty()) {
  1494. TbBusinessCar db = tbBusinessCarService.getById(carId);
  1495. if (db.getRealInTime() == null) {
  1496. tbBusinessCarService.removeById(carId);
  1497. }
  1498. }
  1499. }
  1500. /**
  1501. * 审核通过
  1502. * @param id
  1503. */
  1504. public void confirmJudgePass(String id) {
  1505. TbBusiness tbBusiness = this.getById(id);
  1506. if (tbBusiness == null) {
  1507. throw new AjaxError("业务不存在");
  1508. }
  1509. Date now = new Date();
  1510. List<TbBusinessCar> tbBusinessCars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
  1511. //审核
  1512. List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findByBusinessId(tbBusiness.getId());
  1513. String customerId = tbBusiness.getPickCustomerId();
  1514. TbAccount tbAccount = tbAccountService.getAccountByCustomerId(customerId);
  1515. for (TbBusinessCar tbBusinessCar : tbBusinessCars) {
  1516. for (TbBusinessItem item : tbBusinessItems) {
  1517. String itemName = item.getItemName();
  1518. // todo 扣除 人工、机械装卸车辆---->每辆车都要支付----->
  1519. if (SystemObject.config.getEveryCarPay().contains(itemName) && tbBusinessCar.getPayUnloadMoney() == 0) {
  1520. List<IOrderItem> expenses = new ArrayList<>();
  1521. IOrderItem orderItem = new IOrderItem();
  1522. orderItem.setExpenseNum(Integer.parseInt(item.getNum()))
  1523. .setUniqExpenseId(item.getItemCode());
  1524. expenses.add(orderItem);
  1525. IOrderPriceRes res = syncService.orderPriceCal(expenses);
  1526. BigDecimal price = res.getTotalOrderPrice();
  1527. BigDecimal balance = tbAccount.getTotalMoney();
  1528. if (price.compareTo(balance) > 0) {
  1529. throw new AjaxError("[" + tbAccount.getCustomerName() + "]账户余额不足扣除" + item.getItemName());
  1530. } else {
  1531. tbBusinessCar.setPayUnloadMoney(1);
  1532. tbBusinessCarService.updateById(tbBusinessCar);
  1533. item.setPayTime(now).setPayStatus(1).setPayType(PayEnum.PayType.PER_PAY.getCode())
  1534. .setPayTypeName(PayEnum.PayType.PER_PAY.getDesc());
  1535. tbBusinessItemService.updateById(item);
  1536. tbBusiness.setPayMoney(price.add(tbBusiness.getPayMoney()));
  1537. BigDecimal afterBalance = balance.subtract(price);
  1538. tbAccount.setTotalMoney(afterBalance);//增加累计扣款
  1539. tbAccountService.updateById(tbAccount);
  1540. TbFeeDetails details = tbFeeDetailsService.savePrePayDetails(res, item, tbBusinessCar, tbBusiness, FeeTypeEnum.STEVEDORE_FEE);
  1541. tbFeeStatisticsService.addOrUpdateStatistic(now, PayEnum.PayType.PER_PAY.getCode());//更新当前日期的日统计
  1542. TbDeductionRecord record= automaticPay.createTbDeductionRecord(details, balance, afterBalance, tbBusiness.getPickCustomerId(), tbBusiness.getPickCustomerName(), tbBusinessCar.getCarNo(), tbBusinessCar.getId(), FeeTypeEnum.STEVEDORE_FEE);
  1543. addInvoiceOrder(tbBusiness, res.getTotalOrderPrice(),details,record);
  1544. }
  1545. }
  1546. }
  1547. }
  1548. //其他费项 装卸业务管理费” 进行预存款扣除
  1549. for (TbBusinessItem item : tbBusinessItems) {
  1550. //业务类型是装卸业务管理费且未支付的进行扣款
  1551. if (item.getPayStatus() == 0 && SystemObject.config.getUnLoadItem().contains(item.getItemTypeName())) {
  1552. List<IOrderItem> expenses = new ArrayList<>();
  1553. IOrderItem orderItem = new IOrderItem();
  1554. orderItem.setExpenseNum(Integer.parseInt(item.getNum()))
  1555. .setUniqExpenseId(item.getItemCode());
  1556. expenses.add(orderItem);
  1557. IOrderPriceRes res = syncService.orderPriceCal(expenses);
  1558. BigDecimal price = res.getTotalOrderPrice();
  1559. BigDecimal balance = tbAccount.getTotalMoney();
  1560. if (price.compareTo(balance) > 0) {
  1561. throw new AjaxError("[" + tbAccount.getCustomerName() + "]账户余额不足扣除" + item.getItemName());
  1562. } else {
  1563. BigDecimal afterBalance = balance.subtract(price);
  1564. tbAccount.setTotalMoney(afterBalance);//增加累计扣款
  1565. tbAccountService.updateById(tbAccount);
  1566. item.setPayTime(now).setPayStatus(1).setPayType(PayEnum.PayType.PER_PAY.getCode())
  1567. .setPayTypeName(PayEnum.PayType.PER_PAY.getDesc());
  1568. tbBusinessItemService.updateById(item);
  1569. tbBusiness.setPayMoney(price.add(tbBusiness.getPayMoney()));
  1570. //查找越南车--->统计以
  1571. TbBusinessCar tbBusinessCar = tbBusinessCars.stream().filter(car -> !CAR_LIST.contains(car.getCarNo().substring(0, 1)))
  1572. .findAny().orElse(tbBusinessCars.get(0));
  1573. TbFeeDetails details = tbFeeDetailsService.savePrePayDetails(res, item, tbBusinessCar, tbBusiness, FeeTypeEnum.STEVEDORE_FEE);
  1574. tbFeeStatisticsService.addOrUpdateStatistic(now, PayEnum.PayType.PER_PAY.getCode());//更新当前日期的日统计
  1575. TbDeductionRecord record= automaticPay.createTbDeductionRecord(details, balance, afterBalance, tbBusiness.getPickCustomerId(), tbBusiness.getPickCustomerName(), tbBusinessCar.getCarNo(), tbBusinessCar.getId(), FeeTypeEnum.STEVEDORE_FEE);
  1576. addInvoiceOrder(tbBusiness, res.getTotalOrderPrice(),details,record);
  1577. }
  1578. }
  1579. }
  1580. tbBusiness.setConfirmJudgeTime(now).setConfirmJudgeContent("审核通过")
  1581. .setConfirmJudge(CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode())
  1582. .setJudgeBy(StpUserUtil.getCreateBy()).setPayTime(now);
  1583. this.updateById(tbBusiness);
  1584. }
  1585. /**
  1586. * 添加开票订单
  1587. * @param tbBusiness
  1588. * @param billMoney
  1589. */
  1590. private void addInvoiceOrder(TbBusiness tbBusiness, BigDecimal billMoney,TbFeeDetails details,TbDeductionRecord record) {
  1591. TbInvoiceOrder t = new TbInvoiceOrder();
  1592. t.setBusinessName(tbBusiness.getGoodsName())
  1593. .setBusinessNo(tbBusiness.getNo())
  1594. .setCarNo(tbBusiness.getCarNoStr())
  1595. .setBusinessId(tbBusiness.getId())
  1596. .setCustomerId(tbBusiness.getCustomerId())
  1597. .setBillMoney(billMoney).setDetailId(details.getId())
  1598. .setPreOrderNum(details.getPreOrderNum())
  1599. .setDeductionRecordId(record.getId())
  1600. .setStatus(0).setCreateTime(new Date());
  1601. tbInvoiceOrderService.save(t);
  1602. }
  1603. /**
  1604. * 审核驳回
  1605. * @param id
  1606. * @param judgeContent
  1607. */
  1608. public void callback(String id, String judgeContent) {
  1609. TbBusiness db = this.getById(id);
  1610. db.setConfirmJudge(CarEnum.ConfirmJudgeEnum.CALL_BACK.getCode())
  1611. .setConfirmJudgeContent(judgeContent).setConfirmJudgeTime(new Date())
  1612. .setJudgeBy(StpUserUtil.getCreateBy());
  1613. this.updateById(db);
  1614. }
  1615. }