TmstruckTotalResultServiceImpl.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. package com.steerinfo.dil.service.impl;
  2. import com.steerinfo.dil.feign.OmsFeign;
  3. import com.steerinfo.dil.feign.QmsFeign;
  4. import com.steerinfo.dil.mapper.*;
  5. import com.steerinfo.dil.model.*;
  6. import com.steerinfo.dil.service.ITmstruckTotalResultService;
  7. import com.steerinfo.dil.util.DataChange;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.scheduling.annotation.Scheduled;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import java.math.BigDecimal;
  13. import java.util.*;
  14. /**
  15. * @ author :TXF
  16. * @ time :2021/10/27 10:18
  17. */
  18. @Service(value = "tmstruckTotalResultService")
  19. public class TmstruckTotalResultServiceImpl implements ITmstruckTotalResultService {
  20. @Autowired
  21. private TmstruckTotalResultMapper tmstruckTotalResultMapper;
  22. @Autowired
  23. private OmsFeign omsFeign;
  24. @Autowired
  25. TmstruckEnfactoryResultMapper tmstruckEnfactoryResultMapper;
  26. @Autowired
  27. TmstruckWeightResultMapper tmstruckWeightResultMapper;
  28. @Autowired
  29. TmstruckLoadResultMapper tmstruckLoadResultMapper;
  30. @Autowired
  31. TmstruckUnloadResultMapper tmstruckUnloadResultMapper;
  32. @Autowired
  33. TmstruckLeaveFactoryResultMapper tmstruckLeaveFactoryResultMapper;
  34. @Autowired
  35. TmstruckEnfactoryResultServiceImpl tmstruckEnfactoryResultService;
  36. @Autowired
  37. TmstruckLoadResultServiceImpl tmstruckLoadResultService;
  38. @Autowired
  39. TmstruckUnloadResultServiceImpl tmstruckUnloadResultService;
  40. @Autowired
  41. TmstruckWeightResultServiceImpl tmstruckWeightResultService;
  42. @Autowired
  43. TmstruckLeaveFactoryResultServiceImpl tmstruckLeaveFactoryResultService;
  44. @Autowired
  45. TmstruckReturnResultServiceImpl tmstruckReturnResultService;
  46. /**
  47. * 新增实绩总表
  48. * 运输订单ID
  49. * @param orderId
  50. * @return
  51. */
  52. public int addTotalResult(BigDecimal orderId){
  53. TmstruckTotalResult tmstruckTotalResult = new TmstruckTotalResult();
  54. BigDecimal maxId = tmstruckTotalResultMapper.selectMaxId();
  55. tmstruckTotalResult.setResultTotalId(maxId);
  56. tmstruckTotalResult.setOrderId(orderId);
  57. tmstruckTotalResult.setInsertTime(new Date());
  58. tmstruckTotalResult.setInsertUsername("admin");
  59. tmstruckTotalResult.setOrderStatus("已派单");
  60. tmstruckTotalResultMapper.insertSelective(tmstruckTotalResult);
  61. return maxId.intValue();
  62. }
  63. public int copyAllResult(BigDecimal orderId,BigDecimal orderIdOld,BigDecimal resultTotalIdOld){
  64. //总实绩
  65. TmstruckTotalResult tmstruckTotalResult = new TmstruckTotalResult();
  66. BigDecimal maxId = tmstruckTotalResultMapper.selectMaxId();
  67. tmstruckTotalResult.setResultTotalId(maxId);
  68. tmstruckTotalResult.setOrderId(orderId);
  69. tmstruckTotalResult.setInsertTime(new Date());
  70. tmstruckTotalResult.setInsertUsername("admin");
  71. tmstruckTotalResultMapper.insertSelective(tmstruckTotalResult);
  72. //处理旧实绩
  73. Map<String,Object> serachMap=new HashMap<>();
  74. serachMap.put("resultTotalId",resultTotalIdOld);
  75. List<TmstruckEnfactoryResult> enOlds = tmstruckEnfactoryResultMapper.selectByParameters(serachMap);
  76. if( enOlds !=null && enOlds.size()>0){
  77. //已经进厂则迁移旧的实绩
  78. //接单,生成所有路段实绩
  79. Map<String,Object> map=new HashMap<>();
  80. map.put("orderId",orderId);
  81. map.put("orderReceiveStatus",1);
  82. map.put("capacityNumber","capacityNumber");
  83. omsFeign.driverReceiveOrRefuse(map);
  84. //进厂
  85. serachMap.put("resultTotalId",maxId);
  86. TmstruckEnfactoryResult tmstruckEnfactoryResult=tmstruckEnfactoryResultMapper.selectByParameters(serachMap).get(0);
  87. TmstruckEnfactoryResult tmstruckEnfactoryResult1=enOlds.get(0);
  88. tmstruckEnfactoryResult1.setResultId(tmstruckEnfactoryResult.getResultId());
  89. tmstruckEnfactoryResult1.setResultTotalId(tmstruckEnfactoryResult.getResultTotalId());
  90. tmstruckEnfactoryResultMapper.updateByPrimaryKeySelective(tmstruckEnfactoryResult1);
  91. //计皮
  92. serachMap.put("resultTotalId",maxId);
  93. TmstruckWeightResult tmstruckWeightResult=tmstruckWeightResultMapper.selectByTotalId(serachMap).get(0);
  94. serachMap.put("switch","1");
  95. serachMap.put("resultTotalId",resultTotalIdOld);
  96. List<TmstruckWeightResult> olds = tmstruckWeightResultMapper.selectByTotalId(serachMap);
  97. if(olds!=null && olds.size()>0){
  98. TmstruckWeightResult tmstruckWeightResult1=olds.get(0);
  99. tmstruckWeightResult.setResultTareWeightTime(tmstruckWeightResult1.getResultTareWeightTime());
  100. tmstruckWeightResult.setResultTareWeight(tmstruckWeightResult1.getResultTareWeight());
  101. tmstruckWeightResult.setResultTarePlaceId(tmstruckWeightResult1.getResultTarePlaceId());
  102. tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
  103. Map<String,Object> orderMap=new HashMap<>();
  104. orderMap.put("orderId",orderId);
  105. orderMap.put("seq",2);
  106. tmstruckWeightResultMapper.updateOmstruckStatus(orderMap);
  107. }else{
  108. Map<String,Object> orderMap=new HashMap<>();
  109. orderMap.put("orderId",orderId);
  110. orderMap.put("seq",0);
  111. tmstruckWeightResultMapper.updateOmstruckStatus(orderMap);
  112. }
  113. //迁移排队实绩
  114. serachMap.put("resultTotalId",maxId);
  115. serachMap.put("resultTotalIdOld",resultTotalIdOld);
  116. tmstruckWeightResultMapper.copyQmsResult(serachMap);
  117. }else{
  118. //未进厂,状态为待接收
  119. Map<String,Object> orderMap=new HashMap<>();
  120. orderMap.put("orderId",orderId);
  121. orderMap.put("orderStatus",4);
  122. tmstruckWeightResultMapper.updateOrderStatus(orderMap);
  123. }
  124. return maxId.intValue();
  125. }
  126. /**
  127. * 展示计数实绩列表
  128. * @param map
  129. * @return
  130. */
  131. @Override
  132. public List<Map<String, Object>> selectCountList(Map<String, Object> map) {
  133. return tmstruckTotalResultMapper.selectCountList(map);
  134. }
  135. /**
  136. * 展示包月实绩列表
  137. * @param mapValue
  138. * @return
  139. */
  140. public List<Map<String, Object>> getTmstruckMonthResult(Map<String, Object> mapValue) {
  141. return tmstruckTotalResultMapper.getTmstruckMonthResult(mapValue);
  142. }
  143. /**
  144. * 展示倒库作业报表
  145. * @param mapValue
  146. * @return
  147. */
  148. @Override
  149. public List<Map<String, Object>> getAllReverseResult(Map<String, Object> mapValue) {
  150. return tmstruckTotalResultMapper.getAllReverseResult(mapValue);
  151. }
  152. /**
  153. * 为已接收没有总实绩的运输订单补录总实绩
  154. */
  155. //@Scheduled(fixedRate = 1000*60*5)
  156. public void insertTotalForNullOrder(){
  157. List<BigDecimal> list=tmstruckTotalResultMapper.getOrderForBulu();
  158. for(BigDecimal orderId:list){
  159. addTotalResult(orderId);
  160. }
  161. }
  162. @Override
  163. @Transactional(rollbackFor = Exception.class)
  164. public int changeOrderLine(Map<String, Object> mapValue) throws Exception {
  165. //查询订单详情
  166. Map<String,Object> mesMap=tmstruckTotalResultMapper.getLineId(mapValue);
  167. if(mesMap==null){
  168. throw new Exception("订单状态异常,无法变更!");
  169. }
  170. //更新线路Id
  171. if(mapValue.get("lineId")==null){
  172. throw new Exception("请选择线路!");
  173. }else if(DataChange.dataToBigDecimal(mesMap.get("lineId")).compareTo(DataChange.dataToBigDecimal(mapValue.get("lineId")))==0){
  174. throw new Exception("线路一致,无需更新!");
  175. }else{
  176. tmstruckTotalResultMapper.updateLineId(mapValue);
  177. }
  178. //校验订单,如果未接单就直接结束,已接单则继续修改实绩
  179. if(DataChange.dataToBigDecimal(mesMap.get("orderStatus")).compareTo(new BigDecimal(4))==0){
  180. return 1;
  181. }
  182. //查询并记录有效实绩,进厂,计量,装货,卸货,出厂
  183. mesMap.put("flag","1");//只查询有效实绩
  184. List<TmstruckEnfactoryResult> enfactoryResults= tmstruckTotalResultMapper.selectAllEnfactory(mesMap);
  185. List<TmstruckWeightResult> tmstruckWeightResults= tmstruckTotalResultMapper.selectAllWeight(mesMap);
  186. List<TmstruckUnloadResult> unloadResults=tmstruckTotalResultMapper.selectAllUnload(mesMap);
  187. List<TmstruckLeaveFactoryResult> leaveFactoryResults=tmstruckTotalResultMapper.selectAllLeavefactory(mesMap);
  188. System.out.println(enfactoryResults);
  189. System.out.println(tmstruckWeightResults);
  190. System.out.println(unloadResults);
  191. System.out.println(leaveFactoryResults);
  192. //删除所有旧线路实绩
  193. tmstruckTotalResultMapper.deleteEnByEnTotal(mesMap);
  194. tmstruckTotalResultMapper.deleteWeightByEnTotal(mesMap);
  195. tmstruckTotalResultMapper.deleteUnloadByEnTotal(mesMap);
  196. tmstruckTotalResultMapper.deleteLeaveByEnTotal(mesMap);
  197. //新增所有新线路实绩
  198. mesMap.put("lineId",mapValue.get("lineId"));
  199. addAllSonResult(mesMap);
  200. //查询并记录所有新实绩
  201. System.out.println("-------------------------------------");
  202. mesMap.put("flag","0");//打开查询所有
  203. List<TmstruckEnfactoryResult> enfactoryResultsNew= tmstruckTotalResultMapper.selectAllEnfactory(mesMap);
  204. List<TmstruckWeightResult> tmstruckWeightResultsNew= tmstruckTotalResultMapper.selectAllWeight(mesMap);
  205. //List<TmstruckUnloadResult> unloadResultsNew=tmstruckTotalResultMapper.selectAllUnload(mesMap);//卸货和出厂不处理
  206. //List<TmstruckLeaveFactoryResult> leaveFactoryResultsNew=tmstruckTotalResultMapper.selectAllLeavefactory(mesMap);
  207. System.out.println(enfactoryResultsNew);
  208. System.out.println(tmstruckWeightResultsNew);
  209. //System.out.println(unloadResultsNew);
  210. //System.out.println(leaveFactoryResultsNew);
  211. //更新订单信息,按顺序更新
  212. for(int i=0;i<enfactoryResults.size();i++){
  213. //进厂实绩
  214. try{
  215. TmstruckEnfactoryResult oldResult=enfactoryResults.get(i);
  216. TmstruckEnfactoryResult newResult=enfactoryResultsNew.get(i);
  217. if(oldResult!=null && newResult!=null){
  218. newResult.setGatepostId(oldResult.getGatepostId());
  219. newResult.setResultEntryMode(oldResult.getResultEntryMode());
  220. newResult.setResultEntryGateTime(oldResult.getResultEntryGateTime());
  221. }
  222. tmstruckEnfactoryResultMapper.updateByPrimaryKeySelective(newResult);
  223. }catch (Exception e){
  224. //数组越界,不处理
  225. }
  226. }
  227. for(int i=0;i<tmstruckWeightResults.size();i++){
  228. //计量实绩
  229. try{
  230. TmstruckWeightResult oldResult=tmstruckWeightResults.get(i);
  231. TmstruckWeightResult newResult=tmstruckWeightResultsNew.get(i);
  232. if(oldResult!=null && newResult!=null){
  233. newResult.setResultGrossPlaceId(oldResult.getResultGrossPlaceId());
  234. newResult.setResultGrossWeight(oldResult.getResultGrossWeight());
  235. newResult.setResultGrossWeightTime(oldResult.getResultGrossWeightTime());
  236. newResult.setMaterialId(oldResult.getMaterialId());
  237. newResult.setResultPoundNo(oldResult.getResultPoundNo());
  238. newResult.setResultTarePlaceId(oldResult.getResultTarePlaceId());
  239. newResult.setResultTareWeight(oldResult.getResultTareWeight());
  240. newResult.setResultTareWeightTime(oldResult.getResultTareWeightTime());
  241. newResult.setResultNetWeight(oldResult.getResultNetWeight());
  242. }
  243. tmstruckWeightResultMapper.updateByPrimaryKeySelective(newResult);
  244. }catch (Exception e){
  245. //数组越界,不处理
  246. }
  247. }
  248. return 1;
  249. }
  250. /**
  251. * 通过线路子表路线图生成各实绩
  252. * @param map
  253. * @return
  254. */
  255. public int addAllSonResult(Map<String, Object> map){
  256. Integer resultTotalId = DataChange.dataToBigDecimal(map.get("resultTotalId")).intValue();
  257. Integer lineId = DataChange.dataToBigDecimal(map.get("lineId")).intValue();
  258. int result = 0;
  259. //通过总实绩Id 查询关联的线路子表顺序
  260. List<Map<String, Object>> segmentList = tmstruckTotalResultMapper.getLineMesByOrderId(map);
  261. Map<String,Object> totalIdMap = new HashMap<>();
  262. totalIdMap.put("resultTotalId",resultTotalId);
  263. totalIdMap.put("lineId", lineId);
  264. // 遍历路段顺序号子表
  265. int count = 0;
  266. BigDecimal lineType = (BigDecimal) segmentList.get(0).get("lineType");
  267. if (lineType.intValue() == 4) {
  268. count++;
  269. }
  270. //存放皮重路段顺序号和毛重路段顺序号map
  271. Map<String, Object> tareAndGrossSegmentMap = new HashMap<>();
  272. for (Map<String,Object> segmentMap : segmentList) {
  273. BigDecimal segmentSqe = (BigDecimal) segmentMap.get("segmentSqe");
  274. String linkName = (String) segmentMap.get("linkName");
  275. totalIdMap.put("segmentSqe",segmentSqe);
  276. // 判断是否是计毛
  277. if (linkName.equals("计毛")) {
  278. // 如果是计量则加一
  279. count ++;
  280. tareAndGrossSegmentMap.put("grossSegmentSqe", segmentSqe);
  281. // 有两个计量的时候则新增实绩
  282. if (count == 2) {
  283. totalIdMap.putAll(tareAndGrossSegmentMap);//将皮重顺序号和毛重路段顺序号放进去
  284. tmstruckWeightResultService.addWeightResult(totalIdMap);
  285. // 新增一次则对计数器清零
  286. count = 0;
  287. tareAndGrossSegmentMap.clear(); // 清空毛重皮重 map
  288. result++;
  289. }
  290. }
  291. // 判断是否是计皮
  292. if (linkName.equals("计皮")) {
  293. // 如果是计皮则加一
  294. count ++;
  295. tareAndGrossSegmentMap.put("tareSegmentSqe", segmentSqe);
  296. // 有两个计量的时候则新增实绩
  297. if (count == 2) {
  298. totalIdMap.putAll(tareAndGrossSegmentMap);
  299. tmstruckWeightResultService.addWeightResult(totalIdMap);
  300. // 新增一次则对计数器清零
  301. count = 0;
  302. tareAndGrossSegmentMap.clear(); // 清空毛重皮重 map
  303. result++;
  304. }
  305. }
  306. // 进厂
  307. if (linkName.equals("进厂")) {
  308. tmstruckEnfactoryResultService.addEnFactoryResult(totalIdMap);
  309. result++;
  310. }
  311. // 出厂
  312. if (linkName.equals("出厂")) {
  313. tmstruckLeaveFactoryResultService.addLeaveFactory(totalIdMap);
  314. result++;
  315. }
  316. // 装货
  317. if (linkName.equals("装货")) {
  318. tmstruckLoadResultService.addLoadResult(totalIdMap);
  319. result++;
  320. }
  321. // 卸货
  322. if (linkName.equals("卸货")) {
  323. tmstruckUnloadResultService.addUnloadResult(totalIdMap);
  324. result++;
  325. }
  326. // 退货
  327. // if (linkName.equals("退货")) {
  328. // totalIdMap.put("returnReason", map.get("returnReason")); //退货原因 仅退货有用
  329. // totalIdMap.put("orderId", map.get("orderId")); //添加新订单ID
  330. // tmstruckReturnResultService.addReturnGoodsResult(totalIdMap);
  331. // result++;
  332. // }
  333. }
  334. return result;
  335. }
  336. }