自动化立体仓库 - WMS系统
src/main/java/com/zy/asrs/task/handler/AgvWrkMastHandler.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.AgvLocDetl;
import com.zy.asrs.entity.AgvWaitPakin;
import com.zy.asrs.entity.AgvWrkDetl;
@@ -10,37 +11,45 @@
import com.zy.asrs.service.*;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
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;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
public class AgvWrkMastHandler extends AbstractHandler<String> {
    @Value("${agvBasDev.maxWorkNum}")
    private int maxWrokNum;
    @Autowired
    AgvWrkMastService agvWrkMastService;
    private AgvWrkMastService agvWrkMastService;
    @Autowired
    AgvLocMastService agvLocMastService;
    private AgvLocMastService agvLocMastService;
    @Autowired
    AgvLocDetlService agvLocDetlService;
    private AgvLocDetlService agvLocDetlService;
    @Autowired
    AgvWrkMastLogService agvWrkMastLogService;
    private AgvWrkMastLogService agvWrkMastLogService;
    @Autowired
    AgvWrkDetlService agvWrkDetlService;
    private AgvWrkDetlService agvWrkDetlService;
    @Autowired
    AgvWrkDetlLogService agvWrkDetlLogService;
    private AgvWrkDetlLogService agvWrkDetlLogService;
    @Autowired
    AgvWaitPakinService agvWaitPakinService;
    private AgvWaitPakinService agvWaitPakinService;
    @Autowired
    AgvWaitPakinLogService agvWaitPakinLogService;
    private AgvWaitPakinLogService agvWaitPakinLogService;
    @Autowired
    OrderService orderService;
    private OrderService orderService;
    @Autowired
    private AgvBasDevpService agvBasDevpService;
    @Transactional
    public ReturnT<String> completedPutWayWrk(AgvWrkMast agvWrkMast) {
@@ -53,10 +62,10 @@
        agvWrkMastService.updateById(agvWrkMast);
        if(agvWrkMast.getIoType() == 10){
            // 空板入库 设置库位状态为D.空桶/空栈板
            agvLocMastService.updateLocStsByLocNo(agvWrkMast.getLocNo(),"D");
            agvLocMastService.updateLocStsByLocNo(agvWrkMast.getLocNo(),"D",agvWrkMast.getBarcode());
        }else{
            //修改目标库位状态为F.在库
            agvLocMastService.updateLocStsByLocNo(agvWrkMast.getLocNo(),"F");
            agvLocMastService.updateLocStsByLocNo(agvWrkMast.getLocNo(),"F",agvWrkMast.getBarcode());
        }
        //生成AGV工作历史档
        agvWrkMastLogService.save(agvWrkMast);
@@ -78,8 +87,14 @@
            //更新库存明细
            agvLocDetlService.updateStock(agvWrkMast.getSourceLocNo(),agvWrkMast.getLocNo());
            //修改源库位状态为O
            agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(),"O");
            agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(),"O","");
        }
        //删除AGV工作档
        agvWrkMastService.deleteById(wrkNo);
        //删除AGV工作明细档
        agvWrkDetlService.delete(new EntityWrapper<AgvWrkDetl>().eq("wrk_no",wrkNo));
        if(!isJSON(orderNo)){
            //检查订单是否已完成
            orderService.checkComplete(orderNo);
@@ -90,11 +105,6 @@
                orderService.checkComplete(o);
            });
        }
        //删除AGV工作档
        agvWrkMastService.deleteById(wrkNo);
        //删除AGV工作明细档
        agvWrkDetlService.delete(new EntityWrapper<AgvWrkDetl>().eq("wrk_no",wrkNo));
        return SUCCESS;
    }
@@ -108,7 +118,7 @@
        agvWrkMast.setWrkSts(207L);
        agvWrkMastService.updateById(agvWrkMast);
        //修改源库位状态为O
        agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(),"O");
        agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(),"O","");
        if(agvWrkMast.getIoType() == 101){
            //更新目标库位明细 101.出库 删除源库位库存明细
            agvLocDetlService.delete(new EntityWrapper<AgvLocDetl>().eq("loc_no",agvWrkMast.getSourceLocNo()));
@@ -138,12 +148,25 @@
    @Transactional
    public ReturnT<String> startPutWayWrk(List<AgvWrkMast> agvWrkMastList) throws IOException {
        int startWwrkCode = agvWrkMastService.startWrk(agvWrkMastList,"putaway");
        //下发任务
        int startWrkCode = agvWrkMastService.startWrk(agvWrkMastList,"putaway");
        if(startWrkCode != 0){
            throw new CoolException("任务下发失败");
        }
        int code = agvWrkMastService.containerMove(agvWrkMastList);
        //下发容器入场指令 (缓存货架)
        int code = agvWrkMastService.containerMoveIn(agvWrkMastList);
        if(code == 0){
            agvWrkMastList.forEach(agvWrkMast -> {
            for(AgvWrkMast agvWrkMast : agvWrkMastList){
                //下发容器达到通知 (输送线)
                if("Y".equals(agvWrkMast.getMk())){
                    int containerArrivedCode = agvWrkMastService.containerArrived(agvWrkMast);
                    if(containerArrivedCode != 0){
                        log.error("容器到达指令下发失败");
                        continue;
                    }
                }
                //202.RCS取货中
                agvWrkMast.setWrkSts(202L);
                agvWrkMastService.updateById(agvWrkMast);
@@ -151,7 +174,27 @@
                    //修改AGV入库通知档状态入出状态为Y
                    agvWaitPakinService.updateIoStatus(agvWrkMast.getWrkNo(),"Y");
                }
            }
            return SUCCESS;
        }
        return FAIL;
    }
    @Transactional
    public ReturnT<String> startCarryWrk(List<AgvWrkMast> agvWrkMastList) throws IOException {
        //log.info(agvWrkMastList.toString());
        //任务过滤,过滤掉已存在相同目标库位的工作档
        //agvWrkMastList = filter(agvWrkMastList);
        int code = agvWrkMastService.startWrk(agvWrkMastList,"carry");
        //log.info(agvWrkMastList.toString());
        if (Cools.isEmpty(agvWrkMastList)){
            return SUCCESS;
        }
        if(code == 0){
            agvWrkMastList.forEach(agvWrkMast -> {
                //202.RCS取货中
                agvWrkMast.setWrkSts(202L);
                agvWrkMastService.updateById(agvWrkMast);
            });
            //agvWrkMastService.updateBatchById(agvWrkMastList);
@@ -161,21 +204,23 @@
        return FAIL;
    }
    @Synchronized
    @Transactional
    public ReturnT<String> startCarryWrk(List<AgvWrkMast> agvWrkMastList) throws IOException {
        int code = agvWrkMastService.startWrk(agvWrkMastList,"carry");
        if(code == 0){
            agvWrkMastList.forEach(agvWrkMast -> {
                //202.RCS取货中
                agvWrkMast.setWrkSts(202L);
    public ReturnT<String> dealWatiWrk(List<AgvWrkMast> agvWrkMastList) throws IOException {
        agvWrkMastList.forEach(agvWrkMast -> {
            //查询该站点所有暂存位在工作档中出现的次数
            List<Map<String, Object>> devNoMaps = agvBasDevpService.selectDevNoAndNumBystationCode(agvWrkMast.getLocNo());
            //取第一个暂存位,并查询其次数与配置的次数做比较
            Map<String, Object> devNoMap = devNoMaps.get(0);
            if((int)devNoMap.get("num") < maxWrokNum){
                agvWrkMast.setLocNo(devNoMap.get("dev_no").toString());
                agvWrkMastService.updateById(agvWrkMast);
            });
            //agvWrkMastService.updateBatchById(agvWrkMastList);
                log.info("after:" + devNoMap.toString()  +  ", wrkNo:" + agvWrkMast.getWrkNo() + ", locNo: " + agvWrkMast.getLocNo());
            }
        });
            return SUCCESS;
        }
        return FAIL;
        return SUCCESS;
    }
    private String getOrderNoByWrkNo(int wrkNo){
@@ -200,4 +245,17 @@
            }
        }
    }
    private List<AgvWrkMast> filter(List<AgvWrkMast> agvWrkMastList){
        return agvWrkMastList.stream().filter(agvWrkMast -> {
            AgvWrkMast agvWrkMastWroking = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("source_loc_no", agvWrkMast.getLocNo()));
            if(!Cools.isEmpty(agvWrkMastWroking) && agvWrkMastWroking.getWrkSts()<=202){
                System.out.println("source_loc_no > 1");
                return false;
            }
            log.info(agvWrkMast.toString());
            int num = agvWrkMastService.selectCount(new EntityWrapper<AgvWrkMast>().eq("loc_no", agvWrkMast.getLocNo()));
            return num <= maxWrokNum;
        }).collect(Collectors.toList());
    }
}