package com.steering.pss.qcm;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
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.qcm.model.ComBaseCustomRPlineEntity;

/**
 * 最终用户与认证产线
 * @author Administrator
 */
public class CoreComBaseCustomRPline extends DBCommon {
    public CoreReturnObject getFinallUser(String finallUser) {
        Object[] params = new Object[] { finallUser };
        return this.getDataBySqlID("CoreComBaseCustomRPline.getFinallUser",
                params);
    }

    public CoreReturnObject getProDuc() {
        return this.getDataBySqlID("CoreComBaseCustomRPline.getProDuc");
    }

    public CoreReturnObject getProline(String customerNo, String producCode) {
        Object[] params = new Object[] { customerNo, producCode, customerNo,
                producCode };
        return this
                .getDataBySqlID("CoreComBaseCustomRPline.getProline", params);
    }

    public CoreReturnObject saveCustomRPline(
            ArrayList<ComBaseCustomRPlineEntity> custPlines, String customerNo,
            String producCode) {
        CoreReturnObject core = new CoreReturnObject();
        Connection con = null;
        PreparedStatement ps = null;
        try {
            con = this.getDao("TgDao").getConnection();
            con.setAutoCommit(false);
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreComBaseCustomRPline.deleteCustPline");
            ps = con.prepareStatement(sql);
            ps.setObject(1, customerNo);
            ps.setObject(2, producCode);
            ps.executeUpdate();
            sql = CoreXmlSqlParsersFactory
                    .getSql("CoreComBaseCustomRPline.addCustPline");
            for (ComBaseCustomRPlineEntity custPline : custPlines) {
                String sqlCust = EntityTool.fillSqlByEntity(sql, custPline);
                ps = con.prepareStatement(sqlCust);
                ps.executeUpdate();
            }
            ps.close();
            con.commit();

        }
        catch (SQLException e) {
            try {
                con.rollback();
            }
            catch (SQLException e1) {
                e1.printStackTrace();
            }
            e.printStackTrace();
        }
        finally {
            try {
                if (con != null)
                    con.close();
            }
            catch (SQLException e) {
                e.printStackTrace();
            }
        }

        return core;
    }
    
    
    public CoreReturnObject getCustPline(){
     return this.getDataBySqlID("CoreComBaseCustomRPline.getCustPline");
    }
}
