package com.ruoyi; import cn.hutool.core.collection.CollectionUtil; import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.system.mapper.SysDeptMapper; import com.ruoyi.system.mapper.SysRoleMapper; import com.ruoyi.system.mapper.SysUserMapper; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.scheduling.annotation.EnableScheduling; import springfox.documentation.swagger2.annotations.EnableSwagger2; import java.util.List; /** * 启动程序 * * @author ruoyi */ @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) @EnableScheduling @EnableSwagger2 public class RuoYiApplication { public static void main(String[] args) { // System.setProperty("spring.devtools.restart.enabled", "false"); SpringApplication.run(RuoYiApplication.class, args); System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" + " .-------. ____ __ \n" + " | _ _ \\ \\ \\ / / \n" + " | ( ' ) | \\ _. / ' \n" + " |(_ o _) / _( )_ .' \n" + " | (_,_).' __ ___(_ o _)' \n" + " | |\\ \\ | || |(_,_)' \n" + " | | \\ `' /| `-' / \n" + " | | \\ / \\ / \n" + " ''-' `'-' `-..-' "); // 启动成功后,查询用户表,将用户信息存到redis RedisCache redisCache = SpringUtils.getBean(RedisCache.class); SysUserMapper userMapper = SpringUtils.getBean(SysUserMapper.class); List sysUsers = userMapper.selectUserListByIds(null); if(CollectionUtil.isNotEmpty(sysUsers)){ for (SysUser sysUser : sysUsers) { redisCache.setCacheObject(CacheConstants.USER_KEY+sysUser.getUserId(),sysUser); } } // 初始化角色redis SysRoleMapper roleMapper = SpringUtils.getBean(SysRoleMapper.class); List roles = roleMapper.selectRoleList(new SysRole()); if(CollectionUtil.isNotEmpty(roles)){ for (SysRole role : roles) { redisCache.setCacheObject(CacheConstants.ROLE_KEY+role.getRoleName(),role.getRoleId()); } } // 初始化部门redis SysDeptMapper deptMapper = SpringUtils.getBean(SysDeptMapper.class); List depts = deptMapper.selectDeptList(new SysDept()); if(CollectionUtil.isNotEmpty(depts)){ for (SysDept dept : depts) { redisCache.setCacheObject(CacheConstants.DEPT_KEY+dept.getDeptName(),dept.getDeptId()); } } } }