TmstruckTotalResultServiceImpl.java 16 KB

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