自动化立体仓库 - WMS系统
zhangc
2025-01-09 a66b19e1c09201a922735c2325ca04df7fe544af
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
129
130
131
132
133
134
135
136
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.AppAuth;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.zy.asrs.entity.AgvWarn;
import com.zy.asrs.entity.AgvWrkMast;
import com.zy.asrs.entity.param.AgvWarnBody;
import com.zy.asrs.entity.param.AgvWarnCallBackParam;
import com.zy.asrs.service.AgvWarnService;
import com.zy.asrs.service.AgvWrkMastService;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.utils.AppAuthUtil;
import com.zy.common.web.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.util.*;
 
/**
 * 上报事件类型(eventType):
 *  task:上报任务状态。
 *  task_allocated: 上报任务分配给机器人。
 *  tote_load:上报取箱状态。
 *  tote_unload:上报放箱状态。
 *  robot_reach:机器人到达工作站。
 *  weight:称重事件回调。
 *  rfid:RFID识别事件回调。
 *
 * 任务状态(status):
 *  success:成功。
 *  fail:失败。
 *  cancel:取消。
 *  suspend:挂起。
 */
@Slf4j
@RestController
@RequestMapping("/agv")
public class AgvWarnController extends BaseController {
 
 
    @Autowired
    private ApiLogService apiLogService;
 
    @Autowired
    private AgvWarnService agvWarnService;
 
 
    @Autowired
    private AgvWrkMastService agvWrkMastService;
 
 
    @PostMapping("/service/rest/agvCallbackService/warnCallback")
    @AppAuth(memo = "AGV告警回调")
    public Object taskEventStaus(@RequestBody AgvWarnCallBackParam param, HttpServletRequest request) {
        log.info("AGV告警回调:{}", JSON.toJSONString(param));
        AppAuthUtil.auth("", param, request);
        List<AgvWarnBody> agvWarnBodies = param.getData();
        //  List<AgvWarnBody> agvWarnBodies = JSONArray.parseArray(data, AgvWarnBody.class);
        AgvWarn agvWarn = null;
        List<AgvWarn> agvWarns = new ArrayList<>();
        List<AgvWarn> updates = new ArrayList<>();
        for (AgvWarnBody body : agvWarnBodies) {
            List<AgvWarn> agvWarnList = agvWarnService.selectList(new EntityWrapper<AgvWarn>().eq("robot_code", body.getRobotCode()).eq("begin_time", body.getBeginTime()).eq("warn_content", body.getWarnContent()));
            if (Cools.isEmpty(agvWarnList)) {
                agvWarn = new AgvWarn();
                agvWarn.setBeginTime(body.getBeginTime());
                agvWarn.setAppeTime(new Date());
                agvWarn.setTimes(0);
                agvWarn.setModiTime(DateUtils.convert(body.getBeginTime(), DateUtils.yyyyMMddHHmmss_F));
                agvWarn.setRobotCode(body.getRobotCode());
                agvWarn.setWarnContent(body.getWarnContent());
                if (body.getTaskCode() != null) {
                    try {
                        AgvWrkMast agvWrkMast = agvWrkMastService.selectById(Math.abs(Integer.parseInt(body.getTaskCode())));
                        if (agvWrkMast != null) {
                            agvWarn.setLocNo(agvWrkMast.getLocNo());
                            agvWarn.setSourceLocNo(agvWrkMast.getSourceLocNo());
                        }
                    } catch (Exception e) {
                        log.info("任务不存在");
                    }
                }
                agvWarns.add(agvWarn);
            } else {
                agvWarn = agvWarnList.get(0);
                agvWarn.setWarnContent(agvWarn.getWarnContent().contains(body.getWarnContent()) ? body.getWarnContent() : agvWarn.getWarnContent() + "、" + body.getWarnContent());
                agvWarn.setModiTime(new Date());
                if (body.getTaskCode() != null) {
                    try {
                        AgvWrkMast agvWrkMast = agvWrkMastService.selectById(body.getTaskCode());
                        if (agvWrkMast != null) {
                            agvWarn.setLocNo(agvWrkMast.getLocNo());
                            agvWarn.setSourceLocNo(agvWrkMast.getSourceLocNo());
                        }
                    } catch (Exception e) {
                        log.info("任务不存在");
                    }
                }
                updates.add(agvWarn);
            }
        }
        if (!Cools.isEmpty(agvWarns)) {
            agvWarnService.insertBatch(agvWarns);
        }
        if (!Cools.isEmpty(updates)) {
            agvWarnService.updateBatchById(updates);
        }
        Map<String, Object> result = new HashMap<>();
        logPost(JSONObject.toJSONString(param), JSONObject.toJSONString(result), true);
        result.put("code", 0);
        result.put("message", "成功");
        result.put("reqCode", param.getReqCode());
        return result;
    }
 
    private void logPost(String param, String response, boolean success) {
        apiLogService.save(
                "ESS任务回调",
                "/phyzwms/agv/task/event/status",
                null,
                null,
                param,
                response,
                success
        );
    }
}