TmstrainWeightResultServiceImpl.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package com.steerinfo.dil.service.impl;
  2. import com.steerinfo.dil.mapper.TmstruckWeightResultMapper;
  3. import com.steerinfo.dil.util.DataChange;
  4. import com.steerinfo.framework.mapper.IBaseMapper;
  5. import com.steerinfo.framework.service.impl.BaseServiceImpl;
  6. import com.steerinfo.dil.model.TmstrainWeightResult;
  7. import com.steerinfo.dil.mapper.TmstrainWeightResultMapper;
  8. import com.steerinfo.dil.service.ITmstrainWeightResultService;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import java.text.SimpleDateFormat;
  12. import java.util.Date;
  13. import java.math.BigDecimal;
  14. import java.util.Map;
  15. /**
  16. * TmstrainWeightResult服务实现:
  17. * @author generator
  18. * @version 1.0-SNAPSHORT 2021-12-08 04:34
  19. * 类描述
  20. * 修订历史:
  21. * 日期:2021-12-08
  22. * 作者:generator
  23. * 参考:
  24. * 描述:TmstrainWeightResult服务实现
  25. * @see null
  26. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  27. */
  28. @Service(value = "tmstrainWeightResultService")
  29. public class TmstrainWeightResultServiceImpl implements ITmstrainWeightResultService {
  30. @Autowired
  31. private TmstrainWeightResultMapper tmstrainWeightResultMapper;
  32. @Autowired
  33. private TmstruckWeightResultMapper tmstruckWeightResultMapper;
  34. final private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  35. /**
  36. * 添加火车计量实绩
  37. * @param map
  38. * @return
  39. */
  40. public String addTrainWeightResult(Map<String, Object> map){
  41. String transportNum = String.valueOf(map.get("orderNumber"));
  42. Map<String, Object> mesMap = tmstrainWeightResultMapper.getTrainResultTotalMes(transportNum);
  43. if(mesMap == null){
  44. return "错误";
  45. }
  46. map.putAll(mesMap);
  47. TmstrainWeightResult tmstrainWeightResult = null;
  48. try {
  49. tmstrainWeightResult = generateTrainWeightResult(map);
  50. } catch (Exception e) {
  51. return e.getMessage(); //捕获异常信息
  52. }
  53. Object resultCrossWeightTime = map.get("resultCrossWeightTime");
  54. if(resultCrossWeightTime == null || "".equals(resultCrossWeightTime)){
  55. //如果没有毛重时间 则进行新增
  56. tmstrainWeightResultMapper.insertSelective(tmstrainWeightResult);
  57. }else {
  58. //反之则进行更新 根据总实绩ID进行更新
  59. tmstrainWeightResultMapper.updateByResultTotalIdSelective(tmstrainWeightResult);
  60. }
  61. return "成功";
  62. }
  63. /**
  64. * 生成火运计量实体
  65. * @param map
  66. * @return
  67. */
  68. public TmstrainWeightResult generateTrainWeightResult(Map<String, Object> map) throws Exception {
  69. TmstrainWeightResult tmstrainWeightResult = new TmstrainWeightResult();
  70. //磅单号
  71. tmstrainWeightResult.setResultPoundNo((String) map.get("resultPoundNo"));
  72. //添加火运总实绩ID
  73. tmstrainWeightResult.setResultTotalId(DataChange.dataToBigDecimal(map.get("resultTotalId")));
  74. //设置物资ID
  75. Object materialId = map.get("materialId");
  76. if(materialId != null && !"".equals(materialId)){
  77. tmstrainWeightResult.setMaterialId(DataChange.dataToBigDecimal(materialId));
  78. }
  79. //如果没有计毛时间 则是第一次计量
  80. String resultCrossWeightTime = (String) map.get("resultCrossWeightTime");
  81. if(resultCrossWeightTime == null || resultCrossWeightTime.length() == 0){
  82. //执行新增主键
  83. tmstrainWeightResult.setResultId(tmstrainWeightResultMapper.selectMaxId());
  84. //设置毛重时间
  85. tmstrainWeightResult.setResultGrossWeightTime(DataChange.dataToDate(map.get("resultTareWeightTime")));
  86. //添加毛重轨道衡
  87. Integer tareId = tmstruckWeightResultMapper.selectTruckCalculateId(String.valueOf(map.get("resultTareCalculateNumber")));
  88. if(tareId == null){
  89. throw new Exception("没有此计量衡:" + map.get("resultTareCalculateNumber"));
  90. }
  91. tmstrainWeightResult.setResultGrossPlaceId(new BigDecimal(tareId));
  92. //设置毛重
  93. tmstrainWeightResult.setResultGrossWeight(DataChange.dataToBigDecimal(map.get("resultTareWeight")));
  94. tmstrainWeightResult.setInsertTime(new Date());
  95. tmstrainWeightResult.setInsertUsername("admin");
  96. }else {
  97. //设置皮重汽车衡
  98. String resultTareCalculateNumber = (String) map.get("resultTareCalculateNumber");
  99. if(resultTareCalculateNumber != null){
  100. if(!"".equals(resultTareCalculateNumber)){
  101. Integer tareId = tmstruckWeightResultMapper.selectTruckCalculateId(resultTareCalculateNumber);
  102. if(tareId == null){
  103. throw new Exception("没有此皮重汽车衡:" + map.get("resultTareCalculateNumber"));
  104. }
  105. tmstrainWeightResult.setResultTarePlaceId(new BigDecimal(tareId));
  106. }
  107. }
  108. //设置毛重汽车衡
  109. String resultCrossCalculateNumber = (String) map.get("resultCrossCalculateNumber");
  110. if(resultCrossCalculateNumber != null){
  111. if(!"".equals(resultCrossCalculateNumber)){
  112. Integer crossId = tmstruckWeightResultMapper.selectTruckCalculateId(resultCrossCalculateNumber);
  113. if(crossId == null){
  114. throw new Exception("没有此毛重汽车衡:" + map.get("resultCrossCalculateNumber"));
  115. }
  116. tmstrainWeightResult.setResultGrossPlaceId(new BigDecimal(crossId));
  117. }
  118. }
  119. //毛重
  120. if(map.get("resultCrossWeight") != null){
  121. String resultCrossWeight = String.valueOf(map.get("resultCrossWeight"));
  122. if(!"".equals(resultCrossWeight))
  123. tmstrainWeightResult.setResultGrossWeight(DataChange.dataToBigDecimal(resultCrossWeight));
  124. }
  125. //皮重
  126. if(map.get("resultTareWeight") != null){
  127. String resultTareWeight = String.valueOf(map.get("resultTareWeight"));
  128. if(!"".equals(resultTareWeight))
  129. tmstrainWeightResult.setResultTareWeight(DataChange.dataToBigDecimal(resultTareWeight));
  130. }
  131. //净重
  132. if(map.get("resultNetWeight") != null){
  133. String resultNetWeight = String.valueOf(map.get("resultNetWeight"));
  134. if(!"".equals(resultNetWeight)){
  135. tmstrainWeightResult.setResultNetWeight(DataChange.dataToBigDecimal(resultNetWeight));
  136. }
  137. }
  138. //设置皮重时间
  139. if(map.get("resultTareWeightTime") != null){
  140. String resultTareWeightTime = (String) map.get("resultTareWeightTime");
  141. if(!"".equals(resultTareWeightTime)){
  142. tmstrainWeightResult.setResultTareWeightTime(sdf.parse(resultTareWeightTime));
  143. }
  144. }
  145. //设置毛重时间
  146. if(map.get("resultCrossWeightTime") != null){
  147. String resultGrossWeightTime = (String) map.get("resultCrossWeightTime");
  148. if(!"".equals(resultGrossWeightTime)){
  149. tmstrainWeightResult.setResultGrossWeightTime(sdf.parse(resultGrossWeightTime));
  150. }
  151. }
  152. tmstrainWeightResult.setUpdateTime(new Date());
  153. tmstrainWeightResult.setUpdateUsername("admin");
  154. }
  155. return tmstrainWeightResult;
  156. }
  157. }