package com.kingdee.eas.hr.emp.web.handler;


import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kingdee.shr.base.syssetting.json.GridDataEntity;
import com.kingdee.util.DateTimeUtils;
import com.kingdee.util.StringUtils;
import org.springframework.ui.ModelMap;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;


/**
 * 兼职单
 * @author coyle 
 * 20250331
 */
public class PositionAdminRangeF7HandlerEx extends EmpOrgF7Handler {
	
	
	public String getListDataAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
			throws SHRWebException {
		String modelFilter = (String) modelMap.get("filter");
		if (StringUtils.isEmpty(modelFilter)) {
			String filter = request.getParameter("filter");
			if (null != filter) {
				String empBatchEnrollConsecutiveAddNew;
				String filterEndSign;
				if (filter.indexOf("idRanFromPluralityAdd") != -1) {
					empBatchEnrollConsecutiveAddNew = filter.substring(0, filter.indexOf("idRanFromPluralityAdd"));
					filterEndSign = filter
							.substring(filter.indexOf("idRanFromPluralityAdd") + "idRanFromPluralityAdd".length());
					if (!StringUtils.isEmpty(filterEndSign)) {
						
						filter = empBatchEnrollConsecutiveAddNew
								+ " id not in (select fpositionid from T_HR_EmpOrgRelation t where t.fpersonid='"
								+ filterEndSign + "' and t.fleffdt = {2199-12-31}  and t.FISSYSTEM = 1)";
					} else {
						filter = empBatchEnrollConsecutiveAddNew;
					}
					modelMap.put("filter", filter);
				}

				if (filter.indexOf("idRanFromPluralityDel") != -1) {
					////202503 日期更改
					Date curDate  = new Date();
					String dateStr = DateTimeUtils.format(curDate, "yyyy-MM-dd");
					
					empBatchEnrollConsecutiveAddNew = filter.substring(0, filter.indexOf("idRanFromPluralityDel"));
					filterEndSign = filter
							.substring(filter.indexOf("idRanFromPluralityDel") + "idRanFromPluralityDel".length());
					filter = empBatchEnrollConsecutiveAddNew
							+ " id in (select fpositionid from T_HR_EmpOrgRelation t where t.fpersonid='"
							+ filterEndSign
							+ "' and t.fleffdt >= {"+dateStr+"}  and t.fassigntype=0 and t.fisInner = 1 and t.FActionID not in ('jpoAAAH/03nmaL7Z','V2vNOLaKRuGuv9/HNB5laOZovtk='))";
					modelMap.put("filter", filter);
				}

				if (filter.indexOf("idRanFromPositionHierarchy") != -1) {
					empBatchEnrollConsecutiveAddNew = filter.substring(0, filter.indexOf("idRanFromPositionHierarchy"));
					filterEndSign = filter.substring(
							filter.indexOf("idRanFromPositionHierarchy") + "idRanFromPositionHierarchy".length());
					filter = empBatchEnrollConsecutiveAddNew
							+ " id in (select fchildid from T_ORG_PositionHierarchy where FHierarchyID = '"
							+ filterEndSign + "')";
					modelMap.put("filter", filter);
				}

				if (filter.indexOf("F7query") != -1) {
					filter = filter.replace("F7query", "select");
					modelMap.put("filter", filter);
				}

				if (filter.indexOf("=''") != -1) {
					filter = filter.replace("=''", " is not null");
					modelMap.put("filter", filter);
				}

				if (filter.indexOf("empBatchEnrollConsecutiveAddNew") != -1) {
					empBatchEnrollConsecutiveAddNew = "empBatchEnrollConsecutiveAddNew";
					filterEndSign = "filterEndSign";
					int start = filter.indexOf(empBatchEnrollConsecutiveAddNew);
					int end = filter.indexOf(filterEndSign) + filterEndSign.length();
					String partFilterStr = filter.substring(start, end);
					String partFilterParam = partFilterStr.substring(empBatchEnrollConsecutiveAddNew.length(),
							partFilterStr.indexOf(filterEndSign));
					String[] partFilterParamArr = partFilterParam.split(",");
					String partFilterStrAfterTranfer = "";
					if (partFilterParamArr.length == 2) {
						String bizManageTypeId = partFilterParamArr[0];
						String manageHrOrgID = partFilterParamArr[1];
						partFilterStrAfterTranfer = "adminOrgUnit.id in (select FAdminOrgID from T_HR_AdminOrgBURelation where fbizManagetypeId='"
								+ bizManageTypeId + "' and FManageHrOrgID = '" + manageHrOrgID + "' and fstate = 1)";
					}

					filter = filter.replace(partFilterStr, partFilterStrAfterTranfer);
					modelMap.put("filter", filter);
				}
			}
		}

		return super.getListDataAction(request, response, modelMap);
	}

	protected void afterGetListData(HttpServletRequest request, HttpServletResponse response, GridDataEntity gridDataEntity) throws SHRWebException {
		
		
		
	}
	
}