RoleController.java 11 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package pwc.taxtech.atms.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;
18
import pwc.taxtech.atms.dpo.UserRoleInfo;
eddie.woo's avatar
eddie.woo committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.dimension.DimensionValueUpdateDto;
import pwc.taxtech.atms.dto.navtree.NavTreeDto;
import pwc.taxtech.atms.dto.role.RoleDisplayDto;
import pwc.taxtech.atms.dto.role.RoleDto;
import pwc.taxtech.atms.dto.role.RoleDtoTree;
import pwc.taxtech.atms.dto.role.RolePermissionDto;
import pwc.taxtech.atms.dto.role.UpdateRoleInfo;
import pwc.taxtech.atms.dto.user.DimensionRole;
import pwc.taxtech.atms.dto.user.DimensionUser;
import pwc.taxtech.atms.dto.user.UserRoleDimensionValueDto;
import pwc.taxtech.atms.dto.user.UserRoleDto;
import pwc.taxtech.atms.dto.user.UserRoleUpdateDto;
import pwc.taxtech.atms.service.RoleService;

/** @see PwC.Tax.Tech.Atms.WebApi\Controllers\RoleController.cs */
@RestController
@RequestMapping("/api/v1/role/")
public class RoleController {

    private static Logger logger = LoggerFactory.getLogger(RoleController.class);

    @Autowired
    private RoleService roleService;

    @ApiOperation(value = "获取用户树形列表", notes = "返回所有用户的树形列表")
    @RequestMapping(value = "getRoleTreeList", method = RequestMethod.GET)
    public @ResponseBody List<NavTreeDto> getRoleTreeList() {
        logger.debug("RoleController getRoleTreeList");
        return roleService.getRoleTreeList();
    }

    @ApiOperation(value = "获取所有用户角色", notes = "返回所有用户的角色")
    @RequestMapping(value = "getAllOwnUserRoleList", method = RequestMethod.GET)
    public @ResponseBody List<UserRoleInfo> getAllOwnUserRoleList() {
        logger.debug("RoleController getAllOwnUserRoleList");
        return roleService.getAllOwnUserRoleList();
    }

    @ApiOperation(value = "获取可访问的所有机构", notes = "返回可访问的所有机构")
    @RequestMapping(value = "getAllUserRoleList", method = RequestMethod.GET)
    public @ResponseBody List<UserRoleInfo> getAllUserRoleList() {
        logger.debug("RoleController getAllUserRoleList");
        return roleService.getAllUserRoleList();
    }

65
    @ApiOperation(value = "通过传入的用户Id获取该用户的所有角色")
66 67 68
    @RequestMapping(value = "getAllRoleListByUserID", method = RequestMethod.GET)
    public @ResponseBody List<UserRoleDto> getAllRoleListByUserId(@RequestParam("userID") String userId,
            @RequestParam("serviceTypeID") String serviceTypeId) {
69 70
        logger.debug("RoleController getAllRoleListByUserId");
        return roleService.getAllRoleListByUserId(userId, serviceTypeId);
eddie.woo's avatar
eddie.woo committed
71 72 73 74 75 76 77 78 79 80
    }

    @ApiOperation(value = "获取所有角色")
    @RequestMapping(value = "displayByServiceGroup", method = RequestMethod.GET)
    public @ResponseBody List<RoleDtoTree> getRoleList() {
        logger.debug("RoleController getRoleList");
        return roleService.getRoleList();
    }

    @ApiOperation(value = "获取角色下用户列表")
frank.xa.zhang's avatar
frank.xa.zhang committed
81
    @RequestMapping(value = "getUsersByRoleID", method = RequestMethod.GET)
82 83
    public @ResponseBody List<UserRoleDto> getUsersByRoleId(@RequestParam("roleId") String roleId) {
        return roleService.getUsersByRoleId(roleId);
eddie.woo's avatar
eddie.woo committed
84 85 86
    }

    @ApiOperation(value = "获取角色下额外用户列表")
frank.xa.zhang's avatar
frank.xa.zhang committed
87
    @RequestMapping(value = "getExtraUsersByRoleID", method = RequestMethod.GET)
88 89
    public @ResponseBody List<UserRoleDto> getExtraUsersByRoleId(@RequestParam("roleId") String roleId) {
        return roleService.getExtraUsersByRoleId(roleId);
eddie.woo's avatar
eddie.woo committed
90 91 92 93
    }

    @ApiOperation(value = "删除角色下用户")
    @RequestMapping(value = "removeUserRole", method = RequestMethod.POST)
94
    public @ResponseBody Boolean removeUserRole(@RequestParam("userID") String userId,
95
            @RequestBody List<String> roleIdList, @RequestParam("serviceTypeID") String serviceTypeId) {
96
        roleService.removeUserRole(userId, roleIdList, serviceTypeId);
eddie.woo's avatar
eddie.woo committed
97 98 99 100 101 102 103 104 105 106 107 108
        return true;
    }

    @ApiOperation(value = "Get role list by role type")
    @RequestMapping(value = "displayByRoleType", method = RequestMethod.GET)
    public @ResponseBody List<RoleDto> getRoleListByRoleType(@RequestParam("roleTypeId") String roleTypeId) {
        return roleService.getRoleListByRoleType(roleTypeId);
    }

    @ApiOperation(value = "增加角色分类")
    @RequestMapping(value = "addRoleCategory", method = RequestMethod.GET)
    public @ResponseBody Boolean addRoleCategory(@RequestParam("name") String roleCategoryName,
109
            @RequestParam("roleCategoryID") String roleCategoryId) {
110
        roleService.addRoleCategory(roleCategoryName, roleCategoryId);
eddie.woo's avatar
eddie.woo committed
111 112 113 114 115 116
        return true;
    }

    @ApiOperation(value = "更新角色分类名称")
    @RequestMapping(value = "updateRoleCategory", method = RequestMethod.GET)
    public @ResponseBody Boolean updateRoleCategory(@RequestParam("updateName") String roleCategoryName,
117 118
            @RequestParam("id") String roleCategoryId) {
        roleService.updateRoleCategory(roleCategoryName, roleCategoryId);
eddie.woo's avatar
eddie.woo committed
119 120 121 122 123 124
        return true;
    }

    @SuppressWarnings("rawtypes")
    @ApiOperation(value = "删除角色分类")
    @RequestMapping(value = "deleteRoleCategory", method = RequestMethod.GET)
125 126
    public @ResponseBody OperationResultDto deleteRoleCategory(@RequestParam("id") String roleCategoryId) {
        return roleService.deleteRoleCategory(roleCategoryId);
eddie.woo's avatar
eddie.woo committed
127 128 129 130 131 132 133 134
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    @ApiOperation(value = "Add a role info")
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public @ResponseBody Map addRole(@RequestBody RoleDisplayDto roleDisplayDto) {

        Map result = new HashMap<>();
135 136
        if ("-1".equals(roleService.addRole(roleDisplayDto))) {
            result.put("data", -1);
eddie.woo's avatar
eddie.woo committed
137 138 139 140 141 142 143 144
        } else {
            result.put("data", roleService.getRoleList());
        }
        return result;
    }

    @ApiOperation(value = "Update a role info")
    @RequestMapping(value = "update", method = RequestMethod.PUT)
145
    public void updateRole(@RequestBody UpdateRoleInfo updateRole, @RequestParam("roleID") String roleId) {
eddie.woo's avatar
eddie.woo committed
146

147
        roleService.updateRole(updateRole, roleId);
eddie.woo's avatar
eddie.woo committed
148 149 150 151 152 153 154 155 156 157 158 159
    }

    @ApiOperation(value = "Validate if the role name is unique")
    @RequestMapping(value = "validateRoleNameUnique", method = RequestMethod.GET)
    public Boolean validateRoleNameUnique(@RequestParam("roleName") String roleName,
            @RequestParam("oldRoleName") String oldRoleName) {

        return roleService.validateRoleNameUnique(roleName, oldRoleName);
    }

    @ApiOperation(value = "Need to check mapping between user and role, if yes not allow delete role")
    @RequestMapping(value = "checkReferenceforRole", method = RequestMethod.GET)
160
    public Boolean checkExistReference(@RequestParam("roleID") String roleId) {
eddie.woo's avatar
eddie.woo committed
161

162
        return roleService.checkUserRole(roleId);
eddie.woo's avatar
eddie.woo committed
163 164 165 166 167 168 169 170 171 172
    }

    @ApiOperation(value = "Delete a role info")
    @RequestMapping(value = "delete", method = RequestMethod.POST)
    public @ResponseBody List<RoleDtoTree> deleteRole(@RequestBody RoleDto roleDto) {

        roleService.deleteRole(roleDto);
        return roleService.getRoleList();
    }

173
    @ApiOperation(value = "Get user role list by organizationId, dimensionId and dimensionValueId")
eddie.woo's avatar
eddie.woo committed
174
    @RequestMapping(value = "getUserRoleList", method = RequestMethod.GET)
frank.xa.zhang's avatar
frank.xa.zhang committed
175 176 177
    public @ResponseBody List<UserRoleInfo> getUserRoleList(@RequestParam("organizationID") String organizationId,
            @RequestParam("dimensionID") String dimensionId,
            @RequestParam("dimensionValueID") String dimensionValueId) {
eddie.woo's avatar
eddie.woo committed
178 179

        UserRoleDimensionValueDto userRoleDimensionValueDto = new UserRoleDimensionValueDto();
180 181 182
        userRoleDimensionValueDto.setOrganizationId(organizationId);
        userRoleDimensionValueDto.setDimensionId(dimensionId);
        userRoleDimensionValueDto.setDimensionValueId(dimensionValueId);
eddie.woo's avatar
eddie.woo committed
183 184 185 186 187 188
        return roleService.getUserRoleList(userRoleDimensionValueDto);
    }

    @ApiOperation(value = "Get all role permission list by serviceType")
    @RequestMapping(value = "getAllRolePermission", method = RequestMethod.GET)
    public @ResponseBody List<RolePermissionDto> getAllRolePermission(
frank.xa.zhang's avatar
frank.xa.zhang committed
189
            @RequestParam("serviceTypeID") String serviceTypeId) {
eddie.woo's avatar
eddie.woo committed
190

191
        return roleService.getAllRolePermission(serviceTypeId);
eddie.woo's avatar
eddie.woo committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    }

    @ApiOperation(value = "更新用户角色列表")
    @RequestMapping(value = "updateUserRole", method = RequestMethod.POST)
    public Boolean updateUserRole(@RequestBody UserRoleUpdateDto userRoleDto) {

        roleService.updateUserRole(userRoleDto);
        return true;
    }

    @ApiOperation(value = "用户详情页面,增加范围")
    @RequestMapping(value = "updateDimensionValues", method = RequestMethod.POST)
    public Boolean updateDimensionValues(@RequestBody DimensionValueUpdateDto dimensionValueUpdateDto) {

        roleService.updateDimensionValues(dimensionValueUpdateDto);
        return true;
    }

    @ApiOperation(value = "用户详情页面,增加机构")
    @RequestMapping(value = "updateUserOrg", method = RequestMethod.POST)
212
    public Boolean updateUserOrg(@RequestBody List<String> orgIdList, @RequestParam("userID") String userId) {
eddie.woo's avatar
eddie.woo committed
213

214
        roleService.updateUserOrg(orgIdList, userId);
eddie.woo's avatar
eddie.woo committed
215 216 217 218 219
        return true;
    }

    @ApiOperation(value = "获取维度,角色,用户列表", notes = "机构/卡片/机构卡片/点击用户数")
    @RequestMapping(value = "getDimensionRoleUserList", method = RequestMethod.GET)
220 221 222
    public @ResponseBody List<DimensionRole> getDimensionRoleUserList(@RequestParam("dimensionId") String dimensionId,
            @RequestParam("dimensionValueId") String dimensionValueId) {
        return roleService.getDimensionRoleUserList(dimensionId, dimensionValueId);
eddie.woo's avatar
eddie.woo committed
223 224 225 226
    }

    @ApiOperation(value = "获取某一个维度的 用户 和 机构列表,角色列表", notes = "机构/卡片/机构卡片/点击用户数")
    @RequestMapping(value = "getDimensionUserRoleList", method = RequestMethod.GET)
227 228 229
    public @ResponseBody List<DimensionUser> getDimensionUserRoleList(@RequestParam("dimensionId") String dimensionId,
            @RequestParam("dimensionValueId") String dimensionValueId) {
        return roleService.getDimensionUserRoleList(dimensionId, dimensionValueId);
eddie.woo's avatar
eddie.woo committed
230 231
    }

232 233 234 235
    @ApiOperation(value = "根据区域Id,获取区域用户角色信息", notes = "机构/卡片/区域卡片/选择区域/点击用户数")
    @RequestMapping(value = "getActiveUserRoleListByAreaId", method = RequestMethod.GET)
    public @ResponseBody List<UserRoleInfo> getActiveUserRoleListByAreaId(@RequestParam("areaId") String areaId) {
        return roleService.getActiveUserRoleListByAreaId(areaId);
eddie.woo's avatar
eddie.woo committed
236 237
    }
}