UserController.java 13.7 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
1 2 3 4 5 6
package pwc.taxtech.atms.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
gary's avatar
gary committed
7
import org.springframework.security.access.annotation.Secured;
eddie.woo's avatar
eddie.woo committed
8 9 10 11 12 13 14
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

    // 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);
    }

gary's avatar
gary committed
58
//    @ApiOperation(value = "获取指定用户的权限", notes = "获取用户的权限级别,可访问的模块以及页面")
eddie.woo's avatar
eddie.woo committed
59 60 61 62 63
    @RequestMapping(value = "getUserPermission", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public UserPermissionDto getUserPermission(@RequestParam("userName") String userName) {
        return userService.getUserPermission(userName);
    }

gary's avatar
gary committed
64
//    @ApiOperation(value = "获取指定用户的权限(新接口)", notes = "获取用户的权限级别,可访问的模块以及页面")
eddie.woo's avatar
eddie.woo committed
65 66 67 68 69 70 71 72 73 74 75 76
    @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;
    }

gary's avatar
gary committed
77
//    @ApiOperation(value = "获取所有的用户角色列表")
eddie.woo's avatar
eddie.woo committed
78
    @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
    }

gary's avatar
gary committed
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
    }

gary's avatar
gary committed
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
    }

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

gary's avatar
gary committed
101
//    @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
    }

gary's avatar
gary committed
107
//    @ApiOperation(value = "通过机构Id和用户Id获取该用户的默认角色")
108 109
    @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
    }

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

    @SuppressWarnings("rawtypes")
gary's avatar
gary committed
125
//    @ApiOperation(value = "为角色添加用户")
gary's avatar
gary committed
126 127
    //  todo 这里应该是错的  @ApiOperation(value = "启用或停用用户")
    @Secured("user:edit")
eddie.woo's avatar
eddie.woo committed
128
    @RequestMapping(value = "enableordisableuser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
129 130
    public @ResponseBody
    OperationResultDto enableOrDisableUser(@RequestBody UpdateParam updateParam) {
eddie.woo's avatar
eddie.woo committed
131 132 133 134
        return userRoleService.enableOrDisableUser(updateParam);
    }

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

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

gary's avatar
gary committed
154
//    @ApiOperation(value = "获取事业部,产品线的值下的所有机构的用户权限(维度权限)", notes = "展开事业部卡片>用户>权限设置")
155 156 157 158 159
    @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
160 161
    }

gary's avatar
gary committed
162
//    @ApiOperation(value = "获取在某个维度下的机构的特殊角色,用户单独跟机构设置角色", notes = "展开事业部卡片>用户>权限设置")
163 164 165 166 167
    @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
168 169
    }

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

    @SuppressWarnings("rawtypes")
gary's avatar
gary committed
178
//    @ApiOperation(value = "维度上权限用户删除")
eddie.woo's avatar
eddie.woo committed
179 180 181 182 183
    @RequestMapping(value = "deleteUserRoleDimension", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public OperationResultDto deleteUserRoleDimension(@RequestBody List<UserRoleDimensionValueDto> userRoleList) {
        return userRoleService.deleteUserRoleDimension(userRoleList);
    }

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

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

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

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

gary's avatar
gary committed
218
//    @ApiOperation(value = "添加一个新的用户")
eddie.woo's avatar
eddie.woo committed
219
    @RequestMapping(value = "add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
gary's avatar
gary committed
220
    @Secured("user:add")
221 222
    public @ResponseBody
    OperationResultDto<User> addUser(@RequestBody UserAndUserRoleSaveDto userAndUserRoleSaveDto) {
eddie.woo's avatar
eddie.woo committed
223 224 225 226
        return userAccountService.addNewUser(userAndUserRoleSaveDto);
    }

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

    @SuppressWarnings("rawtypes")
gary's avatar
gary committed
236
//    @ApiOperation(value = "给机构添加用户", notes = "机构管理>点击机构>用户>添加用户>选中用户并提交")
eddie.woo's avatar
eddie.woo committed
237
    @RequestMapping(value = "updateUserRoleForOrg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
gary's avatar
gary committed
238
    @Secured("user:edit")
239 240
    public @ResponseBody
    OperationResultDto updateUserRoleForOrg(
eddie.woo's avatar
eddie.woo committed
241 242 243 244
            @RequestBody List<UserRoleDimensionValueDto> userRoleList) {
        return userRoleService.updateUserRoleForOrg(userRoleList);
    }

245
    @SuppressWarnings("rawtypes")
gary's avatar
gary committed
246
//    @ApiOperation(value = "查询用户信息", notes = "税务运营管理平台>增值税申报")
247
    @RequestMapping(value = "getUserByName", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
248 249
    public @ResponseBody
    UserDto getUserByName(
250 251 252 253
            @RequestBody UserDto userParam) {
        return userRoleService.GetUserByUserName(userParam);
    }

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