machenyang лет назад: 8
Родитель
Сommit
ecd23895c8

+ 183 - 0
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/report/ZuoXiManYiDuController.cs

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