package com.example.xiaoshiweixinback.business.utils; import cn.dev33.satoken.exception.NotLoginException; import com.example.xiaoshiweixinback.business.common.base.RedisConf; import com.example.xiaoshiweixinback.entity.vo.PersonnelVO; import jakarta.annotation.Resource; import org.springframework.stereotype.Component; import java.util.concurrent.TimeUnit; @Component public class CacheUtil { @Resource private RedisUtil redisUtil; public void setLoginUser(PersonnelVO personnelVO,String token) { redisUtil.setEx(token,JsonUtils.objectToJson(personnelVO),3L,TimeUnit.DAYS); } public PersonnelVO getLoginUser(String token) { String json = redisUtil.get(token); if (StringUtils.isEmpty(json)) { throw new NotLoginException("无数据", "user", ""); } else { return com.alibaba.fastjson2.JSONObject.parseObject(json, PersonnelVO.class); } } public Boolean ifHavePermission(String id) { PersonnelVO personnelVO = this.getLoginUser(LoginUtils.getToken()); personnelVO.getPersonType(); if (personnelVO.getPersonType().equals(0) || (id != null && personnelVO.getUuid().equals(id))) { return true; } return false; } }