RefreshTokensService.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * 后台管理员角色
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using MySystem.Models.Bs;
  8. using Library;
  9. using LitJson;
  10. namespace MySystem.Service.Bs
  11. {
  12. public class RefreshTokensService
  13. {
  14. static string _conn = ConfigurationManager.AppSettings["BsSqlConnStr"].ToString();
  15. /// <summary>
  16. /// 查询列表(适合多表关联查询)
  17. /// </summary>
  18. /// <param name="relationData">关联表</param>
  19. /// <param name="condition">查询条件(sql语句)</param>
  20. /// <param name="count">总数(输出)</param>
  21. /// <param name="page">页码</param>
  22. /// <param name="limit">每页条数</param>
  23. /// <returns></returns>
  24. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, out int count, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  25. {
  26. List<string> fields = new List<string>(); //要显示的列,不设置则返回全部字段
  27. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.bsTables, _conn).IndexData("RefreshTokens", relationData, orderBy, page, limit, condition, fields);
  28. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  29. count = int.Parse(obj["count"].ToString());
  30. return diclist;
  31. }
  32. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  33. {
  34. List<string> fields = new List<string>(); //要显示的列,不设置则返回全部字段
  35. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.bsTables, _conn).IndexData("RefreshTokens", relationData, orderBy, page, limit, condition, fields);
  36. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  37. return diclist;
  38. }
  39. /// <summary>
  40. /// 查询列表(单表)
  41. /// </summary>
  42. /// <param name="fieldList">返回的字段</param>
  43. /// <param name="condition">查询条件</param>
  44. /// <param name="page">页码</param>
  45. /// <param name="limit">每页条数</param>
  46. /// <param name="orderBy">排序</param>
  47. /// <returns></returns>
  48. public static List<Dictionary<string, object>> List(string fieldList, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  49. {
  50. List<string> fields = fieldList.Split(',').ToList(); //要显示的列
  51. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.bsTables, _conn).IndexData("RefreshTokens", new List<RelationData>(), orderBy, page, limit, condition, fields);
  52. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  53. return diclist;
  54. }
  55. /// <summary>
  56. /// 查询一条记录
  57. /// </summary>
  58. /// <param name="Id">主键Id</param>
  59. /// <returns></returns>
  60. public static RefreshTokens Query(int Id)
  61. {
  62. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.bsTables, _conn).Query("*", "RefreshTokens", Id);
  63. if (obj.Keys.Count > 0)
  64. {
  65. return Newtonsoft.Json.JsonConvert.DeserializeObject<RefreshTokens>(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
  66. }
  67. return new RefreshTokens();
  68. }
  69. /// <summary>
  70. /// 查询一条记录
  71. /// </summary>
  72. /// <param name="condition">查询条件(sql语句)</param>
  73. /// <returns></returns>
  74. public static RefreshTokens Query(string condition)
  75. {
  76. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.bsTables, _conn).Query("*", "RefreshTokens", condition);
  77. if (obj.Keys.Count > 0)
  78. {
  79. return Newtonsoft.Json.JsonConvert.DeserializeObject<RefreshTokens>(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
  80. }
  81. return new RefreshTokens();
  82. }
  83. /// <summary>
  84. /// 查询一条记录
  85. /// </summary>
  86. /// <param name="condition">查询条件(sql语句)</param>
  87. /// <param name="fields">返回的字段</param>
  88. /// <returns></returns>
  89. public static Dictionary<string, object> Query(string condition, string fields)
  90. {
  91. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.bsTables, _conn).Query(fields, "RefreshTokens", condition);
  92. return obj;
  93. }
  94. public static decimal Sum(string condition, string field)
  95. {
  96. decimal amount = 0;
  97. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.bsTables, _conn).Query("Sum(" + field + ") " + field + "", "RefreshTokens", condition);
  98. if (obj.Keys.Count > 0)
  99. {
  100. amount = decimal.Parse(obj[field].ToString());
  101. }
  102. return amount;
  103. }
  104. /// <summary>
  105. /// 查询记录数
  106. /// </summary>
  107. /// <param name="Id">主键Id</param>
  108. /// <returns></returns>
  109. public static int Count(string condition = "", string field = "Id")
  110. {
  111. int result = 0;
  112. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.bsTables, _conn).Query("count(" + field + ") " + field + "", "RefreshTokens", condition);
  113. if (obj.Keys.Count > 0)
  114. {
  115. result = int.Parse(function.CheckInt(obj[field].ToString()));
  116. }
  117. return result;
  118. }
  119. /// <summary>
  120. /// 查询是否存在
  121. /// </summary>
  122. /// <param name="Id">主键Id</param>
  123. /// <returns></returns>
  124. public static bool Exist(string condition)
  125. {
  126. Dictionary<string, object> obj = new DbServiceNew(AppConfig.Base.bsTables, _conn).Query("1", "RefreshTokens", condition);
  127. if (obj.Keys.Count > 0)
  128. {
  129. return true;
  130. }
  131. return false;
  132. }
  133. /// <summary>
  134. /// 添加数据
  135. /// </summary>
  136. /// <param name="Fields">要设置的字段</param>
  137. /// <returns></returns>
  138. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  139. {
  140. if (check)
  141. {
  142. }
  143. int Id = new DbServiceNew(AppConfig.Base.bsTables, _conn).Add("RefreshTokens", fields, 0);
  144. return new AppResultJson() { Status = "1", Data = Id };
  145. }
  146. /// <summary>
  147. /// 修改数据
  148. /// </summary>
  149. /// <param name="Fields">要设置的字段</param>
  150. /// <param name="Id">主键Id</param>
  151. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  152. {
  153. if (check)
  154. {
  155. }
  156. new DbServiceNew(AppConfig.Base.bsTables, _conn).Edit("RefreshTokens", fields, Id);
  157. return new AppResultJson() { Status = "1", Data = Id };
  158. }
  159. /// <summary>
  160. /// 逻辑删除
  161. /// </summary>
  162. /// <param name="Id">主键Id</param>
  163. public static void Remove(int Id)
  164. {
  165. Dictionary<string, object> fields = new Dictionary<string, object>();
  166. fields.Add("Status", -1);
  167. new DbServiceNew(AppConfig.Base.bsTables, _conn).Edit("RefreshTokens", fields, Id);
  168. }
  169. /// <summary>
  170. /// 删除数据
  171. /// </summary>
  172. /// <param name="Id">主键Id</param>
  173. public static void Delete(int Id)
  174. {
  175. new DbService(AppConfig.Base.dbTables, _conn).Delete("RefreshTokens", Id);
  176. }
  177. /// <summary>
  178. /// 排序
  179. /// </summary>
  180. /// <param name="Id">主键Id</param>
  181. /// <param name="Sort">排序序号</param>
  182. public static void Sort(int Id, int Sort)
  183. {
  184. new DbService(AppConfig.Base.dbTables, _conn).Sort("RefreshTokens", Sort, Id);
  185. }
  186. /// <summary>
  187. /// 导入数据
  188. /// </summary>
  189. /// <param name="ExcelData">json数据</param>
  190. public static void Import(string ExcelData)
  191. {
  192. WebCMSEntities db = new WebCMSEntities();
  193. JsonData list = JsonMapper.ToObject(ExcelData);
  194. for (int i = 1; i < list.Count; i++)
  195. {
  196. JsonData dr = list[i];
  197. db.RefreshTokens.Add(new RefreshTokens()
  198. {
  199. });
  200. db.SaveChanges();
  201. }
  202. db.Dispose();
  203. }
  204. /// <summary>
  205. /// 导出excel表格
  206. /// </summary>
  207. /// <param name="fields">查询条件(单个字段)</param>
  208. /// <param name="condition">查询条件(sql语句)</param>
  209. /// <returns></returns>
  210. // public static void ExportExcel(List<RelationData> relationData, string condition)
  211. // {
  212. // }
  213. }
  214. }