| | |
| | | import com.dy.common.multiDataSource.DataSourceContext; |
| | | import com.dy.common.mybatis.envm.Deleted; |
| | | import com.dy.common.mybatis.envm.Disabled; |
| | | import com.dy.common.util.ConfigXml; |
| | | import com.dy.common.util.ConfigXml4Springboot; |
| | | import com.dy.common.util.MD5; |
| | | import com.dy.pipIrrGlobal.daoBa.BaDistrictMapper; |
| | | import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.context.event.ApplicationReadyEvent; |
| | | import org.springframework.context.ApplicationListener; |
| | | import org.springframework.core.io.ResourceLoader; |
| | | import org.springframework.lang.NonNull; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.net.URL; |
| | | |
| | | /** |
| | | * 监听器,实现功能:在系统启动时初始化,向数据库中插入数据 |
| | |
| | | @Component |
| | | public class InitListener implements ApplicationListener<ApplicationReadyEvent> { |
| | | |
| | | protected ResourceLoader resourceLoader ; |
| | | |
| | | private BaDistrictMapper distriDao ; |
| | | private BaUserMapper userDao ; |
| | | private SePaymentMethodMapper paymentMethodDao ; |
| | | private BaSettingsMapper settingsDao ; |
| | | private SeWaterTypeMapper waterTypeDao ; |
| | | |
| | | @Autowired |
| | | public void setResourceLoader(ResourceLoader resourceLoader){ |
| | | this.resourceLoader = resourceLoader ; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setDistriDao(BaDistrictMapper distriDao){ |
| | |
| | | @SuppressWarnings("unused ") |
| | | private void init(ApplicationReadyEvent event){ |
| | | try { |
| | | URL configFileURL = InitListener.class.getResource("/init-config.xml" ); |
| | | ConfigXml configXml = new ConfigXml() ; |
| | | Document doc = configXml.createDom(configFileURL) ; |
| | | ConfigXml4Springboot configXml = new ConfigXml4Springboot() ; |
| | | Document doc = configXml.createDom(this.resourceLoader, "init-config.xml") ; |
| | | this.doInit(configXml, doc); |
| | | } catch (Exception e) { |
| | | System.out.println("系统启动时,初始化配置出错 !"); |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | private void doInit(ConfigXml configXml, Document doc) throws Exception{ |
| | | private void doInit(ConfigXml4Springboot 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) ; |
| | | Boolean enable = configXml.getSetAttrBoolean(doc, "config.orgs.org" + num, "enable", null, null); |
| | | if(enable != null && enable.booleanValue()){ |
| | | //设置数据源 |
| | | DataSourceContext.set(orgTag); |
| | | if(!this.existDistricts()){ |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }else{ |
| | | break ; |
| | | } |