package com.vci.frameworkcore.compatibility.impl;
|
|
import com.vci.corba.common.PLException;
|
import com.vci.corba.omd.data.BusinessObject;
|
import com.vci.frameworkcore.compatibility.OrgDeptQueryServiceI;
|
import com.vci.frameworkcore.lcstatuspck.FrameworkDataLCStatus;
|
import com.vci.frameworkcore.model.OrgDeptForPlatform1;
|
import com.vci.frameworkcore.model.SmRoleForPlatform1;
|
import com.vci.frameworkcore.pagemodel.OrgDepartmentVO;
|
import com.vci.frameworkcore.pagemodel.SmRoleVO;
|
import com.vci.omd.utils.ObjectTool;
|
import com.vci.starter.revision.bo.TreeWrapperOptions;
|
import com.vci.starter.revision.service.RevisionModelUtil;
|
import com.vci.starter.web.constant.QueryOptionConstant;
|
import com.vci.starter.web.exception.VciBaseException;
|
import com.vci.starter.web.pagemodel.DataGrid;
|
import com.vci.starter.web.pagemodel.PageHelper;
|
import com.vci.starter.web.pagemodel.Tree;
|
import com.vci.starter.web.pagemodel.TreeQueryObject;
|
import com.vci.starter.web.util.BeanUtil;
|
import com.vci.starter.web.util.VciBaseUtil;
|
import com.vci.starter.web.wrapper.VciQueryWrapperForDO;
|
import com.vci.web.service.WebBoServiceI;
|
import com.vci.web.util.Func;
|
import com.vci.web.util.PlatformClientUtil;
|
import com.vci.web.util.WebUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.*;
|
import java.util.function.Function;
|
import java.util.stream.Collectors;
|
|
/**
|
* 部门的查询服务,兼容老平台
|
* @author 谢军
|
* @date 2020/3/10
|
*/
|
@Service
|
public class OrgDeptQueryServiceImpl implements OrgDeptQueryServiceI{
|
|
/**
|
* 业务数据服务
|
*/
|
@Autowired
|
private WebBoServiceI boService;
|
|
/**
|
* 平台调用客户端
|
*/
|
@Autowired
|
private PlatformClientUtil platformClientUtil;
|
|
/**
|
* 对象操作工具类
|
*/
|
@Autowired
|
private RevisionModelUtil revisionModelUtil;
|
|
/**
|
* 根据部门主键获取部门的信息
|
* @param deptOid 部门主键
|
* @return 部门的显示对象,如果部门不存在则返回null,不会抛出异常
|
* @throws VciBaseException 参数为空或者数据库存在问题的时候会抛出异常
|
*/
|
@Override
|
public OrgDepartmentVO getDeptByDeptOid(String deptOid)
|
throws VciBaseException {
|
if(StringUtils.isBlank(deptOid)){
|
return null;
|
}
|
OrgDeptForPlatform1 deptForPlatform1 = boService.selectByOid(deptOid, OrgDeptForPlatform1.class);
|
return deptDO2VO(deptForPlatform1);
|
}
|
|
/**
|
* 部门的数据对象转换为显示对象
|
* @param depts 数据对象
|
* @return 显示对象
|
*/
|
public List<OrgDepartmentVO> deptDO2VOs(Collection<OrgDeptForPlatform1> depts){
|
List<OrgDepartmentVO> departmentVOS = new ArrayList<>();
|
Optional.ofNullable(depts).orElseGet(()->new ArrayList<>()).stream().forEach(dept->{
|
departmentVOS.add(deptDO2VO(dept));
|
});
|
return departmentVOS;
|
}
|
|
/**
|
* 部门的数据对象转换为显示对象
|
* @param deptForPlatform1 数据对象
|
* @return 显示对象
|
*/
|
public OrgDepartmentVO deptDO2VO(OrgDeptForPlatform1 deptForPlatform1){
|
OrgDepartmentVO departmentVO = new OrgDepartmentVO();
|
if(deptForPlatform1!=null){
|
departmentVO.setOid(deptForPlatform1.getPluid());
|
departmentVO.setId(deptForPlatform1.getPlnum());
|
departmentVO.setName(deptForPlatform1.getPlname());
|
if(0 == deptForPlatform1.getPlstatus()){
|
departmentVO.setLcStatus(FrameworkDataLCStatus.ENABLED.getValue());
|
}else{
|
departmentVO.setLcStatus(FrameworkDataLCStatus.DISABLED.getValue());
|
}
|
departmentVO.setPkFatherDepartment(deptForPlatform1.getPlparentuid());
|
departmentVO.setDescription(deptForPlatform1.getPldesc());
|
departmentVO.setCheckInTime(deptForPlatform1.getPlcreatetime());
|
departmentVO.setCreator(deptForPlatform1.getPlcreateuser());
|
departmentVO.setLastModifyTime(deptForPlatform1.getPlupdatetime());
|
departmentVO.setLastModifier(deptForPlatform1.getPlupdateuser());
|
}
|
return departmentVO;
|
}
|
|
/**
|
* 批量获取部门的信息 (根据部门主键)
|
* @param deptOidCollections 部门主键的集合,可以超过1000个
|
* @return 部门的显示对象,如果部门不存在则返回空的列表,不会抛出异常
|
* @throws VciBaseException 参数为空或者数据库存在问题的时候会抛出异常
|
*/
|
@Override
|
public List<OrgDepartmentVO> listDeptByDeptOids(
|
Collection<String> deptOidCollections) throws VciBaseException {
|
if(CollectionUtils.isEmpty(deptOidCollections)){
|
return new ArrayList<>();
|
}
|
List<OrgDeptForPlatform1> depts = new ArrayList<>();
|
WebUtil.switchCollectionForOracleIn(deptOidCollections).stream().forEach(roleOids->{
|
Map<String,String> conditionMap=new HashMap<String, String>();
|
conditionMap.put("pluid", QueryOptionConstant.IN + VciBaseUtil.toInSql(roleOids.toArray(new String[0])));
|
VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap,OrgDeptForPlatform1.class);
|
List<OrgDeptForPlatform1> roleForPlatform1s = boService.selectByQueryWrapper(queryWrapper, OrgDeptForPlatform1.class);
|
if(!CollectionUtils.isEmpty(roleForPlatform1s)){
|
depts.addAll(roleForPlatform1s);
|
}
|
});
|
return deptDO2VOs(depts);
|
}
|
|
/**
|
* 获取部门的列表,默认会以部门名称升序排列,部门的编辑页面列表不要使用这个接口
|
* @param queryMap 查询条件
|
* @param pageHelper 分页和排序的信息,在兼容老平台的时候会自动兼容,如果属性不存在会自动忽略
|
* @return 部门的显示对象列表
|
* @throws VciBaseException 参数为空的时候会抛出异常
|
*/
|
@Override
|
public DataGrid<OrgDepartmentVO> gridDepts(Map<String, String> queryMap,
|
PageHelper pageHelper) throws VciBaseException {
|
if(pageHelper == null){
|
pageHelper = new PageHelper(-1);
|
}
|
pageHelper.addDefaultAsc("plnum");
|
VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(queryMap,OrgDeptForPlatform1.class,pageHelper);
|
List<OrgDeptForPlatform1> deptForPlatform1s = boService.selectByQueryWrapper(queryWrapper, OrgDeptForPlatform1.class);
|
DataGrid<OrgDepartmentVO> dataGrid = new DataGrid<>();
|
if(!CollectionUtils.isEmpty(deptForPlatform1s)){
|
dataGrid.setData(deptDO2VOs(deptForPlatform1s));
|
dataGrid.setTotal(boService.countByQueryWrapper(queryWrapper,OrgDeptForPlatform1.class));
|
}
|
return dataGrid;
|
}
|
|
/**
|
* 根据部门主键获取部门的姓名
|
* @param deptOid 部门主键
|
* @return 部门姓名,如果不存在会返回null
|
*/
|
@Override
|
public String getDeptNameByDeptOid(String deptOid) {
|
WebUtil.alertNotNull(deptOid,"部门的主键");
|
return getDeptByDeptOid(deptOid).getName();
|
}
|
|
/**
|
* 使用用户主键查询部门
|
* @param userOid 用户主键
|
* @param queryMap 查询条件
|
* @param notIn 是否为不包含
|
* @return 角色的显示对象
|
*/
|
private List<OrgDepartmentVO> listDeptByUserOid(String userOid,Map<String,String> queryMap,boolean notIn){
|
if(StringUtils.isBlank(userOid)){
|
return new ArrayList<>();
|
}
|
if(queryMap == null){
|
queryMap = new HashMap<>();
|
}
|
List<OrgDeptForPlatform1> deptForPlatform1s = new ArrayList<>();
|
if(userOid.contains(",")){
|
Map<String, String> finalQueryMap = queryMap;
|
WebUtil.switchCollectionForOracleIn(WebUtil.str2List(userOid)).stream().forEach(userOids->{
|
Map<String,String> conditionMap = new HashMap<>();
|
finalQueryMap.forEach((key,value)->{
|
conditionMap.put(key,value);
|
});
|
conditionMap.put("pluid", notIn ? QueryOptionConstant.NOTIN : QueryOptionConstant.IN + "select pldeptuid from PLUSERDEPT where pluseruid in (" + WebUtil.toInSql(userOids.toArray(new String[0])) + ")");
|
VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap,OrgDeptForPlatform1.class);
|
List<OrgDeptForPlatform1> roleForPlatform1s = boService.selectByQueryWrapper(queryWrapper, OrgDeptForPlatform1.class);
|
if(!CollectionUtils.isEmpty(roleForPlatform1s)){
|
deptForPlatform1s.addAll(roleForPlatform1s);
|
}
|
});
|
}else {
|
queryMap.put("pluid", notIn ? QueryOptionConstant.NOTIN : QueryOptionConstant.IN + "select pldeptuid from PLUSERDEPT where pluseruid ='" + userOid.trim() + "'");
|
}
|
VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(queryMap,OrgDeptForPlatform1.class);
|
List<OrgDeptForPlatform1> roleForPlatform1s = boService.selectByQueryWrapper(queryWrapper, OrgDeptForPlatform1.class);
|
if(!CollectionUtils.isEmpty(roleForPlatform1s)){
|
deptForPlatform1s.addAll(roleForPlatform1s);
|
}
|
return deptDO2VOs(deptForPlatform1s);
|
}
|
|
/**
|
* 根据用户主键获取关联的部门
|
* @param userOid 用户主键
|
* @param queryMap 查询条件,如果需要使用用户的属性来查询可以使用pkUser.xxxx
|
* @return 部门的显示对象
|
*/
|
@Override
|
public List<OrgDepartmentVO> listDeptByUserOid(String userOid,
|
Map<String, String> queryMap) {
|
List<OrgDepartmentVO> departmentVOS = listDeptByUserOid(userOid, queryMap, false);
|
if(CollectionUtils.isEmpty(departmentVOS)){
|
return new ArrayList<>();
|
}
|
return departmentVOS;
|
}
|
|
/**
|
* 获取未关联某个用户的部门
|
* @param userOid 用户主键
|
* @param queryMap 查询条件,如果需要使用用户的属性来查询可以使用pkUser.xxxx
|
* @return 部门的显示对象
|
*/
|
@Override
|
public List<OrgDepartmentVO> listDeptUnInUserOid(String userOid,
|
Map<String, String> queryMap) {
|
return listDeptByUserOid(userOid, queryMap, true);
|
}
|
|
/**
|
* 获取未关联某个用户的部门
|
* @param userOid 用户主键
|
* @param queryMap 查询条件,如果需要使用用户的属性来查询可以使用pkUser.xxxx
|
* @param pageHelper 分页和排序对象,老平台不支持使用部门编号来排序
|
* @return 部门的显示对象
|
*/
|
@Override
|
public DataGrid<OrgDepartmentVO> gridDeptUninUserOid(String userOid,
|
Map<String, String> queryMap, PageHelper pageHelper) {
|
return gridDeptByUserOid(userOid,queryMap,pageHelper,true);
|
}
|
|
/**
|
* 使用用户查询部门列表
|
* @param userOid 用户主键
|
* @param queryMap 查询条件
|
* @param pageHelper 分页对象
|
* @param notIn 不包含
|
* @return 列表数据
|
*/
|
private DataGrid<OrgDepartmentVO> gridDeptByUserOid(String userOid,Map<String,String> queryMap,PageHelper pageHelper,boolean notIn){
|
if(queryMap == null){
|
queryMap = new HashMap<>();
|
}
|
if(StringUtils.isBlank(userOid)){
|
return new DataGrid<>();
|
}
|
if(userOid.contains(",")){
|
String[] userOids = userOid.trim().split(",");
|
if(userOids.length>1000){
|
//这个方法不支持超过1000个的用户查询
|
throw new VciBaseException("这个方法不支持超过1000个用户的主键来查询");
|
}
|
queryMap.put("pluid", notIn ? QueryOptionConstant.NOTIN : QueryOptionConstant.IN + "select pldeptuid from PLUSERDEPT where pluseruid in (" + WebUtil.toInSql(userOids) + ")");
|
}else {
|
queryMap.put("pluid", notIn ? QueryOptionConstant.NOTIN : QueryOptionConstant.IN + "select pldeptuid from PLUSERDEPT where pluseruid ='" + userOid.trim() + "'");
|
}
|
return gridDepts(queryMap,pageHelper);
|
}
|
|
/**
|
* 批量根据用户的主键来获取部门
|
* @param userOidCollection 用户主键集合
|
* @param queryMap 查询条件,如果需要使用用户的属性来查询可以使用pkUser.xxxx
|
* @return 部门的显示对象,key是用户主键,value是这个用户关联的部门
|
*/
|
@Override
|
public Map<String, List<OrgDepartmentVO>> batchListDeptByUserOids(
|
Collection<String> userOidCollection, Map<String, String> queryMap) {
|
if(CollectionUtils.isEmpty(userOidCollection)){
|
return new HashMap<>();
|
}
|
List<OrgDepartmentVO> deptVOList = new ArrayList<>();
|
Map<String,List<String>> userDeptOidMap = new HashMap<>();
|
WebUtil.switchCollectionForOracleIn(userOidCollection).stream().forEach(userOids->{
|
List<OrgDepartmentVO> deptVOs = listDeptByUserOid(userOids.stream().collect(Collectors.joining(",")), queryMap, false);
|
if(!CollectionUtils.isEmpty(deptVOs)){
|
deptVOList.addAll(deptVOs);
|
String sql = "select pluseruid,pldeptuid from pluserdept where pluseruid in (" + WebUtil.toInSql(userOids.toArray(new String[0])) + ")";
|
List<BusinessObject> cbos = boService.queryBySql(sql, null);
|
if(!CollectionUtils.isEmpty(cbos)){
|
cbos.stream().forEach(cbo->{
|
String userOid = ObjectTool.getNewBOAttributeValue(cbo,"pluseruid");
|
List<String> deptOids = userDeptOidMap.getOrDefault(userOid,new ArrayList<>());
|
deptOids.add(ObjectTool.getNewBOAttributeValue(cbo,"pldeptuid"));
|
userDeptOidMap.put(userOid,deptOids);
|
});
|
}
|
}
|
});
|
if(!CollectionUtils.isEmpty(deptVOList)){
|
//这儿应该对deptVOList做一次去重处理,因为肯定会有重复的部门被查出来
|
Map<String, OrgDepartmentVO> deptVOMap = deptVOList.stream()
|
.collect(Collectors.toMap(OrgDepartmentVO::getOid, Function.identity(), (existing, replacement) -> existing));
|
//Map<String, OrgDepartmentVO> deptVOMap = deptVOList.stream().distinct().collect(Collectors.toMap(s -> s.getOid(), t -> t));
|
Map<String, List<OrgDepartmentVO>> userDeptVOMap = new HashMap<>();
|
userDeptOidMap.forEach((userOid,deptOids)->{
|
List<OrgDepartmentVO> deptVOS = new ArrayList<>();
|
deptOids.forEach(deptOid->{
|
if(deptVOMap.containsKey(deptOid)){
|
deptVOS.add(deptVOMap.get(deptOid));
|
}
|
});
|
userDeptVOMap.put(userOid,deptVOS);
|
});
|
return userDeptVOMap;
|
}
|
return new HashMap<>();
|
}
|
|
/**
|
* 获取某个部门的直属下级部门
|
* @param pkFatherDepartmment 部门的主键
|
* @param queryMap 查询条件
|
* @return 部门显示对象
|
*/
|
@Override
|
public List<OrgDepartmentVO> listChildrenDeptByParentOid(
|
String pkFatherDepartmment, Map<String, String> queryMap) {
|
VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(queryMap,OrgDeptForPlatform1.class);
|
if(StringUtils.isBlank(pkFatherDepartmment)){
|
queryWrapperForDO.isNull("plparentuid");
|
}else{
|
queryWrapperForDO.eq("plparentuid",pkFatherDepartmment.trim());
|
}
|
List<OrgDeptForPlatform1> depts = boService.selectByQueryWrapper(queryWrapperForDO, OrgDeptForPlatform1.class);
|
return deptDO2VOs(depts);
|
}
|
|
/**
|
* 获取某个部门的所有层级的下级部门
|
* @param pkFatherDepartmment 部门的主键
|
* @param queryMap 查询条件
|
* @return 部门显示对象
|
*/
|
@Override
|
public List<OrgDepartmentVO> listAllLevelChildrenDeptByParentOid(
|
String pkFatherDepartmment, Map<String, String> queryMap) {
|
VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(queryMap,OrgDeptForPlatform1.class);
|
queryWrapperForDO.in("pluid","select pluid from pldept start with " + (StringUtils.isBlank(pkFatherDepartmment)?" (plparentuid is null or plparentuid = '') ":"plparentuid = '" + pkFatherDepartmment.trim() + "'") + "connect by PRIOR pluid=plparentuid");
|
return deptDO2VOs(boService.selectByQueryWrapper(queryWrapperForDO, OrgDeptForPlatform1.class));
|
}
|
|
/**
|
* 参照树形数据的部门信息
|
* @param treeQueryObject 树形查询的条件
|
* @return 树节点
|
*/
|
@Override
|
public List<Tree> refTreeDept(TreeQueryObject treeQueryObject) {
|
String pkFatherDepartmment=treeQueryObject.getParentOid();
|
Map<String, String> conditionMap = treeQueryObject.getConditionMap();
|
if(conditionMap==null){
|
conditionMap=new HashMap<String, String>();
|
}
|
List<OrgDepartmentVO> orgDepartmentVOList=new ArrayList<OrgDepartmentVO>();
|
if(treeQueryObject.isQueryAllLevel()){
|
orgDepartmentVOList = listAllLevelChildrenDeptByParentOid(pkFatherDepartmment, conditionMap);
|
}else{
|
conditionMap.put("plparentuid", pkFatherDepartmment);
|
VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(conditionMap,OrgDeptForPlatform1.class);
|
orgDepartmentVOList = deptDO2VOs(boService.selectByQueryWrapper(queryWrapperForDO,OrgDeptForPlatform1.class));
|
}
|
TreeWrapperOptions treeWrapperOptions = new TreeWrapperOptions();
|
BeanUtil.convert(treeQueryObject,treeWrapperOptions);
|
treeWrapperOptions.setParentFieldName("pkFatherDepartment");
|
return revisionModelUtil.doList2Trees(orgDepartmentVOList,treeWrapperOptions,dept->{
|
return dept.getId() + " " + dept.getName() + (FrameworkDataLCStatus.DISABLED.getValue().equals(dept.getLcStatus())?"【停用】":"");
|
});
|
}
|
|
/**
|
* 参照树形表格的部门信息,上级部门的是表格中的树形列
|
* @param treeQueryObject 树形查询的条件
|
* @return 部门的树表信息
|
*/
|
@Override
|
public DataGrid refTreeGridDept(TreeQueryObject treeQueryObject) {
|
String pkFatherDepartmment=treeQueryObject.getParentOid();
|
Map<String, String> conditionMap = treeQueryObject.getConditionMap();
|
if(conditionMap==null){
|
conditionMap=new HashMap<String, String>();
|
}
|
List<OrgDepartmentVO> orgDepartmentVOList=new ArrayList<OrgDepartmentVO>();
|
if(treeQueryObject.isQueryAllLevel()){
|
orgDepartmentVOList = listAllLevelChildrenDeptByParentOid(pkFatherDepartmment, conditionMap);
|
}else{
|
conditionMap.put("plparentuid", pkFatherDepartmment);
|
VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(conditionMap,OrgDeptForPlatform1.class);
|
orgDepartmentVOList = deptDO2VOs(boService.selectByQueryWrapper(queryWrapperForDO,OrgDeptForPlatform1.class));
|
}
|
DataGrid dataGrid = new DataGrid();
|
dataGrid.setData(orgDepartmentVOList);
|
if(!CollectionUtils.isEmpty(orgDepartmentVOList)){
|
dataGrid.setTotal(orgDepartmentVOList.size());
|
}
|
return dataGrid;
|
}
|
|
/**
|
* 保存部门角色关联信息,带查重功能
|
* @param userOIds 用户id
|
* @param deptId 部门id
|
* @return
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public boolean saveUsersDept(String[] userOIds, String deptId) throws PLException {
|
if(Func.isEmpty(userOIds) || Func.isBlank(deptId)){
|
return false;
|
}
|
//先进性查重处理
|
List<String> repeatUserOidList = new ArrayList<>();
|
//循环进行查重,避免in大于1000
|
WebUtil.switchCollectionForOracleIn(Arrays.asList(userOIds)).stream().forEach(userOId->{
|
String sql = "select pluseruid,pldeptuid from pluserdept where pldeptuid = '" + deptId
|
+ "' and " + "pluseruid in ("+WebUtil.toInSql(userOId.toArray(new String[0]))+")";
|
List<BusinessObject> cbos = boService.queryBySql(sql, null);
|
if(!CollectionUtils.isEmpty(cbos)){
|
cbos.stream().forEach(cbo->{
|
repeatUserOidList.add(ObjectTool.getNewBOAttributeValue(cbo,"pluseruid"));
|
});
|
}
|
});
|
|
//从即将要执行保存的用户oid中移除当前用户已经存在关联关系的oid
|
//移除重复的
|
List<String> tempList = new ArrayList<>(Arrays.asList(userOIds));
|
tempList.removeAll(repeatUserOidList);
|
userOIds = tempList.toArray(new String[tempList.size()]);
|
if(Func.isNotEmpty(userOIds)){
|
platformClientUtil.getFrameworkService().saveUserDept(userOIds, deptId,null);
|
}
|
return true;
|
}
|
|
}
|