package nccloud.web.mmsfc.dispatchlist.action;

import nc.ui.querytemplate.querytree.IQueryScheme;
import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO;
import nc.vo.mmsfc.dispatchlist.entity.AggDispatchlistVO;
import nc.vo.pubapp.pattern.pub.SqlBuilder;
import nc.vo.pubapp.query2.sql.process.QueryCondition;
import nc.vo.pubapp.query2.sql.process.QuerySchemeProcessor;
import nccloud.dto.mmpub.page.entity.MMQueryTreeFormatVO;
import nccloud.framework.web.ui.pattern.grid.Grid;
import nccloud.pub.mmsfc.dispatchlist.enums.ListTabEnum;
import nccloud.web.mmpub.page.action.AbstractPageQueryAction;
import nccloud.web.mmsfc.dispatchlist.util.DispatchlistScaleUtil;

public class DispatchListListQueryAction extends AbstractPageQueryAction<AggDispatchlistVO> {
    public DispatchListListQueryAction() {
    }

    protected void afterProcess(Grid grid) {
        DispatchlistScaleUtil scale = new DispatchlistScaleUtil();
        scale.processGrid(grid);
    }

    public String getTabConditionClazz() {
        return "nccloud.pub.mmsfc.dispatchlist.rule.DispatchListTabCondition";
    }

    public String getAllTabCode() {
        return ListTabEnum.ALL.getCode();
    }

    public String[] getAllTabs() {
        return new String[]{ListTabEnum.ALL.getCode(), ListTabEnum.TO_COMMIT.getCode(), ListTabEnum.APPROVING.getCode(), ListTabEnum.EXECUTING.getCode()};
    }

    public String getOrderDirect() {
        return "asc";
    }

    public String[] getHeadOrderFields() {
        return new String[]{"vbillcode"};
    }

    @Override
    protected void modifyQuerySchme(MMQueryTreeFormatVO queryInfo, IQueryScheme queryScheme) {
        QuerySchemeProcessor processor = new QuerySchemeProcessor(queryScheme);

        // 获取主表字段的查询条件
        QueryCondition pmoStatus = processor.getQueryCondition("pmo_status");
        if (pmoStatus == null) {
            return;
        }
        String aliasTableName = processor.getTableAliasOfAttribute("pk_dispatchlist_b.cmooutputid");
        SqlBuilder sqlBuilder = new SqlBuilder();
        sqlBuilder.append("mm_mo.fitemstatus", pmoStatus.getValues());
        processor.appendFrom("inner join mm_mo on " + aliasTableName + ".cmooutputid =mm_mo.cmoid and " + sqlBuilder.toString());
//        processor.getFinalFromWhere()
    }

}
