package com.steering.pss.sale.order.ReviewForm;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import CoreFS.Util.StringUtils;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.comm.tools.StringTool;
import com.steering.comm.tools.TransctionTool;
import com.steering.pss.buybillet.Entity.PlnOrderZgSEntity;
import com.steering.pss.plan.order.model.SlmOrderHeadCopy;
import com.steering.pss.qcm.model.GenericEntity;
import com.steering.pss.sale.order.CoreOrderInfoUpdate;
import com.steering.pss.sale.order.CoreOrderStatusCommFun;
import com.steering.pss.sale.order.craftDesign.main.CraftInnerMain;
import com.steering.pss.sale.order.craftDesign.model.ComMscEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscPlPrcEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignStdCicEntity;
import com.steering.pss.sale.order.model.ComMscBlEntity;
import com.steering.pss.sale.order.model.CraftOrdDesignEntity;
import com.steering.pss.sale.order.model.DesignMscPlPcEntity;
import com.steering.pss.sale.order.model.SlmOrderReviewItemListEntity;
import net.sf.json.JSONObject;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class CoreOrderReviewTechnology extends DBCommon {

    /**
     * 修改msc相关数据。
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject UpdateOrderLineMsc(String msc, String mscDesc,
            String mscType, String useCode, String useDesc, String custAlphaNo,
            String pOrdLnPk) {
        Object[] params = new Object[] { msc, mscDesc, mscType, useCode,
                useDesc, custAlphaNo, pOrdLnPk };
        return this.setDataBySqlID(
                "CoreOrderReviewTechnology.UpdateOrderLineMsc", params);
    }

    /**
     * 修改当前合同头状态为，技术评审失败
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject UpdateOrderHeadSts(String ordPk) {
        Object[] params = new Object[] { ordPk };
        return this.setDataBySqlID(
                "CoreOrderReviewTechnology.UpdateOrderHeadSts", params);
    }

    /**
     * 获取当前合同头状态
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetOrderHeadSts(String ordPk) {
        Object[] params = new Object[] { ordPk };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetOrderHeadSts",
                params);
    }

    /**
     * 合同行均为技术评审通过以上的状态，合同头状态修正为技术评审通过。
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject UpdateOrderHead(String ordPk) {
        Object[] params = new Object[] { ordPk };
        return this.setDataBySqlID("CoreOrderReviewTechnology.UpdateOrderHead",
                params);
    }

    /**
     * 依据当前合同行所属合同头Key，查询该合同头下是否还有技术评审通过以下的合同行。
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetLineDtByOrdPk(String ordPk) {
        Object[] params = new Object[] { ordPk };
        return this.getDataBySqlID(
                "CoreOrderReviewTechnology.GetLineDtByOrdPk", params);
    }

    /**
     * 周期修正值
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject UpdateMscPlPc(ArrayList<ArrayList<Object>> parms) {

        ArrayList<Object> spbSqlList = new ArrayList<Object>();
        ArrayList<Object[]> spbParmList = new ArrayList<Object[]>();

        String UpdateMscPlPcSql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.UpdateMscPlPc");

        for (int i = 0; i < parms.size(); i++) {
            spbSqlList.add(UpdateMscPlPcSql);
            spbParmList.add(parms.get(i).toArray());
        }

        CoreReturnObject spbCro = new CoreReturnObject();

        try {
            spbCro = this.getDao("TgDao").ExcuteTransction(spbSqlList,
                    spbParmList);
        }
        catch (Exception e) {
            spbCro = spbCro.SetErrInfo(e.getMessage());
        }

        return spbCro;
    }
    
    /**
     * 周期修正值
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject UpdateCraftMscPlPc(ArrayList<ArrayList<Object>> parms) {

        ArrayList<Object> spbSqlList = new ArrayList<Object>();
        ArrayList<Object[]> spbParmList = new ArrayList<Object[]>();

        String UpdateMscPlPcSql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.UpdateCraftMscPlPc");

        for (int i = 0; i < parms.size(); i++) {
            spbSqlList.add(UpdateMscPlPcSql);
            spbParmList.add(parms.get(i).toArray());
        }

        CoreReturnObject spbCro = new CoreReturnObject();

        try {
            spbCro = this.getDao("TgDao").ExcuteTransction(spbSqlList,
                    spbParmList);
        }
        catch (Exception e) {
            spbCro = spbCro.SetErrInfo(e.getMessage());
        }

        return spbCro;
    }

    /**
     * 技术评审通过
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject doReviewPass(
            ArrayList<ArrayList<String>> paramsPassList, String y) {

        ArrayList<Object> spbSqlList = new ArrayList<Object>();
        ArrayList<Object[]> spbParmList = new ArrayList<Object[]>();

        String updateReviewItemSql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.UpdateReviewItem");

        String updateReviewItemListSql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.updateReviewItemList");

        String updateOrderLineSql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.updateOrderLine");

        for (int i = 0; i < paramsPassList.size(); i++) {
            ArrayList<String> parms = paramsPassList.get(i);

            String deviewNo = parms.get(0).toString();
            // String ordPk = parms.get(1).toString();
            String ordLnPk = parms.get(2).toString();
            String reviewMan = parms.get(3).toString();
            String reviewDept = parms.get(4).toString();

            String orderLineSts = "";
            String reviewSts = "";
            if ("1".equals(y)) {
                orderLineSts = "12020202";
                reviewSts = "S";
            }
            else {
                orderLineSts = "12020203";
                reviewSts = "F";
            }

            Object[] reviewItemParms = new Object[] { reviewSts, deviewNo };
            Object[] reviewItemListParms = new Object[] { reviewSts, reviewMan,
                    reviewDept, deviewNo, ordLnPk };
            Object[] orderLineParms = new Object[] { orderLineSts, ordLnPk };

            spbSqlList.add(updateReviewItemSql);
            spbSqlList.add(updateReviewItemListSql);
            spbSqlList.add(updateOrderLineSql);

            spbParmList.add(reviewItemParms);
            spbParmList.add(reviewItemListParms);
            spbParmList.add(orderLineParms);
        }

        CoreReturnObject spbCro = new CoreReturnObject();

        try {
            spbCro = this.getDao("TgDao").ExcuteTransction(spbSqlList,
                    spbParmList);
        }
        catch (Exception e) {
            spbCro = spbCro.SetErrInfo(e.getMessage());
        }

        return spbCro;
    }

    /**
     * 获取当前合同行主键下面，设计状态不通过的管理科室。
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject isDesignV(String ordLnPk) {
        Object[] obj = new Object[] { ordLnPk };
        return this.getDataBySqlID("CoreOrderReviewTechnology.isDesignV", obj);
    }
    
    /**
     * 获取当前合同行主键下面，设计状态不通过的管理科室。
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject isDesignVCraft(String ordLnPk) {
        Object[] obj = new Object[] { ordLnPk };
        return this.getDataBySqlID("CoreOrderReviewTechnology.isDesignVCraft", obj);
    }

    /**
     * 合同状态数据源绑定
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetSts() {
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetSts");
    }

    /**
     * 合同状态数据源绑定
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetDesignSts() {
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetDesignSts");
    }

    public CoreReturnObject doQuery(ArrayList<String> list) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.doQuery");
        sql = StringTool.ReplaceAll(sql, "#DESIGN_STS#", list.get(0));
        sql = StringTool.ReplaceAll(sql, "#ORDER_NO#", list.get(1));
        sql = StringTool.ReplaceAll(sql, "#REVIEW_STATUS#", list.get(2));
        String reviewStatus = "";
        if (list.get(2).equals("W")) {
            reviewStatus = "0";
        }
        else if (list.get(2).equals("D")) {
            reviewStatus = "1";
        }
        else if (list.get(2).equals("S")) {
            reviewStatus = "2";
        }
        else if (list.get(2).equals("F")) {
            reviewStatus = "3";
        }
        sql = StringTool.ReplaceAll(sql, "#REVIEW_STATUS2#", reviewStatus);
        sql = StringTool.ReplaceAll(sql, "#UNIT_CODE#", list.get(3));
        sql = StringTool.ReplaceAll(sql, "#BEGIN_TIME#", list.get(4));
        sql = StringTool.ReplaceAll(sql, "#END_TIME#", list.get(5));
        sql = StringTool.ReplaceAll(sql, "#SUPPLY_UNIT#", list.get(6));
        CoreReturnObject cro;
        cro = this.getData(sql);
        System.out.print(sql);
        return cro;
    }


    public CoreReturnObject doQueryBBHT(ArrayList<String> list) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.doQueryBBHT");
        sql = StringTool.ReplaceAll(sql, "#DESIGN_STS#", list.get(0));
        sql = StringTool.ReplaceAll(sql, "#ORDER_NO#", list.get(1));
        sql = StringTool.ReplaceAll(sql, "#REVIEW_STATUS#", list.get(2));
        String reviewStatus = "";
        if (list.get(2).equals("W")) {
            reviewStatus = "0";
        }
        else if (list.get(2).equals("D")) {
            reviewStatus = "1";
        }
        else if (list.get(2).equals("S")) {
            reviewStatus = "2";
        }
        else if (list.get(2).equals("F")) {
            reviewStatus = "3";
        }
        sql = StringTool.ReplaceAll(sql, "#REVIEW_STATUS2#", reviewStatus);
        sql = StringTool.ReplaceAll(sql, "#UNIT_CODE#", list.get(3));
        sql = StringTool.ReplaceAll(sql, "#BEGIN_TIME#", list.get(4));
        sql = StringTool.ReplaceAll(sql, "#END_TIME#", list.get(5));
        sql = StringTool.ReplaceAll(sql, "#SUPPLY_UNIT#", list.get(6));
        CoreReturnObject cro;
        cro = this.getData(sql);
        return cro;
    }
    
    
    public CoreReturnObject doQueryCraft(ArrayList<String> list, String[] validDataPurviewIds, String isPopup) {
        return doQueryCraft(list,validDataPurviewIds,isPopup,"");
    }

    public CoreReturnObject doQueryCraft(ArrayList<String> list, String[] validDataPurviewIds, String isPopup,String supp) {
        String units = "1";
        for(String str : validDataPurviewIds){
            units += "', '" + str + "";
        }
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.doQueryCraft");


        sql = StringTool.ReplaceAll(sql, "#DESIGN_STS#", list.get(0));
        String[] manageOrderNos = list.get(1).split("/");
        String orderNo = "";
        String orderSeq = "";
        if(manageOrderNos.length > 1){
            for(int i = 0; i < manageOrderNos.length - 1; i++){
                orderNo += manageOrderNos[i];
            }
            orderSeq = manageOrderNos[manageOrderNos.length - 1];
        }else{
            orderNo = manageOrderNos[0];
        }
        sql = StringTool.ReplaceAll(sql, "#ORDER_NO#", orderNo);
        sql = StringTool.ReplaceAll(sql, "#ORDER_SEQ#", orderSeq);
        sql = StringTool.ReplaceAll(sql, "#REVIEW_STATUS#", list.get(2));
        sql = StringTool.ReplaceAll(sql, "#UNIT_CODE#", list.get(3));
        sql = StringTool.ReplaceAll(sql, "#USER_ID#", list.get(4));
        sql = StringTool.ReplaceAll(sql, "#USER_NAME#", list.get(5));
        sql = StringTool.ReplaceAll(sql, "#BEGIN_TIME#", list.get(6));
        sql = StringTool.ReplaceAll(sql, "#END_TIME#", list.get(7));
        sql = StringTool.ReplaceAll(sql, "#PLAN_STATUS#", list.get(8));
        sql = StringTool.ReplaceAll(sql, "#URGENT#", list.get(9));
        sql = StringTool.ReplaceAll(sql, "#IS_POPUP#", isPopup);
        sql = sql.replaceAll("#UNIT_CODE_S#", units);
        if (!StringUtils.isEmpty(supp)) {
            sql = sql.replaceAll("#SUPPLY_UNIT_FLAG#", " AND  G.SUPPLY_UNIT = '"+ supp +"'"); ;
        } else {
            sql = sql.replaceAll("#SUPPLY_UNIT_FLAG#", ""); ;
        }
        CoreReturnObject cro;
        System.out.print(sql);
        cro = this.getData(sql);
        return cro;
    }

    public CoreReturnObject doQueryCraftBBHT(ArrayList<String> list, String[] validDataPurviewIds, String isPopup,String supp) {
        String units = "1";
        for(String str : validDataPurviewIds){
            units += "', '" + str + "";
        }
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.doQueryCraftBBHT");


        sql = StringTool.ReplaceAll(sql, "#DESIGN_STS#", list.get(0));
        String[] manageOrderNos = list.get(1).split("/");
        String orderNo = "";
        String orderSeq = "";
        if(manageOrderNos.length > 1){
            for(int i = 0; i < manageOrderNos.length - 1; i++){
                orderNo += manageOrderNos[i];
            }
            orderSeq = manageOrderNos[manageOrderNos.length - 1];
        }else{
            orderNo = manageOrderNos[0];
        }
        sql = StringTool.ReplaceAll(sql, "#ORDER_NO#", orderNo);
        sql = StringTool.ReplaceAll(sql, "#ORDER_SEQ#", orderSeq);
        sql = StringTool.ReplaceAll(sql, "#REVIEW_STATUS#", list.get(2));
        sql = StringTool.ReplaceAll(sql, "#UNIT_CODE#", list.get(3));
        sql = StringTool.ReplaceAll(sql, "#USER_ID#", list.get(4));
        sql = StringTool.ReplaceAll(sql, "#USER_NAME#", list.get(5));
        sql = StringTool.ReplaceAll(sql, "#BEGIN_TIME#", list.get(6));
        sql = StringTool.ReplaceAll(sql, "#END_TIME#", list.get(7));
        sql = StringTool.ReplaceAll(sql, "#PLAN_STATUS#", list.get(8));
        sql = StringTool.ReplaceAll(sql, "#URGENT#", list.get(9));
        sql = StringTool.ReplaceAll(sql, "#IS_POPUP#", isPopup);
        sql = sql.replaceAll("#UNIT_CODE_S#", units);
        if (!StringUtils.isEmpty(supp)) {
            sql = sql.replaceAll("#SUPPLY_UNIT_FLAG#", " AND  G.SUPPLY_UNIT = '"+ supp +"'"); ;
        } else {
            sql = sql.replaceAll("#SUPPLY_UNIT_FLAG#", ""); ;
        }
        CoreReturnObject cro;
        cro = this.getData(sql);
        return cro;
    }

    /**
     * 获取合同行从表交货信息
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetOrderLineDelivery(ArrayList<String> list) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.GetOrderLineDelivery");
        sql = StringTool.ReplaceAll(sql, "#DESIGN_STS#", list.get(0));
        sql = StringTool.ReplaceAll(sql, "#ORDER_NO#", list.get(1));
        sql = StringTool.ReplaceAll(sql, "#REVIEW_STATUS#", list.get(2));
        sql = StringTool.ReplaceAll(sql, "#UNIT_CODE#", list.get(3));
        sql = StringTool.ReplaceAll(sql, "#BEGIN_TIME#", list.get(4));
        sql = StringTool.ReplaceAll(sql, "#END_TIME#", list.get(5));
        return this.getData(sql);
    }

    /**
     * 获取技术状态与技术状态明细
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetOrdDesign(String ordLnPk) {
        Object[] obj = new Object[] { ordLnPk };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetOrdDesign",
                obj);
    }
    
    /**
     * 获取技术状态与技术状态明细
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftDesign(String ordLnPk) {
        Object[] obj = new Object[] { ordLnPk, ordLnPk};
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetCraftDesign",
                obj);
    }

    /**
     * 获取不通过的技术状态与技术状态明细
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetOrdDesignNPass(String ordLnPk) {
        Object[] obj = new Object[] { ordLnPk };
        return this.getDataBySqlID(
                "CoreOrderReviewTechnology.GetOrdDesignNPass", obj);
    }
    
    /**
     * 获取不通过的技术状态与技术状态明细
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftDesignNPass(String ordLnPk) {
        Object[] obj = new Object[] { ordLnPk, ordLnPk};
        return this.getDataBySqlID(
                "CoreOrderReviewTechnology.GetCraftDesignNPass", obj);
    }

    /**
     * 产品交付要求数据绑定
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetDesignStd(String designKey) {
        Object[] obj = new Object[] { designKey, designKey };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetDesignStd",
                obj);
    }
    
    /**
     * 产品交付要求数据绑定
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftDesignStd(String designKey) {
        Object[] obj = new Object[] { designKey, designKey };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetCraftDesignStd",
                obj);
    }

    /**
     * 生产制程，全程途径数据绑定
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetDesignMscPl(String designKey) {
        Object[] obj = new Object[] { designKey, designKey };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetDesignMscPl",
                obj);
    }
    
    /**
     * 生产制程，全程途径数据绑定
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftDesignMscPl(String designKey) {
        Object[] obj = new Object[] { designKey };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetCraftDesignMscPl",
                obj);
    }

    /**
     * 依据全程途径获取对应钢种
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetDesignMscPlGz(String designKey, String mscPline) {
        Object[] obj = new Object[] { designKey, mscPline };
        return this.getDataBySqlID(
                "CoreOrderReviewTechnology.GetDesignMscPlGz", obj);
    }
    
    /**
     * 依据全程途径获取对应钢种
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftDesignMscPlGz(String designKey, String mscPline) {
        Object[] obj = new Object[] { designKey, mscPline };
        return this.getDataBySqlID(
                "CoreOrderReviewTechnology.GetCraftDesignMscPlGz", obj);
    }

    /**
     * 依据全程途径获取工序投入产出物料
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetDesignMscPlIn(String designKey, String mscPline) {
        Object[] obj = new Object[] { designKey, mscPline };
        return this.getDataBySqlID(
                "CoreOrderReviewTechnology.GetDesignMscPlIn", obj);
    }
    
    /**
     * 依据全程途径获取工序投入产出物料
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftDesignMscPlIn(String designKey, String mscPline) {
        Object[] obj = new Object[] { designKey, mscPline };
        return this.getDataBySqlID(
                "CoreOrderReviewTechnology.GetCraftDesignMscPlIn", obj);
    }

    /**
     * 依据工序获取适用产线
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetDesignMscPlGxPrl(String designKey,
            String mscPline, String backlogSeq, String processCode) {
        Object[] obj = new Object[] { designKey, mscPline, backlogSeq,
                processCode };
        return this.getDataBySqlID(
                "CoreOrderReviewTechnology.GetDesignMscPlGxPrl", obj);
    }
    
    /**
     * 依据工序获取适用产线
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftDesignMscPlGxPrl(String designKey,
            String mscPline, String backlogSeq, String processCode) {
        Object[] obj = new Object[] { designKey, mscPline, backlogSeq,
                processCode };
        return this.getDataBySqlID(
                "CoreOrderReviewTechnology.GetCraftDesignMscPlGxPrl", obj);
    }

    /**
     * 依据工序获取适用产线
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetComMscJg(String designKey) {
        Object[] obj = new Object[] { designKey };
        return this
                .getDataBySqlID("CoreOrderReviewTechnology.GetComMscJg", obj);
    }
    
    /**
     * 依据工序获取适用产线
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftComMscJg(String designKey) {
        Object[] obj = new Object[] { designKey };
        return this
                .getDataBySqlID("CoreOrderReviewTechnology.GetCraftComMscJg", obj);
    }

    /**
     * 获取接箍备料信息
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetJgBl(String designKey, String codeJg) {
        Object[] obj = new Object[] { designKey, codeJg };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetJgBl", obj);
    }
    
    /**
     * 获取接箍备料信息
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftJgBl(String designKey, String keyJg) {
        Object[] obj = new Object[] { designKey, keyJg };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetCraftJgBl", obj);
    }

    /**
     * 备料码
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetMscBl(String designKey) {
        Object[] obj = new Object[] { designKey, designKey };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetMscBl", obj);
    }
    
    /**
     * 备料码
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftMscBl(String designKey) {
        Object[] obj = new Object[] { designKey };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetCraftMscBl", obj);
    }

    /**
     * 交货行数据绑定
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetMscPlPc(String ordLnPk, String mscPline) {
        Object[] obj = new Object[] { ordLnPk, mscPline, mscPline, mscPline };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetMscPlPc", obj);
    }
    
    /**
     * 交货行数据绑定
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftMscPlPc(String ordLnPk, String mscPline) {
        Object[] obj = new Object[] { ordLnPk, mscPline, mscPline, mscPline };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetCraftMscPlPc", obj);
    }

    /**
     * 获取交货行对应的工序
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetMscPlPcLst(String designKey, String mscPline,
            String ordLnDlyPk) {
        Object[] obj = new Object[] { designKey, mscPline, ordLnDlyPk };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetMscPlPcLst",
                obj);
    }
    
    /**
     * 获取交货行对应的工序
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftMscPlPcLst(String designKey, String mscPline,
            String ordLnDlyPk) {
        Object[] obj = new Object[] { designKey, mscPline, ordLnDlyPk };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetCraftMscPlPcLst",
                obj);
    }

    /**
     * 获取当前选中合同行的技术评审状态。
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetReviewStatus(String ordLnPk) {
        Object[] obj = new Object[] { ordLnPk };
        return this.getDataBySqlID("CoreOrderReviewTechnology.GetReviewStatus",
                obj);
    }

    /**
     * 获取Mps信息
     * @param ordlnPk 合同行主键
     * @return obj
     */
    public CoreReturnObject getMpsInfo(String ordlnPk) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.getMpsInfo");
        sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordlnPk);

        return this.getData(sql);
    }

    /**
     * 修改生成周期
     * @param strJSON
     * @return obj
     */
    public CoreReturnObject setMscPlPc(String strJSON) {
        JSONObject obj = JSONObject.fromObject(strJSON);
        DesignMscPlPcEntity mscPlPc = (DesignMscPlPcEntity) JSONObject.toBean(
                obj, DesignMscPlPcEntity.class);
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.setMscPlPc");
        sql = EntityTool.fillSqlByEntity(sql, mscPlPc);

        return this.setData(sql);
    }
    
    /**
     * 修改生成周期
     * @param strJSON
     * @return obj
     */
    public CoreReturnObject setCraftMscPlPc(String strJSON) {
        JSONObject obj = JSONObject.fromObject(strJSON);
        DesignMscPlPcEntity mscPlPc = (DesignMscPlPcEntity) JSONObject.toBean(
                obj, DesignMscPlPcEntity.class);
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.setCraftMscPlPc");
        sql = EntityTool.fillSqlByEntity(sql, mscPlPc);

        return this.setData(sql);
    }

    /**
     * 评审备料
     * @param paramList
     * @param userDept
     * @param userName
     * @param reason
     * @param flag
     * @return
     */
    public CoreReturnObject doCommitBl(ArrayList<String[]> paramList,
            String userDept, String userName, String reason, String flag) {
        ArrayList<String> sqlList = new ArrayList<String>();
        for (String[] params : paramList) {
            String sqlGetMscBlByPk = CoreXmlSqlParsersFactory
                    .getSql("BLCodeManage.queryMscBlByPk");
            sqlGetMscBlByPk = StringTool.ReplaceAll(sqlGetMscBlByPk,
                    "#PSC_BL#", params[1]);
            Connection con = this.getDao(CoreConstantData.sysbeanstr)
                    .getConnection();
            ArrayList<ComMscBlEntity> mscBlEntityList = EntityTool
                    .getEntitysBySql(sqlGetMscBlByPk, con, ComMscBlEntity.class);
            if (!mscBlEntityList.get(0).getReviewStatus().equals("1")) {
                CoreReturnObject cro = new CoreReturnObject();
                cro.setV_errMsg("只能评审技术评审中的备料管！");
                return cro;
            }
            String sql = CoreXmlSqlParsersFactory
                    .getSql("BLCodeManage.updateReviewStateByPk");
            sql = StringTool.ReplaceAll(sql, "#PSC_BL#", params[1]);
            if (flag.equals("0")) {
                sql = StringTool.ReplaceAll(sql, "#REVIEW_STATUS#", "3");
            }
            else {
            	String sqlBlDesignSts = CoreXmlSqlParsersFactory.getSql("BLCodeManage.getBlDesignSts");
            	sqlBlDesignSts = StringTool.ReplaceAll(sqlBlDesignSts, "#PSC_BL#", params[1]);
            	con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            	ArrayList<GenericEntity> blDesignStsList = EntityTool.getEntitysBySql(sqlBlDesignSts, con, GenericEntity.class);
            	if(!blDesignStsList.get(0).getValue().equals("S")){
            		CoreReturnObject cro = new CoreReturnObject();
                    cro.setV_errMsg("该备料管设计状态未通过，不能进行评审通过！");
                    return cro;
            	}
            	sql = StringTool.ReplaceAll(sql, "#REVIEW_STATUS#", "2");
            }
            sql = StringTool.ReplaceAll(sql, "#DESGIN_KEY#", params[2]);
            sqlList.add(sql);
        }
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqlList);
    }

    /**
     * 技术评审通过/不通过
     * @param paramList 参数 ORD_PK、ORD_LB_PK、DESIGN_KEY组成的ArrayList的集合
     * @param userDept 部门
     * @param userName 操作人
     * @param reason 原因
     * @param flag 通过/ 不通过
     * @param con
     * @return
     * @throws SQLException
     */
    public CoreReturnObject doCommit(ArrayList<String[]> paramList,
            String userDept, String userName, String reason, String flag,
            Connection con) throws SQLException {
        CoreReturnObject core = new CoreReturnObject();
        String sql = "";
        PreparedStatement ps = null;
        ResultSet rs = null;
        CoreOrderInfoUpdate cou =new CoreOrderInfoUpdate();
        // 判断合同行是否能够质量评审,如果有一条不能质量评审,则全部退回
        for (int i = 0; i < paramList.size(); i++) {
            String[] param = paramList.get(i);
            sql = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnology.getOrdLineSatus");
            ps = con.prepareStatement(sql);
            ps.setObject(1, param[1]);
            rs = ps.executeQuery();
            String lineStatus = "";
//            String isLock = "0";
            if (rs.next()) {
                lineStatus = rs.getString("ORDER_LN_STATUS");
//                isLock = rs.getString("ISLOCK");
            }
//            if("1".equals(isLock)){
//                core.setV_errMsg("当前合同行已锁定,不允许再次执行技术评审");
//                return core;
//            }
            if (!lineStatus.equals("12020201")) {
                core.setV_errMsg("当前合同行技术评审完毕,不允许再次执行技术评审");
                return core;
            }
            if (flag.equals("1")) {
                sql = CoreXmlSqlParsersFactory
                        .getSql("CoreOrderReviewTechnology.getOrdLineDesignSatus");
                rs.close();
                ps.close();
                ps = con.prepareStatement(sql);
                ps.setObject(1, param[1]);
                rs = ps.executeQuery();
                List<String> listStatus = new ArrayList<String>();
                while (rs.next()) {
                    String designStatus = rs.getString("DESIGN_STS");
                    listStatus.add(designStatus);
                }
                if(listStatus.size() == 0){
                    core.setV_errMsg("质量设计未完成，请点击质量设计按钮进行质量设计！");
                    return core;
                }
                if (listStatus.contains("W") || listStatus.contains("F")
                        || listStatus.contains("")) {
                    core.setV_errMsg("质量设计未完成，请点击质量设计按钮进行质量设计！");
                    return core;
                }
            }
        }

        for (int i = 0; i < paramList.size(); i++) {
            // 修改合同行在评审明细的状态
            String[] param = paramList.get(i);
            // 获取销售组织
//            CoreCastWell coreCastWell = new CoreCastWell();
//            String[] saleInfo = coreCastWell.getSaleInfo(con, param[0]);
            SqlBuilder b1 = new SqlBuilder("CoreOrderCopy.queryHead");
            b1.Fill(new String[]{param[0]});
            SlmOrderHeadCopy orderHead = EntityTool.getEntityBySqlNoClsCon(b1.toString(), con, SlmOrderHeadCopy.class);
            // 天管合同取msc创建人 ，天淮取前端传的值
            if (!orderHead.getSupplyUnit().equals("120504")){
                // 查询msc创建人创建部门
                sql = CoreXmlSqlParsersFactory
                        .getSql("CoreOrderReviewTechnology.getMscInfo");
                rs.close();
                ps.close();
                ps = con.prepareStatement(sql);
                ps.setObject(1, param[1]);
                rs = ps.executeQuery();
                if (rs.next()) {
                    userDept = "技术中心-" + rs.getString("UNIT_DESC_PROCESS");
                    userName = rs.getString("CREATE_NAME");
                }
            }

            // 查询评审单号
            sql = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnology.getOrderReview");
            rs.close();
            ps.close();
            ps = con.prepareStatement(sql);
            ps.setObject(1, param[0]);
            String reviewNo = "";
            rs = ps.executeQuery();
            if (rs.next()) {
                reviewNo = rs.getString("REVIEW_NO");
            }
            if (reviewNo.length() == 0) {
                core.setV_errMsg("该合同评审单号不存在");
                return core;
            }
            sql = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnology.updateItemList");
            rs.close();
            ps.close();
            ps = con.prepareStatement(sql);
            String info = "";
            if (flag.equals("1")) {
                ps.setObject(1, "S");
                info = userDept + "-" + userName + "在[技术评审界面]点击[评审通过]";
            }
            else {
                ps.setObject(1, "F");
                info = userDept + "-" + userName + "在[技术评审界面]点击[评审不通过]";
            }
            ps.setObject(2, reason);
            ps.setObject(3, userDept);
            ps.setObject(4, userName);
            ps.setObject(5, info);
            ps.setObject(6, reviewNo);
            ps.setObject(7, "T");
            ps.setObject(8, param[1]);
            ps.executeUpdate();

            List<SlmOrderReviewItemListEntity> list = CoreOrderStatusCommFun
                    .selectOrderReviewItemListInfo(con, reviewNo, "T", "L",
                            param[1]);
            CoreOrderStatusCommFun.setOrderReviewItemListValue(con, reviewNo,
                    "T", "L", param[1]);
            if (list != null && list.size() > 0) {
                SlmOrderReviewItemListEntity slm = list.get(0);
                slm.setCreateName(userName);
                slm.setReviewDept(userDept);
                slm.setReviewEdate("");
                slm.setReviewBdate("");
                CoreOrderStatusCommFun.addOrderReviewItemListInfo(con, slm);
            }
            // 修改合同行状态
            // 合同类型
            String ordType = CoreOrderStatusCommFun.getOrderType(con, param[0]);
            sql = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnology.updateOldLineStatus");
            ps.close();
            ps = con.prepareStatement(sql);
            if (flag.equals("1")) {
                if (ordType.equals("120103")) { // 研发合同 直接生效
                    ps.setObject(1, "12020301");
                }
                else {
                    ps.setObject(1, "12020202");
                }
            }
            else {
                ps.setObject(1, "12020203");
            }
            ps.setObject(2, param[1]);
            ps.executeUpdate();
            // 修改合同行下所有交货行的状态
            sql = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnology.updateOldDelivryStatus");
            ps.close();
            ps = con.prepareStatement(sql);
            if (flag.equals("1")) {
                if (ordType.equals("120103")) { // 研发合同 直接生效
                    ps.setObject(1, "12020301");
                }
                else {
                    ps.setObject(1, "12020202");
                }
            }
            else {
                ps.setObject(1, "12020203");
            }
            ps.setObject(2, param[1]);
            ps.executeUpdate();
            cou.doCrmEvent(con,"" ,param[1],"","1");
            cou.doCrmEvent(con,"" ,param[1],"","1","2");
            // 修改合同头状态
            /*
             * for (int i = 0; i < paramList.size(); i++) { String[] param =
             * paramList.get(i); // 查询评审单号 sql = CoreXmlSqlParsersFactory
             * .getSql("CoreOrderReviewTechnology.getOrderReview"); ps =
             * con.prepareStatement(sql); ps.setObject(1, param[0]); String
             * reviewNo = ""; rs = ps.executeQuery(); if (rs.next()) { reviewNo
             * = rs.getString("REVIEW_NO"); } if (reviewNo.length() == 0) {
             * core.setV_errMsg("该合同评审单号不存在"); return core; }
             */
            sql = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnology.getLinesStatus");
            ps.close();
            ps = con.prepareStatement(sql);
            ps.setObject(1, param[0]);
            List<String> lineStatuses = new ArrayList<String>();
            rs = ps.executeQuery();
            while (rs.next()) {
                lineStatuses.add(rs.getString("ORDER_LN_STATUS"));
            }
            if (lineStatuses.size() == 0) {
                core.setV_errMsg("合同行状态异常!");
                return core;
            }
            else {
                // 获取合同行变更状态 (可能技术评审的是合同行变更的合同行)
                // 研发合同 直接生效 这里状态跟合同变更状态判断有冲突 所以跳过这段代码
                String chgeOrdLnPk = getOrderLineChgeOrdLnPk(con, param[1]);
                if (chgeOrdLnPk == null)
                    chgeOrdLnPk = "";
                if (!ordType.equals("120103")) {    //研发合同跳过变更判断
                    if (lineStatuses.contains("12020301")
                            || lineStatuses.contains("12020401")
                            || lineStatuses.contains("12020402")) { // 生效或者已开始提报或者提报完毕(说明已经走过合同流程
                                                                    // 是合同变更来的)
                        List<String> list1 = CoreOrderStatusCommFun
                                .getOrderReviewListStatus(con, param[0]);
                        if (list1.contains("F")) {
                            CoreOrderStatusCommFun.updateOrderReviewItemEDate(
                                    con, reviewNo, "T", "F");
                        }
                        else if (list1.contains("D")) {
                            CoreOrderStatusCommFun.updateOrderReviewItemEDate(
                                    con, reviewNo, "T", "D");
                        }
                        else if (list1.contains("W")) {
                            CoreOrderStatusCommFun.updateOrderReviewItemEDate(
                                    con, reviewNo, "T", "W");
                        }
                        else if (list1.contains("L")) {
                            CoreOrderStatusCommFun.updateOrderReviewItemEDate(
                                    con, reviewNo, "T", "L");
                        }
                        else {
                            CoreOrderStatusCommFun.updateOrderReviewItemEDate(
                                    con, reviewNo, "T", "S");
                        }
                        return core;
                    }
                }
                // 修改合同头状态
                sql = CoreXmlSqlParsersFactory
                        .getSql("CoreOrderReviewTechnology.updateHeadStatus");
                rs.close();
                ps.close();
                
                ps = con.prepareStatement(sql);
                if (flag.equals("1")) {
                    if (ordType.equals("120103")) { // 研发合同
                        if (lineStatuses.contains("12020203")) {
                            if (chgeOrdLnPk.equals("")) {
                                ps.setObject(1, "12020203");
                                ps.setObject(2, "技术评审失败");
                                ps.setObject(3, param[0]);
                                ps.executeUpdate();
                                ps.close();
                            }
                        }
                        else if (lineStatuses.contains("12020201")) {
                            if (chgeOrdLnPk.equals("")) {
                                ps.setObject(1, "12020201");
                                ps.setObject(2, "技术评审中");
                                ps.setObject(3, param[0]);
                                ps.executeUpdate();
                                ps.close();
                            }
                        }
                        else if ((lineStatuses.size() == 1
                                && lineStatuses.contains("12020301")) || !chgeOrdLnPk.equals("")) {
                            if (chgeOrdLnPk.equals("")) {
                                ps.setObject(1, "12020301");
                                ps.setObject(2, "生效");
                                ps.setObject(3, param[0]);
                                ps.executeUpdate();
                                ps.close();
                            }
                            // 修改评审项目技术评审的状态
                            sql = CoreXmlSqlParsersFactory
                                    .getSql("CoreOrderReviewTechnology.updateItemStatus");
                            ps = con.prepareStatement(sql);
                            ps.setObject(1, "S");
                            ps.setObject(2, reviewNo);
                            ps.executeUpdate();
                            ps.close();
                        }
                        else {
                            core.setV_errMsg("合同行异常!");
                            return core;
                        }
                    }
                    else {
                        if (lineStatuses.contains("12020203")) {
                            if (chgeOrdLnPk.equals("")) {
                                ps.setObject(1, "12020203");
                                ps.setObject(2, "技术评审失败");
                                ps.setObject(3, param[0]);
                                ps.executeUpdate();
                                ps.close();
                            }
                        }
                        else if (lineStatuses.contains("12020201")) {
                            if (chgeOrdLnPk.equals("")) {
                                ps.setObject(1, "12020201");
                                ps.setObject(2, "技术评审中");
                                ps.setObject(3, param[0]);
                                ps.executeUpdate();
                                ps.close();
                            }
                        }
                        else if ((lineStatuses.size() == 1
                                && lineStatuses.contains("12020202")) || !chgeOrdLnPk.equals("")) {
                            if (chgeOrdLnPk.equals("")) {
                                ps.setObject(1, "12020202");
                                ps.setObject(2, "技术评审通过");
                                ps.setObject(3, param[0]);
                                ps.executeUpdate();
                                ps.close();
                            }
                            // 修改评审项目技术评审的状态
                            sql = CoreXmlSqlParsersFactory
                                    .getSql("CoreOrderReviewTechnology.updateItemStatus");
                            ps = con.prepareStatement(sql);
                            ps.setObject(1, "S");
                            ps.setObject(2, reviewNo);
                            ps.executeUpdate();
                            ps.close();
                        }
                        else {
                            core.setV_errMsg("合同行异常!");
                            return core;
                        }
                    }
                }
                else {
                    if (lineStatuses.contains("12020203")
                            || lineStatuses.contains("12020301")
                            || lineStatuses.contains("12020401")
                            || lineStatuses.contains("12020402")) {
                        if (chgeOrdLnPk.equals("")) {
                            ps.setObject(1, "12020203");
                            ps.setObject(2, "技术评审失败");
                            ps.setObject(3, param[0]);
                            ps.executeUpdate();
                            ps.close();
                        }
                        sql = CoreXmlSqlParsersFactory
                                .getSql("CoreOrderReviewTechnology.updateItemStatus");
                        ps = con.prepareStatement(sql);
                        ps.setObject(1, "F");
                        ps.setObject(2, reviewNo);
                        ps.executeUpdate();
                        ps.close();
                    }
                    else {
                        core.setV_errMsg("合同行异常!");
                        return core;
                    }
                }
                cou.doCrmEvent(con, param[0],"","","1");
            }

            // 清除回退
            String sqlFallBack = CoreXmlSqlParsersFactory
                    .getSql("QualityDesignFallback.deleteFallBack");
            PreparedStatement psFallBack = con.prepareStatement(sqlFallBack);
            psFallBack.setString(1, param[1]);
            psFallBack.executeUpdate();
            
            //清除质量设计附加要求评审状态
            SqlBuilder b = new SqlBuilder("CoreOrderSpecialInfo.deleteDesignAddAskSts");
            b.Fill(new String[]{ param[1] });
            psFallBack.executeUpdate(b.toString());
            psFallBack.close();
        }
        return core;
    }

    // -----------------2015/06/24
    /**
     * 评审通过或者不能通过
     * @param paramList 数组集合
     * @param userDept 操作人部门
     * @param userName 操作人
     * @return CoreReturnObject
     */
    public CoreReturnObject doCommit(ArrayList<String[]> paramList,
            String userDept, String userName, String reason, String flag) {
        CoreReturnObject core = new CoreReturnObject();
        Connection con = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            con.setAutoCommit(false);
            core = doCommit(paramList, userDept, userName, reason, flag, con);
            if (!core.getV_errMsg().equals("")) {
                con.rollback();
                return core;
            }
            con.commit();
        }
        catch (SQLException e) {
            try {
                con.rollback();
            }
            catch (SQLException e1) {
                e1.printStackTrace();
            }
            e.printStackTrace();
        }
        finally {
            try {
                con.close();
            }
            catch (Exception ex) {

            }
        }
        return core;
    }

    /**
     * 修改评审明细状态（合同行）
     * @param con 连接字符串
     * @param status 状态
     * @param reviewNo 评审主键
     * @param reviewItm 评审项目
     * @param oldLnPk 合同行号
     * @throws SQLException
     */
    public static void updateItemList(Connection con, String status,
            String reviewNo, String reviewItm, String oldLnPk, String reason,
            String userDept, String userName) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.updateItemList");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, status);
        ps.setObject(2, reason);
        ps.setObject(3, userDept);
        ps.setObject(4, userName);
        ps.setObject(5, reviewNo);
        ps.setObject(6, reviewItm);
        ps.setObject(7, oldLnPk);
        ps.executeUpdate();
        ps.close();
    }

    /**
     * 获取合同行状态
     * @param ordLnPk
     * @return obj
     */
    public CoreReturnObject getOrdLnState(String ordLnPk) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.getOrdLnState");
        sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);

        return this.getData(sql);
    }

    /**
     * 获取合同行变更后键值
     * @param con
     * @param ordLnPk
     * @return
     * @throws SQLException
     */
    public String getOrderLineChgeOrdLnPk(Connection con, String ordLnPk)
            throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.getOrdLnChgeOrdLnPk");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, ordLnPk);
        ResultSet rs = ps.executeQuery();
        String chgeLnPk = "";
        if (rs.next()) {
            chgeLnPk = rs.getString(1);
        }
        return chgeLnPk;
    }

    /**
     * 查询MSC备料码
     * @param pscBl
     * @return
     */
    public CoreReturnObject getComMscBl(String blCode) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnology.getComMscBl");
        sql = StringTool.ReplaceAll(sql, "#PSC_BL#", blCode);
        return this.getData(sql);
    }
    
    /**
     * 锁定工艺评审主表
     * @param ordLnPk
     * @return
     */
    public CoreReturnObject lock(ArrayList<String> listJSON){
    	TransctionTool transction = new TransctionTool();
    	try{
	    	Connection con = transction.getCon();
	    	for(String strJSON : listJSON){
	    		CraftOrdDesignEntity craftOrdDesign = EntityTool.getEntityByJSONStr(strJSON, CraftOrdDesignEntity.class);
	    		String sqlGetMaxSeq = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getCraftOrdDesignMaxSeq");
	    		sqlGetMaxSeq = EntityTool.fillSqlByEntity(sqlGetMaxSeq, craftOrdDesign);
	    		ArrayList<GenericEntity> listMaxSeq = EntityTool.getEntitysBySqlNoClsCon(sqlGetMaxSeq, con, GenericEntity.class);
	    		if(listMaxSeq.get(0).getMaxValue().equals("")){
	    			craftOrdDesign.setCraftSeq("1");
	    		}else{
	    			craftOrdDesign.setCraftSeq(String.valueOf(Integer.parseInt(listMaxSeq.get(0).getMaxValue()) + 1));
	    		}
	    		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.insertCraftOrdDesign");
	        	sql = EntityTool.fillSqlByEntity(sql, craftOrdDesign);
	        	boolean result = transction.ExcuteTransction(sql);
	        	if(result == false){
	        		return transction.rollBack();
	        	}
	    	}
    	}catch(Exception ex){
    		CoreReturnObject cro = transction.rollBack();
			cro.setV_errMsg(ex.getMessage());
			return cro;
    	}
    	return transction.commit();
    }
    
    /**
     * 解锁工艺评审主表
     * @param ordLnPk
     * @param craftSeq
     * @return
     */
    public CoreReturnObject unlock(ArrayList<String> listJSON){
    	TransctionTool transction = new TransctionTool();
    	try{
	    	for(String strJSON : listJSON){
	    		CraftOrdDesignEntity craftOrdDesign = EntityTool.getEntityByJSONStr(strJSON, CraftOrdDesignEntity.class);
	    		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.updateCraftOrdDesign");
	        	sql = EntityTool.fillSqlByEntity(sql, craftOrdDesign);
	        	boolean result = transction.ExcuteTransction(sql);
	        	if(result == false){
	        		return transction.rollBack();
	        	}
	    	}
    	}catch(Exception ex){
    		CoreReturnObject cro = transction.rollBack();
			cro.setV_errMsg(ex.getMessage());
			return cro;
    	}
    	return transction.commit();
    }
    
    /**
     * 查询销售合同提报表
     * @param ordLnPk
     * @return
     */
    public CoreReturnObject queryPlnSaleorder(String ordLnPk){
    	String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.queryPlnSaleorder");
    	sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
    	return this.getData(sql);
    }
    
    /**
	 * 清除工艺评审主表
	 * @param ordLnPk
	 * @return
     * @throws SQLException 
	 */
	public int clearCraftOrdDesign(String ordLnPk, Connection con) throws SQLException{
//		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.clearCraftOrdDesign");
//		sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
//		PreparedStatement ps = con.prepareStatement(sql);
//		int cnt = ps.executeUpdate();
//		ps.close();
//		return cnt;
		return 0;
	}
	
	/**
	 * 复制质量设计结果到工艺设计表中
	 * @param designKey
	 * @return
	 */
	public CoreReturnObject copyOrdToCraft(String ordLnPk, String qualityFlag, String userName, String operateType){
		TransctionTool transction = new TransctionTool();
		Connection con = transction.getCon();
		try{
			CoreReturnObject cro;
			String sqlGuid = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getGuid");
			ArrayList<GenericEntity> guidList = EntityTool.getEntitysBySqlNoClsCon(sqlGuid, con, GenericEntity.class);
			String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.copyOrdToCraft2");
			sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
			sql = StringTool.ReplaceAll(sql, "#OPERATE_TYPE#", operateType);
			sql = StringTool.ReplaceAll(sql, "#CREATE_NAME#", userName);
			sql = StringTool.ReplaceAll(sql, "#UPDATE_NAME#", userName);
			sql = StringTool.ReplaceAll(sql, "#DESIGN_KEY_NEW#", guidList.get(0).getValue());
			sql = StringTool.ReplaceAll(sql, "#QUALITY_FLAG#", qualityFlag);
			boolean result = transction.ExcuteTransction(sql);
			if(!result){
				return transction.getReturnObject();
			}
				
			//内控暂时不启用。
			CraftInnerMain craftInnerMain = new CraftInnerMain();
			String msg = craftInnerMain.craftInner(con, guidList.get(0).getValue(), ordLnPk);
			if(!msg.equals("")){
				cro = transction.rollBack();
				cro.setV_errMsg(msg);
				return cro; 
			}
			
			cro = transction.commit();
			String sqlSts2 = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getCraftDesignSts2");
			sqlSts2 = StringTool.ReplaceAll(sqlSts2, "#ORD_LN_PK#", ordLnPk);
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			ArrayList<GenericEntity> craftDesignStsList = EntityTool.getEntitysBySql(sqlSts2, con, GenericEntity.class);
			cro.setResult(craftDesignStsList.get(0).getValue());
			return cro;
		}catch(Exception ex){
			CoreReturnObject cro = transction.rollBack();
			cro.setV_errMsg(ex.getMessage());
			return cro;
		}
	}
	
	/**
	 * 获取工艺质量设计状态
	 * @param ordLnPk
	 * @return
	 */
	public CoreReturnObject getCraftDesignSts(String ordLnPk){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getCraftDesignSts");
		sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
		return this.getData(sql);
	}
	
	/**
	 * 生成工艺评审主表信息
	 * @param ordLnPk
	 * @param designKey
	 * @param userName
	 * @param con
	 * @return
	 * @throws SQLException
	 */
	public int insrtOrUpdtCrafte(String ordLnPk, String designKey, String userName, 
			String operateType, String designStyle, Connection con) throws SQLException{
		SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.queryComMscByOrdLnPk");
		b.Fill(new String[]{ ordLnPk });
		ComMscEntity mscEntity = EntityTool.getEntityBySqlNoClsCon(
				b.toString(), con, ComMscEntity.class);
		CraftOrdDesignEntity craftOrdDesign = new CraftOrdDesignEntity();
		craftOrdDesign.setOrdLnPk(ordLnPk);
		craftOrdDesign.setDesginKey(designKey);
		if(mscEntity != null && designStyle.equals("0")){
			craftOrdDesign.setCreateName(mscEntity.getCreateName());
			craftOrdDesign.setUpdateName(mscEntity.getCreateName());
		}else{
			craftOrdDesign.setCreateName(userName);
			craftOrdDesign.setUpdateName(userName);
		}
		craftOrdDesign.setLockFlag("1");
		//获取上一版本的工艺变更说明
		String sqlMaxCrat = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getCraftOrdDesign");
		sqlMaxCrat = StringTool.ReplaceAll(sqlMaxCrat, "#ORD_LN_PK#", ordLnPk);
		CraftOrdDesignEntity maxCraftEntity = EntityTool.getEntityBySqlNoClsCon(
				sqlMaxCrat, con, CraftOrdDesignEntity.class);
		if(maxCraftEntity != null){
			craftOrdDesign.setCraftChangeMemo(maxCraftEntity.getCraftChangeMemo());
			craftOrdDesign.setPicFdCheck(maxCraftEntity.getPicFdCheck());
			craftOrdDesign.setCicFdCheck(maxCraftEntity.getCicFdCheck());
			craftOrdDesign.setWicFdCheck(maxCraftEntity.getWicFdCheck());
		}
		if(craftOrdDesign.getPicFdCheck().equals("")){
			craftOrdDesign.setPicFdCheck("0");
		}
		if(craftOrdDesign.getCicFdCheck().equals("")){
			craftOrdDesign.setCicFdCheck("0");
		}
		if(craftOrdDesign.getWicFdCheck().equals("")){
			craftOrdDesign.setWicFdCheck("0");
		}
		
		String sql = "";
		String sqlSetAllValidflag = "";
		
		String sqlGetMaxSeq = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getCraftOrdDesignMaxSeq");
		sqlGetMaxSeq = EntityTool.fillSqlByEntity(sqlGetMaxSeq, craftOrdDesign);
		ArrayList<GenericEntity> listMaxSeq = EntityTool.getEntitysBySqlNoClsCon(sqlGetMaxSeq, con, GenericEntity.class);
		if(listMaxSeq.get(0).getMaxValue().equals("")){
			craftOrdDesign.setCraftSeq("1");
		}else{
			craftOrdDesign.setCraftSeq(String.valueOf(Integer.parseInt(listMaxSeq.get(0).getMaxValue()) + 1));
		}
		
		String sqlGetCraftCnt = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getCraftOrdDesign");
		sqlGetCraftCnt = EntityTool.fillSqlByEntity(sqlGetCraftCnt, craftOrdDesign);
		ArrayList<CraftOrdDesignEntity> listCraftCnt = EntityTool.getEntitysBySqlNoClsCon(sqlGetCraftCnt, con, CraftOrdDesignEntity.class);
		
		if(listCraftCnt.size() == 0){
			sqlSetAllValidflag = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.setAllCraftValidflag");
			sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.insertCraftOrdDesign");
		}
		else{
			if(operateType.equals("0"))
			{
				if(listCraftCnt.get(0).getValidflag().equals("1") || listCraftCnt.get(0).getValidflag().equals("0")){
					sqlSetAllValidflag = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.setAllCraftValidflag");
					sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.insertCraftOrdDesign");
				}else{
					sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.updateCraftOrdDesign");
					craftOrdDesign.setCraftSeq(listCraftCnt.get(0).getCraftSeq());
					craftOrdDesign.setValidflag("2");
				}
			}else{
				sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.updateCraftOrdDesign2");
				craftOrdDesign.setCraftSeq(listCraftCnt.get(0).getCraftSeq());
				craftOrdDesign.setLockFlag("");
			}
		}
		
		if(!sqlSetAllValidflag.equals("")){
			sqlSetAllValidflag = EntityTool.fillSqlByEntity(sqlSetAllValidflag, craftOrdDesign);
			PreparedStatement ps2 = con.prepareStatement(sqlSetAllValidflag);
			ps2.executeUpdate();
			ps2.close();
		}
		
		if(designStyle.equals("0")){
			craftOrdDesign.setCraftSource("销售提报");
		}
		sql = EntityTool.fillSqlByEntity(sql, craftOrdDesign);
    	PreparedStatement ps = con.prepareStatement(sql);
		int cnt = ps.executeUpdate();
		ps.close();
		return cnt;
	}
	
	/**
	 * 修改工艺文件号并置为生效状态
	 * @param ordLnPk
	 * @return
	 */
	public CoreReturnObject updateCraftNo(String ordLnPk, String craftNo, String craftPath){
		String sqlGetCraftDesignSts2 = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getCraftDesignSts2");
		sqlGetCraftDesignSts2 = StringTool.ReplaceAll(sqlGetCraftDesignSts2, "#ORD_LN_PK#", ordLnPk);
		Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		ArrayList<GenericEntity> craftDesignStsList = EntityTool.getEntitysBySql(sqlGetCraftDesignSts2, con, GenericEntity.class);
		String designKey = craftDesignStsList.get(0).getValue3();
		String sqlUpdateCraftNo = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.updateCraftNo");
		sqlUpdateCraftNo = StringTool.ReplaceAll(sqlUpdateCraftNo, "#CRAFT_NO#", craftNo);
		sqlUpdateCraftNo = StringTool.ReplaceAll(sqlUpdateCraftNo, "#CRAFT_PATH#", craftPath);
		sqlUpdateCraftNo = StringTool.ReplaceAll(sqlUpdateCraftNo, "#DESGIN_KEY#", designKey);
		return this.setData(sqlUpdateCraftNo);
	}
	
	/**
	 * 获取制程工艺评审中的工艺文件号。
	 * @param designKey
	 * @return
	 */
	public CoreReturnObject getDesignPlCraftNo(String designKey){
		String sqlGetDesignPlCraftNo = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getDesignPlCraftNo");
		sqlGetDesignPlCraftNo = StringTool.ReplaceAll(sqlGetDesignPlCraftNo, "#DESGIN_KEY#", designKey);
		return this.getData(sqlGetDesignPlCraftNo);
	}
	
	/**
	 * 获取管理部门科室
	 * @return
	 */
	public CoreReturnObject getDepartment(){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getDepartment");
		return this.getData(sql);
	}
	
	/**
	 * 获取对应科室的成员
	 * @return
	 */
	public CoreReturnObject getUser(String unitCode){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getUser");
		sql = StringTool.ReplaceAll(sql, "#DEPTID#", unitCode);
		return this.getData(sql);
	}
	
	/**
	 * 工艺指派
	 * @return
	 */
	public CoreReturnObject appoint(ArrayList<String> ordLnPkList, String userName,
			String craftName, String craftId){
		TransctionTool transction = new TransctionTool();
		Connection con = transction.getCon();
		try{
			for(String ordLnPk : ordLnPkList){
				String sqlCraftDesignAppointCnt = CoreXmlSqlParsersFactory.getSql(
						"CoreOrderReviewTechnology.getCraftDesignAppointCnt");
				sqlCraftDesignAppointCnt = StringTool.ReplaceAll(sqlCraftDesignAppointCnt, "#ORD_LN_PK#", ordLnPk);
				ArrayList<GenericEntity> craftDesignAppointCntList = EntityTool.getEntitysBySqlNoClsCon(
						sqlCraftDesignAppointCnt, con, GenericEntity.class);
				String sql = "";
				if(craftDesignAppointCntList.get(0).getCount().equals("0")){
					sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.insertCraftDesignAppoint");
				}else{
					sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.updateCraftDesignAppoint");
				}
				sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
				sql = StringTool.ReplaceAll(sql, "#APPOINT_NAME#", userName);
				sql = StringTool.ReplaceAll(sql, "#CRAFT_NAME#", craftName);
				sql = StringTool.ReplaceAll(sql, "#CRAFT_ID#", craftId);
				boolean result = transction.ExcuteTransction(sql);
				if(!result){
					return transction.getReturnObject();
				}
			}
			
		}catch(Exception ex){
			transction.rollBack();
		}
		return transction.commit();
	}
	
	/**
	 * 获取工艺指派记录
	 * @return
	 */
	public CoreReturnObject getCraftDesignAppointByPk(String ordLnPk){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getCraftDesignAppointByPk");
		sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
		return this.getData(sql);
	}
	
	/**
	 * 修改合同行切长
	 * @return
	 */
	public CoreReturnObject updateOrderLineInspV(String ordLnPk, String inspV){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.updateOrderLineInspV");
		sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
		sql = StringTool.ReplaceAll(sql, "#INSPECTION_VALUE#", inspV);
		return this.setData(sql);
	}
	
	/**
	 * 查询合同行号通过合同行主键
	 * @param ordPk
	 * @return
	 */
	public CoreReturnObject getOrdSeqByOrdPk(String ordPk){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getOrdSeqByOrdPk");
		sql = StringTool.ReplaceAll(sql, "#ORD_PK#", ordPk);
		return this.getData(sql);
	}
	
	/**
	 * 获取工艺文件
	 * @return
	 */
	public CoreReturnObject getCraftOrdDesignFile(String customInfo, String craftNo, String memo, String isValid,String validflag){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getCraftOrdDesignFile");
		sql = StringTool.ReplaceAll(sql, "#CUSTOM_INFO#", customInfo);
		sql = StringTool.ReplaceAll(sql, "#CRAFT_NO#", craftNo);
		sql = StringTool.ReplaceAll(sql, "#MEMO#", memo);
		sql = StringTool.ReplaceAll(sql, "#IS_VALID#", isValid);
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", validflag);
		return this.getData(sql);
	}
	
	/**
	 * 保存工艺文件
	 * @return
	 */
	public CoreReturnObject saveCraftNoBatch(ArrayList<String> list, String craftNo,
			String craftPath, String craftNoV, String memo, String name){
		ArrayList<String> sqllist = new ArrayList<String>();
		String ordLnPks = "'1'";
		for(String ordLnPk : list){
			ordLnPks += ", '" + ordLnPk + "'";
		}
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.saveCraftNoBatch");
		sql = StringTool.ReplaceAll(sql, "#CRAFT_NO#", craftNo);
		sql = StringTool.ReplaceAll(sql, "#CRAFT_PATH#", craftPath);
		sql = StringTool.ReplaceAll(sql, "#CRAFT_NO_V#", craftNoV);
		sql = StringTool.ReplaceAll(sql, "#MEMO#", memo);
		sql = StringTool.ReplaceAll(sql, "#DELETE_NAME#", name);
		sql = sql.replaceAll("#ORD_LN_PK_S#", ordLnPks);
		sqllist.add(sql);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	}
	
	/**
	 * 通过工艺文件号查询工艺文件数
	 * @return
	 */
	public CoreReturnObject getCrafFileByCraftNo(String craftNo, String craftV){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getCrafFileByCraftNo");
		sql = StringTool.ReplaceAll(sql, "#CRAFT_NO#", craftNo);
		sql = StringTool.ReplaceAll(sql, "#CRAFT_NO_V#", craftV);
		return this.getData(sql);
	}
	
	/**
	 * 修改工艺文件备注
	 * @return
	 */
	public CoreReturnObject setCraftFile(String craftNo, String memo, String craftKey){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.setCraftFile");
		sql = StringTool.ReplaceAll(sql, "#CRAFT_NO#", craftNo);
		sql = StringTool.ReplaceAll(sql, "#MEMO#", memo);
		sql = StringTool.ReplaceAll(sql, "#CRAFT_KEY#", craftKey);
		return this.setData(sql);
	}
	
	/**
	 * 删除工艺文件
	 * @return
	 */
	public CoreReturnObject deleteCraftFile(String craftKey, String craftNo, String craftNoV){
		String sql = "";
		if(craftKey.equals("")){
			sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.deleteCraftOrdDesignFile");
			sql = StringTool.ReplaceAll(sql, "#CRAFT_NO#", craftNo);
			sql = StringTool.ReplaceAll(sql, "#CRAFT_NO_V#", craftNoV);
		}else{
			sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.deleteCraftFile");
			sql = StringTool.ReplaceAll(sql, "#CRAFT_KEY#", craftKey);
		}
		
		return this.setData(sql);
	}
	
	/**
	 * 作废工艺文件
	 * @param craftKey
	 * @return
	 */
	public CoreReturnObject invalidCraftFile(String craftKey, String validflag){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.invalidCraftFile");
		sql = StringTool.ReplaceAll(sql, "#CRAFT_KEY#", craftKey);
		sql = StringTool.ReplaceAll(sql, "#VALIDFLAG#", validflag);
		return this.setData(sql);
	}
	
	/**
	 * 获取冶金规范的使用次数
	 * @param ordLnPk
	 * @return
	 */
	public CoreReturnObject getComMscByOrdLnPk(String ordLnPk){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getComMscByOrdLnPk");
		sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
		return this.getData(sql);
	}
	
	/**
	 * 获取标准和客户附加要求的合并项
	 * @param addAskNo
	 * @param stdCode
	 * @return
	 */
	public CoreReturnObject getOrdStdAddAskDesc(String addAskNo, String stdCode){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getOrdStdAddAskDesc");
		sql = StringTool.ReplaceAll(sql, "#ADD_ASK_NO#", addAskNo);
		sql = StringTool.ReplaceAll(sql, "#STD_CODE#", stdCode);
		return this.getData(sql);
	}
	
	/**
	 * 通过主键获取工艺文件
	 * @param craftKey
	 * @return
	 */
	public CoreReturnObject getCraftFileByPk(String craftKey){
		String sql = CoreXmlSqlParsersFactory.getSql("CoreOrderReviewTechnology.getCraftFileByPk");
		sql = StringTool.ReplaceAll(sql, "#CRAFT_KEY#", craftKey);
		return this.getData(sql);
	}
	
	/**
	 * 获取失败的节点名称
	 * @param ordLnPk
	 * @return
	 */
	public CoreReturnObject getFailLstItem(String ordLnPk){
		return this.getData(new SqlBuilder("CoreOrderReviewTechnology.getFailLstItem")
				.Fill(new String[]{ordLnPk}).toString());
	}
	
	/**
	 * 通过合同行主键查询计划表
	 * @param ordLnPk
	 * @return
	 */
	public CoreReturnObject getPlnSaleOrdByPk(String ordLnPk){
		return this.getData(new SqlBuilder("CoreOrderReviewTechnology.getPlnSaleOrdByPk")
				.Fill(new String[]{ordLnPk}).toString());
	}
	
	/**
	 * 锁定计划各工序
	 * @param ordLnPk
	 * @return
	 */
	public CoreReturnObject lockPlnSaleOrd(String ordLnPk){
		TransctionTool transction = new TransctionTool();
		try{
			//备份将要清空的各工序的工艺文件
			SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.clearCraftLockZg");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.clearCraftLockDbk");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.clearCraftLockRcl");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.clearCraftLockJgx");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.saveCraftLockZg");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.saveCraftLockDbk");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.saveCraftLockRcl");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.saveCraftLockJgx");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			
			
			//锁定并清空各工序的工艺文件
			b = new SqlBuilder("CoreOrderReviewTechnology.lockZg");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.lockDbk");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.lockRcl");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.lockJgx");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
		}catch(Exception ex){
			CoreReturnObject cro = transction.rollBack();
			cro.SetErrInfo(ex.getMessage());
			return cro;
		}
		return transction.commit();
	}
	
	/**
	 * 回滚计划各工序
	 * @param ordLnPk
	 * @param craftSeq
	 * @return
	 */
	public CoreReturnObject rollBackPlnProcess(String ordLnPk, String craftSeq){
		TransctionTool transction = new TransctionTool();
		try{
			SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.rollBackCraftOrdDesign");
			b.Fill(new String[]{ordLnPk, craftSeq});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.rollBackPlnZg");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.rollBackPlnDbk");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.rollBackPlnRcl");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.rollBackPlnJgx");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			
		}catch(Exception ex){
			CoreReturnObject cro = transction.rollBack();
			cro.SetErrInfo(ex.getMessage());
			return cro;
		}
		return transction.commit();
	}
	
	/**
	 * 修改计划各工序工艺文件
	 * @param ordLnPk
	 * @return
	 */
	public CoreReturnObject UpdatePlnProcess(String ordLnPk){
		TransctionTool transction = new TransctionTool();
		try{
			SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnZg");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnDbk");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnRcl");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
			b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnJgx");
			b.Fill(new String[]{ordLnPk});
			if(!transction.ExcuteTransction(b.toString())){
				return transction.getReturnObject();
			}
		}catch(Exception ex){
			CoreReturnObject cro = transction.rollBack();
			cro.SetErrInfo(ex.getMessage());
			return cro;
		}
		return transction.commit();
	}
	
	/**
	 * 解锁计划各个工序
	 * @param parms
	 * @return
	 */
	public CoreReturnObject unLockPlnProcess(ArrayList<String[]> parms){
		TransctionTool transction = new TransctionTool();
		try{
			for(String[] parm: parms){
				SqlBuilder b;
				if(parm[2].equals("轧制")){
					b = new SqlBuilder("CoreOrderReviewTechnology.unLockPlnZg");
				}else if(parm[2].equals("镦拔扩")){
					b = new SqlBuilder("CoreOrderReviewTechnology.unLockPlnDbk");
				}else if(parm[2].equals("热处理")){
					b = new SqlBuilder("CoreOrderReviewTechnology.unLockPlnRcl");
				}else{
					b = new SqlBuilder("CoreOrderReviewTechnology.unLockPlnJgx");
				}
				b.Fill(new String[]{parm[0], parm[1]});
				if(!transction.ExcuteTransction(b.toString())){
					return transction.getReturnObject();
				}
			}
		}catch(Exception ex){
			CoreReturnObject cro = transction.rollBack();
			cro.SetErrInfo(ex.getMessage());
			return cro;
		}
		return transction.commit();
	}
	
	/**
	 * 查询计划各个工序
	 * @param ordLnPk
	 * @return
	 */
	public CoreReturnObject queryPlnProcess(String ordLnPk){
		SqlBuilder b;
		if(ordLnPk.length() > 30){
			b = new SqlBuilder("CoreOrderReviewTechnology.queryPlnProcess");
		}else{
			b = new SqlBuilder("CoreOrderReviewTechnology.queryPlnProcessBl");
		}
		
		b.Fill(new String[]{ordLnPk});
		return this.getData(b.toString());
	}
	
	/**
	 * 工艺变更
	 * @param ordLnPk
	 * @return
	 */
	public CoreReturnObject PlnCraftChange(String ordLnPk){
		CoreReturnObject cro = new CoreReturnObject();
		Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		Statement ps = null;
		try {
			ps = con.createStatement();
			con.setAutoCommit(false);
			SqlBuilder b;
			b = new SqlBuilder("CoreOrderReviewTechnology.queryNewCraftMsc");
			b.Fill(new String[]{ordLnPk});
			GenericEntity newCraftMsc = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, GenericEntity.class);
			b = new SqlBuilder("CoreOrderReviewTechnology.queryNewCraftBacklog");
			b.Fill(new String[]{ordLnPk});
			List<GenericEntity> newCraftBacklogs = EntityTool.getEntitysBySqlNoClsCon(b.toString(), con, GenericEntity.class);
			b = new SqlBuilder("CoreOrderReviewTechnology.queryNewCraftJg");
			b.Fill(new String[]{ordLnPk});
			GenericEntity newCraftJg = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, GenericEntity.class);
			b = new SqlBuilder("CoreOrderReviewTechnology.queryNewCraftJgBl");
			b.Fill(new String[]{ordLnPk});
			List<GenericEntity> newCraftJgBls = EntityTool.getEntitysBySqlNoClsCon(b.toString(), con, GenericEntity.class);
			b = new SqlBuilder("CoreOrderReviewTechnology.queryNewCraftBl");
			b.Fill(new String[]{ordLnPk});
			List<GenericEntity> newCraftBls = EntityTool.getEntitysBySqlNoClsCon(b.toString(), con, GenericEntity.class);
			b = new SqlBuilder("CoreOrderReviewTechnology.queryNewCraftBom");
			b.Fill(new String[]{ordLnPk});
			List<GenericEntity> newCraftBoms = EntityTool.getEntitysBySqlNoClsCon(b.toString(), con, GenericEntity.class);
			b = new SqlBuilder("CoreOrderReviewTechnology.queryNewCraftPline");
			b.Fill(new String[]{ordLnPk});
			List<GenericEntity> newCraftPlines = EntityTool.getEntitysBySqlNoClsCon(b.toString(), con, GenericEntity.class);
			b = new SqlBuilder("CoreOrderReviewTechnology.queryNewCraft");
			b.Fill(new String[]{ordLnPk});
			CraftOrdDesignEntity newCraft = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, CraftOrdDesignEntity.class);
			if(ordLnPk.length() > 30){
				b = new SqlBuilder("CoreOrderReviewTechnology.queryPlnOrdProcessS");
			}else{
				b = new SqlBuilder("CoreOrderReviewTechnology.queryPlnOrdProcessSBl");
			}
			b.Fill(new String[]{ordLnPk});
			ResultSet rsPlnOrdProcess = ps.executeQuery(b.toString());
			
			//获取排产制程分解表
			b = new SqlBuilder("CoreOrderReviewTechnology.GetPlnSaleProc");
			b.Fill(new String[]{ ordLnPk });
			List<GenericEntity> plnSaleProcs = EntityTool.getEntitysBySqlNoClsCon(
					b.toString(), con, GenericEntity.class);
			//获取新工艺钢种
			b = new SqlBuilder("CoreOrderReviewTechnology.queryNewCraftAllGrade");
			b.Fill(new String[]{ ordLnPk });
			List<GenericEntity> newCraftAllGrades = EntityTool.getEntitysBySqlNoClsCon(
					b.toString(), con, GenericEntity.class);
			
			//验证轧管CIC
			
			
			boolean existPlnOrdProcess = false;
			while(rsPlnOrdProcess.next()){
				//验证对应工序是否包含索引码
				//获取炼钢索引码
				b = new SqlBuilder("CoreOrderReviewTechnology.queryLgNkIndex");
				b.Fill(new String[]{ newCraft.getDesginKey(), rsPlnOrdProcess.getString("PRO_PLAN_ID"),
						rsPlnOrdProcess.getString("GX_PLAN_NO")});
				CraftOrdDesignMscPlPrcEntity lgNkIdxEntity = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, CraftOrdDesignMscPlPrcEntity.class);
				b = new SqlBuilder("CoreOrderReviewTechnology.queryLgNkCic");
				b.Fill(new String[]{ newCraft.getDesginKey(), rsPlnOrdProcess.getString("PRO_PLAN_ID"),
						rsPlnOrdProcess.getString("GX_PLAN_NO")});
				CraftOrdDesignStdCicEntity lgCicEntity = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, CraftOrdDesignStdCicEntity.class);
				String lgAllCic = rmRepate(lgNkIdxEntity.getCic());
				lgNkIdxEntity.setCic(rmRepate(lgCicEntity.getCic()));// 复制钢种优先级小于100的成分索引码
				
				b = new SqlBuilder("CoreOrderReviewTechnology.queryZgNkIndex");
				b.Fill(new String[]{ newCraft.getDesginKey(), rsPlnOrdProcess.getString("PRO_PLAN_ID"),
						rsPlnOrdProcess.getString("GX_PLAN_NO")});
				CraftOrdDesignMscPlPrcEntity zgNkIdxEntity = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, CraftOrdDesignMscPlPrcEntity.class);
				//使用炼钢成分索引码
				if(zgNkIdxEntity != null && !zgNkIdxEntity.getCic().equals("")){
					zgNkIdxEntity.setCic(rmRepate(lgNkIdxEntity.getCic()));
				}
				
				b = new SqlBuilder("CoreOrderReviewTechnology.queryDbkNkIndex");
				b.Fill(new String[]{ newCraft.getDesginKey(), rsPlnOrdProcess.getString("PRO_PLAN_ID"),
						rsPlnOrdProcess.getString("GX_PLAN_NO")});
				CraftOrdDesignMscPlPrcEntity dbkNkIdxEntity = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, CraftOrdDesignMscPlPrcEntity.class);
				//使用炼钢成分索引码
				if(dbkNkIdxEntity != null && !dbkNkIdxEntity.getCic().equals("")){
					dbkNkIdxEntity.setCic(lgAllCic);
				}
				
				b = new SqlBuilder("CoreOrderReviewTechnology.queryRclNkIndex");
				b.Fill(new String[]{ newCraft.getDesginKey(), rsPlnOrdProcess.getString("PRO_PLAN_ID"),
						rsPlnOrdProcess.getString("GX_PLAN_NO")});
				CraftOrdDesignMscPlPrcEntity rclNkIdxEntity = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, CraftOrdDesignMscPlPrcEntity.class);
				//使用炼钢成分索引码
				if(rclNkIdxEntity != null && !rclNkIdxEntity.getCic().equals("")){
					rclNkIdxEntity.setCic(lgAllCic);
				}
				
				b = new SqlBuilder("CoreOrderReviewTechnology.queryJgxNkIndex");
				b.Fill(new String[]{ newCraft.getDesginKey(), rsPlnOrdProcess.getString("PRO_PLAN_ID"),
						rsPlnOrdProcess.getString("GX_PLAN_NO")});
				CraftOrdDesignMscPlPrcEntity jgxNkIdxEntity = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, CraftOrdDesignMscPlPrcEntity.class);
				//使用炼钢成分索引码
				if(jgxNkIdxEntity != null && !jgxNkIdxEntity.getCic().equals("")){
					jgxNkIdxEntity.setCic(lgAllCic);
				}
				
				//首先验证炼钢索引码
				if(rsPlnOrdProcess.getString("PROCESS_CODE").equals("D")){
					b = new SqlBuilder("CoreOrderReviewTechnology.getZgSLgCic");
					b.Fill(new String[]{ rsPlnOrdProcess.getString("PRO_PLAN_ID"), rsPlnOrdProcess.getString("GX_PLAN_NO") });
					PlnOrderZgSEntity zgsLgCic = EntityTool.getEntityBySqlNoClsCon(b.toString(), con, PlnOrderZgSEntity.class);
					for(String cic : zgsLgCic.getCicGroupGp().split(",")){
						if(!lgNkIdxEntity.getCic().contains(cic.trim())){
							b = new SqlBuilder("CoreOrderReviewTechnology.getZgSByPk");
							b.Fill(new String[]{ rsPlnOrdProcess.getString("PRO_PLAN_ID"), rsPlnOrdProcess.getString("GX_PLAN_NO") });
							PlnOrderZgSEntity zgsInfo = EntityTool.getEntityBySqlNoClsCon(
									b.toString(), con, PlnOrderZgSEntity.class);
							if(!zgsInfo.getGpreqId().equals("")){
								if(lgAllCic.contains(cic.trim())){
									
								}
								cro.setResult("生产计划已生成管坯需求号, 但新工艺文件中不包含成分索引码"+ cic);
								cro.setV_errCode(-1);
								return cro;
							}
						}
					}
				}
				
				existPlnOrdProcess = true;
				//验证MSC 制程 工序
				b = new SqlBuilder("CoreOrderReviewTechnology.queryPlnSaleOrdProc");
				b.Fill(new String[]{rsPlnOrdProcess.getString("ORD_LN_DLY_PK")});
				Statement psPlnSaleOrdProc = con.createStatement();
				ResultSet rsPlnSaleOrdProc = psPlnSaleOrdProc.executeQuery(b.toString());
				while(rsPlnSaleOrdProc.next()){
					if(!rsPlnSaleOrdProc.getString("MSC").equals(newCraftMsc.getValue())){
						cro.setResult("新工艺文件的MSC与计划使用的MSC不一致！");
						return cro;
					}
					
					boolean backlogExist = false;
					boolean processExists = false;
					for(GenericEntity newCraftBacklog : newCraftBacklogs){
						if(newCraftBacklog.getValue().equals(rsPlnSaleOrdProc.getString("INDEX_SEQ"))){
							backlogExist = true;
							if(newCraftBacklog.getValue2().equals(rsPlnSaleOrdProc.getString("PROCESS_SEQ"))){
								processExists = true;
							}
						}
					}
					if(!backlogExist){
						cro.setResult("新工艺文件的制程不包含（"+ rsPlnSaleOrdProc.getString("INDEX_SEQ") +"）！");
						return cro;
					}
					if(!processExists){
						cro.setResult("新工艺文件的制程"+ rsPlnSaleOrdProc.getString("INDEX_SEQ") +"包含的工序"
								+ "与计划使用的制程"+ rsPlnSaleOrdProc.getString("INDEX_SEQ") +"包含的工序不一致！");
						return cro;
					}
				}
				rsPlnSaleOrdProc.close();
				psPlnSaleOrdProc.close();
						

				// 验证接箍和接箍备料
				b = new SqlBuilder("CoreOrderReviewTechnology.queryPlnOrdJg");
				b.Fill(new String[]{rsPlnOrdProcess.getString("ORD_LN_DLY_PK")});
				Statement psPlnOrdJg = con.createStatement();
				ResultSet rsPlnOrdJg = psPlnOrdJg.executeQuery(b.toString());
				while(rsPlnOrdJg.next()){
					if(!newCraftJg.getValue().equals(rsPlnOrdJg.getString("CODE_JG"))){
						cro.setResult("新工艺文件不包含接箍码"+ rsPlnOrdJg.getString("CODE_JG") +"！");
						return cro;
					}
					b = new SqlBuilder("CoreOrderReviewTechnology.queryPlnOrdJgBL");
					String proPlanId = rsPlnOrdJg.getString("PRO_PLAN_ID") == null ? "" : rsPlnOrdJg.getString("PRO_PLAN_ID");
					b.Fill(new String[]{proPlanId});
					Statement psPlnOrdJgBl = con.createStatement();
					ResultSet rsPlnOrdJgBl = psPlnOrdJgBl.executeQuery(b.toString());
					while(rsPlnOrdJgBl.next()){
						boolean jgBlExist = false;
						for(GenericEntity newCraftJgBl : newCraftJgBls){
							if(newCraftJgBl.getValue().equals(rsPlnOrdJgBl.getString("CODE_JG_BL"))){
								jgBlExist = true;
							}
						}
						if(!jgBlExist){
							cro.setResult("新工艺文件不包含接箍料"+ rsPlnOrdJgBl.getString("CODE_JG_BL") +"！");
							return cro;
						}
					}
					rsPlnOrdJgBl.close();
					psPlnOrdJgBl.close();
				}
				rsPlnOrdJg.close();
				psPlnOrdJg.close();
				
				//验证备料
				b = new SqlBuilder("CoreOrderReviewTechnology.queryPlnBl");
				b.Fill(new String[]{rsPlnOrdProcess.getString("ORD_LN_DLY_PK")});
				Statement psPlnOrdBl = con.createStatement();
				ResultSet rsPlnOrdBl = psPlnOrdBl.executeQuery(b.toString());
				while(rsPlnOrdBl.next()){
					boolean blExist = false;
					for(GenericEntity newCraftBl : newCraftBls){
						if(newCraftBl.getValue().equals(rsPlnOrdBl.getString("CODE_DJ_BL"))){
							blExist = true;
							break;
						}
					}
					if(!blExist){
						cro.setResult("新工艺文件不包含管体料"+ rsPlnOrdBl.getString("CODE_DJ_BL") +"！");
						return cro;
					}
				}
				rsPlnOrdBl.close();
				psPlnOrdBl.close(); 
				
				//验证BOM 产线
				boolean bomExist = false;
				for(GenericEntity newCraftBom : newCraftBoms){
					if(newCraftBom.getValue().equals(rsPlnOrdProcess.getString("BOM"))){
						bomExist = true;
					}
				}
				if(!bomExist){
					cro.setResult("新工艺文件的Bom与计划使用的Bom不一致！\r\n计划使用Bom("+ rsPlnOrdProcess.getString("BOM") +")");
					return cro;
				}
				
				boolean plineExist = false;
				for(GenericEntity newCraftPline : newCraftPlines){
					if(newCraftPline.getValue().equals(rsPlnOrdProcess.getString("PLINE_CODE"))){
						plineExist = true;
					}
				}
				if(rsPlnOrdProcess.getString("PROCESS_CODE").equals("D") && !plineExist){
					cro.setResult("新工艺文件中不包含产线"+ rsPlnOrdProcess.getString("PLINE_NAME") +"");
					return cro;
				}
				
				//更新计划排产工艺文件
				Statement psPlnOrdProcess = con.createStatement();
				b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnOrdZg");
				b.Fill(new String[]{newCraft.getCraftNo(), newCraft.getDeleteName(), newCraft.getCraftSeq(),
						newCraft.getCraftNoV(), rsPlnOrdProcess.getString("PRO_PLAN_ID")});
				psPlnOrdProcess.executeUpdate(b.toString());
				b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnOrdDbk");
				b.Fill(new String[]{newCraft.getCraftNo(), newCraft.getDeleteName(), newCraft.getCraftSeq(),
						rsPlnOrdProcess.getString("PRO_PLAN_ID")});
				psPlnOrdProcess.executeUpdate(b.toString());
				b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnOrdRcl");
				b.Fill(new String[]{newCraft.getCraftNo(), newCraft.getDeleteName(), newCraft.getCraftSeq(),
						rsPlnOrdProcess.getString("PRO_PLAN_ID")});
				psPlnOrdProcess.executeUpdate(b.toString());
				b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnOrdJgx");
				b.Fill(new String[]{newCraft.getCraftNo(), newCraft.getDeleteName(), newCraft.getCraftSeq(),
						rsPlnOrdProcess.getString("PRO_PLAN_ID")});
				psPlnOrdProcess.executeUpdate(b.toString());
				
				//获取内控索引号
				//修改炼钢（轧管表中的炼钢索引码集合）
				
				if(lgNkIdxEntity != null){
					//去重复
					lgNkIdxEntity.setCic(rmRepate(lgNkIdxEntity.getCic()));
					lgNkIdxEntity.setPic(rmRepate(lgNkIdxEntity.getPic()));
					lgNkIdxEntity.setSic(rmRepate(lgNkIdxEntity.getSic()));
					lgNkIdxEntity.setDic(rmRepate(lgNkIdxEntity.getDic()));
					lgNkIdxEntity.setWic(rmRepate(lgNkIdxEntity.getWic()));
					lgNkIdxEntity.setGic(rmRepate(lgNkIdxEntity.getGic()));
					
					b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnOrdZgS2");
					b.Fill(new String[]{newCraft.getCraftNo(), newCraft.getDeleteName(), newCraft.getCraftSeq(),
							rsPlnOrdProcess.getString("PRO_PLAN_ID"), rsPlnOrdProcess.getString("GX_PLAN_NO"),
							lgNkIdxEntity.getCic(), lgNkIdxEntity.getPic(), lgNkIdxEntity.getSic(),
							lgNkIdxEntity.getDic(), lgNkIdxEntity.getWic(), lgNkIdxEntity.getGic()});
					psPlnOrdProcess.executeUpdate(b.toString());
				}
				
				//修改轧管
				b = new SqlBuilder("CoreOrderReviewTechnology.queryZgNkLkGrade");
				b.Fill(new String[]{ newCraft.getDesginKey(), rsPlnOrdProcess.getString("PRO_PLAN_ID"),
						rsPlnOrdProcess.getString("GX_PLAN_NO") });
				GenericEntity zgNkLkGrade = EntityTool.getEntityBySqlNoClsCon(
						b.toString(), con, GenericEntity.class);
				
				if(zgNkIdxEntity != null){
					b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnOrdZgS");
					b.Fill(new String[]{newCraft.getCraftNo(), newCraft.getDeleteName(), newCraft.getCraftSeq(),
							rsPlnOrdProcess.getString("PRO_PLAN_ID"), rsPlnOrdProcess.getString("GX_PLAN_NO"),
							zgNkIdxEntity.getCic(), zgNkIdxEntity.getPic(), zgNkIdxEntity.getSic(),
							zgNkIdxEntity.getDic(), zgNkIdxEntity.getWic(), zgNkIdxEntity.getGic(),
							zgNkLkGrade.getValue(), zgNkLkGrade.getValue2(), zgNkLkGrade.getValue3() });
					psPlnOrdProcess.executeUpdate(b.toString());
				}
				
				if(dbkNkIdxEntity != null){
					b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnOrdDbkS");
					b.Fill(new String[]{newCraft.getCraftNo(), newCraft.getDeleteName(), newCraft.getCraftSeq(),
							rsPlnOrdProcess.getString("PRO_PLAN_ID"), rsPlnOrdProcess.getString("GX_PLAN_NO"),
							dbkNkIdxEntity.getCic(), dbkNkIdxEntity.getPic(), dbkNkIdxEntity.getSic(),
							dbkNkIdxEntity.getDic(), dbkNkIdxEntity.getWic(), dbkNkIdxEntity.getGic()});
					psPlnOrdProcess.executeUpdate(b.toString());
				}
				
				if(rclNkIdxEntity != null){
					b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnOrdRclS");
					b.Fill(new String[]{newCraft.getCraftNo(), newCraft.getDeleteName(), newCraft.getCraftSeq(),
							rsPlnOrdProcess.getString("PRO_PLAN_ID"), rsPlnOrdProcess.getString("GX_PLAN_NO"),
							rclNkIdxEntity.getCic(), rclNkIdxEntity.getPic(), rclNkIdxEntity.getSic(),
							rclNkIdxEntity.getDic(), rclNkIdxEntity.getWic(), rclNkIdxEntity.getGic()});
					psPlnOrdProcess.executeUpdate(b.toString());
				}
				
				if(jgxNkIdxEntity != null){
					b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnOrdJgxS");
					b.Fill(new String[]{newCraft.getCraftNo(), newCraft.getDeleteName(), newCraft.getCraftSeq(),
							rsPlnOrdProcess.getString("PRO_PLAN_ID"), rsPlnOrdProcess.getString("GX_PLAN_NO"),
							jgxNkIdxEntity.getCic(), jgxNkIdxEntity.getPic(), jgxNkIdxEntity.getSic(),
							jgxNkIdxEntity.getDic(), jgxNkIdxEntity.getWic(), jgxNkIdxEntity.getGic()});
					psPlnOrdProcess.executeUpdate(b.toString());
				}
				
				b = new SqlBuilder("CoreOrderReviewTechnology.updatePlnOrdProc");
				b.Fill(new String[]{newCraft.getCraftNo(), newCraft.getDeleteName(), newCraft.getCraftSeq(),
						rsPlnOrdProcess.getString("ORD_LN_DLY_PK")});
				psPlnOrdProcess.executeUpdate(b.toString());
				psPlnOrdProcess.close();
				
			}
			rsPlnOrdProcess.close();
			ps.close();
			
			//更新排产制程分解表
			if(existPlnOrdProcess && cro.getResult() == null){
				Statement st = con.createStatement();
				String grades = "";
				for(GenericEntity grade : newCraftAllGrades){
					if(grades.equals("")){
						grades = grade.getValue();
					}else{
						grades += "," + grade.getValue();
					}
				}
				for(GenericEntity plnSaleProc: plnSaleProcs){
					b = new SqlBuilder("CoreOrderReviewTechnology.UpdatePlnProcGrade");
					b.Fill(new String[]{ grades,  plnSaleProc.getValue(), plnSaleProc.getValue2()});
					st.executeUpdate(b.toString());
				}
				st.close();
			}
			
			//修改最大工艺文件的状态
			b = new SqlBuilder("CoreOrderReviewTechnology.UpdateCraftValidflag");
			b.Fill(new String[]{ ordLnPk, "1" });
			Statement psCraftOrdDesign = con.createStatement();
			psCraftOrdDesign.executeUpdate(b.toString());
			psCraftOrdDesign.close();
			
		} catch (Exception e) {
			e.printStackTrace();
			cro.setResult(e.getMessage());
			try {
				con.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			return cro;
		}finally{
			try {
				if(ps != null){
					ps.close();
				}
				if(cro.getResult() != null){
					con.rollback();
				}else{
					con.commit();
				}
				
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			finally{
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return cro;
	}
	
	private String rmRepate(String str){
		if(str.equals("")) return str;
		String[] strAry = str.split(",");
		String newStr = "";
		for(String str2 : strAry){
			if(!newStr.contains(str2)){
				if(newStr.equals("")){
					newStr = str2;
				}else{
					newStr += "," + str2;
				}
			}
		}
		
		return newStr;
	}
	
	/**
	 * 是否存在需要变更的排产数据
	 * @param ordLnPk
	 * @return
	 */
	public CoreReturnObject IsExistCraftChange(String ordLnPk){
		SqlBuilder b;
		if(ordLnPk.length() > 30){
			b = new SqlBuilder("CoreOrderReviewTechnology.queryPlnOrdProcessS");
		}else{
			b = new SqlBuilder("CoreOrderReviewTechnology.queryPlnOrdProcessSBl");
		}
		b.Fill(new String[]{ordLnPk});
		return this.getData(b.toString());
	}
	
	/**
	 * 查询上一版本二级工艺文件
	 * @param ordLnPk
	 * @return
	 */
	public CoreReturnObject QueryPreCraftLv2(String ordLnPk){
		SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.QueryPreCraftLv2");
		b.Fill(new String[]{ordLnPk});
		return this.getData(b.toString());
	}
	
	/**
	 * 修改二级工艺文件
	 * @param parms
	 * @return
	 */
	public CoreReturnObject UpdateCraftLv2(ArrayList<String[]> parms){
		ArrayList<String> sqllist = new ArrayList<String>();
		for(String[] parm : parms){
			SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.updateCraftLv2");
			b.Fill(parm);
			sqllist.add(b.toString());
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	}
	
	/**
	 * 修改工艺变更备注
	 * @param ordLnPk
	 * @param craftSeq
	 * @param craftChangeMemo
	 * @return
	 */
	public CoreReturnObject UpdateCraftChangeMemo(String ordLnPk, String craftSeq, String craftChangeMemo){
		SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.UpdateCraftChangeMemo");
		b.Fill(new String[]{ ordLnPk, craftSeq, craftChangeMemo });
		return this.setData(b.toString());
	}
	
	/**
	 * 通过科室查询技术评审
	 * @return
	 */
	public CoreReturnObject QueryTechnologyByUnit(String department, String unit, String user){
		SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.QueryTechnologyByUnit");
		b.Fill(new String[]{ department, unit, user });
		return this.getData(b.toString());
	}
	
	/**
	 * 通过备料查询接收状态的合同行
	 * @param blCode
	 * @return
	 */
	public CoreReturnObject
    GetOrderLineCntByBl(String blCode){
		SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.GetOrderLineCntByBl");
		b.Fill(new String[]{ blCode });
		return this.getData(b.toString());
	}
	
	/**
	 * 获取质量设计水压标准
	 * @param designKey
	 * @return
	 */
	public CoreReturnObject GetSlmDesignWater(String designKey){
		SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.GetSlmDesignWater");
		b.Fill(new String[]{ designKey });
		return this.getData(b.toString());
	}
	
	/**
	 * 获取工艺评审水压标准
	 * @param designKey
	 * @return
	 */
	public CoreReturnObject GetCraftDesignWater(String designKey){
		SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.GetCraftDesignWater");
		b.Fill(new String[]{ designKey });
		return this.getData(b.toString());
	}

    /**
     * 获取工艺评审加工标准
     * @param designKey
     * @return
     */
    public CoreReturnObject GetCraftDesignProcess(String designKey){
        SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.GetCraftDesignProcess");
        b.Fill(new String[]{ designKey });
        return this.getData(b.toString());
    }
	
	public CoreReturnObject setPicFdCheck(String ordLnPk, String craftSeq, String fdCheck){
		fdCheck = fdCheck.equals("True") ? "1" : "0";
		SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.setPicFdCheck");
		b.Fill(new String[]{ ordLnPk, craftSeq, fdCheck });
		
		return this.setData(b.toString());
	}
	
	public CoreReturnObject setWicFdCheck(String ordLnPk, String craftSeq, String fdCheck){
		fdCheck = fdCheck.equals("True") ? "1" : "0";
		SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.setWicFdCheck");
		b.Fill(new String[]{ ordLnPk, craftSeq, fdCheck });
		
		return this.setData(b.toString());
	}
	
	public CoreReturnObject setCicFdCheck(String ordLnPk, String craftSeq, String fdCheck){
		fdCheck = fdCheck.equals("True") ? "1" : "0";
		SqlBuilder b = new SqlBuilder("CoreOrderReviewTechnology.setCicFdCheck");
		b.Fill(new String[]{ ordLnPk, craftSeq, fdCheck });
		
		return this.setData(b.toString());
	}
}