# 项目复杂度理解

#### 链路复杂度

前端：

<img title="" src="项目复杂度理解资源/ScreenShot_2026-02-25_151229_884.png" alt="ScreenShot_2026-02-25_151229_884.png" width="877">

前端设计页面

![ScreenShot_2026-02-25_152027_078.png](项目复杂度理解资源/ScreenShot_2026-02-25_152027_078.png)

前端代码

```csharp
        protected override void DoAdd()
        {
            if (ActiveRow != null)
            {
                if (MessageUtil.ShowYesNoAndQuestion("是否上料?") == DialogResult.No)
                    return;
                var ccp = new CoreClientParam();
                ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMcpLoading";
                ccp.MethodName = "DoAdd";
                ccp.ServerParams = new object[]
                {
                    ActiveRow.HeatPlanNo,
                    ActiveRow.HeatPlanSqe,
                    JSONFormat.Format(Value), Gx,
                    mchControlBase1.ScrappedList.Select(JSONFormat.Format).ToList(),
                    mchControlBase1.SuspiciousList.Select(JSONFormat.Format).ToList()
                };
                ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
                if (ccp.ReturnCode != -1)
                {
                    MessageUtil.ShowTips(ccp.ReturnInfo);
                    if (ccp.ReturnInfo.Equals("上料成功！"))
                    {
                        Query();
                        doOver();
                    }
                 }
             }
        }
```

> 可以看到
> 
> 1、前后端的参数是魔法约定。
> 
> 2、前端的主要工作是拼装sql。

我们再来看一条复杂一点的前端代码

```csharp
       private void QueryData()
        {
            List<MatGpMEntity> listSource = null;

            if (chkStoveNo.Checked && string.IsNullOrEmpty(this.txtStoveNo.Text))
            {
                MessageUtil.ShowTips("请输入熔炼炉号!");
                this.txtStoveNo.Focus();
                return;
            }
            if (chkJudgeNo.Checked && string.IsNullOrEmpty(this.txtJudgeNo.Text))
            {
                MessageUtil.ShowTips("请输入判定炉号!");
                this.txtJudgeNo.Focus();
                return;
            }

            string stoveNo = "";
            string judgeNo = "";
            string orderNo = "";
            string grade = "";
            string dimter = "";
            string sourceName = "";
            ArrayList list = new ArrayList();
            string strSql = "";
            string strGroup = "";
            string strOut = "";


            if (chkStoveNo.Checked)
            {
                stoveNo = this.txtStoveNo.Text.Trim();
                strOut += " AND T1.STOVE_NO = '" + stoveNo + "'";
            }
            if(chkJudgeNo.Checked)
            {
                judgeNo = this.txtJudgeNo.Text.Trim();
                strOut += " AND T1.JUDGE_STOVE_NO = '" + judgeNo + "'";
            }
            if (chkOrder.Checked)
            {
                orderNo = this.txtOrder.Text.Trim();
                strOut += " AND S1.ORDER_NO||'/'||S1.ORDER_SEQ LIKE '%" + orderNo + "'";
            }
            if(chkSource.Checked)
            {
                sourceName = this.txtSource.Text.Trim();
                strOut += " AND T1.SOURE_NAME LIKE '%" + sourceName + "'";
            }
            if(chkDimter.Checked)
            {
                dimter = this.txtDimter.Text.Trim();
                strOut += " AND T1.DIMATER LIKE '%" + dimter + "'";
            }
            if(chkGrade.Checked)
            {
                grade = this.txtGrade.Text.Trim();
                strOut += " AND T1.GRADENAME LIKE '%" + grade + "'";
            }
            string strKey = "";
            CheckBox item;
            for (int i = 0; i < this.myCheckedListBox1.Controls.Count; i++)
            {
                try
                {
                    item = this.myCheckedListBox1.Controls[i] as CheckBox;

                    if (item != null && item.Checked)
                    {
                        strKey = item.Name;
                        if (strKey.Equals("StoveNo"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.STOVE_NO";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.STOVE_NO";
                        }
                        else if (strKey.Equals("PlanMemo"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "MAX(T1.PLAN_MEMO) PLAN_MEMO";
                           // strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "MAX(T1.PLAN_MEMO) PLAN_MEMO";
                        }
                        else if (strKey.Equals("JudgeStoveNoLg"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.JUDGE_STOVE_NO_LG";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.JUDGE_STOVE_NO_LG";
                        }
                        else if (strKey.Equals("JudgeStoveNo"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.JUDGE_STOVE_NO";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.JUDGE_STOVE_NO";
                        }
                        else if (strKey.Equals("MaterialName"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.MATERIAL_NAME";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.MATERIAL_NAME";
                        }
                        else if (strKey.Equals("Gradename"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.GRADENAME";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.GRADENAME";
                        }
                        else if (strKey.Equals("StdName"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.STD_NAME";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.STD_NAME";
                        }
                        else if (strKey.Equals("Dimater"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.DIMATER";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.DIMATER";
                        }                       
                        else if (strKey.Equals("FixNum"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.FIX_NUM";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.FIX_NUM";
                        }
                        else if (strKey.Equals("FixLen"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.FIX_LEN";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.FIX_LEN";
                        }
                        else if (strKey.Equals("ActLen"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.ACT_LEN";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.ACT_LEN";
                        }
                        else if (strKey.Equals("CutNum1"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "ROUND(T1.ACT_LEN/2,1)CUT_NUM1";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "ROUND(T1.ACT_LEN/2,1)";
                        }
                        else if (strKey.Equals("CutNum2"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "ROUND(T1.ACT_LEN/3,1)CUT_NUM2";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "ROUND(T1.ACT_LEN/3,1)";
                        }
                        else if (strKey.Equals("CutNum3"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "ROUND(T1.ACT_LEN/4,1)CUT_NUM3";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "ROUND(T1.ACT_LEN/4,1)";
                        }
                        else if (strKey.Equals("CutNum4"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "ROUND(T1.ACT_LEN/5,1)CUT_NUM4";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "ROUND(T1.ACT_LEN/5,1)";
                        }
                        else if (strKey.Equals("BelongName"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.BELONG_NAME";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.BELONG_NAME";
                        }
                        else if (strKey.Equals("JudgeResultCode"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "(SELECT T2.BASENAME FROM COM_BASE_INFO T2 WHERE T2.BASECODE = T1.JUDGE_RESULT_CODE )JUDGE_RESULT_CODE";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.JUDGE_RESULT_CODE";
                        }
                        else if (strKey.Equals("InstockTime"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "MAX(TO_CHAR(T1.INSTOCK_TIME,'YYYY-MM-DD HH24:MI:SS'))INSTOCK_TIME";
                            //strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.JUDGE_RESULT_CODE";
                        }
                        else if (strKey.Equals("ProductFlag"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.PRODUCT_FLAG";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.PRODUCT_FLAG";
                        }
                        else if (strKey.Equals("MatStatus"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.MAT_STATUS";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.MAT_STATUS";
                        }
                        else if (strKey.Equals("PlineName"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.PLINE_NAME";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.PLINE_NAME";
                        }
                        else if (strKey.Equals("QcmStaus"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "DECODE(T1.QCM_STAUS,'00','合格','11','待处理','22','废品')QCM_STAUS";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.QCM_STAUS";
                        }
                        else if (strKey.Equals("StorageName"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "(SELECT T3.STORAGE_NAME FROM YDM_BS_STORAGE T3 WHERE T3.STORAGE_NO = T2.STORAGE_NO)STORAGE_NAME";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T2.STORAGE_NO";
                        }
                        else if (strKey.Equals("LocationName"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T2.LOCATION_NAME";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T2.LOCATION_NAME";
                        }
                        else if (strKey.Equals("LaryNo"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T2.LARY_NO";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T2.LARY_NO";
                        }
                        else if (strKey.Equals("OrderNo"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "S1.ORDER_NO||'/'||S1.ORDER_SEQ AS ORDER_NO";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "S1.ORDER_NO,S1.ORDER_SEQ";
                        }
                        //else if (strKey.Equals("QcmMemo"))
                        //{
                        //    strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "MAX((SELECT T.MEMO FROM QCM_GP_JUDGE_APPLY T WHERE T.JUGDE_APPLY_CODE || T.JUGDE_APPLY_SQE = T1.JUGDE_APPLY_CODE GROUP BY T.JUGDE_APPLY_CODE,T.JUGDE_APPLY_SQE,T.MEMO))QCM_MEMO";
                        //    //strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "S1.ORDER_NO,S1.ORDER_SEQ";
                        //}
                        //else if (strKey.Equals("JudgeMemo"))
                        //{
                        //    strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "MAX((SELECT T.JUDGE_MEMO FROM QCM_GP_JUDGE_APPLY T WHERE T.JUGDE_APPLY_CODE || T.JUGDE_APPLY_SQE = T1.JUGDE_APPLY_CODE GROUP BY T.JUGDE_APPLY_CODE,T.JUGDE_APPLY_SQE,T.JUDGE_MEMO))JUDGE_MEMO";
                        //    //strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "S1.ORDER_NO,S1.ORDER_SEQ";
                        //}
                        else if (strKey.Equals("PlineNameNext"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "MAX((SELECT S1.PLINE_NAME FROM PLN_ORDER_ZG_S S1 WHERE S1.PRO_PLAN_ID = T1.PRO_PLAN_ID_ZG AND S1.GX_PLAN_NO = T1.GX_PLAN_NO_ZG))PLINE_NAME_NEXT";
                        }
                        else if (strKey.Equals("PlanTimeB"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "MAX(S1.PLAN_TIME_B) PLAN_TIME_B";
                        }else if(strKey.Equals("Memo"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.MEMO";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.MEMO";
                        }else if(strKey.Equals("SoureName"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "T1.SOURE_NAME";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.SOURE_NAME";
                        }
                        else if (strKey.Equals("IsDealer"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "DECODE(T1.IS_DEALER,'0','自用','1','双经销','2','来料加工','3','定销订购')IS_DEALER";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.IS_DEALER";
                        }
                        else if(strKey.Equals("BackFlag"))
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + " DECODE(T1.BACK_FLAG,'0','正常坯','1','回炉坯','2','套尺坯','3','掉队坯')BACK_FLAG";
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "" : ",") + "T1.BACK_FLAG";
                        }

                        else
                        {
                            strSql += (string.IsNullOrEmpty(strSql) ? "t." : ",t.") + strKey;
                            strGroup += (string.IsNullOrEmpty(strGroup) ? "t." : ",t.") + strKey;
                        }
                    }

                }
                catch { }
            }
            strSql += (string.IsNullOrEmpty(strSql) ? "" : ",");
            strGroup = (string.IsNullOrEmpty(strGroup) ? "" : "group by ") + strGroup;

            string _sql = strOut + strGroup;
            list.Add(strSql);
            list.Add(strOut);
            list.Add(strGroup);
            switch (this.CustomInfo)
            {
                case "STORAGE_NO":
                    listSource = EntityHelper.GetData<MatGpMEntity>(
                    "Core.LgMes.Server.Stuffmanage.Report.FrmStoreSummary.queryData", new object[] { list, arr }, this.ob);
                    break;
                case "BELONG_CODE":
                    listSource = EntityHelper.GetData<MatGpMEntity>(
               "Core.LgMes.Server.Stuffmanage.Report.FrmStoreSummary.queryDataBelong", new object[] { list, belongArr }, this.ob);
                    break;
                case "120501":
                    listSource = EntityHelper.GetData<MatGpMEntity>(
                                   "Core.LgMes.Server.Stuffmanage.Report.FrmStoreSummary.queryDataAll", new object[] { list,this.CustomInfo}, this.ob);
                    break;
                case "120504":
                    listSource = EntityHelper.GetData<MatGpMEntity>(
                                   "Core.LgMes.Server.Stuffmanage.Report.FrmStoreSummary.queryDataAll", new object[] { list, this.CustomInfo }, this.ob);
                    break;
            }

            MatGpMEntitybindingSource.DataSource = listSource;


            bool bContains = false, bChecked = false;

            for (int i = 0; i < this.ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
            {
                try
                {
                    bContains = false;
                    strKey = this.ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;

                    for (int j = 0; j < this.myCheckedListBox1.Controls.Count; j++)
                    {
                        try
                        {
                            item = this.myCheckedListBox1.Controls[j] as CheckBox;

                            if (item.Name.Equals(strKey))
                            {
                                bContains = true;
                                bChecked = item.Checked;
                                break;
                            }
                        }
                        catch { }
                    }

                    if (bContains)
                    {
                        this.ultraGrid1.DisplayLayout.Bands[0].Columns[i].Hidden = !bChecked;
                    }
                }
                catch { }
            }

            this.SetStaticsInfo();
            CommonMethod.SetGridSumArea(this.ultraGrid1);
        }
```

前端不盘逻辑，全是拼装sql，难以理解，并且完全无法进行后端单元测试

后端代码

```java
public CoreReturnObject DoAdd(String HeatPlanNo, String Sqe1, String load,
            String gx, ArrayList<String> ScrappedList,
            ArrayList<String> SuspiciousList) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
         //  TZH 24.4.24 注销物流接口
//        Connection connection2 = this.getDao("TmsDao").getConnection();
        PreparedStatement psta = null;
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyyMMdd",
                Locale.CHINA);
        SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyyMM",
                Locale.CHINA);
        String systime = dateFormat.format(now);
        String BalYearMothDay = dateFormat1.format(now);
        String BalYearMoth = ""; //改25号结转

        try {
            connection.setAutoCommit(false); //
             //  TZH 24.4.24 注销物流接口
//            connection2.setAutoCommit(false); // 取消自动提交事务
            String addport = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.AddPortNew");// 新增管号队列
            PreparedStatement patsport = connection.prepareStatement(addport);

            String addOut = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.AddOutList");// 新增出库记录
            PreparedStatement patsAddOut = connection.prepareStatement(addOut);
            String addOutlist = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.AddOutListQuan");// 新增产权出库
            PreparedStatement patsAddOutlist = connection
                    .prepareStatement(addOutlist);

            String sqlAdd = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.AddLoadResult");// 新增上料实绩
            PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
            String sqlupdate = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.updatePlnZyRclM");// 修改加工计划表从表的实际上料支吨
            PreparedStatement patupdate = connection
                    .prepareStatement(sqlupdate);

            String sqlupdate2 = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.updatePlnZyRclM2");// 修改加工计划表从表的实际上料支吨
            PreparedStatement patupdate2 = connection
                    .prepareStatement(sqlupdate2);

            String sqlupdatepln = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.updatePlnZyRclMpln");// 修改加工计划表
            PreparedStatement patupdatepln = connection
                    .prepareStatement(sqlupdatepln);
            String addPlnInfo = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.AddComInfoResult");// 新增公共信息
            PreparedStatement patsPlan = connection
                    .prepareStatement(addPlnInfo);
            String deleteButt = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.deleteButter");// 删除位置表
            PreparedStatement patsButt = connection
                    .prepareStatement(deleteButt);
            String updateMat = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.updateMatZcPlan");// 修改库存状态
            PreparedStatement patsUpMat = connection
                    .prepareStatement(updateMat);

            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.UpdatePath");// 修改队列表工艺路径
            PreparedStatement pastupdatePath = connection
                    .prepareStatement(updatePath);

            String deleteMat = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.CopyBcMat");// 复制物料主表到MAT_BC_BACKUP表
            PreparedStatement patsMat = connection.prepareStatement(deleteMat);
            String deteleBcMat = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.DeteleBcMat");// 删除物料主表
            PreparedStatement deteleBcMatPath = connection
                    .prepareStatement(deteleBcMat);
            String addPlnInfo1 = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.AddComInfoResult1");// 修改队列表材料，工序状态
            PreparedStatement patsPlan1 = connection
                    .prepareStatement(addPlnInfo1);

            String InsertIntoOrderGroupNo = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.InsertIntoOrderGroupNo");// 修改队列表材料，工序状态
            PreparedStatement patsInsertIntoOrderGroupNo = connection
                    .prepareStatement(InsertIntoOrderGroupNo);

            // 获取加工计划实体了
            PlnZyJgxMEntity pln = PlanService.getSendHttPlanCInfo3(connection,
                    HeatPlanNo);
            BalYearMoth = com.steering.common.StringTool.GetBalYear(com.steering.common.StringTool.GetSupplyUnit(pln.getPlineCode())); //改25号结转

            /*
             * // 获取加工计划实体了 PlnZyJgxCEntity plnC =
             * PlanService.getSendHttPlanCInfo3C(connection, HeatPlanNo,Sqe);
             */

            MchLoadingResultEntity Result = EntityTool.getEntityByJSONStr(load,
                    MchLoadingResultEntity.class);

            // region 检查
            if (pln == null) {
                core.setV_errMsg("找不到炉计划数据！");
                return core;
            }

            // 计划关闭 或计划完成 继续上料 清除结炉状态
            if (pln.getPlanstatus().equals("40")
                    || pln.getPlanstatus().equals("30")) {

                String sql = CoreXmlSqlParsersFactory
                        .getSql("FrmMcpLoading.CancelNodeFlag");
                sql = EntityTool.fillSqlByEntity(sql, Result);
                psta = connection.prepareStatement(sql);
                psta.executeUpdate();
                psta.close();

            } else if (!pln.getPlanstatus().equals("10")
                    && !pln.getPlanstatus().equals("20")) {
                core.setV_errMsg("炉计划不处于下发或生产中状态！");
                return core;
            }

            String cutFalg = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("MchComm.queryComInfo");// 查询 工序是否是结炉状态
            psta = connection.prepareStatement(sql);
            psta.setString(1, HeatPlanNo);
            psta.setString(2, Result.getBatchNo());
            psta.setString(3, gx);
            ResultSet rs = psta.executeQuery();
            if (rs.next()) {
                cutFalg = rs.getString("STATION_STATUS");
            }

            if (cutFalg.equals("2")) {
                core.setV_errMsg("已结炉,不允许此操作！");
                return core;
            }
            rs.close();
            psta.close();
            // endregion

            String resultNo = "";
            int count = 0;
            int detCount = 0;
            double wt = 0d;

            if (StringTool.isInteger(Result.getFailNum())) {
                detCount = Integer.parseInt(Result.getFailNum());
            }
            if (StringTool.isInteger(Result.getProNum())) {
                count = Integer.parseInt(Result.getProNum());
            }
            if (StringTool.isDouble(Result.getProWt())) {
                wt = Double.parseDouble(Result.getProWt());
            }

            if (StringTool.isInteger(Result.getProWt())) {
                wt = Double.parseDouble(Result.getProWt());
            }

            if (count <= 0) {
                core.setV_errMsg("请输入正确的上料支！");
                return core;
            }

            if (wt <= 0.000001) {
                core.setV_errMsg("上料重量异常,,请重新查询再上料！");
                return core;
            }

            if (count < detCount) {
                core.setV_errMsg("废品支数不能大于上料支！");
                return core;
            }

            // 获取最大实绩编号
            sql = CoreXmlSqlParsersFactory
                    .getSql("MchComm.queryLoadNewResultNo");
            psta = connection.prepareStatement(sql);
            psta.setObject(1, pln.getPlineCode() + gx);
            psta.setObject(2, pln.getPlineCode() + gx);
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                resultNo = rs1.getString("RESULT_NO");
            }
            rs1.close();
            psta.close();

            String StorageNo = PlanService.GetStorageIn(pln.getPlineCode(),
                    connection);

            String sqlMatNo = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.queryMatZc");// 查询新增物料信息
            psta = connection.prepareStatement(sqlMatNo);
            psta.setObject(1, pln.getHeatPlanNo());
            psta.setObject(2, Result.getBatchNo());
            psta.setObject(3, Result.getBatchGroudNo());
            psta.setObject(4, StorageNo);
            psta.setObject(5, count + 1);
            rs = psta.executeQuery();
            List<MatBcMEntity> listMat = EntityTool.getEntitysByRs(rs,
                    MatBcMEntity.class);
            rs.close();
            psta.close();

            if (listMat.size() != count) {
                core.setV_errMsg("无足够的库存！");
                return core;
            }

            String sendOut = querySendOut(connection, "800801", pln
                    .getPlineCode());
            // 获取出库流水号
            String butessMatNo = querySendOutList(connection, sendOut);
            int outNo = Integer.parseInt(butessMatNo.substring(butessMatNo
                    .length() - 4, butessMatNo.length()));

            String sendOutlist = querySendOut(connection, "800809", pln
                    .getPlineCode());
            // 获取出库流水号
            String butessMatNolist = querySendOutList(connection, sendOutlist);
            int outNolist = Integer.parseInt(butessMatNolist.substring(
                    butessMatNolist.length() - 4, butessMatNolist.length()));

            List<PlnZyJgxCEntity> plnCs = PlanService.getSendHttPlanCInfo3C(
                    connection, HeatPlanNo, Result.getBatchNo(), Result
                            .getBatchGroudNo());

            if (pln.getSiglLen().equals("")
                    || Double.parseDouble(pln.getSiglLen()) < 0.0001) {

                String sqlGroup = CoreXmlSqlParsersFactory
                        .getSql("FrmMcpLoading.queryOrderGroupNo");//
                psta = connection.prepareStatement(sqlGroup);
                psta.setObject(1, pln.getOrderNo() + "/" + pln.getOrderSeq());
                rs = psta.executeQuery();
                if (!rs.next()) {

                    patsInsertIntoOrderGroupNo.setObject(1, pln.getOrderNo()
                            + "/" + pln.getOrderSeq());
                    patsInsertIntoOrderGroupNo.setObject(2, pln.getLengthmax());
                    patsInsertIntoOrderGroupNo.setObject(3, pln.getLengthmin());
                    patsInsertIntoOrderGroupNo.setObject(4, "001");
                    patsInsertIntoOrderGroupNo.setObject(5, "<=");
                    patsInsertIntoOrderGroupNo.setObject(6, ">=");
                    patsInsertIntoOrderGroupNo.addBatch();

                    if (pln.getLengthdisc().trim().equals("R1")) {
                        patsInsertIntoOrderGroupNo.setObject(1, pln
                                .getOrderNo()
                                + "/" + pln.getOrderSeq());
                        patsInsertIntoOrderGroupNo.setObject(2, pln
                                .getLengthmin());
                        patsInsertIntoOrderGroupNo.setObject(3, "4.88");
                        patsInsertIntoOrderGroupNo.setObject(4, "002");
                        patsInsertIntoOrderGroupNo.setObject(5, "<");
                        patsInsertIntoOrderGroupNo.setObject(6, ">=");
                        patsInsertIntoOrderGroupNo.addBatch();
                    } else if (pln.getLengthdisc().trim().equals("R2")) {
                        patsInsertIntoOrderGroupNo.setObject(1, pln
                                .getOrderNo()
                                + "/" + pln.getOrderSeq());
                        patsInsertIntoOrderGroupNo.setObject(2, pln
                                .getLengthmin());
                        patsInsertIntoOrderGroupNo.setObject(3, "7.62");
                        patsInsertIntoOrderGroupNo.setObject(4, "002");
                        patsInsertIntoOrderGroupNo.setObject(5, "<");
                        patsInsertIntoOrderGroupNo.setObject(6, ">=");
                        patsInsertIntoOrderGroupNo.addBatch();
                    } else if (pln.getLengthdisc().trim().equals("R3")) {
                        patsInsertIntoOrderGroupNo.setObject(1, pln
                                .getOrderNo()
                                + "/" + pln.getOrderSeq());
                        patsInsertIntoOrderGroupNo.setObject(2, pln
                                .getLengthmin());
                        patsInsertIntoOrderGroupNo.setObject(3, "10.36");
                        patsInsertIntoOrderGroupNo.setObject(4, "002");
                        patsInsertIntoOrderGroupNo.setObject(5, "<");
                        patsInsertIntoOrderGroupNo.setObject(6, ">=");
                        patsInsertIntoOrderGroupNo.addBatch();
                    } else if (!pln.getShortest().equals("")) {
                        patsInsertIntoOrderGroupNo.setObject(1, pln
                                .getOrderNo()
                                + "/" + pln.getOrderSeq());
                        patsInsertIntoOrderGroupNo.setObject(2, pln
                                .getLengthmin());
                        patsInsertIntoOrderGroupNo.setObject(3, pln
                                .getShortest());
                        patsInsertIntoOrderGroupNo.setObject(4, "002");
                        patsInsertIntoOrderGroupNo.setObject(5, "<");
                        patsInsertIntoOrderGroupNo.setObject(6, ">=");
                        patsInsertIntoOrderGroupNo.addBatch();
                    }

                    patsInsertIntoOrderGroupNo.executeBatch();
                }
                rs.close();
                psta.close();

            }

            Integer UsedNum = 0;
            Double UsedWt = 0d;
            Double TWt = 0d;
            Integer CurrentCount = 0;
            PlnZyJgxCEntity CurrentJgxC = plnCs.get(CurrentCount);
            Integer CanLoadNum = Integer.parseInt(CurrentJgxC
                    .getPlanIndoubleNum().equals("") ? "0" : CurrentJgxC
                    .getPlanIndoubleNum())
                    - Integer.parseInt(CurrentJgxC.getRealIndoubleNum().equals(
                            "") ? "0" : CurrentJgxC.getRealIndoubleNum());
            Double CanLoadWt = Double.parseDouble(CurrentJgxC
                    .getPlanIndoubleWt().equals("") ? "0" : CurrentJgxC
                    .getPlanIndoubleWt())
                    - Double
                            .parseDouble(CurrentJgxC.getRealIndoubleWt()
                                    .equals("") ? "0" : CurrentJgxC
                                    .getRealIndoubleWt());

            int CountInstorage = 0;

            for (MatBcMEntity lvMat : listMat) {

                /*if (!"002023005".equals(lvMat.getBelongCode())
                        && "C092".equals(pln.getPlineCode())) {
                    core.setV_errMsg("管所属权不属于天淮,不允许上料！清确认管是否倒运至天淮！");
                    return core;
                }*/

                if (lvMat.getStorageNo().equals("")) {
                    core.setV_errMsg("库存正在倒运中,无法上料!");
                    return core;
                }

                if (!lvMat.getStorageNo().equals(StorageNo)) {
                    if (pln.getIsLoadFlag().equals("1")) {

                        String deleteYdmBack = CoreXmlSqlParsersFactory
                                .getSql("FrmMcpLoading.deleteYdmBack");//
                        PreparedStatement patsdeleteYdmBack = connection
                                .prepareStatement(deleteYdmBack);

                        patsdeleteYdmBack.setObject(1, pln.getPlineCode());
                        patsdeleteYdmBack.setObject(2, lvMat.getMatNo());
                        patsdeleteYdmBack.executeUpdate();
                        patsdeleteYdmBack.close();

                        // 上料炉号和判定炉号不一致 改成保存判定炉号的位置信息
                        String insertYdmBack = CoreXmlSqlParsersFactory
                                .getSql("FrmMcpLoading.insertYdmBack");//
                        PreparedStatement patsinsertYdmBack = connection
                                .prepareStatement(insertYdmBack);
                        patsinsertYdmBack.setObject(1, pln.getPlineCode());
                        patsinsertYdmBack.setObject(2, lvMat.getMatNo());
                        patsinsertYdmBack.executeUpdate();
                        patsinsertYdmBack.close();

                    } else {

                        if (CountInstorage == 0) {
                            core.setV_errMsg("库存未在投料库,无法上料");
                            return core;
                        } else {
                            core.setV_errMsg("只有" + CountInstorage
                                    + "支在投料库 ,无法上足" + count + "支");
                            return core;
                        }
                    }

                }
                CountInstorage++;

                if ("1".equals(lvMat.getLockFlag())) {
                    core.setV_errMsg("库存存在质量封锁料,无法上足" + count + "支");
                    return core;
                }

                if ("1".equals(lvMat.getMngLockFlag())) {
                    core.setV_errMsg("库存存在管理封锁料,无法上足" + count + "支");
                    return core;
                }

                while (UsedNum >= CanLoadNum) {
                    patupdate.setObject(1, UsedNum);
                    patupdate.setObject(2, UsedWt);
                    patupdate.setObject(3, pln.getHeatPlanNo());
                    patupdate.setObject(4, CurrentJgxC.getHeatPlanSqe());
                    patupdate.addBatch();

                    CurrentCount++;

                    if (CurrentCount >= plnCs.size()) {
                        core.setV_errMsg("上料支超过排产支！");
                        return core;
                    }

                    CurrentJgxC = plnCs.get(CurrentCount);
                    CanLoadNum = Integer.parseInt(CurrentJgxC
                            .getPlanIndoubleNum().equals("") ? "0"
                            : CurrentJgxC.getPlanIndoubleNum())
                            - Integer.parseInt(CurrentJgxC.getRealIndoubleNum()
                                    .equals("") ? "0" : CurrentJgxC
                                    .getRealIndoubleNum());

                    UsedNum = 0;
                    UsedWt = 0d;
                }

                patsport.setObject(1, Result.getCreatetUser());
                patsport.setObject(2, Result.getLoadShift());
                patsport.setObject(3, Result.getLoadGroup());
                patsport.setObject(4, pln.getFeedHeatNo());
                patsport.setObject(5, CurrentJgxC.getHeatPlanSqe());
                patsport.setObject(6, BalYearMothDay);
                patsport.setObject(7, BalYearMoth);
                patsport.setObject(8, lvMat.getMatNo());
                patsport.setObject(9, pln.getHeatPlanNo());
                patsport.addBatch();

                UsedNum++;
                UsedWt = UsedWt + Double.parseDouble(lvMat.getActWeight());
                TWt = TWt + Double.parseDouble(lvMat.getActWeight());

                // 新增出库表
                patsAddOut.setObject(1, sendOut
                        + StringTool.formatDecimal(outNo, "0000"));
                patsAddOut.setObject(2, HeatPlanNo);
                patsAddOut.setObject(3, sendOut);
                patsAddOut.setObject(4, "800801");
                patsAddOut.setObject(5, "投料出库");
                patsAddOut.setObject(6, lvMat.getMatNo());
                patsAddOut.setObject(7, lvMat.getJudgeStoveNo());
                patsAddOut.setObject(8, lvMat.getBatchNo());
                patsAddOut.setObject(9, lvMat.getBatchGroudNo());
                patsAddOut.setObject(10, lvMat.getMaterialNo());
                patsAddOut.setObject(11, lvMat.getMaterialName());
                patsAddOut.setObject(12, lvMat.getProduccode());
                patsAddOut.setObject(13, lvMat.getProducname());
                patsAddOut.setObject(14, lvMat.getStdCode());
                patsAddOut.setObject(15, lvMat.getStdName());
                patsAddOut.setObject(16, lvMat.getGradecode());
                patsAddOut.setObject(17, lvMat.getGradename());
                patsAddOut.setObject(18, lvMat.getSteelcode());
                patsAddOut.setObject(19, lvMat.getSteelname());
                patsAddOut.setObject(20, lvMat.getStdStyle());
                patsAddOut.setObject(21, lvMat.getStdStyleDesc());
                patsAddOut.setObject(22, lvMat.getSpecCode());
                patsAddOut.setObject(23, lvMat.getSpecName());
                patsAddOut.setObject(24, lvMat.getModelCode());
                patsAddOut.setObject(25, lvMat.getModelDesc());
                patsAddOut.setObject(26, (lvMat.getPlineCode().equals("100101")
                        || lvMat.getPlineCode().equals("100102") || lvMat
                        .getPlineCode().equals("100103")) ? (lvMat
                        .getProcessCdoe().equals("D") ? "C008" : lvMat
                        .getProcessCdoe().equals("E") ? "C013" : lvMat
                        .getProcessCdoe().equals("F") ? "C022" : lvMat
                        .getProcessCdoe().equals("G") ? "C028" : "C041")
                        : lvMat.getPlineCode());
                patsAddOut.setObject(27, (lvMat.getPlineCode().equals("100101")
                        || lvMat.getPlineCode().equals("100102") || lvMat
                        .getPlineCode().equals("100103")) ? (lvMat
                        .getProcessCdoe().equals("D") ? "250机组" : lvMat
                        .getProcessCdoe().equals("E") ? "冷轧机组" : lvMat
                        .getProcessCdoe().equals("F") ? "热处理01#（管加工1号热）"
                        : lvMat.getProcessCdoe().equals("G") ? "加工线01#（管加工1#线）"
                                : "接箍1（美国PMC1077）") : lvMat.getPlineName());
                patsAddOut.setObject(28, lvMat.getActDimater());
                patsAddOut.setObject(29, lvMat.getActHeight());
                patsAddOut.setObject(30, String.valueOf(lvMat.getActLen()));
                patsAddOut.setObject(31, lvMat.getActLenMin());
                patsAddOut.setObject(32, lvMat.getActLenMax());
                patsAddOut.setObject(33, String.valueOf(lvMat.getActCount()));
                patsAddOut.setObject(34, String.valueOf(lvMat.getActWeight()));
                patsAddOut.setObject(35, String.valueOf(lvMat
                        .getActTheoryWeight()));
                patsAddOut.setObject(36, lvMat.getBelongCode());
                patsAddOut.setObject(37, lvMat.getBelongName());
                patsAddOut.setObject(38, lvMat.getStorageNo());
                patsAddOut.setObject(39, lvMat.getLocationNo());
                patsAddOut.setObject(40, lvMat.getLaryNo());
                patsAddOut.setObject(41, lvMat.getLocNo());
                patsAddOut.setObject(42, lvMat.getStorageAttr());
                patsAddOut.setObject(43, lvMat.getStorageAttrName());
                patsAddOut.setObject(44, lvMat.getStorageTypeNo());
                patsAddOut.setObject(45, lvMat.getStorageTypeName());
                patsAddOut.setObject(46, lvMat.getManagementNo());
                patsAddOut.setObject(47, lvMat.getManagementName());
                patsAddOut.setObject(48, systime);
                patsAddOut.setObject(49, lvMat.getProBc());
                patsAddOut.setObject(50, lvMat.getProBz());
                patsAddOut.setObject(51, systime);
                patsAddOut.setObject(52, Result.getLoadShift());
                patsAddOut.setObject(53, Result.getLoadGroup());
                patsAddOut.setObject(54, Result.getCreatetUser());
                patsAddOut.setObject(55, systime);
                patsAddOut.setObject(56, lvMat.getOrdPk());
                patsAddOut.setObject(57, lvMat.getOrdLnPk());
                patsAddOut.setObject(58, lvMat.getOrdLnDlyPk());
                patsAddOut.setObject(59, lvMat.getDepartmentCode());
                patsAddOut.setObject(60, lvMat.getDepartmentDesc());
                patsAddOut.setObject(61, lvMat.getOrderNo());
                patsAddOut.setObject(62, lvMat.getOrderSeq());
                patsAddOut.setObject(63, pln.getDeliveryNo());
                patsAddOut.setObject(64, "801401");
                patsAddOut.setObject(65, "80150105");
                patsAddOut.setObject(66, lvMat.getJudgeStdCode());
                patsAddOut.setObject(67, lvMat.getJudgeStdName());
                patsAddOut.setObject(68, pln.getZyBatchId());
                patsAddOut.setObject(69, lvMat.getStoveNo());
                patsAddOut.setObject(70, Result.getPlineCode());
                patsAddOut.setObject(71, Result.getPlineCode());
                patsAddOut.setObject(72, pln.getOrderNo() + "/"
                        + pln.getOrderSeq());
                patsAddOut.setObject(73, BalYearMoth);
                patsAddOut.setObject(74, lvMat.getProcessCdoe());
                patsAddOut.setObject(75, lvMat.getProcessDesc());
                patsAddOut.addBatch();
                outNo++;

                // 新增产权出库
                patsAddOutlist.setObject(1, sendOutlist
                        + StringTool.formatDecimal(outNolist, "0000"));
                patsAddOutlist.setObject(2, HeatPlanNo);
                patsAddOutlist.setObject(3, sendOutlist);
                patsAddOutlist.setObject(4, "800809");
                patsAddOutlist.setObject(5, "产权出库");
                patsAddOutlist.setObject(6, lvMat.getMatNo());
                patsAddOutlist.setObject(7, lvMat.getJudgeStoveNo());
                patsAddOutlist.setObject(8, lvMat.getBatchNo());
                patsAddOutlist.setObject(9, lvMat.getBatchGroudNo());
                patsAddOutlist.setObject(10, lvMat.getMaterialNo());
                patsAddOutlist.setObject(11, lvMat.getMaterialName());
                patsAddOutlist.setObject(12, lvMat.getProduccode());
                patsAddOutlist.setObject(13, lvMat.getProducname());
                patsAddOutlist.setObject(14, lvMat.getStdCode());
                patsAddOutlist.setObject(15, lvMat.getStdName());
                patsAddOutlist.setObject(16, lvMat.getGradecode());
                patsAddOutlist.setObject(17, lvMat.getGradename());
                patsAddOutlist.setObject(18, lvMat.getSteelcode());
                patsAddOutlist.setObject(19, lvMat.getSteelname());
                patsAddOutlist.setObject(20, lvMat.getStdStyle());
                patsAddOutlist.setObject(21, lvMat.getStdStyleDesc());
                patsAddOutlist.setObject(22, lvMat.getSpecCode());
                patsAddOutlist.setObject(23, lvMat.getSpecName());
                patsAddOutlist.setObject(24, lvMat.getModelCode());
                patsAddOutlist.setObject(25, lvMat.getModelDesc());
                patsAddOutlist.setObject(26, (lvMat.getPlineCode().equals(
                        "100101")
                        || lvMat.getPlineCode().equals("100102") || lvMat
                        .getPlineCode().equals("100103")) ? (lvMat
                        .getProcessCdoe().equals("D") ? "C008" : lvMat
                        .getProcessCdoe().equals("E") ? "C013" : lvMat
                        .getProcessCdoe().equals("F") ? "C022" : lvMat
                        .getProcessCdoe().equals("G") ? "C028" : "C041")
                        : lvMat.getPlineCode());
                patsAddOutlist.setObject(27, (lvMat.getPlineCode().equals(
                        "100101")
                        || lvMat.getPlineCode().equals("100102") || lvMat
                        .getPlineCode().equals("100103")) ? (lvMat
                        .getProcessCdoe().equals("D") ? "250机组" : lvMat
                        .getProcessCdoe().equals("E") ? "冷轧机组" : lvMat
                        .getProcessCdoe().equals("F") ? "热处理01#（管加工1号热）"
                        : lvMat.getProcessCdoe().equals("G") ? "加工线01#（管加工1#线）"
                                : "接箍1（美国PMC1077）") : lvMat.getPlineName());
                patsAddOutlist.setObject(28, lvMat.getActDimater());
                patsAddOutlist.setObject(29, lvMat.getActHeight());
                patsAddOutlist.setObject(30, String.valueOf(lvMat.getActLen()));
                patsAddOutlist.setObject(31, lvMat.getActLenMin());
                patsAddOutlist.setObject(32, lvMat.getActLenMax());
                patsAddOutlist.setObject(33, String
                        .valueOf(lvMat.getActCount()));
                patsAddOutlist.setObject(34, String.valueOf(lvMat
                        .getActWeight()));
                patsAddOutlist.setObject(35, String.valueOf(lvMat
                        .getActTheoryWeight()));
                patsAddOutlist.setObject(36, lvMat.getBelongCode());
                patsAddOutlist.setObject(37, lvMat.getBelongName());
                patsAddOutlist.setObject(38, lvMat.getStorageNo());
                patsAddOutlist.setObject(39, lvMat.getLocationNo());
                patsAddOutlist.setObject(40, lvMat.getLaryNo());
                patsAddOutlist.setObject(41, lvMat.getLocNo());
                patsAddOutlist.setObject(42, lvMat.getStorageAttr());
                patsAddOutlist.setObject(43, lvMat.getStorageAttrName());
                patsAddOutlist.setObject(44, lvMat.getStorageTypeNo());
                patsAddOutlist.setObject(45, lvMat.getStorageTypeName());
                patsAddOutlist.setObject(46, lvMat.getManagementNo());
                patsAddOutlist.setObject(47, lvMat.getManagementName());
                patsAddOutlist.setObject(48, systime);
                patsAddOutlist.setObject(49, lvMat.getProBc());
                patsAddOutlist.setObject(50, lvMat.getProBz());
                patsAddOutlist.setObject(51, systime);
                patsAddOutlist.setObject(52, Result.getLoadShift());
                patsAddOutlist.setObject(53, Result.getLoadGroup());
                patsAddOutlist.setObject(54, Result.getCreatetUser());
                patsAddOutlist.setObject(55, systime);
                patsAddOutlist.setObject(56, lvMat.getOrdPk());
                patsAddOutlist.setObject(57, lvMat.getOrdLnPk());
                patsAddOutlist.setObject(58, lvMat.getOrdLnDlyPk());
                patsAddOutlist.setObject(59, lvMat.getDepartmentCode());
                patsAddOutlist.setObject(60, lvMat.getDepartmentDesc());
                patsAddOutlist.setObject(61, lvMat.getOrderNo());
                patsAddOutlist.setObject(62, lvMat.getOrderSeq());
                patsAddOutlist.setObject(63, pln.getDeliveryNo());
                patsAddOutlist.setObject(64, "801401");
                patsAddOutlist.setObject(65, "80150105");
                patsAddOutlist.setObject(66, lvMat.getJudgeStdCode());
                patsAddOutlist.setObject(67, lvMat.getJudgeStdName());
                patsAddOutlist.setObject(68, pln.getZyBatchId());
                patsAddOutlist.setObject(69, lvMat.getStoveNo());
                patsAddOutlist.setObject(70, Result.getPlineCode());
                patsAddOutlist.setObject(71, Result.getPlineCode());
                patsAddOutlist.setObject(72, pln.getOrderNo() + "/"
                        + pln.getOrderSeq());
                patsAddOutlist.setObject(73, BalYearMoth);
                patsAddOutlist.setObject(74, lvMat.getProcessCdoe());
                patsAddOutlist.setObject(75, lvMat.getProcessDesc());
                if (!pln.getIfMatchOdd().equals("6"))
                    patsAddOutlist.addBatch();

                outNolist++;
                // 修改库存状态
                patsUpMat.setObject(1, "80150105");
                patsUpMat.setObject(2, lvMat.getMatNo());
                patsUpMat.addBatch();
                // 删除位置表
                patsButt.setObject(1, lvMat.getMatNo());
                patsButt.addBatch();
                // 把物料主表复制到List表
                patsMat.setObject(1, lvMat.getMatNo());
                patsMat.addBatch();
                // 删除物料主表
                deteleBcMatPath.setObject(1, lvMat.getMatNo());
                deteleBcMatPath.addBatch();
            }

            patupdate.setObject(1, UsedNum);
            patupdate.setObject(2, UsedWt);
            patupdate.setObject(3, pln.getHeatPlanNo());
            patupdate.setObject(4, CurrentJgxC.getHeatPlanSqe());
            patupdate.addBatch();

            patsport.executeBatch();
            patsAddOut.executeBatch();
            patsAddOutlist.executeBatch();
            patsUpMat.executeBatch();
            patsButt.executeBatch();
            patsMat.executeBatch();
            deteleBcMatPath.executeBatch();

            Result.setOutstockDoc(sendOut);

            // 新增上料实绩
            patAdd.setObject(1, resultNo);
            patAdd.setObject(2, Result.getZyBatchId());
            patAdd.setObject(3, pln.getProPlanId());
            patAdd.setObject(4, pln.getGxPlanNo());
            patAdd.setObject(5, Result.getProNum());
            patAdd.setObject(6, TWt);
            patAdd.setObject(7, Result.getFailNum());
            patAdd.setObject(8, Result.getFailWt());
            patAdd.setObject(9, "");
            patAdd.setObject(10, "");
            patAdd.setObject(11, "");
            patAdd.setObject(12, "");
            patAdd.setObject(13, Result.getLoadTime());
            patAdd.setObject(14, Result.getLoadShift());
            patAdd.setObject(15, Result.getLoadGroup());
            patAdd.setObject(16, "1");
            patAdd.setObject(17, Result.getPlineCode());
            patAdd.setObject(18, Result.getPlineName());
            patAdd.setObject(19, Result.getHeatPlanNo());
            patAdd.setObject(20, systime);
            patAdd.setObject(21, Result.getProducer());
            if (Result.getProducer().equals("")) {
                patAdd.setObject(22, "");
            } else {
                patAdd.setObject(22, Result.getProducerTime());
            }
            patAdd.setObject(23, Result.getCreatetUser());
            patAdd.setObject(24, Result.getOutnumCut());
            patAdd.setObject(25, Result.getLengthIn());
            patAdd.setObject(26, Result.getLengthmaxIn());
            patAdd.setObject(27, Result.getLengthminIn());
            patAdd.setObject(28, sendOut);
            patAdd.setObject(29, Result.getJudgeStoveNo());
            patAdd.setObject(30, Result.getBatchNo());
            patAdd.setObject(31, Result.getBatchGroudNo());
            patAdd.setObject(32, Result.getHeatPlanSqe());
            patAdd.setObject(33, Result.getMatSource());
            patAdd.setObject(34, BalYearMothDay);
            patAdd.setObject(35, BalYearMoth);
            patAdd.addBatch();

            // 新增加工公共信息
            patsPlan.setObject(1, resultNo);
            patsPlan.setObject(2, pln.getZyBatchId());
            patsPlan.setObject(3, "");
            patsPlan.setObject(4, pln.getProPlanId());
            patsPlan.setObject(5, pln.getGxPlanNo());
            patsPlan.setObject(6, pln.getOrderSource());
            patsPlan.setObject(7, pln.getOrderNo());
            patsPlan.setObject(8, pln.getOrderSeq());
            patsPlan.setObject(9, pln.getReqBlId());
            patsPlan.setObject(10, pln.getPlineCode());
            patsPlan.setObject(11, pln.getPlineName());
            patsPlan.setObject(12, gx);
            patsPlan.setObject(13, gx);
            patsPlan.setObject(14, "");
            patsPlan.setObject(15, "");
            patsPlan.setObject(16, pln.getSteelcode());
            patsPlan.setObject(17, pln.getSteelname());
            patsPlan.setObject(18, pln.getOutdiameter());
            patsPlan.setObject(19, pln.getWallthick());
            patsPlan.setObject(20, "");
            patsPlan.setObject(21, "");
            patsPlan.setObject(22, "");
            patsPlan.setObject(23, "");
            patsPlan.setObject(24, "");
            patsPlan.setObject(25, "");
            patsPlan.setObject(26, "");
            patsPlan.setObject(27, "");
            patsPlan.setObject(28, pln.getOutwlId());
            patsPlan.setObject(29, pln.getOutwlDesc());
            patsPlan.setObject(30, pln.getInwlId());
            patsPlan.setObject(31, pln.getInwlDesc());
            patsPlan.setObject(32, pln.getMonitorPoint());
            patsPlan.setObject(33, Result.getIfMonitorRcl());
            patsPlan.setObject(34, pln.getPrdcrNo());
            patsPlan.setObject(35, Result.getProducer());
            if (Result.getProducer().equals("")) {
                patsPlan.setObject(36, "");
            } else {
                patsPlan.setObject(36, Result.getProducerTime());
            }
            patsPlan.setObject(37, pln.getStationRoad());
            patsPlan.setObject(38, pln.getCraftFileNo());
            patsPlan.setObject(39, pln.getCraftFileMan());
            patsPlan.setObject(40, pln.getCraftSeq());
            patsPlan.setObject(41, Result.getProNum());
            patsPlan.setObject(42, TWt);
            patsPlan.setObject(43, Result.getFailNum());
            patsPlan.setObject(44, Result.getFailWt());
            patsPlan.setObject(45, Result.getOfflineNum());
            patsPlan.setObject(46, Result.getOfflineWt());
            patsPlan.setObject(47, Result.getReNum());
            patsPlan.setObject(48, Result.getReWt());
            patsPlan.setObject(49, "1");
            patsPlan.setObject(50, Result.getLoadTime());
            patsPlan.setObject(51, "");
            patsPlan.setObject(52, Result.getLoadShift());
            patsPlan.setObject(53, Result.getLoadGroup());
            patsPlan.setObject(54, "1");
            patsPlan.setObject(55, Result.getCreateTime());
            patsPlan.setObject(56, Result.getCreatetUser());
            patsPlan.setObject(57, pln.getHeatPlanNo());
            patsPlan.setObject(58, pln.getJudgeStoveNo());
            patsPlan.setObject(59, Result.getBatchNo());
            patsPlan.setObject(60, Result.getBatchGroudNo());
            patsPlan.setObject(61, pln.getProduccode());
            patsPlan.setObject(62, pln.getProducname());
            patsPlan.setObject(63, Result.getOutnumCut());
            patsPlan.setObject(64, pln.getSpecCode());
            patsPlan.setObject(65, pln.getSpecName());
            patsPlan.addBatch();

            // 修改计划主表状态
            patupdatepln.setObject(1, "20");
            patupdatepln.setObject(2, "00");
            patupdatepln.setObject(3, HeatPlanNo);
            patupdatepln.addBatch();

            patupdate2.setObject(1, "00");
            patupdate2.setObject(2, pln.getHeatPlanNo());
            patupdate2.setObject(3, Result.getBatchNo());
            patupdate2.addBatch();

            patAdd.executeBatch();
            patsPlan.executeBatch();
            patupdate.executeBatch();
            patupdate2.executeBatch();
            patupdatepln.executeBatch();

            FrmMchBugD.AddMchWaste(connection, HeatPlanNo, resultNo, Result
                    .getPlineCode(), Result.getCreatetUser(), gx,
                    SuspiciousList, ScrappedList);

            // 更新运输需求上料时间
            FrmVrpInStore frmVrpInStore = new FrmVrpInStore();
             //  TZH 24.4.24 注销物流接口
//            frmVrpInStore.updateTmsDemandMLoadTime(connection, connection2,
//                    core, HeatPlanNo, "G");
            if (core.getV_errMsg().equals("")) {
                core.setV_errMsg("上料成功！");
            }

            // 财务系统接口数据处理
            // FmisTool.addBcOutList(connection,core,HeatPlanNo,resultNo,"G");

            core.setResult(1);
            connection.commit();
             //  TZH 24.4.24 注销物流接口
//            connection2.commit();
        } catch (Exception e) {
            core.setV_errMsg(e.getMessage());
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                     //  TZH 24.4.24 注销物流接口
//                    connection2.rollback(); // 回滚事务
                } catch (Exception e2) {
                }
            }
             //  TZH 24.4.24 注销物流接口
//            if (connection2 != null) {
//                try {
//                    connection.rollback(); // 回滚事务
//                    connection2.rollback(); // 回滚事务
//                } catch (Exception e2) {
//                }
//            }
        } finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
                 //  TZH 24.4.24 注销物流接口
//                if (connection2 != null && !connection2.isClosed()) {
//                    connection2.close();
//                }
            } catch (Exception e2) {
            }
        }
        return core;
    }
```

先不忙说长度，我们聊聊滥用事务

```java
            core.setResult(1);
            connection.commit();
             //  TZH 24.4.24 注销物流接口
//            connection2.commit();
        } catch (Exception e) {
            core.setV_errMsg(e.getMessage());
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                     //  TZH 24.4.24 注销物流接口
//                    connection2.rollback(); // 回滚事务
                } catch (Exception e2) {
                }
            }
             //  TZH 24.4.24 注销物流接口
//            if (connection2 != null) {
//                try {
//                    connection.rollback(); // 回滚事务
//                    connection2.rollback(); // 回滚事务
//                } catch (Exception e2) {
//                }
//            }
        } finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
                 //  TZH 24.4.24 注销物流接口
//                if (connection2 != null && !connection2.isClosed()) {
//                    connection2.close();
//                }
            } catch (Exception e2) {
            }
        }
        return core;
```

> 1、明显采取隐藏事务方式
> 
> 2、也就是说，他们任意请求抬手就是事务
> 
> 3、异常随意丢弃

 我们再来聊聊魔法参数

```java
String sqlupdate2 = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.updatePlnZyRclM2");// 修改加工计划表从表的实际上料支吨
            PreparedStatement patupdate2 = connection
                    .prepareStatement(sqlupdate2);

            String sqlupdatepln = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.updatePlnZyRclMpln");// 修改加工计划表
            PreparedStatement patupdatepln = connection
                    .prepareStatement(sqlupdatepln);
            String addPlnInfo = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.AddComInfoResult");// 新增公共信息
            PreparedStatement patsPlan = connection
                    .prepareStatement(addPlnInfo);
            String deleteButt = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.deleteButter");// 删除位置表
            PreparedStatement patsButt = connection
                    .prepareStatement(deleteButt);
            String updateMat = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.updateMatZcPlan");// 修改库存状态
            PreparedStatement patsUpMat = connection
                    .prepareStatement(updateMat);
```

其中

PreparedStatement patupdatepln = connection  
       .prepareStatement(sqlupdatepln);

就是定义一个带参数的请求的参数。

```java
// 新增加工公共信息
            patsPlan.setObject(1, resultNo);
            patsPlan.setObject(2, pln.getZyBatchId());
            patsPlan.setObject(3, "");
            patsPlan.setObject(4, pln.getProPlanId());
            patsPlan.setObject(5, pln.getGxPlanNo());
            patsPlan.setObject(6, pln.getOrderSource());
            patsPlan.setObject(7, pln.getOrderNo());
            patsPlan.setObject(8, pln.getOrderSeq());
            patsPlan.setObject(9, pln.getReqBlId());
            patsPlan.setObject(10, pln.getPlineCode());
            patsPlan.setObject(11, pln.getPlineName());
            patsPlan.setObject(12, gx);
            patsPlan.setObject(13, gx);
            patsPlan.setObject(14, "");
            patsPlan.setObject(15, "");
            patsPlan.setObject(16, pln.getSteelcode());
            patsPlan.setObject(17, pln.getSteelname());
            patsPlan.setObject(18, pln.getOutdiameter());
            patsPlan.setObject(19, pln.getWallthick());
            patsPlan.setObject(20, "");
            patsPlan.setObject(21, "");
            patsPlan.setObject(22, "");
            patsPlan.setObject(23, "");
            patsPlan.setObject(24, "");
            patsPlan.setObject(25, "");
            patsPlan.setObject(26, "");
            patsPlan.setObject(27, "");
            patsPlan.setObject(28, pln.getOutwlId());
            patsPlan.setObject(29, pln.getOutwlDesc());
            patsPlan.setObject(30, pln.getInwlId());
            patsPlan.setObject(31, pln.getInwlDesc());
            patsPlan.setObject(32, pln.getMonitorPoint());
            patsPlan.setObject(33, Result.getIfMonitorRcl());
            patsPlan.setObject(34, pln.getPrdcrNo());
            patsPlan.setObject(35, Result.getProducer());
            if (Result.getProducer().equals("")) {
                patsPlan.setObject(36, "");
            } else {
                patsPlan.setObject(36, Result.getProducerTime());
            }
            patsPlan.setObject(37, pln.getStationRoad());
            patsPlan.setObject(38, pln.getCraftFileNo());
            patsPlan.setObject(39, pln.getCraftFileMan());
            patsPlan.setObject(40, pln.getCraftSeq());
            patsPlan.setObject(41, Result.getProNum());
            patsPlan.setObject(42, TWt);
            patsPlan.setObject(43, Result.getFailNum());
            patsPlan.setObject(44, Result.getFailWt());
            patsPlan.setObject(45, Result.getOfflineNum());
            patsPlan.setObject(46, Result.getOfflineWt());
            patsPlan.setObject(47, Result.getReNum());
            patsPlan.setObject(48, Result.getReWt());
            patsPlan.setObject(49, "1");
            patsPlan.setObject(50, Result.getLoadTime());
            patsPlan.setObject(51, "");
            patsPlan.setObject(52, Result.getLoadShift());
            patsPlan.setObject(53, Result.getLoadGroup());
            patsPlan.setObject(54, "1");
            patsPlan.setObject(55, Result.getCreateTime());
            patsPlan.setObject(56, Result.getCreatetUser());
            patsPlan.setObject(57, pln.getHeatPlanNo());
            patsPlan.setObject(58, pln.getJudgeStoveNo());
            patsPlan.setObject(59, Result.getBatchNo());
            patsPlan.setObject(60, Result.getBatchGroudNo());
            patsPlan.setObject(61, pln.getProduccode());
            patsPlan.setObject(62, pln.getProducname());
            patsPlan.setObject(63, Result.getOutnumCut());
            patsPlan.setObject(64, pln.getSpecCode());
            patsPlan.setObject(65, pln.getSpecName());
            patsPlan.addBatch();
```

魔法赋值，如果错一个位置，整个sql无效

#### 我们来看看他的魔法sql

```xml
    <query id="FrmMcpLoading.AddComInfoResult" desc=" 新增公共信息">
        <![CDATA[ 
        INSERT INTO MCH_COM_INFO (RESULT_NO, ZY_BATCH_ID,PROD_INDEX,PRO_PLAN_ID, 
  GX_PLAN_NO, ORDER_SOURCE, ORDER_NO, ORDER_SEQ, REQ_BL_ID, PLINE_CODE, 
  PLINE_NAME, STATION_CODE, STATION_DESC, GRADECODE, GRADENAME, STEELCODE, 
  STEELNAME, DIMATER, HEIGHT, ACT_DIMATER, ACT_SPEC_CODE, ACT_SPEC_NAME, LEN, ACT_LEN_MIN, 
  ACT_LEN_MAX, LEN_CUT_HEAD, LEN_CUT_END, ACT_MATERIAL_NO, ACT_MATERIAL_NAME, INWL_ID, INWL_DESC, 
  MONITOR_POINT, IF_MONITOR_MCH, PRDCR_NO, PRODUCER, PRODUCER_TIME, STATION_ROAD, 
  CRAFT_FILE_NO, CRAFT_FILE_MAN, CRAFT_SEQ, PRO_NUM, PRO_WT, FAIL_NUM, FAIL_WT, 
  OFFLINE_NUM, OFFLINE_WT, RE_NUM, RE_WT, STATION_STATUS, RRO_TIME, RRO_TIME_NU, 
   PRO_SHIFT, PRO_GROUP, VALIDFLAG, CREATE_TIME, COL_OPERATOR, 
  HEAT_PLAN_NO,JUDGE_STOVE_NO,BATCH_NO,BATCH_GROUD_NO,
  PRODUCCODE,PRODUCNAME,OUTNUM_CUT,SPEC_CODE,SPEC_NAME) VALUES (?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?, ?, (SELECT T.BASENAME FROM COM_BASE_INFO T WHERE T.BASECODE = ?), ?, ?, ?, ?, ?, ?, 
  ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'), 
  ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?, ?, TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'), 
  ?, ?, ?, ?, TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'), ?, ?, ?, ?, ?, ?, ?,?,?,?) 
        ]]>
    </query>
```

> 1、query标签里放insert就是常规操作
> 
> 2、并非mybatis框架
> 
> 3、sql里满是问号。随便动几个问号就会引起维护不走

## 总结

以上只是该系统里最简单的插入业务
