瀏覽代碼

录音文件导出

duhongyu 6 年之前
父節點
當前提交
4e24d3b08e

+ 2 - 0
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Configs/system.config

@@ -33,4 +33,6 @@
33 33
   <!-- ================== 5:Redis配置 ================== -->
34 34
   <add key="Redis_Server" value="192.168.4.18" />
35 35
   <add key="Redis_Port" value="6379" />
36
+  <!-- 录音存储地址 -->
37
+  <add key="Sound_recording" value="D:\\CallCenter_Sound\" />
36 38
 </appSettings>

+ 126 - 0
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/tel/CallrecordsController.cs

@@ -5,7 +5,9 @@ using CallCenterApi.Interface.Controllers.Base;
5 5
 using System;
6 6
 using System.Collections.Generic;
7 7
 using System.Data;
8
+using System.IO;
8 9
 using System.Linq;
10
+using System.Net;
9 11
 using System.Web;
10 12
 using System.Web.Mvc;
11 13
 
@@ -124,6 +126,130 @@ namespace CallCenterApi.Interface.Controllers.tel
124 126
 
125 127
             return Content(obj.ToJson());
126 128
         }
129
+   
130
+        private string filePath = Configs.GetValue("Sound_recording");
131
+        /// <summary>
132
+        /// 导出录音文件
133
+        /// </summary>
134
+        /// <returns></returns>
135
+        public ActionResult ExitSound(string phone, string usercode)
136
+        {
137
+            int userId = CurrentUser.UserData.F_UserId;
138
+            Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
139
+
140
+            string sql = "";
141
+
142
+            string callstate = HttpUtility.UrlDecode(RequestString.GetQueryString("callstate"));
143
+            string calltype = HttpUtility.UrlDecode(RequestString.GetQueryString("calltype"));
144
+            string starttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
145
+            string endtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
146
+            string dept = HttpUtility.UrlDecode(RequestString.GetQueryString("dept"));
147
+            string dealtype = HttpUtility.UrlDecode(RequestString.GetQueryString("dealtype"));
148
+            if (!string.IsNullOrEmpty(userModel.groupcode))
149
+            {
150
+                sql += " and groupcode = '" + userModel.groupcode + "' ";
151
+            }
152
+
153
+            if (usercode != null && usercode.Trim() != "")
154
+            {
155
+                sql += " and UserCode='" + usercode + "'";
156
+            }
157
+            if (dept != null && dept.Trim() != "")
158
+            {
159
+                sql += " and F_DeptId='" + dept.Trim() + "'";
160
+            }
161
+            if (dealtype != null && dealtype.Trim() != "")
162
+            {
163
+                //处理方式
164
+                sql += " and DealType = " + dealtype + " ";
165
+            }
166
+            if (phone != null && phone.Trim() != "")
167
+            {
168
+                sql += " and CallNumber like '%" + phone + "%'";
169
+            }
170
+            if (callstate.Trim() != "")
171
+            {
172
+                sql += " and CallState='" + callstate + "'";
173
+            }
174
+            if (calltype.Trim() != "")
175
+            {
176
+                sql += " and CallType='" + calltype + "'";
177
+            }
178
+            if (starttime.Trim() != "")
179
+            {
180
+                sql += " and datediff(day,BeginTime,'" + starttime + "')<=0 ";
181
+            }
182
+            if (endtime.Trim() != "")
183
+            {
184
+                sql += " and datediff(day,BeginTime,'" + endtime + "')>=0 ";
185
+            }
186
+            var CallList = new BLL.T_Call_CallRecords().GetModelList("FilePath !='' "+ sql);
187
+            var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
188
+            // 如果文件不存在,创建文件; 如果存在,覆盖文件 
189
+            try
190
+            {
191
+                if (!Directory.Exists(filePath))
192
+                {
193
+                    Directory.CreateDirectory(filePath);
194
+                }
195
+                if (CallList!=null )
196
+                {
197
+                    foreach (var it in CallList)
198
+                    {
199
+                        string FilePath = "";
200
+                        if (it.FilePath != "" && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
201
+                        {
202
+                            var ym = config.F_ParamValue;
203
+                            if (ym.Substring(ym.Length - 1) == "/")
204
+                            {
205
+                                ym = ym.Substring(0, ym.Length - 1);
206
+                            }
207
+                            FilePath = ym + it.FilePath.Substring(it.FilePath.IndexOf(':') + 1).Replace('\\', '/');
208
+                        }
209
+                      
210
+                       
211
+                        string filename = "l"+ it.FilePath.Split ('l')[1];
212
+                        filename = filename.Split('.')[0] + "_" + it.CallNumber + ".mp3";
213
+                        try
214
+                        {
215
+                            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FilePath);
216
+                            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
217
+                            Stream responseStream = response.GetResponseStream();
218
+                            string[] sArray = filename.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
219
+                            string flie = @"" + filePath +"\\"+ sArray[0] + "\\" + sArray[1] + "\\" + sArray[2];
220
+                            if (!Directory.Exists(flie))
221
+                            {
222
+                                Directory.CreateDirectory(flie);
223
+                            }
224
+                            if (System.IO.File.Exists(flie + "\\" + sArray[3]))
225
+                            {
226
+                                continue;
227
+                            }
228
+                            Stream stream = new FileStream(flie + "\\"+ sArray[3], FileMode.Create);
229
+                            byte[] bArr = new byte[1024];
230
+                            int size = responseStream.Read(bArr, 0, bArr.Length);
231
+                            while (size > 0)
232
+                            {
233
+                                stream.Write(bArr, 0, size);
234
+                                size = responseStream.Read(bArr, 0, bArr.Length);
235
+                            }
236
+                            stream.Close();
237
+                            responseStream.Close();
238
+                        }
239
+                        catch (Exception e)
240
+                        {
241
+                            continue;
242
+                        }
243
+                    }
244
+                }
245
+                return Success("导出成功");
246
+            }
247
+
248
+            catch (Exception e)
249
+            {
250
+                throw;
251
+            }
252
+        }
127 253
 
128 254
         /// <summary>
129 255
         /// 获取实体