南骏 池
2025-05-13 3da0e2b539be6f7c9f22ecdefaeca677008501ca
MES->OA回写状态
已修改1个文件
40 ■■■■■ 文件已修改
service/QC/OaApi.cs 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/QC/OaApi.cs
@@ -36,7 +36,8 @@
    public async Task<dynamic> SubmitIQCToOA(dynamic queryObj)
    {
        // 修改参数验证字段名
        //if (queryObj.userId.IsNullOrEmpty()) throw new Exception("用户id不允许为空");
        if (string.IsNullOrEmpty(queryObj.userId.ToString())) throw new Exception("用户id不允许为空");
        if (string.IsNullOrEmpty(queryObj.qcczdGuid.ToString())) throw new Exception("异常处置单id不能为空");
        //if (queryObj.qcczdGuid.IsNullOrEmpty()) throw new Exception("异常处置单id不能为空"); // 原参数名为 qcczdGuid
        try
@@ -103,9 +104,42 @@
                }
            }
            return JObject.Parse(response.Content.ToString());  // 直接解析为JObject
            var result = JObject.Parse(response.Content.ToString());
            // 新增状态更新(当OA返回成功时)
            if (result.code?.ToString() == "SUCCESS")
            {
                var updateSql = @"UPDATE Mes_QC_Exceptional
SET checkStatus = 1,
    checkDate   = GETDATE(),
    checkBy     = (select top 1 u.[ACCOUNT] from [dbo].[SYS_USER] u where u.guid = @edtUserCode)
WHERE GUID = @inOrderGuid";
                using (var conn = new SqlConnection(DbHelperSQL.strConn))
                {
                    using (var cmd = new SqlCommand(updateSql, conn))
                    {
                        try
                        {
                            conn.Open();
                            //cmd.Parameters.AddWithValue("@dt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                            cmd.Parameters.AddWithValue("@edtUserCode", queryObj.userId?.ToString());
                            cmd.Parameters.AddWithValue("@inOrderGuid", queryObj.qcczdGuid?.ToString());
                            cmd.ExecuteNonQuery();
                        }
                        catch (Exception updateEx)
                        {
                            Console.WriteLine($"状态更新失败: {updateEx.Message}");
                        }
                        finally
                        {
                            conn.Close();
                        }
                    }
                }
            }
            return result;  // 直接解析为JObject
        }
        catch (Exception ex)
@@ -475,4 +509,4 @@
    {
        _httpClient?.Dispose();
    }
}
}