feat:用户、权限、角色接口
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.dept;
|
||||
|
||||
public class DeptAddRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.dept;
|
||||
|
||||
public class DeptQueryRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.dept;
|
||||
|
||||
public class DeptUpdateRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.dept;
|
||||
|
||||
public class DeptUserUpdateRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.role;
|
||||
|
||||
public class RoleAddRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.role;
|
||||
|
||||
public class RoleQueryRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.role;
|
||||
|
||||
public class RoleUpdateRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.role;
|
||||
|
||||
public class RoleUserUpdateRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.user;
|
||||
|
||||
public class UserAddRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.user;
|
||||
|
||||
public class UserDeptUpdateRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.user;
|
||||
|
||||
public class UserQueryRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.user;
|
||||
|
||||
public class UserRoleUpdateRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.req.user;
|
||||
|
||||
public class UserUpdateRequest {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.resp;
|
||||
|
||||
public class DeptDTO {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xiang.xservice.auth.api.dto.resp;
|
||||
|
||||
public class RoleDTO {
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.xiang.xservice.auth.server.controller;
|
||||
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptAddRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptUserUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.DeptDTO;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class DeptController {
|
||||
@PostMapping("/private/dept/list")
|
||||
public Result<DeptDTO> getDeptList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptQueryRequest request) {
|
||||
return Result.success(new DeptDTO());
|
||||
}
|
||||
|
||||
@GetMapping("/private/dept/info/{id}")
|
||||
public Result<DeptDTO> getDeptInfo(@PathVariable Long id) {
|
||||
return Result.success(new DeptDTO());
|
||||
}
|
||||
|
||||
@PostMapping("/private/dept/add")
|
||||
public Result<Void> addDept(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptAddRequest request) {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/private/dept/update")
|
||||
public Result<Void> updateDept(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptUpdateRequest request) {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/private/dept/del")
|
||||
public Result<Void> delDept(@RequestParam @Valid @NotEmpty(message = "请求参数不能为空") List<Long> ids) {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/private/dept/setUser")
|
||||
public Result<Boolean> setUserDept(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptUserUpdateRequest request) {
|
||||
return Result.success(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.xiang.xservice.auth.server.controller;
|
||||
|
||||
import com.xiang.xservice.auth.api.dto.req.role.RoleAddRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.role.RoleQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.role.RoleUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.role.RoleUserUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.RoleDTO;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class RoleController {
|
||||
|
||||
@PostMapping("/private/role/list")
|
||||
public Result<RoleDTO> getRoleList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleQueryRequest request) {
|
||||
return Result.success(new RoleDTO());
|
||||
}
|
||||
|
||||
@GetMapping("/private/role/info/{id}")
|
||||
public Result<RoleDTO> getRoleInfo(@PathVariable Long id) {
|
||||
return Result.success(new RoleDTO());
|
||||
}
|
||||
|
||||
@PostMapping("/private/role/add")
|
||||
public Result<Void> addRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleAddRequest request) {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/private/role/update")
|
||||
public Result<Void> updateRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleUpdateRequest request) {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/private/role/del")
|
||||
public Result<Void> delRole(@RequestParam @Valid @NotEmpty(message = "请求参数不能为空") List<Long> ids) {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/private/role/setUser")
|
||||
public Result<Boolean> setUserRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleUserUpdateRequest request) {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.xiang.xservice.auth.server.controller;
|
||||
|
||||
import com.xiang.xservice.auth.api.dto.req.LoginRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.RegisterRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.LoginResp;
|
||||
import com.xiang.xservice.auth.api.dto.resp.RegisterResp;
|
||||
import com.xiang.xservice.auth.service.service.XUserService;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import com.xiang.xservice.basic.exception.BusinessException;
|
||||
@@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -34,4 +37,21 @@ public class TokenController {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/public/user/userRegister")
|
||||
public Result<RegisterResp> register(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RegisterRequest request) {
|
||||
|
||||
try {
|
||||
RegisterResp registerResp = userService.userRegister(request);
|
||||
if (Objects.nonNull(registerResp)) {
|
||||
return Result.success("操作成功", registerResp);
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
log.error("【用户注册】用户注册失败:{}", e.getMessage(), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("【用户注册】用户注册失败:{}", e.getMessage(), e);
|
||||
}
|
||||
return Result.error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,104 @@
|
||||
package com.xiang.xservice.auth.server.controller;
|
||||
|
||||
import com.xiang.xservice.auth.api.dto.req.RegisterRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.RegisterResp;
|
||||
import com.xiang.xservice.auth.service.service.XUserService;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserAddRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserDeptUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserQueryRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserRoleUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.req.user.UserUpdateRequest;
|
||||
import com.xiang.xservice.auth.api.dto.resp.UserResp;
|
||||
import com.xiang.xservice.auth.service.entity.XUser;
|
||||
import com.xiang.xservice.auth.service.enums.UserStatusEnum;
|
||||
import com.xiang.xservice.auth.service.repository.mapper.XUserMapper;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import com.xiang.xservice.basic.exception.BusinessException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Objects;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class UserController {
|
||||
|
||||
private final XUserService userService;
|
||||
private final XUserMapper userMapper;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
@PostMapping("/public/user/userRegister")
|
||||
public Result<RegisterResp> register(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RegisterRequest request) {
|
||||
|
||||
try {
|
||||
RegisterResp registerResp = userService.userRegister(request);
|
||||
if (Objects.nonNull(registerResp)) {
|
||||
return Result.success("操作成功", registerResp);
|
||||
@PostMapping("/private/user/list")
|
||||
public Result<UserResp> getUserList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserQueryRequest request) {
|
||||
return Result.success(new UserResp());
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
log.error("【用户注册】用户注册失败:{}", e.getMessage(), e);
|
||||
return Result.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("【用户注册】用户注册失败:{}", e.getMessage(), e);
|
||||
|
||||
@GetMapping("/private/user/info/{id}")
|
||||
public Result<UserResp> getUserById(@PathVariable("id") Long id) {
|
||||
return Result.success(new UserResp());
|
||||
}
|
||||
return Result.error("操作失败");
|
||||
|
||||
@PostMapping("/private/user/add")
|
||||
public Result<Boolean> addUser(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserAddRequest request) {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/private/user/update")
|
||||
public Result<Boolean> updateUser(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserUpdateRequest request) {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/private/user/del")
|
||||
public Result<Boolean> delUser(@RequestParam @Valid @NotEmpty(message = "请求参数不能为空") List<Long> ids) {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/private/user/setDept")
|
||||
public Result<Boolean> setUserDept(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserDeptUpdateRequest request) {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/private/user/setRole")
|
||||
public Result<Boolean> setUserRole(@RequestBody @Valid @NotNull(message = "请求参数不能为空") UserRoleUpdateRequest request) {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/public/user/useraddBatch")
|
||||
public Result<Void> add() {
|
||||
List<CompletableFuture> futures = Lists.newArrayList();
|
||||
List<XUser> list = Lists.newCopyOnWriteArrayList();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
int finalI = i;
|
||||
log.info("第{}批数据生成!", finalI);
|
||||
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
|
||||
for (int j = 0; j < 1000; j++) {
|
||||
log.info("第{}批的第{}条数据生成!", finalI, j);
|
||||
XUser user = new XUser();
|
||||
user.setName("nameTest2" + finalI + j);
|
||||
user.setUsername("usernameTest2" + finalI + j);
|
||||
user.setPassword(passwordEncoder.encode("123456"));
|
||||
user.setEmail("emailTest2" + finalI + j + "@test.com");
|
||||
user.setPhone("13800000000");
|
||||
user.setStatus(UserStatusEnum.USING.getCode());
|
||||
list.add(user);
|
||||
}
|
||||
});
|
||||
futures.add(future);
|
||||
}
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
||||
List<List<XUser>> partition = Lists.partition(list, 3000);
|
||||
CompletableFuture.runAsync(() -> {
|
||||
partition.stream().parallel().forEach(userMapper::insertBatch);
|
||||
});
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ public class AuthorizationServerConfig {
|
||||
.csrf().disable() // 禁用 CSRF
|
||||
.authorizeRequests(authorizeRequests -> authorizeRequests
|
||||
.antMatchers("/public/**").permitAll()
|
||||
.antMatchers("/open/**").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.xiang.xservice.auth.service.entity.XUser;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@Mapper
|
||||
public interface XUserMapper {
|
||||
@@ -16,4 +18,6 @@ public interface XUserMapper {
|
||||
* @return
|
||||
*/
|
||||
int insert(XUser user);
|
||||
|
||||
int insertBatch(List<XUser> list);
|
||||
}
|
||||
|
||||
@@ -130,6 +130,12 @@
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<insert id="insertBatch">
|
||||
insert into x_user(name, username, password, email, phone, status) VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.name}, #{item.username}, #{item.password}, #{item.email}, #{item.phone}, #{item.status})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="delete" >
|
||||
update x_user set del_flag = 1 where id = #{id}
|
||||
|
||||
Reference in New Issue
Block a user