package com.alatus.service;import com.alatus.model.TUser;import com.alatus.query.UserQuery;import com.github.pagehelper.PageInfo;import org.springframework.security.core.userdetails.UserDetailsService;import java.util.List;public interface UserService extends UserDetailsService {PageInfo getUserByPage(Integer current);TUser getUserById(Integer id);int saveUser(UserQuery userQuery);int updateUser(UserQuery userQuery);int delUserById(Integer id);int delUsersByIds(List idList);List getOwnerList();}
package com.alatus.service;import com.alatus.model.TUser;import com.alatus.query.UserQuery;import com.github.pagehelper.PageInfo;import org.springframework.security.core.userdetails.UserDetailsService;import java.util.List;public interface UserService extends UserDetailsService {PageInfo getUserByPage(Integer current);TUser getUserById(Integer id);int saveUser(UserQuery userQuery);int updateUser(UserQuery userQuery);int delUserById(Integer id);int delUsersByIds(List idList);List getOwnerList();}

package com.alatus.web;import com.alatus.constant.Constants;import com.alatus.model.TUser;import com.alatus.query.UserQuery;import com.alatus.result.R;import com.alatus.service.UserService;import com.github.pagehelper.PageInfo;import jakarta.annotation.Resource;import org.springframework.security.core.Authentication;import org.springframework.web.bind.annotation.*;import java.util.Arrays;import java.util.List;@RestControllerpublic class UserController {@Resourceprivate UserService userService;//获取登录信息@GetMapping(value = "/api/login/info")public R loginInfo(Authentication authentication){TUser tUser = (TUser) authentication.getPrincipal();return R.OK(tUser);}//免登录验证//因为发送的请求过来首先会过filter那一关,能到这说明token验证都通过了,我们直接返回200即可@GetMapping(value = "/api/login/free")public R freeLogin(){return R.OK();}//查询用户列表,用户分页查询@GetMapping(value = "/api/users")//传递参数current,可传可不传,public R userPage(@RequestParam(value = "current",required = false) Integer current){if(current == null){current = 1;}//返回结果为PageInfoPageInfo userByPage = userService.getUserByPage(current);return R.OK(userByPage);}@GetMapping(value = "/api/user/{id}")public R userDetail(@PathVariable(value = "id")Integer id){TUser tUser = userService.getUserById(id);return R.OK(tUser);}//添加用户@PostMapping(value = "/api/user/add")public R addUser(UserQuery userQuery,@RequestHeader(value = Constants.TOKEN_NAME)String token){userQuery.setToken(token);int result = userService.saveUser(userQuery);return result >= 1 ? R.OK() : R.FAIL();}//编辑用户@PutMapping(value = "/api/user/edit")public R editUser(UserQuery userQuery,@RequestHeader(value = Constants.TOKEN_NAME)String token){userQuery.setToken(token);int result = userService.updateUser(userQuery);return result >= 1 ? R.OK() : R.FAIL();}@DeleteMapping(value = "/api/user/del/{id}")public R delUser(@PathVariable(value = "id") Integer id,@RequestHeader(value = Constants.TOKEN_NAME)String token){int result = userService.delUserById(id);return result >= 1 ? R.OK() : R.FAIL();}@DeleteMapping(value = "/api/user/batchDel")public R batchDelUsers(@RequestParam(value = "ids")String ids,@RequestHeader(value = Constants.TOKEN_NAME)String token){//将我们的字符串拆分并放到list中作为元素List idList = Arrays.asList(ids.split(","));int result = userService.delUsersByIds(idList);return result >= idList.size() ? R.OK() : R.FAIL();}@GetMapping(value = "/api/user/activityOwner")public R loadActivityOwner(){return R.OK(userService.getOwnerList());}}
package com.alatus.web;import com.alatus.constant.Constants;import com.alatus.model.TUser;import com.alatus.query.UserQuery;import com.alatus.result.R;import com.alatus.service.UserService;import com.github.pagehelper.PageInfo;import jakarta.annotation.Resource;import org.springframework.security.core.Authentication;import org.springframework.web.bind.annotation.*;import java.util.Arrays;import java.util.List;@RestControllerpublic class UserController {@Resourceprivate UserService userService;//获取登录信息@GetMapping(value = "/api/login/info")public R loginInfo(Authentication authentication){TUser tUser = (TUser) authentication.getPrincipal();return R.OK(tUser);}//免登录验证//因为发送的请求过来首先会过filter那一关,能到这说明token验证都通过了,我们直接返回200即可@GetMapping(value = "/api/login/free")public R freeLogin(){return R.OK();}//查询用户列表,用户分页查询@GetMapping(value = "/api/users")//传递参数current,可传可不传,public R userPage(@RequestParam(value = "current",required = false) Integer current){if(current == null){current = 1;}//返回结果为PageInfoPageInfo userByPage = userService.getUserByPage(current);return R.OK(userByPage);}@GetMapping(value = "/api/user/{id}")public R userDetail(@PathVariable(value = "id")Integer id){TUser tUser = userService.getUserById(id);return R.OK(tUser);}//添加用户@PostMapping(value = "/api/user/add")public R addUser(UserQuery userQuery,@RequestHeader(value = Constants.TOKEN_NAME)String token){userQuery.setToken(token);int result = userService.saveUser(userQuery);return result >= 1 ? R.OK() : R.FAIL();}//编辑用户@PutMapping(value = "/api/user/edit")public R editUser(UserQuery userQuery,@RequestHeader(value = Constants.TOKEN_NAME)String token){userQuery.setToken(token);int result = userService.updateUser(userQuery);return result >= 1 ? R.OK() : R.FAIL();}@DeleteMapping(value = "/api/user/del/{id}")public R delUser(@PathVariable(value = "id") Integer id,@RequestHeader(value = Constants.TOKEN_NAME)String token){int result = userService.delUserById(id);return result >= 1 ? R.OK() : R.FAIL();}@DeleteMapping(value = "/api/user/batchDel")public R batchDelUsers(@RequestParam(value = "ids")String ids,@RequestHeader(value = Constants.TOKEN_NAME)String token){//将我们的字符串拆分并放到list中作为元素List idList = Arrays.asList(ids.split(","));int result = userService.delUsersByIds(idList);return result >= idList.size() ? R.OK() : R.FAIL();}@GetMapping(value = "/api/user/activityOwner")public R loadActivityOwner(){return R.OK(userService.getOwnerList());}}
package com.alatus.service.impl;import com.alatus.constant.Constants;import com.alatus.manager.RedisManager;import com.alatus.mapper.TRoleMapper;import com.alatus.mapper.TUserMapper;import com.alatus.model.TRole;import com.alatus.model.TUser;import com.alatus.query.BaseQuery;import com.alatus.query.UserQuery;import com.alatus.util.CacheUtils;import com.alatus.util.JWTUtils;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import jakarta.annotation.Resource;import org.springframework.beans.BeanUtils;import org.springframework.security.core.userdetails.UserDetails;import org.springframework.security.core.userdetails.UsernameNotFoundException;import org.springframework.security.crypto.password.PasswordEncoder;import org.springframework.stereotype.Service;import org.springframework.util.StringUtils;import java.util.ArrayList;import java.util.Date;import java.util.List;@Servicepublic class UserServiceImpl implements com.alatus.service.UserService {@Resourceprivate TUserMapper tUserMapper;//注入角色的Mapper@Resourceprivate TRoleMapper tRoleMapper;@Resourceprivate RedisManager redisManager;//注入一个密码加密器@Resourceprivate PasswordEncoder passwordEncoder;@Overridepublic UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {TUser tUser = tUserMapper.selectByLoginAct(username);if(tUser == null){throw new UsernameNotFoundException("登陆账号不存在");}//查询一下当前登录的角色List tRoleList = tRoleMapper.selectByUserId(tUser.getId());List roleList = new ArrayList();tRoleList.forEach(tRole -> {roleList.add(tRole.getRole());});//设置用户的角色tUser.setRoleList(roleList);return tUser;}@Overridepublic PageInfo getUserByPage(Integer current) {//设置PageHelper和分页情况PageHelper.startPage(current, Constants.PAGE_SIZE);//查询ArrayList list = tUserMapper.selectUserByPage(BaseQuery.builder().build());//封装分页到PageInfo中PageInfo info = new PageInfo(list);return info;}@Overridepublic TUser getUserById(Integer id) {return tUserMapper.selectDetailByPrimaryKey(id);}@Overridepublic int saveUser(UserQuery userQuery) {TUser tUser = new TUser();//把query对象的数据复制到user对象里面//这个工具类的复制要求是两个对象的属性名要相同,属性要相同BeanUtils.copyProperties(userQuery,tUser);tUser.setLoginPwd(passwordEncoder.encode(userQuery.getLoginPwd()));//创建时间tUser.setCreateTime(new Date());//通过token解析出的用户获取ID作为创建者的IDInteger loginId = JWTUtils.parseUserFromJWT(userQuery.getToken()).getId();tUser.setCreateBy(loginId);return tUserMapper.insertSelective(tUser);}@Overridepublic int updateUser(UserQuery userQuery) {TUser tUser = new TUser();//把query对象的数据复制到user对象里面//这个工具类的复制要求是两个对象的属性名要相同,属性要相同BeanUtils.copyProperties(userQuery,tUser);if(StringUtils.hasText(userQuery.getLoginPwd())){tUser.setLoginPwd(passwordEncoder.encode(userQuery.getLoginPwd()));}//编辑时间tUser.setEditTime(new Date());//通过token解析出的用户获取ID作为编辑者的IDInteger loginId = JWTUtils.parseUserFromJWT(userQuery.getToken()).getId();tUser.setEditBy(loginId);return tUserMapper.updateByPrimaryKeySelective(tUser);}@Overridepublic int delUserById(Integer id) {return tUserMapper.deleteByPrimaryKey(id);}@Overridepublic int delUsersByIds(List idList) {//遍历删除法//int result = 0;//for (int i = 0; i < idList.size(); i++) {//result += tUserMapper.deleteByPrimaryKey(Integer.parseInt(idList.get(i)));//}//return result;return tUserMapper.deleteByIds(idList);}@Overridepublic List getOwnerList() {//先从redis获取//redis没有就走mysqlreturn CacheUtils.getCacheData(() -> {//从redis查数据return (List)redisManager.getValue(Constants.OWNER_KEY);},() -> {//生产,从mysql查询数据return (List)tUserMapper.selectByOwner();},(t) -> {//消费,把数据放入缓存redisredisManager.setValue(Constants.OWNER_KEY,t);});}}
package com.alatus.service.impl;import com.alatus.constant.Constants;import com.alatus.manager.RedisManager;import com.alatus.mapper.TRoleMapper;import com.alatus.mapper.TUserMapper;import com.alatus.model.TRole;import com.alatus.model.TUser;import com.alatus.query.BaseQuery;import com.alatus.query.UserQuery;import com.alatus.util.CacheUtils;import com.alatus.util.JWTUtils;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import jakarta.annotation.Resource;import org.springframework.beans.BeanUtils;import org.springframework.security.core.userdetails.UserDetails;import org.springframework.security.core.userdetails.UsernameNotFoundException;import org.springframework.security.crypto.password.PasswordEncoder;import org.springframework.stereotype.Service;import org.springframework.util.StringUtils;import java.util.ArrayList;import java.util.Date;import java.util.List;@Servicepublic class UserServiceImpl implements com.alatus.service.UserService {@Resourceprivate TUserMapper tUserMapper;//注入角色的Mapper@Resourceprivate TRoleMapper tRoleMapper;@Resourceprivate RedisManager redisManager;//注入一个密码加密器@Resourceprivate PasswordEncoder passwordEncoder;@Overridepublic UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {TUser tUser = tUserMapper.selectByLoginAct(username);if(tUser == null){throw new UsernameNotFoundException("登陆账号不存在");}//查询一下当前登录的角色List tRoleList = tRoleMapper.selectByUserId(tUser.getId());List roleList = new ArrayList();tRoleList.forEach(tRole -> {roleList.add(tRole.getRole());});//设置用户的角色tUser.setRoleList(roleList);return tUser;}@Overridepublic PageInfo getUserByPage(Integer current) {//设置PageHelper和分页情况PageHelper.startPage(current, Constants.PAGE_SIZE);//查询ArrayList list = tUserMapper.selectUserByPage(BaseQuery.builder().build());//封装分页到PageInfo中PageInfo info = new PageInfo(list);return info;}@Overridepublic TUser getUserById(Integer id) {return tUserMapper.selectDetailByPrimaryKey(id);}@Overridepublic int saveUser(UserQuery userQuery) {TUser tUser = new TUser();//把query对象的数据复制到user对象里面//这个工具类的复制要求是两个对象的属性名要相同,属性要相同BeanUtils.copyProperties(userQuery,tUser);tUser.setLoginPwd(passwordEncoder.encode(userQuery.getLoginPwd()));//创建时间tUser.setCreateTime(new Date());//通过token解析出的用户获取ID作为创建者的IDInteger loginId = JWTUtils.parseUserFromJWT(userQuery.getToken()).getId();tUser.setCreateBy(loginId);return tUserMapper.insertSelective(tUser);}@Overridepublic int updateUser(UserQuery userQuery) {TUser tUser = new TUser();//把query对象的数据复制到user对象里面//这个工具类的复制要求是两个对象的属性名要相同,属性要相同BeanUtils.copyProperties(userQuery,tUser);if(StringUtils.hasText(userQuery.getLoginPwd())){tUser.setLoginPwd(passwordEncoder.encode(userQuery.getLoginPwd()));}//编辑时间tUser.setEditTime(new Date());//通过token解析出的用户获取ID作为编辑者的IDInteger loginId = JWTUtils.parseUserFromJWT(userQuery.getToken()).getId();tUser.setEditBy(loginId);return tUserMapper.updateByPrimaryKeySelective(tUser);}@Overridepublic int delUserById(Integer id) {return tUserMapper.deleteByPrimaryKey(id);}@Overridepublic int delUsersByIds(List idList) {//遍历删除法//int result = 0;//for (int i = 0; i < idList.size(); i++) {//result += tUserMapper.deleteByPrimaryKey(Integer.parseInt(idList.get(i)));//}//return result;return tUserMapper.deleteByIds(idList);}@Overridepublic List getOwnerList() {//先从redis获取//redis没有就走mysqlreturn CacheUtils.getCacheData(() -> {//从redis查数据return (List)redisManager.getValue(Constants.OWNER_KEY);},() -> {//生产,从mysql查询数据return (List)tUserMapper.selectByOwner();},(t) -> {//消费,把数据放入缓存redisredisManager.setValue(Constants.OWNER_KEY,t);});}}

package com.alatus.mapper;import com.alatus.commons.DataScope;import com.alatus.model.TUser;import com.alatus.query.BaseQuery;import java.util.ArrayList;import java.util.List;public interface TUserMapper {int deleteByPrimaryKey(Integer id);int insert(TUser record);int insertSelective(TUser record);TUser selectByPrimaryKey(Integer id);int updateByPrimaryKeySelective(TUser record);int updateByPrimaryKey(TUser record);TUser selectByLoginAct(String username);@DataScope(tableAlias = "tu",tableField = "id")ArrayList selectUserByPage(BaseQuery query);TUser selectDetailByPrimaryKey(Integer id);int deleteByIds(List idList);List selectByOwner();}
package com.alatus.mapper;import com.alatus.commons.DataScope;import com.alatus.model.TUser;import com.alatus.query.BaseQuery;import java.util.ArrayList;import java.util.List;public interface TUserMapper {int deleteByPrimaryKey(Integer id);int insert(TUser record);int insertSelective(TUser record);TUser selectByPrimaryKey(Integer id);int updateByPrimaryKeySelective(TUser record);int updateByPrimaryKey(TUser record);TUser selectByLoginAct(String username);@DataScope(tableAlias = "tu",tableField = "id")ArrayList selectUserByPage(BaseQuery query);TUser selectDetailByPrimaryKey(Integer id);int deleteByIds(List idList);List selectByOwner();}
id, login_act, login_pwd, `name`, phone, email, account_no_expired, credentials_no_expired, account_no_locked, account_enabled, create_time, create_by, edit_time, edit_by, last_login_timeselectfrom t_userwhere login_act = #{username,jdbcType=VARCHAR}select from t_userwhere id = #{id,jdbcType=INTEGER}selecttu.*,tu2.id createById, tu2.name createByName,tu3.id editById, tu3.name editNamefrom t_user tu left join t_user tu2 on tu.create_by = tu2.id left join t_user tu3 on tu.edit_by = tu3.idwhere tu.id = #{id, jdbcType=INTEGER}selectfrom t_user as tu${filterSQL}selectid,namefrom t_userdelete from t_userwhere id = #{id,jdbcType=INTEGER}delete from t_userwhere id in #{id,jdbcType=INTEGER}insert into t_user (login_act, login_pwd, `name`, phone, email, account_no_expired,credentials_no_expired, account_no_locked, account_enabled, create_time, create_by, edit_time, edit_by, last_login_time)values (#{loginAct,jdbcType=VARCHAR}, #{loginPwd,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{accountNoExpired,jdbcType=INTEGER}, #{credentialsNoExpired,jdbcType=INTEGER}, #{accountNoLocked,jdbcType=INTEGER}, #{accountEnabled,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{createBy,jdbcType=INTEGER}, #{editTime,jdbcType=TIMESTAMP}, #{editBy,jdbcType=INTEGER}, #{lastLoginTime,jdbcType=TIMESTAMP})insert into t_userlogin_act,login_pwd,`name`,phone,email,account_no_expired,credentials_no_expired,account_no_locked,account_enabled,create_time,create_by,edit_time,edit_by,last_login_time,#{loginAct,jdbcType=VARCHAR},#{loginPwd,jdbcType=VARCHAR},#{name,jdbcType=VARCHAR},#{phone,jdbcType=VARCHAR},#{email,jdbcType=VARCHAR},#{accountNoExpired,jdbcType=INTEGER},#{credentialsNoExpired,jdbcType=INTEGER},#{accountNoLocked,jdbcType=INTEGER},#{accountEnabled,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{createBy,jdbcType=INTEGER},#{editTime,jdbcType=TIMESTAMP},#{editBy,jdbcType=INTEGER},#{lastLoginTime,jdbcType=TIMESTAMP},update t_userlogin_act = #{loginAct,jdbcType=VARCHAR},login_pwd = #{loginPwd,jdbcType=VARCHAR},`name` = #{name,jdbcType=VARCHAR},phone = #{phone,jdbcType=VARCHAR},email = #{email,jdbcType=VARCHAR},account_no_expired = #{accountNoExpired,jdbcType=INTEGER},credentials_no_expired = #{credentialsNoExpired,jdbcType=INTEGER},account_no_locked = #{accountNoLocked,jdbcType=INTEGER},account_enabled = #{accountEnabled,jdbcType=INTEGER},create_time = #{createTime,jdbcType=TIMESTAMP},create_by = #{createBy,jdbcType=INTEGER},edit_time = #{editTime,jdbcType=TIMESTAMP},edit_by = #{editBy,jdbcType=INTEGER},last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP},where id = #{id,jdbcType=INTEGER}update t_userset login_act = #{loginAct,jdbcType=VARCHAR},login_pwd = #{loginPwd,jdbcType=VARCHAR},`name` = #{name,jdbcType=VARCHAR},phone = #{phone,jdbcType=VARCHAR},email = #{email,jdbcType=VARCHAR},account_no_expired = #{accountNoExpired,jdbcType=INTEGER},credentials_no_expired = #{credentialsNoExpired,jdbcType=INTEGER},account_no_locked = #{accountNoLocked,jdbcType=INTEGER},account_enabled = #{accountEnabled,jdbcType=INTEGER},create_time = #{createTime,jdbcType=TIMESTAMP},create_by = #{createBy,jdbcType=INTEGER},edit_time = #{editTime,jdbcType=TIMESTAMP},edit_by = #{editBy,jdbcType=INTEGER},last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP}where id = #{id,jdbcType=INTEGER}
id, login_act, login_pwd, `name`, phone, email, account_no_expired, credentials_no_expired, account_no_locked, account_enabled, create_time, create_by, edit_time, edit_by, last_login_timeselectfrom t_userwhere login_act = #{username,jdbcType=VARCHAR}select from t_userwhere id = #{id,jdbcType=INTEGER}selecttu.*,tu2.id createById, tu2.name createByName,tu3.id editById, tu3.name editNamefrom t_user tu left join t_user tu2 on tu.create_by = tu2.id left join t_user tu3 on tu.edit_by = tu3.idwhere tu.id = #{id, jdbcType=INTEGER}selectfrom t_user as tu${filterSQL}selectid,namefrom t_userdelete from t_userwhere id = #{id,jdbcType=INTEGER}delete from t_userwhere id in #{id,jdbcType=INTEGER}insert into t_user (login_act, login_pwd, `name`, phone, email, account_no_expired,credentials_no_expired, account_no_locked, account_enabled, create_time, create_by, edit_time, edit_by, last_login_time)values (#{loginAct,jdbcType=VARCHAR}, #{loginPwd,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{accountNoExpired,jdbcType=INTEGER}, #{credentialsNoExpired,jdbcType=INTEGER}, #{accountNoLocked,jdbcType=INTEGER}, #{accountEnabled,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{createBy,jdbcType=INTEGER}, #{editTime,jdbcType=TIMESTAMP}, #{editBy,jdbcType=INTEGER}, #{lastLoginTime,jdbcType=TIMESTAMP})insert into t_userlogin_act,login_pwd,`name`,phone,email,account_no_expired,credentials_no_expired,account_no_locked,account_enabled,create_time,create_by,edit_time,edit_by,last_login_time,#{loginAct,jdbcType=VARCHAR},#{loginPwd,jdbcType=VARCHAR},#{name,jdbcType=VARCHAR},#{phone,jdbcType=VARCHAR},#{email,jdbcType=VARCHAR},#{accountNoExpired,jdbcType=INTEGER},#{credentialsNoExpired,jdbcType=INTEGER},#{accountNoLocked,jdbcType=INTEGER},#{accountEnabled,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{createBy,jdbcType=INTEGER},#{editTime,jdbcType=TIMESTAMP},#{editBy,jdbcType=INTEGER},#{lastLoginTime,jdbcType=TIMESTAMP},update t_userlogin_act = #{loginAct,jdbcType=VARCHAR},login_pwd = #{loginPwd,jdbcType=VARCHAR},`name` = #{name,jdbcType=VARCHAR},phone = #{phone,jdbcType=VARCHAR},email = #{email,jdbcType=VARCHAR},account_no_expired = #{accountNoExpired,jdbcType=INTEGER},credentials_no_expired = #{credentialsNoExpired,jdbcType=INTEGER},account_no_locked = #{accountNoLocked,jdbcType=INTEGER},account_enabled = #{accountEnabled,jdbcType=INTEGER},create_time = #{createTime,jdbcType=TIMESTAMP},create_by = #{createBy,jdbcType=INTEGER},edit_time = #{editTime,jdbcType=TIMESTAMP},edit_by = #{editBy,jdbcType=INTEGER},last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP},where id = #{id,jdbcType=INTEGER}update t_userset login_act = #{loginAct,jdbcType=VARCHAR},login_pwd = #{loginPwd,jdbcType=VARCHAR},`name` = #{name,jdbcType=VARCHAR},phone = #{phone,jdbcType=VARCHAR},email = #{email,jdbcType=VARCHAR},account_no_expired = #{accountNoExpired,jdbcType=INTEGER},credentials_no_expired = #{credentialsNoExpired,jdbcType=INTEGER},account_no_locked = #{accountNoLocked,jdbcType=INTEGER},account_enabled = #{accountEnabled,jdbcType=INTEGER},create_time = #{createTime,jdbcType=TIMESTAMP},create_by = #{createBy,jdbcType=INTEGER},edit_time = #{editTime,jdbcType=TIMESTAMP},edit_by = #{editBy,jdbcType=INTEGER},last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP}where id = #{id,jdbcType=INTEGER}
package com.alatus.constant;public class Constants {//开始页地址public static final String LOGIN_URI = "/api/login";//redis的key命名规范,项目名:模块名:功能名:唯一业务参数(比如用户ID)public static final String REDIS_JWT_KEY = "crmSystem:user:login:";//七天时间public static final Long EXPIRE_TIME = 7 * 24 * 60 * 60L;//三十分钟public static final Long DEFAULT_EXPIRE_TIME = 30 * 60L;//分页时每页10条记录public static final int PAGE_SIZE = 10;//Token的名字public static final String TOKEN_NAME = "Authorization";//负责人的Keypublic static final String OWNER_KEY = "crm:user:owner";}
package com.alatus.constant;public class Constants {//开始页地址public static final String LOGIN_URI = "/api/login";//redis的key命名规范,项目名:模块名:功能名:唯一业务参数(比如用户ID)public static final String REDIS_JWT_KEY = "crmSystem:user:login:";//七天时间public static final Long EXPIRE_TIME = 7 * 24 * 60 * 60L;//三十分钟public static final Long DEFAULT_EXPIRE_TIME = 30 * 60L;//分页时每页10条记录public static final int PAGE_SIZE = 10;//Token的名字public static final String TOKEN_NAME = "Authorization";//负责人的Keypublic static final String OWNER_KEY = "crm:user:owner";}
package com.alatus.manager;import com.alatus.model.TUser;import jakarta.annotation.Resource;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.stereotype.Component;import java.util.Collection;@Componentpublic class RedisManager {@Resourceprivate RedisTemplate redisTemplate;public Object getValue(String key){return redisTemplate.opsForList().range(key,0,-1);}public  Object setValue(String key, Collection data){Object[] t = new Object[data.size()];data.toArray(t);return redisTemplate.opsForList().leftPushAll(key,t);}}
package com.alatus.manager;import com.alatus.model.TUser;import jakarta.annotation.Resource;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.stereotype.Component;import java.util.Collection;@Componentpublic class RedisManager {@Resourceprivate RedisTemplate redisTemplate;public Object getValue(String key){return redisTemplate.opsForList().range(key,0,-1);}public  Object setValue(String key, Collection data){Object[] t = new Object[data.size()];data.toArray(t);return redisTemplate.opsForList().leftPushAll(key,t);}}
package com.alatus.util;import org.springframework.util.ObjectUtils;import java.util.Objects;import java.util.function.Consumer;import java.util.function.Supplier;public class CacheUtils {//带有缓存的查询方法public static  T getCacheData(Supplier cacheSelector, Supplier databaseSelector, Consumer saveCache){//从redis获取T data = cacheSelector.get();//从数据库获取if(ObjectUtils.isEmpty(data)){data = databaseSelector.get();//数据库查到了if(!ObjectUtils.isEmpty(data)){//把数据放到redissaveCache.accept(data);}}//返回数据return data;}}
package com.alatus.util;import org.springframework.util.ObjectUtils;import java.util.Objects;import java.util.function.Consumer;import java.util.function.Supplier;public class CacheUtils {//带有缓存的查询方法public static  T getCacheData(Supplier cacheSelector, Supplier databaseSelector, Consumer saveCache){//从redis获取T data = cacheSelector.get();//从数据库获取if(ObjectUtils.isEmpty(data)){data = databaseSelector.get();//数据库查到了if(!ObjectUtils.isEmpty(data)){//把数据放到redissaveCache.accept(data);}}//返回数据return data;}}