package com.zy.common.service;
|
|
import com.alibaba.fastjson.JSON;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.core.common.Cools;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.*;
|
import com.zy.asrs.service.*;
|
import com.zy.asrs.utils.Utils;
|
import com.zy.asrs.utils.VersionUtils;
|
import com.zy.common.model.LocTypeDto;
|
import com.zy.common.model.StartupDto;
|
import com.zy.common.properties.SlaveProperties;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 货架核心功能
|
* Created by vincent on 2020/6/11
|
*/
|
@Slf4j
|
@Service
|
public class CommonService {
|
|
public static final List<Integer> FIRST_GROUP_ROW_LIST = new ArrayList<Integer>() {{
|
add(1);
|
}};
|
public static final List<Integer> SECOND_GROUP_ROW_LIST = new ArrayList<Integer>() {{
|
add(3);add(4);
|
}};
|
public static final List<Integer> THIRD_GROUP_ROW_LIST = new ArrayList<Integer>() {{
|
add(6);add(7);
|
}};
|
public static final List<Integer> FOURTH_GROUP_ROW_LIST = new ArrayList<Integer>() {{
|
add(8);
|
}};
|
public static final List<Integer> FIFTH_GROUP_ROW_LIST = new ArrayList<Integer>() {{
|
add(10);add(11);
|
}};
|
public static final List<Integer> SIXTH_GROUP_ROW_LIST = new ArrayList<Integer>() {{
|
add(13);add(14);add(15);add(16);
|
}};
|
public static final List<Integer> SEVENTH_GROUP_ROW_LIST = new ArrayList<Integer>() {{
|
add(13);add(14);
|
}};
|
public static final List<Integer> EIGHTH_GROUP_ROW_LIST = new ArrayList<Integer>() {{
|
add(16);
|
}};
|
|
|
@Autowired
|
private WrkMastService wrkMastService;
|
@Autowired
|
private WrkLastnoService wrkLastnoService;
|
@Autowired
|
private RowLastnoService rowLastnoService;
|
@Autowired
|
private BasCrnpService basCrnpService;
|
@Autowired
|
private StaDescService staDescService;
|
@Autowired
|
private BasDevpService basDevpService;
|
@Autowired
|
private LocMastService locMastService;
|
@Autowired
|
private LocDetlService locDetlService;
|
@Autowired
|
private SlaveProperties slaveProperties;
|
@Autowired
|
private LocRuleService locRuleService;
|
|
/**
|
* 生成工作号
|
* @param wrkMk 0:入出库 ; 1:其他
|
* @return workNo(工作号)
|
*/
|
public int getWorkNo(Integer wrkMk) {
|
WrkLastno wrkLastno = wrkLastnoService.selectById(wrkMk);
|
if (Cools.isEmpty(wrkLastno)) {
|
throw new CoolException("数据异常,请联系管理员");
|
}
|
int workNo = 0;
|
// 入出库类型
|
workNo = wrkLastno.getWrkNo();
|
int sNo = wrkLastno.getSNo();
|
int eNo = wrkLastno.getENo();
|
|
workNo = workNo>=eNo ? sNo : workNo+1;
|
|
while (true) {
|
WrkMast wrkMast = wrkMastService.selectById(workNo);
|
if (null != wrkMast) {
|
workNo = workNo>=eNo ? sNo : workNo+1;
|
} else {
|
break;
|
}
|
}
|
if (workNo > 0){
|
wrkLastno.setWrkNo(workNo);
|
wrkLastnoService.updateById(wrkLastno);
|
}
|
if (workNo == 0) {
|
throw new CoolException("生成工作号失败,请联系管理员");
|
} else {
|
if (wrkMastService.selectById(workNo)!=null) {
|
throw new CoolException("生成工作号" + workNo + "在工作档中已存在");
|
}
|
}
|
return workNo;
|
}
|
|
public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos, LocTypeDto locTypeDto, int times) {
|
return getLocNo(staDescId, sourceStaNo, matNos, locTypeDto, times);
|
}
|
|
/**
|
* 检索库位号
|
*
|
* @param staDescId 路径ID
|
* @param sourceStaNo 源站
|
* @param matNos 物料号集合
|
* @return locNo 检索到的库位号
|
*/
|
public StartupDto getLocNo(Integer staDescId, Integer sourceStaNo, List<String> matNos, LocTypeDto locTypeDto, int times) {
|
// 目标库位
|
LocMast locMast = null;
|
|
// 靠近摆放规则 --- 空托
|
locMast = getLocNoStep4(staDescId, locTypeDto);
|
if (locMast != null) {
|
//找到库位,返回dto
|
return getLocNoStep6(staDescId, sourceStaNo, locMast);//返回dto
|
}
|
|
//库位规则
|
locMast = getLocNoStepRule(matNos, locTypeDto);
|
if (locMast != null) {
|
//找到库位,返回dto
|
return getLocNoStep6(staDescId, sourceStaNo, locMast);//返回dto
|
}
|
|
// 靠近摆放规则 --- 相同订单号, 同天同规格物料
|
locMast = getLocNoStep3(staDescId, matNos, locTypeDto);
|
if (locMast != null) {
|
//找到库位,返回dto
|
return getLocNoStep6(staDescId, sourceStaNo, locMast);//返回dto
|
}
|
|
//搜索单品
|
locMast = getLocNoStepSingle(matNos, locTypeDto);
|
if (locMast != null) {
|
//找到库位,返回dto
|
return getLocNoStep6(staDescId, sourceStaNo, locMast);//返回dto
|
}
|
|
//搜索混放
|
locMast = getLocNoStepMixed(matNos, locTypeDto, times);
|
if (locMast != null) {
|
//找到库位,返回dto
|
return getLocNoStep6(staDescId, sourceStaNo, locMast);//返回dto
|
}
|
|
//找不到库位,抛出异常
|
throw new CoolException("没有空库位");
|
}
|
|
/**
|
* 库位规则
|
*/
|
private LocMast getLocNoStepRule(List<String> matNos, LocTypeDto locTypeDto) {
|
LocMast locMast = null;
|
|
//库位规则只能在单品货物中生效
|
if (matNos.size() == 1) {
|
// 库区锁定
|
List<LocRule> locRules = locRuleService.find(Cools.isEmpty(matNos) ? null : matNos.get(0));
|
if (locRules == null || locRules.isEmpty()) {
|
return null;//没有库位规则,跳出当前任务
|
}
|
|
for (LocRule locRule : locRules) {
|
if (locRule == null) {
|
continue;
|
}
|
|
List<LocMast> locMasts = locMastService.queryFreeLocMast2(locTypeDto.getLocType1(), locRule.getRowBeg(), locRule.getRowEnd(), locRule.getBayBeg(), locRule.getBayEnd(), locRule.getLevBeg(), locRule.getLevEnd());
|
for (LocMast locMast0 : locMasts) {
|
//预留空库位
|
if (locMastService.checkEmptyCount(locMast0, 10)) {
|
return locMast0;
|
}
|
}
|
}
|
|
if (locRules.get(0).getKeepGo() == 0) {
|
//找不到空库位,且禁止继续寻找其他非混载区域库位
|
//找不到库位,抛出异常
|
throw new CoolException("规则区域没有空库位");
|
}
|
}
|
|
return locMast;
|
}
|
|
// 靠近摆放规则 --- 相同订单号, 同天同规格物料
|
private LocMast getLocNoStep3(Integer staDescId, List<String> matNos, LocTypeDto locTypeDto) {
|
LocMast locMast = null;
|
if (!Cools.isEmpty(matNos) && matNos.size() == 1 && staDescId == 1) {
|
//先判断工作档,查找主档IOType=1, wrkSts < 10的工作明细,料号相同的明细库位
|
List<WrkMast> wrkMasts = wrkMastService.selectSameMatnrs(matNos.get(0));
|
for (WrkMast wrkMast : wrkMasts) {
|
LocMast locMast0 = locMastService.findNearloc(wrkMast.getLocNo());
|
if (null != locMast0) {
|
// 浅库位符合尺寸检测
|
if (VersionUtils.checkLocType(locMast0, locTypeDto)) {
|
locMast = locMast0;
|
}
|
}
|
}
|
if (Cools.isEmpty(locMast)) {
|
//再判断库存明细档,料号相同的明细库位
|
List<String> locNos = locDetlService.getSameDetl(matNos.get(0));
|
for (String locNo : locNos) {
|
LocMast locMast0 = locMastService.findNearloc(locNo);
|
if (null != locMast0) {
|
// 浅库位符合尺寸检测
|
if (VersionUtils.checkLocType(locMast0, locTypeDto)) {
|
locMast = locMast0;
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
return locMast;
|
}
|
|
// 靠近摆放规则 --- 空托
|
private LocMast getLocNoStep4(Integer staDescId, LocTypeDto locTypeDto) {
|
LocMast locMast = null;
|
// 靠近摆放规则 --- 空托
|
if (staDescId == 10) {
|
//先判断工作档,查找主档IOType=1, wrkSts < 10的工作明细,料号相同的明细库位
|
List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("io_type",10));
|
for (WrkMast wrkMast : wrkMasts) {
|
LocMast locMast0 = locMastService.findNearloc(wrkMast.getLocNo());
|
if (null != locMast0) {
|
// 浅库位符合尺寸检测
|
if (VersionUtils.checkLocType(locMast0, locTypeDto)) {
|
locMast = locMast0;
|
break;
|
}
|
}
|
}
|
if (Cools.isEmpty(locMast)){
|
List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
|
.eq("loc_sts", "O"));
|
if (locMasts.size() > 0) {
|
for (LocMast loc : locMasts) {
|
LocMast locMast0 = locMastService.findNearloc(loc.getLocNo());
|
if (null != locMast0) {
|
// 浅库位符合尺寸检测
|
if (VersionUtils.checkLocType(locMast0, locTypeDto)) {
|
locMast = locMast0;
|
break;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
return locMast;
|
}
|
|
// 搜索混放
|
private LocMast getLocNoStepMixed(List<String> matNos, LocTypeDto locTypeDto, int times) {
|
LocMast locMast = null;
|
|
if (matNos.size() > 1) {
|
List<LocMast> locMasts = locMastService.selectAreaEmpty(locTypeDto.getLocType1(), 1);//搜索混放库位
|
//混放区域直接取第一个即可
|
for (LocMast mast : locMasts) {
|
//预留空库位
|
if (locMastService.checkEmptyCount(mast, 10)) {
|
locMast = mast;
|
break;
|
}
|
}
|
}
|
|
// 2.库位当前所属尺寸无空库位时,调整尺寸参数,向上兼容检索库位
|
if (Cools.isEmpty(locMast)) {
|
log.error("系统没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times);
|
}
|
|
return locMast;
|
}
|
|
// 搜索单品
|
private LocMast getLocNoStepSingle(List<String> matNos, LocTypeDto locTypeDto) {
|
LocMast locMast = null;
|
// 1.先搜索单品
|
if (matNos.size() == 1) {
|
//单品
|
List<LocMast> locMasts = locMastService.selectAreaEmpty(locTypeDto.getLocType1(), 2);//搜索单品库位
|
for (LocMast mast : locMasts) {
|
List<String> groupLoc = Utils.getGroupLoc(mast.getLocNo());
|
if (!locMastService.checkAllLocEmpty(groupLoc)) {
|
continue;
|
}
|
|
LocMast tmp = null;
|
for (String loc : groupLoc) {
|
LocMast locMast1 = locMastService.selectByLoc(loc);
|
if (locMast1 == null) {
|
continue;
|
}
|
|
if (!locMast1.getLocSts().equals("O")) {
|
continue;
|
}
|
|
tmp = locMast1;
|
break;
|
}
|
|
//预留空库位
|
if (tmp != null && locMastService.checkEmptyCount(mast, 10)) {
|
locMast = tmp;
|
break;
|
}
|
}
|
}
|
|
return locMast;
|
}
|
|
//返回dto
|
private StartupDto getLocNoStep6(Integer staDescId, Integer sourceStaNo, LocMast locMast) {
|
StartupDto startupDto = new StartupDto();
|
String locNo = locMast.getLocNo();
|
// 获取目标站
|
Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
|
.eq("type_no", staDescId)
|
.eq("stn_no", sourceStaNo)
|
.eq("crn_no",Utils.stnNoToLiftNo(sourceStaNo));//借用堆垛机号字段充当提升机号
|
StaDesc staDesc = staDescService.selectOne(wrapper);
|
if (Cools.isEmpty(staDesc)) {
|
log.error("入库路径不存在, staDescId={}, sourceStaNo={}", staDescId, sourceStaNo);
|
throw new CoolException("入库路径不存在");
|
}
|
|
// 检测目标站
|
BasDevp staNo = basDevpService.selectById(staDesc.getCrnStn());
|
if (!staNo.getAutoing().equals("Y")) {
|
throw new CoolException("目标站" + staDesc.getCrnStn() + "不可用");
|
}
|
|
// 生成工作号
|
int workNo = getWorkNo(0);
|
// 返回dto
|
startupDto.setWorkNo(workNo);
|
startupDto.setSourceStaNo(sourceStaNo);
|
startupDto.setStaNo(staNo.getDevNo());
|
startupDto.setLocNo(locMast.getLocNo());
|
return startupDto;
|
}
|
|
}
|