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

import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.sql.ParserException;
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 javax.servlet.http.HttpServletRequest;

public class OccupantsListHandler 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) throws SHRWebException {
        FilterInfo filterInfo = super.getTreeDomainFilter(request);
        if (filterInfo!=null){
            String sql = filterInfo.toSql();
            if (sql.indexOf("longNumber")>=0){
                if (sql.indexOf("LIKE")>=0){
                    sql = sql.replaceAll("longNumber","Dormitory.longNumber");
                }else {
                    sql = sql.replaceFirst("longNumber","Dormitory.longNumber");
                }
            }
            //(longNumber = 'A!1' OR parent.longNumber = 'A!1') AND isSealUp = 0
            if (sql.indexOf("parent.longNumber")>=0){
                sql = sql.replaceFirst("parent.longNumber","Dormitory.parent.longNumber");
            }


            if (sql.indexOf("isSealUp")>=0){
                sql = sql.replaceFirst("isSealUp","Dormitory.isSealUp");
            }
            try {
                filterInfo = new FilterInfo(sql);
            } catch (ParserException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
        return filterInfo;
    }
}
