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

直接内存代替缓存

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