修改bug
This commit is contained in:
parent
10383e2315
commit
64d5b54ed0
|
|
@ -12,6 +12,8 @@ import org.jeecgframework.poi.excel.annotation.Excel;
|
|||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 护理单元
|
||||
|
|
@ -145,5 +147,23 @@ public class NuBaseInfo implements Serializable {
|
|||
private String maintainStatus;//设备状态
|
||||
@TableField(exist = false)
|
||||
private String deviceType;//设备类型
|
||||
@TableField(exist = false)
|
||||
private String parentId;//上级id
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<NuBaseInfo> children = new ArrayList<>();
|
||||
|
||||
// 构造方法
|
||||
public NuBaseInfo(String id, String nuName, String nuId, String parentId) {
|
||||
this.id = id;
|
||||
this.nuName = nuName;
|
||||
this.nuId = nuId;
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
// 添加子节点
|
||||
public void addChild(NuBaseInfo child) {
|
||||
children.add(child);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,4 +17,6 @@ public interface NuBaseInfoMapper extends BaseMapper<NuBaseInfo> {
|
|||
NuBaseInfo queryByElderIdNum(@Param("idCard") String idCard);
|
||||
|
||||
List<NuBaseInfo> selectWlsbList();
|
||||
|
||||
List<NuBaseInfo> selectJcgnList();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,13 @@
|
|||
</select>
|
||||
|
||||
<select id="selectWlsbList" resultType="com.nu.modules.baseinfo.entity.NuBaseInfo">
|
||||
select sn as device_sn,device_name,'1' as device_type,nu_id,maintain_status from nu_iot_tplink_camera
|
||||
union all
|
||||
select cid as device_sn,cid as device_name,'2' as device_type,nu_id,maintain_status from nu_iot_tq_electricity_meter
|
||||
union all
|
||||
select cid as device_sn,cid as device_name,'3' as device_type,nu_id,maintain_status from nu_iot_tq_water_meter
|
||||
union all
|
||||
select sn as device_sn,device_name,'4' as device_type,nu_id,maintain_status from nu_iot_yiweilian_humid_device
|
||||
select nu_id as device_sn,device_name, device_type,nu_id,device_status as maintain_status from nu_iot_device_preview
|
||||
where nu_id is not null and device_status is not null and device_status != '损坏'
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectJcgnList" resultType="com.nu.modules.baseinfo.entity.NuBaseInfo">
|
||||
SELECT a.permission_id as id,b.name as nu_name,a.role_id as nu_id,b.parent_id from nu_app_nuid_permission a
|
||||
inner join nu_app_permission b on a.permission_id = b.id
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description: 护理单元
|
||||
|
|
@ -41,7 +43,7 @@ public class NuBaseInfoServiceImpl extends ServiceImpl<NuBaseInfoMapper, NuBaseI
|
|||
|
||||
QueryWrapper<NuBaseInfo> qw = new QueryWrapper<>();
|
||||
qw.eq("nu_id", nuId);
|
||||
qw.eq("area_flag",areaType);//区域属性
|
||||
// qw.eq("area_flag",areaType);//区域属性
|
||||
qw.eq("del_flag", "0");
|
||||
NuBaseInfo nuBaseInfo = baseMapper.selectOne(qw);
|
||||
if (nuBaseInfo == null) {
|
||||
|
|
@ -82,44 +84,61 @@ public class NuBaseInfoServiceImpl extends ServiceImpl<NuBaseInfoMapper, NuBaseI
|
|||
@Override
|
||||
@DS("#orgCode")
|
||||
public List<Map<String, Object>> getNuListByOrgCode(String orgCode) {
|
||||
//护理单元
|
||||
List<NuBaseInfo> list = baseMapper.selectList(new QueryWrapper<>());
|
||||
List<Map<String, Object>> mapList = new ArrayList<>();
|
||||
//设备信息
|
||||
List<NuBaseInfo> wlsbList = baseMapper.selectWlsbList();
|
||||
//基础功能
|
||||
List<NuBaseInfo> jcgnList = baseMapper.selectJcgnList();
|
||||
List<NuBaseInfo> mergedTrees = buildTree(jcgnList);
|
||||
|
||||
for (NuBaseInfo info : list) {
|
||||
String sxtStr = "";//摄像头集合
|
||||
String dbStr = "";//电表集合
|
||||
String sbStr = "";//水表集合
|
||||
String wsdjStr = "";//温湿度计集合
|
||||
List<NuBaseInfo> children = new ArrayList<>();
|
||||
if(wlsbList == null){
|
||||
continue;
|
||||
}
|
||||
for (NuBaseInfo wlsb : wlsbList) {
|
||||
if (info.getNuId().equals(wlsb.getNuId())) {
|
||||
if ("1".equals(wlsb.getDeviceType())) {
|
||||
sxtStr = sxtStr + wlsb.getDeviceSn() + ",";
|
||||
} else if ("2".equals(wlsb.getDeviceType())) {
|
||||
dbStr = dbStr + wlsb.getDeviceSn() + ",";
|
||||
} else if ("3".equals(wlsb.getDeviceType())) {
|
||||
sbStr = sbStr + wlsb.getDeviceSn() + ",";
|
||||
} else if ("4".equals(wlsb.getDeviceType())) {
|
||||
wsdjStr = wsdjStr + wlsb.getDeviceSn() + ",";
|
||||
if ("SURVEILLANCECAMERA".equals(wlsb.getDeviceType())) {
|
||||
sxtStr = sxtStr + wlsb.getNuId() + ",";
|
||||
} else if ("db".equals(wlsb.getDeviceType())) {
|
||||
dbStr = dbStr + wlsb.getNuId() + ",";
|
||||
} else if ("sb".equals(wlsb.getDeviceType())) {
|
||||
sbStr = sbStr + wlsb.getNuId() + ",";
|
||||
} else if ("wsdj".equals(wlsb.getDeviceType())) {
|
||||
wsdjStr = wsdjStr + wlsb.getNuId() + ",";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (sxtStr.length() > 0) sxtStr = sxtStr.substring(0, sxtStr.length() - 1);
|
||||
if (dbStr.length() > 0) dbStr = dbStr.substring(0, dbStr.length() - 1);
|
||||
if (sbStr.length() > 0) sbStr = sbStr.substring(0, sbStr.length() - 1);
|
||||
if (wsdjStr.length() > 0) wsdjStr = wsdjStr.substring(0, wsdjStr.length() - 1);
|
||||
if (sxtStr.length() > 0) sxtStr = sxtStr.split(",").length +"";
|
||||
if (dbStr.length() > 0) dbStr = dbStr.split(",").length +"";
|
||||
if (sbStr.length() > 0) sbStr = sbStr.split(",").length +"";
|
||||
if (wsdjStr.length() > 0) wsdjStr = wsdjStr.split(",").length +"";
|
||||
|
||||
for (NuBaseInfo mergedTree : mergedTrees) {
|
||||
if (info.getNuId().equals(mergedTree.getNuId())) {
|
||||
children.add(mergedTree);
|
||||
}
|
||||
}
|
||||
Map<String, Object> map = Map.of(
|
||||
"nuId", info.getNuId(),
|
||||
"nuName", info.getNuName(),
|
||||
"status", info.getStatus(),
|
||||
"sxtList", sxtStr,
|
||||
"dbList", dbStr,
|
||||
"sbList", sbStr,
|
||||
"wsdjList", wsdjStr
|
||||
"wsdjList", wsdjStr,
|
||||
"children",children
|
||||
);
|
||||
mapList.add(map);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return mapList;
|
||||
|
|
@ -130,4 +149,69 @@ public class NuBaseInfoServiceImpl extends ServiceImpl<NuBaseInfoMapper, NuBaseI
|
|||
public IPage<NuBaseInfo> getList(String sysOrgCode,Page<NuBaseInfo> page, QueryWrapper<NuBaseInfo> queryWrapper) {
|
||||
return baseMapper.selectPage(page, queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建分类树
|
||||
* @param nodes 原始节点列表
|
||||
* @return 根节点列表
|
||||
*/
|
||||
public List<NuBaseInfo> buildTree(List<NuBaseInfo> nodes) {
|
||||
// 按 nuId 分组
|
||||
Map<String, List<NuBaseInfo>> groupByNuId = nodes.stream()
|
||||
.collect(Collectors.groupingBy(NuBaseInfo::getNuId));
|
||||
|
||||
List<NuBaseInfo> allRootNodes = new ArrayList<>();
|
||||
|
||||
// 对每个 nuId 分组单独构建树
|
||||
for (Map.Entry<String, List<NuBaseInfo>> entry : groupByNuId.entrySet()) {
|
||||
String nuId = entry.getKey();
|
||||
List<NuBaseInfo> sameNuIdNodes = entry.getValue();
|
||||
|
||||
List<NuBaseInfo> rootNodes = buildSingleTree(sameNuIdNodes, nuId);
|
||||
allRootNodes.addAll(rootNodes);
|
||||
}
|
||||
|
||||
return allRootNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建单个 nuId 的分类树
|
||||
*/
|
||||
private List<NuBaseInfo> buildSingleTree(List<NuBaseInfo> nodes, String nuId) {
|
||||
List<NuBaseInfo> rootNodes = new ArrayList<>();
|
||||
Map<String, NuBaseInfo> nodeMap = new HashMap<>();
|
||||
|
||||
// 第一步:将所有节点存入map
|
||||
for (NuBaseInfo node : nodes) {
|
||||
nodeMap.put(node.getId(), node);
|
||||
}
|
||||
|
||||
// 第二步:建立父子关系
|
||||
for (NuBaseInfo node : nodes) {
|
||||
String parentId = node.getParentId();
|
||||
|
||||
if (parentId == null || parentId.isEmpty() || parentId.equals("0")) {
|
||||
// 根节点
|
||||
rootNodes.add(node);
|
||||
} else {
|
||||
// 查找父节点
|
||||
NuBaseInfo parent = nodeMap.get(parentId);
|
||||
if (parent != null) {
|
||||
// 父节点存在,添加到父节点的children
|
||||
if (parent.getChildren() == null) {
|
||||
parent.setChildren(new ArrayList<>());
|
||||
}
|
||||
parent.getChildren().add(node);
|
||||
} else {
|
||||
// 父节点不存在,作为根节点处理
|
||||
rootNodes.add(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rootNodes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue