package cn.base.conf;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

public class Scatter extends NodeHome {
	static private final Logger logger = Logger.getLogger(Scatter.class);
	private String moduleId;
	private String moduleType;
	private String pcfg;
	private String menuArea;
	private int doIceEventThreadPoolCount;
	private int debugPort;
	private String mode;
	private int reloadVdSeconds = 10;
	private int kakouIceRcvSwitch;
	private int kakouWsRcvSwitch;
	private int kakouRecycleRights;
	private int apcFuncSwitch;
	private int dbaFuncSwitch;
	private int kakouDrawDataSwitch;
	private int vdOfflineResendInterval;
	private int recordLostResendInterval;
	private int serviceOfflineCheckInterval;
	private int kakouDrawDataPutAmqSwitch;
	private int kakouDrawDataDelaySendInterval;
	private int kakouLoadBlackPlateNoInterval;
	private int kakouBlackPlateNoSwitch;
	private int kakouVtCasSwitch;
	private String basePath;
	private String filePath;
	private String pacPath;
	private String bulletinPath;
	private String versionPath;
	private String tracePath;
	private String travelSetPath;
	private String resourcePath;
	private String illegalPath;
	private String recordPath;
	private String jklkPath;
	private String peoplePath;
	private String searchPath;
	private String repairPath;
	private String isPicProxy;
	private String isShortRoad;
	private String isLoadGpsXY;
	private String systemTitle;
	private String customName;
	private String loginPage;
	private String mainPage;
	private String moduleLog;
	private String imageHot;
	private String pushletTime;
	private String defaultUrl;
	private int moduleDebugPort;
	private String urlFilter;
	private String dwrFilter;
	private String isUserFbpc;
	private String isUserSzMap;
	private String bqm;
	private String ptdz;
	private String downPath;
	private String szMapSwitch;
	public String getSzMapSwitch() {
		return szMapSwitch;
	}

	public void setSzMapSwitch(String szMapSwitch) {
		this.szMapSwitch = szMapSwitch;
	}

	private String amqSwitch;
	private String iceClientSwitch;
	private String iceServiceSwitch;
	
	
	public String getIsUserSzMap() {
		return isUserSzMap;
	}

	public void setIsUserSzMap(String isUserSzMap) {
		this.isUserSzMap = isUserSzMap;
	}

	public void fillField() {
		StringBuilder sbd = new StringBuilder();
		Map<String,String> tinycfgs = new HashMap<String,String>();
	 
		for(int i = 0; i < this.getList().size(); i++) {
			sbd.setLength(0);
			String value = this.getList().get(i).getValue();
			if (value.startsWith("../")){
				String f = this.getClass().getResource("/").getPath(); 
				String[] filenames = f.substring(1,f.indexOf("/WEB-INF/classes/")).split("/");
				int cutindex = (f.indexOf("/WebRoot/"))>0?2:1 ;
				sbd.append(filenames[filenames.length-cutindex]);
				String g = f.substring(0, f.indexOf("/"+sbd+"/"));
				String right = value.substring(value.indexOf("../")+3);
				value = g+"/"+right;
				//System.out.println("=sbd="+sbd+"=f="+f+"=g="+g+"=right="+right+"===xxxxxx==="+this.getList().get(i).getName() + " --- " + value);
			}
			/*
			if (value.startsWith("../")){
				String  f = this.getClass().getResource("/").getPath(); 
				String[] filenames = f.substring(1,f.indexOf("/WEB-INF/classes/")).split("/");
				int cutindex = (f.indexOf("/WebRoot/"))>0?2:1 ;
				sbd.append(filenames[filenames.length-cutindex]).append(File.separator).append(value.substring(value.indexOf("../")+3));
				value = sbd.toString();
				System.out.println("=f="+f+"=filenames="+filenames+"===yyyyy==="+this.getList().get(i).getName() + " --- " + value);
			}
			*/
			//System.out.println(this.getList().get(i).getName() + " --- " + value);
			tinycfgs.put(this.getList().get(i).getName(), value);
		}
		
		for (Field field : this.getClass().getDeclaredFields()) {
			for(String o : tinycfgs.keySet()){
				if(StringUtils.isNotBlank(o) && field.getName().equalsIgnoreCase(o)){
					try {
						field.setAccessible(true);
						if(field.getType().getSimpleName().equalsIgnoreCase("int")){
							field.set(this, Integer.parseInt(tinycfgs.get(o)));
						}else{
							field.set(this, tinycfgs.get(o));
						}
			            break;
					} catch(Exception e){
						logger.error("动态解析配置文件出错"+ e);
						continue;
					}
				}
			} 
		}
	}
	
	public String getSystemTitle() {
		return systemTitle;
	}

	public void setSystemTitle(String systemTitle) {
		this.systemTitle = systemTitle;
	}

	public String getCustomName() {
		return customName;
	}

	public void setCustomName(String customName) {
		this.customName = customName;
	}

	public String getLoginPage() {
		return loginPage;
	}

	public void setLoginPage(String loginPage) {
		this.loginPage = loginPage;
	}

	public String getMainPage() {
		return mainPage;
	}

	public void setMainPage(String mainPage) {
		this.mainPage = mainPage;
	}
	
	public int getKakouLoadBlackPlateNoInterval() {
		return kakouLoadBlackPlateNoInterval;
	}

	public int getKakouBlackPlateNoSwitch() {
		return kakouBlackPlateNoSwitch;
	}

	public int getKakouDrawDataDelaySendInterval() {
		return kakouDrawDataDelaySendInterval;
	}

	public int getServiceOfflineCheckInterval() {
		return serviceOfflineCheckInterval;
	}

	public int getKakouDrawDataSwitch() {
		return kakouDrawDataSwitch;
	}

	public int getVdOfflineResendInterval() {
		return vdOfflineResendInterval;
	}

	public int getKakouVtCasSwitch() {
		return kakouVtCasSwitch;
	}

	public void setKakouVtCasSwitch(int kakouVtCasSwitch) {
		this.kakouVtCasSwitch = kakouVtCasSwitch;
	}

	public int getRecordLostResendInterval() {
		return recordLostResendInterval;
	}

	public void setVdOfflineResendInterval(int vdOfflineResendInterval) {
		this.vdOfflineResendInterval = vdOfflineResendInterval;
	}

	public int getDbaFuncSwitch() {
		return dbaFuncSwitch;
	}

	public void setDbaFuncSwitch(int dbaFuncSwitch) {
		this.dbaFuncSwitch = dbaFuncSwitch;
	}

	public int getApcFuncSwitch() {
		return apcFuncSwitch;
	}

	public void setApcFuncSwitch(int apcFuncSwitch) {
		this.apcFuncSwitch = apcFuncSwitch;
	}

	public int getKakouRecycleRights() {
		return kakouRecycleRights;
	}

	public void setKakouRecycleRights(int kakouRecycleRights) {
		this.kakouRecycleRights = kakouRecycleRights;
	}

	public int getReloadVdSeconds() {
		if (mode.equalsIgnoreCase("small"))
			return 10;
		if (mode.equalsIgnoreCase("middle"))
			return 300;
		if (mode.equalsIgnoreCase("big"))
			return 600;
		return reloadVdSeconds;
	}

	public void setReloadVdSeconds(int reloadVdSeconds) {
		this.reloadVdSeconds = reloadVdSeconds;
	}

	public String getMode() {
		return mode;
	}

	public void setMode(String mode) {
		this.mode = mode;
	}

	public String getModuleId() {
		return moduleId;
	}

	public int getKakouIceRcvSwitch() {
		return kakouIceRcvSwitch;
	}

	public void setKakouIceRcvSwitch(int kakouIceRcvSwitch) {
		this.kakouIceRcvSwitch = kakouIceRcvSwitch;
	}

	public int getKakouWsRcvSwitch() {
		return kakouWsRcvSwitch;
	}

	public void setKakouWsRcvSwitch(int kakouWsRcvSwitch) {
		this.kakouWsRcvSwitch = kakouWsRcvSwitch;
	}

	public void setModuleId(String moduleId) {
		this.moduleId = moduleId;
	}

	public String getPcfg() {
		return pcfg;
	}

	public void setPcfg(String pcfg) {
		this.pcfg = pcfg;
	}

	public int getDoIceEventThreadPoolCount() {
		return doIceEventThreadPoolCount;
	}

	public void setDoIceEventThreadPoolCount(int doIceEventThreadPoolCount) {
		this.doIceEventThreadPoolCount = doIceEventThreadPoolCount;
	}

	public int getDebugPort() {
		return debugPort;
	}

	public void setDebugPort(int debugPort) {
		this.debugPort = debugPort;
	}

	public int getKakouDrawDataPutAmqSwitch() {
		return kakouDrawDataPutAmqSwitch;
	}

	public void setKakouDrawDataPutAmqSwitch(int kakouDrawDataPutAmqSwitch) {
		this.kakouDrawDataPutAmqSwitch = kakouDrawDataPutAmqSwitch;
	}

	public String getModuleType() {
		return moduleType;
	}
	public void setModuleType(String moduleType) {
		this.moduleType = moduleType;
	}
	public String getBasePath() {
		return basePath;
	}

	public void setBasePath(String basePath) {
		this.basePath = basePath;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	public String getPacPath() {
		return pacPath;
	}
	public void setPacPath(String pacPath) {
		this.pacPath = pacPath;
	}
	public String getTracePath() {
		return tracePath;
	}
	public void setTracePath(String tracePath) {
		this.tracePath = tracePath;
	}
	public String getResourcePath() {
		return resourcePath;
	}
	public void setResourcePath(String resourcePath) {
		this.resourcePath = resourcePath;
	}

	public String getBulletinPath() {
		return bulletinPath;
	}

	public void setBulletinPath(String bulletinPath) {
		this.bulletinPath = bulletinPath;
	}

	public String getVersionPath() {
		return versionPath;
	}

	public void setVersionPath(String versionPath) {
		this.versionPath = versionPath;
	}

	public String getTravelSetPath() {
		return travelSetPath;
	}

	public void setTravelSetPath(String travelSetPath) {
		this.travelSetPath = travelSetPath;
	}

	public String getIllegalPath() {
		return illegalPath;
	}

	public void setIllegalPath(String illegalPath) {
		this.illegalPath = illegalPath;
	}

	public String getRecordPath() {
		return recordPath;
	}

	public void setRecordPath(String recordPath) {
		this.recordPath = recordPath;
	}

	public String getJklkPath() {
		return jklkPath;
	}

	public void setJklkPath(String jklkPath) {
		this.jklkPath = jklkPath;
	}

	public String getPeoplePath() {
		return peoplePath;
	}

	public void setPeoplePath(String peoplePath) {
		this.peoplePath = peoplePath;
	}

	public String getSearchPath() {
		return searchPath;
	}

	public void setSearchPath(String searchPath) {
		this.searchPath = searchPath;
	}

	public String getRepairPath() {
		return repairPath;
	}

	public void setRepairPath(String repairPath) {
		this.repairPath = repairPath;
	}
	
	public String getIsPicProxy() {
		return isPicProxy;
	}
	
	public void setIsPicProxy(String isPicProxy) {
		this.isPicProxy = isPicProxy;
	}
	
	public String getIsShortRoad() {
		return isShortRoad;
	}
	
	public void setIsShortRoad(String isShortRoad) {
		this.isShortRoad = isShortRoad;
	}

	
	public String getModuleLog() {
		return moduleLog;
	}
	
	public void setModuleLog(String moduleLog) {
		this.moduleLog = moduleLog;
	}

	public String getPushletTime() {
		return pushletTime;
	}

	public void setPushletTime(String pushletTime) {
		this.pushletTime = pushletTime;
	}

	public String getDefaultUrl() {
		return defaultUrl;
	}

	public void setDefaultUrl(String defaultUrl) {
		this.defaultUrl = defaultUrl;
	}

	public int getModuleDebugPort() {
		return moduleDebugPort;
	}

	public void setModuleDebugPort(int moduleDebugPort) {
		this.moduleDebugPort = moduleDebugPort;
	}

	public String getUrlFilter() {
		return urlFilter;
	}

	public void setUrlFilter(String urlFilter) {
		this.urlFilter = urlFilter;
	}

	public String getDwrFilter() {
		return dwrFilter;
	}

	public void setDwrFilter(String dwrFilter) {
		this.dwrFilter = dwrFilter;
	}
	public String getImageHot() {
		return imageHot;
	}

	public void setImageHot(String imageHot) {
		this.imageHot = imageHot;
	}
	public String getIsLoadGpsXY() {
		return isLoadGpsXY;
	}

	public void setIsLoadGpsXY(String isLoadGpsXY) {
		this.isLoadGpsXY = isLoadGpsXY;
	}

	public String getIsUserFbpc() {
		return isUserFbpc;
	}

	public void setIsUserFbpc(String isUserFbpc) {
		this.isUserFbpc = isUserFbpc;
	}
	
	
	public String getMenuArea() {
		return menuArea;
	}

	public void setMenuArea(String menuArea) {
		this.menuArea = menuArea;
	}

	public String getBqm() {
		return bqm;
	}

	public void setBqm(String bqm) {
		this.bqm = bqm;
	}

	public String getPtdz() {
		return ptdz;
	}

	public void setPtdz(String ptdz) {
		this.ptdz = ptdz;
	}
	
	public String getDownPath() {
		return downPath;
	}

	public void setDownPath(String downPath) {
		this.downPath = downPath;
	}
	public String getAmqSwitch() {
		return amqSwitch;
	}

	public void setAmqSwitch(String amqSwitch) {
		this.amqSwitch = amqSwitch;
	}

	public String getIceClientSwitch() {
		return iceClientSwitch;
	}

	public void setIceClientSwitch(String iceClientSwitch) {
		this.iceClientSwitch = iceClientSwitch;
	}

	public String getIceServiceSwitch() {
		return iceServiceSwitch;
	}

	public void setIceServiceSwitch(String iceServiceSwitch) {
		this.iceServiceSwitch = iceServiceSwitch;
	}
}
