zy-asrs-common/src/main/java/com/zy/asrs/common/wms/service/CommonService.java
@@ -6,6 +6,7 @@
import com.zy.asrs.common.domain.dto.StartupDto;
import com.zy.asrs.common.domain.entity.StaDesc;
import com.zy.asrs.common.sys.service.StaDescService;
import com.zy.asrs.common.utils.Utils;
import com.zy.asrs.common.utils.VersionUtils;
import com.zy.asrs.common.wms.entity.*;
import com.zy.asrs.framework.common.Cools;
@@ -15,6 +16,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
@@ -41,6 +43,10 @@
    private LocDetlService locDetlService;
    @Autowired
    private LocRuleService locRuleService;
    @Autowired
    private LocDirectionService locDirectionService;
    private Long WHS_TYPE = 0L;//默认立库
    /**
     * 生成工作号
@@ -87,6 +93,11 @@
     */
    @Transactional
    public StartupDto getLocNo(Integer staDescId, Integer sourceStaNo, List<String> matnrs, String batch, Long hostId, LocTypeDto locTypeDto, int times) {
        if (sourceStaNo==999){//平库内置判断站点(临时解决方案)
            WHS_TYPE = 1L;//平库
        } else {
            WHS_TYPE = 0L;//立库
        }
        // 目标库位
        LocMast locMast = null;
@@ -146,7 +157,7 @@
                continue;
            }
            List<LocMast> locMasts = locMastService.queryFreeLocMast2(locTypeDto.getLocType1(), locRule.getRowBeg(), locRule.getRowEnd(), locRule.getBayBeg(), locRule.getBayEnd(), locRule.getLevBeg(), locRule.getLevEnd(), hostId);
            List<LocMast> locMasts = locMastService.queryFreeLocMast2(locTypeDto.getLocType1(), locRule.getRowBeg(), locRule.getRowEnd(), locRule.getBayBeg(), locRule.getBayEnd(), locRule.getLevBeg(), locRule.getLevEnd(), hostId,WHS_TYPE);
            for (LocMast locMast0 : locMasts) {
                //预留空库位
                if (locMastService.checkEmptyCount(locMast0, 10, hostId)) {
@@ -228,12 +239,20 @@
                throw new CoolException("入库路径不存在");
            }
            //找相同空托盘
            LambdaQueryWrapper<LocMast> wrapper0 = new LambdaQueryWrapper<LocMast>()
                    .eq(LocMast::getLocSts, "D")
                    .eq(LocMast::getLocType1, locTypeDto.getLocType1())
                    .eq(LocMast::getCrnNo, staDesc.getDeviceNo())
                    .eq(LocMast::getWhsType, WHS_TYPE)
                    .eq(LocMast::getHostId, hostId);
            LambdaQueryWrapper<LocMast> wrapper1 = new LambdaQueryWrapper<LocMast>()
                    .eq(LocMast::getLocSts, "O")
                    .eq(LocMast::getLocType1, 1)
                    .eq(LocMast::getLocType1, locTypeDto.getLocType1())
                    .eq(LocMast::getCrnNo, staDesc.getDeviceNo())
                    .eq(LocMast::getHostId, hostId)
                    .orderByAsc(LocMast::getLev1, LocMast::getBay1, LocMast::getRow1);
                    .eq(LocMast::getWhsType, WHS_TYPE)
                    .eq(LocMast::getHostId, hostId);
            //库位搜索范围
            LocRangeDto locRangeDto = locTypeDto.getLocRangeDto();
@@ -246,13 +265,26 @@
                wrapper1.le(LocMast::getLev1, locRangeDto.getTargetLev());
            }
            List<LocMast> locMasts = locMastService.list(wrapper1);
            if (!locMasts.isEmpty()) {
                for (LocMast loc : locMasts) {
            List<LocMast> locMasts0 = locMastService.list(wrapper0);
            if (!locMasts0.isEmpty()) {
                for (LocMast loc : locMasts0) {
                    LocMast locMast0 = locMastService.findNearloc(loc.getLocNo(), hostId, locRangeDto);
                    if (null != locMast0) {
                        locMast = locMast0;
                        break;
                    }
                }
            }
            if (locMast == null) {
                List<LocMast> locMasts = locMastService.list(wrapper1);
                if (!locMasts.isEmpty()) {
                    for (LocMast loc : locMasts) {
                        LocMast locMast0 = locMastService.findNearloc(loc.getLocNo(), hostId, locRangeDto);
                        if (null != locMast0) {
                            locMast = locMast0;
                            break;
                        }
                    }
                }
            }
@@ -277,9 +309,26 @@
            throw new CoolException("入库路径不存在");
        }
        RowLastno rowLastno = rowLastnoService.getOne(new LambdaQueryWrapper<RowLastno>().eq(RowLastno::getWhsType, 1).eq(RowLastno::getHostId, hostId));
        if (Cools.isEmpty(rowLastno)) {
            throw new CoolException("1数据异常,请联系管理员");
        }
        int curRow = rowLastno.getCurrentRow();
        int sRow = rowLastno.getStartRow();
        int eRow = rowLastno.getTargetRow();
        LambdaQueryWrapper<LocMast> wrapper1 = new LambdaQueryWrapper<LocMast>()
                .eq(LocMast::getLocSts, "O")
                .eq(LocMast::getHostId, hostId);
                .eq(LocMast::getHostId, hostId)
                .eq(LocMast::getLocType1, locTypeDto.getLocType1())
                .le(LocMast::getRow1, eRow)
                .ge(LocMast::getRow1, sRow)
//                .in(LocMast::getRow1, curRow)
                .orderByAsc(LocMast::getLev1)
                .orderByAsc(LocMast::getBay1);
        //库位搜索范围
        LocRangeDto locRangeDto = locTypeDto.getLocRangeDto();
        if (locRangeDto != null) {
@@ -292,11 +341,41 @@
        }
        List<LocMast> locMasts = locMastService.list(wrapper1);//搜索货物
        for (LocMast mast : locMasts) {
            if (VersionUtils.checkLocType(mast, locTypeDto)) {
                locMast = mast;
            LocMast innerLoc = null;
            for (String loc : Utils.getGroupLoc(mast.getLocNo(), hostId)) {
                //1 2
                LocMast one = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, loc).eq(LocMast::getHostId, hostId));
                if (!one.getLocSts().equals("O")) {
//                    innerLoc = null;
                    continue;
                }
                innerLoc = one;
//                if (innerLoc == null) {
//                    List<Integer> innerDeepRow = locDirectionService.getInnerDeepRow(hostId);
////                    if (innerDeepRow.contains(one.getRow1())) {
//                    innerLoc = one;
////                    }
//                }
            }
            if(innerLoc == null) {
                continue;
            }
            if (VersionUtils.checkLocType(innerLoc, locTypeDto)) {
                locMast = innerLoc;
                break;
            }
        }
        curRow++;
        if (curRow > eRow) {
            curRow = sRow;
        }
        rowLastno.setCurrentRow(curRow);
        rowLastnoService.updateById(rowLastno);
        return locMast;
    }
@@ -326,6 +405,7 @@
        startupDto.setSourceStaNo(sourceStaNo);
        startupDto.setStaNo(staNo.getDevNo());
        startupDto.setLocNo(locMast.getLocNo());
        startupDto.setCrnNo(locMast.getCrnNo());
        return startupDto;
    }
}