feat: 用户管理模块开发
This commit is contained in:
@@ -27,11 +27,6 @@
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>2.4.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.landaiqing</groupId>
|
||||
<artifactId>jc-club-auth-infra</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.landaiqing</groupId>
|
||||
<artifactId>jc-club-auth-domain</artifactId>
|
||||
|
@@ -0,0 +1,36 @@
|
||||
package com.landaiqing.auth.application.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Classname GlobalConfig
|
||||
* @BelongsProject: jc-club
|
||||
* @BelongsPackage: com.landaiqing.subject.application.config
|
||||
* @Author: landaiqing
|
||||
* @CreateTime: 2024-02-16 15:57
|
||||
* @Description: MVC全局处理
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class GlobalConfig extends WebMvcConfigurationSupport {
|
||||
@Override
|
||||
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
super.configureMessageConverters(converters);
|
||||
converters.add(mappingJackson2HttpMessageConverter());
|
||||
}
|
||||
private MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(){
|
||||
ObjectMapper objectMapper=new ObjectMapper();
|
||||
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false);
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
MappingJackson2HttpMessageConverter converter=new MappingJackson2HttpMessageConverter(objectMapper);
|
||||
return converter;
|
||||
}
|
||||
}
|
@@ -1,42 +1,59 @@
|
||||
package com.landaiqing.auth.application.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.landaiqing.auth.application.convert.AuthUserDTOConverter;
|
||||
import com.landaiqing.auth.application.dto.AuthUserDTO;
|
||||
import com.landaiqing.auth.common.entity.Result;
|
||||
import com.landaiqing.auth.domain.entity.AuthUserBO;
|
||||
import com.landaiqing.auth.domain.service.AuthUserDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @Classname UserController
|
||||
* @BelongsProject: jc-club
|
||||
* @BelongsPackage: com.landaiqing.auth.application.controller
|
||||
* @Author: landaiqing
|
||||
* @CreateTime: 2024-02-18 14:24
|
||||
* @CreateTime: 2024-02-19 13:46
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user/")
|
||||
@Slf4j
|
||||
public class UserController {
|
||||
|
||||
// 测试登录,浏览器访问: http://localhost:3001/user/doLogin?username=zhang&password=123456
|
||||
@RequestMapping("doLogin")
|
||||
public SaResult doLogin(String username, String password) {
|
||||
// 此处仅作模拟示例,真实项目需要从数据库中查询数据进行比对
|
||||
if("zhang".equals(username) && "123456".equals(password)) {
|
||||
StpUtil.login(10001);
|
||||
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
|
||||
// 第3步,返回给前端
|
||||
return SaResult.data(tokenInfo);
|
||||
@Resource
|
||||
private AuthUserDomainService authUserDomainService;
|
||||
/**
|
||||
* @description: 用户注册
|
||||
* @param: []
|
||||
* @return: com.landaiqing.auth.common.entity.Result<java.lang.Boolean>
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/19 13:57
|
||||
*/
|
||||
@PostMapping("register")
|
||||
public Result<Boolean> register(@RequestBody AuthUserDTO authUserDTO){
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("UserController.register.dto:{}", JSON.toJSONString(authUserDTO));
|
||||
}
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(authUserDTO.getUserName()),"用户名不能为空");
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(authUserDTO.getEmail()),"邮箱不能为空");
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(authUserDTO.getPassword()),"密码不能为空");
|
||||
|
||||
AuthUserBO authUserBO = AuthUserDTOConverter.INSTANCE.convertDTOToBO(authUserDTO);
|
||||
return Result.ok(authUserDomainService.register(authUserBO));
|
||||
} catch (Exception e) {
|
||||
log.error("UserController.register.error:{}", e.getMessage(), e);
|
||||
return Result.fail("注册用户失败");
|
||||
}
|
||||
return SaResult.error("登录失败");
|
||||
}
|
||||
|
||||
// 查询登录状态,浏览器访问: http://localhost:3001/user/isLogin
|
||||
@RequestMapping("isLogin")
|
||||
public String isLogin() {
|
||||
return "当前会话是否登录:" + StpUtil.isLogin();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,23 @@
|
||||
package com.landaiqing.auth.application.convert;
|
||||
|
||||
import com.landaiqing.auth.application.dto.AuthUserDTO;
|
||||
import com.landaiqing.auth.domain.entity.AuthUserBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 用户dto转换器
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2023/10/8
|
||||
*/
|
||||
@Mapper
|
||||
public interface AuthUserDTOConverter {
|
||||
|
||||
AuthUserDTOConverter INSTANCE = Mappers.getMapper(AuthUserDTOConverter.class);
|
||||
|
||||
AuthUserBO convertDTOToBO(AuthUserDTO authUserDTO);
|
||||
|
||||
AuthUserDTO convertBOToDTO(AuthUserBO authUserBO);
|
||||
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package com.landaiqing.auth.application.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 权限dto
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2023/11/3
|
||||
*/
|
||||
@Data
|
||||
public class AuthPermissionDTO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Long parentId;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private String menuUrl;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Integer show;
|
||||
|
||||
private String icon;
|
||||
|
||||
private String permissionKey;
|
||||
}
|
||||
|
@@ -0,0 +1,23 @@
|
||||
package com.landaiqing.auth.application.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 角色dto
|
||||
*
|
||||
* @author: landaiqing
|
||||
* @date: 2023/11/2
|
||||
*/
|
||||
@Data
|
||||
public class AuthRoleDTO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String roleName;
|
||||
|
||||
private String roleKey;
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,26 @@
|
||||
package com.landaiqing.auth.application.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (AuthRolePermission)实体类
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2023-11-04 22:16:00
|
||||
*/
|
||||
@Data
|
||||
public class AuthRolePermissionDTO implements Serializable {
|
||||
private static final long serialVersionUID = 459343371709166261L;
|
||||
|
||||
private Long id;
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private Long permissionId;
|
||||
|
||||
private List<Long> permissionIdList;
|
||||
}
|
||||
|
@@ -0,0 +1,39 @@
|
||||
package com.landaiqing.auth.application.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* (AuthUser)DTO
|
||||
*/
|
||||
@Data
|
||||
public class AuthUserDTO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String email;
|
||||
|
||||
private String phone;
|
||||
|
||||
private String password;
|
||||
|
||||
private Integer sex;
|
||||
|
||||
private String avatar;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private String introduce;
|
||||
|
||||
private String extJson;
|
||||
|
||||
private Integer isDeleted;
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user