TmsshipLoadShipResultServiceImpl.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. package com.steerinfo.dil.service.impl;
  2. import com.steerinfo.dil.feign.WmshboundFeign;
  3. import com.steerinfo.dil.mapper.*;
  4. import com.steerinfo.dil.model.*;
  5. import com.steerinfo.dil.util.DataChange;
  6. import com.steerinfo.dil.util.NoUtil;
  7. import com.steerinfo.framework.controller.RESTfulResult;
  8. import com.steerinfo.dil.service.ITmsshipLoadShipResultService;
  9. import org.apache.poi.ss.formula.functions.T;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import java.math.BigDecimal;
  14. import java.util.Date;
  15. import java.util.HashMap;
  16. import java.util.List;
  17. import java.util.Map;
  18. /**
  19. * TmsshipLoadShipResult服务实现:
  20. * @author generator
  21. * @version 1.0-SNAPSHORT 2021-08-19 08:47
  22. * 类描述
  23. * 修订历史:
  24. * 日期:2021-08-19
  25. * 作者:generator
  26. * 参考:
  27. * 描述:TmsshipLoadShipResult服务实现
  28. * @see null
  29. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  30. */
  31. @Service(value = "tmsshipLoadShipResultService")
  32. public class TmsshipLoadShipResultServiceImpl implements ITmsshipLoadShipResultService {
  33. @Autowired
  34. TmsshipLoadShipResultMapper tmsshipLoadShipResultMapper;
  35. @Autowired
  36. TmsshipTotalResultServiceImpl tmsshipTotalResultService;
  37. @Autowired
  38. TmsshipEntryWharyResultMapper tmsshipEntryWharyResultMapper;
  39. @Autowired
  40. TmsshipOutWharyResultMapper tmsshipOutWharyResultMapper;
  41. @Autowired
  42. TmsshipShipLocationMapper tmsshipShipLocationMapper;
  43. @Autowired
  44. TmsshipWaterQualityResultMapper tmsshipWaterQualityResultMapper;
  45. @Autowired
  46. WmshboundFeign wmshboundFeign;
  47. @Autowired
  48. NoUtil noUtil;
  49. /**
  50. * 新增抵港,离岗,装船实绩
  51. * @param map
  52. * @return
  53. */
  54. @Override
  55. @Transactional
  56. public int insertLoadShip(Map<String,Object> map) throws Exception {
  57. int i=0;
  58. Map<String,Object> mapVal = (Map<String, Object>) map.get("mapVal");
  59. Map<String,Object> rowMap = (Map<String, Object>) map.get("rowMap");
  60. String userId =(String) mapVal.get("userId");
  61. TmsshipLoadShipResult tmsshipLoadShipResult = new TmsshipLoadShipResult();
  62. TmsshipEntryWharyResult tmsshipEntryWharyResult = new TmsshipEntryWharyResult();
  63. BigDecimal orderId = new BigDecimal((Integer) rowMap.get("orderId"));
  64. BigDecimal batchInfactoryId= DataChange.dataToBigDecimal(rowMap.get("batchInfactoryId"));
  65. Map<String,Object> ppMap = tmsshipLoadShipResultMapper.getPortAndPier(batchInfactoryId);
  66. BigDecimal batchId =DataChange.dataToBigDecimal(rowMap.get("batchId"));
  67. BigDecimal pierId = (BigDecimal) ppMap.get("pierId");
  68. Date noticeDeliveryTime = (Date) ppMap.get("noticeDeliveryTime");
  69. BigDecimal startPortId = DataChange.dataToBigDecimal(ppMap.get("startPortId"));
  70. String resultMemo = (String) mapVal.get("resultMemo");
  71. Date resultArrivalTime = new Date((Long)mapVal.get("resultArrivalTime"));
  72. tmsshipLoadShipResult.setResultArrivalPortTime(resultArrivalTime);
  73. BigDecimal totalResultId = tmsshipTotalResultService.getResultTotalId(orderId);
  74. tmsshipEntryWharyResult.setTotalResultId(totalResultId);
  75. BigDecimal resultEntryId = tmsshipEntryWharyResultMapper.selectEntryId();
  76. tmsshipEntryWharyResult.setResultId(resultEntryId);
  77. String resultEntryNumber = noUtil.setResultNo("DG",resultEntryId);
  78. tmsshipEntryWharyResult.setResultNumber(resultEntryNumber);
  79. tmsshipEntryWharyResult.setWharyId(pierId);
  80. //抵港时间
  81. tmsshipEntryWharyResult.setResultArrivalTime(resultArrivalTime);
  82. if (resultMemo!=null) {
  83. tmsshipEntryWharyResult.setResultMemo(resultMemo);
  84. }
  85. //离港确认人
  86. String resultOutWharyName =(String) mapVal.get("resultOutWharyName");
  87. long resultOutWharyTime = (long) mapVal.get("resultOutWharyTime");
  88. tmsshipEntryWharyResult.setResultPortDeclarationName(resultOutWharyName);
  89. // 设置常规字段
  90. tmsshipEntryWharyResult.setInsertTime(new Date());
  91. tmsshipEntryWharyResult.setInsertUsername(userId);
  92. TmsshipOutWharyResult tmsshipOutWharyResult = new TmsshipOutWharyResult();
  93. tmsshipOutWharyResult.setTotalResultId(totalResultId);
  94. BigDecimal resultOutId = tmsshipOutWharyResultMapper.selectOutId();
  95. tmsshipOutWharyResult.setResultId(resultOutId);
  96. String resultOutNumber = noUtil.setResultNo("LG",resultOutId);
  97. tmsshipOutWharyResult.setResultNumber(resultOutNumber);
  98. tmsshipOutWharyResult.setResultOutWharyName(resultOutWharyName);
  99. tmsshipOutWharyResult.setResultOutWharyTime(new Date(resultOutWharyTime));
  100. tmsshipOutWharyResult.setWharyId(pierId);
  101. if (resultMemo!=null) {
  102. tmsshipOutWharyResult.setResultMemo(resultMemo);
  103. }
  104. // 设置常规字段
  105. tmsshipOutWharyResult.setInsertTime(new Date());
  106. tmsshipOutWharyResult.setInsertUsername(userId);
  107. // 装船
  108. BigDecimal resultId = tmsshipLoadShipResultMapper.selectLoadId();
  109. //通过总实绩id查找船运起运港口
  110. //根据港口和批次Id查询实时库存id
  111. Map<String,Object> idMap=new HashMap<>();
  112. idMap.put("batchInfactoryId",batchId);
  113. idMap.put("downSwimPortId",startPortId);
  114. //查询实时库存
  115. Map<String,Object> gmMap = tmsshipLoadShipResultMapper.selectGmIdByPortId(idMap);
  116. if (gmMap==null) {
  117. return -2;
  118. }else {
  119. BigDecimal gmId = DataChange.dataToBigDecimal(gmMap.get("gmId"));
  120. tmsshipLoadShipResult.setRwarehouseMaterialId(gmId);
  121. }
  122. //获得实装数量
  123. BigDecimal resultActualInstallations = new BigDecimal((String) mapVal.get("resultActualInstallations"));
  124. //装船时间
  125. Date resultLoadShipDate = new Date((Long) mapVal.get("resultLoadShipDate"));
  126. tmsshipLoadShipResult.setResultLoadShipDate(resultLoadShipDate);
  127. //是否清场
  128. String resultIsClear = (String) mapVal.get("resultIsClear");
  129. tmsshipLoadShipResult.setResultIsclear(resultIsClear);
  130. if (resultIsClear.equals("清场")){
  131. wmshboundFeign.clearWmshGridMaterial(gmMap);
  132. }else {
  133. Map<String,Object> outBoundMap=new HashMap<>();
  134. //装船入下游港口港存库库存
  135. outBoundMap.put("portId",rowMap.get("downSwimPortId"));
  136. outBoundMap.put("batchId",rowMap.get("batchId"));
  137. outBoundMap.put("resultMaterialNumber",resultActualInstallations);
  138. wmshboundFeign.addResult(outBoundMap);
  139. }
  140. String resultNumber = noUtil.setResultNo("ZC",resultEntryId);
  141. tmsshipLoadShipResult.setResultId(resultId);
  142. tmsshipLoadShipResult.setTotalResultId(totalResultId);
  143. tmsshipLoadShipResult.setBatchId(batchInfactoryId);
  144. tmsshipLoadShipResult.setResultDeliveryDate(noticeDeliveryTime);
  145. tmsshipLoadShipResult.setResultOutPortTime(new Date(resultOutWharyTime));
  146. tmsshipEntryWharyResult.setResultPortDeclarationName((String) map.get("resultOutWharyName"));
  147. tmsshipLoadShipResult.setResultActualInstallations(resultActualInstallations);
  148. tmsshipLoadShipResult.setResultNumber(resultNumber);
  149. tmsshipLoadShipResult.setInsertUpdateRemark(resultMemo);
  150. // 设置常规字段
  151. tmsshipLoadShipResult.setInsertTime(new Date());
  152. tmsshipLoadShipResult.setInsertUsername(userId);
  153. tmsshipLoadShipResult.setDeleted(new BigDecimal(0));
  154. i += tmsshipEntryWharyResultMapper.insertSelective(tmsshipEntryWharyResult);
  155. i += tmsshipOutWharyResultMapper.insertSelective(tmsshipOutWharyResult);
  156. //获取当前位置
  157. String instructionsShipPosition =(String)rowMap.get("instructionsShipPosition");
  158. //新增位置作业,未到闸
  159. TmsshipShipLocation tmsshipShipLocation=new TmsshipShipLocation();
  160. BigDecimal locationId = tmsshipShipLocationMapper.selectLocationId();
  161. tmsshipShipLocation.setLocationId(locationId);
  162. tmsshipShipLocation.setTotalResultId(totalResultId);
  163. tmsshipShipLocation.setLocationStatus("未到闸船舶");
  164. tmsshipShipLocation.setLocationValue(instructionsShipPosition);
  165. tmsshipShipLocation.setInsertTime(new Date());
  166. tmsshipShipLocation.setLocationRouteTime(new Date());
  167. tmsshipShipLocation.setDeleted(new BigDecimal(0));
  168. i += tmsshipShipLocationMapper.insertSelective(tmsshipShipLocation);
  169. i += tmsshipLoadShipResultMapper.insertSelective(tmsshipLoadShipResult);
  170. //新增水分质检
  171. TmsshipWaterQualityResult tmsshipWaterQualityResult=new TmsshipWaterQualityResult();
  172. BigDecimal qualityId = tmsshipWaterQualityResultMapper.selectQualityId();
  173. tmsshipWaterQualityResult.setTotalResultId(totalResultId);
  174. tmsshipWaterQualityResult.setResultId(qualityId);
  175. //计划日期
  176. long resultPlannedDate = (long) mapVal.get("resultPlannedDate");
  177. tmsshipWaterQualityResult.setResultPlannedDate(new Date(resultPlannedDate));
  178. //预计放货日期
  179. long expectNoticeDate = (long) mapVal.get("expectNoticeDate");
  180. tmsshipWaterQualityResult.setResultEsDeliveryDate(new Date(expectNoticeDate));
  181. //是否需要拼装
  182. String isNeedAssemble =(String) mapVal.get("isNeedAssemble");
  183. tmsshipWaterQualityResult.setIsNeedAssemble(isNeedAssemble);
  184. //单价
  185. BigDecimal waterUnitPrice =DataChange.dataToBigDecimal(mapVal.get("waterUnitPrice"));
  186. tmsshipWaterQualityResult.setWaterUnitPrice(waterUnitPrice);
  187. //空载
  188. String resultEmptyHeavyWaterMeter = (String) mapVal.get("resultEmptyHeavyWaterMeter");
  189. tmsshipWaterQualityResult.setResultEmptyHeavyWaterMeter(resultEmptyHeavyWaterMeter);
  190. BigDecimal contractMoistureValue = DataChange.dataToBigDecimal(mapVal.get("contractMoistureValue"));
  191. tmsshipWaterQualityResult.setResultMoistureContent(contractMoistureValue);
  192. //检测费
  193. BigDecimal resultInspectionFees = DataChange.dataToBigDecimal(map.get("resultInspectionFees"));
  194. tmsshipWaterQualityResult.setResultInspectionFees(resultInspectionFees);
  195. BigDecimal moistureTonnage =DataChange.dataToBigDecimal(mapVal.get("moistureTonnage"));
  196. tmsshipWaterQualityResult.setResultWaterTonnage(moistureTonnage);
  197. i+=tmsshipWaterQualityResultMapper.insertSelective(tmsshipWaterQualityResult);
  198. return i;
  199. }
  200. /**
  201. * 根据主键删除装船
  202. * @param resultId
  203. * @return
  204. */
  205. @Override
  206. public int deleteLoadShip(BigDecimal resultId) {
  207. TmsshipLoadShipResult tmsshipLoadShipResult = selectLoadShip(resultId);
  208. tmsshipLoadShipResult.setDeleted(new BigDecimal(1));
  209. return tmsshipLoadShipResultMapper.updateByPrimaryKeySelective(tmsshipLoadShipResult);
  210. }
  211. /**
  212. * 根据主键查询装船
  213. * @param resultId
  214. * @return
  215. */
  216. @Override
  217. public TmsshipLoadShipResult selectLoadShip(BigDecimal resultId) {
  218. return tmsshipLoadShipResultMapper.selectByPrimaryKey(resultId);
  219. }
  220. /**
  221. * 根据主键修改
  222. * @param
  223. * @return
  224. */
  225. @Override
  226. public int updateLoadShip(Map<String,Object> map) {
  227. int i=0;
  228. TmsshipLoadShipResult tmsshipLoadShipResult=new TmsshipLoadShipResult();
  229. tmsshipLoadShipResult.setResultId(DataChange.dataToBigDecimal(map.get("resultId")));
  230. long resultLoadShipDate =(long) map.get("resultLoadShipDate");
  231. tmsshipLoadShipResult.setResultLoadShipDate(new Date(resultLoadShipDate));
  232. tmsshipLoadShipResult.setResultActualInstallations(DataChange.dataToBigDecimal(map.get("resultActualInstallations")));
  233. long resultOutPortTime =(long) map.get("resultOutPortTime");
  234. tmsshipLoadShipResult.setResultOutPortTime(new Date(resultOutPortTime));
  235. long resultArrivalPortTime = (long) map.get("resultArrivalPortTime");
  236. tmsshipLoadShipResult.setResultArrivalPortTime(new Date(resultArrivalPortTime));
  237. tmsshipLoadShipResult.setUpdateTime(new Date());
  238. tmsshipLoadShipResult.setUpdateUsername((String) map.get("userId"));
  239. String resultIsClear = (String) map.get("resultIsClear");
  240. tmsshipLoadShipResult.setResultIsclear(resultIsClear);
  241. TmsshipWaterQualityResult tmsshipWaterQualityResult=new TmsshipWaterQualityResult();
  242. tmsshipWaterQualityResult.setResultId(DataChange.dataToBigDecimal(map.get("waterQualiyResultId")));
  243. long planDate =(long) map.get("planDate");
  244. tmsshipWaterQualityResult.setResultPlannedDate(new Date(planDate));
  245. long planDeliveryDate =(long) map.get("planDeliveryDate");
  246. tmsshipWaterQualityResult.setResultEsDeliveryDate(new Date(planDeliveryDate));
  247. String resultHeavyWeight =(String) map.get("resultHeavyWeight");
  248. tmsshipWaterQualityResult.setResultEmptyHeavyWaterMeter(resultHeavyWeight);
  249. TmsshipOutWharyResult tmsshipOutWharyResult=new TmsshipOutWharyResult();
  250. tmsshipOutWharyResult.setResultId(DataChange.dataToBigDecimal(map.get("outWharyResultId")));
  251. tmsshipOutWharyResult.setResultOutWharyTime(new Date(resultOutPortTime));
  252. tmsshipOutWharyResult.setResultOutWharyName((String) map.get("resultOutPortName"));
  253. i += tmsshipOutWharyResultMapper.updateByPrimaryKeySelective(tmsshipOutWharyResult);
  254. i += tmsshipLoadShipResultMapper.updateByPrimaryKeySelective(tmsshipLoadShipResult);
  255. i +=tmsshipWaterQualityResultMapper.updateByPrimaryKeySelective(tmsshipWaterQualityResult);
  256. return i;
  257. }
  258. /**
  259. * 查询所有装船信息
  260. * @param mapVal
  261. * @return
  262. */
  263. @Override
  264. public List<Map<String, Object>> selectLoadShipList(Map<String, Object> mapVal) {
  265. return tmsshipLoadShipResultMapper.selectLoadShipList(mapVal);
  266. }
  267. /**
  268. * 查询一条装船指令下的总重量
  269. * @param instructionsId
  270. * @return
  271. */
  272. @Override
  273. public BigDecimal selectAllWeight(BigDecimal instructionsId) {
  274. return tmsshipLoadShipResultMapper.selectAllWeight(instructionsId);
  275. }
  276. /**
  277. * 查询装船表单
  278. * @param resultId
  279. * @return
  280. */
  281. @Override
  282. public List<Map<String, Object>> getLoadShip(BigDecimal resultId) {
  283. return tmsshipLoadShipResultMapper.selectLoadShip(resultId);
  284. }
  285. /**
  286. * 根据物资名称和外轮船名得到批次
  287. * @param mapVal
  288. * @return
  289. */
  290. @Override
  291. public BigDecimal getBatchId(Map<String, Object> mapVal) {
  292. return tmsshipLoadShipResultMapper.getBatchId(mapVal);
  293. }
  294. }