BusinessActSummaryService.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * 企业伙伴激活汇总
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Main;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Main
  12. {
  13. public class BusinessActSummaryService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].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. fields.Add("Id");
  29. fields.Add("CreateDate"); //添加时间
  30. fields.Add("Status"); //状态
  31. fields.Add("PartnerId"); //伙伴Id
  32. fields.Add("TradeMonth"); //交易月
  33. fields.Add("BrandId"); //品牌
  34. fields.Add("ActCount"); //激活数
  35. fields.Add("TradeDate"); //交易日
  36. fields.Add("UserId"); //创客
  37. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("BusinessActSummary", relationData, orderBy, page, limit, condition, fields);
  38. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  39. count = int.Parse(obj["count"].ToString());
  40. return diclist;
  41. }
  42. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  43. {
  44. List<string> fields = new List<string>(); //要显示的列
  45. fields.Add("Id");
  46. fields.Add("CreateDate"); //添加时间
  47. fields.Add("Status"); //状态
  48. fields.Add("PartnerId"); //伙伴Id
  49. fields.Add("TradeMonth"); //交易月
  50. fields.Add("BrandId"); //品牌
  51. fields.Add("ActCount"); //激活数
  52. fields.Add("TradeDate"); //交易日
  53. fields.Add("UserId"); //创客
  54. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("BusinessActSummary", relationData, orderBy, page, limit, condition, fields);
  55. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  56. return diclist;
  57. }
  58. /// <summary>
  59. /// 查询一条记录
  60. /// </summary>
  61. /// <param name="Id">主键Id</param>
  62. /// <returns></returns>
  63. public static BusinessActSummary Query(int Id)
  64. {
  65. WebCMSEntities db = new WebCMSEntities();
  66. BusinessActSummary editData = db.BusinessActSummary.FirstOrDefault(m => m.Id == Id) ?? new BusinessActSummary();
  67. db.Dispose();
  68. return editData;
  69. }
  70. public static BusinessActSummary Query(string condition, string fields = "*")
  71. {
  72. DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail(fields, "BusinessActSummary", condition);
  73. if (dt.Rows.Count > 0)
  74. {
  75. Dictionary<string, object> row = new Dictionary<string, object>();
  76. foreach (DataColumn dc in dt.Columns)
  77. {
  78. row.Add(dc.ColumnName, dt.Rows[0][dc.ColumnName].ToString());
  79. }
  80. return Newtonsoft.Json.JsonConvert.DeserializeObject<BusinessActSummary>(Newtonsoft.Json.JsonConvert.SerializeObject(row));
  81. }
  82. return new BusinessActSummary();
  83. }
  84. public static decimal Sum(string condition, string field)
  85. {
  86. DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("Sum(" + field + ")", "BusinessActSummary", condition);
  87. decimal amount = 0;
  88. if (dt.Rows.Count > 0)
  89. {
  90. amount = decimal.Parse(dt.Rows[0][0].ToString());
  91. }
  92. return amount;
  93. }
  94. /// <summary>
  95. /// 查询记录数
  96. /// </summary>
  97. /// <param name="Id">主键Id</param>
  98. /// <returns></returns>
  99. public static int Count(string condition = "", string field = "Id")
  100. {
  101. int result = 0;
  102. DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("count(" + field + ")", "BusinessActSummary", condition);
  103. if (dt.Rows.Count > 0)
  104. {
  105. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  106. }
  107. return result;
  108. }
  109. /// <summary>
  110. /// 查询是否存在
  111. /// </summary>
  112. /// <param name="Id">主键Id</param>
  113. /// <returns></returns>
  114. public static bool Exist(int Id)
  115. {
  116. WebCMSEntities db = new WebCMSEntities();
  117. bool check = db.BusinessActSummary.Any(m => m.Id == Id);
  118. db.Dispose();
  119. return check;
  120. }
  121. /// <summary>
  122. /// 添加数据
  123. /// </summary>
  124. /// <param name="Fields">要设置的字段</param>
  125. /// <returns></returns>
  126. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  127. {
  128. if (check)
  129. {
  130. }
  131. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("BusinessActSummary", fields, 0);
  132. return new AppResultJson() { Status = "1", Data = Id };
  133. }
  134. /// <summary>
  135. /// 修改数据
  136. /// </summary>
  137. /// <param name="Fields">要设置的字段</param>
  138. /// <param name="Id">主键Id</param>
  139. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  140. {
  141. if (check)
  142. {
  143. }
  144. new DbService(AppConfig.Base.mainTables, _conn).Edit("BusinessActSummary", fields, Id);
  145. return new AppResultJson() { Status = "1", Data = Id };
  146. }
  147. /// <summary>
  148. /// 逻辑删除
  149. /// </summary>
  150. /// <param name="Id">主键Id</param>
  151. public static void Remove(int Id)
  152. {
  153. Dictionary<string, object> fields = new Dictionary<string, object>();
  154. fields.Add("Status", -1);
  155. new DbService(AppConfig.Base.mainTables, _conn).Edit("BusinessActSummary", fields, Id);
  156. }
  157. /// <summary>
  158. /// 删除数据
  159. /// </summary>
  160. /// <param name="Id">主键Id</param>
  161. public static void Delete(int Id)
  162. {
  163. new DbService(AppConfig.Base.mainTables, _conn).Delete("BusinessActSummary", Id);
  164. }
  165. /// <summary>
  166. /// 排序
  167. /// </summary>
  168. /// <param name="Id">主键Id</param>
  169. /// <param name="Sort">排序序号</param>
  170. public static void Sort(int Id, int Sort)
  171. {
  172. new DbService(AppConfig.Base.mainTables, _conn).Sort("BusinessActSummary", Sort, Id);
  173. }
  174. /// <summary>
  175. /// 导入数据
  176. /// </summary>
  177. /// <param name="ExcelData">json数据</param>
  178. public static void Import(string ExcelData)
  179. {
  180. WebCMSEntities db = new WebCMSEntities();
  181. JsonData list = JsonMapper.ToObject(ExcelData);
  182. for (int i = 1; i < list.Count; i++)
  183. {
  184. JsonData dr = list[i];
  185. db.BusinessActSummary.Add(new BusinessActSummary()
  186. {
  187. CreateDate = DateTime.Now,
  188. UpdateDate = DateTime.Now,
  189. });
  190. db.SaveChanges();
  191. }
  192. db.Dispose();
  193. }
  194. /// <summary>
  195. /// 导出excel表格
  196. /// </summary>
  197. /// <param name="fields">查询条件(单个字段)</param>
  198. /// <param name="condition">查询条件(sql语句)</param>
  199. /// <returns></returns>
  200. // public static void ExportExcel(List<RelationData> relationData, string condition)
  201. // {
  202. // }
  203. }
  204. }