package com.kingdee.eas.custom.abk.dormitory.handler;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemCollection;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.shr.base.syssetting.DomainFilterFacadeFactory;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.web.dynamic.model.ListUIViewInfo;
import com.kingdee.shr.base.syssetting.web.dynamic.model.TreeNavigationInfo;
import com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo;
import com.kingdee.shr.base.syssetting.web.handler.ListHandler;
import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
import com.kingdee.util.StringUtils;
import org.springframework.ui.ModelMap;

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

public class DormitoryListHandler extends ListHandler {
    @Override
    protected UIViewInfo getUIViewInfo(HttpServletRequest request) throws SHRWebException {
        ListUIViewInfo uiViewInfo = (ListUIViewInfo) super.getUIViewInfo(request);
        TreeNavigationInfo treeNavigation = uiViewInfo.getTreeNavigation();
        treeNavigation.setBuilder("com.kingdee.eas.custom.abk.dormitory.builder.DormitoryBuilder");
        uiViewInfo.setNavigateList(true);
        return uiViewInfo;
    }
    protected FilterInfo getTreeDomainFilter(HttpServletRequest request, Map<String, String> param) throws SHRWebException {
        ListUIViewInfo uiViewInfo = (ListUIViewInfo)this.getUIViewInfo(request);
        if (!uiViewInfo.isNavigateList()) {
            return null;
        } else {
            String filterName;
            if (param == null) {
                filterName = request.getParameter("tree_params");
                if (StringUtils.isEmpty(filterName)) {
                    return null;
                }

                param = JSONUtils.convertJsonToObject(SHRContext.getInstance().getContext(), filterName);
            }

            filterName = uiViewInfo.getTreeDomainFilter();
            if (StringUtils.isEmpty(filterName)) {
                filterName = "TreeLongNumberFilter";
            } else if (filterName.startsWith("$")) {
                filterName = filterName.substring(1).trim();
            }

            try {
                ((Map)param).putAll(this.assembleDomainParams(request));
                return DomainFilterFacadeFactory.getLocalInstance(SHRContext.getInstance().getContext()).getFilter(filterName, uiViewInfo.getQueryFieldName(), (Map)param);
            } catch (BOSException var6) {
                throw new SHRWebException(var6.getMessage(), var6);
            }
        }
    }

    @Override
    public String getTreeDataAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
        return super.getTreeDataAction(request, response, modelMap);
    }
}
