Browse Source

Merge branch 'master' of zed/finekit into master

master
richie 5 years ago committed by Gogs
parent
commit
140ff682d5
  1. 64
      src/main/java/com/fanruan/api/decision/AuthorityKit.java
  2. 35
      src/main/java/com/fanruan/api/decision/role/CustomRoleKit.java
  3. 11
      src/main/java/com/fanruan/api/decision/user/UserKit.java
  4. 30
      src/test/java/com/fanruan/api/decision/AuthorityKitTest.java
  5. 24
      src/test/java/com/fanruan/api/decision/role/CustomRoleKitTest.java
  6. 25
      src/test/java/com/fanruan/api/decision/user/UserKitTest.java

64
src/main/java/com/fanruan/api/decision/AuthorityKit.java

@ -1,6 +1,12 @@
package com.fanruan.api.decision;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.base.constant.AuthorityStaticItemId;
import com.fr.decision.authority.base.constant.AuthorityValue;
import com.fr.decision.authority.base.constant.type.authority.AuthorityType;
import com.fr.decision.authority.controller.GradeAuthorityController;
import com.fr.decision.authority.data.personnel.DepRole;
import com.fr.decision.webservice.utils.WebServiceUtils;
/**
* @author richie
@ -13,7 +19,7 @@ public class AuthorityKit {
/**
* 内置管理系统节点id
*/
public static class Management{
public static class Management {
public static final String USER = AuthorityStaticItemId.DEC_MANAGEMENT_USER_ID;
public static final String AUTHORITY = AuthorityStaticItemId.DEC_MANAGEMENT_AUTHORITY_ID;
@ -42,4 +48,60 @@ public class AuthorityKit {
public static final String MAINTENANCE = AuthorityStaticItemId.DEC_MANAGEMENT_MAINTENANCE_ID;
}
/**
* 给部门职位设置人员管理权限
*
* @param depostId 部门职位id
* @param authValue 接受/拒绝
* @param authId 实体id
* @param authType 权限类型
* @throws Exception 异常
*/
public static void setDepAuth(String depostId, int authValue, String authId, int authType) throws Exception {
DepRole depRole = WebServiceUtils.parseUniqueDepartmentPostId(depostId);
AuthorityContext.getInstance().getAuthorityController(GradeAuthorityController.class).setDepAuthorityValue(
depRole.getDepartmentId(),
depRole.getPostId(),
AuthorityValue.fromInteger(authValue),
authId,
AuthorityType.fromInteger(authType));
}
/**
* 给用户设置人员管理权限
*
* @param userId 用户id
* @param authValue 接受/拒绝
* @param authId 实体id
* @param authType 权限类型
* @throws Exception 异常
*/
public static void setUserAuth(String userId, int authValue, String authId, int authType) throws Exception {
AuthorityContext.getInstance().getAuthorityController(GradeAuthorityController.class).setUserAuthorityValue(
userId,
AuthorityValue.fromInteger(authValue),
authId,
AuthorityType.fromInteger(authType));
}
/**
* 给角色设置人员管理权限
*
* @param roleId 角色id
* @param authValue 接受/拒绝
* @param authId 实体id
* @param authType 权限类型
* @throws Exception 异常
*/
public static void setCustomRoleAuth(String roleId, int authValue, String authId, int authType) throws Exception {
AuthorityContext.getInstance().getAuthorityController(GradeAuthorityController.class).setCustomAuthorityValue(
roleId,
AuthorityValue.fromInteger(authValue),
authId,
AuthorityType.fromInteger(authType));
}
}

35
src/main/java/com/fanruan/api/decision/role/CustomRoleKit.java

@ -0,0 +1,35 @@
package com.fanruan.api.decision.role;
import com.fr.decision.authority.data.CustomRole;
import com.fr.decision.webservice.utils.ControllerFactory;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* @author Zed
* @version 10.0
* Created by Zed on 2020/4/30
*/
public class CustomRoleKit {
/**
* 获取角色id
*
* @param userId 用户id
* @param keyword 搜索关键字
* @return 角色id
* @throws Exception 异常
*/
public static List<String> getCustomRoleIds(@NotNull String userId, String keyword) throws Exception {
List<String> result = new ArrayList<>();
CustomRole[] roles = ControllerFactory.getInstance().getCustomRoleController(userId).getAllCustomRoles(userId, keyword);
for (CustomRole role : roles) {
result.add(role.getId());
}
return result;
}
}

11
src/main/java/com/fanruan/api/decision/user/UserKit.java

@ -75,4 +75,15 @@ public class UserKit {
public static List<String> getUserNamesFromEmail(String email) throws Exception {
return UserService.getInstance().getUserNamesFromEmail(email);
}
/**
* 获取当前用户id
*
* @param request 请求体
* @return 用户id
* @throws Exception 异常
*/
public static String getCurrentUserId(HttpServletRequest request) throws Exception {
return UserService.getInstance().getCurrentUserId(request);
}
}

30
src/test/java/com/fanruan/api/decision/AuthorityKitTest.java

@ -0,0 +1,30 @@
package com.fanruan.api.decision;
import org.junit.Assert;
import org.junit.Test;
import java.lang.reflect.Method;
/**
* @author Zed
* @version 10.0
* Created by Zed on 2020/4/30
*/
public class AuthorityKitTest {
@Test
public void setAuth() throws Exception {
Class<?> classBook = Class.forName("com.fanruan.api.decision.AuthorityKit");
Assert.assertNotNull(classBook);
Method method1 = classBook.getDeclaredMethod("setCustomRoleAuth", String.class, int.class, String.class, int.class);
Assert.assertNotNull(method1);
Method method2 = classBook.getDeclaredMethod("setUserAuth", String.class, int.class, String.class, int.class);
Assert.assertNotNull(method2);
Method method3 = classBook.getDeclaredMethod("setDepAuth", String.class, int.class, String.class, int.class);
Assert.assertNotNull(method3);
}
}

24
src/test/java/com/fanruan/api/decision/role/CustomRoleKitTest.java

@ -0,0 +1,24 @@
package com.fanruan.api.decision.role;
import org.junit.Assert;
import org.junit.Test;
import java.lang.reflect.Method;
/**
* @author Zed
* @version 10.0
* Created by Zed on 2020/4/30
*/
public class CustomRoleKitTest {
@Test
public void getCustomRoleIds() throws Exception {
Class<?> classBook = Class.forName("com.fanruan.api.decision.role.CustomRoleKit");
Assert.assertNotNull(classBook);
Method method1 = classBook.getDeclaredMethod("getCustomRoleIds", String.class, String.class);
Assert.assertNotNull(method1);
}
}

25
src/test/java/com/fanruan/api/decision/user/UserKitTest.java

@ -0,0 +1,25 @@
package com.fanruan.api.decision.user;
import org.junit.Assert;
import org.junit.Test;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
/**
* @author Zed
* @version 10.0
* Created by Zed on 2020/4/30
*/
public class UserKitTest {
@Test
public void getCurrentUserId() throws Exception {
Class<?> classBook = Class.forName("com.fanruan.api.decision.user.UserKit");
Assert.assertNotNull(classBook);
Method method1 = classBook.getDeclaredMethod("getCurrentUserId", HttpServletRequest.class);
Assert.assertNotNull(method1);
}
}
Loading…
Cancel
Save