5650b818f49762ac22bd57e934bb364d6a405a04.svn-base 11.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
/**
 * Copyright © 2015-2018 ODM All rights reserved.
 */
package com.thinkgem.jeesite.common.config;

import java.io.File;
import java.io.IOException;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.DefaultResourceLoader;

import com.ckfinder.connector.ServletContextFactory;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.thinkgem.jeesite.common.utils.JsonUtil;
import com.thinkgem.jeesite.common.utils.PropertiesLoader;
import com.thinkgem.jeesite.common.utils.StringUtils;

/**
 * 全局配置类
 * @author ThinkGem
 * @version 2014-06-25
 */
public class Global {
	private static Boolean isycsl = false;
	private static Boolean istitle = false ;
	
	private static Boolean istest = false ;
	
	protected static Logger logger = LoggerFactory.getLogger(Global.class);
	/**
	 * 当前对象实例
	 */
	private static Global global = new Global();
	
	/**
	 * 保存全局属性值
	 */
	private static Map<String, String> map = Maps.newHashMap();
	
	/**
	 * 属性文件加载对象
	 */
	private static PropertiesLoader loader = new PropertiesLoader("jeesite.properties");

	/**
	 * 显示/隐藏
	 */
	public static final String SHOW = "1";
	public static final String HIDE = "0";

	/**
	 * 是/否
	 */
	public static final String YES = "1";
	public static final String NO = "0";
	
	/**
	 * 对/错
	 */
	public static final String TRUE = "true";
	public static final String FALSE = "false";
	
	/**
	 * 上传文件基础虚拟路径
	 */
	public static final String USERFILES_BASE_URL = "/userfiles/";
	/**
	 * 临时文件基础虚拟路径
	 */
	public static final String UP_DATA_URL = "/updatas/";
	
	/**
	 * 上报文件本地校验路径
	 */
	public static final String SJHJ_XSD_URL = "/xsd/";
	
	/**
	 * 上报生成报文路径
	 */
	public static final String SJHJ_DATA_URL = "/updatas/";
	/**
	 * 日志结果保存路径
	 */
	public static final String LOGBOOK_URL = "/booklogs/";
	/**
	 * 获取当前对象实例
	 */
	public static Global getInstance() {
		return global;
	}
	
	/**
	 * 报文上报用户名
	 */
	public static final String UP_NAME = "610700";
	
	/**
	 * 报文上报用户密码
	 */
	public static final String UP_PASSWORD = "yuiop90876";
	
	/**
	 * 报文上报用户名
	 */
	public static final String UP_IPCONFIG = "172.16.56.28";
	//public static final String UP_IPCONFIG = "172.0.0.1";
	
	/**
	 * 一窗受理,登簿推送
	 */
	//public static final String POST_YCSL_URL_FZ = "http://172.16.56.31:8080/estateplat-acceptance/rest/v1.0/bdc/dbxx";
	public static final String POST_YCSL_URL_FZ = getYcslUrl()+"/accept/registerInfo";
 
	public static final String POST_YCSL_URL_XTTJ = getYcslUrl()+"/api/rest/bhSqxx";
 
	public static final String POST_YCSL_URL_YWZT = getYcslUrl()+"/api/rest/updateYwzt";
	
	public static final String POST_YCSL_URL_queryTradeWj = getYcslUrl()+"/accept/findTradeInfo";
	
	public static final String POST_YCSL_URL_downTradeFiles = getYcslUrl()+"/accept/downFileByPath";
	
	public static final String POST_YCSL_URL_insertSL = getYcslUrl()+"/accept/saveAcceptInfo";
	
	public static final String POST_YCSL_URL_updateSL = getYcslUrl()+"/accept/modifyAcceptInfo";
	
	public static final String POST_YCSL_URL_deleteSL = getYcslUrl()+"/accept/removeAcceptInfo";
	
	public static final String POST_YCSL_URL_queryTradeYw = getYcslUrl()+"/accept/findTradeToEstate";
	
	public static final String POST_YCSL_URL_queryTradeEstate = getYcslUrl()+"/accept/findEstateTrade";
	
	public static final String POST_YCSL_URL_saveHookRelation = getYcslUrl()+"/accept/saveHookRelation";
	
	public static final String POST_YCSL_URL_removeHookRelation = getYcslUrl()+"/accept/removeHookRelation";
	
	public static final String POST_YCSL_URL_saveHouseStatus = getYcslUrl()+"/accept/saveHouseStatus";
	
	public static final String POST_YCSL_URL_modifyHouseStatus = getYcslUrl()+"/accept/modifyHouseStatus";
	
	public static final String POST_YCSL_URL_terminateInfo = getYcslUrl()+"/accept/terminateInfo";
	
	public static final String POST_YCSL_URL_findLicenseInfo = getYcslUrl()+"/accept/findLicenseInfo";
	
	public static final String POST_YCSL_URL_wsqk = getYcslUrl()+"/accept/wsqk";
	
	public static final String POST_YCSL_URL_downDealFiles = getYcslUrl()+"/accept/downDealByPath";
	
	/**
	 * 数据汇总,复核请求
	 */
	public static final String POST_SJHZ_URL_FH = "http://172.16.58.79:8000/platSi/fhDmlRec";
	
	
	/**
	 * 获取配置
	 * @see ${fns:getConfig('adminPath')}
	 */
	public static String getConfig(String key) {
		String value = map.get(key);
		if (value == null){
			value = loader.getProperty(key);
			map.put(key, value != null ? value : StringUtils.EMPTY);
		}
		return value;
	}
	
	/**
	 * 获取访问接口使用的用户名 密码 
	 * 
	 */
	public static String getInterUserName(){
		return getConfig("reg.inter.username");
	}
	public static String getInterPassword(){
		return getConfig("reg.inter.password");
	}
	
	
	public static String getYcslUrl(){
		return getConfig("reg.ycsl.url");
	}
	
	/***
	* @Title: getAreaCode 
	* @Description: 获取当前系统部署的区县代码 
	* @param @return    设定文件 
	* @return String    返回类型 
	* @throws
	 */
	public static String getAreaCode(){
		return getConfig("reg.areacode");
	}

	public static String getsyncRowNum(){
		return getConfig("dmlRec.syncRowNum");
	}
	public static String getfhRowNum(){
		return getConfig("dmlRec.fhRowNum");
	}
	
	public static String getPictures(){
		return getConfig("reg.pictures");
	}
	
	/*
	 * 微信公众号路径
	 */
	public static String getWxUrl(){
		return getConfig("reg.wxurl");
	}
	
	/*
	 * 權籍接口系統路径
	 */
	public static String getTitleUrl(){
		return getConfig("reg.titleurl");
	}
	
 
	
	 
	
	 public static List<String> getIPList() {
	        
		 
		 	List<String> res_list = Lists.newArrayList();
	        Enumeration<NetworkInterface> e1;
	        try {
	            e1 = NetworkInterface.getNetworkInterfaces();
	            while (e1.hasMoreElements()) {
	                NetworkInterface ni = e1.nextElement();
	                
	                List<String> ips =  Lists.newLinkedList();
	              
	                
	                Enumeration<InetAddress> e2 = ni.getInetAddresses();
	                while (e2.hasMoreElements()) {
	                    InetAddress ia = e2.nextElement();
	                    if(ia instanceof Inet6Address) {
	                        continue; // omit IPv6 address
	                    }
	                    ips.add(ia.getHostAddress());                    
	                }
	                res_list.addAll(ips);
	            }
	        } catch (SocketException e) {
	            e.printStackTrace();
	        }
	        return res_list;
	    }
	/**
	 * 一窗开通标志
	 * @return
	 */
	public static Boolean isYcsl(){
		if(!isycsl) {
			String ycsl = getConfig("reg.ycsl"); 
			String[] list = StringUtils.isEmpty(ycsl) ? new String[]{}:ycsl.split(","); 
			for(String ip : list) {
				if(StringUtils.isEmpty(ip) ) {
					continue;
				}
				if(getIPList().contains(ip)) { 
					isycsl = true;
					break;
		        } 
			}
		}
		return isycsl; 
		 
	}
	
 
 
	
	/**
	 * 权籍开通标志
	 * @return
	 */
	public static Boolean isTitle(){
		if(!istitle) {
			String title = getConfig("reg.title");
			String[] list = StringUtils.isEmpty(title) ? new String[]{}:title.split(",");
			 
			for(String ip : list) {
				if(StringUtils.isEmpty(ip) ) {
					continue;
				}
				if(getIPList().contains(ip)) { 
					istitle = true;
					break;
		        } 
			}
			return istitle; 
		}
		return istitle;
	}
	
	
	/**
	 * 测试标志
	 * @return
	 */
	public static Boolean isTest(){  
		if(!istest) {
			String title = getConfig("reg.test");
			String[] list = StringUtils.isEmpty(title) ? new String[]{}:title.split(",");
			 
			for(String ip : list) {
				if(StringUtils.isEmpty(ip) ) {
					continue;
				}
				if(getIPList().contains(ip)) { 
					istest = true;
					break;
		        } 
			} 
		}
		return istest;
	}
	
	/**
	 * 业务号新生成方式
	 * @return
	 */
	public static Boolean isNewCreateType(){
		return Boolean.parseBoolean(StringUtils.isEmpty(getConfig("reg.ywh.new"))?"false":getConfig("reg.ywh.new"));
	}
	
	/**
	 * 是否新区
	 * @return
	 */
	public static Boolean isXq(){
		return Boolean.parseBoolean(StringUtils.isEmpty(getConfig("reg.xq"))?"false":getConfig("reg.xq"));
	}
	
	
	/**
	 * 获取管理端根路径
	 */
	public static String getAdminPath() {
		return getConfig("adminPath");
	}
	
	/**
	 * 获取前端根路径
	 */
	public static String getFrontPath() {
		return getConfig("frontPath");
	}
	
	/**
	 * 获取URL后缀
	 */
	public static String getUrlSuffix() {
		return getConfig("urlSuffix");
	}
	
	public static String getDbName(){
		return Global.getConfig("jdbc.type");
	}
	 
	public static String getSumDataWSUrl(){
		return Global.getConfig("webServiceUrl");
	}
	 	
	public static String getCommonLogUrl(){
		return Global.getConfig("commitLogUrl");
	}
	
	/**
	 * 是否是演示模式,演示模式下不能修改用户、角色、密码、菜单、授权
	 */
	public static Boolean isDemoMode() {
		String dm = getConfig("demoMode");
		return "true".equals(dm) || "1".equals(dm);
	}
	
	/**
	 * 在修改系统用户和角色时是否同步到Activiti
	 */
	public static Boolean isSynActivitiIndetity() {
		String dm = getConfig("activiti.isSynActivitiIndetity");
		return "true".equals(dm) || "1".equals(dm);
	}
    
	/**
	 * 页面获取常量
	 * @see ${fns:getConst('YES')}
	 */
	public static Object getConst(String field) {
		try {
			return Global.class.getField(field).get(null);
		} catch (Exception e) {
			// 异常代表无配置,这里什么也不做
		}
		return null;
	}

	/**
	 * 获取上传文件的根目录
	 * @return
	 */
	public static String getUserfilesBaseDir() {
		String dir = getConfig("userfiles.basedir");
		if (StringUtils.isBlank(dir)){
			try {
				dir = ServletContextFactory.getServletContext().getRealPath("/");
			} catch (Exception e) {
				return "";
			}
		}
		if(!dir.endsWith("/")) {
			dir += "/";
		}
//		System.out.println("userfiles.basedir: " + dir);
		return dir;
	}
	//--------------------------
	/**
	 * 获取上传文件的根目录
	 * @return
	 */
	public static String getUpdatefilesBaseDir() {
		String dir = getConfig("updatefiles.basedir");
		if (StringUtils.isBlank(dir)){
			try {
				dir = ServletContextFactory.getServletContext().getRealPath("/");
			} catch (Exception e) {
				return "";
			}
		}
		if(!dir.endsWith("/")) {
			dir += "/";
		}
//		System.out.println("userfiles.basedir: " + dir);
		return dir;
	}
	//----------------------------------
    /**
     * 获取工程路径
     * @return
     */
    public static String getProjectPath(){
    	// 如果配置了工程路径,则直接返回,否则自动获取。
		String projectPath = Global.getConfig("projectPath");
		if (StringUtils.isNotBlank(projectPath)){
			return projectPath;
		}
		try {
			File file = new DefaultResourceLoader().getResource("").getFile();
			if (file != null){
				while(true){
					File f = new File(file.getPath() + File.separator + "src" + File.separator + "main");
					if (f == null || f.exists()){
						break;
					}
					if (file.getParentFile() != null){
						file = file.getParentFile();
					}else{
						break;
					}
				}
				projectPath = file.toString();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return projectPath;
    }
	
}