package com.steering.pss.plan.order;

import java.util.ArrayList;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plan.order.model.PlnSaleordProcEntity;

/**
 * 合同制程更改
 * @author xiaohai
 */
public class CoreChangeIndex extends DBCommon {
    /**
     * 查询合同拆分
     * @param ordLnDlyPk
     * @return
     */
    public CoreReturnObject queryPlnOrderProc(String ordLnDlyPk) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreChangeIndex.queryPlnOrderProc",
                new Object[] { ordLnDlyPk });
        return cro;
    }

    /**
     * 查询交货行子记录
     * @param ordLnDlyPk
     * @return
     */
    public CoreReturnObject queryPlnSaleOrderProc(String ordLnDlyPk) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreChangeIndex.queryPlnSaleOrderProc",
                new Object[] { ordLnDlyPk });
        return cro;
    }

    /**
     * 查询交货行子记录状态
     * @param ordLnDlyPk
     * @param plnDivideId
     * @return
     */
    public CoreReturnObject queryPlnOrdProcById(String ordLnDlyPk,
            String plnDivideId) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreChangeIndex.queryPlnOrdProcById",
                new Object[] { ordLnDlyPk, plnDivideId });
        return cro;
    }

    /**
     * 新增交货行子记录
     * @param ordProc
     * @return
     */
    public CoreReturnObject addPlnOrdProc(PlnSaleordProcEntity ordProc) {
        CoreReturnObject cro = new CoreReturnObject();
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreChangeIndex.addPlnOrdProc");
        String sqlAdd = EntityTool.fillSqlByEntity(sql, ordProc);
        cro = this.setData(sqlAdd);
        return cro;
    }

    /**
     * 更新交货行子记录拆分量
     * @param ordProc
     * @return
     */
    public CoreReturnObject updatePlnOrdProc(
            ArrayList<PlnSaleordProcEntity> list) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreChangeIndex.updatePlnOrdProc");
        for (int i = 0; i < list.size(); i++) {
            String sqlUp = EntityTool.fillSqlByEntity(sql, list.get(i));
            sqllist.add(sqlUp);
            parmlist.add(new Object[] {});
        }
        cro = this.setData(sqllist, parmlist);
        return cro;
    }

    /**
     * 删除交货行子记录
     * @param list
     * @return
     */
    public CoreReturnObject deletePlnOrdProc(ArrayList<ArrayList<Object>> list) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        for (int i = 0; i < list.size(); i++) {
            sqllist.add("CoreChangeIndex.deletePlnOrdProc");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }

}