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

import com.kingdee.bos.BOSException;
import com.kingdee.bos.metadata.entity.FilterInfo;
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.json.GridDataEntity;
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.F7Handler;
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 DormitoryF7Handler extends F7Handler {
    @Override
    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(filterName);
            }

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

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