JSD-7566 单点登录+用户同步
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
4.3 KiB

package com.fr.plugin.ztsso.utils;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.base.constant.SoftRoleType;
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType;
import com.fr.decision.authority.data.BaseUserDataRecord;
import com.fr.decision.authority.data.Department;
import com.fr.decision.record.OperateMessage;
import com.fr.decision.webservice.bean.user.DepartmentPostBean;
import com.fr.decision.webservice.exception.general.DuplicatedNameException;
import com.fr.decision.webservice.utils.UserSourceFactory;
import com.fr.decision.webservice.v10.user.DepartmentService;
import com.fr.general.ComparatorUtils;
import com.fr.intelli.record.MetricRegistry;
import com.fr.stable.StableUtils;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.condition.QueryCondition;
import com.fr.stable.query.restriction.Restriction;
import com.fr.stable.query.restriction.RestrictionFactory;
import java.util.ArrayList;
import java.util.Collections;
public class FRDepartmentUtils {
/**
* 获取用户Service
* @return
*/
public static DepartmentService getDepartmentService(){
return DepartmentService.getInstance();
}
/**
* 添加部门
* @param pId 父节点id
* @param dpName 部门名称
*/
public static DepartmentPostBean addDP(String pId, String dpName) throws Exception {
return getDepartmentService().addDepartment(pId,dpName);
}
public static DepartmentPostBean addDP(String id,String pId, String orgName) throws Exception {
String pId2 = pId;
if (ComparatorUtils.equals(pId, "decision-dep-root") ) {
pId2 = null;
}
checkDuplicatedDepartmentName(pId2, orgName);
Department var4 = (new Department()).name(orgName).parentId(pId2).id(id).creationType(ManualOperationType.KEY).lastOperationType(ManualOperationType.KEY).enable(true);
if (pId2 != null) {
UserSourceFactory.getInstance().checkSource(var4, (BaseUserDataRecord)AuthorityContext.getInstance().getDepartmentController().getById(pId));
}
AuthorityContext.getInstance().getDepartmentController().add(var4);
deleteSoftData(getDepartmentService().getDepartmentFullPath(var4.getId()).replaceAll("/", "-"));
MetricRegistry.getMetric().submit(OperateMessage.build("Dec-Module-User_Manager", "Dec-Department", getDepartmentFullPath(pId, orgName, "/"), "Dec-Log_Add"));
return new DepartmentPostBean(var4.getId(), false, false, var4.getParentId(), "", var4.getName());
}
private static void checkDuplicatedDepartmentName(String var1, String var2) throws Exception {
QueryCondition var3 = QueryFactory.create().addRestriction(RestrictionFactory.and(new Restriction[]{RestrictionFactory.eq("name", var2), RestrictionFactory.eq("parentId", var1)}));
Department var4 = (Department)AuthorityContext.getInstance().getDepartmentController().findOne(var3);
if (var4 != null) {
throw new DuplicatedNameException();
}
}
private static void deleteSoftData(String var1) throws Exception {
QueryCondition var2 = QueryFactory.create().addRestriction(RestrictionFactory.and(new Restriction[]{RestrictionFactory.eq("deletedName", var1), RestrictionFactory.eq("type", SoftRoleType.DEP)}));
AuthorityContext.getInstance().getSoftDataController().remove(var2);
}
private static String getDepartmentFullPath(String var1, String var2, String var3) throws Exception {
ArrayList var4 = new ArrayList();
var4.add(var2);
while(!ComparatorUtils.equals(var1, "decision-dep-root") && var1 != null) {
Department var5 = (Department)AuthorityContext.getInstance().getDepartmentController().getById(var1);
var4.add(var5.getName());
var1 = var5.getParentId();
}
Collections.reverse(var4);
return StableUtils.join(var4.toArray(new String[0]), var3);
}
/**
* 修改组织
* @param id
* @param dpName
*/
public static void updateDP(String id,String dpName) throws Exception {
getDepartmentService().editDepartment(id,dpName);
}
/**
* 删除机构
* @param id
* @return
*/
public static void deleteDepartment(String id) throws Exception {
getDepartmentService().deleteDepartment(id);
}
}