55import com .ligg .apiadmin .service .UserManagementService ;
66import com .ligg .common .constants .Constant ;
77import com .ligg .common .enums .BusinessStates ;
8+ import com .ligg .common .module .entity .UserEntity ;
89import com .ligg .common .module .vo .PageVo ;
910import com .ligg .common .service .FileService ;
11+ import com .ligg .common .service .UserService ;
12+ import com .ligg .common .utils .BCryptUtil ;
1013import com .ligg .common .utils .Response ;
1114import io .swagger .v3 .oas .annotations .Operation ;
1215import io .swagger .v3 .oas .annotations .tags .Tag ;
1316import jakarta .validation .constraints .NotNull ;
1417import lombok .RequiredArgsConstructor ;
18+ import org .springframework .beans .BeanUtils ;
1519import org .springframework .validation .annotation .Validated ;
1620import org .springframework .web .bind .annotation .*;
1721import org .springframework .web .multipart .MultipartFile ;
1822
23+ import java .time .LocalDateTime ;
24+
1925/**
2026 * @Author Ligg
2127 * @Time 2025/10/28
@@ -29,6 +35,8 @@ public class UserManagementController {
2935
3036 private final FileService fileService ;
3137
38+ private final UserService userService ;
39+
3240 private final UserManagementService userManagementService ;
3341
3442 /**
@@ -39,17 +47,41 @@ public class UserManagementController {
3947 public Response <PageVo <UserManagementVo >> Userlist (@ NotNull Long pageNumber ,
4048 @ NotNull Long pageSize ,
4149 @ RequestParam (required = false ) String search ) {
42- PageVo <UserManagementVo > userListPage = userManagementService .getUserListPage (pageNumber , pageSize ,search );
50+ PageVo <UserManagementVo > userListPage = userManagementService .getUserListPage (pageNumber , pageSize , search );
4351 return Response .success (BusinessStates .SUCCESS , userListPage );
4452 }
4553
54+ @ Operation (summary = "添加用户信息" )
55+ @ PostMapping
56+ public Response <String > addUserInfo (@ Validated UserInfoDto userInfo ,
57+ MultipartFile avatarFile ) {
58+ if (userService .lambdaQuery ().eq (UserEntity ::getEmail , userInfo .getEmail ()).exists ()) {
59+ return Response .error (BusinessStates .METHOD_NOT_ALLOWED , "该邮箱已经被使用,请更换邮箱" );
60+ }
61+ UserEntity userEntity = new UserEntity ();
62+ BeanUtils .copyProperties (userInfo , userEntity );
63+ if (avatarFile != null && !avatarFile .isEmpty ()) {
64+ if (avatarFile .getSize () > Constant .FILE_SIZE ) {
65+ return Response .error (BusinessStates .VALIDATION_FAILED , "文件大小不可大于2mb" );
66+ }
67+ String avatarPath = fileService .uploadImage (avatarFile , Constant .AVATAR_FILE_PATH );
68+ userEntity .setAvatar (avatarPath );
69+ }
70+ userEntity .setPassword (BCryptUtil .encrypt (userEntity .getPassword ()));
71+ userEntity .setCreateTime (LocalDateTime .now ());
72+ userEntity .setUpdateTime (LocalDateTime .now ());
73+ userManagementService .addUserInfo (userEntity );
74+ return Response .success (BusinessStates .SUCCESS );
75+ }
76+
77+
4678 @ PutMapping
4779 @ Operation (summary = "更新用户信息" )
4880 public Response <String > updateUserInfo (@ Validated UserInfoDto userInfo ,
4981 MultipartFile avatarFile ) {
5082 if (avatarFile != null && !avatarFile .isEmpty ()) {
5183 if (avatarFile .getSize () > Constant .FILE_SIZE ) {
52- return Response .error (BusinessStates .VALIDATION_FAILED ,"文件大小不可大于2mb" );
84+ return Response .error (BusinessStates .VALIDATION_FAILED , "文件大小不可大于2mb" );
5385 }
5486 String avatarPath = fileService .uploadImage (avatarFile , Constant .AVATAR_FILE_PATH );
5587 userInfo .setAvatar (avatarPath );
0 commit comments