Search in sources :

Example 1 with User

use of com.moxi.mogublog.commons.entity.User in project mogu_blog_v2 by moxi624.

the class CommentServiceImpl method getPageList.

@Override
public IPage<Comment> getPageList(CommentVO commentVO) {
    QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
    if (StringUtils.isNotEmpty(commentVO.getKeyword()) && !StringUtils.isEmpty(commentVO.getKeyword().trim())) {
        queryWrapper.like(SQLConf.CONTENT, commentVO.getKeyword().trim());
    }
    if (commentVO.getType() != null) {
        queryWrapper.eq(SQLConf.TYPE, commentVO.getType());
    }
    if (StringUtils.isNotEmpty(commentVO.getSource()) && !SysConf.ALL.equals(commentVO.getSource())) {
        queryWrapper.eq(SQLConf.SOURCE, commentVO.getSource());
    }
    if (StringUtils.isNotEmpty(commentVO.getUserName())) {
        String userName = commentVO.getUserName();
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.like(SQLConf.NICK_NAME, userName);
        userQueryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
        List<User> list = userService.list(userQueryWrapper);
        if (list.size() > 0) {
            List<String> userUid = new ArrayList<>();
            list.forEach(item -> {
                userUid.add(item.getUid());
            });
            queryWrapper.in(SQLConf.USER_UID, userUid);
        } else {
            // 当没有查询到用户时,默认UID
            queryWrapper.in(SQLConf.USER_UID, SysConf.DEFAULT_UID);
        }
    }
    Page<Comment> page = new Page<>();
    page.setCurrent(commentVO.getCurrentPage());
    page.setSize(commentVO.getPageSize());
    queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
    IPage<Comment> pageList = commentService.page(page, queryWrapper);
    List<Comment> commentList = pageList.getRecords();
    Set<String> userUidSet = new HashSet<>();
    Set<String> blogUidSet = new HashSet<>();
    commentList.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getUserUid())) {
            userUidSet.add(item.getUserUid());
        }
        if (StringUtils.isNotEmpty(item.getToUserUid())) {
            userUidSet.add(item.getToUserUid());
        }
        if (StringUtils.isNotEmpty(item.getBlogUid())) {
            blogUidSet.add(item.getBlogUid());
        }
    });
    // 获取博客
    Collection<Blog> blogList = new ArrayList<>();
    if (blogUidSet.size() > 0) {
        blogList = blogService.listByIds(blogUidSet);
    }
    Map<String, Blog> blogMap = new HashMap<>();
    blogList.forEach(item -> {
        // 评论管理并不需要查看博客内容,因此将其排除
        item.setContent("");
        blogMap.put(item.getUid(), item);
    });
    // 获取头像
    Collection<User> userCollection = new ArrayList<>();
    if (userUidSet.size() > 0) {
        userCollection = userService.listByIds(userUidSet);
    }
    final StringBuffer fileUids = new StringBuffer();
    userCollection.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getAvatar())) {
            fileUids.append(item.getAvatar() + SysConf.FILE_SEGMENTATION);
        }
    });
    String pictureList = null;
    if (fileUids != null) {
        pictureList = this.pictureFeignClient.getPicture(fileUids.toString(), SysConf.FILE_SEGMENTATION);
    }
    List<Map<String, Object>> picList = webUtil.getPictureMap(pictureList);
    Map<String, String> pictureMap = new HashMap<>();
    picList.forEach(item -> {
        pictureMap.put(item.get(SQLConf.UID).toString(), item.get(SQLConf.URL).toString());
    });
    Map<String, User> userMap = new HashMap<>();
    userCollection.forEach(item -> {
        // 判断头像是否为空
        if (pictureMap.get(item.getAvatar()) != null) {
            item.setPhotoUrl(pictureMap.get(item.getAvatar()));
        }
        userMap.put(item.getUid(), item);
    });
    for (Comment item : commentList) {
        try {
            ECommentSource commentSource = ECommentSource.valueOf(item.getSource());
            item.setSourceName(commentSource.getName());
        } catch (Exception e) {
            log.error("ECommentSource 转换异常");
        }
        if (StringUtils.isNotEmpty(item.getUserUid())) {
            item.setUser(userMap.get(item.getUserUid()));
        }
        if (StringUtils.isNotEmpty(item.getToUserUid())) {
            item.setToUser(userMap.get(item.getToUserUid()));
        }
        if (StringUtils.isNotEmpty(item.getBlogUid())) {
            item.setBlog(blogMap.get(item.getBlogUid()));
        }
    }
    pageList.setRecords(commentList);
    return pageList;
}
Also used : User(com.moxi.mogublog.commons.entity.User) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) ECommentSource(com.moxi.mougblog.base.enums.ECommentSource) Blog(com.moxi.mogublog.commons.entity.Blog) Comment(com.moxi.mogublog.commons.entity.Comment) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) DeleteException(com.moxi.mougblog.base.exception.exceptionType.DeleteException)

Example 2 with User

use of com.moxi.mogublog.commons.entity.User in project mogu_blog_v2 by moxi624.

the class UserServiceImpl method deleteUser.

@Override
public String deleteUser(UserVO userVO) {
    User user = userService.getById(userVO.getUid());
    user.setStatus(EStatus.DISABLED);
    user.setUpdateTime(new Date());
    user.updateById();
    return ResultUtil.successWithMessage(MessageConf.DELETE_SUCCESS);
}
Also used : User(com.moxi.mogublog.commons.entity.User)

Example 3 with User

use of com.moxi.mogublog.commons.entity.User in project mogu_blog_v2 by moxi624.

the class UserServiceImpl method insertUserInfo.

@Override
public User insertUserInfo(HttpServletRequest request, String response) {
    Map<String, Object> map = JsonUtils.jsonToMap(response);
    boolean exist = false;
    User user = new User();
    Map<String, Object> data = JsonUtils.jsonToMap(JsonUtils.objectToJson(map.get(SysConf.DATA)));
    if (data.get(SysConf.UUID) != null && data.get(SysConf.SOURCE) != null) {
        if (getUserBySourceAnduuid(data.get(SysConf.SOURCE).toString(), data.get(SysConf.UUID).toString()) != null) {
            user = getUserBySourceAnduuid(data.get(SysConf.SOURCE).toString(), data.get(SysConf.UUID).toString());
            exist = true;
        }
    } else {
        log.error("未获取到uuid或source");
        throw new InsertException(ErrorCode.INSERT_DEFAULT_ERROR, MessageConf.INSERT_DEFAULT_ERROR);
    }
    if (data.get(SysConf.EMAIL) != null) {
        user.setEmail(data.get(SysConf.EMAIL).toString());
    }
    if (data.get(SysConf.AVATAR) != null) {
        user.setAvatar(data.get(SysConf.AVATAR).toString());
    }
    if (data.get(SysConf.NICKNAME) != null) {
        user.setNickName(data.get(SysConf.NICKNAME).toString());
    }
    user.setLoginCount(user.getLoginCount() + 1);
    user.setLastLoginTime(new Date());
    user.setLastLoginIp(IpUtils.getIpAddr(request));
    if (exist) {
        user.updateById();
    } else {
        user.setUuid(data.get(SysConf.UUID).toString());
        user.setSource(data.get(SysConf.SOURCE).toString());
        user.setUserName("mg".concat(user.getSource()).concat(user.getUuid()));
        // 产生(0,999999]之间的随机数
        Integer randNum = (int) (Math.random() * (999999) + 1);
        // 进行六位数补全
        String workPassWord = String.format("%06d", randNum);
        user.setPassWord(workPassWord);
        user.insert();
    }
    return user;
}
Also used : User(com.moxi.mogublog.commons.entity.User) InsertException(com.moxi.mougblog.base.exception.exceptionType.InsertException)

Example 4 with User

use of com.moxi.mogublog.commons.entity.User in project mogu_blog_v2 by moxi624.

the class LoginRestApi method bindUserEmail.

@ApiOperation(value = "激活用户账号", notes = "激活用户账号")
@GetMapping("/activeUser/{token}")
public String bindUserEmail(@PathVariable("token") String token) {
    // 从redis中获取用户信息
    String userInfo = redisUtil.get(RedisConf.ACTIVATE_USER + RedisConf.SEGMENTATION + token);
    if (StringUtils.isEmpty(userInfo)) {
        return ResultUtil.result(SysConf.ERROR, MessageConf.INVALID_TOKEN);
    }
    User user = JsonUtils.jsonToPojo(userInfo, User.class);
    if (EStatus.FREEZE != user.getStatus()) {
        return ResultUtil.result(SysConf.ERROR, "用户账号已经被激活");
    }
    user.setStatus(EStatus.ENABLE);
    user.updateById();
    // 更新成功后,需要把该用户名下其它未激活的用户删除【删除】
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq(SQLConf.USER_NAME, user.getUserName());
    queryWrapper.ne(SQLConf.UID, user.getUid());
    queryWrapper.ne(SQLConf.STATUS, EStatus.ENABLE);
    List<User> userList = userService.list(queryWrapper);
    if (userList.size() > 0) {
        List<String> uidList = new ArrayList<>();
        userList.forEach(item -> {
            uidList.add(item.getUid());
        });
        // 移除所有未激活的用户【该用户名下的】
        userService.removeByIds(uidList);
    }
    return ResultUtil.result(SysConf.SUCCESS, MessageConf.OPERATION_SUCCESS);
}
Also used : User(com.moxi.mogublog.commons.entity.User) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ArrayList(java.util.ArrayList) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with User

use of com.moxi.mogublog.commons.entity.User in project mogu_blog_v2 by moxi624.

the class LoginRestApi method register.

@ApiOperation(value = "用户注册", notes = "用户注册")
@PostMapping("/register")
public String register(@Validated({ Insert.class }) @RequestBody UserVO userVO, BindingResult result) {
    ThrowableUtils.checkParamArgument(result);
    // 判断是否开启登录方式
    Boolean isOpenLoginType = webConfigService.isOpenLoginType(RedisConf.PASSWORD);
    if (!isOpenLoginType) {
        return ResultUtil.result(SysConf.ERROR, "后台未开启注册功能!");
    }
    if (userVO.getUserName().length() < Constants.NUM_FIVE || userVO.getUserName().length() >= Constants.NUM_TWENTY || userVO.getPassWord().length() < Constants.NUM_FIVE || userVO.getPassWord().length() >= Constants.NUM_TWENTY) {
        return ResultUtil.result(SysConf.ERROR, MessageConf.PARAM_INCORRECT);
    }
    HttpServletRequest request = RequestHolder.getRequest();
    String ip = IpUtils.getIpAddr(request);
    Map<String, String> map = IpUtils.getOsAndBrowserInfo(request);
    QueryWrapper<User> queryWrapper = new QueryWrapper<>();
    queryWrapper.and(wrapper -> wrapper.eq(SQLConf.USER_NAME, userVO.getUserName()).or().eq(SQLConf.EMAIL, userVO.getEmail()));
    queryWrapper.eq(SysConf.STATUS, EStatus.ENABLE);
    queryWrapper.last(SysConf.LIMIT_ONE);
    User user = userService.getOne(queryWrapper);
    if (user != null) {
        return ResultUtil.result(SysConf.ERROR, MessageConf.USER_OR_EMAIL_EXIST);
    }
    user = new User();
    user.setUserName(userVO.getUserName());
    user.setNickName(userVO.getNickName());
    user.setPassWord(MD5Utils.string2MD5(userVO.getPassWord()));
    user.setEmail(userVO.getEmail());
    // 设置账号来源,蘑菇博客
    user.setSource(SysConf.MOGU);
    user.setLastLoginIp(ip);
    user.setBrowser(map.get(SysConf.BROWSER));
    user.setOs(map.get(SysConf.OS));
    // 判断是否开启用户邮件激活状态
    SystemConfig systemConfig = systemConfigService.getConfig();
    String openEmailActivate = systemConfig.getOpenEmailActivate();
    String resultMessage = "注册成功";
    if (EOpenStatus.OPEN.equals(openEmailActivate)) {
        user.setStatus(EStatus.FREEZE);
    } else {
        // 未开启注册用户邮件激活,直接设置成激活状态
        user.setStatus(EStatus.ENABLE);
    }
    user.insert();
    // 判断是否需要发送邮件通知
    if (EOpenStatus.OPEN.equals(openEmailActivate)) {
        // 生成随机激活的token
        String token = StringUtils.getUUID();
        // 过滤密码
        user.setPassWord("");
        // 将从数据库查询的数据缓存到redis中,用于用户邮箱激活,1小时后过期
        redisUtil.setEx(RedisConf.ACTIVATE_USER + RedisConf.SEGMENTATION + token, JsonUtils.objectToJson(user), 1, TimeUnit.HOURS);
        // 发送邮件,进行账号激活
        rabbitMqUtil.sendActivateEmail(user, token);
        resultMessage = "注册成功,请登录邮箱进行账号激活";
    }
    return ResultUtil.result(SysConf.SUCCESS, resultMessage);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SystemConfig(com.moxi.mogublog.commons.entity.SystemConfig) User(com.moxi.mogublog.commons.entity.User) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

User (com.moxi.mogublog.commons.entity.User)18 ApiOperation (io.swagger.annotations.ApiOperation)10 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)6 SystemConfig (com.moxi.mogublog.commons.entity.SystemConfig)3 JSONObject (com.alibaba.fastjson.JSONObject)2 IPage (com.baomidou.mybatisplus.core.metadata.IPage)2 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Blog (com.moxi.mogublog.commons.entity.Blog)1 Comment (com.moxi.mogublog.commons.entity.Comment)1 Feedback (com.moxi.mogublog.commons.entity.Feedback)1 Link (com.moxi.mogublog.commons.entity.Link)1 ECommentSource (com.moxi.mougblog.base.enums.ECommentSource)1 DeleteException (com.moxi.mougblog.base.exception.exceptionType.DeleteException)1 InsertException (com.moxi.mougblog.base.exception.exceptionType.InsertException)1 List (java.util.List)1 Map (java.util.Map)1 AuthResponse (me.zhyd.oauth.model.AuthResponse)1