NotificationOfActionProvider.cs 4.8 KB

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