增加用户管理功能
This commit is contained in:
parent
2350e786c1
commit
992d987c01
|
|
@ -0,0 +1,57 @@
|
|||
package com.mdd.admin.controller.user;
|
||||
|
||||
import com.mdd.admin.service.user.IUserService;
|
||||
import com.mdd.admin.validate.common.PageParam;
|
||||
import com.mdd.admin.vo.user.UserVo;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.entity.user.User;
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("api/user")
|
||||
public class UserController {
|
||||
|
||||
@Resource
|
||||
IUserService iUserService;
|
||||
|
||||
/**
|
||||
* 用户列表
|
||||
*
|
||||
* @author fzr
|
||||
* @param pageParam 分页参数
|
||||
* @param params 搜索参数
|
||||
* @return Object
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public Object list(@Validated PageParam pageParam,
|
||||
@RequestParam Map<String, String> params) {
|
||||
PageResult<UserVo> list = iUserService.list(pageParam, params);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户详情
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 主键
|
||||
* @return Object
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
|
||||
UserVo vo = iUserService.detail(id);
|
||||
return AjaxResult.success(vo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.mdd.admin.service.user;
|
||||
|
||||
import com.mdd.admin.validate.common.PageParam;
|
||||
import com.mdd.admin.vo.user.UserVo;
|
||||
import com.mdd.common.core.PageResult;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户服务接口类
|
||||
*/
|
||||
public interface IUserService {
|
||||
|
||||
/**
|
||||
* 用户列表
|
||||
*
|
||||
* @author fzr
|
||||
* @param pageParam (分页参数)
|
||||
* @param params (搜索参数)
|
||||
* @return PageResult<UserVo>
|
||||
*/
|
||||
PageResult<UserVo> list(PageParam pageParam, Map<String, String> params);
|
||||
|
||||
UserVo detail(Integer id);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
package com.mdd.admin.service.user.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.mdd.admin.service.user.IUserService;
|
||||
import com.mdd.admin.validate.common.PageParam;
|
||||
import com.mdd.admin.vo.article.ArticleListVo;
|
||||
import com.mdd.admin.vo.user.UserVo;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.entity.user.User;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.utils.StringUtil;
|
||||
import com.mdd.common.utils.TimeUtil;
|
||||
import com.mdd.common.utils.UrlUtil;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl implements IUserService {
|
||||
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<UserVo> list(PageParam pageParam, Map<String, String> params) {
|
||||
Integer pageNo = pageParam.getPageNo();
|
||||
Integer pageSize = pageParam.getPageSize();
|
||||
|
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("is_delete", 0);
|
||||
queryWrapper.orderByDesc("id");
|
||||
queryWrapper.select(User.class, info->
|
||||
!info.getColumn().equals("is_delete") &&
|
||||
!info.getColumn().equals("delete_time") &&
|
||||
!info.getColumn().equals("update_time") &&
|
||||
!info.getColumn().equals("password") &&
|
||||
!info.getColumn().equals("salt")
|
||||
);
|
||||
|
||||
if (StringUtil.isNotEmpty(params.get("keyword"))) {
|
||||
String keyword = params.get("keyword");
|
||||
queryWrapper.nested(wq->wq
|
||||
.like("sn", keyword).or()
|
||||
.like("nickname", keyword).or()
|
||||
.like("mobile", keyword));
|
||||
}
|
||||
|
||||
userMapper.setSearch(queryWrapper, params, new String[]{
|
||||
"=:channel:int",
|
||||
"datetime:startTime-endTime@t.create_time:str"
|
||||
});
|
||||
|
||||
IPage<User> iPage = userMapper.selectPage( new Page<>(pageNo, pageSize), queryWrapper);
|
||||
|
||||
List<UserVo> list = new LinkedList<>();
|
||||
for (User user : iPage.getRecords()) {
|
||||
UserVo vo = new UserVo();
|
||||
BeanUtils.copyProperties(user, vo);
|
||||
|
||||
vo.setAvatar(UrlUtil.toAbsoluteUrl(user.getAvatar()));
|
||||
vo.setLastLoginTime(TimeUtil.timestampToDate(user.getLastLoginTime()));
|
||||
vo.setCreateTime(TimeUtil.timestampToDate(user.getCreateTime()));
|
||||
list.add(vo);
|
||||
}
|
||||
|
||||
return PageResult.iPageHandle(iPage.getTotal(), iPage.getCurrent(), iPage.getSize(), list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户详情
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 主键
|
||||
* @return UserVo
|
||||
*/
|
||||
@Override
|
||||
public UserVo detail(Integer id) {
|
||||
Assert.notNull(
|
||||
userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id")
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1")
|
||||
), "数据不存在!");
|
||||
|
||||
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select(User.class, info->
|
||||
!info.getColumn().equals("is_delete") &&
|
||||
!info.getColumn().equals("delete_time") &&
|
||||
!info.getColumn().equals("update_time") &&
|
||||
!info.getColumn().equals("password") &&
|
||||
!info.getColumn().equals("salt")
|
||||
)
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
UserVo vo = new UserVo();
|
||||
BeanUtils.copyProperties(user, vo);
|
||||
|
||||
vo.setAvatar(UrlUtil.toAbsoluteUrl(user.getAvatar()));
|
||||
vo.setLastLoginTime(TimeUtil.timestampToDate(user.getLastLoginTime()));
|
||||
vo.setCreateTime(TimeUtil.timestampToDate(user.getCreateTime()));
|
||||
return vo;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.mdd.admin.vo.user;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户Vo
|
||||
*/
|
||||
@Data
|
||||
public class UserVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer id;
|
||||
private String sn;
|
||||
private String avatar;
|
||||
private String realName;
|
||||
private String nickname;
|
||||
private String username;
|
||||
private String mobile;
|
||||
private String sex;
|
||||
private String channel;
|
||||
private String lastLoginIp;
|
||||
private String lastLoginTime;
|
||||
private String createTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.mdd.common.entity.user;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户实体
|
||||
*/
|
||||
@Data
|
||||
public class User implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
private Integer id; // 主键
|
||||
private String sn; // 编号
|
||||
private String avatar; // 用户头像
|
||||
private String realName; // 真实姓名
|
||||
private String nickname; // 用户昵称
|
||||
private String username; // 用户账号
|
||||
private String password; // 用户密码
|
||||
private String mobile; // 用户电话
|
||||
private String salt; // 加密盐巴
|
||||
private Integer sex; // 用户性别: [1=男, 2=女]
|
||||
private Integer is_delete; // 是否删除: [0=否, 1=是]
|
||||
private String lastLoginIp; // 最后登录IP
|
||||
private Long lastLoginTime; // 最后登录时间
|
||||
private Long createTime; // 创建时间
|
||||
private Long updateTime; // 更新时间
|
||||
private Long deleteTime; // 删除时间
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.mdd.common.mapper.user;
|
||||
|
||||
import com.mdd.common.core.basics.IBaseMapper;
|
||||
import com.mdd.common.entity.user.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 用户Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends IBaseMapper<User> {
|
||||
}
|
||||
Loading…
Reference in New Issue