Нет описания

GDLYController.cs 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using CallCenter.Utility;
  2. using CallCenterApi.DB;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Web;
  9. using System.Web.Mvc;
  10. namespace CallCenterApi.Interface.Controllers.report
  11. {
  12. public class GDLYController : BaseController
  13. {
  14. //// GET: GDLY
  15. //public ActionResult Index()
  16. //{
  17. // return View();
  18. //}
  19. /// <summary>
  20. /// 获取工单来源报表
  21. /// </summary>
  22. /// <param name="stime"></param>
  23. /// <param name="endtime"></param>
  24. /// <returns></returns>
  25. public ActionResult GetDataList(string stime, string endtime)
  26. {
  27. ActionResult res = NoToken("未知错误,请重新登录");
  28. DataTable dtNew = new DataTable();
  29. dtNew = getData(stime, endtime);
  30. res = Success("获取工单来源数据成功", dtNew);
  31. return res;
  32. }
  33. private DataTable getData(string stime, string endtime)
  34. {
  35. DataTable dtNew = new DataTable();
  36. #region 添加表格标题
  37. DataColumn dc = new DataColumn("坐席人员");
  38. dtNew.Columns.Add(dc);
  39. var sqlGDLY = " and F_State=1 and F_DictionaryFlag='GDLY' ";
  40. var recordCount = 0;
  41. var dtGDLY = BLL.PagerBLL.GetListPager(
  42. "T_Sys_DictionaryValue",
  43. "F_DictionaryValueId",
  44. "*",
  45. sqlGDLY,
  46. "ORDER BY F_Sort ",
  47. 10,
  48. 1,
  49. true,
  50. out recordCount);
  51. List<Model.T_Sys_DictionaryValue> modelList = new BLL.T_Sys_DictionaryValue().DataTableToList(dtGDLY);
  52. for (int i = 0; i < modelList.Count; i++)
  53. {
  54. string colname = modelList[i].F_Name;
  55. dtNew.Columns.Add(new DataColumn(colname));
  56. }
  57. #endregion
  58. string sqltimeCallRecords = "";
  59. if (stime != null && stime.Trim() != "")
  60. {
  61. sqltimeCallRecords += " and CONVERT(varchar , CreateTime, 120)>=CONVERT(varchar , '" + stime.Trim() + " 00:00:01', 120) ";
  62. }
  63. if (endtime != null && endtime.Trim() != "")
  64. {
  65. sqltimeCallRecords += " and CONVERT(varchar , CreateTime, 120)<=CONVERT(varchar , '" + endtime.Trim() + " 23:59:59', 120) ";
  66. }
  67. double day = 0;
  68. if (stime != null && endtime != null && endtime.Trim() != "" && stime.Trim() != "")
  69. {
  70. TimeSpan time = Convert.ToDateTime(endtime) - Convert.ToDateTime(stime);
  71. day = time.Days + 1;
  72. }
  73. //获取坐席数据
  74. DataTable dt = new DataTable();
  75. string sql = "SELECT * from T_Sys_UserAccount where F_DeleteFlag=0 order by F_Userid asc";
  76. dt = DbHelperSQL.Query(sql).Tables[0];
  77. for (int i = 0; i < dt.Rows.Count; i++)
  78. {
  79. DataRow drNew = dtNew.NewRow();
  80. drNew["坐席人员"] = dt.Rows[i]["F_UserName"].ToString();
  81. //获取工单来源数据
  82. DataTable dtnew = new DataTable();
  83. string sqlnew = "select * from T_Sys_DictionaryValue where F_State=1 and F_DictionaryFlag='GDLY'";
  84. dtnew = DbHelperSQL.Query(sqlnew).Tables[0];
  85. for (int j = 0; j < dtnew.Rows.Count; j++)
  86. {
  87. string str = "select count(*) from T_Wo_WorkOrder where IsDel=0 and type=" + Convert.ToInt32(dtnew.Rows[j]["F_DictionaryValueId"].ToString()) + " and CreateUserID='" + dt.Rows[i]["F_Userid"].ToString() + "'" + sqltimeCallRecords;
  88. DataTable dtj = DbHelperSQL.Query(str).Tables[0];
  89. int sum = 0;
  90. if (dtj.Rows[0][0] != null && dtj.Rows[0][0].ToString() != "")
  91. {
  92. sum = Convert.ToInt32(dtj.Rows[0][0]);
  93. }
  94. drNew[j + 1] = sum.ToString();
  95. }
  96. dtNew.Rows.Add(drNew);
  97. }
  98. return dtNew;
  99. }
  100. /// <summary>
  101. /// 导出excel
  102. /// </summary>
  103. /// <returns></returns>
  104. public ActionResult ExportExcel(string stime, string endtime)
  105. {
  106. ActionResult res = NoToken("未知错误,请重新登录");
  107. if (Request.IsAuthenticated)
  108. {
  109. //导出dtnew
  110. NPOIHelper npoi = new NPOIHelper();
  111. DataTable dt = getData(stime, endtime);
  112. if (npoi.ExportToExcel("工单来源数据报表", dt, null) == "")
  113. {
  114. return Success("导出成功");
  115. }
  116. else
  117. {
  118. return Error("导出失败");
  119. }
  120. }
  121. return res;
  122. }
  123. }
  124. }