机构标签与名称去掉枚举实现方式,改为全部从配置文件中得到。
| | |
| | | package com.dy.pipIrrGlobal.util; |
| | | |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.alibaba.fastjson2.annotation.JSONField; |
| | | import com.baomidou.mybatisplus.annotation.EnumValue; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public enum Org { |
| | | |
| | | // Ym("ym", "元谋"), |
| | | // Pj("pj", "片角镇"), |
| | | Sp("sp", "沙盘"), |
| | | Jyg("ym", "嘉峪关"); |
| | | |
| | | @EnumValue |
| | | public String tag ; |
| | | public String name ; |
| | | |
| | | Org(String tag, String name){ |
| | | this.tag = tag ; |
| | | this.name = name ; |
| | | } |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2024/7/24 11:45 |
| | | * @Description |
| | | */ |
| | | public class Org { |
| | | //用来转json |
| | | public static List<Map> OrgList = new ArrayList<>(); |
| | | static { |
| | | Org[] all = Org.values(); |
| | | for (Org one : all) { |
| | | Map<String, String> objMap = new HashMap<>(); |
| | | objMap.put("tag", one.tag); |
| | | objMap.put("name", one.name); |
| | | OrgList.add(objMap) ; |
| | | public static List<OrgVo> OrgList = new ArrayList<>(); |
| | | |
| | | public class OrgVo{ |
| | | public String tag ; |
| | | public String name ; |
| | | |
| | | public String getTag() { |
| | | return this.tag ; |
| | | } |
| | | |
| | | public String getName() { |
| | | return this.name ; |
| | | } |
| | | } |
| | | |
| | | public String getTag() { |
| | | return this.tag ; |
| | | } |
| | | |
| | | public String getName() { |
| | | return this.name ; |
| | | } |
| | | |
| | | public static Org get(String tag){ |
| | | // if(tag.equals(Ym.tag) || tag.equals(Jyg.tag)){ |
| | | // return Ym ; |
| | | // }else if(tag.equals(Pj.tag)){ |
| | | // return Pj ; |
| | | // } |
| | | if(tag.equals(Jyg.tag)){ |
| | | return Jyg ; |
| | | }else if(tag.equals(Sp.tag)) { |
| | | return Sp; |
| | | } |
| | | return null ; |
| | | } |
| | | |
| | | |
| | | @JSONField |
| | | public JSONObject toJson() { |
| | | return JSONObject.of("tag", getTag(), "name", getName()); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | 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 ; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | <config> |
| | | <orgs> |
| | | <!-- 多个组织,用编号区分,编号从1开始 --> |
| | | <org1 name="ym"> |
| | | <org1 tag="ym" name="元谋"> |
| | | <districts> |
| | | <province name="云南省" num="53" level="1"> |
| | | <city name="楚雄彝族自治州" num="23" level="2"> |
| | |
| | | <item4 name="银行转账"/> |
| | | </payments> |
| | | <settings> |
| | | <item1 item_name="lng" item_value="101.87345" remarks="经度"/> |
| | | <item2 item_name="lat" item_value="25.70424" remarks="纬度"/> |
| | | <item1 item_name="lng" item_value="101.87345" remarks="经度"/> |
| | | <item2 item_name="lat" item_value="25.70424" remarks="纬度"/> |
| | | </settings> |
| | | <waterTypes> |
| | | <item1 typeName="灌溉用水"/> |
| | |
| | | <item5 typeName="绿化用水"/> |
| | | </waterTypes> |
| | | </org1> |
| | | <org2 name="sp"> |
| | | <org2 tag="sp" name="沙盘"> |
| | | <districts> |
| | | <province name="天津" num="53" level="1"> |
| | | <city name="天津市" num="23" level="2"> |
| | |
| | | |
| | | //工作报太频繁,N次上报处理1次,取值范围是1-100 |
| | | ServerProperties.workReportDealOneByTimes = conf.getSetAttrPlusInt(doc, "config.base", "workReportDealOneByTimes", null, 1, 100, null) ; |
| | | if(ServerProperties.workReportDealOneByTimes < 1 || ServerProperties.disconnectedByNoUpDataMinutes > 100){ |
| | | if(ServerProperties.workReportDealOneByTimes < 1 || ServerProperties.workReportDealOneByTimes > 100){ |
| | | throw new Exception("workReportDealOneByTimes取值必须是1~100") ; |
| | | } |
| | | |
| | |
| | | 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,"name", null, false, null) ; |
| | | String orgTag = configXml.getSetAttrTxt(doc, "config.orgs.org" + num,"tag", null, false, null) ; |
| | | //设置数据源 |
| | | DataSourceContext.set(orgTag); |
| | | if(!this.existDistricts()){ |
| | |
| | | import java.util.Objects; |
| | | import java.util.UUID; |
| | | |
| | | //import org.springframework.cache.CacheManager; |
| | | |
| | | /** |
| | | * 注解Tag 在API中显示: Tag 注解, 给整个接口起了个名字与描述" |
| | | * 注解ApiResponses 和 注解ApiResponse 用来配置响应; |
| | |
| | | ) |
| | | }) |
| | | @GetMapping(path = "allOrg") |
| | | public BaseResponse<List<Org>> allOrg(){ |
| | | public BaseResponse<List<Org.OrgVo>> allOrg(){ |
| | | //List<Org> list = Arrays.asList(Org.Ym, Org.Pj) ; |
| | | return BaseResponseUtils.buildSuccess(Org.OrgList); |
| | | } |
| | |
| | | package com.dy.sso.util; |
| | | |
| | | import jakarta.servlet.ServletContext; |
| | | import jakarta.servlet.ServletContextEvent; |
| | | import jakarta.servlet.ServletContextListener; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import com.dy.pipIrrGlobal.util.OrgListenerSupport; |
| | | import org.springframework.boot.context.event.ApplicationReadyEvent; |
| | | import org.springframework.context.ApplicationListener; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Slf4j |
| | | public class SsoListener implements ServletContextListener { |
| | | @Component |
| | | public class SsoListener extends OrgListenerSupport implements ApplicationListener<ApplicationReadyEvent> { |
| | | |
| | | |
| | | @Override |
| | | public void contextInitialized(ServletContextEvent event) { |
| | | ServletContextListener.super.contextInitialized(event); |
| | | ServletContext con = event.getServletContext(); |
| | | public void onApplicationEvent(ApplicationReadyEvent event) { |
| | | try { |
| | | //等1秒,等待com.alibaba.druid.pool.DruidDataSource实始化完成 |
| | | Thread.sleep(1000L); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | super.init(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void contextDestroyed(ServletContextEvent event) { |
| | | ServletContextListener.super.contextDestroyed(event); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrStatistics.listeners; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2024/7/24 11:24 |
| | | * @Description |
| | | */ |
| | | public class StLossSv { |
| | | } |