| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- using CallCenter.Utility;
- using CallCenterApi.Interface.Controllers.Base;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace CallCenterApi.Interface.Controllers.report
- {
- public class ZuoXiManYiDuController : BaseController
- {
- //// GET: ZuoXiManYiDu
- //public ActionResult Index()
- //{
- // return View();
- //}
- //坐席满意度
- //获取表头
- public ActionResult GetColumnList()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- String[] str = { "坐席姓名", "非常满意", "非常满意占比", "基本满意", "基本满意占比", "不满意", "不满意占比", "未评价", "未评价占比" };
- res = Success("获取坐席满意度评价情况报表表头成功", str);
- return res;
- }
- //获取数据
- public ActionResult GetDataList(string stime, string endtime)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- DataTable dtNew = new DataTable();
- dtNew = getData(stime, endtime);
- res = Success("获取坐席满意度评价情况报表数据成功", dtNew);
- return res;
- }
- //导出数据
- public ActionResult ExptList(string stime, string endtime)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- NPOIHelper npoi = new NPOIHelper();
- DataTable dt = getData(stime, endtime);
- if (npoi.ExportToExcel("坐席满意度评价情况", dt) == "")
- {
- return Success("导出成功");
- }
- else
- {
- return Error("导出失败");
- }
- }
- return res;
- }
- private DataTable getData(string stime, string endtime)
- {
- DataTable dtNew = new DataTable();
- #region
- DataColumn dc1 = new DataColumn("坐席姓名");
- DataColumn dc2 = new DataColumn("非常满意");
- DataColumn dc3 = new DataColumn("非常满意占比");
- DataColumn dc4 = new DataColumn("基本满意");
- DataColumn dc5 = new DataColumn("基本满意占比");
- DataColumn dc6 = new DataColumn("不满意");
- DataColumn dc7 = new DataColumn("不满意占比");
- DataColumn dc8 = new DataColumn("未评价");
- DataColumn dc9 = new DataColumn("未评价占比");
- dtNew.Columns.Add(dc1);
- dtNew.Columns.Add(dc2);
- dtNew.Columns.Add(dc3);
- dtNew.Columns.Add(dc4);
- dtNew.Columns.Add(dc5);
- dtNew.Columns.Add(dc6);
- dtNew.Columns.Add(dc7);
- dtNew.Columns.Add(dc8);
- dtNew.Columns.Add(dc9);
- #endregion
- string sqltimeCallRecords = "";
- string time = "";
- if (stime != null && stime.Trim() != "")
- {
- time += " and CONVERT(varchar , BeginTime, 120)>=CONVERT(varchar , '" + stime.Trim() + " 00:00:01', 120) ";
- }
- if (endtime != null && endtime.Trim() != "")
- {
- time += " and CONVERT(varchar , BeginTime, 120)<=CONVERT(varchar , '" + endtime.Trim() + " 23:59:59', 120) ";
- }
- //存储数据
- Dictionary<string, List<List<string>>> body = new Dictionary<string, List<List<string>>>();
- //坐席
- DataTable dtable = new BLL.T_Sys_UserAccount().GetList("F_RoleId in (1,4,28,29) and F_DeleteFlag=0").Tables[0];//客服坐席、班长坐席、售前坐席、投诉坐席
- int allcount = dtable.Rows.Count;
- for (int i = 0; i < allcount; i++)
- {
- int userid = Convert.ToInt32(dtable.Rows[i]["F_UserId"].ToString());
- List<string> bodyitem = new List<string>();
- string[] UNDN = getRoleNameAndUserName(userid);
- bodyitem.Add(UNDN[2]);
- DataTable dt = new BLL.T_Call_CallRecords().GetList("UserId='" + userid + "'" + time).Tables[0];
- //1非常满意、2基本满意、3不满意、4未评价
- for (int j = 1; j <= 4; j++)
- {
- string[] cp = getMYDCountAndPercent(dt, j);
- bodyitem.AddRange(cp);
- }
- if (body.ContainsKey(UNDN[1]))
- {
- body[UNDN[1]].Add(bodyitem);
- }
- else
- {
- List<List<string>> bodylist = new List<List<string>>();
- bodylist.Add(bodyitem);
- body.Add(UNDN[1], bodylist);
- }
- }
- foreach (string key in body.Keys)
- {
- DataRow dr = dtNew.NewRow();
- int count = body[key].Count;
- foreach (List<string> listiteam in body[key])
- {
- dr["坐席姓名"] = listiteam[0].ToString();
- dr["非常满意"] = listiteam[1].ToString();
- dr["非常满意占比"] = listiteam[2].ToString();
- dr["基本满意"] = listiteam[3].ToString();
- dr["基本满意占比"] = listiteam[4].ToString();
- dr["不满意"] = listiteam[5].ToString();
- dr["不满意占比"] = listiteam[6].ToString();
- dr["未评价"] = listiteam[7].ToString();
- dr["未评价占比"] = listiteam[8].ToString();
- }
- dtNew.Rows.Add(dr);
- }
- return dtNew;
- }
- /// <summary>
- /// 通过UserId得到角色和姓名
- /// </summary>
- /// <param name="userid"></param>
- /// <returns></returns>
- private string[] getRoleNameAndUserName(int userid)
- {
- var user = new BLL.T_Sys_UserAccount().GetModel(userid);
- string[] resarr = new string[3];
- if (user != null)
- {
- var role = new BLL.T_Sys_RoleInfo().GetModel(user.F_RoleId);
- if (role != null)
- {
- resarr[0] = role.F_RoleName;
- }
- resarr[1] = user.F_UserCode;
- //姓名会重复 但后面要显示姓名
- resarr[2] = user.F_UserName;
- }
- return resarr;
- }
- /// <summary>
- /// 每种满意度的个数和占比
- /// </summary>
- /// <param name="dt"></param>
- /// <param name="type"></param>
- /// <returns></returns>
- private string[] getMYDCountAndPercent(DataTable dt, int type)
- {
- int allcount = dt.Rows.Count;
- int typecount = 0;
- if (type == 4) typecount = dt.Select("MYD IS NULL").Count();
- else typecount = dt.Select("MYD=" + type).Count();
- string percent = "0.00";
- if (allcount > 0) percent = (typecount * 1.0 / allcount).ToString("0.00");
- return new string[] { typecount.ToString(), percent };
- }
- }
- }
|