野心家
2025-02-17 796cfcc66392f78362cd72ca2510fc5194c0d079
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.zy.asrs.task;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.exception.CoolException;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.TaskWrkLog;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.TaskWrkService;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
 
@Slf4j
@Component
public class AssignTasksRCSScheduler {
    @Autowired
    private TaskWrkService taskWrkService;
    @Autowired
    private ApiLogService apiLogService;
    @Value("${wcs.urlWcs}")
    private String wcsUrl;
    @Value("${wcs.movePathWcs}")
    private String wcsmovePath;
    @Value("${wcs.outboundTaskRequest}")
    private String wcsoutboundTaskRequest;
    @Value("${wms.TaskExecCallback}")
    private String TaskExecCallback;
    @Value("${wms.taskStatusFeedbackPath}")
    private String taskStatusFeedbackPath;
 
    /**
     * 自动派发出库任务给RCS
     *
     * @throws IOException
     */
    @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;
                }
                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
                    );
                }
            }
        }
    }
}