package com.kingdee.eas.custom.expandassess.hadler;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.web.handler.DynamicListHandler;
import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
import com.kingdee.util.StringUtils;

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

/**
 * @author qingwu
 * @date 2024/5/17
 * @apiNote
 */
public class DynamicListHandlerEx  extends DynamicListHandler {
    /**
     * 获取生效日期过滤器
     * 移除父类方法过滤条件
     *
     * @param effectDate
     * @return
     */
    protected FilterInfo getEffectDateFilter(Date effectDate) {
        return null;
    }

    /**
     * 过滤分录数据  ID为空的数据
     *
     * @param request
     * @param params
     * @param filterCondition
     * @param effectDate
     * @return
     * @throws SHRWebException
     */
    @Override
    protected FilterInfo assembleFilterInfo(HttpServletRequest request, Map<String, String> params,
                                            Map filterCondition, Date effectDate) throws SHRWebException {
        FilterInfo filterInfo = super.assembleFilterInfo(request, params, filterCondition, effectDate);
        try {

            String custom_params = request.getParameter("custom_params");
            if (!StringUtils.isEmpty(custom_params)) {
                FilterInfo customFilter = new FilterInfo();
                Map customParams = JSONUtils.convertJsonToObject(custom_params);
                String billId = (String) customParams.get("billId");
                customFilter.getFilterItems().add(new FilterItemInfo("expandAssess.id", billId));
                customFilter.getFilterItems().add(new FilterItemInfo("entrys.id", null, CompareType.NOTEQUALS));
                filterInfo.mergeFilter(customFilter, "AND");
            }
            return filterInfo;
        } catch (BOSException e) {
            e.printStackTrace();
            throw new SHRWebException(e);
        }
    }
}
