自动化立体仓库 - WMS系统
zwl
3 天以前 6efef82561e2cf14f09871d63e1581c6174cfe10
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
package com.zy.asrs.task.newWay.handler;
 
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.entity.param.RCSParam;
import com.zy.asrs.service.*;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
 
@Slf4j
@Service
@Transactional
public class AssignTasksToRCSHandler extends AbstractHandler<String> {
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private ApiLogService apiLogService;
    @Value("${rcs.address.url}")
    private String url;
    @Value("${rcs.address.attrcs}")
    private String attrcs;
 
    public ReturnT<String> start(WrkMast wrkMast) {
        LocalDateTime now = LocalDateTime.now();
        String noww="bb" + new Date().getTime();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDate = now.format(formatter); // 格式化日期时间
 
        LinkedHashMap<String,Object> rcsParam=new LinkedHashMap<>();
        rcsParam.put("task_id",noww);
        rcsParam.put("start_location","102");
        rcsParam.put("start_site_level",1);
        rcsParam.put("start_command",1);
        rcsParam.put("target_location",wrkMast.getMemo());
        rcsParam.put("target_site_level",1);
        rcsParam.put("target_command",2);
        rcsParam.put("priority",1);
        rcsParam.put("robot_type",3);//车 辆 类 型 0:XC 1:XCD 2:XP_T 3:XP_L
        rcsParam.put("MoverID","XS1");
 
        LinkedHashMap<String,Object> map=new LinkedHashMap<>();
        map.put("data",rcsParam);
        String response ="";
        Boolean bool =false;
        String msg = "";
 
        wrkMast.setPauseMk(noww);
        try {
            log.info("wms派发搬运任务给AGV搬运={}", rcsParam);
            response = new HttpHandler.Builder()
                    // .setHeaders(headParam)
                    .setUri(url)
                    .setPath(attrcs)
                    .setJson(JSON.toJSONString(map))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            JSONObject data = jsonObject.getJSONObject("data");
            JSONObject errInfo = jsonObject.getJSONObject("err_info");
            if(data.getInteger("result")==0){
                if(wrkMast.getIoType()==103||wrkMast.getIoType()==107){
                    wrkMast.setWrkSts(16L);//待回库
                }else{
                    wrkMast.setWrkSts(15L);//下发RCS-成功
                }
 
                wrkMast.setErrorMemo(noww);
                wrkMastService.updateById(wrkMast);
                bool = true;
            }else{
                msg=errInfo.getString("err_msg");
            }
        } catch (Exception e) {
            log.error("wms派发搬运任务给AGV搬运失败返回值={}", response);
        } finally {
            apiLogService.save("wms派发搬运任务给AGV搬运"
                    , url + attrcs
                    , null
                    , "127.0.0.1"
                    , JSON.toJSONString(map)
                    , response
                    , bool
            );
        }
        return SUCCESS;
    }
}