Bläddra i källkod

通风口开发

hanqingsong 4 år sedan
förälder
incheckning
d4937eee78

+ 20 - 0
src/main/java/com/chinaitop/depot/intelligent/common/ConstantClass.java

@@ -0,0 +1,20 @@
1
+package com.chinaitop.depot.intelligent.common;
2
+
3
+/**
4
+ * @author qingsong.han
5
+ * @description: 常量类
6
+ * @create 2021-09-13 16:49
7
+ */
8
+public class ConstantClass {
9
+    /**
10
+     * 用于字符串拼接类型判定
11
+     */
12
+    public static final int TYPE_BUILDER = 1;
13
+    public static final int TYPE_BUFFER = 2;
14
+    // 清除控制柜已发送指令(PLC断开操作-控制柜下-指令为3位0x)
15
+    public static final String CLEAN_NLL = "00 00 00";
16
+    // 通风口 操作状态
17
+    public static final String TYPE_NO = "1"; // 开启
18
+    public static final String TYPE_OFF = "0"; // 关闭
19
+
20
+}

+ 53 - 0
src/main/java/com/chinaitop/depot/intelligent/factoryObject/StringJoinFactory.java

@@ -0,0 +1,53 @@
1
+package com.chinaitop.depot.intelligent.factoryObject;
2
+
3
+import com.chinaitop.depot.intelligent.common.ConstantClass;
4
+import com.chinaitop.depot.intelligent.factoryObject.factoryInterface.StringFactory;
5
+import org.springframework.stereotype.Component;
6
+
7
+/**
8
+ * @author qingsong.han
9
+ * @description: 用于字符串连接简单工厂模式 类
10
+ * @create 2021-09-08 10:46
11
+ */
12
+@Component
13
+public class StringJoinFactory implements StringFactory {
14
+    /**
15
+     * 创建拼接字符串方法
16
+     *
17
+     * @param type  1: stringBuild,2: stringBuffer 默认 stringBuild
18
+     * @param value 参数 按照传入的顺序拼接(例: a b c = abc)
19
+     * @return string
20
+     */
21
+    @Override
22
+    public String joinString(int type, String... value) {
23
+        switch (type) {
24
+            case ConstantClass.TYPE_BUILDER:
25
+                return stringBuilderJoin(value);
26
+            case ConstantClass.TYPE_BUFFER:
27
+                return stringBufferJoin(value);
28
+            default:
29
+                return stringBuilderJoin(value);
30
+        }
31
+    }
32
+
33
+    /**
34
+     * 内部拼接方法
35
+     */
36
+    private String stringBuilderJoin(String... value) {
37
+        StringBuilder builder = new StringBuilder();
38
+        for (String s : value) {
39
+            builder.append(s);
40
+        }
41
+        return builder.toString();
42
+    }
43
+
44
+    @SuppressWarnings("all")
45
+    private String stringBufferJoin(String... value) {
46
+        StringBuffer buffer = new StringBuffer();
47
+        for (String s : value) {
48
+            buffer.append(s);
49
+        }
50
+        return buffer.toString();
51
+    }
52
+
53
+}

+ 19 - 0
src/main/java/com/chinaitop/depot/intelligent/factoryObject/factoryInterface/StringFactory.java

@@ -0,0 +1,19 @@
1
+package com.chinaitop.depot.intelligent.factoryObject.factoryInterface;
2
+
3
+/**
4
+ * @author qingsong.han
5
+ * @description: 简单工厂-字符串接口
6
+ * @create 2021-09-15 15:51
7
+ */
8
+public interface StringFactory {
9
+
10
+    /**
11
+     * 字符串拼接接口
12
+     * @param type 1(ConstantClass.TYPE_BUILDER): StringBuilder
13
+     *             2(ConstantClass.TYPE_BUFFER): StringBuffer
14
+     * @param value 传入参数需按拼接先后顺序传入 (例: a b c => abc)
15
+     * @return string
16
+     */
17
+    String joinString(int type, String... value);
18
+
19
+}

+ 144 - 0
src/main/java/com/chinaitop/depot/intelligent/socket/SocketServer.java

@@ -0,0 +1,144 @@
1
+package com.chinaitop.depot.intelligent.socket;
2
+
3
+import com.chinaitop.depot.intelligent.common.ConstantClass;
4
+import com.chinaitop.depot.intelligent.factoryObject.StringJoinFactory;
5
+import com.chinaitop.depot.intelligent.factoryObject.factoryInterface.StringFactory;
6
+import com.chinaitop.depot.intelligent.utils.DataUtils;
7
+import org.slf4j.Logger;
8
+import org.slf4j.LoggerFactory;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.stereotype.Component;
11
+
12
+import java.io.IOException;
13
+import java.io.InputStream;
14
+import java.io.OutputStream;
15
+import java.net.*;
16
+import java.time.LocalDateTime;
17
+
18
+/**
19
+ * @author qingsong.han
20
+ * @description: socketServer 服务监听
21
+ * @create 2021-09-06 16:52
22
+ */
23
+@Component
24
+public class SocketServer {
25
+    private final static Logger log = LoggerFactory.getLogger(SocketServer.class);
26
+    /**
27
+     * 硬件配置端口 client 为 ip:2001
28
+     * SocketServer 监听地址为10.100.208.233:2002(衡水深州库固定SocketClient地址为10.100.208.233)
29
+     */
30
+    private static final int port = 0x7D2;
31
+    // 连续请求积压数>1,否则为50
32
+    private static final int backlog = 3;
33
+    // 设置连接超时时间
34
+    private static final int timeout = 0x2BF20;
35
+    // 休眠时间
36
+    private static final long sleepTime = 0x3E8L;
37
+    //计数防止死循环
38
+    private int temp = 0;
39
+    private static final int tempCount = 0x29;
40
+    // 本类注入ServerSocket
41
+    private ServerSocket serverSocket;
42
+    // client 默认端口全部为2001
43
+    private static final String clientPort = ":2001";
44
+    // 注入字符串拼接工厂接口
45
+    private StringFactory stringFactory;
46
+
47
+    @Autowired
48
+    public void setStringFactory(StringFactory stringFactory) {
49
+        this.stringFactory = stringFactory;
50
+    }
51
+
52
+    public SocketServer() throws IOException {
53
+        /*
54
+         * 获取服务器ip.硬件配置固定地址,所以服务器也必须固定
55
+         * 衡水深州内网固定服务端(DNS):
56
+         * 测试环境
57
+         *  IP地址: 10.100.208.233
58
+         *  子网掩码: 255.255.254.0
59
+         *  默认网关: 10.100.209.254
60
+         * 生产环境(服务器ip地址)
61
+         *  IP地址: 10.100.209.27
62
+         */
63
+        InetAddress localHost = InetAddress.getLocalHost(); // 获取本机ip
64
+        serverSocket = new ServerSocket(port, backlog, localHost); // 连接请求队列的长度为3
65
+        log.info("SocketServer服务器启动!");
66
+    }
67
+
68
+    public void service(String ip, String orders) {
69
+        while (true) {
70
+            Socket socket = null;
71
+            try {
72
+                serverSocket.setSoTimeout(timeout); // 连接超时时间
73
+                socket = serverSocket.accept(); // 从连接请求队列中取出连接
74
+                String clientAddress = socket.getRemoteSocketAddress().toString(); // 获取远程客户机
75
+                log.info("New connection accepted: {}", clientAddress);
76
+                // 连接字符串
77
+                String clientIP = stringFactory.joinString(ConstantClass.TYPE_BUILDER, "/", ip, clientPort);
78
+                // 判断是否存在client 连接(ip:2001)
79
+                if (clientAddress.equals(clientIP)) {
80
+                    log.info(LocalDateTime.now() + "***连接成功,设备的ip及其端口号: {}", socket.getRemoteSocketAddress());
81
+                    outByte(socket, orders); // 输出指令
82
+                    log.info(LocalDateTime.now() + "***指令发送成功: {}", orders);
83
+                    inputByte(socket); // 接收返回
84
+                    // 清除PLC控制柜指令,使其断开连接上一条指令(如有其它断开PLC指令使用else if 添加判断)
85
+                    Thread.sleep(sleepTime);
86
+                    int length = orders.length();
87
+                    if (length == ConstantClass.CLEAN_NLL.length()) {
88
+                        outByte(socket, ConstantClass.CLEAN_NLL);
89
+                        log.info(LocalDateTime.now() + "***PLC断开指令发送成功:{}", ConstantClass.CLEAN_NLL);
90
+                    }
91
+                    break;
92
+                }
93
+            } catch (Exception e) {
94
+                e.printStackTrace();
95
+            } finally {
96
+                try {
97
+                    if (socket != null)
98
+                        socket.close();
99
+                } catch (IOException e) {
100
+                    e.printStackTrace();
101
+                }
102
+            }
103
+            temp++;
104
+            if (temp == tempCount) {
105
+                log.info("设备ID配置有误,与数据库没有匹配的设备");
106
+                break;
107
+            }
108
+        }
109
+    }
110
+
111
+    /**
112
+     * 发送socket输出流指令编码
113
+     *
114
+     * @param socket tcp
115
+     * @param orders 十六进制字符串编码
116
+     * @throws IOException
117
+     */
118
+    private void outByte(Socket socket, String orders) throws IOException {
119
+        // 字符串转十六进制byte数组
120
+        byte[] bytes = DataUtils.hexStringToByteArray(orders);
121
+        // socket输出流
122
+        OutputStream os = socket.getOutputStream();
123
+        os.write(bytes);
124
+        os.flush();
125
+    }
126
+
127
+    /**
128
+     * TODO 未使用 没有返回编码解释 已测出: 成功: 01, 启动或关闭超时: A3 本地模式: 54
129
+     * TODO 注: 如何远程清除故障
130
+     * socket 接收PLC调用回写编码
131
+     *
132
+     * @param socket tcp
133
+     * @throws IOException
134
+     */
135
+    private void inputByte(Socket socket) throws IOException {
136
+        // socket 接收返回输入信号
137
+        InputStream inputStream = socket.getInputStream();
138
+        int read = inputStream.read();
139
+        // 十进制转十六进制 占位2 并格式化大写(示例: 01)
140
+        String result = String.format("%02x", read).toUpperCase();
141
+        log.info(LocalDateTime.now() + "***接收到PLC返回编码: {}", result);
142
+    }
143
+
144
+}

+ 56 - 57
src/main/java/com/chinaitop/depot/intelligent/ventilation/controller/AerationRecordController.java

@@ -1,8 +1,7 @@
1 1
 package com.chinaitop.depot.intelligent.ventilation.controller;
2 2
 
3
-import com.chinaitop.depot.intelligent.socket.SocketClient;
4
-import com.chinaitop.depot.intelligent.utils.ConstUtils;
5
-import com.chinaitop.depot.intelligent.utils.HexConvertUtils;
3
+import com.chinaitop.depot.intelligent.common.ConstantClass;
4
+import com.chinaitop.depot.intelligent.socket.SocketServer;
6 5
 import com.chinaitop.depot.intelligent.utils.ParameterUtil;
7 6
 import com.chinaitop.depot.intelligent.ventilation.model.TCtldevinfo;
8 7
 import com.chinaitop.depot.intelligent.ventilation.model.TCtldevinfoBype;
@@ -27,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
27 26
 import org.springframework.web.bind.annotation.RequestMethod;
28 27
 import org.springframework.web.bind.annotation.RestController;
29 28
 
29
+import javax.annotation.Resource;
30 30
 import java.text.SimpleDateFormat;
31 31
 import java.util.List;
32 32
 
@@ -39,9 +39,10 @@ public class AerationRecordController {
39 39
     private AerationRecordService aerationRecordService;
40 40
     @Autowired
41 41
     private AerationParameterService aerationParameterService;
42
-
43 42
     @Autowired
44 43
     private AerationBypeService bypeService;
44
+    @Resource
45
+    private SocketServer socketServer;
45 46
 
46 47
 
47 48
     @RequestMapping(value = "/getList", method = RequestMethod.GET)
@@ -52,13 +53,13 @@ public class AerationRecordController {
52 53
             @ApiImplicitParam(name = "vDevKindCode", value = "设备类型", paramType = "query"),
53 54
             @ApiImplicitParam(name = "vCfCode", value = "仓库名称", paramType = "query")
54 55
     })
55
-    public ResponseEntity<PageInfo<TVentilation>> getList(Integer pageNum, Integer pageSize, String vCfCode, String vDevKindCode,String type) {
56
+    public ResponseEntity<PageInfo<TVentilation>> getList(Integer pageNum, Integer pageSize, String vCfCode, String vDevKindCode, String type) {
56 57
         List<TVentilation> list = null;
57 58
         try {
58 59
             if (null != pageNum && null != pageSize) {
59 60
                 PageHelper.startPage(pageNum, pageSize);
60 61
             }
61
-            list = aerationRecordService.getList(vCfCode, vDevKindCode,type);
62
+            list = aerationRecordService.getList(vCfCode, vDevKindCode, type);
62 63
         } catch (Exception e) {
63 64
             e.printStackTrace();
64 65
             ResponseEntity.failed(e.getMessage());
@@ -67,10 +68,7 @@ public class AerationRecordController {
67 68
         return ResponseEntity.ok(pageInfo);
68 69
     }
69 70
 
70
-    @Autowired
71
-    private SocketClient socketClient;
72
-
73
-  //新增
71
+    //新增
74 72
     @RequestMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
75 73
     @ApiOperation(value = "数据更新与添加", notes = "数据更新与添加")
76 74
     @ApiImplicitParams({
@@ -82,59 +80,47 @@ public class AerationRecordController {
82 80
     public ResponseEntity save(String task, String aerationTaskControl, Integer orgId, String saveType) {
83 81
         ObjectMapper mapper = new ObjectMapper();
84 82
         mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
85
-        String result = "";
86 83
         try {
87 84
             //注意,这里如果打开通风设备关闭不了的话请查看---通风操作打开的需要通风操作关闭,熏蒸操作并不能管理通风操作的通风设备。
88 85
             if (ParameterUtil.isnotnull(saveType) && ParameterUtil.isequal(saveType, "fumigationData")) {//新增熏蒸的通风控制
89 86
                 aerationRecordService.saveFumigation(task, aerationTaskControl, orgId);
90 87
             } else {//新增通风控制
91 88
                 // 通风指令发送
92
-            	
93
-            	if(task!=null){
94
-            		
95
-            		String devinfo = "";
96
-            		if(!task.contains("[") && !task.contains("]")){
97
-            		   devinfo = "["+task+"]";  //task 包括id和vstatue
98
-            		}else{
99
-            			devinfo = task;
100
-            		}
101
-            		List<TCtldevinfo> idObject = mapper.readValue(devinfo, new TypeReference<List<TCtldevinfo>>() {});
102
-            		TCtldevinfo tCtldevinfo = new TCtldevinfo();
103
-	                for(int i = 0;i<idObject.size();i++){
104
-	                    tCtldevinfo = aerationParameterService.getById(idObject.get(i).getId());
105
-	                  /*  tCtldevinfo.setVstatue(idObject.get(i).getVstatue());
106
-                        String dir = ConstUtils.directiveJoint("00", tCtldevinfo.getVcfcode(), tCtldevinfo.getVdevcode(), tCtldevinfo.getVdevkindcode(), "0" + tCtldevinfo.getVstatue(), "");
107
-	                    System.out.println(dir);
108
-	                    // 16进制字符串转byte数组
109
-	                    byte[] bytes = HexConvertUtils.hexStringToByte(dir);
110
-	                    // 发送指令
111
-//	                    String soc = socketClient.startClient(bytes);*/
112
-//	                    result = TypeEnum.resultDispose(soc);
89
+                if (task != null) {
90
+                    String devinfo = "";
91
+                    if (!task.contains("[") && !task.contains("]")) {
92
+                        devinfo = "[" + task + "]";  //task 包括id和vstatue
93
+                    } else {
94
+                        devinfo = task;
95
+                    }
96
+                    List<TCtldevinfo> idObject = mapper.readValue(devinfo, new TypeReference<List<TCtldevinfo>>() {
97
+                    });
98
+                    for (int i = 0; i < idObject.size(); i++) {
99
+                        TCtldevinfo tCtldevinfo = aerationParameterService.getById(idObject.get(i).getId());
113 100
                         //获取设备指令信息
114 101
                         TCtldevinfoBype aByte = bypeService.getByte(Integer.valueOf(tCtldevinfo.getVdevkindcode()));
115
-                        //0:关闭,1:打开,2:反转,3:停止
116
-                        String vstatue = tCtldevinfo.getVstatue();
117
-                        String tcStop = "";
118
-                        if (vstatue.equals("0")){
119
-                            tcStop = aByte.getTcStop();
120
-                        }else if (vstatue.equals("1")){
121
-                            tcStop = aByte.getTcStart();
102
+                        //0:关闭,1:打开,2:反转,3:停止 上次操作在库里保存的 状态
103
+//                        String vstatue = tCtldevinfo.getVstatue();
104
+                        // 用户操作的是开启还是关闭
105
+                        String userUseState = idObject.get(i).getVstatue();
106
+                        String stopOrStart = "";
107
+                        if (userUseState.equals(ConstantClass.TYPE_OFF)) {
108
+                            stopOrStart = aByte.getTcStop();
109
+                        } else if (userUseState.equals(ConstantClass.TYPE_NO)) {
110
+                            stopOrStart = aByte.getTcStart();
122 111
                         }
123
-
124
-                        aerationRecordService.switchingMethod(tCtldevinfo.getCtIp(),tcStop);
112
+                        // 调用socketServer,发送指令
113
+                        socketServer.service(tCtldevinfo.getCtIp(), stopOrStart);// 新增通风作业记录
125 114
                         aerationRecordService.save(tCtldevinfo, aerationTaskControl, orgId);
126
-                      /*  if(TypeEnum.S_SOH.getDesc().equals(result) && tCtldevinfo.getVstatue().equals(tCtldevinfo.getVstatue())){
127
-	                    }*/
128
-	                    Thread.currentThread().sleep(2000);
129
-	                }
130
-            	}
131
-            	
115
+                    }
116
+                }
117
+
132 118
             }
133 119
         } catch (Exception e) {
134 120
             e.printStackTrace();
135
-            return ResponseEntity.failed("设备连接异常!!");
121
+            return ResponseEntity.failed(TypeEnum.S_STX.getDesc());
136 122
         }
137
-        return ResponseEntity.ok(result);
123
+        return ResponseEntity.ok(TypeEnum.C_SOH.getDesc());
138 124
     }
139 125
 
140 126
     //根据仓房和设备名称查询通风的记录
@@ -154,23 +140,23 @@ public class AerationRecordController {
154 140
         return ResponseEntity.ok(tVentilation);
155 141
     }
156 142
 
157
-    
143
+
158 144
     @RequestMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
159 145
     @ApiOperation(value = "数据更新与添加", notes = "数据更新与添加")
160 146
     @ApiImplicitParams({
161 147
             @ApiImplicitParam(name = "tVentilationJson", value = "表数据json串", paramType = "form")
162 148
     })
163
-    public ResponseEntity add(String tVentilationJson,Integer orgId) {
149
+    public ResponseEntity add(String tVentilationJson, Integer orgId) {
164 150
         try {
165
-        	aerationRecordService.add(tVentilationJson,orgId);
151
+            aerationRecordService.add(tVentilationJson, orgId);
166 152
         } catch (Exception e) {
167 153
             e.printStackTrace();
168 154
             ResponseEntity.failed(e.getMessage());
169 155
         }
170 156
         return ResponseEntity.ok();
171 157
     }
172
-    
173
-    
158
+
159
+
174 160
     @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
175 161
     @ApiOperation(value = "根据粮情id删除信息", notes = "根据粮情id删除信息")
176 162
     @ApiImplicitParams({
@@ -188,19 +174,32 @@ public class AerationRecordController {
188 174
         }
189 175
         return ResponseEntity.failed("ID数据有误!");
190 176
     }
191
-    
177
+
192 178
     @RequestMapping(value = "/getById", method = RequestMethod.POST)
193 179
     @ApiOperation(value = "根据id查询信息", notes = "根据id查询信息")
194 180
     @ApiImplicitParams({
195 181
             @ApiImplicitParam(name = "id", value = "id", paramType = "query")
196 182
     })
197 183
     public ResponseEntity<TVentilation> getById(String id) {
198
-    	TVentilation tVentilation = null;
184
+        TVentilation tVentilation = null;
199 185
         if (StringUtils.isNotBlank(id)) {
200
-        	tVentilation = aerationRecordService.getById(id);
186
+            tVentilation = aerationRecordService.getById(id);
201 187
         } else {
202 188
             return ResponseEntity.failed("ID数据有误!");
203 189
         }
204 190
         return ResponseEntity.ok(tVentilation);
205 191
     }
192
+
193
+
194
+    /**
195
+     * TODO /test 测试ServerSocket 接口
196
+     * http://localhost:9028/intelligents/aerationRecord/test?ip=10.100.208.225&orders=AA 00 00
197
+     * @param ip
198
+     * @param orders
199
+     */
200
+    @RequestMapping(value = "/test", method = RequestMethod.GET)
201
+    public void test(String ip, String orders) {
202
+        socketServer.service(ip, orders);
203
+    }
204
+
206 205
 }

+ 1 - 1
src/main/java/com/chinaitop/depot/intelligent/ventilation/service/AerationRecordService.java

@@ -25,5 +25,5 @@ public interface AerationRecordService {
25 25
 
26 26
 	TVentilation getById(String id);
27 27
 
28
-	void switchingMethod(String ip,String bype)throws Exception;
28
+//	void switchingMethod(String ip,String bype)throws Exception;
29 29
 }

+ 3 - 3
src/main/java/com/chinaitop/depot/intelligent/ventilation/service/impl/AerationParameterServiceImpl.java

@@ -66,11 +66,11 @@ public class AerationParameterServiceImpl implements AerationParameterService {
66 66
 //				SendEntity.cxfFactor().saveWindDevice(SendEntity.sendAndConvert(jsonObject, "U"));
67 67
 			} else {
68 68
 				// 获取Max+1值
69
-				Map<String, Object> valueMax = wareHouseBasicInfoService.getCode("t_ctldevinfo", "sitecode", "vdevcode", null);
69
+				Map<String, Object> valueMax = wareHouseBasicInfoService.getCode("t_ctldevinfo", "vdevcode");
70 70
 				// 替换值
71 71
 //				jsonObject.put("vdevcode",valueMax.get("column2"));
72
-				tCtldevinfo.setVdevcode(valueMax.get("column2").toString());
73
-				tCtldevinfo.setId(uUidUtils.getCodeId(String.valueOf(orgId), "t_ctldevinfo"));
72
+				tCtldevinfo.setVdevcode(valueMax.get("column1").toString());
73
+				tCtldevinfo.setId(UuidUtils.getCode());
74 74
 				tCtldevinfo.setDelFlag(1); //未删除
75 75
                 tCtldevinfoMapper.insert(tCtldevinfo);
76 76
 				// 推送数据并返回结果

+ 5 - 33
src/main/java/com/chinaitop/depot/intelligent/ventilation/service/impl/AerationRecordServiceImpl.java

@@ -1,6 +1,7 @@
1 1
 package com.chinaitop.depot.intelligent.ventilation.service.impl;
2 2
 
3 3
 import com.alibaba.fastjson.JSONObject;
4
+import com.chinaitop.depot.intelligent.common.ConstantClass;
4 5
 import com.chinaitop.depot.intelligent.fumigation.model.TFumigationPlan;
5 6
 import com.chinaitop.depot.intelligent.utils.DataUtils;
6 7
 import com.chinaitop.depot.intelligent.utils.JsonToObjectUtils;
@@ -40,8 +41,8 @@ public class AerationRecordServiceImpl implements AerationRecordService {
40 41
     @Autowired
41 42
     private AerationParameterService aerationParameterService;
42 43
 
43
-    @Autowired
44
-    private ServerSocket serverSocket;
44
+    /*@Autowired
45
+    private ServerSocket serverSocket;*/
45 46
 
46 47
     @Override
47 48
     public List<TVentilation> getList(String vCfCode, String vDevKindCode, String type) {
@@ -80,7 +81,7 @@ public class AerationRecordServiceImpl implements AerationRecordService {
80 81
             tVentilation.setvDistinguishState(0); //通风
81 82
             tVentilation.setvUpdateTime(new Date());
82 83
 
83
-            if (tCtldevinfo.getVstatue().equals(1)) { //vState的状态是手动的状态  vStatue是系统里的  1是打开
84
+            if (tCtldevinfo.getVstatue().equals(ConstantClass.TYPE_NO)) { //vState的状态是手动的状态  vStatue是系统里的  1是打开
84 85
                 String id = UuidUtils.getCode();
85 86
                 Date date1 = new Date();
86 87
                 tVentilation.setvStartTime(date1); //开始时间
@@ -99,7 +100,7 @@ public class AerationRecordServiceImpl implements AerationRecordService {
99 100
                 tJobMapper.updateByKey(tJob);
100 101
             }
101 102
 
102
-            if (tCtldevinfo.getVstatue().equals(0)) { //0是关闭
103
+            if (tCtldevinfo.getVstatue().equals(ConstantClass.TYPE_OFF)) { //0是关闭
103 104
                 Date date = new Date();
104 105
                 //记录表
105 106
                 TVentilationExample example = new TVentilationExample();
@@ -275,33 +276,4 @@ public class AerationRecordServiceImpl implements AerationRecordService {
275 276
         // TODO Auto-generated method stub
276 277
         return tVentilationMapper.selectByPrimaryKey(id);
277 278
     }
278
-
279
-    @Override
280
-    public void switchingMethod(String ip, String oders) throws Exception {
281
-        //计数防止死循环
282
-        int temp = 0;
283
-        while (true) {
284
-            //超过10秒没有连接返回数据自动断开连接
285
-            serverSocket.setSoTimeout(10000);
286
-            Socket socket = serverSocket.accept();
287
-            String sket = socket.getRemoteSocketAddress().toString();
288
-            if (sket.contains(ip)) {
289
-                log.info(new Date().toString() + "***连接成功,设备的ip及其端口号***" + socket.getRemoteSocketAddress());
290
-                byte[] bytes1 = DataUtils.hexStringToByteArray(oders);
291
-                log.info(new Date().toString() + "***实际发送指令:" + oders);
292
-                OutputStream os = socket.getOutputStream();
293
-                os.write(bytes1);
294
-                log.info(new Date().toString() + "***指令发送成功");
295
-                os.flush();
296
-            }
297
-            if (socket != null) {
298
-                socket.close();
299
-            }
300
-            temp++;
301
-            if (temp == 41) {
302
-                log.info("设备ID配置有误,与数据库没有匹配的设备");
303
-                break;
304
-            }
305
-        }
306
-    }
307 279
 }

+ 4 - 1
src/main/java/com/unissoft/model/TypeEnum.java

@@ -12,7 +12,10 @@ public enum TypeEnum {
12 12
     S_EOT("S_EOT", "未知原因!"),
13 13
     S_2D_SOH("S_2D_SOH", "本地模式,无法远程控制!"),
14 14
     S_EM("S_EM", "仓房号为空!"),
15
-    SM("SM", "设备正忙!");
15
+    SM("SM", "设备正忙!"),
16
+    // 通风
17
+    C_SOH("C_SOH", "指令发送成功!")
18
+    ;
16 19
 
17 20
     private String code;
18 21
     private String desc;