package com.steerinfo.dil.service.impl; import com.steerinfo.dil.mapper.BackgroundProcessingMapper; import com.steerinfo.dil.service.IBackgroundProcessService; import com.steerinfo.dil.util.DataChange; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @Service(value = "backgroundProcessingService") public class BackgroundProcessingServiceImpl implements IBackgroundProcessService { @Autowired private BackgroundProcessingMapper backgroundProcessingMapper; /** * 更新订单所属厂区 * @param map * @return */ @Override public int updatePurOrgId(Map map) { return backgroundProcessingMapper.updatePurOrderOrgId(map); } /** * 删除重复实绩 * @param orderNumber * @return */ public int deleteErrorResult(String orderNumber) { Map orderMes = backgroundProcessingMapper.getOrderMesByOrderNum(orderNumber); int orderType = DataChange.dataToBigDecimal(orderMes.get("orderType")).intValue(); List arrayList = Arrays.asList(11, 15, 16, 21); //没有固定路线不支持此操作 if(arrayList.contains(orderType)){ return 0; } BigDecimal resultTotalId = DataChange.dataToBigDecimal(orderMes.get("resultTotalId")); List enFactoryList = backgroundProcessingMapper.enFactoryCheck(resultTotalId); if(enFactoryList != null && enFactoryList.size() != 0){ //查询出当前顺序号中所有的实绩 for (Integer sqe : enFactoryList) { List> mesList = backgroundProcessingMapper.getEnFactoryResult(resultTotalId, sqe); closeWay(mesList, 1); } } List loadList = backgroundProcessingMapper.loadCheck(resultTotalId); if(loadList != null && loadList.size() != 0){ for (Integer sqe : loadList) { List> mesList = backgroundProcessingMapper.loadResult(resultTotalId, sqe); closeWay(mesList, 2); } } List unloadList = backgroundProcessingMapper.unloadCheck(resultTotalId); if(unloadList != null && unloadList.size() != 0){ for (Integer sqe : unloadList) { List> mesList = backgroundProcessingMapper.unloadResult(resultTotalId, sqe); closeWay( mesList, 3); } } List weightList = backgroundProcessingMapper.weightCheck(resultTotalId); if(weightList != null && weightList.size() != 0){ for (Integer sqe : weightList) { List> mesList = backgroundProcessingMapper.weightResult(resultTotalId, sqe); closeWay(mesList, 4); } } List outFactoryList = backgroundProcessingMapper.outFactoryCheck(resultTotalId); if(outFactoryList != null && outFactoryList.size() != 0){ for (Integer sqe : outFactoryList) { List> mesList = backgroundProcessingMapper.outFactoryResult(resultTotalId, sqe); closeWay(mesList, 5); } } return 0; } /** * 关闭通用方法 * @param mesList 这些顺序号的实绩信息 * @param type 1:进厂 2:计量 3:装货:4:卸货 5:出厂 */ public void closeWay(List> mesList, int type){ List resultList = new ArrayList<>(); for (Map map : mesList) { //有过操作时间的不做删除 if(map.get("time") == null){ resultList.add(DataChange.dataToBigDecimal(map.get("resultId")).intValue()); //添入列表中 } } if(mesList.size() == resultList.size()){ //如果所有的实绩都为空 ,则只保留一条实绩,其余的全部删除 resultList.remove(0); } if(resultList.size() != 0){ //删除实绩数据 if(type == 1) backgroundProcessingMapper.deleteEnFactoryUnnecessaryResult(resultList); else if(type == 2) backgroundProcessingMapper.deleteLoadUnnecessaryResult(resultList); else if(type == 3) backgroundProcessingMapper.deleteUnloadUnnecessaryResult(resultList); else if(type == 4) backgroundProcessingMapper.deleteWeightUnnecessaryResult(resultList); else if(type == 5) backgroundProcessingMapper.deleteOutFactoryUnnecessaryResult(resultList); } } }