| | |
| | | package com.example.erp.service.userInfo; |
| | | |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.example.erp.common.CacheUtil; |
| | | import com.example.erp.common.Result; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.example.erp.controller.dto.UserDTO; |
| | | import com.example.erp.entity.userInfo.User; |
| | | import com.example.erp.mapper.userInfo.UserMapper; |
| | | import com.example.erp.controller.dto.UserDTO; |
| | | import com.example.erp.tools.TokenTools; |
| | | import org.apache.ibatis.jdbc.Null; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @DS("user_info") |
| | | public class UserService { |
| | | |
| | | @Autowired |
| | | private UserMapper userMapper; |
| | | private final UserMapper userMapper; |
| | | |
| | | public UserService(UserMapper userMapper) { |
| | | this.userMapper = userMapper; |
| | | } |
| | | |
| | | |
| | | @Cacheable(value="users", key="#userDTO.getUserId()") |
| | |
| | | } |
| | | return returnUser; |
| | | } |
| | | |
| | | /*----------------新版本登陆*/ |
| | | public UserDTO doLogin(UserDTO userDTO) { |
| | | User user = userMapper.selectOne(new QueryWrapper<User>(). |
| | | eq("login_name", userDTO.getUserId()).eq("password", userDTO.getPass())); |
| | | if(user!=null){ |
| | | StpUtil.login(user.getId()); |
| | | userDTO.setPass(null); |
| | | userDTO.setId(user.getId()); |
| | | userDTO.setUserName(user.getUserName()); |
| | | userDTO.setToken(StpUtil.getTokenValue()); |
| | | return userDTO; |
| | | }else{ |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | public Boolean isLogin() { |
| | | // 返回当前用户是否登录 |
| | | return StpUtil.isLogin(); |
| | | } |
| | | |
| | | public Boolean logout() { |
| | | StpUtil.logout(); |
| | | return true; |
| | | } |
| | | } |
| | | |