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

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.bsf.service.app.IHRMsfService;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.shr.customer.gtiit.osf.util.DateUtils;
import com.kingdee.shr.integration.oa.util.IntegrateOAUtil;
import com.kingdee.shr.integration.oa.util.MappingFieldInfo;

/**
 * 获取职务的接口
 * @author zkwuh
 *
 */
public class GtiitLocalJobOsfService implements IHRMsfService{
	
	private static final Logger logger = LoggerFactory.getLogger(GtiitLocalJobOsfService.class);

	public Object process(Context ctx, Map map) throws EASBizException, BOSException {
		logger.error("GtiitLocalJobOsfService enter ");
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		// 开始时间
		String startDate = (String) map.get("startDate");
		// 结束时间
		String endDate = (String) map.get("endDate");
		if (StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)) {
			startDate=DateUtils.formatDate(startDate,true);
			endDate=DateUtils.formatDate(endDate,false);
		}
		logger.error("GtiitLocalJobOsfService接口入参开始时间" + startDate + ",结束时间" + endDate);
		List<MappingFieldInfo> fieldList = this.initMappingField();
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT\r\n" + 
				"	fid SHRID,\r\n" + 
				"	fnumber JOB_CODE,\r\n" + 
				"	fname_l1 JOB_NAME_EN,\r\n" + 
				"	fname_l2 JOB_NAME_CN,\r\n" + 
				"	cfapproval APPROVAL_AUTHORITY,\r\n" + 
				"	fcreatetime ERP_CREATION_DATE,\r\n" + 
				"	flastupdatetime ERP_LAST_UPDATE_DATE \r\n" + 
				"FROM\r\n" + 
				"	T_HR_HRJob");
		
		if(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)) {
			sql.append("  where flastupdatetime >= '"+startDate+"' and flastupdatetime <= '"+endDate+"'");
		}
		logger.info("GtiitLocalJobOsfService执行的SQL"+sql.toString());
		IRowSet rs = DbUtil.executeQuery(ctx, sql.toString());
		List<HashMap<String, String>> dataList = IntegrateOAUtil.getRsListData(fieldList, rs);
		return dataList;
	}

	private List<MappingFieldInfo> initMappingField() {
		List<MappingFieldInfo> list = new ArrayList();
		MappingFieldInfo fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("SHRID");
		fieldInfo.setShrField("SHRID");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("JOB_CODE");
		fieldInfo.setShrField("JOB_CODE");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("JOB_NAME_EN");
		fieldInfo.setShrField("JOB_NAME_EN");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("JOB_NAME_CN");
		fieldInfo.setShrField("JOB_NAME_CN");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("APPROVAL_AUTHORITY");
		fieldInfo.setShrField("APPROVAL_AUTHORITY");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("ERP_CREATION_DATE");
		fieldInfo.setShrField("ERP_CREATION_DATE");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("ERP_LAST_UPDATE_DATE");
		fieldInfo.setShrField("ERP_LAST_UPDATE_DATE");
		list.add(fieldInfo);
		return list;
	}
	

}
