自动化立体仓库 - WMS系统
pang.jiabao
1 天以前 259e38eb55c12b501427702d551d4de61182406c
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -7,6 +7,8 @@
import com.core.common.*;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.mes.MesOutApply;
import com.zy.asrs.entity.mes.TransTask;
import com.zy.asrs.entity.param.*;
import com.zy.asrs.enums.CommonEnum;
import com.zy.asrs.enums.LocStsType;
@@ -25,6 +27,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -41,6 +44,11 @@
@Slf4j
@Service
public class MobileServiceImpl implements MobileService {
    @Value("${wms.wmsTransStartStation2}")
    public String WMS_TRANS_START_STATION_2;
    @Value("${wms.zpalletId}")
    public String WMS_ZPALLET_ID;
    @Autowired
    private MatService matService;
@@ -114,6 +122,9 @@
    private BasStationService basStationService;
    @Autowired
    private BasContainerService basContainerService;
    @Resource
    private MesService mesService;
    @Override
    @Transactional
@@ -632,7 +643,7 @@
            param.getCombMats().forEach(elem -> {
                Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, elem.getOrderNo());
                if (Cools.isEmpty(order) || order.getSettle() > 2) {
                    throw new CoolException("单据编号已过期");
                    throw new CoolException("订单号不存在或者已执行完成");
                }
                // 订单明细数量校验
//                OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
@@ -654,6 +665,7 @@
                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme());
                detlDto.setOrderId(order.getId());
                detlDto.setOrderNo(order.getOrderNo());
                detlDto.setStandby1(detls.getStandby1());
                if (DetlDto.has(detlDtos, detlDto)) {
                    DetlDto one = DetlDto.findDto(detlDtos, detlDto);
                    assert one != null;
@@ -663,38 +675,38 @@
                }
            });
            BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode()));
            if (Objects.isNull(container)) {
                throw new CoolException("数据错误:容器码不存在!!");
            }
            if (container.getMixMax() < detlDtos.size()) {
                throw new CoolException("超出容器最大混装数量,当前容器最大数量为:" + container.getMixMax() + "!!");
            }
            Set<String> matnrs = detlDtos.stream().map(DetlDto::getMatnr).collect(Collectors.toSet());
            List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr", matnrs));
            Set<Long> tagIds = mats.stream().map(Mat::getTagId).collect(Collectors.toSet());
            if (tagIds.size() > 1) {
                throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!");
            }
//            BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode()));
//            if (Objects.isNull(container)) {
//                throw new CoolException("数据错误:容器码不存在!!");
//            }
//            if (container.getMixMax() < detlDtos.size()) {
//                throw new CoolException("超出容器最大混装数量,当前容器最大数量为:" + container.getMixMax() + "!!");
//            }
//            Set<String> matnrs = detlDtos.stream().map(DetlDto::getMatnr).collect(Collectors.toSet());
//            List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr", matnrs));
//            Set<Long> tagIds = mats.stream().map(Mat::getTagId).collect(Collectors.toSet());
//            if (tagIds.size() > 1) {
//                throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!");
//            }
            //还可以放入多少种物料
            Integer suplus = container.getMixMax();
//            Integer suplus = container.getMixMax();
            for (DetlDto detlDto : detlDtos) {
                Mat mat = matService.selectByMatnr(detlDto.getMatnr());
                if (Cools.isEmpty(mat)) {
                    throw new CoolException(detlDto.getMatnr() + "商品档案不存在");
                }
                //最多可放数量
                Double singleMax = mat.getUpQty() * suplus;
                if (singleMax.compareTo(detlDto.getAnfme()) < 0) {
                    throw new CoolException("物料:" + detlDto.getMatnr() + "单次组托上限为:" + mat.getUpQty() + ",当前总量超出托盘装载上限!!");
                }
                BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty());
                //当前物料需要占用料箱格数
                Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue();
                suplus = suplus - curr;
                if (suplus < 0) {
                    throw new CoolException("物料:" + detlDto.getMatnr() + ", 超出当前托盘装载上限!!");
                }
//                Double singleMax = mat.getUpQty() * suplus;
//                if (singleMax.compareTo(detlDto.getAnfme()) < 0) {
//                    throw new CoolException("物料:" + detlDto.getMatnr() + "单次组托上限为:" + mat.getUpQty() + ",当前总量超出托盘装载上限!!");
//                }
//                BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty());
//                //当前物料需要占用料箱格数
//                Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue();
//                suplus = suplus - curr;
//                if (suplus < 0) {
//                    throw new CoolException("物料:" + detlDto.getMatnr() + ", 超出当前托盘装载上限!!");
//                }
                WaitPakin waitPakin = new WaitPakin();
                BeanUtils.copyProperties(mat, waitPakin);
@@ -706,6 +718,7 @@
                waitPakin.setIoStatus("N");     // 入出状态
                waitPakin.setAnfme(detlDto.getAnfme());  // 数量
                waitPakin.setStatus("Y");    // 状态
                waitPakin.setStandby1(detlDto.getStandby1());
                waitPakin.setAppeUser(userId);
                waitPakin.setAppeTime(now);
                waitPakin.setModiUser(userId);
@@ -1272,6 +1285,90 @@
        return R.ok();
    }
    @Override
    @Transactional
    public R callEmptyBinOutBound(MesOutApply mesOutApply, String staNo, String locType, Long userId) {
        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_sts", 'D').eq("loc_type2", locType));
        if(locMast == null) {
            return R.parse("该类型:" + locType +"空托盘不存在");
        }
        // 获取路径
        Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                .eq("type_no", 110)
                .eq("stn_no", 204)
                .eq("crn_no", locMast.getCrnNo());
        StaDesc staDesc = staDescService.selectOne(wrapper);
        if (staDesc == null) {
            return R.parse("出库路径不存在,站点:" + staNo);
        }
        Date now = new Date();
        // 生成工作档
        int workNo = commonService.getWorkNo(WorkNoType.PAKOUT.type);
        WrkMast wrkMast = new WrkMast();
        wrkMast.setWrkNo(workNo);
        wrkMast.setIoTime(now);
        wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
        wrkMast.setIoType(110); // 入出库状态: 110.空板出库
        wrkMast.setIoPri(10D);
        wrkMast.setSourceStaNo(staDesc.getCrnStn$()); // 源站
        wrkMast.setStaNo(staDesc.getStnNo$()); // 目标站
        wrkMast.setCrnNo(staDesc.getCrnNo());
        wrkMast.setSourceLocNo(locMast.getLocNo()); // 源库位
        wrkMast.setFullPlt("N"); // 满板:Y
        wrkMast.setPicking("N"); // 拣料
        wrkMast.setExitMk("N"); // 退出
        wrkMast.setEmptyMk("Y"); // 空板
        wrkMast.setLinkMis("N");
        wrkMast.setAppeUser(userId);
        wrkMast.setAppeTime(now);
        wrkMast.setModiUser(userId);
        wrkMast.setModiTime(now);
        if (mesOutApply != null) {
            wrkMast.setTaskNo(mesOutApply.getTaskno());
            wrkMast.setAgvSta(mesOutApply.getStationId());
            wrkMast.setMemo(JSONObject.toJSONString(mesOutApply));
        } else {
            wrkMast.setAgvSta(staNo);
        }
        wrkMastService.insert(wrkMast);
        // 更新库位状态
        if (locMast.getLocSts().equals("D")) {
            locMast.setLocSts("R");
            locMast.setModiUser(userId);
            locMast.setModiTime(now);
            locMastService.updateById(locMast);
        }
        log.info("生成空托出库任务成功,任务号:{}",wrkMast.getWrkNo());
        return R.ok("出库成功");
    }
    @Override
    public R callEmptyBinInBound(String site, Long userId) {
        TransTask transTask = new TransTask();
//        transTask.setTaskno(mesInApply.getTaskno());
//        transTask.setTaskname(mesInApply.getTaskname());
//        transTask.setOrderNo(mesInApply.getOrderNo());
        transTask.setTransType("02"); // 下毛坯
//        transTask.setCurProcess(mesInApply.getProductLineId());
        transTask.setCurStationId(site);
        transTask.setNextStationId(WMS_TRANS_START_STATION_2);
        transTask.setItemno(WMS_ZPALLET_ID);  // 固定为空托的编码
        transTask.setQty(1);    // 空托只回1个
//        transTask.setProductLineId(mesInApply.getProductLineId());
        transTask.setOperateType(1);
        transTask.setAgvFactory(1);
        JSONObject sendAgvTask = mesService.submitTask(transTask);
        if ("1".equals(sendAgvTask.getString("Success"))) {
            log.info("pda呼叫料框回库成功,{}", JSONObject.toJSONString(transTask));
            return R.ok("成功");
        } else {
            log.error("pda呼叫料框回库失败,{}", JSONObject.toJSONString(transTask));
            return R.parse("失败");
        }
    }
    /**
     * @author Ryan
     * @date 2025/9/25
@@ -1374,7 +1471,7 @@
        task.setWrkNo(workNo)
                .setIoTime(new Date())
                .setWrkSts(1L) // 工作状态:11.生成出库ID
                .setIoType(11) // 入出库状态: 11.库格移载
                .setIoType(1) // 入出库状态: 11.库格移载
                .setTaskType("agv")
                .setIoPri(10D)
                .setLocNo(loc.getLocNo()) // 目标库位