TmstruckWeightResultServiceImpl.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package com.steerinfo.dil.service.impl;
  2. import com.steerinfo.dil.feign.TmsFeign;
  3. import com.steerinfo.dil.mapper.TmstruckReceiptResultMapper;
  4. import com.steerinfo.dil.mapper.UtilsMapper;
  5. import com.steerinfo.dil.model.TmstruckReceiptResult;
  6. import com.steerinfo.dil.model.TmstruckWeightResult;
  7. import com.steerinfo.dil.mapper.TmstruckWeightResultMapper;
  8. import com.steerinfo.dil.service.ITmstruckWeightResultService;
  9. import com.steerinfo.dil.util.DataChange;
  10. import io.swagger.annotations.ApiModel;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Service;
  13. import java.text.ParseException;
  14. import java.text.SimpleDateFormat;
  15. import java.util.Date;
  16. import java.math.BigDecimal;
  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-10-25 02:28
  24. * 类描述
  25. * 修订历史:
  26. * 日期:2021-10-25
  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. TmstruckWeightResultMapper tmstruckWeightResultMapper;
  37. @Autowired
  38. TmsFeign tmsFeign;
  39. @Autowired
  40. UtilsServiceImpl utilsService;
  41. @Autowired
  42. UtilsMapper utilsMapper;
  43. @Autowired
  44. TmstruckReceiptResultMapper tmstruckReceiptResultMapper;
  45. /**
  46. * 接收计量实绩信息
  47. * "orderNumber":"WYSDD2021091000000002",
  48. * "resultTareCalculateNumber":"1号汽车衡",
  49. * "resultCrossCalculateNumber":"1号汽车衡",
  50. * "resultTareWeight":40.00,
  51. * "resultCrossWeight":40.00,
  52. * "resultNetWeight":0,
  53. * "resultTareWeightTime":"2021-09-10 09:05:22",
  54. * "resultCrossWeightTime":"2021-09-10 09:05:22",
  55. * "resultNetWeightTime":"2021-09-10 09:05:22",
  56. * "resultPoundNo":"Bd123456780",
  57. * "materialId":40
  58. * @param mapList
  59. * @return
  60. */
  61. @Override
  62. public int receiveTmsTruckWeightResult(List<Map<String, Object>> mapList) throws Exception {
  63. //遍历列表
  64. int count = 0;
  65. for (Map<String, Object> map : mapList) {
  66. //通过传来的运输订单号 与 物资ID查询计重实绩ID
  67. Map<String, Object> stringObjectMap = tmstruckWeightResultMapper.selectTotalIdByOrderNo(map);
  68. if(stringObjectMap == null){
  69. throw new Exception(map.get("orderNumber") + "没有此订单信息或物资信息(" + map.get("materialId") + ")错误");
  70. }
  71. map.putAll(stringObjectMap);
  72. TmstruckWeightResult tmstruckWeightResult = generateWeightResult(map);
  73. count += tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  74. BigDecimal orderType = DataChange.dataToBigDecimal(map.get("orderTypee"));
  75. if("5678".contains(orderType.toString())){
  76. if(map.get("resultTareWeightTime") != null ){
  77. //如果是采购订单 计皮后自动完成签收
  78. autoReceipt((String) map.get("orderNumber"));
  79. }
  80. }
  81. //路段顺序号+1
  82. utilsService.updateOrderLineSequence(map);
  83. //推送数据
  84. utilsService.pushMesToWebsocket((String) stringObjectMap.get("capacityNumber"), "计量");
  85. }
  86. return count;
  87. }
  88. /**
  89. * 生成计量实体类
  90. * @param map
  91. * @return
  92. */
  93. public TmstruckWeightResult generateWeightResult(Map<String, Object> map) throws Exception {
  94. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  95. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  96. tmstruckWeightResult.setId(DataChange.dataToBigDecimal(map.get("weightTaskResultId")));
  97. BigDecimal orderType = DataChange.dataToBigDecimal(map.get("orderTypee"));
  98. //磅单号
  99. tmstruckWeightResult.setResultPoundNo((String) map.get("resultPoundNo"));
  100. //如果是采购订单 先计毛再计皮
  101. if("5678".contains(orderType.toString())){
  102. String resultCrossWeightTime = (String) map.get("resultCrossWeightTime");
  103. //如果毛重数据为空 则是第一次计量为毛重 此时第一次计量时间放皮重时间里面
  104. if(resultCrossWeightTime == null || resultCrossWeightTime.length() == 0){
  105. //设置毛重时间
  106. String firstTime = (String) map.get("resultTareWeightTime");
  107. tmstruckWeightResult.setResultGrossWeightTime(sdf.parse(firstTime));
  108. //添加毛重汽车衡
  109. Integer tareId = tmstruckWeightResultMapper.selectTruckCalculateId((String) map.get("resultTareCalculateNumber"));
  110. if(tareId == null){
  111. throw new Exception("没有此汽车衡:" + map.get("resultTareCalculateNumber"));
  112. }
  113. tmstruckWeightResult.setResultTarePlaceId(new BigDecimal(tareId));
  114. //设置毛重
  115. BigDecimal resultTareWeight = DataChange.dataToBigDecimal(map.get("resultTareWeight"));
  116. tmstruckWeightResult.setResultGrossWeight(resultTareWeight);
  117. tmstruckWeightResult.setInsertTime(new Date());
  118. tmstruckWeightResult.setInsertUsername("admin");
  119. }else {
  120. //设置皮重汽车衡
  121. Integer tareId = tmstruckWeightResultMapper.selectTruckCalculateId((String) map.get("resultTareCalculateNumber"));
  122. if(tareId == null){
  123. throw new Exception("没有此皮重汽车衡:" + map.get("resultTareCalculateNumber"));
  124. }
  125. tmstruckWeightResult.setResultTarePlaceId(new BigDecimal(tareId));
  126. //设置毛重汽车衡
  127. Integer crossId = tmstruckWeightResultMapper.selectTruckCalculateId((String) map.get("resultCrossCalculateNumber"));
  128. if(crossId == null){
  129. throw new Exception("没有此毛重汽车衡:" + map.get("resultCrossCalculateNumber"));
  130. }
  131. tmstruckWeightResult.setResultGrossPlaceId(new BigDecimal(crossId));
  132. //毛重
  133. BigDecimal resultCrossWeight = DataChange.dataToBigDecimal(map.get("resultCrossWeight"));
  134. tmstruckWeightResult.setResultGrossWeight(resultCrossWeight);
  135. //皮重
  136. BigDecimal resultTareWeight = DataChange.dataToBigDecimal(map.get("resultTareWeight"));
  137. tmstruckWeightResult.setResultTareWeight(resultTareWeight);
  138. //净重
  139. tmstruckWeightResult.setResultNetWeight(DataChange.dataToBigDecimal(map.get("resultNetWeight")));
  140. //设置皮重时间
  141. String resultTareWeightTime = (String) map.get("resultTareWeightTime");
  142. tmstruckWeightResult.setResultTareWeightTime(sdf.parse(resultTareWeightTime));
  143. //设置毛重时间
  144. String resultGrossWeightTime = (String) map.get("resultCrossWeightTime");
  145. tmstruckWeightResult.setResultGrossWeightTime(sdf.parse(resultGrossWeightTime));
  146. tmstruckWeightResult.setUpdateTime(new Date());
  147. tmstruckWeightResult.setUpdateUsername("admin");
  148. }
  149. }
  150. return tmstruckWeightResult;
  151. }
  152. /**
  153. * 自动签收
  154. * @return
  155. */
  156. public void autoReceipt(String orderNumber){
  157. TmstruckReceiptResult tmstruckReceiptResult = new TmstruckReceiptResult();
  158. //通过运输订单号查询总实绩ID
  159. BigDecimal resultTotalId = utilsMapper.getTotalIdByOrderNumber(orderNumber);
  160. tmstruckReceiptResult.setResultTotalId(resultTotalId);
  161. tmstruckReceiptResult.setStatus(new BigDecimal(1));
  162. tmstruckReceiptResult.setInsertUsername("admin");
  163. tmstruckReceiptResult.setInsertTime(new Date());
  164. tmstruckReceiptResultMapper.updateByTotalResultId(tmstruckReceiptResult);
  165. System.out.println(orderNumber + "收货成功");
  166. }
  167. }