package com.kingdee.shr.customer.gtiit.handler;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.ui.ModelMap;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.eas.base.param.IParamControl;
import com.kingdee.eas.base.param.ParamControlFactory;
import com.kingdee.eas.basedata.org.HROrgUnitCollection;
import com.kingdee.eas.basedata.org.HROrgUnitFactory;
import com.kingdee.eas.basedata.org.HROrgUnitInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.hr.emp.ContractTempletCollection;
import com.kingdee.eas.hr.emp.ContractTempletFactory;
import com.kingdee.eas.hr.emp.ContractTempletInfo;
import com.kingdee.eas.hr.emp.ContractTypeCollection;
import com.kingdee.eas.hr.emp.ContractTypeFactory;
import com.kingdee.eas.hr.emp.ContractTypeInfo;
import com.kingdee.eas.hr.emp.LabContractFirstPartyCollection;
import com.kingdee.eas.hr.emp.LabContractFirstPartyFactory;
import com.kingdee.eas.hr.emp.LabContractFirstPartyInfo;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
import com.kingdee.shr.contract.web.handler.SHREmployeeNotLaborContractEditHandler;

public class SHREmployeeNotLaborContractEditHandlerEx extends SHREmployeeNotLaborContractEditHandler{
	
	public String getDefaultHrOrgAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
		Context ctx = SHRContext.getInstance().getContext();
		try {
			IParamControl ipc = ParamControlFactory.getLocalInstance(ctx);
			String defaultHrOrgNumber = ipc.getParamValue(null, "defaultHrOrgNumber");
			HROrgUnitCollection hrOrgUnitCollection = HROrgUnitFactory.getLocalInstance(ctx).getHROrgUnitCollection("where number = '"+defaultHrOrgNumber+"'");
			if(hrOrgUnitCollection!=null && hrOrgUnitCollection.size()>0) {
				HROrgUnitInfo hrOrgUnitInfo = hrOrgUnitCollection.get(0);
				modelMap.put("hrOrgId", hrOrgUnitInfo.getId().toString());
				modelMap.put("hrOrgName", hrOrgUnitInfo.getName(Locale.ENGLISH));
			}
		} catch (BOSException e) {
			e.printStackTrace();
		} catch (EASBizException e) {
			e.printStackTrace();
		}
		JSONUtils.writeJson(response, modelMap);
		return null;
	}
	
	public String getDefaultContractPartyAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
		Context ctx = SHRContext.getInstance().getContext();
		try {
			IParamControl ipc = ParamControlFactory.getLocalInstance(ctx);
			String defaultContractPartyNumber = ipc.getParamValue(null, "defaultContractPartyNumber");
			LabContractFirstPartyCollection labContractFirstPartyCollection = LabContractFirstPartyFactory.getLocalInstance(ctx).getLabContractFirstPartyCollection("where number = '"+defaultContractPartyNumber+"'");
			if(labContractFirstPartyCollection!=null && labContractFirstPartyCollection.size()>0) {
				LabContractFirstPartyInfo labContractFirstPartyInfo = labContractFirstPartyCollection.get(0);
				modelMap.put("contractPartyId", labContractFirstPartyInfo.getId().toString());
				modelMap.put("contractPartyName", labContractFirstPartyInfo.getName(Locale.ENGLISH));
			}
		} catch (BOSException e) {
			e.printStackTrace();
		} catch (EASBizException e) {
			e.printStackTrace();
		}  
		JSONUtils.writeJson(response, modelMap);
		return null;
	}
	
	public String getDefaultContractTypeAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
		Context ctx = SHRContext.getInstance().getContext();
		try {
			IParamControl ipc = ParamControlFactory.getLocalInstance(ctx);
			String defaultContractTypeNumber = ipc.getParamValue(null, "defaultContractAgreementNumber"); 
			ContractTypeCollection contractTypeCollection = ContractTypeFactory.getLocalInstance(ctx).getContractTypeCollection("where number = '"+defaultContractTypeNumber+"'");
			if(contractTypeCollection!=null && contractTypeCollection.size()>0) {
				ContractTypeInfo contractTypeInfo = contractTypeCollection.get(0);
				modelMap.put("contractTypeId", contractTypeInfo.getId().toString());
				modelMap.put("contractTypeName", contractTypeInfo.getName(Locale.ENGLISH));
			}
		} catch (BOSException e) {
			e.printStackTrace();
		} catch (EASBizException e) {
			e.printStackTrace();
		}  
		JSONUtils.writeJson(response, modelMap);
		return null;
	}
	
	public String getDefaultContractTempletAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
		Context ctx = SHRContext.getInstance().getContext();
		try {
			IParamControl ipc = ParamControlFactory.getLocalInstance(ctx);
			String defaultContractTempletNumber = ipc.getParamValue(null, "defaultContractTempletNumber");
			ContractTempletCollection contractTempletCollection = ContractTempletFactory.getLocalInstance(ctx).getContractTempletCollection("where number = '"+defaultContractTempletNumber+"'");
			if(contractTempletCollection!=null && contractTempletCollection.size()>0) {
				ContractTempletInfo contractTempletInfo = contractTempletCollection.get(0);
				modelMap.put("contractTempletId", contractTempletInfo.getId().toString());
				modelMap.put("contractTempletName", contractTempletInfo.getName(Locale.ENGLISH));
			}
		} catch (BOSException e) {
			e.printStackTrace();
		} catch (EASBizException e) {
			e.printStackTrace();
		}  
		JSONUtils.writeJson(response, modelMap);
		return null;
	}

}
