作者 钟来

对接plc

@@ -99,7 +99,7 @@ public class ControlDeviceConreoller extends BaseController { @@ -99,7 +99,7 @@ public class ControlDeviceConreoller extends BaseController {
99 String body = new String(bodyBytes, request.getCharacterEncoding()); 99 String body = new String(bodyBytes, request.getCharacterEncoding());
100 DeviceCommand deviceCommand = new DeviceCommand(); 100 DeviceCommand deviceCommand = new DeviceCommand();
101 deviceCommand.setDeviceId(deviceId); 101 deviceCommand.setDeviceId(deviceId);
102 - deviceCommand.setCommandType(CommandType.write); 102 + deviceCommand.setCommandType(CommandType.read);
103 deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class)); 103 deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class));
104 return rocketMqSendService.deviceControl(deviceCommand); 104 return rocketMqSendService.deviceControl(deviceCommand);
105 } 105 }
@@ -101,31 +101,36 @@ public class MNPLCProtocolParserFactoryImpl implements ProtocolParserFactory { @@ -101,31 +101,36 @@ public class MNPLCProtocolParserFactoryImpl implements ProtocolParserFactory {
101 number_name = keyArr[0]+"区"+keyArr[2]+"号"+iotProductPlcDevice.getName()+keyArr[2]; 101 number_name = keyArr[0]+"区"+keyArr[2]+"号"+iotProductPlcDevice.getName()+keyArr[2];
102 if("YEL".equals(identifier)) 102 if("YEL".equals(identifier))
103 { 103 {
104 - int type = jsonObject.get(key.replace("SENSOR","TYPE")).getAsInt();  
105 - if(type==0) 104 + String yuerlTypeKey = key.replace(data_identifier,"TYPE");
  105 + if (jsonObject.has(yuerlTypeKey))
106 { 106 {
107 - continue;  
108 - }  
109 - number += "_"+keyArr[3];  
110 - number_name += keyArr[3]+"号探头";  
111 - if (data_identifier.equals("SENSOR"))  
112 - {  
113 - switch (type) 107 + int type = jsonObject.get(yuerlTypeKey).getAsInt();
  108 + if(type==0)
114 { 109 {
115 - case 3:  
116 - data_identifier = "pH";  
117 - break;  
118 - case 5:  
119 - data_identifier = "dom";  
120 - break;  
121 - case 16:  
122 - data_identifier = "yw";  
123 - break;  
124 - case 17:  
125 - data_identifier = "yl";  
126 - break; 110 + continue;
  111 + }
  112 + number += "_"+keyArr[3];
  113 + number_name += keyArr[3]+"号探头";
  114 + if (data_identifier.equals("SENSOR"))
  115 + {
  116 + switch (type)
  117 + {
  118 + case 3:
  119 + data_identifier = "pH";
  120 + break;
  121 + case 5:
  122 + data_identifier = "dom";
  123 + break;
  124 + case 16:
  125 + data_identifier = "yw";
  126 + break;
  127 + case 17:
  128 + data_identifier = "yl";
  129 + break;
  130 + }
127 } 131 }
128 } 132 }
  133 +
129 } 134 }
130 } 135 }
131 136
@@ -28,6 +28,7 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto @@ -28,6 +28,7 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto
28 private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenServiceImpl.class); 28 private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenServiceImpl.class);
29 @Override 29 @Override
30 public NoticeMessageDto read(String deviceId, JsonObject jsonObject) { 30 public NoticeMessageDto read(String deviceId, JsonObject jsonObject) {
  31 + log.info("不支持读功能");
31 return null; 32 return null;
32 } 33 }
33 34
@@ -40,7 +41,7 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto @@ -40,7 +41,7 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto
40 noticeMessageDto.setTopic(topic); 41 noticeMessageDto.setTopic(topic);
41 noticeMessageDto.setTopicconfig(topicModel); 42 noticeMessageDto.setTopicconfig(topicModel);
42 43
43 - //将jsonObject里面的两层键值比如:{"1":{"key","value","key1",1}}提取成一层放在commdjson里面如{"key":"value","key1":1} 44 + //将{"0":"a,b,c","1":"a,b,c"}变成{"A_SYS_0_"}
44 JsonObject commdjson = flattenJsonObject(jsonObject); 45 JsonObject commdjson = flattenJsonObject(jsonObject);
45 46
46 noticeMessageDto.setCommd(commdjson.toString().getBytes()); 47 noticeMessageDto.setCommd(commdjson.toString().getBytes());
@@ -36,7 +36,8 @@ @@ -36,7 +36,8 @@
36 * LEVEL:液位值 36 * LEVEL:液位值
37 * MODE:运行模式 37 * MODE:运行模式
38 * OTHER:现场扩展参数 38 * OTHER:现场扩展参数
39 -* 39 +* YWJC: 液位计自动控制
  40 +* CXCLEAN: 冲洗次数清零
40 41
41 格式示例:`A_TLJ_1_RUN` 42 格式示例:`A_TLJ_1_RUN`
42 43
@@ -15,6 +15,7 @@ import org.springframework.stereotype.Controller; @@ -15,6 +15,7 @@ import org.springframework.stereotype.Controller;
15 import org.springframework.web.bind.annotation.PathVariable; 15 import org.springframework.web.bind.annotation.PathVariable;
16 import org.springframework.web.bind.annotation.RequestMapping; 16 import org.springframework.web.bind.annotation.RequestMapping;
17 import org.springframework.web.bind.annotation.RequestMethod; 17 import org.springframework.web.bind.annotation.RequestMethod;
  18 +import org.springframework.web.bind.annotation.ResponseBody;
18 19
19 import javax.servlet.http.HttpServletResponse; 20 import javax.servlet.http.HttpServletResponse;
20 import java.io.*; 21 import java.io.*;
@@ -29,6 +30,7 @@ public class LogController { @@ -29,6 +30,7 @@ public class LogController {
29 @Autowired 30 @Autowired
30 private DeviceCommandListenService deviceCommandListenService; 31 private DeviceCommandListenService deviceCommandListenService;
31 @ApiOperation("获取") 32 @ApiOperation("获取")
  33 + @ResponseBody
32 @RequestMapping(value = "getOperation_token",method = RequestMethod.GET) 34 @RequestMapping(value = "getOperation_token",method = RequestMethod.GET)
33 public String getOperation_token() 35 public String getOperation_token()
34 { 36 {
@@ -11,11 +11,12 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -11,11 +11,12 @@ import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.stereotype.Controller; 11 import org.springframework.stereotype.Controller;
12 import org.springframework.web.bind.annotation.RequestMapping; 12 import org.springframework.web.bind.annotation.RequestMapping;
13 import org.springframework.web.bind.annotation.RequestMethod; 13 import org.springframework.web.bind.annotation.RequestMethod;
  14 +import org.springframework.web.bind.annotation.RestController;
14 15
15 import java.util.Map; 16 import java.util.Map;
16 17
17 @Api(tags = "系统运行接口") 18 @Api(tags = "系统运行接口")
18 -@Controller 19 +@RestController
19 @RequestMapping("/sys") 20 @RequestMapping("/sys")
20 public class SysConfigController { 21 public class SysConfigController {
21 22