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
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
137
138
139
140
package com.qianwen.smartman.modules.cps.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
 
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
 
import com.qianwen.core.boot.ctrl.BladeController;
import com.qianwen.core.datascope.props.DataScopeProperties;
import com.qianwen.core.mp.intercept.QueryInterceptor;
import com.qianwen.core.scanner.modular.annotation.GetResource;
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
import com.qianwen.core.secure.annotation.PreAuth;
import com.qianwen.core.tenant.annotation.NonDS;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.utils.SpringUtil;
import com.qianwen.core.websocket.config.WebSocketMessageSender;
import com.qianwen.core.websocket.distribute.MessageDO;
import com.qianwen.core.websocket.distribute.RedisMessageDistributor;
import com.qianwen.smartman.common.cache.cps.WorkstationCache;
import com.qianwen.smartman.common.websocket.realtime.RealTimeDaraResponseJsonWebSocketMessage;
import com.qianwen.smartman.modules.cps.message.dto.TelemetryDataResponseDTO;
import com.qianwen.smartman.modules.cps.service.CollectDeviceTypeService;
import com.qianwen.smartman.modules.cps.service.ICommonGroupService;
import com.qianwen.smartman.modules.cps.service.WorkstationDatapointsService;
import com.qianwen.smartman.modules.cps.vo.CollectDeviceTypeVO;
import com.qianwen.smartman.modules.cps.vo.WorkstationDatapointsVO;
import com.qianwen.smartman.modules.cps.vo.WorkstationGroupVO;
import com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO;
import com.qianwen.smartman.modules.mdc.mapper.SuperProcessParameterMapper;
 
import cn.hutool.json.JSONUtil;
 
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
@Api(value = "test", tags = {"test"})
@RestController
@ApiResource({"smis/test"})
public class MyTestController {// extends BladeController
    
    @Autowired
    private WorkstationDatapointsService workstationDatapointsService;
   
    @Autowired
    private CollectDeviceTypeService typeService;
    
    @Autowired
    DataScopeProperties dsp;
    @Autowired
    QueryInterceptor qi;
    @Autowired
    SuperProcessParameterMapper pmapper;
    
    @GetMapping({"/dsp"})
    @ApiOperation("dsp")
    public R<String> showdsp() {
        Properties props = System.getProperties();
        String appName = props.getProperty("spring.application.name");
        return R.data(appName);
    }
    
    @GetMapping({"/realtimesend"})
    @ApiOperation("realtimesend")
    public R<String> realtimesend(String wid,String k,String v) {
        RedisMessageDistributor messageDistributor = (RedisMessageDistributor) SpringUtil.getBean(RedisMessageDistributor.class);
        
        RealTimeDaraResponseJsonWebSocketMessage jsonWebSocketMessage = new RealTimeDaraResponseJsonWebSocketMessage();
        jsonWebSocketMessage.setId(wid);
        
        Map<String, Object> map = WorkstationCache.getWorkstationRealTime(wid);
        map.keySet().forEach(key->{
            if(key.equals(k)) {
                Object d = map.get(k);
                
                TelemetryDataResponseDTO a = (TelemetryDataResponseDTO)d;
                a.setV(v);
                System.out.println(d);
            }
        });
        jsonWebSocketMessage.setData(map);
        
        MessageDO messageDO = new MessageDO();
        messageDO.setNeedBroadcast(false);
        messageDO.setMessageText(JSONUtil.toJsonStr(jsonWebSocketMessage));
        messageDistributor.distribute(messageDO);
        
   
        return R.data("1");
    }
    
    
    
    @GetMapping({"/listDatapointsByWorkstationId"})
    @ApiOperation("根据工位id获取数据点")
    public R<String> listDatapointsByWorkstationId() {
        
        //InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("dp/dpstart.json");
        String str;
        try {
            str = IOUtils.resourceToString("/dp/dpstart.json",  Charset.forName("utf8"));
        } catch (IOException e) {
            str = "error";
            e.printStackTrace();
        }
 
        return R.data(str);
    }
    
    
    @GetMapping({"/typelist"})
    @ApiOperation("采集类型列表")
    public R<List<CollectDeviceTypeVO>> typelist() {
        
        
        return R.data(typeService.typeList());
    }
    
    @GetMapping({"/lastP"})
    @ApiOperation("采集类型列表")
    public R<ProcessParameterVO> lastP() {//1656818952295661569_DeviceStatus
        ProcessParameterVO vo = this.pmapper.lastParameterNotEqValue(1656818952295661569L, "DeviceStatus", "2");
        ProcessParameterVO vo1 = this.pmapper.firstParameterEqValueGtTime(1656818952295661569L, "DeviceStatus", "2",System.currentTimeMillis()-20000);
        
        return R.data(vo);
    }
    
    
}