GTMessagePushUser.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using LYFZ.CloudServerData.Model;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. namespace LYFZ.CloudServerData.DAL
  8. {
  9. public class GTMessagePushUser : BaseDataOperate<LYFZ.CloudServerData.Model.GTMessagePushUser>
  10. {
  11. public GTMessagePushUser(LYFZ.CloudServerData.Model.DBConnection dbConn)
  12. {
  13. base.DBConn = dbConn;
  14. }
  15. public bool BadgeClear(string cid, int badge = 0)
  16. {
  17. string sql = String.Format("update [dbo].[tb_GTMessagePushUser] set Badge={1} where GTClientID='{0}'", cid, badge);
  18. if (LYFZ.Helper.SQLHelper.ExecuteSql(sql, this.DBConn.GetDBConnectionString()) > 0)
  19. {
  20. return true;
  21. }
  22. else
  23. {
  24. return false;
  25. }
  26. }
  27. /// <summary>
  28. /// 用户未读消息统计 (Badge累加 1)
  29. /// </summary>
  30. /// <param name="cidList"></param>
  31. /// <returns></returns>
  32. public bool AddBadgeNumber(string[] cidList)
  33. {
  34. if (cidList.Length > 0)
  35. {
  36. string cidString = String.Join(",", cidList).Trim(',').Trim();
  37. if (!String.IsNullOrEmpty(cidString))
  38. {
  39. string sql = String.Format("update [dbo].[tb_GTMessagePushUser] set Badge=Badge+1 where GTClientID in ('{0}')", cidString.Trim(',').Trim()).Replace(",", "','");
  40. if (LYFZ.Helper.SQLHelper.ExecuteSql(sql, this.DBConn.GetDBConnectionString()) > 0)
  41. {
  42. return true;
  43. }
  44. else
  45. {
  46. return false;
  47. }
  48. }
  49. else
  50. {
  51. return true;
  52. }
  53. }
  54. else
  55. {
  56. return true;
  57. }
  58. }
  59. /// <summary>
  60. ///
  61. /// </summary>
  62. /// <param name="targetUser">目标用户 0 为全部用户 1 为企业用户 2 为特定用户 3 为指定用户(UserID) 的用户</param>
  63. /// <returns></returns>
  64. public List<PushSingleUser> GetPushSingleUserList(int targetUser, string targetList, string eid)
  65. {
  66. List<PushSingleUser> sUserList = new List<PushSingleUser>();
  67. //E1000
  68. targetList = targetList.Trim(',');
  69. string sql = String.Format("SELECT [GTType],[Badge],[UserID],[GTClientID] FROM [dbo].[tb_GTMessagePushUser]");
  70. DataTable tb = null;
  71. if (eid.ToLower() == "E1000".ToLower())
  72. {
  73. if (targetUser == 0)
  74. {
  75. tb = LYFZ.Helper.SQLHelper.Query(String.Format("{0} where UpdateTime>{1}", sql, DateTime.Now.AddDays(-90).ToJavaScriptTimeStamp()), this.DBConn.GetDBConnectionString()).Tables[0];
  76. }
  77. else
  78. {
  79. tb = LYFZ.Helper.SQLHelper.Query(String.Format("{0} where (EnterpriseID='{1}')", sql, targetList.Replace(":", "' and userid='").Replace(",", "') or ([EnterpriseID]='")), this.DBConn.GetDBConnectionString()).Tables[0];
  80. }
  81. }
  82. else
  83. {
  84. if (targetList.Trim(',').Trim().Length > 0 || targetUser == 0)
  85. {
  86. switch (targetUser)
  87. {
  88. case 0:
  89. tb = LYFZ.Helper.SQLHelper.Query(String.Format("{0} where UpdateTime>{1}", sql, DateTime.Now.AddDays(-90).ToJavaScriptTimeStamp()), this.DBConn.GetDBConnectionString()).Tables[0];
  90. break;
  91. case 1:
  92. tb = LYFZ.Helper.SQLHelper.Query(String.Format("{0} where EnterpriseID in ('{1}')", sql, targetList.Replace(",", "','")), this.DBConn.GetDBConnectionString()).Tables[0];
  93. break;
  94. case 2:
  95. tb = LYFZ.Helper.SQLHelper.Query(String.Format("{0} where GTClientID in ('{1}')", sql, targetList.Replace(",", "','")), this.DBConn.GetDBConnectionString()).Tables[0];
  96. break;
  97. case 3:
  98. tb = LYFZ.Helper.SQLHelper.Query(String.Format("{0} where EnterpriseID='{2}' and UserID in ('{1}')", sql, targetList.Replace(",", "','"), eid), this.DBConn.GetDBConnectionString()).Tables[0];
  99. break;
  100. }
  101. }
  102. }
  103. if (tb != null)
  104. {
  105. foreach (DataRow row in tb.Rows)
  106. {
  107. PushSingleUser sUser = new PushSingleUser();
  108. sUser.GTType = Convert.ToInt32(row["GTType"].ToString());
  109. sUser.GTClientID = row["GTClientID"].ToString();
  110. sUser.Badge = Convert.ToInt32(row["Badge"].ToString());
  111. sUser.UserID = row["UserID"].ToString();
  112. sUserList.Add(sUser);
  113. }
  114. }
  115. return sUserList;
  116. }
  117. }
  118. }