package com.dy.pipIrrGlobal.util; import com.dy.common.util.ConfigXml; import com.dy.common.webListener.ConfigListener; import org.jdom2.Document; import org.springframework.boot.context.event.ApplicationReadyEvent; import java.net.URL; /** * @Author: liurunyu * @Date: 2024/7/24 13:41 * @Description */ public abstract class OrgListenerSupport { /** * 实始化 */ @SuppressWarnings("unused ") protected void init() { this.init(null); } /** * 实始化 */ @SuppressWarnings("unused ") protected void init(ApplicationReadyEvent event) { try { URL configFileURL = ConfigListener.class.getResource("/init-config.xml"); ConfigXml configXml = new ConfigXml(); Document doc = configXml.createDom(configFileURL); this.doInit(configXml, doc); } catch (Exception e) { System.out.println("系统启动时,初始化配置出错 !"); System.out.println(e.getMessage()); e.printStackTrace(); } } private void doInit(ConfigXml configXml, Document doc) throws Exception { if (configXml != null && doc != null) { for (int num = 1; num <= 10000; num++) { if (configXml.existElement(doc, "config.orgs.org" + num)) { String orgTag = configXml.getSetAttrTxt(doc, "config.orgs.org" + num, "tag", null, false, null); String orgName = configXml.getSetAttrTxt(doc, "config.orgs.org" + num, "name", null, false, null); Org.OrgVo vo = new Org().new OrgVo() ; vo.tag = orgTag ; vo.name = orgName ; Org.OrgList.add(vo) ; }else{ break ; } } } } }