From db0b018fc17807947b9d1297eac71cb8430891bb Mon Sep 17 00:00:00 2001
From: zrg <z1873@LAPTOP-EAVL132E>
Date: 星期三, 25 二月 2026 15:10:48 +0800
Subject: [PATCH] 新增系统参数用于区分发送消息类型   新增桌面端 异常反馈发送信息方法, 老的控制台不知道app消息推送

---
 DingDingMsg_EarlyWarning/Program.cs |  331 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 265 insertions(+), 66 deletions(-)

diff --git a/DingDingMsg_EarlyWarning/Program.cs b/DingDingMsg_EarlyWarning/Program.cs
index b11be21..44302e6 100644
--- a/DingDingMsg_EarlyWarning/Program.cs
+++ b/DingDingMsg_EarlyWarning/Program.cs
@@ -20,15 +20,21 @@
             //鏂帿灏�
             string appKey = "dingkdddbhdcssk7jduw";
             string appSecret = "iv07c-GLfJPnzfJaNAAOfJDl3Z-eODvDAhlInMZCZhGorkle5Evbaxx3ImylvdjQ";
-            Console.WriteLine("绋嬪簭姝e湪鎵ц,璇蜂笉瑕佸叧闂�!!!!");
+            Console.WriteLine("绋嬪簭2姝e湪鎵ц,璇蜂笉瑕佸叧闂�!!!!");
+            string HDeptName = "";
+            string HWarningDate = "10";
+            string HRecordDate = DateTime.MinValue.ToString();
+            string HRecordDate_spc = "";
             // 璁板綍涓婃鎵ц鏂板畾鏃朵换鍔$殑鏃堕棿
             while (true)
             {
-                //鏌ユ壘璁惧淇濆吇棰勮
-                string sql = "SELECT a.HInterID,b.HEntryID,c.HEquipFileNo 璁惧缂栫爜, c.HName 璁惧鍚嶇О FROM Sb_EquipMaintainPlanBillMain a " +
+                #region 鏌ユ壘璁惧淇濆吇棰勮
+                string sql = "SELECT a.HInterID,b.HEntryID,c.HEquipFileNo 璁惧缂栫爜, c.HName 璁惧鍚嶇О,d.HName 璁惧閮ㄩ棬 FROM Sb_EquipMaintainPlanBillMain a " +
                     "INNER JOIN Sb_EquipMaintainPlanBillSub_Plan b ON a.HInterID = b.HInterID " +
                     "LEFT JOIN Gy_EquipFileBillMain c ON a.HEquipID = c.HInterID " +
-                    "WHERE CAST(CONVERT(datetime, b.HErrBeginTime, 120) AS DATE) = CAST(GETDATE() AS DATE) and HSendFlag = '0'";
+                    "LEFT JOIN Gy_Department d ON a.HDeptID = d.HItemID " +
+                   " WHERE  CONVERT(date, b.HErrBeginTime, 120) = CONVERT(date, GETDATE(), 120) and HSendFlag = '0'";
+                DBHelper.CustomWriteLog("鏌ヨ璁惧淇濆吇璁″垝:" + sql, DateTime.Now.ToString("yyyy-MM-dd"));
                 dt = oCN.RunProcReturn(sql, "Sb_EquipMaintainPlanBillMain");
                 //璁惧淇濆吇棰勮鑷姩鍙戜俊鎭�
                 if (dt.Tables[0].Rows.Count > 0)
@@ -37,72 +43,15 @@
 
                     for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
                     {
-                        HContext = "璁惧缂栫爜涓�:"+dt.Tables[0].Rows[i]["璁惧缂栫爜"].ToString()+ ",璁惧鍚嶇О涓�:"+dt.Tables[0].Rows[i]["璁惧鍚嶇О"].ToString()+",宸插埌淇濆吇棰勮鏃ユ湡,闇�灏藉揩杩涜淇濆吇";
+                        HContext = "璁惧缂栫爜涓�:" + dt.Tables[0].Rows[i]["璁惧缂栫爜"].ToString() + ",璁惧鍚嶇О涓�:" + dt.Tables[0].Rows[i]["璁惧鍚嶇О"].ToString() + ",宸插埌淇濆吇棰勮鏃ユ湡,闇�灏藉揩杩涜淇濆吇";
                         //鏇存柊璁惧淇濆吇璁″垝棰勮 瀛愯〃
-                        string sql1 = "update Sb_EquipMaintainPlanBillSub_Plan set HSendFlag='1' where HInterID="+ dt.Tables[0].Rows[i]["HInterID"].ToString() + " and  HEntryID=" + dt.Tables[0].Rows[i]["HEntryID"].ToString()+""; ;
+                        string sql1 = "update Sb_EquipMaintainPlanBillSub_Plan set HSendFlag='1' where HInterID=" + dt.Tables[0].Rows[i]["HInterID"].ToString() + " and  HEntryID=" + dt.Tables[0].Rows[i]["HEntryID"].ToString() + ""; ;
                         oCN.RunProc(sql1);
                         DBHelper.CustomWriteLog("璁惧淇濆吇璁″垝棰勮:" + sql1 + "    鏇存柊瀛愯〃璇彞:" + sql1, DateTime.Now.ToString("yyyy-MM-dd"));
-
+                        HDeptName = dt.Tables[0].Rows[i]["璁惧閮ㄩ棬"].ToString();
                         string sql2 = "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 = '璁惧淇濆吇璁″垝棰勮鎺ユ敹浜�'";
-                        dts = oCN.RunProcReturn(sql2, "Gy_Czygl");
-                        for (int j = 0; j < dts.Tables[0].Rows.Count; j++)
-                        {
-                            string HName = dts.Tables[0].Rows[j]["閽夐拤id"].ToString();
-                            string Stares = dts.Tables[0].Rows[j]["鎺ユ敹浜�"].ToString();
-                            MSG msg = new MSG();
-                            //鑾峰彇浼佷笟鐨刟ccess_token鐨勫��
-                            string response = msg.GetAccessToken(appKey, appSecret);
-                            JObject responseJson = JObject.Parse(response);
-                            // 鑾峰彇access_token鐨勫��
-                            string accessToken = responseJson["accessToken"].ToString();
-
-                            //璋冪敤鏂规硶鍙戦�佹秷鎭�           
-                            //string agentId = "3118119317";//閽夐拤鍚庡彴寤虹珛鐨勫皬绋嬪簭id
-                            //鏂帿灏�
-                            string agentId = "3151454458";//閽夐拤鍚庡彴寤虹珛鐨勫皬绋嬪簭id
-                            string userIdList = HName;//閽夐拤浜哄憳鐨刬d
-                            string deptIdList = "0"; // 绌哄瓧绗︿覆琛ㄧず涓嶆寚瀹氶儴闂�
-                            string toAllUser = "false";
-                            string message = HContext;
-
-                            // 璋冪敤鏂规硶鍙戦�佹秷鎭�
-                            response = await msg.SendTextMessage(accessToken, agentId, userIdList, deptIdList, toAllUser, message);
-                            ResponseData responseData = JsonConvert.DeserializeObject<ResponseData>(response);
-                            if (responseData.errcode == 0)
-                            {                          
-                                DBHelper.CustomWriteLog("閽夐拤鍙戦�佷俊鎭垚鍔�!", DateTime.Now.ToString("yyyy-MM-dd"));
-                            }
-                            else
-                            {
-                                Console.WriteLine(responseData.errcode);
-                                DBHelper.CustomWriteLog("閽夐拤杩斿洖淇℃伅:" + response, DateTime.Now.ToString("yyyy-MM-dd"));
-                            }
-                        }                                              
-                    }
-                }
-
-                //鏌ユ壘妯″叿淇濆吇棰勮
-                string newsql = "SELECT a.HInterID,b.HEntryID,c.HMouldNo 妯″叿缂栫爜, c.HName 妯″叿鍚嶇О,B.HErrBeginQty,HSendFlag FROM Sc_MouldMaintainPlanBillMain a " +
-                    "INNER JOIN Sc_MouldMaintainPlanBillSub_Plan b ON a.HInterID = b.HInterID " +
-                    "LEFT JOIN Gy_MouldFileMain c ON a.HMouldID = c.HInterID " +
-                    "WHERE b.HErrBeginQty >= (select sum(HUseLife) from Sc_MouldLifeUseBillSub WHERE HMaterID = a.HMouldID) and b.HSendFlag = '0'";
-                dt = oCN.RunProcReturn(newsql, "Sb_EquipMaintainPlanBillMain");
-                //妯″叿淇濆吇棰勮鑷姩鍙戜俊鎭�
-                if (dt.Tables[0].Rows.Count > 0)
-                {
-                    string HContext = "";   
-
-                    for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
-                    {
-                        HContext = "妯″叿缂栫爜涓�:" + dt.Tables[0].Rows[i]["妯″叿缂栫爜"].ToString() + ",妯″叿鍚嶇О涓�:" + dt.Tables[0].Rows[i]["妯″叿鍚嶇О"].ToString() + ",宸插埌淇濆吇棰勮鏃ユ湡,闇�灏藉揩杩涜淇濆吇";
-                        //鏇存柊妯″叿淇濆吇璁″垝棰勮 瀛愯〃
-                        string sql1 = "update Sc_MouldMaintainPlanBillSub_Plan set HSendFlag='1' where HInterID=" + dt.Tables[0].Rows[i]["HInterID"].ToString() + " and  HEntryID=" + dt.Tables[0].Rows[i]["HEntryID"].ToString() + ""; ;
-                        oCN.RunProc(sql1);
-                        DBHelper.CustomWriteLog("妯″叿淇濆吇璁″垝棰勮:" + sql1 + "    鏇存柊瀛愯〃璇彞:" + sql1, DateTime.Now.ToString("yyyy-MM-dd"));
-
-                        string sql2 = "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 = '妯″叿淇濆吇璁″垝棰勮鎺ユ敹浜�'";
+                            "  left join System_UserGroup c on b.GroupId = c.GroupID  where c.GroupName = '" + HDeptName + "璁惧淇濆吇璁″垝棰勮鎺ユ敹浜�'";
+                        DBHelper.CustomWriteLog("璁惧淇濆吇璁″垝棰勮鎺ユ敹浜�:" + sql2, DateTime.Now.ToString("yyyy-MM-dd"));
                         dts = oCN.RunProcReturn(sql2, "Gy_Czygl");
                         for (int j = 0; j < dts.Tables[0].Rows.Count; j++)
                         {
@@ -139,6 +88,256 @@
                         }
                     }
                 }
+
+                #endregion
+
+                #region 鏌ユ壘妯″叿淇濆吇棰勮
+                string newsql = "SELECT a.HInterID,b.HEntryID,c.HMouldNo 妯″叿缂栫爜, c.HName 妯″叿鍚嶇О,B.HErrBeginQty,HSendFlag,d.HName 妯″叿閮ㄩ棬 FROM Sc_MouldMaintainPlanBillMain a " +
+                    "INNER JOIN Sc_MouldMaintainPlanBillSub_Plan b ON a.HInterID = b.HInterID " +
+                    "LEFT JOIN Gy_MouldFileMain c ON a.HMouldID = c.HInterID " +
+                    "LEFT JOIN Gy_Department d ON a.HDeptID = d.HItemID " +
+                    " WHERE  b.HErrBeginQty <= (select b.HUseNowQty+sum(HUseLife) from Sc_MouldLifeUseBillSub WHERE HMaterID = a.HMouldID) and b.HSendFlag = '0'";
+                DBHelper.CustomWriteLog("鏌ヨ妯″叿淇濆吇璁″垝:" + newsql, DateTime.Now.ToString("yyyy-MM-dd"));
+                dt = oCN.RunProcReturn(newsql, "Sb_EquipMaintainPlanBillMain");
+                //妯″叿淇濆吇棰勮鑷姩鍙戜俊鎭�
+                if (dt.Tables[0].Rows.Count > 0)
+                {
+                    string HContext = "";
+
+                    for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
+                    {
+                        HContext = "妯″叿缂栫爜涓�:" + dt.Tables[0].Rows[i]["妯″叿缂栫爜"].ToString() + ",妯″叿鍚嶇О涓�:" + dt.Tables[0].Rows[i]["妯″叿鍚嶇О"].ToString() + ",宸插埌淇濆吇棰勮娆℃暟,闇�灏藉揩杩涜淇濆吇";
+                        //鏇存柊妯″叿淇濆吇璁″垝棰勮 瀛愯〃
+                        string sql1 = "update Sc_MouldMaintainPlanBillSub_Plan set HSendFlag='1' where HInterID=" + dt.Tables[0].Rows[i]["HInterID"].ToString() + " and  HEntryID=" + dt.Tables[0].Rows[i]["HEntryID"].ToString() + ""; ;
+                        oCN.RunProc(sql1);
+                        DBHelper.CustomWriteLog("妯″叿淇濆吇璁″垝棰勮:" + sql1 + "    鏇存柊瀛愯〃璇彞:" + sql1, DateTime.Now.ToString("yyyy-MM-dd"));
+                        HDeptName = dt.Tables[0].Rows[i]["妯″叿閮ㄩ棬"].ToString();
+                        string sql2 = "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 = '妯″叿淇濆吇璁″垝棰勮鎺ユ敹浜�'";
+                        DBHelper.CustomWriteLog("妯″叿淇濆吇璁″垝棰勮鎺ユ敹浜�:" + sql2, DateTime.Now.ToString("yyyy-MM-dd"));
+                        dts = oCN.RunProcReturn(sql2, "Gy_Czygl");
+                        for (int j = 0; j < dts.Tables[0].Rows.Count; j++)
+                        {
+                            string HName = dts.Tables[0].Rows[j]["閽夐拤id"].ToString();
+                            string Stares = dts.Tables[0].Rows[j]["鎺ユ敹浜�"].ToString();
+                            MSG msg = new MSG();
+                            //鑾峰彇浼佷笟鐨刟ccess_token鐨勫��
+                            string response = msg.GetAccessToken(appKey, appSecret);
+                            JObject responseJson = JObject.Parse(response);
+                            // 鑾峰彇access_token鐨勫��
+                            string accessToken = responseJson["accessToken"].ToString();
+
+                            //璋冪敤鏂规硶鍙戦�佹秷鎭�           
+                            //string agentId = "3118119317";//閽夐拤鍚庡彴寤虹珛鐨勫皬绋嬪簭id
+                            //鏂帿灏�
+                            string agentId = "3151454458";//閽夐拤鍚庡彴寤虹珛鐨勫皬绋嬪簭id
+                            string userIdList = HName;//閽夐拤浜哄憳鐨刬d
+                            string deptIdList = "0"; // 绌哄瓧绗︿覆琛ㄧず涓嶆寚瀹氶儴闂�
+                            string toAllUser = "false";
+                            string message = HContext;
+
+                            // 璋冪敤鏂规硶鍙戦�佹秷鎭�
+                            response = await msg.SendTextMessage(accessToken, agentId, userIdList, deptIdList, toAllUser, message);
+                            ResponseData responseData = JsonConvert.DeserializeObject<ResponseData>(response);
+                            if (responseData.errcode == 0)
+                            {
+                                DBHelper.CustomWriteLog("閽夐拤鍙戦�佷俊鎭垚鍔�!", DateTime.Now.ToString("yyyy-MM-dd"));
+                            }
+                            else
+                            {
+                                Console.WriteLine(responseData.errcode);
+                                DBHelper.CustomWriteLog("閽夐拤杩斿洖淇℃伅:" + response, DateTime.Now.ToString("yyyy-MM-dd"));
+                            }
+                        }
+                    }
+                }
+                #endregion
+
+                #region 璁惧閲囬泦寮傚父
+                DBHelper.CustomWriteLog("璁惧閲囬泦寮傚父寮�濮�!", DateTime.Now.ToString("yyyy-MM-dd"));
+                //璁惧閲囬泦寮傚父鏃讹紙寮�宸ュ悗锛岃澶囨寔缁�10鍒嗛挓鏈噰闆嗭級锛岃繘琛屾秷鎭璀�
+                //鑾峰彇 涓洪璀�  骞朵笖鐘舵�佷负寮�宸ョ殑 璁惧 鍜屽伐鑹哄弬鏁�
+                dt = oCN.RunProcReturn("exec  h_p_Sb_EquiMessageWarn", "h_p_Sb_EquiMessageWarn");
+
+
+                if (dt.Tables[0].Rows.Count > 0 && (DateTime.Now - DateTime.Parse(HRecordDate)).TotalMinutes >= int.Parse(HWarningDate))
+                {
+                    string HEquipFileName = "";
+                    string HRemark = "";
+
+                    //涓洪璀︾殑璁惧 鍜� 宸ヨ壓鍙傛暟 杩涜寰幆
+                    for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
+                    {
+                        HRecordDate = dt.Tables[0].Rows[i]["HRecordDate"].ToString();//璁板綍鏃堕棿
+                        HWarningDate = dt.Tables[0].Rows[i]["HWarningDate"].ToString();//棰勮鏃堕棿
+                        string HCollectionDate = dt.Tables[0].Rows[i]["HCollectionDate"].ToString();//閲囬泦鏃堕棿
+                        string HEquipFileNo = dt.Tables[0].Rows[i]["HEquipFileNo"].ToString();//璁惧缂栧彿
+                        string HParameterName = dt.Tables[0].Rows[i]["HName"].ToString();//宸ヨ壓鍙傛暟
+
+                        if ((DateTime.Now - DateTime.Parse(HRecordDate)).TotalMinutes >= int.Parse(HWarningDate))
+                        {
+                            //鏍规嵁 璁惧+宸ヨ壓鍙傛暟+閲囬泦鏃堕棿 鏌ヨ宸ヨ壓鍙傛暟涓存椂琛ㄧ殑鏁版嵁
+                            DataSet ds = oCN.RunProcReturn("exec h_p_Sb_EquipMentTechParam_Temp '" + HEquipFileNo + "', '" + HParameterName + "', '" + HCollectionDate + "'", "h_p_Sb_EquipMentTechParam_Temp");
+                            if (ds.Tables[0].Rows.Count > 0)
+                            {
+                                string HMaxCreateTime = ds.Tables[0].Rows[0]["HCreateTime"].ToString();
+                                // 鍒ゆ柇 褰撳墠鏃堕棿-鍙傛暟鐨勫垱寤烘椂闂� 鏄惁澶т簬棰勮鏃堕棿  濡傛灉 澶т簬棰勮鏃堕棿鍒欓渶瑕侀拤閽夊彂娑堟伅
+                                if ((DateTime.Now - DateTime.Parse(HMaxCreateTime)).TotalMinutes >= int.Parse(HWarningDate))
+                                {
+                                    if (HEquipFileName != HEquipFileNo)
+                                    {
+                                        HRemark += "璁惧缂栫爜:" + HEquipFileNo + "---";
+                                        HEquipFileName = HEquipFileNo;
+                                    }
+
+                                    DBHelper.CustomWriteLog("鏈�澶ф椂闂�:" + HMaxCreateTime + "," + i, DateTime.Now.ToString("yyyy-MM-dd"));
+                                    //鍙戦�佹秷鎭�
+                                    HRemark += HParameterName + ",";
+                                    DBHelper.CustomWriteLog("鏇存柊鏃堕棿:" + HEquipFileNo, DateTime.Now.ToString("yyyy-MM-dd"));
+                                    //鏇存柊璁板綍鏃堕棿
+                                    oCN.RunProc("update Gy_EquipFileBillMain set HRecordDate=getdate() where HEquipFileNo='" + HEquipFileNo + "'");
+                                }
+                                DBHelper.CustomWriteLog("璁惧閲囬泦寮傚父寮�濮�---涓嶉渶瑕侀璀�!", DateTime.Now.ToString("yyyy-MM-dd"));
+                            }
+                            else
+                            {
+                                if (HEquipFileName != HEquipFileNo)
+                                {
+                                    HRemark += "璁惧缂栫爜:" + HEquipFileNo + "---";
+                                    HEquipFileName = HEquipFileNo;
+                                }
+                                //鍙戦�佹秷鎭�
+                                HRemark += HParameterName + ",";
+                                //鏇存柊璁板綍鏃堕棿
+                                oCN.RunProc("update Gy_EquipFileBillMain set HRecordDate=getdate() where HEquipFileNo='" + HEquipFileNo + "'");
+                            }
+                        }
+                    }
+
+                    HRecordDate = DateTime.Now.ToString();
+
+                    if (HRemark.Length > 0)
+                    {
+                        HRemark += "娌℃湁閲囬泦鍒版暟鎹�!";
+
+                        // 鏍规嵁 瑙掕壊 鍘绘煡璇㈤渶瑕佸彂娑堟伅鐨勯拤閽夊彿
+                        string sql2 = "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 = '璁惧鏈噰闆嗗埌鍙傛暟棰勮'";
+                        dts = oCN.RunProcReturn(sql2, "Gy_Czygl");
+                        for (int j = 0; j < dts.Tables[0].Rows.Count; j++)
+                        {
+                            string HName = dts.Tables[0].Rows[j]["閽夐拤id"].ToString();
+                            string Stares = dts.Tables[0].Rows[j]["鎺ユ敹浜�"].ToString();
+                            MSG msg = new MSG();
+                            //鑾峰彇浼佷笟鐨刟ccess_token鐨勫��
+                            string response = msg.GetAccessToken(appKey, appSecret);
+                            JObject responseJson = JObject.Parse(response);
+                            // 鑾峰彇access_token鐨勫��
+                            string accessToken = responseJson["accessToken"].ToString();
+
+                            //璋冪敤鏂规硶鍙戦�佹秷鎭�           
+                            //string agentId = "3118119317";//閽夐拤鍚庡彴寤虹珛鐨勫皬绋嬪簭id
+                            //鏂帿灏�
+                            string agentId = "3151454458";//閽夐拤鍚庡彴寤虹珛鐨勫皬绋嬪簭id
+                            string userIdList = HName;//閽夐拤浜哄憳鐨刬d
+                            string deptIdList = "0"; // 绌哄瓧绗︿覆琛ㄧず涓嶆寚瀹氶儴闂�
+                            string toAllUser = "false";
+                            string message = HRemark;
+
+                            // 璋冪敤鏂规硶鍙戦�佹秷鎭�
+                            response = await msg.SendTextMessage(accessToken, agentId, userIdList, deptIdList, toAllUser, message);
+                            ResponseData responseData = JsonConvert.DeserializeObject<ResponseData>(response);
+                            if (responseData.errcode == 0)
+                            {
+                                DBHelper.CustomWriteLog("閽夐拤鍙戦�佷俊鎭垚鍔�!", DateTime.Now.ToString("yyyy-MM-dd"));
+                            }
+                            else
+                            {
+                                Console.WriteLine(responseData.errcode);
+                                DBHelper.CustomWriteLog("閽夐拤杩斿洖淇℃伅:" + response, DateTime.Now.ToString("yyyy-MM-dd"));
+                            }
+                        }
+                    }
+
+                }
+                DBHelper.CustomWriteLog("璁惧閲囬泦寮傚父缁撴潫!", DateTime.Now.ToString("yyyy-MM-dd"));
+
+                #endregion
+
+                #region
+                DBHelper.CustomWriteLog("spc寮傚父鍙戞秷鎭�!", DateTime.Now.ToString("yyyy-MM-dd"));
+                //spc 寮傚父琛ㄦ湁鏈彂娑堟伅鐨勬暟鎹椂 涓�灏忔椂 鍙戦�佷竴娆℃秷鎭�
+                //鑾峰彇 寮傚父琛� 鏈夋湭鍙戞秷鎭殑鏁版嵁
+                dt = oCN.RunProcReturn("select * from h_v_QC_SendMessageList", "h_v_QC_SendMessageList");
+
+
+                if (HRecordDate_spc == "")
+                {
+                    HRecordDate_spc = DateTime.Now.ToString();
+                }
+                //鏍规嵁30鍒嗛挓鏃堕棿 鍘诲彂閫佹秷鎭�
+                if (dt.Tables[0].Rows.Count > 0 && (DateTime.Now - DateTime.Parse(HRecordDate_spc)).TotalMinutes >= 30)
+                {
+
+                    //涓洪璀︾殑璁惧 鍜� 宸ヨ壓鍙傛暟 杩涜寰幆
+                    for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
+                    {
+                        string HMaterID = dt.Tables[0].Rows[i]["HMaterID"].ToString();
+                        string HQCCheckItemID = dt.Tables[0].Rows[i]["HQCCheckItemID"].ToString();
+                        //string HMaterNumber = dt.Tables[0].Rows[i]["鐗╂枡浠g爜"].ToString();
+                        //string HQCCheckItemNumber = dt.Tables[0].Rows[i]["椤圭洰浠g爜"].ToString();
+                        string HMouldNum = dt.Tables[0].Rows[i]["绌村彿"].ToString();
+                        string HRemark = dt.Tables[0].Rows[i]["閿欒鏁版嵁"].ToString();
+
+                        if (HRemark.Length > 0)
+                        {
+                            // 鏍规嵁 瑙掕壊 鍘绘煡璇㈤渶瑕佸彂娑堟伅鐨勯拤閽夊彿
+                            string sql2 = "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 = 'SPC鏁版嵁寮傚父棰勮'";
+                            dts = oCN.RunProcReturn(sql2, "Gy_Czygl");
+                            for (int j = 0; j < dts.Tables[0].Rows.Count; j++)
+                            {
+                                string HName = dts.Tables[0].Rows[j]["閽夐拤id"].ToString();
+                                string Stares = dts.Tables[0].Rows[j]["鎺ユ敹浜�"].ToString();
+                                MSG msg = new MSG();
+                                //鑾峰彇浼佷笟鐨刟ccess_token鐨勫��
+                                string response = msg.GetAccessToken(appKey, appSecret);
+                                JObject responseJson = JObject.Parse(response);
+                                // 鑾峰彇access_token鐨勫��
+                                string accessToken = responseJson["accessToken"].ToString();
+
+                                //璋冪敤鏂规硶鍙戦�佹秷鎭�
+                                //string agentId = "3118119317";//閽夐拤鍚庡彴寤虹珛鐨勫皬绋嬪簭id
+                                //鏂帿灏�
+                                string agentId = "3151454458";//閽夐拤鍚庡彴寤虹珛鐨勫皬绋嬪簭id
+                                string userIdList = HName;//閽夐拤浜哄憳鐨刬d
+                                string deptIdList = "0"; // 绌哄瓧绗︿覆琛ㄧず涓嶆寚瀹氶儴闂�
+                                string toAllUser = "false";
+                                string message = HRemark;
+                                DBHelper.CustomWriteLog("spc寮傚父 褰撳墠鏃堕棿:"+ HRecordDate_spc, DateTime.Now.ToString("yyyy-MM-dd"));
+
+                                // 璋冪敤鏂规硶鍙戦�佹秷鎭�
+                                response = await msg.SendTextMessage(accessToken, agentId, userIdList, deptIdList, toAllUser, message);
+                                ResponseData responseData = JsonConvert.DeserializeObject<ResponseData>(response);
+                                if (responseData.errcode == 0)
+                                {
+                                    DBHelper.CustomWriteLog("spc寮傚父鍙戞伅鎴愬姛!", DateTime.Now.ToString("yyyy-MM-dd"));
+                                    string sql3 = "update QC_SendMessage set HMessageIsSend=1 where HMaterID=" + HMaterID + " and HQCCheckItemID=" + HQCCheckItemID + " and HMouldNum='" + HMouldNum + "'";
+                                    oCN.RunProc(sql3);
+                                }
+                                else
+                                {
+                                    Console.WriteLine(responseData.errcode);
+                                    DBHelper.CustomWriteLog("spc寮傚父杩斿洖淇℃伅:" + response, DateTime.Now.ToString("yyyy-MM-dd"));
+                                }
+                            }
+
+                            HRecordDate_spc = DateTime.Now.ToString();
+                        }
+                    }
+                }
+                DBHelper.CustomWriteLog("spc寮傚父鍙戞伅缁撴潫!", DateTime.Now.ToString("yyyy-MM-dd"));
+                #endregion
                 // 绛夊緟涓�鍒嗛挓
                 await Task.Delay(TimeSpan.FromMinutes(1));
             }

--
Gitblit v1.9.1