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

重构了上下级关系

上级 39736a5c
package cn.ibizlab.core.extensions.aspect;
import cn.ibizlab.core.extensions.mapping.IBZEmp2UserMapping;
import cn.ibizlab.core.extensions.service.OUModelService;
import cn.ibizlab.core.ou.domain.IBZEmployee;
import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.util.service.IBZUSERService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.List;
@Aspect
@Order(0)
@Component
public class IBZEmp2UserAspect
{
@Autowired
@Lazy
private IBZUSERService ibzuserService;
@Autowired
@Lazy
private IBZEmp2UserMapping ibzEmp2UserMapping;
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.creat*(..))")
public void AfterCreateEmp(JoinPoint point) throws Exception {
saveUser(point);
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.updat*(..))")
public void AfterUpdateEmp(JoinPoint point) throws Exception {
saveUser(point);
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.remove(..))")
public void AfterRemoveEmp(JoinPoint point) throws Exception {
removeUser(point);
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.removeBatch(..))")
public void AfterRemoveEmpBatch(JoinPoint point) throws Exception {
removeUser(point);
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.sav*(..))")
public void AfterSaveEmp(JoinPoint point) throws Exception {
saveUser(point);
}
private void saveUser(JoinPoint point)
{
Object[] args = point.getArgs();
if (args.length > 0)
{
Object obj = args[0];
if(obj instanceof IBZEmployee)
{
ibzuserService.saveOrUpdate((IBZUSER) ibzEmp2UserMapping.toUser(obj));
}
else if (obj instanceof List)
{
ibzuserService.saveOrUpdateBatch((List) ibzEmp2UserMapping.toUser(obj));
}
}
}
private void removeUser(JoinPoint point)
{
Object[] args = point.getArgs();
if (args.length > 0)
{
Object obj = args[0];
if(obj instanceof String)
{
ibzuserService.removeById((String) obj);
}
else if (obj instanceof List)
{
ibzuserService.removeByIds((List) obj);
}
}
}
}
package cn.ibizlab.core.extensions.mapping;
import org.mapstruct.Mapper;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValuePropertyMappingStrategy;
import java.util.List;
@Mapper(componentModel = "spring", uses = {},
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface IBZEmp2UserMapping<IBZUSER, IBZEmployee> {
IBZUSER toUser(IBZEmployee emp);
IBZEmployee toEmp(IBZUSER user);
List<IBZUSER> toUser(List<IBZEmployee> ibzEmployeeList);
List <IBZEmployee> toEmp(List<IBZUSER> ibzuserList);
}
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.ou.domain.IBZEmployee;
import cn.ibizlab.core.ou.service.IIBZEmployeeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.*;
......@@ -15,6 +19,77 @@ public class OUCoreService
@Lazy
private OUModelService ouModelService;
@Autowired
@Lazy
private IIBZEmployeeService iibzEmployeeService;
public List<IBZEmployee> getEmpByOrg(String orgid)
{
if(StringUtils.isEmpty(orgid) || "nullorgid".equals(orgid))
return new ArrayList<>();
return iibzEmployeeService.list(new QueryWrapper<IBZEmployee>().eq("orgid",orgid).orderByAsc("showorder"));
}
public List<IBZEmployee> getEmpByDept(String deptid)
{
if(StringUtils.isEmpty(deptid) || "nulldeptid".equals(deptid))
return new ArrayList<>();
return iibzEmployeeService.list(new QueryWrapper<IBZEmployee>().eq("mdeptid",deptid).orderByAsc("showorder"));
}
public List<IBZEmployee> getSubEmpByOrg(String orgid)
{
if(StringUtils.isEmpty(orgid) || "nullorgid".equals(orgid))
return new ArrayList<>();
Map<String, Map<String, Set<String>>> store=ouModelService.getOrgModel();
Map<String, Set<String>> orgmodel=this.getOrgModel(orgid);
if(orgmodel.get("sub").size()==store.size())
return iibzEmployeeService.list();
return iibzEmployeeService.list(new QueryWrapper<IBZEmployee>().in("orgid",orgmodel.get("sub")));
}
public List<IBZEmployee> getSubEmpByDept(String deptid)
{
if(StringUtils.isEmpty(deptid) || "nulldeptid".equals(deptid))
return new ArrayList<>();
Map<String, Set<String>> deptmodel=this.getDeptModel(deptid);
return iibzEmployeeService.list(new QueryWrapper<IBZEmployee>().in("mdeptid",deptmodel.get("sub")));
}
public List<IBZEmployee> getParentEmpByOrg(String orgid,boolean bRecurrence)
{
if(StringUtils.isEmpty(orgid) || "nullorgid".equals(orgid))
return new ArrayList<>();
Map<String, Set<String>> orgmodel=this.getOrgModel(orgid);
List<String> parent=new ArrayList<>();
for(String str:orgmodel.get("parent"))
{
parent.add(str);
if(!bRecurrence)
break;
}
if(parent.size()==0)
return new ArrayList<>();
return iibzEmployeeService.list(new QueryWrapper<IBZEmployee>().in("orgid",parent));
}
public List<IBZEmployee> getParentEmpByDept(String deptid,boolean bRecurrence)
{
if(StringUtils.isEmpty(deptid) || "nulldeptid".equals(deptid))
return new ArrayList<>();
Map<String, Set<String>> deptmodel=this.getDeptModel(deptid);
List<String> parent=new ArrayList<>();
for(String str:deptmodel.get("parent"))
{
parent.add(str);
if(!bRecurrence)
break;
}
if(parent.size()==0)
return new ArrayList<>();
return iibzEmployeeService.list(new QueryWrapper<IBZEmployee>().in("mdeptid",parent));
}
public Map<String, Set<String>> getOrgModel(String orgid)
{
......@@ -28,7 +103,9 @@ public class OUCoreService
{
Map<String, Set<String>> map=new HashMap<>();
map.put("parent",new LinkedHashSet<>());
map.put("sub",new LinkedHashSet<>());
Set<String> sub=new LinkedHashSet<>();
sub.add(orgid);
map.put("sub",sub);
return map;
}
}
......@@ -45,7 +122,9 @@ public class OUCoreService
{
Map<String, Set<String>> map=new HashMap<>();
map.put("parent",new LinkedHashSet<>());
map.put("sub",new LinkedHashSet<>());
Set<String> sub=new LinkedHashSet<>();
sub.add(deptid);
map.put("sub",sub);
return map;
}
}
......
......@@ -4,8 +4,11 @@ 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 cn.ibizlab.util.security.AuthenticationUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
......@@ -14,12 +17,18 @@ import java.util.*;
@Service
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()
{
Map<String, Map<String, Set<String>>> store=new LinkedHashMap<>();
......@@ -70,7 +79,7 @@ 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)
......@@ -192,7 +201,7 @@ public class OUModelService
}
@CacheEvict( value="ibzou-model",allEntries = true)
public void refreshModel()
{
......
package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.extensions.service.OUCoreService;
import cn.ibizlab.core.ou.domain.IBZEmployee;
import cn.ibizlab.core.ou.service.IIBZEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
@RestController
public class OUCoreResource
{
@Autowired
private OUCoreService ouCoreService;
@Autowired
private IIBZEmployeeService iibzEmployeeService;
@GetMapping("/ibzemployees/{userId}/oumaps")
public ResponseEntity<Map<String, Set<String>>> getOUMapsByUserId(@PathVariable("userId") String userId)
{
IBZEmployee emp=iibzEmployeeService.get(userId);
String orgid="nullorgid";
if(!StringUtils.isEmpty(emp.getOrgid()))
orgid=emp.getOrgid();
String deptid="nulldeptid";
if(!StringUtils.isEmpty(emp.getMdeptid()))
deptid=emp.getMdeptid();
return ResponseEntity.ok(this.getMaps(orgid,deptid));
}
@GetMapping("/ibzdepartments/{deptId}/emp")
public ResponseEntity<Map> getEmpByDept(@PathVariable("deptId") String deptId)
{
Map map=new LinkedHashMap<>();
List<IBZEmployee> list=ouCoreService.getEmpByDept(deptId);
for(IBZEmployee emp:list)
map.put(emp.getUserid(),emp);
return ResponseEntity.ok(map);
}
@GetMapping("/ibzdepartments/{deptId}/fatheremp")
public ResponseEntity<Map> getFatherEmpByDept(@PathVariable("deptId") String deptId)
{
Map map=new LinkedHashMap<>();
List<IBZEmployee> list=ouCoreService.getParentEmpByDept(deptId,false);
for(IBZEmployee emp:list)
map.put(emp.getUserid(),emp);
return ResponseEntity.ok(map);
}
@GetMapping("/ibzdepartments/{deptId}/parentemp")
public ResponseEntity<Map> getParentEmpByDept(@PathVariable("deptId") String deptId)
{
Map map=new LinkedHashMap<>();
List<IBZEmployee> list=ouCoreService.getParentEmpByDept(deptId,true);
for(IBZEmployee emp:list)
map.put(emp.getUserid(),emp);
return ResponseEntity.ok(map);
}
@GetMapping("/ibzdepartments/{deptId}/subemp")
public ResponseEntity<Map> getSubEmpByDept(@PathVariable("deptId") String deptId)
{
Map map=new LinkedHashMap<>();
List<IBZEmployee> list=ouCoreService.getSubEmpByDept(deptId);
for(IBZEmployee emp:list)
map.put(emp.getUserid(),emp);
return ResponseEntity.ok(map);
}
@GetMapping("/ibzorganizations/{orgId}/emp")
public ResponseEntity<Map> getEmpByOrg(@PathVariable("orgId") String orgId)
{
Map map=new LinkedHashMap<>();
List<IBZEmployee> list=ouCoreService.getEmpByOrg(orgId);
for(IBZEmployee emp:list)
map.put(emp.getUserid(),emp);
return ResponseEntity.ok(map);
}
@GetMapping("/ibzorganizations/{orgId}/fatheremp")
public ResponseEntity<Map> getFatherEmpByOrg(@PathVariable("orgId") String orgId)
{
Map map=new LinkedHashMap<>();
List<IBZEmployee> list=ouCoreService.getParentEmpByOrg(orgId,false);
for(IBZEmployee emp:list)
map.put(emp.getUserid(),emp);
return ResponseEntity.ok(map);
}
@GetMapping("/ibzorganizations/{orgId}/parentemp")
public ResponseEntity<Map> getParentEmpByOrg(@PathVariable("orgId") String orgId)
{
Map map=new LinkedHashMap<>();
List<IBZEmployee> list=ouCoreService.getParentEmpByOrg(orgId,true);
for(IBZEmployee emp:list)
map.put(emp.getUserid(),emp);
return ResponseEntity.ok(map);
}
@GetMapping("/ibzorganizations/{orgId}/subemp")
public ResponseEntity<Map> getSubEmpByOrg(@PathVariable("orgId") String orgId)
{
Map map=new LinkedHashMap<>();
List<IBZEmployee> list=ouCoreService.getSubEmpByOrg(orgId);
for(IBZEmployee emp:list)
map.put(emp.getUserid(),emp);
return ResponseEntity.ok(map);
}
private Map<String, Set<String>> getMaps(String orgid,String deptid)
{
Map<String, Set<String>> map=new LinkedHashMap<>();
Map<String, Set<String>> storemap=ouCoreService.getOrgModel(orgid);
map.put("parentorg",storemap.get("parent"));
map.put("suborg",storemap.get("sub"));
Set<String> father=new LinkedHashSet<>();
for(String str:storemap.get("parent"))
{
father.add(str);
break;
}
map.put("fatherorg",father);
Map<String, Set<String>> storedeptmap=ouCoreService.getDeptModel(deptid);
map.put("parentdept",storedeptmap.get("parent"));
map.put("subdept",storedeptmap.get("sub"));
Set<String> fatherdept=new LinkedHashSet<>();
for(String str:storedeptmap.get("parent"))
{
fatherdept.add(str);
break;
}
map.put("fatherdept",fatherdept);
return map;
}
}
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}")
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册