自动化立体仓库 - WCS系统
#
zjj
2023-12-08 d04ce586afce3b78f238289dad10dacd4c22206a
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.zy.asrs.task;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.domain.enums.TaskStatusType;
import com.zy.asrs.entity.CommandInfo;
import com.zy.asrs.entity.StaDesc;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.param.TaskOverToWms;
import com.zy.asrs.entity.param.TaskStatusFeedbackParam;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.CommandInfoService;
import com.zy.asrs.service.StaDescService;
import com.zy.asrs.service.TaskWrkService;
import com.zy.asrs.utils.PostMesDataUtils;
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;
import java.util.Map;
 
/**
 * 定时将任务(完成、取消)转成日志
 */
@Slf4j
@Component
public class TaskLogScheduler {
 
    @Autowired
    private TaskWrkService taskWrkService;
    @Autowired
    private CommandInfoService commandInfoService;
    @Autowired
    private ApiLogService apiLogService;
 
    @Autowired
    private StaDescService staDescService;
 
    @Value("${wms.url}")
    private String wmsUrl;
    @Value("${wms.movePath}")
    private String movePath;
 
    @Scheduled(cron = "0/3 * * * * ? ")
    public void execute() throws IOException {
        for (TaskWrk taskWrk : taskWrkService.selectToBeHistoryData()) {
            TaskStatusFeedbackParam taskStatusFeedbackParam = new TaskStatusFeedbackParam(taskWrk);
            if (taskWrk.getStatus().equals(TaskStatusType.OVER.id)) {//完成
                taskStatusFeedbackParam.setTaskStatus("done");
                Map<String, Object> map = new HashMap<>();
                map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2");
                TaskOverToWms taskOverToWms = new TaskOverToWms();
                taskOverToWms.setFeedbackFrom("WCS"); //来源
                taskOverToWms.setWarehouseId("1688469798893297665"); //仓库标识
                taskOverToWms.setTaskNo(taskWrk.getTaskNo()); //任务号
                taskOverToWms.setTaskType(taskStatusFeedbackParam.getTaskType()); // 任务类型
                taskOverToWms.setContainerCode(taskWrk.getBarcode()); // 容器编码
                if (taskWrk.getIoType() ==1 ){
                    taskOverToWms.setEquipmentCode(String.valueOf(taskWrk.getCrnNo())); //设备编码
                    taskOverToWms.setTargetLocationCode(taskWrk.getOriginTargetPoint()); //目标库位
                }else if (taskWrk.getIoType() ==2){
                    Map<Integer,String> map1 = new HashMap<>();
                    map1.put(102,"J-1101");
                    map1.put(106,"J-1103");
                    map1.put(110,"J-1105");
                    map1.put(114,"J-1107");
                    map1.put(118,"J-1109");
                    map1.put(122,"J-1111");
                    StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>().eq("stn_no", taskWrk.getTargetPoint()));
                    taskOverToWms.setEquipmentCode(staDesc.getStnDesc()); //设备编码
                    taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint()); //源库位
                }
 
                taskOverToWms.setTaskStatus("done"); //任务状态
                String response = null;
                try {
                    response = new HttpHandler.Builder()
                            .setHeaders(map)
                            .setUri(wmsUrl)
                            .setPath("wcsManager/wcsInterface/taskStatusFeedback")
                            .setJson(JSON.toJSONString(taskOverToWms))
                            .build()
                            .doPost();
                }catch (Exception e){
                    continue;
                }
                apiLogService.save("Wms任务完成接口"
                        ,wmsUrl+"/wcsManager/wcsInterface/taskStatusFeedback"
                        ,null
                        ,"127.0.0.1"
                        ,JSON.toJSONString(taskOverToWms)
                        ,response
                        ,true
                );
 
                JSONObject jsonObject = JSON.parseObject(response);
                if (jsonObject.getInteger("code").equals(200)){
 
                }else {
                    continue;
                }
 
                //new PostMesDataUtils().postMesData("完成上报",wmsUrl,movePath,taskWrk);
            } else if (taskWrk.getStatus().equals(TaskStatusType.CANCEL.id)) {
                taskStatusFeedbackParam.setTaskStatus("cancelled");
                //new PostMesDataUtils().postMesData("取消任务完成",wmsUrl,movePath,taskWrk);
            }
 
            if (taskWrkService.saveToHistory(taskWrk.getTaskNo()) > 0) {
                //任务已经转日志,将该任务下面的指令转日志
                commandInfoService.saveToHistory(taskWrk.getTaskNo());
 
                //删除任务
                taskWrkService.delete(new EntityWrapper<TaskWrk>().eq("task_no", taskWrk.getTaskNo()));
                //删除指令
                commandInfoService.delete(new EntityWrapper<CommandInfo>().eq("task_no", taskWrk.getTaskNo()));
            }
        }
    }
 
}