TbBusinessService.java 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. package com.pj.project.tb_business;
  2. import java.math.BigDecimal;
  3. import java.time.LocalDateTime;
  4. import java.time.ZoneId;
  5. import java.time.format.DateTimeFormatter;
  6. import java.time.temporal.ChronoUnit;
  7. import java.util.*;
  8. import java.util.stream.Collectors;
  9. import cn.hutool.core.date.DateUtil;
  10. import cn.hutool.core.util.NumberUtil;
  11. import cn.hutool.core.util.RandomUtil;
  12. import cn.hutool.core.util.StrUtil;
  13. import cn.hutool.http.HttpUtil;
  14. import cn.hutool.json.JSONObject;
  15. import cn.hutool.json.JSONUtil;
  16. import cn.hutool.log.StaticLog;
  17. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  18. import com.baomidou.mybatisplus.extension.service.IService;
  19. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  20. import com.google.gson.JsonObject;
  21. import com.pj.api.wx.bo.MsgDataBO;
  22. import com.pj.api.wx.service.WxService;
  23. import com.pj.constants.UserTypeEnum;
  24. import com.pj.current.config.*;
  25. import com.pj.current.satoken.StpUserUtil;
  26. import com.pj.project.oa.bo.OAResultBO;
  27. import com.pj.project.oa.bo.ParamsBO;
  28. import com.pj.project.relation_business_car.RelationBusinessCar;
  29. import com.pj.project.relation_business_car.RelationBusinessCarService;
  30. import com.pj.project.relation_type_item.RelationTypeItemService;
  31. import com.pj.project.tb_business_car.TbBusinessCar;
  32. import com.pj.project.tb_business_car.TbBusinessCarService;
  33. import com.pj.project.tb_business_item.TbBusinessItem;
  34. import com.pj.project.tb_business_item.TbBusinessItemService;
  35. import com.pj.project.tb_business_people.TbBusinessPeople;
  36. import com.pj.project.tb_business_people.TbBusinessPeopleService;
  37. import com.pj.project.tb_business_sort.TbBusinessSort;
  38. import com.pj.project.tb_business_sort.TbBusinessSortService;
  39. import com.pj.project.tb_car.TbCar;
  40. import com.pj.project.tb_car.TbCarService;
  41. import com.pj.project.tb_car_no_color.TbCarNoColor;
  42. import com.pj.project.tb_car_no_color.TbCarNoColorService;
  43. import com.pj.project.tb_costomer.TbCostomer;
  44. import com.pj.project.tb_costomer.TbCostomerService;
  45. import com.pj.project.tb_declare.TbDeclare;
  46. import com.pj.project.tb_declare.TbDeclareService;
  47. import com.pj.project.tb_driver.TbDriver;
  48. import com.pj.project.tb_driver.TbDriverService;
  49. import com.pj.project.tb_goods.TbGoods;
  50. import com.pj.project.tb_goods.TbGoodsService;
  51. import com.pj.project.tb_item.TbItem;
  52. import com.pj.project.tb_item.TbItemService;
  53. import com.pj.project.tb_item_type.TbItemType;
  54. import com.pj.project.tb_item_type.TbItemTypeService;
  55. import com.pj.project.tb_notices.TbNoticesService;
  56. import com.pj.project.tb_sort_group.TbSortGroup;
  57. import com.pj.project.tb_sort_group.TbSortGroupService;
  58. import com.pj.project.tb_unit.TbUnit;
  59. import com.pj.project.tb_unit.TbUnitService;
  60. import com.pj.project4sp.admin.SpAdmin;
  61. import com.pj.project4sp.admin.SpAdminService;
  62. import com.pj.project4sp.global.BusinessException;
  63. import com.pj.utils.so.SoMap;
  64. import com.sun.org.apache.regexp.internal.RE;
  65. import lombok.extern.slf4j.Slf4j;
  66. import org.springframework.beans.factory.annotation.Autowired;
  67. import org.springframework.context.annotation.Lazy;
  68. import org.springframework.stereotype.Service;
  69. import com.pj.utils.sg.*;
  70. import org.springframework.transaction.annotation.Transactional;
  71. import javax.annotation.Resource;
  72. /**
  73. * Service: tb_business -- 入境登记
  74. *
  75. * @author qzy
  76. */
  77. @Service
  78. @Transactional(rollbackFor = Exception.class)
  79. @Slf4j
  80. public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness> implements IService<TbBusiness> {
  81. /**
  82. * 底层 Mapper 对象
  83. */
  84. @Autowired
  85. TbBusinessMapper tbBusinessMapper;
  86. @Resource
  87. private TbCarService tbCarService;
  88. @Resource
  89. private TbDriverService tbDriverService;
  90. @Resource
  91. private TbCostomerService tbCostomerService;
  92. @Resource
  93. private TbItemService tbItemService;
  94. @Resource
  95. private TbItemTypeService tbItemTypeService;
  96. @Resource
  97. private TbBusinessItemService tbBusinessItemService;
  98. @Resource
  99. TbUnitService tbUnitService;
  100. @Resource
  101. TbBusinessPeopleService tbBusinessPeopleService;
  102. @Resource
  103. private PartConfig partConfig;
  104. @Resource
  105. private CarConfig carConfig;
  106. @Resource
  107. private TbNoticesService tbNoticesService;
  108. @Resource
  109. private TbCarNoColorService tbCarNoColorService;
  110. @Resource
  111. TbBusinessCarService tbBusinessCarService;
  112. @Resource
  113. @Lazy
  114. TbDeclareService tbDeclareService;
  115. @Resource
  116. WxConfig wxConfig;
  117. @Resource
  118. @Lazy
  119. WxService wxService;
  120. @Resource
  121. MyConfig myConfig;
  122. @Resource
  123. private SpAdminService spAdminService;
  124. @Resource
  125. private TbBusinessSortService tbBusinessSortService;
  126. @Resource
  127. private TbSortGroupService tbSortGroupService;
  128. @Resource
  129. private TbGoodsService tbGoodsService;
  130. @Resource
  131. private RelationBusinessCarService relationBusinessCarService;
  132. @Resource
  133. private OAConfig oaConfig;
  134. private final List<String> CAR_LIST = StrUtil.splitTrim("浙,粤,京,津,冀,晋,蒙,辽,黑,沪,吉,苏,皖,赣,鲁,豫,鄂,湘,桂,琼,渝,川,贵,云,藏, 陕, 甘, 青, 宁", ",");
  135. /**
  136. * 增
  137. */
  138. public AjaxJson addOrUpdate(TbBusiness t) {
  139. t.setBusinessType(TbBusiness.BusinessType.HOLD_CAR.getCode());
  140. if (StrUtil.isEmpty(t.getDeclareNo())) {
  141. throw new BusinessException("请选择申报单");
  142. }
  143. if (StrUtil.isNotEmpty(t.getId()) && StrUtil.isNotEmpty(t.getDeclareNo())) {
  144. TbBusiness db = this.getById(t.getId());
  145. if (!StrUtil.equals(db.getDeclareNo(), t.getDeclareNo())) {
  146. TbDeclare tbDeclare = tbDeclareService.findByDeclareNo(db.getDeclareNo());
  147. if (tbDeclare != null) {
  148. tbDeclare.setBusinessId("");
  149. tbDeclareService.updateById(tbDeclare);
  150. }
  151. }
  152. }
  153. Double carSize = t.getCardSize();
  154. if (carSize != null && carSize > carConfig.getMaxLength()) {
  155. return AjaxJson.getError("车辆规格不能大于" + carConfig.getMaxLength());
  156. }
  157. Double netWeight = t.getNetWeight();
  158. if (netWeight != null && netWeight > carConfig.getMaxWeight()) {
  159. return AjaxJson.getError("车辆载重不能大于" + carConfig.getMaxWeight());
  160. }
  161. SpAdmin spAdmin = StpUserUtil.getAdmin();
  162. String createName = StrUtil.isEmpty(spAdmin.getNickname()) ? spAdmin.getName() : spAdmin.getNickname();
  163. t.setCreateBy(createName);
  164. createCarUnit(t);
  165. String customerId = t.getCustomerId();
  166. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  167. t.setCustomerName(tbCostomer.getName()).setCustomerType(tbCostomer.getPayType());
  168. if (StrUtil.equals(customerId, UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  169. t.setConfirmInputBy(StpUserUtil.getAdmin().getName())
  170. .setConfirmInput(1)
  171. .setConfirmInputTime(new Date());
  172. }
  173. if (StrUtil.isEmpty(t.getId())) {
  174. t.setCreateTime(new Date());
  175. t.setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  176. storeMsg(t.getCustomerId(), "新增一条业务数据:【" + t.getNo() + "】" + DateUtil.now() + "。");
  177. } else {
  178. storeMsg(t.getCustomerId(), "业务订单:【" + t.getNo() + "】数据发生更改," + DateUtil.now() + "。");
  179. }
  180. saveOrUpdate(t);
  181. createBusinessPeople(t);
  182. tbBusinessItemService.removeByBusinessId(t.getId());
  183. BigDecimal price = new BigDecimal(0);
  184. List<TbBusinessItem> items = JSONUtil.toList(t.getItemJson(), TbBusinessItem.class);
  185. int index = 1;
  186. for (TbBusinessItem item : items) {
  187. Double num = NumberUtil.parseDouble(item.getNum());
  188. TbItem tbItem = tbItemService.getById(item.getItemId());
  189. String typeId = tbItem.getTypeId();
  190. price = price.add(NumberUtil.mul(num, tbItem.getPrice()));
  191. TbItemType tbItemType = tbItemTypeService.getById(typeId);
  192. item.setBusinessId(t.getId()).setItemCode(tbItem.getItemCode()).setBusinessType(tbItem.getBusinessType())
  193. .setPayType(tbItem.getPayType()).setPayTypeName(tbItem.getPayTypeName())
  194. .setItemName(tbItem.getItemName()).setItemPrice(tbItem.getPrice())
  195. .setTaxRate(NumberUtil.div(tbItem.getTaxRate().doubleValue(), 100D, 2))
  196. .setItemTypeId(typeId).setItemTypeName(tbItemType.getName()).setBusinessType(tbItemType.getBusinessType())
  197. .setUnit(tbItem.getUnit()).setTotal(NumberUtil.mul(num, tbItem.getPrice())).setCreateTime(new Date())
  198. .setNo(t.getNo() + "0" + index);
  199. tbBusinessItemService.save(item);
  200. index++;
  201. }
  202. List<TbBusinessCar> carList = JSONUtil.toList(t.getCarJson(), TbBusinessCar.class);
  203. String chinaCarNo = carList.stream().map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  204. t.setChinaCarNo(StrUtil.isNotEmpty(chinaCarNo) ? chinaCarNo.toUpperCase() : "");
  205. carList.forEach(tbBusinessCar -> {
  206. tbBusinessCar.setIsLock(0);
  207. String carNo = tbBusinessCar.getCarNo().toUpperCase();
  208. TbBusinessCar car = tbBusinessCarService.findInAndNoBusinessCar(carNo);
  209. if (car != null) {
  210. tbBusinessCar.setId(car.getId()).setRealInTime(car.getRealInTime()).setIsLock(car.getIsLock());
  211. }
  212. TbCar tbCar = tbCarService.findByCardNo(carNo);
  213. tbBusinessCar.setBusinessId(t.getId());
  214. tbBusinessCar.setCarNo(carNo).setCarCompany(tbCar != null ? tbCar.getCustomerName() : "临时");
  215. tbBusinessCar.setBusinessId(t.getId()).setCustomerId(t.getCustomerId());
  216. if (StrUtil.isEmpty(tbBusinessCar.getNo())) {
  217. tbBusinessCar.setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  218. }
  219. });
  220. String yueCarNo = t.getCardNo().toUpperCase();
  221. TbBusinessCar yueCar = tbBusinessCarService.findInAndNoBusinessCar(yueCarNo);
  222. if (yueCar == null) {
  223. yueCar = new TbBusinessCar();
  224. yueCar.setIsLock(0);
  225. }
  226. yueCar.setBusinessId(t.getId()).setCarSize(t.getCardSize()).setCarNo(yueCarNo).setCustomerId(t.getCustomerId());
  227. if (StrUtil.isEmpty(yueCar.getNo())) {
  228. yueCar.setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  229. }
  230. carList.add(yueCar);
  231. tbBusinessCarService.saveOrUpdateBatch(carList);
  232. t.setItemPrice(price)
  233. .setTotalMoney(price);
  234. this.saveOrUpdate(t);
  235. if (StrUtil.isNotEmpty(t.getDeclareNo())) {
  236. TbDeclare tbDeclare = tbDeclareService.findByDeclareNo(t.getDeclareNo());
  237. tbDeclare.setBusinessId(t.getId());
  238. tbDeclareService.updateById(tbDeclare);
  239. }
  240. return AjaxJson.getSuccess();
  241. }
  242. public void storeMsg(String businessCustomerId, String content) {
  243. String currentCustomerId = StpUserUtil.getCustomerId();
  244. if (StrUtil.equals(currentCustomerId, UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  245. BusinessMessageManager.set(businessCustomerId, content);
  246. } else {
  247. BusinessMessageManager.set(UserTypeEnum.PLATFORM_ADMIN.getCustomerId(), content);
  248. }
  249. }
  250. private void createBusinessPeople(TbBusiness t) {
  251. tbBusinessPeopleService.removeByBusinessId(t.getId());
  252. List<TbBusinessPeople> peopleList = JSONUtil.toList(t.getPeopleJson(), TbBusinessPeople.class);
  253. peopleList.forEach(tbBusinessPeople -> tbBusinessPeople.setBusinessId(t.getId()).setCreateTime(new Date()));
  254. tbBusinessPeopleService.saveBatch(peopleList);
  255. }
  256. private void createCarUnit(TbBusiness t) {
  257. TbUnit tbUnit = tbUnitService.findByUnit(t.getCardSize());
  258. if (tbUnit == null) {
  259. tbUnit = new TbUnit();
  260. tbUnit.setUnit(t.getCardSize() + "");
  261. tbUnitService.save(tbUnit);
  262. }
  263. }
  264. private TbDriver createDriver(TbBusiness business) {
  265. TbDriver tbDriver = tbDriverService.findByIdCardNo(business.getCardNo());
  266. if (tbDriver == null) {
  267. tbDriver = new TbDriver();
  268. tbDriver.setCreateTime(new Date()).setIdCard(business.getCardNo())
  269. .setName(business.getDriverName()).setPhone(business.getDriverPhone());
  270. tbDriverService.save(tbDriver);
  271. }
  272. return tbDriver;
  273. }
  274. private TbCar createCar(TbBusiness business) {
  275. String cardNo = business.getCardNo();
  276. TbCar tbCar = tbCarService.findByCardNo(cardNo);
  277. if (tbCar == null) {
  278. tbCar = new TbCar();
  279. }
  280. tbCar.setCardNo(cardNo)
  281. .setCardSize(business.getCardSize())
  282. .setCountryName(business.getCountryName())
  283. .setLastGoodsName(business.getGoodsName())
  284. .setLastNetWeight(business.getNetWeight());
  285. tbCarService.saveOrUpdate(tbCar);
  286. return tbCar;
  287. }
  288. /**
  289. * 查集合 - 根据条件(参数为空时代表忽略指定条件)
  290. */
  291. public List<TbBusiness> getList(SoMap so) {
  292. return tbBusinessMapper.getList(so);
  293. }
  294. public void pay(String id, String payTicket) {
  295. TbBusiness tbBusiness = this.getById(id);
  296. SpAdmin admin = StpUserUtil.getAdmin();
  297. tbBusiness.setPayStatus(2).setPayBy(admin.getName())
  298. .setPayBy(StpUserUtil.getAdmin().getName())
  299. .setPayTicket(payTicket)
  300. .setPayTime(new Date());
  301. if (StrUtil.equals(admin.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  302. tbBusiness.setAdminConfirmPay(1).setPayStatus(3)
  303. .setAdminConfirmPayBy(admin.getName()).setAdminConfirmPayTime(new Date());
  304. }
  305. this.updateById(tbBusiness);
  306. storeMsg(tbBusiness.getCustomerId(), "业务订单【" + tbBusiness.getNo() + "】已支付" + DateUtil.now() + "。");
  307. //发送消息
  308. String text = "您的费用已支付,业务单号[" + tbBusiness.getNo() + "]";
  309. tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text);
  310. }
  311. public void confirm(List<String> ids) {
  312. ids.forEach(id -> {
  313. TbBusiness business = this.getById(id);
  314. business.setConfirmInput(1).setAdminConfirmInput(1)
  315. .setConfirmInputTime(new Date())
  316. .setConfirmInputBy(StpUserUtil.getAdmin().getName());
  317. this.updateById(business);
  318. List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(business.getId());
  319. String carNoStr = cars.stream().map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  320. storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】已确认" + DateUtil.now() + "。");
  321. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
  322. String messageType = business.getGoodsId();
  323. items.forEach(item -> {
  324. String businessType = item.getBusinessType();
  325. //合作伙伴创建+是否下单后付款
  326. if (!StrUtil.equals(businessType, TbCostomer.CustomerEnum.BUSINESS_TYPE.getType())) {
  327. String customerId = business.getCreateByCustomerId();
  328. List<String> customerType = new ArrayList<>();
  329. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  330. if (tbCostomer != null) {
  331. customerType = StrUtil.splitTrim(tbCostomer.getType(), ",");
  332. }
  333. if (customerType.contains(businessType)) {
  334. StaticLog.error("订单自动确认=======================" + id);
  335. MsgDataBO msgDataBO = new MsgDataBO("订单号:" + item.getNo(), "系统自动确认",
  336. DateUtil.now(),
  337. business.getGoodsName() + "(" + item.getItemTypeName() + item.getItemName() + "-" + carNoStr + ")");
  338. List<SpAdmin> spAdminList = spAdminService.findByCustomerId(customerId);
  339. Date now = new Date();
  340. item.setPickCustomerId(customerId).setPick(1)
  341. .setPickCustomerName(tbCostomer.getName()).setPickTime(now)
  342. .setConfirm(1).setConfirmTime(now);
  343. tbBusinessItemService.updateById(item);
  344. List<String> customerMessageType = StrUtil.splitTrim(tbCostomer.getMessageType(), ",");
  345. if (customerMessageType.contains(messageType)) {
  346. spAdminList.stream().map(SpAdmin::getOpenid).forEach(openId -> {
  347. String detailUrl = myConfig.getWebDomain() + "/pages/business-item/item-detail?itemId=" + item.getId() + "&openid=" + openId;
  348. wxService.sendTemplateMsg(wxConfig.getBusinessConfirmTemplate(), openId, msgDataBO, detailUrl);
  349. });
  350. }
  351. } else {
  352. StaticLog.error("正常流程=======================" + id);
  353. String remark = "车牌:";
  354. String carNo = business.getCardNo();
  355. String chinaCarNo = business.getChinaCarNo();
  356. if (StrUtil.isNotEmpty(carNo) && StrUtil.isNotEmpty(chinaCarNo)) {
  357. remark += carNo + "、" + chinaCarNo;
  358. }
  359. if (StrUtil.isEmpty(carNo) && StrUtil.isNotEmpty(chinaCarNo)) {
  360. remark += chinaCarNo;
  361. }
  362. if (StrUtil.isNotEmpty(carNo) && StrUtil.isEmpty(chinaCarNo)) {
  363. remark += carNo;
  364. }
  365. MsgDataBO msgDataBO = new MsgDataBO("订单号:" + item.getNo(), item.getItemTypeName(),
  366. item.getItemName(), business.getGoodsName(), DateUtil.now(), remark);
  367. List<String> openidList = tbCostomerService.findByMessageTypeOpenid(businessType, messageType);
  368. openidList.stream().filter(StrUtil::isNotEmpty).forEach(openid -> {
  369. String detailUrl = myConfig.getWebDomain() + "/pages/business-item/item-detail?itemId=" + item.getId() + "&openid=" + openid;
  370. wxService.sendTemplateMsg(wxConfig.getBusinessNoticeTemplate(), openid, msgDataBO, detailUrl);
  371. });
  372. }
  373. }
  374. });
  375. });
  376. }
  377. public void adminConfirmPay(List<String> ids, String ticket) {
  378. ids.forEach(id -> {
  379. TbBusiness business = this.getById(id);
  380. business.setAdminConfirmPayTime(new Date()).setAdminConfirmPay(1).setAdminConfirmPayBy(StpUserUtil.getAdmin().getName())
  381. .setPayStatus(3).setPayTicket(ticket);
  382. this.updateById(business);
  383. storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】已确认支付" + DateUtil.now() + "。");
  384. //发送消息
  385. String text = "您的费用已支付,业务单号[" + business.getNo() + "]";
  386. tbNoticesService.sendNotice(business.getId(), business.getNo(), business.getCustomerId(), text);
  387. });
  388. }
  389. @Deprecated
  390. public void adminConfirmIn(String id, String inChannel) {
  391. TbBusiness tbBusiness = this.getById(id);
  392. tbBusiness.setRealInTime(new Date()).setInChannel(inChannel);
  393. this.updateById(tbBusiness);
  394. //更新境外车入场记录
  395. //更新中国车入场记录
  396. //发送消息
  397. String text = "您的车辆已入场,业务单号[" + tbBusiness.getNo() + "]";
  398. tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text);
  399. }
  400. public BigDecimal calculationPartMoney(Date iTime, Date oTime) {
  401. BigDecimal zero = new BigDecimal("0");
  402. if (iTime == null || oTime == null) {
  403. return zero;
  404. }
  405. LocalDateTime inDayTime = iTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
  406. LocalDateTime outDayTime = oTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
  407. long minutes = ChronoUnit.MINUTES.between(inDayTime, outDayTime);
  408. if (minutes < 0) {
  409. return zero;
  410. }
  411. long days = ChronoUnit.DAYS.between(inDayTime.toLocalDate(), outDayTime.toLocalDate());
  412. BigDecimal p = partConfig.getBasePrice();//乘积因子
  413. BigDecimal extraPrice = partConfig.getExtraPrice();
  414. int unit = (int) Math.ceil(NumberUtil.div(minutes, 24 * 60));
  415. if (minutes < partConfig.getFreeMinutes()) {
  416. unit = 0;
  417. }
  418. return p.multiply(new BigDecimal(unit)).add(new BigDecimal(days).multiply(extraPrice));
  419. }
  420. public Map<String, Object> getBusinessMoney(String businessCarId, String state) {
  421. Map<String, Object> result = new HashMap<>();
  422. List<TbBusiness> businessList = this.findOtherBusinessByCarId(businessCarId);
  423. businessList = businessList.stream().filter(tbBusiness -> 3 > tbBusiness.getPayStatus()).collect(Collectors.toList());
  424. Set<TbBusinessCar> cars = new HashSet<>();
  425. //越南车是否需要支付
  426. int vietnamCarPay = businessList.stream().anyMatch(tbBusiness -> {
  427. TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
  428. return tbGoods.getVietnamCarPay() == 1;
  429. }) ? 1 : 0;
  430. //中国车是否需要支付
  431. int chinaCarPay = businessList.stream().anyMatch(tbBusiness -> {
  432. TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
  433. return tbGoods.getChinaCarPay() == 1;
  434. }) ? 1 : 0;
  435. //无业务的车辆,中国车和越南车都需要支付
  436. if (businessList.isEmpty()) {
  437. vietnamCarPay = 1;
  438. chinaCarPay = 1;
  439. cars.add(tbBusinessCarService.getById(businessCarId));
  440. }
  441. businessList = businessList.stream().filter(tbBusiness -> {
  442. TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
  443. Integer payStep = tbGoods.getPayStep();
  444. //确认订单后方可缴费
  445. return TbGoods.PayStep.AFTER_CONFIRM.getCode().equals(payStep) && tbBusiness.getAdminConfirmInput() == 1
  446. //或者下单后可缴费
  447. || TbGoods.PayStep.BEFORE_CONFIRM.getCode().equals(payStep) && tbBusiness.getAdminConfirmInput() >= 0;
  448. }).collect(Collectors.toList());
  449. businessList.forEach(tbBusiness -> {
  450. List<TbBusinessCar> businessCars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
  451. cars.addAll(businessCars);
  452. });
  453. List<String> businessIdList = businessList.stream().map(TbBusiness::getId).collect(Collectors.toList());
  454. String businessIds = StrUtil.join(",", businessIdList);
  455. // result.put("type", businessType);
  456. result.put("showPay", true);
  457. result.put("businessId", businessIds);
  458. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessIdList(businessIdList);
  459. Date now = new Date();
  460. List<Map<String, Object>> carsList = new ArrayList<>();
  461. for (TbBusinessCar tbBusinessCar : cars) {
  462. Date inTime = tbBusinessCar.getRealInTime();
  463. BigDecimal partMoney = new BigDecimal("0");
  464. String carType = tbBusinessCar.getCarType();
  465. if (StrUtil.isEmpty(carType)) {
  466. carType = TbItem.ItemTypeEnum.EMPTY_TYPE.getType();
  467. }
  468. if (inTime != null && tbBusinessCar.getRealOutTime() == null) {
  469. if (tbBusinessCar.getPay() == 1 && tbBusinessCar.getPayTime() != null) {
  470. inTime = tbBusinessCar.getPayTime();
  471. }
  472. partMoney = this.calculationPartMoney(inTime, now);
  473. }
  474. if (StrUtil.isNotEmpty(tbBusinessCar.getColor())) {//蓝色车辆免费
  475. List<TbCarNoColor> freeList = tbCarNoColorService.getFreeColor();
  476. List<String> colorList = freeList.stream().map(f -> f.getCarNoColor().substring(0, 1)).collect(Collectors.toList());
  477. String color = tbBusinessCar.getColor().substring(0, 1);
  478. if (colorList.contains(color)) {
  479. partMoney = new BigDecimal("0");
  480. }
  481. }
  482. //越南车牌,是否免费
  483. if (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0) {
  484. partMoney = new BigDecimal("0");
  485. }
  486. //中国车,是否免费
  487. if (TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) {
  488. partMoney = new BigDecimal("0");
  489. }
  490. Map<String, Object> carMap = new HashMap<>();
  491. carMap.put("price", partMoney);
  492. carMap.put("id", tbBusinessCar.getId());
  493. carMap.put("carNo", tbBusinessCar.getCarNo());
  494. carMap.put("pay", tbBusinessCar.getPay());
  495. carMap.put("no", tbBusinessCar.getNo());
  496. if (TbBusinessCar.PayTypeEnum.FEE_TYPE.getType().equals(tbBusinessCar.getPayType())) {
  497. carMap.put("price", 0);
  498. }
  499. carsList.add(carMap);
  500. }
  501. result.put("carList", carsList.stream().sorted(Comparator.comparingDouble(obj -> Double.valueOf(obj.get("price").toString()))).collect(Collectors.toList()));
  502. BigDecimal itemsPrice = new BigDecimal("0");
  503. List<Map<String, Object>> itemList = new ArrayList<>();
  504. for (TbBusinessItem item : items) {
  505. BigDecimal itemPrice = item.getItemPrice().multiply(new BigDecimal(item.getNum()));
  506. if (item.getPayStatus() == 1) {
  507. continue;
  508. }
  509. itemsPrice = itemsPrice.add(itemPrice);
  510. Map<String, Object> itemMap = new HashMap<>();
  511. itemMap.put("id", item.getId());
  512. itemMap.put("name", item.getItemName() + "(" + item.getItemTypeName() + ")");
  513. itemMap.put("price", itemPrice);
  514. itemMap.put("pay", item.getPayStatus());
  515. itemList.add(itemMap);
  516. TbBusinessSort tbBusinessSort = tbBusinessSortService.findByItemTypeId(item.getItemTypeId());
  517. if (tbBusinessSort != null) {
  518. TbSortGroup sortGroup = tbSortGroupService.getById(tbBusinessSort.getGroupId());
  519. if (sortGroup.getCompletePay().equals(1) && sortGroup.getStatus().equals(1)) {
  520. List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sortGroup.getId());
  521. for (TbBusinessSort sort : sorts) {
  522. long count = items.stream().filter(tbBusinessItem -> StrUtil.equals(sort.getTypeId(), tbBusinessItem.getItemTypeId()))
  523. .count();
  524. if (count == 0) {
  525. result.put("showPay", false);
  526. }
  527. }
  528. }
  529. }
  530. }
  531. result.put("itemsPrice", itemsPrice);
  532. result.put("itemList", itemList);
  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. public void deleteOtherBusiness(String id) {
  557. TbBusiness db = super.getById(id);
  558. String declareNo = db.getDeclareNo();
  559. if (StrUtil.isNotEmpty(declareNo)) {
  560. tbDeclareService.rebackDeclareNo(declareNo);
  561. }
  562. this.removeById(id);
  563. //删除响应业务项
  564. tbBusinessItemService.removeByBusinessId(id);
  565. //检查是否删除车辆
  566. List<TbBusinessCar> tbBusinessCarList = tbBusinessCarService.findOtherBusinessCar(id);
  567. tbBusinessCarList.forEach(tbBusinessCar -> {
  568. //未入场
  569. if (tbBusinessCar.getRealInTime() == null) {
  570. List<RelationBusinessCar> relationBusinessCars = relationBusinessCarService.findByBusinessCarId(tbBusinessCar.getId());
  571. //无关联业务==>删除
  572. if (relationBusinessCars.size() == 1) {
  573. tbBusinessCarService.removeById(tbBusinessCar.getId());
  574. }
  575. }
  576. });
  577. //删除关系
  578. relationBusinessCarService.removeByBusinessId(id);
  579. }
  580. public int checkCarBusinessType(String typeId, String carNo, String operateTime, int before) {
  581. return tbBusinessMapper.checkCarBusinessType(typeId, carNo, operateTime, before);
  582. }
  583. public int checkCarBusinessType(String typeId, String carNo, String timeStart, String timeEnd, String businessId) {
  584. return tbBusinessMapper.checkCarBusinessTypeByTime(typeId, carNo, timeStart, timeEnd, businessId);
  585. }
  586. public void manualConfirmPay(String id, List<TbBusinessCar> cars, String remark) {
  587. TbBusiness db = this.getById(id);
  588. if (db == null) {
  589. throw new BusinessException("业务不存在");
  590. }
  591. Date now = new Date();
  592. db.setPayStatus(3).setPayMoney(db.getItemPrice()).setPayTime(now);
  593. this.updateById(db);
  594. cars.forEach(tbBusinessCar -> {
  595. Date realInTime = tbBusinessCar.getRealInTime();
  596. Date realOutTime = tbBusinessCar.getRealOutTime();
  597. if (realInTime != null && realOutTime != null) {
  598. BigDecimal price = calculationPartMoney(realInTime, realOutTime);
  599. tbBusinessCar.setMoney(price);
  600. }
  601. tbBusinessCar.setPay(1).setPayTime(now);
  602. tbBusinessCarService.updateById(tbBusinessCar);
  603. });
  604. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
  605. items.forEach(tbBusinessItem -> tbBusinessItem
  606. .setPayStatus(1).setPayTime(now)
  607. .setRemark(StrUtil.isEmpty(remark) ? "手动确认" : remark)
  608. );
  609. tbBusinessItemService.updateBatchById(items);
  610. }
  611. public void unBindCar(String id, String businessCarId) {
  612. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  613. ew.eq("id", id).eq("business_car_id", businessCarId);
  614. TbBusiness db = getOne(ew);
  615. if (db == null) {
  616. throw new BusinessException("业务单不存在");
  617. }
  618. tbBusinessMapper.unBindCar(id);
  619. }
  620. public TbBusiness addOtherBusiness(OtherBusinessBO otherBusinessBO) {
  621. List<TbItem> tbItems = otherBusinessBO.getItems();
  622. if (tbItems.isEmpty()) {
  623. throw new BusinessException("请选择明细");
  624. }
  625. List<TbBusinessCar> cars = otherBusinessBO.getCars();
  626. if (cars.isEmpty()) {
  627. throw new BusinessException("作业车辆不能为空");
  628. }
  629. Date now = new Date();
  630. TbGoods tbGoods = tbGoodsService.getById(otherBusinessBO.getGoodsId());
  631. TbBusiness tbBusiness = new TbBusiness();
  632. String customerId = otherBusinessBO.getCustomerId();
  633. tbBusiness.setCreateBy(StpUserUtil.getAdmin().getName());
  634. tbBusiness.setPayStep(tbGoods.getPayStep());
  635. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  636. if (tbCostomer != null) {
  637. tbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
  638. }
  639. BigDecimal price = new BigDecimal("0");
  640. List<TbBusinessItem> itemList = new ArrayList<>();
  641. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
  642. int index = 1;
  643. for (TbItem tbItem : tbItems) {
  644. TbItem db = tbItemService.getById(tbItem.getId());
  645. TbBusinessItem item = new TbBusinessItem();
  646. int num = tbItem.getNum();
  647. String typeId = tbItem.getTypeId();
  648. TbItemType tbItemType = tbItemTypeService.getById(typeId);
  649. BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
  650. item.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
  651. .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2));
  652. item.setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId())
  653. .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
  654. .setItemTypeId(typeId).setItemTypeName(tbItemType.getName())
  655. .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
  656. price = price.add(itemTotalPrice);
  657. itemList.add(item);
  658. index++;
  659. }
  660. String declareNo = otherBusinessBO.getDeclareNo();
  661. tbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
  662. .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
  663. .setNo(no).setGoodsName(tbGoods.getName()).setGoodsId(otherBusinessBO.getGoodsId())
  664. .setPayStep(tbGoods.getPayStep()).setDeclareNo(declareNo).setCardNo(otherBusinessBO.getCardNo());
  665. tbBusiness.setCreateTime(now).setCreateByCustomerId(StpUserUtil.getCustomerId())
  666. .setItemPrice(price).setTotalMoney(price).setOwner(otherBusinessBO.getOwner());
  667. tbBusiness.setChinaCarNo(otherBusinessBO.getChinaCarNo());
  668. this.save(tbBusiness);
  669. Integer chinaCarPay = tbGoods.getChinaCarPay();
  670. Integer vietnamCarPay = tbGoods.getVietnamCarPay();
  671. String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
  672. for (TbBusinessCar car : cars) {
  673. String carNo = car.getCarNo().trim().toUpperCase();
  674. String carType = car.getCarType();
  675. if (StrUtil.isEmpty(carType)) {
  676. throw new BusinessException(carNo + "类型不能为空");
  677. }
  678. List<TbBusinessCar> notOutRecords = tbBusinessCarService.findNotOutCar(carNo);
  679. if (notOutRecords.size() > 1) {
  680. throw new BusinessException(carNo + "有多个未出场记录,请先处理");
  681. }
  682. //最新一条记录
  683. TbBusinessCar db = tbBusinessCarService.findTheLastRecord(carNo);
  684. //不存在,或者已离场记录--->新建记录;
  685. if (db == null || db.getRealInTime() != null && db.getRealOutTime() != null) {
  686. db = new TbBusinessCar();
  687. db.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
  688. }
  689. for (TbBusinessItem item : itemList) {
  690. checkOtherBusiness(item.getItemTypeId(), otherBusinessBO.getOperateTime(), tbBusiness.getId(), carNo);
  691. }
  692. db.setPayType(TbBusinessCar.PayTypeEnum.NO_PAY_TYPE.getType());
  693. if ((TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) || (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
  694. db.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
  695. }
  696. TbCar tbCar = tbCarService.findByCardNo(carNo);
  697. if (tbCar != null) {
  698. db.setCarCompany(tbCar.getCustomerName());
  699. if (!TbCar.CarTypeEnum.BUSINESS_CAR.getType().equals(tbCar.getCarType())) {
  700. db.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
  701. }
  702. }
  703. db.setCarNo(carNo).setIsLock(0);
  704. db.setCarSize(car.getCarSize())
  705. .setTimeUpdate(now).setCarType(car.getCarType())
  706. .setNetWeight(car.getNetWeight())
  707. .setCustomerId(customerId)
  708. .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  709. tbBusinessCarService.saveOrUpdate(db);
  710. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  711. relationBusinessCar.setBusinessId(tbBusiness.getId()).setBusinessCarId(db.getId());
  712. relationBusinessCarService.save(relationBusinessCar);
  713. }
  714. if (StrUtil.isNotEmpty(declareNo)) {
  715. TbDeclare declare = tbDeclareService.findByDeclareNo(declareNo);
  716. declare.setBusinessId(tbBusiness.getId());
  717. tbDeclareService.updateById(declare);
  718. }
  719. itemList.forEach(tbBusinessItem -> tbBusinessItem.setBusinessId(tbBusiness.getId()));
  720. tbBusinessItemService.saveBatch(itemList);
  721. return tbBusiness;
  722. }
  723. public List<TbBusiness> getOtherBusiness(SoMap startPage) {
  724. return tbBusinessMapper.getOtherBusiness(startPage);
  725. }
  726. public void editOtherBusiness(OtherBusinessBO otherBusinessBO) {
  727. String id = otherBusinessBO.getId();
  728. TbBusiness dbBusiness = this.getById(id);
  729. if (dbBusiness == null) {
  730. throw new BusinessException("记录不存在");
  731. }
  732. List<TbItem> tbItems = otherBusinessBO.getItems();
  733. if (tbItems.isEmpty()) {
  734. throw new BusinessException("请选择收费明细");
  735. }
  736. List<TbBusinessCar> cars = otherBusinessBO.getCars();
  737. if (cars.isEmpty()) {
  738. throw new BusinessException("作业车辆不能为空");
  739. }
  740. Date now = new Date();
  741. List<RelationBusinessCar> relationBusinessCars = relationBusinessCarService.findByBusinessId(id);
  742. List<String> businessCarIds = cars.stream().filter(tbBusinessCar -> StrUtil.isNotEmpty(tbBusinessCar.getId()))
  743. .map(TbBusinessCar::getId).collect(Collectors.toList());
  744. List<String> removeIds = relationBusinessCars.stream()
  745. .filter(relationBusinessCar -> !businessCarIds.contains(relationBusinessCar.getBusinessCarId()))
  746. .map(RelationBusinessCar::getId)
  747. .collect(Collectors.toList());
  748. if (!removeIds.isEmpty()) {
  749. relationBusinessCarService.removeByIds(removeIds);
  750. }
  751. TbGoods tbGoods = tbGoodsService.getById(otherBusinessBO.getGoodsId());
  752. Integer chinaCarPay = tbGoods.getChinaCarPay();
  753. Integer vietnamCarPay = tbGoods.getVietnamCarPay();
  754. String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
  755. List<TbBusinessItem> itemList = new ArrayList<>();
  756. if (TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() != dbBusiness.getPayStatus()) {
  757. tbBusinessItemService.removeByBusinessId(id);
  758. BigDecimal price = new BigDecimal("0");
  759. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
  760. int index = 1;
  761. for (TbItem tbItem : tbItems) {
  762. TbItem db = tbItemService.getById(tbItem.getId());
  763. TbBusinessItem item = new TbBusinessItem();
  764. int num = tbItem.getNum();
  765. TbItemType tbItemType = tbItemTypeService.getById(tbItem.getTypeId());
  766. BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
  767. item.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
  768. .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2));
  769. item.setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId()).setBusinessId(dbBusiness.getId())
  770. .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
  771. .setItemTypeId(tbItem.getTypeId()).setItemTypeName(tbItemType.getName())
  772. .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
  773. price = price.add(itemTotalPrice);
  774. itemList.add(item);
  775. index++;
  776. }
  777. dbBusiness.setItemPrice(price).setTotalMoney(price);
  778. tbBusinessItemService.saveBatch(itemList);
  779. }
  780. for (TbBusinessCar tbBusinessCar : cars) {
  781. String businessCarId = tbBusinessCar.getId();
  782. String carNo = tbBusinessCar.getCarNo();
  783. for (TbBusinessItem item : itemList) {
  784. checkOtherBusiness(item.getItemTypeId(), otherBusinessBO.getOperateTime(), dbBusiness.getId(), carNo);
  785. }
  786. String carType = tbBusinessCar.getCarType();
  787. if (StrUtil.isNotEmpty(businessCarId)) {
  788. //原来已存在的
  789. TbBusinessCar dbBusinessCar = tbBusinessCarService.getById(businessCarId);
  790. //如果修改了车牌号
  791. String dbCarNo = dbBusinessCar.getCarNo();
  792. if (!dbCarNo.equals(carNo)) {
  793. //把关联删除掉,然后添加新的关联
  794. relationBusinessCarService.removeByBusinessIdAndCarId(dbBusiness.getId(), businessCarId);
  795. TbBusinessCar otherCar = tbBusinessCarService.findTheLastRecord(carNo);
  796. if (otherCar == null ||//不存在或者已离场===>新建
  797. (otherCar.getRealInTime() != null && otherCar.getRealOutTime() != null)) {
  798. otherCar = new TbBusinessCar();
  799. otherCar.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4))
  800. .setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
  801. .setNetWeight(tbBusinessCar.getNetWeight()).setCustomerId(dbBusiness.getCustomerId())
  802. .setTimeUpdate(now).setIsLock(0).setCarType(tbBusinessCar.getCarType());
  803. if ((TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) || (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
  804. otherCar.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
  805. }
  806. tbBusinessCarService.save(otherCar);
  807. } else {
  808. List<TbBusiness> tbBusinessList = this.findOtherBusinessByCarId(businessCarId);
  809. if (tbBusinessList.size() == 1 && dbBusinessCar.getRealInTime() == null) {
  810. tbBusinessCarService.removeById(businessCarId);
  811. }
  812. }
  813. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  814. relationBusinessCar.setBusinessId(dbBusiness.getId()).setBusinessCarId(otherCar.getId());
  815. relationBusinessCarService.save(relationBusinessCar);
  816. } else {
  817. dbBusinessCar.setNetWeight(tbBusinessCar.getNetWeight()).setNetWeight(tbBusinessCar.getNetWeight())
  818. .setCarSize(tbBusinessCar.getCarSize()).setCarType(tbBusinessCar.getCarType());
  819. tbBusinessCarService.updateById(dbBusinessCar);
  820. }
  821. } else {
  822. TbBusinessCar checkCar = tbBusinessCarService.findTheLastRecord(carNo);
  823. if (checkCar == null ||
  824. (checkCar.getRealInTime() != null && checkCar.getRealOutTime() != null)) {
  825. checkCar = new TbBusinessCar();
  826. checkCar.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
  827. }
  828. checkCar.setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
  829. .setNetWeight(tbBusinessCar.getNetWeight()).setCustomerId(dbBusiness.getCustomerId())
  830. .setTimeUpdate(now).setIsLock(0).setCarType(tbBusinessCar.getCarType());
  831. if ((TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) || (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
  832. checkCar.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
  833. }
  834. tbBusinessCarService.saveOrUpdate(checkCar);
  835. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  836. relationBusinessCar.setBusinessId(dbBusiness.getId()).setBusinessCarId(checkCar.getId());
  837. relationBusinessCarService.save(relationBusinessCar);
  838. }
  839. }
  840. if (!StrUtil.equals(dbBusiness.getGoodsId(), otherBusinessBO.getGoodsId())) {
  841. dbBusiness.setGoodsId(otherBusinessBO.getGoodsId())
  842. .setGoodsName(tbGoods.getName()).setPayStep(tbGoods.getPayStep());
  843. }
  844. String declareNo = otherBusinessBO.getDeclareNo();
  845. if (!StrUtil.equals(declareNo, dbBusiness.getDeclareNo())) {
  846. tbDeclareService.rebackDeclareNo(dbBusiness.getDeclareNo());
  847. TbDeclare tbDeclare = tbDeclareService.findByDeclareNo(declareNo);
  848. tbDeclare.setBusinessId(dbBusiness.getId());
  849. tbDeclareService.updateById(tbDeclare);
  850. }
  851. dbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
  852. .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
  853. .setGoodsId(otherBusinessBO.getGoodsId()).setOwner(otherBusinessBO.getOwner())
  854. .setDeclareNo(declareNo).setCardNo(otherBusinessBO.getCardNo());
  855. dbBusiness.setChinaCarNo(otherBusinessBO.getChinaCarNo());
  856. this.updateById(dbBusiness);
  857. }
  858. public void bindOtherBusinessCar(String businessId, List<String> businessCarIdList) {
  859. TbBusiness tbBusiness = this.getById(businessId);
  860. relationBusinessCarService.removeByBusinessId(businessId);
  861. List<TbBusinessCar> carList = tbBusinessCarService.listByIds(businessCarIdList);
  862. String chinaCarNo = carList.stream().filter(tbBusinessCar -> {
  863. String carNo = tbBusinessCar.getCarNo();
  864. String carStr = StrUtil.sub(carNo, 0, 1);
  865. return CAR_LIST.contains(carStr);
  866. }).map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  867. String yueCarNo = carList.stream().filter(tbBusinessCar -> {
  868. String carNo = tbBusinessCar.getCarNo();
  869. String carStr = StrUtil.sub(carNo, 0, 1);
  870. return !CAR_LIST.contains(carStr);
  871. }).map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
  872. tbBusiness.setChinaCarNo(chinaCarNo);
  873. tbBusiness.setCardNo(yueCarNo);
  874. this.updateById(tbBusiness);
  875. businessCarIdList.forEach(businessCarId -> {
  876. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  877. relationBusinessCar.setBusinessCarId(businessCarId).setBusinessId(businessId);
  878. relationBusinessCarService.save(relationBusinessCar);
  879. });
  880. }
  881. private void checkOtherBusiness(String itemTypeId, String operateTimeStr, String businessId, String carNo) {
  882. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  883. TbBusinessSort sort = tbBusinessSortService.findByItemTypeId(itemTypeId);
  884. if (sort == null) {
  885. return;
  886. }
  887. List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sort.getGroupId());
  888. LocalDateTime operateTime = LocalDateTime.parse(operateTimeStr, formatter);
  889. int i = 0;
  890. for (TbBusinessSort tbBusinessSort : sorts) {
  891. if (i == 0 && StrUtil.equals(tbBusinessSort.getTypeId(), itemTypeId) && sorts.size() > 1) {
  892. TbBusinessSort afterItem = sorts.get(i + 1);
  893. String typeId = afterItem.getTypeId();
  894. Integer interval = afterItem.getIntervalTime();
  895. LocalDateTime endTime = operateTime.plusMinutes(interval);
  896. if (afterItem.getIntervalTime() > 0) {
  897. int count = this.checkCarBusinessType(typeId, carNo, endTime.format(formatter), 1);
  898. if (count > 0) {
  899. throw new BusinessException("车辆:[" + carNo + "]" + tbBusinessSort.getTypeName() + "后" + afterItem.getIntervalTime() + "分钟才可以执行" + afterItem.getTypeName());
  900. }
  901. }
  902. }
  903. if (i > 0 && StrUtil.equals(tbBusinessSort.getTypeId(), itemTypeId)) {
  904. TbBusinessSort beforeItem = sorts.get(i - 1);
  905. String typeId = beforeItem.getTypeId();
  906. Integer interval = tbBusinessSort.getIntervalTime();
  907. LocalDateTime endTime = operateTime.minusMinutes(interval);
  908. if (tbBusinessSort.getIntervalTime() > 0) {
  909. int count = this.checkCarBusinessType(typeId, carNo, endTime.format(formatter), 0);
  910. if (count > 0) {
  911. throw new BusinessException("车辆:[" + carNo + "]" + beforeItem.getTypeName() + "后" + tbBusinessSort.getIntervalTime() + "分钟才可以执行" + tbBusinessSort.getTypeName());
  912. }
  913. }
  914. }
  915. Integer singleIntervalTime = tbBusinessSort.getSingleIntervalTime();
  916. String timeStart = operateTime.minusHours(singleIntervalTime).format(formatter);
  917. String timeEnd = operateTime.plusHours(singleIntervalTime).format(formatter);
  918. int count = this.checkCarBusinessType(itemTypeId, carNo, timeStart, timeEnd, businessId);
  919. if (count > 0) {
  920. throw new BusinessException("车辆:[" + carNo + "]" + singleIntervalTime + "小时内已有相同作业");
  921. }
  922. i++;
  923. }
  924. }
  925. public TbBusiness findByDeclareNo(String declareNo) {
  926. QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
  927. ew.eq("declare_no", declareNo).orderByDesc("id");
  928. List<TbBusiness> list = this.list(ew);
  929. return list.isEmpty() ? null : list.get(0);
  930. }
  931. /**
  932. * 选择异常单发送
  933. *
  934. * @param errorBusinessBO
  935. * @param isAdmin 是否管理员
  936. */
  937. public void selectErrorBusiness(ErrorBusinessBO errorBusinessBO, boolean isAdmin) {
  938. TbBusiness tbBusiness = getById(errorBusinessBO.getId());
  939. if (tbBusiness == null) {
  940. throw new AjaxError("业务已被删除");
  941. }
  942. String businessId = tbBusiness.getId();
  943. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(businessId);
  944. tbBusiness.setPayStatus(errorBusinessBO.getPayStatus())
  945. .setSupplement(1)
  946. .setSupplementBy(errorBusinessBO.getSupplementBy())
  947. .setSupplementTime(new Date())
  948. .setSupplementReason(errorBusinessBO.getSupplementReason());
  949. if (TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() == errorBusinessBO.getPayStatus()) {
  950. tbBusiness.setPayMoney(tbBusiness.getItemPrice())
  951. .setPayTime(errorBusinessBO.getPayTime());
  952. items.forEach(item -> item.setPayTime(errorBusinessBO.getPayTime()).setPayStatus(1));
  953. tbBusinessItemService.updateBatchById(items);
  954. }
  955. List<TbBusinessCar> tbBusinessCars = errorBusinessBO.getCars();
  956. tbBusinessCars.forEach(this::handlerCarPay);
  957. tbBusinessCarService.updateBatchById(tbBusinessCars);
  958. if (isAdmin) {
  959. //发起审批
  960. sendOA(tbBusiness, items, tbBusinessCars, errorBusinessBO.getSupplementBy());
  961. }
  962. this.updateById(tbBusiness);
  963. }
  964. /**
  965. * 处理车辆支付
  966. * @param tbBusinessCar
  967. */
  968. private void handlerCarPay(TbBusinessCar tbBusinessCar) {
  969. String carNo = tbBusinessCar.getCarNo();
  970. String payType = tbBusinessCar.getPayType();
  971. Date payTime = tbBusinessCar.getPayTime();
  972. Date inTime = tbBusinessCar.getRealInTime();
  973. if (inTime == null) {
  974. throw new AjaxError(carNo + "入场时间不能为空");
  975. }
  976. Date outTime = tbBusinessCar.getRealOutTime();
  977. if (outTime == null) {
  978. throw new AjaxError(carNo + "离场时间不能为空");
  979. }
  980. if (payType.equals(TbBusinessCar.PayTypeEnum.HAS_PAY_TYPE.getType())) {
  981. if (payTime == null) {
  982. throw new AjaxError(carNo + "支付时间不能为空");
  983. }
  984. outTime = payTime;
  985. }
  986. //计算停车费
  987. BigDecimal parkMoney = this.calculationPartMoney(inTime, outTime);
  988. tbBusinessCar.setMoney(parkMoney);
  989. }
  990. /**
  991. * 发起流程审批
  992. *
  993. * @param tbBusiness
  994. * @param items
  995. * @param tbBusinessCars
  996. * @param sendBy
  997. */
  998. private void sendOA(TbBusiness tbBusiness, List<TbBusinessItem> items, List<TbBusinessCar> tbBusinessCars, String sendBy) {
  999. ParamsBO paramsBO = buildParams(tbBusiness, items, tbBusinessCars);
  1000. String json = JSONUtil.toJsonStr(paramsBO);
  1001. log.info("构建流程表单数据:{}", json);
  1002. String resp = HttpUtil.createPost(oaConfig.getUrl())
  1003. .timeout(2000).setReadTimeout(3000).body(json)
  1004. .execute().body();
  1005. log.info("请求返回:{}", resp);
  1006. OAResultBO oaResultBO = JSONUtil.toBean(resp, OAResultBO.class);
  1007. if (oaResultBO.getSuccess() && oaResultBO.getCode() == 200) {
  1008. tbBusiness.setSendOa(1).setSendTime(new Date()).setSendBy(sendBy)
  1009. .setOaFdId(oaResultBO.getData().getFdId());
  1010. }
  1011. }
  1012. /**
  1013. * 构建表单数据
  1014. *
  1015. * @param tbBusiness
  1016. * @param items
  1017. * @param tbBusinessCars
  1018. * @return
  1019. */
  1020. private ParamsBO buildParams(TbBusiness tbBusiness, List<TbBusinessItem> items, List<TbBusinessCar> tbBusinessCars) {
  1021. String operator = tbBusiness.getSupplementBy();
  1022. String reason = tbBusiness.getSupplementReason();
  1023. ParamsBO paramsBO = new ParamsBO();
  1024. paramsBO.setRequestId(System.currentTimeMillis() + "")
  1025. .setBusinessSystemCode(oaConfig.getSystemCode());
  1026. ParamsBO.DataBO dataBO = new ParamsBO.DataBO();
  1027. String project = tbBusiness.getGoodsName();
  1028. JSONObject docCreator = new JSONObject();
  1029. docCreator.set("PersonNo", oaConfig.getPersonNo());
  1030. dataBO.setOperationalProject(project)
  1031. .setOperationalPerson(operator).setOperationalReason(reason)
  1032. .setDocSubject(project + "补单流程").setFdTemplateId(oaConfig.getTemplateId()).setDocCreator(JSONUtil.toJsonStr(docCreator));
  1033. //基础信息
  1034. ParamsBO.DataBO.FormValuesBO formValuesBO = buildFormValues(tbBusiness);
  1035. //车辆信息
  1036. ParamsBO.DataBO.FormValuesBO.VehicleInfoBO vehicleInfoBO = buildCarParams(tbBusinessCars);
  1037. formValuesBO.setVehicleInfo(vehicleInfoBO);
  1038. ParamsBO.DataBO.FormValuesBO.SpecificBusinessItemsBO specificBusinessItemsBO = buildItemPrams(items);
  1039. formValuesBO.setSpecificBusinessItems(specificBusinessItemsBO);
  1040. dataBO.setFormValues(formValuesBO);
  1041. paramsBO.setData(dataBO);
  1042. return paramsBO;
  1043. }
  1044. /**
  1045. * 构建业务项
  1046. *
  1047. * @param items
  1048. * @return
  1049. */
  1050. private ParamsBO.DataBO.FormValuesBO.SpecificBusinessItemsBO buildItemPrams(List<TbBusinessItem> items) {
  1051. ParamsBO.DataBO.FormValuesBO.SpecificBusinessItemsBO specificBusinessItemsBO = new ParamsBO.DataBO.FormValuesBO.SpecificBusinessItemsBO();
  1052. List<String> itemTypeNameList = new ArrayList<>();
  1053. List<String> itemNameList = new ArrayList<>();
  1054. List<String> itemPriceList = new ArrayList<>();
  1055. List<String> unitList = new ArrayList<>();
  1056. List<String> numList = new ArrayList<>();
  1057. List<String> payStatusList = new ArrayList<>();
  1058. List<String> payTimeList = new ArrayList<>();
  1059. List<String> remarkList = new ArrayList<>();
  1060. items.forEach(item -> {
  1061. itemTypeNameList.add(item.getItemTypeName());
  1062. itemNameList.add(item.getItemName());
  1063. itemPriceList.add(item.getItemPrice().toString());
  1064. unitList.add(item.getUnit());
  1065. numList.add(item.getNum());
  1066. payStatusList.add(item.getPayStatus() == 1 ? "已支付" : "未支付");
  1067. payTimeList.add(item.getPayTime()==null?"-":DateUtil.format(item.getPayTime(), "yyyy-MM-dd HH:mm:ss"));
  1068. remarkList.add(StrUtil.isEmpty(item.getRemark()) ? "-" : item.getRemark());
  1069. });
  1070. specificBusinessItemsBO.setChargingItem(itemTypeNameList)
  1071. .setChargeDetail(itemNameList).setUnitPrice(itemPriceList).setChargingStandard(unitList)
  1072. .setQuantity(numList).setPayoutStatus(payStatusList).setPayTime(payTimeList).setNote(remarkList);
  1073. return specificBusinessItemsBO;
  1074. }
  1075. /**
  1076. * 构建基础信息
  1077. *
  1078. * @param tbBusiness
  1079. * @return
  1080. */
  1081. private ParamsBO.DataBO.FormValuesBO buildFormValues(TbBusiness tbBusiness) {
  1082. ParamsBO.DataBO.FormValuesBO formValuesBO = new ParamsBO.DataBO.FormValuesBO();
  1083. String project = tbBusiness.getGoodsName();
  1084. formValuesBO.setOperationalProject(project).setWorkingTime(tbBusiness.getOperateTime())
  1085. .setOperatingOutlay(tbBusiness.getItemPrice()).setAmount(tbBusiness.getItemPrice())
  1086. .setPaymentTime(tbBusiness.getPayTime()).setCargoOwner(tbBusiness.getOwner()).setOperationNo(tbBusiness.getNo())
  1087. .setRecordingTime(tbBusiness.getCreateTime()).setRecorder(tbBusiness.getCreateBy())
  1088. .setIsPay(TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() == tbBusiness.getPayStatus() ? "已支付" : "未支付");
  1089. return formValuesBO;
  1090. }
  1091. /**
  1092. * 构建车辆表单
  1093. *
  1094. * @param tbBusinessCars
  1095. * @return
  1096. */
  1097. private ParamsBO.DataBO.FormValuesBO.VehicleInfoBO buildCarParams(List<TbBusinessCar> tbBusinessCars) {
  1098. ParamsBO.DataBO.FormValuesBO.VehicleInfoBO vehicleInfoBO = new ParamsBO.DataBO.FormValuesBO.VehicleInfoBO();
  1099. List<String> carNoList = new ArrayList<>();
  1100. List<String> typeList = new ArrayList<>();
  1101. List<String> loadList = new ArrayList<>();
  1102. List<String> unitsList = new ArrayList<>();
  1103. List<String> payStatusList = new ArrayList<>();
  1104. List<String> carStatusList = new ArrayList<>();
  1105. List<String> feeList = new ArrayList<>();
  1106. List<String> inList = new ArrayList<>();
  1107. List<String> outList = new ArrayList<>();
  1108. tbBusinessCars.forEach(tbBusinessCar -> {
  1109. carNoList.add(tbBusinessCar.getCarNo());
  1110. typeList.add(tbBusinessCar.getCarType());
  1111. loadList.add(tbBusinessCar.getNetWeight());
  1112. Double carSize = tbBusinessCar.getCarSize();
  1113. unitsList.add(carSize == null ? "-" : carSize.toString());
  1114. payStatusList.add(tbBusinessCar.getPayType());
  1115. carStatusList.add(tbBusinessCar.getIsLock() == 1 ? "正常" : "锁定");
  1116. feeList.add(tbBusinessCar.getMoney() == null ? "-" : tbBusinessCar.getMoney().toString());
  1117. inList.add(tbBusinessCar.getRealInTime() == null ? "-" : DateUtil.format(tbBusinessCar.getRealInTime(), "yyyy-MM-dd HH:mm:ss"));
  1118. outList.add(tbBusinessCar.getRealOutTime() == null ? "-" : DateUtil.format(tbBusinessCar.getRealOutTime(), "yyyy-MM-dd HH:mm:ss"));
  1119. });
  1120. vehicleInfoBO.setLicenseNo(carNoList).setType(typeList).setLoad(loadList).setSpecifications(unitsList)
  1121. .setPaymentStatus(payStatusList).setVehicleState(carStatusList).setParkingFee(feeList)
  1122. .setEntryTime(inList).setDepartureTime(outList);
  1123. return vehicleInfoBO;
  1124. }
  1125. //添加异常单
  1126. public void addErrorBusiness(ErrorBusinessBO errorBusinessBO) {
  1127. List<TbItem> tbItems = errorBusinessBO.getItems();
  1128. if (tbItems.isEmpty()) {
  1129. throw new BusinessException("请选择明细");
  1130. }
  1131. List<TbBusinessCar> cars = errorBusinessBO.getCars();
  1132. if (cars.isEmpty()) {
  1133. throw new BusinessException("作业车辆不能为空");
  1134. }
  1135. Date now = new Date();
  1136. TbGoods tbGoods = tbGoodsService.getById(errorBusinessBO.getGoodsId());
  1137. TbBusiness tbBusiness = new TbBusiness();
  1138. String customerId = errorBusinessBO.getCustomerId();
  1139. tbBusiness.setCreateBy(StpUserUtil.getAdmin().getNickname());
  1140. tbBusiness.setPayStep(tbGoods.getPayStep());
  1141. TbCostomer tbCostomer = tbCostomerService.getById(customerId);
  1142. if (tbCostomer != null) {
  1143. tbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
  1144. }
  1145. boolean businessIsPay=TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() == errorBusinessBO.getPayStatus();
  1146. Date businessPayTime=errorBusinessBO.getPayTime();
  1147. BigDecimal price = new BigDecimal("0");
  1148. List<TbBusinessItem> itemList = new ArrayList<>();
  1149. String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
  1150. int index = 1;
  1151. for (TbItem tbItem : tbItems) {
  1152. TbItem db = tbItemService.getById(tbItem.getId());
  1153. TbBusinessItem tbBusinessItem = new TbBusinessItem();
  1154. int num = tbItem.getNum();
  1155. String typeId = tbItem.getTypeId();
  1156. TbItemType tbItemType = tbItemTypeService.getById(typeId);
  1157. BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
  1158. tbBusinessItem.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
  1159. .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2))
  1160. .setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId())
  1161. .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
  1162. .setItemTypeId(typeId).setItemTypeName(tbItemType.getName())
  1163. .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
  1164. price = price.add(itemTotalPrice);
  1165. if (businessIsPay){
  1166. tbBusinessItem.setPayTime(businessPayTime)
  1167. .setPayStatus(1);
  1168. }
  1169. itemList.add(tbBusinessItem);
  1170. index++;
  1171. }
  1172. String declareNo = errorBusinessBO.getDeclareNo();
  1173. tbBusiness.setCardSize(errorBusinessBO.getCarSize()).setNetWeight(errorBusinessBO.getNetWeight())
  1174. .setOperator(errorBusinessBO.getOperator()).setOperateTime(errorBusinessBO.getOperateTime())
  1175. .setNo(no).setGoodsName(tbGoods.getName()).setGoodsId(errorBusinessBO.getGoodsId())
  1176. .setSupplementReason(errorBusinessBO.getSupplementReason()).setSupplementTime(new Date())
  1177. .setSupplementBy(errorBusinessBO.getSupplementBy())
  1178. .setPayStep(tbGoods.getPayStep()).setDeclareNo(declareNo).setCardNo(errorBusinessBO.getCardNo());
  1179. tbBusiness.setCreateTime(now).setCreateByCustomerId(StpUserUtil.getCustomerId())
  1180. .setItemPrice(price).setTotalMoney(price).setOwner(errorBusinessBO.getOwner());
  1181. tbBusiness.setChinaCarNo(errorBusinessBO.getChinaCarNo());
  1182. if (businessIsPay) {//如果已支付
  1183. tbBusiness.setPayMoney(tbBusiness.getItemPrice())
  1184. .setPayTime(businessPayTime);
  1185. }
  1186. this.save(tbBusiness);
  1187. Integer chinaCarPay = tbGoods.getChinaCarPay();
  1188. Integer vietnamCarPay = tbGoods.getVietnamCarPay();
  1189. String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
  1190. for (TbBusinessCar car : cars) {
  1191. String carNo = car.getCarNo().trim().toUpperCase();
  1192. String carType = car.getCarType();
  1193. if (StrUtil.isEmpty(carType)) {
  1194. throw new BusinessException(carNo + "类型不能为空");
  1195. }
  1196. car.setCreateTime(now).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
  1197. if ((TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0)
  1198. || (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
  1199. car.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
  1200. }
  1201. TbCar tbCar = tbCarService.findByCardNo(carNo);
  1202. if (tbCar != null) {
  1203. car.setCarCompany(tbCar.getCustomerName());
  1204. if (!TbCar.CarTypeEnum.BUSINESS_CAR.getType().equals(tbCar.getCarType())) {
  1205. car.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
  1206. }
  1207. }
  1208. car.setCarNo(carNo).setIsLock(0);
  1209. car.setCarSize(car.getCarSize())
  1210. .setTimeUpdate(now).setCarType(car.getCarType())
  1211. .setNetWeight(car.getNetWeight())
  1212. .setCustomerId(customerId)
  1213. .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
  1214. //新增放行记录
  1215. tbBusinessCarService.save(car);
  1216. RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
  1217. relationBusinessCar.setBusinessId(tbBusiness.getId()).setBusinessCarId(car.getId());
  1218. relationBusinessCarService.save(relationBusinessCar);
  1219. }
  1220. if (StrUtil.isNotEmpty(declareNo)) {
  1221. TbDeclare declare = tbDeclareService.findByDeclareNo(declareNo);
  1222. declare.setBusinessId(tbBusiness.getId());
  1223. tbDeclareService.updateById(declare);
  1224. }
  1225. itemList.forEach(tbBusinessItem -> tbBusinessItem.setBusinessId(tbBusiness.getId()));
  1226. tbBusinessItemService.saveBatch(itemList);
  1227. }
  1228. /**
  1229. * 单独发起审批
  1230. * @param id
  1231. */
  1232. public void applyOA(String id, String sendBy) {
  1233. TbBusiness tbBusiness = this.getById(id);
  1234. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
  1235. List<TbBusinessCar> tbBusinessCars = tbBusinessCarService.findOtherBusinessCar(id);
  1236. sendOA(tbBusiness, items, tbBusinessCars, sendBy);
  1237. this.updateById(tbBusiness);
  1238. }
  1239. }