Ver Código Fonte

关键词统计

duhongyu 4 anos atrás
pai
commit
0a2b07483e

BIN
.vs/CallCenter_AY/v15/.suo


+ 57 - 6
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/report/DataAnalysisController.cs

@@ -142,7 +142,7 @@ namespace CallCenterApi.Interface.Controllers.report
142 142
         /// <param name="date"></param>
143 143
         /// <param name="isdc"></param>
144 144
         /// <returns></returns>
145
-        public ActionResult GetKeyReport_1(string sdate, string edate, string source , int isdc = 0)
145
+        public ActionResult GetKeyReport_1(string sdate, string edate, string source , int isdc = 0, int pid = 38)
146 146
         {
147 147
             DateTime dttime = DateTime.Now;
148 148
             if (string.IsNullOrEmpty(sdate))
@@ -153,15 +153,66 @@ namespace CallCenterApi.Interface.Controllers.report
153 153
             {
154 154
                 edate = dttime.ToString("yyyy-MM-dd") + " 23:59:59";
155 155
             }
156
-            string sql = "";
156
+            string lsql = "";
157 157
             if (!string.IsNullOrEmpty(source))
158 158
             {
159
-                sql += "and F_InfoSource='"+ source + "'";
159
+                lsql += "and F_InfoSource='"+ source + "'";
160 160
             }
161
-            var lsql = "select F_Key  ,COUNT(1) as keycount ,dbo.GetDictionaryName(F_Key) as keyname  from T_Bus_WorkOrder where F_CreateTime between '"+ sdate + "' and '"+ edate + "' and F_IsDelete = 0 "+sql +"  group by F_Key order by keycount desc";
162
-            var db = DbHelperSQL.Query(lsql).Tables[0];
163
-            return Success("成功", db);
161
+            //var lsql = "select F_Key  ,COUNT(1) as keycount ,dbo.GetDictionaryName(F_Key) as keyname  from T_Bus_WorkOrder where F_CreateTime between '"+ sdate + "' and '"+ edate + "' and F_IsDelete = 0 "+sql +"  group by F_Key order by keycount desc";
162
+            //var db = DbHelperSQL.Query(lsql).Tables[0];
163
+            //return Success("成功", db);
164
+
165
+
166
+            var date = DateTime.Now;
167
+            string sql = $" select F_Key ,count(1) keycount from dbo.T_Bus_WorkOrder where F_IsDelete=0 and F_CreateTime between '" + sdate + "' and '" + edate + "' "+ lsql + "group by F_Key ";
168
+            DataTable dt = DbHelperSQL.Query(sql).Tables[0];
169
+
170
+            var keyAllList = new BLL.T_Sys_DictionaryValue().GetModelList(" F_State=0 ");
171
+            var keylist = keyAllList.Where(p => p.F_PrentId == pid).ToList();
172
+            int total = 0;
173
+            var list = keylist.Select(p =>
174
+            {
175
+                var ids = getChildren(keyAllList, p.F_ValueId);
176
+                ids.Insert(0, p.F_ValueId);
177
+                int sum = dt.Select(" F_Key in (" + string.Join(",", ids) + ") ").Sum(x => x.Field<int>("keycount"));
178
+                total += sum;
179
+                return new
180
+                {
181
+                    F_Key = p.F_ValueId,
182
+                    keyname = p.F_Value,
183
+                    keycount = sum
184
+                };
185
+            }).ToList();
186
+
187
+            var listrate = list.Select(p => new
188
+            {
189
+                p.F_Key,
190
+                p.keyname,
191
+                p.keycount,
192
+            });
193
+
194
+            return Success("加载成功", listrate.OrderByDescending(p => p.keycount));
195
+        }
196
+        /// <summary>
197
+        /// 获取父级下的所有子级id
198
+        /// </summary>
199
+        /// <param name="list"></param>
200
+        /// <param name="pid"></param>
201
+        /// <returns></returns>
202
+        private List<int> getChildren(List<Model.T_Sys_DictionaryValue> list, int pid)
203
+        {
204
+            List<int> ids = new List<int>();
205
+            var clist = list.Where(p => p.F_PrentId == pid).ToList();
206
+            foreach (var d in clist)
207
+            {
208
+                ids.Add(d.F_ValueId);
209
+                ids = ids.Union(getChildren(list, d.F_ValueId)).ToList();
210
+            }
211
+            return ids;
164 212
         }
213
+
214
+
215
+
165 216
         //public ActionResult GetKeyReport1(string date, int isdc = 0)
166 217
         //{
167 218
         //    DateTime dttime = DateTime.Now;