package com.museum.service.impl;
import com.museum.constant.Constant;
import com.museum.domain.dto.LoginDTO;
import com.museum.domain.dto.PageDTO;
import com.museum.domain.dto.UserDTO;
import com.museum.domain.dto.UserInfoDTO;
import com.museum.domain.po.TUser;
import com.museum.domain.query.LoginQuery;
import com.museum.domain.query.UserQuery;
import com.museum.enums.CodeEnum;
import com.museum.manager.JWTManager;
import com.museum.manager.RedisManager;
import com.museum.mapper.TUserMapper;
import com.museum.service.UserService;
import com.museum.util.ExtBeanUtils;
import com.museum.util.JSONUtils;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Slf4j //lombok提供的日志注解
@Service
public class UserServiceImpl implements UserService {
@Resource
private TUserMapper tUserMapper;
@Resource
private PasswordEncoder passwordEncoder;
@Resource
private JWTManager jwtManager;
@Resource
private RedisManager redisManager;
@Resource
private ThreadPoolExecutor threadPoolExecutor;
/**
* 登录的业务实现
*
* @return
*/
@Override
public LoginDTO login(LoginQuery loginQuery) {
//根据登录账号查询用户
TUser tUser = tUserMapper.login(loginQuery.getLoginAct());
System.out.println(tUser);
if (ObjectUtils.isEmpty(tUser)) { //用户对象是空,说明用户不存在
return new LoginDTO(CodeEnum.LOGIN_ACCOUNT_NONE_EXIST);
}
//判断密码是否匹配
if (!passwordEncoder.matches(loginQuery.getLoginPwd(), tUser.getLoginPwd())) { //明文和密文不匹配的时候,那么久返回错误提示
return new LoginDTO(CodeEnum.LOGIN_PASSWORDD_ERROR);
}
//判断账号过期
if (tUser.getExpireTime().before(new Date())) {
//账号过期了
return new LoginDTO(CodeEnum.LOGIN_ACCOUNT_EXPIRE);
}
//判断账号状态是否锁定
if (tUser.getState() == Constant.USER_STATE_LOCK) {
return new LoginDTO(CodeEnum.LOGIN_ACCOUNT_LOCK);
}
//判断账号状态是否禁用
if (tUser.getState() == Constant.USER_STATE_DISABLED) {
return new LoginDTO(CodeEnum.LOGIN_ACCOUNT_DISABLED);
}
//以上都验证通过了,那么久登录成功了
UserDTO userDTO = new UserDTO();
//Spring框架提供了一个对象属性复制的工具类:BeanUtils
//把 tUser对象的所有属性值 复制到 userDTO对象属性里面去
//复制时,需要两个对象的属性名相同、类型也相同才能复制
BeanUtils.copyProperties(tUser, userDTO);
//1、生成token
//String token = "iuefhsudhfgjku"; // UUID.randomUUID().toString()
//使用uuid生成一个不重复的字符串作为token是可以的,但是我们后续需要从token中获取一些业务参数数据,如果用uuid没法实现;
//所以我们使用jwt生成一个token,因为jwt生成的token里面可以存放一些数据,并且这些数据可以解析出来;
String userJSON = JSONUtils.writeValueAsString(userDTO); //把userDTO转成json字符串
String token = jwtManager.createToken(userJSON);
//2、token写入redis
if (loginQuery.getIsRememberMe()) { //true, 选择了记住我
redisManager.setValue(Constant.REDIS_TOKEN_KEY + token, token, Constant.EXPIRE_TIME, TimeUnit.MINUTES);
} else {
redisManager.setValue(Constant.REDIS_TOKEN_KEY + token, token, Constant.DEFAUL_EXPIRE_TIME, TimeUnit.MINUTES);
}
//把token设置到返回对象中
userDTO.setToken(token);
//更新登录时间 (异步执行)
/* 1、创建一个线程去执行
new Thread(() -> {
TUser user = new TUser();
user.setId(tUser.getId());
user.setLastLoginTime(new Date()); //用户最近登录时间
tUserMapper.updateByPrimaryKeySelective(user);
}).start();
*/
//2、使用线程池异步执行
threadPoolExecutor.execute(() -> {
TUser user = new TUser();
user.setId(tUser.getId());
user.setLastLoginTime(new Date()); //用户最近登录时间
int update = tUserMapper.updateByPrimaryKeySelective(user);
log.info("更新用户id为 {} 的最近登录时间, 手机号为 {}, 更新结果为 {}.", tUser.getId(), tUser.getPhone(), update);
});
//登录返回
return new LoginDTO(CodeEnum.SUCCESS, userDTO);
}
/**
* 退出登录
*
* @param token
* @return
*/
@Override
public Boolean logout(String token) {
return redisManager.removeKey(Constant.REDIS_TOKEN_KEY + token);
}
/**
* 分页查询用户列表数据
*
* @param current
* @return
*/
@Override
public PageDTO<UserInfoDTO> getUserByPage(Integer current) {
//分页查询分两个查询,1、查符合条件的数据总条数;2、查询当前页的数据
int totalRow = tUserMapper.selectByCount();
// select * from t_user limit start, pageSize
int start = (current - 1) * Constant.PAGE_SIZE;
List<TUser> userList = tUserMapper.selectByPage(start, Constant.PAGE_SIZE);
int totalPage = totalRow / Constant.PAGE_SIZE;
if (totalRow % Constant.PAGE_SIZE > 0) { //如果除不尽,总页数就需要加1
totalPage ++;
}
//需要把 List<TUser> 转换为 List<UserInfoDTO>
List<UserInfoDTO> userInfoDTOList = ExtBeanUtils.copyPropertiesForList(userList, UserInfoDTO.class);
return new PageDTO<>(current, Constant.PAGE_SIZE, totalRow, totalPage, userInfoDTOList);
}
/**
* 新增用户提交保存
*
* @param userQuery
* @return
*/
@Override
public int saveUser(UserQuery userQuery) {
TUser tUser = new TUser();
BeanUtils.copyProperties(userQuery, tUser);
//把密码加密
String encodePwd = passwordEncoder.encode(userQuery.getLoginPwd());
tUser.setLoginPwd(encodePwd); //密码要加密后存入数据库,不能存明文
tUser.setCreateTime(new Date()); //创建时间
//拿到当前登录人的id
String token = userQuery.getToken();
//通过token解析出里面的登录id数据
Integer currentLoginUserId = jwtManager.getLoginUserId(token);
tUser.setCreateBy(currentLoginUserId); //创建人
return tUserMapper.insertSelective(tUser);
}
/***
* 根据用户id查询用户信息
*
* @param id
* @return
*/
@Override
public UserInfoDTO getUserById(Integer id) {
TUser tUser = tUserMapper.selectById(id);
UserInfoDTO userInfoDTO = new UserInfoDTO();
BeanUtils.copyProperties(tUser, userInfoDTO);
//兼容一下创建人和编辑人是空的情况,避免页面出现null的错误
if (ObjectUtils.isEmpty(userInfoDTO.getCreateByPO())) {
userInfoDTO.setCreateByPO(new TUser());
}
if (ObjectUtils.isEmpty(userInfoDTO.getEditByPO())) {
userInfoDTO.setEditByPO(new TUser());
}
return userInfoDTO;
}
@Override
public int updateUser(UserQuery userQuery) {
TUser tUser = new TUser();
BeanUtils.copyProperties(userQuery, tUser);
//把密码加密
String encodePwd = passwordEncoder.encode(userQuery.getLoginPwd());
tUser.setLoginPwd(enco
没有合适的资源?快使用搜索试试~ 我知道了~
基于Java的博物馆管理系统设计源码
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共474个文件
xml:200个
class:130个
java:130个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 9 浏览量
2024-05-26
04:39:51
上传
评论
收藏 66.66MB ZIP 举报
温馨提示
本项目是基于Java的博物馆管理系统设计源码,包含471个文件,其中包括200个XML文件、130个Java源文件、130个.class文件、2个YAML文件、2个LST文件、1个gitignore文件、1个.iml文件、1个musem-server/src/main/docker/dockerfile文件和1个MF文件。此外,项目还包括1个Properties文件。该项目是一个毕业设计项目,通过Java编程语言和前端技术实现,旨在为博物馆提供一个高效、便捷的管理系统,包括藏品管理、展览规划、游客服务等。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 474 条
- 1
- 2
- 3
- 4
- 5
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/326bc6aa99bd4e068708ab91a88ba159_weixin_44087733.jpg!1)
沐知全栈开发
- 粉丝: 5334
- 资源: 5025
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)