NotificationOfActionProvider.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using Dapper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using Winsoft.GOV.Framework.Model;
  7. namespace Winsoft.GOV.Framework.Provider
  8. {
  9. public class NotificationOfActionProvider : BaseProvider<NotificationOfAction>
  10. {
  11. private static string cols = "QL_NAME,"
  12. + "QL_INNER_CODE,"
  13. + "QL_DEP,"
  14. + "OUGUID,"
  15. + "AType,"
  16. + "UPDATE_DATE,"
  17. + "IsRead";
  18. private static string vals = "@QL_NAME,"
  19. + "@QL_INNER_CODE,"
  20. + "@QL_DEP,"
  21. + "@OUGUID,"
  22. + "@AType,"
  23. + "@UPDATE_DATE,"
  24. + "@IsRead";
  25. public void CreateTable()
  26. {
  27. string sql = "create table if not exists notificationofaction("
  28. + "QL_NAME varchar(200),"
  29. + "QL_INNER_CODE varchar(50),"
  30. + "QL_DEP varchar(50),"
  31. + "OUGUID varchar(50),"
  32. + "QL_KIND varchar(2),"
  33. + "AType int,"
  34. + "UPDATE_DATE datetime,"
  35. + "IsRead bool,"
  36. + "PRIMARY KEY (QL_INNER_CODE)"
  37. + "); "
  38. + "call add_index('notificationofaction', 'index1', 'index1(IsRead,UPDATE_DATE)'); "
  39. + "call add_index('notificationofaction', 'index2', 'index2(QL_INNER_CODE)'); "
  40. + "call add_index('notificationofaction', 'index3', 'index3(IsRead)'); "
  41. + "call add_index('notificationofaction', 'index4', 'index4(UPDATE_DATE)'); "
  42. + "call add_index('notificationofaction', 'index5', 'index5(QL_KIND)'); ";
  43. //+ "call add_index('PowerMattersBase', 'index4', 'index4(QL_NAME)'); ";
  44. using (var con = GetDbConnection())
  45. {
  46. con.Execute(sql);
  47. }
  48. }
  49. public NotificationOfActionProvider(County county) : base(county)
  50. {
  51. }
  52. public void InserOrUpdate(NotificationOfAction n)
  53. {
  54. using (var con = GetDbConnection())
  55. {
  56. string sql = "insert into notificationofaction(" + cols + ") values("+ vals + ") on duplicate key update QL_NAME = @QL_NAME, QL_DEP = @QL_DEP, OUGUID = @OUGUID, AType = @AType, IsRead = @IsRead, UPDATE_DATE=@UPDATE_DATE";
  57. con.Execute(sql, n);
  58. }
  59. }
  60. public void Read(string QL_INNER_CODE)
  61. {
  62. using (var con = GetDbConnection())
  63. {
  64. string sql = "update notificationofaction set IsRead = 1 where QL_INNER_CODE='" + QL_INNER_CODE + "'";
  65. con.Execute(sql);
  66. }
  67. }
  68. public int UnreadCount()
  69. {
  70. using (var con = GetDbConnection())
  71. {
  72. string sql = "select count(*) notificationofaction where IsRead = 0";
  73. return con.QueryFirstOrDefault<int>(sql);
  74. }
  75. }
  76. public PagedResult<NotificationOfAction> FindByPage(int itemIndex, int size)
  77. {
  78. string sql = "select " + cols + " from notificationofaction order by UPDATE_DATE desc";
  79. return GetPagedList(sql, itemIndex, size);
  80. }
  81. public PagedResult<NotificationOfAction> FindByPage(int itemIndex, int size, string[] ql_kinds)
  82. {
  83. string sql = "select " + cols + " from notificationofaction ";
  84. if (ql_kinds.Length > 0)
  85. {
  86. sql = sql + " where ql_kind in ('" + string.Join("','", ql_kinds) + "')";
  87. }
  88. sql = sql + " order by UPDATE_DATE desc";
  89. return GetPagedList(sql, itemIndex, size);
  90. }
  91. public PagedResult<NotificationOfAction> FindByPage(string key, int itemIndex, int size, string[] ql_kinds, bool isHidRead)
  92. {
  93. string sql = "select " + cols + " from notificationofaction where 1=1";
  94. if (ql_kinds.Length > 0)
  95. {
  96. sql = sql + " and ql_kind in ('" + string.Join("','", ql_kinds) + "')";
  97. }
  98. if (!String.IsNullOrWhiteSpace(key))
  99. sql = sql + " and (ql_name like '%" + key + "%' or ql_dep like '%" + key + "%')";
  100. if (isHidRead)
  101. sql = sql + " and IsRead = 0";
  102. sql = sql + " order by UPDATE_DATE desc";
  103. return GetPagedList(sql, itemIndex, size);
  104. }
  105. public PagedResult<NotificationOfAction> FindUnreadByPage(int itemIndex, int size)
  106. {
  107. string sql = "select " + cols + " from notificationofaction where IsRead = 0 order by UPDATE_DATE desc";
  108. return GetPagedList(sql, itemIndex, size);
  109. }
  110. }
  111. }