施工管控

This commit is contained in:
cwchen 2024-08-08 17:44:40 +08:00
parent 7e4d462382
commit 0e1cb7f1ce
6 changed files with 68 additions and 47 deletions

View File

@ -12,6 +12,7 @@ public class BusinessConstants {
public static final int TYPE = 1;
public static final int TYPE2 = 2;
public static final int TYPE3 = 0;
public static final Long PARENT_ID = 0l;
/** 资源类型 1-人员*/
public static final String RESOURCE_TYPE_USER = "1";

View File

@ -0,0 +1,50 @@
package com.bonus.common.core.utils;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
/**
* @className:BuildTreeUtil
* @author:cwchen
* @date:2024-08-08-16:15
* @version:1.0
* @description:构建树
*/
public class BuildTreeUtil {
public static JSONArray listInfoToTree(JSONArray arr, String id, String pid, String child) {
JSONArray ret = new JSONArray();
// 将数据直接构建成为hash
JSONObject hash = new JSONObject();
// 节点大小
int size = arr.size();
// 将数组转为Object的形式key为数组中的id并组装为map
for (int i = 0; i < size; i++) {
JSONObject json = (JSONObject) arr.get(i);
hash.put(json.getString(id), json);
}
// 遍历结果集
for (int j = 0; j < size; j++) {
// 单条记录
JSONObject nodeVal = (JSONObject) arr.get(j);
// 在hash中取出key为单条记录中pid的值
JSONObject hashParent = (JSONObject) hash.get(nodeVal.get(pid).toString());
// 如果记录的pid存在则说明它有父节点将她添加到孩子节点的集合中这里与刚才所说的所有parentId为空的节点填充一个projectid并不冲突因为当填入projectId的时候hashParent是get不到值的
if (hashParent != null) {
// 构造child属性
if (hashParent.get(child) != null) {
JSONArray chArr = (JSONArray) hashParent.get(child);
chArr.add(nodeVal);
hashParent.put(child, chArr);
} else {
JSONArray chArr = new JSONArray();
chArr.add(nodeVal);
hashParent.put(child, chArr);
}
} else {
ret.add(nodeVal);
}
}
return ret;
}
}

View File

@ -1,40 +0,0 @@
package com.bonus.common.entity.bracelet;
import com.bonus.common.entity.bracelet.vo.BallTreeVo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @className:BuildTreeUtil
* @author:cwchen
* @date:2024-08-08-16:15
* @version:1.0
* @description:构建树
*/
public class BuildTreeUtil {
public static List<BallTreeVo> ballListToChildren(List<BallTreeVo> list) {
Map<String, BallTreeVo> map = new HashMap<>();
List<BallTreeVo> result = new ArrayList<>();
// 第一次遍历将所有节点存储到map中
for (BallTreeVo node : list) {
map.put(node.getId() + "", node);
}
// 第二次遍历构建Children关系
for (BallTreeVo node : list) {
BallTreeVo parent = map.get(node.getParentId());
if (parent != null) {
if (parent.getChildren() == null) {
parent.setChildren(new ArrayList<>());
}
parent.getChildren().add(node);
} else {
result.add(node);
}
}
return result;
}
}

View File

@ -3,6 +3,7 @@ package com.bonus.common.entity.bracelet.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
@ -23,8 +24,8 @@ public class BallTreeVo {
private String devCode;
/**设备下标*/
private String devIndex;
/**父ID*/
private Long parentId;
private List<BallTreeVo> children;
private List<BallTreeVo> children = new ArrayList<>();
}

View File

@ -1,12 +1,15 @@
package com.bonus.bracelet.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.bonus.bracelet.mapper.ConsControlMapper;
import com.bonus.bracelet.service.IConsControlService;
import com.bonus.common.core.constant.BusinessConstants;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.utils.encryption.Sm4Utils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.entity.bracelet.BraceletParamsDto;
import com.bonus.common.entity.bracelet.BuildTreeUtil;
import com.bonus.common.core.utils.BuildTreeUtil;
import com.bonus.common.entity.bracelet.vo.BallTreeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -14,6 +17,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* @className:ConsControlServiceImpl
@ -31,20 +35,25 @@ public class ConsControlServiceImpl implements IConsControlService {
@Override
public AjaxResult getBallDeviceLists(BraceletParamsDto dto) {
JSONArray resultTree = new JSONArray();
try {
List<BallTreeVo> list = new ArrayList<>();
list = mapper.getBallDeviceLists(dto);
for (BallTreeVo vo : list) {
//过滤工程数据
if (Objects.equals(vo.getParentId(), BusinessConstants.PARENT_ID)) {
continue;
}
String[] valArr = vo.getLabel().split("-");
if (StringUtils.isNotEmpty(valArr[1])) {
vo.setLabel(valArr[0] + "-" + Sm4Utils.decode(valArr[1]));
}
}
List<BallTreeVo> handleList = BuildTreeUtil.ballListToChildren(list);
return AjaxResult.success(handleList);
//构建球机树
resultTree = BuildTreeUtil.listInfoToTree(JSONArray.parseArray(JSON.toJSONString(list)), "id", "parentId", "children");
} catch (Exception e) {
log.error(e.toString(), e);
}
return AjaxResult.success();
return AjaxResult.success(resultTree);
}
}

View File

@ -20,7 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
tdu.id,
CONCAT(tpe.name,'-',tpe.phone) AS label,
td.dev_code AS devCode,
td.dev_index AS devIndex,
IFNULL(td.dev_index,0) AS devIndex,
tdu.pro_id AS parentId,
tp.depart_id AS departId
FROM tb_dev_use tdu