Bladeren bron

添加注册接口认证校验

callm 2 weken geleden
bovenliggende
commit
2ab59cf424

+ 16 - 0
UAS_MES_YDCY/.workbuddy/memory/2026-11-11.md

@@ -0,0 +1,16 @@
+# 2026-11-11
+
+## 6 个界面 SN 录入加 MDM 注册校验
+- LogicHandler 新增公用方法 `CheckMDMRegistrationLog(iSN, iMakeCode, out err)`:SN 在 `MDMREGISTRATIONLOG.MRL_SNCODE` 中存在才调 `CheckMDMRegistration`(iSourceCode/iUserCode 用 User.UserSourceCode/User.UserCode);未登记直接 true。
+- 插入位置(CheckStepSNAndMacode 成功分支内、拿到 oMakeCode 之后):
+  - Make_FuselageLabelPrint:回车分支成功内,nextstepcode 判断前(sncode.Text)
+  - Make_SNLabelCheckFuge:两处——UnLoading 下料分支 + GetCollectItem(code.Text)
+  - Packing_PackageCollection / PackageCollectionPallet / PackageCollectionPalletNoWeigh / PackageCollectionWeigh:oMsID 补齐 if 块之后、ms_status=="2" 判断前(sn_code.Text)
+  - Packing 系列放 oMsID 补齐之后是因为成功分支可能是 `|| ms_status=="2"`,那时 oMakeCode 要等补齐才有值
+- 失败提示:`<<" + err`,红字,输出控件分别为 sncode/code/sn_code。
+
+## EIS 接口 500 修复:请求体改 form-data
+- 根因:接口不是 raw JSON,而是 **multipart/form-data**,字段名固定 `data`,值为 JSON 字符串(Postman 截图证实,raw JSON 直接 500)。
+- `PostEisHelper` 已改:`ContentType = "multipart/form-data; boundary=..."`,body 为 `--boundary / Content-Disposition: form-data; name="data" / 空行 / JSON / --boundary--`;5 个鉴权 Header 不变。
+- catch 拆出 `WebException`:500 等非 200 时读取 `wex.Response` 流,把服务端返回报文拼进错误信息,便于排查。
+- 签名算法仍未确认(MD5(Accesskey+AccessSecret+Timestamp) 占位),接口这次 500 是请求格式问题不是签名问题。

+ 6 - 0
UAS_MES_YDCY/FunctionCode/Make/Make_FuselageLabelPrint.cs

@@ -141,6 +141,12 @@ namespace UAS_MES_NEW.Make
                         oMakeCode = ma_code.Text;
                     if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsId, out oErrorMessage))
                     {
+                        //SN 在 MDMREGISTRATIONLOG 中登记过则调接口校验 MDM 注册,未通过直接拦截
+                        if (!LogicHandler.CheckMDMRegistrationLog(sncode.Text, oMakeCode, out oErrorMessage))
+                        {
+                            OperateResult.AppendText("<<" + oErrorMessage + "\n", Color.Red, sncode);
+                            return;
+                        }
                         string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsId + "'").ToString();
                         if (nextstepcode != User.CurrentStepCode)
                         {

+ 12 - 0
UAS_MES_YDCY/FunctionCode/Make/Make_SNLabelCheckFuge.cs

@@ -298,6 +298,12 @@ namespace UAS_MES_NEW.Make
                     {
                         if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, code.Text, User.UserCode, out oMakeCode, out oMsid, out ErrorMessage))
                         {
+                            //SN 在 MDMREGISTRATIONLOG 中登记过则调接口校验 MDM 注册,未通过直接拦截
+                            if (!LogicHandler.CheckMDMRegistrationLog(code.Text, oMakeCode, out ErrorMessage))
+                            {
+                                OperateResult.AppendText("<<" + ErrorMessage + "\n", Color.Red, code);
+                                return;
+                            }
                             sql.Clear();
                             sql.Append("select ms_firstsn,cm_makecode,cm_craftcode,nvl(cm_status,0)cm_status,cm_id,cm_stepcode,");
                             sql.Append("ms_makecode,cm_mccode,cm_materialtype from craftmaterial left join makeserial on cm_makecode");
@@ -354,6 +360,12 @@ namespace UAS_MES_NEW.Make
         {
             if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, code.Text, User.UserCode, out oMakeCode, out oMsid, out ErrorMessage))
             {
+                //SN 在 MDMREGISTRATIONLOG 中登记过则调接口校验 MDM 注册,未通过直接拦截
+                if (!LogicHandler.CheckMDMRegistrationLog(code.Text, oMakeCode, out ErrorMessage))
+                {
+                    OperateResult.AppendText("<<" + ErrorMessage + "\n", Color.Red, code);
+                    return;
+                }
                 nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsid + "'").ToString();
                 if (nextstepcode != User.CurrentStepCode)
                 {

+ 6 - 0
UAS_MES_YDCY/FunctionCode/Packing/Packing_PackageCollection.cs

@@ -251,6 +251,12 @@ namespace UAS_MES_NEW.Packing
                             oMsStatus = dt.Rows[0]["ms_status"].ToString();
                             oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
                         }
+                        //SN 在 MDMREGISTRATIONLOG 中登记过则调接口校验 MDM 注册,未通过直接拦截
+                        if (!LogicHandler.CheckMDMRegistrationLog(sn_code.Text, oMakeCode, out ErrorMessage))
+                        {
+                            OperateResult.AppendText("<<" + ErrorMessage + "\n", Color.Red, sn_code);
+                            return;
+                        }
                         //如果是已完工序列号验证装箱工序是否存在于途程中
                         if (oMsStatus == "2")
                         {

+ 6 - 0
UAS_MES_YDCY/FunctionCode/Packing/Packing_PackageCollectionPallet.cs

@@ -296,6 +296,12 @@ namespace UAS_MES_NEW.Packing
                             oMsStatus = dt.Rows[0]["ms_status"].ToString();
                             oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
                         }
+                        //SN 在 MDMREGISTRATIONLOG 中登记过则调接口校验 MDM 注册,未通过直接拦截
+                        if (!LogicHandler.CheckMDMRegistrationLog(sn_code.Text, oMakeCode, out ErrorMessage))
+                        {
+                            OperateResult.AppendText("<<" + ErrorMessage + "\n", Color.Red, sn_code);
+                            return;
+                        }
                         //如果是已完工序列号验证装箱工序是否存在于途程中
                         if (oMsStatus == "2")
                         {

+ 6 - 0
UAS_MES_YDCY/FunctionCode/Packing/Packing_PackageCollectionPalletNoWeigh.cs

@@ -280,6 +280,12 @@ namespace UAS_MES_NEW.Packing
                             oMsStatus = dt.Rows[0]["ms_status"].ToString();
                             oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
                         }
+                        //SN 在 MDMREGISTRATIONLOG 中登记过则调接口校验 MDM 注册,未通过直接拦截
+                        if (!LogicHandler.CheckMDMRegistrationLog(sn_code.Text, oMakeCode, out ErrorMessage))
+                        {
+                            OperateResult.AppendText("<<" + ErrorMessage + "\n", Color.Red, sn_code);
+                            return;
+                        }
                         //如果是已完工序列号验证装箱工序是否存在于途程中
                         if (oMsStatus == "2")
                         {

+ 6 - 0
UAS_MES_YDCY/FunctionCode/Packing/Packing_PackageCollectionWeigh.cs

@@ -327,6 +327,12 @@ namespace UAS_MES_NEW.Packing
                             oMsStatus = dt.Rows[0]["ms_status"].ToString();
                             oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
                         }
+                        //SN 在 MDMREGISTRATIONLOG 中登记过则调接口校验 MDM 注册,未通过直接拦截
+                        if (!LogicHandler.CheckMDMRegistrationLog(sn_code.Text, oMakeCode, out ErrorMessage))
+                        {
+                            OperateResult.AppendText("<<" + ErrorMessage + "\n", Color.Red, sn_code);
+                            return;
+                        }
                         if (oMsStatus == "2")
                         {
                             string prodcode = dt.Rows[0]["ms_prodcode"].ToString();

+ 41 - 2
UAS_MES_YDCY/PublicMethod/LogicHandler.cs

@@ -2163,14 +2163,20 @@ namespace UAS_MES_NEW.PublicMethod
 
                 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(EIS_URL);
                 request.Method = "POST";
-                request.ContentType = "application/json";
                 request.Timeout = 30 * 1000;
                 request.Headers.Add("Accesskey", EIS_ACCESSKEY);
                 request.Headers.Add("Requestid", requestId);
                 request.Headers.Add("AccessSecret", EIS_ACCESSSECRET);
                 request.Headers.Add("Signature", signature);
                 request.Headers.Add("Timestamp", timestamp);
-                byte[] data = Encoding.UTF8.GetBytes(postData);
+                //接口按 form-data 方式接收:字段名固定为 data,值为上面的 JSON 字符串(与 Postman form-data 一致)
+                string boundary = "----Boundary" + System.DateTime.Now.Ticks.ToString("x");
+                request.ContentType = "multipart/form-data; boundary=" + boundary;
+                string formBody = "--" + boundary + "\r\n"
+                    + "Content-Disposition: form-data; name=\"data\"\r\n\r\n"
+                    + postData + "\r\n"
+                    + "--" + boundary + "--\r\n";
+                byte[] data = Encoding.UTF8.GetBytes(formBody);
                 request.ContentLength = data.Length;
                 using (Stream rs = request.GetRequestStream())
                 {
@@ -2182,6 +2188,24 @@ namespace UAS_MES_NEW.PublicMethod
                     return sr.ReadToEnd();
                 }
             }
+            catch (WebException wex)
+            {
+                //非 200 响应时尽量把服务端返回的报文带出来,便于排查
+                string respText = "";
+                try
+                {
+                    if (wex.Response != null)
+                    {
+                        using (StreamReader sr = new StreamReader(wex.Response.GetResponseStream(), Encoding.UTF8))
+                        {
+                            respText = sr.ReadToEnd();
+                        }
+                    }
+                }
+                catch { }
+                iErrorMessage = "请求EIS接口失败:" + wex.Message + (respText == "" ? "" : ",接口返回:" + respText);
+                return null;
+            }
             catch (Exception ex)
             {
                 iErrorMessage = "请求EIS接口失败:" + ex.Message;
@@ -2272,6 +2296,21 @@ namespace UAS_MES_NEW.PublicMethod
             }
         }
 
+        /// <summary>
+        /// MDM 注册前置校验:SN 存在于 MDMREGISTRATIONLOG 表 MRL_SNCODE 字段中时,才调用 CheckMDMRegistration 接口校验
+        /// 未登记或接口校验通过返回 true;接口校验不通过返回 false 并给出接口实际错误信息
+        /// </summary>
+        public static bool CheckMDMRegistrationLog(string iSN, string iMakeCode, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            //SN 不在 MDMREGISTRATIONLOG 中登记,无需调接口校验
+            if (dh.getFieldDataByCondition("MDMREGISTRATIONLOG", "count(1)", "MRL_SNCODE='" + iSN + "'").ToString() == "0")
+            {
+                return true;
+            }
+            return CheckMDMRegistration(iSN, iMakeCode, User.UserSourceCode, User.UserCode, out oErrorMessage);
+        }
+
         /// <summary>
         /// 取 JSON 对象里的字符串值(键不存在或值为 null 时返回空串)
         /// </summary>