zrg
2026-02-27 7ca0d964d2df19bf56e8a8a96f34f26a139b078d
增加异常工艺参数预警通知
1个文件已添加
8个文件已修改
214 ■■■■ 已修改文件
DingDingMsg/.vs/DingDingMsg/DesignTimeBuild/.dtbcache.v2 补丁 | 查看 | 原始文档 | blame | 历史
DingDingMsg/.vs/DingDingMsg/v16/.suo 补丁 | 查看 | 原始文档 | blame | 历史
DingDingMsg/MesMessage/GeTuiService.cs 150 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DingDingMsg/MesMessage/MesMessageList.Designer.cs 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DingDingMsg/MesMessage/MesMessageList.cs 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DingDingMsg/MesMessage/bin/Debug/MesMessage.pdb 补丁 | 查看 | 原始文档 | blame | 历史
DingDingMsg/MesMessage/obj/Debug/DesignTimeResolveAssemblyReferences.cache 补丁 | 查看 | 原始文档 | blame | 历史
DingDingMsg/MesMessage/obj/Debug/MesMessage.csproj.GenerateResource.cache 补丁 | 查看 | 原始文档 | blame | 历史
DingDingMsg/MesMessage/obj/Debug/MesMessage.pdb 补丁 | 查看 | 原始文档 | blame | 历史
DingDingMsg/.vs/DingDingMsg/DesignTimeBuild/.dtbcache.v2
Binary files differ
DingDingMsg/.vs/DingDingMsg/v16/.suo
Binary files differ
DingDingMsg/MesMessage/GeTuiService.cs
@@ -2,7 +2,9 @@
using com.igetui.api.openservice.igetui;
using com.igetui.api.openservice.igetui.template;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
@@ -15,6 +17,8 @@
        private static readonly string APPID = "X3I10VqaROAH8C7ElIc1L5";
        private static readonly string APPKEY = "V425beWn5K65BcOYKTcXx8";
        private static readonly string MASTERSECRET = "LOXAgRbXS98NxHKUXmlJQ";
        static DBHelper oCN = new DBHelper();
        static DataSet ds = new DataSet();
        // 注意:不再声明静态 IGtPush 字段,避免类型初始化异常
@@ -23,61 +27,112 @@
        /// </summary>
        public static void PubishSingle(int HInterID)
        {
            try
            {
                DataSet ds = new DataSet();
                DBHelper oCN = new DBHelper();
                JObject NameMsgKVP = new JObject();
                ds = oCN.RunProcReturn($@"
                    select * from h_v_OA_WorkLinkBillAllList where hmainid = {HInterID};
                    select * from h_v_OA_WorkLinkBillAllList where hmainid = {HInterID}
                    select * from Gy_UserClientIdRelation
                ", "h_v_OA_WorkLinkBillAllList");
                if (ds.Tables[0].Rows.Count == 0) return;
                DataRow billRow = ds.Tables[0].Rows[0];
                string title = billRow["主题"].ToString();
                string content = billRow["内容"].ToString();
                string sendType = billRow["发送类型"].ToString();
                string receiver = billRow["接收人"].ToString();
                string ccReceiver = billRow["抄送接收人"].ToString();
                // 创建通知模板
                var template = GetNotificationTemplate(
                    title,
                    content,
                    "/pages/ZLGL/OA_WorkLink/OA_WorkLinkBillQuery",
                    "0"
                );
                bool anySuccess = false;
                // 遍历所有客户端ID
                foreach (DataRow userRow in ds.Tables[1].Rows)
                NotificationTemplate template = null;
                ConcurrentDictionary<string, List<string>> userClientIDDictionary = new ConcurrentDictionary<string, List<string>>();
                // 将用户设备关联表 收集为 Map
                if (ds.Tables[1].Rows.Count > 0)
                {
                    string userName = userRow["HUserName"].ToString();
                    string clientId = userRow["HClientID"].ToString();
                    bool needPush = sendType == "公共" ||
                                    userName == receiver ||
                                    userName == ccReceiver;
                    if (needPush)
                    foreach (DataRow row in ds.Tables[1].Rows)
                    {
                        bool success = PushMessageToSingle(template, clientId);
                        if (success) anySuccess = true;
                        if (userClientIDDictionary.ContainsKey(row["HUserName"].ToString()))
                        {
                            userClientIDDictionary[row["HUserName"].ToString()].Add(row["HClientID"].ToString());
                        }
                        else
                        {
                            userClientIDDictionary.TryAdd(row["HUserName"].ToString(), new List<string>() { row["HClientID"].ToString() });
                        }
                    }
                }
                if (!anySuccess)
                if (ds.Tables[0].Rows.Count > 0)
                {
                    // 推送失败,备用方案:使用 RabbitMQ 或 WebSocket
                    DBHelper.CustomWriteLog("个推推送失败(可能内网原因),尝试备用方案", DateTime.Now.ToString("yyyy-MM-dd"));
                    // WebSocketServer.PushOne(HInterID);
                    string title = ds.Tables[0].Rows[0]["主题"].ToString();
                    string content = ds.Tables[0].Rows[0]["内容"].ToString();
                    template = GetNotificationTemplate(title, content, "/pages/ZLGL/OA_WorkLink/OA_WorkLinkBillQuery", "0"); // 跳转到工作联系单查询页面
                    bool pushSuccess = false;
                    // 广播
                    if (ds.Tables[0].Rows[0]["发送类型"].ToString() == "公共")
                    {
                        string rule = GetSystemRule();
                        if (rule == "华舟")
                        {
                            // 推送给接收人 和 抄送人
                            foreach (DataRow row in ds.Tables[0].Rows)
                            {
                                List<string> clientIDList = new List<string>();
                                if (userClientIDDictionary.ContainsKey(row["接收人"].ToString()))
                                {
                                    clientIDList = userClientIDDictionary[row["接收人"].ToString()];
                                }
                                else if (userClientIDDictionary.ContainsKey(row["抄送接收人"].ToString()))
                                {
                                    clientIDList = userClientIDDictionary[row["抄送接收人"].ToString()];
                                }
                                foreach (string clientID in clientIDList)
                                {
                                    pushSuccess = PushMessageToSingle(template, clientID);
                                }
                            }
                        }
                        else
                        {
                            // 遍历 全推送
                            foreach (DataRow row in ds.Tables[1].Rows)
                            {
                                pushSuccess = PushMessageToSingle(template, row["HClientID"].ToString());
                            }
                        }
                    }
                    else // 单独推送
                    {
                        // 推送给接收人 和 抄送人
                        foreach (DataRow row in ds.Tables[0].Rows)
                        {
                            List<string> clientIDList = new List<string>();
                            if (userClientIDDictionary.ContainsKey(row["接收人"].ToString()))
                            {
                                clientIDList = userClientIDDictionary[row["接收人"].ToString()];
                            }
                            else if (userClientIDDictionary.ContainsKey(row["抄送接收人"].ToString()))
                            {
                                clientIDList = userClientIDDictionary[row["抄送接收人"].ToString()];
                            }
                            foreach (string clientID in clientIDList)
                            {
                                pushSuccess = PushMessageToSingle(template, clientID);
                            }
                        }
                    }
                    if (!pushSuccess)
                    {
                        // 个推 推送不成功(内网环境) 使用webSocket进行推送
                        // TODO: 使用 rabbitMQ 实现消息队列
                        // WebSocketServer.PushOne(HInterID);
                    }
                }
            }
            catch (Exception ex)
            {
                DBHelper.CustomWriteLog($"PubishSingle 异常: {ex}", DateTime.Now.ToString("yyyy-MM-dd"));
                DBHelper.CustomWriteLog(ex.ToString(), DateTime.Now.ToString("yyyy-MM-dd"));
                return;
            }
        }
@@ -150,5 +205,18 @@
            return template;
        }
        /// <summary>
        /// 获取系统参数 OA_AndengFlowRule_XT 的值
        /// </summary>
        private static string GetSystemRule()
        {
            string sql = "select HValue from xt_SystemParameter where HKey='WMS_CampanyName'";
            DataSet ds = oCN.RunProcReturn(sql, "xt_SystemParameter");
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                return ds.Tables[0].Rows[0]["HValue"].ToString();
            return null;
        }
    }
}
DingDingMsg/MesMessage/MesMessageList.Designer.cs
@@ -43,16 +43,16 @@
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(132, 82);
            this.button1.Location = new System.Drawing.Point(96, 79);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(123, 44);
            this.button1.Size = new System.Drawing.Size(176, 46);
            this.button1.TabIndex = 0;
            this.button1.Text = "安灯呼叫运行中";
            this.button1.UseVisualStyleBackColor = true;
            // 
            // timer2
            // 
            this.timer2.Interval = 300000;
            this.timer2.Interval = 60000;
            this.timer2.Tick += new System.EventHandler(this.Timer1_Tick);
            // 
            // MesMessageList
@@ -62,7 +62,7 @@
            this.ClientSize = new System.Drawing.Size(424, 226);
            this.Controls.Add(this.button1);
            this.Name = "MesMessageList";
            this.Text = "Form1";
            this.Text = "安灯呼叫";
            this.ResumeLayout(false);
        }
DingDingMsg/MesMessage/MesMessageList.cs
@@ -145,14 +145,14 @@
                    return;
                }
                #region 异常工艺参数预警(每 5 分钟执行一次,但定时器为1分钟,所以内部判断时间差)
                #region 异常工艺参数预警(每 1 分钟执行一次,但定时器为1分钟,所以内部判断时间差)
                DBHelper.CustomWriteLog("开始进入执行循环 :", DateTime.Now.ToString("yyyy-MM-dd"));
             
                #endregion
                #region 异常工艺参数预警处理(每分钟执行)
                // 查询出要更新的异常参数(最近5分钟内的未发送数据)
                string Sql = "select HItemID from Sb_EquipMentCollectionTechParam_ERR where HCreateTime>=DATEADD(minute, - 4, GETDATE()) AND HSendFlag = 0";
                // 查询出要更新的异常参数(最近1分钟内的未发送数据)
                string Sql = "select HItemID from Sb_EquipMentCollectionTechParam_ERR where HCreateTime>=DATEADD(minute, - 1, GETDATE()) AND HSendFlag = 0";
                DBHelper.CustomWriteLog("查询出异常的参数:" + Sql, DateTime.Now.ToString("yyyy-MM-dd"));
                DataSet dsErr = oCN.RunProcReturn(Sql, "Sb_EquipMentCollectionTechParam_ERR");
                if (dsErr != null && dsErr.Tables[0].Rows.Count > 0)
@@ -242,7 +242,55 @@
                    }
                    else if (rule == "APP")
                    {
                        // 查询出要发信息的异常参数
                        string newSql = @"SELECT 工序名称, STUFF((
                                            SELECT DISTINCT '; ' + 设备编码 + ' - ' + 工艺参数名称 + ' - 数采值: ' + CAST(数采值 AS VARCHAR(10))
                                                   + ' - 上限值: ' + CAST(上限值 AS VARCHAR(10)) + ' - 下限值: ' + CAST(下限值 AS VARCHAR(10))
                                            FROM h_v_Sb_EquipMentCollectionTechParam_ERRList AS InnerTable
                                            WHERE InnerTable.工序名称 = OuterTable.工序名称
                                              AND 发现异常时间 >= DATEADD(minute, -1, GETDATE())
                                            FOR XML PATH('')), 1, 2, '') AS 内容
                                          FROM h_v_Sb_EquipMentCollectionTechParam_ERRList AS OuterTable
                                          GROUP BY 工序名称";
                        DataSet dsContent = oCN.RunProcReturn(newSql, "h_v_Sb_EquipMentCollectionTechParam_ERRList");
                        for (int j = 0; j < dsContent.Tables[0].Rows.Count; j++)
                        {
                            DBHelper.CustomWriteLog("异常内容数量   " + dsContent.Tables[0].Rows.Count, DateTime.Now.ToString("yyyy-MM-dd"));
                            string HContext = dsContent.Tables[0].Rows[j]["内容"].ToString();
                            string HDeptName = dsContent.Tables[0].Rows[j]["工序名称"].ToString();
                            if (!string.IsNullOrEmpty(HContext) && HContext.ToLower() != "null")
                            {
                                // 查询出要发送的人
                                string newSql1 = $@"select a.HDingDingUserID 钉钉id, a.Czymc 接收人
                                                from Gy_Czygl a
                                                left join System_UserGroupInfo b on a.Czybm = b.UserId
                                                left join System_UserGroup c on b.GroupId = c.GroupID
                                                where c.GroupName = '{HDeptName}工艺异常预警接收人'";
                                DataSet dsUsers = oCN.RunProcReturn(newSql1, "Gy_Czygl");
                                if (dsUsers.Tables[0].Rows.Count > 0)
                                {
                                    for (int i = 0; i < dsUsers.Tables[0].Rows.Count; i++)
                                    {
                                        string HName = dsUsers.Tables[0].Rows[i]["钉钉id"].ToString();
                                        var ds = oCN.RunProcReturn($"exec h_p_OA_WorkLinkBill_TechParam_ERR_Create '{HContext}','{HName}'", "h_p_OA_WorkLinkBill_TechParam_ERR_Create");
                                        if (ds != null && ds.Tables[0].Rows.Count > 0)
                                        {
                                            // 第一步:先获取字符串并判断是否为"0",是则直接跳过
                                            int newHInterID = int.Parse(ds.Tables[0].Rows[0]["HInterID"].ToString());
                                            if (newHInterID != 0)
                                            {
                                                DBHelper.CustomWriteLog($"执行消息推送...{newHInterID}", DateTime.Now.ToString("yyyy-MM-dd"));
                                                GeTuiService.PubishSingle(newHInterID); // 同步方法,若耗时较长可考虑异步优化
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion
DingDingMsg/MesMessage/bin/Debug/MesMessage.pdb
Binary files differ
DingDingMsg/MesMessage/obj/Debug/DesignTimeResolveAssemblyReferences.cache
Binary files differ
DingDingMsg/MesMessage/obj/Debug/MesMessage.csproj.GenerateResource.cache
Binary files differ
DingDingMsg/MesMessage/obj/Debug/MesMessage.pdb
Binary files differ