提交 d86e600a 编写于 作者: sq3536's avatar sq3536

直接内存代替缓存

上级 8a95b275
...@@ -18,51 +18,59 @@ import java.util.*; ...@@ -18,51 +18,59 @@ import java.util.*;
public class OUModelService public class OUModelService
{ {
@Autowired @Autowired
private IIBZOrganizationService iibzOrganizationService; private IIBZOrganizationService iibzOrganizationService;
@Autowired @Autowired
private IIBZDepartmentService iibzDepartmentService; private IIBZDepartmentService iibzDepartmentService;
@Cacheable( value="ibzou-model",key = "'orgmap'") private Map<String, Map<String, Set<String>>> orgmap=null;
public synchronized Map<String, Map<String, Set<String>>> getOrgModel() private Object lockOrg=new Object();
//@Cacheable( value="ibzou-model",key = "'orgmap'")
public Map<String, Map<String, Set<String>>> getOrgModel()
{ {
Map<String, Map<String, Set<String>>> store=new LinkedHashMap<>(); if(orgmap!=null)
Map<String, IBZOrganization> orgset=new LinkedHashMap<>(); return orgmap;
List<IBZOrganization> listOrg=iibzOrganizationService.list(); synchronized(lockOrg)
for(IBZOrganization org:listOrg)
{ {
Map<String, Set<String>> map=new HashMap<>(); if(orgmap!=null)
Set<String> parent=new LinkedHashSet<String>(); return orgmap;
if(!StringUtils.isEmpty(org.getParentorgid())) Map<String, Map<String, Set<String>>> store=new LinkedHashMap<>();
parent.add(org.getParentorgid()); Map<String, IBZOrganization> orgset=new LinkedHashMap<>();
map.put("parent",parent); List<IBZOrganization> listOrg=iibzOrganizationService.list();
Set<String> sub=new LinkedHashSet<String>(); for(IBZOrganization org:listOrg)
sub.add(org.getOrgid()); {
map.put("sub",sub); Map<String, Set<String>> map=new HashMap<>();
store.put(org.getOrgid(),map); Set<String> parent=new LinkedHashSet<String>();
orgset.put(org.getOrgid(),org); if(!StringUtils.isEmpty(org.getParentorgid()))
} parent.add(org.getParentorgid());
map.put("parent",parent);
Set<String> sub=new LinkedHashSet<String>();
sub.add(org.getOrgid());
map.put("sub",sub);
store.put(org.getOrgid(),map);
orgset.put(org.getOrgid(),org);
}
for(IBZOrganization org:listOrg) for(IBZOrganization org:listOrg)
{ {
loopOrg(org,orgset,store); loopOrg(org,orgset,store);
} }
for(IBZOrganization org:listOrg) for(IBZOrganization org:listOrg)
{
for(String sub:store.get(org.getOrgid()).get("sub"))
{ {
if(!org.getOrgid().equals(sub)) for(String sub:store.get(org.getOrgid()).get("sub"))
store.get(sub).get("parent").add(org.getOrgid()); {
if(!org.getOrgid().equals(sub))
store.get(sub).get("parent").add(org.getOrgid());
}
} }
orgmap=store;
} }
return store; return orgmap;
} }
public void loopOrg(IBZOrganization org,Map<String, IBZOrganization> orgset,Map<String, Map<String, Set<String>>> store) public void loopOrg(IBZOrganization org,Map<String, IBZOrganization> orgset,Map<String, Map<String, Set<String>>> store)
...@@ -79,102 +87,114 @@ public class OUModelService ...@@ -79,102 +87,114 @@ public class OUModelService
} }
@Cacheable( value="ibzou-model",key = "'deptmap'")
public synchronized Map<String, Map<String, Set<String>>> getDeptModel(Map<String, Map<String, Set<String>>> orgstore)
{
if(orgstore==null)
orgstore=this.getOrgModel();
Map<String, Map<String, Set<String>>> store=new LinkedHashMap<>();
Map<String, IBZDepartment> deptset=new LinkedHashMap<>();
Map<String, Set<String>> bcmap=new HashMap<>(); private Map<String, Map<String, Set<String>>> deptmap=null;
private Object lockDept=new Object();
List<IBZDepartment> listDept=iibzDepartmentService.list(); //@Cacheable( value="ibzou-model",key = "'deptmap'")
for(IBZDepartment dept:listDept) public Map<String, Map<String, Set<String>>> getDeptModel(Map<String, Map<String, Set<String>>> orgstore)
{
if(deptmap!=null)
return deptmap;
synchronized(lockDept)
{ {
Map<String, Set<String>> map=new HashMap<>(); if(deptmap!=null)
Set<String> parent=new LinkedHashSet<String>(); return deptmap;
if(!StringUtils.isEmpty(dept.getParentdeptid())) if(orgstore==null)
parent.add(dept.getParentdeptid()); orgstore=this.getOrgModel();
map.put("parent",parent); Map<String, Map<String, Set<String>>> store=new LinkedHashMap<>();
Set<String> sub=new LinkedHashSet<String>(); Map<String, IBZDepartment> deptset=new LinkedHashMap<>();
sub.add(dept.getDeptid());
map.put("sub",sub); Map<String, Set<String>> bcmap=new HashMap<>();
store.put(dept.getDeptid(),map);
deptset.put(dept.getDeptid(),dept); List<IBZDepartment> listDept=iibzDepartmentService.list();
for(IBZDepartment dept:listDept)
String bc=dept.getBcode();
if(!StringUtils.isEmpty(bc))
{ {
bc=bc.replace(";",",").replace(";",",").replace(",",","); Map<String, Set<String>> map=new HashMap<>();
String[] bcs=bc.split(","); Set<String> parent=new LinkedHashSet<String>();
for(String strbc:bcs) if(!StringUtils.isEmpty(dept.getParentdeptid()))
parent.add(dept.getParentdeptid());
map.put("parent",parent);
Set<String> sub=new LinkedHashSet<String>();
sub.add(dept.getDeptid());
map.put("sub",sub);
store.put(dept.getDeptid(),map);
deptset.put(dept.getDeptid(),dept);
String bc=dept.getBcode();
if(!StringUtils.isEmpty(bc))
{ {
strbc=strbc.trim(); bc=bc.replace(";",",").replace(";",",").replace(",",",");
if(!StringUtils.isEmpty(strbc)) String[] bcs=bc.split(",");
for(String strbc:bcs)
{ {
if(!bcmap.containsKey(strbc)) strbc=strbc.trim();
if(!StringUtils.isEmpty(strbc))
{ {
Set<String> bcset=new HashSet<>(); if(!bcmap.containsKey(strbc))
bcmap.put(strbc,bcset); {
Set<String> bcset=new HashSet<>();
bcmap.put(strbc,bcset);
}
bcmap.get(strbc).add(dept.getDeptid()+":"+dept.getOrgid());
} }
bcmap.get(strbc).add(dept.getDeptid()+":"+dept.getOrgid());
} }
} }
} }
} for(IBZDepartment dept:listDept)
for(IBZDepartment dept:listDept)
{
loopDept(dept,deptset,store);
}
for(IBZDepartment dept:listDept)
{
for(String sub:store.get(dept.getDeptid()).get("sub"))
{ {
if(!dept.getDeptid().equals(sub)) loopDept(dept,deptset,store);
store.get(sub).get("parent").add(dept.getDeptid());
} }
}
for(IBZDepartment dept:listDept) for(IBZDepartment dept:listDept)
{ {
String orgid=dept.getOrgid(); for(String sub:store.get(dept.getDeptid()).get("sub"))
if(StringUtils.isEmpty(orgid)||(!orgstore.containsKey(orgid))) {
continue; if(!dept.getDeptid().equals(sub))
store.get(sub).get("parent").add(dept.getDeptid());
}
}
String bc=dept.getBcode(); for(IBZDepartment dept:listDept)
if(!StringUtils.isEmpty(bc))
{ {
bc = bc.replace(";", ",").replace(";", ",").replace(",", ","); String orgid=dept.getOrgid();
String[] bcs = bc.split(","); if(StringUtils.isEmpty(orgid)||(!orgstore.containsKey(orgid)))
for (String strbc : bcs) continue;
String bc=dept.getBcode();
if(!StringUtils.isEmpty(bc))
{ {
strbc = strbc.trim(); bc = bc.replace(";", ",").replace(";", ",").replace(",", ",");
if (!StringUtils.isEmpty(strbc)) String[] bcs = bc.split(",");
for (String strbc : bcs)
{ {
if(bcmap.containsKey(strbc)) strbc = strbc.trim();
if (!StringUtils.isEmpty(strbc))
{ {
Set<String> bcset=bcmap.get(strbc); if(bcmap.containsKey(strbc))
for(String bcstring:bcset)
{ {
String[] bcstringarr=bcstring.split(":"); Set<String> bcset=bcmap.get(strbc);
if(bcstringarr.length==2) for(String bcstring:bcset)
{ {
String bcdept=bcstringarr[0]; String[] bcstringarr=bcstring.split(":");
String bcorg=bcstringarr[1]; if(bcstringarr.length==2)
for(String porg:orgstore.get(orgid).get("parent"))
{ {
if(bcorg.equals(porg)) String bcdept=bcstringarr[0];
store.get(dept.getDeptid()).get("parent").add(bcdept); String bcorg=bcstringarr[1];
} for(String porg:orgstore.get(orgid).get("parent"))
for(String sorg:orgstore.get(orgid).get("sub")) {
{ if(bcorg.equals(porg))
if(bcorg.equals(sorg)) store.get(dept.getDeptid()).get("parent").add(bcdept);
store.get(dept.getDeptid()).get("sub").add(bcdept); }
for(String sorg:orgstore.get(orgid).get("sub"))
{
if(bcorg.equals(sorg))
store.get(dept.getDeptid()).get("sub").add(bcdept);
}
} }
} }
} }
...@@ -182,9 +202,11 @@ public class OUModelService ...@@ -182,9 +202,11 @@ public class OUModelService
} }
} }
} }
deptmap=store;
} }
return store; return deptmap;
} }
public void loopDept(IBZDepartment dept,Map<String, IBZDepartment> deptset,Map<String, Map<String, Set<String>>> store) public void loopDept(IBZDepartment dept,Map<String, IBZDepartment> deptset,Map<String, Map<String, Set<String>>> store)
...@@ -201,10 +223,12 @@ public class OUModelService ...@@ -201,10 +223,12 @@ public class OUModelService
} }
@CacheEvict( value="ibzou-model",allEntries = true) //@CacheEvict( value="ibzou-model",allEntries = true)
public void refreshModel() public synchronized void refreshModel()
{ {
this.deptmap=null;
this.orgmap=null;
} }
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册