123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package com.scbfkj.uni.system;
- import com.scbfkj.uni.library.DataEncryptionUtil;
- import com.scbfkj.uni.service.ControlService;
- import jakarta.annotation.PostConstruct;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Component;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.time.LocalDateTime;
- import java.util.List;
- import com.scbfkj.uni.service.LoggerService;
- @Component
- public class SystemInit {
- @Value("${db.center.config}")
- private String centerConfig;
- @Value("${db.security.config}")
- private String securityconfig;
- @Value("${app.security.enable:true}")
- private boolean enableSecurity;
- @Value("${app.container.code}")
- private String containerCode;
- @Value("${log.target}")
- private List<String> targets;
- @PostConstruct
- public void init() throws Exception {
- Config.containerCode = containerCode;
- Config.enable = enableSecurity;
- Config.centerConnectionStr = DataEncryptionUtil.decryptRSAByPrivateKey(centerConfig);
- Config.securityConnectionStr = DataEncryptionUtil.decryptRSAByPrivateKey(securityconfig);
- // 日志配置初始化
- for (String targetStr : targets) {
- String target = DataEncryptionUtil.decryptRSAByPrivateKey(targetStr);
- Config.targets.add(target);
- }
- initializeSystemEnvironment();
- ControlService.startServiceByContainerCode();
- // 日志任务
- // ScheduleUtil.start(() -> {
- // try {
- // LoggerService.sendLog();
- // } catch (FileNotFoundException exception) {
- // System.out.println(exception.getMessage());
- // }
- // }, "* * * * * *");
- }
- private void initializeSystemEnvironment() {
- // 运行环境初始化
- File resource = new File("logs");
- boolean exists = resource.exists();
- if (!exists) {
- if (!resource.mkdirs()) {
- throw new RuntimeException("创建日志目录失败");
- } else {
- System.out.println("创建目录成功:" + resource.getAbsolutePath());
- }
- }
- }
- }
|