NotificationOfActionProvider.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. + "AType int,"
  33. + "UPDATE_DATE datetime,"
  34. + "IsRead bool,"
  35. + "PRIMARY KEY (QL_INNER_CODE)"
  36. + "); "
  37. + "call add_index('NotificationOfAction', 'index1', 'index1(IsRead,UPDATE_DATE)'); "
  38. + "call add_index('NotificationOfAction', 'index2', 'index2(QL_INNER_CODE)'); "
  39. + "call add_index('NotificationOfAction', 'index3', 'index3(IsRead)'); "
  40. + "call add_index('NotificationOfAction', 'index4', 'index4(UPDATE_DATE)'); ";
  41. //+ "call add_index('PowerMattersBase', 'index4', 'index4(QL_NAME)'); ";
  42. using (var con = GetDbConnection())
  43. {
  44. con.Execute(sql);
  45. }
  46. }
  47. public NotificationOfActionProvider(County county) : base(county)
  48. {
  49. }
  50. public void InserOrUpdate(NotificationOfAction n)
  51. {
  52. using (var con = GetDbConnection())
  53. {
  54. 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";
  55. con.Execute(sql, n);
  56. }
  57. }
  58. public void Read(string QL_INNER_CODE)
  59. {
  60. using (var con = GetDbConnection())
  61. {
  62. string sql = "update NotificationOfAction set IsRead = 1 where QL_INNER_CODE='" + QL_INNER_CODE + "'";
  63. con.Execute(sql);
  64. }
  65. }
  66. public int UnreadCount()
  67. {
  68. using (var con = GetDbConnection())
  69. {
  70. string sql = "select count(*) NotificationOfAction where IsRead = 0";
  71. return con.QueryFirstOrDefault<int>(sql);
  72. }
  73. }
  74. public PagedResult<NotificationOfAction> FindByPage(int itemIndex, int size)
  75. {
  76. string sql = "select " + cols + " from NotificationOfAction order by UPDATE_DATE desc";
  77. return GetPagedList(sql, itemIndex, size);
  78. }
  79. public PagedResult<NotificationOfAction> FindUnreadByPage(int itemIndex, int size)
  80. {
  81. string sql = "select " + cols + " from NotificationOfAction where IsRead = 0 order by UPDATE_DATE desc";
  82. return GetPagedList(sql, itemIndex, size);
  83. }
  84. }
  85. }