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.

170 lines
4.6 KiB

package com.eco.plugin.xx.jlyhsjtb.utils;
import com.fr.decision.authority.data.User;
import com.fr.decision.privilege.TransmissionTool;
import com.fr.decision.webservice.bean.user.DepRoleBean;
import com.fr.decision.webservice.bean.user.UserBean;
import com.fr.decision.webservice.bean.user.UserRolesBean;
import com.fr.decision.webservice.bean.user.UserUpdateBean;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.decision.webservice.v10.user.UserService;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
public class FRUserUtils {
/**
* 获取用户Service
* @return
*/
public static UserService getUserService(){
return UserService.getInstance();
}
/**
* 添加用户
* @param userBean
*/
public static void addUser(UserBean userBean) throws Exception {
userBean.setPassword(TransmissionTool.defaultEncrypt(userBean.getPassword()));
getUserService().addUser(userBean);
}
/**
* 删除用户
* @param userBean
*/
public static void updateUser(UserBean userBean) throws Exception {
getUserService().editUser(userBean,"");
}
/**
* 删除用户
* @param user
* @return
*/
public static int deleteUser(User user) throws Exception {
String userId = user.getId();
UserUpdateBean userUpdateBean = new UserUpdateBean();
userUpdateBean.setRemoveUserIds(new String[]{userId});
return getUserService().deleteUsers(userUpdateBean);
}
/**
* 删除用户 根据用户名删除用户
* @param username
* @return
*/
public static int deleteByUsername(String username) throws Exception {
User user = getUserByUserName(username);
String userId = user.getId();
UserUpdateBean userUpdateBean = new UserUpdateBean();
userUpdateBean.setRemoveUserIds(new String[]{userId});
return getUserService().deleteUsers(userUpdateBean);
}
/**
* 根据用户名获取用户实体
* @param userName
* @return
*/
public static User getUserByUserName(String userName) throws Exception {
return getUserService().getUserByUserName(userName);
}
/**
* 根据用户名获取用户实体
* @param userName
* @return
*/
public static UserBean getUserBeanByUserName(String userName ) throws Exception {
String id = getUserService().getUserByUserName(userName).getId();
return getUser(id);
}
/**
* 根据id获取用户
* @param id
* @return
* @throws Exception
*/
public static UserBean getUser(String id) throws Exception {
return getUserService().getUser(id);
}
/**
* 判断是否是管理员
* @param username
* @return
*/
public static boolean isAdmin(String username) throws Exception{
return getUserService().isAdmin(getUserByUserName(username).getId());
}
/**
* 禁用启用用户
* @param userId
* @param state false 禁用 true 启用
* @throws Exception 异常说明失败
*/
public static void forbidUser(String userId,boolean state) throws Exception {
getUserService().forbidUser(userId,state);
}
/**
* 修改用户部门
* @param departmentId
* @param postId
* @param ud
* @throws Exception
*/
public static void updateDepartmentPostUsers(String departmentId, String postId, UserUpdateBean ud) throws Exception {
getUserService().updateDepartmentPostUsers(departmentId,"",ud);
}
public static User getCurrentUser(HttpServletRequest req) throws Exception {
String username = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req);
if(Utils.isNullStr(username)){
return null;
}
return getUserByUserName(username);
}
/**
* 获取用户部门角色
* @param username
* @return
* @throws Exception
*/
private static UserRolesBean getUserRolesBean(String username) throws Exception {
return FRUserUtils.getUserService().getUserDepAndCustomRoles(username);
}
/**
* 获取部门职务
* @param username
* @return
* @throws Exception
*/
public static List<DepRoleBean> getDepRoleBean(String username) throws Exception{
return getUserRolesBean(username).getDepRoles();
}
/**
* 获取角色
* @param username
* @return
* @throws Exception
*/
public static List<String> getCustomRoles(String username) throws Exception{
return getUserRolesBean(username).getCustomRoles();
}
}