Нет описания

ZuoXiManYiDuController.cs 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using CallCenter.Utility;
  2. using CallCenterApi.Interface.Controllers.Base;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. namespace CallCenterApi.Interface.Controllers.report
  10. {
  11. public class ZuoXiManYiDuController : BaseController
  12. {
  13. //// GET: ZuoXiManYiDu
  14. //public ActionResult Index()
  15. //{
  16. // return View();
  17. //}
  18. //坐席满意度
  19. //获取表头
  20. public ActionResult GetColumnList()
  21. {
  22. ActionResult res = NoToken("未知错误,请重新登录");
  23. String[] str = { "坐席姓名", "非常满意", "非常满意占比", "基本满意", "基本满意占比", "不满意", "不满意占比", "未评价", "未评价占比" };
  24. res = Success("获取坐席满意度评价情况报表表头成功", str);
  25. return res;
  26. }
  27. //获取数据
  28. public ActionResult GetDataList(string stime, string endtime)
  29. {
  30. ActionResult res = NoToken("未知错误,请重新登录");
  31. DataTable dtNew = new DataTable();
  32. dtNew = getData(stime, endtime);
  33. res = Success("获取坐席满意度评价情况报表数据成功", dtNew);
  34. return res;
  35. }
  36. //导出数据
  37. public ActionResult ExptList(string stime, string endtime)
  38. {
  39. ActionResult res = NoToken("未知错误,请重新登录");
  40. if (Request.IsAuthenticated)
  41. {
  42. NPOIHelper npoi = new NPOIHelper();
  43. DataTable dt = getData(stime, endtime);
  44. if (npoi.ExportToExcel("坐席满意度评价情况", dt) == "")
  45. {
  46. return Success("导出成功");
  47. }
  48. else
  49. {
  50. return Error("导出失败");
  51. }
  52. }
  53. return res;
  54. }
  55. private DataTable getData(string stime, string endtime)
  56. {
  57. DataTable dtNew = new DataTable();
  58. #region
  59. DataColumn dc1 = new DataColumn("坐席姓名");
  60. DataColumn dc2 = new DataColumn("非常满意");
  61. DataColumn dc3 = new DataColumn("非常满意占比");
  62. DataColumn dc4 = new DataColumn("基本满意");
  63. DataColumn dc5 = new DataColumn("基本满意占比");
  64. DataColumn dc6 = new DataColumn("不满意");
  65. DataColumn dc7 = new DataColumn("不满意占比");
  66. DataColumn dc8 = new DataColumn("未评价");
  67. DataColumn dc9 = new DataColumn("未评价占比");
  68. dtNew.Columns.Add(dc1);
  69. dtNew.Columns.Add(dc2);
  70. dtNew.Columns.Add(dc3);
  71. dtNew.Columns.Add(dc4);
  72. dtNew.Columns.Add(dc5);
  73. dtNew.Columns.Add(dc6);
  74. dtNew.Columns.Add(dc7);
  75. dtNew.Columns.Add(dc8);
  76. dtNew.Columns.Add(dc9);
  77. #endregion
  78. string sqltimeCallRecords = "";
  79. string time = "";
  80. if (stime != null && stime.Trim() != "")
  81. {
  82. time += " and CONVERT(varchar , BeginTime, 120)>=CONVERT(varchar , '" + stime.Trim() + " 00:00:01', 120) ";
  83. }
  84. if (endtime != null && endtime.Trim() != "")
  85. {
  86. time += " and CONVERT(varchar , BeginTime, 120)<=CONVERT(varchar , '" + endtime.Trim() + " 23:59:59', 120) ";
  87. }
  88. //存储数据
  89. Dictionary<string, List<List<string>>> body = new Dictionary<string, List<List<string>>>();
  90. //坐席
  91. DataTable dtable = new BLL.T_Sys_UserAccount().GetList("F_RoleId in (1,4,28,29) and F_DeleteFlag=0").Tables[0];//客服坐席、班长坐席、售前坐席、投诉坐席
  92. int allcount = dtable.Rows.Count;
  93. for (int i = 0; i < allcount; i++)
  94. {
  95. int userid = Convert.ToInt32(dtable.Rows[i]["F_UserId"].ToString());
  96. List<string> bodyitem = new List<string>();
  97. string[] UNDN = getRoleNameAndUserName(userid);
  98. bodyitem.Add(UNDN[2]);
  99. DataTable dt = new BLL.T_Call_CallRecords().GetList("UserId='" + userid + "'" + time).Tables[0];
  100. //1非常满意、2基本满意、3不满意、4未评价
  101. for (int j = 1; j <= 4; j++)
  102. {
  103. string[] cp = getMYDCountAndPercent(dt, j);
  104. bodyitem.AddRange(cp);
  105. }
  106. if (body.ContainsKey(UNDN[1]))
  107. {
  108. body[UNDN[1]].Add(bodyitem);
  109. }
  110. else
  111. {
  112. List<List<string>> bodylist = new List<List<string>>();
  113. bodylist.Add(bodyitem);
  114. body.Add(UNDN[1], bodylist);
  115. }
  116. }
  117. foreach (string key in body.Keys)
  118. {
  119. DataRow dr = dtNew.NewRow();
  120. int count = body[key].Count;
  121. foreach (List<string> listiteam in body[key])
  122. {
  123. dr["坐席姓名"] = listiteam[0].ToString();
  124. dr["非常满意"] = listiteam[1].ToString();
  125. dr["非常满意占比"] = listiteam[2].ToString();
  126. dr["基本满意"] = listiteam[3].ToString();
  127. dr["基本满意占比"] = listiteam[4].ToString();
  128. dr["不满意"] = listiteam[5].ToString();
  129. dr["不满意占比"] = listiteam[6].ToString();
  130. dr["未评价"] = listiteam[7].ToString();
  131. dr["未评价占比"] = listiteam[8].ToString();
  132. }
  133. dtNew.Rows.Add(dr);
  134. }
  135. return dtNew;
  136. }
  137. /// <summary>
  138. /// 通过UserId得到角色和姓名
  139. /// </summary>
  140. /// <param name="userid"></param>
  141. /// <returns></returns>
  142. private string[] getRoleNameAndUserName(int userid)
  143. {
  144. var user = new BLL.T_Sys_UserAccount().GetModel(userid);
  145. string[] resarr = new string[3];
  146. if (user != null)
  147. {
  148. var role = new BLL.T_Sys_RoleInfo().GetModel(user.F_RoleId);
  149. if (role != null)
  150. {
  151. resarr[0] = role.F_RoleName;
  152. }
  153. resarr[1] = user.F_UserCode;
  154. //姓名会重复 但后面要显示姓名
  155. resarr[2] = user.F_UserName;
  156. }
  157. return resarr;
  158. }
  159. /// <summary>
  160. /// 每种满意度的个数和占比
  161. /// </summary>
  162. /// <param name="dt"></param>
  163. /// <param name="type"></param>
  164. /// <returns></returns>
  165. private string[] getMYDCountAndPercent(DataTable dt, int type)
  166. {
  167. int allcount = dt.Rows.Count;
  168. int typecount = 0;
  169. if (type == 4) typecount = dt.Select("MYD IS NULL").Count();
  170. else typecount = dt.Select("MYD=" + type).Count();
  171. string percent = "0.00";
  172. if (allcount > 0) percent = (typecount * 1.0 / allcount).ToString("0.00");
  173. return new string[] { typecount.ToString(), percent };
  174. }
  175. }
  176. }