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.

81 lines
3.0 KiB

/*
* Copyright (C), 2018-2021
* Project: starter
* FileName: DepartmentServiceKit
* Author: Louis
* Date: 2021/5/14 9:38
*/
package com.eco.plugin.xx.jbsync.kit;
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.Post;
import com.fr.decision.record.OperateMessage;
import com.fr.decision.webservice.exception.general.DuplicatedNameException;
import com.fr.decision.webservice.v10.user.DepartmentService;
import com.fr.intelli.record.MetricRegistry;
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;
/**
* <Function Description><br>
* <PostServiceKit>
*
* @author xx
* @since 1.0.0
*/
public class PostServiceKit extends DepartmentService {
public static final String DECISION_DEP_ROOT = "decision-dep-root";
private static volatile PostServiceKit postServiceKit = null;
public PostServiceKit() {
}
public static PostServiceKit getInstance() {
if (postServiceKit == null) {
postServiceKit = new PostServiceKit();
}
return postServiceKit;
}
/**
* 根据id获取职务
* @param id
* @return
* @throws Exception
*/
public Post getByid(String id) throws Exception {
return AuthorityContext.getInstance().getPostController().getById(id);
}
/**
* 添加部门
* @param postname
* @param postid
* @return
* @throws Exception
*/
public Post addPost(String postname,String postid) throws Exception {
this.checkDuplicatedPost(postname);
Post post = (new Post()).id(postid).name(postname).creationType(ManualOperationType.KEY).lastOperationType(ManualOperationType.KEY).enable(true).description("");
AuthorityContext.getInstance().getPostController().add(post);
this.deleteSoftData(post.getName());
MetricRegistry.getMetric().submit(OperateMessage.build("Dec-Module-User_Manager", "Dec-Dec-Post",postname, "Dec-Log_Add"));
return post;
}
private void checkDuplicatedPost(String postname) throws Exception {
Post post = (Post)AuthorityContext.getInstance().getPostController().findOne(QueryFactory.create().addRestriction(RestrictionFactory.eq("name", postname)));
if (post != null) {
throw new DuplicatedNameException("Duplicated names! ", post.getName());
}
}
private void deleteSoftData(String var1) throws Exception {
QueryCondition var2 = QueryFactory.create().addRestriction(RestrictionFactory.and(new Restriction[]{RestrictionFactory.eq("deletedName", var1), RestrictionFactory.eq("type", SoftRoleType.POST)}));
AuthorityContext.getInstance().getSoftDataController().remove(var2);
}
}