package com.steering.pss.qcm;

import CoreFS.SA08.CoreXmlSqlParsersFactory;
import java.util.*;
import CoreFS.SA06.CoreReturnObject;
 
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.SqlBuilder;
import com.steering.comm.tools.StringTool;

@SuppressWarnings("unchecked")
public class JGRBLCode extends DBCommon {

    public CoreReturnObject GetGrid1() {
        return this.getDataBySqlID("JGRBLCode.InitJGRSTEEL"); // 初始化接箍码
    }

    /**
     * Title: doQuery
     * Description: 查询
     * @param steelcode  钢级代码
     * @return  平台统一返回对象
     */
    public CoreReturnObject doQuery(String steelcode) {
        Object[] obj = new Object[] { steelcode, steelcode };
        return this.getDataBySqlID("JGRBLCode.QUERY", obj);  
    }
    
    /**
     * Title: doQuery
     * Description: 查询2
     * @param steelcode  钢级代码
     * @return  平台统一返回对象
     */
    public CoreReturnObject doQuery2(String codeJg, String custAlphaNo, String alphaCode) {
        Object[] obj = new Object[] { codeJg, custAlphaNo, alphaCode};
        return this.getDataBySqlID("JGRBLCode.QUERY2", obj);  
    }

    /**
     * Title: doAdd
     * Description: 保存功能
     * @param params  关联的参数
     * @param activecode  激活行的接箍码
     * @return   平台统一返回对象
     */
    public CoreReturnObject doAdd(ArrayList<Object> params) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<Object> sqlIDList = new ArrayList<Object>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        if (params.size() > 0) {
            for (int i = 0; i < params.size(); i++) {
                ArrayList<Object> list = (ArrayList<Object>) params.get(i);
                parmlist.add(list.toArray());                              
                sqlIDList.add(CoreXmlSqlParsersFactory.getSql("JGRBLCode.ADD"));
            }//重新关联
        }
        cro = this.getDao("TgDao").ExcuteTransction(sqlIDList, parmlist);
        return cro;             
    }
    
    /**
     * 判断接箍和备料的关系是否重复
     * @param codeJg
     * @param pscBl
     * @param custAlphaNo
     * @param alphaCode
     * @return
     */
    public CoreReturnObject checkJgRBlIsRepeat(String codeJg, String pscBl, String custAlphaNo, String alphaCode){
    	String sql = CoreXmlSqlParsersFactory.getSql("JGRBLCode.checkJgRBlIsRepeat");
    	sql = StringTool.ReplaceAll(sql, "#CODE_JG#", codeJg);
    	sql = StringTool.ReplaceAll(sql, "#PSC_BL#", pscBl);
    	sql = StringTool.ReplaceAll(sql, "#CUST_ALPHA_NO#", custAlphaNo);
    	sql = StringTool.ReplaceAll(sql, "#ALPHA_CODE#", alphaCode);
    	return this.getData(sql);
    }
    
    /**
     * 删除备料和接箍的关系
     * @param codeJg
     * @param pscBl
     * @param custAlphaNo
     * @param alphaCode
     * @return
     */
    public CoreReturnObject delete(String codeJg, String pscBl, String custAlphaNo, String alphaCode){
    	String sql = CoreXmlSqlParsersFactory.getSql("JGRBLCode.delete");
    	sql = StringTool.ReplaceAll(sql, "#CODE_JG#", codeJg);
    	sql = StringTool.ReplaceAll(sql, "#PSC_BL#", pscBl);
    	sql = StringTool.ReplaceAll(sql, "#CUST_ALPHA_NO#", custAlphaNo);
    	sql = StringTool.ReplaceAll(sql, "#ALPHA_CODE#", alphaCode);
    	return this.setData(sql);
    }
    
    public CoreReturnObject getComMscJgByKeyJg(String keyJg){
    	SqlBuilder b = new SqlBuilder("JGRBLCode.getComMscJgByKeyJg");
    	b.Fill(new String[]{keyJg});
    	return this.getData(b.toString());
    }
}
