package com.steering.pss.plan.order;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.DateFormat;

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

import com.steering.comm.db.DBCommon;
import com.steering.pss.plan.base.CorePlnComm;

/**
 * 销售合同处理类
 * @author 杨天海
 * @version 1.1
 */
public class CoreSaleOrderOP extends DBCommon {
    /**
     * 查询基础维护数据
     * @return
     */
    public CoreReturnObject queryBaseinfoAll() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryBaseinfoAll");
        return cro;
    }

    /**
     * 查询钢种
     * @return
     */
    public CoreReturnObject queryBaseGrade() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryBaseGrade");
        return cro;
    }
    
    /**
     * 查询是否Assel
     * @param ordLnPk
     * @return
     */
    public CoreReturnObject queryAsselFl(String ordLnPk){
        return this.getDataBySqlID("CoreSaleOrderOP.queryAsselFl", new Object[]{ ordLnPk });
    }

    /**
     * 查询基础维护数据
     * @param str 基础分类编码
     */
    public CoreReturnObject queryBaseinfo(String str) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryBaseinfo",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询投料原则，投料率
     * @param list 年月
     */
    public CoreReturnObject queryPutRate(ArrayList<Object> list) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryPutRate", list
                .toArray());
        return cro;
    }

    /**
     * 查询产线基础表
     * @param str 产线代码
     * @return
     */
    public CoreReturnObject queryBasePline(String str) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryBasePline",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询备料轧管产线
     * @return
     */
    public CoreReturnObject queryBlZgPline() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryZgPline");
        return cro;
    }

    /**
     * 查询监制基础表
     * @param list 监制编号,主制程号
     * @return
     */
    public CoreReturnObject queryLinePrdcr(ArrayList<Object> list) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryLinePrdcr", list
                .toArray());
        return cro;
    }

    /**
     * 查询规格基础表
     * @param str 规格代码
     * @return
     */
    public CoreReturnObject queryBasespec(String str) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryBasespec",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询客户基础表
     * @param str 客户编号
     * @return
     */
    public CoreReturnObject queryBaseCustomer(String str) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryBaseCustomer",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询附加要求信息
     * @param str 附加要求码
     * @return
     */
    public CoreReturnObject queryAddAsk(String str) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryAddAsk",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询附加要求基础表
     * @param str 附加要求项
     * @return
     */
    public CoreReturnObject queryBaseAddAsk(String str) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryBaseAddAsk",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询基础维护数据
     * @param str 快速检索码
     */
    public CoreReturnObject queryBaseinfoSort(String str) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryBaseinfoSort",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询品名基础表
     * @param str 品名代码
     */
    public CoreReturnObject queryProducType(String str) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryProducType",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询计重方式
     * @param str 附加要求编码
     */
    public CoreReturnObject queryWeighType(String str) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryWeighType",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询交货到站
     * @param list 合同行
     */
    public CoreReturnObject queryTransit(ArrayList<Object> list) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryTransit", list
                .toArray());
        return cro;
    }

    /**
     * 查询交货运输方案
     * @param list 合同行
     */
    public CoreReturnObject queryTranType(ArrayList<Object> list) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryTranType", list
                .toArray());
        return cro;
    }

    /**
     * 查询热处理组各部门已排产量
     * @param list 查询参数
     * @return object
     */
    public CoreReturnObject queryPlanWeight(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryPlanWeight",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询加工组各部门已排产量
     * @param list 查询参数
     * @return object
     */
    public CoreReturnObject queryJgxPlanWeight(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryJgxPlanWeight",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询轧管机组月排产量
     * @param list 查询参数
     * @return object
     */
    public CoreReturnObject queryRollPlanWeight(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryRollPlanWeight",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询销售合同
     * @param list 查询参数
     * @return object
     */
    public CoreReturnObject querySaleOrder(ArrayList<Object> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.querysaleorder", list
                .toArray());
        return cro;
    }

    /**
     * 查询接箍合同信息
     * @param str 接箍合同号
     * @return object
     */
    public CoreReturnObject queryJgbyOrderno(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryJgbyOrderno",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询备料需求信息
     * @param str 备料需求编号
     * @return object
     */
    public CoreReturnObject queryBLbyReqBlId(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryBLbyReqBlId",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询接箍合同
     * @return object
     */
    public CoreReturnObject queryJgOrder(ArrayList<Object> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryjgorder", list
                .toArray());
        return cro;
    }

    /**
     * 根据状态查询所有接箍合同
     * @return object
     */
    public CoreReturnObject queryJgDeal() {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.QueryJgDeal");
        return cro;
    }

    /**
     * 根据状态查询所有接箍料编辑信息
     * @return object
     */
    public CoreReturnObject queryJgDealedit() {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryJgDealedit");
        return cro;
    }

    /**
     * 查询短节备料需求信息
     * @return object
     */
    public CoreReturnObject queryDjBlNeed(ArrayList<Object> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryDjBlNeed", list
                .toArray());
        return cro;
    }

    /**
     * 查询接箍备料需求信息
     * @return object
     */
    public CoreReturnObject queryJgBlNeed() {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryJgBlNeed");
        return cro;
    }

    /**
     * 查询导出销售合同
     * @param list 查询参数
     * @return object
     */
    public CoreReturnObject queryExportSaleOrder(ArrayList<String> list,
            String notCraft) {
        CoreReturnObject cro = null;
        String isGuan = list.get(0);
        list.remove(0);
        if (isGuan.equals("")) {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.queryExportSaleOrder");
            if (notCraft.trim().equals("1")) {
                sql = sql + " AND T.CRAFT_FILE_NO IS NULL";
            }
            cro = this.getData(sql, list.toArray());
        }
        if (isGuan.equals("0")) {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.queryExportIsGSaleOrder");
            if (notCraft.trim().equals("1")) {
                sql = sql + " AND T.CRAFT_FILE_NO IS NULL";
            }
            cro = this.getData(sql, list.toArray());
        }
        if (isGuan.equals("1")) {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.queryExportNotGSaleOrder");
            if (notCraft.trim().equals("1")) {
                sql = sql + " AND T.CRAFT_FILE_NO IS NULL";
            }
            cro = this.getData(sql, list.toArray());
        }
        // 查询外部导入系统的合同
        if (isGuan.equals("-1")) {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.queryExportOutImport");
            if (notCraft.trim().equals("1")) {
                sql = sql + " AND T.CRAFT_FILE_NO IS NULL";
            }
            cro = this.getData(sql, list.toArray());
        }
        return cro;
    }

    /**
     * 查询已下发的接箍合同
     * @param list 查询参数
     * @return object
     */
    public CoreReturnObject queryIssJgOrder(ArrayList<String> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryIssJgOrder", list
                .toArray());
        return cro;
    }

    /**
     * 查询质量设计表得到DESGIN_KEY
     * @param list 查询参数
     * @return object
     */
    public CoreReturnObject queryDesginKey(ArrayList<Object> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.querydesginkey", list
                .toArray());
        return cro;
    }

    /**
     * 查询产品码
     * @param list 查询参数
     * @return object
     */
    public CoreReturnObject queryPsc(ArrayList<String> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.querypsc", list.toArray());
        return cro;
    }

    /**
     * 根据产品码查找对应冶金规范码
     * @param str 查询参数
     * @return object
     */
    public CoreReturnObject queryPscForMsc(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.querypscformsc",
                new Object[] { str });
        return cro;
    }

    /**
     * 根据备料冶金规范查找制程号
     * @param list 冶金规范码
     * @return object
     */
    public CoreReturnObject queryMscIndex(ArrayList<String> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryMscIndex", list
                .toArray());
        return cro;
    }

    /**
     * 查询工艺单号和负责人
     * @param list 合同头,合同行
     * @return
     */
    public CoreReturnObject queryMscTpco(ArrayList<Object> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryMscTpco", list
                .toArray());
        return cro;
    }

    /**
     * 根据质量设计查找制程号
     * @return object
     */
    public CoreReturnObject queryDesginIndex() {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryDesginIndex");
        return cro;
    }

    /**
     * 根据DESGIN_KEY查询接箍码
     * @param str 查询参数
     * @return object
     */
    public CoreReturnObject queryJgCode(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryjgcode",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询短节备料组
     * @param str desgin_key
     * @return object
     */
    public CoreReturnObject queryBlGroup(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryBlGroup",
                new Object[] { str });
        return cro;
    }

    /**
     * 根据DESGIN_KEY查询短节备料码
     * @param str 查询参数
     * @return object
     */
    public CoreReturnObject queryBlCode(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryblcode",
                new Object[] { str });
        return cro;
    }

    /**
     * 根据DESGIN_KEY与备料组查询短节备料码
     * @param list 查询参数
     * @return object
     */
    public CoreReturnObject queryBlCodeByGp(ArrayList<String> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryBlCodeByGp", list
                .toArray());
        return cro;
    }

    /**
     * 销售合同查询工序
     * @param list desgin_key和全程产线号
     * @return object
     */
    public CoreReturnObject queryMscplPrc(ArrayList<String> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryMscplPrc", list
                .toArray());
        return cro;
    }

    /**
     * 备料需求查询工序
     * @param list 冶金规范码和全程产线号
     * @return object
     */
    public CoreReturnObject queryBlProcess(ArrayList<String> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryblprocess", list
                .toArray());
        return cro;
    }

    /**
     * 根据接箍码查询接箍基础信息
     * @param str 查询参数
     * @return object
     */
    public CoreReturnObject queryJgBase(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryjgbase",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询备料清单表
     * @param str 查询参数
     * @return object
     */
    public CoreReturnObject queryBlList(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.querybllist",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询监制信息
     * @param str 监制编号
     * @return
     */
    public CoreReturnObject queryOrderPrdcr(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryOrderPrdcr",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询接箍合同接箍料
     * @param list 查询参数
     * @return object
     */
    public CoreReturnObject queryJgBl(ArrayList<String> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryjgbl", list.toArray());
        return cro;
    }

    /************************
     * 根据接箍合同查询接箍与备料对应关系
     * @param str 查询参数
     * @return object
     */
    public CoreReturnObject queryRelByJg(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryrelbyjg",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询合同行生产BOM
     * @param list 质量设计主键
     * @return object
     */
    public CoreReturnObject queryLine_bom(ArrayList<String> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryLine_bom", list
                .toArray());
        return cro;
    }

    /**
     * 查询物料基础表
     * @param str 物料编码
     * @return object
     */
    public CoreReturnObject queryMaterial(String str) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryMaterial",
                new Object[] { str });
        return cro;
    }

    /**
     * 接箍信息处理
     * @param listJG 接箍信息
     * @param listUpdate 合同更新信息
     * @return object
     */
    public CoreReturnObject tranSactionJg(ArrayList<ArrayList<String>> listJG,
            ArrayList<ArrayList<String>> listUpdate) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();

        for (int i = 0; i < listJG.size(); i++) {
            sqllist.add("CoreSaleOrderOP.SavePretreatJG");
            parmlist.add(listJG.get(i).toArray());
        }

        for (int i = 0; i < listUpdate.size(); i++) {
            sqllist.add("CoreSaleOrderOP.updateJgSaleorder");
            parmlist.add(listUpdate.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);

        // 判断是否可以下发
        for (int i = 0; i < listUpdate.size(); i++) {
            ArrayList<String> param = listUpdate.get(i);
            isPrepIssued(param.get(param.size() - 1));
        }
        return cro;
    }

    /**
     * 取消接箍合同
     * @param list
     * @return
     */
    public CoreReturnObject doCancelJg(ArrayList<ArrayList<Object>> list) {
        CoreReturnObject cro = null;
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();

        Connection conn = null;
        PreparedStatement psta = null;
        try {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.querySaleStatus");
            conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            conn.setAutoCommit(false);
            for (int i = 0; i < list.size(); i++) {
                psta = conn.prepareStatement(sql);
                psta.setString(1, list.get(i).get(1).toString());
                ResultSet rs = psta.executeQuery();
                while (rs.next()) {
                    // 查询接箍合同接箍量
                    String sqlJg = CoreXmlSqlParsersFactory
                            .getSql("CoreSaleOrderOP.haveJgOrder");
                    PreparedStatement ps = null;
                    ps = conn.prepareStatement(sqlJg);
                    ps.setString(1, rs.getString("ORDER_NO"));
                    ps.setString(2, rs.getString("ORDER_SEQ"));
                    ps.setString(3, rs.getString("DELIVERY_NO"));
                    ResultSet reSet = ps.executeQuery();
                    while (reSet.next()) {
                        // 更新接箍料需求量
                        String sqlJgBl = CoreXmlSqlParsersFactory
                                .getSql("CoreSaleOrderOP.queryrelbyjg");
                        PreparedStatement psJgl = conn
                                .prepareStatement(sqlJgBl);
                        psJgl.setString(1, reSet.getString("JG_ORDERNO"));
                        ResultSet rsJgl = psJgl.executeQuery();
                        while (rsJgl.next()) {
                            Date dt = new Date();// 如果不需要格式,可直接用dt,dt就是当前系统时间
                            DateFormat df = new SimpleDateFormat(
                                    "yyyy/MM/dd HH:mm:ss");// 设置显示格式
                            String nowTime = df.format(dt);// 用DateFormat的format()方法在dt中获取并以yyyy/MM/dd
                                                           // HH:mm:ss格式显示
                            double jgblReqWeight = rsJgl
                                    .getDouble("JGBL_REQ_WEIGHT");
                            int jgblReqNum = rsJgl.getInt("JGBL_REQ_NUM");

                            Object[] parm = new Object[] { -jgblReqWeight,
                                    -jgblReqNum, list.get(i).get(0).toString(),
                                    nowTime, rsJgl.getString("REQ_BL_ID") };
                            sqllist.add("CoreSaleOrderOP.updatejglneed");
                            parmlist.add(parm);
                        }
                        psJgl.close();
                        rsJgl.close();

                        // 删除接箍合同形成的接箍料。
                        sqllist.add("CoreSaleOrderOP.DeleteJgReq");
                        parmlist.add(new Object[] { reSet
                                .getString("JG_ORDERNO") });
                    }
                    ps.close();
                    reSet.close();

                    // 更新销售合同计划量
                    sqllist.add("CoreSaleOrderOP.updateJgSaleorder");
                    Object[] param = new Object[] { "0", "0", "0",
                            rs.getString("ORD_LN_DLY_PK") };
                    parmlist.add(param);

                    // 删除接箍合同
                    sqllist.add("CoreSaleOrderOP.RollbackJg");
                    param = new Object[] { rs.getString("ORDER_NO"),
                            rs.getString("ORDER_SEQ"),
                            rs.getString("DELIVERY_NO") };
                    parmlist.add(param);
                }
            }
            conn.commit();
        }
        catch (SQLException sqle) {
            try {
                conn.rollback();
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        finally {
            try {
                if (conn != null && !conn.isClosed()) {
                    conn.close();
                }
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        cro = this.setDataById(sqllist, parmlist);

        // 判断是否可以下发
        for (int i = 0; i < list.size(); i++) {
            ArrayList<Object> param = list.get(i);
            isPrepIssued(param.get(param.size() - 1).toString());
        }
        return cro;
    }

    /**
     * 短节备料处理
     * @param listBL 短节备料信息
     * @param param 合同更新信息
     * @return object
     */
    public CoreReturnObject tranSactionDj(ArrayList<ArrayList<String>> listBL,
            ArrayList<ArrayList<String>> param) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        for (int i = 0; i < listBL.size(); i++) {
            sqllist.add("CoreSaleOrderOP.SavePretreatBL");
            parmlist.add(listBL.get(i).toArray());
        }
        for (int i = 0; i < param.size(); i++) {
            sqllist.add("CoreSaleOrderOP.updateDjSaleorder");
            parmlist.add(param.get(i).toArray());
        }

        cro = this.setDataById(sqllist, parmlist);

        // 判断是否可以下发
        for (int i = 0; i < param.size(); i++) {
            ArrayList<String> list = param.get(i);
            isPrepIssued(list.get(list.size() - 1));
        }
        return cro;
    }

    /**
     * 撤消短节合同
     * @param list
     * @return
     */
    public CoreReturnObject doCancelDj(ArrayList<ArrayList<Object>> list) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();

        Connection conn = null;
        PreparedStatement psta = null;
        try {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.querySaleStatus");
            conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            conn.setAutoCommit(false);
            for (int i = 0; i < list.size(); i++) {
                psta = conn.prepareStatement(sql);
                psta.setString(1, list.get(i).get(0).toString());
                ResultSet rs = psta.executeQuery();
                while (rs.next()) {
                    Object[] parm = new Object[] { "0",
                            list.get(i).get(0).toString() };
                    Object[] param = new Object[] { rs.getString("ORDER_NO"),
                            rs.getString("ORDER_SEQ"),
                            rs.getString("DELIVERY_NO"), };
                    sqllist.add("CoreSaleOrderOP.updateDjSaleorder");
                    parmlist.add(parm);

                    sqllist.add("CoreSaleOrderOP.RollbackDj");
                    parmlist.add(param);
                }
                rs.close();
            }
            conn.commit();
        }
        catch (SQLException sqle) {
            try {
                conn.rollback();
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        finally {
            try {
                if (conn != null && !conn.isClosed()) {
                    conn.close();
                }
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        cro = this.setDataById(sqllist, parmlist);
        // 判断是否可以下发
        for (int i = 0; i < list.size(); i++) {
            ArrayList<Object> param = list.get(i);
            isPrepIssued(param.get(param.size() - 1).toString());
        }
        return cro;
    }

    /**
     * 通过合同号查询销售合同
     * @param list 合同号、行号、交货码
     * @return object
     */
    public CoreReturnObject querySaleByPrimary(ArrayList<String> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CoreSaleOrderOP.querySaleByPrimary", list
                .toArray());
        return cro;
    }

    /**
     * 查询接箍及备料关系
     * @param str 查询参数
     * @return object
     */
    public CoreReturnObject queryRelation(String str) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryrelation",
                new Object[] { str });
        return cro;
    }

    /**
     * 查询销售合同状态
     * @param list 合同主键
     * @return object
     */
    public CoreReturnObject querySaleStatus(ArrayList<String> list) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.querySaleStatus", list
                .toArray());
        return cro;
    }

    /**
     * 更新备料需求制程与工序信息
     * @param list 更新列表
     * @return object
     */
    public CoreReturnObject updateBlIndexChanged(ArrayList<String> list) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.setDataBySqlID("CoreSaleOrderOP.updateBlIndexChanged", list
                .toArray());
        return cro;
    }

    /**
     * 轧管确认
     * @param list 轧制月份、轧管产线
     * @return
     */
    public CoreReturnObject saveSaleOrderZg(ArrayList<ArrayList<String>> 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("CoreSaleOrderOP.saveSaleOrderZg");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);

        // 判断是否可以下发
        for (int i = 0; i < list.size(); i++) {
            ArrayList<String> param = list.get(i);
            isPrepIssued(param.get(param.size() - 1));
        }
        return cro;
    }

    /**
     * 钢种坯料确认
     * @param list
     * @return
     */
    public CoreReturnObject saveSaleOrderGrade(ArrayList<ArrayList<String>> 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("CoreSaleOrderOP.saveSaleOrderGrade");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);

        // 判断是否可以下发
        for (int i = 0; i < list.size(); i++) {
            ArrayList<String> param = list.get(i);
            isPrepIssued(param.get(param.size() - 1));
        }
        return cro;
    }

    /**
     * 镦拔扩确认
     * @param list 镦拔扩投入物料
     * @return
     */
    public CoreReturnObject saveSaleOrderBj(ArrayList<ArrayList<String>> 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("CoreSaleOrderOP.saveSaleOrderBj");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);

        // 判断是否可以下发
        for (int i = 0; i < list.size(); i++) {
            ArrayList<String> param = list.get(i);
            isPrepIssued(param.get(param.size() - 1));
        }
        return cro;
    }

    /**
     * 热处理确认
     * @param list 加工组、热处理组
     * @return
     */
    public CoreReturnObject saveSaleOrderRcl(ArrayList<ArrayList<String>> 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("CoreSaleOrderOP.saveSaleOrderRcl");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);

        // 判断是否可以下发
        for (int i = 0; i < list.size(); i++) {
            ArrayList<String> param = list.get(i);
            isPrepIssued(param.get(param.size() - 1));
        }
        return cro;
    }

    /**
     * 加工线确认
     * @param list 加工组、热处理组
     * @return
     */
    public CoreReturnObject saveSaleOrderGjg(ArrayList<ArrayList<String>> 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("CoreSaleOrderOP.saveSaleOrderGjg");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);

        // 判断是否可以下发
        for (int i = 0; i < list.size(); i++) {
            ArrayList<String> param = list.get(i);
            isPrepIssued(param.get(param.size() - 1));
        }
        return cro;
    }

    /**
     * 预处理信息保存
     * @param list 保存信息
     * @return Object
     */
    public CoreReturnObject updatePretreat(ArrayList<ArrayList<String>> list) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        Connection conn = null;
        PreparedStatement psta = null;
        try {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.queryPretreatNo");
            java.util.Date date = new java.util.Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String dateNowStr = sdf.format(date);
            String pretreatday = dateNowStr.substring(2, 6) + "X"
                    + dateNowStr.substring(4, 8);

            conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            conn.setAutoCommit(false);

            psta = conn.prepareStatement(sql);
            psta.setString(1, pretreatday);
            ResultSet rs = psta.executeQuery();
            while (rs.next()) {
                if (rs.getString("MAXACCEPT") != null
                        && !rs.getString("MAXACCEPT").equals("")) {
                    String sequences = rs.getString("MAXACCEPT");
                    if (sequences.length() > 2) {
                        sequences = sequences.substring(sequences.length() - 2,
                                sequences.length());
                    }
                    sequences = CorePlnComm.padding(sequences, '0', 2);
                    pretreatday = pretreatday + sequences;
                }
                else {
                    pretreatday = pretreatday + "01";
                }
            }

            for (int i = 0; i < list.size(); i++) {
                list.get(i).add(0, pretreatday);
                sqllist.add("CoreSaleOrderOP.updatePretreat");
                parmlist.add(list.get(i).toArray());
            }
            rs.close();
            psta.close();
            conn.commit();
        }
        catch (SQLException sqle) {
            try {
                conn.rollback();
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        finally {
            try {
                if (conn != null && !conn.isClosed()) {
                    conn.close();
                }
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }

    /**
     * 取消预处理
     * @param 更新状态
     * @param 记录回退日志
     * @return Object
     */
    public CoreReturnObject CancelPre(ArrayList<ArrayList<String>> listLog,
            ArrayList<ArrayList<String>> list) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        Connection conn = null;
        PreparedStatement psta = null;
        try {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.queryCancelPreNo");
            java.util.Date date = new java.util.Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String dateNowStr = sdf.format(date);
            String sequences = "";

            conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            conn.setAutoCommit(false);

            psta = conn.prepareStatement(sql);
            psta.setString(1, dateNowStr);
            ResultSet rs = psta.executeQuery();
            while (rs.next()) {
                if (rs.getString("MAXBACKLOGT") != null
                        && !rs.getString("MAXBACKLOGT").equals("")) {
                    sequences = rs.getString("MAXBACKLOGT");
                }
                else {
                    sequences = "1";
                }
            }

            for (int i = 0; i < listLog.size(); i++) {
                String cout = String.valueOf(Integer.parseInt(sequences) + i);
                if (cout.length() > 10) {
                    cout = cout.substring(cout.length() - 10, cout.length());
                }
                cout = CorePlnComm.padding(cout, '0', 10);

                listLog.get(i).add(0, dateNowStr + cout);
                sqllist.add("CoreSaleOrderOP.insertCancelPreLog");
                parmlist.add(listLog.get(i).toArray());

                // 更新销售合同各工序状态
                sqllist.add("CoreSaleOrderOP.updateCancelPre");
                parmlist.add(list.get(i).toArray());
            }
        }
        catch (SQLException sqle) {
            try {
                conn.rollback();
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        finally {
            try {
                if (conn != null && !conn.isClosed()) {
                    conn.close();
                }
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }

    /**
     * 查询回退合同日志
     * @param 查询条件
     */
    public CoreReturnObject queryCancelLog(ArrayList<String> list) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryCancelLog", list
                .toArray());
        return cro;
    }

    /**
     * 删除回退合同日志
     * @param 查询条件
     */
    public CoreReturnObject updateDeletelog(ArrayList<ArrayList<String>> 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(CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.updateDeletelog"));
            parmlist.add(list.get(i).toArray());
        }
        cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
        return cro;
    }

    /**
     * 更新短节备料组
     * @param list 短节备料组
     * @return Object
     */
    public CoreReturnObject updateDjBlGroup(ArrayList<String> list) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.setDataBySqlID("CoreSaleOrderOP.updateDjBlGroup", list
                .toArray());
        return cro;
    }

    /**
     * 判断备料是否可以下发
     * @param blReqId
     */
    private void isBliussed(String blReqId) {
        Connection conn = null;
        PreparedStatement psta = null;
        try {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.queryBLbyReqBlId");
            conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            conn.setAutoCommit(false);
            psta = conn.prepareStatement(sql);
            psta.setString(1, blReqId);
            ResultSet rs = psta.executeQuery();
            while (rs.next()) {
                if (rs.getString("D_IS_OK") != null
                        && !rs.getString("D_IS_OK").equals("0")
                        && rs.getString("E_IS_OK") != null
                        && !rs.getString("E_IS_OK").equals("0")
                        && rs.getString("F_IS_OK") != null
                        && !rs.getString("F_IS_OK").equals("0")
                        && rs.getString("GRADECODE") != null
                        && rs.getString("JGBL_REQ_WEIGHT") != null
                        && !rs.getString("JGBL_REQ_WEIGHT").equals("0")
                        && rs.getString("JGBL_REQ_NUM") != null
                        && !rs.getString("JGBL_REQ_NUM").equals("0")) {
                    this.setDataBySqlID("CoreSaleOrderOP.IfAllowBlIssue",
                            new Object[] { "1", blReqId });
                }
                else {
                    this.setDataBySqlID("CoreSaleOrderOP.IfAllowBlIssue",
                            new Object[] { "0", blReqId });
                }
            }
            psta.close();
            rs.close();
            conn.commit();
        }
        catch (SQLException sqle) {
            try {
                conn.rollback();
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        finally {
            try {
                if (conn != null && !conn.isClosed()) {
                    conn.close();
                }
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    /**
     * 保存接箍料需求信息，并保存接箍与备料关系
     * @param list 需求信息
     * @param listrlation 对应关系
     * @param listupdate 更新接箍料信息
     * @return object
     */
    public CoreReturnObject saveJglNeed(ArrayList<ArrayList<String>> list,
            ArrayList<ArrayList<String>> listrlation,
            ArrayList<ArrayList<String>> listupdate) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();

        Connection conn = null;
        PreparedStatement psta = null;
        try {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.queryJgReqblid");
            String sequences = "";
            conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            conn.setAutoCommit(false);
            psta = conn.prepareStatement(sql);
            ResultSet rs = psta.executeQuery();
            while (rs.next()) {
                if (rs.getString("REQ_BL_ID") != null
                        && !rs.getString("REQ_BL_ID").equals("")) {
                    sequences = rs.getString("REQ_BL_ID");
                }
                else {

                }
                break;
            }
            rs.close();
            psta.close();
            conn.commit();

            for (int i = 0; i < list.size(); i++) {
                String num = String.valueOf(Integer.parseInt(sequences
                        .substring(13, 16))
                        + i);
                num = sequences.substring(0, 13)
                        + CorePlnComm.padding(num, '0', 3);
                for (int j = 0; j < listrlation.size(); j++) {
                    if (listrlation.get(j).get(1).equals(list.get(i).get(0))) {
                        listrlation.get(j).set(1, num);
                        sqllist.add(CoreXmlSqlParsersFactory
                                .getSql("CoreSaleOrderOP.saverelation"));
                        parmlist.add(listrlation.get(j).toArray());
                    }
                }

                list.get(i).set(0, num);
                sqllist.add(CoreXmlSqlParsersFactory
                        .getSql("CoreSaleOrderOP.savejglneed"));
                parmlist.add(list.get(i).toArray());
            }

            for (int i = 0; i < listupdate.size(); i++) {
                sqllist.add(CoreXmlSqlParsersFactory
                        .getSql("CoreSaleOrderOP.UpdateBlreq"));
                parmlist.add(listupdate.get(i).toArray());
            }
        }
        catch (SQLException sqle) {
            try {
                conn.rollback();
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        finally {
            try {
                if (conn != null && !conn.isClosed()) {
                    conn.close();
                }
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);

        // 更新接箍合同对应销售合同接箍料编制状态
        for (int i = 0; i < listupdate.size(); i++) {
            isFinishedJgl(listupdate.get(i).get(1).toString());
        }
        return cro;
    }

    /**
     * 是否完成接箍料编制
     * @param jgOrderNum 接箍合同号
     */
    private void isFinishedJgl(String jgOrderNum) {
        Connection conn = null;
        PreparedStatement psta = null;
        try {
            boolean isFinished = true;
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.queryJgbyOrderno");
            conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            conn.setAutoCommit(false);

            psta = conn.prepareStatement(sql);
            psta.setString(1, jgOrderNum);
            ResultSet result = psta.executeQuery();
            while (result.next()) {
                if (result.getString("ORDER_NO") != null
                        && result.getString("ORDER_SEQ") != null
                        && result.getString("DELIVERY_NO") != null) {
                    String order_no = result.getString("ORDER_NO");
                    String order_seq = result.getString("ORDER_SEQ");
                    String delivery_no = result.getString("DELIVERY_NO");

                    // 查询接箍合同信息,判断是否完成接箍料编制
                    sql = CoreXmlSqlParsersFactory
                            .getSql("CoreSaleOrderOP.haveJgOrder");
                    PreparedStatement psta1 = conn.prepareStatement(sql);
                    psta1.setString(1, order_no);
                    psta1.setString(2, order_seq);
                    psta1.setString(3, delivery_no);
                    ResultSet rs = psta1.executeQuery();
                    while (rs.next()) {
                        if (rs.getString("IFBUYPLAN") != null
                                && !rs.getString("IFBUYPLAN").equals("1")) {
                            if (rs.getInt("ORDERNUM") > rs.getInt("JGWT_BLREQ")
                                    + rs.getInt("MATCHNUM")) {
                                isFinished = false;
                            }
                        }
                    }
                    rs.close();
                    psta1.close();

                    // 如果完成，更新销售合同接箍料需求是否制订
                    ArrayList<String> sqllist = new ArrayList<String>();
                    ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
                    if (isFinished) {
                        sqllist.add("CoreSaleOrderOP.isFinishedJgOrder");
                        parmlist.add(new Object[] { "1", jgOrderNum });

                        sqllist.add("CoreSaleOrderOP.isFinishedJgl");
                        parmlist.add(new Object[] { "1", order_no, order_seq,
                                delivery_no });
                        this.setDataById(sqllist, parmlist);
                    }
                    else {
                        sqllist.add("CoreSaleOrderOP.isFinishedJgOrder");
                        parmlist.add(new Object[] { "0", jgOrderNum });

                        sqllist.add("CoreSaleOrderOP.isFinishedJgl");
                        parmlist.add(new Object[] { "0", order_no, order_seq,
                                delivery_no });
                        this.setDataById(sqllist, parmlist);
                    }

                    // 判断是否可以下发
                    // 查询接箍合同信息,判断是否完成接箍料编制
                    sql = CoreXmlSqlParsersFactory
                            .getSql("CoreSaleOrderOP.querySaleByPrimary");
                    psta1 = conn.prepareStatement(sql);
                    psta1.setString(1, order_no);
                    psta1.setString(2, order_seq);
                    psta1.setString(3, delivery_no);
                    rs = psta1.executeQuery();
                    while (rs.next()) {
                        String ord_ln_dly_pk = rs.getString("ORD_LN_DLY_PK");
                        isPrepIssued(ord_ln_dly_pk);
                    }
                    rs.close();
                    psta1.close();
                }
            }
            result.close();
            psta.close();
            conn.commit();
        }
        catch (SQLException sqle) {
            try {
                conn.rollback();
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        finally {
            try {
                if (conn != null && !conn.isClosed()) {
                    conn.close();
                }
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    /**
     * 判断是否可以下发
     * @param ord_ln_dly_pk
     */
    private void isPrepIssued(String ord_ln_dly_pk) {
        Connection conn = null;
        PreparedStatement psta = null;
        try {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.querySaleStatus");
            conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            conn.setAutoCommit(false);

            psta = conn.prepareStatement(sql);
            psta.setString(1, ord_ln_dly_pk);
            ResultSet rs = psta.executeQuery();
            while (rs.next()) {
                // 合同状态为已接收
                if (rs.getString("PORDERSTATUS") != null
                        && rs.getString("PORDERSTATUS").equals("1")) {
                    if (rs.getString("JGORD_IS_OK") != null
                            && rs.getString("JGL_REQ_IS_OK") != null
                            && rs.getString("DJBL_REQ_IS_OK") != null
                            && rs.getString("D_IS_OK") != null
                            && rs.getString("E_IS_OK") != null
                            && rs.getString("F_IS_OK") != null
                            && rs.getString("G_IS_OK") != null
                            && !rs.getString("JGORD_IS_OK").equals("0")
                            && !rs.getString("JGL_REQ_IS_OK").equals("0")
                            && !rs.getString("DJBL_REQ_IS_OK").equals("0")
                            && !rs.getString("D_IS_OK").equals("0")
                            && !rs.getString("E_IS_OK").equals("0")
                            && !rs.getString("F_IS_OK").equals("0")
                            && !rs.getString("G_IS_OK").equals("0")) {
                        // 接箍、接箍料需求、短节备料需求、钢种是否确认、
                        // 轧管、管加工都经过确认
                        this.setDataBySqlID("CoreSaleOrderOP.IfAllowIssue",
                                new Object[] { "1", ord_ln_dly_pk });
                    }
                    else {
                        this.setDataBySqlID("CoreSaleOrderOP.IfAllowIssue",
                                new Object[] { "0", ord_ln_dly_pk });
                    }
                }
            }
            rs.close();
            psta.close();
            conn.commit();
        }
        catch (SQLException sqle) {
            try {
                conn.rollback();
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        finally {
            try {
                if (conn != null && !conn.isClosed()) {
                    conn.close();
                }
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    /**
     * 更新接箍料需求信息，并更新接箍与备料关系
     * @param list 备料需求信息
     * @param listUpdateRel 更新对应关系
     * @param listRelation 新建对应关系
     * @param listupdate 更新接箍料信息
     * @return object
     */
    public CoreReturnObject updateJglNeed(ArrayList<String> list,
            ArrayList<ArrayList<String>> listUpdateRel,
            ArrayList<ArrayList<String>> listRelation,
            ArrayList<ArrayList<String>> listupdate) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        sqllist.add(CoreXmlSqlParsersFactory
                .getSql("CoreSaleOrderOP.updatejglneed"));
        parmlist.add(list.toArray());
        for (int i = 0; i < listUpdateRel.size(); i++) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.updaterelation"));
            parmlist.add(listUpdateRel.get(i).toArray());
        }
        for (int i = 0; i < listRelation.size(); i++) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.saverelation"));
            parmlist.add(listRelation.get(i).toArray());
        }
        for (int i = 0; i < listupdate.size(); i++) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.UpdateBlreq"));
            parmlist.add(listupdate.get(i).toArray());
        }
        cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);

        // 更新接箍合同对应销售合同接箍料编制状态
        for (int i = 0; i < listupdate.size(); i++) {
            isFinishedJgl(listupdate.get(i).get(1).toString());
        }
        return cro;
    }

    /**
     * 删除备料需求信息
     * @param listRel 接箍与备料对应关系信息
     * @param list 备料信息
     * @return object
     */
    public CoreReturnObject deleteBlNeed(ArrayList<ArrayList<String>> listRel,
            ArrayList<ArrayList<String>> listJgl,
            ArrayList<ArrayList<String>> list) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        for (int i = 0; i < listRel.size(); i++) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.DeleteRelation"));
            parmlist.add(listRel.get(i).toArray());
        }
        for (int i = 0; i < listJgl.size(); i++) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.DeleteBlneed"));
            parmlist.add(listJgl.get(i).toArray());
        }
        for (int i = 0; i < list.size(); i++) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.UpdateBlreq"));
            parmlist.add(list.get(i).toArray());
        }
        cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);

        // 更新接箍合同对应销售合同接箍料编制状态
        for (int i = 0; i < list.size(); i++) {
            isFinishedJgl(list.get(i).get(1).toString());
        }
        return cro;
    }

    /**
     * 删除接箍与备料关系
     * @param list_Rel 接箍与接箍料关系信息
     * @param list_Jgl 接箍料需求更新信息
     * @return object
     */
    public CoreReturnObject deleteJglOne(ArrayList<ArrayList<String>> list_Rel,
            ArrayList<ArrayList<String>> list_Jgl,
            ArrayList<ArrayList<String>> list) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        for (int i = 0; i < list_Rel.size(); i++) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.DeleteRelation"));
            parmlist.add(list_Rel.get(i).toArray());
        }
        for (int i = 0; i < list_Jgl.size(); i++) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.updatejglneed"));
            parmlist.add(list_Jgl.get(i).toArray());
        }
        for (int i = 0; i < list.size(); i++) {
            sqllist.add(CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.UpdateBlreq"));
            parmlist.add(list.get(i).toArray());
        }
        cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);

        // 更新接箍合同对应销售合同接箍料编制状态
        for (int i = 0; i < list.size(); i++) {
            isFinishedJgl(list.get(i).get(1).toString());
        }
        return cro;
    }

    /**
     * 下发接箍合同
     * @param list 接箍合同信息
     * @return object
     */
    public CoreReturnObject issuedJgOrder(ArrayList<ArrayList<String>> 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("CoreSaleOrderOP.issuedJgOrder");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }

    /**
     * 取消下发接箍合同
     * @param list
     * @return object
     */
    public CoreReturnObject cancelJgIssued(ArrayList<ArrayList<String>> 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("CoreSaleOrderOP.cancelJgIssued");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }

    /**
     * 下发销售合同
     * @param list 更新列表
     * @param listPrc 各工序列
     * @return object
     */
    public CoreReturnObject issuedSaleOrder(ArrayList<ArrayList<String>> list,
            ArrayList<ArrayList<String>> listPrc,
            ArrayList<ArrayList<String>> listPss) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();

        // 工序合同
        for (int i = 0; i < listPrc.size(); i++) {
            String designKey = listPrc.get(i).get(0);
            String createName = listPrc.get(i).get(1);
            String ordLnDlyPk = listPrc.get(i).get(2);
            CoreSalePrcOrder prcOrder = new CoreSalePrcOrder(designKey,
                    createName);
            prcOrder.creatProcess(ordLnDlyPk);

            sqllist.addAll(prcOrder.getSqllist());
            parmlist.addAll(prcOrder.getParmlist());
        }

        // /更新合同信息
        for (int i = 0; i < list.size(); i++) {
            sqllist.add("CoreSaleOrderOP.issuedSaleOrder");
            parmlist.add(list.get(i).toArray());
        }

        // /更新进程表
        for (int i = 0; i < listPss.size(); i++) {
            sqllist.add("CoreSaleOrderOP.updatePocessOrder");
            parmlist.add(listPss.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }

    /**
     * 取消下发销售合同
     * @param list
     * @param listOrder
     * @return
     */
    public CoreReturnObject cancelSaleIssued(ArrayList<ArrayList<String>> list,
            ArrayList<ArrayList<String>> listOrder,
            ArrayList<ArrayList<String>> listPss) {
        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("CoreSaleOrderOP.CancelSaleIssued");
            parmlist.add(list.get(i).toArray());

            // 删除轧管工序合同
            sqllist.add("CorePrcOrder.DelSaleProZg");
            parmlist.add(listOrder.get(i).toArray());

            // 删除镦拔扩工序合同
            sqllist.add("CorePrcOrder.DelSaleProBj");
            parmlist.add(listOrder.get(i).toArray());

            // 删除热处理工序合同
            sqllist.add("CorePrcOrder.DelSaleProRcl");
            parmlist.add(listOrder.get(i).toArray());

            // 删除加工线工序合同
            sqllist.add("CorePrcOrder.DelSaleProJgx");
            parmlist.add(listOrder.get(i).toArray());

            // 删除管坯需求合同
            sqllist.add("CorePrcOrder.DelSaleGpReq");
            parmlist.add(listOrder.get(i).toArray());
        }

        // /更新进程表
        for (int i = 0; i < listPss.size(); i++) {
            sqllist.add("CoreSaleOrderOP.updatePocessOrder");
            parmlist.add(listPss.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }

    /**
     * 下发备料需求
     * @param list 需求信息
     * @param listPro 轧管、热处理等工序列
     * @return object
     */
    public CoreReturnObject issuedJglNeed(ArrayList<ArrayList<String>> 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++) {
            // 备料下发工序
//            CoreBlPrcOrder prcOrder = new CoreBlPrcOrder("");
//            prcOrder.creatProcess(list.get(i).get(0));
//            sqllist.addAll(prcOrder.getSqllist());
//            parmlist.addAll(prcOrder.getParmlist());

            sqllist.add("CoreSaleOrderOP.IssuedJglNeed");
            parmlist.add(list.get(i).toArray());

            // 下发接箍与接箍料对应关系表
            sqllist.add("CoreSaleOrderOP.IssuedRelation");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }

    /**
     * 取消下发备料
     * @param list
     * @return
     */
    public CoreReturnObject cancelBlIssued(ArrayList<ArrayList<String>> 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("CoreSaleOrderOP.cancelBlIssued");
            parmlist.add(list.get(i).toArray());

            // 删除轧管工序合同
            sqllist.add("CorePrcOrder.DelBlProZg");
            parmlist.add(list.get(i).toArray());

            // 删除镦拔扩工序合同
            sqllist.add("CorePrcOrder.DelBlProBj");
            parmlist.add(list.get(i).toArray());

            // 删除热处理工序合同
            sqllist.add("CorePrcOrder.DelBlProRcl");
            parmlist.add(list.get(i).toArray());

            // 更新接箍料与接箍合同关系表
            sqllist.add("CoreSaleOrderOP.cancelBlrelIssued");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }

    /**
     * 更新接箍合同利库量和外购量
     * @param list 利库外购信息
     * @return object
     */
    public CoreReturnObject updateLkwgWeight(ArrayList<ArrayList<String>> 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(CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.UpdateLkwgWeight"));
            parmlist.add(list.get(i).toArray());
        }
        cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);

        // 更新接箍合同对应销售合同接箍料编制状态
        for (int i = 0; i < list.size(); i++) {
            isFinishedJgl(list.get(i).get(5).toString());
        }
        return cro;
    }

    /**
     * 保存短节备料需求利库信息
     * @param list 更新列表
     * @return object
     */
    public CoreReturnObject updateDjblRcl(ArrayList<ArrayList<String>> 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(CoreXmlSqlParsersFactory
                    .getSql("CoreSaleOrderOP.UpdateDjblRcl"));
            parmlist.add(list.get(i).toArray());
        }
        cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
        // 更新需求是否可以下发
        for (int i = 0; i < list.size(); i++) {
            String blReqid = list.get(i).get(list.get(i).size() - 1);
            isBliussed(blReqid);
        }
        return cro;
    }

    /**
     * 备料轧管确认
     * @param list
     * @return object
     */
    public CoreReturnObject confirmBlZg(ArrayList<ArrayList<String>> 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("CoreSaleOrderOP.confirmBlZg");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        // 更新需求是否可以下发
        for (int i = 0; i < list.size(); i++) {
            String blReqid = list.get(i).get(list.get(i).size() - 1);
            isBliussed(blReqid);
        }
        return cro;
    }

    /**
     * 备料镦拔扩确认
     * @param list
     * @return object
     */
    public CoreReturnObject confirmBlBj(ArrayList<ArrayList<String>> 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("CoreSaleOrderOP.confirmBlBj");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        // 更新需求是否可以下发
        for (int i = 0; i < list.size(); i++) {
            String blReqid = list.get(i).get(list.get(i).size() - 1);
            isBliussed(blReqid);
        }
        return cro;
    }

    /**
     * 备料热处理确认
     * @param list
     * @return object
     */
    public CoreReturnObject confirmBlRcl(ArrayList<ArrayList<String>> 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("CoreSaleOrderOP.confirmBlRcl");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        // 更新需求是否可以下发
        for (int i = 0; i < list.size(); i++) {
            String blReqid = list.get(i).get(list.get(i).size() - 1);
            isBliussed(blReqid);
        }
        return cro;
    }

    /**
     * 查询镦拔扩与轧管规格关联
     * @param list
     * @return object
     */
    public CoreReturnObject queryRollRupset(ArrayList<String> list) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CoreSaleOrderOP.queryRollRupset", list
                .toArray());
        return cro;
    }
}