package pwc.taxtech.atms.controller; import java.util.List; 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; import io.swagger.annotations.ApiOperation; 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.UserDto; import pwc.taxtech.atms.dto.user.UserOrgDto; import pwc.taxtech.atms.dto.user.UserOrgRoleDto; 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; import pwc.taxtech.atms.entitiy.User; import pwc.taxtech.atms.service.RoleService; import pwc.taxtech.atms.service.UserAccountService; import pwc.taxtech.atms.service.UserRoleService; import pwc.taxtech.atms.service.UserService; @RestController @RequestMapping("/api/v1/user/") public class UserController { private static final Logger logger = LoggerFactory.getLogger(UserController.class); @Autowired private UserService userService; @Autowired private UserRoleService userRoleService; @Autowired private RoleService roleService; @Autowired private UserAccountService userAccountService; // 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) public List<UserRoleDisplayInfo> getAllUserRoleList(@RequestParam("serviceTypeID") String serviceTypeID) { return userRoleService.getAllUserRoleList(serviceTypeID); } @ApiOperation(value = "根据传入的用户ID获取该用户以及所属机构的信息") @RequestMapping(value = "getUser/{userId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public UserDto getUserByID(@PathVariable("userId") String userId) { return userService.getUserByID(userId); } @ApiOperation(value = "通过传入的用户ID获取该用户所有的角色", notes = "通过用户获取可访问不可访问的所有机构,包括维度上继承下来的") @RequestMapping(value = "getUserRoleByUserID", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public OrgRoleDtoList getUserRoleByUserID(@RequestParam("userID") String userID) { return userRoleService.getUserRoleByUserID(userID); } @ApiOperation(value = "根据传入的用户ID获取该用户的角色机构等信息") @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 = "获取用户的默认角色") @RequestMapping(value = "getUserRoleListByUserID", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public UserRoleDisplayInfo getUserRoleListByUserID(@RequestParam("userId") String userId) { return userRoleService.getUserRoleListByUserID(userId); } @ApiOperation(value = "通过机构ID和用户ID获取该用户的默认角色") @RequestMapping(value = "getUserRoleByOrgIDUserID", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public UserOrganizationDto getUserRoleByOrgIDUserID(@RequestParam("userID") String userID, @RequestParam("orgID") String orgID) { return userRoleService.getUserRoleByOrgID(userID, orgID); } @ApiOperation(value = "为角色添加用户") @RequestMapping(value = "addUsersToRole", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody Boolean addUsersToRole(@RequestBody UserRoleSaveDto userRoleSaveDto) { roleService.addUsersToRole(userRoleSaveDto.getRoleID(), userRoleSaveDto.getServiceTypeID(), userRoleSaveDto.getUserIdList()); return true; } @SuppressWarnings("rawtypes") @ApiOperation(value = "为角色添加用户") @RequestMapping(value = "enableordisableuser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody OperationResultDto enableOrDisableUser(@RequestBody UpdateParam updateParam) { return userRoleService.enableOrDisableUser(updateParam); } @SuppressWarnings("rawtypes") @ApiOperation(value = "为机构删除用户角色") @RequestMapping(value = "deleteUserRoleForOrg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody OperationResultDto deleteUserRoleForOrg(@RequestBody UserOrgDto userDto) { logger.debug("enter deleteUserRoleForOrg"); return userRoleService.deleteUserRoleByOrgID(userDto); } @SuppressWarnings("rawtypes") @ApiOperation(value = "机构删除,包括维度上的继承删除") @RequestMapping(value = "deleteUserRoleOrg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody OperationResultDto deleteUserRoleOrg( @RequestBody List<UserRoleDimensionValueDto> userRoleList) { return userRoleService.deleteUserRoleOrg(userRoleList); } @ApiOperation(value = "获取事业部,产品线的值下的所有机构的用户权限(维度权限)", notes = "展开事业部卡片>用户>权限设置") @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); } @ApiOperation(value = "获取在某个维度下的机构的特殊角色,用户单独跟机构设置角色", notes = "展开事业部卡片>用户>权限设置") @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); } @ApiOperation(value = "获取用户维度角色列表", notes = "展开事业部卡片>用户") @RequestMapping(value = "getDimensionUserRoleList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public List<UserOrgRoleDto> getDimensionUserRoleList(@RequestParam("parentDimensionID") String parentDimensionID, @RequestParam("dimensionValueID") String dimensionValueID) { return userRoleService.getDimensionUserRoleList(parentDimensionID, dimensionValueID); } @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) public @ResponseBody OperationResultDto<?> updateUserRoleForDimension( @RequestBody List<UserRoleDimensionValueDto> userRoleList) { return userRoleService.updateUserRoleForDimension(userRoleList); } @SuppressWarnings("rawtypes") @ApiOperation(value = "添加事业部的值的权限") @RequestMapping(value = "updateUserRoleDimension", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody OperationResultDto updateUserRoleDimension( @RequestBody List<UserRoleDimensionValueDto> userRoleList) { return userRoleService.updateUserRoleDimension(userRoleList); } @ApiOperation(value = "更新一个用户的信息") @RequestMapping(value = "update", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody OperationResultDto<User> updateUser(@RequestBody UserAndUserRoleSaveDto userDto) { return userService.updateUser(userDto); } @SuppressWarnings("rawtypes") @ApiOperation(value = "机构用户权限编辑") @RequestMapping(value = "updateUserRoleOrganization", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody OperationResultDto updateUserRoleOrganization( @RequestBody List<UserRoleDimensionValueDto> userRoleList) { return userRoleService.updateUserRoleOrganization(userRoleList); } @ApiOperation(value = "添加一个新的用户") @RequestMapping(value = "add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody OperationResultDto<User> addUser(@RequestBody UserAndUserRoleSaveDto userAndUserRoleSaveDto) { return userAccountService.addNewUser(userAndUserRoleSaveDto); } @SuppressWarnings("rawtypes") @ApiOperation(value = "删除可继承权限", notes = "用户管理>点击用户卡片>点击各机构设置数据的修改按钮>点击角色>取消设置下的允许继承>确定") @RequestMapping(value = "deleteUserOrg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody OperationResultDto deleteUserOrg(@RequestBody List<UserRoleDimensionValueDto> userRoleList) { return userService.deleteUserOrg(userRoleList); } @SuppressWarnings("rawtypes") @ApiOperation(value = "给机构添加用户", notes = "机构管理>点击机构>用户>添加用户>选中用户并提交") @RequestMapping(value = "updateUserRoleForOrg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody OperationResultDto updateUserRoleForOrg( @RequestBody List<UserRoleDimensionValueDto> userRoleList) { return userRoleService.updateUserRoleForOrg(userRoleList); } @SuppressWarnings("rawtypes") @ApiOperation(value = "查询用户信息", notes = "税务运营管理平台>增值税申报") @RequestMapping(value = "getUserByName", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody UserDto getUserByName( @RequestBody UserDto userParam) { return userRoleService.GetUserByUserName(userParam); } }