137 lines
5.5 KiB
Plaintext
137 lines
5.5 KiB
Plaintext
package com.sercurityControl.proteam.service.impl;
|
|
|
|
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.domain.AjaxResult;
|
|
import com.securityControl.common.redis.service.RedisService;
|
|
import com.sercurityControl.proteam.domain.DeviceMachineEntity;
|
|
import com.sercurityControl.proteam.domain.NodeVo;
|
|
import com.sercurityControl.proteam.domain.QxGroupVo;
|
|
import com.sercurityControl.proteam.dutyTask.domain.TodayTaskVo;
|
|
import com.sercurityControl.proteam.mapper.DeviceMachineMapper;
|
|
import com.sercurityControl.proteam.service.DeviceMachineService;
|
|
import com.sercurityControl.proteam.util.JsonHelper;
|
|
import com.sercurityControl.proteam.util.QxVideotape;
|
|
import com.sercurityControl.proteam.util.QxWebUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
import java.util.*;
|
|
|
|
/**
|
|
* @author bonus
|
|
* @data 2023/3/17 10:53
|
|
* @description 设备分配
|
|
*/
|
|
@Service
|
|
@Slf4j
|
|
public class DeviceMachineServiceImpl implements DeviceMachineService {
|
|
|
|
@Autowired
|
|
private DeviceMachineMapper mapper;
|
|
|
|
@Autowired
|
|
private RedisService redisUtil;
|
|
|
|
/**
|
|
* 获取设备分配数据
|
|
*
|
|
* @param entity 实体类
|
|
* @return 集合
|
|
*/
|
|
@Override
|
|
public PageInfo<DeviceMachineEntity> getDeviceMachineList(DeviceMachineEntity entity) {
|
|
List<DeviceMachineEntity> list = new ArrayList<>();
|
|
if (StringUtils.isNotBlank(entity.getOrg())) {
|
|
String[] arr = entity.getOrg().split(",");
|
|
List<String> orgList = Arrays.asList(arr);
|
|
entity.setOrgList(orgList);
|
|
}
|
|
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();
|
|
PageHelper.startPage(Integer.parseInt(entity.getPage()), Integer.parseInt(entity.getLimit()));
|
|
list = mapper.getDeviceMachineList(entity);
|
|
//父类节点
|
|
String index = (String) redisUtil.get("dev:nodeIndex");
|
|
String[] indexList = index.split(",");
|
|
for (DeviceMachineEntity device : list) {
|
|
StringBuilder nodeIndex = new StringBuilder();
|
|
StringBuilder nodeName = new StringBuilder();
|
|
for (String str : indexList) {
|
|
String node = (String) redisUtil.get(str + ":" + device.getPuId());
|
|
nodeIndex.append(ObjectUtils.isEmpty(node) ? "" : node + ",");
|
|
if (!ObjectUtils.isEmpty(node)) {
|
|
for (NodeVo nodeVo : nodelist) {
|
|
if (node.equals(nodeVo.getIndex())) {
|
|
nodeName.append(nodeVo.getName()).append(",");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
device.setNodeIndex(nodeIndex.length() > 0 ? nodeIndex.deleteCharAt(nodeIndex.lastIndexOf(",")).toString() : "");
|
|
device.setNodeName(nodeName.length() > 0 ? nodeName.deleteCharAt(nodeName.lastIndexOf(",")).toString() : "");
|
|
}
|
|
}
|
|
PageInfo<DeviceMachineEntity> pageInfo = new PageInfo<>(list);
|
|
return pageInfo;
|
|
}
|
|
/**
|
|
*
|
|
*/
|
|
@Override
|
|
public void refreshRedisUtilSchedule() {
|
|
try {
|
|
String groupNode = QxWebUtil.getGroupNode();
|
|
redisUtil.set("dev:groupNode", groupNode, 60 * 60 * 6);
|
|
getNodeDevice();
|
|
} catch (Exception e) {
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|