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

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.StringTool;
import com.steering.comm.tools.TransctionTool;
import com.steering.pss.qcm.model.GenericEntity;
import com.steering.pss.sale.order.CoreOrderStatusCommFun;
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.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CoreOrderReviewTechnologyList 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(
                "CoreOrderReviewTechnologyList.UpdateOrderLineMsc", params);
    }

    public CoreReturnObject UpdateOrderLineWbs(String wbs,String pOrdLnPk) {
        Object[] params = new Object[] {wbs, pOrdLnPk };
        return this.setDataBySqlID(
                "CoreOrderReviewTechnologyList.UpdateOrderLineWbs", params);
    }

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

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

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

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

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

        String updateOrderLineSql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.isDesignV",
                obj);
    }

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

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

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

    public CoreReturnObject doQuery(ArrayList<String> list) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.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));
        CoreReturnObject cro;
        cro = this.getData(sql);
        return cro;
    }

    public CoreReturnObject doQueryCraft(ArrayList<String> list) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.doQueryCraft");
        
        String[] manageOrderNos = list.get(0).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, "#UNIT_CODE#", list.get(1));
        // sql = StringTool.ReplaceAll(sql, "#USER_ID#", list.get(2));
        // sql = StringTool.ReplaceAll(sql, "#USER_NAME#", list.get(3));
        sql = StringTool.ReplaceAll(sql, "#BEGIN_TIME#", list.get(1));
        sql = StringTool.ReplaceAll(sql, "#END_TIME#", list.get(2));
        sql = StringTool.ReplaceAll(sql, "#HIS#", list.get(3));
        sql = StringTool.ReplaceAll(sql, "#PLAN_STATUS#", list.get(4));
        sql = StringTool.ReplaceAll(sql, "#IS_BL#", list.get(5));
        sql = StringTool.ReplaceAll(sql, "#USER_DESC#", list.get(6));
        CoreReturnObject cro;
        cro = this.getData(sql);
        return cro;
    }

    public CoreReturnObject doQueryCraft1(ArrayList<String> list) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.doQueryCraft1");

        String[] manageOrderNos = list.get(0).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, "#UNIT_CODE#", list.get(1));
        // sql = StringTool.ReplaceAll(sql, "#USER_ID#", list.get(2));
        // sql = StringTool.ReplaceAll(sql, "#USER_NAME#", list.get(3));
        sql = StringTool.ReplaceAll(sql, "#BEGIN_TIME#", list.get(1));
        sql = StringTool.ReplaceAll(sql, "#END_TIME#", list.get(2));
        sql = StringTool.ReplaceAll(sql, "#HIS#", list.get(3));
        sql = StringTool.ReplaceAll(sql, "#PLAN_STATUS#", list.get(4));
        sql = StringTool.ReplaceAll(sql, "#IS_BL#", list.get(5));
        sql = StringTool.ReplaceAll(sql, "#USER_DESC#", list.get(6));
        sql = StringTool.ReplaceAll(sql, "#MSC#", list.get(7));
        CoreReturnObject cro;
        cro = this.getData(sql);
        return cro;
    }

    /**
     * 获取合同行从表交货信息
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetOrderLineDelivery(ArrayList<String> list) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.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(
                "CoreOrderReviewTechnologyList.GetOrdDesign", obj);
    }

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

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

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

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

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

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

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

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

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

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

    /**
     * 依据全程途径获取工序投入产出物料
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject GetCraftDesignMscPlIn(String designKey,
            String mscPline) {
        Object[] obj = new Object[] { designKey, mscPline };
        return this.getDataBySqlID(
                "CoreOrderReviewTechnologyList.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(
                "CoreOrderReviewTechnologyList.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(
                "CoreOrderReviewTechnologyList.GetCraftDesignMscPlGxPrl", obj);
    }

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

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

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

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

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

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

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

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

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

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

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

    /**
     * 获取Mps信息
     * @param ordlnPk 合同行主键
     * @return obj
     */
    public CoreReturnObject getMpsInfo(String ordlnPk) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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;
        // 判断合同行是否能够质量评审,如果有一条不能质量评审,则全部退回
        for (int i = 0; i < paramList.size(); i++) {
            String[] param = paramList.get(i);
            sql = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnologyList.getOrdLineSatus");
            ps = con.prepareStatement(sql);
            ps.setObject(1, param[1]);
            rs = ps.executeQuery();
            String lineStatus = "";
            if (rs.next()) {
                lineStatus = rs.getString("ORDER_LN_STATUS");
            }
            if (!lineStatus.equals("12020201")) {
                core.setV_errMsg("当前合同行技术评审完毕,不允许再次执行技术评审");
                return core;
            }
            if (flag.equals("1")) {
                sql = CoreXmlSqlParsersFactory
                        .getSql("CoreOrderReviewTechnologyList.getOrdLineDesignSatus");
                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.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);
            // 查询评审单号
            sql = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.updateItemList");
            ps = con.prepareStatement(sql);
            if (flag.equals("1")) {
                ps.setObject(1, "S");
            }
            else {
                ps.setObject(1, "F");
            }
            ps.setObject(2, reason);
            ps.setObject(3, userDept);
            ps.setObject(4, userName);
            ps.setObject(5, reviewNo);
            ps.setObject(6, "T");
            ps.setObject(7, 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);
            }
            // 修改合同行状态
            sql = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnologyList.updateOldLineStatus");
            ps = con.prepareStatement(sql);
            if (flag.equals("1")) {
                ps.setObject(1, "12020202");
            }
            else {
                ps.setObject(1, "12020203");
            }
            ps.setObject(2, param[1]);
            ps.executeUpdate();
            // 修改合同行下所有交货行的状态
            sql = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnologyList.updateOldDelivryStatus");
            ps = con.prepareStatement(sql);
            if (flag.equals("1")) {
                ps.setObject(1, "12020202");
            }
            else {
                ps.setObject(1, "12020203");
            }
            ps.setObject(2, param[1]);
            ps.executeUpdate();

            // 修改合同头状态
            /*
             * for (int i = 0; i < paramList.size(); i++) { String[] param =
             * paramList.get(i); // 查询评审单号 sql = CoreXmlSqlParsersFactory
             * .getSql("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.getLinesStatus");
            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 (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");
                    }
                    // con.commit();
                    return core;
                }
                // 修改合同头状态
                sql = CoreXmlSqlParsersFactory
                        .getSql("CoreOrderReviewTechnologyList.updateHeadStatus");
                ps = con.prepareStatement(sql);
                if (flag.equals("1")) {
                    if (lineStatuses.contains("12020203")) {
                        if (chgeOrdLnPk.equals("")) {
                            ps.setObject(1, "12020203");
                            ps.setObject(2, "技术评审失败");
                            ps.setObject(3, param[0]);
                            ps.executeUpdate();
                        }
                    }
                    else if (lineStatuses.contains("12020201")) {
                        if (chgeOrdLnPk.equals("")) {
                            ps.setObject(1, "12020201");
                            ps.setObject(2, "技术评审中");
                            ps.setObject(3, param[0]);
                            ps.executeUpdate();
                        }
                    }
                    else if (lineStatuses.size() == 1
                            && lineStatuses.contains("12020202")) {
                        if (chgeOrdLnPk.equals("")) {
                            ps.setObject(1, "12020202");
                            ps.setObject(2, "技术评审通过");
                            ps.setObject(3, param[0]);
                            ps.executeUpdate();
                        }
                        // 修改评审项目技术评审的状态
                        sql = CoreXmlSqlParsersFactory
                                .getSql("CoreOrderReviewTechnologyList.updateItemStatus");
                        ps = con.prepareStatement(sql);
                        ps.setObject(1, "S");
                        ps.setObject(2, reviewNo);
                        ps.executeUpdate();
                    }
                    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("CoreOrderReviewTechnologyList.updateItemStatus");
                        ps = con.prepareStatement(sql);
                        ps.setObject(1, "F");
                        ps.setObject(2, reviewNo);
                        ps.executeUpdate();
                        ps.close();
                    }
                    else {
                        core.setV_errMsg("合同行异常!");
                        return core;
                    }
                }
            }

            // 清除回退
            String sqlFallBack = CoreXmlSqlParsersFactory
                    .getSql("QualityDesignFallback.deleteFallBack");
            PreparedStatement psFallBack = con.prepareStatement(sqlFallBack);
            psFallBack.setString(1, param[1]);
            psFallBack.executeUpdate();
        }
        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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.clearCraftOrdDesign");
        sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
        PreparedStatement ps = con.prepareStatement(sql);
        int cnt = ps.executeUpdate();
        ps.close();
        return cnt;
    }

    /**
     * 复制质量设计结果到工艺设计表中
     * @param designKey
     * @return
     */
    public CoreReturnObject copyOrdToCraft(String ordLnPk, String qualityFlag,
            String userName) {
        TransctionTool transction = new TransctionTool();
        Connection con = transction.getCon();
        CoreReturnObject cro;
        try{
            String sqlGuid = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnologyList.getGuid");
            ArrayList<GenericEntity> guidList = EntityTool
                    .getEntitysBySqlNoClsCon(sqlGuid, con, GenericEntity.class);
            String sql = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnologyList.copyOrdToCraft");
            sql = StringTool.ReplaceAll(sql, "#ORD_LN_PK#", ordLnPk);
            sql = StringTool.ReplaceAll(sql, "#CREATE_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("CoreOrderReviewTechnologyList.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){
        	cro = transction.rollBack();
			cro.setV_errMsg(ex.getMessage());
			return cro;
        }
    }

    /**
     * 获取工艺质量设计状态
     * @param ordLnPk
     * @return
     */
    public CoreReturnObject getCraftDesignSts(String ordLnPk) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.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, Connection con) throws SQLException {
        CraftOrdDesignEntity craftOrdDesign = new CraftOrdDesignEntity();
        craftOrdDesign.setOrdLnPk(ordLnPk);
        craftOrdDesign.setDesginKey(designKey);
        craftOrdDesign.setCreateName(userName);
        craftOrdDesign.setUpdateName(userName);
        craftOrdDesign.setLockFlag("1");
        String sqlGetMaxSeq = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.getCraftOrdDesign");
        sqlGetCraftCnt = EntityTool.fillSqlByEntity(sqlGetCraftCnt,
                craftOrdDesign);
        ArrayList<CraftOrdDesignEntity> listCraftCnt = EntityTool
                .getEntitysBySqlNoClsCon(sqlGetCraftCnt, con,
                        CraftOrdDesignEntity.class);
        String sql = "";
        if (listCraftCnt.size() == 0) {
            sql = CoreXmlSqlParsersFactory
                    .getSql("CoreOrderReviewTechnologyList.insertCraftOrdDesign");
        }
        else {
            if (listCraftCnt.get(0).getValidflag().equals("1")) {
                sql = CoreXmlSqlParsersFactory
                        .getSql("CoreOrderReviewTechnologyList.insertCraftOrdDesign");
            }
            else {
                sql = CoreXmlSqlParsersFactory
                        .getSql("CoreOrderReviewTechnologyList.updateCraftOrdDesign");
                craftOrdDesign.setCraftSeq(listCraftCnt.get(0).getCraftSeq());
                craftOrdDesign.setValidflag("2");
            }
        }
        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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.getDesignPlCraftNo");
        sqlGetDesignPlCraftNo = StringTool.ReplaceAll(sqlGetDesignPlCraftNo,
                "#DESGIN_KEY#", designKey);
        return this.getData(sqlGetDesignPlCraftNo);
    }

    /**
     * 获取管理部门科室
     * @return
     */
    public CoreReturnObject getDepartment() {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.getDepartment");
        return this.getData(sql);
    }

    /**
     * 获取对应科室的成员
     * @return
     */
    public CoreReturnObject getUser(String unitCode) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.insertCraftDesignAppoint");
                }
                else {
                    sql = CoreXmlSqlParsersFactory
                            .getSql("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.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("CoreOrderReviewTechnologyList.getOrdSeqByOrdPk");
        sql = StringTool.ReplaceAll(sql, "#ORD_PK#", ordPk);
        return this.getData(sql);
    }

    /**
     * 获取工艺文件
     * @return
     */
    public CoreReturnObject getCraftOrdDesignFile() {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.getCraftOrdDesignFile");
        return this.getData(sql);
    }

    /**
     * 保存工艺文件
     * @return
     */
    public CoreReturnObject saveCraftNoBatch(ArrayList<String> list,
            String craftNo, String craftPath, String craftNoV, String memo) {
        ArrayList<String> sqllist = new ArrayList<String>();
        String ordLnPks = "'1'";
        for (String ordLnPk : list) {
            ordLnPks += ", '" + ordLnPk + "'";
        }
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.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 = 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("CoreOrderReviewTechnologyList.getCrafFileByCraftNo");
        sql = StringTool.ReplaceAll(sql, "#CRAFT_NO#", craftNo);
        sql = StringTool.ReplaceAll(sql, "#CRAFT_NO_V#", craftV);
        return this.getData(sql);
    }

    /**
     * 修改工艺文件备注
     * @return
     */
    public CoreReturnObject setCraftFileMemo(String craftNo, String craftV,
            String memo) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderReviewTechnologyList.setCraftFileMemo");
        sql = StringTool.ReplaceAll(sql, "#CRAFT_NO#", craftNo);
        sql = StringTool.ReplaceAll(sql, "#CRAFT_NO_V#", craftV);
        sql = StringTool.ReplaceAll(sql, "#MEMO#", memo);
        return this.setData(sql);
    }
}