413 lines
16 KiB
Plaintext
413 lines
16 KiB
Plaintext
package com.sercurityControl.proteam.controller;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.securityControl.common.core.utils.StringUtils;
|
|
import com.securityControl.common.core.utils.aes.StringHelper;
|
|
import com.securityControl.common.core.web.controller.BaseController;
|
|
import com.securityControl.common.core.web.domain.AjaxResult;
|
|
import com.securityControl.common.log.annotation.Log;
|
|
import com.securityControl.common.log.enums.BusinessType;
|
|
import com.securityControl.common.log.enums.OperationType;
|
|
import com.securityControl.common.redis.service.RedisService;
|
|
import com.sercurityControl.proteam.domain.DeviceMachineEntity;
|
|
import com.sercurityControl.proteam.domain.NodeEntity;
|
|
import com.sercurityControl.proteam.domain.NodeVo;
|
|
import com.sercurityControl.proteam.domain.QxGroupVo;
|
|
import com.sercurityControl.proteam.service.DeviceMachineService;
|
|
import com.sercurityControl.proteam.util.JsonHelper;
|
|
import com.sercurityControl.proteam.util.QxWebUtil;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.util.*;
|
|
|
|
/**
|
|
* 设备分配控制层
|
|
*
|
|
* @author bonus
|
|
*/
|
|
@Api(tags = "设备分配")
|
|
@Slf4j
|
|
@RestController
|
|
@RequestMapping("/pot/deviceMachine/")
|
|
public class DeviceMachineController extends BaseController {
|
|
|
|
@Autowired
|
|
private DeviceMachineService service;
|
|
|
|
@Autowired
|
|
private RedisService redisUtil;
|
|
|
|
/**
|
|
* 获取设备分配数据
|
|
*
|
|
* @param entity 实体类
|
|
* @return 集合
|
|
*/
|
|
@ApiOperation(value = "获取设备分配数据")
|
|
@PostMapping("/getDeviceMachineList")
|
|
@Log(title = "获取设备分配数据", menu = "获取设备分配数据", businessType = BusinessType.QUERY, details = "获取设备分配数据")
|
|
public Map<String, Object> getDeviceMachineList(DeviceMachineEntity entity) {
|
|
PageHelper.startPage(Integer.parseInt(entity.getPage()), Integer.parseInt(entity.getLimit()));
|
|
Map<String, Object> map = new HashMap<String, Object>(6);
|
|
try {
|
|
PageInfo<DeviceMachineEntity> pageInfo = service.getDeviceMachineList(entity);
|
|
map.put("code", 200);
|
|
map.put("msg", "获取数据成功");
|
|
map.put("count", pageInfo.getTotal());
|
|
map.put("curr", Integer.parseInt(entity.getPage()));
|
|
map.put("limit", Integer.parseInt(entity.getLimit()));
|
|
map.put("data", pageInfo.getList());
|
|
} catch (Exception e) {
|
|
map.put("code", 200);
|
|
map.put("msg", "获取数据成功");
|
|
map.put("error", e.toString());
|
|
map.put("count", 0);
|
|
map.put("curr", Integer.parseInt(entity.getPage()));
|
|
map.put("limit", Integer.parseInt(entity.getLimit()));
|
|
map.put("data", new ArrayList<DeviceMachineEntity>());
|
|
}
|
|
return map;
|
|
}
|
|
|
|
/**
|
|
* 获取分组节点
|
|
*
|
|
* @return 集合
|
|
*/
|
|
@ApiOperation(value = "获取分组节点")
|
|
@PostMapping("getGroupNode")
|
|
@Log(title = "获取分组节点", menu = "获取分组节点", businessType = BusinessType.EXPORT, details = "获取分组节点", grade = OperationType.EXPORT_BUSINESS)
|
|
public AjaxResult getGroupNode(String type) {
|
|
try {
|
|
String groupNode = (String) redisUtil.get("dev:groupNode");
|
|
if (StringUtils.isNotEmpty(groupNode) && !groupNode.contains("null")) {
|
|
QxGroupVo vo = JSON.parseObject(groupNode, QxGroupVo.class);
|
|
List<NodeVo> nodelist = vo.getNodelist();
|
|
if (StringHelper.isNotEmpty(type)) {
|
|
List<NodeVo> list = getNodeList(type, nodelist);
|
|
return AjaxResult.success(list);
|
|
} else {
|
|
return AjaxResult.success(JsonHelper.jsonStrToJsonObj(groupNode).getJSONArray("nodelist"));
|
|
}
|
|
} else {
|
|
return AjaxResult.error();
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return AjaxResult.error();
|
|
}
|
|
}
|
|
|
|
public List<NodeVo> getNodeList(String type, List<NodeVo> nodelist) {
|
|
List<NodeVo> list = new ArrayList<>();
|
|
try {
|
|
for (NodeVo node : nodelist) {
|
|
if (type.equals(node.getParentIndex()) || type.equals(node.getIndex())) {
|
|
if (!"1".equals(node.getIndex())) {
|
|
list.add(node);
|
|
}
|
|
}
|
|
if ("all".equals(type)) {
|
|
if (!"1".equals(node.getIndex())) {
|
|
list.add(node);
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
log.error(e.toString(), e);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
/**
|
|
* 查询设备
|
|
*
|
|
* @return 集合
|
|
*/
|
|
@ApiOperation(value = "查询设备")
|
|
@PostMapping("getPu")
|
|
@Log(title = "查询设备", menu = "查询设备", businessType = BusinessType.EXPORT, details = "查询设备", grade = OperationType.EXPORT_BUSINESS)
|
|
public AjaxResult getPu(String puId, String all) {
|
|
try {
|
|
String pu = QxWebUtil.getPu(puId);
|
|
if (StringUtils.isNotEmpty(pu) && !pu.contains("null")) {
|
|
if (StringUtils.isNotBlank(all) && "all".equals(all)) {
|
|
return AjaxResult.success();
|
|
} else {
|
|
return AjaxResult.success(JsonHelper.jsonStrToJsonObj(pu).getJSONArray("rows"));
|
|
}
|
|
} else {
|
|
return AjaxResult.error();
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return AjaxResult.error();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 分组节点添加设备
|
|
*
|
|
* @return 集合
|
|
*/
|
|
@ApiOperation(value = "分组节点添加设备")
|
|
@PostMapping("getPuSet")
|
|
@Log(title = "分组节点添加设备", menu = "分组节点添加设备", businessType = BusinessType.EXPORT, details = "分组节点添加设备", grade = OperationType.EXPORT_BUSINESS)
|
|
public AjaxResult getPuSet(String puIds, String node, String oldNode) {
|
|
try {
|
|
List<NodeVo> nodeList = JSON.parseArray(node, NodeVo.class);
|
|
System.err.println(nodeList);
|
|
String[] arrPuId = puIds.split(",");
|
|
if (arrPuId.length > 200) {
|
|
return AjaxResult.error("最多200个设备");
|
|
}
|
|
HashSet<String> map = new HashSet<>();
|
|
for (NodeVo vo : nodeList) {
|
|
for (String str : arrPuId) {
|
|
String strValue = (String) redisUtil.get(vo.getParentIndex() + ":" + str);
|
|
if (!ObjectUtil.isEmpty(strValue)) {
|
|
map.add(strValue);
|
|
}
|
|
if("false".equals(oldNode)) {
|
|
redisUtil.set(vo.getParentIndex() + ":" + str, vo.getIndex(), 60 * 60 * 6);
|
|
}else{
|
|
redisUtil.delete(vo.getParentIndex() + ":" + str);
|
|
}
|
|
}
|
|
}
|
|
for (String value : map) {
|
|
QxWebUtil.getPuRemove(puIds, value);
|
|
}
|
|
if("false".equals(oldNode)){//不是清空
|
|
for (NodeVo vo : nodeList) {
|
|
QxWebUtil.getPuSet(puIds, vo.getIndex());
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
log.error(e.toString(),e);
|
|
return AjaxResult.error(e.toString());
|
|
}
|
|
return AjaxResult.success();
|
|
}
|
|
|
|
/**
|
|
* 分组节点添加设备
|
|
*
|
|
* @return 集合
|
|
*/
|
|
@ApiOperation(value = "分组节点添加设备")
|
|
@PostMapping("refreshRedisUtil")
|
|
@Log(title = "分组节点添加设备", menu = "分组节点添加设备", businessType = BusinessType.EXPORT, details = "分组节点添加设备", grade = OperationType.EXPORT_BUSINESS)
|
|
public AjaxResult refreshRedisUtil() {
|
|
try {
|
|
String groupNode = QxWebUtil.getGroupNode();
|
|
redisUtil.set("dev:groupNode", groupNode, 60 * 60 * 6);
|
|
getNodeDevice();
|
|
return AjaxResult.success();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return AjaxResult.error();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 分组节点添加设备
|
|
*
|
|
* @return 集合
|
|
*/
|
|
@ApiOperation(value = "节点添加")
|
|
@PostMapping("nodeAdd")
|
|
@Log(title = "节点添加", menu = "节点添加", businessType = BusinessType.EXPORT, details = "节点添加", grade = OperationType.EXPORT_BUSINESS)
|
|
public AjaxResult nodeAdd(NodeEntity entity) {
|
|
try {
|
|
if (entity.getContext().length() > 255) {
|
|
return AjaxResult.error("节点名称过长");
|
|
}
|
|
AjaxResult determine = determine(entity);
|
|
if (!ObjectUtil.isEmpty(determine)) {
|
|
return determine;
|
|
} else {
|
|
String nodeAdd = QxWebUtil.nodeAdd(entity.getContext(), entity.getParentId());
|
|
if (!ObjectUtil.isEmpty(nodeAdd)) {
|
|
JSONObject jsonObject = JSONObject.parseObject(nodeAdd);
|
|
if ("0".equals(jsonObject.getString("code"))) {
|
|
return AjaxResult.success("添加成功");
|
|
} else {
|
|
return AjaxResult.error("添加失败");
|
|
}
|
|
} else {
|
|
return AjaxResult.error("添加失败");
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return AjaxResult.error();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 分组节点添加设备
|
|
*
|
|
* @return 集合
|
|
*/
|
|
@ApiOperation(value = "节点修改")
|
|
@PostMapping("nodeSet")
|
|
@Log(title = "节点修改", menu = "节点修改", businessType = BusinessType.EXPORT, details = "节点修改", grade = OperationType.EXPORT_BUSINESS)
|
|
public AjaxResult nodeSet(NodeEntity entity) {
|
|
try {
|
|
if (entity.getContext().length() > 255) {
|
|
return AjaxResult.error("节点名称过长");
|
|
}
|
|
AjaxResult determine = determine(entity);
|
|
if (!ObjectUtil.isEmpty(determine)) {
|
|
return determine;
|
|
} else {
|
|
String nodeAdd = QxWebUtil.nodeSet(entity.getContext(), entity.getNodeId());
|
|
if (!ObjectUtil.isEmpty(nodeAdd)) {
|
|
JSONObject jsonObject = JSONObject.parseObject(nodeAdd);
|
|
if ("0".equals(jsonObject.getString("code"))) {
|
|
return AjaxResult.success("修改成功");
|
|
} else {
|
|
return AjaxResult.error("修改失败");
|
|
}
|
|
} else {
|
|
return AjaxResult.error("修改失败");
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return AjaxResult.error();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 分组节点添加设备
|
|
*
|
|
* @return 集合
|
|
*/
|
|
@ApiOperation(value = "节点删除")
|
|
@PostMapping("nodeRemove")
|
|
@Log(title = "节点删除", menu = "节点删除", businessType = BusinessType.EXPORT, details = "节点删除", grade = OperationType.EXPORT_BUSINESS)
|
|
public AjaxResult nodeRemove(NodeEntity entity) {
|
|
try {
|
|
String nodeRemove = QxWebUtil.nodeRemove(entity.getNodeId());
|
|
if (!ObjectUtil.isEmpty(nodeRemove)) {
|
|
JSONObject jsonObject = JSONObject.parseObject(nodeRemove);
|
|
if ("0".equals(jsonObject.getString("code"))) {
|
|
return AjaxResult.success("删除成功");
|
|
} else {
|
|
return AjaxResult.error("删除失败");
|
|
}
|
|
} else {
|
|
return AjaxResult.error("删除失败");
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return AjaxResult.error("删除失败");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 获取分组节点
|
|
*
|
|
* @return 集合
|
|
*/
|
|
@ApiOperation(value = "获取分组节点")
|
|
@PostMapping("groupNode")
|
|
@Log(title = "获取分组节点", menu = "获取分组节点", businessType = BusinessType.EXPORT, details = "获取分组节点", grade = OperationType.EXPORT_BUSINESS)
|
|
public AjaxResult groupNode(String type) {
|
|
try {
|
|
String groupNode = QxWebUtil.getGroupNode();
|
|
redisUtil.set("dev:groupNode", groupNode, 60 * 60 * 6);
|
|
if (StringUtils.isNotEmpty(groupNode) && !groupNode.contains("null")) {
|
|
QxGroupVo vo = JSON.parseObject(groupNode, QxGroupVo.class);
|
|
List<NodeVo> nodelist = vo.getNodelist();
|
|
if (StringHelper.isNotEmpty(type)) {
|
|
List<NodeVo> list = getNodeList(type, nodelist);
|
|
return AjaxResult.success(list);
|
|
} else {
|
|
return AjaxResult.success(JsonHelper.jsonStrToJsonObj(groupNode).getJSONArray("nodelist"));
|
|
}
|
|
} else {
|
|
return AjaxResult.error();
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return AjaxResult.error();
|
|
}
|
|
}
|
|
|
|
public void getNodeDevice() {
|
|
try {
|
|
StringBuilder nodeIndex = new StringBuilder();
|
|
String groupNode = QxWebUtil.getGroupNode();
|
|
QxGroupVo vo = JSON.parseObject(groupNode, QxGroupVo.class);
|
|
if (vo != null) {
|
|
List<NodeVo> nodeList = vo.getNodelist();
|
|
for (NodeVo entity : nodeList) {
|
|
if (!"0".equals(entity.getParentIndex())) {
|
|
String groupPu = QxWebUtil.getGroupPu(entity.getIndex());
|
|
JSONObject json = JSON.parseObject(groupPu);
|
|
jsonArrayToMapList(json.getJSONArray("rows").toString(), entity.getParentIndex(), entity.getIndex());
|
|
} else {
|
|
nodeIndex.append(entity.getIndex()).append(",");
|
|
}
|
|
}
|
|
}
|
|
redisUtil.set("dev:" + "nodeIndex", nodeIndex.toString(), 60 * 60 * 6);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
public void jsonArrayToMapList(String jsonArrayString, String parentIndex, String nodeIndex) {
|
|
JSONArray jsonArr = JSON.parseArray(jsonArrayString);
|
|
if (jsonArr != null && jsonArr.size() > 0) {
|
|
for (int i = 0; i < jsonArr.size(); i++) {
|
|
JSONObject jsonObject = JSON.parseObject(jsonArr.getString(i));
|
|
Map<String, String> map = new HashMap<String, String>(16);
|
|
redisUtil.set(parentIndex + ":" + jsonObject.getString("puid"), nodeIndex, 60 * 60 * 6);
|
|
}
|
|
}
|
|
}
|
|
|
|
public AjaxResult determine(NodeEntity entity) {
|
|
String groupNode = (String) redisUtil.get("dev:groupNode");
|
|
if (StringUtils.isNotEmpty(groupNode) && !groupNode.contains("null")) {
|
|
QxGroupVo vo = JSON.parseObject(groupNode, QxGroupVo.class);
|
|
List<NodeVo> nodeList = vo.getNodelist();
|
|
for (NodeVo nodeVo : nodeList) {
|
|
if (entity.getParentId().equals(nodeVo.getParentIndex())) {
|
|
if (entity.getContext().equals(nodeVo.getName())) {
|
|
return AjaxResult.error("节点名称已存在");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|