No Description

CallrecordsController.cs 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.DB;
  4. using CallCenterApi.Interface.Controllers.Base;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Web;
  10. using System.Web.Mvc;
  11. namespace CallCenterApi.Interface.Controllers.tel
  12. {
  13. [Authority]
  14. public class CallrecordsController : BaseController
  15. {
  16. //获取通话记录列表
  17. public ActionResult GetList(string phone, string usercode,int isdc=0)
  18. {
  19. string sql = "";
  20. DataTable dt = new DataTable();
  21. // int roleid = User.F_RoleId;
  22. string callstate = HttpUtility.UrlDecode(RequestString.GetQueryString("callstate"));
  23. string calltype = HttpUtility.UrlDecode(RequestString.GetQueryString("calltype"));
  24. string actiontype = HttpUtility.UrlDecode(RequestString.GetQueryString("actiontype"));
  25. string starttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  26. string endtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  27. string tasktype = HttpUtility.UrlDecode(RequestString.GetQueryString("tasktype"));
  28. string extnumber = HttpUtility.UrlDecode(RequestString.GetQueryString("extnumber"));
  29. string PhoneType = HttpUtility.UrlDecode(RequestString.GetQueryString("phoneType"));
  30. string group = HttpUtility.UrlDecode(RequestString.GetQueryString("group"));
  31. int callback = RequestString.GetInt("callback", 0);
  32. int waitTime = RequestString.GetInt("waitTime", -1);
  33. int type = RequestString.GetInt("type", 0);
  34. int islike = RequestString.GetInt("islike", 1);
  35. int notconnected = RequestString.GetInt("notconnected", 0);
  36. string CallbackCallid = HttpUtility.UrlDecode(RequestString.GetQueryString("callbackCallid"));
  37. string strpageindex = RequestString.GetQueryString("page");
  38. int pageindex = 1;
  39. string strpagesize = RequestString.GetQueryString("pagesize");
  40. int pagesize = 10;
  41. //if (roleid != 0)
  42. //{
  43. // if (roleid == 1)
  44. // {
  45. // sql += " and UserCode='" + User.F_WorkNumber + "' ";
  46. // }
  47. //}
  48. if (type != 0)
  49. {
  50. sql += " and F_CallInType = '" + type + "' ";
  51. }
  52. if (usercode != null && usercode.Trim() != "")
  53. {
  54. sql += " and UserCode in(" + usercode + ")";
  55. }
  56. if (PhoneType != null && PhoneType.Trim() != "")
  57. {
  58. if (PhoneType =="12366")
  59. {
  60. sql += " and PhoneType in('12366','2214605')";
  61. }
  62. else
  63. sql += " and PhoneType='"+ PhoneType + "'";
  64. }
  65. if (islike > 0)
  66. {
  67. if (phone != null && phone.Trim() != "")
  68. {
  69. sql += " and CallNumber like '%" + phone + "%'";
  70. }
  71. }
  72. else
  73. {
  74. if (phone != null && phone.Trim() != "")
  75. {
  76. sql += " and CallNumber = '" + phone + "' ";
  77. }
  78. }
  79. if (callback>0)
  80. {
  81. if (callback==1)
  82. {
  83. sql += " and Callback is not null ";
  84. }
  85. else
  86. {
  87. sql += " and Callback is null and CallType=0 and CallState=0";
  88. }
  89. }
  90. if (!string .IsNullOrEmpty (CallbackCallid))
  91. {
  92. sql += "and CallbackCallid='" + CallbackCallid + "'";
  93. }
  94. if (!string .IsNullOrEmpty (group))
  95. {
  96. sql += " and UserCode in(select F_UserCode from T_Sys_UserAccount where F_UserName like '%"+ group + "%' )";
  97. }
  98. if (waitTime>-1)
  99. {
  100. sql += "and (DATEDIFF (SECOND ,TalkStartTime,BeginTime)='"+ waitTime + "' or ((DATEDIFF (SECOND ,TalkStartTime,EndTime)='"+ waitTime + "' and TalkStartTime is null ) ))";
  101. }
  102. if (callstate.Trim() != "")
  103. {
  104. if (callstate.Trim() == "0")
  105. {
  106. sql += " and CallState=0 and isnull(UserCode,'')!='' ";
  107. }
  108. else if (callstate.Trim() == "3")
  109. {
  110. sql += " and CallState=0 and CallType=0 and isnull(UserCode,'')='' ";
  111. }
  112. else
  113. {
  114. sql += " and CallState='" + callstate + "'";
  115. }
  116. }
  117. if (notconnected>0)
  118. {
  119. if (notconnected!=2)
  120. {
  121. string where = "";
  122. if (starttime.Trim() != "")
  123. {
  124. where += " and BeginTime>='" + starttime + "' ";
  125. }
  126. if (endtime.Trim() != "")
  127. {
  128. where += " and BeginTime<='" + endtime + "' ";
  129. }
  130. sql += "and CallNumber in (select CallNumber from T_Call_CallRecords where CallType = 0" + where + " group by CallNumber having SUM( case when CallState = 1 and DealType = 6 then 1 else 0 end )= 0)";
  131. }
  132. }
  133. if (starttime.Trim() != "")
  134. {
  135. sql += " and BeginTime>='" + starttime + "' ";
  136. }
  137. if (endtime.Trim() != "")
  138. {
  139. sql += " and BeginTime<='" + endtime + "' ";
  140. }
  141. //else
  142. // sql += " and isnull(UserCode,'')<>'' ";
  143. if (calltype.Trim() != "")
  144. {
  145. if (calltype=="3")
  146. {
  147. sql += " and CallType='1'";
  148. sql += " and CallRecordsId in(select F_CallRecordId from T_Bus_VisitResult WITH(NOLOCK) where F_CallRecordId !='' and F_CallRecordId is not null )";
  149. }
  150. else
  151. sql += " and CallType='" + calltype + "'";
  152. }
  153. if (tasktype.Trim() != "")
  154. {
  155. if (tasktype.Trim() == "2")
  156. {
  157. sql += " and TaskType='" + tasktype + "'";
  158. }
  159. else if (tasktype.Trim() == "0")
  160. {
  161. sql += " and (TaskType is null or TaskType!='2')";
  162. }
  163. }
  164. if (actiontype.Trim() != "")
  165. {
  166. sql += " and ActionType=" + actiontype.Trim();
  167. }
  168. if(extnumber.Trim()!="")
  169. {
  170. sql += " and isnull(ExtNumber,'')='" + extnumber.Trim() + "'";
  171. }
  172. if (strpageindex.Trim() != "")
  173. {
  174. pageindex = Convert.ToInt32(strpageindex);
  175. }
  176. if (strpagesize.Trim() != "")
  177. {
  178. pagesize = Convert.ToInt32(strpagesize);
  179. }
  180. if (isdc > 0)
  181. {
  182. if (notconnected>0)
  183. {
  184. var dtdc = DbHelperSQL.Query(" select ROW_NUMBER() OVER(ORDER BY CallRecordsId desc) 编号, CallNumber 电话号码,(case CallType when 0 then '呼入' else '呼出' end ) 呼叫方向,(case CallState when 0 then ( case when CallType=0 and isnull(UserCode,'')='' then '主动放弃' else '未接通' end ) else '已接通' end ) 呼叫状态,UserCode 坐席工号, "
  185. + "BeginTime 开始时间,TalkStartTime 通话开始时间 ,TalkEndTime " +
  186. " 通话结束时间 ,EndTime 结束时间 ,LongTime 通话时长 ,PhoneType " +
  187. "电话类别"
  188. + " from T_Call_CallRecords a WITH(NOLOCK) where 1=1 " + sql + "ORDER BY CallRecordsId desc").Tables[0];
  189. var msg = new NPOIHelper().ExportToExcel("通话记录", dtdc);
  190. if (msg == "")
  191. {
  192. return Success("导出成功");
  193. }
  194. else
  195. {
  196. return Error("导出失败");
  197. }
  198. }
  199. else
  200. {
  201. var dtdc = DbHelperSQL.Query(" select ROW_NUMBER() OVER(ORDER BY CallRecordsId desc) 编号, CallNumber 电话号码,(case CallType when 0 then '呼入' else '呼出' end ) 呼叫方向,(case CallState when 0 then ( case when CallType=0 and isnull(UserCode,'')='' then '主动放弃' else '未接通' end ) else '已接通' end ) 呼叫状态,UserCode 坐席工号,dbo.GetUserName(UserCode) as 坐席姓名, "
  202. + "BeginTime 开始时间,TalkStartTime 通话开始时间 ,TalkEndTime " +
  203. " 通话结束时间 ,EndTime 结束时间 ,LongTime 通话时长 ,PhoneType " +
  204. "电话类别"
  205. + " from T_Call_CallRecords a WITH(NOLOCK) where 1=1 " + sql + "ORDER BY CallRecordsId desc").Tables[0];
  206. var msg = new NPOIHelper().ExportToExcel("通话记录", dtdc);
  207. if (msg == "")
  208. {
  209. return Success("导出成功");
  210. }
  211. else
  212. {
  213. return Error("导出失败");
  214. }
  215. }
  216. }
  217. else
  218. {
  219. int recordCount = 0;
  220. if (notconnected==2)
  221. {
  222. dt = BLL.PagerBLL.GetListPager(
  223. "(select COUNT(1) count, CallNumber from T_Call_CallRecords where CallType = 0 "+sql +" group by CallNumber having SUM( case when CallState = 1 and DealType = 6 then 1 else 0 end) = 0) a",
  224. "CallNumber",
  225. "*",
  226. "",
  227. "order by a.count",
  228. pagesize,
  229. pageindex,
  230. true,
  231. out recordCount);
  232. }
  233. else
  234. {
  235. dt = BLL.PagerBLL.GetListPager(
  236. "T_Call_CallRecords WITH(NOLOCK)",
  237. "CallRecordsId",
  238. "*,dbo.GetUserName(UserCode) as UserName, WorkOrderId,dbo.GetDictionaryName(F_CallInType) as TypeName",
  239. sql,
  240. "ORDER BY CallRecordsId desc ",
  241. pagesize,
  242. pageindex,
  243. true,
  244. out recordCount);
  245. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  246. dt.Columns.Add("WaitTime", typeof(string));
  247. foreach (DataRow dr in dt.Rows)
  248. {
  249. string path = dr["FilePath"] != null ? dr["FilePath"].ToString() : "";
  250. if (path != "" && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
  251. {
  252. var ym = config.F_ParamValue;
  253. if (ym.Substring(ym.Length - 1) == "/")
  254. {
  255. ym = ym.Substring(0, ym.Length - 1);
  256. }
  257. string lujing = path.Substring(path.IndexOf(':') + 1).Replace('\\', '/');
  258. string wlpath = ym + lujing;
  259. dr["FilePath"] = wlpath;
  260. }
  261. if (dr["TalkStartTime"]!=null && dr["TalkStartTime"].ToString() != "" && dr["BeginTime"] != null
  262. && dr["BeginTime"].ToString() != "")
  263. {
  264. var ltime = DateTime.Parse(dr["TalkStartTime"].ToString ());
  265. TimeSpan ts = ltime - DateTime.Parse(dr["BeginTime"].ToString());
  266. double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
  267. dr["WaitTime"] = DateTimeConvert.parseTimeSeconds(tss, 1);
  268. }
  269. else if (dr["EndTime"] != null && dr["EndTime"].ToString() != "" && dr["BeginTime"] != null && dr["BeginTime"].ToString() != "")
  270. {
  271. var ltime = DateTime.Parse(dr["EndTime"].ToString());
  272. TimeSpan ts = ltime - DateTime.Parse(dr["BeginTime"].ToString());
  273. double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
  274. dr["WaitTime"] = DateTimeConvert.parseTimeSeconds(tss, 1);
  275. }
  276. if (dr["PhoneType"] != null && dr["PhoneType"].ToString() != "")
  277. {
  278. if (dr["PhoneType"].ToString() == "2214605")
  279. {
  280. dr["PhoneType"] = "12366";
  281. }
  282. }
  283. }
  284. }
  285. var obj = new
  286. {
  287. state = "success",
  288. message = "成功",
  289. rows = dt,
  290. total = recordCount
  291. };
  292. return Content(obj.ToJson());
  293. }
  294. }
  295. //获取通话记录列表
  296. public ActionResult GetNotconnectedList(string phone="")
  297. {
  298. string sql = "";
  299. DataTable dt = new DataTable();
  300. string strpageindex = RequestString.GetQueryString("page");
  301. int pageindex = 1;
  302. string strpagesize = RequestString.GetQueryString("pagesize");
  303. int pagesize = 10;
  304. if (strpageindex.Trim() != "")
  305. {
  306. pageindex = Convert.ToInt32(strpageindex);
  307. }
  308. if (strpagesize.Trim() != "")
  309. {
  310. pagesize = Convert.ToInt32(strpagesize);
  311. }
  312. if (phone != null && phone.Trim() != "")
  313. {
  314. sql += " and CallNumber = '" + phone + "'";
  315. }
  316. // sql += "and CallType=0";
  317. int recordCount = 0;
  318. dt = BLL.PagerBLL.GetListPager(
  319. "(select COUNT(1) count, CallNumber from T_Call_CallRecords where CallType = 0 group by CallNumber having SUM( case when CallState = 1 and DealType = 6 then 1 else 0 end) = 0) a",
  320. "CallNumber",
  321. "*",
  322. sql,
  323. "order by a.count",
  324. pagesize,
  325. pageindex,
  326. true,
  327. out recordCount);
  328. var obj = new
  329. {
  330. state = "success",
  331. message = "成功",
  332. rows = dt,
  333. total = recordCount
  334. };
  335. return Content(obj.ToJson());
  336. }
  337. //获取未接来电
  338. public ActionResult GetListWJ(string phone)
  339. {
  340. string sql = "";
  341. DataTable dt = new DataTable();
  342. string starttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  343. string endtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  344. string ishf = HttpUtility.UrlDecode(RequestString.GetQueryString("ishf"));//是否回复 0否1是
  345. string ishfSuccess = HttpUtility.UrlDecode(RequestString.GetQueryString("ishfsuc"));//是否回复成功 0否1是
  346. string strpageindex = RequestString.GetQueryString("page");
  347. int pageindex = 1;
  348. string strpagesize = RequestString.GetQueryString("pagesize");
  349. int pagesize = 10;
  350. if (phone != null && phone.Trim() != "")
  351. {
  352. sql += " and CallNumber like '%" + phone + "%'";
  353. }
  354. if (starttime.Trim() != "")
  355. {
  356. sql += " and datediff(day,BeginTime,'" + starttime.Trim() + "')<=0 ";
  357. }
  358. if (endtime.Trim() != "")
  359. {
  360. sql += " and datediff(day,BeginTime,'" + endtime.Trim() + "')>=0 ";
  361. }
  362. if (ishf.Trim() != "")
  363. {
  364. sql += " and F_wjishf=" + ishf.Trim() + " ";
  365. }
  366. if (ishfSuccess.Trim() != "")
  367. {
  368. sql += " and F_wjishfSuccess=" + ishfSuccess.Trim() + " ";
  369. }
  370. sql += " and CallState='0'";
  371. sql += " and CallType='0'";
  372. if (strpageindex.Trim() != "")
  373. {
  374. pageindex = Convert.ToInt32(strpageindex);
  375. }
  376. if (strpagesize.Trim() != "")
  377. {
  378. pagesize = Convert.ToInt32(strpagesize);
  379. }
  380. int recordCount = 0;
  381. dt = BLL.PagerBLL.GetListPager(
  382. "T_Call_CallRecords WITH(NOLOCK)",
  383. "CallRecordsId",
  384. "*",
  385. sql,
  386. "ORDER BY CallRecordsId desc",
  387. pagesize,
  388. pageindex,
  389. true,
  390. out recordCount);
  391. var obj = new
  392. {
  393. state = "success",
  394. message = "成功",
  395. rows = dt,
  396. total = recordCount
  397. };
  398. return Content(obj.ToJson());
  399. }
  400. //获取转移或三方通话,均为手机号
  401. //rep_transfer只有转移的数据
  402. public ActionResult GetListZY(string phone, string usercode)
  403. {
  404. string sql = "";
  405. DataTable dt = new DataTable();
  406. string callstate = HttpUtility.UrlDecode(RequestString.GetQueryString("callstate"));
  407. string starttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  408. string endtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  409. string strpageindex = RequestString.GetQueryString("page");
  410. int pageindex = 1;
  411. string strpagesize = RequestString.GetQueryString("pagesize");
  412. int pagesize = 10;
  413. sql += " and ActionType>1";//1正常呼入呼出、2转移、3三方通话
  414. if (usercode != null && usercode.Trim() != "")
  415. {
  416. sql += " and UserCode='" + usercode + "'";
  417. }
  418. if (phone != null && phone.Trim() != "")
  419. {
  420. sql += " and CallNumber like '%" + phone + "%'";
  421. }
  422. if (callstate.Trim() != "")
  423. {
  424. sql += " and CallState='" + callstate + "'";
  425. }
  426. if (starttime.Trim() != "")
  427. {
  428. sql += " and datediff(day,BeginTime,'" + starttime + "')<=0 ";
  429. }
  430. if (endtime.Trim() != "")
  431. {
  432. sql += " and datediff(day,BeginTime,'" + endtime + "')>=0 ";
  433. }
  434. if (strpageindex.Trim() != "")
  435. {
  436. pageindex = Convert.ToInt32(strpageindex);
  437. }
  438. if (strpagesize.Trim() != "")
  439. {
  440. pagesize = Convert.ToInt32(strpagesize);
  441. }
  442. int recordCount = 0;
  443. dt = BLL.PagerBLL.GetListPager(
  444. "T_Call_CallRecords WITH(NOLOCK)",
  445. "CallRecordsId",
  446. "*",
  447. sql,
  448. "ORDER BY CallRecordsId desc",
  449. pagesize,
  450. pageindex,
  451. true,
  452. out recordCount);
  453. List<Model.T_Call_CallRecords> callList = new BLL.T_Call_CallRecords().DataTableToList(dt);
  454. var obj = new
  455. {
  456. state = "success",
  457. message = "成功",
  458. rows = callList,
  459. total = recordCount
  460. };
  461. return Content(obj.ToJson());
  462. }
  463. /// <summary>
  464. /// 更新回拨
  465. /// </summary>
  466. /// <returns></returns>
  467. [Authority]
  468. public ActionResult UpdateCallback(string callid)
  469. {
  470. var b = new BLL.T_Call_CallRecords().UpdateCallback(callid);
  471. if (b )
  472. {
  473. return Success("更新成功");
  474. }
  475. else
  476. {
  477. return Success("更新失败");
  478. }
  479. }
  480. /// <summary>
  481. /// 更新回拨
  482. /// </summary>
  483. /// <returns></returns>
  484. [Authority]
  485. public ActionResult UpdateCallbackid(string callid,string p_callid)
  486. {
  487. var b = new BLL.T_Call_CallRecords().UpdateCallbackid(callid, p_callid);
  488. if (b)
  489. {
  490. return Success("更新成功");
  491. }
  492. else
  493. {
  494. return Success("更新失败");
  495. }
  496. }
  497. //删除通话记录
  498. public ActionResult DelCallRecord(string[] ids)
  499. {
  500. if (ids != null && ids.Length > 0)
  501. {
  502. string idd = " ";
  503. foreach (string str in ids)
  504. {
  505. idd += str + ",";
  506. }
  507. if (new BLL.T_Call_CallRecords().DeleteList(idd.TrimEnd(',')))
  508. {
  509. return Success("删除成功");
  510. }
  511. else
  512. return Error("删除失败");
  513. }
  514. else
  515. {
  516. return Error("请选择要删除的记录");
  517. }
  518. }
  519. }
  520. }