MerchantTradeSummaryService.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.MainModels;
  5. using Library;
  6. using LitJson;
  7. using System.Data;
  8. namespace MySystem
  9. {
  10. public class MerchantTradeSummaryService
  11. {
  12. string _conn = "";
  13. public MerchantTradeSummaryService()
  14. {
  15. _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  16. }
  17. /// <summary>
  18. /// 查询列表
  19. /// </summary>
  20. /// <param name="fields">查询条件(单个字段)</param>
  21. /// <param name="condition">查询条件(sql语句)</param>
  22. /// <param name="page">页码</param>
  23. /// <param name="limit">每页条数</param>
  24. /// <returns></returns>
  25. public List<Dictionary<string, object>> List(List<FieldItem> fields, string condition, string TradeMonth, int page = 1, int limit = 30, string orderby = "Id desc")
  26. {
  27. Dictionary<string, object> obj = new DbService(AppConfig.Base.statTables, _conn).IndexData("MerchantTradeSummary" + TradeMonth, fields, orderby, "0", page, limit, condition);
  28. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  29. return diclist;
  30. }
  31. public List<Dictionary<string, object>> List2(List<FieldItem> fields, string condition, string TradeMonth, int page = 1, int limit = 30, string orderby = "Id desc")
  32. {
  33. Dictionary<string, object> obj = new DbService(AppConfig.Base.statTables, AppConfig.Base.StatConnRds).IndexData("MerchantTradeSummaryList" + TradeMonth, fields, orderby, "0", page, limit, condition);
  34. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  35. return diclist;
  36. }
  37. public bool CheckTableExist(string date)
  38. {
  39. DataTable dt = CustomerSqlConn.dtable("show Tables like 'MerchantTradeSummaryList" + date + "'", AppConfig.Base.StatConnRds);
  40. if(dt.Rows.Count > 0)
  41. {
  42. return true;
  43. }
  44. return false;
  45. }
  46. /// <summary>
  47. /// 查询一条记录
  48. /// </summary>
  49. /// <param name="Id">主键Id</param>
  50. /// <returns></returns>
  51. public MerchantTradeSummary Query(int MerchantId, string TradeDate)
  52. {
  53. WebCMSEntities db = new WebCMSEntities();
  54. MerchantTradeSummary editData = db.MerchantTradeSummary.FirstOrDefault(m => m.MerchantId == MerchantId && m.TradeDate == TradeDate) ?? new MerchantTradeSummary();
  55. db.Dispose();
  56. return editData;
  57. }
  58. public Dictionary<string, string> Sum(string field, string condition)
  59. {
  60. Dictionary<string, string> result = new Dictionary<string, string>();
  61. string sumString = "";
  62. string[] fieldlist = field.Split(',');
  63. foreach(string f in fieldlist)
  64. {
  65. sumString += "sum(" + f + ") " + f + ",";
  66. }
  67. sumString = sumString.TrimEnd(',');
  68. DataTable dt = CustomerSqlConn.dtable("select " + sumString + " from MerchantTradeSummary where 1=1" + condition, _conn);
  69. if(dt.Rows.Count > 0)
  70. {
  71. foreach(string f in fieldlist)
  72. {
  73. result.Add(f, function.CheckNum(dt.Rows[0][f].ToString()));
  74. }
  75. }
  76. return result;
  77. }
  78. /// <summary>
  79. /// 添加数据
  80. /// </summary>
  81. /// <param name="Fields">要设置的字段</param>
  82. /// <returns></returns>
  83. public int Add(Dictionary<string, object> Fields)
  84. {
  85. return new DbService(AppConfig.Base.statTables, _conn).Add("MerchantTradeSummary", Fields, 0);
  86. }
  87. /// <summary>
  88. /// 修改数据
  89. /// </summary>
  90. /// <param name="Fields">要设置的字段</param>
  91. /// <param name="Id">主键Id</param>
  92. public void Edit(Dictionary<string, object> Fields, int Id)
  93. {
  94. new DbService(AppConfig.Base.statTables, _conn).Edit("MerchantTradeSummary", Fields, Id);
  95. }
  96. /// <summary>
  97. /// 删除数据
  98. /// </summary>
  99. /// <param name="Id">主键Id</param>
  100. public void Delete(int Id)
  101. {
  102. new DbService(AppConfig.Base.statTables, _conn).Delete("MerchantTradeSummary", Id);
  103. }
  104. /// <summary>
  105. /// 排序
  106. /// </summary>
  107. /// <param name="Id">主键Id</param>
  108. /// <param name="Sort">排序序号</param>
  109. public void Sort(int Id, int Sort)
  110. {
  111. new DbService(AppConfig.Base.statTables, _conn).Sort("MerchantTradeSummary", Sort, Id);
  112. }
  113. /// <summary>
  114. /// 导入数据
  115. /// </summary>
  116. /// <param name="ExcelData">json数据</param>
  117. public void Import(string ExcelData)
  118. {
  119. WebCMSEntities db = new WebCMSEntities();
  120. JsonData list = JsonMapper.ToObject(ExcelData);
  121. for (int i = 1; i < list.Count;i++ )
  122. {
  123. JsonData dr = list[i];
  124. db.MerchantTradeSummary.Add(new MerchantTradeSummary()
  125. {
  126. CreateDate = DateTime.Now,
  127. UpdateDate = DateTime.Now,
  128. });
  129. db.SaveChanges();
  130. }
  131. db.Dispose();
  132. }
  133. /// <summary>
  134. /// 导出excel表格
  135. /// </summary>
  136. /// <param name="fields">查询条件(单个字段)</param>
  137. /// <param name="condition">查询条件(sql语句)</param>
  138. /// <returns></returns>
  139. public Dictionary<string, object> ExportExcel(List<FieldItem> fields, string condition, string orderby = "Id desc")
  140. {
  141. Dictionary<string, object> obj = new DbService(AppConfig.Base.statTables, _conn).IndexData("MerchantTradeSummary", fields, orderby, "0", 1, 20000, condition, "Id", false);
  142. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  143. foreach (Dictionary<string, object> dic in diclist)
  144. {
  145. }
  146. Dictionary<string, object> result = new Dictionary<string, object>();
  147. result.Add("Status", "1");
  148. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  149. result.Add("Obj", diclist);
  150. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  151. result.Add("Fields", ReturnFields);
  152. return result;
  153. }
  154. }
  155. }