UserSwapWhiteService.cs 9.7 KB

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