This commit is contained in:
LittleBoy 2022-12-05 00:23:46 +08:00
parent 11226f53ea
commit 158b6a5163
8 changed files with 130 additions and 18 deletions

View File

@ -3,14 +3,18 @@ package me.xiaoyan.point.api.controller.admin;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.xiaoyan.point.api.error.BizException; import me.xiaoyan.point.api.error.BizException;
import me.xiaoyan.point.api.pojo.UserInfo;
import me.xiaoyan.point.api.pojo.vo.GoodsQueryParam;
import me.xiaoyan.point.api.pojo.vo.PageDataResult;
import me.xiaoyan.point.api.pojo.vo.UserAdminInfo; import me.xiaoyan.point.api.pojo.vo.UserAdminInfo;
import me.xiaoyan.point.api.pojo.vo.UserQueryParam;
import me.xiaoyan.point.api.service.UserInfoService;
import me.xiaoyan.point.api.util.DataStatus;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap; import java.util.HashMap;
@RestController @RestController
@ -19,6 +23,9 @@ import java.util.HashMap;
public class UserAdminController { public class UserAdminController {
private HashMap<String, UserAdminInfo> userStoreMap = new HashMap<>(); private HashMap<String, UserAdminInfo> userStoreMap = new HashMap<>();
@Resource
private UserInfoService userInfoService;
@PostConstruct @PostConstruct
public void initUserStore() { public void initUserStore() {
log.info("初始化用户数据"); log.info("初始化用户数据");
@ -57,4 +64,13 @@ public class UserAdminController {
return "ok"; return "ok";
} }
@PostMapping("/list")
public PageDataResult list(@RequestBody UserQueryParam param) {
return PageDataResult.convert(userInfoService.queryByPage(param));
}
@GetMapping("/remove")
public boolean remove(int id) {
return userInfoService.updateById(UserInfo.builder().id(id).status(DataStatus.DELETE).build());
}
} }

View File

@ -64,4 +64,6 @@ public class UserInfo implements Serializable {
private Integer status; private Integer status;
@TableField(exist = false) @TableField(exist = false)
private Point pointInfo; private Point pointInfo;
@TableField(exist = false)
private UserInfo parent;
} }

View File

@ -0,0 +1,9 @@
package me.xiaoyan.point.api.pojo.vo;
import lombok.Data;
@Data
public class UserQueryParam extends PageParam {
private String nickname;
private String openId;
}

View File

@ -1,8 +1,10 @@
package me.xiaoyan.point.api.service; package me.xiaoyan.point.api.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import me.xiaoyan.point.api.pojo.UserInfo; import me.xiaoyan.point.api.pojo.UserInfo;
import me.xiaoyan.point.api.pojo.vo.UserLoginData; import me.xiaoyan.point.api.pojo.vo.UserLoginData;
import me.xiaoyan.point.api.pojo.vo.UserQueryParam;
public interface UserInfoService extends IService<UserInfo> { public interface UserInfoService extends IService<UserInfo> {
@ -16,4 +18,6 @@ public interface UserInfoService extends IService<UserInfo> {
UserInfo getInfoById(Integer uid); UserInfo getInfoById(Integer uid);
UserInfo getInfoByCode(String code); UserInfo getInfoByCode(String code);
Page<UserInfo> queryByPage(UserQueryParam param);
} }

View File

@ -1,10 +1,15 @@
package me.xiaoyan.point.api.service.impl; package me.xiaoyan.point.api.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson; import com.google.gson.Gson;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.xiaoyan.point.api.pojo.vo.UserQueryParam;
import me.xiaoyan.point.api.util.DataStatus;
import me.xiaoyan.point.api.util.QueryWrapperUtil;
import me.xiaoyan.point.api.util.WechatDecryptDataUtil; import me.xiaoyan.point.api.util.WechatDecryptDataUtil;
import me.xiaoyan.point.api.error.BizException; import me.xiaoyan.point.api.error.BizException;
import me.xiaoyan.point.api.mapper.UserInfoMapper; import me.xiaoyan.point.api.mapper.UserInfoMapper;
@ -28,6 +33,7 @@ import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
@Service @Service
@Slf4j @Slf4j
@ -157,4 +163,31 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
// 使用openid查询用户信息 // 使用openid查询用户信息
return this.getBaseMapper().selectOneByOpenId(sessionData.getOpenid()); return this.getBaseMapper().selectOneByOpenId(sessionData.getOpenid());
} }
private UserInfo getParent(int parentUid) {
if (parentUid < 1) return null;
return getBaseMapper().selectById(parentUid);
}
@Override
public Page<UserInfo> queryByPage(UserQueryParam param) {
QueryWrapper q = QueryWrapperUtil
.builder()
// 查询标题
.eq("nickname", param.getNickname())
.eq("open_id", param.getOpenId())
.ne("status", DataStatus.DELETE)
.build();
Page<UserInfo> page = getBaseMapper().selectPage(param.getPage(), q);
List<UserInfo> records = page.getRecords();
if (records != null && records.size() > 0) {
records.forEach(u -> {
u.setPointInfo(pointService.getById(u.getId()));
u.setParent(getParent(u.getParentId()));
});
}
return page;
}
} }

View File

@ -0,0 +1,7 @@
package me.xiaoyan.point.api.util;
public class DataStatus {
public static final int NORMAL = 1;
public static final int DELETE = 0;
}

View File

@ -0,0 +1,36 @@
package me.xiaoyan.point.api.util;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.util.StringUtils;
public class QueryWrapperUtil {
private QueryWrapper q;
private QueryWrapperUtil(QueryWrapper queryWrapper) {
this.q = queryWrapper;
}
public static QueryWrapperUtil builder() {
return new QueryWrapperUtil(new QueryWrapper());
}
public static QueryWrapperUtil builder(QueryWrapper queryWrapper) {
return new QueryWrapperUtil(queryWrapper);
}
public QueryWrapperUtil eq(String column, String value) {
if (StringUtils.hasText(value)) {
q.eq(column, value);
}
return this;
}
public QueryWrapperUtil ne(String column, Object value) {
q.ne(column, value);
return this;
}
public QueryWrapper build() {
return this.q;
}
}

View File

@ -14,7 +14,8 @@ create table userinfo
first_login_time datetime default current_timestamp, first_login_time datetime default current_timestamp,
update_time datetime null on update current_timestamp, update_time datetime null on update current_timestamp,
status tinyint(2) default 1 status tinyint(2) default 1
) engine = innodb collate = 'utf8mb4_general_ci' comment '用户表'; ) engine = innodb
collate = 'utf8mb4_general_ci' comment '用户表';
create table point create table point
( (
@ -24,7 +25,8 @@ create table point
expire_point int(10) null default 0, expire_point int(10) null default 0,
expire_time datetime null, expire_time datetime null,
update_time datetime null on update current_timestamp update_time datetime null on update current_timestamp
) engine = innodb collate = 'utf8mb4_general_ci' comment '积分表'; ) engine = innodb
collate = 'utf8mb4_general_ci' comment '积分表';
create table point_record create table point_record
( (
id bigint(15) primary key auto_increment, id bigint(15) primary key auto_increment,
@ -34,7 +36,8 @@ create table point_record
reason varchar(100) not null, reason varchar(100) not null,
valid_time datetime null, valid_time datetime null,
expire_time datetime null expire_time datetime null
) engine = innodb collate = 'utf8mb4_general_ci' comment '积分记录表'; ) engine = innodb
collate = 'utf8mb4_general_ci' comment '积分记录表';
create table sign_record create table sign_record
( (
@ -43,8 +46,9 @@ create table sign_record
point int(10) not null, point int(10) not null,
ip varchar(50) not null, ip varchar(50) not null,
create_time datetime default current_timestamp create_time datetime default current_timestamp
) engine = innodb collate = 'utf8mb4_general_ci' comment '打卡记录表'; ) engine = innodb
collate = 'utf8mb4_general_ci' comment '打卡记录表';
drop table if exists goods;
create table goods create table goods
( (
id bigint(15) primary key auto_increment, id bigint(15) primary key auto_increment,
@ -64,7 +68,8 @@ create table goods
update_time datetime null on update current_timestamp, update_time datetime null on update current_timestamp,
status tinyint(2) default 1, status tinyint(2) default 1,
index ix_title (title) index ix_title (title)
) engine = innodb comment '商品表'; ) engine = innodb
collate = 'utf8mb4_general_ci' comment '商品表';
create table order_info create table order_info
( (
@ -76,4 +81,4 @@ create table order_info
create_time datetime default current_timestamp, create_time datetime default current_timestamp,
update_time datetime null on update current_timestamp, update_time datetime null on update current_timestamp,
status tinyint(2) default 1 comment '订单状态(0:已删除 1:待确认 2:已取消 3:已完成)' status tinyint(2) default 1 comment '订单状态(0:已删除 1:待确认 2:已取消 3:已完成)'
) comment '订单表'; ) collate = 'utf8mb4_general_ci' comment '订单表';