package com.steering.pss.buybillet;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import CoreFS.Util.StringUtils;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.pss.buybillet.Entity.MatGpMEntity;
import com.steering.pss.buybillet.Entity.PlnOrderDzSEntity;
import com.steering.pss.buybillet.Entity.PlnOrderZgSEntity;
import com.steering.pss.buybillet.Entity.PlnSteelEntity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
//import com.steering.pss.buybillet.model.*;

public class Buybillet extends DBCommon {
    public CoreReturnObject queryPLN_REQINF_GP() {

        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getPLN_REQINF_GP");
        return cro;
    }

    public CoreReturnObject queryPLN_REQINF_GP_DETAILS() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getPLN_REQINF_GP_DETAILS");
        return cro;
    }

    public CoreReturnObject queryGP_PIKIND() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getPiKind");
        return cro;
    }

    public CoreReturnObject queryGP_CICSTEELGRADES() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getCicSteelgrades");
        return cro;
    }

    public CoreReturnObject InsertBUY_GP_REQ(String ids) throws SQLException {
        Connection conn = null;
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        try {
            String[] _ids = ids.split(",");
            String id = _ids[0];
            ids = "";
            for (String str : _ids) {
                ids += "'";
                ids += str;
                ids += "'";
                ids += ",";
            }
            if (ids.endsWith(",")) {
                ids = ids.substring(0, ids.length() - 1);
            }

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

            String GPBUYPLANID = "";

            GPBUYPLANID = getGpBuyPlanId(conn);

            String sqlBeforeInsert = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.beforeInsertBUY_GP_REQ");
            sqlBeforeInsert = sqlBeforeInsert.replaceAll("#gpreq_id#", ids);

            sqllist.add(sqlBeforeInsert);
            parmlist.add(new Object[]{});

            String sqlInsert = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.insertBUY_GP_REQ");
            sqlInsert = sqlInsert.replaceAll("#gpreq_id#", ids);
            sqllist.add(sqlInsert);

            parmlist.add(new Object[]{GPBUYPLANID, id});
            String sqlUpdate = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.updatePLN_REQINF_GP_buyplanid");
            sqlUpdate += CoreConverter.toSqlConditionString("gpreq_id", _ids);
            sqllist.add(sqlUpdate);
            parmlist.add(new Object[]{GPBUYPLANID});
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (conn != null || !conn.isClosed()) {
                conn = null;
            }
        }
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
    }

    public CoreReturnObject InsertBUY_GP_REQ_YP(String pkind, String gz,
                                                String cic, String dm, String dbpc, String weight)
            throws SQLException {

        Connection conn = null;
        conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
        String GPBUYPLANID = "";
        try {
            GPBUYPLANID = getGpBuyPlanId(conn);

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (conn != null && !conn.isClosed()) {
                conn = null;
            }
        }
        String dmstr = String.format("%.2f", Float.parseFloat(dm));
        String materialname = "";
        String pab = "";
        if (pkind.equals("1")) {
            pab = "PA";
            materialname = "PA" + dmstr + "," + gz;
        }
        if (pkind.equals("2")) {
            pab = "PB";
            materialname = "PB" + dmstr + "," + gz;
        }
        // materialname = materialname.replace(" ","");
        return this.setDataBySqlID("BuyGpDAL.insertBUY_GP_REQ_YP",
                new Object[]{GPBUYPLANID, pkind, materialname, gz, dm, dbpc,
                        weight, gz, cic, pab, dmstr, gz});

    }

    // 删除需求单
    public CoreReturnObject DeleteBUY_GP_REQ(String ids) {
        ArrayList<String> sqllist = new ArrayList<String>();
        /*
         * String[] _ids = ids.split(","); ids = ""; for(String str : _ids){ ids
         * +="'"; ids +=str; ids +="'"; ids +=","; } if(ids.endsWith(",")){ ids
         * = ids.substring(0, ids.length()-1); }
         */
        // 更新需求单状态语句
        String sqlDelete = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.deleteBUY_GP_REQ");
        sqlDelete = sqlDelete.replaceAll("#GPPBUYPLANID#", ids);
        sqllist.add(sqlDelete);
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist);
    }

    public CoreReturnObject test1(String GPBUYPLANID, String ids) {
        return this.setDataBySqlID("BuyGpDAL.updatePLN_REQINF_GP_buyplanid",
                new Object[]{GPBUYPLANID, ids});
    }

    public CoreReturnObject queryBUY_GP_REQ() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ");
        return cro;
    }

    public CoreReturnObject queryBUY_GP_REQ1() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ1");
        return cro;
    }

    public CoreReturnObject queryBUY_GP_REQ2(String isTH) {
        CoreReturnObject cro = new CoreReturnObject();
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.getBUY_GP_REQ1");
        if (isTH.equals("TH")) {
            String[] strs = {"120504"};
            sqlSelect += CoreConverter.toSqlConditionString("SUPPLY_UNIT_CODE", strs);
        } else {
            String[] strs = {"120501"};
            sqlSelect += CoreConverter.toSqlConditionString("SUPPLY_UNIT_CODE", strs);
        }
        cro = this.getData(sqlSelect);
        return cro;
    }

    public CoreReturnObject queryBUY_GP_REQ3(String isTH,String req_status,String startdate,String enddate) {
        CoreReturnObject cro = new CoreReturnObject();
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.getBUY_GP_REQ1");
        if (isTH.equals("TH")) {
            String[] strs = {"120504"};
            sqlSelect += CoreConverter.toSqlConditionString("SUPPLY_UNIT_CODE", strs);
        } else {
            String[] strs = {"120501"};
            sqlSelect += CoreConverter.toSqlConditionString("SUPPLY_UNIT_CODE", strs);
        }
        if(!StringUtils.isEmpty(req_status) && !req_status.equals("0")){
            sqlSelect += "and a.REQ_STATUS = '" + req_status + "'";
        }
        if(!StringUtils.isEmpty(startdate) && !StringUtils.isEmpty(enddate)){
            sqlSelect += "and a.ISSUED_TIME >=  TO_DATE('"+ startdate +"', 'YYYY-MM-DD HH24:MI:SS')";
            sqlSelect += "and a.ISSUED_TIME <=  TO_DATE('"+ enddate +"', 'YYYY-MM-DD HH24:MI:SS')";
        }
        cro = this.getData(sqlSelect);
        return cro;
    }

    public CoreReturnObject updateGpreqVersion(ArrayList<ArrayList> ids) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        for (ArrayList id : ids) {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.updateGpreqVersion");
            sqllist.add(sql);
            parmlist.add(id.toArray());
        }
        cro = this.setData(sqllist,parmlist);
        return cro;
    }

    public CoreReturnObject queryBUY_GP_REQ_XS() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ_XS");
        return cro;
    }

    //本部外购坯需求(销售)
    public CoreReturnObject queryBUY_GP_REQ_XS1() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ_XS1");
        return cro;
    }

    //天淮外购坯需求(销售)
    public CoreReturnObject queryBUY_GP_REQ_XS1TH() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ_XS1TH");
        return cro;
    }

    //天淮外购坯需求(双经销)
    public CoreReturnObject queryBUY_GP_REQ_XS1THSJX() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ_XS1THSJX");
        return cro;
    }

    //天淮外购坯需求(定销订购)
    public CoreReturnObject queryBUY_GP_REQ_XS1THSJX1() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ_XS1THSJX1");
        return cro;
    }

    //天淮外购坯需求(来料加工)
    public CoreReturnObject queryBUY_GP_REQ_XS1THSJX2() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ_XS1THSJX2");
        return cro;
    }

    //天淮外购坯需求(库存商备坯)
    public CoreReturnObject queryBUY_GP_REQ_XS1THSJX3() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ_XS1THSJX3");
        return cro;
    }

    // 查找符合特定供应商的需求单
    public CoreReturnObject queryBUY_GP_SpecialSupplier(String supplier) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ_SpecialSupplier",
                new Object[]{supplier});
        return cro;
    }

    public CoreReturnObject queryBUY_GP_SpecialSupplier1(String supplier) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ_SpecialSupplier1",
                new Object[]{supplier});
        return cro;
    }

    public CoreReturnObject queryBUY_GP_SpecialSupplier1TH(String supplier) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ_SpecialSupplier1TH",
                new Object[]{supplier});
        return cro;
    }

    public CoreReturnObject queryBUY_BASE_CUSTOMER() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_BASE_CUSTOMER");
        return cro;
    }

    public CoreReturnObject queryBUY_BASE_CUSTOMERSJX() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_BASE_CUSTOMERSJX");
        return cro;
    }

    //定销订购
    public CoreReturnObject queryBUY_BASE_CUSTOMERSJX1() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_BASE_CUSTOMERSJX1");
        return cro;
    }

    //来料加工
    public CoreReturnObject queryBUY_BASE_CUSTOMERSJX2() {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("BuyGpDAL.getBUY_BASE_CUSTOMERSJX2");
        return cro;
    }

    public CoreReturnObject queryBUY_GP_REQ_SUPPLIER(String id) {
        return this.getDataBySqlID("BuyGpDAL.getBUY_GP_REQ_SUPPLIER",
                new Object[]{id});
    }

    // 生成采购合同
    public CoreReturnObject InsertBUY_GP_ORDER(String supplier, String ids) {
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String[] _ids = ids.split(",");
        /*
         * String GPBUYPLANID = ""; for(String str : _ids){ GPBUYPLANID +="'";
         * GPBUYPLANID +=str; GPBUYPLANID +="'"; GPBUYPLANID +=","; }
         * if(GPBUYPLANID.endsWith(",")){ GPBUYPLANID = GPBUYPLANID.substring(0,
         * GPBUYPLANID.length()-1); }
         */
        // 插入合同表语句
        String sqlInsert = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.insertBUY_GP_ORDER");
        sqlInsert += CoreConverter.toSqlConditionString("a.GPBUYPLANID", _ids);
        sqllist.add(sqlInsert);
        parmlist.add(new Object[]{supplier, supplier, supplier});
        // 更新需求单状态语句
        String sqlUpdate = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_REQ_Status2");
        sqlUpdate += CoreConverter.toSqlConditionString("GPBUYPLANID", _ids);
        sqllist.add(sqlUpdate);
        parmlist.add(new Object[]{});
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
    }

    public CoreReturnObject InsertBUY_GP_ORDER1(String supplier, String ids) {
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String[] _ids = ids.split(",");
        /*
         * String GPBUYPLANID = ""; for(String str : _ids){ GPBUYPLANID +="'";
         * GPBUYPLANID +=str; GPBUYPLANID +="'"; GPBUYPLANID +=","; }
         * if(GPBUYPLANID.endsWith(",")){ GPBUYPLANID = GPBUYPLANID.substring(0,
         * GPBUYPLANID.length()-1); }
         */
        // 插入合同表语句
        String sqlInsert = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.insertBUY_GP_ORDER1");
        sqlInsert += CoreConverter.toSqlConditionString("a.GPREQ_ID", _ids);
        sqllist.add(sqlInsert);
        parmlist.add(new Object[]{supplier, supplier, supplier});
        // 更新需求单状态语句
        String sqlUpdate = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_REQ_Status21");
        sqlUpdate += CoreConverter.toSqlConditionString("GPREQ_ID", _ids);
        sqllist.add(sqlUpdate);
        parmlist.add(new Object[]{});
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
    }

    public CoreReturnObject InsertBUY_GP_ORDER1SJH(String supplier, String ids) {
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String[] _ids = ids.split(",");
        /*
         * String GPBUYPLANID = ""; for(String str : _ids){ GPBUYPLANID +="'";
         * GPBUYPLANID +=str; GPBUYPLANID +="'"; GPBUYPLANID +=","; }
         * if(GPBUYPLANID.endsWith(",")){ GPBUYPLANID = GPBUYPLANID.substring(0,
         * GPBUYPLANID.length()-1); }
         */
        // 插入合同表语句
        String sqlInsert = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.insertBUY_GP_ORDER1SJX");
        sqlInsert += CoreConverter.toSqlConditionString("a.GPREQ_ID", _ids);
        sqllist.add(sqlInsert);
        parmlist.add(new Object[]{supplier, supplier, supplier});
        // 更新需求单状态语句
        String sqlUpdate = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_REQ_Status21");
        sqlUpdate += CoreConverter.toSqlConditionString("GPREQ_ID", _ids);
        sqllist.add(sqlUpdate);
        parmlist.add(new Object[]{});
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
    }

    // 删除采购合同
    public CoreReturnObject DeleteBUY_GP_ORDER(String ids) {
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String[] _ids = ids.split(",");
        ids = "";
        for (String str : _ids) {
            ids += "'";
            ids += str;
            ids += "'";
            ids += ",";
        }
        if (ids.endsWith(",")) {
            ids = ids.substring(0, ids.length() - 1);
        }

        // 更新需求单状态语句
        String sqlUpdate = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_REQ_Status21");
        sqlUpdate = sqlUpdate.replaceAll("#ORD_NO_PK#", ids);
        sqllist.add(sqlUpdate);

        // 删除合同表语句
        String sqlDelete = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.deleteBUY_GP_ORDER");
        sqlDelete += CoreConverter.toSqlConditionString("ORD_NO_PK", _ids);
        sqllist.add(sqlDelete);

        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist);
    }

    public CoreReturnObject DeleteBUY_GP_ORDER1(String ids) {
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String[] _ids = ids.split(",");
        ids = "";
        for (String str : _ids) {
            ids += "'";
            ids += str;
            ids += "'";
            ids += ",";
        }
        if (ids.endsWith(",")) {
            ids = ids.substring(0, ids.length() - 1);
        }

        // 更新需求单状态语句
        /*
         * String sqlUpdate =
         * CoreXmlSqlParsersFactory.getSql("BuyGpDAL.updateBUY_GP_REQ_Status211"
         * ); sqlUpdate = sqlUpdate.replaceAll("#ORD_NO_PK#", ids);
         * sqllist.add(sqlUpdate);
         */

        // 删除合同表语句
        String sqlDelete = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.deleteBUY_GP_ORDER2");
        sqlDelete = sqlDelete.replaceAll("#ORD_NO_PK#", ids);
        sqllist.add(sqlDelete);

        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist);
    }

    public CoreReturnObject queryBUY_GP_ORDER() {
        return this.getDataBySqlID("BuyGpDAL.getBUY_GP_ORDER");

    }

    public CoreReturnObject queryBUY_GP_ORDERTH() {
        return this.getDataBySqlID("BuyGpDAL.getBUY_GP_ORDERTH");

    }

    public CoreReturnObject queryBUY_BASE_CUSTOMERALL() {
        return this.getDataBySqlID("BuyGpDAL.getBUY_BASE_CUSTOMERALL");
    }

    public CoreReturnObject updateBUY_GP_REQ_Status1(String ids) {
        String[] _ids = ids.split(",");
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String sqlUpdate = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_REQ_Status1");// gpreq_id in ()
        // sqlUpdate += CoreConverter.toSqlConditionString("gpreq_id", new
        // String[]{"GP_20160700002", "GP_20160700003"});
        sqlUpdate = sqlUpdate.replaceAll("#gpbuyplanid#", ids);
        sqllist.add(sqlUpdate);
        parmlist.add(new Object[]{});
        // return this.setDataBySqlID("BuyGpDAL.updateBUY_GP_REQ_Status1");
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
    }

    public CoreReturnObject updateBUY_GP_REQ_Status0(String ids) {
        // return this.setDataBySqlID("BuyGpDAL.updateBUY_GP_REQ_Status0");
        String[] _ids = ids.split(",");
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String sqlUpdate = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_REQ_Status0");// gpreq_id in ()
        // sqlUpdate += CoreConverter.toSqlConditionString("gpreq_id", new
        // String[]{"GP_20160700002", "GP_20160700003"});
        sqlUpdate = sqlUpdate.replaceAll("#gpbuyplanid#", ids);
        sqllist.add(sqlUpdate);
        parmlist.add(new Object[]{});
        // return this.setDataBySqlID("BuyGpDAL.updateBUY_GP_REQ_Status1");
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
    }

    public CoreReturnObject updateBUY_GP_REQ_Status11(String ids) {
        String[] _ids = ids.split(",");
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String sqlUpdate = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_REQ_Status11");// gpreq_id in ()
        // sqlUpdate += CoreConverter.toSqlConditionString("gpreq_id", new
        // String[]{"GP_20160700002", "GP_20160700003"});
        sqlUpdate = sqlUpdate.replaceAll("#gpbuyplanid#", ids);
        sqllist.add(sqlUpdate);
        parmlist.add(new Object[]{});
        // return this.setDataBySqlID("BuyGpDAL.updateBUY_GP_REQ_Status1");
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
    }

    public CoreReturnObject updateBUY_GP_REQ_Status01(String ids) {
        // return this.setDataBySqlID("BuyGpDAL.updateBUY_GP_REQ_Status0");
        String[] _ids = ids.split(",");
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String sqlUpdate = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_REQ_Status01");// gpreq_id in ()
        // sqlUpdate += CoreConverter.toSqlConditionString("gpreq_id", new
        // String[]{"GP_20160700002", "GP_20160700003"});
        sqlUpdate = sqlUpdate.replaceAll("#gpbuyplanid#", ids);
        sqllist.add(sqlUpdate);
        parmlist.add(new Object[]{});
        // return this.setDataBySqlID("BuyGpDAL.updateBUY_GP_REQ_Status1");
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
    }

    public CoreReturnObject updateBUY_BASE_CUSTOMER(String CUSTOMER_NO,
                                                    String CUSTOMER_NM, String REGION_NO, String WET_D, String WET_DG,
                                                    String WET_DGF) {
        // return this.setDataBySqlID("BuyGpDAL.updateBUY_BASE_CUSTOMER",new
        // Object[]{CUSTOMER_NM,REGION_NO,CUSTOMER_NO,WET_D,WET_DG,WET_DGF,CUSTOMER_NO});
        CoreReturnObject cro = null;
        ArrayList<String> sqlList = new ArrayList<String>();
        ArrayList<Object[]> parmList = new ArrayList<Object[]>();
        sqlList.add("BuyGpDAL.updateBUY_BASE_CUSTOMER");
        sqlList.add("BuyGpDAL.updateBUY_BASE_REQ");
        parmList.add(new Object[]{CUSTOMER_NM, REGION_NO, CUSTOMER_NO});
        parmList.add(new Object[]{WET_D, WET_DG, WET_DGF, CUSTOMER_NO});
        cro = this.setDataById(sqlList, parmList);
        return cro;
    }

    public CoreReturnObject update(String CUSTOMER_NO, String CUSTOMER_NM,
                                   String REGION_NO, String WET_D, String WET_DG, String WET_DGF) {
        CoreReturnObject cro = null;
        ArrayList<String> sqlList = new ArrayList<String>();
        ArrayList<Object[]> parmList = new ArrayList<Object[]>();
        sqlList.add("BuyGpDAL.updateBUY_BASE_CUSTOMER");
        sqlList.add("BuyGpDAL.updateBUY_BASE_REQ");
        parmList.add(new Object[]{CUSTOMER_NM, REGION_NO, CUSTOMER_NO});
        parmList.add(new Object[]{WET_D, WET_DG, WET_DGF, CUSTOMER_NO});
        cro = this.setDataById(sqlList, parmList);
        return cro;
    }

    public String getGpBuyPlanId(Connection conn) throws SQLException {
        String sql = CoreXmlSqlParsersFactory.getSql("BuyGpDAL.getGpBuyPlanId");
        String versionNo = "";
        PreparedStatement ps = conn.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            if (rs.getString("VERSION_NO") != null) {
                versionNo = rs.getString("VERSION_NO");
            }
        }
        rs.close();
        ps.close();
        return versionNo;

    }

    public CoreReturnObject updateTEST(ArrayList<String> listJson) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String sqlUpdate = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_ORDER");
        // 合同主键
        String ordpks = "";
        for (String strJSON : listJson) {
            String str = strJSON;
            String[] tempstr = str.split(";");
            ArrayList<String> listValue = new ArrayList<String>();

            for (String strsub : tempstr) {
                String tempstrsub = strsub.split(":").length == 1 ? "" : strsub
                        .split(":")[1];
                listValue.add(tempstrsub);
            }
            String ordernopk = listValue.get(0);
            String orderno = listValue.get(1);
            String weight = listValue.get(2);
            String bc = listValue.get(3);
            String jhdate = listValue.get(4);
            // 此处拼接SQL 语句
            // sqlUpdate = sqlUpdate.replaceAll("#ORDERNO#", orderno);
            // sqlUpdate = sqlUpdate.replaceAll("#ORDNOPK#", ordernopk);

            sqllist.add(sqlUpdate);

            /* sqllist.add("BuyGpDAL.updateBUY_GP_ORDER"); */
            // parmlist.add(new
            // Object[]{orderno,orderno,jhdate,jhdate,bc,bc,weight,weight,orderno,orderno,ordernopk});
            parmlist.add(new Object[]{orderno, jhdate, jhdate, bc, bc,
                    weight, weight, orderno, orderno, ordernopk, ordernopk});

            ordpks += "'" + ordernopk + "'";
            ordpks += ",";
        }
        if (ordpks.length() > 0) {
            ordpks = ordpks.substring(0, ordpks.length() - 1);
        }

        // String sqlUpdate1 =
        // CoreXmlSqlParsersFactory.getSql("BuyGpDAL.updateBUY_GP_REQ_SYWEIGHT_ORDERWEIGHT");
        // sqlUpdate1 = sqlUpdate1.replaceAll("#ORD_NO_PK#", ordpks);
        // sqllist.add(sqlUpdate1);
        // parmlist.add(new Object[]{});
        String sqlUpdateOrderLine = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_ORDER_LINE");
        sqllist.add(sqlUpdateOrderLine);
        parmlist.add(new Object[]{});
        cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
        return cro;
    }

    public CoreReturnObject updateTEST1(ArrayList<String> listJson) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String sqlUpdate = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_ORDER");
        // 合同主键
        String ordpks = "";
        for (String strJSON : listJson) {
            String str = strJSON;
            String[] tempstr = str.split(";");
            ArrayList<String> listValue = new ArrayList<String>();

            for (String strsub : tempstr) {
                String tempstrsub = strsub.split(":").length == 1 ? "" : strsub
                        .split(":")[1];
                listValue.add(tempstrsub);
            }
            String ordernopk = listValue.get(0);
            String orderno = listValue.get(1);
            String weight = listValue.get(2);
            String bc = listValue.get(3);
            String jhdate = listValue.get(4);
            String memo = listValue.get(5);
            String orderPrice = listValue.get(6);
            // 此处拼接SQL 语句
            // sqlUpdate = sqlUpdate.replaceAll("#ORDERNO#", orderno);
            // sqlUpdate = sqlUpdate.replaceAll("#ORDNOPK#", ordernopk);

            sqllist.add(sqlUpdate);

            /* sqllist.add("BuyGpDAL.updateBUY_GP_ORDER"); */
            // parmlist.add(new
            // Object[]{orderno,orderno,jhdate,jhdate,bc,bc,weight,weight,orderno,orderno,ordernopk});
            parmlist.add(new Object[]{memo, orderno, jhdate, jhdate, bc, bc,
                    weight, weight, orderno, orderno, orderPrice, orderPrice, ordernopk, ordernopk});

            ordpks += "'" + ordernopk + "'";
            ordpks += ",";
        }
        if (ordpks.length() > 0) {
            ordpks = ordpks.substring(0, ordpks.length() - 1);
        }

        String sqlUpdate1 = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_REQ_SYWEIGHT_ORDERWEIGHT2");
        sqlUpdate1 = sqlUpdate1.replaceAll("#ORD_NO_PK#", ordpks);
        sqllist.add(sqlUpdate1);
        parmlist.add(new Object[]{});
        String sqlUpdateOrderLine = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_ORDER_LINE");
        sqllist.add(sqlUpdateOrderLine);
        parmlist.add(new Object[]{});
        cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
        return cro;
    }

    public CoreReturnObject queryTest() {
        String str = "D9638D81133742C49FED2DEEDD473439";
        return this.getDataBySqlID("BuyGpDAL.Test", new Object[]{str});
    }

    // 利余量
    public CoreReturnObject update_LYL(String gpreq_id) {
        ArrayList<String> sqllist = new ArrayList<String>();
        // String sqlupdate =
        // CoreXmlSqlParsersFactory.getSql("BuyGpDAL.updateBUY_GP_REQ_SYWEIGHT_LYL");
        String sqlupdate = "";
        sqlupdate = sqlupdate.replaceAll("#gpreq_id#", gpreq_id);
        sqllist.add(sqlupdate);
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist);
    }

    // 是否交齐
    public CoreReturnObject UpdateBUY_GP_REQ_JQ(String ids) {
        String[] _ids = ids.split(",");
        String id = _ids[0];
        ids = "";
        for (String str : _ids) {
            ids += "'";
            ids += str;
            ids += "'";
            ids += ",";
        }
        if (ids.endsWith(",")) {
            ids = ids.substring(0, ids.length() - 1);
        }
        ArrayList<String> sqllist = new ArrayList<String>();
        String sqlupdate = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_REQ_JQ");
        sqlupdate = sqlupdate.replaceAll("#gpbuyplanid#", ids);
        sqllist.add(sqlupdate);
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist);
    }

    // 是否交齐
    public CoreReturnObject UpdateBUY_GP_REQ_JQ_CANCEL(String ids) {
        String[] _ids = ids.split(",");
        String id = _ids[0];
        ids = "";
        for (String str : _ids) {
            ids += "'";
            ids += str;
            ids += "'";
            ids += ",";
        }
        if (ids.endsWith(",")) {
            ids = ids.substring(0, ids.length() - 1);
        }
        ArrayList<String> sqllist = new ArrayList<String>();
        String sqlupdate = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateBUY_GP_REQ_JQ_Cancel");
        sqlupdate = sqlupdate.replaceAll("#gpbuyplanid#", ids);
        sqllist.add(sqlupdate);
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist);
    }

    // 查找符合特定供应商的需求单
    public CoreReturnObject queryBUY_GP_ORDERCF(String ord_no_pk, String type) {
        CoreReturnObject cro = new CoreReturnObject();

        if (type.equals("1")) {
            cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_ORDERCF1",
                    new Object[]{ord_no_pk});

        } else {
            cro = this.getDataBySqlID("BuyGpDAL.getBUY_GP_ORDERCF2",
                    new Object[]{ord_no_pk});
        }
        return cro;
    }

    // 保存拆分后的合同
    public CoreReturnObject updateBUY_GP_ORDERCF(String ord_no_pk,
                                                 String supp_name, String weight) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.setDataBySqlID("BuyGpDAL.getBUY_GP_ORDERCFSAVE",
                new Object[]{supp_name, weight, weight, weight, ord_no_pk,
                        weight, weight, ord_no_pk, ord_no_pk});
        return cro;
    }

    // 通过管坯需求号查询生产合同
    public CoreReturnObject queryBUY_GP_REQ_SCORDER(String gpreq_id) {
        return this.getDataBySqlID("BuyGpDAL.QueryOrderByGpreq",
                new Object[]{gpreq_id});
    }

    // 查询销售详细数据导出
    public CoreReturnObject queryBUY_GP_ORDER_FORXSEXCEL() {
        return this.getDataBySqlID("BuyGpDAL.QueryForXsAll", new Object[]{});
    }

    // 需求单脱单
    public CoreReturnObject UpdateBUY_GP_REQ_TD(String GPREQ_ID, String plan_ids) {
        ArrayList<String> sqllist = new ArrayList<String>();
        // 外购坯需求脱单操作语句
        String[] _ids = plan_ids.split(",");
        // String id = _ids[0];
        String ids = "";
        for (String str : _ids) {
            ids += "'";
            ids += str;
            ids += "'";
            ids += ",";
        }
        if (ids.endsWith(",")) {
            ids = ids.substring(0, ids.length() - 1);
        }
        // String sqlUpdate =
        // CoreXmlSqlParsersFactory.getSql("BuyGpDAL.UPDATE_CGPREQUIRES_TD");
        String sqlUpdate = "";
        sqlUpdate = sqlUpdate.replaceAll("#gpreq_id#", GPREQ_ID);
        sqlUpdate = sqlUpdate.replaceAll("#plan_id#", ids);
        sqllist.add(sqlUpdate);
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist);
    }

    public CoreReturnObject insertBUY_CGP_DCYB(String stove_no,
                                               String judge_stove_no, String plan_count, String plan_weight,
                                               String dhdate, String create_name, String ord_no_pk) {
        return this.setDataBySqlID("BuyGpDAL.insertBUY_CGP_DCYB", new Object[]{
                stove_no, judge_stove_no, plan_count, plan_weight, dhdate,
                create_name, ord_no_pk});
    }

    public CoreReturnObject getBUY_CGP_DCYB(String ord_no_pk) {
        return this.getDataBySqlID("BuyGpDAL.getBUY_CGP_DCYB",
                new Object[]{ord_no_pk});
    }

    public CoreReturnObject updateBUY_CGP_DCYB(String stove_no,
                                               String judge_stove_no, String plan_count, String plan_weight,
                                               String dhdate, String update_name, String dcyb_pk) {
        return this.setDataBySqlID("BuyGpDAL.updateBUY_CGP_DCYB", new Object[]{
                stove_no, judge_stove_no, plan_count, plan_weight, dhdate,
                update_name, dcyb_pk});
    }

    public CoreReturnObject deleteBUY_CGP_DCYB(String dcyb_pk) {
        return this.setDataBySqlID("BuyGpDAL.deleteBUY_CGP_DCYB",
                new Object[]{dcyb_pk});
    }

    public CoreReturnObject test_CGP_RK() {
        return this.setDataBySqlID("BuyGpDAL.test_CGP_RK", new Object[]{30});
    }

    public CoreReturnObject get_CGP_RK_Orders(String supplier, String orderno) {
        // ArrayList<String> sqllist = new ArrayList<String>();
        // ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.get_CGP_RK_Orders");
        if (!supplier.equals("")) {
            String[] suppliers = {supplier};
            sqlSelect += CoreConverter.toSqlConditionString("SUPP_CODE",
                    suppliers);
        }
        if (!orderno.equals("")) {
            sqlSelect += " AND (b.ORDER_NO || '/' || SUBSTR(TO_CHAR(1000+TO_NUMBER(ORDER_SQE)),-3)) LIKE '%"
                    + orderno + "%'";
        }
        return this.getData(sqlSelect);
    }

    public CoreReturnObject get_CGP_RK_OrdersTH(String supplier, String orderno) {
        // ArrayList<String> sqllist = new ArrayList<String>();
        // ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.get_CGP_RK_OrdersTH");
        if (!supplier.equals("")) {
            String[] suppliers = {supplier};
            sqlSelect += CoreConverter.toSqlConditionString("SUPP_CODE",
                    suppliers);
        }
        if (!orderno.equals("")) {
            sqlSelect += " AND (b.ORDER_NO || '/' || SUBSTR(TO_CHAR(1000+TO_NUMBER(ORDER_SQE)),-3)) LIKE '%"
                    + orderno + "%'";
        }
        return this.getData(sqlSelect);
    }

    public CoreReturnObject get_CGP_Orders_Dcyb(String ord_no_pk) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.get_CGP_Orders_Dcyb");
        return this.getData(sqlSelect, new Object[]{ord_no_pk});
    }

    public String get_INSTOCKDOC() throws SQLException {
        String instockDoc = "";
        String sql = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.getMaxInstockDoc");
        ;
        Connection conn = null;
        try {

            conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            PreparedStatement ps = conn.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                if (rs.getString("rn") != null) {
                    instockDoc = rs.getString("rn");
                }
            }
            rs.close();
            ps.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (conn != null || !conn.isClosed()) {
                conn = null;
            }
        }
        return instockDoc;

    }

    public CoreReturnObject get_TH_GP_JUDGE_STOVE_NO() {
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.get_TH_GP_JUDGE_STOVE_NO");

        return this.getData(sqlSelect);
    }

    public CoreReturnObject do_CGP_RK(String order_no_pk, String stove_no,
                                      String judge_stove_no, String carno, String departmentid,
                                      ArrayList<String> listJson, String username, String stockname,
                                      String location, String level, String isJielu) {
        departmentid = "002001016";
        // CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        // ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String instockDoc = "";
        try {
            instockDoc = get_INSTOCKDOC();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        for (String strJSON : listJson) {
            String str = strJSON;
            String[] tempstr = str.split(";");
            ArrayList<String> listValue = new ArrayList<String>();
            Integer index = 0;
            for (String strsub : tempstr) {
                String tempstrsub = strsub.split(":").length == 1 ? "" : strsub
                        .split(":")[1];
                listValue.add(tempstrsub);
            }
            String bc = listValue.get(0);
            String count = listValue.get(1);
            String weight = listValue.get(2);
            String weight1 = weight;

            String gplength = "0";
            if (listValue.size() > 3) {
                gplength = listValue.get(3);
            }

            double gpweight = Double.parseDouble(weight)
                    / Double.parseDouble(count);
            // weight = String.format("%.4f",gpweight);
            /**************** 以下插入入库实绩表 ******************/
            index++;
            String sqlInsertGp_InList = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.insert_Ydm_Gp_Inlist");
            // 入库顺序号
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#rowcount#",
                    index.toString());
            // 入库单号
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#rn#",
                    instockDoc);
            // 车号
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#car_no#",
                    carno);
            // 炉号、判定炉号
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#stove_no#",
                    stove_no);
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll(
                    "#judge_stove_no#", judge_stove_no);
            // 采购合同号主键
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#ord_no_pk#",
                    order_no_pk);
            // 倍尺
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#bc#", bc);
            // 支数
            sqlInsertGp_InList = sqlInsertGp_InList
                    .replaceAll("#count#", count);
            // 仓库名称
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll(
                    "#storage_name#", stockname);
            // 库位代码
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#location#",
                    location);
            // 层号
            sqlInsertGp_InList = sqlInsertGp_InList
                    .replaceAll("#level#", level);
            // 用户名
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#create_name#",
                    username);
            // 单支重
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#act_weight#",
                    weight); // 此处修改实际重

            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#weight#",
                    weight);
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#gplength#",
                    gplength);
            sqllist.add(sqlInsertGp_InList);
            System.out.println();
            System.out.println(sqlInsertGp_InList);
            System.out.println();
            /**************** 以下插入位置表 ******************/
            String sqlInsertGp_BUTTRESS = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.insert_YDM_GP_BUTTRESS");

            // 炉号、判定炉号
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll(
                    "#stove_no#", stove_no);
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll(
                    "#judge_stove_no#", judge_stove_no);
            // 倍尺
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll("#bc#", bc);
            // 支数
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll("#count#",
                    count);
            // 仓库名称
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll(
                    "#storage_name#", stockname);
            // 库位代码
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll(
                    "#location#", location);
            // 层号
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll("#level#",
                    level);
            // 用户名
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll(
                    "#create_name#", username);

            sqllist.add(sqlInsertGp_BUTTRESS);

            /**************** 以下插入库存表 ******************/
            String sqlInsertGp_M = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.insert_MAT_GP_M");

            // 炉号、判定炉号
            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#stove_no#", stove_no);
            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#judge_stove_no#",
                    judge_stove_no);
            // 倍尺
            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#bc#", bc);
            // 支数
            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#count#", count);
            // 采购合同号主键
            sqlInsertGp_M = sqlInsertGp_M
                    .replaceAll("#ord_no_pk#", order_no_pk);

            // 用户名
            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#create_name#", username);
            // 单支重
            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#act_weight#", weight); // 此处修改实际重

            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#weight#", weight);

            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#gplength#", gplength);

            sqllist.add(sqlInsertGp_M);

            /**************** 以下更新管坯交库实绩表 ******************/
            String sqlUpdateLGINSTORE_RESULT = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.UPDATE_STL_LG_INSTORE_RESULT");

            // 判定炉号
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#judge_stove_no#", judge_stove_no);
            // 倍尺
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#bc#", bc);
            // 支数
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#count#", count);
            // 采购合同号主键
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#ord_no_pk#", order_no_pk);
            // 总重
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#weight#", weight);
            // 结炉标识
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#jielu#", isJielu);

            sqllist.add(sqlUpdateLGINSTORE_RESULT);

            /**************** 以下插入管坯交库实绩表 ******************/
            String sqlInsertLGINSTORE_RESULT = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.insert_STL_LG_INSTORE_RESULT");

            // 炉号、判定炉号
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#stove_no#", stove_no);
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#judge_stove_no#", judge_stove_no);
            // 倍尺
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#bc#", bc);
            // 支数
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#count#", count);
            // 采购合同号主键
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#ord_no_pk#", order_no_pk);
            // 总重
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#weight#", weight);
            // 结炉标识
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#jielu#", isJielu);
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#gplength#", gplength);
            sqllist.add(sqlInsertLGINSTORE_RESULT);

            /**************** 以下插入管坯交库实绩表结炉状态 ******************/
            String sqlInsertLGINSTORE_RESULT_JIELU = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.UPDATE_STL_LG_INSTORE_RESULT_JIELU");

            // 判定炉号
            sqlInsertLGINSTORE_RESULT_JIELU = sqlInsertLGINSTORE_RESULT_JIELU
                    .replaceAll("#judge_stove_no#", judge_stove_no);
            // 采购合同号主键
            sqlInsertLGINSTORE_RESULT_JIELU = sqlInsertLGINSTORE_RESULT_JIELU
                    .replaceAll("#ord_no_pk#", order_no_pk);

            // 结炉标识
            sqlInsertLGINSTORE_RESULT_JIELU = sqlInsertLGINSTORE_RESULT_JIELU
                    .replaceAll("#jielu#", isJielu);

            sqllist.add(sqlInsertLGINSTORE_RESULT_JIELU);

        }
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist);
    }

    public CoreReturnObject do_CGP_RK_TH(String order_no_pk, String stove_no,
                                         String judge_stove_no, String carno, String departmentid,
                                         ArrayList<String> listJson, String username, String stockname,
                                         String location, String level, String isJielu) {
        departmentid = "002001016";
        // CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        // ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String instockDoc = "";
        try {
            instockDoc = get_INSTOCKDOC();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        for (String strJSON : listJson) {
            String str = strJSON;
            String[] tempstr = str.split(";");
            ArrayList<String> listValue = new ArrayList<String>();
            Integer index = 0;
            for (String strsub : tempstr) {
                String tempstrsub = strsub.split(":").length == 1 ? "" : strsub
                        .split(":")[1];
                listValue.add(tempstrsub);
            }
            String bc = listValue.get(0);
            String count = listValue.get(1);
            String weight = listValue.get(2);
            String weight1 = weight;

            String gplength = "0";
            if (listValue.size() > 3) {
                gplength = listValue.get(3);
            }

            double gpweight = Double.parseDouble(weight)
                    / Double.parseDouble(count);
            // weight = String.format("%.4f",gpweight);

            String judge_stove_no1 = stove_no;
            /**************** 以下插入入库实绩表 ******************/
            index++;
            String sqlInsertGp_InList = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.insert_Ydm_Gp_Inlist_TH");
            // 入库顺序号
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#rowcount#",
                    index.toString());
            // 入库单号
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#rn#",
                    instockDoc);
            // 车号
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#car_no#",
                    carno);
            // 炉号、判定炉号
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#stove_no#",
                    stove_no);
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll(
                    "#judge_stove_no#", judge_stove_no1);
            // 采购合同号主键
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#ord_no_pk#",
                    order_no_pk);
            // 倍尺
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#bc#", bc);
            // 支数
            sqlInsertGp_InList = sqlInsertGp_InList
                    .replaceAll("#count#", count);
            // 仓库名称
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll(
                    "#storage_name#", stockname);
            // 库位代码
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#location#",
                    location);
            // 层号
            sqlInsertGp_InList = sqlInsertGp_InList
                    .replaceAll("#level#", level);
            // 用户名
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#create_name#",
                    username);
            // 单支重
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#act_weight#",
                    weight); // 此处修改实际重

            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#weight#",
                    weight);
            sqlInsertGp_InList = sqlInsertGp_InList.replaceAll("#gplength#",
                    gplength);
            sqllist.add(sqlInsertGp_InList);
            /**************** 以下插入位置表 ******************/
            String sqlInsertGp_BUTTRESS = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.insert_YDM_GP_BUTTRESS_TH");

            // 炉号、判定炉号
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll(
                    "#stove_no#", stove_no);
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll(
                    "#judge_stove_no#", judge_stove_no1);
            // 倍尺
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll("#bc#", bc);
            // 支数
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll("#count#",
                    count);
            // 仓库名称
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll(
                    "#storage_name#", stockname);
            // 库位代码
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll(
                    "#location#", location);
            // 层号
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll("#level#",
                    level);
            // 用户名
            sqlInsertGp_BUTTRESS = sqlInsertGp_BUTTRESS.replaceAll(
                    "#create_name#", username);

            sqllist.add(sqlInsertGp_BUTTRESS);

            /**************** 以下插入库存表 ******************/
            String sqlInsertGp_M = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.insert_MAT_GP_M_TH");

            // 炉号、判定炉号
            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#stove_no#", stove_no);
            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#judge_stove_no#",
                    judge_stove_no1);
            // 倍尺
            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#bc#", bc);
            // 支数
            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#count#", count);
            // 采购合同号主键
            sqlInsertGp_M = sqlInsertGp_M
                    .replaceAll("#ord_no_pk#", order_no_pk);

            // 用户名
            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#create_name#", username);
            // 单支重
            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#act_weight#", weight); // 此处修改实际重

            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#weight#", weight);

            sqlInsertGp_M = sqlInsertGp_M.replaceAll("#gplength#", gplength);

            sqllist.add(sqlInsertGp_M);

            /**************** 以下更新管坯交库实绩表 ******************/
            String sqlUpdateLGINSTORE_RESULT = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.UPDATE_STL_LG_INSTORE_RESULT_TH");

            // 冶炼炉号
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#stove_no#", stove_no);
            // 判定炉号
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#judge_stove_no#", judge_stove_no1);
            // 倍尺
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#bc#", bc);
            // 支数
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#count#", count);
            // 采购合同号主键
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#ord_no_pk#", order_no_pk);
            // 总重
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#weight#", weight);
            // 结炉标识
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#jielu#", isJielu);
            // 结炉标识
            sqlUpdateLGINSTORE_RESULT = sqlUpdateLGINSTORE_RESULT.replaceAll(
                    "#gplength#", gplength);

            sqllist.add(sqlUpdateLGINSTORE_RESULT);

            /**************** 以下插入管坯交库实绩表 ******************/
            String sqlInsertLGINSTORE_RESULT = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.insert_STL_LG_INSTORE_RESULT_TH");

            // 炉号、判定炉号
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#stove_no#", stove_no);
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#judge_stove_no#", judge_stove_no1);
            // 倍尺
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#bc#", bc);
            // 支数
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#count#", count);
            // 采购合同号主键
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#ord_no_pk#", order_no_pk);
            // 总重
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#weight#", weight);
            // 结炉标识
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#jielu#", isJielu);
            //管坯实际长度
            sqlInsertLGINSTORE_RESULT = sqlInsertLGINSTORE_RESULT.replaceAll(
                    "#gplength#", gplength);
            sqllist.add(sqlInsertLGINSTORE_RESULT);

            /**************** 以下插入管坯交库实绩表结炉状态 ******************/
            String sqlInsertLGINSTORE_RESULT_JIELU = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.UPDATE_STL_LG_INSTORE_RESULT_JIELU_TH");

            // 判定炉号
            sqlInsertLGINSTORE_RESULT_JIELU = sqlInsertLGINSTORE_RESULT_JIELU
                    .replaceAll("#judge_stove_no#", judge_stove_no1);
            // 采购合同号主键
            sqlInsertLGINSTORE_RESULT_JIELU = sqlInsertLGINSTORE_RESULT_JIELU
                    .replaceAll("#ord_no_pk#", order_no_pk);

            // 结炉标识
            sqlInsertLGINSTORE_RESULT_JIELU = sqlInsertLGINSTORE_RESULT_JIELU
                    .replaceAll("#jielu#", isJielu);

            sqllist.add(sqlInsertLGINSTORE_RESULT_JIELU);

        }
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist);
    }

    /**
     * 查询是否结炉状态
     *
     * @param order_no_pk    采购合同号主键
     * @param judge_stove_no 判定炉号
     * @return
     */
    public CoreReturnObject get_CGP_RK_JIELU(String order_no_pk,
                                             String judge_stove_no) {
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.SELECT_STL_LG_INSTORE_RESULT_JIELU");

        // 判定炉号
        sqlSelect = sqlSelect.replaceAll("#judge_stove_no#", judge_stove_no);
        // 采购合同号主键
        sqlSelect = sqlSelect.replaceAll("#ord_no_pk#", order_no_pk);

        return this.getData(sqlSelect);
    }

    public CoreReturnObject get_CGP_RK_Stock(String supplier, String orderno) {
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.get_MAT_GP_M");
        /*
         * if(!supplier.equals("")) { String[] suppliers = {supplier}; sqlSelect
         * += CoreConverter.toSqlConditionString("SUPP_CODE",suppliers); }
         */
        /*
         * if(!orderno.equals("")) { sqlSelect +=
         * " AND ORDER_NO LIKE '"+orderno+"'"; }
         */
        return this.getData(sqlSelect);
    }

    /**
     * 获取仓库入库的层数@return
     */
    public CoreReturnObject get_CGP_RK_Level() {
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.get_CGP_RUKU_Level");
        return this.getData(sqlSelect);
    }

    /**
     * 获取用户所属权限的仓库
     *
     * @return
     */
    public CoreReturnObject get_CGP_Stock(String[] departments) {
        String ids = "";
        for (String str : departments) {
            ids += "'";
            ids += str;
            ids += "'";
            ids += ",";
        }
        if (ids.endsWith(",")) {
            ids = ids.substring(0, ids.length() - 1);
        }

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.get_CGP_RUKU_Stock");
        sqlSelect = sqlSelect.replace("#departments#", ids);
        return this.getData(sqlSelect);
    }

    /**
     * 获取仓库的库位信息
     *
     * @return
     */
    public CoreReturnObject get_CGP_Stock_Location(String stockname) {
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.get_CGP_RUKU_Stock_Location");
        sqlSelect = sqlSelect.replaceAll("#storage_name#", stockname);
        return this.getData(sqlSelect);
    }

    /**
     * 撤单查询
     *
     * @return
     */
    public CoreReturnObject get_CGP_Stock_CHEDAN(String STORAGE_NAME,
                                                 String orderno, String judge_stove_no) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.get_CGP_RUKU_Stock_CHEDAN");

        if (orderno.equals("")) {
            orderno = "无合同号";
        }
        if (judge_stove_no.equals("")) {
            judge_stove_no = "无判定炉号";
        }
        sqlSelect = sqlSelect.replaceAll("#STORAGE_NAME#", STORAGE_NAME);
        sqlSelect = sqlSelect.replaceAll("#JUDGE_STOVE_NO#", judge_stove_no);
        sqlSelect = sqlSelect.replaceAll("#ORDER_NO#", orderno);
        return this.getData(sqlSelect);

    }

    public CoreReturnObject get_CGP_Stock_CHEDAN_TH(String STORAGE_NAME,
                                                    String orderno, String judge_stove_no) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.get_CGP_RUKU_Stock_CHEDAN_TH");

        String sql = "";
        if (orderno.equals("")) {
            orderno = "无合同号";
        } else {
            sql += " and ORDER_NO like '%" + orderno + "%'";
        }
        if (judge_stove_no.equals("")) {
            judge_stove_no = "无判定炉号";
        } else {
            sql += " and JUDGE_STOVE_NO = '" + judge_stove_no + "'";
        }
        sqlSelect = sqlSelect.replaceAll("#sql#", sql);
        return this.getData(sqlSelect);

    }

    /**
     * 撤单查询
     *
     * @return
     */
    public CoreReturnObject get_CGP_Stock_CHEDAN_DETAILS(String instock_doc) {
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.get_CGP_RUKU_Stock_CHEDAN_Details");
        sqlSelect = sqlSelect.replaceAll("#instock_doc#", instock_doc);
        return this.getData(sqlSelect);
    }

    public CoreReturnObject get_CGP_Stock_CHEDAN_DETAILS_TH(String instock_doc) {
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.get_CGP_RUKU_Stock_CHEDAN_Details_TH");
        sqlSelect = sqlSelect.replaceAll("#instock_doc#", instock_doc);
        return this.getData(sqlSelect);
    }

    /**
     * 撤单操作
     *
     * @param instock_doc
     * @return
     */
    public CoreReturnObject delete_CGP_Stock_CHEDAN(String ids1,
                                                    String STORAGE_NAME) {
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.deleteInstockDoc");
        String ids = "";
        for (String str : ids1.split(",")) {
            ids += "'";
            ids += str;
            ids += "'";
            ids += ",";
        }
        if (ids.endsWith(",")) {
            ids = ids.substring(0, ids.length() - 1);
        }
        sqlSelect = sqlSelect.replaceAll("#instock_doc#", ids);
        sqlSelect = sqlSelect.replaceAll("#storage_name#", STORAGE_NAME);
        return this.setData(sqlSelect);
    }

    public CoreReturnObject delete_CGP_Stock_CHEDAN_New(String ids1,
                                                        String STORAGE_NAME, String ids2) {
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.deleteInstockDocNew");
        String ids = "";
        for (String str : ids1.split(",")) {
            ids += "'";
            ids += str;
            ids += "'";
            ids += ",";
        }
        if (ids.endsWith(",")) {
            ids = ids.substring(0, ids.length() - 1);
        }
        String ids0 = "";
        for (String str : ids2.split(",")) {
            ids0 += "'";
            ids0 += str;
            ids0 += "'";
            ids0 += ",";
        }
        if (ids0.endsWith(",")) {
            ids0 = ids0.substring(0, ids0.length() - 1);
        }
        sqlSelect = sqlSelect.replaceAll("#instock_doc#", ids);
        sqlSelect = sqlSelect.replaceAll("#storage_name#", STORAGE_NAME);
        sqlSelect = sqlSelect.replaceAll("#judge_stove_no#", ids0);
        return this.setData(sqlSelect);
    }

    public CoreReturnObject delete_CGP_Stock_CHEDAN_TH(String ids1,
                                                       String STORAGE_NAME, String ids2) {
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.deleteInstockDocTH");
        String ids = "";
        for (String str : ids1.split(",")) {
            ids += "'";
            ids += str;
            ids += "'";
            ids += ",";
        }
        if (ids.endsWith(",")) {
            ids = ids.substring(0, ids.length() - 1);
        }
        String ids0 = "";
        for (String str : ids2.split(",")) {
            ids0 += "'";
            ids0 += str;
            ids0 += "'";
            ids0 += ",";
        }
        if (ids0.endsWith(",")) {
            ids0 = ids0.substring(0, ids0.length() - 1);
        }
        sqlSelect = sqlSelect.replaceAll("#instock_doc#", ids);
        sqlSelect = sqlSelect.replaceAll("#storage_name#", STORAGE_NAME);
        sqlSelect = sqlSelect.replaceAll("#judge_stove_no#", ids0);
        return this.setData(sqlSelect);
    }

    /**
     * 设置结炉状态
     *
     * @param judge_stove_no 判定炉号
     * @param jielustatus    结炉状态
     * @return
     */
    public CoreReturnObject update_JieluStatus(String judge_stove_no,
                                               String jielustatus) {
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.updateJIELUStatus");
        sqlSelect = sqlSelect.replaceAll("#judge_stove_no#", judge_stove_no);
        sqlSelect = sqlSelect.replaceAll("#jielu#", jielustatus);
        return this.setData(sqlSelect);
    }

    public String get_GpreqId(String orderid) {

        String gpreq_id = "";
        Connection connection = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {

            String sql = "SELECT gpbuyplanid FROM BUY_GP_ORDER t where t.ord_no_pk ='"
                    + orderid + "'";
            connection = this.getDao(CoreConstantData.sysbeanstr)
                    .getConnection();
            ps = connection.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()) {
                if (rs.getString("gpbuyplanid") != null) {
                    gpreq_id = rs.getString("gpbuyplanid");
                }
            }
            rs.close();

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                if (ps != null) {
                    ps.close();
                }
                if (connection != null) {
                    connection.close();
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return gpreq_id;

    }

    public CoreReturnObject update_RKZL(String orderid, String stove_no,
                                        String judge_stove_no, String type) {
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        CoreReturnObject cro = new CoreReturnObject();
        /*
         * List<PlnSteelEntity> plnOrderZg = EntityTool.getEntitysByRs(rs,
         * PlnSteelEntity.class);
         */

        String gpreqId = get_GpreqId(orderid);

        PlnSteelEntity plnSteelEntity = new PlnSteelEntity();
        plnSteelEntity.setProPlanId(gpreqId);
        plnSteelEntity.setStoveNo(stove_no);
        plnSteelEntity.setJudgeStoveNo(judge_stove_no);
        // 以下设置 plnSteelEntity 实体类的值
        String sql = "";
        String matGpNum = "";
        Integer gpreqCount, interNum, remianNum = 0;
        PreparedStatement psta;
        ResultSet rs;
        // String type = "1";
        try {
            connection.setAutoCommit(false);
            if (type.equals("1")) // 如果入库是 铸坯
            {
                sql = CoreXmlSqlParsersFactory
                        .getSql("BuyGpDAL.selectPlnOrderZg");// 查询铸造订单下对应的轧管订单
                sql = EntityTool.fillSqlByEntity(sql, plnSteelEntity);
                psta = connection.prepareStatement(sql);
                rs = psta.executeQuery();
                List<PlnOrderZgSEntity> plnOrderZg = EntityTool.getEntitysByRs(
                        rs, PlnOrderZgSEntity.class);
                rs.close();
                psta.close();

                for (int i = 0; i < plnOrderZg.size(); i++) {
                    // 该轧管订单下已分配多少支
                    sql = CoreXmlSqlParsersFactory
                            .getSql("BuyGpDAL.selectMatGpMNumZg");
                    sql = EntityTool.fillSqlByEntity(sql, plnOrderZg.get(i));
                    psta = connection.prepareStatement(sql);
                    rs = psta.executeQuery();
                    if (rs.next()) {
                        matGpNum = rs.getString("DB_ACT_COUNT");
                    }
                    rs.close();
                    psta.close();

                    gpreqCount = Integer.parseInt(plnOrderZg.get(i)
                            .getGpreqNum()) - Integer.parseInt(matGpNum);
                    if (gpreqCount <= 0) {
                        continue;
                    } else {
                        sql = CoreXmlSqlParsersFactory
                                .getSql("BuyGpDAL.selectMatGpMNum");// 查询库存已入支数根据倍尺分组(还未挂轧管单号的)

                        psta = connection.prepareStatement(sql);
                        psta.setString(1, plnSteelEntity.getProPlanId());
                        psta.setString(2, plnSteelEntity.getStoveNo());
                        psta.setString(3, plnSteelEntity.getJudgeStoveNo());
                        rs = psta.executeQuery();
                        List<MatGpMEntity> matGp = EntityTool.getEntitysByRs(
                                rs, MatGpMEntity.class);
                        rs.close();
                        psta.close();
                        for (int j = 0; j < matGp.size(); j++) {
                            interNum = gpreqCount
                                    / Integer
                                    .parseInt(matGp.get(j).getFixNum());
                            remianNum = gpreqCount
                                    % Integer
                                    .parseInt(matGp.get(j).getFixNum());
                            matGp.get(j).setProPlanIdZg(
                                    plnOrderZg.get(i).getProPlanId());
                            matGp.get(j).setGxPlanNoZg(
                                    plnOrderZg.get(i).getGxPlanNo());
                            if (j == matGp.size() - 1 && remianNum > 0) {
                                interNum = interNum + 1;
                            }
                            if (Integer.parseInt(matGp.get(j).getActCount()) > interNum) {
                                matGp.get(j).setActCount(
                                        String.valueOf(interNum));
                            }

                            String updateMatGpMZgSql = CoreXmlSqlParsersFactory
                                    .getSql("BuyGpDAL.updateMatGpMZg");
                            updateMatGpMZgSql = EntityTool.fillSqlByEntity(
                                    updateMatGpMZgSql, matGp.get(j));
                            PreparedStatement updateMatGpMZgPsta = connection
                                    .prepareStatement(updateMatGpMZgSql);
                            updateMatGpMZgPsta.executeUpdate();
                            updateMatGpMZgPsta.close();

                            gpreqCount = gpreqCount
                                    - Integer.parseInt(matGp.get(j)
                                    .getActCount())
                                    * Integer
                                    .parseInt(matGp.get(j).getFixNum());
                            if (gpreqCount <= 0) {
                                break;
                            }
                        }
                    }

                }
            }
            if (type.equals("0"))// 如果入库是锻坯
            {
                sql = CoreXmlSqlParsersFactory
                        .getSql("BuyGpDAL.selectPlnOrderDz");// 查询铸造订单下对应的锻造订单
                sql = EntityTool.fillSqlByEntity(sql, plnSteelEntity);
                psta = connection.prepareStatement(sql);
                rs = psta.executeQuery();
                List<PlnOrderDzSEntity> plnOrderDz = EntityTool.getEntitysByRs(
                        rs, PlnOrderDzSEntity.class);
                rs.close();
                psta.close();
                for (int i = 0; i < plnOrderDz.size(); i++) {
                    // 该锻造订单下已分配多少支
                    sql = CoreXmlSqlParsersFactory
                            .getSql("BuyGpDAL.selectMatGpMNumZg");
                    psta = connection.prepareStatement(sql);
                    psta.setString(1, plnSteelEntity.getProPlanId());
                    psta.setString(2, plnSteelEntity.getStoveNo());
                    psta.setString(3, plnSteelEntity.getJudgeStoveNo());
                    rs = psta.executeQuery();
                    if (rs.next()) {
                        matGpNum = rs.getString("DB_ACT_COUNT");
                    }
                    rs.close();
                    psta.close();

                    gpreqCount = Integer.parseInt(plnOrderDz.get(i).getNumS())
                            - Integer.parseInt(matGpNum);
                    if (gpreqCount <= 0) {
                        continue;
                    } else {
                        sql = CoreXmlSqlParsersFactory
                                .getSql("BuyGpDAL.selectMatGpMNum");// 查询库存已入支数根据倍尺分组(还未挂轧管单号的)
                        sql = EntityTool.fillSqlByEntity(sql, plnSteelEntity);
                        psta = connection.prepareStatement(sql);

                        rs = psta.executeQuery();
                        List<MatGpMEntity> matGp = EntityTool.getEntitysByRs(
                                rs, MatGpMEntity.class);
                        rs.close();
                        psta.close();
                        for (int j = 0; j < matGp.size(); j++) {
                            interNum = gpreqCount
                                    / Integer
                                    .parseInt(matGp.get(j).getFixNum());
                            remianNum = gpreqCount
                                    % Integer
                                    .parseInt(matGp.get(j).getFixNum());
                            matGp.get(j).setProPlanIdZg(
                                    plnOrderDz.get(i).getProPlanId());
                            matGp.get(j).setGxPlanNoZg(
                                    plnOrderDz.get(i).getGxPlanNo());
                            if (j == matGp.size() - 1 && remianNum > 0) {
                                interNum = interNum + 1;
                            }
                            if (Integer.parseInt(matGp.get(j).getActCount()) > interNum) {
                                matGp.get(j).setActCount(
                                        String.valueOf(interNum));
                            }

                            String updateMatGpMZgSql = CoreXmlSqlParsersFactory
                                    .getSql("BuyGpDAL.updateMatGpMZg");
                            updateMatGpMZgSql = EntityTool.fillSqlByEntity(
                                    updateMatGpMZgSql, matGp.get(j));
                            PreparedStatement updateMatGpMZgPsta = connection
                                    .prepareStatement(updateMatGpMZgSql);

                            updateMatGpMZgPsta.executeUpdate();

                            updateMatGpMZgPsta.close();

                            gpreqCount = gpreqCount
                                    - Integer.parseInt(matGp.get(j)
                                    .getActCount())
                                    * Integer
                                    .parseInt(matGp.get(j).getFixNum());
                            if (gpreqCount <= 0) {
                                break;
                            }
                        }
                    }
                }
            }
            connection.commit();
            cro.setV_errCode(1);
        } catch (Exception e) {
            try {
                connection.rollback();
            } catch (SQLException e1) {

                e1.printStackTrace();
            }
        } finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return cro;

    }

    public CoreReturnObject queryRkinfo(String judge_stove_no, String dm,
                                        String dbpc, String gz) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();

        PreparedStatement psta;
        ResultSet rs;
        String sql = "";
        try {
            sql = CoreXmlSqlParsersFactory.getSql("BuyGpDAL.selectMatGpMRules");
            sql = sql.replace("#judge_stove_no#", judge_stove_no);

            psta = connection.prepareStatement(sql);
            rs = psta.executeQuery();
            String _dm = "", _dbpc = "", _gz = "", _storage = "";
            while (rs.next()) {
                _dm = String.valueOf(rs.getInt("dimater"));
                _dbpc = String.valueOf(rs.getInt("fix_len"));
                _gz = rs.getString("gradename");
                _storage = rs.getString("storage_name");
                break;
            }
            rs.close();
            psta.close();
            String returnMessage = "";
            String returnCode = "0";
            if (!_dm.equals("") && !dm.equals(_dm)) {
                returnMessage += " 断面不相同 ;\n";
                returnCode = "-1";
            }
            if (!_dbpc.equals("") && !dbpc.equals(_dbpc)) {
                returnMessage += " 单倍坯长不相同 ;\n";
                returnCode = "-1";
            }
            if (!_gz.equals("") && !gz.equals(_gz)) {
                returnMessage += " 钢种不相同 ;";
                returnCode = "-1";
            }
            if (returnCode.equals("-1")) {
                returnMessage = _storage + "已入过此炉，且以下信息不同，不能重复入库!\n"
                        + returnMessage;
            }
            cro.setV_errMsg(returnMessage);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
        return cro;

    }

    public CoreReturnObject get_CGP_Stock_INFO(String STORAGE_NAME,
                                               String judge_stove_no) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectMatGpMStocks");

        if (judge_stove_no.equals("")) {
            judge_stove_no = "无判定炉号";
        }
        sqlSelect = sqlSelect.replaceAll("#STORAGE_NAME#", STORAGE_NAME);
        sqlSelect = sqlSelect.replaceAll("#JUDGE_STOVE_NO#", judge_stove_no);
        CoreReturnObject cro = this.getData(sqlSelect);
        Object o = cro.getResult();
        return cro;

    }

    public CoreReturnObject get_CGP_Stock_INFO_TH(String STORAGE_NAME,
                                                  String stove_no) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectMatGpMStocksTH");

        if (stove_no.equals("")) {
            stove_no = "无冶炼炉号";
        }
        sqlSelect = sqlSelect.replaceAll("#STORAGE_NAME#", STORAGE_NAME);
        sqlSelect = sqlSelect.replaceAll("#STOVE_NO#", stove_no);
        CoreReturnObject cro = this.getData(sqlSelect);
        Object o = cro.getResult();
        return cro;

    }

    public CoreReturnObject get_CGP_Stock_JIELUINFO(String judge_stove_no) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectMatGpMStocksJieluInfo");

        if (judge_stove_no.equals("")) {
            judge_stove_no = "无判定炉号";
        }
        sqlSelect = sqlSelect.replaceAll("#JUDGE_STOVE_NO#", judge_stove_no);
        return this.getData(sqlSelect);

    }

    /***
     * 撤销结炉
     *
     * @param judge_stove_no
     * @return
     */
    public CoreReturnObject deleteMatGpMStocksJielu(String judge_stove_no) {

        return this.setDataBySqlID("BuyGpDAL.deleteMatGpMStocksJielu",
                new Object[]{judge_stove_no});
    }

    /***
     * 撤销天淮结炉
     * @param stove_no
     * @return
     */
    public CoreReturnObject deleteJieluTH(String stove_no) {

        return this.setDataBySqlID("BuyGpDAL.deleteMatGpMStocksJieluTH",
                new Object[]{stove_no});
    }

    /***
     * 增加结炉
     *
     * @param judge_stove_no
     * @return
     */
    public CoreReturnObject updateMatGpMStocksJielu(String judge_stove_no) {

        return this.setDataBySqlID("BuyGpDAL.updateMatGpMStocksJielu",
                new Object[]{judge_stove_no});
    }

    public CoreReturnObject updateMatGpMStocksJieluTH(String stove_no) {

        return this.setDataBySqlID("BuyGpDAL.updateMatGpMStocksJieluTH",
                new Object[]{stove_no});
    }

    /***
     * 获取销售管理数据
     * @return
     */
    public CoreReturnObject get_Rpt_Sales_All(String year) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectRptSalesAll");
        sqlSelect = sqlSelect.replaceAll("#RPT_YM#", year);
        return this.getData(sqlSelect);

    }

    /***
     * 管理报表数据
     * @param year
     * @return
     */
    public CoreReturnObject get_Rpt_Management_All(String year) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectRptManagementAll");
        sqlSelect = sqlSelect.replaceAll("#RPT_YM#", year);
        return this.getData(sqlSelect);
    }

    public CoreReturnObject get_Rpt_Pline_Judge_All(String yearmonth) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectRptPlineJudgeAll");
        sqlSelect = sqlSelect.replaceAll("#RPT_YM#", yearmonth);
        return this.getData(sqlSelect);
    }

    /***
     * 获取生铁废钢铁水计量数据
     * @param yearmonth
     * @return
     */
    public CoreReturnObject get_Rpt_Measure_Cg(String yearmonth) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectRptMeasureCg");
        StringBuilder sb = new StringBuilder(yearmonth);//构造一个StringBuilder对象
        sb.insert(4, "-");//在指定的位置1，插入指定的字符串
        yearmonth = sb.toString();
        sqlSelect = sqlSelect.replaceAll("#RPT_YM#", yearmonth);
        return this.getData(sqlSelect);
    }

    /*
     * public CoreReturnObject test171224(ArrayList judge_stove_no){
     *
     * String sqlSelect = CoreXmlSqlParsersFactory .getSql("BuyGpDAL.myTest");
     * MatGpModelEntity matEntity = new MatGpModelEntity();
     * matEntity.setMyId("GP_W20170600174");
     * matEntity.setMyAge("WFSC-XS-圆坯1706-006"); sqlSelect =
     * EntityTool.fillSqlByEntity(sqlSelect,matEntity);
     *
     * //CoreReturnObject cro = new CoreReturnObject();
     *
     * return this.getData(sqlSelect); }
     */
    public CoreReturnObject get_Rpt_Ls_All(String year) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectRptLsAll");

        sqlSelect = sqlSelect.replaceAll("#RPT_YEAR#", year);
        String sqlWhere = getSqlWhereYearMonth(year);
        sqlSelect = sqlSelect.replaceAll("#RPT_YM#", sqlWhere);
        return this.getData(sqlSelect);
    }

    private static String getSqlWhereYearMonth(String year) {
        List<String> list = new ArrayList<String>();
        Calendar c = Calendar.getInstance();
        int currentYear = c.get(Calendar.YEAR);
        int currentMonth = c.get(Calendar.MONTH) + 1;
        for (int i = 1; i < 13; i++) {
            if (Integer.parseInt(year) < currentYear) {
                String date = year + (i >= 10 ? "" : "0") + i;
                list.add(date);
            }
            if (Integer.parseInt(year) == currentYear) {
                if (i > 1 && i > currentMonth)
                    break;
                String date = year + (i >= 10 ? "" : "0") + i;
                list.add(date);
            }
            if (Integer.parseInt(year) > currentYear) {
                String date = year + "01";
                list.add(date);
                break;
            }

        }
        String strA = list.toString();
        strA = strA.replace('[', '(');
        strA = strA.replace(']', ')');
        return strA;
    }

    public CoreReturnObject get_Rpt_Ls_Details(String dept, String pline, String rptym) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectRptLsDetails");

        sqlSelect = sqlSelect.replaceAll("#DEPT#", dept);
        sqlSelect = sqlSelect.replaceAll("#PLINE#", pline);
        sqlSelect = sqlSelect.replaceAll("#RPTYM#", rptym);
        return this.getData(sqlSelect);
    }

    public CoreReturnObject get_Rpt_DaySCKB(String startDate) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date dt1 = null;
        try {
            dt1 = sdf.parse(startDate);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt1);
        int day = rightNow.getTime().getDate();

        String beginDate = sdf.format(rightNow.getTime()) + "2100";
        rightNow.add(Calendar.DAY_OF_YEAR, -1);// 日期减1天  
        String endDate = sdf.format(rightNow.getTime()) + "2100";

        rightNow.set(Calendar.DAY_OF_MONTH, 1);
        rightNow.add(Calendar.DATE, -1);

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(dt1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.add(Calendar.DATE, -1);
        String lastDate = sdf.format(calendar.getTime()) + "2100";

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectRptDaySCKB");


        sqlSelect = sqlSelect.replaceAll("#BGEINDATE#", beginDate);
        sqlSelect = sqlSelect.replaceAll("#ENDDATE#", endDate);
        sqlSelect = sqlSelect.replaceAll("#LASTDATE#", lastDate);
        sqlSelect = sqlSelect.replaceAll("#DAYS#", String.valueOf(day));
        return this.getData(sqlSelect);
    }

    public CoreReturnObject get_Rpt_DaySCKB(String startDate, String endDate, Integer Days) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date dt1 = null;
        Date dt2 = null;
        try {
            dt1 = sdf.parse(startDate);
            dt2 = sdf.parse(endDate);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt1);
        rightNow.add(Calendar.DAY_OF_YEAR, -1);// 日期减1天  
        //String beginDate = sdf.format(rightNow.getTime()) +"2100";
        String beginDate = sdf.format(rightNow.getTime());
        rightNow.setTime(dt2);
        rightNow.add(Calendar.DAY_OF_YEAR, -1);// 日期减1天  
        //String endDate1 = sdf.format(rightNow.getTime())+"2100";
        String endDate1 = sdf.format(rightNow.getTime());
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectRptDaySCKB");

        //endDate = endDate+"2100";
        Days = Days + 1;
        sqlSelect = sqlSelect.replaceAll("#BGEINDATE#", endDate);
        sqlSelect = sqlSelect.replaceAll("#ENDDATE#", endDate1);
        sqlSelect = sqlSelect.replaceAll("#LASTDATE#", beginDate);
        sqlSelect = sqlSelect.replaceAll("#DAYS#", String.valueOf(Days));
        return this.getData(sqlSelect);
    }

    public CoreReturnObject get_Rpt_JG_ONLINE() {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectRptJGONLINE");

        return this.getData(sqlSelect);
    }

    public CoreReturnObject get_Rpt_JG_HSK(String beginDate, String endDate) {

        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("BuyGpDAL.selectRptJGHSK");

        sqlSelect = sqlSelect.replaceAll("#BGEINDATE#", beginDate);
        sqlSelect = sqlSelect.replaceAll("#ENDDATE#", endDate);
        return this.getData(sqlSelect);
    }

    /**
     * 接箍线个人产量月报
     *
     * @param year1
     * @param year2
     * @return
     */
    public CoreReturnObject get_FrmIndvProd_All(String year1, String year2) {
        year1 = "'" + year1 + "'";
        year2 = "'" + year2 + "'";
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("IndDAL.getGRCLYB");
        sqlSelect = sqlSelect.replaceAll("#RPT_YM1#", year1);
        sqlSelect = sqlSelect.replaceAll("#RPT_YM2#", year2);
        return this.getData(sqlSelect);
    }

    /***
     * 接箍生产准备
     * @param year1
     * @param year2
     * @return
     */
    public CoreReturnObject get_FrmJGSC_All(String year1, String year2) {
        year1 = "'" + year1 + "'";
        year2 = "'" + year2 + "'";
        String sqlSelect = CoreXmlSqlParsersFactory
                .getSql("IndDAL.getJGSCYB");
        sqlSelect = sqlSelect.replaceAll("#RPT_YM1#", year1);
        sqlSelect = sqlSelect.replaceAll("#RPT_YM2#", year2);
        return this.getData(sqlSelect);
    }

    public CoreReturnObject get_FrmddTJ_data(String PlineCode, String Date) {
        String sqlSelect = "";
        if (PlineCode.toUpperCase().equals("C001") || PlineCode.toUpperCase().equals("C003")) {
            sqlSelect = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.selectLGTJ");
        } else {
            sqlSelect = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.selectZGTJ");
        }

        sqlSelect = sqlSelect.replaceAll("#DATE#", Date);
        sqlSelect = sqlSelect.replaceAll("#PLINECODE#", PlineCode);
        return this.getData(sqlSelect);
    }

    public CoreReturnObject get_FrmddTJ_data(String PlineCode, String Date, String Date1) {
        String sqlSelect = "";
        if (PlineCode.toUpperCase().equals("C001") || PlineCode.toUpperCase().equals("C003")) {
            sqlSelect = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.selectLGTJ1");
        } else if (PlineCode.toUpperCase().equals("C008") || PlineCode.toUpperCase().equals("C009") ||
                PlineCode.toUpperCase().equals("C010") || PlineCode.toUpperCase().equals("C017")
        ) {
            sqlSelect = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.selectZGTJ1");
        } else if (PlineCode.toUpperCase().startsWith("C049") || PlineCode.toUpperCase().startsWith("C050")) {
            sqlSelect = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.selectRCLTJ1");
        } else if (PlineCode.toUpperCase().startsWith("C028")
                || PlineCode.toUpperCase().startsWith("C029")
                || PlineCode.toUpperCase().startsWith("C030") || PlineCode.toUpperCase().startsWith("C031") || PlineCode.toUpperCase().startsWith("C032")
                || PlineCode.toUpperCase().startsWith("C033") || PlineCode.toUpperCase().startsWith("C034") || PlineCode.toUpperCase().startsWith("C035")
                || PlineCode.toUpperCase().startsWith("C036") || PlineCode.toUpperCase().startsWith("C037") || PlineCode.toUpperCase().startsWith("C053")
                || PlineCode.toUpperCase().startsWith("C056") || PlineCode.toUpperCase().startsWith("C039") || PlineCode.toUpperCase().startsWith("C051")
                || PlineCode.toUpperCase().startsWith("C038") || PlineCode.toUpperCase().startsWith("C057") || PlineCode.toUpperCase().startsWith("C052")
                || PlineCode.toUpperCase().startsWith("C078") || PlineCode.toUpperCase().startsWith("C058")
        ) {
            sqlSelect = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.selectRCLTJG");
        } else {
            sqlSelect = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.selectRCLTJ");
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date dt1 = null;
        Date dt2 = null;
        try {
            dt1 = sdf.parse(Date1);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt1);

        rightNow.add(Calendar.DAY_OF_YEAR, -1);// 日期减1天  
        String startDate = sdf.format(rightNow.getTime());

        if (PlineCode.length() == 2) {
            sqlSelect = sqlSelect.replaceAll("#DATE#", Date);
            sqlSelect = sqlSelect.replaceAll("#DATE1#", startDate);
            sqlSelect = sqlSelect.replaceAll("#PLINECODE#", PlineCode);
        }
        if (PlineCode.length() == 4) {
            sqlSelect = sqlSelect.replaceAll("#DATE#", Date);
            sqlSelect = sqlSelect.replaceAll("#DATE1#", startDate);
            sqlSelect = sqlSelect.replaceAll("#PLINECODE#", PlineCode);
        }
        if (PlineCode.length() == 5) {
            String pCode = PlineCode.substring(0, 4);
            String Station = PlineCode.substring(4, 5);
            sqlSelect = sqlSelect.replaceAll("#DATE#", Date);
            sqlSelect = sqlSelect.replaceAll("#DATE1#", startDate);
            sqlSelect = sqlSelect.replaceAll("#PLINECODE#", pCode);
            sqlSelect = sqlSelect.replaceAll("#STATION#", Station);
        }
        return this.getData(sqlSelect);
    }


    public CoreReturnObject get_FrmddTJChart_data(String startdate, String enddate, String days, String PlineCode) {
        String sqlSelect = "";

        if (PlineCode.toUpperCase().equals("A")) {
            sqlSelect = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.selectLGDDTJAll");
        } else if (PlineCode.toUpperCase().equals("C001") || PlineCode.toUpperCase().equals("C003")) {
            sqlSelect = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.selectLGDDTJ");
        } else if (PlineCode.toUpperCase().equals("D")) {
            sqlSelect = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.selectZGDDTJAll");
        } else if (PlineCode.toUpperCase().equals("C008") || PlineCode.toUpperCase().equals("C009") ||
                PlineCode.toUpperCase().equals("C010") || PlineCode.toUpperCase().equals("C017")
        ) {
            sqlSelect = CoreXmlSqlParsersFactory
                    .getSql("BuyGpDAL.selectZGDDTJ");
        } else {
            boolean b = PlineCode.toUpperCase().equals("C0490") || PlineCode.toUpperCase().equals("C0500");
            if (b) {
                sqlSelect = CoreXmlSqlParsersFactory
                        .getSql("BuyGpDAL.selectRCLDDTJYT");
            } else if (PlineCode.toUpperCase().equals("F0") || PlineCode.toUpperCase().equals("F1")) {
                sqlSelect = CoreXmlSqlParsersFactory
                        .getSql("BuyGpDAL.selectRCLDDTJAll");

            } else if (PlineCode.toUpperCase().equals("F01") || PlineCode.toUpperCase().equals("F02") ||
                    PlineCode.toUpperCase().equals("F11") ||
                    PlineCode.toUpperCase().equals("F12") || PlineCode.toUpperCase().equals("F13")) {
                sqlSelect = CoreXmlSqlParsersFactory
                        .getSql("BuyGpDAL.selectRCLDDTJPARTIAL");

            } else if (PlineCode.toUpperCase().equals("F03")) {
                sqlSelect = CoreXmlSqlParsersFactory
                        .getSql("BuyGpDAL.selectRCLDDTJPARTIALYT");

            } else {
                sqlSelect = CoreXmlSqlParsersFactory
                        .getSql("BuyGpDAL.selectRCLDDTJ");
            }
        }


        sqlSelect = sqlSelect.replaceAll("#STARTDATE#", startdate);
        sqlSelect = sqlSelect.replaceAll("#ENDDATE#", enddate);
        sqlSelect = sqlSelect.replaceAll("#DAYS#", days);
        if (PlineCode.length() == 4) {
            sqlSelect = sqlSelect.replaceAll("#PLINECODE#", PlineCode);
        } else if (PlineCode.length() == 5) {
            String pCode = PlineCode.substring(0, 4);
            String Station = PlineCode.substring(4, 5);
            sqlSelect = sqlSelect.replaceAll("#PLINECODE#", pCode);
            sqlSelect = sqlSelect.replaceAll("#STATION#", Station);
        } else if (PlineCode.length() == 2) {
            String Station = PlineCode.substring(1);
            sqlSelect = sqlSelect.replaceAll("#STATION#", Station);
        } else if (PlineCode.length() == 3) {
            if (PlineCode.toUpperCase().equals("F01")) {
                String pCode = " 'C022','C023','C024','C025','C026' ";
                String Station = "0";
                sqlSelect = sqlSelect.replaceAll("#PLINECODE#", pCode);
                sqlSelect = sqlSelect.replaceAll("#STATION#", Station);
                sqlSelect = sqlSelect.replaceAll("#REGION#", PlineCode);
            }
            if (PlineCode.toUpperCase().equals("F02")) {
                String pCode = " 'C054','C055','C048' ";
                String Station = "0";
                sqlSelect = sqlSelect.replaceAll("#PLINECODE#", pCode);
                sqlSelect = sqlSelect.replaceAll("#STATION#", Station);
                sqlSelect = sqlSelect.replaceAll("#REGION#", PlineCode);
            }
            if (PlineCode.toUpperCase().equals("F03")) {
                String pCode = " 'C049','C050' ";
                String Station = "0";
                sqlSelect = sqlSelect.replaceAll("#PLINECODE#", pCode);
                sqlSelect = sqlSelect.replaceAll("#STATION#", Station);
                sqlSelect = sqlSelect.replaceAll("#REGION#", PlineCode);
            }
            if (PlineCode.toUpperCase().equals("F11")) {
                String pCode = " 'C022','C023','C024','C025','C026' ";
                String Station = "1";
                sqlSelect = sqlSelect.replaceAll("#PLINECODE#", pCode);
                sqlSelect = sqlSelect.replaceAll("#STATION#", Station);
                sqlSelect = sqlSelect.replaceAll("#REGION#", PlineCode);
            }
            if (PlineCode.toUpperCase().equals("F12")) {
                String pCode = " 'C054','C055','C048' ";
                String Station = "1";
                sqlSelect = sqlSelect.replaceAll("#PLINECODE#", pCode);
                sqlSelect = sqlSelect.replaceAll("#STATION#", Station);
                sqlSelect = sqlSelect.replaceAll("#REGION#", PlineCode);
            }
            if (PlineCode.toUpperCase().equals("F13")) {
                String pCode = " 'C049','C050' ";
                String Station = "1";
                sqlSelect = sqlSelect.replaceAll("#PLINECODE#", pCode);
                sqlSelect = sqlSelect.replaceAll("#STATION#", Station);
                sqlSelect = sqlSelect.replaceAll("#REGION#", PlineCode);
            }
        }
        return this.getData(sqlSelect);
    }

    /**
     * 审批状态修改
     * @param ids
     * @return
     */
    public CoreReturnObject UpdateExamineStatus(String ids,String newStatus,String oldStatus) {
        SqlBuilder b = new SqlBuilder("BuyGpDAL.UpdateExamineStatus");
        String sql = b.Fill(new String[]{newStatus, oldStatus}).toString();
        sql += CoreConverter.toSqlConditionString("GPREQ_ID", ids.split(","));
        return this.setData(sql);
    }
}
