TmstruckWeightResultServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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.RulesMapper;
  5. import com.steerinfo.dil.mapper.TmstruckReceiptResultMapper;
  6. import com.steerinfo.dil.mapper.TmstruckWeightResultMapper;
  7. import com.steerinfo.dil.mapper.UtilsMapper;
  8. import com.steerinfo.dil.model.TmstruckReceiptResult;
  9. import com.steerinfo.dil.model.TmstruckWeightResult;
  10. import com.steerinfo.dil.service.ITmstruckWeightResultService;
  11. import com.steerinfo.dil.util.DataChange;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Service;
  14. import org.springframework.transaction.annotation.Transactional;
  15. import java.math.BigDecimal;
  16. import java.text.DecimalFormat;
  17. import java.text.ParseException;
  18. import java.text.SimpleDateFormat;
  19. import java.util.*;
  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 RulesServiceImpl rulesService;
  45. @Autowired
  46. OmsFeign omsFeign;
  47. /**
  48. * 派单时新增计重实绩
  49. * 总实绩ID、计皮点、计毛点
  50. * @return
  51. */
  52. @Override
  53. public int addWeightResult(Map<String, Object> map) {
  54. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  55. //生成最大主键ID
  56. tmstruckWeightResult.setWeightTaskResultId(tmstruckWeightResultMapper.selectMaxId());
  57. BigDecimal resultTotalId = DataChange.dataToBigDecimal(map.get("resultTotalId"));
  58. tmstruckWeightResult.setResultTotalId(resultTotalId);
  59. // 添加路段顺序号以及汽车衡
  60. List<Integer> calculateList = null;
  61. Integer calculateId = 0;
  62. Object grossSegmentSqe = map.get("grossSegmentSqe");
  63. //获取毛重汽车衡
  64. if(grossSegmentSqe != null){
  65. tmstruckWeightResult.setGrossSegmentSqe(DataChange.dataToBigDecimal(grossSegmentSqe));
  66. map.put("segmentSqe", grossSegmentSqe);
  67. calculateList = utilsMapper.getLineSegmentGateCalcId(map);
  68. //取汽车衡的Id
  69. calculateList.remove(null);
  70. calculateId = utilsService.randomGetValue(calculateList);
  71. tmstruckWeightResult.setResultGrossPlaceId(new BigDecimal(calculateId));
  72. }
  73. Object tareSegmentSqe = map.get("tareSegmentSqe");
  74. if(tareSegmentSqe != null){
  75. tmstruckWeightResult.setTareSegmentSqe(DataChange.dataToBigDecimal(tareSegmentSqe));
  76. map.put("segmentSqe", tareSegmentSqe);
  77. calculateList = utilsMapper.getLineSegmentGateCalcId(map);
  78. calculateList.remove(null);
  79. calculateId = utilsService.randomGetValue(calculateList);
  80. tmstruckWeightResult.setResultTarePlaceId(new BigDecimal(calculateId));
  81. }
  82. if(map.get("isdeduct") == null){
  83. //添加是否需要扣水扣杂
  84. //通过总实绩ID查询订单类型
  85. Integer orderType = tmstruckWeightResultMapper.getOrderTypeByTotalId(resultTotalId);
  86. if("67".contains(orderType.toString()) || orderType == 10){
  87. tmstruckWeightResult.setIsdeduct(new BigDecimal(1));
  88. }
  89. }else {
  90. tmstruckWeightResult.setIsdeduct(DataChange.dataToBigDecimal(map.get("isdeduct")));
  91. }
  92. return tmstruckWeightResultMapper.insertSelective(tmstruckWeightResult);
  93. }
  94. /**
  95. * 查询所有计毛实绩
  96. * @param map
  97. * @return
  98. */
  99. @Override
  100. public List<Map<String, Object>> getAllJiMaoResult(Map<String, Object> map) {
  101. Integer orderType = (Integer) map.get("orderTypee");
  102. switch (orderType){
  103. case 1:
  104. case 2:
  105. case 3:
  106. return tmstruckWeightResultMapper.getXSAllJiMaoResult(map); // apiID:212
  107. case 4:
  108. return tmstruckWeightResultMapper.getSteelNzJiMaoResult(map); //apiId:264
  109. case 5:
  110. case 6:
  111. case 7:
  112. case 8:
  113. case 17:
  114. case 18:
  115. return tmstruckWeightResultMapper.getCGAllJiMaoResult(map); //apiId:102
  116. case 9:
  117. return tmstruckWeightResultMapper.getImportedDomesticNzJiMaoResult(map); // apiID:354
  118. case 10:
  119. return tmstruckWeightResultMapper.getImportedDomesticNzJiMao2Result(map); // apiID:354
  120. case 11:
  121. return tmstruckWeightResultMapper.getInFactoryJiLiangResult(map); //apiId: 358
  122. case 12:
  123. case 13:
  124. case 15:
  125. case 16:
  126. return tmstruckWeightResultMapper.getSporadicSuppliesJiMiaoResult(map); //apiId:405
  127. }
  128. return null;
  129. }
  130. /**
  131. * 查询所有计皮实绩
  132. * @param map
  133. * @return
  134. */
  135. @Override
  136. public List<Map<String, Object>> getAllJiPiResult(Map<String, Object> map) {
  137. Integer orderType = (Integer) map.get("orderTypee");
  138. switch (orderType){
  139. case 1:
  140. case 2:
  141. case 3:
  142. return tmstruckWeightResultMapper.getXSAllJiPiResult(map); //apiId:211
  143. case 4:
  144. return tmstruckWeightResultMapper.getSteelNzJiPiResult(map); //apiId:262
  145. case 5:
  146. case 6:
  147. case 7:
  148. case 8:
  149. case 17:
  150. case 18:
  151. return tmstruckWeightResultMapper.getCGAllJiPiResult(map); // apiId: 104
  152. case 9:
  153. return tmstruckWeightResultMapper.getImportedDomesticNzJiPiResult(map);// apiId: 104
  154. case 10:
  155. return tmstruckWeightResultMapper.getImportedDomesticNzJiPi2Result(map);// apiId: 104
  156. case 11:
  157. break;
  158. case 12:
  159. // return tmstruckWeightResultMapper.getSporadicSuppliesJiPiResult(map);//apiId:392
  160. case 13:
  161. // return tmstruckWeightResultMapper.getFactorySkinSporadicJIPi(map); //apiId=401
  162. case 15:
  163. case 16:
  164. return tmstruckWeightResultMapper.getFactorySkinSporadicWeight(map); //apiId=401
  165. }
  166. return null;
  167. }
  168. /**
  169. * 更新计量实绩 计皮点 计毛点 皮重
  170. * @param map
  171. */
  172. public int updateWeightResult(Map<String, Object> map){
  173. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  174. //通过订单Id 查询路段顺序号为最小的 且没有净重的计量实绩ID
  175. BigDecimal id = tmstruckWeightResultMapper.getWeightIdBySQEAndOrderId(map);
  176. tmstruckWeightResult.setId(id);
  177. if(map.get("tarePlaceId") != null){ //如果皮重汽车衡不为空 更新皮重汽车衡
  178. tmstruckWeightResult.setResultTarePlaceId(DataChange.dataToBigDecimal(map.get("tarePlaceId")));
  179. }
  180. if(map.get("grossPlaceId") != null){//如果毛重汽车衡不为空 更新毛重汽车衡
  181. tmstruckWeightResult.setResultGrossPlaceId(DataChange.dataToBigDecimal(map.get("grossPlaceId")));
  182. }
  183. if(map.get("resultTareWeight")!= null){ //如果皮重不为空 更新皮重
  184. tmstruckWeightResult.setResultTareWeight(DataChange.dataToBigDecimal(map.get("resultTareWeight")));
  185. }
  186. return tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  187. }
  188. /**
  189. * 自动签收
  190. * @return
  191. */
  192. public int autoReceipt(BigDecimal resultTotalId){
  193. TmstruckReceiptResult tmstruckReceiptResult = new TmstruckReceiptResult();
  194. tmstruckReceiptResult.setResultTotalId(resultTotalId);
  195. tmstruckReceiptResult.setStatus(new BigDecimal(1));
  196. tmstruckReceiptResult.setInsertUsername("admin");
  197. tmstruckReceiptResult.setInsertTime(new Date());
  198. return tmstruckReceiptResultMapper.updateByTotalResultId(tmstruckReceiptResult);
  199. }
  200. /**
  201. * 多拼计算计毛汽车衡
  202. * @param map
  203. */
  204. public int calculateTruckCalculate(Map<String, Object> map, Integer resultTotalId){
  205. //通过总实绩ID查询订单Id
  206. Integer orderId = utilsService.getOrderIdByTotalId(resultTotalId);
  207. //查询未装车的装车实绩
  208. List<Map<String, Object>> list = rulesService.judgeLastMaterial(new BigDecimal(orderId));
  209. Map<String, Object> mesMap = new HashMap<>(); //用于查询更新存放数据map
  210. mesMap.put("orderId", orderId);
  211. int i = 0;
  212. if(list.size() == 0){
  213. //如果是最后一拼则走出厂称 计算出厂称
  214. mesMap.put("materialId", map.get("materialId"));
  215. mesMap.put("nature", 1);
  216. Integer calculate = rulesService.calculateWeighbridge(mesMap);
  217. //更新汽车衡
  218. mesMap.put("grossPlaceId", calculate);
  219. i += updateWeightResult(mesMap);
  220. }else {
  221. //如果后面还有物资未装车 则走拼装秤 10号秤 (固定数据)
  222. mesMap.put("materialId", map.get("materialId"));
  223. mesMap.put("grossPlaceId", 10);
  224. i += updateWeightResult(mesMap);
  225. }
  226. return i;
  227. }
  228. /**
  229. * 单拼销售计算汽车衡
  230. * @return
  231. */
  232. public int calculateTruckCalculateByOne(Map<String, Object> map, Integer type){
  233. String orderNumber = (String) map.get("orderNumber");
  234. //通过运输订单号查找物资ID、订单ID
  235. Map<String, Object> oIdAndMidMap = tmstruckWeightResultMapper.getOrderIdAndMaterialIdByOrderNum(orderNumber);
  236. //通过物资ID计算汽车衡
  237. if(type == 1){
  238. //1:进厂
  239. oIdAndMidMap.put("nature", type); //1: 进厂秤
  240. int calculateId = rulesService.calculateWeighbridge(oIdAndMidMap);
  241. oIdAndMidMap.put("tarePlaceId", calculateId);
  242. }else if(type == 2){
  243. //2:出厂
  244. oIdAndMidMap.put("nature", type); //2: 出厂称
  245. int calculateId = rulesService.calculateWeighbridge(oIdAndMidMap);
  246. oIdAndMidMap.put("grossPlaceId", calculateId);
  247. }
  248. return updateWeightResult(oIdAndMidMap);
  249. }
  250. }