package com.cloud.device.controller;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.cloud.device.constants.Constants;
|
import com.cloud.device.model.Device;
|
import com.cloud.device.model.Dic;
|
import com.cloud.device.service.DeviceService;
|
import com.cloud.device.service.DicService;
|
import com.cloud.device.service.NodeService;
|
import com.cloud.device.vo.MenuTreeVo;
|
import com.cloud.model.common.Page;
|
import com.cloud.model.common.Result;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.MediaType;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.io.IOException;
|
import java.text.ParseException;
|
import java.util.*;
|
|
@Slf4j
|
@Api(value = "DeviceController",description = "设备管理")
|
@RequestMapping(value = "/data/api-d/device")
|
@RestController
|
public class DeviceController {
|
|
@Autowired
|
private DeviceService deviceService;
|
@Autowired
|
private DicService dicService;
|
@Autowired
|
private NodeService nodeService;
|
|
@RequestMapping("/getDeviceType")
|
@ApiOperation(value = "获取设备类型", notes = "获取设备类型", httpMethod = "POST",produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
public Result getDeviceType(){
|
try {
|
Map<String, Object> map = new HashMap<>();
|
map.put("type", Dic.DIC_DEVICE_TYPE);
|
|
return Result.ok(Constants.RESULT_QUERY_OK, dicService.getDicByType(map));
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@GetMapping("/getDeviceBrand")
|
@ApiOperation(value = "获取设备品牌", notes = "获取设备品牌", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
public Result getDeviceBrand(){
|
try {
|
Map<String, Object> map = new HashMap<>();
|
map.put("type", Dic.DIC_DEVICE_BRAND);
|
return Result.ok(Constants.RESULT_QUERY_OK, dicService.getDicByType(map));
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@GetMapping("/getStatus")
|
@ApiOperation(value = "获取设备状态字典列表", notes = "获取设备状态字典列表", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
public Result getStatusList(){
|
try {
|
Map<String, Object> map = new HashMap<>();
|
map.put("type", Dic.DIC_DEVICE_STATUS);
|
return Result.ok(Constants.RESULT_QUERY_OK, dicService.getDicByType(map));
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@GetMapping("/findPlatDeviceList")
|
@ApiOperation(value = "获取平台设备列表(分页)",notes = "获取平台设备列表(分页)",httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name ="param", value = "无用参数", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "start", value = "起始页", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "length", value = "条数", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "orgId", value = "组织机构id", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name ="condition", value = "设备名称/设备id/设备位置", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "type", value = "类型(MENU或其它)", required = true, dataType = "String", paramType = "query")
|
})
|
public Page<Device> findPlatDeviceList(@RequestParam Map<String,Object> param){
|
return deviceService.findPlatDeviceList(param);
|
|
}
|
|
@GetMapping("/findAllPlatDeviceList")
|
@ApiOperation(value = "获取所有非集群监控设备列表(不分页)",notes = "获取所有非集群监控设备列表(不分页)",httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name ="param", value = "无用参数", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "orgId", value = "组织机构id", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name ="condition", value = "设备名称/设备id/设备位置", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "type", value = "类型(MENU或其它)", required = true, dataType = "String", paramType = "query")
|
})
|
public Result findAllPlatDeviceList(@RequestParam Map<String,Object> param){
|
try {
|
return Result.ok(Constants.RESULT_QUERY_OK, deviceService.findAllPlatDeviceList(param));
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@ApiOperation(value = "通过区域查找设备", notes = "通过区域查找设备", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "param", value = "无用参数", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "condition", value = "设备名称/设备位置", required = false, dataType = "String", paramType = "query")
|
})
|
@GetMapping("/findByArea")
|
public Result findByArea(@RequestParam Map<String,Object> param){
|
try {
|
return Result.ok(Constants.RESULT_QUERY_OK, deviceService.findByArea(param));
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@ApiOperation(value = "通过区域查找设备", notes = "通过区域查找设备", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "param", value = "无用参数", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "condition", value = "设备名称/设备位置", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "orgId", value = "组织机构id", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "type", value = "类型(MENU或其它)", required = true, dataType = "String", paramType = "query")
|
})
|
@GetMapping("/findAllDeviceByArea")
|
public Result findAllDeviceByArea(@RequestParam Map<String, Object> param){
|
try {
|
return Result.ok(Constants.RESULT_QUERY_OK, deviceService.findAllDeviceByArea(param));
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@RequestMapping("/getDeviceById")
|
@ApiOperation(value = "通过id查找设备", notes = "通过id查找设备", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name="id",value = "设备id", required = true, dataType = "String",paramType = "query")
|
})
|
public Result getDeviceById(@RequestParam String id){
|
try {
|
return Result.ok(Constants.RESULT_QUERY_OK, deviceService.selectById(id));
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
|
}
|
|
@RequestMapping("/getNodeByDeviceId")
|
@ApiOperation(value = "根据摄像机id获取摄像机信息(节点信息)",notes = "根据摄像机id获取摄像机信息(节点信息)",
|
httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "deviceId", value = "摄像机id", required = true, dataType = "String", paramType = "query")
|
})
|
public Result getNodeByDeviceId(@RequestParam String deviceId){
|
try {
|
JSONObject jsonResult = new JSONObject();
|
Device device = deviceService.selectById(deviceId);
|
if(device !=null){
|
jsonResult.put("device", device);
|
if(StringUtils.isNotEmpty(device.getNodeId())){
|
jsonResult.put("node", nodeService.selectById(device.getNodeId()));
|
}
|
}
|
return Result.ok(Constants.RESULT_QUERY_OK, jsonResult);
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@RequestMapping("/saveDevice")
|
@ApiOperation(value = "保存设备",notes = "保存设备",httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "device", value = "设备实例", required = true, dataType = "Device", paramType = "body")
|
// @ApiImplicitParam(name = "orgId", value = "所属组织机构id", required = true, dataType = "String", paramType = "query"),
|
// @ApiImplicitParam(name = "name", value="设备名称", required = true, dataType = "String", paramType = "query"),
|
// @ApiImplicitParam(name = "type", value = "设备类型(摄像机或PAD或分析的字典值)", required = true, dataType = "String", paramType = "query"),
|
// @ApiImplicitParam(name = "brand", value = "设备品牌", required = true, dataType = "String", paramType = "query"),
|
// @ApiImplicitParam(name = "ip", value = "设备ip", required = true, dataType = "String", paramType = "query"),
|
// @ApiImplicitParam(name = "port", value = "端口", required = true, dataType = "String", paramType = "query"),
|
// @ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String", paramType = "query"),
|
// @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String", paramType = "query"),
|
// @ApiImplicitParam(name = "address", value = "位置", required = true, dataType = "String", paramType = "query")
|
})
|
public Result saveDevice(@RequestBody Device device){
|
try {
|
//查找此ip是否有重复的设备
|
Device existDevice = deviceService.findByIp(device.getIp());
|
if(existDevice !=null){
|
if(StringUtils.isEmpty(device.getId()) || (StringUtils.isNotEmpty(device.getId()) && !device.getId().equals(existDevice.getId()))){
|
return Result.custom("重复添加摄像机",500,false,"设备ip不允许重复");
|
}
|
}
|
|
|
return Result.ok(Constants.RESULT_SAVE_OK, deviceService.saveDevice(device));
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@GetMapping("/updateOrg")
|
@ApiOperation(value = "更新设备所属组织", notes = "更新设备所属组织", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "设备id",required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "orgId", value = "组织id", required = true, dataType = "Integer", paramType = "query")
|
})
|
public Result updateOrg(String id,Integer orgId){
|
try {
|
log.info("id:"+id+",orgId:"+orgId);
|
if(StringUtils.isNotEmpty(id) && orgId > 0)
|
return Result.ok(Constants.RESULT_SAVE_OK, deviceService.updateOrg(id, orgId));
|
else
|
return Result.custom("更新失败,参数不正确",401,false,"");
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@RequestMapping("/deleteDevice")
|
@ApiOperation(value = "删除设备", notes = "删除设备", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "设备id", required = true, dataType = "String", paramType = "query")
|
})
|
public Result deleteDevice(@RequestParam String id){
|
try {
|
return Result.ok(Constants.RESULT_DELETE_OK, deviceService.deleteById(id));
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@ApiOperation(value="获取设备组织机构树", notes = "获取设备组织机构",httpMethod = "GET",produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "param", value = "无用参数", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "name", value = "名称、模糊查询", required = false, dataType = "String", paramType = "query")
|
})
|
@RequestMapping("/getOrgDeviceTree")
|
private List<MenuTreeVo> getOrgDeviceTree(@RequestParam Map<String, Object> param){
|
try {
|
return deviceService.getOrgDeviceTree(param);
|
} catch (Exception e) {
|
e.printStackTrace();
|
return new ArrayList<>();
|
}
|
}
|
|
@ApiOperation(value = "地图中获取所有设备", notes = "地图中获取所有设备", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@GetMapping("/findAllDevices")
|
public Result findAllDevices(){
|
try {
|
return Result.ok(Constants.RESULT_QUERY_OK, deviceService.findAllDevices());
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@ApiOperation(value = "更新设备经纬度", notes = "更新设备经纬度", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "param", value = "无用参数", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "type", value = "类型", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "longitude", value = "经度", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "latitude", value = "纬度", required = true, dataType = "String", paramType = "query")
|
})
|
@GetMapping("/updatePosById")
|
public Result updatePosById(@RequestParam Map<String,Object> param){
|
try {
|
return Result.ok(Constants.RESULT_SAVE_OK, deviceService.updatePosById(param));
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@ApiOperation(value = "更新节点公网ip和端口", notes = "更新节点公网ip和端口", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "param", value = "无用参数", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "publicIp", value = "公网ip", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "publicPort", value = "公网端口", required = true, dataType = "String", paramType = "query")
|
})
|
@GetMapping("/updatePublicIpPort")
|
public Result updatePublicIpPort(@RequestParam Map<String,Object> param){
|
try {
|
return Result.ok(Constants.RESULT_SAVE_OK, deviceService.updatePublicIpPort(param));
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
@ApiOperation(value = "通过devId获取节点信息", notes = "通过devId获取节点信息", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "devId", value = "devId",required = true,dataType = "String",paramType = "query")
|
})
|
@GetMapping("/getNodeByDevId")
|
public Result getNodeByDevId(@RequestParam String devId){
|
return Result.ok(Constants.RESULT_QUERY_OK, deviceService.getNodeByDevId(devId));
|
}
|
|
@ApiOperation(value = "getDevSnapshot",notes =
|
"获取实时流截图{\"devId\":\"DS-2CD2T46WDA2-I20180622AACHC30488278\"}",
|
httpMethod = "POST",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
@RequestMapping("/getDevSnapshot")
|
public Result getDevSnapshot(@RequestBody Map reqMap, HttpServletRequest req) throws ParseException, IOException {
|
String devId = (String) reqMap.get("devId");
|
if (StringUtils.isBlank(devId)){
|
throw new RuntimeException("获取实时流截图 devId:"+devId+"为空。");
|
}
|
log.info("获取实时流截图 devId:"+devId);
|
JSONObject url = deviceService.getDevSnapshot(devId); // :80/dddd.jpg
|
return Result.ok("获取实时流截图成功。",url);
|
}
|
|
|
// @AuthNoneIgnore
|
// @ApiOperation(value = "测试设备连接", notes = "测试设备连接" ,httpMethod = "GET",produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
// @ApiImplicitParams({
|
// @ApiImplicitParam(name = "str_brand", value = "品牌",required = true,dataType = "String", paramType = "query"),
|
// @ApiImplicitParam(name = "str_ip", value = "ip", required = true, dataType = "String", paramType = "query"),
|
// @ApiImplicitParam(name = "n_port", value = "端口", required = true, dataType = "String", paramType = "query"),
|
// @ApiImplicitParam(name = "str_username", value = "用户名", required = true, dataType = "String", paramType = "query"),
|
// @ApiImplicitParam(name = "str_password", value = "密码", required = true, dataType = "String", paramType = "query")
|
// })
|
// public Result testDeviceConn(@RequestParam Map<String,Object> param){
|
//
|
// return Result.ok(Constants.RESULT_QUERY_OK, deviceService.testDeviceConn(param));
|
// }
|
|
}
|