package com.kingdee.shr.compensation.web.handler.integrate;

import java.util.Map;

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

import org.apache.commons.lang3.StringUtils;
import org.springframework.ui.ModelMap;

import com.google.common.collect.Maps;
import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
import com.kingdee.shr.compensation.app.integrate.CalSubmitSchemeFactory;
import com.kingdee.shr.compensation.app.integrate.CalSubmitSchemeInfo;
import com.kingdee.shr.compensation.util.columnModel.CmpColumnModels;
import com.kingdee.shr.customer.gtiit.handler.BaseSubmitBillEntryGenerator;

/**
 * 专业应用展示员工自助提报单表单Handler
 * @author xiaoxin
 *
 */
public class BatchSubmitShemeBillComEditHandler extends BatchSubmitShemeBillEditHandler{

	@Override
	public String getEditGridColModelAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
			throws SHRWebException {
		String submitSchemeId = request.getParameter("submitSchemeId");
		if (StringUtils.isEmpty(submitSchemeId)) {
			JSONUtils.writeJson(response, modelMap);
			return null;
		} else {
			boolean dynamicColmunRequired = this.isDynamicColmunRequired(request);
			Map<String, Object> params = Maps.newHashMap();
			params.put("datasource", Integer.valueOf(request.getParameter("datasource")));
			params.put("costTypeId", request.getParameter("costTypeId"));
			params.put("dynamicColmunRequired", dynamicColmunRequired);
			params.put("hrOrgUnitId", request.getParameter("hrOrgUnitId"));
			Context ctx = SHRContext.getInstance().getContext();
			CmpColumnModels cmpColumnModels = new BaseSubmitBillEntryGenerator().getEntryColumnModels(ctx, submitSchemeId,
					params);
			modelMap.put("colNames", cmpColumnModels.getColNames());
			modelMap.put("colModel", cmpColumnModels.getColModel());
			modelMap.put("defaultSortname", (Object) null);

			CalSubmitSchemeInfo schemeInfo;
			try {
				schemeInfo = CalSubmitSchemeFactory.getLocalInstance(ctx)
						.getCalSubmitSchemeInfo(new ObjectUuidPK(submitSchemeId));
			} catch (EASBizException var11) {
				throw new ShrWebBizException(var11.getMessage(), var11);
			} catch (BOSException var12) {
				throw new SHRWebException(var12.getMessage(), var12);
			}

			modelMap.put("description", schemeInfo.getDescription());
			JSONUtils.writeJson(response, modelMap);
			return null;
		}
	}
}
