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

重构了上下级关系

上级 fb0312a8
package cn.ibizlab.core.extensions.aspect;
import cn.ibizlab.core.extensions.service.OUModelService;
import cn.ibizlab.util.annotation.DEField;
import cn.ibizlab.util.enums.DEFieldDefaultValueType;
import cn.ibizlab.util.enums.DEPredefinedFieldType;
import cn.ibizlab.util.helper.DEFieldCacheMap;
import cn.ibizlab.util.security.AuthenticationUser;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.AlternativeJdkIdGenerator;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 实体属性默认值切面,只有新建(Create)时才会填充默认值
*/
@Aspect
@Order(0)
@Component
public class OUModelRefreshAspect
{
@Autowired
@Lazy
private OUModelService ouModelService;
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZOrganizationService.creat*(..))")
public void AfterCreateOrg(JoinPoint point) throws Exception {
ouModelService.refreshModel();
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZOrganizationService.updat*(..))")
public void AfterUpdateOrg(JoinPoint point) throws Exception {
ouModelService.refreshModel();
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZOrganizationService.remov*(..))")
public void AfterRemoveOrg(JoinPoint point) throws Exception {
ouModelService.refreshModel();
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZOrganizationService.sav*(..))")
public void AfterSaveOrg(JoinPoint point) throws Exception {
ouModelService.refreshModel();
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZDepartmentService.creat*(..))")
public void AfterCreateDept(JoinPoint point) throws Exception {
ouModelService.refreshModel();
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZDepartmentService.updat*(..))")
public void AfterUpdateDept(JoinPoint point) throws Exception {
ouModelService.refreshModel();
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZDepartmentService.remov*(..))")
public void AfterRemoveDept(JoinPoint point) throws Exception {
ouModelService.refreshModel();
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZDepartmentService.sav*(..))")
public void AfterSaveDept(JoinPoint point) throws Exception {
ouModelService.refreshModel();
}
}
package cn.ibizlab.core.extensions.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import java.util.*;
@Service
public class OUCoreService
{
@Autowired
@Lazy
private OUModelService ouModelService;
public Map<String, Set<String>> getOrgModel(String orgid)
{
Map<String, Map<String, Set<String>>> store=ouModelService.getOrgModel();
if(store.containsKey(orgid))
{
Map<String, Set<String>> map = store.get(orgid);
return map;
}
else
{
Map<String, Set<String>> map=new HashMap<>();
map.put("parent",new LinkedHashSet<>());
map.put("sub",new LinkedHashSet<>());
return map;
}
}
public Map<String, Set<String>> getDeptModel(String deptid)
{
Map<String, Map<String, Set<String>>> store=ouModelService.getDeptModel(ouModelService.getOrgModel());
if(store.containsKey(deptid))
{
Map<String, Set<String>> map = store.get(deptid);
return map;
}
else
{
Map<String, Set<String>> map=new HashMap<>();
map.put("parent",new LinkedHashSet<>());
map.put("sub",new LinkedHashSet<>());
return map;
}
}
}
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.ou.domain.IBZDepartment;
import cn.ibizlab.core.ou.domain.IBZOrganization;
import cn.ibizlab.core.ou.service.IIBZDepartmentService;
import cn.ibizlab.core.ou.service.IIBZOrganizationService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.*;
@Service
public class OUModelService
{
@Autowired
private IIBZOrganizationService iibzOrganizationService;
@Autowired
private IIBZDepartmentService iibzDepartmentService;
public synchronized 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)
{
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)
{
for(String sub:store.get(org.getOrgid()).get("sub"))
{
if(!org.getOrgid().equals(sub))
store.get(sub).get("parent").add(org.getOrgid());
}
}
return store;
}
public void loopOrg(IBZOrganization org,Map<String, IBZOrganization> orgset,Map<String, Map<String, Set<String>>> store)
{
if(!StringUtils.isEmpty(org.getParentorgid()))
{
if(store.containsKey(org.getParentorgid()))
{
store.get(org.getParentorgid()).get("sub").add(org.getOrgid());
loopOrg(orgset.get(org.getParentorgid()),orgset,store);
}
}
}
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<>();
List<IBZDepartment> listDept=iibzDepartmentService.list();
for(IBZDepartment dept:listDept)
{
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))
{
bc=bc.replace(";",",").replace(";",",").replace(",",",");
String[] bcs=bc.split(",");
for(String strbc:bcs)
{
strbc=strbc.trim();
if(!StringUtils.isEmpty(strbc))
{
if(!bcmap.containsKey(strbc))
{
Set<String> bcset=new HashSet<>();
bcmap.put(strbc,bcset);
}
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"))
{
if(!dept.getDeptid().equals(sub))
store.get(sub).get("parent").add(dept.getDeptid());
}
}
for(IBZDepartment dept:listDept)
{
String orgid=dept.getOrgid();
if(StringUtils.isEmpty(orgid)||(!orgstore.containsKey(orgid)))
continue;
String bc=dept.getBcode();
if(!StringUtils.isEmpty(bc))
{
bc = bc.replace(";", ",").replace(";", ",").replace(",", ",");
String[] bcs = bc.split(",");
for (String strbc : bcs)
{
strbc = strbc.trim();
if (!StringUtils.isEmpty(strbc))
{
if(!bcmap.containsKey(strbc))
{
Set<String> bcset=bcmap.get(strbc);
for(String bcstring:bcset)
{
String[] bcstringarr=bcstring.split(":");
if(bcstringarr.length==2)
{
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);
}
}
}
}
}
}
}
}
return store;
}
public void loopDept(IBZDepartment dept,Map<String, IBZDepartment> deptset,Map<String, Map<String, Set<String>>> store)
{
if(!StringUtils.isEmpty(dept.getParentdeptid()))
{
if(store.containsKey(dept.getParentdeptid()))
{
store.get(dept.getParentdeptid()).get("sub").add(dept.getDeptid());
loopDept(deptset.get(dept.getParentdeptid()),deptset,store);
}
}
}
public void refreshModel()
{
}
}
package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.ou.service.IIBZOrganizationService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 上下级组织信息查询服务
*/
@RestController
public class OUCoreService
{
@Autowired
OUCoreService ouCoreService;
/**
* 获取上下级组织、部门信息
* @return
*/
//@GetMapping("/ibzou/org/{loginname}")
}
package cn.ibizlab.ouapi.rest.extensions;
import cn.ibizlab.core.ou.service.IIBZOrganizationService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 上下级组织信息查询服务
*/
@RestController
public class OrgFeignService {
@Autowired
IIBZOrganizationService orgService;
/**
* 获取上下级组织、部门信息
* @return
*/
@GetMapping("/ibzou/org/{loginname}")
public JSONObject getOrgInfo(@PathVariable("loginname") String loginName){
String orgLevel="";
String deptLevel="";
JSONObject orgInfo= new JSONObject();
JSONObject org = new JSONObject();
JSONObject orgDept = new JSONObject();
//查询用户的levelCode
List<JSONObject> empInfo= orgService.select(String.format("select t1.ORGCODE, t2.DEPTCODE, t1.ORGLEVEL,t2.DEPTLEVEL from ibzemp t left join ibzorg t1 on t.orgid =t1.orgid left join ibzdept t2 on t.MDEPTID=t2.DEPTID where t.LOGINNAME='%s' ",loginName));
if(empInfo.size()==0)
return null;
orgLevel=empInfo.get(0).getString("ORGLEVEL");
deptLevel=empInfo.get(0).getString("DEPTLEVEL");
//通过levelCode查询上下级组织信息
List<JSONObject> pOrgLists= orgService.select(String.format("select orgcode from ibzorg t where INSTR('%s', t.orglevel )=1 ",orgLevel));
List<JSONObject> sOrgLists= orgService.select(String.format("select orgcode from ibzorg t where INSTR(t.orglevel ,'%s' )=1 ",orgLevel));
List<JSONObject> pOrgDeptLists= orgService.select(String.format("select deptcode from ibzdept t where INSTR('%s',t.deptlevel)=1 ",deptLevel));
List<JSONObject> sOrgDeptLists= orgService.select(String.format("select deptcode from ibzdept t where INSTR(t.deptlevel,'%s')=1 ",deptLevel));
org.put("porg",parseData(pOrgLists,"orgcode"));
org.put("sorg",parseData(sOrgLists,"orgcode"));
orgDept.put("porgdept",parseData(pOrgDeptLists,"deptcode"));
orgDept.put("sorgdept",parseData(sOrgDeptLists,"deptcode"));
orgInfo.put("org",org);
orgInfo.put("orgdept",orgDept);
//设置当前用户组织、部门信息
JSONObject curUser=new JSONObject();
curUser.put("org",empInfo.get(0).getString("ORGCODE"));
curUser.put("orgdept",empInfo.get(0).getString("DEPTCODE"));
orgInfo.put("curuser",curUser);
return orgInfo;
}
/**
* 数据解析
* @param datas
* @return
*/
private JSONArray parseData(List<JSONObject> datas , String field ){
JSONArray array=new JSONArray();
if(datas.size()>0){
for(JSONObject org: datas){
array.add(org.getString(field));
}
}
return array;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册