自动化立体仓库 - WMS系统
#
1
14 小时以前 8257d89c461f6553d66fad1e5e3df3d172a00924
src/main/java/com/zy/asrs/controller/OpenController.java
@@ -5,11 +5,13 @@
import com.core.common.*;
import com.core.exception.CoolException;
import com.zy.asrs.entity.param.*;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.OpenService;
import com.zy.common.model.DetlDto;
import com.zy.common.web.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@@ -243,16 +245,23 @@
        if (Cools.isEmpty(param.getUpc())) {
            return R.error("UPC[upc]不能为空");
        }
        if (Cools.isEmpty(param.getSupplier())) {
            return R.error("货源[supplier]不能为空");
        if (Cools.isEmpty(param.getItem())) {
            return R.error("UPC[item]不能为空");
        }
//        if (Cools.isEmpty(param.getSupplier())) {
//            return R.error("货源[supplier]不能为空");
//        }
        if (Cools.isEmpty(param.getStaNo())) {
            return R.error("分拣点位[staNo]不能为空");
        }
        if (Cools.isEmpty(param.getBindingTags())) {
            return R.error("分拣绑定类别[bindingTags]不能为空");
        }
        openService.taskArmReport(param);
        try{
            openService.taskArmReport(param);
        } catch (Exception e){
            return R.error(e.getMessage()).add(e.getMessage());
        }
        return R.ok();
    }
@@ -395,6 +404,9 @@
        } catch (Exception e){
            return R.error("单据编号[order_id]以 "+sign_arm_sku+" 与 "+sign_arm_order+" 作为拆分标记拆分失败!!!");
        }
        if (param.getArm_no()>4){
            return R.ok().add(true);
        }
        boolean taskArmWorkOrderSign = openService.TaskArmWorkOrderSign(param);
        return R.ok().add(taskArmWorkOrderSign);
@@ -402,28 +414,155 @@
    /**
     * 分拣线上报接收
     * AGV上报接收
     */
    @PostMapping("/agv/task/v1")
    @AppAuth(memo = "AGV上报接收")
    @PostMapping("/agv/task/v1/agvCallback")
//    @AppAuth(memo = "AGV上报接收")
    public synchronized R TaskAgvReport(@RequestHeader(required = false) String appkey,
                                        @RequestBody TaskAgvReportParam param,
                                        HttpServletRequest request) {
//        auth(appkey, param, request);
        // 日志记录
        ApiLogService apiLogService = SpringUtils.getBean(ApiLogService.class);
        apiLogService.save(
                "AGV上报接收",
                "/open/asrs/agv/task/v1/agvCallback",
                null,
                request.getRemoteAddr(),
                JSON.toJSONString(param),
                null,
                true
        );
        if (Cools.isEmpty(param)) {
            return R.parse(BaseRes.PARAM);
        }
        if (Cools.isEmpty(param.getReqCode())) {
            return R.error("WMS任务号[reqCode]不能为空");
        }
        if (Cools.isEmpty(param.getTaskCode())) {
            return R.error("WMS任务号[reqCode]不能为空");
        }
        String taskCode = param.getTaskCode();
        if (taskCode == null || !taskCode.matches("^\\d+-.*$")) {
            throw new CoolException("taskCode 格式错误,需为 数字-xxx,例如 123-ABC");
        }
        param.setTaskNo(Integer.parseInt(taskCode.substring(0, taskCode.indexOf("-"))));
        boolean taskAgvReport = openService.TaskAgvReport(param);
        if (taskAgvReport){
            agvBindAndBin(String.valueOf(param.getTaskNo()));
            return R.ok();
        }
        return R.error("任务号不存在");
    }
    /**
     * PDA创建AGV任务
     */
    @PostMapping("/agv/task/v1/createTask")
    @AppAuth(memo = "PDA创建AGV任务")
    public synchronized R TaskAgvCreate(@RequestHeader(required = false) String appkey,
                                        @RequestBody TaskAgvCreateParam param,
                                        HttpServletRequest request) {
        auth(appkey, param, request);
        if (Cools.isEmpty(param)) {
            return R.parse(BaseRes.PARAM);
        }
        if (Cools.isEmpty(param.getTaskNo())) {
            return R.error("WMS任务号[taskNo]不能为空");
        }
//        if (Cools.isEmpty(param.getTimestamp())) {
//            return R.error("RGV任务号[timestamp]不能为空");
//        }
        boolean taskAgvReport = openService.TaskAgvReport(param);
        if (taskAgvReport){
        boolean taskAgvCreate = openService.taskAgvCreate(param);
        if (taskAgvCreate){
            return R.ok();
        }
        return R.error("任务号不存在");
    }
    /**
     * PDA获取AGV库位
     */
    @PostMapping("/agv/loc/v1/getLocList")
    @AppAuth(memo = "PDA检索AGV库位")
    public synchronized R GetAgvLocList(@RequestHeader(required = false) String appkey,
                                        @RequestBody AgvLocListParam param,
                                        HttpServletRequest request) {
        auth(appkey, param, request);
        List<AgvLocListDetlParam> list = openService.getAgvLocList(param);
        if (!list.isEmpty()) {
            return R.ok(list);
        }
        return R.error("库位不存在或无明细");
    }
    /**
     * PDA绑定解绑
     */
    @PostMapping("/agv/bindCtnrAndBin/v1")
    @AppAuth(memo = "PDA绑定与解绑")
    public synchronized R bindCtnrAndBin(@RequestHeader(required = false) String appkey,
                                        @RequestBody bindCtnrAndBinParam param,
                                        HttpServletRequest request) {
        auth(appkey, param, request);
        if (Cools.isEmpty(param)) {
            return R.parse(BaseRes.PARAM);
        }
        boolean bindCtnrAndBin = openService.bindCtnrAndBin(param);
        if (bindCtnrAndBin) {
            return R.ok();
        }
        return R.error("库位不存在或无明细");
    }
    /**
     * AGV申请过光栅
     */
    @PostMapping("/agv/arm/grating/v1/agvCallback")
    @AppAuth(memo = "AGV申请过光栅")
    public synchronized R agvGrating(@RequestHeader(required = false) String appkey,
                                         @RequestBody AgvGoTheArnParam param,
                                         HttpServletRequest request) {
//        auth(appkey, param, request);
        if (Cools.isEmpty(param)) {
            return R.parse(BaseRes.PARAM);
        }
        if (Cools.isEmpty(param.getCurrentPositionCode())) {
            return R.error("位置[currentPositionCode]不能为空");
        }
        boolean bindCtnrAndBin = true;
        List<ArmAgvGratingParam> armList = param.getArmNo();
        if (armList.isEmpty()){
            return R.error("库位不存在或无明细");
        }
        for (ArmAgvGratingParam arm : armList){
            if (bindCtnrAndBin){
                bindCtnrAndBin = openService.agvApplicationPassedTheGrating(arm);
//                System.out.println("请求通过光栅"+armNo);
            }
        }
        if (bindCtnrAndBin) {
            asyncProcessAfterValidation(param);
            return new R(0,"成功");
        }
        return R.error("库位不存在或无明细");
    }
    @Async
    public void agvBindAndBin(String taskNo) {
        try {
            Thread.sleep(500);
            openService.agvBindAndBin(taskNo);
        } catch (Exception e) {
            log.error("异步处理AGV光栅后续逻辑失败", e);
        }
    }
    @Async
    public void asyncProcessAfterValidation(AgvGoTheArnParam param) {
        try {
            Thread.sleep(500);
            openService.agvApplicationPassedTheGrating(param);
        } catch (Exception e) {
            log.error("异步处理AGV光栅后续逻辑失败", e);
        }
    }
}