TmstruckWeightResultServiceImpl.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. package com.steerinfo.dil.service.impl;
  2. import com.steerinfo.dil.mapper.TmstruckReceiptResultMapper;
  3. import com.steerinfo.dil.mapper.TmstruckWeightResultMapper;
  4. import com.steerinfo.dil.model.TmstruckReceiptResult;
  5. import com.steerinfo.dil.model.TmstruckWeightResult;
  6. import com.steerinfo.dil.service.ITmstruckWeightResultService;
  7. import com.steerinfo.dil.util.DataChange;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.transaction.annotation.Transactional;
  11. import java.math.BigDecimal;
  12. import java.text.DecimalFormat;
  13. import java.util.Date;
  14. import java.util.List;
  15. import java.util.Map;
  16. /**
  17. * TmstruckWeightResult服务实现:
  18. * @author generator
  19. * @version 1.0-SNAPSHORT 2021-09-09 02:21
  20. * 类描述
  21. * 修订历史:
  22. * 日期:2021-09-09
  23. * 作者:generator
  24. * 参考:
  25. * 描述:TmstruckWeightResult服务实现
  26. * @see null
  27. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  28. */
  29. @Service(value = "tmstruckWeightResultService")
  30. public class TmstruckWeightResultServiceImpl implements ITmstruckWeightResultService {
  31. @Autowired
  32. private TmstruckWeightResultMapper tmstruckWeightResultMapper;
  33. @Autowired
  34. private TmstruckReceiptResultMapper tmstruckReceiptResultMapper;
  35. @Autowired
  36. private UtilsServiceImpl utilsService;
  37. /**
  38. * 查询所有计毛实绩
  39. * @param map
  40. * @return
  41. */
  42. @Override
  43. public List<Map<String, Object>> getAllJiMaoResult(Map<String, Object> map) {
  44. Integer orderType = (Integer) map.get("orderTypee");
  45. switch (orderType){
  46. case 1:
  47. return tmstruckWeightResultMapper.getXSAllJiMaoResult(map); // apiID:212
  48. case 2:
  49. break;
  50. case 3:
  51. break;
  52. case 4:
  53. break;
  54. case 5:
  55. case 6:
  56. case 7:
  57. case 8:
  58. return tmstruckWeightResultMapper.getCGAllJiMaoResult(map);
  59. case 9:
  60. break;
  61. case 10:
  62. break;
  63. case 11:
  64. }
  65. return null;
  66. }
  67. /**
  68. * 查询所有计皮实绩
  69. * @param map
  70. * @return
  71. */
  72. @Override
  73. public List<Map<String, Object>> getAllJiPiResult(Map<String, Object> map) {
  74. Integer orderType = (Integer) map.get("orderTypee");
  75. switch (orderType){
  76. case 1:
  77. return tmstruckWeightResultMapper.getXSAllJiPiResult(map); //apiId:211
  78. case 2:
  79. break;
  80. case 3:
  81. break;
  82. case 4:
  83. break;
  84. case 5:
  85. case 6:
  86. case 7:
  87. case 8:
  88. return tmstruckWeightResultMapper.getCGAllJiPiResult(map); // apiId: 104
  89. case 9:
  90. break;
  91. case 10:
  92. break;
  93. case 11:
  94. }
  95. return null;
  96. }
  97. /**
  98. * 派单时新增计重实绩
  99. * 总实绩ID、计皮点、计毛点
  100. * @return
  101. */
  102. @Override
  103. public int addWeightResult(Map<String, Object> map) {
  104. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  105. //生成最大主键ID
  106. tmstruckWeightResult.setWeightTaskResultId(tmstruckWeightResultMapper.selectMaxId());
  107. tmstruckWeightResult.setResultTotalId(DataChange.dataToBigDecimal(map.get("resultTotalId")));
  108. // 添加计皮计毛作业点ID
  109. tmstruckWeightResult.setResultGrossPlaceId(DataChange.dataToBigDecimal(map.get("truckCalculateIdMao")));
  110. tmstruckWeightResult.setResultTarePlaceId(DataChange.dataToBigDecimal(map.get("truckCalculateIdPi")));
  111. return tmstruckWeightResultMapper.insertSelective(tmstruckWeightResult);
  112. }
  113. /**
  114. * 通过物资ID获取对应汽车衡 如果有多个汽车衡中随机选择
  115. * @param materialId
  116. * @return
  117. */
  118. @Override
  119. public int getCalculateIdByMaterial(BigDecimal materialId) {
  120. List<Integer> calculateIdList = tmstruckWeightResultMapper.getCalculateIdByMaterial(materialId);
  121. return calculateIdList.get((int)(Math.random()*calculateIdList.size()));
  122. }
  123. /**
  124. * 更新计毛实绩 采集需要的数据
  125. * 运输订单号
  126. * 汽车衡编号
  127. * //物资名称
  128. * 毛重
  129. * 毛重时间
  130. * 磅单号
  131. * @return
  132. */
  133. @Override
  134. @Transactional
  135. public int addJiMaoResult(Map<String, Object> map) {
  136. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  137. //通过传来的运输订单号查询计重实绩
  138. map.putAll(tmstruckWeightResultMapper.selectTotalIdByOrderNo((String) map.get("orderNumber")));
  139. BigDecimal weightTaskResultId = DataChange.dataToBigDecimal(map.get("weightTaskResultId"));
  140. tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId);
  141. //添加毛重
  142. DecimalFormat df = new DecimalFormat("0.00");
  143. String resultGrossWeight = df.format((double) map.get("resultGrossWeight"));
  144. tmstruckWeightResult.setResultGrossWeight(new BigDecimal(resultGrossWeight));
  145. //添加毛重时间
  146. long resultGrossWeightTime = (long) map.get("resultGrossWeightTime");
  147. tmstruckWeightResult.setResultGrossWeightTime(new Date(resultGrossWeightTime));
  148. //通过汽车衡编号查询汽车衡ID
  149. Integer calculateId = tmstruckWeightResultMapper.selectTruckCalculateId((String) map.get("truckCalculateNumber"));
  150. //添加计毛汽车衡
  151. if(calculateId != null){
  152. tmstruckWeightResult.setResultGrossPlaceId(new BigDecimal(calculateId));
  153. }
  154. Integer lineSequence = null; //路段顺序号
  155. BigDecimal orderType = DataChange.dataToBigDecimal(map.get("orderTypee"));
  156. switch (orderType.intValue()){
  157. //如果订单类型为销售订单 则执行销售订单计皮规则 resultTareWeight
  158. case 1:
  159. //计算净重 从map中获取皮重 tareWeight
  160. double netWeight = ((BigDecimal) map.get("resultGrossWeight")).doubleValue() - ((Double) map.get("tareWeight"));
  161. String resultNetWeight = df.format(netWeight);
  162. tmstruckWeightResult.setResultNetWeight(new BigDecimal(resultNetWeight));
  163. addUpdateRegularField(tmstruckWeightResult); //插入第二次计重时间
  164. lineSequence = 5; //设置路段顺序号为5:出厂
  165. break;
  166. case 2:
  167. break;
  168. case 3:
  169. break;
  170. case 4:
  171. break;
  172. case 5:
  173. case 6:
  174. case 7:
  175. case 8: //采购订单记录计毛为第一次计重 添加磅单号
  176. tmstruckWeightResult.setResultPoundNo((String) map.get("resultPoundNo"));
  177. addInsertRegularField(tmstruckWeightResult); //插入第一次计重时间常规字段
  178. lineSequence = 5; //设置路段顺序号为3:卸货
  179. break;
  180. case 9:
  181. break;
  182. case 10:
  183. break;
  184. case 11:
  185. break;
  186. }
  187. int i = tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  188. //更新订单路段顺序号
  189. int i2 = utilsService.updateOrderLineSequence(map, lineSequence);
  190. return i +i2;
  191. }
  192. /**
  193. * 更新计皮实绩 需要采集的数据
  194. * 运输订单号 orderNumber
  195. * 汽车衡编号 truckCalculateNumber
  196. * 皮重 resultTareWeight
  197. * 皮重时间 resultTareWeightTime
  198. * 净重
  199. * @param map
  200. * @return
  201. */
  202. @Override
  203. @Transactional
  204. public int addJiPiResult(Map<String, Object> map) {
  205. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  206. //通过传来的运输订单号查询计重实绩
  207. map.putAll(tmstruckWeightResultMapper.selectTotalIdByOrderNo((String) map.get("orderNumber")));
  208. BigDecimal resultId = (BigDecimal) map.get("weightTaskResultId");
  209. tmstruckWeightResult.setWeightTaskResultId(resultId);
  210. //添加皮重
  211. DecimalFormat df = new DecimalFormat("0.00");
  212. String resultTareWeight = df.format((double) map.get("resultTareWeight"));
  213. tmstruckWeightResult.setResultTareWeight(new BigDecimal(resultTareWeight));
  214. //添加皮重时间
  215. long resultTareWeightTime = (long) map.get("resultTareWeightTime");
  216. tmstruckWeightResult.setResultTareWeightTime(new Date(resultTareWeightTime));
  217. //通过汽车衡编号查询汽车衡ID 添加计皮汽车衡
  218. Integer calculateId = tmstruckWeightResultMapper.selectTruckCalculateId((String) map.get("truckCalculateNumber"));
  219. if(calculateId != null){
  220. tmstruckWeightResult.setResultTarePlaceId(new BigDecimal(calculateId));
  221. }
  222. int i1 = 0;
  223. Integer lineSequence = null; //路段顺序号
  224. BigDecimal orderType = DataChange.dataToBigDecimal(map.get("orderTypee"));
  225. switch (orderType.intValue()){
  226. case 1: //销售订单计皮为第一次计重
  227. tmstruckWeightResult.setResultPoundNo((String) map.get("resultPoundNo"));
  228. addInsertRegularField(tmstruckWeightResult);// 添加插入常规字段 就是第一次计重时间
  229. break;
  230. case 2:
  231. break;
  232. case 3:
  233. break;
  234. case 4:
  235. break;
  236. case 5:
  237. case 6:
  238. case 7:
  239. case 8: //如果订单类型为采购订单 则执行采购订单计皮规则
  240. //计算净重 先从map中获取毛重 grossWeight
  241. double netWeight = ((BigDecimal) map.get("grossWeight")).doubleValue() - ((Double) map.get("resultTareWeight"));
  242. String resultNetWeight = df.format(netWeight);
  243. tmstruckWeightResult.setResultNetWeight(new BigDecimal(resultNetWeight));
  244. addUpdateRegularField(tmstruckWeightResult); // 添加更新常规字段 就是第二次计重时间
  245. //计皮作业完成后自动完成签收
  246. TmstruckReceiptResult tmstruckReceiptResult = new TmstruckReceiptResult();
  247. tmstruckReceiptResult.setResultTotalId(DataChange.dataToBigDecimal(map.get("resultTotalId")));
  248. tmstruckReceiptResult.setStatus(new BigDecimal(1));
  249. tmstruckReceiptResult.setInsertUsername("admin");
  250. tmstruckReceiptResult.setInsertTime(new Date());
  251. i1 = tmstruckReceiptResultMapper.updateByTotalResultId(tmstruckReceiptResult);
  252. lineSequence = 5; // 出厂
  253. break;
  254. case 9:
  255. break;
  256. case 10:
  257. break;
  258. case 11:
  259. break;
  260. }
  261. int i = tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  262. //更新订单路段顺序号
  263. int i2 = utilsService.updateOrderLineSequence(map, lineSequence);
  264. return i + i1 + i2;
  265. }
  266. /**
  267. * 添加首次计重时的常规字段
  268. * @param tmstruckWeightResult
  269. */
  270. public void addInsertRegularField(TmstruckWeightResult tmstruckWeightResult){
  271. tmstruckWeightResult.setInsertTime(new Date());
  272. tmstruckWeightResult.setInsertUsername("admin");
  273. tmstruckWeightResult.setInsertUpdateRemark("无");
  274. }
  275. /**
  276. * 添加第二次计重时的常规字段
  277. * @param tmstruckWeightResult
  278. */
  279. public void addUpdateRegularField(TmstruckWeightResult tmstruckWeightResult){
  280. tmstruckWeightResult.setUpdateTime(new Date());
  281. tmstruckWeightResult.setUpdateUsername("admin");
  282. }
  283. /**
  284. *通过运输订单判断下一步是否需要计量,更新汽车衡到计量实绩中
  285. */
  286. @Override
  287. public int isNextNeedJl(BigDecimal orderId) {
  288. //通过运输订单id获取路段顺序号、物资类型、计量实绩主键、line_id
  289. Map<String,BigDecimal> map = tmstruckWeightResultMapper.selectByOrderId(orderId);
  290. //通过运输订单id获取物资的类型
  291. BigDecimal materialTypeId = DataChange.dataToBigDecimal(map.get("materialTypeId"));
  292. //获取路段顺序号
  293. BigDecimal orderLineSequence = DataChange.dataToBigDecimal(map.get("orderLineSequence"));
  294. //计量实绩主键
  295. BigDecimal weightTaskResultId = DataChange.dataToBigDecimal(map.get("weightTaskResultId"));
  296. //line_id
  297. BigDecimal lineId=new BigDecimal(map.get("lineId").toString());
  298. //通过运输线路判断下一步是否为计量,当前是啥,下下一步是啥
  299. //如果下一步为计量,且当前步为进厂,则选择进厂称,如果下下步为出厂则选择出厂称,其他则选择中转称
  300. List<BigDecimal> list=getNextStep(lineId,orderLineSequence.intValue());
  301. if(list.size()==3){
  302. //0:进厂;1:计毛;2:计皮;3:卸货;4:装货;5:出厂
  303. if(list.get(1).intValue()==1 || list.get(1).intValue()==2){
  304. //如果当前为进厂
  305. if(list.get(0).intValue()==0){
  306. //获取到汽车衡id
  307. BigDecimal truckCalculateId =tmstruckWeightResultMapper.getTruckCalculateNumber(materialTypeId,new BigDecimal(1));
  308. //将获取到的汽车衡id更新到计量实绩表中
  309. //如果下一步为计毛作业
  310. if(list.get(1).intValue()==1){
  311. //通过订单号获取计量实绩主键,并更新
  312. TmstruckWeightResult tmstruckWeightResult=new TmstruckWeightResult();
  313. tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId);
  314. tmstruckWeightResult.setResultGrossPlaceId(truckCalculateId);
  315. tmstruckWeightResult.setUpdateTime(new Date());
  316. tmstruckWeightResult.setUpdateUsername("admin");
  317. tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  318. }
  319. //如果下一步为计皮作业
  320. if(list.get(1).intValue()==2){
  321. //通过订单号获取计量实绩主键,并更新
  322. TmstruckWeightResult tmstruckWeightResult=new TmstruckWeightResult();
  323. tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId);
  324. tmstruckWeightResult.setResultTarePlaceId(truckCalculateId);
  325. tmstruckWeightResult.setUpdateTime(new Date());
  326. tmstruckWeightResult.setUpdateUsername("admin");
  327. tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  328. }
  329. }
  330. //如果计量后一步为出厂
  331. else if(list.get(2).intValue()==5){
  332. //获取到汽车衡id
  333. BigDecimal truckCalculateId =tmstruckWeightResultMapper.getTruckCalculateNumber(materialTypeId,new BigDecimal(2));
  334. //将获取到的汽车衡id更新到计量实绩表中
  335. //如果下一步为计毛作业
  336. if(list.get(1).intValue()==1){
  337. //通过订单号获取计量实绩主键,并更新
  338. TmstruckWeightResult tmstruckWeightResult=new TmstruckWeightResult();
  339. tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId);
  340. tmstruckWeightResult.setResultGrossPlaceId(truckCalculateId);
  341. tmstruckWeightResult.setUpdateTime(new Date());
  342. tmstruckWeightResult.setUpdateUsername("admin");
  343. tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  344. }
  345. //如果下一步为计皮作业
  346. if(list.get(1).intValue()==2){
  347. //通过订单号获取计量实绩主键,并更新
  348. TmstruckWeightResult tmstruckWeightResult=new TmstruckWeightResult();
  349. tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId);
  350. tmstruckWeightResult.setResultTarePlaceId(truckCalculateId);
  351. tmstruckWeightResult.setUpdateTime(new Date());
  352. tmstruckWeightResult.setUpdateUsername("admin");
  353. tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  354. }
  355. }else{
  356. //获取到汽车衡id
  357. BigDecimal truckCalculateId =tmstruckWeightResultMapper.getTruckCalculateNumber(materialTypeId,new BigDecimal(3));
  358. //将获取到的汽车衡id更新到计量实绩表中
  359. //如果下一步为计毛作业
  360. if(list.get(1).intValue()==1){
  361. //通过订单号获取计量实绩主键,并更新
  362. TmstruckWeightResult tmstruckWeightResult=new TmstruckWeightResult();
  363. tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId);
  364. tmstruckWeightResult.setResultGrossPlaceId(truckCalculateId);
  365. tmstruckWeightResult.setUpdateTime(new Date());
  366. tmstruckWeightResult.setUpdateUsername("admin");
  367. tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  368. }
  369. //如果下一步为计皮作业
  370. if(list.get(1).intValue()==2){
  371. //通过订单号获取计量实绩主键,并更新
  372. TmstruckWeightResult tmstruckWeightResult=new TmstruckWeightResult();
  373. tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId);
  374. tmstruckWeightResult.setResultTarePlaceId(truckCalculateId);
  375. tmstruckWeightResult.setUpdateTime(new Date());
  376. tmstruckWeightResult.setUpdateUsername("admin");
  377. tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  378. }
  379. }
  380. }
  381. }else {
  382. return 0;
  383. }
  384. return 0;
  385. }
  386. public List<BigDecimal> getNextStep(BigDecimal lineId, int orderLineSequence) {
  387. return tmstruckWeightResultMapper.getNextStep(lineId,orderLineSequence);
  388. }
  389. }