RefreshTokensService.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * 后台管理员角色
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using MySystem.BsModels;
  8. using Library;
  9. using LitJson;
  10. namespace MySystem.Service.Bs
  11. {
  12. public class RefreshTokensService
  13. {
  14. string _conn = "";
  15. public RefreshTokensService()
  16. {
  17. _conn = ConfigurationManager.AppSettings["BsSqlConnStr"].ToString();
  18. }
  19. /// <summary>
  20. /// 查询列表
  21. /// </summary>
  22. /// <param name="relationData">关联表</param>
  23. /// <param name="condition">查询条件(sql语句)</param>
  24. /// <param name="count">总数(输出)</param>
  25. /// <param name="page">页码</param>
  26. /// <param name="limit">每页条数</param>
  27. /// <returns></returns>
  28. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, out int count, int page = 1, int limit = 30)
  29. {
  30. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("RefreshTokens", relationData, "RefreshTokens.Id desc", page, limit, condition, "RefreshTokens.Name,RefreshTokens.CreateDate,RefreshTokens.Status,RefreshTokens.Id");
  31. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  32. count = int.Parse(obj["count"].ToString());
  33. return diclist;
  34. }
  35. /// <summary>
  36. /// 查询一条记录
  37. /// </summary>
  38. /// <param name="Id">主键Id</param>
  39. /// <returns></returns>
  40. public RefreshTokens Query(int Id)
  41. {
  42. WebCMSEntities db = new WebCMSEntities();
  43. RefreshTokens editData = db.RefreshTokens.FirstOrDefault(m => m.UserId == Id) ?? new RefreshTokens();
  44. db.Dispose();
  45. return editData;
  46. }
  47. public RefreshTokens Query(string refreshToken)
  48. {
  49. WebCMSEntities db = new WebCMSEntities();
  50. RefreshTokens editData = db.RefreshTokens.FirstOrDefault(m => m.RefreshToken == refreshToken) ?? new RefreshTokens();
  51. db.Dispose();
  52. return editData;
  53. }
  54. /// <summary>
  55. /// 添加数据
  56. /// </summary>
  57. /// <param name="Fields">要设置的字段</param>
  58. /// <returns></returns>
  59. public int Add(Dictionary<string, object> Fields)
  60. {
  61. WebCMSEntities db = new WebCMSEntities();
  62. RefreshTokens add = db.RefreshTokens.Add(new RefreshTokens()
  63. {
  64. UserId = (int)Fields["UserId"],
  65. ExpiredDate = (DateTime)Fields["ExpiredDate"],
  66. RefreshToken = Fields["RefreshToken"].ToString(),
  67. }).Entity;
  68. db.SaveChanges();
  69. int Id = add.UserId;
  70. db.Dispose();
  71. return Id;
  72. }
  73. /// <summary>
  74. /// 修改数据
  75. /// </summary>
  76. /// <param name="Fields">要设置的字段</param>
  77. /// <param name="Id">主键Id</param>
  78. public void Edit(Dictionary<string, object> Fields, int Id)
  79. {
  80. WebCMSEntities db = new WebCMSEntities();
  81. RefreshTokens edit = db.RefreshTokens.FirstOrDefault(m => m.UserId == Id);
  82. if(edit != null)
  83. {
  84. edit.ExpiredDate = (DateTime)Fields["ExpiredDate"];
  85. edit.RefreshToken = Fields["RefreshToken"].ToString();
  86. db.SaveChanges();
  87. }
  88. db.Dispose();
  89. }
  90. /// <summary>
  91. /// 删除数据
  92. /// </summary>
  93. /// <param name="Id">主键Id</param>
  94. public void Delete(int Id)
  95. {
  96. new DbService(AppConfig.Base.dbTables, _conn).Delete("RefreshTokens", Id);
  97. }
  98. /// <summary>
  99. /// 排序
  100. /// </summary>
  101. /// <param name="Id">主键Id</param>
  102. /// <param name="Sort">排序序号</param>
  103. public void Sort(int Id, int Sort)
  104. {
  105. new DbService(AppConfig.Base.dbTables, _conn).Sort("RefreshTokens", Sort, Id);
  106. }
  107. /// <summary>
  108. /// 导入数据
  109. /// </summary>
  110. /// <param name="ExcelData">json数据</param>
  111. public void Import(string ExcelData)
  112. {
  113. WebCMSEntities db = new WebCMSEntities();
  114. JsonData list = JsonMapper.ToObject(ExcelData);
  115. for (int i = 1; i < list.Count;i++ )
  116. {
  117. JsonData dr = list[i];
  118. db.RefreshTokens.Add(new RefreshTokens()
  119. {
  120. });
  121. db.SaveChanges();
  122. }
  123. db.Dispose();
  124. }
  125. /// <summary>
  126. /// 导出excel表格
  127. /// </summary>
  128. /// <param name="fields">查询条件(单个字段)</param>
  129. /// <param name="condition">查询条件(sql语句)</param>
  130. /// <returns></returns>
  131. public Dictionary<string, object> ExportExcel(List<RelationData> relationData, string condition)
  132. {
  133. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("RefreshTokens", relationData, "RefreshTokens.Id desc", 1, 20000, condition, "RefreshTokens.Name,RefreshTokens.CreateDate,RefreshTokens.Status,RefreshTokens.Id");
  134. List<RefreshTokens> diclist = obj["data"] as List<RefreshTokens>;
  135. Dictionary<string, object> result = new Dictionary<string, object>();
  136. result.Add("Status", "1");
  137. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  138. result.Add("Obj", diclist);
  139. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  140. result.Add("Fields", ReturnFields);
  141. return result;
  142. }
  143. }
  144. }