项目中后台查询字典切换显示内容

List list = companyDao.xyunitUserListByType(hash);

Map<String, String> para = new HashMap<String, String>();
para.put("Unit_type", "612");
para.put("Unit_nmtype", "601");
para.put("Class_type", "611");


para.put("Communication_methods_type", "207");
para.put("Unit_condition", "604");
para.put("Industry_categories", "99997");
list = listFormat(list, para);

 

//封装的方法==============

public List listFormat(List list,Map<String,String>para) {
if(null==list ||list.size()==0) {
return new ArrayList();
}
//获取list元素的类
Class c=list.get(0).getClass();
boolean flag=false;
//hashmap为真。实体类为false
if(c.equals(HashMap.class)) {
flag=true;
}

try {
//便利参数,获取需要替换的字段,以及按照的fid
for (String key : para.keySet()) {
String fid=para.get(key);
//redis 获取字典
List listResult= (List) RedisUtils.get(fid);
// redis为空则查询后再存
if(null==listResult) {
listResult=dictService.getDictByFid(fid);
RedisUtils.save(key, listResult);
}
//取得get/set方法,输入值
Method gm =null;Method sm =null;String allin=null;
if(!flag) {
gm =c.getMethod("get"+key, null);
sm =c.getMethod("set"+key, String.class);
}
//循环处理list
for(int i =0;i<list.size();i++) {
Object o = list .get(i);
if(flag) { allin=(String) ((Map) o).get(key);}
else { allin=(String) gm.invoke(o, null);}
System.out.println("输入量="+allin);
String out="";
//切割循环处理具体量
if (null!=allin&&!"".equals(allin)) {
String[] ins=allin.split(",");
for(int j =0;j<ins.length;j++) {
String in =ins[j];
if (!"".equals(in)) {
String res=null;
//进行配对
for(int z =0;z<listResult.size();z++) {
if(ins[j].equals(((Map)listResult.get(z)).get("id"))) {
res=(String) ((Map)listResult.get(z)).get("name");break;
}
}
//未找到不处理
if (null==res) {
out=in;
}else {
out = out+res+" ";
}}
}
System.out.println("输出量="+out);
if(!flag) {sm.invoke(o, out);}
else{((Map<String, String>) o).put(key, out);}
list.remove(i);
list.add(i, o);
}
}

}

} catch (Exception e) {
e.printStackTrace();
}
return list;

}

posted @ 2020-01-11 19:40  红尘沙漏  阅读(242)  评论(0编辑  收藏  举报