package com.ld.poetry.service.impl;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ld.poetry.config.PoetryResult;
import com.ld.poetry.constants.CommonConst;
import com.ld.poetry.dao.UserMapper;
import com.ld.poetry.entity.User;
import com.ld.poetry.entity.WebInfo;
import com.ld.poetry.entity.WeiYan;
import com.ld.poetry.enums.PoetryEnum;
import com.ld.poetry.handle.PoetryRuntimeException;
import com.ld.poetry.im.http.dao.ImChatGroupUserMapper;
import com.ld.poetry.im.http.dao.ImChatUserFriendMapper;
import com.ld.poetry.im.http.entity.ImChatGroupUser;
import com.ld.poetry.im.http.entity.ImChatUserFriend;
import com.ld.poetry.im.websocket.ImConfigConst;
import com.ld.poetry.im.websocket.TioUtil;
import com.ld.poetry.im.websocket.TioWebsocketStarter;
import com.ld.poetry.service.UserService;
import com.ld.poetry.service.WeiYanService;
import com.ld.poetry.utils.*;
import com.ld.poetry.utils.cache.PoetryCache;
import com.ld.poetry.utils.mail.MailUtil;
import com.ld.poetry.vo.BaseRequestVO;
import com.ld.poetry.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import org.tio.core.Tio;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
* <p>
* 用户信息表 服务实现类
* </p>
*
* @author sara
* @since 2021-08-12
*/
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
@Autowired
private WeiYanService weiYanService;
@Autowired
private ImChatGroupUserMapper imChatGroupUserMapper;
@Autowired
private ImChatUserFriendMapper imChatUserFriendMapper;
@Autowired
private MailUtil mailUtil;
@Value("${user.code.format}")
private String codeFormat;
@Override
public PoetryResult<UserVO> login(String account, String password, Boolean isAdmin) {
password = new String(SecureUtil.aes(CommonConst.CRYPOTJS_KEY.getBytes(StandardCharsets.UTF_8)).decrypt(password));
User one = lambdaQuery().and(wrapper -> wrapper
.eq(User::getUsername, account)
.or()
.eq(User::getEmail, account)
.or()
.eq(User::getPhoneNumber, account))
.eq(User::getPassword, DigestUtils.md5DigestAsHex(password.getBytes()))
.one();
if (one == null) {
return PoetryResult.fail("账号/密码错误,请重新输入!");
}
if (!one.getUserStatus()) {
return PoetryResult.fail("账号被冻结!");
}
String adminToken = "";
String userToken = "";
if (isAdmin) {
if (one.getUserType() != PoetryEnum.USER_TYPE_ADMIN.getCode() && one.getUserType() != PoetryEnum.USER_TYPE_DEV.getCode()) {
return PoetryResult.fail("请输入管理员账号!");
}
if (PoetryCache.get(CommonConst.ADMIN_TOKEN + one.getId()) != null) {
adminToken = (String) PoetryCache.get(CommonConst.ADMIN_TOKEN + one.getId());
}
} else {
if (PoetryCache.get(CommonConst.USER_TOKEN + one.getId()) != null) {
userToken = (String) PoetryCache.get(CommonConst.USER_TOKEN + one.getId());
}
}
if (isAdmin && !StringUtils.hasText(adminToken)) {
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
adminToken = CommonConst.ADMIN_ACCESS_TOKEN + uuid;
PoetryCache.put(adminToken, one, CommonConst.TOKEN_EXPIRE);
PoetryCache.put(CommonConst.ADMIN_TOKEN + one.getId(), adminToken, CommonConst.TOKEN_EXPIRE);
} else if (!isAdmin && !StringUtils.hasText(userToken)) {
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
userToken = CommonConst.USER_ACCESS_TOKEN + uuid;
PoetryCache.put(userToken, one, CommonConst.TOKEN_EXPIRE);
PoetryCache.put(CommonConst.USER_TOKEN + one.getId(), userToken, CommonConst.TOKEN_EXPIRE);
}
UserVO userVO = new UserVO();
BeanUtils.copyProperties(one, userVO);
userVO.setPassword(null);
if (isAdmin && one.getUserType() == PoetryEnum.USER_TYPE_ADMIN.getCode()) {
userVO.setIsBoss(true);
}
if (isAdmin) {
userVO.setAccessToken(adminToken);
} else {
userVO.setAccessToken(userToken);
}
return PoetryResult.success(userVO);
}
@Override
public PoetryResult exit() {
String token = PoetryUtil.getToken();
Integer userId = PoetryUtil.getUserId();
if (token.contains(CommonConst.USER_ACCESS_TOKEN)) {
PoetryCache.remove(CommonConst.USER_TOKEN + userId);
TioWebsocketStarter tioWebsocketStarter = TioUtil.getTio();
if (tioWebsocketStarter != null) {
Tio.removeUser(tioWebsocketStarter.getServerTioConfig(), String.valueOf(userId), "remove user");
}
} else if (token.contains(CommonConst.ADMIN_ACCESS_TOKEN)) {
PoetryCache.remove(CommonConst.ADMIN_TOKEN + userId);
}
PoetryCache.remove(token);
return PoetryResult.success();
}
@Override
public PoetryResult<UserVO> regist(UserVO user) {
String regex = "\\d{11}";
if (user.getUsername().matches(regex)) {
return PoetryResult.fail("用户名不能为11位数字!");
}
if (user.getUsername().contains("@")) {
return PoetryResult.fail("用户名不能包含@!");
}
if (StringUtils.hasText(user.getPhoneNumber()) && StringUtils.hasText(user.getEmail())) {
return PoetryResult.fail("手机号与邮箱只能选择其中一个!");
}
if (StringUtils.hasText(user.getPhoneNumber())) {
Integer codeCache = (Integer) PoetryCache.get(CommonConst.FORGET_PASSWORD + user.getPhoneNumber() + "_1");
if (codeCache == null || codeCache != Integer.parseInt(user.getCode())) {
return PoetryResult.fail("验证码错误!");
}
PoetryCache.remove(CommonConst.FORGET_PASSWORD + user.getPhoneNumber() + "_1");
} else if (StringUtils.hasText(user.getEmail())) {
Integer codeCache = (Integer) PoetryCache.get(CommonConst.FORGET_PASSWORD + user.getEmail() + "_2");
if (codeCache == null || codeCache != Integer.parseInt(user.getCode())) {
return PoetryResult.fail("验证码错误!");
}
PoetryCache.remove(CommonConst.FORGET_PASSWORD + user.getEmail() + "_2");
} else {
return PoetryResult.fail("请输入邮箱或手机号!");
}
user.setPassword(new String(SecureUtil.aes(CommonConst.CRYPOTJS_KEY.getBytes(StandardCharsets.UTF_8)).decrypt(user.getPassword())));
Integer count = lambdaQuery().eq(User::getUsername, user.getUsername()).count();
if (count != 0) {
return PoetryResult.fail("用户名重复!");
}
if (StringUtils.hasText(user.getPhoneNumber())) {
Integer phoneNumberCount = lambdaQuery().eq(User::getPhoneNumber, user.getPhoneNumber()).count();
if
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
最美POETIZE个人博客系统源码 这是一个 SpringBoot + Vue2 + Vue3 的产物,支持移动端自适应,配有完备的前台和后台管理功能。 网站分两个模块: 博客系统:具有文章,表白墙,图片墙,收藏夹,乐曲,视频播放,留言,友链,时间线,后台管理等功能。 聊天室系统:具有朋友圈(时间线),好友,群等功能。
资源推荐
资源详情
资源评论
收起资源包目录
最美POETIZE个人博客系统源码
(322个子文件)
.browserslistrc 30B
.browserslistrc 30B
font-awesome.min.css 30KB
markdown-highlight.css 6KB
index.css 5KB
animation.css 3KB
animation.css 2KB
color.css 2KB
color.css 2KB
tocbot.css 1KB
index.css 1KB
.editorconfig 121B
.editorconfig 121B
fontawesome-webfont.eot 162KB
spring.factories 106B
.gitignore 395B
.gitignore 395B
.gitignore 231B
.gitignore 231B
index.html 2KB
index.html 1003B
UserServiceImpl.java 25KB
ArticleServiceImpl.java 18KB
ImChatGroupUserController.java 18KB
ImChatGroupController.java 11KB
CommonQuery.java 10KB
CommentServiceImpl.java 9KB
ImWsMsgHandler.java 8KB
MailSendUtil.java 7KB
QiniuUtil.java 7KB
ImChatUserMessageController.java 7KB
WebInfoController.java 6KB
CommonConst.java 6KB
ImChatUserFriendController.java 6KB
PoetryUtil.java 6KB
MailUtil.java 6KB
WeiYanController.java 5KB
ResourceController.java 5KB
ImChatUserGroupMessageController.java 5KB
ResourceAggregationController.java 5KB
UserController.java 5KB
FamilyController.java 5KB
AdminUserController.java 4KB
SortLabelController.java 4KB
LoginCheckAspect.java 4KB
LocalUtil.java 3KB
PoetryApplicationRunner.java 3KB
ImServerAioListener.java 3KB
CustomEnvironmentPostProcessor.java 3KB
CodeGenerator.java 3KB
FriendController.java 3KB
PoetryCache.java 3KB
ArticleController.java 3KB
AdminArticleController.java 3KB
SysConfigController.java 3KB
MessageCache.java 3KB
SaveCheckAspect.java 3KB
AdminCommentController.java 3KB
PictureController.java 2KB
TreeHoleController.java 2KB
Article.java 2KB
ImConfigConst.java 2KB
MusicController.java 2KB
FileFilter.java 2KB
CommentController.java 2KB
User.java 2KB
FileStorageService.java 2KB
TioWebsocketStarter.java 2KB
Family.java 2KB
WebInfo.java 2KB
CollectController.java 2KB
PoetryExceptionHandler.java 2KB
AdminController.java 2KB
PoetryFilter.java 2KB
FamilyVO.java 2KB
CommentTypeEnum.java 2KB
StringUtil.java 2KB
ArticleVO.java 2KB
ScheduleTask.java 2KB
Resource.java 2KB
Comment.java 2KB
UserService.java 1KB
CommentVO.java 1KB
HistoryInfoMapper.java 1KB
ImChatGroup.java 1KB
ResourcePath.java 1KB
WeiYan.java 1KB
PoetryResult.java 1KB
ImChatGroupUser.java 1KB
Sort.java 1KB
HistoryInfo.java 1KB
ImChatUserMessage.java 1KB
ImChatUserGroupMessage.java 1KB
GroupVO.java 1KB
ImIpStatListener.java 1KB
UserVO.java 1KB
ImChatUserFriend.java 1KB
SysConfig.java 1KB
CorsConfig.java 1KB
QiniuController.java 1KB
共 322 条
- 1
- 2
- 3
- 4
资源评论
- 盾墙2024-12-17资源有很好的参考价值,总算找到了自己需要的资源啦。
- 2301_774850002024-05-15终于找到了超赞的宝藏资源,果断冲冲冲,支持!
百创科技
- 粉丝: 2042
- 资源: 261
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Power Quality Disturbance:基于MATLAB Simulink的各种电能质量扰动仿真模型,包括配电线路故障、感应电机启动、变压器励磁、单相 三相非线性负载等模型,可用于模拟各种
- 教务管理系统(jsp+servlet+mysql)130225.rar
- 教务管理系统(jsp+servlet+mysql).rar
- 酒店订单管理系统(Jsp+servlet+mysql)130224.rar
- 酒店订单管理系统(Jsp+servlet+mysql).rar
- 乐趣大型购物系统 v1.1(jsp+servlet+mysql).rar
- 聊天系统(java+applet)130227.rar
- 龙门物流管理系统(Ext+SSH).rar
- 乐趣大型购物系统 v1.1(jsp+servlet+mysql)130223.rar
- 基于动态窗口算法的AGV仿真避障 可设置起点目标点,设置地图,设置移动障碍物起始点目标点,未知静态障碍物 动态窗口方法(DynamicWindowApproach) 是一种可以实现实时避障的局部规划算
- 内容管理系统(hibernate3+struts2+spring2).rar
- 内容管理系统(hibernate3+struts2+spring2)130224.rar
- 企业费用管理系统(SSH+Oracle).rar
- 企业费用管理系统(SSH+Oracle)130222.rar
- 企业级新闻系统(SSH+MYSQL).rar
- 通用的在线考试系统(jsp+struts+hibernate+oracle).rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功