鄂尔多斯-招源科技

CallPlanController.cs 50KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. using CallCenter.Utility;
  2. using CallCenterApi.DB;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using CallCenterApi.Interface.Models.Dto;
  5. using CallCenterApi.Interface.Models.Filter;
  6. using CallCenterApi.Interface.Models.Input;
  7. using CallCenterApi.Model;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Web;
  15. using System.Web.Mvc;
  16. namespace CallCenterApi.Interface.Controllers.callout
  17. {
  18. public class CallPlanController : BaseController
  19. {
  20. private BLL.T_CTI_Task taskBLL = new BLL.T_CTI_Task();
  21. private BLL.T_Call_TaskTelNum taskTellNumBLL = new BLL.T_Call_TaskTelNum();
  22. private BLL.T_Sys_DictionaryValue dictValueBLL = new BLL.T_Sys_DictionaryValue();
  23. private BLL.T_CTI_TaskAgent taskAgentBLL = new BLL.T_CTI_TaskAgent();
  24. private BLL.T_Sys_UserAccount userAccount = new BLL.T_Sys_UserAccount();
  25. private BLL.T_CTI_TaskRecord taskRecordBLL = new BLL.T_CTI_TaskRecord();
  26. private BLL.CallResult callResultBLL = new BLL.CallResult();
  27. private BLL.T_CTI_TaskDaily taskDailyBLL = new BLL.T_CTI_TaskDaily();
  28. private BLL.T_CTI_TaskPhonePart taskPhonePartBLL = new BLL.T_CTI_TaskPhonePart();
  29. private BLL.T_Sys_SeatGroup seatGroupBLL = new BLL.T_Sys_SeatGroup();
  30. private BLL.T_Sys_SystemConfig systemConfigBLL = new BLL.T_Sys_SystemConfig();
  31. private BLL.T_Call_PageField pageFieldBLL = new BLL.T_Call_PageField();
  32. #region 外呼任务
  33. /// <summary>
  34. /// 获取列表
  35. /// </summary>
  36. /// <param name="filter"></param>
  37. /// <returns></returns>
  38. public ActionResult GetList(FilterCallPlan filter)
  39. {
  40. //if (!Request.IsAuthenticated)
  41. // return NoToken("未知错误,请重新登录");
  42. var sql = " and State>=0 and TaskType=" + filter.TaskType;
  43. if (!string.IsNullOrWhiteSpace(filter.Name))
  44. {
  45. sql += " and (TaskName like '%" + filter.Name.Trim() + "%' ) ";
  46. }
  47. Model.PageData<Model.T_CTI_Task> pageModel = new Model.PageData<Model.T_CTI_Task>();
  48. var recordCount = 0;
  49. var dt = BLL.PagerBLL.GetListPager(
  50. "T_CTI_Task",
  51. "TaskID",
  52. "*",
  53. sql,
  54. "ORDER BY AddTime desc",
  55. filter.PageSize,
  56. filter.PageIndex,
  57. true,
  58. out recordCount);
  59. List<Model.T_CTI_Task> modelList = new BLL.T_CTI_Task().DataTableToList(dt);
  60. var list = new List<CallPlanDto>();
  61. //查询坐席组
  62. var agentGroupList = seatGroupBLL.DataTableToList(seatGroupBLL.GetList("").Tables[0]);
  63. //查询坐席
  64. var agentList = userAccount.DataTableToList(userAccount.GetList(" F_DeleteFlag=0 ").Tables[0]);
  65. foreach (var model in modelList)
  66. {
  67. //计算数据
  68. string calledRate = "0";
  69. var allcount = model.y_HMCount ?? 0;
  70. float calledcount = model.y_HCCount ?? 0;
  71. calledRate = allcount == 0 ? "" : (calledcount / allcount * 100).ToString("f2") + "%";
  72. string connectedRate = "0";
  73. float connected = model.y_YJCount ?? 0;
  74. connectedRate = calledcount == 0 ? "0" : (connected / calledcount * 100).ToString("f2") + "%";
  75. var taskTellNumDt = taskTellNumBLL.GetList(" F_HCState=1 and F_YJState=1 and F_UserId>0 and F_TaskId=" + model.TaskID).Tables[0];
  76. float connectedAgentCount = taskTellNumDt?.Rows.Count ?? 0;
  77. var connectedAgentRate = "0";
  78. connectedAgentRate = connected == 0 ? "0" : (connectedAgentCount / connected * 100).ToString("f2") + "%";
  79. var agentGroupStr = model.AgentGroupId == -999 ? "不转坐席" : "";
  80. var agentGroup = agentGroupList.SingleOrDefault(x => x.F_ZXZID == model.AgentGroupId);
  81. var agentCount = agentList.Where(x => x.F_SeartGroupID == (agentGroup?.F_ZXZID ?? 0)).Count();
  82. list.Add(new CallPlanDto
  83. {
  84. id = model.TaskID,
  85. name = model.TaskName,
  86. tasktype = model.TaskType == 1 ? "点击外呼" : "自动外呼",
  87. state = Enum.GetName(typeof(EnumTaskState), (model.State ?? -1)),
  88. addtime = Convert.ToDateTime(model.AddTime).ToString("yyyy-MM-dd HH:mm:ss"),
  89. talkid = model.y_TkModelId ?? 0,
  90. pre = model.Pre, //线路前缀
  91. concurrencytype = model.ConcurrencyType,
  92. concurrency = model.Concurrency,
  93. planstartdate = model.PlanStartDate.ToString("yyyy-MM-dd"),
  94. planenddate = model.PlanEndDate.ToString("yyyy-MM-dd"),
  95. starttime1 = model.StartTime1.ToString("HH:mm:ss"),
  96. endtime1 = model.EndTime1.ToString("HH:mm:ss"),
  97. starttime2 = model.StartTime2.ToString("HH:mm:ss"),
  98. endtime2 = model.EndTime2.ToString("HH:mm:ss"),
  99. agentgroup = agentGroup?.F_ZXZName ?? agentGroupStr,//坐席组
  100. agentgroupid = model.AgentGroupId,
  101. agentcount = agentCount,//坐席组人数
  102. allcount = model.y_HMCount ?? 0, //号码总数
  103. calledcount = model.y_HCCount ?? 0, //已呼个数
  104. calledrate = calledRate, //已完成百分比
  105. callleftcount = (int)(allcount - calledcount), //剩余个数
  106. connected = model.y_YJCount ?? 0, //总应答数
  107. connectedrate = connectedRate, //应答率
  108. connectedagentcount = (int)connectedAgentCount, //转坐席数
  109. connectedagentrate = connectedAgentRate, //转坐席率
  110. });
  111. }
  112. var obj = new
  113. {
  114. rows = list,
  115. total = recordCount
  116. };
  117. return Content(obj.ToJson());
  118. }
  119. /// <summary>
  120. /// 获取实体
  121. /// </summary>
  122. /// <param name="id"></param>
  123. /// <returns></returns>
  124. public ActionResult GetModel(int id)
  125. {
  126. //if (!Request.IsAuthenticated)
  127. // return NoToken("未知错误,请重新登录");
  128. var model = taskBLL.GetModel(id);
  129. if (model == null)
  130. return Error("预测外呼任务不存在");
  131. //计算数据
  132. string calledRate = "0";
  133. var allcount = model.y_HMCount ?? 0;
  134. float calledcount = model.y_HCCount ?? 0;
  135. calledRate = allcount == 0 ? "" : (calledcount / allcount * 100).ToString("f2") + "%";
  136. string connectedRate = "0";
  137. float connected = model.y_YJCount ?? 0;
  138. connectedRate = calledcount == 0 ? "0" : (connected / calledcount * 100).ToString("f2") + "%";
  139. var taskTellNumDt = taskTellNumBLL.GetList(" F_HCState=1 and F_YJState=1 and F_UserId>0 and F_TaskId=" + model.TaskID).Tables[0];
  140. float connectedAgentCount = taskTellNumDt?.Rows.Count ?? 0;
  141. var connectedAgentRate = "0";
  142. connectedAgentRate = connected == 0 ? "0" : (connectedAgentCount / connected * 100).ToString("f2") + "%";
  143. //查询坐席组
  144. var agentGroupList = seatGroupBLL.DataTableToList(seatGroupBLL.GetList("").Tables[0]);
  145. //查询坐席
  146. var agentList = userAccount.DataTableToList(userAccount.GetList(" F_DeleteFlag=0 ").Tables[0]);
  147. var agentGroupStr = model.AgentGroupId == -999 ? "不转坐席" : "";
  148. var agentGroup = agentGroupList.SingleOrDefault(x => x.F_ZXZID == model.AgentGroupId);
  149. var agentCount = agentList.Where(x => x.F_SeartGroupID == (agentGroup?.F_ZXZID ?? 0)).Count();
  150. return Success("获取成功", new CallPlanDto
  151. {
  152. id = model.TaskID,
  153. name = model.TaskName,
  154. tasktype = model.TaskType == 1 ? "点击外呼" : "自动外呼",
  155. state = "暂停",
  156. addtime = Convert.ToDateTime(model.AddTime).ToString("yyyy-MM-dd HH:mm:ss"),
  157. talkid = model.y_TkModelId ?? 0,
  158. pre = model.Pre, //线路前缀
  159. recordpathid = model.RecordFileId,
  160. concurrencytypestr = model.ConcurrencyType == 0 ? "并发数" : "并发速率",
  161. concurrencytype = model.ConcurrencyType,
  162. concurrency = model.Concurrency,
  163. planstartdate = model.PlanStartDate.ToString("yyyy-MM-dd"),
  164. planenddate = model.PlanEndDate.ToString("yyyy-MM-dd"),
  165. starttime1 = model.StartTime1.ToString("HH:mm"),
  166. endtime1 = model.EndTime1.ToString("HH:mm"),
  167. starttime2 = model.StartTime2.ToString("HH:mm"),
  168. endtime2 = model.EndTime2.ToString("HH:mm"),
  169. agentgroup = agentGroup?.F_ZXZName ?? agentGroupStr,//坐席组
  170. agentgroupid = model.AgentGroupId,
  171. agentcount = agentCount,//坐席组人数
  172. allcount = model.y_HMCount ?? 0, //号码总数
  173. calledcount = model.y_HCCount ?? 0, //已呼个数
  174. calledrate = calledRate, //已完成百分比
  175. callleftcount = (int)(allcount - calledcount), //剩余个数
  176. connected = model.y_YJCount ?? 0, //总应答数
  177. connectedrate = connectedRate, //应答率
  178. connectedagentcount = (int)connectedAgentCount, //转坐席数
  179. connectedagentrate = connectedAgentRate, //转坐席率
  180. });
  181. }
  182. /// <summary>
  183. /// 添加/修改
  184. /// </summary>
  185. /// <param name="input"></param>
  186. /// <returns></returns>
  187. public ActionResult CreateOrUpdate(CallPlanInput input)
  188. {
  189. //if (!Request.IsAuthenticated)
  190. // return NoToken("未知错误,请重新登录");
  191. var model = new Model.T_CTI_Task();
  192. if (input.Id <= 0)
  193. {
  194. model.TaskName = input.Name;
  195. model.TaskType = input.Type;
  196. model.AgentGroupId = input.AgentGroupId;
  197. model.y_TkModelId = input.PagerId;
  198. model.Pre = input.Pre;
  199. if (input.ConcurrencyType == 0)
  200. {
  201. var num = 0;
  202. if (!int.TryParse(input.Concurrency.ToString(), out num))
  203. return Error("并发数必须为不小于1的整数");
  204. input.Concurrency = (int)input.Concurrency;
  205. }
  206. if (input.Concurrency < 1)
  207. return Error("输入的并发数和进号速率必须不小于1");
  208. model.ConcurrencyType = input.ConcurrencyType;
  209. model.Concurrency = input.ConcurrencyType == 0 ? (int)input.Concurrency : input.Concurrency;
  210. model.RecordFileId = input.RecordPathId;
  211. model.y_HMCount = 0;
  212. model.y_HCCount = 0;
  213. model.y_YJCount = 0;
  214. model.y_HTCount = 0;
  215. model.TrunkGroupID = 0;
  216. model.CallType = 1;
  217. model.State = 2;
  218. model.AddTime = DateTime.Now;
  219. model.y_PSort = 2;
  220. model.y_SXH = 0;
  221. model.y_FPCount = 0;
  222. model.y_HSCount = 0;
  223. model.y_OkCount = 0;
  224. model.y_RFCount = 0;
  225. model.y_ConsCount = 0;
  226. model.y_InvlCount = 0;
  227. model.y_NoAnswerCount = 0;
  228. model.y_ShutDownCount = 0;
  229. model.PlanStartDate = input.PlanStartDate ?? DateTime.Now;
  230. model.PlanEndDate = input.PlanEndDate?.AddDays(1).AddSeconds(-1) ?? DateTime.Now;
  231. model.StartTime1 = input.StartTime1 ?? DateTime.Now;
  232. model.EndTime1 = input.EndTime1 ?? DateTime.Now;
  233. model.StartTime2 = input.StartTime2 ?? DateTime.Now;
  234. model.EndTime2 = input.EndTime2 ?? DateTime.Now;
  235. var taskId = taskBLL.Add(model);
  236. if (taskId > 0)
  237. {
  238. try
  239. {
  240. pageFieldBLL.UpdateByTaskId(taskId);
  241. model.TaskID = taskId;
  242. DataTable dt = taskTellNumBLL.GetTableDesign();
  243. switch (input.ImportType)
  244. {
  245. case 1: //从文本文件导入
  246. var file = Request.Files[0];
  247. using (StreamReader sr = new StreamReader(file.InputStream))
  248. {
  249. String line;
  250. while ((line = sr.ReadLine()) != null)
  251. {
  252. var row = dt.NewRow();
  253. row["F_TaskId"] = model.TaskID;
  254. row["F_Phone"] = line.ToString();
  255. dt.Rows.Add(row);
  256. }
  257. }
  258. break;
  259. case 2: //从文本框中导入
  260. if (string.IsNullOrWhiteSpace(input.PhoneList))
  261. return Error("号码不可以为空");
  262. var arr = input.PhoneList.Split(new char[] { '\r', '\n', ',', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  263. foreach (var p in arr)
  264. {
  265. var row = dt.NewRow();
  266. row["F_TaskId"] = model.TaskID;
  267. row["F_Phone"] = p;
  268. dt.Rows.Add(row);
  269. }
  270. break;
  271. case 3: //从号码段导入
  272. if (string.IsNullOrWhiteSpace(input.PhoneStr))
  273. return Error("号码不可以为空");
  274. double phoneInt = 0;
  275. if (!double.TryParse(input.PhoneStr, out phoneInt))
  276. return Error("请输入正确的手机号码段");
  277. phoneInt = phoneInt * 10000;
  278. for (int i = 1; i < 10000; i++)
  279. {
  280. var row = dt.NewRow();
  281. row["F_TaskId"] = model.TaskID;
  282. row["F_Phone"] = phoneInt + i;
  283. dt.Rows.Add(row);
  284. }
  285. break;
  286. case 4: //从Excel中导入
  287. string[] strArr = input.SelectIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  288. var idArr = strArr.Select(x => Convert.ToInt32(x)).ToArray();
  289. var fieldList = pageFieldBLL.DataTableToList(pageFieldBLL.GetList($"F_ID in ({string.Join(",", idArr)})").Tables[0]);
  290. NPOIHelper npoi = new NPOIHelper();
  291. var dtExcel = npoi.ExcelToTable(input.FilePath, 0);
  292. for (int i = 0; i < dtExcel.Rows.Count; i++)
  293. {
  294. var row = dt.NewRow();
  295. for (int j = 0; j < dtExcel.Columns.Count; j++)
  296. {
  297. if (fieldList.Count < (j + 1))
  298. break;
  299. row["F_TaskId"] = model.TaskID;
  300. var field = fieldList.SingleOrDefault(x => x.F_Id == idArr[j]);
  301. row[field.F_DBFieldlName] = dtExcel.Rows[i][j];
  302. }
  303. dt.Rows.Add(row);
  304. }
  305. break;
  306. }
  307. if (input.CheckFilter1)
  308. {
  309. PhoneNumFilter(dt);
  310. }
  311. if (input.CheckFilter2)
  312. {
  313. PhoneNumFilterMonth(dt);
  314. }
  315. taskTellNumBLL.SqlBulkCopy(dt);
  316. model.y_HMCount = dt.Rows.Count;
  317. if (taskBLL.Update(model))
  318. return Success("添加成功");
  319. return Error("添加失败");
  320. }
  321. catch (Exception e)
  322. {
  323. return Error(e.Message);
  324. }
  325. }
  326. return Error("添加失败");
  327. }
  328. model = taskBLL.GetModel(input.Id);
  329. if (model == null)
  330. return Error("当前外呼任务不存在");
  331. model.TaskName = input.Name;
  332. model.TaskType = input.Type;
  333. model.AgentGroupId = input.AgentGroupId;
  334. model.y_TkModelId = input.PagerId;
  335. //model.Pre = input.Pre;
  336. if (input.ConcurrencyType == 0)
  337. {
  338. var num = 0;
  339. if (!int.TryParse(input.Concurrency.ToString(), out num))
  340. return Error("并发数必须为不小于1的整数");
  341. input.Concurrency = (int)input.Concurrency;
  342. }
  343. if (input.Concurrency < 1)
  344. return Error("输入的并发数和进号速率必须不小于1");
  345. model.ConcurrencyType = input.ConcurrencyType;
  346. model.Concurrency = input.ConcurrencyType == 0 ? (int)input.Concurrency : input.Concurrency;
  347. model.PlanStartDate = input.PlanStartDate ?? DateTime.Now;
  348. model.PlanEndDate = input.PlanEndDate?.AddDays(1).AddSeconds(-1) ?? DateTime.Now;
  349. model.StartTime1 = input.StartTime1 ?? DateTime.Now;
  350. model.EndTime1 = input.EndTime1 ?? DateTime.Now;
  351. model.StartTime2 = input.StartTime2 ?? DateTime.Now;
  352. model.EndTime2 = input.EndTime2 ?? DateTime.Now;
  353. model.RecordFileId = input.RecordPathId;
  354. if (taskBLL.Update(model))
  355. return Success("修改成功");
  356. return Error("修改失败");
  357. }
  358. /// <summary>
  359. /// 更新状态
  360. /// </summary>
  361. /// <param name="id"></param>
  362. /// <param name="state"></param>
  363. /// <returns></returns>
  364. public ActionResult UpdateState(int[] ids, int state)
  365. {
  366. //if (!Request.IsAuthenticated)
  367. // return NoToken("未知错误,请重新登录");
  368. var sql = "";
  369. if (ids.Length > 0)
  370. {
  371. sql += " TaskID in (" + string.Join(",", ids) + ") ";
  372. }
  373. var model = taskBLL.GetList(sql).Tables[0];
  374. foreach (DataRow item in model.Rows)
  375. {
  376. if (Convert.ToInt32(item["State"]) == -1)
  377. return Error("选择的任务存在已删除状态,执行失败");
  378. }
  379. if (taskBLL.UpdateStateBatch(sql, state))
  380. return Success("修改成功");
  381. return Error("修改失败");
  382. }
  383. /// <summary>
  384. /// 更新并发数
  385. /// </summary>
  386. /// <param name="id"></param>
  387. /// <param name="concurrency"></param>
  388. /// <returns></returns>
  389. public ActionResult UpdateConcurrency(long id, float concurrency, int concurrencyType = 0)
  390. {
  391. //if (!Request.IsAuthenticated)
  392. // return NoToken("未知错误,请重新登录");
  393. var model = taskBLL.GetModel(id);
  394. if (model == null)
  395. return Error("该外呼任务不存在");
  396. if (concurrencyType == 0)
  397. {
  398. var num = 0;
  399. if (!int.TryParse(concurrency.ToString(), out num))
  400. return Error("并发数必须为不小于1的整数");
  401. concurrency = num;
  402. }
  403. if (concurrency < 1)
  404. return Error("输入的并发数和进号速率必须不小于1");
  405. model.ConcurrencyType = concurrencyType;
  406. model.Concurrency = concurrency;
  407. if (taskBLL.Update(model))
  408. return Success("修改成功");
  409. return Error("修改失败");
  410. }
  411. /// <summary>
  412. /// 清空号码
  413. /// </summary>
  414. /// <returns></returns>
  415. public ActionResult ClearPhone(long id)
  416. {
  417. //if (!Request.IsAuthenticated)
  418. // return NoToken("未知错误,请重新登录");
  419. var num = taskBLL.DeletePhoneByTaskId(id);
  420. if (num > 0)
  421. {
  422. var task = taskBLL.GetModel(id);
  423. return Success("删除成功");
  424. }
  425. return Error("删除失败");
  426. }
  427. /// <summary>
  428. /// 去除号码前缀
  429. /// </summary>
  430. /// <param name="callId"></param>
  431. /// <param name="tel"></param>
  432. /// <returns></returns>
  433. public ActionResult RemovePre(string callId, string tel)
  434. {
  435. //if (!Request.IsAuthenticated)
  436. // return NoToken("未知错误,请重新登录");
  437. var callResult = callResultBLL.GetModel(callId);
  438. if (callResult == null)
  439. return Error("通话记录未正常添加");
  440. var task = taskBLL.GetModel(callResult.TaskId);
  441. if (task == null)
  442. return Error("任务不存在");
  443. var len = task.Pre.Length;
  444. return Success("去除成功", tel.Substring(len));
  445. }
  446. /// <summary>
  447. /// 更新外呼任务状态
  448. /// </summary>
  449. /// <returns></returns>
  450. public ActionResult UpdateCallPlanState()
  451. {
  452. StringBuilder sb = new StringBuilder();
  453. var log = LogFactory.GetLogger(this.GetType().ToString());
  454. var list = taskBLL.DataTableToList(taskBLL.GetList(" state>=0 ").Tables[0]);
  455. foreach (var task in list)
  456. {
  457. if (task.PlanStartDate <= DateTime.Now && task.PlanEndDate > DateTime.Now)
  458. {
  459. if (task.State == 2)
  460. {
  461. if (task.PlanStartDate < DateTime.Now && DateTime.Now < task.StartTime1)
  462. {
  463. task.State = 0;
  464. if (!taskBLL.Update(task))
  465. return Error($"更新自动外呼任务状态为0=待处理失败,ID={task.TaskID},Name={task.TaskName}");
  466. log.Info($"更新自动外呼任务状态为0=待处理成功,ID={task.TaskID},Name={task.TaskName}");
  467. }
  468. }
  469. if (task.State == 0)
  470. {
  471. if ((DateTime.Now >= task.StartTime1 && DateTime.Now < task.EndTime1) || (DateTime.Now > task.StartTime2 && DateTime.Now < task.EndTime2))
  472. {
  473. task.State = 1;
  474. if (!taskBLL.Update(task))
  475. return Error($"更新自动外呼任务状态为1=处理中失败,ID={task.TaskID},Name={task.TaskName}");
  476. log.Info($"更新自动外呼任务状态为1=处理中成功,ID={task.TaskID},Name={task.TaskName}");
  477. }
  478. }
  479. if (task.State == 1)
  480. {
  481. if (task.PlanEndDate < DateTime.Now)
  482. {
  483. task.State = 0;
  484. if (!taskBLL.Update(task))
  485. return Error($"更新自动外呼任务状态为2=暂停失败,ID={task.TaskID},Name={task.TaskName}");
  486. log.Info($"更新自动外呼任务状态为2=暂停成功,ID={task.TaskID},Name={task.TaskName}");
  487. }
  488. }
  489. }
  490. }
  491. return Success("处理完成");
  492. }
  493. /// <summary>
  494. /// 获取号码
  495. /// </summary>
  496. /// <param name="id"></param>
  497. /// <param name="pageSize"></param>
  498. /// <param name="pageIndex"></param>
  499. /// <returns></returns>
  500. public ActionResult GetPhoneList(FilterCallPhone filter)
  501. {
  502. //if (!Request.IsAuthenticated)
  503. // return NoToken("未知错误,请重新登录");
  504. var model = taskBLL.GetModel(filter.Id);
  505. if (model == null)
  506. return Error("外呼任务不存在");
  507. var sql = "";
  508. if (filter.UserId > 0)
  509. {
  510. sql += $" and F_UserId={filter.UserId} ";
  511. }
  512. if (!string.IsNullOrWhiteSpace(filter.Phone))
  513. {
  514. sql += $" and F_Phone like '%{filter.Phone}%'";
  515. }
  516. if (filter.FPState > -1)
  517. {
  518. sql += $" and F_FPState={filter.FPState} ";
  519. }
  520. if (filter.HCState > -1)
  521. {
  522. sql += $" and F_HCState={filter.HCState} ";
  523. }
  524. if (filter.YJState > -1)
  525. {
  526. sql += $" and F_YJState={filter.YJState} ";
  527. }
  528. var field = "F_Id,t.TaskName,F_Phone,F_FPState,F_HCState,F_YJState,F_Username,tn.F_CreateTime";
  529. if (filter.TaskType == 2)
  530. {
  531. field += " F_Phone,F_HCState,F_YJState";
  532. }
  533. var recordCount = 0;
  534. var dt = BLL.PagerBLL.GetListPager(
  535. " T_Call_TaskTelNum tn left join T_CTI_Task t on t.TaskID=tn.F_TaskId ",
  536. " F_Id ",
  537. field,
  538. " and F_TaskId=" + filter.Id + sql,
  539. "ORDER BY F_Id desc",
  540. filter.PageSize,
  541. filter.PageIndex,
  542. true,
  543. out recordCount);
  544. List<Model.T_Call_TaskTelNum> modelList = new BLL.T_Call_TaskTelNum().DataTableToListForShow(dt);
  545. var obj = new
  546. {
  547. rows = modelList.Select(x => new
  548. {
  549. taskname = x.TaskName,
  550. phone = x.F_Phone,
  551. agent = string.IsNullOrWhiteSpace(x.F_UserName) ? "" : x.F_UserName,
  552. isallot = x.F_FPState == null ? "" : (x.F_FPState > 0 ? "已分配" : "未分配"),
  553. iscalled = x.F_HCState > 0 ? "已呼叫" : "未呼叫",
  554. isconnected = x.F_YJState > 0 ? "已接通" : "未接通",
  555. createtime = Convert.ToDateTime(x.F_CreateTime).ToString("yyyy-MM-dd HH:mm:ss")
  556. }),
  557. total = recordCount
  558. };
  559. return Content(obj.ToJson());
  560. }
  561. /// <summary>
  562. /// 获取分配给当前登录坐席的号码
  563. /// </summary>
  564. /// <param name="filter"></param>
  565. /// <returns></returns>
  566. public ActionResult GetMyPhoneList(FilterCallPhone filter)
  567. {
  568. if (!Request.IsAuthenticated)
  569. return NoToken("未知错误,请重新登录");
  570. var sql = "";
  571. if (filter.Id > 0)
  572. {
  573. var model = taskBLL.GetModel(filter.Id);
  574. sql += " and F_TaskId=" + filter.Id;
  575. if (model == null)
  576. return Error("外呼任务不存在");
  577. }
  578. sql += $" and F_UserId={CurrentUser.UserData.F_UserId} ";
  579. if (!string.IsNullOrWhiteSpace(filter.Phone))
  580. {
  581. sql += $" and F_Phone like '%{filter.Phone}%'";
  582. }
  583. if (filter.FPState > -1)
  584. {
  585. sql += $" and F_FPState={filter.FPState} ";
  586. }
  587. if (filter.HCState > -1)
  588. {
  589. sql += $" and F_HCState={filter.HCState} ";
  590. }
  591. if (filter.YJState > -1)
  592. {
  593. sql += $" and F_YJState={filter.YJState} ";
  594. }
  595. var field = "F_Id,t.TaskName,F_Phone,F_FPState,F_HCState,F_YJState,F_Username,tn.F_CreateTime";
  596. if (filter.TaskType == 2)
  597. {
  598. field += " F_Phone,F_HCState,F_YJState";
  599. }
  600. var recordCount = 0;
  601. var dt = BLL.PagerBLL.GetListPager(
  602. " T_Call_TaskTelNum tn left join T_CTI_Task t on t.TaskID=tn.F_TaskId ",
  603. " F_Id ",
  604. field,
  605. sql,
  606. "ORDER BY F_Id desc",
  607. filter.PageSize,
  608. filter.PageIndex,
  609. true,
  610. out recordCount);
  611. List<Model.T_Call_TaskTelNum> modelList = new BLL.T_Call_TaskTelNum().DataTableToListForShow(dt);
  612. var obj = new
  613. {
  614. rows = modelList.Select(x => new
  615. {
  616. id = x.F_Id,
  617. taskname = x.TaskName,
  618. phone = x.F_Phone,
  619. agent = string.IsNullOrWhiteSpace(x.F_UserName) ? "" : x.F_UserName,
  620. isallot = x.F_FPState == null ? "" : (x.F_FPState > 0 ? "已分配" : "未分配"),
  621. iscalled = x.F_HCState > 0 ? "已呼叫" : "未呼叫",
  622. isconnected = x.F_YJState > 0 ? "已接通" : "未接通",
  623. createtime = Convert.ToDateTime(x.F_CreateTime).ToString("yyyy-MM-dd HH:mm:ss")
  624. }),
  625. total = recordCount
  626. };
  627. return Content(obj.ToJson());
  628. }
  629. /// <summary>
  630. /// 坐席自主获取号码(点击外呼分配号码)
  631. /// </summary>
  632. /// <param name="id">外呼任务ID</param>
  633. /// <param name="userId">坐席ID</param>
  634. /// <returns></returns>
  635. public ActionResult AllotPhoneList(int id, int count)
  636. {
  637. //if (!Request.IsAuthenticated)
  638. // return NoToken("未知错误,请重新登录");
  639. if (count <= 0)
  640. return Error("参数错误");
  641. if (id <= 0)
  642. return Error("请选择外呼任务");
  643. var model = taskBLL.GetModel(id);
  644. if (model == null)
  645. return Error("外呼任务不存在");
  646. var obj = DbHelperSQL.GetSingle($"SELECT Count(F_ID) FROM T_Call_TaskTelNum WHERE F_UserId={CurrentUser.UserData.F_UserId} and F_TaskId={id} and F_HCState=0 ");
  647. var sum = obj == null ? 0 : Convert.ToInt32(obj);
  648. if (sum >= 50)
  649. return Error("请先完成已分配任务");
  650. var res = DbHelperSQL.ExecuteSql($"UPDATE T_Call_TaskTelNum SET F_FPState=1,F_UserId={CurrentUser.UserData.F_UserId},F_Username='{CurrentUser.UserData.F_UserName}' WHERE F_Id in(SELECT TOP({count}) F_Id FROM T_Call_TaskTelNum WHERE F_TaskId={id} and F_FPState=0)");
  651. if (res > 0)
  652. return Success($"获取到{res}条可用号码");
  653. return Error("未获取到可用号码");
  654. }
  655. public ActionResult GetMyCallPlan()
  656. {
  657. var taskList = taskBLL.DataTableToList(taskBLL.GetList("state=1").Tables[0]);
  658. return Success("获取成功", taskList.Select(x => new
  659. {
  660. id = x.TaskID,
  661. name = x.TaskName
  662. }));
  663. }
  664. public ActionResult GetCallNumDetail(int id)
  665. {
  666. var taskId = DbHelperSQL.GetSingle($"SELECT F_TaskId FROM T_Call_TaskTelNum WHERE F_ID={id}");
  667. if (taskId == null || Convert.ToInt32(taskId) <= 0)
  668. return Error("参数错误");
  669. var fieldList = pageFieldBLL.DataTableToList(pageFieldBLL.GetList($"F_TaskId={taskId}").Tables[0]);
  670. StringBuilder sb = new StringBuilder();
  671. Dictionary<string, string> dicTitle = new Dictionary<string, string>();
  672. foreach (var item in fieldList)
  673. {
  674. sb.Append(item.F_DBFieldlName + ",");
  675. dicTitle.Add(item.F_DBFieldlName, item.F_Name);
  676. }
  677. if (!string.IsNullOrWhiteSpace(sb.ToString()))
  678. {
  679. var callNum = DbHelperSQL.Query($"SELECT {sb.ToString().Trim(',')} FROM T_Call_TaskTelNum WHERE F_ID={id}").Tables[0];
  680. Dictionary<string, string> dic = new Dictionary<string, string>();
  681. for (int j = 0; j < callNum.Columns.Count; j++)
  682. {
  683. dic.Add(callNum.Columns[j].ColumnName, callNum.Rows[0][j].ToString());
  684. }
  685. return Success("获取成功", dic.Select(x => new
  686. {
  687. field = x.Key,
  688. text = dicTitle[x.Key],
  689. value = x.Value
  690. }));
  691. }
  692. return Success("");
  693. }
  694. #endregion
  695. #region 导入导出号码
  696. /// <summary>
  697. /// 导入号码信息
  698. /// </summary>
  699. /// <param name="type">导入方式:1=Excel; 2=txt .......</param>
  700. /// <returns></returns>
  701. public ActionResult ImportData(ImportDataInput input)
  702. {
  703. if (Request.Files.Count <= 0)
  704. return Error("请正确上传Excel文件");
  705. var file = Request.Files[0];
  706. if (!file.ContentType.Equals("application/vnd.ms-excel") && !file.ContentType.Equals("application/x-xls"))
  707. return Error("请正确上传Excel文件");
  708. var filePath = "";
  709. NPOIHelper npoi = new NPOIHelper();
  710. var dt = npoi.ExcelToTable(file, 0, out filePath);
  711. var obj = dt.AsEnumerable().Take(10).CopyToDataTable();
  712. var colCount = obj.Columns.Count;
  713. var rowCount = obj.Rows.Count;
  714. string[] headArr = new string[colCount];
  715. for (int i = 0; i < colCount; i++)
  716. {
  717. headArr[i] = obj.Columns[i].ToString();
  718. }
  719. string[][] itemArr = new string[rowCount][];
  720. itemArr[0] = new string[rowCount];
  721. for (int i = 0; i < rowCount; i++)
  722. {
  723. var row = obj.Rows[i];
  724. var itemArray = row.ItemArray;
  725. itemArr[i] = new string[itemArray.Count()];
  726. for (int j = 0; j < itemArray.Count(); j++)
  727. {
  728. itemArr[i][j] = itemArray[j].ToString();
  729. }
  730. }
  731. return Success("上传成功", new
  732. {
  733. filepath = filePath,
  734. heads = headArr,
  735. items = itemArr
  736. });
  737. }
  738. /// <summary>
  739. /// 导出号码信息
  740. /// </summary>
  741. /// <returns></returns>
  742. public ActionResult ExportData(long taskId, int type = 0)
  743. {
  744. //if (!Request.IsAuthenticated)
  745. // return NoToken("未知错误,请重新登录");
  746. NPOIHelper npoi = new NPOIHelper();
  747. var task = taskBLL.GetModel(taskId);
  748. if (task == null)
  749. return Error("该外呼任务不存在");
  750. switch (type)
  751. {
  752. case 1:
  753. var dt1 = taskTellNumBLL.GetPhoneList(" F_TaskId=" + task.TaskID + " and F_HCState=1 and (F_YJState=0 or F_YJState is null) ").Tables[0];
  754. var msg1 = npoi.ExportToExcel(DateTime.Now.ToString("yyyyMMdd") + task.TaskName + "导出未接通号码", dt1);
  755. return !string.IsNullOrWhiteSpace(msg1) ? Error(msg1) : Success("导出成功");
  756. case 2:
  757. var dt2 = taskTellNumBLL.GetPhoneList(" F_TaskId=" + task.TaskID + " and F_HCState=1 and F_YJState=1 ").Tables[0];
  758. var msg2 = npoi.ExportToExcel(DateTime.Now.ToString("yyyyMMdd") + task.TaskName + "导出已接通号码", dt2);
  759. return !string.IsNullOrWhiteSpace(msg2) ? Error(msg2) : Success("导出成功");
  760. }
  761. return Error("参数错误");
  762. }
  763. #endregion
  764. #region 自动放音
  765. /// <summary>
  766. /// 获取自动放音文件
  767. /// </summary>
  768. /// <returns></returns>
  769. public ActionResult GetRecordDropList()
  770. {
  771. //if (!Request.IsAuthenticated)
  772. // return NoToken("未知错误,请重新登录");
  773. var list = taskRecordBLL.DataTableToList(taskRecordBLL.GetList("").Tables[0]).Select(x => new
  774. {
  775. id = x.Id,
  776. name = x.Name,
  777. });
  778. return Success("成功", list.ToList());
  779. }
  780. /// <summary>
  781. /// 获取自动放音文件
  782. /// </summary>
  783. /// <returns></returns>
  784. public ActionResult GetRecordList(FilterTalkRecord filter)
  785. {
  786. //if (!Request.IsAuthenticated)
  787. // return NoToken("未知错误,请重新登录");
  788. var recordCount = 0;
  789. var dt = BLL.PagerBLL.GetListPager(
  790. "T_CTI_TaskRecord ",
  791. "id",
  792. "*",
  793. "",
  794. "ORDER BY id desc",
  795. filter.PageSize,
  796. filter.PageIndex,
  797. true,
  798. out recordCount);
  799. var list = taskRecordBLL.DataTableToList(dt).Select(x => new
  800. {
  801. id = x.Id,
  802. name = x.Name,
  803. recordpath = x.RecordPath,
  804. recordtime = x.RecordTime,
  805. });
  806. var obj = new
  807. {
  808. rows = list,
  809. total = recordCount
  810. };
  811. return Content(obj.ToJson());
  812. }
  813. /// <summary>
  814. /// 获取录音
  815. /// </summary>
  816. /// <param name="id"></param>
  817. /// <returns></returns>
  818. public ActionResult GetRecord(int id)
  819. {
  820. //if (!Request.IsAuthenticated)
  821. // return NoToken("未知错误,请重新登录");
  822. var x = taskRecordBLL.GetModel(id);
  823. return Success("成功", new
  824. {
  825. id = x.Id,
  826. name = x.Name,
  827. recordpath = x.RecordPath,
  828. recordtime = x.RecordTime,
  829. remark = x.Remark
  830. });
  831. }
  832. /// <summary>
  833. /// 添加/更新自动放音
  834. /// </summary>
  835. /// <param name="input"></param>
  836. /// <returns></returns>
  837. public ActionResult CreateOrUpdateRecord(Model.T_CTI_TaskRecord input)
  838. {
  839. //if (!Request.IsAuthenticated)
  840. // return NoToken("未知错误,请重新登录");
  841. Model.T_CTI_TaskRecord model = new Model.T_CTI_TaskRecord();
  842. if (input.Id <= 0)
  843. {
  844. var dir = Server.MapPath("~/UploadRecord/");
  845. if (!Directory.Exists(dir))
  846. {
  847. Directory.CreateDirectory(dir);
  848. }
  849. var file = Request.Files[0];
  850. if (file.ContentType != "audio/x-wav" && file.ContentType != "audio/wav")
  851. return Error("上传录音格式必须为.wav");
  852. var name = DateTime.Now.ToString("yyyyMMddHHmmss") + Guid.NewGuid().ToString("N").Substring(0, 10) + ".wav";
  853. var path = dir + name;
  854. Request.Files[0].SaveAs(path);
  855. FileInfo fileInfo = new FileInfo(path);
  856. var fileName = FileUp.UploadFile(fileInfo, "/", "120.194.141.197", "Administrator", "hykj@800100");
  857. var sysConfig = systemConfigBLL.GetModel(40);
  858. if (sysConfig == null)
  859. return Error("自动放音录音路径查询失败");
  860. model.Name = input.Name;
  861. model.RecordPath = sysConfig.F_ParamValue + fileName;
  862. //model.RecordTime = input.RecordTime;
  863. model.Remark = input.Remark;
  864. if (taskRecordBLL.Add(model) > 0)
  865. return Success("添加成功");
  866. return Error("添加失败");
  867. }
  868. return Success("添加失败");
  869. }
  870. #endregion
  871. #region 话单查询
  872. /// <summary>
  873. /// 话务分析
  874. /// </summary>
  875. /// <returns></returns>
  876. public ActionResult GetTalkAnalysis(DateTime? start, DateTime? end)
  877. {
  878. //if (!Request.IsAuthenticated)
  879. // return NoToken("未知错误,请重新登录");
  880. //var where = "";
  881. //if (start != null && end != null)
  882. //{
  883. // where += " PlanStartDate<'" + start.ToString() + "' and PlanEndDate>";
  884. //}
  885. var fir = taskPhonePartBLL.DataTableToList(taskPhonePartBLL.GetList("").Tables[0]);
  886. var sec = taskDailyBLL.DataTableToList(taskDailyBLL.GetList("").Tables[0]);
  887. var thi = taskDailyBLL.DataTableToList(taskDailyBLL.GetList().Tables[0]);
  888. var obj = new
  889. {
  890. fir = fir.Select(x => new
  891. {
  892. date = x.Date.ToString("yyyy-MM-dd"),
  893. phonepart = x.PhonePart,
  894. province = x.Province,
  895. city = x.City,
  896. connectedcount = x.CalledCount == 0 ? "" : (x.ConnectedCount / x.CalledCount * 100).ToString("f2") + "%",
  897. connectedagentcount = x.ConnectedCount == 0 ? "" : (x.ConnectedAgentCount / x.ConnectedCount * 100).ToString("f2") + "%",
  898. }),
  899. sec = sec.Select(x => new
  900. {
  901. date = x.Date.ToString("yyyy-MM-dd"),
  902. allcount = x.AllCount,
  903. calledcount = x.CalledCount,
  904. connectedcount = x.ConnectedCount,
  905. connectedagentcount = x.ConnectedAgentCount,
  906. connectedrate = x.CalledCount == 0 ? "" : (x.ConnectedCount / x.CalledCount * 100).ToString("f2") + "%",
  907. connectedagentrate = x.ConnectedCount == 0 ? "" : (x.ConnectedAgentCount / x.ConnectedCount * 100).ToString("f2") + "%",
  908. taskid = x.TaskId,
  909. taskname = x.TaskName
  910. }),
  911. thi = thi.Select(x => new
  912. {
  913. date = x.Date.ToString("yyyy-MM-dd"),
  914. allcount = x.AllCount,
  915. calledcount = x.CalledCount,
  916. connectedcount = x.ConnectedCount,
  917. connectedagentcount = x.ConnectedAgentCount,
  918. connectedrate = x.CalledCount == 0 ? "" : (x.ConnectedCount / x.CalledCount * 100).ToString("f2") + "%",
  919. connectedagentrate = x.ConnectedCount == 0 ? "" : (x.ConnectedAgentCount / x.ConnectedCount * 100).ToString("f2") + "%",
  920. taskid = x.TaskId,
  921. taskname = x.TaskName
  922. })
  923. };
  924. return Success("", obj);
  925. }
  926. /// <summary>
  927. /// 获取通话记录列表
  928. /// </summary>
  929. /// <returns></returns>
  930. public ActionResult GetTalkRecords(FilterTalkRecord filter)
  931. {
  932. //if (!Request.IsAuthenticated)
  933. // return NoToken("未知错误,请重新登录");
  934. var sort = "ORDER BY startdate desc";
  935. if (!string.IsNullOrWhiteSpace(filter.SortField))
  936. {
  937. var arr = filter.SortField.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  938. EnumTalkRecordsSortField e;
  939. if (!Enum.TryParse(arr[0], out e))
  940. return Error("排序字段参数错误");
  941. sort = "ORDER BY " + e.ToString() + " " + arr[1];
  942. }
  943. StringBuilder where = new StringBuilder();
  944. if (!string.IsNullOrWhiteSpace(filter.UserCode))
  945. {
  946. where.Append(" and agentid=" + filter.UserCode);
  947. }
  948. if (!string.IsNullOrWhiteSpace(filter.Phone))
  949. {
  950. where.Append(" and callee like '%" + filter.Phone + "%'");
  951. }
  952. if (filter.CallType != 0)
  953. {
  954. where.Append(" and calltype=" + filter.CallType);
  955. }
  956. if (!string.IsNullOrWhiteSpace(filter.TalkTime))
  957. {
  958. var arr = filter.TalkTime.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  959. if (arr.Length == 2)
  960. {
  961. if (arr[0] == "1")
  962. {
  963. where.Append(" and talktime>" + arr[1]);
  964. }
  965. else if (arr[0] == "2")
  966. {
  967. where.Append(" and talktime=" + arr[1]);
  968. }
  969. else if (arr[0] == "3")
  970. {
  971. where.Append(" and talktime<" + arr[1]);
  972. }
  973. else { }
  974. }
  975. }
  976. if (filter.StartTime == null || filter.EndTime == null)
  977. {
  978. filter.StartTime = DateTime.Now.AddDays(-3);
  979. filter.EndTime = DateTime.Now;
  980. }
  981. where.Append(" and datediff(s,'" + filter.StartTime + "',getdate())>=0 and datediff(s,getdate(),'" + filter.EndTime + "')>=0 ");
  982. // 全部=0
  983. // 未接通=1
  984. // 接通排队=2
  985. // 接通未转入坐席=3
  986. // 接通且分配坐席=4
  987. int recordCount = 0;
  988. Model.PageData<Model.CallResult> pageModel = new Model.PageData<Model.CallResult>();
  989. StringBuilder fields = new StringBuilder();
  990. var dt = BLL.PagerBLL.GetListPager(
  991. "V_AutoCallResult",
  992. "V_AutoCallResult.id",
  993. "V_AutoCallResult.id,itemid, callee, agentid, username,startdate,enddate,getinagentdate,calltype,talktime,RecordPath",
  994. where.ToString(),
  995. sort,
  996. filter.PageSize,
  997. filter.PageIndex,
  998. true,
  999. out recordCount);
  1000. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  1001. var callResultList = callResultBLL.DataTableToList(dt);
  1002. var list = new List<AutoCallRecordDto>();
  1003. callResultList.ForEach(x =>
  1004. {
  1005. var recordPath = "";
  1006. if (!string.IsNullOrWhiteSpace(x.RecordPath) && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
  1007. {
  1008. var ym = config.F_ParamValue;
  1009. if (ym.Substring(ym.Length - 1) == "/")
  1010. {
  1011. ym = ym.Substring(0, ym.Length - 1);
  1012. }
  1013. recordPath = ym + x.RecordPath.Substring(x.RecordPath.IndexOf(':') + 1).Replace('\\', '/');
  1014. }
  1015. list.Add(new AutoCallRecordDto
  1016. {
  1017. id = x.Id,
  1018. taskid = x.TaskId,
  1019. callnumber = x.CallNumber,
  1020. usercode = x.Usercode == "0" ? "" : x.Usercode,
  1021. startdate = x.StartDate?.ToString("yyyy-MM-dd HH:mm:ss") ?? "",
  1022. getinagentdate = x.GetInAgentDate?.ToString("yyyy-MM-dd HH:mm:ss") ?? "",
  1023. enddate = x.EndDate?.ToString("yyyy-MM-dd HH:mm:ss") ?? "",
  1024. recordpath = recordPath,
  1025. username = x.Username,
  1026. state = x.State,
  1027. talktime = x.TalkTime > 0 ? x.TalkTime.ToString() : ""
  1028. });
  1029. });
  1030. var obj = new
  1031. {
  1032. rows = list,
  1033. total = recordCount
  1034. };
  1035. return Content(obj.ToJson());
  1036. }
  1037. #endregion
  1038. #region 过滤号码
  1039. #region 过滤号码-数据源
  1040. /// <summary>
  1041. /// 过滤号码
  1042. /// </summary>
  1043. /// <param name="dt"></param>
  1044. private DataTable PhoneNumFilter(DataTable dt)
  1045. {
  1046. var dtClone = dt.Copy();
  1047. foreach (DataRow row in dtClone.Rows)
  1048. {
  1049. var rows = dt.Select("[F_Phone]='" + row["F_Phone"] + "'");
  1050. if (rows.Length > 1)
  1051. {
  1052. for (int num = 0; num < rows.Count() - 1; num++)
  1053. {
  1054. dt.Rows.Remove(rows[num]);
  1055. }
  1056. }
  1057. }
  1058. return dt;
  1059. }
  1060. #endregion
  1061. #region 过滤号码-前三个月
  1062. private DataTable PhoneNumFilterMonth(DataTable dt, string phone = "F_Phone")
  1063. {
  1064. var taskTelNumDt = taskTellNumBLL.GetList(" datediff(mm,F_CreateTime,getdate())<=3 ").Tables[0];
  1065. foreach (DataRow row in taskTelNumDt.Rows)
  1066. {
  1067. var rows = dt.Select("[" + phone + "]='" + row["F_Phone"] + "'");
  1068. if (rows.Length > 1)
  1069. {
  1070. for (int num = 0; num < rows.Count() - 1; num++)
  1071. {
  1072. dt.Rows.Remove(rows[num]);
  1073. }
  1074. }
  1075. }
  1076. return dt;
  1077. }
  1078. #endregion
  1079. #endregion
  1080. }
  1081. }