|
@@ -94,61 +94,69 @@ public class TdDeviceController extends BaseController {
|
94
|
94
|
if (isNew) {
|
95
|
95
|
// 如果是新增操作
|
96
|
96
|
if (null != origin) {
|
97
|
|
- return ResponseBean.error("该农机已绑定设备, 请先解绑");
|
|
97
|
+ if (origin.getMachineryId().equals(tdDevice.getMachineryId())) {
|
|
98
|
+ return ResponseBean.error("该设备已绑定当前农机");
|
|
99
|
+ } else {
|
|
100
|
+ return ResponseBean.error("该设备已绑定其他农机, 请先解绑");
|
|
101
|
+ }
|
98
|
102
|
}
|
99
|
103
|
} else {
|
100
|
104
|
if (null != origin) {
|
101
|
105
|
// 如果非新增操作, 并且当前的 id 与 数据库 id 不一致
|
102
|
106
|
if (!tdDevice.getDeviceId().equals(origin.getDeviceId())) {
|
103
|
|
- return ResponseBean.error("该农机已绑定设备");
|
|
107
|
+ if (origin.getMachineryId().equals(tdDevice.getMachineryId())) {
|
|
108
|
+ return ResponseBean.error("该设备已绑定当前农机");
|
|
109
|
+ } else {
|
|
110
|
+ return ResponseBean.error("该设备已绑定其他农机, 请先解绑");
|
|
111
|
+ }
|
104
|
112
|
}
|
105
|
113
|
} else {
|
106
|
114
|
isNew = true;
|
107
|
115
|
}
|
108
|
116
|
}
|
109
|
117
|
|
110
|
|
- if (StringUtils.isEmpty(tdDevice.getApiConfig())) {
|
111
|
|
- return ResponseBean.error("未绑定海康设备");
|
112
|
|
- }
|
|
118
|
+// if (StringUtils.isEmpty(tdDevice.getApiConfig())) {
|
|
119
|
+// return ResponseBean.error("未绑定海康设备");
|
|
120
|
+// }
|
113
|
121
|
|
114
|
122
|
TaMachinery taMachinery = iTaMachineryService.getExistBy("machinery_id", tdDevice.getMachineryId(), false, true);
|
115
|
123
|
if (taMachinery == null) {
|
116
|
124
|
return ResponseBean.error("绑定农机不存在");
|
117
|
125
|
}
|
118
|
126
|
|
119
|
|
- try {
|
120
|
|
- DeviceSummary deviceSummary = JSONObject.parseObject(tdDevice.getApiConfig(), DeviceSummary.class);
|
121
|
|
- if (null == deviceSummary) {
|
122
|
|
- return ResponseBean.error("未绑定海康设备");
|
123
|
|
- }
|
124
|
|
-
|
125
|
|
- if (StringUtils.isEmpty(deviceSummary.getDeviceId())) {
|
126
|
|
- return ResponseBean.error("未绑定海康设备");
|
127
|
|
- }
|
128
|
|
-
|
129
|
|
- TdHatcDevice hatcDevice = iTdHatcDeviceService.getById(deviceSummary.getDeviceId());
|
130
|
|
- if (null == hatcDevice) {
|
131
|
|
- return ResponseBean.error("绑定的海康设备不存在");
|
132
|
|
- }
|
133
|
|
-
|
134
|
|
- if (null == deviceSummary.getChannel() || deviceSummary.getChannel() < 1) {
|
135
|
|
- return ResponseBean.error("未设置通道号, 或者通道号不正确");
|
136
|
|
- }
|
137
|
|
-
|
138
|
|
- if (null == deviceSummary.getNetType() || deviceSummary.getNetType() < 0 || deviceSummary.getNetType() > 3) {
|
139
|
|
- return ResponseBean.error("未设置网络类型, 或者网络类型不正确");
|
140
|
|
- }
|
141
|
|
-
|
142
|
|
- tdDevice.setDeviceNo(hatcDevice.getTerminalId());
|
143
|
|
- tdDevice.setDeviceType(hatcDevice.getProductKey());
|
144
|
|
- taMachinery.setOnlineStatus(hatcDevice.getDeviceStatus());
|
145
|
|
- } catch (Exception e) {
|
146
|
|
- e.printStackTrace();
|
147
|
|
- return ResponseBean.error("海康设备参数无效");
|
148
|
|
- }
|
|
127
|
+// try {
|
|
128
|
+// DeviceSummary deviceSummary = JSONObject.parseObject(tdDevice.getApiConfig(), DeviceSummary.class);
|
|
129
|
+// if (null == deviceSummary) {
|
|
130
|
+// return ResponseBean.error("未绑定海康设备");
|
|
131
|
+// }
|
|
132
|
+//
|
|
133
|
+// if (StringUtils.isEmpty(deviceSummary.getDeviceId())) {
|
|
134
|
+// return ResponseBean.error("未绑定海康设备");
|
|
135
|
+// }
|
|
136
|
+//
|
|
137
|
+// TdHatcDevice hatcDevice = iTdHatcDeviceService.getById(deviceSummary.getDeviceId());
|
|
138
|
+// if (null == hatcDevice) {
|
|
139
|
+// return ResponseBean.error("绑定的海康设备不存在");
|
|
140
|
+// }
|
|
141
|
+//
|
|
142
|
+// if (null == deviceSummary.getChannel() || deviceSummary.getChannel() < 1) {
|
|
143
|
+// return ResponseBean.error("未设置通道号, 或者通道号不正确");
|
|
144
|
+// }
|
|
145
|
+//
|
|
146
|
+// if (null == deviceSummary.getNetType() || deviceSummary.getNetType() < 0 || deviceSummary.getNetType() > 3) {
|
|
147
|
+// return ResponseBean.error("未设置网络类型, 或者网络类型不正确");
|
|
148
|
+// }
|
|
149
|
+//
|
|
150
|
+// tdDevice.setDeviceNo(hatcDevice.getTerminalId());
|
|
151
|
+// tdDevice.setDeviceType(hatcDevice.getProductKey());
|
|
152
|
+// taMachinery.setOnlineStatus(hatcDevice.getDeviceStatus());
|
|
153
|
+// } catch (Exception e) {
|
|
154
|
+// e.printStackTrace();
|
|
155
|
+// return ResponseBean.error("海康设备参数无效");
|
|
156
|
+// }
|
149
|
157
|
|
150
|
158
|
boolean isOk = isNew ? iTdDeviceService.save(tdDevice) : iTdDeviceService.updateById(tdDevice);
|
151
|
|
- iTaMachineryService.updateById(taMachinery);
|
|
159
|
+// iTaMachineryService.updateById(taMachinery);
|
152
|
160
|
|
153
|
161
|
if (isOk){
|
154
|
162
|
return ResponseBean.success(tdDevice);
|
|
@@ -156,20 +164,20 @@ public class TdDeviceController extends BaseController {
|
156
|
164
|
return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
157
|
165
|
}
|
158
|
166
|
}
|
159
|
|
-//
|
160
|
|
-// /**
|
161
|
|
-// * 根据id删除对象
|
162
|
|
-// * @param id 实体ID
|
163
|
|
-// */
|
164
|
|
-// @RequestMapping(value="/tdDevice/{id}", method= RequestMethod.DELETE)
|
165
|
|
-// @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
|
166
|
|
-// public ResponseBean tdDeviceDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
|
167
|
|
-// if(iTdDeviceService.removeById(id)){
|
168
|
|
-// return ResponseBean.success("success");
|
169
|
|
-// }else {
|
170
|
|
-// return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
171
|
|
-// }
|
172
|
|
-// }
|
|
167
|
+
|
|
168
|
+ /**
|
|
169
|
+ * 根据id删除对象
|
|
170
|
+ * @param id 实体ID
|
|
171
|
+ */
|
|
172
|
+ @RequestMapping(value="/admin/device/{id}", method= RequestMethod.DELETE)
|
|
173
|
+ @ApiOperation(value="取消绑定", notes = "取消绑定", httpMethod = "DELETE", response = ResponseBean.class)
|
|
174
|
+ public ResponseBean tdDeviceDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
|
|
175
|
+ if(iTdDeviceService.removeLogicById(id)){
|
|
176
|
+ return ResponseBean.success("success");
|
|
177
|
+ } else {
|
|
178
|
+ return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
|
179
|
+ }
|
|
180
|
+ }
|
173
|
181
|
//
|
174
|
182
|
// /**
|
175
|
183
|
// * 修改对象
|