TmstrainLoadingResultServiceImpl.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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.service.ITmstrainLoadingResultService;
  6. import com.steerinfo.dil.util.DataChange;
  7. import com.steerinfo.framework.service.pagehelper.PageHelper;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.transaction.annotation.Transactional;
  11. import java.math.BigDecimal;
  12. import java.util.*;
  13. /**
  14. * TmstrainLoadingResult服务实现:
  15. * @author generator
  16. * @version 1.0-SNAPSHORT 2021-08-30 02:23
  17. * 类描述
  18. * 修订历史:
  19. * 日期:2021-08-30
  20. * 作者:generator
  21. * 参考:
  22. * 描述:TmstrainLoadingResult服务实现
  23. * @see null
  24. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  25. */
  26. @Service(value = "tmstrainLoadingResultService")
  27. public class TmstrainLoadingResultServiceImpl implements ITmstrainLoadingResultService {
  28. @Autowired
  29. private TmstrainLoadingResultMapper tmstrainLoadingResultMapper;
  30. @Autowired
  31. private TmstrainLoadingTempMapper tmstrainLoadingTempMapper;
  32. @Autowired
  33. private WmshBoundFeign wmshBoundFeign;
  34. @Autowired
  35. private TmstrainTruckTotalResultMapper tmstrainTruckTotalResultMapper;
  36. @Autowired
  37. private TmstrainTotalResultMapper tmstrainTotalResultMapper;
  38. @Autowired
  39. private TmstrainMeasureCommissionServiceImpl tmstrainMeasureCommissionService;
  40. @Autowired
  41. private TmstrainWeightResultMapper tmstrainWeightResultMapper;
  42. /**
  43. * 查看所有装车实绩
  44. * @param map
  45. * @return
  46. */
  47. @Override
  48. public List<Map<String, Object>> getTmstrainWagonLoad(Map<String, Object> map) {
  49. BigDecimal resultType = DataChange.dataToBigDecimal(map.get("resultType"));
  50. switch (resultType.intValue()){
  51. case 1:
  52. case 2:
  53. case 3:
  54. List<Map<String, Object>> tmsWagonLoadInfo = tmstrainLoadingResultMapper.getTmsWagonLoadInfo(map);// apiId = 58 - 209
  55. for (Map<String, Object> obj : tmsWagonLoadInfo) {
  56. Integer deleted = DataChange.dataToBigDecimal(obj.get("deleted")).intValue();
  57. if(deleted == 0){
  58. obj.put("isUnload", "已装车");
  59. }else {
  60. obj.put("isUnload", "已卸车");
  61. }
  62. }
  63. return tmsWagonLoadInfo;
  64. case 4:
  65. return tmstrainLoadingResultMapper.selectLoadedForConverted(map); //apiId = 203
  66. case 10:
  67. //查询国产矿需要补录的装车实绩
  68. return tmstrainLoadingResultMapper.getNoPurOrderIdLoadResult(map); //apiId = 209
  69. }
  70. return null;
  71. }
  72. /**
  73. * 添加火运总实绩
  74. * @param loadingId
  75. * @return
  76. */
  77. public int addTotalResult(BigDecimal loadingId){
  78. TmstrainTotalResult tmstrainTotalResult = new TmstrainTotalResult();
  79. BigDecimal maxId = tmstrainTotalResultMapper.selectMaxId();
  80. tmstrainTotalResult.setId(maxId); //获取添加火运总实绩主键ID
  81. //生成火运单号
  82. tmstrainTotalResult.setTransportNum(DataChange.generateEightDigitsNumber("WTRAN", maxId.intValue()));
  83. //添加火运装车实绩ID
  84. tmstrainTotalResult.setLoadingId(loadingId);
  85. //新增计量实绩
  86. TmstrainWeightResult tmstrainWeightResult=new TmstrainWeightResult();
  87. tmstrainWeightResult.setResultId(tmstrainWeightResultMapper.selectMaxId());
  88. tmstrainWeightResult.setResultTotalId(maxId);
  89. tmstrainWeightResultMapper.insertSelective(tmstrainWeightResult);
  90. return tmstrainTotalResultMapper.insertSelective(tmstrainTotalResult);
  91. }
  92. /**
  93. * 进口矿新增装车实绩
  94. * @param mapValue
  95. * @return
  96. */
  97. @Override
  98. @Transactional
  99. public int addTmstrainLoadingResult(Map<String,Object> mapValue) throws Exception{
  100. List<Map<String, Object>> list= (List<Map<String, Object>>) mapValue.get("list");
  101. String userId=null;
  102. if(mapValue.get("userId")!=null)
  103. userId=mapValue.get("userId").toString();
  104. else
  105. throw new Exception("用户id为空,请先登录再操作!");
  106. //装车实绩list
  107. List<TmstrainLoadingResult> loadingResults=new ArrayList<>();
  108. //取分隔符
  109. List<String> splits=tmstrainLoadingResultMapper.findSplitsForImported();
  110. int i = 0;
  111. for(Map<String,Object> map:list){
  112. TmstrainLoadingResult result=new TmstrainLoadingResult();
  113. //设置序列号主键
  114. BigDecimal maxId = tmstrainLoadingResultMapper.selectMaxId();
  115. result.setResultId(maxId);
  116. //配单
  117. List<Map<String,Object>> orderList= tmstrainLoadingResultMapper.getPurchaseOrderListForImported(map);//第一次模糊查询
  118. if(orderList.size() > 1){
  119. //根据外轮船名模糊查找不唯一,再根据物资名和外轮船名匹配
  120. map.put("materialName",map.get("mineral"));
  121. String productName=map.get("productName").toString();
  122. for(String split:splits){
  123. String arr[]=productName.split(split);
  124. if(arr.length>1){
  125. //切割成功,退出
  126. map.put("resultForeignShipName",arr[1]);
  127. break;
  128. }
  129. }
  130. orderList= tmstrainLoadingResultMapper.getPurchaseOrderListForImported(map);
  131. }
  132. if(orderList.size() > 0){
  133. Map<String,Object> details=orderList.get(0);
  134. BigDecimal purchaseOrderId=DataChange.dataToBigDecimal(details.get("purchaseOrderId"));
  135. BigDecimal materialId=DataChange.dataToBigDecimal(details.get("materialId"));
  136. BigDecimal supplierId=DataChange.dataToBigDecimal(details.get("supplierId"));
  137. BigDecimal batchId=DataChange.dataToBigDecimal(details.get("batchId"));
  138. result.setPurchaseOrderRailPlanId(purchaseOrderId);
  139. result.setMaterialId(materialId);
  140. result.setSendUnitId(supplierId);
  141. result.setBatchId(batchId);
  142. }else{
  143. throw new Exception("没有对应的进口矿采购订单号:"+map.get("productName").toString());
  144. }
  145. //处理实绩表
  146. result.setSendStationId(DataChange.dataToBigDecimal(mapValue.get("sendStationId")));//发站
  147. result.setArrivalStationId(DataChange.dataToBigDecimal(mapValue.get("arrivalStationId")));//到站
  148. result.setResultLoadingDate(new Date((Long)mapValue.get("resultLoadingDate")));//装车日期
  149. result.setResultType(DataChange.dataToBigDecimal(mapValue.get("resultType")));//装车类型
  150. // result.setResultIsclear(mapValue.get("resultIsclear").toString());
  151. // result.setResultClass(mapValue.get("resultClass").toString());
  152. result.setResultRemarks((String) mapValue.get("resultRemarks"));//备注
  153. result.setResultWagonNo(map.get("wagonNo").toString());//车皮号
  154. //添加常规字段
  155. addRegularField(result,userId);
  156. //通过车皮号计算车皮标重
  157. result.setResultBillableTonnage(new BigDecimal(calculateWagonWeight(result.getResultWagonNo())));
  158. //通过到站ID匹配计量衡 如果是老区轨道衡或者是新区轨道衡 则匹配轨道衡
  159. //如果到站ID是老区轨道衡
  160. BigDecimal arrivalStationId = result.getArrivalStationId();
  161. if(arrivalStationId!=null && arrivalStationId.intValue() == 1){
  162. result.setTrainCalculateId(new BigDecimal(13)); //设置计量衡为 铁专线(老区)
  163. result.setSendRequest(new BigDecimal(1));
  164. }
  165. loadingResults.add(result);
  166. i += addTotalResult(maxId);//添加总实绩和计量实绩
  167. }
  168. //批量插入
  169. int count = tmstrainLoadingResultMapper.batchInsert(loadingResults);
  170. //发送委托
  171. if(count==loadingResults.size()){
  172. ArrayList<Map<String,Object>> resultIdList=new ArrayList<>();
  173. Map<String, Object> map1 = new HashMap<>();
  174. for(TmstrainLoadingResult tmstrainLoadingResult:loadingResults){
  175. Map<String, Object> temp = new HashMap<>();
  176. temp.put("resultId",tmstrainLoadingResult.getResultId());
  177. resultIdList.add(temp);
  178. }
  179. map1.put("resultIdList",resultIdList);
  180. i = tmstrainMeasureCommissionService.batchSendMeasureCommission(map1);
  181. if(i==-1){
  182. throw new Exception("计量委托发送失败!");
  183. }
  184. }
  185. return count;
  186. }
  187. /**
  188. * 国产矿新增导入
  189. * @param mapValue
  190. * @return
  191. */
  192. public int addDomesticLoadResult(Map<String, Object> mapValue) throws Exception {
  193. List<Map<String, Object>> list= (List<Map<String, Object>>) mapValue.get("list");
  194. String userId=null;
  195. if(mapValue.get("userId")!=null)
  196. userId=mapValue.get("userId").toString();
  197. else
  198. throw new Exception("用户id为空,请先登录再操作!");
  199. //装车实绩list
  200. List<TmstrainLoadingResult> loadingResults=new ArrayList<>();
  201. //获取分隔符
  202. List<String> splits=tmstrainLoadingResultMapper.findSplitsForDomestic();
  203. int i = 0;
  204. for(Map<String,Object> map:list){
  205. TmstrainLoadingResult result=new TmstrainLoadingResult();
  206. //设置序列号主键
  207. BigDecimal maxId = tmstrainLoadingResultMapper.selectMaxId();
  208. result.setResultId(maxId);
  209. //配单
  210. List<Map<String,Object>> orderList= tmstrainLoadingResultMapper.getPurchaseOrderList(map);
  211. if(orderList.size() <= 0){
  212. //找不到则对品名拆分,重新查询
  213. String productName=map.get("productName").toString();
  214. for(String split:splits){
  215. String []arr=productName.split(split);
  216. if(arr.length>1){
  217. String supplierName=arr[0];
  218. map.put("supplierName",supplierName);
  219. break;
  220. }
  221. }
  222. orderList=tmstrainLoadingResultMapper.getPurchaseOrderList(map);
  223. }
  224. if(orderList.size() > 0){
  225. Map<String,Object> details=orderList.get(0);
  226. BigDecimal purchaseOrderId=DataChange.dataToBigDecimal(details.get("purchaseOrderId"));
  227. BigDecimal materialId=DataChange.dataToBigDecimal(details.get("materialId"));
  228. BigDecimal supplierId=DataChange.dataToBigDecimal(details.get("supplierId"));
  229. BigDecimal batchId=DataChange.dataToBigDecimal(details.get("batchId"));
  230. result.setPurchaseOrderRailPlanId(purchaseOrderId);
  231. result.setMaterialId(materialId);
  232. result.setSendUnitId(supplierId);
  233. result.setBatchId(batchId);
  234. }else{
  235. throw new Exception("没有对应的国产矿采购订单号:"+map.get("productName"));
  236. }
  237. //处理实绩表
  238. result.setArrivalStationId(new BigDecimal(map.get("arrivalStationId").toString()));//到站
  239. result.setResultLoadingDate(new Date((Long)map.get("resultLoadingDate")));//装车日期
  240. result.setResultType(new BigDecimal(map.get("resultType").toString()));//装车类型,国产矿应该为3
  241. result.setResultRemarks((String) map.get("resultRemarks"));//备注
  242. result.setResultWagonNo(map.get("wagonNo").toString());//车皮号
  243. //取得发站名,查询是否存在该站台,如果存在则绑定,否则新增该站台再绑定
  244. String sendStationName=(String) map.get("sendStation");//发站名
  245. if(sendStationName!=null){
  246. BigDecimal sendStationId=tmstrainLoadingResultMapper.getSendStationId(sendStationName);
  247. if(sendStationId==null){
  248. //如果没有该站,新增
  249. sendStationId=tmstrainLoadingResultMapper.getMaxSendStationId().add(new BigDecimal(1));
  250. Map<String,Object> station=new HashMap<>();
  251. station.put("arrivalId",sendStationId);
  252. station.put("arrivalName",sendStationName);
  253. station.put("insertTime",new Date());
  254. station.put("updateTime",new Date());
  255. if(tmstrainLoadingResultMapper.addSendStation(station)<=0){
  256. throw new Exception("添加发站失败");
  257. }
  258. }
  259. result.setSendStationId(sendStationId);
  260. }
  261. //添加常规字段
  262. addRegularField(result,userId);
  263. //通过车皮号计算车皮标重
  264. result.setResultBillableTonnage(new BigDecimal(calculateWagonWeight(result.getResultWagonNo())));
  265. //通过到站ID匹配计量衡 如果是老区轨道衡或者是新区轨道衡 则匹配轨道衡
  266. //如果到站ID是老区轨道衡
  267. BigDecimal arrivalStationId = result.getArrivalStationId();
  268. if(arrivalStationId!=null && arrivalStationId.intValue() == 1){
  269. result.setTrainCalculateId(new BigDecimal(13)); //设置计量衡为 铁专线(老区)
  270. result.setSendRequest(new BigDecimal(1));
  271. }
  272. loadingResults.add(result);
  273. i += addTotalResult(maxId);
  274. }
  275. //批量插入
  276. int count = tmstrainLoadingResultMapper.batchInsert(loadingResults);
  277. //发送委托
  278. if(count==loadingResults.size()){
  279. ArrayList<Map<String,Object>> resultIdList=new ArrayList<>();
  280. Map<String, Object> map1 = new HashMap<>();
  281. for(TmstrainLoadingResult tmstrainLoadingResult:loadingResults){
  282. Map<String, Object> temp = new HashMap<>();
  283. temp.put("resultId",tmstrainLoadingResult.getResultId());
  284. resultIdList.add(temp);
  285. }
  286. map1.put("resultIdList",resultIdList);
  287. i = tmstrainMeasureCommissionService.batchSendMeasureCommission(map1);
  288. if(i==-1){
  289. throw new Exception("计量委托发送失败!");
  290. }
  291. }
  292. return count;
  293. }
  294. /**
  295. * 国产矿新增配单补录
  296. * @param map
  297. * @return
  298. */
  299. public int updateDomesticLoadResult(Map<String, Object> map) throws Exception {
  300. //获取要补录的实绩ID 列表
  301. List<Integer> resultIdList = (List<Integer>) map.get("resultIdList");
  302. TmstrainLoadingResult tmstrainLoadingResult = new TmstrainLoadingResult();
  303. BigDecimal purchaseOrderId = DataChange.dataToBigDecimal(map.get("purchaseOrderId"));
  304. if(purchaseOrderId.intValue() != 0){
  305. //查询补录信息
  306. Map<String,Object> record=tmstrainLoadingResultMapper.getRecordByPurOrderId(purchaseOrderId);
  307. BigDecimal materialId=DataChange.dataToBigDecimal(record.get("materialId"));
  308. BigDecimal supplierId=DataChange.dataToBigDecimal(record.get("supplierId"));
  309. BigDecimal batchId =DataChange.dataToBigDecimal(record.get("batchId"));
  310. //设置补录字段
  311. tmstrainLoadingResult.setBatchId(batchId);
  312. tmstrainLoadingResult.setMaterialId(materialId);
  313. tmstrainLoadingResult.setSendUnitId(supplierId);
  314. }
  315. tmstrainLoadingResult.setPurchaseOrderRailPlanId(purchaseOrderId); //采购订单Id
  316. if(map.get("userId")!=null)
  317. tmstrainLoadingResult.setUpdateUsername(map.get("userId").toString());
  318. else
  319. throw new Exception("用户id为空,请先登录!");
  320. int count = 0;
  321. //对每一个实绩id对应的记录修改字段
  322. for (Integer resultId : resultIdList) {
  323. tmstrainLoadingResult.setResultId(new BigDecimal(resultId)); //设置要补录的实绩主键
  324. tmstrainLoadingResult.setUpdateTime(new Date());
  325. count += tmstrainLoadingResultMapper.updateByPrimaryKeySelective(tmstrainLoadingResult);
  326. }
  327. //配单成功,发送计量委托
  328. if(resultIdList.size()-count==0){
  329. Map<String, Object> map1 = new HashMap<>();
  330. List<Map<String,Object>> resultIdList1=new ArrayList<>();
  331. for(Integer resultId:resultIdList){
  332. Map<String, Object> temp = new HashMap<>();
  333. temp.put("resultId",resultId);
  334. resultIdList1.add(temp);
  335. }
  336. map1.put("resultIdList",resultIdList1);
  337. int i = tmstrainMeasureCommissionService.batchSendMeasureCommission(map1);
  338. if(i==-1){
  339. return i;
  340. }
  341. }
  342. return count;
  343. }
  344. /**
  345. * 通过车皮标重计算车皮标重
  346. * @return
  347. */
  348. public int calculateWagonWeight(String wagonNo){
  349. String number = wagonNo.substring(0,2);
  350. if (number.equals("14"))
  351. {
  352. String No = wagonNo.substring(0,3);
  353. if (No.equals("143")||No.equals("140")||No.equals("141")||No.equals("142")){
  354. return 60;
  355. }
  356. else if (No.equals("145")){
  357. return 61;
  358. }
  359. }
  360. else if(number.equals("45")||number.equals("46")){
  361. return 60;
  362. }
  363. else if(number.equals("42")||number.equals("47")||number.equals("48")||number.equals("49")){
  364. return 61;
  365. }
  366. else if(number.equals("15")||number.equals("16")||number.equals("17")||number.equals("18")){
  367. return 70;
  368. }
  369. return 0;
  370. }
  371. /**
  372. * 添加港存库出库实绩
  373. * @param map2
  374. * @param batchId
  375. */
  376. public int addOutWarehouse(Map<String,Object> map2, BigDecimal batchId){
  377. Map<String, Object> map = new HashMap<>();
  378. map.put("isClean",map2.get("isClean"));
  379. map.put("resultMaterialNumber",map2.get("resultTonnage"));
  380. map.put("batchId", batchId);
  381. //通过港口名称查找港口id
  382. BigDecimal portId = tmstrainLoadingResultMapper.getPortIdByPortName((String) map2.get("portName"));
  383. map.put("portId", portId);
  384. //根据港口和批次查找唯一的港存库id
  385. BigDecimal gridId = tmstrainLoadingResultMapper.getGridIdByPortAndBatch(map);
  386. map.put("gmId",gridId);
  387. if (map2.get("isClean").equals("清场")){
  388. wmshBoundFeign.clearWmshGridMaterial(map);
  389. }
  390. else {
  391. Map<String, Object> stringObjectMap = wmshBoundFeign.addResult(map);
  392. if (!stringObjectMap.equals("")||stringObjectMap!=null){
  393. return -1;
  394. }
  395. }
  396. return 1;
  397. }
  398. /**
  399. * 添加常规字段
  400. * @param tmstrainLoadingResult
  401. */
  402. public void addRegularField(TmstrainLoadingResult tmstrainLoadingResult,String userName){
  403. //常规字段插入
  404. tmstrainLoadingResult.setInsertUsername(userName);
  405. tmstrainLoadingResult.setInsertTime(new Date());
  406. tmstrainLoadingResult.setInsertUpdateRemark("无");
  407. tmstrainLoadingResult.setDeleted(new BigDecimal(0));
  408. }
  409. /**
  410. * 通过ID获取装车实绩数据
  411. * @param resultId
  412. * @return
  413. */
  414. @Override
  415. public List<Map<String, Object>> getTmstrainLoadingResultByResultId(BigDecimal resultId) {
  416. return tmstrainLoadingResultMapper.selectByResultId(resultId);
  417. }
  418. /**
  419. * 修改进口矿国产矿火运装车实绩
  420. * @param map
  421. * @return
  422. */
  423. @Transactional(rollbackFor = {Exception.class})
  424. @Override
  425. public int updateTmstrainLoadingResult(Map<String,Object> map) throws Exception{
  426. TmstrainLoadingResult tmstrainLoadingResult=new TmstrainLoadingResult();
  427. String wagonNo=map.get("resultWagonNo").toString();
  428. BigDecimal resultId=DataChange.dataToBigDecimal(map.get("resultId"));
  429. Integer resultType=(Integer) map.get("resultType");
  430. if(wagonNo==null || wagonNo.length()!=7 || calculateWagonWeight(wagonNo)<=0){
  431. throw new Exception("车皮号异常");
  432. }else if(resultId==null){
  433. throw new Exception("主键为空");
  434. }else if(resultType==0){
  435. throw new Exception("类型异常");
  436. }
  437. //国产矿未配单仅支持修改部分字段,并且不重新发委托
  438. List<Map<String,Object>> results=tmstrainLoadingResultMapper.selectByResultId(resultId);
  439. if(resultType==3 && results!=null && results.get(0)!=null && results.get(0).get("purchaseOrderNo")==null){
  440. tmstrainLoadingResult.setResultId(resultId);
  441. tmstrainLoadingResult.setResultWagonNo(wagonNo);
  442. tmstrainLoadingResult.setSendStationId(DataChange.dataToBigDecimal(map.get("sendStationId")));
  443. tmstrainLoadingResult.setArrivalStationId(DataChange.dataToBigDecimal(map.get("arrivalStationId")));
  444. tmstrainLoadingResult.setResultLoadingDate(new Date((Long)map.get("resultLoadingDate")));
  445. if(map.get("resultRemarks")!=null)
  446. tmstrainLoadingResult.setResultRemarks(map.get("resultRemarks").toString());
  447. tmstrainLoadingResultMapper.updateByPrimaryKeySelective(tmstrainLoadingResult);
  448. return 1;
  449. }
  450. //进口矿字段
  451. if(resultType!=3){
  452. if(map.get("resultClass")!=null)
  453. tmstrainLoadingResult.setResultClass(map.get("resultClass").toString());
  454. if(map.get("resultIsclear")!=null)
  455. tmstrainLoadingResult.setResultIsclear(map.get("resultIsclear").toString());
  456. if(map.get("capacityId")!=null)
  457. tmstrainLoadingResult.setCapacityId(DataChange.dataToBigDecimal(map.get("capacityId")));
  458. if(map.get("resultBillableTonnage")!=null)
  459. tmstrainLoadingResult.setResultBillableTonnage(DataChange.dataToBigDecimal(map.get("resultBillableTonnage")));
  460. }
  461. //通过采购订单号查询获得采购订单ID、批次ID、物资ID、发货单位ID
  462. if(map.get("purchaseOrderNo")!=null){
  463. String purchaseOrderNo = map.get("purchaseOrderNo").toString() ;
  464. BigDecimal purchaseOrderId = tmstrainLoadingResultMapper.getPurchaseOrderIdByPurOrderNo(purchaseOrderNo);
  465. BigDecimal batchId = tmstrainLoadingResultMapper.getBatchIdByPurOrderNo(purchaseOrderNo);
  466. Map<String,Object> record=tmstrainLoadingResultMapper.getRecordByPurOrderId(purchaseOrderId);
  467. BigDecimal materialId=DataChange.dataToBigDecimal(record.get("materialId"));
  468. BigDecimal supplierId=DataChange.dataToBigDecimal(record.get("supplierId"));
  469. if(purchaseOrderId==null || batchId==null ||materialId==null ||supplierId==null){
  470. throw new Exception("采购订单号异常");
  471. }
  472. tmstrainLoadingResult.setBatchId(batchId);
  473. tmstrainLoadingResult.setPurchaseOrderRailPlanId(purchaseOrderId);
  474. tmstrainLoadingResult.setMaterialId(materialId);
  475. tmstrainLoadingResult.setSendUnitId(supplierId);
  476. }
  477. //设置其他字段
  478. tmstrainLoadingResult.setResultId(resultId);
  479. tmstrainLoadingResult.setResultWagonNo(wagonNo);
  480. tmstrainLoadingResult.setSendStationId(DataChange.dataToBigDecimal(map.get("sendStationId")));
  481. tmstrainLoadingResult.setArrivalStationId(DataChange.dataToBigDecimal(map.get("arrivalStationId")));
  482. tmstrainLoadingResult.setResultLoadingDate(new Date((Long)map.get("resultLoadingDate")));
  483. if(map.get("resultRemarks")!=null)
  484. tmstrainLoadingResult.setResultRemarks(map.get("resultRemarks").toString());
  485. tmstrainLoadingResult.setUpdateTime(new Date());
  486. if(map.get("userId")!=null){
  487. tmstrainLoadingResult.setUpdateUsername(map.get("userId").toString());
  488. }else{
  489. throw new Exception("没有用户id,请登录再操作!");
  490. }
  491. //更新
  492. int count=tmstrainLoadingResultMapper.updateByPrimaryKeySelective(tmstrainLoadingResult);
  493. if(count <= 0){
  494. throw new Exception("修改失败");
  495. }
  496. //修改成功,发送计量委托
  497. List<Map<String, Object>> resultIdList = new ArrayList<>();
  498. Map<String, Object> map1 = new HashMap<>();
  499. Map<String, Object> map2 = new HashMap<>();
  500. map1.put("resultId",resultId);
  501. resultIdList.add(map1);
  502. map2.put("resultIdList",resultIdList);
  503. count = tmstrainMeasureCommissionService.batchSendMeasureCommission(map2);
  504. if(count<=0)
  505. throw new Exception("发送计量委托失败");
  506. return count;
  507. }
  508. /**
  509. * 删除装车作业
  510. * @param resultId
  511. * @return
  512. */
  513. @Override
  514. public int deleteTmstrainLoadingResultByResultId(BigDecimal resultId) {
  515. TmstrainLoadingResult tmstrainLoadingResult = new TmstrainLoadingResult();
  516. tmstrainLoadingResult.setResultId(resultId);
  517. tmstrainLoadingResult.setDeleted(new BigDecimal(1));
  518. return tmstrainLoadingResultMapper.updateByPrimaryKeySelective(tmstrainLoadingResult);
  519. }
  520. /**
  521. * 内转添加装车实绩
  522. * "railPlanId": 1,
  523. * "resultClass":"白班",
  524. * "resultWagonNo":"1609999",
  525. * "insertUpdateRemark": "这是第二条",
  526. * "scanCodeText": "HRB400E-12-21706023-9-3077-385-20210909120037-a0691de83a1a1fef-08010103010100014-20"
  527. * @param map
  528. * @return
  529. */
  530. @Override
  531. @Transactional
  532. public int addTrainLoadResultForConverted(Map<String, Object> map) {
  533. int count = 0;
  534. TmstrainLoadingResult tmstrainLoadingResult = new TmstrainLoadingResult();
  535. String resultWagonNo = (String) map.get("resultWagonNo"); //车皮号
  536. BigDecimal railPlanId = DataChange.dataToBigDecimal(map.get("railPlanId")); //发运计划ID
  537. Integer loadingId = tmstrainLoadingResultMapper.getLoadingIdByWnoAndRailPlanId(resultWagonNo, railPlanId.intValue());
  538. //通过火运装车实绩ID查询火运总实绩ID 如果火运装车实绩不为空
  539. BigDecimal trainTotalId = null;
  540. if(loadingId != null){
  541. trainTotalId = tmstrainTotalResultMapper.getTotalIdByLoadingId(loadingId);
  542. }
  543. //如果没有这个车皮号和发运计划的装车实绩,则新增一条装车实绩
  544. if(loadingId == null){
  545. //获取装车实绩主键ID
  546. BigDecimal maxId = tmstrainLoadingResultMapper.selectMaxId();
  547. tmstrainLoadingResult.setId(maxId);
  548. //获取发运计划ID
  549. tmstrainLoadingResult.setPurchaseOrderRailPlanId(railPlanId);
  550. tmstrainLoadingResult.setResultWagonNo(resultWagonNo);
  551. //通过车皮号计算车皮标重
  552. tmstrainLoadingResult.setResultBillableTonnage(new BigDecimal(calculateWagonWeight(resultWagonNo)));
  553. tmstrainLoadingResult.setResultLoadingDate(new Date());
  554. tmstrainLoadingResult.setResultClass((String) map.get("resultClass")); //班别
  555. tmstrainLoadingResult.setInsertUpdateRemark((String) map.get("insertUpdateRemark"));
  556. tmstrainLoadingResult.setInsertTime(new Date());
  557. tmstrainLoadingResult.setInsertUsername("admin");
  558. tmstrainLoadingResult.setResultType(new BigDecimal(4)); //内转类型
  559. tmstrainLoadingResult.setDeleted(new BigDecimal(0)); //逻辑删除0
  560. //添加车皮装车实绩
  561. count += tmstrainLoadingResultMapper.insertSelective(tmstrainLoadingResult);
  562. //添加火运总实绩
  563. TmstrainTotalResult tmstrainTotalResult = new TmstrainTotalResult();
  564. trainTotalId = tmstrainTotalResultMapper.selectMaxId();
  565. tmstrainTotalResult.setId(trainTotalId); //获取添加火运总实绩主键ID
  566. //添加火运装车实绩ID
  567. tmstrainTotalResult.setLoadingId(maxId);
  568. count += tmstrainTotalResultMapper.insertSelective(tmstrainTotalResult);
  569. }
  570. //通过物资扫描结果匹配出库主键ID
  571. Integer outBoundResultId = tmstrainLoadingResultMapper.getOutBoundResultIdByScan((String) map.get("scanCodeText"));
  572. //通过出库主键查询汽运总实绩ID和物资ID
  573. Map<String, Object> mesMap = tmstrainLoadingResultMapper.getResultTotalIdByOutBoundResultId(outBoundResultId);
  574. //通过汽运总实绩ID查询该订单是否已装车(扫一件即可全部扫描上)
  575. Integer resultId = tmstrainLoadingResultMapper.getTrainTruckIdByTruckTotalId(DataChange.dataToBigDecimal(mesMap.get("resultTotalId")));
  576. if(resultId != null){
  577. return 1; //如果已经扫描上了则默认已装车
  578. }
  579. //添加火运物资中间表
  580. TmstrainTruckTotalResult tmstrainTruckTotalResult = new TmstrainTruckTotalResult();
  581. tmstrainTruckTotalResult.setResultId(tmstrainTruckTotalResultMapper.selectMaxId());//添加火运物资中间表主键ID
  582. tmstrainTruckTotalResult.setTmstruckTotalResultId(DataChange.dataToBigDecimal(mesMap.get("resultTotalId")));//添加汽运总实绩ID
  583. tmstrainTruckTotalResult.setMaterialId(DataChange.dataToBigDecimal(mesMap.get("materialId")));//添加物资ID
  584. tmstrainTruckTotalResult.setTmstrainTotalResultId(trainTotalId);//添加火运总实绩ID
  585. tmstrainTruckTotalResult.setLoadStatus(new BigDecimal(0)); //已装车
  586. tmstrainTruckTotalResult.setInsertTime(new Date());
  587. tmstrainTruckTotalResult.setInsertUsername("admin");
  588. count += tmstrainTruckTotalResultMapper.insertSelective(tmstrainTruckTotalResult);
  589. return count;
  590. }
  591. @Override
  592. public List<Map<String, Object>> selectLoadByResultId(BigDecimal resultId) {
  593. return tmstrainLoadingResultMapper.selectLoadByResultId(resultId);
  594. }
  595. @Override
  596. public List<Map<String, Object>> getSendStationName() {
  597. return tmstrainLoadingResultMapper.getSendStationName();
  598. }
  599. @Override
  600. public List<Map<String, Object>> getArrivalStationName() {
  601. return tmstrainLoadingResultMapper.getArrivalStationName();
  602. }
  603. @Override
  604. public List<Map<String, Object>> getBatchId() {
  605. return tmstrainLoadingResultMapper.getBatchId();
  606. }
  607. @Override
  608. public List<Map<String, Object>> getWagonNo(Map<String, Object> map) {
  609. return tmstrainLoadingResultMapper.getWagonNo(map);
  610. }
  611. /**
  612. * 内转查询车皮物资信息
  613. * @param map
  614. * @return
  615. */
  616. @Override
  617. public List<Map<String, Object>> getMaterialAndCarByLoadingId(Map<String, Object> map) {
  618. return tmstrainLoadingResultMapper.getMaterialAndCarByLoadingId(map);
  619. }
  620. /**
  621. * 根据物资名和外轮船名查询采购订单号
  622. * @param map
  623. * @return
  624. */
  625. @Override
  626. public List<Map<String, Object>> getPurchaseOrderList(Map<String, Object> map) {
  627. return tmstrainLoadingResultMapper.getPurchaseOrderList(map);
  628. }
  629. //万州港出库
  630. @Override
  631. @Transactional
  632. public int addWarehouseOutResult(Map<String, Object> map) {
  633. //根据车皮号计算标重
  634. BigDecimal resultType =DataChange.dataToBigDecimal(map.get("resultType"));
  635. List<Map<String,Object>> wagonList =(List<Map<String, Object>>) map.get("wagonList");
  636. for (Map<String,Object> wagon:wagonList){
  637. //根据车皮号计算车皮标重
  638. String wagonNo =(String) wagon.get("wagonNo");
  639. //根据采购订单号查找批次
  640. String purchaseNo =(String) map.get("purchaseNo");
  641. BigDecimal batchId=null;
  642. List<Map<String, Object>> batchInfocatoryByNo = tmstrainLoadingResultMapper.getBatchInfocatoryByNo(purchaseNo);
  643. if (batchInfocatoryByNo.size() >= 1){
  644. Map<String, Object> map1 = batchInfocatoryByNo.get(0);
  645. batchId =DataChange.dataToBigDecimal(map1.get("batchId"));
  646. }
  647. int wagonWeight = calculateWagonWeight(wagonNo);
  648. map.put("resultTonnage",wagonWeight);
  649. //如果订单类型为采购进口矿火运(万州港---达州 || 万州港--老区轨道衡) 添加总车皮标重传输给港存库
  650. if(resultType.intValue() == 1){
  651. int i = addOutWarehouse(map, batchId);
  652. return i;
  653. }
  654. }
  655. return 0;
  656. }
  657. }