#
Junjie
2025-05-23 87fd4ae058bc3103e8696f10615bf84472d54128
src/main/java/com/zy/asrs/task/AssignTasksRCSScheduler.java
@@ -32,63 +32,146 @@
    private String wcsmovePath;
    @Value("${wcs.outboundTaskRequest}")
    private String wcsoutboundTaskRequest;
    @Value("${wcs.inboundTaskApplyPathWcs}")
    private String wcsInboundTaskApplyPathWcs;
    @Value("${wms.TaskExecCallback}")
    private String TaskExecCallback;
    @Value("${wms.taskStatusFeedbackPath}")
    private String taskStatusFeedbackPath;
    /**
     * 自动派发出库任务给RCS
     *
     * @throws IOException
     * 自动派发移库任务给RCS
     */
    @Scheduled(cron = "0/3 * * * * ? ")
    public void execute() throws IOException {
        if(true){
            List<TaskWrk> taskWrks=taskWrkService.selectList(new EntityWrapper<TaskWrk>()
                    .eq("wrk_sts",1).eq("io_type",3));
            for(TaskWrk taskWrk:taskWrks){
                HashMap<String, Object> headParam = new HashMap<>();
                String response = "";
                Boolean bool = false;
                String dz="";
                if(taskWrk.getIoType()==2){
                    dz=wcsoutboundTaskRequest;
                }else{
                    dz=wcsmovePath;
    public void executeMove() {
        List<TaskWrk> taskWrks = taskWrkService.selectList(new EntityWrapper<TaskWrk>()
                .eq("wrk_sts", 1).eq("io_type", 3));
        for (TaskWrk taskWrk : taskWrks) {
            HashMap<String, Object> headParam = new HashMap<>();
            String response = "";
            boolean bool = false;
            try {
                headParam.put("taskNo", taskWrk.getTaskNo());
                headParam.put("sourceLocNo", taskWrk.getStartPoint());//源库位
                headParam.put("locNo", taskWrk.getTargetPoint());//目标库位
                log.info("wcs派发任务给RCS移库={}", taskWrk);
                response = new HttpHandler.Builder()
                        // .setHeaders(headParam)
                        .setUri(wcsUrl)
                        .setPath(wcsmovePath)
                        .setJson(JSON.toJSONString(headParam))
                        .build()
                        .doPost();
                JSONObject jsonObject = JSON.parseObject(response);
                if (jsonObject.get("code").equals(200)) {
                    //派发出库任务给RCS==>成功下发移库任务
                    taskWrk.setWrkSts(2);
                    taskWrkService.updateById(taskWrk);
                    bool = true;
                }
                try {
                    headParam.put("taskNo", taskWrk.getTaskNo());
                    headParam.put("sourceLocNo",taskWrk.getStartPoint());//源库位
                    headParam.put("locNo",taskWrk.getTargetPoint());//目标库位
                    log.info("wcs派发任务给RCS出库={}", taskWrk);
                    response = new HttpHandler.Builder()
                            // .setHeaders(headParam)
                            .setUri(wcsUrl)
                            .setPath(dz)
                            .setJson(JSON.toJSONString(headParam))
                            .build()
                            .doPost();
                    JSONObject jsonObject = JSON.parseObject(response);
                    if(jsonObject.get("code").equals(200)){
                        //派发出库任务给RCS==>成功下发出库任务
                        taskWrk.setWrkSts(2);
                        taskWrkService.updateById(taskWrk);
                        bool = true;
                    }
                } catch (Exception e) {
                    log.error("wcs派发任务给RCS出库失败{},返回值={}", taskWrk, response);
                } finally {
                    apiLogService.save("wcs派发任务给RCS出库"
                            , wcsUrl + dz
                            , null
                            , "127.0.0.1"
                            , JSON.toJSONString(headParam)
                            , response
                            , bool
                    );
                }
            } catch (Exception e) {
                log.error("wcs派发任务给RCS移库失败{},返回值={}", taskWrk, response);
            } finally {
                apiLogService.save("wcs派发任务给RCS移库"
                        , wcsUrl + wcsmovePath
                        , null
                        , "127.0.0.1"
                        , JSON.toJSONString(headParam)
                        , response
                        , bool
                );
            }
        }
    }
    /**
     * 自动派发出库任务给RCS
     */
    @Scheduled(cron = "0/3 * * * * ? ")
    public void executeOut() {
        List<TaskWrk> taskWrks = taskWrkService.selectList(new EntityWrapper<TaskWrk>()
                .eq("wrk_sts", 1).eq("io_type", 2));
        for(TaskWrk taskWrk:taskWrks){
            HashMap<String, Object> headParam = new HashMap<>();
            String response = "";
            boolean bool = false;
            try {
                headParam.put("taskNo", taskWrk.getTaskNo());
                headParam.put("sourceLocNo",taskWrk.getStartPoint());//源库位
                headParam.put("staNo",taskWrk.getTargetPoint());//目标站
                log.info("wcs派发任务给RCS出库={}", taskWrk);
                response = new HttpHandler.Builder()
                        .setUri(wcsUrl)
                        .setPath(wcsoutboundTaskRequest)
                        .setJson(JSON.toJSONString(headParam))
                        .build()
                        .doPost();
                JSONObject jsonObject = JSON.parseObject(response);
                if(jsonObject.get("code").equals(200)){
                    //派发出库任务给RCS==>成功下发出库任务
                    taskWrk.setWrkSts(11);
                    taskWrkService.updateById(taskWrk);
                    bool = true;
                }
            } catch (Exception e) {
                log.error("wcs派发任务给RCS出库失败{},返回值={}", taskWrk, response);
            } finally {
                apiLogService.save("wcs派发任务给RCS出库"
                        , wcsUrl + wcsoutboundTaskRequest
                        , null
                        , "127.0.0.1"
                        , JSON.toJSONString(headParam)
                        , response
                        , bool
                );
            }
        }
    }
    /**
     * 自动派发入库任务给RCS
     */
    @Scheduled(cron = "0/3 * * * * ? ")
    public void executeIn() {
        List<TaskWrk> taskWrks = taskWrkService.selectList(new EntityWrapper<TaskWrk>()
                .eq("wrk_sts", 1).eq("io_type", 2));
        for(TaskWrk taskWrk:taskWrks){
            HashMap<String, Object> headParam = new HashMap<>();
            String response = "";
            boolean bool = false;
            try {
                headParam.put("taskNo", taskWrk.getTaskNo());
                headParam.put("sourceStaNo",taskWrk.getOriginStartPoint());//源站
                headParam.put("staNo",taskWrk.getOriginTargetPoint());//目标站
                headParam.put("locNo",taskWrk.getTargetPoint());//目标库位
                log.info("wcs派发任务给RCS入库={}", taskWrk);
                response = new HttpHandler.Builder()
                        .setUri(wcsUrl)
                        .setPath(wcsInboundTaskApplyPathWcs)
                        .setJson(JSON.toJSONString(headParam))
                        .build()
                        .doPost();
                JSONObject jsonObject = JSON.parseObject(response);
                if(jsonObject.get("code").equals(200)){
                    //派发出库任务给RCS==>成功下发入库任务
                    taskWrk.setWrkSts(2);
                    taskWrkService.updateById(taskWrk);
                    bool = true;
                }
            } catch (Exception e) {
                log.error("wcs派发任务给RCS入库失败{},返回值={}", taskWrk, response);
            } finally {
                apiLogService.save("wcs派发任务给RCS入库"
                        , wcsUrl + wcsInboundTaskApplyPathWcs
                        , null
                        , "127.0.0.1"
                        , JSON.toJSONString(headParam)
                        , response
                        , bool
                );
            }
        }
    }
}