zwl
2025-07-05 9b6a50bf1288d2f7f06a67bec0c902d1256e44fe
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,10 +157,10 @@
                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)) {
                if (locMastService.checkEmptyCount(locMast0, 5, hostId)) {
                    return locMast0;
                }
            }
@@ -233,12 +244,14 @@
                    .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, locTypeDto.getLocType1())
                    .eq(LocMast::getCrnNo, staDesc.getDeviceNo())
                    .eq(LocMast::getWhsType, WHS_TYPE)
                    .eq(LocMast::getHostId, hostId);
            //库位搜索范围
@@ -296,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) {
@@ -311,11 +341,63 @@
        }
        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;
                }
                if(Utils.getRow(one.getLocNo())==2){
                    LocMast locMast1=locMastService.getOne(new LambdaQueryWrapper<LocMast>()
                            .eq(LocMast::getRow1, 1)
                            .eq(LocMast::getBay1,one.getBay1())
                            .eq(LocMast::getLev1,one.getLev1())
                            .eq(LocMast::getHostId, hostId));
                    if(!locMast1.getLocSts().equals("F")){
                        continue;
                    }else if (locMast1.getLocSts().equals("O")){
                        one=locMast1;
                    }
                }else if(Utils.getRow(one.getLocNo())==3){
                    LocMast locMast1=locMastService.getOne(new LambdaQueryWrapper<LocMast>()
                            .eq(LocMast::getRow1, 4)
                            .eq(LocMast::getBay1,one.getBay1())
                            .eq(LocMast::getLev1,one.getLev1())
                            .eq(LocMast::getHostId, hostId));
                    if(!locMast1.getLocSts().equals("F")){
                        continue;
                    }else if (locMast1.getLocSts().equals("O")){
                        one=locMast1;
                    }
                }
                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;
    }