package com.steering.pss.qcm;

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

import com.steering.comm.db.DBCommon;

/**
 * 工序基础信息管理类
 * @author WQ 2014/10/16
 * @version v1.0
 * @modify
 */
public class CoreProcessBasics extends DBCommon {
	/**
     * 工序基础信息查询
     * @param includeDeleted 是否包含已删除数据
     * @param name 工序描述
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
	public CoreReturnObject getLineList(Boolean includeDeleted,
            String name) {
        String deletedFlag = includeDeleted ? "0" : "";
        Object[] params = new Object[] { deletedFlag, name};
        return this.getDataBySqlID("CoreProcessBasics.QUERY", params);
	}
	
	/**
	 * 查询所有的工序
	 */
	public CoreReturnObject getAllProcess(){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreProcessBasics.getAllProcess");
		return this.getData(sql);
	}
	
	/**
     * 工序基础信息新增
     * @param parm 参数
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
	public CoreReturnObject doAdd(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory.getSql("CoreProcessBasics.ADD");
		try {
			cro = this.getDao("TgDao").ExcuteNonQuery(strSql, parm.toArray());
		} catch (SQLException e) {
			cro = cro.SetErrInfo(e.getMessage());
		}
		return cro;
	}
	
	/**
     * 工序基础信息修改
     * @param parm 参数
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
	public CoreReturnObject doModify(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory.getSql("CoreProcessBasics.MODIFY");
		try {
			cro = this.getDao("TgDao").ExcuteNonQuery(strSql, parm.toArray());
		} catch (SQLException 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("CoreProcessBasics.DELETE");
                params.add(new Object[] { operator,
                        plineCodes.get(i).toString() });
            }
            else {
                sqlIDList.add("CoreProcessBasics.RESUME");
                params.add(new Object[] { plineCodes.get(i).toString() });
            }
        }
		return this.setDataById(sqlIDList, params);
	}
    
    public CoreReturnObject getMaxProcess1Code(){
        return this.getDataBySqlID("CoreProcessBasics.getMaxProcess1Code");
    }
    
    public CoreReturnObject queryProcess2Data(ArrayList<String> list){
        return this.getDataBySqlID("CoreProcessBasics.queryProcess2Data", list.toArray());
    }
    
    public CoreReturnObject insertProcess2Data(ArrayList<String> list){
        return this.setDataBySqlID("CoreProcessBasics.insertProcess2Data", list.toArray());
    }
    
    public CoreReturnObject loadProcess1Data(){
        return this.getDataBySqlID("CoreProcessBasics.loadProcess1Data");
    }
    
    public CoreReturnObject getMaxProcess2Code(){
        return this.getDataBySqlID("CoreProcessBasics.getMaxProcess2Code");
    }
    
    public CoreReturnObject updateProcess2(ArrayList<String> list){
        return this.setDataBySqlID("CoreProcessBasics.updateProcess2", list.toArray());
    }
    
    public CoreReturnObject deleteOrResumeProcess2(ArrayList<String> list){
        if(list.get(0).equals("0")){
            return this.setDataBySqlID("CoreProcessBasics.deleteProcess2", list.toArray());
        }
        else {
            list.remove(1);
            return this.setDataBySqlID("CoreProcessBasics.resumeProcess2", list.toArray());
        }
    }
    
    public CoreReturnObject isExistProcess2(String process_Code_C, String process_Desc_C){
        ArrayList<String> list = new ArrayList<String>();
        list.add(process_Desc_C);
        list.add(process_Code_C);
        return this.getDataBySqlID("CoreProcessBasics.isExistProcess2", list.toArray());
    }
    
    public CoreReturnObject isExistProcess1(String process_Code, String process_Desc){
        ArrayList<String> list = new ArrayList<String>();
        list.add(process_Desc);
        list.add(process_Code);
        return this.getDataBySqlID("CoreProcessBasics.isExistProcess1", list.toArray());
    }
    
    public CoreReturnObject isExistProcess2Id(ArrayList<String> list){
        return this.getDataBySqlID("CoreProcessBasics.isExistProcess2Id", list.toArray());
    }
    
    public CoreReturnObject loadProcessStyle(){
        return this.getDataBySqlID("CoreProcessBasics.LoadProcessStyle");
    }
}
