yangys
2024-10-30 25db770e621f1259b8d5b7fd514207f7481c2d0f
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
package com.qianwen.smartman.modules.cps.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap;
import io.swagger.annotations.Api;
import java.util.Collections;
import com.qianwen.smartman.common.websocket.entity.FmsArea;
import com.qianwen.smartman.common.websocket.entity.FmsWorkstation;
import com.qianwen.smartman.common.websocket.fms.FmsVisualDataResponseMessage;
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.utils.SpringUtil;
import com.qianwen.core.websocket.distribute.MessageDO;
import com.qianwen.core.websocket.distribute.RedisMessageDistributor;
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;
 
@ApiResource({"smis/test"})
@Api(value = "测试websocket", tags = {"测试websocket"})
@RestController
public class WebSocketTestController {
    @RequestMapping({"/send-message"})
    public R<Boolean> sendMessage() {
        RedisMessageDistributor messageDistributor = (RedisMessageDistributor) SpringUtil.getBean(RedisMessageDistributor.class);
        MessageDO messageOne = new MessageDO();
        messageOne.setNeedBroadcast(Boolean.FALSE);
        JSONObject json = new JSONObject();
        json.put("type", "realTimeData");
        json.put("id", "111");
        json.put("data", ImmutableMap.of("data", "hello realTimeData"));
        messageOne.setMessageText(json.toJSONString());
        messageDistributor.distribute(messageOne);
        JSONObject typeTwo = new JSONObject();
        typeTwo.put("type", "internalMessageData");
        typeTwo.put("data", "hello internalMessageData");
        MessageDO messageTwo = new MessageDO();
        messageTwo.setNeedBroadcast(false);
        messageTwo.setMessageText(typeTwo.toJSONString());
        messageDistributor.distribute(messageTwo);
        return R.success("");
    }
 
    @PostMapping({"/send-fms-area"})
    public R<Boolean> sendFmsMessage(@RequestBody FmsArea fmsArea) {
        FmsVisualDataResponseMessage responseMessage = new FmsVisualDataResponseMessage();
        responseMessage.setFmsAreaList(Collections.singletonList(fmsArea));
        responseMessage.setFmsAreaList(Collections.singletonList(fmsArea));
        responseMessage.setFmsAreaList(Collections.singletonList(fmsArea));
        responseMessage.setFmsAreaList(Collections.singletonList(fmsArea));
        MessageDO messageDO = new MessageDO();
        messageDO.setNeedBroadcast(true);
        messageDO.setMessageText(JSONObject.toJSONString(responseMessage));
        RedisMessageDistributor messageDistributor = (RedisMessageDistributor) SpringUtil.getBean(RedisMessageDistributor.class);
        messageDistributor.distribute(messageDO);
        return R.success("");
    }
 
    @PostMapping({"/send-fms-carry"})
    public R<Boolean> sendFmsCarry(@RequestBody FmsWorkstation fmsCarry) {
        FmsVisualDataResponseMessage responseMessage = new FmsVisualDataResponseMessage();
        responseMessage.setFmsCarryList(Collections.singletonList(fmsCarry));
        MessageDO messageDO = new MessageDO();
        messageDO.setNeedBroadcast(false);
        messageDO.setMessageText(JSONObject.toJSONString(responseMessage));
        RedisMessageDistributor messageDistributor = (RedisMessageDistributor) SpringUtil.getBean(RedisMessageDistributor.class);
        messageDistributor.distribute(messageDO);
        return R.success("");
    }
 
    @PostMapping({"/send-fms-manual"})
    public R<Boolean> sendFmsManual(@RequestBody FmsWorkstation station) {
        FmsVisualDataResponseMessage responseMessage = new FmsVisualDataResponseMessage();
        responseMessage.setFmsManualStationList(Collections.singletonList(station));
        MessageDO messageDO = new MessageDO();
        messageDO.setNeedBroadcast(false);
        messageDO.setMessageText(JSONObject.toJSONString(responseMessage));
        RedisMessageDistributor messageDistributor = (RedisMessageDistributor) SpringUtil.getBean(RedisMessageDistributor.class);
        messageDistributor.distribute(messageDO);
        return R.success("");
    }
 
    @PostMapping({"/send-fms-station"})
    public R<Boolean> sendFmsStation(@RequestBody FmsWorkstation workstation) {
        FmsVisualDataResponseMessage responseMessage = new FmsVisualDataResponseMessage();
        responseMessage.setFmsWorkstationList(Collections.singletonList(workstation));
        MessageDO messageDO = new MessageDO();
        messageDO.setNeedBroadcast(false);
        messageDO.setMessageText(JSONObject.toJSONString(responseMessage));
        RedisMessageDistributor messageDistributor = (RedisMessageDistributor) SpringUtil.getBean(RedisMessageDistributor.class);
        messageDistributor.distribute(messageDO);
        return R.success("");
    }
}