TmstruckWeightResultServiceImpl.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. package com.steerinfo.dil.service.impl;
  2. import com.steerinfo.dil.feign.QmsFeign;
  3. import com.steerinfo.dil.mapper.RulesMapper;
  4. import com.steerinfo.dil.mapper.TmstruckReceiptResultMapper;
  5. import com.steerinfo.dil.mapper.TmstruckWeightResultMapper;
  6. import com.steerinfo.dil.mapper.UtilsMapper;
  7. import com.steerinfo.dil.model.TmstruckReceiptResult;
  8. import com.steerinfo.dil.model.TmstruckWeightResult;
  9. import com.steerinfo.dil.service.ITmstruckWeightResultService;
  10. import com.steerinfo.dil.util.DataChange;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Service;
  13. import org.springframework.transaction.annotation.Transactional;
  14. import java.math.BigDecimal;
  15. import java.text.DecimalFormat;
  16. import java.util.Date;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. /**
  21. * TmstruckWeightResult服务实现:
  22. * @author generator
  23. * @version 1.0-SNAPSHORT 2021-09-09 02:21
  24. * 类描述
  25. * 修订历史:
  26. * 日期:2021-09-09
  27. * 作者:generator
  28. * 参考:
  29. * 描述:TmstruckWeightResult服务实现
  30. * @see null
  31. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  32. */
  33. @Service(value = "tmstruckWeightResultService")
  34. public class TmstruckWeightResultServiceImpl implements ITmstruckWeightResultService {
  35. @Autowired
  36. private TmstruckWeightResultMapper tmstruckWeightResultMapper;
  37. @Autowired
  38. private TmstruckReceiptResultMapper tmstruckReceiptResultMapper;
  39. @Autowired
  40. private UtilsServiceImpl utilsService;
  41. @Autowired
  42. private UtilsMapper utilsMapper;
  43. @Autowired
  44. private QmsFeign qmsFeign;
  45. @Autowired
  46. private RulesServiceImpl rulesService;
  47. @Autowired
  48. private RulesMapper rulesMapper;
  49. @Autowired
  50. private TmstruckLoadResultServiceImpl tmstruckLoadResultService;
  51. @Autowired
  52. private TmstruckLeaveFactoryResultServiceImpl tmstruckLeaveFactoryResultService;
  53. /**
  54. * 查询所有计毛实绩
  55. * @param map
  56. * @return
  57. */
  58. @Override
  59. public List<Map<String, Object>> getAllJiMaoResult(Map<String, Object> map) {
  60. Integer orderType = (Integer) map.get("orderTypee");
  61. switch (orderType){
  62. case 1:
  63. return tmstruckWeightResultMapper.getXSAllJiMaoResult(map); // apiID:212
  64. case 2:
  65. break;
  66. case 3:
  67. break;
  68. case 4:
  69. break;
  70. case 5:
  71. case 6:
  72. case 7:
  73. case 8:
  74. return tmstruckWeightResultMapper.getCGAllJiMaoResult(map);
  75. case 9:
  76. break;
  77. case 10:
  78. break;
  79. case 11:
  80. }
  81. return null;
  82. }
  83. /**
  84. * 查询所有计皮实绩
  85. * @param map
  86. * @return
  87. */
  88. @Override
  89. public List<Map<String, Object>> getAllJiPiResult(Map<String, Object> map) {
  90. Integer orderType = (Integer) map.get("orderTypee");
  91. switch (orderType){
  92. case 1:
  93. return tmstruckWeightResultMapper.getXSAllJiPiResult(map); //apiId:211
  94. case 2:
  95. break;
  96. case 3:
  97. break;
  98. case 4:
  99. break;
  100. case 5:
  101. case 6:
  102. case 7:
  103. case 8:
  104. return tmstruckWeightResultMapper.getCGAllJiPiResult(map); // apiId: 104
  105. case 9:
  106. break;
  107. case 10:
  108. break;
  109. case 11:
  110. }
  111. return null;
  112. }
  113. /**
  114. * 派单时新增计重实绩
  115. * 总实绩ID、计皮点、计毛点
  116. * @return
  117. */
  118. @Override
  119. public int addWeightResult(Map<String, Object> map) {
  120. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  121. //生成最大主键ID
  122. tmstruckWeightResult.setWeightTaskResultId(tmstruckWeightResultMapper.selectMaxId());
  123. tmstruckWeightResult.setResultTotalId(DataChange.dataToBigDecimal(map.get("resultTotalId")));
  124. //添加是否需要扣水扣杂
  125. tmstruckWeightResult.setIsdeduct(DataChange.dataToBigDecimal(map.get("isdeduct")));
  126. // 添加物资Id (销售、内转到异地库)
  127. tmstruckWeightResult.setMaterialId(DataChange.dataToBigDecimal(map.get("materialId")));
  128. return tmstruckWeightResultMapper.insertSelective(tmstruckWeightResult);
  129. }
  130. /**
  131. * 更新计毛实绩 采集需要的数据
  132. * 运输订单号
  133. * 汽车衡编号
  134. * 物资名称
  135. * 毛重
  136. * 毛重时间
  137. * 磅单号
  138. * @return
  139. */
  140. @Override
  141. @Transactional
  142. public int addJiMaoResult(Map<String, Object> map) {
  143. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  144. //通过物资名称和物资规格查询物资Id
  145. int materialId = tmstruckWeightResultMapper.getMaterialIdByMaterialNameAndSpe(map);
  146. map.put("materialId", materialId);
  147. //通过传来的运输订单号与物资ID查询计重实绩
  148. map.putAll(tmstruckWeightResultMapper.selectTotalIdByOrderNo(map));
  149. generateMaoWeightResult(map, tmstruckWeightResult);
  150. BigDecimal orderId = DataChange.dataToBigDecimal(map.get("orderId"));
  151. BigDecimal orderType = DataChange.dataToBigDecimal(map.get("orderTypee"));
  152. int i = 0;
  153. switch (orderType.intValue()){
  154. case 1:
  155. //添加第二次计量常规字段
  156. addUpdateRegularField(tmstruckWeightResult);
  157. //查询当前计毛是否为最后一拼(针对多拼) (查询是否还有装车实绩没有数据)
  158. List<Map<String, Object>> list = rulesMapper.judgeLastMaterial(orderId);
  159. if(list.size() == 0){
  160. //如果没有未装车的装车实绩则计算出厂门岗并更新出厂实绩
  161. BigDecimal resultTotalId = DataChange.dataToBigDecimal(map.get("resultTotalId"));
  162. //计算出厂门岗 更新出厂门岗
  163. int gatepostId = rulesService.calculateGatepost(map);
  164. i += tmstruckLeaveFactoryResultService.updateLeaveFactoryGatepostId(resultTotalId.intValue(), gatepostId);
  165. }else {
  166. //如果还有未装车的实绩 则代表还有未装车的物资 计算各个物资装车点 并更新到装车实绩中
  167. //如果是多拼 使用多种物资计算第一个装货的物资和装车点
  168. Map<String, Object> platIdMap = rulesService.calculateMaterial(list); //获得materialId loadingId
  169. platIdMap.put("orderId", map.get("orderId"));
  170. i += tmstruckLoadResultService.updateLoadingId(platIdMap); //更新装货点
  171. //更新下一计量实绩以当前毛重为皮重
  172. platIdMap.put("resultTareWeight", map.get("resultGrossWeight"));
  173. i += updateWeightResult(platIdMap);
  174. //添加仓库排队
  175. platIdMap.put("orderNumber", map.get("orderNumber"));
  176. qmsFeign.addQueueResultByCk(platIdMap);
  177. }
  178. break;
  179. case 2:
  180. case 3:
  181. break;
  182. case 4:
  183. break;
  184. case 5:
  185. case 6:
  186. case 7:
  187. case 8: //采购订单记录计毛为第一次计重 添加磅单号
  188. addInsertRegularField(tmstruckWeightResult); //插入第一次计重时间常规字段
  189. break;
  190. case 9:
  191. break;
  192. case 10:
  193. break;
  194. case 11:
  195. break;
  196. }
  197. i += tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  198. //路段顺序号 + 1
  199. i += utilsService.updateOrderLineSequence(map);
  200. return i;
  201. }
  202. /**
  203. * 生成计毛实体类
  204. * @param map
  205. * @return
  206. */
  207. public void generateMaoWeightResult(Map<String, Object> map, TmstruckWeightResult tmstruckWeightResult){
  208. //添加磅单号
  209. tmstruckWeightResult.setResultPoundNo((String) map.get("resultPoundNo"));
  210. //添加查询出来的主键
  211. BigDecimal weightTaskResultId = DataChange.dataToBigDecimal(map.get("weightTaskResultId"));
  212. tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId);
  213. //添加毛重
  214. DecimalFormat df = new DecimalFormat("0.00");
  215. String resultGrossWeight = df.format((double) map.get("resultGrossWeight"));
  216. tmstruckWeightResult.setResultGrossWeight(new BigDecimal(resultGrossWeight));
  217. //添加毛重时间
  218. long resultGrossWeightTime = (long) map.get("resultGrossWeightTime");
  219. tmstruckWeightResult.setResultGrossWeightTime(new Date(resultGrossWeightTime));
  220. //添加净重 (如果传入的净重不为0)
  221. BigDecimal resultNetWeight = DataChange.dataToBigDecimal(map.get("resultNetWeight"));
  222. if(resultNetWeight.intValue() != 0){
  223. tmstruckWeightResult.setResultNetWeight(resultNetWeight);
  224. }
  225. //通过汽车衡编号查询汽车衡ID
  226. Integer calculateId = tmstruckWeightResultMapper.selectTruckCalculateId((String) map.get("truckCalculateNumber"));
  227. //添加计毛汽车衡
  228. if(calculateId != null){
  229. tmstruckWeightResult.setResultGrossPlaceId(new BigDecimal(calculateId));
  230. }
  231. }
  232. /**
  233. * 更新计皮实绩 需要采集的数据
  234. * 运输订单号 orderNumber
  235. * 汽车衡编号 truckCalculateNumber
  236. * 皮重 resultTareWeight
  237. * 皮重时间 resultTareWeightTime
  238. * 净重
  239. * 物资名称:materialName 物资规格:materialSpecification 型号:materialModel
  240. * @param map
  241. * @return
  242. */
  243. @Override
  244. @Transactional
  245. public int addJiPiResult(Map<String, Object> map) {
  246. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  247. //通过物资名称和物资规格查询物资Id
  248. int materialId = tmstruckWeightResultMapper.getMaterialIdByMaterialNameAndSpe(map);
  249. map.put("materialId", materialId);
  250. //通过传来的运输订单号 与 物资ID查询计重实绩ID
  251. map.putAll(tmstruckWeightResultMapper.selectTotalIdByOrderNo(map));
  252. generatePiWeightResult(map, tmstruckWeightResult);
  253. int i = 0;
  254. BigDecimal orderType = DataChange.dataToBigDecimal(map.get("orderTypee"));
  255. switch (orderType.intValue()){
  256. case 1:
  257. //销售订单计皮为第一次计重
  258. addInsertRegularField(tmstruckWeightResult);// 添加插入常规字段 就是第一次计重时间;
  259. //查询还未装车的物资
  260. List<Map<String, Object>> mapList = rulesService.judgeLastMaterial(DataChange.dataToBigDecimal(map.get("orderId")));
  261. if(mapList.size() == 1){
  262. //如果是单拼 则直接
  263. Map<String, Object> mesMap = mapList.get(0);
  264. i += tmstruckLoadResultService.updateLoadingId(mesMap); //更新装货点
  265. //添加仓库排队
  266. mesMap.put("orderNumber", map.get("orderNumber"));
  267. qmsFeign.addQueueResultByCk(mesMap);
  268. }else {
  269. //如果是多拼 使用多种物资计算第一个装货的物资和装车点
  270. Map<String, Object> platIdMap = rulesService.calculateMaterial(mapList); //获得materialId loadingId
  271. platIdMap.put("orderId", map.get("orderId"));
  272. i += tmstruckLoadResultService.updateLoadingId(platIdMap); //更新装货点
  273. //添加仓库排队
  274. platIdMap.put("orderNumber", map.get("orderNumber"));
  275. qmsFeign.addQueueResultByCk(platIdMap);
  276. }
  277. break;
  278. case 2:
  279. case 3:
  280. //销售订单计皮为第一次计重
  281. addInsertRegularField(tmstruckWeightResult);// 添加插入常规字段 就是第一次计重时间;
  282. //焦炭、水渣只有一种物资 装货点是通过发运计划的时候填写的
  283. break;
  284. case 4:
  285. break;
  286. case 5:
  287. case 6:
  288. case 7:
  289. case 8:
  290. //如果订单类型为采购订单 则执行采购订单计皮规则
  291. addUpdateRegularField(tmstruckWeightResult); // 添加更新常规字段 就是第二次计重时间
  292. //计皮作业完成后自动完成签收
  293. i += autoReceipt(DataChange.dataToBigDecimal(map.get("resultTotalId")));
  294. //计皮完成后计算出厂门岗并更新实绩出厂门岗ID
  295. i += rulesService.calculateGatepost(map);
  296. break;
  297. case 9:
  298. break;
  299. case 10:
  300. break;
  301. case 11:
  302. break;
  303. }
  304. i += tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  305. //路段顺序号 + 1
  306. i += utilsService.updateOrderLineSequence(map);
  307. return i;
  308. }
  309. /**
  310. * 生成计皮实绩
  311. * @param tmstruckWeightResult
  312. * @return
  313. */
  314. public void generatePiWeightResult(Map<String, Object> map, TmstruckWeightResult tmstruckWeightResult){
  315. //添加磅单号
  316. tmstruckWeightResult.setResultPoundNo((String) map.get("resultPoundNo"));
  317. //添加查询出来的主键
  318. BigDecimal resultId = (BigDecimal) map.get("weightTaskResultId");
  319. tmstruckWeightResult.setWeightTaskResultId(resultId);
  320. //添加皮重
  321. DecimalFormat df = new DecimalFormat("0.00");
  322. String resultTareWeight = df.format((double) map.get("resultTareWeight"));
  323. tmstruckWeightResult.setResultTareWeight(new BigDecimal(resultTareWeight));
  324. //添加皮重时间
  325. long resultTareWeightTime = (long) map.get("resultTareWeightTime");
  326. tmstruckWeightResult.setResultTareWeightTime(new Date(resultTareWeightTime));
  327. //添加净重 (如果传入的净重不为0)
  328. BigDecimal resultNetWeight = DataChange.dataToBigDecimal(map.get("resultNetWeight"));
  329. if(resultNetWeight.intValue() != 0){
  330. tmstruckWeightResult.setResultNetWeight(resultNetWeight);
  331. }
  332. //通过汽车衡编号查询汽车衡ID 添加计皮汽车衡
  333. Integer calculateId = tmstruckWeightResultMapper.selectTruckCalculateId((String) map.get("truckCalculateNumber"));
  334. if(calculateId != null){
  335. tmstruckWeightResult.setResultTarePlaceId(new BigDecimal(calculateId));
  336. }
  337. }
  338. /**
  339. * 更新计量实绩 计皮点 计毛点 皮重
  340. * @param map
  341. */
  342. public int updateWeightResult(Map<String, Object> map){
  343. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  344. //通过物资ID和运输订单Id修改查找计量实绩ID
  345. Integer id = tmstruckWeightResultMapper.getWeightIdByMaterialIdAndOrderId(map);
  346. tmstruckWeightResult.setId(new BigDecimal(id));
  347. if(map.get("tarePlaceId") != null){ //如果皮重汽车衡不为空 更新皮重汽车衡
  348. tmstruckWeightResult.setResultTarePlaceId(DataChange.dataToBigDecimal(map.get("tarePlaceId")));
  349. }
  350. if(map.get("grossPlaceId") != null){//如果毛重汽车衡不为空 更新毛重汽车衡
  351. tmstruckWeightResult.setResultGrossPlaceId(DataChange.dataToBigDecimal(map.get("grossPlaceId")));
  352. }
  353. if(map.get("resultTareWeight")!= null){ //如果皮重不为空 更新皮重
  354. tmstruckWeightResult.setResultTareWeight(DataChange.dataToBigDecimal(map.get("resultTareWeight")));
  355. }
  356. return tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  357. }
  358. /**
  359. * 自动签收
  360. * @return
  361. */
  362. public int autoReceipt(BigDecimal resultTotalId){
  363. TmstruckReceiptResult tmstruckReceiptResult = new TmstruckReceiptResult();
  364. tmstruckReceiptResult.setResultTotalId(resultTotalId);
  365. tmstruckReceiptResult.setStatus(new BigDecimal(1));
  366. tmstruckReceiptResult.setInsertUsername("admin");
  367. tmstruckReceiptResult.setInsertTime(new Date());
  368. return tmstruckReceiptResultMapper.updateByTotalResultId(tmstruckReceiptResult);
  369. }
  370. /**
  371. * 添加首次计重时的常规字段
  372. * @param tmstruckWeightResult
  373. */
  374. public void addInsertRegularField(TmstruckWeightResult tmstruckWeightResult){
  375. tmstruckWeightResult.setInsertTime(new Date());
  376. tmstruckWeightResult.setInsertUsername("admin");
  377. tmstruckWeightResult.setInsertUpdateRemark("无");
  378. }
  379. /**
  380. * 添加第二次计重时的常规字段
  381. * @param tmstruckWeightResult
  382. */
  383. public void addUpdateRegularField(TmstruckWeightResult tmstruckWeightResult){
  384. tmstruckWeightResult.setUpdateTime(new Date());
  385. tmstruckWeightResult.setUpdateUsername("admin");
  386. }
  387. /**
  388. * 多拼计算计毛汽车衡
  389. * @param map
  390. */
  391. public int calculateTruckCalculate(Map<String, Object> map, Integer resultTotalId){
  392. //通过总实绩ID查询订单Id
  393. Integer orderId = utilsService.getOrderIdByTotalId(resultTotalId);
  394. //查询未装车的装车实绩
  395. List<Map<String, Object>> list = rulesService.judgeLastMaterial(new BigDecimal(orderId));
  396. Map<String, Object> mesMap = new HashMap<>(); //用于查询更新存放数据map
  397. mesMap.put("orderId", orderId);
  398. int i = 0;
  399. if(list.size() == 0){
  400. //如果是最后一拼则走出厂称 计算出厂称
  401. mesMap.put("materialId", map.get("materialId"));
  402. mesMap.put("nature", 1);
  403. Integer calculate = rulesService.calculateWeighbridge(mesMap);
  404. //更新汽车衡
  405. mesMap.put("grossPlaceId", calculate);
  406. i += updateWeightResult(mesMap);
  407. }else {
  408. //如果后面还有物资未装车 则走拼装秤 10号秤 (固定数据)
  409. mesMap.put("materialId", map.get("materialId"));
  410. mesMap.put("grossPlaceId", 10);
  411. i += updateWeightResult(mesMap);
  412. }
  413. return i;
  414. }
  415. /**
  416. * 单拼销售计算汽车衡
  417. * @return
  418. */
  419. public int calculateTruckCalculateByOne(Map<String, Object> map, Integer type){
  420. String orderNumber = (String) map.get("orderNumber");
  421. //通过运输订单号查找物资ID、订单ID
  422. Map<String, Object> oIdAndMidMap = tmstruckWeightResultMapper.getOrderIdAndMaterialIdByOrderNum(orderNumber);
  423. //通过物资ID计算汽车衡
  424. if(type == 1){
  425. //1:进厂
  426. oIdAndMidMap.put("nature", type); //1: 进厂秤
  427. int calculateId = rulesService.calculateWeighbridge(oIdAndMidMap);
  428. oIdAndMidMap.put("tarePlaceId", calculateId);
  429. }else if(type == 2){
  430. //2:出厂
  431. oIdAndMidMap.put("nature", type); //2: 出厂称
  432. int calculateId = rulesService.calculateWeighbridge(oIdAndMidMap);
  433. oIdAndMidMap.put("grossPlaceId", calculateId);
  434. }
  435. return updateWeightResult(oIdAndMidMap);
  436. }
  437. public List<BigDecimal> getNextStep(BigDecimal lineId, int orderLineSequence) {
  438. return tmstruckWeightResultMapper.getNextStep(lineId,orderLineSequence);
  439. }
  440. }