SystemInit.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.scbfkj.uni.system;
  2. import com.scbfkj.uni.library.DataEncryptionUtil;
  3. import com.scbfkj.uni.service.ControlService;
  4. import jakarta.annotation.PostConstruct;
  5. import org.springframework.beans.factory.annotation.Value;
  6. import org.springframework.stereotype.Component;
  7. import java.io.File;
  8. import java.io.FileNotFoundException;
  9. import java.time.LocalDateTime;
  10. import java.util.List;
  11. import com.scbfkj.uni.service.LoggerService;
  12. @Component
  13. public class SystemInit {
  14. @Value("${db.center.config}")
  15. private String centerConfig;
  16. @Value("${db.security.config}")
  17. private String securityconfig;
  18. @Value("${app.security.enable:true}")
  19. private boolean enableSecurity;
  20. @Value("${app.container.code}")
  21. private String containerCode;
  22. @Value("${log.target}")
  23. private List<String> targets;
  24. @PostConstruct
  25. public void init() throws Exception {
  26. Config.containerCode = containerCode;
  27. Config.enable = enableSecurity;
  28. Config.centerConnectionStr = DataEncryptionUtil.decryptRSAByPrivateKey(centerConfig);
  29. Config.securityConnectionStr = DataEncryptionUtil.decryptRSAByPrivateKey(securityconfig);
  30. // 日志配置初始化
  31. for (String targetStr : targets) {
  32. String target = DataEncryptionUtil.decryptRSAByPrivateKey(targetStr);
  33. Config.targets.add(target);
  34. }
  35. initializeSystemEnvironment();
  36. ControlService.startServiceByContainerCode();
  37. // 日志任务
  38. // ScheduleUtil.start(() -> {
  39. // try {
  40. // LoggerService.sendLog();
  41. // } catch (FileNotFoundException exception) {
  42. // System.out.println(exception.getMessage());
  43. // }
  44. // }, "* * * * * *");
  45. }
  46. private void initializeSystemEnvironment() {
  47. // 运行环境初始化
  48. File resource = new File("logs");
  49. boolean exists = resource.exists();
  50. if (!exists) {
  51. if (!resource.mkdirs()) {
  52. throw new RuntimeException("创建日志目录失败");
  53. } else {
  54. System.out.println("创建目录成功:" + resource.getAbsolutePath());
  55. }
  56. }
  57. }
  58. }