From d8b7123d8bd91f8d01fa46e7d6138357ad88c70a Mon Sep 17 00:00:00 2001 From: lijiahang Date: Fri, 14 Jul 2023 10:34:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BB=A3=E7=A0=81.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/entity/dto/SystemUserDTO.java | 64 ++++++++ .../orion-ops-module-infra-service/pom.xml | 6 - .../controller/SystemUserController.http | 74 +++++++++ .../controller/SystemUserController.java | 94 ++++++++++++ .../infra/convert/SystemUserConvert.java | 35 +++++ .../convert/SystemUserProviderConvert.java | 33 +++++ .../ops/module/infra/dao/SystemUserDAO.java | 17 +++ .../infra/define/InfraCacheKeyDefine.java | 22 +++ .../infra/entity/domain/SystemUserDO.java | 64 ++++++++ .../request/SystemUserCreateRequest.java | 61 ++++++++ .../request/SystemUserQueryRequest.java | 51 +++++++ .../request/SystemUserUpdateRequest.java | 65 ++++++++ .../entity/request/UserLoginRequest.java | 26 ++++ .../module/infra/entity/vo/SystemUserVO.java | 64 ++++++++ .../infra/service/AuthenticationService.java | 29 ++++ .../infra/service/SystemUserService.java | 76 ++++++++++ .../impl/AuthenticationServiceImpl.java | 67 +++++++++ .../service/impl/SystemUserServiceImpl.java | 140 ++++++++++++++++++ .../resources/mapper/SystemUserMapper.xml | 28 ++++ 19 files changed, 1010 insertions(+), 6 deletions(-) create mode 100644 orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/entity/dto/SystemUserDTO.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemUserController.http create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemUserController.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemUserConvert.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemUserProviderConvert.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/dao/SystemUserDAO.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/InfraCacheKeyDefine.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/SystemUserDO.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/SystemUserCreateRequest.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/SystemUserQueryRequest.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/SystemUserUpdateRequest.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/UserLoginRequest.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/SystemUserVO.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/AuthenticationService.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/SystemUserService.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/AuthenticationServiceImpl.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemUserServiceImpl.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/SystemUserMapper.xml diff --git a/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/entity/dto/SystemUserDTO.java b/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/entity/dto/SystemUserDTO.java new file mode 100644 index 00000000..f341f340 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/entity/dto/SystemUserDTO.java @@ -0,0 +1,64 @@ +package com.orion.ops.module.infra.entity.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import java.io.Serializable; +import lombok.*; + +import java.util.*; + +/** + * 用户 业务对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-7-13 18:42 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "SystemUserDTO", description = "用户 业务对象") +public class SystemUserDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + private Long id; + + @Schema(description = "用户名") + private String username; + + @Schema(description = "密码") + private String password; + + @Schema(description = "花名") + private String nickname; + + @Schema(description = "头像地址") + private String avatar; + + @Schema(description = "手机号") + private String mobile; + + @Schema(description = "邮箱") + private String email; + + @Schema(description = "用户状态 0正常 1停用 2锁定") + private Byte status; + + @Schema(description = "最后登录时间") + private Date lastLoginTime; + + @Schema(description = "创建时间") + private Date createTime; + + @Schema(description = "修改时间") + private Date updateTime; + + @Schema(description = "创建人") + private String creator; + + @Schema(description = "修改人") + private String updater; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/pom.xml b/orion-ops-module-infra/orion-ops-module-infra-service/pom.xml index ad28d2b7..c1e4c613 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/pom.xml +++ b/orion-ops-module-infra/orion-ops-module-infra-service/pom.xml @@ -34,12 +34,6 @@ orion-ops-spring-boot-starter-security - - - com.orion.ops - orion-ops-spring-boot-starter-swagger - - com.orion.ops diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemUserController.http b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemUserController.http new file mode 100644 index 00000000..b914d616 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemUserController.http @@ -0,0 +1,74 @@ +### 创建用户 +POST {{baseUrl}}/infra/system-user/create +Content-Type: application/json +Authorization: {{token}} + +{ + "username": "", + "password": "", + "nickname": "", + "avatar": "", + "mobile": "", + "email": "", + "status": "", + "lastLoginTime": "" +} + + +### 通过 id 更新用户 +PUT {{baseUrl}}/infra/system-user/update +Content-Type: application/json +Authorization: {{token}} + +{ + "id": "", + "username": "", + "password": "", + "nickname": "", + "avatar": "", + "mobile": "", + "email": "", + "status": "", + "lastLoginTime": "" +} + + +### 通过 id 查询用户 +GET {{baseUrl}}/infra/system-user/get?id=1 +Authorization: {{token}} + + +### 通过 id 批量查询用户 +GET {{baseUrl}}/infra/system-user/list?idList=1,2,3 +Authorization: {{token}} + + +### 分页查询用户 +POST {{baseUrl}}/infra/system-user/query +Content-Type: application/json +Authorization: {{token}} + +{ + "id": "", + "username": "", + "password": "", + "nickname": "", + "avatar": "", + "mobile": "", + "email": "", + "status": "", + "lastLoginTime": "" +} + + +### 通过 id 删除用户 +DELETE {{baseUrl}}/infra/system-user/delete?id=1 +Authorization: {{token}} + + +### 通过 id 批量删除用户 +DELETE {{baseUrl}}/infra/system-user/delete-batch?idList=1,2,3 +Authorization: {{token}} + + + diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemUserController.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemUserController.java new file mode 100644 index 00000000..aae1a989 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemUserController.java @@ -0,0 +1,94 @@ +package com.orion.ops.module.infra.controller; + +import com.orion.lang.define.wrapper.DataGrid; +import com.orion.ops.framework.common.annotation.RestWrapper; +import com.orion.ops.module.infra.entity.request.SystemUserCreateRequest; +import com.orion.ops.module.infra.entity.request.SystemUserQueryRequest; +import com.orion.ops.module.infra.entity.request.SystemUserUpdateRequest; +import com.orion.ops.module.infra.entity.vo.SystemUserVO; +import com.orion.ops.module.infra.service.SystemUserService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 用户 api + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-7-13 18:42 + */ +@Tag(name = "infra - 用户服务") +@Slf4j +@Validated +@RestWrapper +@RestController +@RequestMapping("/infra/system-user") +@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"}) +public class SystemUserController { + + @Resource + private SystemUserService systemUserService; + + @PostMapping("/create") + @Operation(summary = "创建用户") + @PreAuthorize("@ss.hasPermission('infra:system-user:create')") + public Long createSystemUser(@Validated @RequestBody SystemUserCreateRequest request) { + return systemUserService.createSystemUser(request); + } + + @PutMapping("/update") + @Operation(summary = "通过 id 更新用户") + @PreAuthorize("@ss.hasPermission('infra:system-user:update')") + public Integer updateSystemUser(@Validated @RequestBody SystemUserUpdateRequest request) { + return systemUserService.updateSystemUser(request); + } + + @GetMapping("/get") + @Operation(summary = "通过 id 查询用户") + @Parameter(name = "id", description = "id", required = true) + @PreAuthorize("@ss.hasPermission('infra:system-user:query')") + public SystemUserVO getSystemUser(@RequestParam("id") Long id) { + return systemUserService.getSystemUser(id); + } + + @GetMapping("/list") + @Operation(summary = "通过 id 批量查询用户") + @Parameter(name = "idList", description = "idList", required = true) + @PreAuthorize("@ss.hasPermission('infra:system-user:query')") + public List getSystemUserList(@RequestParam("idList") List idList) { + return systemUserService.getSystemUserList(idList); + } + + @PostMapping("/query") + @Operation(summary = "分页查询用户") + @PreAuthorize("@ss.hasPermission('infra:system-user:query')") + public DataGrid getSystemUserPage(@Validated @RequestBody SystemUserQueryRequest request) { + return systemUserService.getSystemUserPage(request); + } + + @PutMapping("/delete") + @Operation(summary = "通过 id 删除用户") + @Parameter(name = "id", description = "id", required = true) + @PreAuthorize("@ss.hasPermission('infra:system-user:delete')") + public Integer deleteSystemUser(@RequestParam("id") Long id) { + return systemUserService.deleteSystemUser(id); + } + + @PutMapping("/delete-batch") + @Operation(summary = "通过 id 批量删除用户") + @Parameter(name = "idList", description = "idList", required = true) + @PreAuthorize("@ss.hasPermission('infra:system-user:delete')") + public Integer batchDeleteSystemUser(@RequestParam("idList") List idList) { + return systemUserService.batchDeleteSystemUser(idList); + } + +} + diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemUserConvert.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemUserConvert.java new file mode 100644 index 00000000..0d9664f7 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemUserConvert.java @@ -0,0 +1,35 @@ +package com.orion.ops.module.infra.convert; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import com.orion.ops.module.infra.entity.domain.*; +import com.orion.ops.module.infra.entity.vo.*; +import com.orion.ops.module.infra.entity.dto.*; +import com.orion.ops.module.infra.entity.request.*; +import com.orion.ops.module.infra.convert.*; +import java.util.List; + +/** + * 用户 内部对象转换器 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-7-13 18:42 + */ +@Mapper +@SuppressWarnings("ALL") +public interface SystemUserConvert { + + SystemUserConvert MAPPER = Mappers.getMapper(SystemUserConvert.class); + + SystemUserDO to(SystemUserCreateRequest request); + + SystemUserDO to(SystemUserUpdateRequest request); + + SystemUserDO to(SystemUserQueryRequest request); + + SystemUserVO to(SystemUserDO request); + + List to(List list); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemUserProviderConvert.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemUserProviderConvert.java new file mode 100644 index 00000000..da8c72f4 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemUserProviderConvert.java @@ -0,0 +1,33 @@ +package com.orion.ops.module.infra.convert; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import com.orion.ops.module.infra.entity.domain.*; +import com.orion.ops.module.infra.entity.vo.*; +import com.orion.ops.module.infra.entity.dto.*; +import com.orion.ops.module.infra.entity.request.*; +import com.orion.ops.module.infra.convert.*; +import java.util.List; + +/** + * 用户 暴露服务转换器 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-7-13 18:42 + */ +@Mapper +@SuppressWarnings("ALL") +public interface SystemUserProviderConvert { + + SystemUserProviderConvert MAPPER = Mappers.getMapper(SystemUserProviderConvert.class); + + SystemUserDO to(SystemUserDTO dto); + + SystemUserDTO to(SystemUserDO dto); + + List toDO(List list); + + List toDTO(List list); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/dao/SystemUserDAO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/dao/SystemUserDAO.java new file mode 100644 index 00000000..72f66d60 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/dao/SystemUserDAO.java @@ -0,0 +1,17 @@ +package com.orion.ops.module.infra.dao; + +import com.orion.ops.module.infra.entity.domain.SystemUserDO; +import com.orion.ops.framework.mybatis.core.mapper.IMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + * 用户 Mapper 接口 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-7-13 18:42 + */ +@Mapper +public interface SystemUserDAO extends IMapper { + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/InfraCacheKeyDefine.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/InfraCacheKeyDefine.java new file mode 100644 index 00000000..c061f1ed --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/InfraCacheKeyDefine.java @@ -0,0 +1,22 @@ +package com.orion.ops.module.infra.define; + +import com.orion.lang.define.cache.CacheKeyDefine; + +import java.util.concurrent.TimeUnit; + +/** + * 基建模块缓存 key + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/7/13 21:54 + */ +public interface InfraCacheKeyDefine { + + CacheKeyDefine USER_INFO = new CacheKeyDefine("user:info:{}", "用户信息", 30, TimeUnit.DAYS); + + CacheKeyDefine USER_TOKEN = new CacheKeyDefine("user:token:{}", "用户认证 authenticationToken", 48, TimeUnit.HOURS); + + CacheKeyDefine USER_REFRESH = new CacheKeyDefine("user:refresh:{}", "用户认证 refreshToken", 54, TimeUnit.HOURS); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/SystemUserDO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/SystemUserDO.java new file mode 100644 index 00000000..fcda49a4 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/SystemUserDO.java @@ -0,0 +1,64 @@ +package com.orion.ops.module.infra.entity.domain; + +import com.baomidou.mybatisplus.annotation.*; +import com.orion.ops.framework.mybatis.core.domain.BaseDO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.util.*; + +/** + * 用户 实体对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-7-13 18:42 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@TableName(value = "system_user", autoResultMap = true) +@Schema(name = "SystemUserDO", description = "用户 实体对象") +public class SystemUserDO extends BaseDO { + + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + @Schema(description = "用户名") + @TableField("username") + private String username; + + @Schema(description = "密码") + @TableField("password") + private String password; + + @Schema(description = "花名") + @TableField("nickname") + private String nickname; + + @Schema(description = "头像地址") + @TableField("avatar") + private String avatar; + + @Schema(description = "手机号") + @TableField("mobile") + private String mobile; + + @Schema(description = "邮箱") + @TableField("email") + private String email; + + @Schema(description = "用户状态 0正常 1停用 2锁定") + @TableField("status") + private Byte status; + + @Schema(description = "最后登录时间") + @TableField("last_login_time") + private Date lastLoginTime; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/SystemUserCreateRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/SystemUserCreateRequest.java new file mode 100644 index 00000000..3833d0bb --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/SystemUserCreateRequest.java @@ -0,0 +1,61 @@ +package com.orion.ops.module.infra.entity.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import java.io.Serializable; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.*; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * 用户 创建请求对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-7-14 10:29 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "SystemUserCreateRequest", description = "用户 创建请求对象") +public class SystemUserCreateRequest implements Serializable { + + @NotBlank + @Schema(description = "用户名") + private String username; + + @NotBlank + @Schema(description = "密码") + private String password; + + @NotBlank + @Schema(description = "花名") + private String nickname; + + @NotBlank + @Schema(description = "头像地址") + private String avatar; + + @NotBlank + @Schema(description = "手机号") + private String mobile; + + @NotBlank + @Schema(description = "邮箱") + private String email; + + @NotNull + @Schema(description = "用户状态 0正常 1停用 2锁定") + private Byte status; + + @NotNull + @Schema(description = "最后登录时间") + private Date lastLoginTime; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/SystemUserQueryRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/SystemUserQueryRequest.java new file mode 100644 index 00000000..a09df5c0 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/SystemUserQueryRequest.java @@ -0,0 +1,51 @@ +package com.orion.ops.module.infra.entity.request; + +import com.orion.ops.framework.common.entity.PageRequest; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.util.*; + +/** + * 用户 查询请求对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-7-14 10:29 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@Schema(name = "SystemUserQueryRequest", description = "用户 查询请求对象") +public class SystemUserQueryRequest extends PageRequest { + + @Schema(description = "id") + private Long id; + + @Schema(description = "用户名") + private String username; + + @Schema(description = "密码") + private String password; + + @Schema(description = "花名") + private String nickname; + + @Schema(description = "头像地址") + private String avatar; + + @Schema(description = "手机号") + private String mobile; + + @Schema(description = "邮箱") + private String email; + + @Schema(description = "用户状态 0正常 1停用 2锁定") + private Byte status; + + @Schema(description = "最后登录时间") + private Date lastLoginTime; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/SystemUserUpdateRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/SystemUserUpdateRequest.java new file mode 100644 index 00000000..284ea6e5 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/SystemUserUpdateRequest.java @@ -0,0 +1,65 @@ +package com.orion.ops.module.infra.entity.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import java.io.Serializable; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.*; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * 用户 更新请求对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-7-14 10:29 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "SystemUserUpdateRequest", description = "用户 更新请求对象") +public class SystemUserUpdateRequest implements Serializable { + + @NotNull + @Schema(description = "id") + private Long id; + + @NotBlank + @Schema(description = "用户名") + private String username; + + @NotBlank + @Schema(description = "密码") + private String password; + + @NotBlank + @Schema(description = "花名") + private String nickname; + + @NotBlank + @Schema(description = "头像地址") + private String avatar; + + @NotBlank + @Schema(description = "手机号") + private String mobile; + + @NotBlank + @Schema(description = "邮箱") + private String email; + + @NotNull + @Schema(description = "用户状态 0正常 1停用 2锁定") + private Byte status; + + @NotNull + @Schema(description = "最后登录时间") + private Date lastLoginTime; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/UserLoginRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/UserLoginRequest.java new file mode 100644 index 00000000..b088e8f9 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/UserLoginRequest.java @@ -0,0 +1,26 @@ +package com.orion.ops.module.infra.entity.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; + +/** + * 登陆请求 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/7/13 22:16 + */ +@Data +public class UserLoginRequest { + + @NotEmpty + @Schema(description = "用户名") + private String username; + + @NotEmpty + @Schema(description = "密码") + private String password; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/SystemUserVO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/SystemUserVO.java new file mode 100644 index 00000000..b4193af7 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/SystemUserVO.java @@ -0,0 +1,64 @@ +package com.orion.ops.module.infra.entity.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import java.io.Serializable; +import lombok.*; + +import java.util.*; + +/** + * 用户 视图响应对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-7-13 18:42 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "SystemUserVO", description = "用户 视图响应对象") +public class SystemUserVO implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + private Long id; + + @Schema(description = "用户名") + private String username; + + @Schema(description = "密码") + private String password; + + @Schema(description = "花名") + private String nickname; + + @Schema(description = "头像地址") + private String avatar; + + @Schema(description = "手机号") + private String mobile; + + @Schema(description = "邮箱") + private String email; + + @Schema(description = "用户状态 0正常 1停用 2锁定") + private Byte status; + + @Schema(description = "最后登录时间") + private Date lastLoginTime; + + @Schema(description = "创建时间") + private Date createTime; + + @Schema(description = "修改时间") + private Date updateTime; + + @Schema(description = "创建人") + private String creator; + + @Schema(description = "修改人") + private String updater; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/AuthenticationService.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/AuthenticationService.java new file mode 100644 index 00000000..89fdc355 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/AuthenticationService.java @@ -0,0 +1,29 @@ +package com.orion.ops.module.infra.service; + +import com.orion.ops.module.infra.entity.request.UserLoginRequest; + +/** + * 认证服务 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/7/13 22:15 + */ +public interface AuthenticationService { + + /** + * 登陆 + * + * @param request request + * @return token + */ + String login(UserLoginRequest request); + + /** + * 登出 + * + * @param token token + */ + void logout(String token); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/SystemUserService.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/SystemUserService.java new file mode 100644 index 00000000..c0ef8f46 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/SystemUserService.java @@ -0,0 +1,76 @@ +package com.orion.ops.module.infra.service; + +import com.orion.lang.define.wrapper.DataGrid; +import com.orion.ops.module.infra.entity.vo.*; +import com.orion.ops.module.infra.entity.dto.*; +import com.orion.ops.module.infra.entity.request.*; +import com.orion.ops.module.infra.convert.*; + +import java.util.List; + +/** + * 用户 服务类 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-7-13 18:42 + */ +public interface SystemUserService { + + /** + * 创建用户 + * + * @param request request + * @return id + */ + Long createSystemUser(SystemUserCreateRequest request); + + /** + * 通过 id 更新用户 + * + * @param request request + * @return effect + */ + Integer updateSystemUser(SystemUserUpdateRequest request); + + /** + * 通过 id 查询用户 + * + * @param id id + * @return row + */ + SystemUserVO getSystemUser(Long id); + + /** + * 通过 id 批量查询用户 + * + * @param idList idList + * @return rows + */ + List getSystemUserList(List idList); + + /** + * 分页查询用户 + * + * @param request request + * @return rows + */ + DataGrid getSystemUserPage(SystemUserQueryRequest request); + + /** + * 通过 id 删除用户 + * + * @param id id + * @return effect + */ + Integer deleteSystemUser(Long id); + + /** + * 通过 id 批量删除用户 + * + * @param idList idList + * @return effect + */ + Integer batchDeleteSystemUser(List idList); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/AuthenticationServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/AuthenticationServiceImpl.java new file mode 100644 index 00000000..c3ee660b --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/AuthenticationServiceImpl.java @@ -0,0 +1,67 @@ +package com.orion.ops.module.infra.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.orion.lang.utils.Valid; +import com.orion.lang.utils.crypto.Signatures; +import com.orion.ops.framework.common.constant.ErrorMessage; +import com.orion.ops.module.infra.dao.SystemUserDAO; +import com.orion.ops.module.infra.entity.domain.SystemUserDO; +import com.orion.ops.module.infra.entity.request.UserLoginRequest; +import com.orion.ops.module.infra.service.AuthenticationService; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Optional; + +/** + * 认证服务实现 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/7/13 22:15 + */ +@Service +public class AuthenticationServiceImpl implements AuthenticationService { + + /** + * 允许多端登陆 + */ + private final boolean allowMultiPlatform = false; + + @Resource + private SystemUserDAO systemUserDAO; + + @Resource + private RedisTemplate redisTemplate; + + @Override + public String login(UserLoginRequest request) { + // 检查登陆 + LambdaQueryWrapper wrapper = systemUserDAO.wrapper() + .eq(SystemUserDO::getUsername, request.getUsername()) + .eq(SystemUserDO::getPassword, Signatures.md5(request.getPassword())); + // 获取登陆用户 + Optional systemUserDO = systemUserDAO.of(wrapper).only().get(); + Valid.isTrue(systemUserDO.isPresent(), ErrorMessage.USERNAME_PASSWORD_ERROR); + // 检查用户状态 + + // 设置缓存 + + // 不允许多端登陆删除缓存 + + // 生成 authenticationToken + + // 生成 refreshToken + + // + + return null; + } + + @Override + public void logout(String token) { + + } + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemUserServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemUserServiceImpl.java new file mode 100644 index 00000000..c02dbedc --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemUserServiceImpl.java @@ -0,0 +1,140 @@ +package com.orion.ops.module.infra.service.impl; + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.orion.lang.define.wrapper.DataGrid; +import com.orion.lang.utils.Valid; +import com.orion.lang.utils.collect.Lists; +import com.orion.ops.framework.common.constant.ErrorMessage; +import com.orion.ops.module.infra.entity.vo.*; +import com.orion.ops.module.infra.entity.dto.*; +import com.orion.ops.module.infra.entity.request.*; +import com.orion.ops.module.infra.convert.*; +import com.orion.ops.module.infra.entity.domain.SystemUserDO; +import com.orion.ops.module.infra.dao.SystemUserDAO; +import com.orion.ops.module.infra.service.SystemUserService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 用户 服务实现类 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-7-14 10:16 + */ +@Slf4j +@Service +public class SystemUserServiceImpl implements SystemUserService { + + @Resource + private SystemUserDAO systemUserDAO; + + @Override + public Long createSystemUser(SystemUserCreateRequest request) { + // 转换 + SystemUserDO record = SystemUserConvert.MAPPER.to(request); + record.setId(null); + // 查询是否存在 + this.checkSystemUserPresent(record); + // 插入 + int effect = systemUserDAO.insert(record); + log.info("SystemUserService-createSystemUser effect: {}, domain: {}", effect, JSON.toJSONString(record)); + return record.getId(); + } + + @Override + public Integer updateSystemUser(SystemUserUpdateRequest request) { + // 转换 + SystemUserDO record = SystemUserConvert.MAPPER.to(request); + Valid.notNull(record.getId(), ErrorMessage.ID_MISSING); + // 查询是否存在 + this.checkSystemUserPresent(record); + // 更新 + int effect = systemUserDAO.updateById(record); + log.info("SystemUserService-updateSystemUser effect: {}, domain: {}", effect, JSON.toJSONString(record)); + return effect; + } + + @Override + public SystemUserVO getSystemUser(Long id) { + // 查询 + SystemUserDO record = systemUserDAO.selectById(id); + Valid.notNull(record, ErrorMessage.DATA_ABSENT); + // 转换 + return SystemUserConvert.MAPPER.to(record); + } + + @Override + public List getSystemUserList(List idList) { + // 查询 + List records = systemUserDAO.selectBatchIds(idList); + if (records.isEmpty()) { + return Lists.empty(); + } + // 转换 + return SystemUserConvert.MAPPER.to(records); + } + + @Override + public DataGrid getSystemUserPage(SystemUserQueryRequest request) { + // 构造条件 + LambdaQueryWrapper wrapper = systemUserDAO.wrapper() + .eq(SystemUserDO::getId, request.getId()) + .eq(SystemUserDO::getUsername, request.getUsername()) + .eq(SystemUserDO::getPassword, request.getPassword()) + .eq(SystemUserDO::getNickname, request.getNickname()) + .eq(SystemUserDO::getAvatar, request.getAvatar()) + .eq(SystemUserDO::getMobile, request.getMobile()) + .eq(SystemUserDO::getEmail, request.getEmail()) + .eq(SystemUserDO::getStatus, request.getStatus()) + .eq(SystemUserDO::getLastLoginTime, request.getLastLoginTime()); + // 查询 + return systemUserDAO.of() + .wrapper(wrapper) + .page(request) + .dataGrid(SystemUserConvert.MAPPER::to); + } + + @Override + public Integer deleteSystemUser(Long id) { + int effect = systemUserDAO.deleteById(id); + log.info("SystemUserService-deleteSystemUser id: {}, effect: {}", id, effect); + return effect; + } + + @Override + public Integer batchDeleteSystemUser(List idList) { + int effect = systemUserDAO.deleteBatchIds(idList); + log.info("SystemUserService-batchDeleteSystemUser idList: {}, effect: {}", JSON.toJSONString(idList), effect); + return effect; + } + + /** + * 检测对象是否存在 + * + * @param domain domain + */ + private void checkSystemUserPresent(SystemUserDO domain) { + // 构造条件 + LambdaQueryWrapper wrapper = systemUserDAO.wrapper() + // 更新时忽略当前记录 + .ne(SystemUserDO::getId, domain.getId()) + // 用其他字段做重复校验 + .eq(SystemUserDO::getUsername, domain.getUsername()) + .eq(SystemUserDO::getPassword, domain.getPassword()) + .eq(SystemUserDO::getNickname, domain.getNickname()) + .eq(SystemUserDO::getAvatar, domain.getAvatar()) + .eq(SystemUserDO::getMobile, domain.getMobile()) + .eq(SystemUserDO::getEmail, domain.getEmail()) + .eq(SystemUserDO::getStatus, domain.getStatus()) + .eq(SystemUserDO::getLastLoginTime, domain.getLastLoginTime()); + // 检查是否存在 + boolean present = systemUserDAO.of().wrapper(wrapper).present(); + Valid.isFalse(present, ErrorMessage.DATA_PRESENT); + } + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/SystemUserMapper.xml b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/SystemUserMapper.xml new file mode 100644 index 00000000..fe911eb3 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/SystemUserMapper.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + create_time, update_time, creator, updater, deleted, id, username, password, nickname, avatar, mobile, email, status, last_login_time + + +