forked from integrated_whb/integrated_whb
Merge remote-tracking branch 'origin/dev' into dev
commit
53ce6b2698
|
@ -33,6 +33,7 @@ public class AppElectronicFenceController extends BaseController {
|
|||
@ResponseBody
|
||||
public Object listTree() {
|
||||
PageData pd = this.getPageData();
|
||||
pd.put("childKey", "children");
|
||||
return ReturnMap.ok().put("zTreeNodes", JSON.toJSONString(electronicFenceService.listTree(pd)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public class ElectronicFenceController extends BaseController {
|
|||
String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件
|
||||
if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
|
||||
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
|
||||
pd.put("childKey", "nodes");
|
||||
return ReturnMap.ok().put("zTreeNodes", JSON.toJSONString(electronicFenceService.listTree(pd)));
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ public interface ElectronicFenceMapper {
|
|||
List<PageData> listAll(PageData pd);
|
||||
|
||||
List<Map<String, Object>> listTree(PageData pd);
|
||||
List<Map<String, Object>> listTreeApp(PageData pd);
|
||||
|
||||
List<PageData> findByPId(PageData pd);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,11 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService {
|
|||
|
||||
@Override
|
||||
public List<Map<String, Object>> listTree(PageData pd) {
|
||||
if ("children".equals(pd.getString("childKey"))) {
|
||||
// 手机端
|
||||
List<Map<String, Object>> dataList = electronicFenceMapper.listTreeApp(pd);
|
||||
return buildTreeApp(dataList);
|
||||
}
|
||||
List<Map<String, Object>> dataList = electronicFenceMapper.listTree(pd);
|
||||
return buildTree(dataList);
|
||||
}
|
||||
|
@ -59,26 +64,6 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService {
|
|||
return electronicFenceMapper.findByPId(pd).size() > 0 ;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Map<String,Object>> dataList = new ArrayList<>();
|
||||
HashMap<String,Object> d1 = new HashMap();
|
||||
d1.put("id","96acf1a16df646dda03592af042f3abc");
|
||||
d1.put("name","卓云企业");
|
||||
d1.put("pId","0");
|
||||
d1.put("ELECTRONIC_FENCE_ID","1");
|
||||
d1.put("ELECTRONIC_FENCE_NAME","电子围栏1");
|
||||
HashMap<String,Object> d2 = new HashMap();
|
||||
d2.put("id","e16f4020df5145bd8ada827ec1bf310f");
|
||||
d2.put("name","开发部");
|
||||
d2.put("pId","96acf1a16df646dda03592af042f3abc");
|
||||
d2.put("ELECTRONIC_FENCE_ID","2");
|
||||
d2.put("ELECTRONIC_FENCE_NAME","电子围栏2");
|
||||
dataList.add(d1);
|
||||
dataList.add(d2);
|
||||
List<Map<String, Object>> maps = buildTree(dataList);
|
||||
System.out.println(maps);
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> buildTree(List<Map<String, Object>> dataList) {
|
||||
Map<String, Map<String, Object>> idToNodeMap = new HashMap<>();
|
||||
List<Map<String, Object>> rootNodes = new ArrayList<>();
|
||||
|
@ -105,6 +90,34 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService {
|
|||
}
|
||||
}
|
||||
|
||||
return rootNodes;
|
||||
}
|
||||
public static List<Map<String, Object>> buildTreeApp(List<Map<String, Object>> dataList) {
|
||||
Map<String, Map<String, Object>> idToNodeMap = new HashMap<>();
|
||||
List<Map<String, Object>> rootNodes = new ArrayList<>();
|
||||
|
||||
// Map IDs to their nodes
|
||||
for (Map<String, Object> data : dataList) {
|
||||
String id = (String) data.get("ELECTRONIC_FENCE_AREA_ID");
|
||||
idToNodeMap.put(id, data);
|
||||
}
|
||||
|
||||
// Find root nodes and attach children
|
||||
for (Map.Entry<String, Map<String, Object>> entry : idToNodeMap.entrySet()) {
|
||||
Map<String, Object> node = entry.getValue();
|
||||
String pId = (String) node.get("pId");
|
||||
if ("0".equals(pId)) {
|
||||
rootNodes.add(node);
|
||||
} else {
|
||||
Map<String, Object> parentNode = idToNodeMap.get(pId);
|
||||
if (parentNode != null) {
|
||||
List<Map<String, Object>> children = (List<Map<String, Object>>) parentNode.getOrDefault("children", new ArrayList<>());
|
||||
children.add(node);
|
||||
parentNode.put("children", children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rootNodes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,6 +177,17 @@
|
|||
f
|
||||
where f.ISDELETE = '0' and f.CORPINFO_ID = #{CORPINFO_ID} and f.PARENT_ID = #{ELECTRONIC_FENCE_AREA_ID}
|
||||
</select>
|
||||
<select id="listTreeApp" resultType="java.util.Map">
|
||||
SELECT
|
||||
ELECTRONIC_FENCE_AREA_ID,
|
||||
IFNULL(ELECTRONIC_FENCE_ID,ELECTRONIC_FENCE_AREA_ID) id,
|
||||
ELECTRONIC_FENCE_AREA_NAME name,
|
||||
PARENT_ID pId
|
||||
FROM
|
||||
electronic_fence f
|
||||
WHERE
|
||||
f.ISDELETE = '0' and f.CORPINFO_ID = #{CORPINFO_ID}
|
||||
</select>
|
||||
|
||||
|
||||
<!-- 批量删除 -->
|
||||
|
|
Loading…
Reference in New Issue