123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- package com.steerinfo.dil.service.impl;
- import com.steerinfo.dil.feign.OmsFeign;
- import com.steerinfo.dil.feign.QmsFeign;
- import com.steerinfo.dil.mapper.*;
- import com.steerinfo.dil.model.*;
- import com.steerinfo.dil.service.ITmstruckTotalResultService;
- import com.steerinfo.dil.util.DataChange;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.util.*;
- /**
- * @ author :TXF
- * @ time :2021/10/27 10:18
- */
- @Service(value = "tmstruckTotalResultService")
- public class TmstruckTotalResultServiceImpl implements ITmstruckTotalResultService {
- @Autowired
- private TmstruckTotalResultMapper tmstruckTotalResultMapper;
- @Autowired
- private OmsFeign omsFeign;
- @Autowired
- TmstruckEnfactoryResultMapper tmstruckEnfactoryResultMapper;
- @Autowired
- TmstruckWeightResultMapper tmstruckWeightResultMapper;
- @Autowired
- TmstruckLoadResultMapper tmstruckLoadResultMapper;
- @Autowired
- TmstruckUnloadResultMapper tmstruckUnloadResultMapper;
- @Autowired
- TmstruckLeaveFactoryResultMapper tmstruckLeaveFactoryResultMapper;
- @Autowired
- TmstruckEnfactoryResultServiceImpl tmstruckEnfactoryResultService;
- @Autowired
- TmstruckLoadResultServiceImpl tmstruckLoadResultService;
- @Autowired
- TmstruckUnloadResultServiceImpl tmstruckUnloadResultService;
- @Autowired
- TmstruckWeightResultServiceImpl tmstruckWeightResultService;
- @Autowired
- TmstruckLeaveFactoryResultServiceImpl tmstruckLeaveFactoryResultService;
- @Autowired
- TmstruckReturnResultServiceImpl tmstruckReturnResultService;
- /**
- * 新增实绩总表
- * 运输订单ID
- * @param orderId
- * @return
- */
- public int addTotalResult(BigDecimal orderId){
- TmstruckTotalResult tmstruckTotalResult = new TmstruckTotalResult();
- BigDecimal maxId = tmstruckTotalResultMapper.selectMaxId();
- tmstruckTotalResult.setResultTotalId(maxId);
- tmstruckTotalResult.setOrderId(orderId);
- tmstruckTotalResult.setInsertTime(new Date());
- tmstruckTotalResult.setInsertUsername("admin");
- tmstruckTotalResultMapper.insertSelective(tmstruckTotalResult);
- return maxId.intValue();
- }
- public int copyAllResult(BigDecimal orderId,BigDecimal orderIdOld,BigDecimal resultTotalIdOld){
- //总实绩
- TmstruckTotalResult tmstruckTotalResult = new TmstruckTotalResult();
- BigDecimal maxId = tmstruckTotalResultMapper.selectMaxId();
- tmstruckTotalResult.setResultTotalId(maxId);
- tmstruckTotalResult.setOrderId(orderId);
- tmstruckTotalResult.setInsertTime(new Date());
- tmstruckTotalResult.setInsertUsername("admin");
- tmstruckTotalResultMapper.insertSelective(tmstruckTotalResult);
- //处理旧实绩
- Map<String,Object> serachMap=new HashMap<>();
- serachMap.put("resultTotalId",resultTotalIdOld);
- List<TmstruckEnfactoryResult> enOlds = tmstruckEnfactoryResultMapper.selectByParameters(serachMap);
- if( enOlds !=null && enOlds.size()>0){
- //已经进厂则迁移旧的实绩
- //接单,生成所有路段实绩
- Map<String,Object> map=new HashMap<>();
- map.put("orderId",orderId);
- map.put("orderReceiveStatus",1);
- map.put("capacityNumber","capacityNumber");
- omsFeign.driverReceiveOrRefuse(map);
- //进厂
- serachMap.put("resultTotalId",maxId);
- TmstruckEnfactoryResult tmstruckEnfactoryResult=tmstruckEnfactoryResultMapper.selectByParameters(serachMap).get(0);
- TmstruckEnfactoryResult tmstruckEnfactoryResult1=enOlds.get(0);
- tmstruckEnfactoryResult1.setResultId(tmstruckEnfactoryResult.getResultId());
- tmstruckEnfactoryResult1.setResultTotalId(tmstruckEnfactoryResult.getResultTotalId());
- tmstruckEnfactoryResultMapper.updateByPrimaryKeySelective(tmstruckEnfactoryResult1);
- //计皮
- serachMap.put("resultTotalId",maxId);
- TmstruckWeightResult tmstruckWeightResult=tmstruckWeightResultMapper.selectByTotalId(serachMap).get(0);
- serachMap.put("switch","1");
- serachMap.put("resultTotalId",resultTotalIdOld);
- List<TmstruckWeightResult> olds = tmstruckWeightResultMapper.selectByTotalId(serachMap);
- if(olds!=null && olds.size()>0){
- TmstruckWeightResult tmstruckWeightResult1=olds.get(0);
- tmstruckWeightResult.setResultTareWeightTime(tmstruckWeightResult1.getResultTareWeightTime());
- tmstruckWeightResult.setResultTareWeight(tmstruckWeightResult1.getResultTareWeight());
- tmstruckWeightResult.setResultTarePlaceId(tmstruckWeightResult1.getResultTarePlaceId());
- tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
- Map<String,Object> orderMap=new HashMap<>();
- orderMap.put("orderId",orderId);
- orderMap.put("seq",2);
- tmstruckWeightResultMapper.updateOmstruckStatus(orderMap);
- }else{
- Map<String,Object> orderMap=new HashMap<>();
- orderMap.put("orderId",orderId);
- orderMap.put("seq",0);
- tmstruckWeightResultMapper.updateOmstruckStatus(orderMap);
- }
- //迁移排队实绩
- serachMap.put("resultTotalId",maxId);
- serachMap.put("resultTotalIdOld",resultTotalIdOld);
- tmstruckWeightResultMapper.copyQmsResult(serachMap);
- }else{
- //未进厂,状态为待接收
- Map<String,Object> orderMap=new HashMap<>();
- orderMap.put("orderId",orderId);
- orderMap.put("orderStatus",4);
- tmstruckWeightResultMapper.updateOrderStatus(orderMap);
- }
- return maxId.intValue();
- }
- /**
- * 展示计数实绩列表
- * @param map
- * @return
- */
- @Override
- public List<Map<String, Object>> selectCountList(Map<String, Object> map) {
- return tmstruckTotalResultMapper.selectCountList(map);
- }
- /**
- * 展示包月实绩列表
- * @param mapValue
- * @return
- */
- public List<Map<String, Object>> getTmstruckMonthResult(Map<String, Object> mapValue) {
- return tmstruckTotalResultMapper.getTmstruckMonthResult(mapValue);
- }
- /**
- * 展示倒库作业报表
- * @param mapValue
- * @return
- */
- @Override
- public List<Map<String, Object>> getAllReverseResult(Map<String, Object> mapValue) {
- return tmstruckTotalResultMapper.getAllReverseResult(mapValue);
- }
- /**
- * 为已接收没有总实绩的运输订单补录总实绩
- */
- @Scheduled(fixedRate = 1000*60*5)
- public void insertTotalForNullOrder(){
- List<BigDecimal> list=tmstruckTotalResultMapper.getOrderForBulu();
- for(BigDecimal orderId:list){
- addTotalResult(orderId);
- }
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public int changeOrderLine(Map<String, Object> mapValue) throws Exception {
- //查询订单详情
- Map<String,Object> mesMap=tmstruckTotalResultMapper.getLineId(mapValue);
- if(mesMap==null){
- throw new Exception("订单状态异常,无法变更!");
- }
- //更新线路Id
- if(mapValue.get("lineId")==null){
- throw new Exception("请选择线路!");
- }else if(DataChange.dataToBigDecimal(mesMap.get("lineId")).compareTo(DataChange.dataToBigDecimal(mapValue.get("lineId")))==0){
- throw new Exception("线路一致,无需更新!");
- }else{
- tmstruckTotalResultMapper.updateLineId(mapValue);
- }
- //校验订单,如果未接单就直接结束,已接单则继续修改实绩
- if(DataChange.dataToBigDecimal(mesMap.get("orderStatus")).compareTo(new BigDecimal(4))==0){
- return 1;
- }
- //查询并记录有效实绩,进厂,计量,装货,卸货,出厂
- mesMap.put("flag","1");//只查询有效实绩
- List<TmstruckEnfactoryResult> enfactoryResults= tmstruckTotalResultMapper.selectAllEnfactory(mesMap);
- List<TmstruckWeightResult> tmstruckWeightResults= tmstruckTotalResultMapper.selectAllWeight(mesMap);
- List<TmstruckUnloadResult> unloadResults=tmstruckTotalResultMapper.selectAllUnload(mesMap);
- List<TmstruckLeaveFactoryResult> leaveFactoryResults=tmstruckTotalResultMapper.selectAllLeavefactory(mesMap);
- System.out.println(enfactoryResults);
- System.out.println(tmstruckWeightResults);
- System.out.println(unloadResults);
- System.out.println(leaveFactoryResults);
- //删除所有旧线路实绩
- tmstruckTotalResultMapper.deleteEnByEnTotal(mesMap);
- tmstruckTotalResultMapper.deleteWeightByEnTotal(mesMap);
- tmstruckTotalResultMapper.deleteUnloadByEnTotal(mesMap);
- tmstruckTotalResultMapper.deleteLeaveByEnTotal(mesMap);
- //新增所有新线路实绩
- mesMap.put("lineId",mapValue.get("lineId"));
- addAllSonResult(mesMap);
- //查询并记录所有新实绩
- System.out.println("-------------------------------------");
- mesMap.put("flag","0");//打开查询所有
- List<TmstruckEnfactoryResult> enfactoryResultsNew= tmstruckTotalResultMapper.selectAllEnfactory(mesMap);
- List<TmstruckWeightResult> tmstruckWeightResultsNew= tmstruckTotalResultMapper.selectAllWeight(mesMap);
- //List<TmstruckUnloadResult> unloadResultsNew=tmstruckTotalResultMapper.selectAllUnload(mesMap);//卸货和出厂不处理
- //List<TmstruckLeaveFactoryResult> leaveFactoryResultsNew=tmstruckTotalResultMapper.selectAllLeavefactory(mesMap);
- System.out.println(enfactoryResultsNew);
- System.out.println(tmstruckWeightResultsNew);
- //System.out.println(unloadResultsNew);
- //System.out.println(leaveFactoryResultsNew);
- //更新订单信息,按顺序更新
- for(int i=0;i<enfactoryResults.size();i++){
- //进厂实绩
- try{
- TmstruckEnfactoryResult oldResult=enfactoryResults.get(i);
- TmstruckEnfactoryResult newResult=enfactoryResultsNew.get(i);
- if(oldResult!=null && newResult!=null){
- newResult.setGatepostId(oldResult.getGatepostId());
- newResult.setResultEntryMode(oldResult.getResultEntryMode());
- newResult.setResultEntryGateTime(oldResult.getResultEntryGateTime());
- }
- tmstruckEnfactoryResultMapper.updateByPrimaryKeySelective(newResult);
- }catch (Exception e){
- //数组越界,不处理
- }
- }
- for(int i=0;i<tmstruckWeightResults.size();i++){
- //计量实绩
- try{
- TmstruckWeightResult oldResult=tmstruckWeightResults.get(i);
- TmstruckWeightResult newResult=tmstruckWeightResultsNew.get(i);
- if(oldResult!=null && newResult!=null){
- newResult.setResultGrossPlaceId(oldResult.getResultGrossPlaceId());
- newResult.setResultGrossWeight(oldResult.getResultGrossWeight());
- newResult.setResultGrossWeightTime(oldResult.getResultGrossWeightTime());
- newResult.setMaterialId(oldResult.getMaterialId());
- newResult.setResultPoundNo(oldResult.getResultPoundNo());
- // newResult.setResultTarePlaceId(oldResult.getResultTarePlaceId());
- // newResult.setResultTareWeight(oldResult.getResultTareWeight());
- // newResult.setResultTareWeightTime(oldResult.getResultTareWeightTime());
- }
- tmstruckWeightResultMapper.updateByPrimaryKeySelective(newResult);
- }catch (Exception e){
- //数组越界,不处理
- }
- }
- return 1;
- }
- /**
- * 通过线路子表路线图生成各实绩
- * @param map
- * @return
- */
- public int addAllSonResult(Map<String, Object> map){
- Integer resultTotalId = DataChange.dataToBigDecimal(map.get("resultTotalId")).intValue();
- Integer lineId = DataChange.dataToBigDecimal(map.get("lineId")).intValue();
- int result = 0;
- //通过总实绩Id 查询关联的线路子表顺序
- List<Map<String, Object>> segmentList = tmstruckTotalResultMapper.getLineMesByOrderId(map);
- Map<String,Object> totalIdMap = new HashMap<>();
- totalIdMap.put("resultTotalId",resultTotalId);
- totalIdMap.put("lineId", lineId);
- // 遍历路段顺序号子表
- int count = 0;
- BigDecimal lineType = (BigDecimal) segmentList.get(0).get("lineType");
- if (lineType.intValue() == 4) {
- count++;
- }
- //存放皮重路段顺序号和毛重路段顺序号map
- Map<String, Object> tareAndGrossSegmentMap = new HashMap<>();
- for (Map<String,Object> segmentMap : segmentList) {
- BigDecimal segmentSqe = (BigDecimal) segmentMap.get("segmentSqe");
- String linkName = (String) segmentMap.get("linkName");
- totalIdMap.put("segmentSqe",segmentSqe);
- // 判断是否是计毛
- if (linkName.equals("计毛")) {
- // 如果是计量则加一
- count ++;
- tareAndGrossSegmentMap.put("grossSegmentSqe", segmentSqe);
- // 有两个计量的时候则新增实绩
- if (count == 2) {
- totalIdMap.putAll(tareAndGrossSegmentMap);//将皮重顺序号和毛重路段顺序号放进去
- tmstruckWeightResultService.addWeightResult(totalIdMap);
- // 新增一次则对计数器清零
- count = 0;
- tareAndGrossSegmentMap.clear(); // 清空毛重皮重 map
- result++;
- }
- }
- // 判断是否是计皮
- if (linkName.equals("计皮")) {
- // 如果是计皮则加一
- count ++;
- tareAndGrossSegmentMap.put("tareSegmentSqe", segmentSqe);
- // 有两个计量的时候则新增实绩
- if (count == 2) {
- totalIdMap.putAll(tareAndGrossSegmentMap);
- tmstruckWeightResultService.addWeightResult(totalIdMap);
- // 新增一次则对计数器清零
- count = 0;
- tareAndGrossSegmentMap.clear(); // 清空毛重皮重 map
- result++;
- }
- }
- // 进厂
- if (linkName.equals("进厂")) {
- tmstruckEnfactoryResultService.addEnFactoryResult(totalIdMap);
- result++;
- }
- // 出厂
- if (linkName.equals("出厂")) {
- tmstruckLeaveFactoryResultService.addLeaveFactory(totalIdMap);
- result++;
- }
- // 装货
- if (linkName.equals("装货")) {
- tmstruckLoadResultService.addLoadResult(totalIdMap);
- result++;
- }
- // 卸货
- if (linkName.equals("卸货")) {
- tmstruckUnloadResultService.addUnloadResult(totalIdMap);
- result++;
- }
- // 退货
- // if (linkName.equals("退货")) {
- // totalIdMap.put("returnReason", map.get("returnReason")); //退货原因 仅退货有用
- // totalIdMap.put("orderId", map.get("orderId")); //添加新订单ID
- // tmstruckReturnResultService.addReturnGoodsResult(totalIdMap);
- // result++;
- // }
- }
- return result;
- }
- }
|