New file |
| | |
| | | package com.example.erp.service.userInfo; |
| | | |
| | | 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.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; |
| | | |
| | | |
| | | @Cacheable(value="users", key="#userDTO.getUserId()") |
| | | public UserDTO login(UserDTO userDTO) { |
| | | |
| | | if(StrUtil.isBlank(userDTO.getUserId()) ||StrUtil.isBlank(userDTO.getPass())){ |
| | | return null; |
| | | }else{ |
| | | int getUserCount=userMapper.checkUser(userDTO.getUserId(),userDTO.getPass()); |
| | | if(getUserCount==1){ |
| | | String token = TokenTools.getToken(userDTO.getUserId(),userDTO.getPass()); |
| | | userDTO.setToken(token); |
| | | User user = userMapper.findOneLoginName(userDTO.getUserId()); |
| | | userDTO.setUserName(user.getUserName()); |
| | | return userDTO; |
| | | } |
| | | return null; |
| | | |
| | | } |
| | | } |
| | | |
| | | @CacheEvict(value="users",key="#id",beforeInvocation=true) |
| | | public String deleteCache(String id ) { |
| | | //System.out.println("delete user by id: " + id); |
| | | return null; |
| | | |
| | | } |
| | | |
| | | public String getUserByID(String userId){ |
| | | return userMapper.getUserByID(userId); |
| | | } |
| | | |
| | | @Transactional |
| | | public User register(User user) { |
| | | User returnUser = new User(); |
| | | if(userMapper.register(user)){ |
| | | User getUser = userMapper.findOne(user.getId()); |
| | | returnUser.setUserName(getUser.getUserName()); |
| | | returnUser.setLoginName(getUser.getLoginName()); |
| | | } |
| | | return returnUser; |
| | | } |
| | | } |
| | | |