//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package nc.bs.pu.m422x.query;

import nc.bs.pu.m422x.plugin.StoreReqAppPluginPoint;
import nc.bs.pu.m422x.query.rule.CanOutreqNumCalcRule;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.ui.querytemplate.querytree.IQueryScheme;
import nc.vo.pu.m422x.entity.StoreReqAppVO;
import nccloud.baseapp.core.log.NCCForUAPLogger;
import nccloud.commons.lang.ArrayUtils;

public class QueryFor4455BP1 extends Abstract422XRefQueryBP1 {
    public QueryFor4455BP1(IQueryScheme queryScheme) {
        super(queryScheme);
    }

    private void addRule(AroundProcesser<StoreReqAppVO> processer) {
        processer.addAfterRule(new CanOutreqNumCalcRule());
    }

    public StringBuilder makeGetPKSql() {
        StringBuilder wholeSql = new StringBuilder();
        wholeSql.append(" SELECT DISTINCT a.cpickmid,b.cpickm_bid");
        wholeSql.append(" FROM");
        wholeSql.append(" (");
        wholeSql.append(" SELECT cpickmid");
        wholeSql.append(this.psor.getFinalFromWhere());
        // 查询审核通过
        wholeSql.append(" AND fbillstatus = 1");
        // wholeSql.append(" AND APPROVERTIME > '2024-11-01'");
        // NCCForUAPLogger.debug("finalFromWhere = " + this.psor.getFinalFromWhere());
        wholeSql.append(" ) a");
        wholeSql.append(" INNER JOIN mm_pickm_b b ON b.cpickmid = a.cpickmid AND b.dr = 0 ");
        // 未出库数量>0
        wholeSql.append(" WHERE ");
        wholeSql.append(" ( COALESCE(b.nplanoutastnum, 0) - COALESCE(b.nshouldastnum, 0) - COALESCE(b.npscastnum, 0) - COALESCE(b.naccoutastnum, 0) ) > 0 ");
        NCCForUAPLogger.debug("wholeSql = " + wholeSql);
        return wholeSql;
    }

    protected StoreReqAppVO[] processQueryResult(StoreReqAppVO[] queryResult) {
        if (ArrayUtils.isEmpty(queryResult)) {
            return null;
        } else {
            AroundProcesser<StoreReqAppVO> processer = new AroundProcesser(StoreReqAppPluginPoint.PULL_4455);
            this.addRule(processer);
            return (StoreReqAppVO[]) processer.after(queryResult);
        }
    }
}
