SecurityController.ts 6.08 KB
import {AxiosResponse, AxiosStatic} from 'axios';
import dayjs, {Dayjs} from 'dayjs';
// region 前端扩展导入包
import {TreeItem} from "autumn-vue/lib/core/bean/TreeItem";
import {Page} from "autumn-vue/lib/core/page/Page";
import {Role} from 'lib/src/entity/security/entity/Role';
import {User} from "lib/src/entity/security/entity/User";

// endregion

/**
 */
export class SecurityController {

    /**
     * 添加角色
     * @param role
     * @return Role
     * @throws IOException
     * @throws FieldException
     */
    static addRole(axios: AxiosStatic, role: any): Promise<AxiosResponse<Role>> {
        return axios.post('security/addRole', role);
    }

    /**
     * 添加用户
     * @param user
     * @return User
     * @throws FieldException
     */
    static addUser(axios: AxiosStatic, user: any): Promise<AxiosResponse<User>> {
        return axios.post('security/addUser', user);
    }

    /**
     * 用户修改自己的密码
     * @param userPassword
     * @return boolean
     */
    static changePassword(axios: AxiosStatic, userPassword: any): Promise<AxiosResponse<boolean>> {
        return axios.post('security/changePassword', userPassword);
    }

    /**
     */
    static enableUser(axios: AxiosStatic, userId: number, enabled: boolean): Promise<AxiosResponse<boolean>> {
        return axios.post('security/enableUser', null, {params: {userId: userId, enabled: enabled}});
    }

    /**
     */
    static enabledRole(axios: AxiosStatic, roleId: number, enabled: boolean): Promise<AxiosResponse<boolean>> {
        return axios.post('security/enabledRole', null, {params: {roleId: roleId, enabled: enabled}});
    }

    /**
     */
    static getEnabledRoles(axios: AxiosStatic): Promise<AxiosResponse<Role[]>> {
        return axios.get('security/getEnabledRoles');
    }

    /**
     */
    static getEnabledUsers(axios: AxiosStatic): Promise<AxiosResponse<User[]>> {
        return axios.get('security/getEnabledUsers');
    }

    /**
     */
    static getLoginUser(axios: AxiosStatic): Promise<AxiosResponse<User>> {
        return axios.get('security/getLoginUser');
    }

    /**
     */
    static getPrivilegeTreeByRoleId(axios: AxiosStatic, roleId: number): Promise<AxiosResponse<TreeItem[]>> {
        return axios.get('security/getPrivilegeTreeByRoleId', {params: {roleId: roleId}});
    }

    /**
     */
    static getRoleById(axios: AxiosStatic, roleId: number): Promise<AxiosResponse<Role>> {
        return axios.get('security/getRoleById', {params: {roleId: roleId}});
    }

    /**
     * 根据用户ID获取用户
     * @param userId
     * @return User
     */
    static getUserById(axios: AxiosStatic, userId: number): Promise<AxiosResponse<User>> {
        return axios.get('security/getUserById', {params: {userId: userId}});
    }

    /**
     * 根据用户名获取用户
     * @param userName
     * @return User
     */
    static getUserByUserName(axios: AxiosStatic, userName: string): Promise<AxiosResponse<User>> {
        return axios.get('security/getUserByUserName', {params: {userName: userName}});
    }

    /**
     */
    static pageRole(axios: AxiosStatic, pagination: any): Promise<AxiosResponse<Page<Role>>> {
        return axios.post('security/pageRole', pagination);
    }

    static PAGE_ROLE = 'security/pageRole';

    /**
     * 分页查询用户
     * @param pagination
     * @return Page
     */
    static pageUser(axios: AxiosStatic, pagination: any): Promise<AxiosResponse<Page<User>>> {
        return axios.post('security/pageUser', pagination);
    }

    static PAGE_USER = 'security/pageUser';

    /**
     * 删除角色
     * @param roleId
     * @return int
     * @throws IOException
     */
    static removeRoleById(axios: AxiosStatic, roleId: number): Promise<AxiosResponse<number>> {
        return axios.delete('security/removeRoleById', {params: {roleId: roleId}});
    }

    /**
     * 根据用户ID删除用户
     * @param userId
     */
    static removeUserById(axios: AxiosStatic, userId: number): Promise<AxiosResponse<number>> {
        return axios.delete('security/removeUserById', {params: {userId: userId}});
    }

    /**
     * 管理员重置密码
     * @param userPassword
     * @return boolean
     */
    static resetPassword(axios: AxiosStatic, userPassword: any): Promise<AxiosResponse<boolean>> {
        return axios.post('security/resetPassword', userPassword);
    }

    /**
     * 编辑个人信息
     * @param user
     * @return User
     * @throws FieldException
     */
    static updateProfile(axios: AxiosStatic, user: any): Promise<AxiosResponse<User>> {
        return axios.post('security/updateProfile', user);
    }

    /**
     * 修改角色
     * @param role
     * @return Role
     * @throws FieldException
     * @throws IOException
     */
    static updateRole(axios: AxiosStatic, role: any): Promise<AxiosResponse<Role>> {
        return axios.post('security/updateRole', role);
    }

    /**
     * 修改角色权限
     * @param role
     * @return Role
     * @throws FieldException
     * @throws IOException
     */
    static updateRolePrivileges(axios: AxiosStatic, role: any): Promise<AxiosResponse<Role>> {
        return axios.post('security/updateRolePrivileges', role);
    }

    /**
     */
    static updateRoleSetting(axios: AxiosStatic, role: any): Promise<AxiosResponse<Role>> {
        return axios.post('security/updateRoleSetting', role);
    }

    /**
     * 编辑用户
     * @param user
     * @return User
     * @throws FieldException
     */
    static updateUser(axios: AxiosStatic, user: any): Promise<AxiosResponse<User>> {
        return axios.post('security/updateUser', user);
    }

    // region 前端扩展代码区
    /**
     *
     * @return Authenticity
     */
    static getUserAuthentication(axios: AxiosStatic, module: string | undefined | null): Promise<AxiosResponse> {
        return axios.get('security/getUserAuthentication', {params: {module: module}});
    }

    static changeMobile(axios: AxiosStatic, mobile: string): Promise<AxiosResponse<User>> {
        return axios.post('security/changeMobile', null, {params: {mobile: mobile}});
    }

    // endregion
}