BossApplication.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. package com.td.Dawa;
  2. import com.td.Dawa.config.enums.GameEnum;
  3. import com.td.Dawa.game.comusers.service.ComUsersService;
  4. import com.td.Dawa.game.excelcharacterattri.service.ExcelCharacterAttriService;
  5. import com.td.Dawa.game.excelcharactercolor.service.ExcelCharacterColorService;
  6. import com.td.Dawa.game.excelcharactercreate.service.ExcelCharacterCreateService;
  7. import com.td.Dawa.game.excelcharacterlevel.service.ExcelCharacterLevelService;
  8. import com.td.Dawa.game.exceldrop.service.ExcelDropService;
  9. import com.td.Dawa.game.excelparameter.service.ExcelParameterService;
  10. import com.td.Dawa.game.excelprop.service.ExcelPropService;
  11. import com.td.Dawa.game.excelresources.service.ExcelResourcesService;
  12. import com.td.Dawa.game.excelscene.service.ExcelSceneService;
  13. import com.td.Dawa.game.excelworkpro.service.ExcelWorkProService;
  14. import com.td.Dawa.sys.sysmenu.vo.SysMenuVo;
  15. import com.td.Dawa.sys.sysshortcutmenu.service.SysShortcutMenuService;
  16. import com.td.Dawa.sys.sysshortcutmenu.vo.SysShortcutMenuVo;
  17. import com.td.Dawa.sys.sysuser.service.SysUserService;
  18. import com.td.Dawa.sys.sysuser.vo.SysUserVo;
  19. import com.td.Dawa.sys.sysusermenu.service.SysUserMenuService;
  20. import com.td.Dawa.util.*;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.beans.factory.annotation.Value;
  24. import org.springframework.boot.ApplicationRunner;
  25. import org.springframework.boot.SpringApplication;
  26. import org.springframework.boot.autoconfigure.SpringBootApplication;
  27. import org.springframework.cache.annotation.EnableCaching;
  28. import org.springframework.context.annotation.Bean;
  29. import org.springframework.context.annotation.Configuration;
  30. import org.springframework.scheduling.annotation.EnableAsync;
  31. import org.springframework.scheduling.annotation.EnableScheduling;
  32. import org.springframework.security.core.session.SessionRegistry;
  33. import org.springframework.security.core.session.SessionRegistryImpl;
  34. import org.springframework.stereotype.Controller;
  35. import org.springframework.web.bind.annotation.GetMapping;
  36. import org.springframework.web.bind.annotation.RequestMapping;
  37. import org.springframework.web.servlet.ModelAndView;
  38. import javax.imageio.ImageIO;
  39. import javax.servlet.http.HttpServletRequest;
  40. import javax.servlet.http.HttpServletResponse;
  41. import java.awt.*;
  42. import java.awt.image.BufferedImage;
  43. import java.io.IOException;
  44. import java.net.InetAddress;
  45. import java.net.UnknownHostException;
  46. import java.util.List;
  47. @EnableAsync//开启异步调用
  48. @EnableCaching// 开启缓存,需要显示的指定
  49. @EnableScheduling
  50. @SpringBootApplication
  51. public class BossApplication {
  52. public static void main(String[] args) {
  53. SpringApplication.run(BossApplication.class, args);
  54. }
  55. /**
  56. * 解决不能注入session注册表问题
  57. */
  58. @Bean
  59. SessionRegistry sessionRegistry() {
  60. return new SessionRegistryImpl();
  61. }
  62. }
  63. @Slf4j
  64. @Controller
  65. @RequestMapping("/")
  66. @Configuration
  67. class IndexController {
  68. @Autowired
  69. private SysUserService sysUserService;
  70. @Autowired
  71. private RedisSettingMap redisSettingMap;
  72. @Autowired
  73. private SysUserMenuService sysUserMenuService;
  74. @Autowired
  75. private SysShortcutMenuService sysShortcutMenuService;
  76. @Autowired
  77. private ComUsersService comUsersService;
  78. @Autowired
  79. private ExcelWorkProService excelWorkProService;
  80. @Autowired
  81. private ExcelSceneService excelSceneService;
  82. @Autowired
  83. private ExcelResourcesService excelResourcesService;
  84. @Autowired
  85. private ExcelPropService excelPropService;
  86. @Autowired
  87. private ExcelParameterService excelParameterService;
  88. @Autowired
  89. private ExcelCharacterLevelService excelCharacterLevelService;
  90. @Autowired
  91. private ExcelCharacterCreateService excelCharacterCreateService;
  92. @Autowired
  93. private ExcelCharacterAttriService excelCharacterAttriService;
  94. @Autowired
  95. private ExcelCharacterColorService excelCharacterColorService;
  96. @Value("${server.servlet.context-path:}")
  97. private String contextPath;
  98. /**
  99. * 端口
  100. */
  101. @Value("${server.port}")
  102. private String port;
  103. /**
  104. * 启动成功
  105. */
  106. @Bean
  107. public ApplicationRunner applicationRunner() {
  108. return applicationArguments -> {
  109. try {
  110. /**
  111. * 当启动时候,向redis设置一次数据。
  112. */
  113. //更新sys_setting
  114. redisSettingMap.updateSysSettingMap();
  115. //更新excel表对应缓存
  116. excelCharacterColorService.updateListToCache(GameEnum.REDIS_KEY_EXCEL_CHARACTER_COLOR.getMessage());
  117. excelWorkProService.updateListToCache(GameEnum.REDIS_KEY_EXCEL_WORK_PRO.getMessage());
  118. excelPropService.updateListToCache(GameEnum.REDIS_KEY_EXCEL_PROP.getMessage());
  119. excelSceneService.updateListToCache(GameEnum.REDIS_KEY_EXCEL_SCENE.getMessage());
  120. //生产和资源
  121. excelCharacterCreateService.updateListToCache(GameEnum.REDIS_KEY_EXCEL_CHARACTER_CREATE.getMessage());
  122. excelResourcesService.updateListToCache(GameEnum.REDIS_KEY_EXCEL_RESOURCES.getMessage());
  123. //等级
  124. excelCharacterLevelService.updateListToCache(GameEnum.REDIS_KEY_EXCEL_CHARACTER_LEVEL.getMessage());
  125. excelCharacterAttriService.updateListToCache(GameEnum.REDIS_KEY_EXCEL_CHARACTER_ATTRI.getMessage());
  126. //参数
  127. excelParameterService.updateListToCache(GameEnum.REDIS_KEY_EXCEL_PARAMETER.getMessage());
  128. //获取本机内网IP
  129. log.info("启动成功:" + "http://" + InetAddress.getLocalHost().getHostAddress() + ":" + port + contextPath);
  130. } catch (UnknownHostException e) {
  131. //输出到日志文件中
  132. log.error(ErrorUtil.errorInfoToString(e));
  133. }
  134. };
  135. }
  136. /**
  137. * 跳转登录页面
  138. */
  139. @GetMapping("loginPage")
  140. public ModelAndView login() {
  141. ModelAndView modelAndView = new ModelAndView("login");
  142. //系统信息 SysSettingUtil.getSysSetting()
  143. modelAndView.addObject("sys", redisSettingMap.getSysSettingMap());
  144. //系统审查信息 SysSettingTaskUtil.getSysSettingTask()
  145. modelAndView.addObject("sysSettingTask", redisSettingMap.getSysSettingTaskMap());
  146. //系统限制信息 SysSettingLimitUtil.getSysSettingLimit()
  147. modelAndView.addObject("sysSettingLimit", redisSettingMap.getSysSettingLimitMap());
  148. //后端公钥
  149. String publicKey = redisSettingMap.getRSAPublicKeyBase64(); //RsaUtil.getPublicKey();
  150. log.info("login后端公钥:" + publicKey);
  151. modelAndView.addObject("publicKey", publicKey);
  152. return modelAndView;
  153. }
  154. /**
  155. * 跳转首页
  156. */
  157. @GetMapping("")
  158. public void index1(HttpServletResponse response) {
  159. //内部重定向
  160. try {
  161. response.sendRedirect(contextPath + "/index");
  162. } catch (IOException e) {
  163. //输出到日志文件中
  164. log.error(ErrorUtil.errorInfoToString(e));
  165. }
  166. }
  167. @GetMapping("index")
  168. public ModelAndView index() {
  169. ModelAndView modelAndView = new ModelAndView("index");
  170. //系统信息 SysSettingUtil.getSysSetting()
  171. modelAndView.addObject("sys", redisSettingMap.getSysSettingMap());
  172. //系统审查信息 SysSettingTaskUtil.getSysSettingTask()
  173. modelAndView.addObject("sysSettingTask", redisSettingMap.getSysSettingTaskMap());
  174. //系统限制信息 SysSettingLimitUtil.getSysSettingLimit()
  175. modelAndView.addObject("sysSettingLimit", redisSettingMap.getSysSettingLimitMap());
  176. //登录用户
  177. SysUserVo sysUserVo = sysUserService.findByLoginName(SecurityUtil.getLoginUser().getUsername()).getData();
  178. sysUserVo.setPassword(null);//隐藏部分属性
  179. modelAndView.addObject("loginUser", sysUserVo);
  180. //登录用户系统菜单
  181. List<SysMenuVo> menuVoList = sysUserMenuService.findByUserId(sysUserVo.getUserId()).getData();
  182. modelAndView.addObject("menuList", menuVoList);
  183. //登录用户快捷菜单
  184. List<SysShortcutMenuVo> shortcutMenuVoList = sysShortcutMenuService.findByUserId(sysUserVo.getUserId()).getData();
  185. modelAndView.addObject("shortcutMenuList", shortcutMenuVoList);
  186. //后端公钥
  187. String publicKey = redisSettingMap.getRSAPublicKeyBase64(); // RsaUtil.getPublicKey();
  188. log.info("index后端公钥:" + publicKey);
  189. modelAndView.addObject("publicKey", publicKey);
  190. //获取一个全平台的用户数据
  191. Long allComUserCount = comUsersService.findAllCount();
  192. modelAndView.addObject("allComUserCount", allComUserCount);
  193. Long todayComUserCount = comUsersService.newToday();
  194. modelAndView.addObject("todayComUserCount", todayComUserCount);
  195. return modelAndView;
  196. }
  197. /**
  198. * 获取验证码图片和文本(验证码文本会保存在HttpSession中)
  199. */
  200. @RequestMapping("getVerifyCodeImage")
  201. public void getVerifyCodeImage(HttpServletRequest request, HttpServletResponse response) throws IOException {
  202. //设置页面不缓存
  203. response.setHeader("Pragma", "no-cache");
  204. response.setHeader("Cache-Control", "no-cache");
  205. response.setDateHeader("Expires", 0);
  206. response.getOutputStream();
  207. String verifyCode = VerifyCodeImageUtil.generateTextCode(VerifyCodeImageUtil.TYPE_NUM_UPPER, 4, null);
  208. //将验证码放到HttpSession里面
  209. request.getSession().setAttribute("verifyCode", verifyCode);
  210. log.info("本次生成的验证码为:" + verifyCode + ",已存放到HttpSession中");
  211. //设置输出的内容的类型为JPEG图像
  212. response.setContentType("image/jpeg");
  213. BufferedImage bufferedImage = VerifyCodeImageUtil.generateImageCode(verifyCode, 90, 30, 3, true, Color.WHITE, Color.BLACK, null);
  214. //写给浏览器
  215. ImageIO.write(bufferedImage, "JPEG", response.getOutputStream());
  216. }
  217. /**
  218. * 跳转实时系统硬件监控
  219. */
  220. @GetMapping("monitor")
  221. public ModelAndView monitor() {
  222. return new ModelAndView("monitor.html", "port", port);
  223. }
  224. /**
  225. * 跳转实时日志
  226. */
  227. @GetMapping("logging")
  228. public ModelAndView logging() {
  229. return new ModelAndView("logging.html", "port", port);
  230. }
  231. }