自动化立体仓库 - WMS系统
whycq
2024-05-17 1a8e7f30035b45771d05cd4cc99aae2743576112
src/main/java/com/zy/common/web/WcsController.java
@@ -8,8 +8,8 @@
import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.WrkMastMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.Utils;
import com.zy.common.CodeRes;
import com.zy.common.model.AgvBasDevpDto;
import com.zy.common.model.LocTypeDto;
import com.zy.common.model.StartupDto;
import com.zy.common.service.CommonService;
@@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
@@ -33,6 +34,8 @@
@RestController
@RequestMapping("/rpc")
public class WcsController {
    private static HashMap<String,String> currentContainerMap;
    @Autowired
    private WrkMastService wrkMastService;
@@ -62,6 +65,10 @@
    private WrkMastMapper wrkMastMapper;
    @Autowired
    private WrkMastLogService wrkMastLogService;
    @Autowired
    private AgvWrkDetlService agvWrkDetlService;
    @Autowired
    private AgvLocDetlService agvLocDetlService;
//    @Autowired
//    private ErpService erpService;
@@ -497,6 +504,12 @@
            }
        }
        //检查目标库位,库存明细是否添加成功
        List<LocDetl> checkLocDetls = locDetlService.selectByLocNo(dto.getLocNo());
        if (checkLocDetls.isEmpty()) {
            throw new CoolException("库存明细迁移失败");
        }
//        //清空源库位数据
        LocMast locMast1 = locMastService.selectByLoc(wrkMast.getSourceLocNo());
//        if (locMast1.getLocSts().equals("P")) {
@@ -577,24 +590,154 @@
        if(Cools.isEmpty(agvBasDevp) || !"O".equals(agvBasDevp.getLocSts())){
            throw new CoolException("当前站点不存在或者站点不为空");
        }
        if(Cools.isEmpty(agvWaitPakinService.selectByContainerCode(containerCode))){
            throw new CoolException("该料箱位组托");
        AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("barcode", containerCode));
        //拣料、盘点完成任务
        if(!Cools.isEmpty(agvWrkMast) && (agvWrkMast.getIoType() == 103 || agvWrkMast.getIoType() == 107) && agvWrkMast.getWrkSts() == 205){
            //绑定站点
            agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"F",containerCode,agvWrkMast.getWhsType().shortValue());
            //生成拣料、盘点再入库任务
            List<AgvWrkMast> agvWrkMastList = new ArrayList<>();
            agvWrkMast.setMk("Y");
            agvWrkMast.setLocNo(agvBasDevp.getDevNo());
            agvWrkMastList.add(agvWrkMast);
            agvWorkService.pickIn(agvWrkMastList);
            return R.ok();
        }
        //去找agv工作档任务
        if(!Cools.isEmpty(agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("barcode",containerCode)))){
            throw new CoolException("该料箱正在入库中");
        //入库任务
        if (!Cools.isEmpty(agvWaitPakinService.selectByContainerCode(containerCode))){
            //绑定站点
            agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"F",containerCode,agvWrkMast.getWhsType().shortValue());
            //生成工作档
            List<AgvBasDevp> agvBasDevpList = agvBasDevpService.selectList(new EntityWrapper<AgvBasDevp>().eq("dev_no", param.getDevNo()));
            agvWorkService.createWaitPainWrkMastStart(agvBasDevpList, null, true);
            return R.ok();
        }
        //绑定站点
        agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"F",containerCode);
        //生成工作档
        List<AgvBasDevp> agvBasDevpList = agvBasDevpService.selectList(new EntityWrapper<AgvBasDevp>().eq("dev_no", param.getDevNo()));
        agvWorkService.createWaitPainWrkMastStart(agvBasDevpList, null, true);
        return R.error("没有查询到该料箱信息");
    }
    @PostMapping("/current/containerCode")
    @ResponseBody
    public R move(@RequestBody ReplenishmentParam param){
        if(Cools.isEmpty(currentContainerMap)){
            currentContainerMap = new HashMap<>();
        }
        String containerCode = param.getContainerCode().split(";")[0];
        if(Cools.isEmpty(containerCode)){
            throw new CoolException("料箱码为空");
        }
        if(!Character.isDigit(containerCode.charAt(0))){
            containerCode = containerCode.substring(3,containerCode.length());
        }
        String devNo = param.getDevNo();
        String currentContainerCode = currentContainerMap.get(devNo);
        //判断容器是否发生变化
        if(!Cools.isEmpty(currentContainerCode) && !Cools.eq(containerCode,currentContainerCode)){
            //查询旧容器的工作档
            AgvWrkMast agvWrkMast = agvWrkMastService.selectByContainerCode(currentContainerCode);
            if(!Cools.isEmpty(agvWrkMast) && agvWrkMast.getIoType() == 101){
                //将工作党状态改为容器离场
                agvWrkMast.setWrkSts(206L);
                agvWrkMastService.updateById(agvWrkMast);
//                //发送容器立场请求,完成工作档
//                List<AgvWrkMast> agvWrkMastList = new ArrayList<>();
//                agvWrkMastList.add(agvWrkMast);
//                try {
//                    int code = agvWrkMastService.containerMoveOut(agvWrkMastList);
//                    if(code == 0){
//                        //将工作党状态改为容器离场
//                        agvWrkMast.setWrkSts(206L);
//                        agvWrkMastService.updateById(agvWrkMast);
//                    }
//                } catch (IOException e) {
//                    log.error(e.getMessage());
//                }
            }
        }
        currentContainerMap.put(devNo,containerCode);
        return R.ok();
    }
    /*
    显示AGV输送线拣料、盘点、入库信息
     */
    @PostMapping("/info")
    @ResponseBody
    public R containerMove(@RequestBody ReplenishmentParam param){
        String devNo = param.getDevNo();
        String containerCode = currentContainerMap.get(devNo);
        AgvBasDevpDto agvBasDevpDto = new AgvBasDevpDto();
        //查找该容器的工作档
        AgvWrkMast agvWrkMast = agvWrkMastService.selectByContainerCode(containerCode);
        if(!Cools.isEmpty(agvWrkMast)){
            List<AgvWrkDetl> agvWrkDetlList = agvWrkDetlService.selectList(new EntityWrapper<AgvWrkDetl>().eq("wrk_no", agvWrkMast.getWrkNo()));
            for (AgvWrkDetl agvWrkDetl : agvWrkDetlList){
                agvWrkDetl.setVolume(agvWrkDetl.getAnfme());
                if(agvWrkMast.getIoType() == 103){
                    //寻找是否有相同物料的工作档明细,并返回数量之和
                    double anfme = getAllAnfmeInAgvWrkDetlList(agvWrkDetlList,agvWrkDetl);
                    AgvLocDetl agvLocDetl = agvLocDetlService.selectByMatnrAndBatchAndCsocodeAndisoCode(agvWrkMast.getSourceLocNo(), agvWrkDetl.getMatnr(), agvWrkDetl.getBatch(), agvWrkDetl.getThreeCode(), agvWrkDetl.getDeadTime());
                    //用于结余数量显示
                    agvWrkDetl.setVolume(agvLocDetl.getAnfme() - anfme);
                }
                if(agvWrkMast.getIoType() == 53){
                    AgvLocDetl agvLocDetl = agvLocDetlService.selectByMatnrAndBatchAndCsocodeAndisoCode(agvWrkMast.getLocNo(), agvWrkDetl.getMatnr(), agvWrkDetl.getBatch(), agvWrkDetl.getThreeCode(), agvWrkDetl.getDeadTime());
                    if(Cools.isEmpty(agvLocDetl)){
                        agvWrkDetl.setVolume(0.0);
                    }else {
                        agvWrkDetl.setVolume(agvLocDetl.getAnfme());
                    }
                }
            };
            agvBasDevpDto.setAgvWrkDetls(agvWrkDetlList);
            agvBasDevpDto.setAgvWrkMast(agvWrkMast);
        }
        //查找该容器的入库通知档
        List<AgvWaitPakin> agvWaitPakinList = agvWaitPakinService.selectList(new EntityWrapper<AgvWaitPakin>().eq("supp_code", containerCode));
        if(!Cools.isEmpty(agvWaitPakinList)){
            agvBasDevpDto.setAgvWaitPakins(agvWaitPakinList);
        }
        System.out.println("currentContainerMap: " + currentContainerMap);
        System.out.println("agvBasDevpDto: " + agvBasDevpDto);
        return R.ok(agvBasDevpDto);
    }
    private double getAllAnfmeInAgvWrkDetlList(List<AgvWrkDetl> agvWrkDetlList, AgvWrkDetl wd0) {
        double allAnfme = 0;
        for (AgvWrkDetl wd1 : agvWrkDetlList){
            if(Cools.eq(wd0.getMatnr(),wd1.getMatnr())
                    && Cools.eq(wd0.getBatch(),wd1.getBatch())
                    && Cools.eq(wd0.getThreeCode(),wd1.getThreeCode())
                    && Cools.eq(wd0.getDeadTime(),wd1.getDeadTime())){
                allAnfme += wd1.getAnfme();
            }
        }
        return allAnfme;
    }
}