TmstruckWeightResultServiceImpl.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. package com.steerinfo.dil.service.impl;
  2. import com.steerinfo.dil.feign.OmsFeign;
  3. import com.steerinfo.dil.feign.QmsFeign;
  4. import com.steerinfo.dil.mapper.*;
  5. import com.steerinfo.dil.model.TmstruckLeaveFactoryResult;
  6. import com.steerinfo.dil.model.TmstruckLoadResult;
  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.text.ParseException;
  17. import java.text.SimpleDateFormat;
  18. import java.util.*;
  19. /**
  20. * TmstruckWeightResult服务实现:
  21. * @author generator
  22. * @version 1.0-SNAPSHORT 2021-09-09 02:21
  23. * 类描述
  24. * 修订历史:
  25. * 日期:2021-09-09
  26. * 作者:generator
  27. * 参考:
  28. * 描述:TmstruckWeightResult服务实现
  29. * @see null
  30. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  31. */
  32. @Service(value = "tmstruckWeightResultService")
  33. public class TmstruckWeightResultServiceImpl implements ITmstruckWeightResultService {
  34. @Autowired
  35. private TmstruckWeightResultMapper tmstruckWeightResultMapper;
  36. @Autowired
  37. private UtilsServiceImpl utilsService;
  38. @Autowired
  39. private UtilsMapper utilsMapper;
  40. @Autowired
  41. private TmstruckLoadResultMapper tmstruckLoadResultMapper;
  42. @Autowired
  43. OmsFeign omsFeign;
  44. /**
  45. * 派单时新增计重实绩
  46. * 总实绩ID、计皮点、计毛点
  47. * @return
  48. */
  49. @Override
  50. public int addWeightResult(Map<String, Object> map) {
  51. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  52. //生成最大主键ID
  53. tmstruckWeightResult.setWeightTaskResultId(tmstruckWeightResultMapper.selectMaxId());
  54. BigDecimal resultTotalId = DataChange.dataToBigDecimal(map.get("resultTotalId"));
  55. tmstruckWeightResult.setResultTotalId(resultTotalId);
  56. // 添加路段顺序号以及汽车衡
  57. List<Integer> calculateList = null;
  58. Integer calculateId = 0;
  59. Object grossSegmentSqe = map.get("grossSegmentSqe");
  60. //获取毛重汽车衡
  61. if(grossSegmentSqe != null){
  62. tmstruckWeightResult.setGrossSegmentSqe(DataChange.dataToBigDecimal(grossSegmentSqe));
  63. map.put("segmentSqe", grossSegmentSqe);
  64. calculateList = utilsMapper.getLineSegmentGateCalcId(map);
  65. //取汽车衡的Id
  66. calculateList.remove(null);
  67. calculateId = utilsService.randomGetValue(calculateList);
  68. tmstruckWeightResult.setResultGrossPlaceId(new BigDecimal(calculateId));
  69. }
  70. Object tareSegmentSqe = map.get("tareSegmentSqe");
  71. if(tareSegmentSqe != null){
  72. tmstruckWeightResult.setTareSegmentSqe(DataChange.dataToBigDecimal(tareSegmentSqe));
  73. map.put("segmentSqe", tareSegmentSqe);
  74. calculateList = utilsMapper.getLineSegmentGateCalcId(map);
  75. calculateList.remove(null);
  76. calculateId = utilsService.randomGetValue(calculateList);
  77. tmstruckWeightResult.setResultTarePlaceId(new BigDecimal(calculateId));
  78. }
  79. if(map.get("isdeduct") == null){
  80. //添加是否需要扣水扣杂
  81. //通过总实绩ID查询订单类型
  82. Integer orderType = tmstruckWeightResultMapper.getOrderTypeByTotalId(resultTotalId);
  83. if("67".contains(orderType.toString()) || orderType == 10){
  84. tmstruckWeightResult.setIsdeduct(new BigDecimal(1));
  85. }
  86. }else {
  87. tmstruckWeightResult.setIsdeduct(DataChange.dataToBigDecimal(map.get("isdeduct")));
  88. }
  89. return tmstruckWeightResultMapper.insertSelective(tmstruckWeightResult);
  90. }
  91. /**
  92. * 查询所有计毛实绩
  93. * @param map
  94. * @return
  95. */
  96. @Override
  97. public List<Map<String, Object>> getAllJiMaoResult(Map<String, Object> map) {
  98. Integer orderType = (Integer) map.get("orderTypee");
  99. if(orderType==2){
  100. String endDate = (String) map.get("endDate");
  101. if (endDate!=null){
  102. String s = endDate.replaceAll("00:00:00", "23:59:59");
  103. map.put("endDate",s);
  104. }
  105. }
  106. switch (orderType){
  107. case 1:
  108. case 2:
  109. case 3:
  110. return tmstruckWeightResultMapper.getXSAllJiMaoResult(map); // apiID:212
  111. case 4:
  112. return tmstruckWeightResultMapper.getSteelNzJiMaoResult(map); //apiId:264
  113. case 5:
  114. case 6:
  115. case 7:
  116. case 8:
  117. case 17:
  118. case 18:
  119. return tmstruckWeightResultMapper.getCGAllJiMaoResult(map); //apiId:102
  120. case 9:
  121. return tmstruckWeightResultMapper.getImportedDomesticNzJiMaoResult(map); // apiID:354
  122. case 10:
  123. case 20:
  124. case 15:
  125. case 16:
  126. case 23:
  127. case 24:
  128. return tmstruckWeightResultMapper.getImportedDomesticNzJiMao2Result(map); // apiID:354
  129. case 11:
  130. return tmstruckWeightResultMapper.getInFactoryJiLiangResult(map); //apiId: 358
  131. case 12:
  132. case 13:
  133. case 14:
  134. case 19:
  135. case 100:
  136. return tmstruckWeightResultMapper.getSporadicSuppliesJiMiaoResult(map); //apiId:405
  137. }
  138. return null;
  139. }
  140. /**
  141. * 查询所有计皮实绩
  142. * @param map
  143. * @return
  144. */
  145. @Override
  146. public List<Map<String, Object>> getAllJiPiResult(Map<String, Object> map) {
  147. Integer orderType = (Integer) map.get("orderTypee");
  148. if (orderType==2){
  149. String endDate = (String) map.get("endDate");
  150. if (endDate!=null){
  151. String s = endDate.replaceAll("00:00:00", "23:59:59");
  152. map.put("endDate",s);
  153. }
  154. }
  155. switch (orderType){
  156. case 1:
  157. case 2:
  158. case 3:
  159. return tmstruckWeightResultMapper.getXSAllJiPiResult(map); //apiId:211
  160. case 4:
  161. return tmstruckWeightResultMapper.getSteelNzJiPiResult(map); //apiId:262
  162. case 5:
  163. case 6:
  164. case 7:
  165. case 8:
  166. case 17:
  167. case 18:
  168. return tmstruckWeightResultMapper.getCGAllJiPiResult(map); // apiId: 104
  169. case 9:
  170. return tmstruckWeightResultMapper.getImportedDomesticNzJiPiResult(map);// apiId: 104
  171. case 10:
  172. case 20:
  173. return tmstruckWeightResultMapper.getImportedDomesticNzJiPi2Result(map);// apiId: 104
  174. case 11:
  175. break;
  176. case 12:
  177. case 13:
  178. case 14:
  179. case 19:
  180. case 100:
  181. return tmstruckWeightResultMapper.getFactorySkinSporadicWeight(map); //apiId=401
  182. }
  183. return null;
  184. }
  185. /**
  186. * 修改钢材计量实绩。
  187. * @param map orderId, oldMaterialMapList, newMaterialMapList
  188. * @return
  189. */
  190. @Transactional(rollbackFor = Exception.class)
  191. public int updateSteelTruckWeightResult(Map<String, Object> map){
  192. BigDecimal orderId = DataChange.dataToBigDecimal(map.get("orderId"));
  193. List<Map<String, Object>> newMaterialMapList = (List<Map<String, Object>>) map.get("newMaterialMapList");
  194. List<Map<String, Object>> oldMaterialMapList = (List<Map<String, Object>>) map.get("oldMaterialMapList");
  195. int newSize = newMaterialMapList.size();
  196. int oldSize = oldMaterialMapList.size();
  197. //这是新增的情况
  198. if(newSize != oldSize){
  199. Map<String, Object> mapOne = tmstruckWeightResultMapper.getOldWeightMes(orderId);
  200. BigDecimal resultTotalId = DataChange.dataToBigDecimal(mapOne.get("resultTotalId"));
  201. int maxGrossSqe = DataChange.dataToBigDecimal(mapOne.get("maxGrossSqe")).intValue();
  202. int outFactorySqe = 0;
  203. if(newSize > oldSize){
  204. //新增计量装货和修改出厂实绩
  205. outFactorySqe = insertSomeResult(newSize, oldSize, maxGrossSqe, resultTotalId);
  206. }else{
  207. outFactorySqe = deleteSomeResult(newSize, oldSize, maxGrossSqe, resultTotalId);
  208. }
  209. //修改出厂实绩路段顺序号
  210. TmstruckLeaveFactoryResult tmstruckLeaveFactoryResult = new TmstruckLeaveFactoryResult();
  211. tmstruckLeaveFactoryResult.setResultTotalId(resultTotalId);
  212. tmstruckLeaveFactoryResult.setSegmentSqe(new BigDecimal(outFactorySqe));
  213. tmstruckWeightResultMapper.updateLeaveFactorySqe(tmstruckLeaveFactoryResult);
  214. }
  215. //查询是否已经生成过出库实绩
  216. BigDecimal boundResultId = tmstruckWeightResultMapper.getOutBoundResult(orderId);
  217. if(boundResultId != null){//如果已经扫过出库,则需要对出库表物资子表进行操作
  218. Map<String, Object> changeMap = checkMaterial(oldMaterialMapList, newMaterialMapList);
  219. if(changeMap.get("delete")!= null){
  220. //如果有删除的记录,需要对出库实绩物资表中进行删除
  221. List<BigDecimal> delete = (List<BigDecimal>) changeMap.get("delete");
  222. for (BigDecimal deleteMaterialId : delete) {
  223. tmstruckWeightResultMapper.deleteOutBoundResult(boundResultId, deleteMaterialId);
  224. }
  225. }
  226. if(changeMap.get("add")!= null){
  227. //如果有添加的记录,需要进行添加操作
  228. List<Map<String, Object>> add = (List<Map<String, Object>>) changeMap.get("add");
  229. for (Map<String, Object> addMap : add) {
  230. addMap.put("boundResultId", boundResultId);
  231. addMap.put("resultMaterialId",tmstruckWeightResultMapper.getOutBoundMaterialMaxId());
  232. tmstruckWeightResultMapper.addOutBoundResult(addMap);
  233. }
  234. }
  235. if(changeMap.get("update") != null){
  236. //如果有修改的记录,需要进行修改操作
  237. List<Map<String, Object>> update = (List<Map<String, Object>>) changeMap.get("update");
  238. for (Map<String, Object> updateMap : update) {
  239. updateMap.put("boundResultId", boundResultId);
  240. tmstruckWeightResultMapper.updateOutBoundResult(updateMap);
  241. }
  242. }
  243. }
  244. return 0;
  245. }
  246. public int insertSomeResult(int newSize, int oldSize, int maxGrossSqe, BigDecimal resultTotalId){
  247. //根据新增的物资情况去新增计量实绩与装货实绩并修改最终出厂路段顺序号
  248. for (int i = 0; i < newSize - oldSize; i++) {
  249. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  250. tmstruckWeightResult.setId(tmstruckWeightResultMapper.selectMaxId());
  251. tmstruckWeightResult.setResultTotalId(resultTotalId);
  252. tmstruckWeightResult.setTareSegmentSqe(new BigDecimal(++ maxGrossSqe));
  253. tmstruckWeightResult.setInsertTime(new Date());
  254. //新增装车实绩
  255. TmstruckLoadResult tmstruckLoadResult = new TmstruckLoadResult();
  256. tmstruckLoadResult.setResultId(tmstruckLoadResultMapper.selectMaxId());
  257. tmstruckLoadResult.setResultTotalId(resultTotalId);
  258. tmstruckLoadResult.setSegmentSqe(new BigDecimal(++ maxGrossSqe));
  259. tmstruckLoadResult.setInsertTime(new Date());
  260. tmstruckLoadResultMapper.insertSelective(tmstruckLoadResult);
  261. //新增计量实绩 毛重顺序要卡在装车之后
  262. tmstruckWeightResult.setGrossSegmentSqe(new BigDecimal(++ maxGrossSqe));
  263. tmstruckWeightResultMapper.insertSelective(tmstruckWeightResult);
  264. }
  265. return ++ maxGrossSqe;
  266. }
  267. /**
  268. * 删除计量实绩及装车实绩
  269. * @param newSize
  270. * @param oldSize
  271. * @param maxGrossSqe
  272. * @param resultTotalId
  273. * @return
  274. */
  275. public int deleteSomeResult(int newSize, int oldSize, int maxGrossSqe, BigDecimal resultTotalId ){
  276. for (int i = 0; i < oldSize - newSize; i++) {
  277. tmstruckWeightResultMapper.deleteWeightResult(resultTotalId, maxGrossSqe--);//删除计量实绩
  278. //装车在计毛顺序之前
  279. tmstruckWeightResultMapper.deleteLoadResult(resultTotalId, maxGrossSqe--);//删除装车实绩
  280. //计量实绩中有两个路段顺序所以需要再次减1
  281. maxGrossSqe --;
  282. }
  283. //出厂需要 + 1
  284. return maxGrossSqe + 1;
  285. }
  286. /**
  287. * 遍历两次物资集合,找出哪些修改哪些新增哪些删除的物资
  288. * @param newMaterialMapList
  289. * @param oldMaterialMapList
  290. * @return
  291. */
  292. public Map<String, Object> checkMaterial(List<Map<String, Object>> oldMaterialMapList, List<Map<String, Object>> newMaterialMapList){
  293. Map<String, Object> returnMap = new HashMap<>();
  294. List<BigDecimal> delete = new ArrayList<>(); //存放删除的物资ID
  295. List<Map<String, Object>> add = new ArrayList<>(); //存放添加的物资ID及件数
  296. List<Map<String, Object>> update = new ArrayList<>(); // 存放修改的物资Id及件数
  297. //先遍历old中的物资 查找有没有相同的物资 找到修改和删除的物资
  298. for (Map<String, Object> map : oldMaterialMapList) {
  299. String materialId = String.valueOf(map.get("materialId"));//拿到key
  300. //通过这个key去新物资集合中获取是否包含这个key
  301. Map<String, Object> newMap = getNewMap(Integer.parseInt(materialId), newMaterialMapList);
  302. if(newMap == null){
  303. //如果在新物资中没有找到,则代表此物资已删除
  304. delete.add(DataChange.dataToBigDecimal(map.get("materialId")));
  305. }else{ //如果找到了,取出件数进行对比
  306. BigDecimal newNumber = DataChange.dataToBigDecimal(newMap.get("materialNumber")); //拿到新物资中的件数
  307. BigDecimal oldNumber = DataChange.dataToBigDecimal(map.get("materialNumber"));
  308. int i = newNumber.compareTo(oldNumber);
  309. if(i != 0){ //如果件数不相等,则需要进行修改,添加进修改list中
  310. Map<String, Object> updateMap = new HashMap<>();
  311. updateMap.put("materialId", materialId);
  312. updateMap.put("materialNumber", newNumber);
  313. update.add(updateMap);
  314. }
  315. }
  316. }
  317. //再次遍历new中的物资 查找 新增 的物资
  318. for (Map<String, Object> map : newMaterialMapList) {
  319. String materialId = String.valueOf(map.get("materialId"));
  320. Map<String, Object> oldMaps = getNewMap(Integer.parseInt(materialId), oldMaterialMapList);
  321. if(oldMaps == null){
  322. //如果在旧map中没有找到,则代表是新增的物资,将新增的物资存放到新增列表中
  323. add.add(map);
  324. }
  325. }
  326. if(add.size() != 0) returnMap.put("add", add);
  327. if(delete.size() != 0) returnMap.put("delete", delete);
  328. if(update.size() != 0) returnMap.put("update", update);
  329. return returnMap;
  330. }
  331. /**
  332. * 遍历list查看里面的map是否包含这个值
  333. * @param key
  334. * @param mapList
  335. * @return
  336. */
  337. public Map<String, Object> getNewMap(int key, List<Map<String, Object>> mapList){
  338. for (Map<String, Object> map : mapList) {
  339. if(map.containsValue(key)){
  340. return map;
  341. }
  342. }
  343. return null;
  344. }
  345. /**
  346. * 更新计量实绩 计皮点 计毛点 皮重
  347. * @param map
  348. */
  349. // public int updateWeightResult(Map<String, Object> map){
  350. // TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  351. // //通过订单Id 查询路段顺序号为最小的 且没有净重的计量实绩ID
  352. // BigDecimal id = tmstruckWeightResultMapper.getWeightIdBySQEAndOrderId(map);
  353. // tmstruckWeightResult.setId(id);
  354. // if(map.get("tarePlaceId") != null){ //如果皮重汽车衡不为空 更新皮重汽车衡
  355. // tmstruckWeightResult.setResultTarePlaceId(DataChange.dataToBigDecimal(map.get("tarePlaceId")));
  356. // }
  357. // if(map.get("grossPlaceId") != null){//如果毛重汽车衡不为空 更新毛重汽车衡
  358. // tmstruckWeightResult.setResultGrossPlaceId(DataChange.dataToBigDecimal(map.get("grossPlaceId")));
  359. // }
  360. // if(map.get("resultTareWeight")!= null){ //如果皮重不为空 更新皮重
  361. // tmstruckWeightResult.setResultTareWeight(DataChange.dataToBigDecimal(map.get("resultTareWeight")));
  362. // }
  363. // return tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  364. // }
  365. /**
  366. * 多拼计算计毛汽车衡
  367. * @param map
  368. */
  369. // public int calculateTruckCalculate(Map<String, Object> map, Integer resultTotalId){
  370. // //通过总实绩ID查询订单Id
  371. // Integer orderId = utilsService.getOrderIdByTotalId(resultTotalId);
  372. // //查询未装车的装车实绩
  373. // List<Map<String, Object>> list = rulesService.judgeLastMaterial(new BigDecimal(orderId));
  374. // Map<String, Object> mesMap = new HashMap<>(); //用于查询更新存放数据map
  375. // mesMap.put("orderId", orderId);
  376. // int i = 0;
  377. // if(list.size() == 0){
  378. // //如果是最后一拼则走出厂称 计算出厂称
  379. // mesMap.put("materialId", map.get("materialId"));
  380. // mesMap.put("nature", 1);
  381. // Integer calculate = rulesService.calculateWeighbridge(mesMap);
  382. // //更新汽车衡
  383. // mesMap.put("grossPlaceId", calculate);
  384. // i += updateWeightResult(mesMap);
  385. // }else {
  386. // //如果后面还有物资未装车 则走拼装秤 10号秤 (固定数据)
  387. // mesMap.put("materialId", map.get("materialId"));
  388. // mesMap.put("grossPlaceId", 10);
  389. // i += updateWeightResult(mesMap);
  390. // }
  391. // return i;
  392. // }
  393. /**
  394. * 单拼销售计算汽车衡
  395. * @return
  396. */
  397. // public int calculateTruckCalculateByOne(Map<String, Object> map, Integer type){
  398. // String orderNumber = (String) map.get("orderNumber");
  399. // //通过运输订单号查找物资ID、订单ID
  400. // Map<String, Object> oIdAndMidMap = tmstruckWeightResultMapper.getOrderIdAndMaterialIdByOrderNum(orderNumber);
  401. // //通过物资ID计算汽车衡
  402. // if(type == 1){
  403. // //1:进厂
  404. // oIdAndMidMap.put("nature", type); //1: 进厂秤
  405. // int calculateId = rulesService.calculateWeighbridge(oIdAndMidMap);
  406. // oIdAndMidMap.put("tarePlaceId", calculateId);
  407. //
  408. // }else if(type == 2){
  409. // //2:出厂
  410. // oIdAndMidMap.put("nature", type); //2: 出厂称
  411. // int calculateId = rulesService.calculateWeighbridge(oIdAndMidMap);
  412. // oIdAndMidMap.put("grossPlaceId", calculateId);
  413. // }
  414. // return updateWeightResult(oIdAndMidMap);
  415. // }
  416. }