|
|
@@ -1,6 +1,7 @@
|
|
|
package com.supervision.web.peopleGateManage.controller;
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.supervision.web.peopleGateManage.service.DeviceService;
|
|
|
import com.supervision.web.peopleGateManage.service.PeopleDeviceService;
|
|
|
@@ -13,6 +14,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -37,13 +39,22 @@ public class DeviceManageController {
|
|
|
*/
|
|
|
@PostMapping("/list")
|
|
|
public Map<String, Object> listDevices(@RequestBody Map<String, Object> params) {
|
|
|
- PageInfo<Device> pageInfo = deviceService.searchByCondition(params);
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("total", pageInfo.getTotal());
|
|
|
- result.put("list", pageInfo.getList());
|
|
|
- result.put("pageNum", pageInfo.getPageNum());
|
|
|
- result.put("pageSize", pageInfo.getPageSize());
|
|
|
- return result;
|
|
|
+ try {
|
|
|
+ PageInfo<Device> pageInfo = deviceService.searchByCondition(params);
|
|
|
+ result.put("total", pageInfo.getTotal());
|
|
|
+ result.put("list", pageInfo.getList());
|
|
|
+ result.put("pageNum", pageInfo.getPageNum());
|
|
|
+ result.put("pageSize", pageInfo.getPageSize());
|
|
|
+ result.put("status", true);
|
|
|
+ result.put("message", "获取所有设备列表成功");
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ result.put("status", false);
|
|
|
+ result.put("message", "获取所有设备列表失败: " + e.getMessage());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -51,72 +62,137 @@ public class DeviceManageController {
|
|
|
*/
|
|
|
@GetMapping("/listDeviceName")
|
|
|
public Map<String, Object> listDeviceName() {
|
|
|
- List<Device> pageInfo = deviceService.searchAllDeviceNames();
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("total", pageInfo.size());
|
|
|
- result.put("list", pageInfo);
|
|
|
- return result;
|
|
|
+ try {
|
|
|
+ List<Device> pageInfo = deviceService.searchAllDeviceNames();
|
|
|
+ result.put("total", pageInfo.size());
|
|
|
+ result.put("list", pageInfo);
|
|
|
+ result.put("status", true);
|
|
|
+ result.put("message", "获取所有设备列表成功");
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ result.put("status", false);
|
|
|
+ result.put("message", "获取所有设备列表失败: " + e.getMessage());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增设备(支持从指定设备或所有设备同步人员信息)
|
|
|
*/
|
|
|
@PostMapping("/add")
|
|
|
- public String addDevice(@RequestBody DeviceAddRequest request) {
|
|
|
- // 1. 保存新设备
|
|
|
- Device device = new Device();
|
|
|
- device.setType(request.getModel());
|
|
|
- device.setLocation(request.getLocation());
|
|
|
- device.setIp(request.getIp());
|
|
|
- device.setPort(request.getPort());
|
|
|
- device.setAccount(request.getAccount());
|
|
|
- device.setPassword(request.getPassword());
|
|
|
- deviceService.add(device);
|
|
|
-
|
|
|
- // 2. 同步逻辑
|
|
|
- if (request.getSyncMode() != null) {
|
|
|
- if (request.getSyncMode() == 1) {
|
|
|
- // 同步所有人员
|
|
|
- List<PeopleInfo> allPeople = peopleInfoService.getAll();
|
|
|
- for (PeopleInfo p : allPeople) {
|
|
|
- peopleDeviceService.bindPersonToDevice(p.getPersonId(), device.getId());
|
|
|
- }
|
|
|
- } else if (request.getSyncMode() == 2 && request.getSyncFromDeviceId() != null) {
|
|
|
- // 从指定设备同步
|
|
|
- List<String> personIds = peopleDeviceService.getPersonsByDevice(request.getSyncFromDeviceId());
|
|
|
- for (String personId : personIds) {
|
|
|
- peopleDeviceService.bindPersonToDevice(personId, device.getId());
|
|
|
- }
|
|
|
- }
|
|
|
+ public Map<String, Object> addDevice(@RequestBody Map<String, Object> params) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ try {
|
|
|
+ // 1. 保存新设备
|
|
|
+ Device device = new Device();
|
|
|
+ device.setName((String) params.get("name"));
|
|
|
+ device.setSerialNumber((String) params.get("serialNumber"));
|
|
|
+ device.setType((String) params.get("type"));
|
|
|
+ device.setLocation((String) params.get("location"));
|
|
|
+ device.setFirmwareVersion((String) params.get("firmwareVersion"));
|
|
|
+ device.setIp((String) params.get("ip"));
|
|
|
+ device.setPort((Integer) params.get("port"));
|
|
|
+ device.setAccount((String) params.get("account"));
|
|
|
+ device.setPassword((String) params.get("password"));
|
|
|
+ device.setRemark((String) params.get("remarks"));
|
|
|
+
|
|
|
+ // 将前端门体信息和摄像头信息转为 JSON 存储
|
|
|
+ device.setDoors(JSON.toJSONString(params.get("doorInfo")));
|
|
|
+ device.setChannels(JSON.toJSONString(params.get("videoInfo")));
|
|
|
+
|
|
|
+ device.setCreateTime(new Date());
|
|
|
+ device.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ device.setEnable((Boolean) params.get("enable"));
|
|
|
+
|
|
|
+ deviceService.add(device); // 保存到数据库
|
|
|
+
|
|
|
+// // 2. 同步逻辑
|
|
|
+// if (request.getSyncMode() != null) {
|
|
|
+// if (request.getSyncMode() == 1) {
|
|
|
+// // 同步所有人员
|
|
|
+// List<PeopleInfo> allPeople = peopleInfoService.getAll();
|
|
|
+// for (PeopleInfo p : allPeople) {
|
|
|
+// peopleDeviceService.bindPersonToDevice(p.getPersonId(), device.getId());
|
|
|
+// }
|
|
|
+// } else if (request.getSyncMode() == 2 && request.getSyncFromDeviceId() != null) {
|
|
|
+// // 从指定设备同步
|
|
|
+// List<String> personIds = peopleDeviceService.getPersonsByDevice(request.getSyncFromDeviceId());
|
|
|
+// for (String personId : personIds) {
|
|
|
+// peopleDeviceService.bindPersonToDevice(personId, device.getId());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ result.put("status", true);
|
|
|
+ result.put("message", "添加设备成功");
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ result.put("status", false);
|
|
|
+ result.put("message", "添加设备失败: " + e.getMessage());
|
|
|
+ return result;
|
|
|
}
|
|
|
-
|
|
|
- return "success";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改设备
|
|
|
*/
|
|
|
@PutMapping("/update")
|
|
|
- public String updateDevice(@RequestBody Device device) {
|
|
|
- deviceService.update(device);
|
|
|
- return "success";
|
|
|
+ public Map<String, Object> updateDevice(@RequestBody Device device) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ try {
|
|
|
+ deviceService.update(device);
|
|
|
+ result.put("status", true);
|
|
|
+ result.put("message", "修改设备成功");
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ result.put("status", false);
|
|
|
+ result.put("message", "修改设备失败: " + e.getMessage());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除设备
|
|
|
*/
|
|
|
@DeleteMapping("/delete/{id}")
|
|
|
- public String deleteDevice(@PathVariable Long id) {
|
|
|
- deviceService.delete(id);
|
|
|
- return "success";
|
|
|
+ public Map<String, Object> deleteDevice(@PathVariable Long id) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ try {
|
|
|
+ deviceService.delete(id);
|
|
|
+ result.put("status", true);
|
|
|
+ result.put("message", "删除设备成功");
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ result.put("status", false);
|
|
|
+ result.put("message", "删除设备失败: " + e.getMessage());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查看单个设备详情
|
|
|
*/
|
|
|
@GetMapping("/get/{id}")
|
|
|
- public Device getDevice(@PathVariable Long id) {
|
|
|
- return deviceService.getById(id);
|
|
|
+ public Map<String, Object> getDevice(@PathVariable Long id) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ try {
|
|
|
+ Device device = deviceService.getById(id);
|
|
|
+ result.put("data", device);
|
|
|
+ result.put("status", true);
|
|
|
+ result.put("message", "获取单个设备详情成功");
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ result.put("status", false);
|
|
|
+ result.put("message", "获取单个设备详情失败: " + e.getMessage());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|