自动化立体仓库 - WMS系统
cl
2 天以前 18c51d40be82435289ba3be6bd5f8e15fdf786f7
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
package com.zy.iot.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.common.web.BaseController;
import com.zy.integration.iot.publish.IotPublishService;
import com.zy.iot.service.IotDbConfigService;
import com.zy.iot.constant.IotConstants;
import com.zy.iot.entity.IotPublishRecord;
import com.zy.iot.service.IotPublishRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * 后台:仅出站 MQTT(WMS 发出),支持列表与手动重发。
 */
@RestController
public class IotMqttOutboundController extends BaseController {
 
    @Autowired
    private IotDbConfigService iotDbConfigService;
    @Autowired
    private IotPublishRecordService iotPublishRecordService;
    @Autowired
    private IotPublishService iotPublishService;
 
    @RequestMapping(value = "/iotMqttOutbound/list/auth")
    @ManagerAuth(memo = "IoT MQTT 发送记录")
    public R list(@RequestParam(defaultValue = "1") Integer curr,
                  @RequestParam(defaultValue = "16") Integer limit,
                  @RequestParam(required = false) String instruction_id,
                  @RequestParam(required = false) String publish_status,
                  @RequestParam(required = false) String publish_topic,
                  @RequestParam(required = false) String container_id) {
        EntityWrapper<IotPublishRecord> wrapper = new EntityWrapper<>();
        wrapper.eq("direction", IotConstants.DIRECTION_OUTBOUND);
        wrapper.isNotNull("publish_topic");
        wrapper.isNotNull("publish_payload");
        if (!Cools.isEmpty(instruction_id)) {
            wrapper.like("instruction_id", instruction_id);
        }
        if (!Cools.isEmpty(publish_status)) {
            wrapper.eq("publish_status", publish_status);
        }
        if (!Cools.isEmpty(publish_topic)) {
            wrapper.like("publish_topic", publish_topic);
        }
        if (!Cools.isEmpty(container_id)) {
            wrapper.like("container_id", container_id);
        }
        wrapper.orderBy("create_time", false);
        return R.ok(iotPublishRecordService.selectPage(new Page<>(curr, limit), wrapper));
    }
 
    @RequestMapping(value = "/iotMqttOutbound/resend/auth")
    @ManagerAuth(memo = "IoT MQTT 发送重发")
    public R resend(@RequestParam Long id) {
        if (id == null) {
            return R.error("缺少 id");
        }
        if (!iotDbConfigService.isMqttEnabled()) {
            return R.error("IoT 未开启");
        }
        IotPublishRecord record = iotPublishRecordService.selectById(id);
        if (record == null) {
            return R.error("记录不存在");
        }
        if (!IotConstants.DIRECTION_OUTBOUND.equals(record.getDirection())) {
            return R.error("仅支持出站记录重发");
        }
        if (Cools.isEmpty(record.getPublishTopic()) || Cools.isEmpty(record.getPublishPayload())) {
            return R.error("无发送主题或消息体");
        }
        iotPublishService.publishRecordNow(id);
        record = iotPublishRecordService.selectById(id);
        if (record != null && IotConstants.PUBLISH_STATUS_SUCCESS.equals(record.getPublishStatus())) {
            return R.ok();
        }
        String err = record != null && !Cools.isEmpty(record.getErrorMessage())
                ? record.getErrorMessage()
                : "发送失败";
        return R.error(err);
    }
}