MerchantTradeSummaryService.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. /// <summary>
  38. /// 查询一条记录
  39. /// </summary>
  40. /// <param name="Id">主键Id</param>
  41. /// <returns></returns>
  42. public MerchantTradeSummary Query(int MerchantId, string TradeDate)
  43. {
  44. WebCMSEntities db = new WebCMSEntities();
  45. MerchantTradeSummary editData = db.MerchantTradeSummary.FirstOrDefault(m => m.MerchantId == MerchantId && m.TradeDate == TradeDate) ?? new MerchantTradeSummary();
  46. db.Dispose();
  47. return editData;
  48. }
  49. public Dictionary<string, string> Sum(string field, string condition)
  50. {
  51. Dictionary<string, string> result = new Dictionary<string, string>();
  52. string sumString = "";
  53. string[] fieldlist = field.Split(',');
  54. foreach(string f in fieldlist)
  55. {
  56. sumString += "sum(" + f + ") " + f + ",";
  57. }
  58. sumString = sumString.TrimEnd(',');
  59. DataTable dt = CustomerSqlConn.dtable("select " + sumString + " from MerchantTradeSummary where 1=1" + condition, _conn);
  60. if(dt.Rows.Count > 0)
  61. {
  62. foreach(string f in fieldlist)
  63. {
  64. result.Add(f, function.CheckNum(dt.Rows[0][f].ToString()));
  65. }
  66. }
  67. return result;
  68. }
  69. /// <summary>
  70. /// 添加数据
  71. /// </summary>
  72. /// <param name="Fields">要设置的字段</param>
  73. /// <returns></returns>
  74. public int Add(Dictionary<string, object> Fields)
  75. {
  76. return new DbService(AppConfig.Base.statTables, _conn).Add("MerchantTradeSummary", Fields, 0);
  77. }
  78. /// <summary>
  79. /// 修改数据
  80. /// </summary>
  81. /// <param name="Fields">要设置的字段</param>
  82. /// <param name="Id">主键Id</param>
  83. public void Edit(Dictionary<string, object> Fields, int Id)
  84. {
  85. new DbService(AppConfig.Base.statTables, _conn).Edit("MerchantTradeSummary", Fields, Id);
  86. }
  87. /// <summary>
  88. /// 删除数据
  89. /// </summary>
  90. /// <param name="Id">主键Id</param>
  91. public void Delete(int Id)
  92. {
  93. new DbService(AppConfig.Base.statTables, _conn).Delete("MerchantTradeSummary", Id);
  94. }
  95. /// <summary>
  96. /// 排序
  97. /// </summary>
  98. /// <param name="Id">主键Id</param>
  99. /// <param name="Sort">排序序号</param>
  100. public void Sort(int Id, int Sort)
  101. {
  102. new DbService(AppConfig.Base.statTables, _conn).Sort("MerchantTradeSummary", Sort, Id);
  103. }
  104. /// <summary>
  105. /// 导入数据
  106. /// </summary>
  107. /// <param name="ExcelData">json数据</param>
  108. public void Import(string ExcelData)
  109. {
  110. WebCMSEntities db = new WebCMSEntities();
  111. JsonData list = JsonMapper.ToObject(ExcelData);
  112. for (int i = 1; i < list.Count;i++ )
  113. {
  114. JsonData dr = list[i];
  115. db.MerchantTradeSummary.Add(new MerchantTradeSummary()
  116. {
  117. CreateDate = DateTime.Now,
  118. UpdateDate = DateTime.Now,
  119. });
  120. db.SaveChanges();
  121. }
  122. db.Dispose();
  123. }
  124. /// <summary>
  125. /// 导出excel表格
  126. /// </summary>
  127. /// <param name="fields">查询条件(单个字段)</param>
  128. /// <param name="condition">查询条件(sql语句)</param>
  129. /// <returns></returns>
  130. public Dictionary<string, object> ExportExcel(List<FieldItem> fields, string condition, string orderby = "Id desc")
  131. {
  132. Dictionary<string, object> obj = new DbService(AppConfig.Base.statTables, _conn).IndexData("MerchantTradeSummary", fields, orderby, "0", 1, 20000, condition, "Id", false);
  133. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  134. foreach (Dictionary<string, object> dic in diclist)
  135. {
  136. }
  137. Dictionary<string, object> result = new Dictionary<string, object>();
  138. result.Add("Status", "1");
  139. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  140. result.Add("Obj", diclist);
  141. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  142. result.Add("Fields", ReturnFields);
  143. return result;
  144. }
  145. }
  146. }