Bladeren bron

工序计件增加对接模型

xuwei 3 jaren geleden
bovenliggende
commit
aeae39ab27
2 gewijzigde bestanden met toevoegingen van 87 en 174 verwijderingen
  1. 71 80
      DK.Service/CMNModuleService/PLCWorkLogic..cs
  2. 16 94
      DK.Service/PMModuleLogic/PMModuleLogicDAL.cs

+ 71 - 80
DK.Service/CMNModuleService/PLCWorkLogic..cs

@@ -52,24 +52,22 @@ namespace Dongke.IBOSS.PRD.Service.CMNModuleService
 
                 try
                 {
-                    //冯林勇 modify 2022-08-19 注释掉写入PCL数据
                     //按当前登录用户在工位表中的当前工号查找工位类型
-                    //workStationType = getWorkStationType(conn, sUserInfo.UserCode);
-                    //DataTable dataTable = GetWorkStationInfo(conn, sUserInfo.UserCode);
-                    //if (dataTable == null || dataTable.Rows.Count == 0)
-                    //{
-                    //    return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "当前工号无工位信息" };
-                    //}
-
-                    //if (dataTable.Columns.Contains("PLC_FLAG"))
-                    //{
-                    //    string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
-                    //    if (plc_flag != "1")
-                    //    {
-                    //        return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
-                    //    }
-                    //}
-                    //冯林勇 modify 2022-08-19 注释掉写入PCL数据
+                    workStationType = getWorkStationType(conn, sUserInfo.UserCode);
+                    DataTable dataTable = GetWorkStationInfo(conn, sUserInfo.UserCode);
+                    if (dataTable == null || dataTable.Rows.Count == 0)
+                    {
+                        return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "当前工号无工位信息" };
+                    }
+
+                    if (dataTable.Columns.Contains("PLC_FLAG"))
+                    {
+                        string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
+                        if (plc_flag != "1")
+                        {
+                            return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
+                        }
+                    }
                     workStationType = 3211;
 
                     //成检交接3211
@@ -323,32 +321,32 @@ t.plc_flag
                 new CDAParameter("WORKSTATIONTYPE", workStationType),
                 new CDAParameter("USERCODE", userCode)
              );
-            //冯林勇 modify 2022-08-19 注释掉写入PCL数据
-            //if (dataTable == null || dataTable.Rows.Count == 0)
-            //{
-            //    return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "当前工号无工位信息" };
-            //}
-
-            //if (dataTable.Columns.Contains("PLC_FLAG"))
-            //{
-            //    string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
-            //    if (plc_flag != "1")
-            //    {
-            //        return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
-            //    }
-            //}
-            //string ip = dataTable.Rows[0]["PLCIP"] + "";
-            //if (string.IsNullOrWhiteSpace(ip))
-            //{
-            //    return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
-            //}
-            //int port = Convert.ToInt32(dataTable.Rows[0]["PLCPORT"]);
-            //         JArray plcObj = JArray.Parse(dataTable.Rows[0]["PLCOBJECT"].ToString());
-            //冯林勇 modify 2022-08-19 注释掉写入PCL数据
+
+            if (dataTable == null || dataTable.Rows.Count == 0)
+            {
+                return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "当前工号无工位信息" };
+            }
+
+            if (dataTable.Columns.Contains("PLC_FLAG"))
+            {
+                string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
+                if (plc_flag != "1")
+                {
+                    return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
+                }
+            }
+            string ip = dataTable.Rows[0]["PLCIP"] + "";
+            if (string.IsNullOrWhiteSpace(ip))
+            {
+                return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
+            }
+            int port = Convert.ToInt32(dataTable.Rows[0]["PLCPORT"]);
+            JArray plcObj = JArray.Parse(dataTable.Rows[0]["PLCOBJECT"].ToString());
+
             //写入PLC
             using (SocketClient<SiemensS7_1200Model> plc = new SocketClient<SiemensS7_1200Model>())
             {
-                //冯林勇 modify 2022-08-19 注释掉写入PCL数据
+
                 //测试静态数据 测试成功
                 //plc.Connect(ip, port);
                 //plc.Write<string>("D", "102.2", "2020070101");
@@ -360,15 +358,14 @@ t.plc_flag
                 //plc.Write<short>("D", "102.14", Convert.ToInt16(plcPara["goodsmodel"]));
 
                 //自动按配置写
-                //plc.Connect(ip, port);
-                //for (int i = 0; i < plcObj.Count; i++)
-                //{
-                //    if (plcObj[i]["type"].ToString().ToLower() == "string")
-                //        plc.Write<string>(plcObj[i]["code"].ToString(), plcObj[i]["number"].ToString(), plcPara[plcObj[i]["name"].ToString()].ToString());
-                //    else if (plcObj[i]["type"].ToString().ToLower() == "int")
-                //        plc.Write<short>(plcObj[i]["code"].ToString(), plcObj[i]["number"].ToString(), Convert.ToInt16(plcPara[plcObj[i]["name"].ToString()]));
-                //}
-                //冯林勇 modify 2022-08-19 注释掉写入PCL数据
+                plc.Connect(ip, port);
+                for (int i = 0; i < plcObj.Count; i++)
+                {
+                    if (plcObj[i]["type"].ToString().ToLower() == "string")
+                        plc.Write<string>(plcObj[i]["code"].ToString(), plcObj[i]["number"].ToString(), plcPara[plcObj[i]["name"].ToString()].ToString());
+                    else if (plcObj[i]["type"].ToString().ToLower() == "int")
+                        plc.Write<short>(plcObj[i]["code"].ToString(), plcObj[i]["number"].ToString(), Convert.ToInt16(plcPara[plcObj[i]["name"].ToString()]));
+                }
 
             }
 #if DEBUG
@@ -478,7 +475,7 @@ t.plc_flag
 #endregion
 
         /// <summary>
-        /// 写PLC2
+        /// 写PLC2 xuwei modify 2022-09-10 优化代码
         /// </summary>
         /// <param name="workStationType"></param>
         /// <param name="plcPara"></param>
@@ -490,30 +487,33 @@ t.plc_flag
             {
                 List<CDAParameter> paras = new List<CDAParameter>();
 
-#region 读取工位配置信息
-                string sql =
-                        "SELECT --t.*\n" + @"
-t.workstationtypeid, 
-t.workstationname, 
-t.procedureid, 
-t.groutinglineid, 
-t.usercode, 
-t.pccode, 
-t.plcip, 
-t.plcport, 
-t.plcobject,
-t.valueflag,
-t.plcobjectread, 
-t.plc_flag" +
-                        "  FROM tp_mst_workstation t\n" +
-                        " WHERE t.workstationtypeid = @workstationtype@";
-
-                paras.Add(new CDAParameter("workstationtype", workStationType));
+                #region 读取工位配置信息
+                string sql = @"
+                    SELECT
+                        T.WORKSTATIONTYPEID, 
+                        T.WORKSTATIONNAME, 
+                        T.PROCEDUREID, 
+                        T.GROUTINGLINEID, 
+                        T.USERCODE, 
+                        T.PCCODE, 
+                        T.PLCIP, 
+                        T.PLCPORT, 
+                        T.PLCOBJECT,
+                        T.VALUEFLAG,
+                        T.PLCOBJECTREAD, 
+                        T.PLC_FLAG
+                    FROM 
+                        TP_MST_WORKSTATION T
+                    WHERE 
+                        T.PLC_FLAG = 1
+                        AND T.WORKSTATIONTYPEID = @WORKSTATIONTYPE@
+                    ";
+                paras.Add(new CDAParameter("WORKSTATIONTYPE", workStationType));
 
                 if (!string.IsNullOrEmpty(userCode))
                 {
-                    sql += " AND t.usercode = @usercode@";
-                    paras.Add(new CDAParameter("usercode", userCode));
+                    sql += " AND T.USERCODE = @USERCODE@";
+                    paras.Add(new CDAParameter("USERCODE", userCode));
                 }
 
                 DataTable dataTable = conn.ExecuteDatatable(sql, paras.ToArray());
@@ -529,15 +529,6 @@ t.plc_flag" +
                     };
                     //xuwei end
                 }
-
-                if (dataTable.Columns.Contains("PLC_FLAG"))
-                {
-                    string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
-                    if (plc_flag != "1")
-                    {
-                        return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
-                    }
-                }
                 #endregion
 
                 string ip = dataTable.Rows[0]["PLCIP"] + "";

+ 16 - 94
DK.Service/PMModuleLogic/PMModuleLogicDAL.cs

@@ -75,11 +75,11 @@ namespace Dongke.IBOSS.PRD.Service.PMModuleLogic
         public static DataTable AddWorkPiece(int procedureID, DataTable barcodeTable, SUserInfo sUserInfo, out ProcedureEntity procedureInfo)
         {
             #region xuwei add 2022-09-08 提交监控数据
-            SendData(
-                "procedureid=" + procedureID 
-                + "&barcode="+barcodeTable.Rows[0]["Barcode"].ToString()
-                + "&usercode="+sUserInfo.UserCode
-                );
+            //SendData(
+            //    "procedureid=" + procedureID 
+            //    + "&barcode="+barcodeTable.Rows[0]["Barcode"].ToString()
+            //    + "&usercode="+sUserInfo.UserCode
+            //    );
             #endregion
 
             procedureInfo = null;
@@ -627,102 +627,24 @@ namespace Dongke.IBOSS.PRD.Service.PMModuleLogic
                 dtBarCode.Rows.Add(dr);
                 #endregion
 
-                // 工序保存有错误时,不进行后续PLC操作 add by chenxy 2020-09-18
+
                 if (string.IsNullOrEmpty(errMsg))
                 {
                     errMsg = dtBarCode.Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()] + "";
                 }
-                // 工序保存有错误时,不进行后续PLC操作
-                //if (!string.IsNullOrEmpty(errMsg))
-                //{
-                    // 如果是3#刮蹬,调用PLC接口 2020-09-07 fubin
-                    //if (procedure.ProcedureID == 99)
-                    //{
-                    //    string sql =
-                    //    "select t.flowprocedureid from tp_pm_inproduction t where t.barcode ='" + barcodeTable.Rows[0]["Barcode"] + "'";
-                    //    object flowprocedureid = oracleTrConn.GetSqlResultToObj(sql);
-                    //    if (flowprocedureid + "" == "99")
-                    //    {
-                    //        Hashtable plcPara = new Hashtable();
-                    //        plcPara.Add("finishflag", 1);
-                    //        string errMsg1 = PLCModuleLogic.PlcWrite2(3201, plcPara).Message;
-                    //        if (string.IsNullOrEmpty(errMsg1))
-                    //        {
-                    //            errMsg1 = System.Environment.NewLine + "【PLC】线体可以放行";
-                    //        }
-                    //        else
-                    //        {
-                    //            errMsg1 = System.Environment.NewLine + "【PLC】" + errMsg1;
-                    //        }
-                    //        dtBarCode.Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()] = errMsg + errMsg1;
-                    //    }
-                    //}
-
-                    // errMsg 有值,dtBarCode中无值时,要写入dtBarCode中,将错误信息返回给前台
-                    //string mm = dtBarCode.Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()] + "";
-                    //if (mm != errMsg)
-                    //{
-                    //    dtBarCode.Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()] = errMsg;
-                    //}
-                    //return dtBarCode;
-                //}
-
-                // 如果是3#包装,更新三车间包装标识
-                //if (procedure.ProcedureID == 107)
-                //{
-                //    string sql = string.Empty;
-                //    int r = 0;
-                //    foreach (DataRow row in barcodeTable.Rows)
-                //    {
-                //        sql =
-                //        "UPDATE tp_pm_groutingdailydetail gdd\n" +
-                //        "   SET gdd.packingby3 = '1'\n" +
-                //        " WHERE gdd.barcode = '" + row["Barcode"] + "'";
-
-                //        r += oracleTrConn.ExecuteNonQuery(sql);
-                //    }
-                //}
-
-                // 如果是3#上水,调用PLC接口 2020-09-03 fubin
-                //if (procedure.ProcedureID == 94)
-                //{
-                    /* 暂时不对接,上水机械臂暂停 2020-10-24 chenxy
-                    string sql =
-                    "SELECT g.seatcovercode\n" +
-                    "  FROM tp_pm_groutingdailydetail p\n" +
-                    "  LEFT JOIN tp_mst_goods g\n" +
-                    "    ON g.goodsid = p.goodsid\n" +
-                    " WHERE p.valueflag = '1'\n" +
-                    "   AND p.barcode = '" + barcodeTable.Rows[0]["Barcode"] + "'";
-
-                    object goodsModel = oracleTrConn.GetSqlResultToObj(sql);
 
+                #region xuwei add 2022-09-10 PDA扫码后的PLC写入操作(用于施釉4+1线)
+                //机械施釉4+1线 工序ID = 37
+                if (procedure.ProcedureID == 37)
+                {
                     Hashtable plcPara = new Hashtable();
+                    plcPara.Add("goodsid", goodsID);
+                    plcPara.Add("barcode", barcodeTable.Rows[0]["Barcode"]);
+                    plcPara.Add("finishflag", 1);
+                    errMsg = PLCModuleLogic.PlcWrite2(1110, plcPara, sUserInfo.UserCode).Message;
+                }
+                #endregion
 
-                    if (goodsModel.ToInt32() != 0)
-                    {
-                        plcPara.Add("goodsmodel", goodsModel);
-                        plcPara.Add("finishflag", 1);
-                        plcPara.Add("errorflag", 0);
-                    }
-                    else
-                    {
-                        plcPara.Add("goodsmodel", 0);
-                        plcPara.Add("finishflag", 1);
-                        plcPara.Add("errorflag", 1);
-                    }
-                    errMsg = PLCModuleLogic.PlcWrite2(3320, plcPara, sUserInfo.UserCode).Message;
-                    */
-                //}
-
-                // 如果是3#刮蹬,调用PLC接口 2020-09-07 fubin
-                //if (procedure.ProcedureID == 99)
-                //{
-                //    Hashtable plcPara = new Hashtable();
-                //    plcPara.Add("finishflag", 1);
-                //    //xuwei modify 2021-12-24 按打卡工号识别线号
-                //    errMsg = PLCModuleLogic.PlcWrite2(3201, plcPara, sUserInfo.UserCode).Message;
-                //}
 
                 // 没有错误 提交事务
                 if (string.IsNullOrEmpty(errMsg))