mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-23 17:49:34 +08:00
学员管理
This commit is contained in:
parent
0dc02ffad7
commit
4dfd5518cb
@ -52,14 +52,6 @@ public class AdminUserController {
|
||||
|
||||
PaginationResult<AdminUser> result = adminUserService.paginate(page, size, filter);
|
||||
|
||||
ArrayList<AdminUser> data = new ArrayList<>();
|
||||
for (AdminUser adminUser : result.getData()) {
|
||||
adminUser.setPassword(null);
|
||||
adminUser.setSalt(null);
|
||||
data.add(adminUser);
|
||||
}
|
||||
result.setData(data);
|
||||
|
||||
return JsonResponse.data(result);
|
||||
}
|
||||
|
||||
|
@ -1,44 +1,185 @@
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.domain.User;
|
||||
import xyz.playedu.api.event.UserDestroyEvent;
|
||||
import xyz.playedu.api.request.backend.UserRequest;
|
||||
import xyz.playedu.api.service.UserService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserPaginateFilter;
|
||||
import xyz.playedu.api.util.HelperUtil;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/2/23 09:48
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/backend/v1/user")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index() {
|
||||
return null;
|
||||
public JsonResponse index(
|
||||
@RequestParam(name = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(name = "size", defaultValue = "10") Integer size,
|
||||
@RequestParam(name = "name", required = false) String name,
|
||||
@RequestParam(name = "email", required = false) String email,
|
||||
@RequestParam(name = "nickname", required = false) String nickname,
|
||||
@RequestParam(name = "id_card", required = false) String idCard,
|
||||
@RequestParam(name = "is_active", required = false) Integer isActive,
|
||||
@RequestParam(name = "is_lock", required = false) Integer isLock,
|
||||
@RequestParam(name = "is_verify", required = false) Integer isVerify,
|
||||
@RequestParam(name = "is_set_password", required = false) Integer isSetPassword,
|
||||
@RequestParam(name = "created_at", required = false) Date[] createdAt
|
||||
) {
|
||||
UserPaginateFilter filter = new UserPaginateFilter();
|
||||
if (name != null && name.length() > 0) {
|
||||
filter.setName(name);
|
||||
}
|
||||
if (nickname != null && nickname.length() > 0) {
|
||||
filter.setNickname(nickname);
|
||||
}
|
||||
if (email != null && email.length() > 0) {
|
||||
filter.setEmail(email);
|
||||
}
|
||||
if (idCard != null && idCard.length() > 0) {
|
||||
filter.setIdCard(idCard);
|
||||
}
|
||||
if (isActive != null) {
|
||||
filter.setIsActive(isActive);
|
||||
}
|
||||
if (isLock != null) {
|
||||
filter.setIsLock(isLock);
|
||||
}
|
||||
if (isVerify != null) {
|
||||
filter.setIsVerify(isVerify);
|
||||
}
|
||||
if (isSetPassword != null) {
|
||||
filter.setIsSetPassword(isSetPassword);
|
||||
}
|
||||
if (createdAt != null && createdAt.length == 2) {
|
||||
filter.setCreatedAt(createdAt);
|
||||
}
|
||||
|
||||
PaginationResult<User> result = userService.paginate(page, size, filter);
|
||||
return JsonResponse.data(result);
|
||||
}
|
||||
|
||||
@GetMapping("/create")
|
||||
public JsonResponse create() {
|
||||
return null;
|
||||
return JsonResponse.data(null);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public JsonResponse store() {
|
||||
return null;
|
||||
public JsonResponse store(@RequestBody @Validated UserRequest request) {
|
||||
if (userService.emailIsExists(request.getEmail())) {
|
||||
return JsonResponse.error("邮箱已存在");
|
||||
}
|
||||
|
||||
String salt = HelperUtil.randomString(6);
|
||||
String password = HelperUtil.MD5(request.getPassword() + salt);
|
||||
|
||||
User user = new User();
|
||||
user.setEmail(request.getEmail());
|
||||
user.setNickname(request.getNickname());
|
||||
user.setName(request.getName());
|
||||
user.setAvatar(request.getAvatar());
|
||||
user.setPassword(password);
|
||||
user.setSalt(salt);
|
||||
user.setIdCard(request.getIdCard());
|
||||
user.setCredit1(request.getCredit1());
|
||||
user.setIsActive(request.getIsActive());
|
||||
user.setIsLock(request.getIsLock());
|
||||
user.setIsVerify(request.getIsVerify());
|
||||
user.setVerifyAt(request.getVerifyAt());
|
||||
user.setIsSetPassword(request.getIsSetPassword());
|
||||
|
||||
user.setCreateIp("127.0.0.1");
|
||||
user.setCreateCity("内网");
|
||||
user.setCreatedAt(new Date());
|
||||
user.setUpdatedAt(new Date());
|
||||
|
||||
userService.save(user);
|
||||
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public JsonResponse edit(@PathVariable(name = "id") Integer id) {
|
||||
return null;
|
||||
User user = userService.getById(id);
|
||||
if (user == null) {
|
||||
return JsonResponse.error("学员不存在");
|
||||
}
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("user", user);
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public JsonResponse update(@PathVariable(name = "id") Integer id) {
|
||||
return null;
|
||||
public JsonResponse update(@PathVariable(name = "id") Integer id, @RequestBody @Validated UserRequest request) {
|
||||
User user = userService.getById(id);
|
||||
if (user == null) {
|
||||
return JsonResponse.error("学员不存在");
|
||||
}
|
||||
|
||||
if (!request.getEmail().equals(user.getEmail()) && userService.emailIsExists(request.getEmail())) {
|
||||
return JsonResponse.error("邮箱已存在");
|
||||
}
|
||||
|
||||
User newUser = new User();
|
||||
newUser.setId(user.getId());
|
||||
newUser.setEmail(request.getEmail());
|
||||
newUser.setNickname(request.getNickname());
|
||||
newUser.setName(request.getName());
|
||||
newUser.setAvatar(request.getAvatar());
|
||||
newUser.setIdCard(request.getIdCard());
|
||||
newUser.setCredit1(request.getCredit1());
|
||||
newUser.setIsActive(request.getIsActive());
|
||||
newUser.setIsLock(request.getIsLock());
|
||||
newUser.setIsVerify(request.getIsVerify());
|
||||
newUser.setVerifyAt(request.getVerifyAt());
|
||||
newUser.setIsSetPassword(request.getIsSetPassword());
|
||||
|
||||
if (request.getPassword() != null && request.getPassword().length() > 0) {//更新密码
|
||||
String salt = HelperUtil.randomString(6);
|
||||
String password = HelperUtil.MD5(request.getPassword());
|
||||
|
||||
newUser.setPassword(password);
|
||||
newUser.setSalt(salt);
|
||||
}
|
||||
|
||||
userService.updateById(newUser);
|
||||
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public JsonResponse destroy(@PathVariable(name = "id") Integer id) {
|
||||
return null;
|
||||
User user = userService.getById(id);
|
||||
if (user == null) {
|
||||
return JsonResponse.error("学员不存在");
|
||||
}
|
||||
userService.removeById(user.getId());
|
||||
|
||||
applicationContext.publishEvent(new UserDestroyEvent(this, user.getId(), new Date()));
|
||||
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@ -34,11 +36,13 @@ public class AdminUser implements Serializable {
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* Salt
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
|
215
src/main/java/xyz/playedu/api/domain/User.java
Normal file
215
src/main/java/xyz/playedu/api/domain/User.java
Normal file
@ -0,0 +1,215 @@
|
||||
package xyz.playedu.api.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @TableName users
|
||||
*/
|
||||
@TableName(value = "users")
|
||||
@Data
|
||||
public class User implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 邮件
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 真实姓名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* salt
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
* 身份证号
|
||||
*/
|
||||
@JsonProperty("id_card")
|
||||
private String idCard;
|
||||
|
||||
/**
|
||||
* 学分
|
||||
*/
|
||||
private Integer credit1;
|
||||
|
||||
/**
|
||||
* 注册Ip
|
||||
*/
|
||||
@JsonProperty("create_ip")
|
||||
private String createIp;
|
||||
|
||||
/**
|
||||
* 注册城市
|
||||
*/
|
||||
@JsonProperty("create_city")
|
||||
private String createCity;
|
||||
|
||||
/**
|
||||
* 激活[1:是,0:否]
|
||||
*/
|
||||
@JsonProperty("is_active")
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 锁定[1:是,0:否]
|
||||
*/
|
||||
@JsonProperty("is_lock")
|
||||
private Integer isLock;
|
||||
|
||||
/**
|
||||
* 实名认证[1:是,0:否]
|
||||
*/
|
||||
@JsonProperty("is_verify")
|
||||
private Integer isVerify;
|
||||
|
||||
/**
|
||||
* 实名认证时间
|
||||
*/
|
||||
@JsonProperty("verify_at")
|
||||
private Date verifyAt;
|
||||
|
||||
/**
|
||||
* 设置密码[1:是,0:否]
|
||||
*/
|
||||
@JsonProperty("is_set_password")
|
||||
private Integer isSetPassword;
|
||||
|
||||
/**
|
||||
* 登录时间
|
||||
*/
|
||||
@JsonProperty("login_at")
|
||||
private Date loginAt;
|
||||
|
||||
@JsonProperty("created_at")
|
||||
private Date createdAt;
|
||||
|
||||
@JsonProperty("updated_at")
|
||||
private Date updatedAt;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (this == that) {
|
||||
return true;
|
||||
}
|
||||
if (that == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != that.getClass()) {
|
||||
return false;
|
||||
}
|
||||
User other = (User) that;
|
||||
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
|
||||
&& (this.getEmail() == null ? other.getEmail() == null : this.getEmail().equals(other.getEmail()))
|
||||
&& (this.getNickname() == null ? other.getNickname() == null : this.getNickname().equals(other.getNickname()))
|
||||
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
|
||||
&& (this.getAvatar() == null ? other.getAvatar() == null : this.getAvatar().equals(other.getAvatar()))
|
||||
&& (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
|
||||
&& (this.getSalt() == null ? other.getSalt() == null : this.getSalt().equals(other.getSalt()))
|
||||
&& (this.getIdCard() == null ? other.getIdCard() == null : this.getIdCard().equals(other.getIdCard()))
|
||||
&& (this.getCredit1() == null ? other.getCredit1() == null : this.getCredit1().equals(other.getCredit1()))
|
||||
&& (this.getCreateIp() == null ? other.getCreateIp() == null : this.getCreateIp().equals(other.getCreateIp()))
|
||||
&& (this.getCreateCity() == null ? other.getCreateCity() == null : this.getCreateCity().equals(other.getCreateCity()))
|
||||
&& (this.getIsActive() == null ? other.getIsActive() == null : this.getIsActive().equals(other.getIsActive()))
|
||||
&& (this.getIsLock() == null ? other.getIsLock() == null : this.getIsLock().equals(other.getIsLock()))
|
||||
&& (this.getIsVerify() == null ? other.getIsVerify() == null : this.getIsVerify().equals(other.getIsVerify()))
|
||||
&& (this.getVerifyAt() == null ? other.getVerifyAt() == null : this.getVerifyAt().equals(other.getVerifyAt()))
|
||||
&& (this.getIsSetPassword() == null ? other.getIsSetPassword() == null : this.getIsSetPassword().equals(other.getIsSetPassword()))
|
||||
&& (this.getLoginAt() == null ? other.getLoginAt() == null : this.getLoginAt().equals(other.getLoginAt()))
|
||||
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
|
||||
&& (this.getUpdatedAt() == null ? other.getUpdatedAt() == null : this.getUpdatedAt().equals(other.getUpdatedAt()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||
result = prime * result + ((getEmail() == null) ? 0 : getEmail().hashCode());
|
||||
result = prime * result + ((getNickname() == null) ? 0 : getNickname().hashCode());
|
||||
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
|
||||
result = prime * result + ((getAvatar() == null) ? 0 : getAvatar().hashCode());
|
||||
result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
|
||||
result = prime * result + ((getSalt() == null) ? 0 : getSalt().hashCode());
|
||||
result = prime * result + ((getIdCard() == null) ? 0 : getIdCard().hashCode());
|
||||
result = prime * result + ((getCredit1() == null) ? 0 : getCredit1().hashCode());
|
||||
result = prime * result + ((getCreateIp() == null) ? 0 : getCreateIp().hashCode());
|
||||
result = prime * result + ((getCreateCity() == null) ? 0 : getCreateCity().hashCode());
|
||||
result = prime * result + ((getIsActive() == null) ? 0 : getIsActive().hashCode());
|
||||
result = prime * result + ((getIsLock() == null) ? 0 : getIsLock().hashCode());
|
||||
result = prime * result + ((getIsVerify() == null) ? 0 : getIsVerify().hashCode());
|
||||
result = prime * result + ((getVerifyAt() == null) ? 0 : getVerifyAt().hashCode());
|
||||
result = prime * result + ((getIsSetPassword() == null) ? 0 : getIsSetPassword().hashCode());
|
||||
result = prime * result + ((getLoginAt() == null) ? 0 : getLoginAt().hashCode());
|
||||
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
|
||||
result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" [");
|
||||
sb.append("Hash = ").append(hashCode());
|
||||
sb.append(", id=").append(id);
|
||||
sb.append(", email=").append(email);
|
||||
sb.append(", nickname=").append(nickname);
|
||||
sb.append(", name=").append(name);
|
||||
sb.append(", avatar=").append(avatar);
|
||||
sb.append(", password=").append(password);
|
||||
sb.append(", salt=").append(salt);
|
||||
sb.append(", idCard=").append(idCard);
|
||||
sb.append(", credit1=").append(credit1);
|
||||
sb.append(", createIp=").append(createIp);
|
||||
sb.append(", createCity=").append(createCity);
|
||||
sb.append(", isActive=").append(isActive);
|
||||
sb.append(", isLock=").append(isLock);
|
||||
sb.append(", isVerify=").append(isVerify);
|
||||
sb.append(", verifyAt=").append(verifyAt);
|
||||
sb.append(", isSetPassword=").append(isSetPassword);
|
||||
sb.append(", loginAt=").append(loginAt);
|
||||
sb.append(", createdAt=").append(createdAt);
|
||||
sb.append(", updatedAt=").append(updatedAt);
|
||||
sb.append(", serialVersionUID=").append(serialVersionUID);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
25
src/main/java/xyz/playedu/api/event/UserDestroyEvent.java
Normal file
25
src/main/java/xyz/playedu/api/event/UserDestroyEvent.java
Normal file
@ -0,0 +1,25 @@
|
||||
package xyz.playedu.api.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/2/23 13:51
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserDestroyEvent extends ApplicationEvent {
|
||||
|
||||
private Integer userId;
|
||||
private Date at;
|
||||
|
||||
public UserDestroyEvent(Object source, Integer userId, Date date) {
|
||||
super(source);
|
||||
this.userId = userId;
|
||||
this.at = date;
|
||||
}
|
||||
}
|
20
src/main/java/xyz/playedu/api/mapper/UserMapper.java
Normal file
20
src/main/java/xyz/playedu/api/mapper/UserMapper.java
Normal file
@ -0,0 +1,20 @@
|
||||
package xyz.playedu.api.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import xyz.playedu.api.domain.User;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【users】的数据库操作Mapper
|
||||
* @createDate 2023-02-23 14:04:49
|
||||
* @Entity xyz.playedu.api.domain.User
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,54 @@
|
||||
package xyz.playedu.api.request.backend;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/2/23 13:56
|
||||
*/
|
||||
@Data
|
||||
public class UserRequest {
|
||||
|
||||
@NotNull(message = "请输入邮箱")
|
||||
@Email(message = "请输入合法邮箱")
|
||||
private String email;
|
||||
|
||||
@NotNull(message = "请输入昵称")
|
||||
private String nickname;
|
||||
|
||||
@Length(min = 1, max = 20, message = "姓名长度在1-20个字符之间")
|
||||
private String name;
|
||||
|
||||
@NotNull(message = "请上传头像")
|
||||
private String avatar;
|
||||
|
||||
@NotNull(message = "请输入密码")
|
||||
private String password;
|
||||
|
||||
@JsonProperty("id_card")
|
||||
private String idCard;
|
||||
|
||||
private Integer credit1;
|
||||
|
||||
@JsonProperty("is_active")
|
||||
private Integer isActive;
|
||||
|
||||
@JsonProperty("is_lock")
|
||||
private Integer isLock;
|
||||
|
||||
@JsonProperty("is_verify")
|
||||
private Integer isVerify;
|
||||
|
||||
@JsonProperty("verify_at")
|
||||
private Date verifyAt;
|
||||
|
||||
@JsonProperty("is_set_password")
|
||||
private Integer isSetPassword;
|
||||
|
||||
}
|
17
src/main/java/xyz/playedu/api/service/UserService.java
Normal file
17
src/main/java/xyz/playedu/api/service/UserService.java
Normal file
@ -0,0 +1,17 @@
|
||||
package xyz.playedu.api.service;
|
||||
|
||||
import xyz.playedu.api.domain.User;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserPaginateFilter;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【users】的数据库操作Service
|
||||
* @createDate 2023-02-23 13:50:58
|
||||
*/
|
||||
public interface UserService extends IService<User> {
|
||||
boolean emailIsExists(String email);
|
||||
|
||||
PaginationResult<User> paginate(int page, int size, UserPaginateFilter filter);
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.enums.SqlKeyword;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.ibatis.jdbc.SQL;
|
||||
import xyz.playedu.api.domain.User;
|
||||
import xyz.playedu.api.service.UserService;
|
||||
import xyz.playedu.api.mapper.UserMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserPaginateFilter;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【users】的数据库操作Service实现
|
||||
* @createDate 2023-02-23 13:50:58
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
||||
@Override
|
||||
public boolean emailIsExists(String email) {
|
||||
User user = getOne(query().getWrapper().eq("email", email));
|
||||
return user != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaginationResult<User> paginate(int page, int size, UserPaginateFilter filter) {
|
||||
QueryWrapper<User> wrapper = query().getWrapper().eq("1", "1");
|
||||
|
||||
if (filter != null) {
|
||||
if (filter.getEmail() != null) {
|
||||
wrapper.eq("email", filter.getEmail());
|
||||
}
|
||||
if (filter.getName() != null) {
|
||||
wrapper.eq("name", filter.getName());
|
||||
}
|
||||
if (filter.getNickname() != null) {
|
||||
wrapper.eq("nickname", filter.getNickname());
|
||||
}
|
||||
if (filter.getIdCard() != null) {
|
||||
wrapper.eq("id_card", filter.getIdCard());
|
||||
}
|
||||
if (filter.getIsActive() != null) {
|
||||
wrapper.eq("is_active", filter.getIsActive());
|
||||
}
|
||||
if (filter.getIsLock() != null) {
|
||||
wrapper.eq("is_lock", filter.getIsLock());
|
||||
}
|
||||
if (filter.getIsVerify() != null) {
|
||||
wrapper.eq("is_verify", filter.getIsVerify());
|
||||
}
|
||||
if (filter.getIsSetPassword() != null) {
|
||||
wrapper.eq("is_set_password", filter.getIsSetPassword());
|
||||
}
|
||||
if (filter.getCreatedAt() != null && filter.getCreatedAt().length == 2) {
|
||||
wrapper.between("created_at", filter.getCreatedAt()[0], filter.getCreatedAt()[1]);
|
||||
}
|
||||
if (filter.getSortField() != null && filter.getSortAlgo() != null) {
|
||||
wrapper.orderBy(true, filter.getSortAlgo().toUpperCase() == "ASC", filter.getSortField());
|
||||
}
|
||||
}
|
||||
|
||||
IPage<User> userPage = new Page<>(page, size);
|
||||
userPage = page(userPage, wrapper);
|
||||
|
||||
PaginationResult<User> pageResult = new PaginationResult<>();
|
||||
pageResult.setData(userPage.getRecords());
|
||||
pageResult.setTotal(userPage.getTotal());
|
||||
|
||||
return pageResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
package xyz.playedu.api.types.paginate;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/2/23 14:23
|
||||
*/
|
||||
@Data
|
||||
public class UserPaginateFilter {
|
||||
|
||||
private String nickname;
|
||||
|
||||
private String name;
|
||||
|
||||
private String email;
|
||||
|
||||
private String idCard;
|
||||
|
||||
private Integer isActive;
|
||||
private Integer isLock;
|
||||
private Integer isVerify;
|
||||
private Integer isSetPassword;
|
||||
|
||||
// 创建时间范围过滤
|
||||
private Date[] createdAt;
|
||||
|
||||
// 排序控制
|
||||
private String sortField;
|
||||
private String sortAlgo;
|
||||
|
||||
}
|
38
src/main/resources/mapper/UserMapper.xml
Normal file
38
src/main/resources/mapper/UserMapper.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?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="xyz.playedu.api.mapper.UserMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.User">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="email" column="email" jdbcType="VARCHAR"/>
|
||||
<result property="nickname" column="nickname" jdbcType="VARCHAR"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="avatar" column="avatar" jdbcType="VARCHAR"/>
|
||||
<result property="password" column="password" jdbcType="VARCHAR"/>
|
||||
<result property="salt" column="salt" jdbcType="VARCHAR"/>
|
||||
<result property="idCard" column="id_card" jdbcType="VARCHAR"/>
|
||||
<result property="credit1" column="credit1" jdbcType="INTEGER"/>
|
||||
<result property="createIp" column="create_ip" jdbcType="VARCHAR"/>
|
||||
<result property="createCity" column="create_city" jdbcType="VARCHAR"/>
|
||||
<result property="isActive" column="is_active" jdbcType="TINYINT"/>
|
||||
<result property="isLock" column="is_lock" jdbcType="TINYINT"/>
|
||||
<result property="isVerify" column="is_verify" jdbcType="TINYINT"/>
|
||||
<result property="verifyAt" column="verify_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="isSetPassword" column="is_set_password" jdbcType="TINYINT"/>
|
||||
<result property="loginAt" column="login_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,email,nickname,
|
||||
name,avatar,password,
|
||||
salt,id_card,credit1,
|
||||
create_ip,create_city,is_active,
|
||||
is_lock,is_verify,verify_at,
|
||||
is_set_password,login_at,created_at,
|
||||
updated_at
|
||||
</sql>
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user