TmstruckWeightResultServiceImpl.java 10 KB

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