TmsWeightResultServiceImpl.java 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. package com.steerinfo.dil.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.steerinfo.dil.feign.DzFeign;
  4. import com.steerinfo.dil.feign.WmsFeign;
  5. import com.steerinfo.dil.mapper.*;
  6. import com.steerinfo.dil.model.*;
  7. import com.steerinfo.dil.util.DaZongUtil;
  8. import com.steerinfo.dil.util.DataChange;
  9. import com.steerinfo.dil.util.EntityDispose;
  10. import com.steerinfo.framework.controller.RESTfulResult;
  11. import com.steerinfo.framework.mapper.IBaseMapper;
  12. import com.steerinfo.framework.service.impl.BaseServiceImpl;
  13. import org.apache.log4j.Logger;
  14. import org.checkerframework.checker.units.qual.A;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.beans.factory.annotation.Required;
  17. import org.springframework.stereotype.Service;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import org.springframework.web.bind.annotation.RequestParam;
  20. import java.text.DateFormat;
  21. import java.text.SimpleDateFormat;
  22. import java.util.*;
  23. import java.math.BigDecimal;
  24. import java.util.concurrent.*;
  25. /**
  26. * TmsWeightResult服务实现:
  27. * @author generator
  28. * @version 1.0-SNAPSHORT 2023-10-30 10:06
  29. * 类描述
  30. * 修订历史:
  31. * 日期:2023-10-30
  32. * 作者:generator
  33. * 参考:
  34. * 描述:TmsWeightResult服务实现
  35. * @see null
  36. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  37. */
  38. @Service(value = "tmsWeightResultService")
  39. public class TmsWeightResultServiceImpl {
  40. static final Logger log = Logger.getLogger(TmsWeightResultServiceImpl.class);
  41. @Autowired
  42. private TmsWeightResultMapper tmsWeightResultMapper;
  43. @Autowired
  44. OmsTransOrderServiceImpl omsTransOrderService;
  45. @Autowired
  46. private OmsTransOrderMapper omsTransOrderMapper;
  47. @Autowired
  48. private RmsOperationPointMapper rmsOperationPointMapper;
  49. @Autowired
  50. private AmsTransPlanMapper amsTransPlanMapper;
  51. @Autowired
  52. private AmsPlanChildMapper amsPlanChildMapper;
  53. @Autowired
  54. private OmsOrderChildMapper omsOrderChildMapper;
  55. @Autowired
  56. OmsOrderChildServiceImpl omsOrderChildService;
  57. @Autowired
  58. private WmsFeign wmsFeign;
  59. @Autowired
  60. EntityDispose entityDispose;
  61. @Autowired
  62. DaZongUtil daZongUtil;
  63. @Autowired
  64. DzFeign dzFeign;
  65. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  66. @Transactional(rollbackFor = Exception.class)
  67. public String syncWeightResult(Map<String, Object> map) throws Exception {
  68. JSONObject jsonObject = new JSONObject(map);
  69. //查询运输订单
  70. List<BigDecimal> transOrderIds = omsTransOrderMapper.getTransOrderIdByNumber(map);
  71. if(transOrderIds.size() != 1){
  72. omsTransOrderService.reGenerateTransOrder(map);
  73. throw new Exception("运输订单异常!不能同步!");
  74. }
  75. //物资分录
  76. BigDecimal transOrderChildId = DataChange.dataToBigDecimal(map.get("transOrderChildId").toString());
  77. //查询运输订单下的计量实绩
  78. Map<String,Object> searchMap = new HashMap<>();
  79. searchMap.put("transOrderId",transOrderIds.get(0));
  80. searchMap.put("deleted",0);
  81. Map<String, Object> transOrder = omsTransOrderMapper.getTransOrder(searchMap);
  82. List<TmsWeightResult> list = tmsWeightResultMapper.selectByParametersSt(searchMap);
  83. log.debug(list.toString());
  84. String poundNo = map.get("poundNo").toString();
  85. String weightBz = DataChange.getString(map.get("weightBz"));
  86. String url = map.get("url") == null ? "" : map.get("url").toString();
  87. if("新增".equals(map.get("operationType"))){
  88. // 判断该运单子表是否有净重
  89. List<BigDecimal> netWeightIds = tmsWeightResultMapper.selectNetWeightId(transOrderChildId);
  90. if (netWeightIds.size() > 0 && netWeightIds.get(0) != null) {
  91. return "该运单子实绩已有净重";
  92. }
  93. //根据运单获取运单子表的数量
  94. //if(tmsWeightResultMapper.getTransOrderChildNotWeight(transOrderIds.get(0),transOrderChildId).size() < 1) {
  95. // //如果实绩ID是运单子表数量的两倍,则说明存在复磅的情况
  96. // List<BigDecimal> transOrderChildIds = tmsWeightResultMapper.getTransOrderChildId(transOrderIds.get(0));
  97. // if(transOrderChildIds.size() == 1 && transOrderChildIds.get(0) != null) {
  98. // }else{
  99. // throw new Exception("该分录不可用,请检查是否正确。");
  100. // }
  101. //}
  102. if(map.get("tarePointName")!=null && !"".equals(map.get("tarePointName").toString())){
  103. BigDecimal tarePlaceId = omsTransOrderMapper.getOperationPointId(map.get("tarePointName").toString(),
  104. "" + map.get("tarePointCode"));
  105. if(tarePlaceId == null){
  106. //没有就新增
  107. tarePlaceId = rmsOperationPointMapper.nextPlaceId();
  108. RmsOperationPoint rmsOperationPoint = new RmsOperationPoint();
  109. rmsOperationPoint.setOperationPointId(tarePlaceId);
  110. rmsOperationPoint.setOperationPointName(map.get("tarePointName").toString());
  111. rmsOperationPoint.setOperationPointCode(map.get("tarePointCode").toString());
  112. rmsOperationPoint.setOperationPointType("汽车衡");
  113. rmsOperationPoint.setOperationPointStatus("正常");
  114. rmsOperationPoint.setRemark("自动新增");
  115. rmsOperationPoint.setDeleted(0);
  116. rmsOperationPointMapper.insertSelective(rmsOperationPoint);
  117. }
  118. BigDecimal tareWeight = DataChange.dataToBigDecimal(map.get("tareWeight").toString());
  119. Date tareWeightTime = DataChange.dataToDate(map.get("tareWeightTime").toString());
  120. String actualWeight = map.get("actualWeight") == null ? "0" : map.get("actualWeight").toString();
  121. //皮重
  122. for(int i =0;i<list.size();i++){
  123. TmsWeightResult item = list.get(i);
  124. if(item.getNetWeight() == null){
  125. item.setTransOrderChildId(transOrderChildId);
  126. item.setPoundNo(poundNo);
  127. item.setTarePlaceId(tarePlaceId);
  128. item.setTareWeight(tareWeight);
  129. item.setTareWeightTime(tareWeightTime);
  130. item.setAlternateFields6(url);
  131. item.setAlternateFields8(weightBz);
  132. item.setAlternateFields11(actualWeight);
  133. item.setInsertUpdateRemark(list.get(list.size() - 1).getResultId().toString());
  134. // item.setUpdateUsername(map.get("userName").toString());
  135. // item.setUpdateTime(new Date());
  136. //计算净重
  137. if(item.getTarePlaceId()!=null && item.getGrossPlaceId()!= null){
  138. BigDecimal netWeight = DataChange.dataToBigDecimal(map.get("netWeight"));
  139. BigDecimal bzw = DataChange.dataToBigDecimal(map.get("bzw"));
  140. if(netWeight != null && netWeight.compareTo(BigDecimal.ZERO) > 0){
  141. item.setNetWeight(netWeight);
  142. }else{
  143. item.setNetWeight(item.getGrossWeight().subtract(item.getTareWeight()));
  144. }
  145. item.setAlternateFields13(bzw.toString());
  146. item.setNetWeightTime(tareWeightTime);
  147. if("是".equals(transOrder.get("isMultiple"))){
  148. try {
  149. //查询运单
  150. OmsTransOrder omsTransOrder = omsTransOrderMapper.selectByPrimaryKey(transOrderIds.get(0));
  151. List<OmsOrderChild> omsOrderChildList = omsOrderChildMapper.selectByParameters(searchMap);
  152. Map<String, Object> objectObjectHashMap = new HashMap<>();
  153. BigDecimal nineTransOrderId = null;
  154. if("销售".equals(omsTransOrder.getBusinessScene())) {
  155. //查询有没有采购状态为9的运单
  156. objectObjectHashMap.put("scene","采购");
  157. objectObjectHashMap.put("capacityId",omsTransOrder.getCapacityId());
  158. objectObjectHashMap.put("driverId",omsTransOrder.getDriverId());
  159. objectObjectHashMap.put("materialId",omsOrderChildList.get(0).getMaterialId());
  160. nineTransOrderId = omsTransOrderMapper.getNineTransOrder(objectObjectHashMap);
  161. }else{
  162. //查询有没有销售状态为9的运单
  163. objectObjectHashMap.put("scene","销售");
  164. objectObjectHashMap.put("capacityId",omsTransOrder.getCapacityId());
  165. objectObjectHashMap.put("driverId",omsTransOrder.getDriverId());
  166. objectObjectHashMap.put("materialId",omsOrderChildList.get(0).getMaterialId());
  167. nineTransOrderId = omsTransOrderMapper.getNineTransOrder(objectObjectHashMap);
  168. }
  169. if(nineTransOrderId != null) {
  170. omsTransOrderMapper.updateNineOrder(nineTransOrderId);
  171. }
  172. } catch (Exception e) {
  173. e.printStackTrace();
  174. }
  175. //判断是否一车多趟
  176. try{
  177. omsTransOrderService.reDispatchOrder(transOrderIds.get(0));
  178. }catch (Exception e){
  179. e.printStackTrace();
  180. log.error("一车多趟重复派车失败:"+e.getMessage());
  181. }
  182. }
  183. //迁移库存
  184. transGridMaterial(transOrderChildId,item.getNetWeight(),""+map.get("userId"),""+map.get("userName"),item.getNetWeightTime());
  185. }
  186. if("9".equals(weightBz)){
  187. //冲减,净重为0
  188. item.setNetWeight(BigDecimal.ZERO);
  189. }
  190. tmsWeightResultMapper.updateByPrimaryKeySelective(item);
  191. if(item.getNetWeightTime() != null) {
  192. omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"出厂",item.getUpdateUsername(),item.getPoundNo());
  193. }else{
  194. omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"计皮",item.getUpdateUsername(),item.getPoundNo());
  195. }
  196. omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getTareWeightTime(),"计皮");
  197. omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getNetWeightTime(),"净重");
  198. OmsOrderChild omsOrderChild = omsOrderChildMapper.selectByPrimaryKey(transOrderChildId);
  199. omsOrderChild.setNetWeight(item.getNetWeight());
  200. omsOrderChild.setActualWeight(DataChange.dataToBigDecimal(item.getAlternateFields11()).compareTo(BigDecimal.ZERO) == 0 ? item.getNetWeight() : DataChange.dataToBigDecimal(item.getAlternateFields11()));
  201. omsOrderChildMapper.updateByPrimaryKeySelective(omsOrderChild);
  202. map.put("resultId",item.getResultId());//返回给日志记录
  203. threadPool.execute(()->{
  204. try {
  205. Thread.sleep(500);
  206. AmsPlanChild amsPlanChild = amsPlanChildMapper.selectByPrimaryKey(omsOrderChild.getPlanChildId());
  207. omsTransOrderService.sumWeight(amsPlanChild.getRequirementChildId());
  208. omsTransOrderService.sumWeightPlan(amsPlanChild.getPlanChildId());
  209. } catch (InterruptedException e) {
  210. e.printStackTrace();
  211. }
  212. });
  213. return "同步成功!";
  214. }
  215. }
  216. }else if(map.get("grossPointName")!=null && !"".equals(map.get("grossPointName").toString())){
  217. BigDecimal grossPlaceId = omsTransOrderMapper.getOperationPointId(map.get("grossPointName").toString(),
  218. "" + map.get("grossPointCode"));
  219. if(grossPlaceId == null){
  220. //没有就新增
  221. grossPlaceId = rmsOperationPointMapper.nextPlaceId();
  222. RmsOperationPoint rmsOperationPoint = new RmsOperationPoint();
  223. rmsOperationPoint.setOperationPointId(grossPlaceId);
  224. rmsOperationPoint.setOperationPointName(map.get("grossPointName").toString());
  225. rmsOperationPoint.setOperationPointCode(map.get("grossPointCode").toString());
  226. rmsOperationPoint.setOperationPointType("汽车衡");
  227. rmsOperationPoint.setOperationPointStatus("正常");
  228. rmsOperationPoint.setRemark("自动新增");
  229. rmsOperationPoint.setDeleted(0);
  230. rmsOperationPointMapper.insertSelective(rmsOperationPoint);
  231. }
  232. BigDecimal grossWeight = DataChange.dataToBigDecimal(map.get("grossWeight").toString());
  233. Date grossWeightTime = DataChange.dataToDate(map.get("grossWeightTime").toString());
  234. String actualWeight = map.get("actualWeight") == null ? "0" : map.get("actualWeight").toString();
  235. //毛重
  236. for(int i =0;i<list.size();i++){
  237. TmsWeightResult item = list.get(i);
  238. if(item.getNetWeight() == null){
  239. item.setTransOrderChildId(transOrderChildId);
  240. item.setPoundNo(poundNo);
  241. item.setGrossPlaceId(grossPlaceId);
  242. item.setGrossWeight(grossWeight);
  243. item.setGrossWeightTime(grossWeightTime);
  244. item.setResultImage(url);
  245. item.setAlternateFields8(weightBz);
  246. item.setAlternateFields11(actualWeight);
  247. item.setInsertUpdateRemark(list.get(list.size() - 1).getResultId().toString());
  248. // item.setUpdateUsername(map.get("userName").toString());
  249. // item.setUpdateTime(new Date());
  250. //计算净重
  251. if(item.getTarePlaceId()!=null && item.getGrossPlaceId()!= null){
  252. BigDecimal netWeight = DataChange.dataToBigDecimal(map.get("netWeight"));
  253. BigDecimal bzw = DataChange.dataToBigDecimal(map.get("bzw"));
  254. if(netWeight != null && netWeight.compareTo(BigDecimal.ZERO) > 0){
  255. item.setNetWeight(netWeight);
  256. }else{
  257. item.setNetWeight(item.getGrossWeight().subtract(item.getTareWeight()));
  258. }
  259. item.setAlternateFields13(bzw.toString());
  260. item.setNetWeightTime(grossWeightTime);
  261. //迁移库存
  262. transGridMaterial(transOrderChildId,item.getNetWeight(),""+map.get("userId"),""+map.get("userName"),item.getNetWeightTime());
  263. if("是".equals(transOrder.get("isMultiple"))){
  264. try {
  265. //查询运单
  266. OmsTransOrder omsTransOrder = omsTransOrderMapper.selectByPrimaryKey(transOrderIds.get(0));
  267. List<OmsOrderChild> omsOrderChildList = omsOrderChildMapper.selectByParameters(searchMap);
  268. Map<String, Object> objectObjectHashMap = new HashMap<>();
  269. BigDecimal nineTransOrderId = null;
  270. if("销售".equals(omsTransOrder.getBusinessScene())) {
  271. //查询有没有采购状态为9的运单
  272. objectObjectHashMap.put("scene","采购");
  273. objectObjectHashMap.put("capacityId",omsTransOrder.getCapacityId());
  274. objectObjectHashMap.put("driverId",omsTransOrder.getDriverId());
  275. objectObjectHashMap.put("materialId",omsOrderChildList.get(0).getMaterialId());
  276. nineTransOrderId = omsTransOrderMapper.getNineTransOrder(objectObjectHashMap);
  277. }else{
  278. //查询有没有销售状态为9的运单
  279. objectObjectHashMap.put("scene","销售");
  280. objectObjectHashMap.put("capacityId",omsTransOrder.getCapacityId());
  281. objectObjectHashMap.put("driverId",omsTransOrder.getDriverId());
  282. objectObjectHashMap.put("materialId",omsOrderChildList.get(0).getMaterialId());
  283. nineTransOrderId = omsTransOrderMapper.getNineTransOrder(objectObjectHashMap);
  284. }
  285. if(nineTransOrderId != null) {
  286. omsTransOrderMapper.updateNineOrder(nineTransOrderId);
  287. }
  288. } catch (Exception e) {
  289. e.printStackTrace();
  290. }
  291. //判断是否一车多趟
  292. try{
  293. omsTransOrderService.reDispatchOrder(transOrderIds.get(0));
  294. }catch (Exception e){
  295. e.printStackTrace();
  296. log.error("一车多趟重复派车失败:"+e.getMessage());
  297. }
  298. }
  299. //判断是否还有下一拼,有则提前设置皮重信息
  300. // if(i != list.size()-1){
  301. // list.get(i+1).setTarePlaceId(grossPlaceId);
  302. // list.get(i+1).setTareWeight(grossWeight);
  303. // list.get(i+1).setTareWeightTime(grossWeightTime);
  304. //// list.get(i+1).setUpdateUsername(map.get("userName").toString());
  305. //// list.get(i+1).setUpdateTime(new Date());
  306. // tmsWeightResultMapper.updateByPrimaryKeySelective(list.get(i+1));
  307. // }
  308. }
  309. if("9".equals(weightBz)){
  310. //冲减,净重为0
  311. item.setNetWeight(BigDecimal.ZERO);
  312. }
  313. tmsWeightResultMapper.updateByPrimaryKeySelective(item);
  314. if(item.getNetWeightTime() != null) {
  315. omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"出厂",item.getUpdateUsername(),item.getPoundNo());
  316. }else{
  317. omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"计毛",item.getUpdateUsername(),item.getPoundNo());
  318. }
  319. omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getGrossWeightTime(),"计毛");
  320. omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getNetWeightTime(),"净重");
  321. OmsOrderChild omsOrderChild = omsOrderChildMapper.selectByPrimaryKey(transOrderChildId);
  322. omsOrderChild.setNetWeight(item.getNetWeight());
  323. omsOrderChild.setActualWeight(DataChange.dataToBigDecimal(item.getAlternateFields11()).compareTo(BigDecimal.ZERO) == 0 ? item.getNetWeight() : DataChange.dataToBigDecimal(item.getAlternateFields11()));
  324. omsOrderChildMapper.updateByPrimaryKeySelective(omsOrderChild);
  325. map.put("resultId",item.getResultId());//返回给日志记录
  326. threadPool.execute(()->{
  327. try {
  328. Thread.sleep(500);
  329. AmsPlanChild amsPlanChild = amsPlanChildMapper.selectByPrimaryKey(omsOrderChild.getPlanChildId());
  330. omsTransOrderService.sumWeight(amsPlanChild.getRequirementChildId());
  331. omsTransOrderService.sumWeightPlan(amsPlanChild.getPlanChildId());
  332. } catch (InterruptedException e) {
  333. e.printStackTrace();
  334. }
  335. });
  336. return "同步成功!";
  337. }
  338. }
  339. }else {
  340. throw new Exception("tarePointName或grossPointName不能为空!");
  341. }
  342. }else if ("修改".equals(map.get("operationType"))){
  343. if(map.get("tarePointName")!=null && !"".equals(map.get("tarePointName").toString())){
  344. BigDecimal tarePlaceId = omsTransOrderMapper.getOperationPointId(map.get("tarePointName").toString(),
  345. "" + map.get("tarePointCode"));
  346. if(tarePlaceId == null){
  347. //没有就新增
  348. tarePlaceId = rmsOperationPointMapper.nextPlaceId();
  349. RmsOperationPoint rmsOperationPoint = new RmsOperationPoint();
  350. rmsOperationPoint.setOperationPointId(tarePlaceId);
  351. rmsOperationPoint.setOperationPointName(map.get("tarePointName").toString());
  352. rmsOperationPoint.setOperationPointCode(map.get("tarePointCode").toString());
  353. rmsOperationPoint.setOperationPointType("汽车衡");
  354. rmsOperationPoint.setOperationPointStatus("正常");
  355. rmsOperationPoint.setRemark("自动新增");
  356. rmsOperationPoint.setDeleted(0);
  357. rmsOperationPointMapper.insertSelective(rmsOperationPoint);
  358. }
  359. BigDecimal tareWeight = DataChange.dataToBigDecimal(map.get("tareWeight").toString());
  360. Date tareWeightTime = DataChange.dataToDate(map.get("tareWeightTime").toString());
  361. String actualWeight = map.get("actualWeight") == null ? "0" : map.get("actualWeight").toString();
  362. //皮重
  363. for(int i =0;i<list.size();i++){
  364. TmsWeightResult item = list.get(i);
  365. if(transOrderChildId.equals(item.getTransOrderChildId())){
  366. item.setPoundNo(poundNo);
  367. item.setTarePlaceId(tarePlaceId);
  368. item.setTareWeight(tareWeight);
  369. item.setTareWeightTime(tareWeightTime);
  370. item.setAlternateFields6(url);
  371. item.setAlternateFields8(weightBz);
  372. item.setAlternateFields11(actualWeight);
  373. //item.setUpdateUsername(map.get("userName").toString());
  374. item.setUpdateTime(new Date());
  375. //计算净重
  376. if(item.getTarePlaceId()!=null && item.getGrossPlaceId()!= null){
  377. BigDecimal netWeight = DataChange.dataToBigDecimal(map.get("netWeight"));
  378. BigDecimal bzw = DataChange.dataToBigDecimal(map.get("bzw"));
  379. if(netWeight != null && netWeight.compareTo(BigDecimal.ZERO) > 0){
  380. item.setNetWeight(netWeight);
  381. }else{
  382. item.setNetWeight(item.getGrossWeight().subtract(item.getTareWeight()));
  383. }
  384. item.setAlternateFields13(bzw.toString());
  385. item.setNetWeightTime(tareWeightTime);
  386. //迁移库存
  387. transGridMaterial(transOrderChildId,item.getNetWeight(),""+map.get("userId"),""+map.get("userName"),item.getNetWeightTime());
  388. }
  389. if("9".equals(weightBz)){
  390. //冲减,净重为0
  391. item.setNetWeight(BigDecimal.ZERO);
  392. }
  393. tmsWeightResultMapper.updateByPrimaryKeySelective(item);
  394. OmsOrderChild omsOrderChild = omsOrderChildMapper.selectByPrimaryKey(transOrderChildId);
  395. omsOrderChild.setNetWeight(item.getNetWeight());
  396. omsOrderChild.setActualWeight(DataChange.dataToBigDecimal(item.getAlternateFields11()).compareTo(BigDecimal.ZERO) == 0 ? item.getNetWeight() : DataChange.dataToBigDecimal(item.getAlternateFields11()));
  397. omsOrderChildMapper.updateByPrimaryKeySelective(omsOrderChild);
  398. map.put("resultId",item.getResultId());//返回给日志记录
  399. try{
  400. if(item.getNetWeightTime() != null) {
  401. omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"出厂",item.getUpdateUsername(),item.getPoundNo());
  402. }else{
  403. omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"计皮",item.getUpdateUsername(),item.getPoundNo());
  404. }
  405. omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getTareWeightTime(),"计皮");
  406. omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getNetWeightTime(),"净重");
  407. }catch (Exception e){}
  408. threadPool.execute(()->{
  409. try {
  410. Thread.sleep(500);
  411. AmsPlanChild amsPlanChild = amsPlanChildMapper.selectByPrimaryKey(omsOrderChild.getPlanChildId());
  412. omsTransOrderService.sumWeight(amsPlanChild.getRequirementChildId());
  413. omsTransOrderService.sumWeightPlan(amsPlanChild.getPlanChildId());
  414. } catch (InterruptedException e) {
  415. e.printStackTrace();
  416. }
  417. });
  418. return "同步成功!";
  419. }
  420. }
  421. }else if(map.get("grossPointName")!=null && !"".equals(map.get("grossPointName").toString())){
  422. BigDecimal grossPlaceId = omsTransOrderMapper.getOperationPointId(map.get("grossPointName").toString(),
  423. "" + map.get("grossPointCode"));
  424. if(grossPlaceId == null){
  425. //没有就新增
  426. grossPlaceId = rmsOperationPointMapper.nextPlaceId();
  427. RmsOperationPoint rmsOperationPoint = new RmsOperationPoint();
  428. rmsOperationPoint.setOperationPointId(grossPlaceId);
  429. rmsOperationPoint.setOperationPointName(map.get("grossPointName").toString());
  430. rmsOperationPoint.setOperationPointCode(map.get("grossPointCode").toString());
  431. rmsOperationPoint.setOperationPointType("汽车衡");
  432. rmsOperationPoint.setOperationPointStatus("正常");
  433. rmsOperationPoint.setRemark("自动新增");
  434. rmsOperationPoint.setDeleted(0);
  435. rmsOperationPointMapper.insertSelective(rmsOperationPoint);
  436. }
  437. BigDecimal grossWeight = DataChange.dataToBigDecimal(map.get("grossWeight").toString());
  438. Date grossWeightTime = DataChange.dataToDate(map.get("grossWeightTime").toString());
  439. String actualWeight = map.get("actualWeight") == null ? "0" : map.get("actualWeight").toString();
  440. //毛重
  441. for(int i =0;i<list.size();i++){
  442. TmsWeightResult item = list.get(i);
  443. if(transOrderChildId.equals(item.getTransOrderChildId())){
  444. item.setPoundNo(poundNo);
  445. item.setGrossPlaceId(grossPlaceId);
  446. item.setGrossWeight(grossWeight);
  447. item.setGrossWeightTime(grossWeightTime);
  448. item.setResultImage(url);
  449. item.setAlternateFields8(weightBz);
  450. item.setAlternateFields11(actualWeight);
  451. //item.setUpdateUsername(map.get("userName").toString());
  452. item.setUpdateTime(new Date());
  453. //计算净重
  454. if(item.getTarePlaceId()!=null && item.getGrossPlaceId()!= null){
  455. BigDecimal netWeight = DataChange.dataToBigDecimal(map.get("netWeight"));
  456. BigDecimal bzw = DataChange.dataToBigDecimal(map.get("bzw"));
  457. if(netWeight != null && netWeight.compareTo(BigDecimal.ZERO) > 0){
  458. item.setNetWeight(netWeight);
  459. }else{
  460. item.setNetWeight(item.getGrossWeight().subtract(item.getTareWeight()));
  461. }
  462. item.setAlternateFields13(bzw.toString());
  463. item.setNetWeightTime(grossWeightTime);
  464. //迁移库存
  465. transGridMaterial(transOrderChildId,item.getNetWeight(),""+map.get("userId"),""+map.get("userName"),item.getNetWeightTime());
  466. ////判断是否还有下一拼,有则提前设置皮重信息
  467. //if(i != list.size()-1){
  468. // list.get(i+1).setTarePlaceId(grossPlaceId);
  469. // list.get(i+1).setTareWeight(grossWeight);
  470. // list.get(i+1).setTareWeightTime(grossWeightTime);
  471. // list.get(i+1).setUpdateUsername(map.get("userId").toString());
  472. // list.get(i+1).setUpdateTime(new Date());
  473. // tmsWeightResultMapper.updateByPrimaryKeySelective(list.get(i+1));
  474. //}
  475. }
  476. if("9".equals(weightBz)){
  477. //冲减,净重为0
  478. item.setNetWeight(BigDecimal.ZERO);
  479. }
  480. tmsWeightResultMapper.updateByPrimaryKeySelective(item);
  481. OmsOrderChild omsOrderChild = omsOrderChildMapper.selectByPrimaryKey(transOrderChildId);
  482. omsOrderChild.setNetWeight(item.getNetWeight());
  483. omsOrderChild.setActualWeight(DataChange.dataToBigDecimal(item.getAlternateFields11()).compareTo(BigDecimal.ZERO) == 0 ? item.getNetWeight() : DataChange.dataToBigDecimal(item.getAlternateFields11()));
  484. omsOrderChildMapper.updateByPrimaryKeySelective(omsOrderChild);
  485. map.put("resultId",item.getResultId());//返回给日志记录
  486. try{
  487. if(item.getNetWeightTime() != null) {
  488. omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"出厂",item.getUpdateUsername(),item.getPoundNo());
  489. }else{
  490. omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"计毛",item.getUpdateUsername(),item.getPoundNo());
  491. }
  492. omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getGrossWeightTime(),"计毛");
  493. omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getNetWeightTime(),"净重");
  494. }catch (Exception e){}
  495. threadPool.execute(()->{
  496. try {
  497. Thread.sleep(500);
  498. AmsPlanChild amsPlanChild = amsPlanChildMapper.selectByPrimaryKey(omsOrderChild.getPlanChildId());
  499. omsTransOrderService.sumWeight(amsPlanChild.getRequirementChildId());
  500. omsTransOrderService.sumWeightPlan(amsPlanChild.getPlanChildId());
  501. } catch (InterruptedException e) {
  502. e.printStackTrace();
  503. }
  504. });
  505. return "同步成功!";
  506. }
  507. }
  508. }else{
  509. throw new Exception("tarePointName或grossPointName不能为空!");
  510. }
  511. }else{
  512. throw new Exception("未知的操作类型:"+map.get("operationType"));
  513. }
  514. return "同步成功!实绩已存在!";
  515. }
  516. public List<Map<String, Object>> getWeightResultList(Map<String, Object> map) {
  517. return tmsWeightResultMapper.getTmsWeightResultList(map);
  518. }
  519. public List<Map<String, Object>> purchaseTrainWeightList(Map<String, Object> map) {
  520. return tmsWeightResultMapper.purchaseTrainWeightList(map);
  521. }
  522. public String purchaseTrainWeight(Map<String, Object> map) throws Exception {
  523. List<Map<String, Object>> orderList = (ArrayList) map.get("orderList");
  524. if(orderList.size() < 1){
  525. throw new Exception("没有数据!无法计量!");
  526. }
  527. DateFormat format = new SimpleDateFormat("yyyyMMdd");
  528. DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
  529. String userId ="" + map.get("userId");
  530. String userName ="" + map.get("userName");
  531. List<TmsWeightResult> insertList = new ArrayList<>();//新增数组
  532. List<TmsWeightResult> updateList = new ArrayList<>();//更新数组
  533. List<Map<String,Object>> paramList = new ArrayList<>();//推送大宗数据
  534. //遍历,有实绩的修改,无实绩的新增
  535. for(Map<String, Object> item :orderList){
  536. BigDecimal resultId = DataChange.dataToBigDecimal(item.get("resultId"));
  537. BigDecimal transOrderId = DataChange.dataToBigDecimal(item.get("transOrderId"));
  538. BigDecimal transOrderChildId = DataChange.dataToBigDecimal(item.get("transOrderChildId"));
  539. BigDecimal netWeight = DataChange.dataToBigDecimal(item.get("netWeight"));
  540. BigDecimal tareWeight = DataChange.dataToBigDecimal(item.get("tareWeight"));
  541. BigDecimal grossWeight = DataChange.dataToBigDecimal(item.get("grossWeight"));
  542. Date weightTime = format.parse(item.get("weightTime").toString());
  543. String requireNumber = item.get("requireNumber").toString();
  544. String poundNo = item.get("poundNo").toString();
  545. String trainSeq = item.get("trainSeq").toString();
  546. String capacityId = item.get("capacityId").toString();
  547. Date loadTime = format.parse(item.get("loadTime").toString());
  548. String sendStation = item.get("sendStation").toString();
  549. String endStation = item.get("endStation").toString();
  550. String tdls = item.get("tdls").toString();
  551. String tdfl = item.get("tdfl").toString();
  552. if(resultId.compareTo(BigDecimal.ZERO) == 0){
  553. //新增
  554. TmsWeightResult tmsWeightResult = new TmsWeightResult();
  555. tmsWeightResult.setResultId(tmsWeightResultMapper.nextId());
  556. tmsWeightResult.setTransOrderId(transOrderId);
  557. tmsWeightResult.setTransOrderChildId(transOrderChildId);
  558. tmsWeightResult.setPoundNo(poundNo);
  559. tmsWeightResult.setNetWeight(netWeight);
  560. tmsWeightResult.setTareWeight(tareWeight);
  561. tmsWeightResult.setGrossWeight(grossWeight);
  562. tmsWeightResult.setNetWeightTime(weightTime);
  563. tmsWeightResult.setDeleted(BigDecimal.ZERO);
  564. tmsWeightResult.setInsertTime(new Date());
  565. tmsWeightResult.setInsertUsername(userId);
  566. insertList.add(tmsWeightResult);
  567. //大宗新增
  568. Map<String,Object> params =new HashMap<>();
  569. params.put("ywlx",0);//0 -收货 1-发货
  570. params.put("czbz",1);//1-新增 2-修改 3-删除
  571. params.put("djbh",tmsWeightResult.getPoundNo());
  572. params.put("hccc",trainSeq);
  573. params.put("clbh",capacityId);
  574. params.put("cllx","");
  575. params.put("gbsj",format2.format(weightTime));
  576. params.put("sfsj",format2.format(loadTime));
  577. params.put("fhdd",sendStation);
  578. params.put("shdd",endStation);
  579. params.put("mz",tmsWeightResult.getGrossWeight());
  580. params.put("pz",tmsWeightResult.getTareWeight());
  581. params.put("jz",tmsWeightResult.getNetWeight());
  582. params.put("tzdh",requireNumber);
  583. params.put("tdls",tdls);
  584. params.put("tdfl",tdfl);
  585. params.put("username",userName);
  586. params.put("note","");
  587. paramList.add(params);
  588. }else{
  589. //修改
  590. TmsWeightResult tmsWeightResult = tmsWeightResultMapper.selectByPrimaryKey(resultId);
  591. tmsWeightResult.setNetWeight(netWeight);
  592. tmsWeightResult.setTareWeight(tareWeight);
  593. tmsWeightResult.setGrossWeight(grossWeight);
  594. tmsWeightResult.setUpdateTime(new Date());
  595. tmsWeightResult.setUpdateUsername(userId);
  596. updateList.add(tmsWeightResult);
  597. //大宗修改
  598. Map<String,Object> params =new HashMap<>();
  599. params.put("ywlx",0);//0 -收货 1-发货
  600. params.put("czbz",2);//1-新增 2-修改 3-删除
  601. params.put("djbh",tmsWeightResult.getPoundNo());
  602. params.put("hccc",trainSeq);
  603. params.put("clbh",capacityId);
  604. params.put("cllx","");
  605. params.put("gbsj",format2.format(weightTime));
  606. params.put("sfsj",format2.format(loadTime));
  607. params.put("fhdd",sendStation);
  608. params.put("shdd",endStation);
  609. params.put("mz",tmsWeightResult.getGrossWeight());
  610. params.put("pz",tmsWeightResult.getTareWeight());
  611. params.put("jz",tmsWeightResult.getNetWeight());
  612. params.put("tzdh",requireNumber);
  613. params.put("tdls",tdls);
  614. params.put("tdfl",tdfl);
  615. params.put("username",userName);
  616. params.put("note","");
  617. paramList.add(params);
  618. }
  619. }
  620. //数据更新之前先修改入库(自动更新库存)
  621. // Map<String,Object> inboundMap = new HashMap<>();
  622. // inboundMap.put("transPlanId",map.get("transPlanId"));
  623. // inboundMap.put("inboundNumber",map.get("weight"));
  624. // inboundMap.put("gridName","原料在途库");
  625. // inboundMap.put("materialId",map.get("materialId"));
  626. // inboundMap.put("userId",userId);
  627. // inboundMap.put("userName",userName);
  628. // RESTfulResult inbountResult = wmsFeign.updateInbound(inboundMap);
  629. // if(!"succeed".equals(inbountResult.getStatus())){
  630. // throw new Exception(inbountResult.getMessage());
  631. // }
  632. if(insertList.size() > 0){
  633. tmsWeightResultMapper.batchInsert(insertList);
  634. }
  635. if(updateList.size() > 0){
  636. tmsWeightResultMapper.batchUpdate(updateList);
  637. }
  638. //推送大宗
  639. // Map<String,Object>[] paramArray = paramList.toArray(new Map[paramList.size()]);
  640. // daZongUtil.execute("30010000060", paramArray);
  641. return "上传成功!";
  642. }
  643. public String checkWeightResult(Map<String, Object> map) throws Exception {
  644. //初始化
  645. List<Map<String,Object>> list = (List) map.get("list");
  646. List<TmsWeightResult> tmsWeightResults = new ArrayList<>();
  647. String checkStr = map.get("checkStr").toString();
  648. List<String> poundNoList = new ArrayList<>();//磅单数组
  649. //校验并赋值
  650. for(Map<String ,Object> item : list){
  651. TmsWeightResult tmsWeightResult = tmsWeightResultMapper.selectByPrimaryKey(DataChange.dataToBigDecimal(item.get("resultId")));
  652. if(checkStr.contains("已审核")){
  653. tmsWeightResult.setAlternateFields3("已审核");
  654. }else{
  655. tmsWeightResult.setAlternateFields3("已弃审");
  656. }
  657. tmsWeightResult.setAlternateFields4(map.get("userName").toString());
  658. tmsWeightResult.setAlternateFields5(dateFormat.format(new Date()));
  659. tmsWeightResults.add(tmsWeightResult);
  660. poundNoList.add(tmsWeightResult.getPoundNo());
  661. }
  662. map.put("poundNoList",poundNoList);
  663. //批量更新
  664. if(tmsWeightResults.size() > 0){
  665. tmsWeightResultMapper.batchUpdate(tmsWeightResults);
  666. //推送大宗
  667. if(checkStr.contains("已审核")){
  668. dzFeign.updWeightStatus(map);
  669. }
  670. return "操作成功:"+checkStr;
  671. }else{
  672. return "没有能审批的数据!";
  673. }
  674. }
  675. //根据运单id返回过磅重量到通知单
  676. public void netWeightToRequirement(BigDecimal transOrderId, BigDecimal netWeight) {
  677. //根据运单id获取通知单
  678. //omsTransOrderMapper.select
  679. }
  680. //补单,生成计量实绩与子表实绩
  681. @Transactional(rollbackFor = Exception.class)
  682. public List<Map<String,Object>> addOrderWeight(Map<String,Object> map) {
  683. List<Map<String,Object>> mapList = new ArrayList<>();
  684. if(!map.containsKey("gross")) {
  685. mapList.add(map);
  686. return mapList;
  687. }
  688. List<Map<String,Object>> grossList = (List<Map<String, Object>>) map.get("gross");
  689. if(grossList.size() == 0) {
  690. mapList.add(map);
  691. return mapList;
  692. }
  693. //根据运单子表Id,查询计划子表ID,需求子表ID
  694. BigDecimal transOrderChildId = DataChange.dataToBigDecimal(map.get("transOrderChildId"));
  695. Map<String,Object> mesInfo = tmsWeightResultMapper.selectMesInfo(transOrderChildId);
  696. BigDecimal transPlanId = DataChange.dataToBigDecimal(mesInfo.get("transPlanId"));
  697. BigDecimal planChildId = DataChange.dataToBigDecimal(mesInfo.get("planChildId"));
  698. BigDecimal requirementChildId = DataChange.dataToBigDecimal(mesInfo.get("requirementChildId"));
  699. Map<String, Object> firstWeightMap = new HashMap<>();
  700. Map<String, Object> secondTareWeightMap = new HashMap<>();
  701. Map<String, Object> secondGrossWeightMap = new HashMap<>();
  702. for (Map<String,Object> stringObjectMap : grossList) {
  703. Map<String, Object> weightMap = new HashMap<>();
  704. String tdls = stringObjectMap.get("tdls").toString();
  705. String tdfl = stringObjectMap.get("tdfl").toString();
  706. // 防止该通知单数据来自大宗,去查一遍
  707. BigDecimal stTdfl = tmsWeightResultMapper.selectStTdfl(tdls,tdfl);
  708. BigDecimal mz = DataChange.dataToBigDecimal(stringObjectMap.get("mz"));
  709. BigDecimal jz = DataChange.dataToBigDecimal(stringObjectMap.get("netWeight"));
  710. BigDecimal bzw = DataChange.dataToBigDecimal(stringObjectMap.get("bzw"));
  711. if (requirementChildId.compareTo(stTdfl) == 0) {
  712. weightMap.putAll(map);
  713. weightMap.remove("gross");
  714. weightMap.put("grossWeight",mz);
  715. weightMap.put("netWeight",jz);
  716. weightMap.put("bzw",bzw);
  717. firstWeightMap.putAll(weightMap);
  718. //mapList.add(weightMap);
  719. continue;
  720. }
  721. //根据sttdfl去寻找计划子表与计划
  722. BigDecimal newPlanChildId = amsPlanChildMapper.selectPlanChildId(stTdfl);
  723. AmsPlanChild amsPlanChild = new AmsPlanChild();
  724. if (newPlanChildId == null) {
  725. //需要补录计划表、计划子表、运单子表
  726. AmsTransPlan amsTransPlan = amsTransPlanMapper.selectByPrimaryKey(transPlanId);
  727. amsTransPlan.setTransPlanId(amsTransPlanMapper.nextId());
  728. amsTransPlan.setInsertTime(new Date());
  729. amsTransPlanMapper.insertSelective(amsTransPlan);
  730. amsPlanChild = amsPlanChildMapper.selectByPrimaryKey(planChildId);
  731. amsPlanChild.setPlanChildId(amsPlanChildMapper.nextId());
  732. amsPlanChild.setTransPlanId(amsTransPlan.getTransPlanId());
  733. amsPlanChild.setRequirementChildId(stTdfl);
  734. amsPlanChild.setInsertTime(new Date());
  735. // 查询通知单数量
  736. BigDecimal stTdflMaterialWeight = amsPlanChildMapper.selectMaterialWeight(stTdfl);
  737. amsPlanChild.setMaterialNumber(stTdflMaterialWeight);
  738. //修改通知单状态
  739. amsPlanChildMapper.updateRequirementStatus(stTdfl);
  740. amsPlanChildMapper.insertSelective(amsPlanChild);
  741. }else {
  742. amsPlanChild = amsPlanChildMapper.selectByPrimaryKey(newPlanChildId);
  743. }
  744. //运单子表
  745. OmsOrderChild omsOrderChild = omsOrderChildMapper.selectByPrimaryKey(transOrderChildId);
  746. // 根据运单id去找下面有没有补单的
  747. BigDecimal newOrderChildId = omsOrderChildMapper.selectNewOrderChildId(omsOrderChild.getTransOrderId());
  748. if (newOrderChildId == null) {
  749. omsOrderChild.setOrderChildId(omsOrderChildMapper.nextId());
  750. omsOrderChild.setPlanChildId(amsPlanChild.getPlanChildId());
  751. omsOrderChild.setMaterialNumber(new BigDecimal(0));
  752. omsOrderChild.setInsertUpdateRemark("补单自动生成运单子表");
  753. omsOrderChild.setAlternateFields7("0");
  754. entityDispose.disposeOrderChild(omsOrderChild);
  755. omsOrderChildMapper.insertSelective(omsOrderChild);
  756. }else{
  757. omsOrderChild.setOrderChildId(newOrderChildId);
  758. omsOrderChild.setPlanChildId(amsPlanChild.getPlanChildId());
  759. omsOrderChild.setMaterialNumber(new BigDecimal(0));
  760. omsOrderChild.setInsertUpdateRemark("补单自动生成运单子表");
  761. omsOrderChild.setAlternateFields7("0");
  762. omsOrderChildMapper.updateByPrimaryKeySelective(omsOrderChild);
  763. }
  764. //生成计量实绩皮重报文
  765. Map<String,Object> tareWeightMap = tmsWeightResultMapper.selectTareWeightMap(omsOrderChild.getTransOrderId());
  766. if (tareWeightMap != null) {
  767. tareWeightMap.put("operationType",map.get("operationType"));
  768. tareWeightMap.put("transOrderNumber",map.get("transOrderNumber"));
  769. tareWeightMap.put("transOrderChildId",omsOrderChild.getOrderChildId());
  770. secondTareWeightMap.putAll(tareWeightMap);
  771. //mapList.add(tareWeightMap);
  772. }
  773. //生成计量实绩毛重报文
  774. weightMap.putAll(map);
  775. weightMap.remove("gross");
  776. weightMap.put("grossWeight",mz);
  777. weightMap.put("netWeight",jz);
  778. weightMap.put("bzw",bzw);
  779. weightMap.put("transOrderChildId",omsOrderChild.getOrderChildId());
  780. secondGrossWeightMap.putAll(weightMap);
  781. //mapList.add(weightMap);
  782. }
  783. mapList.add(firstWeightMap);
  784. if(secondTareWeightMap.get("transOrderChildId") != null) {
  785. mapList.add(secondTareWeightMap);
  786. }
  787. if(secondGrossWeightMap.get("transOrderChildId") != null) {
  788. mapList.add(secondGrossWeightMap);
  789. }
  790. return mapList;
  791. }
  792. /**
  793. * 迁移库存
  794. * @param transOrderChildId
  795. * @param netWeight
  796. * @param userId
  797. * @param userName
  798. */
  799. public void transGridMaterial(BigDecimal transOrderChildId,BigDecimal netWeight,String userId,String userName,@RequestParam(required = false) Date netWeightTime) {
  800. return;
  801. // try{
  802. // Map<String,Object> boundResult = tmsWeightResultMapper.getBoundResult(transOrderChildId);
  803. // String businessScene = boundResult.get("businessScene").toString();
  804. // BigDecimal loadPointId = DataChange.dataToBigDecimal(boundResult.get("loadPointId"));
  805. // BigDecimal unloadPointId = DataChange.dataToBigDecimal(boundResult.get("unloadPointId"));
  806. // switch (businessScene){
  807. // case "采购":
  808. // //汽车入厂,不入库厂内,出库在途;
  809. // //boundResult.put("gridId",boundResult.get("unloadPointId"));
  810. // //boundResult.put("inboundNumber",netWeight);
  811. // //boundResult.put("inboundType","采购汽运计量入库");
  812. // //boundResult.put("inboundTime",netWeightTime);
  813. // //boundResult.put("model","汽运");
  814. // //boundResult.put("userId",userId);
  815. // //boundResult.put("userName",userName);
  816. // //RESTfulResult inbountResult = wmsFeign.inbound(boundResult);
  817. // //if(!"succeed".equals(inbountResult.getStatus())){
  818. // // throw new Exception(inbountResult.getMessage());
  819. // //}
  820. // boundResult.put("gridId",boundResult.get("loadPointId"));
  821. // boundResult.put("outboundNumber",netWeight);
  822. // boundResult.put("outboundType","采购汽运在途出库");
  823. // boundResult.put("userId",userId);
  824. // boundResult.put("cgjh","原料在途库");
  825. // boundResult.put("model","汽运");
  826. // boundResult.put("userName",userName);
  827. // boundResult.put("outboundTime",netWeightTime);
  828. // RESTfulResult outbountResult = wmsFeign.outbound(boundResult);
  829. // if(!"succeed".equals(outbountResult.getStatus())){
  830. // throw new Exception(outbountResult.getMessage());
  831. // }
  832. // break;
  833. // case "销售":
  834. // //boundResult.put("gridId",boundResult.get("loadPointId"));
  835. // //boundResult.put("outboundNumber",netWeight);
  836. // //boundResult.put("outboundType","销售汽运计量出库");
  837. // //boundResult.put("userId",userId);
  838. // //boundResult.put("model","汽运");
  839. // //boundResult.put("userName",userName);
  840. // //boundResult.put("outboundTime",netWeightTime);
  841. // //RESTfulResult outbountResult = wmsFeign.outbound(boundResult);
  842. // //if(!"succeed".equals(outbountResult.getStatus())){
  843. // // throw new Exception(outbountResult.getMessage());
  844. // //}
  845. // //break;
  846. // case "生产":
  847. //// if(loadPointId.compareTo(unloadPointId) == 0){
  848. //// //装卸货点相同,则不进行迁移库存
  849. //// return;
  850. //// }
  851. //// //先出库
  852. //// Map<String,Object> outBoundMap = JSONObject.parseObject(JSONObject.toJSONString(boundResult),Map.class);
  853. //// outBoundMap.put("gridId",boundResult.get("loadPointId"));
  854. //// outBoundMap.put("outboundNumber",netWeight);
  855. //// outBoundMap.put("outboundType","生产汽运计量出库");
  856. //// outBoundMap.put("userId",userId);
  857. //// outBoundMap.put("outboundTime",netWeightTime);
  858. //// outBoundMap.put("userName",userName);
  859. //// RESTfulResult outbountResult2 = wmsFeign.outbound(outBoundMap);
  860. ////// if(!"succeed".equals(outbountResult2.getStatus())){
  861. ////// throw new Exception(outbountResult2.getMessage());
  862. ////// }
  863. //// //再入库
  864. //// Map<String,Object> inBoundMap = JSONObject.parseObject(JSONObject.toJSONString(boundResult),Map.class);
  865. //// inBoundMap.put("gridId",inBoundMap.get("unloadPointId"));
  866. //// inBoundMap.put("inboundNumber",netWeight);
  867. //// inBoundMap.put("inboundType","生产汽运计量入库");
  868. //// inBoundMap.put("userId",userId);
  869. //// inBoundMap.put("userName",userName);
  870. //// inBoundMap.put("inboundTime",netWeightTime);
  871. //// RESTfulResult inbountResult2 = wmsFeign.inbound(inBoundMap);
  872. //// if(!"succeed".equals(inbountResult2.getStatus())){
  873. //// throw new Exception(inbountResult2.getMessage());
  874. //// }
  875. // break;
  876. // default:
  877. // throw new Exception("未知的业务类型!");
  878. // }
  879. // }catch (Exception e){
  880. // e.printStackTrace();
  881. // log.error("转移库存失败:"+e.getMessage());
  882. // }
  883. }
  884. @Transactional(rollbackFor = Exception.class)
  885. public String syncTheoryWeight(Map<String, Object> map) {
  886. //获取需要同步的订单编码
  887. List<Map<String, Object>> mapList = tmsWeightResultMapper.syncTheoryWeight(map);
  888. for (Map<String, Object> objectMap : mapList) {
  889. //获取大宗理论重量
  890. Map<String, Object> dzMap = dzFeign.syncTheoryWeight(objectMap);
  891. TmsWeightResult tmsWeightResult = tmsWeightResultMapper.selectByPrimaryKey(DataChange.dataToBigDecimal(objectMap.get("resultId")));
  892. tmsWeightResult.setAlternateFields11(dzMap.get("theoryWeight").toString());
  893. tmsWeightResultMapper.updateByPrimaryKey(tmsWeightResult);
  894. }
  895. return "OK";
  896. }
  897. public String buluBzwWeight() {
  898. List<TmsWeightResult> list = tmsWeightResultMapper.selectForBzw();
  899. while(list.size() > 0){
  900. Map<String,Object> searchMap = new HashMap<>();
  901. searchMap.put("list",list);
  902. List<Map<String,Object>> resultList = dzFeign.getTransOrderBzw(searchMap);
  903. for(Map<String,Object> item : resultList){
  904. TmsWeightResult tmsWeightResult = new TmsWeightResult();
  905. tmsWeightResult.setResultId(DataChange.dataToBigDecimal(item.get("resultId")));
  906. tmsWeightResult.setGrossWeight(DataChange.dataToBigDecimal(item.get("grossWeight")));
  907. tmsWeightResult.setTareWeight(DataChange.dataToBigDecimal(item.get("tareWeight")));
  908. tmsWeightResult.setNetWeight(DataChange.dataToBigDecimal(item.get("netWeight")));
  909. tmsWeightResult.setAlternateFields13(DataChange.dataToBigDecimal(item.get("bzw")).toString());
  910. tmsWeightResultMapper.updateByPrimaryKeySelective(tmsWeightResult);
  911. }
  912. //继续查询,直到查不到为止
  913. list = tmsWeightResultMapper.selectForBzw();
  914. }
  915. return "操作成功!";
  916. }
  917. ExecutorService threadPool = new ThreadPoolExecutor(2,5,
  918. 1L, TimeUnit.SECONDS,
  919. new LinkedBlockingQueue<>(3),
  920. Executors.defaultThreadFactory(),
  921. new ThreadPoolExecutor.AbortPolicy());
  922. }