Commit df226832 authored by tangwei's avatar tangwei

增加数据字典,表单批量查询接口

parent 24d0b99a
package com.yeejoin.amos.boot.biz.common.utils;
import java.util.List;
public class MenuFrom {
public String id;
public String key;
public String value;
public String title;
public String label;
public String name;
public String parentId;
public Boolean isLeaf=false;
public List<MenuFrom> children;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public Boolean getIsLeaf() {
return isLeaf;
}
public void setIsLeaf(Boolean isLeaf) {
this.isLeaf = isLeaf;
}
public List<MenuFrom> getChildren() {
return children;
}
public void setChildren(List<MenuFrom> children) {
this.children = children;
}
public MenuFrom(String id,String value,String key, String title, String label, String name, String parentId) {
super();
this.id = id;
this.value = value;
this.key = key;
this.title = title;
this.label = label;
this.name = name;
this.parentId = parentId;
}
public MenuFrom() {
super();
}
}
...@@ -12,6 +12,8 @@ public class RedisKey { ...@@ -12,6 +12,8 @@ public class RedisKey {
public static final String FORM_CODE = "form_code_"; public static final String FORM_CODE = "form_code_";
//根据字典code获取数据字典列表 //根据字典code获取数据字典列表
public static final String DATA_DICTIONARY_CODE= "data_dictionary_code_"; public static final String DATA_DICTIONARY_CODE= "data_dictionary_code_";
//根据字典code获取数据字典列表
public static final String DATA_DICTIONARY_CODE_XIN= "data_dictionary_code_xin_";
//根据id获取消防人员基本信息 //根据id获取消防人员基本信息
public static final String FIREFIGHTERS_ID="firefighters_id_"; public static final String FIREFIGHTERS_ID="firefighters_id_";
//根据id获取消防人员列表基本信息 //根据id获取消防人员列表基本信息
......
...@@ -128,4 +128,141 @@ public class TreeParser{ ...@@ -128,4 +128,141 @@ public class TreeParser{
return childList; return childList;
} }
/**
* @param topId 父id
* @param entityList 数据集合
* @param packageURL 集合对象包名+类名
* @param IDMethodName 集合对象获取树id 方法名
* @param IDHierarchy 集合对象获取树id 来源于自己 还是父级( 1自己,2 父级 ,3 父级的父级)
* @param NAMEMethodName 集合对象获取树name 方法名
* @param PARENTIDMethodName 集合对象获取树父id 方法名
* @return java.util.List<com.yeejoin.amos.boot.module.jcs.api.vo.Menu>
* <PRE>
* author tw
* date 2021/6/10
* </PRE>
*/
@SuppressWarnings("unchecked")
public static List<MenuFrom> getTreexin(String topId, @SuppressWarnings("rawtypes") Collection entityList,String packageURL,String IDMethodName,int IDHierarchy, String NAMEMethodName,String PARENTIDMethodName ) throws Exception{
List<MenuFrom> resultList=new ArrayList<>();
@SuppressWarnings("rawtypes")
Class clazz= Class.forName(packageURL);
Method IDMethodNameme = null;
switch (IDHierarchy) { case 1:
IDMethodNameme = clazz.getDeclaredMethod(IDMethodName);
break;
case 2:
IDMethodNameme = clazz.getSuperclass().getDeclaredMethod(IDMethodName);
break;
case 3:
IDMethodNameme = clazz.getSuperclass().getSuperclass().getDeclaredMethod(IDMethodName);
break;
default:
IDMethodNameme = clazz.getDeclaredMethod(IDMethodName);
break;
}
Method NAMEMethodNameme = clazz.getDeclaredMethod(NAMEMethodName);
Method PARENTIDMethodNameme = clazz.getDeclaredMethod(PARENTIDMethodName);
//获取顶层元素集合
String parentId;
for (Object ob : entityList) {
Object entity = clazz.cast(ob);
parentId=PARENTIDMethodNameme.invoke(entity)!=null? String.valueOf(PARENTIDMethodNameme.invoke(entity)):null;
if(parentId==null||parentId.equals(topId)){
MenuFrom menu=new MenuFrom(String.valueOf(IDMethodNameme.invoke(entity)),String.valueOf(IDMethodNameme.invoke(entity)),String.valueOf(IDMethodNameme.invoke(entity)), String.valueOf(NAMEMethodNameme.invoke(entity)),String.valueOf(NAMEMethodNameme.invoke(entity)), String.valueOf(NAMEMethodNameme.invoke(entity)),parentId);
resultList.add(menu);
}
}
//获取每个顶层元素的子数据集合
for (MenuFrom entity : resultList) {
List<MenuFrom> list=getSubxin(entity.getKey(), entityList, packageURL, IDMethodName,IDHierarchy, NAMEMethodName, PARENTIDMethodName);
if(list!=null&&list.size()>0) {
entity.setIsLeaf(true);
}
entity.setChildren(list);
}
return resultList;
}
/**
* 获取子数据集合
*/
@SuppressWarnings("unchecked")
private static List<MenuFrom> getSubxin(String topId, @SuppressWarnings("rawtypes") Collection entityList,String packageURL,String IDMethodName,int IDHierarchy,String NAMEMethodName,String PARENTIDMethodName ) throws Exception{
List<MenuFrom> childList=new ArrayList<>();
@SuppressWarnings("rawtypes")
Class clazz= Class.forName(packageURL);
Method IDMethodNameme = null;
switch (IDHierarchy) {
case 1:
IDMethodNameme = clazz.getDeclaredMethod(IDMethodName);
break;
case 2:
IDMethodNameme = clazz.getSuperclass().getDeclaredMethod(IDMethodName);
break;
case 3:
IDMethodNameme = clazz.getSuperclass().getSuperclass().getDeclaredMethod(IDMethodName);
break;
default:
IDMethodNameme = clazz.getDeclaredMethod(IDMethodName);
break;
}
Method NAMEMethodNameme = clazz.getDeclaredMethod(NAMEMethodName);
Method PARENTIDMethodNameme = clazz.getDeclaredMethod(PARENTIDMethodName);
String parentId;
//子集的直接子对象
for (Object ob : entityList) {
Object entity = clazz.cast(ob);
parentId=PARENTIDMethodNameme.invoke(entity)!=null? String.valueOf(PARENTIDMethodNameme.invoke(entity)):null;
if(parentId==null) {
if(parentId==topId){
MenuFrom menu=new MenuFrom(String.valueOf(IDMethodNameme.invoke(entity)),String.valueOf(IDMethodNameme.invoke(entity)),String.valueOf(IDMethodNameme.invoke(entity)), String.valueOf(NAMEMethodNameme.invoke(entity)),String.valueOf(NAMEMethodNameme.invoke(entity)), String.valueOf(NAMEMethodNameme.invoke(entity)),parentId);
childList.add(menu);
}
}else {
if(topId!=null&&topId.equals(parentId)){
MenuFrom menu=new MenuFrom(String.valueOf(IDMethodNameme.invoke(entity)),String.valueOf(IDMethodNameme.invoke(entity)),String.valueOf(IDMethodNameme.invoke(entity)), String.valueOf(NAMEMethodNameme.invoke(entity)),String.valueOf(NAMEMethodNameme.invoke(entity)), String.valueOf(NAMEMethodNameme.invoke(entity)),parentId);
menu.setIsLeaf(true);
childList.add(menu);
}
}
}
//子集的间接子对象
for (MenuFrom entity : childList) {
entity.setChildren(getSubxin(entity.getKey(), entityList, packageURL, IDMethodName,IDHierarchy, NAMEMethodName, PARENTIDMethodName));
}
//递归退出条件
if(childList.size()==0){
return null;
}
return childList;
}
} }
...@@ -12,6 +12,7 @@ import com.yeejoin.amos.boot.module.jcs.biz.service.impl.DataDictionaryServiceIm ...@@ -12,6 +12,7 @@ import com.yeejoin.amos.boot.module.jcs.biz.service.impl.DataDictionaryServiceIm
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bouncycastle.jcajce.provider.asymmetric.ec.SignatureSpi.ecCVCDSA;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -177,18 +178,19 @@ public class DataDictionaryController extends BaseController { ...@@ -177,18 +178,19 @@ public class DataDictionaryController extends BaseController {
QueryWrapper<DataDictionary> queryWrapper = new QueryWrapper<>(); QueryWrapper<DataDictionary> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type", type); queryWrapper.eq("type", type);
queryWrapper.orderByAsc("sort_num"); queryWrapper.orderByAsc("sort_num");
if(redisUtils.hasKey(RedisKey.DATA_DICTIONARY_CODE+type)){ if(redisUtils.hasKey(RedisKey.DATA_DICTIONARY_CODE_XIN+type)){
Object obj= redisUtils.get(RedisKey.DATA_DICTIONARY_CODE+type); Object obj= redisUtils.get(RedisKey.DATA_DICTIONARY_CODE_XIN+type);
objectObjectHashMap.put(type,obj); objectObjectHashMap.put(type,obj);
}else{ }else{
Collection<DataDictionary> list=iDataDictionaryService.list(queryWrapper); Collection<DataDictionary> list=iDataDictionaryService.list(queryWrapper);
List<Menu> menus = null; List<MenuFrom> menus = null;
menus = TreeParser.getTree(null, list, DataDictionary.class.getName(),"getCode",0, "getName", "getParent"); menus = TreeParser.getTreexin(null, list, DataDictionary.class.getName(),"getCode",0, "getName", "getParent");
redisUtils.set(RedisKey.DATA_DICTIONARY_CODE+type, JSON.toJSON(menus),time); redisUtils.set(RedisKey.DATA_DICTIONARY_CODE_XIN+type, JSON.toJSON(menus),time);
objectObjectHashMap.put(type,menus); objectObjectHashMap.put(type,menus);
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("系统异常!"); throw new RuntimeException("系统异常!");
} }
return ResponseHelper.buildResponse(objectObjectHashMap); return ResponseHelper.buildResponse(objectObjectHashMap);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment