package com.kingdee.shr.customer.gtiit.osf;
import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.bsf.service.app.IHRMsfService;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.eas.base.permission.PermItemFactory;
import com.kingdee.eas.base.permission.PermItemInfo;
import com.kingdee.eas.base.permission.UserFactory;
import com.kingdee.eas.base.permission.UserInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.hr.emp.EmployeeInterfacePermBizException;
import com.kingdee.eas.util.app.ContextUtil;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.shr.base.permission.api.service.SHRFunctionPermissionService;
import com.kingdee.shr.integration.oa.util.IntegrateOAUtil;
import com.kingdee.shr.integration.oa.util.MappingFieldInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GtiitPositionService implements IHRMsfService{
	private static final Logger logger = LoggerFactory.getLogger(GtiitPositionService.class);

	public Object process(Context ctx, Map param) throws EASBizException, BOSException {
		logger.error("GtiitPositionService enter ");
		new ArrayList();
		String positionPermItem = "fffffff0-ffff-efff-e22e-0000000dfa23PERMITEM";
		PermItemInfo permItem = PermItemFactory.getLocalInstance(ctx)
				.getPermItemInfo(new ObjectUuidPK(positionPermItem));

		try {
			SHRFunctionPermissionService.checkCurrnetUserFunctionPermission(ctx, permItem);
		} catch (Exception var9) {
			logger.error(var9.getMessage(), var9);
			String userId = ContextUtil.getCurrentUserInfo(ctx).getId().toString();
			UserInfo userInfo = UserFactory.getLocalInstance(ctx).getUserInfo(new ObjectUuidPK(userId));
			throw new EmployeeInterfacePermBizException(EmployeeInterfacePermBizException.NO_FUNCTION_PERMISSION,
					new Object[]{userInfo.getName(), permItem.getAlias()});
		}

		List<MappingFieldInfo> fieldList = this.initMappingField();
		StringBuffer sql = IntegrateOAUtil.getSelectFieldSql(fieldList);
		sql.append(" from t_org_position pos ");
		sql.append(" left join t_org_position parent on parent.fid=pos.FParentID");
		sql.append(" left join t_org_admin org on org.fid=pos.FAdminOrgUnitID");
		sql.append(" left join T_ORG_Job tjob on pos.FJobID=tjob.FID");
		sql.append(" left join T_HR_JobLevel jobLevl on pos.FJobLevelID=jobLevl.FID");
		sql.append(" where org.FIsStartSHR=1");
		sql.append(" order by org.flongNumber,pos.fnumber");
		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("Name");
		fieldInfo.setShrField("pos.fname_l2");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("Namel1");
		fieldInfo.setShrField("pos.fname_l1");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("fnumber");
		fieldInfo.setShrField("pos.FNumber");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("parent_id");
		fieldInfo.setShrField("pos.FParentID");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("dept_id");
		fieldInfo.setShrField("pos.FAdminOrgUnitID");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("effectdate");
		fieldInfo.setShrField("pos.FEFFDT");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("descn");
		fieldInfo.setShrField("pos.FDescription_L2");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("deletedstatus");
		fieldInfo.setShrField("pos.FDeletedStatus");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("isrespposition");
		fieldInfo.setShrField("pos.FIsRespPosition");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("eas_id");
		fieldInfo.setShrField("pos.fid");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("positiontype_id");
		fieldInfo.setShrField("pos.FJobLevelID");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("positiontype_name");
		fieldInfo.setShrField("jobLevl.FName_l2");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("fcreateTime");
		fieldInfo.setShrField("pos.fcreateTime");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("fLastUpdateTime");
		fieldInfo.setShrField("pos.FLastUpdateTime");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("fOrgNumber");
		fieldInfo.setShrField("org.FNumber");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("supFnumber");
		fieldInfo.setShrField("parent.FNumber");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("positiontype_number");
		fieldInfo.setShrField("jobLevl.FNumber");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("job_number");
		fieldInfo.setShrField("tjob.FNumber");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("longNamel1");
		fieldInfo.setShrField("pos.cflongname_l1");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("longNamel2");
		fieldInfo.setShrField("pos.cflongname_l2");
		list.add(fieldInfo);
		fieldInfo = new MappingFieldInfo();
		fieldInfo.setOaField("orgName");
		fieldInfo.setShrField("org.fsimplename");
		list.add(fieldInfo);
		return list;
	}
}
