package com.engine.salary.formlua.entity.parameter;

import com.engine.salary.entity.datacollection.DataCollectionEmployee;
import org.mozilla.javascript.commonjs.module.provider.ModuleSource;

import java.util.Iterator;
import java.util.Map;


public class ThreadLocalData {
	private Map<String, Object> expressContext;
	private ModuleSource moduleSource;

	private DataCollectionEmployee employee;

	public ModuleSource getModuleSource() {
		return moduleSource;
	}

	public void setModuleSource(ModuleSource moduleSource) {
		this.moduleSource = moduleSource;
	}

	public DataCollectionEmployee getEmployee() {
		return employee;
	}

	public void setEmployee(DataCollectionEmployee employee) {
		this.employee = employee;
	}

	public Map<String, Object> getExpressContext() {
		return expressContext;
	}

	public void setExpressContext(Map<String, Object> expressContext) {
		transMap(expressContext);
		this.expressContext = expressContext;
	}

	private void transMap(Map<String, Object> expressContext){
		Iterator<String> iterator=expressContext.keySet().iterator();
		while (iterator.hasNext()){
			String key=iterator.next();
			Object obj=expressContext.get(key);
			if(obj instanceof DataType){
				DataType dataType=(DataType)obj;
				if(dataType.getFieldId()!=null){
					int idx=key.indexOf(dataType.getFieldId().toString());
					if(idx>=0){
						String localKey=key.substring(0,idx+dataType.getFieldId().toString().length());
						dataType.setAggCndKey(localKey);
					}
				}

			}
		}
	}
}
