TmstruckLeaveFactoryResultServiceImpl.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. package com.steerinfo.dil.service.impl;
  2. import com.steerinfo.dil.feign.*;
  3. import com.steerinfo.dil.mapper.TmstruckEnfactoryResultMapper;
  4. import com.steerinfo.dil.mapper.TmstruckLeaveFactoryResultMapper;
  5. import com.steerinfo.dil.mapper.UtilsMapper;
  6. import com.steerinfo.dil.model.TmstruckLeaveFactoryResult;
  7. import com.steerinfo.dil.service.ITmstruckLeaveFactoryResultService;
  8. import com.steerinfo.dil.service.IUtilsService;
  9. import com.steerinfo.dil.util.DataChange;
  10. import com.steerinfo.route.service.impl.RouteServiceImpl;
  11. import com.steerinfo.framework.controller.RESTfulResult;
  12. import org.apache.commons.lang3.builder.ToStringExclude;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import java.math.BigDecimal;
  17. import java.text.SimpleDateFormat;
  18. import java.util.*;
  19. /**
  20. * TmstruckLeaveFactoryResult服务实现:
  21. * @author generator
  22. * @version 1.0-SNAPSHORT 2021-09-11 10:32
  23. * 类描述
  24. * 修订历史:
  25. * 日期:2021-09-11
  26. * 作者:generator
  27. * 参考:
  28. * 描述:TmstruckLeaveFactoryResult服务实现
  29. * @see null
  30. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  31. */
  32. @Service(value = "tmstruckLeaveFactoryResultService")
  33. public class TmstruckLeaveFactoryResultServiceImpl implements ITmstruckLeaveFactoryResultService {
  34. @Autowired
  35. private ITmstruckLeaveFactoryResultService tmstruckLeaveFactoryResultService;
  36. @Autowired
  37. private RouteServiceImpl routeService;
  38. @Autowired
  39. private TmstruckLeaveFactoryResultMapper tmstruckLeaveFactoryResultMapper;
  40. @Autowired
  41. private TmstruckEnfactoryResultMapper tmstruckEnfactoryResultMapper;
  42. @Autowired
  43. private UtilsServiceImpl utilsService;
  44. @Autowired
  45. private UtilsMapper utilsMapper;
  46. @Autowired
  47. private OtmsFeign otmsFeign;
  48. @Autowired
  49. private TmstruckEnfactoryResultServiceImpl tmstruckEnfactoryResultService;
  50. @Autowired
  51. OffSiteTransportationServiceImpl offSiteTransportationService;
  52. @Autowired
  53. TmstruckSmsRusultServiceImpl tmstruckSmsRusultService;
  54. @Autowired
  55. OmsFeign omsFeign;
  56. @Autowired
  57. BmsTruckFeign bmsTruckFeign;
  58. @Autowired
  59. AmsFeign amsFeign;
  60. /**
  61. * 查看运输线路是否为出厂
  62. * @param orderNumber
  63. * @return
  64. */
  65. @Override
  66. public Integer selectTransportRoute(String orderNumber) {
  67. return tmstruckLeaveFactoryResultMapper.selectTransportRoute(orderNumber);
  68. }
  69. /**
  70. * 派单后新增出厂实绩
  71. * 总实绩ID、线路终点
  72. * @param map
  73. * @return
  74. */
  75. @Override
  76. public int addLeaveFactory(Map<String, Object> map) {
  77. TmstruckLeaveFactoryResult tmstruckLeaveFactoryResult = new TmstruckLeaveFactoryResult();
  78. //添加主键
  79. tmstruckLeaveFactoryResult.setId(tmstruckLeaveFactoryResultMapper.selectMaxId());
  80. //添加总实绩ID
  81. BigDecimal resultTotalId = DataChange.dataToBigDecimal(map.get("resultTotalId"));
  82. tmstruckLeaveFactoryResult.setResultTotalId(resultTotalId);
  83. List<Integer> gatepostIdList = utilsMapper.getLineSegmentGateCalcId(map);
  84. gatepostIdList.remove(null);
  85. //随机取门岗值
  86. Integer gatepostId = utilsService.randomGetValue(gatepostIdList);
  87. //获取门岗ID
  88. tmstruckLeaveFactoryResult.setGatepostId(new BigDecimal(gatepostId));
  89. //添加路段顺序号
  90. tmstruckLeaveFactoryResult.setSegmentSqe(DataChange.dataToBigDecimal(map.get("segmentSqe")));
  91. //添加门岗ID 出厂门岗为线路的终点
  92. return tmstruckLeaveFactoryResultMapper.insertSelective(tmstruckLeaveFactoryResult);
  93. }
  94. @Override
  95. public Map<String, Object> getTruckFactoryResult(String nu) {
  96. return tmstruckLeaveFactoryResultMapper.getTruckFactoryResult(nu);
  97. }
  98. /**
  99. * APP查询出厂信息
  100. * @param orderNumber
  101. * @return
  102. */
  103. @Override
  104. public List<Map<String, Object>> getLeaveFactoryList(String orderNumber) {
  105. return tmstruckLeaveFactoryResultMapper.getLeaveFactoryList(orderNumber);
  106. }
  107. /**
  108. * 查询所有的出厂实绩
  109. * 1:销售订单;2:焦炭发运计划;3:水渣发运计划;4:内转到异地库;5:采购辅料订单;6:采购老区燃料订单;
  110. * 7:采购新区燃料订单;8:采购进口矿(万州-厂内);9:采购内转(达州-厂内);10:采购内转(老区-厂内); 11:厂内内转
  111. * @param map
  112. * @return
  113. */
  114. @Override
  115. public List<Map<String, Object>> getLeaveFactoryResult(Map<String, Object> map) {
  116. Integer orderType = (Integer) map.get("orderTypee");
  117. switch (orderType){
  118. case 1:
  119. case 2:
  120. case 3:
  121. return tmstruckLeaveFactoryResultMapper.selectAllLeaveFacatoryForSale(map);
  122. case 4:
  123. return tmstruckLeaveFactoryResultMapper.selectSteelNzLeaveFactory(map);
  124. case 5:
  125. case 6:
  126. case 7:
  127. case 8:
  128. case 17:
  129. case 18:
  130. return tmstruckLeaveFactoryResultMapper.getCGLeaveFactoryResult(map); //apiId:110
  131. case 9:
  132. return tmstruckLeaveFactoryResultMapper.getImportedDomesticNzEnFactoryResult(map); //apiId:110
  133. case 10:
  134. case 20:
  135. return tmstruckEnfactoryResultMapper.getCgNzOutFactory(map);
  136. case 11:
  137. return tmstruckLeaveFactoryResultMapper.getInFactoryOutFactoryResult(map); //apiId:361
  138. case 12:
  139. case 13:
  140. case 14:
  141. case 19:
  142. case 100:
  143. return tmstruckLeaveFactoryResultMapper.getSporadicLeaveFactory(map);//apiId:421
  144. }
  145. return null;
  146. }
  147. /**
  148. * 通过 PDA 出厂
  149. * 1:销售订单;2:焦炭发运计划;3:水渣发运计划;4:内转到异地库;5:采购辅料订单;6:采购老区燃料订单;
  150. * 7:采购新区燃料订单;8:采购进口矿(万州-厂内);9:采购内转(达州-厂内);10:采购内转(老区-厂内); 11:厂内内转
  151. * @param map
  152. * @return
  153. */
  154. @Transactional(rollbackFor = Exception.class)
  155. public int leaveFactoryByPDA(Map<String, Object> map) throws Exception{
  156. int i = 0;
  157. String orderNumber = (String) map.get("orderNumber");
  158. orderNumber = orderNumber.substring(0, orderNumber.length() - 1);
  159. //通过订单号查询订单类型 及总实绩Id
  160. Map<String, Object> mesMap = utilsMapper.getOrderTypeByOrderNumber(orderNumber);
  161. int orderType = DataChange.dataToBigDecimal(mesMap.get("orderType")).intValue();
  162. String capacityNumber = (String) mesMap.get("capacityNumber");
  163. if(orderType == 11 || orderType == 15 || orderType == 16){
  164. return orderType11Use(map, mesMap,capacityNumber);
  165. }else if(orderType == 21){
  166. return tmstruckEnfactoryResultService.orderType21Use(map, orderNumber, DataChange.dataToBigDecimal(mesMap.get("orderId")));
  167. }
  168. Map<String, Object> selectMap = tmstruckLeaveFactoryResultMapper.selectResultId(DataChange.dataToBigDecimal(mesMap.get("resultTotalId")));
  169. if(selectMap == null){
  170. throw new Exception("该车已出厂!!");
  171. }else{
  172. BigDecimal segmentSqe = DataChange.dataToBigDecimal(selectMap.get("segmentSqe"));
  173. BigDecimal orderSegmentSqe = DataChange.dataToBigDecimal(mesMap.get("orderSegmentSqe"));
  174. //如果当前路段顺序号 +1 不等于出厂路段顺序号 则不允许出厂
  175. if(segmentSqe.intValue() != (orderSegmentSqe.intValue() + 1)){
  176. throw new Exception("该车作业环节未全部完成!");
  177. }
  178. }
  179. map.putAll(mesMap);
  180. map.putAll(selectMap);
  181. map.remove("Sqe");
  182. map.put("orderNumber", orderNumber);
  183. BigDecimal orderId = DataChange.dataToBigDecimal(map.get("orderId"));
  184. i += updateLeaveResultByPDA(map); //更新出厂实绩
  185. //更新路段顺序号
  186. i += utilsService.updateOrderLineSequence(map);
  187. switch (orderType){
  188. case 1:
  189. Integer driverConfirmationSteel = utilsMapper.getDriverConfirmation(orderId);
  190. if(driverConfirmationSteel == null){
  191. throw new Exception("请提醒司机确认订单!");
  192. }
  193. try {
  194. //发送短信
  195. Map<String,Object>messageMap = tmstruckLeaveFactoryResultMapper.getMessageMap(orderId);
  196. if(messageMap.get("saleOrderConsigneeTEL") != null){
  197. String capacityNum = (String) messageMap.get("capacityNumber");
  198. String mobile = (String)messageMap.get("saleOrderConsigneeTEL");
  199. tmstruckSmsRusultService.generaSendMessage(mobile,capacityNum,orderId);
  200. }
  201. //销售厂外监控
  202. Map<String, Object> parem=tmstruckLeaveFactoryResultService.getTruckFactoryResult(orderNumber);
  203. parem.put("turnOf","0");
  204. otmsFeign.createTotalResult(parem);
  205. }catch (Exception ex){
  206. }
  207. break;
  208. case 2:
  209. case 3:
  210. //查询司机是否已确认订单 如果订单未确认 则不允许出厂
  211. Integer driverConfirmation = utilsMapper.getDriverConfirmation(orderId);
  212. if(driverConfirmation == null){
  213. throw new Exception("请提醒司机确认订单!");
  214. }
  215. i += utilsService.closeOrderNormally(map);
  216. // 判断是否要自动派单
  217. Map<String,Object> mapValue = omsFeign.getSaleAllMessages(orderId.intValue());
  218. Object closeStatus = mapValue.get("closeStatus");
  219. if (closeStatus != null && DataChange.dataToBigDecimal(closeStatus).intValue() == 0) {
  220. amsFeign.dispatchTruckOrderByCarrier(mapValue);
  221. }
  222. bmsTruckFeign.addDetailsOrder(orderId);
  223. break;
  224. case 4:
  225. break;
  226. case 5:
  227. case 6:
  228. case 7:
  229. case 8:
  230. //判断出厂路段顺序号是否为最后一个 采购订单关闭订单
  231. i += utilsService.closeOrderNormally(map);
  232. //查询是否为一车多趟采购订单类型
  233. Integer isMoreTripsStatus = tmstruckLeaveFactoryResultMapper.getIsMoreTripsStatus(DataChange.dataToBigDecimal(map.get("orderId")));
  234. if(isMoreTripsStatus != null && isMoreTripsStatus == 1){
  235. //如果是一车多趟 则重新下一个运输订单
  236. omsFeign.addNewTransportOrder(orderId.intValue());
  237. }
  238. break;
  239. case 9:
  240. case 17:
  241. case 18:
  242. //判断出厂路段顺序号是否为最后一个 采购订单关闭订单
  243. i += utilsService.closeOrderNormally(map);
  244. break;
  245. case 10:
  246. case 20:
  247. //生成新的采购内转运输订单
  248. //判断出厂路段顺序号是否为最后一个 采购订单关闭订单
  249. i += utilsService.closeOrderNormally(map);
  250. //根据运输订单ID查询路段顺序号
  251. Integer seq = tmstruckLeaveFactoryResultMapper.getSeq(orderId);
  252. if(seq == 10){
  253. //判断是否满足条件--计划是否被启用
  254. Integer j = tmstruckLeaveFactoryResultMapper.getPlanEnable(orderId);
  255. if(j == 1){
  256. //生成新的运输订单
  257. omsFeign.addPurInwardOrder(orderId);
  258. }
  259. try {
  260. bmsTruckFeign.addInwardDetailsOrder(map);
  261. } catch (Exception e) {
  262. e.printStackTrace();
  263. }
  264. }
  265. break;
  266. case 12:
  267. case 13:
  268. case 14:
  269. //关闭当前订单
  270. i += utilsService.closeOrderNormally(map);
  271. //生成新的零星订单
  272. omsFeign.pushMessageToDriver(map);
  273. break;
  274. }
  275. utilsService.pushMesToWebsocket((String) map.get("capacityNumber"), "出厂");
  276. return i;
  277. }
  278. /**
  279. * 内转订单类型
  280. * @Author TXF
  281. * @Date 2022/3/18 18:03
  282. * @param map
  283. * @param mesMap
  284. * @param capacityNumber
  285. * @return
  286. **/
  287. public int orderType11Use(Map<String, Object> map, Map<String, Object> mesMap, String capacityNumber){
  288. //内转订单类型 没有生成实绩 直接新增
  289. int sqe = DataChange.dataToBigDecimal(mesMap.get("Sqe")).intValue();
  290. sqe = sqe + 1;
  291. map.put("resultId",tmstruckLeaveFactoryResultMapper.selectMaxId());//出厂实绩ID
  292. map.put("Sqe",sqe);//查询路段顺序号+1
  293. map.put(("totalId"),mesMap.get("totalId"));
  294. tmstruckLeaveFactoryResultMapper.insertSelective(generateLeaveFactory(map));
  295. //更新路段顺序号
  296. mesMap.put("orderLineSequence",sqe);
  297. utilsService.updateOrderLineSqeByOrderNumber(mesMap);
  298. utilsService.pushMesToWebsocket(capacityNumber, "出厂");
  299. return 1;
  300. }
  301. //内转订单类型新增出厂实绩
  302. private TmstruckLeaveFactoryResult generateLeaveFactory(Map<String, Object> map) {
  303. TmstruckLeaveFactoryResult tmstruckLeaveFactoryResult = new TmstruckLeaveFactoryResult();
  304. //获取出厂实绩ID
  305. tmstruckLeaveFactoryResult.setResultId(DataChange.dataToBigDecimal(map.get("resultId")));
  306. //添加门岗
  307. tmstruckLeaveFactoryResult.setGatepostId(DataChange.dataToBigDecimal(map.get("gatepostId")));
  308. //添加路段顺序号
  309. tmstruckLeaveFactoryResult.setSegmentSqe(DataChange.dataToBigDecimal(map.get("Sqe")));
  310. //添加出厂时间
  311. tmstruckLeaveFactoryResult.setResultOutGateTime(new Date());
  312. tmstruckLeaveFactoryResult.setInsertTime(new Date());
  313. tmstruckLeaveFactoryResult.setResultOutMode("手动抬杆");
  314. tmstruckLeaveFactoryResult.setInsertUsername("admin");
  315. if(map.get("Sqe") !=null){
  316. tmstruckLeaveFactoryResult.setSegmentSqe(DataChange.dataToBigDecimal(map.get("Sqe")));
  317. }
  318. if(map.get("totalId") !=null){
  319. tmstruckLeaveFactoryResult.setResultTotalId(DataChange.dataToBigDecimal(map.get("totalId")));
  320. }
  321. return tmstruckLeaveFactoryResult;
  322. }
  323. /**
  324. * 更新出厂实绩
  325. * @param mapValue {运输订单号:orderNumber 门岗名称:gatepostName}
  326. * @return
  327. */
  328. public int updateLeaveResultByPDA(Map<String, Object> mapValue){
  329. TmstruckLeaveFactoryResult tmstruckLeaveFactoryResult = new TmstruckLeaveFactoryResult();
  330. tmstruckLeaveFactoryResult.setResultId(DataChange.dataToBigDecimal(mapValue.get("resultId")));
  331. //通过门岗名称获取门岗ID
  332. if(mapValue.get("gatepostId") == null){
  333. Integer gatepostId = tmstruckEnfactoryResultMapper.selectGatepostIdByGatepostName((String) mapValue.get("gatepostName"));
  334. if(gatepostId != null){
  335. tmstruckLeaveFactoryResult.setGatepostId(new BigDecimal(gatepostId));
  336. }
  337. }else {
  338. tmstruckLeaveFactoryResult.setGatepostId(DataChange.dataToBigDecimal(mapValue.get("gatepostId")));
  339. }
  340. //设置常规字段 添加 出厂时间 和 出厂方式
  341. tmstruckLeaveFactoryResult.setResultOutGateTime(new Date());
  342. tmstruckLeaveFactoryResult.setResultOutMode("手动抬杠");
  343. tmstruckLeaveFactoryResult.setInsertUsername("admin");
  344. tmstruckLeaveFactoryResult.setInsertTime(new Date());
  345. return tmstruckLeaveFactoryResultMapper.updateByPrimaryKeySelective(tmstruckLeaveFactoryResult);
  346. }
  347. /**
  348. * 通过总实绩Id修改出厂实绩出厂门岗
  349. * @param resultTotalId
  350. * @param gatepostId
  351. * @return
  352. */
  353. public int updateLeaveFactoryGatepostId(Integer resultTotalId, Integer gatepostId){
  354. TmstruckLeaveFactoryResult tmstruckLeaveFactoryResult = new TmstruckLeaveFactoryResult();
  355. //通过总实绩ID查询出产实绩
  356. BigDecimal resultId = tmstruckLeaveFactoryResultMapper.getResultIdByTotalId(resultTotalId);
  357. tmstruckLeaveFactoryResult.setResultId(resultId);
  358. tmstruckLeaveFactoryResult.setGatepostId(new BigDecimal(gatepostId));
  359. return tmstruckLeaveFactoryResultMapper.updateByPrimaryKeySelective(tmstruckLeaveFactoryResult);
  360. }
  361. /**
  362. * 查询零星物资出厂列表
  363. * @param mapValue
  364. * @return
  365. */
  366. @Override
  367. public List<Map<String, Object>> getSporadicLeaveFactory(Map<String, Object> mapValue) {
  368. return tmstruckLeaveFactoryResultMapper.getSporadicLeaveFactory(mapValue);
  369. }
  370. }