|
|
@@ -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
|
}
|