package com.steering.pss.qcm;

import java.util.ArrayList;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.db.DBCommon;

/**
 * 订货规格
 * @author Administrator
 */
public class CoreSpecOrderBasics extends DBCommon {

    /**
     * 订货规格基础信息查询
     * @param specCode 产品规格代码
     * @param includeDeleted 是否包含已删除数据
     * @param name 产品规格描述
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject getLineList(String specCode,
            Boolean includeDeleted) {
        String deletedFlag = includeDeleted ? "0" : "";
        Object[] params = new Object[] { specCode, deletedFlag };
        return this.getDataBySqlID("CoreSpecificationsBasicsSupplement.QUERY",
                params);
    }

    /**
     * 新增订货规格
     * @param parms 新增订货规格参数
     * @return obj
     */
    public CoreReturnObject doAdd(ArrayList<ArrayList<Object>> parms) {
        CoreReturnObject cro = new CoreReturnObject();

        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreSpecificationsBasicsSupplement.ADD");

        ArrayList<Object> sqllist = new ArrayList<Object>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();

        for (int i = 0; i < parms.size(); i++) {
            sqllist.add(sql);
            parmlist.add(parms.get(i).toArray());
        }

        try {
            cro = this.getDao("TgDao").ExcuteTransction(sqllist, parmlist);
        }
        catch (Exception e) {
            cro = cro.SetErrInfo(e.getMessage());
        }

        return cro;
    }

    /**
     * 修改订货规格
     * @param parms 修改订货规格参数
     * @return obj
     */
    public CoreReturnObject doModify(ArrayList<ArrayList<Object>> parms) {

        CoreReturnObject cro = new CoreReturnObject();

        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreSpecificationsBasicsSupplement.MODIFY");

        ArrayList<Object> sqllist = new ArrayList<Object>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();

        for (int i = 0; i < parms.size(); i++) {
            sqllist.add(sql);
            parmlist.add(parms.get(i).toArray());
        }

        try {
            cro = this.getDao("TgDao").ExcuteTransction(sqllist, parmlist);
        }
        catch (Exception e) {
            cro = cro.SetErrInfo(e.getMessage());
        }

        return cro;

    }

    /**
     * 订货规格基础信息删除或恢复
     * @param plineCodes 产线代码集合
     * @param operator 操作人
     * @param isDelete true删除 false恢复
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject deleteLineInfo(ArrayList<Object> plineCodes,
            String operator, Boolean isDelete) {
        ArrayList<String> sqlIDList = new ArrayList<String>();
        ArrayList<Object[]> params = new ArrayList<Object[]>();
        for (int i = 0; i < plineCodes.size(); i++) {
            if (isDelete) {
                sqlIDList.add("CoreSpecificationsBasicsSupplement.DELETE");
                params.add(new Object[] { operator,
                        plineCodes.get(i).toString() });
            }
            else {
                sqlIDList.add("CoreSpecificationsBasicsSupplement.RESUME");
                params.add(new Object[] { plineCodes.get(i).toString() });
            }
        }
        return this.setDataById(sqlIDList, params);
    }
}
