package cc.smtweb.system.bpm.web.design.db;

import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.mvc.service.DefaultComboHandler;
import cc.smtweb.framework.core.util.CommUtil;

import java.util.List;
import java.util.Set;

/**
 * Created by Akmm at 2022/3/22 19:25
 */
public class ModelTableComboHandler extends DefaultComboHandler<ModelTable> {
    public ModelTableComboHandler() {
        super(ModelTable.ENTITY_NAME);
    }

    @Override
    protected void buildCondition(StringBuilder sql, List<Object> args) {
        super.buildCondition(sql, args);
        long prj_id = params.readLong("prj_id");
        if (prj_id > 0) {
            Set<Long> setId = ModelProjectCache.getInstance().getDependsPrjIds(prj_id);
            if (!setId.isEmpty()) {
                sql.append(" and tb_prj_id in (").append(CommUtil.getSqlInIds(setId)).append(")");
            }
        }

        long db_id = params.readLong("db_id");
        if (db_id > 0) {
            sql.append(" and tb_db_id=?");
            args.add(db_id);
        }
    }
}
