初始化用户代码.
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
@@ -34,12 +34,6 @@
|
||||
<artifactId>orion-ops-spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- swagger -->
|
||||
<dependency>
|
||||
<groupId>com.orion.ops</groupId>
|
||||
<artifactId>orion-ops-spring-boot-starter-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- redis -->
|
||||
<dependency>
|
||||
<groupId>com.orion.ops</groupId>
|
||||
|
||||
@@ -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}}
|
||||
|
||||
|
||||
|
||||
@@ -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<SystemUserVO> getSystemUserList(@RequestParam("idList") List<Long> idList) {
|
||||
return systemUserService.getSystemUserList(idList);
|
||||
}
|
||||
|
||||
@PostMapping("/query")
|
||||
@Operation(summary = "分页查询用户")
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-user:query')")
|
||||
public DataGrid<SystemUserVO> 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<Long> idList) {
|
||||
return systemUserService.batchDeleteSystemUser(idList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<SystemUserVO> to(List<SystemUserDO> list);
|
||||
|
||||
}
|
||||
@@ -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<SystemUserDO> toDO(List<SystemUserDTO> list);
|
||||
|
||||
List<SystemUserDTO> toDTO(List<SystemUserDO> list);
|
||||
|
||||
}
|
||||
@@ -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<SystemUserDO> {
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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<SystemUserVO> getSystemUserList(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 分页查询用户
|
||||
*
|
||||
* @param request request
|
||||
* @return rows
|
||||
*/
|
||||
DataGrid<SystemUserVO> getSystemUserPage(SystemUserQueryRequest request);
|
||||
|
||||
/**
|
||||
* 通过 id 删除用户
|
||||
*
|
||||
* @param id id
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteSystemUser(Long id);
|
||||
|
||||
/**
|
||||
* 通过 id 批量删除用户
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer batchDeleteSystemUser(List<Long> idList);
|
||||
|
||||
}
|
||||
@@ -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<String, String> redisTemplate;
|
||||
|
||||
@Override
|
||||
public String login(UserLoginRequest request) {
|
||||
// 检查登陆
|
||||
LambdaQueryWrapper<SystemUserDO> wrapper = systemUserDAO.wrapper()
|
||||
.eq(SystemUserDO::getUsername, request.getUsername())
|
||||
.eq(SystemUserDO::getPassword, Signatures.md5(request.getPassword()));
|
||||
// 获取登陆用户
|
||||
Optional<SystemUserDO> systemUserDO = systemUserDAO.of(wrapper).only().get();
|
||||
Valid.isTrue(systemUserDO.isPresent(), ErrorMessage.USERNAME_PASSWORD_ERROR);
|
||||
// 检查用户状态
|
||||
|
||||
// 设置缓存
|
||||
|
||||
// 不允许多端登陆删除缓存
|
||||
|
||||
// 生成 authenticationToken
|
||||
|
||||
// 生成 refreshToken
|
||||
|
||||
//
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logout(String token) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<SystemUserVO> getSystemUserList(List<Long> idList) {
|
||||
// 查询
|
||||
List<SystemUserDO> records = systemUserDAO.selectBatchIds(idList);
|
||||
if (records.isEmpty()) {
|
||||
return Lists.empty();
|
||||
}
|
||||
// 转换
|
||||
return SystemUserConvert.MAPPER.to(records);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataGrid<SystemUserVO> getSystemUserPage(SystemUserQueryRequest request) {
|
||||
// 构造条件
|
||||
LambdaQueryWrapper<SystemUserDO> 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<Long> 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<SystemUserDO> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.orion.ops.module.infra.dao.SystemUserDAO">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.orion.ops.module.infra.entity.domain.SystemUserDO">
|
||||
<id column="id" property="id"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="creator" property="creator"/>
|
||||
<result column="updater" property="updater"/>
|
||||
<result column="deleted" property="deleted"/>
|
||||
<result column="username" property="username"/>
|
||||
<result column="password" property="password"/>
|
||||
<result column="nickname" property="nickname"/>
|
||||
<result column="avatar" property="avatar"/>
|
||||
<result column="mobile" property="mobile"/>
|
||||
<result column="email" property="email"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="last_login_time" property="lastLoginTime"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
create_time, update_time, creator, updater, deleted, id, username, password, nickname, avatar, mobile, email, status, last_login_time
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user