19 changed files with 259 additions and 287 deletions
-
8sql/demo.sql
-
2src/main/java/com/qyft/gd/system/common/base/BaseEntity.java
-
24src/main/java/com/qyft/gd/system/common/enums/DeletedEnum.java
-
42src/main/java/com/qyft/gd/system/config/CorsConfig.java
-
16src/main/java/com/qyft/gd/system/config/MybatisPlusConfig.java
-
53src/main/java/com/qyft/gd/system/config/SwaggerConfig.java
-
61src/main/java/com/qyft/gd/system/controller/UserController.java
-
36src/main/java/com/qyft/gd/system/core/MyMetaObjectHandler.java
-
52src/main/java/com/qyft/gd/system/model/bo/UserBO.java
-
43src/main/java/com/qyft/gd/system/model/dto/UserAuthInfo.java
-
27src/main/java/com/qyft/gd/system/model/entity/User.java
-
19src/main/java/com/qyft/gd/system/model/form/RoleForm.java
-
34src/main/java/com/qyft/gd/system/model/form/UserForm.java
-
27src/main/java/com/qyft/gd/system/model/query/UserPageQuery.java
-
33src/main/java/com/qyft/gd/system/model/vo/UserInfoVO.java
-
38src/main/java/com/qyft/gd/system/model/vo/UserPageVO.java
-
9src/main/java/com/qyft/gd/system/service/UserService.java
-
20src/main/java/com/qyft/gd/system/service/impl/UserServiceImpl.java
-
2src/main/resources/application.yml
@ -0,0 +1,24 @@ |
|||
package com.qyft.gd.system.common.enums; |
|||
|
|||
import com.qyft.gd.system.common.base.IBaseEnum; |
|||
import lombok.Getter; |
|||
|
|||
/** |
|||
* 删除状态枚举 |
|||
*/ |
|||
@Getter |
|||
public enum DeletedEnum implements IBaseEnum<Integer> { |
|||
|
|||
ENABLE(1, "删除"), |
|||
DISABLE(0, "未删除"); |
|||
|
|||
private final Integer value; |
|||
|
|||
|
|||
private final String label; |
|||
|
|||
DeletedEnum(Integer value, String label) { |
|||
this.value = value; |
|||
this.label = label; |
|||
} |
|||
} |
@ -0,0 +1,42 @@ |
|||
package com.qyft.gd.system.config; |
|||
|
|||
import org.springframework.boot.web.servlet.FilterRegistrationBean; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.web.cors.CorsConfiguration; |
|||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
|||
import org.springframework.web.filter.CorsFilter; |
|||
|
|||
import java.util.Collections; |
|||
|
|||
/** |
|||
* CORS 资源共享配置 |
|||
* |
|||
* @author haoxr |
|||
* @since 2023/4/17 |
|||
*/ |
|||
@Configuration |
|||
public class CorsConfig { |
|||
|
|||
@Bean |
|||
public FilterRegistrationBean filterRegistrationBean() { |
|||
CorsConfiguration corsConfiguration = new CorsConfiguration(); |
|||
//1.允许任何来源 |
|||
corsConfiguration.setAllowedOriginPatterns(Collections.singletonList("*")); |
|||
//2.允许任何请求头 |
|||
corsConfiguration.addAllowedHeader(CorsConfiguration.ALL); |
|||
//3.允许任何方法 |
|||
corsConfiguration.addAllowedMethod(CorsConfiguration.ALL); |
|||
//4.允许凭证 |
|||
corsConfiguration.setAllowCredentials(true); |
|||
|
|||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
|||
source.registerCorsConfiguration("/**", corsConfiguration); |
|||
CorsFilter corsFilter = new CorsFilter(source); |
|||
|
|||
FilterRegistrationBean<CorsFilter> filterRegistrationBean=new FilterRegistrationBean<>(corsFilter); |
|||
filterRegistrationBean.setOrder(-101); |
|||
|
|||
return filterRegistrationBean; |
|||
} |
|||
} |
@ -0,0 +1,61 @@ |
|||
package com.qyft.gd.system.controller; |
|||
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.qyft.gd.system.common.base.BasePageQuery; |
|||
import com.qyft.gd.system.common.result.PageResult; |
|||
import com.qyft.gd.system.common.result.Result; |
|||
import com.qyft.gd.system.model.entity.User; |
|||
import com.qyft.gd.system.service.UserService; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
@Tag(name = "用户接口") |
|||
@RestController |
|||
@RequestMapping("/api/user") |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class UserController { |
|||
private final UserService userService; |
|||
|
|||
@Operation(summary = "用户列表") |
|||
@GetMapping("/list") |
|||
public PageResult<User> getAllUsers(BasePageQuery pageQuery) { |
|||
IPage<User> result = userService.page(new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()), null); |
|||
return PageResult.success(result); |
|||
} |
|||
|
|||
@Operation(summary = "添加新用户") |
|||
@PostMapping("/") |
|||
public Result<String> addUser(@RequestBody User user) { |
|||
boolean isSuccess = userService.addUser(user); |
|||
if (isSuccess) { |
|||
return Result.success(); |
|||
} |
|||
return Result.failed(); |
|||
} |
|||
|
|||
@Operation(summary = "更新用户信息") |
|||
@PutMapping("/{id}") |
|||
public Result<String> updateUser(@PathVariable Long id, @RequestBody User user) { |
|||
user.setId(id); |
|||
boolean isSuccess = userService.updateUser(user); |
|||
if (isSuccess) { |
|||
return Result.success(); |
|||
} |
|||
return Result.failed(); |
|||
} |
|||
|
|||
@Operation(summary = "删除用户") |
|||
@DeleteMapping("/{id}") |
|||
public Result<String> deleteUser(@PathVariable Long id) { |
|||
boolean isSuccess = userService.deleteUser(id); |
|||
if (isSuccess) { |
|||
return Result.success(); |
|||
} |
|||
return Result.failed(); |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
package com.qyft.gd.system.core; |
|||
|
|||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
|||
import org.apache.ibatis.reflection.MetaObject; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.time.LocalDateTime; |
|||
|
|||
/** |
|||
* mybatis-plus 字段自动填充 |
|||
*/ |
|||
@Component |
|||
public class MyMetaObjectHandler implements MetaObjectHandler { |
|||
|
|||
/** |
|||
* 新增填充创建时间 |
|||
* |
|||
* @param metaObject 元数据 |
|||
*/ |
|||
@Override |
|||
public void insertFill(MetaObject metaObject) { |
|||
this.strictInsertFill(metaObject, "createTime", LocalDateTime::now, LocalDateTime.class); |
|||
this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class); |
|||
} |
|||
|
|||
/** |
|||
* 更新填充更新时间 |
|||
* |
|||
* @param metaObject 元数据 |
|||
*/ |
|||
@Override |
|||
public void updateFill(MetaObject metaObject) { |
|||
this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class); |
|||
} |
|||
|
|||
} |
@ -1,52 +0,0 @@ |
|||
package com.qyft.gd.system.model.bo; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.time.LocalDateTime; |
|||
|
|||
/** |
|||
* 用户持久化对象 |
|||
*/ |
|||
@Data |
|||
public class UserBO { |
|||
|
|||
/** |
|||
* 用户ID |
|||
*/ |
|||
private Long id; |
|||
|
|||
/** |
|||
* 账户名 |
|||
*/ |
|||
private String username; |
|||
|
|||
/** |
|||
* 昵称 |
|||
*/ |
|||
private String nickname; |
|||
|
|||
/** |
|||
* 性别(1->男;2->女) |
|||
*/ |
|||
private Integer gender; |
|||
|
|||
/** |
|||
* 头像URL |
|||
*/ |
|||
private String avatar; |
|||
|
|||
/** |
|||
* 状态: 1->启用;0->禁用 |
|||
*/ |
|||
private Integer status; |
|||
|
|||
/** |
|||
* 角色名称,多个使用英文逗号(,)分割 |
|||
*/ |
|||
private String roleNames; |
|||
|
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
private LocalDateTime createTime; |
|||
} |
@ -1,43 +0,0 @@ |
|||
package com.qyft.gd.system.model.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.Set; |
|||
|
|||
/** |
|||
* 用户认证信息 |
|||
*/ |
|||
@Data |
|||
public class UserAuthInfo { |
|||
|
|||
/** |
|||
* 用户ID |
|||
*/ |
|||
private Long userId; |
|||
|
|||
/** |
|||
* 用户名 |
|||
*/ |
|||
private String username; |
|||
|
|||
/** |
|||
* 昵称 |
|||
*/ |
|||
private String nickname; |
|||
|
|||
/** |
|||
* 用户密码 |
|||
*/ |
|||
private String password; |
|||
|
|||
/** |
|||
* 状态(1:启用;0:禁用) |
|||
*/ |
|||
private Integer status; |
|||
|
|||
/** |
|||
* 用户所属的角色集合 |
|||
*/ |
|||
private Set<String> roles; |
|||
|
|||
} |
@ -1,19 +0,0 @@ |
|||
package com.qyft.gd.system.model.form; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
@Schema(description = "角色表单对象") |
|||
@Data |
|||
public class RoleForm { |
|||
|
|||
@Schema(description = "角色ID") |
|||
private Long id; |
|||
|
|||
@Schema(description = "角色名称") |
|||
private String name; |
|||
|
|||
@Schema(description = "角色编码") |
|||
private String code; |
|||
|
|||
} |
@ -1,34 +0,0 @@ |
|||
package com.qyft.gd.system.model.form; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 用户表单对象 |
|||
*/ |
|||
@Schema(description = "用户表单对象") |
|||
@Data |
|||
public class UserForm { |
|||
|
|||
@Schema(description = "用户ID") |
|||
private Long id; |
|||
|
|||
@Schema(description = "用户名") |
|||
private String username; |
|||
|
|||
@Schema(description = "昵称") |
|||
private String nickname; |
|||
|
|||
@Schema(description = "性别") |
|||
private Integer gender; |
|||
|
|||
@Schema(description = "用户头像") |
|||
private String avatar; |
|||
|
|||
@Schema(description = "用户状态(1:正常;0:禁用)") |
|||
private Integer status; |
|||
|
|||
@Schema(description = "角色ID") |
|||
private Long roleIds; |
|||
|
|||
} |
@ -1,27 +0,0 @@ |
|||
package com.qyft.gd.system.model.query; |
|||
|
|||
import com.qyft.gd.system.common.base.BasePageQuery; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 用户分页查询对象 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = false) |
|||
@Schema(description = "用户分页查询对象") |
|||
public class UserPageQuery extends BasePageQuery { |
|||
|
|||
@Schema(description = "关键字(用户名/昵称/手机号)") |
|||
private String keywords; |
|||
|
|||
@Schema(description = "用户状态") |
|||
private Integer status; |
|||
|
|||
@Schema(description = "角色ID") |
|||
private List<Long> roleIds; |
|||
|
|||
} |
@ -1,33 +0,0 @@ |
|||
package com.qyft.gd.system.model.vo; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.util.Set; |
|||
|
|||
/** |
|||
* 用户登录视图对象 |
|||
*/ |
|||
@Schema(description ="当前登录用户视图对象") |
|||
@Data |
|||
public class UserInfoVO { |
|||
|
|||
@Schema(description="用户ID") |
|||
private Long userId; |
|||
|
|||
@Schema(description="用户名") |
|||
private String username; |
|||
|
|||
@Schema(description="用户昵称") |
|||
private String nickname; |
|||
|
|||
@Schema(description="头像地址") |
|||
private String avatar; |
|||
|
|||
@Schema(description="用户角色编码集合") |
|||
private Set<String> roles; |
|||
|
|||
@Schema(description="用户权限标识集合") |
|||
private Set<String> perms; |
|||
|
|||
} |
@ -1,38 +0,0 @@ |
|||
package com.qyft.gd.system.model.vo; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.time.LocalDateTime; |
|||
|
|||
/** |
|||
* 用户分页视图对象 |
|||
*/ |
|||
@Schema(description = "用户分页对象") |
|||
@Data |
|||
public class UserPageVO { |
|||
|
|||
@Schema(description = "用户ID") |
|||
private Long id; |
|||
|
|||
@Schema(description = "用户名") |
|||
private String username; |
|||
|
|||
@Schema(description = "用户昵称") |
|||
private String nickname; |
|||
|
|||
@Schema(description = "性别") |
|||
private Integer gender; |
|||
|
|||
@Schema(description = "用户状态(1:启用;0:禁用)") |
|||
private Integer status; |
|||
|
|||
@Schema(description = "角色名称,多个使用英文逗号(,)分割") |
|||
private String roleNames; |
|||
|
|||
@Schema(description = "创建时间") |
|||
@JsonFormat(pattern = "yyyy/MM/dd HH:mm") |
|||
private LocalDateTime createTime; |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue