UserController.java 13.3 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
1 2
package pwc.taxtech.atms.controller;

3
import io.swagger.annotations.ApiOperation;
eddie.woo's avatar
eddie.woo committed
4 5 6 7 8 9 10 11 12 13 14
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
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;
15 16 17
import pwc.taxtech.atms.dpo.UserDto;
import pwc.taxtech.atms.dpo.UserOrgDto;
import pwc.taxtech.atms.dpo.UserOrgRoleDto;
eddie.woo's avatar
eddie.woo committed
18 19 20 21 22 23 24 25 26 27 28 29
import pwc.taxtech.atms.dto.LoginInputDto;
import pwc.taxtech.atms.dto.LoginOutputDto;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.organization.OrgRoleDtoList;
import pwc.taxtech.atms.dto.permission.UserPermissionDto;
import pwc.taxtech.atms.dto.permission.UserPermissionKeyDto;
import pwc.taxtech.atms.dto.user.UpdateParam;
import pwc.taxtech.atms.dto.user.UserAndUserRoleSaveDto;
import pwc.taxtech.atms.dto.user.UserOrganizationDto;
import pwc.taxtech.atms.dto.user.UserRoleDimensionValueDto;
import pwc.taxtech.atms.dto.user.UserRoleDisplayInfo;
import pwc.taxtech.atms.dto.user.UserRoleSaveDto;
30
import pwc.taxtech.atms.entity.User;
31
import pwc.taxtech.atms.service.impl.RoleServiceImpl;
32
import pwc.taxtech.atms.service.impl.UserAccountServiceImpl;
33
import pwc.taxtech.atms.service.impl.UserRoleServiceImpl;
34
import pwc.taxtech.atms.service.impl.UserServiceImpl;
eddie.woo's avatar
eddie.woo committed
35

36 37
import java.util.List;

eddie.woo's avatar
eddie.woo committed
38 39 40 41 42
@RestController
@RequestMapping("/api/v1/user/")
public class UserController {
    private static final Logger logger = LoggerFactory.getLogger(UserController.class);
    @Autowired
43
    private UserServiceImpl userService;
eddie.woo's avatar
eddie.woo committed
44
    @Autowired
45
    private UserRoleServiceImpl userRoleService;
eddie.woo's avatar
eddie.woo committed
46
    @Autowired
47
    private RoleServiceImpl roleService;
eddie.woo's avatar
eddie.woo committed
48
    @Autowired
49
    private UserAccountServiceImpl userAccountService;
eddie.woo's avatar
eddie.woo committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

    // used to test,
    // http://localhost:8080/atms-api/api/v1/user/getUser?id=0906913f-f8c3-423c-b9b1-9ae1be647087
    @RequestMapping(value = "getUser", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public User getUser(@RequestParam("id") String id) {
        return userService.getUser(id);
    }

    @ApiOperation(value = "获取指定用户的权限", notes = "获取用户的权限级别,可访问的模块以及页面")
    @RequestMapping(value = "getUserPermission", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public UserPermissionDto getUserPermission(@RequestParam("userName") String userName) {
        return userService.getUserPermission(userName);
    }

    @ApiOperation(value = "获取指定用户的权限(新接口)", notes = "获取用户的权限级别,可访问的模块以及页面")
    @RequestMapping(value = "getUserPermissionKey", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public UserPermissionKeyDto getUserPermissionKey(@RequestParam("userName") String userName) {
        return userService.getUserPermissionKey(userName);
    }

    @RequestMapping(value = "login", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public OperationResultDto<LoginOutputDto> login(@RequestBody(required = false) LoginInputDto input) {
        logger.debug("enter login");
        OperationResultDto<LoginOutputDto> result = userService.login(input);
        return result;
    }

    @ApiOperation(value = "获取所有的用户角色列表")
    @RequestMapping(value = "getAllUserRoleList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
frank.xa.zhang's avatar
frank.xa.zhang committed
79
    public List<UserRoleDisplayInfo> getAllUserRoleList(@RequestParam("serviceTypeID") String serviceTypeId) {
80
        return userRoleService.getAllUserRoleList(serviceTypeId);
eddie.woo's avatar
eddie.woo committed
81 82
    }

83
    @ApiOperation(value = "根据传入的用户Id获取该用户以及所属机构的信息")
eddie.woo's avatar
eddie.woo committed
84
    @RequestMapping(value = "getUser/{userId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
85 86
    public UserDto getUserById(@PathVariable("userId") String userId) {
        return userService.getUserById(userId);
eddie.woo's avatar
eddie.woo committed
87 88
    }

89
    @ApiOperation(value = "通过传入的用户Id获取该用户所有的角色", notes = "通过用户获取可访问不可访问的所有机构,包括维度上继承下来的")
90 91
    @RequestMapping(value = "getUserRoleByUserID", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public OrgRoleDtoList getUserRoleByUserId(@RequestParam("userID") String userId) {
92
        return userRoleService.getUserRoleByUserId(userId);
eddie.woo's avatar
eddie.woo committed
93 94
    }

95
    @ApiOperation(value = "根据传入的用户Id获取该用户的角色机构等信息")
eddie.woo's avatar
eddie.woo committed
96 97 98 99 100 101
    @RequestMapping(value = "displaySingle", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public UserAndUserRoleSaveDto getSingleUserByUserId(@RequestParam("userId") String userId) {
        return userRoleService.getSingleUserByUserId(userId);
    }

    @ApiOperation(value = "获取用户的默认角色")
102 103 104
    @RequestMapping(value = "getUserRoleListByUserId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public UserRoleDisplayInfo getUserRoleListByUserId(@RequestParam("userId") String userId) {
        return userRoleService.getUserRoleListByUserId(userId);
eddie.woo's avatar
eddie.woo committed
105 106
    }

107 108 109
    @ApiOperation(value = "通过机构Id和用户Id获取该用户的默认角色")
    @RequestMapping(value = "getUserRoleByOrgIdUserId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public UserOrganizationDto getUserRoleByOrgIdUserId(@RequestParam("userId") String userId,
110
                                                        @RequestParam("orgId") String orgId) {
111
        return userRoleService.getUserRoleByOrgId(userId, orgId);
eddie.woo's avatar
eddie.woo committed
112 113 114 115
    }

    @ApiOperation(value = "为角色添加用户")
    @RequestMapping(value = "addUsersToRole", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
116 117
    public @ResponseBody
    Boolean addUsersToRole(@RequestBody UserRoleSaveDto userRoleSaveDto) {
118
        roleService.addUsersToRole(userRoleSaveDto.getRoleId(), userRoleSaveDto.getServiceTypeId(),
eddie.woo's avatar
eddie.woo committed
119 120 121 122 123 124 125
                userRoleSaveDto.getUserIdList());
        return true;
    }

    @SuppressWarnings("rawtypes")
    @ApiOperation(value = "为角色添加用户")
    @RequestMapping(value = "enableordisableuser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
126 127
    public @ResponseBody
    OperationResultDto enableOrDisableUser(@RequestBody UpdateParam updateParam) {
eddie.woo's avatar
eddie.woo committed
128 129 130 131 132 133
        return userRoleService.enableOrDisableUser(updateParam);
    }

    @SuppressWarnings("rawtypes")
    @ApiOperation(value = "为机构删除用户角色")
    @RequestMapping(value = "deleteUserRoleForOrg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
134 135
    public @ResponseBody
    OperationResultDto deleteUserRoleForOrg(@RequestBody UserOrgDto userDto) {
eddie.woo's avatar
eddie.woo committed
136
        logger.debug("enter deleteUserRoleForOrg");
137
        return userRoleService.deleteUserRoleByOrgId(userDto);
eddie.woo's avatar
eddie.woo committed
138
    }
139

eddie.woo's avatar
eddie.woo committed
140 141 142
    @SuppressWarnings("rawtypes")
    @ApiOperation(value = "机构删除,包括维度上的继承删除")
    @RequestMapping(value = "deleteUserRoleOrg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
143 144
    public @ResponseBody
    OperationResultDto deleteUserRoleOrg(
eddie.woo's avatar
eddie.woo committed
145 146 147 148 149
            @RequestBody List<UserRoleDimensionValueDto> userRoleList) {
        return userRoleService.deleteUserRoleOrg(userRoleList);
    }

    @ApiOperation(value = "获取事业部,产品线的值下的所有机构的用户权限(维度权限)", notes = "展开事业部卡片>用户>权限设置")
150 151 152 153 154
    @RequestMapping(value = "getUserRoleByDimensionValueId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<UserRoleDisplayInfo> getUserRoleByDimensionValueId(
            @RequestParam("parentDimensionId") String parentDimensionId,
            @RequestParam("dimensionValueId") String dimensionValueId) {
        return userRoleService.getUserRoleByDimensionValueId(parentDimensionId, dimensionValueId);
eddie.woo's avatar
eddie.woo committed
155 156 157
    }

    @ApiOperation(value = "获取在某个维度下的机构的特殊角色,用户单独跟机构设置角色", notes = "展开事业部卡片>用户>权限设置")
158 159 160 161 162
    @RequestMapping(value = "getSpecialUserRoleByDimensionValueId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<UserRoleDisplayInfo> getSpecialUserRoleByDimensionValueId(
            @RequestParam("parentDimensionId") String parentDimensionId,
            @RequestParam("dimensionValueId") String dimensionValueId) {
        return userRoleService.getSpecialUserRoleByDimensionValueId(parentDimensionId, dimensionValueId);
eddie.woo's avatar
eddie.woo committed
163 164 165 166
    }

    @ApiOperation(value = "获取用户维度角色列表", notes = "展开事业部卡片>用户")
    @RequestMapping(value = "getDimensionUserRoleList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
167 168 169
    public List<UserOrgRoleDto> getDimensionUserRoleList(@RequestParam("parentDimensionId") String parentDimensionId,
                                                         @RequestParam("dimensionValueId") String dimensionValueId) {
        return userRoleService.getDimensionUserRoleList(parentDimensionId, dimensionValueId);
eddie.woo's avatar
eddie.woo committed
170 171 172 173 174 175 176 177 178 179 180
    }

    @SuppressWarnings("rawtypes")
    @ApiOperation(value = "维度上权限用户删除")
    @RequestMapping(value = "deleteUserRoleDimension", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public OperationResultDto deleteUserRoleDimension(@RequestBody List<UserRoleDimensionValueDto> userRoleList) {
        return userRoleService.deleteUserRoleDimension(userRoleList);
    }

    @ApiOperation(value = "为维度添加用户")
    @RequestMapping(value = "updateUserRoleForDimension", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
181 182
    public @ResponseBody
    OperationResultDto<?> updateUserRoleForDimension(
eddie.woo's avatar
eddie.woo committed
183 184 185 186 187 188 189
            @RequestBody List<UserRoleDimensionValueDto> userRoleList) {
        return userRoleService.updateUserRoleForDimension(userRoleList);
    }

    @SuppressWarnings("rawtypes")
    @ApiOperation(value = "添加事业部的值的权限")
    @RequestMapping(value = "updateUserRoleDimension", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
190 191
    public @ResponseBody
    OperationResultDto updateUserRoleDimension(
eddie.woo's avatar
eddie.woo committed
192 193 194 195 196 197
            @RequestBody List<UserRoleDimensionValueDto> userRoleList) {
        return userRoleService.updateUserRoleDimension(userRoleList);
    }

    @ApiOperation(value = "更新一个用户的信息")
    @RequestMapping(value = "update", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
198 199
    public @ResponseBody
    OperationResultDto<User> updateUser(@RequestBody UserAndUserRoleSaveDto userDto) {
eddie.woo's avatar
eddie.woo committed
200 201 202 203 204 205
        return userService.updateUser(userDto);
    }

    @SuppressWarnings("rawtypes")
    @ApiOperation(value = "机构用户权限编辑")
    @RequestMapping(value = "updateUserRoleOrganization", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
206 207
    public @ResponseBody
    OperationResultDto updateUserRoleOrganization(
eddie.woo's avatar
eddie.woo committed
208 209 210 211 212 213
            @RequestBody List<UserRoleDimensionValueDto> userRoleList) {
        return userRoleService.updateUserRoleOrganization(userRoleList);
    }

    @ApiOperation(value = "添加一个新的用户")
    @RequestMapping(value = "add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
214 215
    public @ResponseBody
    OperationResultDto<User> addUser(@RequestBody UserAndUserRoleSaveDto userAndUserRoleSaveDto) {
eddie.woo's avatar
eddie.woo committed
216 217 218 219 220 221
        return userAccountService.addNewUser(userAndUserRoleSaveDto);
    }

    @SuppressWarnings("rawtypes")
    @ApiOperation(value = "删除可继承权限", notes = "用户管理>点击用户卡片>点击各机构设置数据的修改按钮>点击角色>取消设置下的允许继承>确定")
    @RequestMapping(value = "deleteUserOrg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
222 223
    public @ResponseBody
    OperationResultDto deleteUserOrg(@RequestBody List<UserRoleDimensionValueDto> userRoleList) {
eddie.woo's avatar
eddie.woo committed
224 225 226 227 228 229
        return userService.deleteUserOrg(userRoleList);
    }

    @SuppressWarnings("rawtypes")
    @ApiOperation(value = "给机构添加用户", notes = "机构管理>点击机构>用户>添加用户>选中用户并提交")
    @RequestMapping(value = "updateUserRoleForOrg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
230 231
    public @ResponseBody
    OperationResultDto updateUserRoleForOrg(
eddie.woo's avatar
eddie.woo committed
232 233 234 235
            @RequestBody List<UserRoleDimensionValueDto> userRoleList) {
        return userRoleService.updateUserRoleForOrg(userRoleList);
    }

236 237 238
    @SuppressWarnings("rawtypes")
    @ApiOperation(value = "查询用户信息", notes = "税务运营管理平台>增值税申报")
    @RequestMapping(value = "getUserByName", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
239 240
    public @ResponseBody
    UserDto getUserByName(
241 242 243 244
            @RequestBody UserDto userParam) {
        return userRoleService.GetUserByUserName(userParam);
    }

eddie.woo's avatar
eddie.woo committed
245
}