SysConfig.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package com.gzlh.bus;
  2. import cn.hutool.core.io.FileUtil;
  3. import cn.hutool.json.JSONObject;
  4. import cn.hutool.json.XML;
  5. import com.gzlh.config.dto.ApplicationConfigDTO;
  6. import com.gzlh.config.dto.CaputreSetting;
  7. import com.gzlh.config.dto.EventDTO;
  8. import com.gzlh.config.dto.SerialSetting;
  9. import lombok.Data;
  10. import lombok.extern.slf4j.Slf4j;
  11. import java.io.File;
  12. import java.util.List;
  13. import java.util.Properties;
  14. @Data
  15. @Slf4j
  16. public class SysConfig {
  17. public static List<EventDTO> eventDTOList;
  18. public static SerialSetting serialSetting;
  19. public static CaputreSetting caputreSetting;
  20. public static void initConfig() {
  21. Properties properties = System.getProperties();
  22. String rootPath = properties.getProperty("user.dir");
  23. String separator = File.separator;
  24. String configFile = rootPath + separator + "config.xml";
  25. if (!FileUtil.exist(configFile)) {
  26. log.error("配置文件不存在:{}", configFile);
  27. return;
  28. }
  29. String content = FileUtil.readUtf8String(configFile);
  30. JSONObject result = XML.toJSONObject(content);
  31. log.info("result:{}",result.toJSONString(0));
  32. ApplicationConfigDTO configDTO = result.toBean(ApplicationConfigDTO.class);
  33. eventDTOList=configDTO.getConfig().getEventList().getEvent();
  34. serialSetting=configDTO.getConfig().getSysConfig().getSerialSetting();
  35. caputreSetting=configDTO.getConfig().getSysConfig().getCaputreSetting();
  36. }
  37. }