|
|
@@ -1,9 +1,26 @@
|
|
1
|
1
|
package com.chinaitop.depot.intelligent.ventilation.controller;
|
|
2
|
2
|
|
|
|
3
|
+import java.text.SimpleDateFormat;
|
|
|
4
|
+import java.util.List;
|
|
|
5
|
+
|
|
|
6
|
+import javax.annotation.Resource;
|
|
|
7
|
+import javax.validation.constraints.NotNull;
|
|
|
8
|
+
|
|
|
9
|
+import org.apache.commons.lang.StringUtils;
|
|
|
10
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
11
|
+import org.springframework.http.MediaType;
|
|
|
12
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
13
|
+import org.springframework.util.MultiValueMap;
|
|
|
14
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
15
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
16
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
17
|
+
|
|
|
18
|
+import com.chinaitop.depot.intelligent.grainsituation.service.TemperatureRecordService;
|
|
3
|
19
|
import com.chinaitop.depot.intelligent.socket.SocketClient;
|
|
4
|
20
|
import com.chinaitop.depot.intelligent.utils.ConstUtils;
|
|
5
|
21
|
import com.chinaitop.depot.intelligent.utils.HexConvertUtils;
|
|
6
|
22
|
import com.chinaitop.depot.intelligent.utils.ParameterUtil;
|
|
|
23
|
+import com.chinaitop.depot.intelligent.utils.RemoteControlUtil;
|
|
7
|
24
|
import com.chinaitop.depot.intelligent.ventilation.model.TCtldevinfo;
|
|
8
|
25
|
import com.chinaitop.depot.intelligent.ventilation.model.TVentilation;
|
|
9
|
26
|
import com.chinaitop.depot.intelligent.ventilation.service.AerationParameterService;
|
|
|
@@ -14,20 +31,13 @@ import com.github.pagehelper.PageHelper;
|
|
14
|
31
|
import com.github.pagehelper.PageInfo;
|
|
15
|
32
|
import com.unissoft.model.ResponseEntity;
|
|
16
|
33
|
import com.unissoft.model.TypeEnum;
|
|
|
34
|
+
|
|
17
|
35
|
import io.swagger.annotations.Api;
|
|
18
|
36
|
import io.swagger.annotations.ApiImplicitParam;
|
|
19
|
37
|
import io.swagger.annotations.ApiImplicitParams;
|
|
20
|
38
|
import io.swagger.annotations.ApiOperation;
|
|
21
|
|
-import org.apache.commons.lang.StringUtils;
|
|
22
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
23
|
|
-import org.springframework.http.MediaType;
|
|
24
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
25
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
26
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
27
|
|
-
|
|
28
|
|
-import java.text.SimpleDateFormat;
|
|
29
|
|
-import java.util.List;
|
|
30
|
39
|
|
|
|
40
|
+@SuppressWarnings("all")
|
|
31
|
41
|
@RestController
|
|
32
|
42
|
@RequestMapping(value = "/intelligents/aerationRecord")
|
|
33
|
43
|
@Api(value = "AerationRecordController", description = "通风记录控制类")
|
|
|
@@ -45,15 +55,18 @@ public class AerationRecordController {
|
|
45
|
55
|
@ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
|
|
46
|
56
|
@ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query"),
|
|
47
|
57
|
@ApiImplicitParam(name = "vDevKindCode", value = "设备类型", paramType = "query"),
|
|
48
|
|
- @ApiImplicitParam(name = "vCfCode", value = "仓库名称", paramType = "query")
|
|
|
58
|
+ @ApiImplicitParam(name = "vCfCode", value = "仓房编号", paramType = "query"),
|
|
|
59
|
+ @ApiImplicitParam(name = "type", value = "仓房编号", paramType = "query"),
|
|
|
60
|
+ @ApiImplicitParam(name = "orgId", value = "单位ID", paramType = "query")
|
|
49
|
61
|
})
|
|
50
|
|
- public ResponseEntity<PageInfo<TVentilation>> getList(Integer pageNum, Integer pageSize, String vCfCode, String vDevKindCode,String type) {
|
|
|
62
|
+ public ResponseEntity<PageInfo<TVentilation>> getList(Integer pageNum, Integer pageSize, String vCfCode, String vDevKindCode,String type,
|
|
|
63
|
+ @NotNull String orgId) {
|
|
51
|
64
|
List<TVentilation> list = null;
|
|
52
|
65
|
try {
|
|
53
|
66
|
if (null != pageNum && null != pageSize) {
|
|
54
|
67
|
PageHelper.startPage(pageNum, pageSize);
|
|
55
|
68
|
}
|
|
56
|
|
- list = aerationRecordService.getList(vCfCode, vDevKindCode,type);
|
|
|
69
|
+ list = aerationRecordService.getList(vCfCode, vDevKindCode,type, orgId);
|
|
57
|
70
|
} catch (Exception e) {
|
|
58
|
71
|
e.printStackTrace();
|
|
59
|
72
|
ResponseEntity.failed(e.getMessage());
|
|
|
@@ -65,8 +78,13 @@ public class AerationRecordController {
|
|
65
|
78
|
@Autowired
|
|
66
|
79
|
private SocketClient socketClient;
|
|
67
|
80
|
|
|
68
|
|
- //新增
|
|
69
|
|
- @RequestMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
|
|
|
81
|
+ @Autowired
|
|
|
82
|
+ private TemperatureRecordService temperatureRecordService;
|
|
|
83
|
+
|
|
|
84
|
+ @Resource
|
|
|
85
|
+ private RemoteControlUtil remoteControlUtil;
|
|
|
86
|
+
|
|
|
87
|
+ @RequestMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
|
|
70
|
88
|
@ApiOperation(value = "数据更新与添加", notes = "数据更新与添加")
|
|
71
|
89
|
@ApiImplicitParams({
|
|
72
|
90
|
@ApiImplicitParam(name = "task", value = "所有id的Sting", paramType = "form"),
|
|
|
@@ -74,63 +92,79 @@ public class AerationRecordController {
|
|
74
|
92
|
@ApiImplicitParam(name = "orgId", value = "当前登录人组织id", paramType = "form"),
|
|
75
|
93
|
@ApiImplicitParam(name = "saveType", value = "存储类型", paramType = "form")
|
|
76
|
94
|
})
|
|
77
|
|
- public ResponseEntity save(String task, String aerationTaskControl, Integer orgId, String saveType) {
|
|
78
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
79
|
|
- mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
|
80
|
|
- String result = "";
|
|
81
|
|
- try {
|
|
82
|
|
- //注意,这里如果打开通风设备关闭不了的话请查看---通风操作打开的需要通风操作关闭,熏蒸操作并不能管理通风操作的通风设备。
|
|
83
|
|
- if (ParameterUtil.isnotnull(saveType) && ParameterUtil.isequal(saveType, "fumigationData")) {//新增熏蒸的通风控制
|
|
84
|
|
- aerationRecordService.saveFumigation(task, aerationTaskControl, orgId);
|
|
85
|
|
- } else {//新增通风控制
|
|
86
|
|
- // 通风指令发送
|
|
87
|
|
-
|
|
88
|
|
- if(task!=null){
|
|
89
|
|
-
|
|
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
|
|
- TCtldevinfo tCtldevinfo = new TCtldevinfo();
|
|
98
|
|
- for(int i = 0;i<idObject.size();i++){
|
|
99
|
|
- tCtldevinfo = aerationParameterService.getById(idObject.get(i).getId());
|
|
100
|
|
- tCtldevinfo.setvState(Integer.valueOf(idObject.get(i).getVstatue()));
|
|
101
|
|
- String dir = ConstUtils.directiveJoint("00", tCtldevinfo.getVcfcode(), tCtldevinfo.getVdevcode(), tCtldevinfo.getVdevkindcode(), "0" + tCtldevinfo.getVstatue(), "");
|
|
102
|
|
- System.out.println(dir);
|
|
103
|
|
- // 16进制字符串转byte数组
|
|
104
|
|
- byte[] bytes = HexConvertUtils.hexStringToByte(dir);
|
|
105
|
|
- // 发送指令
|
|
106
|
|
- String soc = socketClient.startClient(bytes);
|
|
107
|
|
- result = TypeEnum.resultDispose(soc);
|
|
108
|
|
- if(TypeEnum.S_SOH.getDesc().equals(result) && tCtldevinfo.getvState()!=Integer.valueOf(tCtldevinfo.getVstatue())){
|
|
109
|
|
- aerationRecordService.save(tCtldevinfo, aerationTaskControl, orgId);
|
|
110
|
|
- }
|
|
111
|
|
- Thread.currentThread().sleep(2000);
|
|
112
|
|
- }
|
|
113
|
|
- }
|
|
114
|
|
-
|
|
115
|
|
- }
|
|
116
|
|
- } catch (Exception e) {
|
|
117
|
|
- e.printStackTrace();
|
|
118
|
|
- return ResponseEntity.failed("设备连接异常!!");
|
|
119
|
|
- }
|
|
120
|
|
- return ResponseEntity.ok(result);
|
|
|
95
|
+ public ResponseEntity save(String task, String aerationTaskControl, @NotNull Integer orgId, String saveType) {
|
|
|
96
|
+
|
|
|
97
|
+ // 1.获取库端url
|
|
|
98
|
+ String url = temperatureRecordService.getRemoteUrl(orgId.toString());
|
|
|
99
|
+ if (StringUtils.isBlank(url))
|
|
|
100
|
+ return ResponseEntity.failed("库端硬件地址未配置!");
|
|
|
101
|
+ // 2.封装请求数据
|
|
|
102
|
+ MultiValueMap<String, Object> requestEntity = new LinkedMultiValueMap<>();
|
|
|
103
|
+ requestEntity.add("task", task);
|
|
|
104
|
+ requestEntity.add("aerationTaskControl", aerationTaskControl);
|
|
|
105
|
+ requestEntity.add("orgId", orgId);
|
|
|
106
|
+ requestEntity.add("saveType", saveType);
|
|
|
107
|
+ return remoteControlUtil.remoteScan(
|
|
|
108
|
+ String.format("%s%s", url, remoteControlUtil.xzSave),
|
|
|
109
|
+ requestEntity, "POST", null
|
|
|
110
|
+ );
|
|
|
111
|
+
|
|
|
112
|
+// ObjectMapper mapper = new ObjectMapper();
|
|
|
113
|
+// mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
|
|
114
|
+// String result = "";
|
|
|
115
|
+// try {
|
|
|
116
|
+// //注意,这里如果打开通风设备关闭不了的话请查看---通风操作打开的需要通风操作关闭,熏蒸操作并不能管理通风操作的通风设备。
|
|
|
117
|
+// if (ParameterUtil.isnotnull(saveType) && ParameterUtil.isequal(saveType, "fumigationData")) {//新增熏蒸的通风控制
|
|
|
118
|
+// aerationRecordService.saveFumigation(task, aerationTaskControl, orgId);
|
|
|
119
|
+// } else {//新增通风控制
|
|
|
120
|
+// // 通风指令发送
|
|
|
121
|
+//
|
|
|
122
|
+// if(task!=null){
|
|
|
123
|
+//
|
|
|
124
|
+// String devinfo = "";
|
|
|
125
|
+// if(!task.contains("[") && !task.contains("]")){
|
|
|
126
|
+// devinfo = "["+task+"]"; //task 包括id和vstatue
|
|
|
127
|
+// }else{
|
|
|
128
|
+// devinfo = task;
|
|
|
129
|
+// }
|
|
|
130
|
+// List<TCtldevinfo> idObject = mapper.readValue(devinfo, new TypeReference<List<TCtldevinfo>>() {});
|
|
|
131
|
+// TCtldevinfo tCtldevinfo = new TCtldevinfo();
|
|
|
132
|
+// for(int i = 0;i<idObject.size();i++){
|
|
|
133
|
+// tCtldevinfo = aerationParameterService.getById(idObject.get(i).getId());
|
|
|
134
|
+// tCtldevinfo.setvState(Integer.valueOf(idObject.get(i).getVstatue()));
|
|
|
135
|
+// String dir = ConstUtils.directiveJoint("00", tCtldevinfo.getVcfcode(), tCtldevinfo.getVdevcode(), tCtldevinfo.getVdevkindcode(), "0" + tCtldevinfo.getVstatue(), "");
|
|
|
136
|
+// System.out.println(dir);
|
|
|
137
|
+// // 16进制字符串转byte数组
|
|
|
138
|
+// byte[] bytes = HexConvertUtils.hexStringToByte(dir);
|
|
|
139
|
+// // 发送指令
|
|
|
140
|
+// String soc = socketClient.startClient(bytes);
|
|
|
141
|
+// result = TypeEnum.resultDispose(soc);
|
|
|
142
|
+// if(TypeEnum.S_SOH.getDesc().equals(result) && tCtldevinfo.getvState()!=Integer.valueOf(tCtldevinfo.getVstatue())){
|
|
|
143
|
+// aerationRecordService.save(tCtldevinfo, aerationTaskControl, orgId);
|
|
|
144
|
+// }
|
|
|
145
|
+// Thread.currentThread().sleep(2000);
|
|
|
146
|
+// }
|
|
|
147
|
+// }
|
|
|
148
|
+//
|
|
|
149
|
+// }
|
|
|
150
|
+// } catch (Exception e) {
|
|
|
151
|
+// e.printStackTrace();
|
|
|
152
|
+// return ResponseEntity.failed("设备连接异常!!");
|
|
|
153
|
+// }
|
|
|
154
|
+// return ResponseEntity.ok();
|
|
121
|
155
|
}
|
|
122
|
156
|
|
|
123
|
|
- //根据仓房和设备名称查询通风的记录
|
|
124
|
157
|
@RequestMapping(value = "/getByCode", method = RequestMethod.POST)
|
|
125
|
158
|
@ApiOperation(value = "根据仓房和设备名称查询信息", notes = "根据仓房和设备名称查询信息")
|
|
126
|
159
|
@ApiImplicitParams({
|
|
127
|
160
|
@ApiImplicitParam(name = "vcfcode", value = "vcfcode", paramType = "query"),
|
|
128
|
|
- @ApiImplicitParam(name = "vdevname", value = "vdevname", paramType = "query")
|
|
|
161
|
+ @ApiImplicitParam(name = "vdevname", value = "vdevname", paramType = "query"),
|
|
|
162
|
+ @ApiImplicitParam(name = "orgId", value = "单位ID", paramType = "query")
|
|
129
|
163
|
})
|
|
130
|
|
- public ResponseEntity<TVentilation> getById(String vcfcode, String vdevname) {
|
|
|
164
|
+ public ResponseEntity<TVentilation> getById(String vcfcode, String vdevname, @NotNull String orgId) {
|
|
131
|
165
|
TVentilation tVentilation = null;
|
|
132
|
166
|
if (StringUtils.isNotBlank(vcfcode) && StringUtils.isNotBlank(vcfcode)) {
|
|
133
|
|
- tVentilation = aerationRecordService.getByCode(vcfcode, vdevname);
|
|
|
167
|
+ tVentilation = aerationRecordService.getByCode(vcfcode, vdevname, orgId);
|
|
134
|
168
|
} else {
|
|
135
|
169
|
return ResponseEntity.failed("ID数据有误!");
|
|
136
|
170
|
}
|