TmstruckWeightResultServiceImpl.java 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  1. package com.steerinfo.dil.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.steerinfo.dil.feign.OmsFeign;
  4. import com.steerinfo.dil.feign.TmstruckFeign;
  5. import com.steerinfo.dil.mapper.*;
  6. import com.steerinfo.dil.model.OmstruckOrder;
  7. import com.steerinfo.dil.model.TmstruckReceiveResult;
  8. import com.steerinfo.dil.model.TmstruckWeightBatch;
  9. import com.steerinfo.dil.model.TmstruckWeightResult;
  10. import com.steerinfo.dil.service.ITmstruckWeightResultService;
  11. import com.steerinfo.dil.util.DataChange;
  12. import com.steerinfo.dil.util.SaleLogUtil;
  13. import com.steerinfo.dil.util.newFileTool;
  14. import org.apache.commons.lang.time.FastDateFormat;
  15. import org.apache.ibatis.exceptions.TooManyResultsException;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.scripting.groovy.GroovyScriptEvaluator;
  20. import org.springframework.stereotype.Service;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import java.io.IOException;
  23. import java.text.ParseException;
  24. import java.text.SimpleDateFormat;
  25. import java.util.*;
  26. import java.math.BigDecimal;
  27. /**
  28. * TmstruckWeightResult服务实现:
  29. * @author generator
  30. * @version 1.0-SNAPSHORT 2021-10-25 02:28
  31. * 类描述
  32. * 修订历史:
  33. * 日期:2021-10-25
  34. * 作者:generator
  35. * 参考:
  36. * 描述:TmstruckWeightResult服务实现
  37. * @see null
  38. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  39. */
  40. @Service(value = "tmstruckWeightResultService")
  41. public class TmstruckWeightResultServiceImpl implements ITmstruckWeightResultService {
  42. @Autowired
  43. KDWebServiceServiceImpl KDWebServiceServiceImpl;
  44. @Autowired
  45. TmstruckWeightResultMapper tmstruckWeightResultMapper;
  46. @Autowired
  47. UtilsServiceImpl utilsService;
  48. @Autowired
  49. UtilsMapper utilsMapper;
  50. @Autowired
  51. OmsFeign omsFeign;
  52. @Autowired
  53. TmstruckFeign tmstruckFeign;
  54. @Autowired
  55. TmstruckReceiveResultMapper tmstruckReceiveResultMapper;
  56. @Autowired
  57. OmstruckOrderMapper omstruckOrderMapper;
  58. @Autowired
  59. TmstrainWeightResultServiceImpl tmstrainWeightResultService;
  60. @Autowired
  61. SaleLogUtil saleLogUtil;
  62. @Autowired
  63. TmstruckWeightBatchMapper tmstruckWeightBatchMapper;
  64. //属于采购订单的订单类型(先计毛后计皮)
  65. final private List<Integer> judgeOrderTypeList = Arrays.asList(5, 6, 7, 8, 9, 12, 15, 17, 18,23,24,19);
  66. //老厂区需要给金蝶回传的数据订单类型
  67. final private List<Integer> judgeToKDTypeList = Arrays.asList(5,6,7,8,17,18,23,20);
  68. //纯采购订单类型
  69. final private List<Integer> apoOrderType = Arrays.asList(5,6,7,17,18);
  70. //采购内转订单类型
  71. final private List<Integer> apoInwardOrderType = Arrays.asList(10,15,16,23,24,20);
  72. Logger logger = LoggerFactory.getLogger(getClass());
  73. /**
  74. * 接收达钢计量实绩信息
  75. * "orderNumber":"WYSDD2021091000000002",
  76. * "resultTareCalculateNumber":"1号汽车衡",
  77. * "resultCrossCalculateNumber":"1号汽车衡",
  78. * "resultTareWeight":40.00,
  79. * "resultCrossWeight":40.00,
  80. * "resultNetWeight":0,
  81. * "resultTareWeightTime":"2021-09-10 09:05:22",
  82. * "resultCrossWeightTime":"2021-09-10 09:05:22",
  83. * "resultPoundNo":"Bd123456780",
  84. * "materialId":40
  85. * @param mapList
  86. * @return
  87. */
  88. @Override
  89. @Transactional
  90. public String receiveTmsTruckWeightResultByDaGang(List<Map<String, Object>> mapList){
  91. //遍历列表
  92. StringBuilder sb = new StringBuilder();
  93. for (Map<String, Object> map : mapList) {
  94. sb.append(" ");
  95. String resultTareCalculateNumber = (String) map.get("resultTareCalculateNumber");
  96. //如果计量衡名字中含有铁专线 则代表是轨道衡 走轨道衡路线
  97. if(resultTareCalculateNumber.contains("铁专线")){
  98. sb.append(tmstrainWeightResultService.addTrainWeightResult(map));
  99. }else {
  100. //走汽车衡
  101. map.put("needCheckToKD", "1"); //老厂区专属变量 用于区分新、老厂区 老厂区部分秤需要给金蝶传输数据
  102. sb.append(addTruckWeightResult(map));
  103. }
  104. }
  105. return sb.toString();
  106. }
  107. /*
  108. * 接收达兴计量实绩
  109. * @Author TXF
  110. * @Date 2022/2/9 14:57
  111. * @param mapList
  112. * @return
  113. **/
  114. @Transactional
  115. @Override
  116. public String receiveTmsTruckWeightResultByDaXing(List<Map<String, Object>> mapList) {
  117. StringBuilder sb = new StringBuilder();
  118. //遍历列表
  119. for (Map<String, Object> map : mapList) {
  120. sb.append(addTruckWeightResult(map));
  121. }
  122. return sb.toString();
  123. }
  124. /**
  125. * 添加汽车衡计量实绩
  126. * @param map
  127. * @return
  128. */
  129. public String addTruckWeightResult(Map<String, Object> map) {
  130. System.out.println("---------------------------------" + new Date() + "新接收到的计量实绩" + "---------------------------------");
  131. JSONObject jsonObject = new JSONObject(map);
  132. logger.info("计量信息:{}", jsonObject.toString());
  133. System.out.println("---------------------------------" + new Date() + "新接收到的计量实绩" + "---------------------------------");
  134. try{
  135. new Thread( new Runnable() {
  136. public void run(){
  137. try {
  138. newFileTool.newFile(jsonObject.toString(),"计量传输物流实绩");
  139. } catch (IOException e) {
  140. e.printStackTrace();
  141. }
  142. }
  143. }).start();
  144. }catch (Exception e) {
  145. e.printStackTrace();
  146. }
  147. if(map.get("flag") != null && map.get("flag").equals("GCXS")){
  148. System.out.println("这是钢材销售");
  149. TmstruckWeightResult tmstruckWeightResult = null;
  150. try {
  151. tmstruckWeightResult = generateSteelWeightResult(map);
  152. tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  153. utilsService.pushMesToWebsocket((String) map.get("carNo"), "计量");
  154. return map.get("carNo") + "传输成功";
  155. } catch (Exception e) {
  156. try{
  157. new Thread( new Runnable() {
  158. public void run(){
  159. try {
  160. newFileTool.newFile(map.get("carNo") + e.getMessage() + "传输失败","计量传输物流实绩");
  161. } catch (IOException e) {
  162. e.printStackTrace();
  163. }
  164. }
  165. }).start();
  166. }catch (Exception e1) {
  167. e1.printStackTrace();
  168. }
  169. System.out.println(map.get("carNo") + e.getMessage() + "传输失败");
  170. return map.get("carNo") + e.getMessage() + "传输失败";
  171. }
  172. }
  173. //首先通过运输订单号查询订单类型
  174. Map<String, Object> oneMap = utilsMapper.getOrderTypeByOrderNumber((String) map.get("orderNumber")); //用于判断订单类型
  175. if(oneMap == null){
  176. try{
  177. new Thread( new Runnable() {
  178. public void run(){
  179. try {
  180. newFileTool.newFile(map.get("orderNumber") + "系统无此订单" + "传输失败","计量传输物流实绩");
  181. } catch (IOException e) {
  182. e.printStackTrace();
  183. }
  184. }
  185. }).start();
  186. }catch (Exception e) {
  187. e.printStackTrace();
  188. }
  189. return map.get("orderNumber") + "系统无此订单";
  190. }
  191. int orderType= DataChange.dataToBigDecimal(oneMap.get("orderType")).intValue();
  192. if(orderType == 11 || orderType == 15 || orderType == 16){
  193. return insertWeightResultBy11(map, oneMap);
  194. }
  195. //为1的时候计量重新更新单据
  196. if(DataChange.dataToBigDecimal(map.get("WLReUpdateFlag")).intValue() == 1){
  197. return linkUpdateAPO(map, orderType);
  198. }
  199. //通过运输订单号查询计量实绩Id
  200. Map<String, Object> stringObjectMap = tmstruckWeightResultMapper.selectWeightIdByOrderId(map);
  201. if(stringObjectMap == null){
  202. //通过传来的运输订单号 与 物资ID查询计重实绩ID
  203. stringObjectMap = tmstruckWeightResultMapper.selectTotalIdByOrderNo(map);
  204. if(stringObjectMap == null){
  205. try{
  206. new Thread( new Runnable() {
  207. public void run(){
  208. try {
  209. newFileTool.newFile(map.get("orderNumber") + "没有此订单信息或物资信息(" + map.get("materialId") + ")错误" + "传输失败","计量传输物流实绩");
  210. } catch (IOException e) {
  211. e.printStackTrace();
  212. }
  213. }
  214. }).start();
  215. }catch (Exception e) {
  216. e.printStackTrace();
  217. }
  218. return map.get("orderNumber") + "没有此订单信息或物资信息(" + map.get("materialId") + ")错误";
  219. }
  220. }
  221. map.putAll(stringObjectMap);
  222. TmstruckWeightResult tmstruckWeightResult = null;
  223. try {
  224. tmstruckWeightResult = generateWeightResult(map);
  225. } catch (Exception e) {
  226. return e.getMessage();
  227. }
  228. //如果含有这个变量则代表是老区订单需要判断是否回传给金蝶
  229. if(map.get("needCheckToKD") != null){
  230. if(map.get("resultNetWeight") != null){
  231. Object resultCrossWeightTime = map.get("resultCrossWeightTime");
  232. if (judgeToKDTypeList.contains(orderType) && resultCrossWeightTime != null && !"".equals(resultCrossWeightTime)) {
  233. String resultNetWeight = String.valueOf(map.get("resultNetWeight")); //如果净重不为空 或者净重不为0
  234. if (!"null".equals(resultNetWeight) && !"".equals(resultNetWeight) && !"0".equals(resultNetWeight)) {
  235. //回传数据给金蝶方法
  236. sendMesToKD(map, orderType);
  237. }
  238. }
  239. }
  240. }
  241. tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  242. //如果订单类型是零星订单 需要查询一下是否还有未计量物资
  243. if(orderType == 12 || orderType == 13){
  244. dealWithLxOrder(map, stringObjectMap);
  245. }
  246. //根据线路ID去判断
  247. try {
  248. if(oneMap.get("lineId") != null) {
  249. Map<String,Object> lastLineMap = tmstruckWeightResultMapper.getLineName(DataChange.dataToBigDecimal(oneMap.get("lineId")));
  250. String lastLineName = lastLineMap.get("lastLineName").toString();
  251. BigDecimal segmentSqe = DataChange.dataToBigDecimal(lastLineMap.get("segmentSqe"));
  252. TmstruckWeightResult tmsTruckWeightResult1 = tmstruckWeightResultMapper.selectByPrimaryKey(tmstruckWeightResult.getWeightTaskResultId());
  253. if("计毛".equals(lastLineName) && tmstruckWeightResult != null && tmstruckWeightResult.getResultGrossWeight() != null
  254. && tmsTruckWeightResult1.getGrossSegmentSqe().compareTo(segmentSqe) == 0) {
  255. omstruckOrderMapper.updateOrderStatus(DataChange.dataToBigDecimal(oneMap.get("orderIds")));
  256. }
  257. if("计皮".equals(lastLineName) && tmstruckWeightResult != null && tmstruckWeightResult.getResultTareWeight() != null
  258. && tmsTruckWeightResult1.getTareSegmentSqe().compareTo(segmentSqe) == 0) {
  259. omstruckOrderMapper.updateOrderStatus(DataChange.dataToBigDecimal(oneMap.get("orderIds")));
  260. }
  261. }
  262. } catch (Exception e) {
  263. e.printStackTrace();
  264. }
  265. //推送数据
  266. try {
  267. utilsService.pushMesToWebsocket((String) oneMap.get("capacityNumber"), "计量");
  268. } catch (Exception e) {
  269. e.printStackTrace();
  270. }
  271. return map.get("orderNumber") + "成功";
  272. }
  273. private TmstruckWeightResult generateSteelWeightResult(Map<String, Object> map) throws Exception {
  274. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  275. //该数据为不走物流扫码的数据
  276. //1.通过车号去寻找正在作业的5的运输订单号
  277. String carNo = (String) map.get("carNo");
  278. //String FLID = (String) map.get("FLID");
  279. Object resultNetWeight = map.get("resultNetWeight");
  280. Object FLID = map.get("FLID");
  281. List<Map<String,Object>> weightMapList = new ArrayList<>();
  282. if(resultNetWeight != null && !"".equals(resultNetWeight) && FLID != null && !"".equals(FLID)) {
  283. //物资
  284. Object good = map.get("good");
  285. //物资数量
  286. Object goodNum = map.get("goodNum");
  287. //理重
  288. Object theoryWeight = map.get("theoryWeight");
  289. String[] goodList = good.toString().split("、");
  290. String[] flIdList = FLID.toString().split("&");
  291. String[] goodNumList = goodNum.toString().split("、");
  292. String[] theoryWeightList = theoryWeight.toString().split("、");
  293. for(int i = 0 ; i < flIdList.length ; i ++) {
  294. Map<String, Object> codeMap = new HashMap<>();
  295. codeMap.putAll(map);
  296. codeMap.put("FLID",flIdList[i]);
  297. codeMap.put("good",goodList[i]);
  298. codeMap.put("goodNum",goodNumList[i]);
  299. codeMap.put("theoryWeight",theoryWeightList[i]);
  300. weightMapList.add(codeMap);
  301. }
  302. if(weightMapList.size() > 1) {
  303. weightMapList.get(weightMapList.size() - 1).put("resultNetWeight",0);
  304. weightMapList.get(weightMapList.size() - 1).put("resultTareWeight",0);
  305. weightMapList.get(weightMapList.size() - 1).put("resultCrossWeight",0);
  306. }
  307. map.put("weightMapList",weightMapList);
  308. addWeightBatchResult(map);
  309. }else{
  310. weightMapList.add(map);
  311. }
  312. for(Map<String,Object> codeMap : weightMapList) {
  313. //判断该车有没有净重
  314. BigDecimal saleMaterialId = null;
  315. if (resultNetWeight != null && !"".equals(resultNetWeight) && codeMap.get("FLID") != null && !"".equals(codeMap.get("FLID"))) {
  316. String flId = codeMap.get("FLID").toString();
  317. codeMap.put("flId",flId);
  318. BigDecimal orderIdByFLID = omstruckOrderMapper.selectOrderIdByFLID(codeMap.get("FLID"));
  319. if(orderIdByFLID == null) {
  320. throw new Exception("该分录没有对应的运输订单");
  321. }
  322. saleMaterialId = tmstruckWeightResultMapper.getSaleMaterialId(codeMap);
  323. codeMap.put("saleMaterialId",saleMaterialId);
  324. //首先判断该分录有没有净重
  325. Map<String,Object> orderMesBySaleMaterialId = tmstruckWeightResultMapper.getOrderMesBySaleMaterialIdHaveWeight(saleMaterialId);
  326. if(orderMesBySaleMaterialId == null) {
  327. //根据分录id和车号去找
  328. Map<String,Object> orderMesByOrderIdByFLID = tmstruckWeightResultMapper.getOrderMesBySaleMaterialId(orderIdByFLID);
  329. if(orderMesByOrderIdByFLID != null) {
  330. codeMap.putAll(orderMesByOrderIdByFLID);
  331. }else{
  332. throw new Exception("该分录对应的订单没有净重可供填充!");
  333. }
  334. }else{
  335. codeMap.putAll(orderMesBySaleMaterialId);
  336. }
  337. }else{
  338. Map<String,Object> orderMes = tmstruckWeightResultMapper.getOrderMes(carNo);
  339. if (orderMes == null) {
  340. throw new Exception("该车无分录ID且无正在运行中的订单,系统无法匹配数据");
  341. }
  342. codeMap.putAll(orderMes);
  343. }
  344. tmstruckWeightResult.setId(DataChange.dataToBigDecimal(codeMap.get("weightTaskResultId")));
  345. int orderType = DataChange.dataToBigDecimal(codeMap.get("orderTypee")).intValue();
  346. //磅单号
  347. tmstruckWeightResult.setResultPoundNo((String) codeMap.get("resultPoundNo"));
  348. String resultCrossWeightTime = (String) codeMap.get("resultCrossWeightTime");
  349. if(codeMap.get("orderNumber") != null) {
  350. tmstruckWeightResult.setInsertUpdateRemark((String)codeMap.get("orderNumber"));
  351. }
  352. if(resultNetWeight != null && !"".equals(resultNetWeight) && codeMap.get("saleMaterialId") != null) {
  353. codeMap.put("good",(codeMap.get("goodspa") + "" + codeMap.get("good")).replaceAll(" ",""));
  354. BigDecimal materialId = tmstruckWeightResultMapper.getMaterialId(codeMap);
  355. if(materialId == null){
  356. throw new Exception("系统找不到该物资");
  357. }
  358. codeMap.put("materialId",materialId);
  359. tmstruckWeightResult.setMaterialId(materialId);
  360. tmstruckWeightResult.setMaterialNum(DataChange.dataToBigDecimal(codeMap.get("goodNum")));
  361. tmstruckWeightResult.setSaleMaterialId(DataChange.dataToBigDecimal(codeMap.get("saleMaterialId")));
  362. tmstruckWeightResult.setSaleMaterialId(saleMaterialId);
  363. }
  364. addWeightResult(tmstruckWeightResult, codeMap); //添加计量实绩数据
  365. // 更新订单中路段顺序号,如果毛重时间为空则为计皮:也就是销售第一次计皮,反之有毛重时间则为计毛
  366. if(resultCrossWeightTime == null || resultCrossWeightTime.length() == 0){
  367. codeMap.put("segmentSqe", codeMap.get("tareSegmentSqe")); //皮重路段顺序
  368. }else{
  369. //查询有净重的路段顺序号最大的
  370. BigDecimal orderLineSqe = tmstruckWeightResultMapper.selectOrderLineSqe(DataChange.dataToBigDecimal(codeMap.get("resultTotalId")));
  371. if(orderLineSqe != null && orderLineSqe.compareTo(DataChange.dataToBigDecimal(codeMap.get("grossSegmentSqe"))) > 0){
  372. codeMap.put("segmentSqe",orderLineSqe);
  373. }else{
  374. codeMap.put("segmentSqe", codeMap.get("grossSegmentSqe")); //毛重路段顺序
  375. }
  376. }
  377. if(orderType == 1 || orderType == 4){
  378. //如果是钢材订单,获取下一个还没计量的实绩 将毛重数据作为下一个计量实绩的皮重
  379. //并且是第二次传入重量才执行
  380. List<Map<String, Object>> steelMapList = tmstruckWeightResultMapper.getNoNetWeightResultId(DataChange.dataToBigDecimal(codeMap.get("resultTotalId")));
  381. if(steelMapList.size() >= 2){ //当前更新还未提交所以如果是拼装需要查询两个出来 以第二个为准
  382. Map<String, Object> steelMap = steelMapList.get(1);
  383. if(resultNetWeight != null && !"".equals(resultNetWeight)){
  384. updateSteelAssemble(codeMap, steelMap); //更新下一拼实绩
  385. codeMap.put("segmentSqe", steelMap.get("tareSegmentSqe")); // 修改路段顺序号直接到下一皮重路段顺序
  386. }
  387. }
  388. }
  389. utilsService.updateOrderLineSequence(codeMap);
  390. }
  391. return tmstruckWeightResult;
  392. }
  393. /**
  394. * 生成汽运计量实体类
  395. * @Author TXF
  396. * @Date 2022/1/5 16:41
  397. * @param map
  398. * @return
  399. **/
  400. public TmstruckWeightResult generateWeightResult(Map<String, Object> map) throws Exception {
  401. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  402. tmstruckWeightResult.setId(DataChange.dataToBigDecimal(map.get("weightTaskResultId")));
  403. int orderType = DataChange.dataToBigDecimal(map.get("orderTypee")).intValue();
  404. //磅单号
  405. tmstruckWeightResult.setResultPoundNo((String) map.get("resultPoundNo"));
  406. String resultCrossWeightTime = (String) map.get("resultCrossWeightTime");
  407. tmstruckWeightResult.setMaterialId(DataChange.dataToBigDecimal(map.get("materialId")));
  408. //如果是采购订单 先计毛再计皮
  409. if(judgeOrderTypeList.contains(orderType)){
  410. //如果毛重数据为空 则是第一次计量为毛重 此时第一次计量时间放皮重时间里面
  411. if(resultCrossWeightTime == null || resultCrossWeightTime.length() == 0){
  412. addMaoWeightResult(tmstruckWeightResult, map);
  413. //更新订单中路段顺序号
  414. map.put("segmentSqe", map.get("grossSegmentSqe")); //毛重路段顺序
  415. utilsService.updateOrderLineSequence(map);
  416. }else {
  417. addWeightResult(tmstruckWeightResult, map);
  418. //更新订单中路段顺序号
  419. map.put("segmentSqe", map.get("tareSegmentSqe")); //皮重路段顺序
  420. utilsService.updateOrderLineSequence(map);
  421. if (orderType==19){
  422. //获取第二个还未计量的物资将第一个物资的皮重作为第二个物资的毛重。
  423. List<Map<String, Object>> resultMapList = tmstruckWeightResultMapper.getNoNetWeightResultForSaleReturn(DataChange.dataToBigDecimal(map.get("resultTotalId")));
  424. if (resultMapList.size()>=2){//如果为多拼
  425. Map<String, Object> saleReturnMap = resultMapList.get(1);
  426. Object resultNetWeight = map.get("resultNetWeight");
  427. if(resultNetWeight != null && !"".equals(resultNetWeight)){
  428. updateSaleReturnAssemble(map, saleReturnMap); //更新下一拼实绩
  429. map.put("segmentSqe", saleReturnMap.get("tareSegmentSqe"));
  430. utilsService.updateOrderLineSequence(map);// 修改路段顺序号直接到下一皮重路段顺序
  431. }
  432. }
  433. }//添加计量实绩数据
  434. String orderNumber = (String) map.get("orderNumber");
  435. //如果是采购订单 计皮后自动完成签收
  436. //查询是此订单是否已签收过
  437. Integer check = utilsMapper.checkoutReceipt(orderNumber);
  438. if(check == null){
  439. autoReceipt(orderNumber, map.get("resultTareWeightTime"));
  440. }
  441. }
  442. }
  443. else if(orderType == 10 || orderType == 20 || orderType == 14){
  444. //查询还有几条没有净重的实绩
  445. Integer resultNum = tmstruckWeightResultMapper.selectNoNetWeightResult((String) map.get("orderNumber"));
  446. if(resultNum == 2){
  447. //如果有两条则是走先计皮后计毛顺序
  448. addWeightResult(tmstruckWeightResult, map); //添加计量实绩数据 (正常添加对应皮毛重方法)
  449. if(resultCrossWeightTime == null || resultCrossWeightTime.length() == 0){
  450. map.put("segmentSqe", map.get("tareSegmentSqe")); //皮重路段顺序
  451. }else{
  452. map.put("segmentSqe", map.get("grossSegmentSqe")); //毛重路段顺序
  453. }
  454. utilsService.updateOrderLineSequence(map);
  455. }else if(resultNum == 1){
  456. //只剩一条数据时则是计毛后计皮顺序
  457. //如果毛重数据为空 则是第一次计量为毛重 此时第一次计量时间放皮重时间里面
  458. if(resultCrossWeightTime == null || resultCrossWeightTime.length() == 0){
  459. addMaoWeightResult(tmstruckWeightResult, map);
  460. //更新订单中路段顺序号
  461. map.put("segmentSqe", map.get("grossSegmentSqe")); //毛重路段顺序
  462. utilsService.updateOrderLineSequence(map);
  463. }else {
  464. //根据总实绩id获取磅单号
  465. String resultPoundNoOld = tmstruckWeightResultMapper.selectTruckWeightResultOld(DataChange.dataToBigDecimal(map.get("resultTotalId")));
  466. if(resultPoundNoOld != null && resultPoundNoOld.equals(map.get("resultPoundNo"))) {
  467. return tmstruckWeightResult;
  468. }
  469. addWeightResult(tmstruckWeightResult, map); //添加计量实绩数据
  470. //更新订单中路段顺序号
  471. map.put("segmentSqe", map.get("tareSegmentSqe")); //皮重路段顺序
  472. utilsService.updateOrderLineSequence(map);
  473. String orderNumber = (String) map.get("orderNumber");
  474. //如果是采购订单 计皮后自动完成签收
  475. //查询是此订单是否已签收过
  476. Integer check = utilsMapper.checkoutReceipt(orderNumber);
  477. if(check == null){
  478. autoReceipt(orderNumber, map.get("resultTareWeightTime"));
  479. }
  480. if(orderType == 20){
  481. //此订单类型比较特殊 如果订单类型为20则需要回传金蝶
  482. sendMesToKD(map, orderType);
  483. }
  484. }
  485. }
  486. }
  487. else{
  488. addWeightResult(tmstruckWeightResult, map); //添加计量实绩数据
  489. // 更新订单中路段顺序号,如果毛重时间为空则为计皮:也就是销售第一次计皮,反之有毛重时间则为计毛
  490. if(resultCrossWeightTime == null || resultCrossWeightTime.length() == 0){
  491. map.put("segmentSqe", map.get("tareSegmentSqe")); //皮重路段顺序
  492. }else{
  493. map.put("segmentSqe", map.get("grossSegmentSqe")); //毛重路段顺序
  494. }
  495. if(orderType == 1 || orderType == 4){
  496. //如果是钢材订单,获取下一个还没计量的实绩 将毛重数据作为下一个计量实绩的皮重
  497. //并且是第二次传入重量才执行
  498. List<Map<String, Object>> steelMapList = tmstruckWeightResultMapper.getNoNetWeightResultId(DataChange.dataToBigDecimal(map.get("resultTotalId")));
  499. if(steelMapList.size() >= 2){ //当前更新还未提交所以如果是拼装需要查询两个出来 以第二个为准
  500. Map<String, Object> steelMap = steelMapList.get(1);
  501. Object resultNetWeight = map.get("resultNetWeight");
  502. if(resultNetWeight != null && !"".equals(resultNetWeight)){
  503. updateSteelAssemble(map, steelMap); //更新下一拼实绩
  504. map.put("segmentSqe", steelMap.get("tareSegmentSqe")); // 修改路段顺序号直接到下一皮重路段顺序
  505. }
  506. }
  507. }
  508. utilsService.updateOrderLineSequence(map);
  509. }
  510. return tmstruckWeightResult;
  511. }
  512. /**
  513. * 添加第一次为毛重数据的计量实绩
  514. * @param tmstruckWeightResult
  515. * @param map
  516. */
  517. public void addMaoWeightResult(TmstruckWeightResult tmstruckWeightResult, Map<String, Object> map) throws Exception{
  518. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  519. //设置毛重时间
  520. String firstTime = (String) map.get("resultTareWeightTime");
  521. tmstruckWeightResult.setResultGrossWeightTime(sdf.parse(firstTime));
  522. //添加毛重汽车衡
  523. Integer tareId = tmstruckWeightResultMapper.selectTruckCalculateId((String) map.get("resultTareCalculateNumber"));
  524. if(tareId == null){
  525. throw new Exception("没有此计量衡:" + map.get("resultTareCalculateNumber"));
  526. }
  527. tmstruckWeightResult.setResultGrossPlaceId(new BigDecimal(tareId));
  528. //设置毛重
  529. BigDecimal resultTareWeight = DataChange.dataToBigDecimal(map.get("resultTareWeight"));
  530. tmstruckWeightResult.setResultGrossWeight(resultTareWeight);
  531. tmstruckWeightResult.setInsertTime(new Date());
  532. tmstruckWeightResult.setInsertUsername("admin");
  533. }
  534. /**
  535. * 添加计量实绩添加数据
  536. * @param tmstruckWeightResult
  537. * @param map
  538. * @return
  539. */
  540. public void addWeightResult(TmstruckWeightResult tmstruckWeightResult, Map<String, Object> map) throws Exception{
  541. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  542. //设置皮重汽车衡
  543. String resultTareCalculateNumber = (String) map.get("resultTareCalculateNumber");
  544. if(resultTareCalculateNumber != null){
  545. if(!"".equals(resultTareCalculateNumber)){
  546. Integer tareId = tmstruckWeightResultMapper.selectTruckCalculateId(resultTareCalculateNumber);
  547. if(tareId == null){
  548. throw new Exception("没有此皮重汽车衡:" + map.get("resultTareCalculateNumber"));
  549. }
  550. tmstruckWeightResult.setResultTarePlaceId(new BigDecimal(tareId));
  551. }
  552. }
  553. //设置毛重汽车衡
  554. String resultCrossCalculateNumber = (String) map.get("resultCrossCalculateNumber");
  555. if(resultCrossCalculateNumber != null){
  556. if(!"".equals(resultCrossCalculateNumber)){
  557. Integer crossId = tmstruckWeightResultMapper.selectTruckCalculateId(resultCrossCalculateNumber);
  558. if(crossId == null){
  559. throw new Exception("没有此毛重汽车衡:" + map.get("resultCrossCalculateNumber"));
  560. }
  561. tmstruckWeightResult.setResultGrossPlaceId(new BigDecimal(crossId));
  562. }
  563. }
  564. //毛重
  565. if(map.get("resultCrossWeight") != null){
  566. String resultCrossWeight = String.valueOf(map.get("resultCrossWeight"));
  567. if(!"".equals(resultCrossWeight))
  568. tmstruckWeightResult.setResultGrossWeight(DataChange.dataToBigDecimal(resultCrossWeight));
  569. }
  570. //皮重
  571. if(map.get("resultTareWeight") != null){
  572. String resultTareWeight = String.valueOf(map.get("resultTareWeight"));
  573. if(!"".equals(resultTareWeight))
  574. tmstruckWeightResult.setResultTareWeight(DataChange.dataToBigDecimal(resultTareWeight));
  575. }
  576. //净重
  577. if(map.get("resultNetWeight") != null){
  578. String resultNetWeight = String.valueOf(map.get("resultNetWeight"));
  579. if(!"".equals(resultNetWeight)){
  580. tmstruckWeightResult.setResultNetWeight(DataChange.dataToBigDecimal(resultNetWeight));
  581. }
  582. }
  583. //设置皮重时间
  584. if(map.get("resultTareWeightTime") != null){
  585. String resultTareWeightTime = (String) map.get("resultTareWeightTime");
  586. if(!"".equals(resultTareWeightTime)){
  587. tmstruckWeightResult.setResultTareWeightTime(sdf.parse(resultTareWeightTime));
  588. }
  589. }
  590. //设置毛重时间
  591. if(map.get("resultCrossWeightTime") != null){
  592. String resultGrossWeightTime = (String) map.get("resultCrossWeightTime");
  593. if(!"".equals(resultGrossWeightTime)){
  594. tmstruckWeightResult.setResultGrossWeightTime(sdf.parse(resultGrossWeightTime));
  595. }
  596. }
  597. tmstruckWeightResult.setUpdateTime(new Date());
  598. tmstruckWeightResult.setUpdateUsername("admin");
  599. }
  600. /**
  601. * 自动签收
  602. * @return
  603. */
  604. public void autoReceipt(String orderNumber, Object tareWeightTime){
  605. TmstruckReceiveResult tmstruckReceiveResult = new TmstruckReceiveResult();
  606. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  607. //通过运输订单号查询总实绩ID
  608. BigDecimal resultTotalId = utilsMapper.getTotalIdByOrderNumber(orderNumber);
  609. tmstruckReceiveResult.setResultTotalId(resultTotalId);
  610. tmstruckReceiveResult.setStatus(new BigDecimal(1));
  611. tmstruckReceiveResult.setInsertUsername("admin");
  612. Date receiptTime;
  613. try {
  614. //取皮重时间为收货时间
  615. receiptTime = sdf.parse((String) tareWeightTime);
  616. } catch (ParseException e) {
  617. receiptTime = new Date();
  618. System.out.println(e.getMessage());
  619. }
  620. tmstruckReceiveResult.setInsertTime(receiptTime);
  621. tmstruckReceiveResult.setUpdateTime(receiptTime);
  622. int i = tmstruckReceiveResultMapper.updateByTotalResultId(tmstruckReceiveResult);
  623. if(i == 1) {
  624. System.out.println(orderNumber + "收货成功");
  625. }else {
  626. System.out.println(orderNumber + "收货失败");
  627. }
  628. }
  629. /**
  630. * 纯内转订单类型
  631. * @Author TXF
  632. * @Date 2022/2/18 9:55
  633. * @param map
  634. * @return
  635. **/
  636. public String insertWeightResultBy11(Map<String, Object> map, Map<String, Object> oneMap){
  637. TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
  638. tmstruckWeightResult.setResultPoundNo((String) map.get("resultPoundNo"));
  639. tmstruckWeightResult.setMaterialId(DataChange.dataToBigDecimal(map.get("materialId")));
  640. int sqe = DataChange.dataToBigDecimal(oneMap.get("Sqe")).intValue(); //获取订单路段顺序号
  641. sqe = sqe + 1;
  642. Object resultNetWeight = map.get("resultNetWeight");
  643. if(resultNetWeight != null && !"".equals((String) resultNetWeight)){
  644. //判断是否有卸货实绩已经卸过货 如果有卸货实绩 则结束订单
  645. Integer resultId = utilsMapper.getUnloadResultByTotalId(DataChange.dataToBigDecimal(oneMap.get("totalId")));
  646. if(resultId != null){
  647. int orderIds = DataChange.dataToBigDecimal(oneMap.get("orderIds")).intValue();
  648. try {
  649. omsFeign.closeInwardOrder(orderIds, sqe, (String) resultNetWeight);
  650. } catch (Exception e) {
  651. e.printStackTrace();
  652. }
  653. }else {
  654. Map<String, Object> threeMap = new HashMap<>(); //用于更新路段顺序号
  655. threeMap.put("orderLineSequence", sqe);
  656. threeMap.put("orderNumber", map.get("orderNumber"));
  657. utilsMapper.updateLineSeqByOrderIdOrNum2(threeMap); //更新订单路段顺序号
  658. }
  659. }else {
  660. Map<String, Object> threeMap = new HashMap<>(); //用于更新路段顺序号
  661. threeMap.put("orderLineSequence", sqe);
  662. threeMap.put("orderNumber", map.get("orderNumber"));
  663. utilsMapper.updateLineSeqByOrderIdOrNum2(threeMap); //更新订单路段顺序号
  664. }
  665. //首先查询这个订单号的这个物资ID是否有计量实绩
  666. Map<String, Object> twoMap = tmstruckWeightResultMapper.selectResultIdByOrderNoAndMaterialId(map); //判断这个物资是否已经计量过
  667. Object resultCrossWeightTime = map.get("resultCrossWeightTime");
  668. if(twoMap == null){//如果查出来为空,则进行新增操作
  669. tmstruckWeightResult.setId(tmstruckWeightResultMapper.selectMaxId()); //新增主键
  670. tmstruckWeightResult.setResultTotalId(DataChange.dataToBigDecimal(oneMap.get("totalId"))); //新增总实绩ID
  671. if(resultCrossWeightTime == null || "".equals(String.valueOf(resultCrossWeightTime))){//只有一条数据的情况
  672. tmstruckWeightResult.setTareSegmentSqe(new BigDecimal(sqe));
  673. }
  674. else {
  675. tmstruckWeightResult.setTareSegmentSqe(new BigDecimal(sqe));
  676. tmstruckWeightResult.setGrossSegmentSqe(new BigDecimal(sqe));
  677. }
  678. try {
  679. addWeightResult(tmstruckWeightResult, map);
  680. } catch (Exception e) {
  681. return e.getMessage();
  682. }
  683. tmstruckWeightResultMapper.insertSelective(tmstruckWeightResult); //新增计量实绩
  684. }else {
  685. //如果不为空则证明进行过至少一次计量
  686. tmstruckWeightResult.setId(DataChange.dataToBigDecimal(twoMap.get("weightTaskResultId")));
  687. //取出计量数据与传进来的毛皮数据进行对比
  688. BigDecimal inTareWeight = DataChange.dataToBigDecimal(twoMap.get("resultTareWeight"));
  689. if(inTareWeight.compareTo(DataChange.dataToBigDecimal(map.get("resultTareWeight"))) > 0){
  690. //如果取出来的皮重 大于 传进来的皮重 则需要调换路段顺序号
  691. tmstruckWeightResult.setGrossSegmentSqe(DataChange.dataToBigDecimal(twoMap.get("tareSegmentSqe")));
  692. tmstruckWeightResult.setTareSegmentSqe(new BigDecimal(sqe));
  693. }else{
  694. tmstruckWeightResult.setGrossSegmentSqe(new BigDecimal(sqe));
  695. }
  696. try {
  697. addWeightResult(tmstruckWeightResult, map);
  698. } catch (Exception e) {
  699. return e.getMessage();
  700. }
  701. tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  702. }
  703. //推送数据
  704. utilsService.pushMesToWebsocket((String) oneMap.get("capacityNumber"), "计量");
  705. return map.get("orderNumber") + "成功";
  706. }
  707. /**
  708. * 处理零星订单多拼方法
  709. * @Author TXF
  710. * @Date 2022/3/15 18:37
  711. * @param map
  712. * @param stringObjectMap
  713. * @return
  714. **/
  715. public void dealWithLxOrder(Map<String, Object> map, Map<String, Object> stringObjectMap){
  716. if(map.get("resultNetWeight") != null){
  717. String resultNetWeight = String.valueOf(map.get("resultNetWeight"));
  718. if(! ("".equals(resultNetWeight) || "null".equals(resultNetWeight))){
  719. //查询是否还有物资如果为空则为已经计量完成
  720. Integer materialId = utilsMapper.getNextMaterialId(DataChange.dataToBigDecimal(stringObjectMap.get("orderId")));
  721. if(materialId != null){
  722. stringObjectMap.put("materialId", materialId);
  723. stringObjectMap.put("asd", 1);
  724. Map<String, Object> returnMap = null;
  725. try {
  726. returnMap = tmstruckFeign.sendMeasureCommission(stringObjectMap);
  727. String code = (String) returnMap.get("code");
  728. if(!"200".equals(code)){
  729. System.out.println(returnMap.get("data"));
  730. }
  731. } catch (Exception e) {
  732. System.out.println(e.getMessage());
  733. }
  734. }
  735. }
  736. }
  737. }
  738. /**
  739. * 修改拼装钢材物资
  740. * @param map
  741. * @param steelMap
  742. */
  743. public void updateSteelAssemble(Map<String, Object> map, Map<String, Object> steelMap) throws Exception{
  744. //更新实绩
  745. TmstruckWeightResult steelWightModel = new TmstruckWeightResult();
  746. steelWightModel.setId(DataChange.dataToBigDecimal(steelMap.get("weightTaskResultId"))); //查询出来的主键
  747. steelMap.put("resultTareCalculateNumber", map.get("resultCrossCalculateNumber")); //皮重汽车衡即为毛重汽车衡
  748. steelMap.put("resultTareWeight", map.get("resultCrossWeight"));//皮重即为毛重
  749. steelMap.put("resultTareWeightTime", map.get("resultCrossWeightTime"));//皮重时间即为毛重时间
  750. addWeightResult(steelWightModel, steelMap);
  751. tmstruckWeightResultMapper.updateByPrimaryKeySelective(steelWightModel);
  752. }
  753. //修改拼装退货物资
  754. /**
  755. * 修改拼装钢材物资
  756. * @param map
  757. * @param steelMap
  758. */
  759. public void updateSaleReturnAssemble(Map<String, Object> map, Map<String, Object> steelMap) throws Exception{
  760. //更新实绩
  761. TmstruckWeightResult SaleReturn = new TmstruckWeightResult();
  762. SaleReturn.setId(DataChange.dataToBigDecimal(steelMap.get("weightTaskResultId"))); //查询出来的主键
  763. steelMap.put("resultCrossCalculateNumber", map.get("resultTareCalculateNumber")); //皮重汽车衡即为毛重汽车衡
  764. steelMap.put("resultCrossWeight", map.get("resultTareWeight"));//毛重即皮重
  765. steelMap.put("resultCrossWeightTime", map.get("resultTareWeightTime"));//毛重时间即皮重时间
  766. addWeightResult(SaleReturn, steelMap);
  767. tmstruckWeightResultMapper.updateByPrimaryKeySelective(SaleReturn);
  768. }
  769. /**
  770. * 回传数据给金蝶方法
  771. * @Author TXF
  772. * @Date 2022/2/9 15:46
  773. * @param
  774. * @return
  775. **/
  776. public void sendMesToKD(Map<String, Object> map, Integer orderType){
  777. String resultTareCalculateNumber = String.valueOf(map.get("resultTareCalculateNumber"));
  778. if(! resultTareCalculateNumber.contains("精煤")){ //如果不是精煤称的则不回传金蝶 或者没有皮重称
  779. return;
  780. }
  781. String orderNumber = (String) map.get("orderNumber");
  782. Map<String, Object> mesMap = new HashMap<>();
  783. switch (orderType){
  784. case 6:
  785. //查询订单信息
  786. mesMap = tmstruckWeightResultMapper.getPurOrderMesToKD(orderNumber);
  787. break;
  788. case 20:
  789. case 23:
  790. mesMap = tmstruckWeightResultMapper.get20PurOrderMesToKD(orderNumber);
  791. }
  792. //将map数据全放进mesMap中
  793. map.putAll(mesMap);
  794. //访问金蝶接口
  795. KDWebServiceServiceImpl.sendMesToKD(map);
  796. }
  797. /**
  798. * 计量联动删除方法
  799. * @param mapList
  800. * @return
  801. */
  802. public String linkageDeleteTransportOrder(List<Map<String, Object>> mapList) throws Exception{
  803. try{
  804. new Thread( new Runnable() {
  805. public void run(){
  806. try {
  807. newFileTool.newFile(mapList.toString(),"计量-物流联动删单");
  808. } catch (IOException e) {
  809. e.printStackTrace();
  810. }
  811. }
  812. }).start();
  813. }catch (Exception e) {
  814. e.printStackTrace();
  815. }
  816. //联动删除
  817. for (Map<String, Object> map : mapList) {
  818. String orderNumber = (String) map.get("orderNumber");
  819. //判断该运输订单号是否是钢材的
  820. Map<String,Object> orderMes = tmstruckWeightResultMapper.getOOType(orderNumber);
  821. if(orderMes == null) {
  822. return "failed";
  823. }
  824. //新增日志表
  825. saleLogUtil.logOrder(DataChange.dataToBigDecimal(orderMes.get("orderId")),"计量联动删除","计量系统",SaleLogUtil.DELETE);
  826. BigDecimal resultTotalId = DataChange.dataToBigDecimal(orderMes.get("resultTotalId"));
  827. BigDecimal orderId = DataChange.dataToBigDecimal(orderMes.get("orderId"));
  828. Integer orderType = DataChange.dataToBigDecimal(orderMes.get("orderType")).intValue();
  829. if(orderType == 1 || orderType == 4) {
  830. //删皮,此时没有物资名称,只有运输订单号
  831. if(map.get("good") == null || "".equals(map.get("good"))){
  832. //清空皮重信息,且将进厂时间清空,且将路段顺序号置为0
  833. tmstruckWeightResultMapper.updateWeightTare(resultTotalId);
  834. tmstruckWeightResultMapper.updateEnfactoryResult(resultTotalId);
  835. tmstruckWeightResultMapper.updateOrderLineSqe(orderId);
  836. tmstruckWeightResultMapper.updateTotalStatus(resultTotalId);
  837. }
  838. //如果传输了物资,则判断该物资是第几拼
  839. if(map.get("good") != null && !"".equals(map.get("good"))){
  840. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  841. //查询物资
  842. map.put("good",map.get("goodspa") + "" + map.get("good"));
  843. BigDecimal materialId = tmstruckWeightResultMapper.getMaterialId(map);
  844. if(materialId == null) {
  845. return "没有找到该物资,返回failed";
  846. }
  847. //查询该物资id及对应的净重还有毛重时间是哪一拼
  848. String resultGrossWeightTime = (String) map.get("resultCrossWeightTime");
  849. Date resultGrossWeightTime1 = sdf.parse(resultGrossWeightTime);
  850. Map<String, Object> weightMap = new HashMap<>();
  851. weightMap.put("resultTotalId",orderMes.get("resultTotalId"));
  852. weightMap.put("materialId",materialId);
  853. weightMap.put("resultGrossWeightTime",resultGrossWeightTime);
  854. weightMap.put("saleMaterialId",map.get("saleMaterialId"));
  855. Map<String,Object> map1 = tmstruckWeightResultMapper.selectWeightMes(weightMap);
  856. tmstruckWeightResultMapper.updateMakeDate(DataChange.dataToBigDecimal(weightMap.get("saleMaterialId")));
  857. //根据查询信息判断是哪一拼
  858. Integer spellNum = (DataChange.dataToBigDecimal(map1.get("grossSqe")).intValue() + DataChange.dataToBigDecimal(map1.get("tareSqe")).intValue()) / 6;
  859. if(spellNum == 1){
  860. //如果是第一拼
  861. tmstruckWeightResultMapper.updateWeightResult(DataChange.dataToBigDecimal(map1.get("weightTaskResultId")));
  862. //删除下二拼的皮重
  863. tmstruckWeightResultMapper.updateWeightTareNoGross(resultTotalId);
  864. tmstruckWeightResultMapper.updateEnfactoryResult(resultTotalId);
  865. tmstruckWeightResultMapper.updateOrderLineSqe(orderId);
  866. tmstruckWeightResultMapper.updateTotalStatus(resultTotalId);
  867. }else{
  868. tmstruckWeightResultMapper.updateWeightResult(DataChange.dataToBigDecimal(map1.get("weightTaskResultId")));
  869. tmstruckWeightResultMapper.updateWeightTareNoGross(resultTotalId);
  870. //查询有净重的实绩的最大路段顺序号
  871. BigDecimal orderLineSqe = tmstruckWeightResultMapper.selectOrderLineSqe(resultTotalId);
  872. if(orderLineSqe != null) {
  873. tmstruckWeightResultMapper.updateOrderLineSqeBySqe(orderId,orderLineSqe.intValue());
  874. }
  875. }
  876. }
  877. }else{
  878. tmstruckWeightResultMapper.linkageDeleteTransportOrder(orderNumber);
  879. }
  880. }
  881. return "success";
  882. }
  883. /**
  884. * 计量联动修改方法(修改关联的采购订单,以及同步修改运输订单物资子表的物资)
  885. * @param map
  886. * @param orderType
  887. * @return
  888. */
  889. public String linkUpdateAPO(Map<String, Object> map, Integer orderType){
  890. //如果等于1 则代表是需要变更采购订单号的订单
  891. Map<String, Object> mesMap = tmstruckWeightResultMapper.getAPOMes(String.valueOf(map.get("ArrivalBillNo")));
  892. if (mesMap == null){
  893. return map.get("ArrivalBillNo") + "系统没有此订单号!失败";
  894. }
  895. mesMap.put("orderNumber", map.get("orderNumber"));
  896. try{
  897. new Thread( new Runnable() {
  898. public void run(){
  899. try {
  900. Map<String,Object> oldOrderMes = tmstruckWeightResultMapper.getOldOrderMes(mesMap);
  901. map.put("oldOrderMes",oldOrderMes);
  902. JSONObject jsonObject = new JSONObject(map);
  903. newFileTool.newFile(jsonObject.toString(),"计量-物流联动换单");
  904. } catch (IOException e) {
  905. e.printStackTrace();
  906. }
  907. }
  908. }).start();
  909. }catch (Exception e) {
  910. e.printStackTrace();
  911. }
  912. saleLogUtil.logOrder(map.get("orderNumber")+"","计量联动换采购订单","计量系统",SaleLogUtil.UPDATE);
  913. if(orderType == 20 || orderType == 15 || orderType == 16 || orderType == 23 || orderType == 24){
  914. //20订单修改的表不一样呀,找寻该采购订单对应的最新需求id和计划id
  915. BigDecimal planId = tmstruckWeightResultMapper.selectNewPlanId(mesMap);
  916. mesMap.put("planId",planId);
  917. tmstruckWeightResultMapper.updatePurchaseInwordAPOId(mesMap);
  918. tmstruckWeightResultMapper.updateOmsTruckMaterialId(mesMap);
  919. }else{
  920. //修改订单管理采购订单ID 以及物资子表 物资ID
  921. tmstruckWeightResultMapper.updateOmsTruckPlanId(mesMap);
  922. tmstruckWeightResultMapper.updateOmsTruckMaterialId(mesMap);
  923. }
  924. return mesMap.get("orderNumber") + "数据修改成功";
  925. }
  926. @Override
  927. public Boolean checkOrder(Map<String, Object> map) {
  928. //获取三个参数
  929. //try {
  930. // if (map != null) {
  931. // JSONObject jsonObject = new JSONObject(map);
  932. // FastDateFormat format = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
  933. // logger.info("=========" + "计量检查" + format.format(new Date()));
  934. // logger.info(jsonObject.toString());
  935. // logger.info("=========" + "计量检查" + format.format(new Date()));
  936. //
  937. // try{
  938. // new Thread( new Runnable() {
  939. // public void run(){
  940. // try {
  941. // newFileTool.newFile(jsonObject.toString(),"计量物流金蝶核对");
  942. // } catch (IOException e) {
  943. // e.printStackTrace();
  944. // }
  945. // }
  946. // }).start();
  947. // }catch (Exception e) {
  948. // e.printStackTrace();
  949. // }
  950. // //判断该车的运输订单号是否是钢材且是否是正在作业中的,如果不是就返回true
  951. // int i = tmstruckWeightResultMapper.checkOrderIsSteel(map);
  952. // if (i == 0) {
  953. // return true;
  954. // }
  955. //
  956. // //判断该分录是不是在物流系统,如果不在返回true
  957. // int j = tmstruckWeightResultMapper.checkOrder(map);
  958. // BigDecimal saleMaterialId = tmstruckWeightResultMapper.getSaleMaterialId(map);
  959. // ////判断该分录在计量实绩表里有没有净重,如果有
  960. // //try {
  961. // // Map<String,Object> weightMesBySaleMaterialId = tmstruckWeightResultMapper.getWeightMesBySaleMaterialId(saleMaterialId);
  962. // // if(weightMesBySaleMaterialId != null && weightMesBySaleMaterialId.get("poundNo") != null) {
  963. // // //系统自动走删皮
  964. // // linkageDeleteTransportOrder2(weightMesBySaleMaterialId);
  965. // // }
  966. // //} catch (Exception e) {
  967. // // e.printStackTrace();
  968. // //}
  969. // //根据运输订单号查询计量实绩ID
  970. // BigDecimal weightTaskResultId = tmstruckWeightResultMapper.getWeightTaskResultIdNoNet(map);
  971. // if(weightTaskResultId != null && saleMaterialId != null) {
  972. // //更新计量实绩
  973. // System.out.println("更新计量实绩校验");
  974. // //tmstruckWeightResultMapper.updateWeightTaskBySaleMaterialId(weightTaskResultId,saleMaterialId);
  975. // }
  976. // if (j == 0) {
  977. // //如果是自提,则更换规格
  978. // BigDecimal jlSaleOrderMaterialId = tmstruckWeightResultMapper.getJlSaleOrderMaterialId(map);
  979. // BigDecimal wlSaleOrderMaterialId = tmstruckWeightResultMapper.getWlSaleOrderMaterialId(map);
  980. // BigDecimal wlOrderId = tmstruckWeightResultMapper.getJlOrderId(wlSaleOrderMaterialId);
  981. // if(jlSaleOrderMaterialId != null) {
  982. // //如果车序号子表存在,判断拼数是否相同
  983. // BigDecimal jlSpell = tmstruckWeightResultMapper.getJlSpell(jlSaleOrderMaterialId);
  984. // BigDecimal wlSpell = tmstruckWeightResultMapper.getWlSpell(map);
  985. // //如果拼数相同,则继续更换运单,否则返回
  986. // if (jlSpell.compareTo(wlSpell) == 0) {
  987. // //判断正确的车序号主键有没有派车
  988. // BigDecimal jlOrderId = tmstruckWeightResultMapper.getJlOrderId(jlSaleOrderMaterialId);
  989. // if(jlOrderId != null) {
  990. // //分别更新
  991. // tmstruckWeightResultMapper.updateOrderPlanId(jlOrderId,wlSaleOrderMaterialId);
  992. // tmstruckWeightResultMapper.updateOrderPlanId(wlOrderId,jlSaleOrderMaterialId);
  993. // //清空运输订单子表的某个数据
  994. // tmstruckWeightResultMapper.updateOrderMaterialId(jlOrderId);
  995. // tmstruckWeightResultMapper.updateOrderMaterialId(wlOrderId);
  996. // }else{
  997. // tmstruckWeightResultMapper.updateOrderPlanId(wlOrderId,jlSaleOrderMaterialId);
  998. // tmstruckWeightResultMapper.updateOrderMaterialId(wlOrderId);
  999. // }
  1000. // }
  1001. // }else {
  1002. // //如果对不上,那么就将运输订单里面的状态变一下
  1003. // tmstruckWeightResultMapper.updateOmsRedQrCode(map);
  1004. // }
  1005. // //根据分录ID查询车序号
  1006. // utilsService.pushMesToWebsocket((String) map.get("carNo"), "计量");
  1007. // return false;
  1008. // }else{
  1009. // return true;
  1010. // }
  1011. // }
  1012. //} catch (Exception e) {
  1013. // return true;
  1014. //}
  1015. return true;
  1016. }
  1017. /**
  1018. * 计量联动删除方法
  1019. * @param map
  1020. * @return
  1021. */
  1022. public String linkageDeleteTransportOrder2(Map<String, Object> map) throws Exception{
  1023. try{
  1024. new Thread( new Runnable() {
  1025. public void run(){
  1026. try {
  1027. JSONObject jsonObject = new JSONObject(map);
  1028. newFileTool.newFile(jsonObject.toString(),"计量-物流联动删单");
  1029. } catch (IOException e) {
  1030. e.printStackTrace();
  1031. }
  1032. }
  1033. }).start();
  1034. }catch (Exception e) {
  1035. e.printStackTrace();
  1036. }
  1037. //联动删除
  1038. String poundNo = (String) map.get("poundNo");
  1039. //判断该运输订单号是否是钢材的
  1040. Map<String,Object> orderMes = null;
  1041. try {
  1042. orderMes = tmstruckWeightResultMapper.getOOPoundMes(poundNo);
  1043. } catch (Exception e) {
  1044. return "error:信息错误,该磅单号对应多条实绩.";
  1045. }
  1046. if(orderMes == null) {
  1047. return "error:没有找到对应的单据信息,请核实后再发送";
  1048. }
  1049. BigDecimal resultTotalId = DataChange.dataToBigDecimal(orderMes.get("resultTotalId"));
  1050. BigDecimal orderId = DataChange.dataToBigDecimal(orderMes.get("orderId"));
  1051. Integer orderType = DataChange.dataToBigDecimal(orderMes.get("orderType")).intValue();
  1052. if(orderType == 1 || orderType == 4) {
  1053. //删皮,此时没有物资名称,只有运输订单号
  1054. if(orderMes.get("netWeight") == null || "".equals(orderMes.get("netWeight"))){
  1055. //清空皮重信息,且将进厂时间清空,且将路段顺序号置为0
  1056. tmstruckWeightResultMapper.updateWeightTare(resultTotalId);
  1057. tmstruckWeightResultMapper.updateEnfactoryResult(resultTotalId);
  1058. tmstruckWeightResultMapper.updateOrderLineSqe(orderId);
  1059. tmstruckWeightResultMapper.updateTotalStatus(resultTotalId);
  1060. try {
  1061. Map<String, Object> enFactoryMap = new HashMap<>();
  1062. enFactoryMap.put("orderNumber",orderMes.get("orderNumber") + " ");
  1063. tmstruckFeign.enFactoryResultByPDA(enFactoryMap);
  1064. } catch (Exception e) {
  1065. e.printStackTrace();
  1066. }
  1067. return "删除皮重信息,同时将进厂信息删除,请提醒司机重新扫进厂,否则不能过磅!";
  1068. }
  1069. //如果传输了物资,则判断该物资是第几拼
  1070. if(orderMes.get("netWeight") != null){
  1071. //查询该物资id及对应的净重还有毛重时间是哪一拼
  1072. //判断该总实绩下净重的条数
  1073. int netWeightCount = tmstruckWeightResultMapper.getNetWeightCount(resultTotalId);
  1074. //去除制单日期
  1075. tmstruckWeightResultMapper.updateMakeDate(DataChange.dataToBigDecimal(orderMes.get("saleMaterialId")));
  1076. //根据查询信息判断是哪一拼
  1077. Integer spellNum = (DataChange.dataToBigDecimal(orderMes.get("grossSqe")).intValue() + DataChange.dataToBigDecimal(orderMes.get("tareSqe")).intValue()) / 6;
  1078. if(spellNum == 1){
  1079. //如果是第一拼
  1080. tmstruckWeightResultMapper.updateWeightResult(DataChange.dataToBigDecimal(orderMes.get("weightTaskResultId")));
  1081. }else{
  1082. tmstruckWeightResultMapper.updateWeightResult(DataChange.dataToBigDecimal(orderMes.get("weightTaskResultId")));
  1083. tmstruckWeightResultMapper.updateWeightTareNoGross(resultTotalId);
  1084. //查询有净重的实绩的最大路段顺序号
  1085. BigDecimal orderLineSqe = tmstruckWeightResultMapper.selectOrderLineSqe(resultTotalId);
  1086. if(orderLineSqe != null) {
  1087. tmstruckWeightResultMapper.updateOrderLineSqeBySqe(orderId,orderLineSqe.intValue());
  1088. }
  1089. }
  1090. if(netWeightCount == 1) {
  1091. //删除下面拼装的皮重
  1092. tmstruckWeightResultMapper.updateWeightTareNoGross(resultTotalId);
  1093. tmstruckWeightResultMapper.updateEnfactoryResult(resultTotalId);
  1094. tmstruckWeightResultMapper.updateOrderLineSqe(orderId);
  1095. tmstruckWeightResultMapper.updateTotalStatus(resultTotalId);
  1096. //try {
  1097. // Map<String, Object> enFactoryMap = new HashMap<>();
  1098. // enFactoryMap.put("orderNumber",orderMes.get("orderNumber") + " ");
  1099. // tmstruckFeign.enFactoryResultByPDA(enFactoryMap);
  1100. //} catch (Exception e) {
  1101. // e.printStackTrace();
  1102. //}
  1103. return "该车整条计量数据1条,删除整条数据1条,同时将进厂信息删除,请提醒司机重新扫进厂,否则不能过磅!";
  1104. }
  1105. return "磅单号:" + poundNo + "删除成功" ;
  1106. }
  1107. }else{
  1108. return "error:非出厂钢材订单,不能通过该操作删除";
  1109. }
  1110. return "success";
  1111. }
  1112. @Transactional(rollbackFor = Exception.class)
  1113. public String changeOrderNumber(Map<String,Object> map) throws Exception{
  1114. //校验
  1115. if(map==null || map.get("capacityNumber")==null){
  1116. throw new Exception("缺乏车牌号:capacityNumber");
  1117. }
  1118. //查询车辆对应订单信息
  1119. Map<String,Object> details = null;
  1120. try{
  1121. details = omstruckOrderMapper.findOrderDetailByCapacityNumber(map);
  1122. }catch (TooManyResultsException e){
  1123. e.printStackTrace();
  1124. throw new Exception("查询到多个实绩");
  1125. }
  1126. if(details==null || details.get("orderId")==null){
  1127. throw new Exception("没有查询到正在执行的运单!");
  1128. }
  1129. //生成新的运输订单号
  1130. BigDecimal orderId=omstruckOrderMapper.selectMaxId();
  1131. String result=DataChange.generateEightDigitsNumber("WYSDD", orderId.intValue());
  1132. //更新
  1133. OmstruckOrder omstruckOrder=new OmstruckOrder();
  1134. omstruckOrder.setOrderId(DataChange.dataToBigDecimal(details.get("orderId")));
  1135. omstruckOrder.setOrderNumber(result);
  1136. omstruckOrderMapper.updateByPrimaryKeySelective(omstruckOrder);
  1137. return result;
  1138. }
  1139. @Override
  1140. public List<Map<String,Object>> queryApoByOrderNo(List<String> orderNos) {
  1141. List<Map<String,Object>> mapList = new ArrayList<>();
  1142. for (String orderNo :orderNos) {
  1143. Integer orderType = tmstruckWeightResultMapper.queryOrderType(orderNo);
  1144. String apo = null;
  1145. Map<String,Object> map = null;
  1146. if(apoOrderType.contains(orderType)) {
  1147. map = tmstruckWeightResultMapper.queryApoByOrderNo(orderNo);
  1148. }
  1149. if (apoInwardOrderType.contains(orderType)) {
  1150. map = tmstruckWeightResultMapper.queryApoInwardByOrderNo(orderNo);
  1151. }
  1152. if(map != null) {
  1153. mapList.add(map);
  1154. }
  1155. }
  1156. return mapList;
  1157. }
  1158. public void addWeightBatchResult(Map<String,Object> map) {
  1159. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1160. TmstruckWeightBatch tmstruckWeightBatch = new TmstruckWeightBatch();
  1161. BigDecimal weightBatchId = tmstruckWeightBatchMapper.weightBatchID();
  1162. tmstruckWeightBatch.setId(weightBatchId);
  1163. //皮重
  1164. if(map.get("resultTareWeight") != null && !"".equals(map.get("resultTareWeight"))) {
  1165. tmstruckWeightBatch.setBatchTareWeight(DataChange.dataToBigDecimal(map.get("resultTareWeight")));
  1166. }
  1167. //毛重
  1168. if(map.get("resultCrossWeight") != null && !"".equals(map.get("resultCrossWeight"))) {
  1169. tmstruckWeightBatch.setBatchGrossWeight(DataChange.dataToBigDecimal(map.get("resultCrossWeight")));
  1170. }
  1171. //净重
  1172. if(map.get("resultNetWeight") != null && !"".equals(map.get("resultNetWeight"))) {
  1173. tmstruckWeightBatch.setBatchNetWeight(DataChange.dataToBigDecimal(map.get("resultNetWeight")));
  1174. }
  1175. //毛重时间
  1176. if(map.get("resultCrossWeightTime") != null && !"".equals(map.get("resultCrossWeightTime"))) {
  1177. try {
  1178. tmstruckWeightBatch.setBatchGrossWeightTime(sdf.parse(map.get("resultCrossWeightTime").toString()));
  1179. } catch (ParseException e) {
  1180. e.printStackTrace();
  1181. }
  1182. }
  1183. //皮重时间
  1184. if(map.get("resultTareWeightTime") != null && !"".equals(map.get("resultTareWeightTime"))) {
  1185. try {
  1186. tmstruckWeightBatch.setBatchTareWeightTime(sdf.parse(map.get("resultTareWeightTime").toString()));
  1187. } catch (ParseException e) {
  1188. e.printStackTrace();
  1189. }
  1190. }
  1191. //绑定批次表与分录id的关系
  1192. List<Map<String,Object>> weightMapList = (List<Map<String, Object>>) map.get("weightMapList");
  1193. //改分录表
  1194. for (Map<String,Object> weightMap : weightMapList) {
  1195. weightMap.put("weightBatchId",weightBatchId);
  1196. tmstruckWeightBatchMapper.updateFluMes(weightMap);
  1197. }
  1198. for (Map<String,Object> weightMap : weightMapList) {
  1199. weightMap.put("weightBatchId",weightBatchId);
  1200. tmstruckWeightBatchMapper.updateOmMes(weightMap);
  1201. }
  1202. tmstruckWeightBatchMapper.insertSelective(tmstruckWeightBatch);
  1203. }
  1204. }