鄂尔多斯-招源科技

CallrecordsController.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Net;
  10. using System.Text;
  11. using System.Web;
  12. using System.Web.Mvc;
  13. namespace CallCenterApi.Interface.Controllers.tel
  14. {
  15. public class CallrecordsController : BaseController
  16. {
  17. private readonly BLL.T_Sys_Department deptBLL = new BLL.T_Sys_Department();
  18. //获取通话记录列表
  19. public ActionResult GetList(string phone, string usercode)
  20. {
  21. ActionResult res = NoToken("未知错误,请重新登录");
  22. if (Request.IsAuthenticated)
  23. {
  24. string sql = "";
  25. DataTable dt = new DataTable();
  26. int roleid = CurrentUser.UserData.F_RoleId;
  27. int deptid = CurrentUser.UserData.F_DeptId;
  28. string deptCode = CurrentUser.UserData.F_DeptCode;
  29. string callstate = HttpUtility.UrlDecode(RequestString.GetQueryString("callstate"));
  30. string calltype = HttpUtility.UrlDecode(RequestString.GetQueryString("calltype"));
  31. string starttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  32. string endtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  33. string dept = HttpUtility.UrlDecode(RequestString.GetQueryString("dept"));
  34. string username = HttpUtility.UrlDecode(RequestString.GetQueryString("username"));
  35. string strpageindex = RequestString.GetQueryString("page");
  36. int pageindex = 1;
  37. string strpagesize = RequestString.GetQueryString("pagesize");
  38. int pagesize = 10;
  39. //17=系统管理员,36=客服,37=组长,38=组员,39=业主,40=话务员,41=客服主管,43=分公司市场部主任,45=业务稽核,46=集团客户部,
  40. //47 =网络部,48=市场部经理,50=业务支撑中心,51=市场部,52=客户服务中心,53=总经理,54=副总经理,55=业务负责人,56=投诉处理员,57=基础业务主管,
  41. if (roleid != 0)
  42. {
  43. if (roleid != 17)
  44. {
  45. //各分公司
  46. if (deptCode.Replace("|0|1|", "").Length > 0)
  47. {
  48. if (roleid == 36 || roleid == 38 || roleid == 40)
  49. {
  50. usercode = CurrentUser.UserData.F_UserCode;
  51. sql += " and UserCode='" + usercode + "'";
  52. }
  53. else
  54. {
  55. sql += " and UserCode in (select F_UserCode from T_Sys_UserAccount where F_DeptID in (select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptCode + "%')) ";
  56. }
  57. }
  58. //总公司
  59. //else
  60. //{
  61. // sql += " and UserCode in (select F_UserCode from T_Sys_UserAccount where F_DeptId=" + deptid + ")";
  62. //}
  63. }
  64. }
  65. if (usercode != null && usercode.Trim() != "")
  66. {
  67. sql += " and UserCode='" + usercode + "'";
  68. }
  69. //if (!string.IsNullOrWhiteSpace(dept) && Convert.ToInt32(dept) >= 0)
  70. //{
  71. // sql += " and UserCode in (select F_UserCode from T_Sys_UserAccount where F_DeptId=" + dept.Trim() + ")";
  72. //}
  73. if (!string.IsNullOrWhiteSpace(dept))
  74. {
  75. var deptModel = deptBLL.GetModel(!string.IsNullOrWhiteSpace(dept) ? Convert.ToInt32(dept) : 0);
  76. if (deptModel != null)
  77. {
  78. sql += $" and UserCode in (select F_UserCode from T_Sys_UserAccount where F_DeptId in(select F_DeptId from T_Sys_Department where F_DeptCode like '{deptModel.F_DeptCode}%'))";
  79. }
  80. }
  81. if (phone != null && phone.Trim() != "")
  82. {
  83. sql += " and CallNumber like '%" + phone + "%'";
  84. }
  85. if (callstate.Trim() != "")
  86. {
  87. sql += " and CallState='" + callstate + "'";
  88. }
  89. if (calltype.Trim() != "")
  90. {
  91. sql += " and CallType='" + calltype + "'";
  92. }
  93. if (starttime.Trim() != "")
  94. {
  95. sql += " and datediff(day,BeginTime,'" + starttime + "')<=0 ";
  96. }
  97. if (endtime.Trim() != "")
  98. {
  99. sql += " and datediff(day,BeginTime,'" + endtime + "')>=0 ";
  100. }
  101. if (username.Trim() != "")
  102. {
  103. sql += " and T_Sys_UserAccount.F_UserName like '%" + username.Trim() + "%'";
  104. }
  105. if (strpageindex.Trim() != "")
  106. {
  107. pageindex = Convert.ToInt32(strpageindex);
  108. }
  109. if (strpagesize.Trim() != "")
  110. {
  111. pagesize = Convert.ToInt32(strpagesize);
  112. }
  113. int recordCount = 0;
  114. dt = BLL.PagerBLL.GetListPager(
  115. "T_Call_CallRecords left join T_Sys_UserAccount ON T_Sys_UserAccount.F_UserCode=T_Call_CallRecords.UserCode left join T_Sys_Department ON T_Sys_UserAccount.F_DeptId=T_Sys_Department.F_DeptId ",
  116. "CallRecordsId",
  117. "*,T_Sys_UserAccount.F_UserName,T_Sys_Department.F_DeptName,(SELECT F_DeptName from T_Sys_Department t where t.F_DeptId=T_Sys_Department.F_ParentId) as ParentName ",
  118. sql,
  119. "ORDER BY CallRecordsId desc",
  120. pagesize,
  121. pageindex,
  122. true,
  123. out recordCount);
  124. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  125. var users = new BLL.T_Sys_UserAccount().GetModelList("");
  126. foreach (DataRow dr in dt.Rows)
  127. {
  128. string path = dr["FilePath"] != null ? dr["FilePath"].ToString() : "";
  129. if (path != "" && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
  130. {
  131. var ym = config.F_ParamValue;
  132. if (ym.Substring(ym.Length - 1) == "/")
  133. {
  134. ym = ym.Substring(0, ym.Length - 1);
  135. }
  136. dr["FilePath"] = ym + path.Substring(path.IndexOf(':') + 1).Replace('\\', '/');
  137. }
  138. string ucode = dr["UserCode"] != null ? dr["UserCode"].ToString() : "";
  139. string uname = dr["UserName"] != null ? dr["UserName"].ToString() : "";
  140. if (ucode != "")
  141. {
  142. if (uname == "")
  143. {
  144. var uu = users.Where(u => u.F_UserCode.Equals(ucode)).FirstOrDefault();
  145. if (uu != null)
  146. dr["UserName"] = uu.F_UserName;
  147. }
  148. }
  149. }
  150. var obj = new
  151. {
  152. state = "success",
  153. message = "成功",
  154. rows = dt,
  155. total = recordCount
  156. };
  157. res = Content(obj.ToJson());
  158. }
  159. return res;
  160. }
  161. //通话记录导出
  162. public ActionResult GetListExpt(string phone, string usercode)
  163. {
  164. ActionResult res = NoToken("未知错误,请重新登录");
  165. if (Request.IsAuthenticated)
  166. {
  167. string sql = " 1=1 ";
  168. DataTable dt = new DataTable();
  169. int userid = CurrentUser.UserData.F_UserId;
  170. int roleid = CurrentUser.UserData.F_RoleId;
  171. int deptid = CurrentUser.UserData.F_DeptId;
  172. string deptcode = CurrentUser.UserData.F_DeptCode;
  173. string callstate = HttpUtility.UrlDecode(RequestString.GetQueryString("callstate"));
  174. string calltype = HttpUtility.UrlDecode(RequestString.GetQueryString("calltype"));
  175. string starttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  176. string endtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  177. string dept = HttpUtility.UrlDecode(RequestString.GetQueryString("dept"));
  178. if (roleid != 0)
  179. {
  180. if (roleid != 17)
  181. {
  182. //if (deptcode.IndexOf("|533|") > 0)
  183. //{
  184. // sql += " and UserCode in (select F_UserCode from T_Sys_UserAccount where F_DeptId=" + deptid + ")";
  185. //}
  186. if (deptcode.IndexOf("|531|") > 0)
  187. {
  188. if (roleid == 32)
  189. {
  190. usercode = CurrentUser.UserData.F_UserCode;
  191. sql += " and UserCode='" + usercode + "'";
  192. }
  193. else
  194. {
  195. sql += " and UserCode in (select F_UserCode from T_Sys_UserAccount where F_DeptID in (select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptcode + "%')) ";
  196. }
  197. }
  198. else
  199. {
  200. sql += " and UserCode in (select F_UserCode from T_Sys_UserAccount where F_DeptId=" + deptid + ")";
  201. }
  202. }
  203. }
  204. if (usercode != null && usercode.Trim() != "")
  205. {
  206. sql += " and UserCode='" + usercode + "'";
  207. }
  208. if (dept != null && dept.Trim() != "")
  209. {
  210. sql += " and UserCode in (select F_UserCode from T_Sys_UserAccount where F_DeptId=" + dept.Trim() + ")";
  211. }
  212. if (phone != null && phone.Trim() != "")
  213. {
  214. sql += " and CallNumber like '%" + phone + "%'";
  215. }
  216. if (callstate.Trim() != "")
  217. {
  218. sql += " and CallState='" + callstate + "'";
  219. }
  220. if (calltype.Trim() != "")
  221. {
  222. sql += " and CallType='" + calltype + "'";
  223. }
  224. if (starttime.Trim() != "")
  225. {
  226. sql += " and datediff(day,BeginTime,'" + starttime + "')<=0 ";
  227. }
  228. if (endtime.Trim() != "")
  229. {
  230. sql += " and datediff(day,BeginTime,'" + endtime + "')>=0 ";
  231. }
  232. dt = new BLL.T_Call_CallRecords().GetListExpt(sql).Tables[0];
  233. NPOIHelper npoi = new NPOIHelper();
  234. if (npoi.ExportToExcel("通话记录数据", dt, col()) == "")
  235. {
  236. return Success("导出成功");
  237. }
  238. else
  239. {
  240. return Error("导出失败");
  241. }
  242. }
  243. return res;
  244. }
  245. private string[] col()
  246. {
  247. string[] ccc = {
  248. "电话号码","呼叫方向","呼叫状态","是否处理","坐席工号","坐席姓名",
  249. "开始时间","通话开始时间","通话结束时间","结束时间","通话时长"
  250. };
  251. return ccc;
  252. }
  253. //删除通话记录
  254. public ActionResult DelCallRecord(string[] ids)
  255. {
  256. ActionResult res = NoToken("未知错误,请重新登录");
  257. if (Request.IsAuthenticated)
  258. {
  259. if (ids != null && ids.Length > 0)
  260. {
  261. string idd = " ";
  262. foreach (string str in ids)
  263. {
  264. idd += str + ",";
  265. }
  266. if (new BLL.T_Call_CallRecords().DeleteList(idd.TrimEnd(',')))
  267. {
  268. res = Success("删除成功");
  269. }
  270. else
  271. res = Error("删除失败");
  272. }
  273. else
  274. {
  275. res = Error("请选择要删除的记录");
  276. }
  277. }
  278. return res;
  279. }
  280. public ActionResult GetCallVoiceRemoveName(string callId)
  281. {
  282. var callRecord = new BLL.T_Call_CallRecords().GetModelByCallId(callId);
  283. if (callRecord == null)
  284. return Error("通话记录不存在");
  285. var filePath = "";
  286. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  287. string path = callRecord.FilePath ?? "";
  288. if (path != "" && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
  289. {
  290. var ym = config.F_ParamValue;
  291. if (ym.Substring(ym.Length - 1) == "/")
  292. {
  293. ym = ym.Substring(0, ym.Length - 1);
  294. }
  295. filePath = ym + path.Substring(path.IndexOf(':') + 1).Replace('\\', '/');
  296. }
  297. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(filePath);
  298. request.Method = "GET";
  299. request.ContentType = "audio/wav";
  300. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  301. Stream myResponseStream = response.GetResponseStream();
  302. StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
  303. return File(myResponseStream, "audio/wav", $"{callRecord.CallNumber}-{callRecord.BeginTime?.ToString("yyyyMMdd") ?? DateTime.Now.ToString("yyyyMMdd")}-{callRecord.UserCode}.wav");
  304. }
  305. }
  306. }