No Description

CallrecordsController.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. int type = RequestString.GetInt("type", 0);
  31. int islike = RequestString.GetInt("islike", 1);
  32. string strpageindex = RequestString.GetQueryString("page");
  33. int pageindex = 1;
  34. string strpagesize = RequestString.GetQueryString("pagesize");
  35. int pagesize = 10;
  36. //if (roleid != 0)
  37. //{
  38. // if (roleid == 1)
  39. // {
  40. // sql += " and UserCode='" + User.F_WorkNumber + "' ";
  41. // }
  42. //}
  43. if (type != 0)
  44. {
  45. sql += " and F_CallInType = '" + type + "' ";
  46. }
  47. if (usercode != null && usercode.Trim() != "")
  48. {
  49. sql += " and UserCode in(" + usercode + ")";
  50. }
  51. if (PhoneType != null && PhoneType.Trim() != "")
  52. {
  53. sql += " and PhoneType='"+ PhoneType + "'";
  54. }
  55. if (islike > 0)
  56. {
  57. if (phone != null && phone.Trim() != "")
  58. {
  59. sql += " and CallNumber like '%" + phone + "%'";
  60. }
  61. }
  62. else
  63. {
  64. if (phone != null && phone.Trim() != "")
  65. {
  66. sql += " and CallNumber = '" + phone + "'";
  67. }
  68. }
  69. if (callstate.Trim() != "")
  70. {
  71. if (callstate.Trim() == "0")
  72. {
  73. sql += " and CallState=0 and isnull(UserCode,'')!='' ";
  74. }
  75. else if (callstate.Trim() == "3")
  76. {
  77. sql += " and CallState=0 and CallType=0 and isnull(UserCode,'')='' ";
  78. }
  79. else
  80. {
  81. sql += " and CallState='" + callstate + "'";
  82. }
  83. }
  84. //else
  85. // sql += " and isnull(UserCode,'')<>'' ";
  86. if (calltype.Trim() != "")
  87. {
  88. if (calltype=="3")
  89. {
  90. sql += " and CallType='1'";
  91. sql += " and CallId in(select F_CallRecordId from T_Bus_VisitResult WITH(NOLOCK) where F_CallRecordId !='' and F_CallRecordId is not null )";
  92. }
  93. else
  94. sql += " and CallType='" + calltype + "'";
  95. }
  96. if (tasktype.Trim() != "")
  97. {
  98. if (tasktype.Trim() == "2")
  99. {
  100. sql += " and TaskType='" + tasktype + "'";
  101. }
  102. else if (tasktype.Trim() == "0")
  103. {
  104. sql += " and (TaskType is null or TaskType!='2')";
  105. }
  106. }
  107. if (actiontype.Trim() != "")
  108. {
  109. sql += " and ActionType=" + actiontype.Trim();
  110. }
  111. if (starttime.Trim() != "")
  112. {
  113. sql += " and BeginTime>='" + starttime + "' ";
  114. }
  115. if (endtime.Trim() != "")
  116. {
  117. sql += " and BeginTime<='" + endtime + "' ";
  118. }
  119. if(extnumber.Trim()!="")
  120. {
  121. sql += " and isnull(ExtNumber,'')='" + extnumber.Trim() + "'";
  122. }
  123. if (strpageindex.Trim() != "")
  124. {
  125. pageindex = Convert.ToInt32(strpageindex);
  126. }
  127. if (strpagesize.Trim() != "")
  128. {
  129. pagesize = Convert.ToInt32(strpagesize);
  130. }
  131. if (isdc > 0)
  132. {
  133. 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 CallType when 0 then (case when isnull(UserCode,'')!='' then '主动放弃' else '未接通' end) else '未接通' end ) else '已接通' end ) 呼叫状态,UserCode 坐席工号,dbo.GetUserName(UserCode) as 坐席姓名, "
  134. + "BeginTime 开始时间,TalkStartTime 通话开始时间 ,TalkEndTime " +
  135. " 通话结束时间 ,EndTime 结束时间 ,LongTime 通话时长 ,PhoneType " +
  136. "电话类别"
  137. + " from T_Call_CallRecords a WITH(NOLOCK) where 1=1 " + sql+ "ORDER BY CallRecordsId desc").Tables[0];
  138. var msg = new NPOIHelper().ExportToExcel("通话记录", dtdc);
  139. if (msg == "")
  140. {
  141. return Success("导出成功");
  142. }
  143. else
  144. {
  145. return Error("导出失败");
  146. }
  147. }
  148. else
  149. {
  150. int recordCount = 0;
  151. dt = BLL.PagerBLL.GetListPager(
  152. "T_Call_CallRecords WITH(NOLOCK)",
  153. "CallRecordsId",
  154. "*,dbo.GetUserName(UserCode) as UserName",
  155. sql,
  156. "ORDER BY CallRecordsId desc",
  157. pagesize,
  158. pageindex,
  159. true,
  160. out recordCount);
  161. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  162. // var usercodes= (from r in dt.AsEnumerable() select r.Field<string>("UserCode")).ToList<string>().Distinct();
  163. // var users = new BLL.T_Sys_UserAccount().GetModelList(" F_UserCode in ('" + string.Join("','", usercodes) + "')");
  164. dt.Columns.Add("TypeName", typeof(string));
  165. dt.Columns.Add("WorkOrderId", typeof(string));
  166. foreach (DataRow dr in dt.Rows)
  167. {
  168. string path = dr["FilePath"] != null ? dr["FilePath"].ToString() : "";
  169. if (path != "" && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
  170. {
  171. var ym = config.F_ParamValue;
  172. if (ym.Substring(ym.Length - 1) == "/")
  173. {
  174. ym = ym.Substring(0, ym.Length - 1);
  175. }
  176. string lujing = path.Substring(path.IndexOf(':') + 1).Replace('\\', '/');
  177. string wlpath = ym + lujing;
  178. //if (!CommonHelper.FileIsExist(wlpath))
  179. //{
  180. // wlpath = lujing;
  181. //}
  182. dr["FilePath"] = wlpath;
  183. }
  184. if (dr["F_CallInType"] != null && dr["F_CallInType"].ToString() != "")
  185. {
  186. int tid = Int32.Parse(dr["F_CallInType"].ToString());
  187. var tn = new BLL.T_Sys_DictionaryValue().GetModel(tid);
  188. if (tn != null)
  189. {
  190. dr["TypeName"] = tn.F_Value;
  191. }
  192. }
  193. dr["WorkOrderId"] = DB.DbHelperSQL.GetSingle(" select top 1 F_WorkOrderId from T_Bus_WorkOrder WITH(NOLOCK) where F_CallRecordId='" + dr["CallRecordsId"].ToString() + "' and F_IsDelete=0 ");
  194. }
  195. var obj = new
  196. {
  197. state = "success",
  198. message = "成功",
  199. rows = dt,
  200. total = recordCount
  201. };
  202. return Content(obj.ToJson());
  203. }
  204. }
  205. //获取未接来电
  206. public ActionResult GetListWJ(string phone)
  207. {
  208. string sql = "";
  209. DataTable dt = new DataTable();
  210. string starttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  211. string endtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  212. string ishf = HttpUtility.UrlDecode(RequestString.GetQueryString("ishf"));//是否回复 0否1是
  213. string ishfSuccess = HttpUtility.UrlDecode(RequestString.GetQueryString("ishfsuc"));//是否回复成功 0否1是
  214. string strpageindex = RequestString.GetQueryString("page");
  215. int pageindex = 1;
  216. string strpagesize = RequestString.GetQueryString("pagesize");
  217. int pagesize = 10;
  218. if (phone != null && phone.Trim() != "")
  219. {
  220. sql += " and CallNumber like '%" + phone + "%'";
  221. }
  222. if (starttime.Trim() != "")
  223. {
  224. sql += " and datediff(day,BeginTime,'" + starttime.Trim() + "')<=0 ";
  225. }
  226. if (endtime.Trim() != "")
  227. {
  228. sql += " and datediff(day,BeginTime,'" + endtime.Trim() + "')>=0 ";
  229. }
  230. if (ishf.Trim() != "")
  231. {
  232. sql += " and F_wjishf=" + ishf.Trim() + " ";
  233. }
  234. if (ishfSuccess.Trim() != "")
  235. {
  236. sql += " and F_wjishfSuccess=" + ishfSuccess.Trim() + " ";
  237. }
  238. sql += " and CallState='0'";
  239. sql += " and CallType='0'";
  240. if (strpageindex.Trim() != "")
  241. {
  242. pageindex = Convert.ToInt32(strpageindex);
  243. }
  244. if (strpagesize.Trim() != "")
  245. {
  246. pagesize = Convert.ToInt32(strpagesize);
  247. }
  248. int recordCount = 0;
  249. dt = BLL.PagerBLL.GetListPager(
  250. "T_Call_CallRecords WITH(NOLOCK)",
  251. "CallRecordsId",
  252. "*",
  253. sql,
  254. "ORDER BY CallRecordsId desc",
  255. pagesize,
  256. pageindex,
  257. true,
  258. out recordCount);
  259. var obj = new
  260. {
  261. state = "success",
  262. message = "成功",
  263. rows = dt,
  264. total = recordCount
  265. };
  266. return Content(obj.ToJson());
  267. }
  268. //获取转移或三方通话,均为手机号
  269. //rep_transfer只有转移的数据
  270. public ActionResult GetListZY(string phone, string usercode)
  271. {
  272. string sql = "";
  273. DataTable dt = new DataTable();
  274. string callstate = HttpUtility.UrlDecode(RequestString.GetQueryString("callstate"));
  275. string starttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  276. string endtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  277. string strpageindex = RequestString.GetQueryString("page");
  278. int pageindex = 1;
  279. string strpagesize = RequestString.GetQueryString("pagesize");
  280. int pagesize = 10;
  281. sql += " and ActionType>1";//1正常呼入呼出、2转移、3三方通话
  282. if (usercode != null && usercode.Trim() != "")
  283. {
  284. sql += " and UserCode='" + usercode + "'";
  285. }
  286. if (phone != null && phone.Trim() != "")
  287. {
  288. sql += " and CallNumber like '%" + phone + "%'";
  289. }
  290. if (callstate.Trim() != "")
  291. {
  292. sql += " and CallState='" + callstate + "'";
  293. }
  294. if (starttime.Trim() != "")
  295. {
  296. sql += " and datediff(day,BeginTime,'" + starttime + "')<=0 ";
  297. }
  298. if (endtime.Trim() != "")
  299. {
  300. sql += " and datediff(day,BeginTime,'" + endtime + "')>=0 ";
  301. }
  302. if (strpageindex.Trim() != "")
  303. {
  304. pageindex = Convert.ToInt32(strpageindex);
  305. }
  306. if (strpagesize.Trim() != "")
  307. {
  308. pagesize = Convert.ToInt32(strpagesize);
  309. }
  310. int recordCount = 0;
  311. dt = BLL.PagerBLL.GetListPager(
  312. "T_Call_CallRecords WITH(NOLOCK)",
  313. "CallRecordsId",
  314. "*",
  315. sql,
  316. "ORDER BY CallRecordsId desc",
  317. pagesize,
  318. pageindex,
  319. true,
  320. out recordCount);
  321. List<Model.T_Call_CallRecords> callList = new BLL.T_Call_CallRecords().DataTableToList(dt);
  322. var obj = new
  323. {
  324. state = "success",
  325. message = "成功",
  326. rows = callList,
  327. total = recordCount
  328. };
  329. return Content(obj.ToJson());
  330. }
  331. //删除通话记录
  332. public ActionResult DelCallRecord(string[] ids)
  333. {
  334. if (ids != null && ids.Length > 0)
  335. {
  336. string idd = " ";
  337. foreach (string str in ids)
  338. {
  339. idd += str + ",";
  340. }
  341. if (new BLL.T_Call_CallRecords().DeleteList(idd.TrimEnd(',')))
  342. {
  343. return Success("删除成功");
  344. }
  345. else
  346. return Error("删除失败");
  347. }
  348. else
  349. {
  350. return Error("请选择要删除的记录");
  351. }
  352. }
  353. }
  354. }