| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149 |
- using CallCenter.Utility;
- using CallCenterApi.DB;
- using CallCenterApi.Interface.Controllers.Base;
- using CallCenterApi.Interface.Models.Dto;
- using CallCenterApi.Interface.Models.Filter;
- using CallCenterApi.Interface.Models.Input;
- using CallCenterApi.Model;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Web;
- using System.Web.Mvc;
- namespace CallCenterApi.Interface.Controllers.callout
- {
- public class CallPlanController : BaseController
- {
- private BLL.T_CTI_Task taskBLL = new BLL.T_CTI_Task();
- private BLL.T_Call_TaskTelNum taskTellNumBLL = new BLL.T_Call_TaskTelNum();
- private BLL.T_Sys_DictionaryValue dictValueBLL = new BLL.T_Sys_DictionaryValue();
- private BLL.T_CTI_TaskAgent taskAgentBLL = new BLL.T_CTI_TaskAgent();
- private BLL.T_Sys_UserAccount userAccount = new BLL.T_Sys_UserAccount();
- private BLL.T_CTI_TaskRecord taskRecordBLL = new BLL.T_CTI_TaskRecord();
- private BLL.CallResult callResultBLL = new BLL.CallResult();
- private BLL.T_CTI_TaskDaily taskDailyBLL = new BLL.T_CTI_TaskDaily();
- private BLL.T_CTI_TaskPhonePart taskPhonePartBLL = new BLL.T_CTI_TaskPhonePart();
- private BLL.T_Sys_SeatGroup seatGroupBLL = new BLL.T_Sys_SeatGroup();
- private BLL.T_Sys_SystemConfig systemConfigBLL = new BLL.T_Sys_SystemConfig();
- private BLL.T_Call_PageField pageFieldBLL = new BLL.T_Call_PageField();
- #region 外呼任务
- /// <summary>
- /// 获取列表
- /// </summary>
- /// <param name="filter"></param>
- /// <returns></returns>
- public ActionResult GetList(FilterCallPlan filter)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- var sql = " and State>=0 and TaskType=" + filter.TaskType;
- if (!string.IsNullOrWhiteSpace(filter.Name))
- {
- sql += " and (TaskName like '%" + filter.Name.Trim() + "%' ) ";
- }
- Model.PageData<Model.T_CTI_Task> pageModel = new Model.PageData<Model.T_CTI_Task>();
- var recordCount = 0;
- var dt = BLL.PagerBLL.GetListPager(
- "T_CTI_Task",
- "TaskID",
- "*",
- sql,
- "ORDER BY AddTime desc",
- filter.PageSize,
- filter.PageIndex,
- true,
- out recordCount);
- List<Model.T_CTI_Task> modelList = new BLL.T_CTI_Task().DataTableToList(dt);
- var list = new List<CallPlanDto>();
- //查询坐席组
- var agentGroupList = seatGroupBLL.DataTableToList(seatGroupBLL.GetList("").Tables[0]);
- //查询坐席
- var agentList = userAccount.DataTableToList(userAccount.GetList(" F_DeleteFlag=0 ").Tables[0]);
- foreach (var model in modelList)
- {
- //计算数据
- string calledRate = "0";
- var allcount = model.y_HMCount ?? 0;
- float calledcount = model.y_HCCount ?? 0;
- calledRate = allcount == 0 ? "" : (calledcount / allcount * 100).ToString("f2") + "%";
- string connectedRate = "0";
- float connected = model.y_YJCount ?? 0;
- connectedRate = calledcount == 0 ? "0" : (connected / calledcount * 100).ToString("f2") + "%";
- var taskTellNumDt = taskTellNumBLL.GetList(" F_HCState=1 and F_YJState=1 and F_UserId>0 and F_TaskId=" + model.TaskID).Tables[0];
- float connectedAgentCount = taskTellNumDt?.Rows.Count ?? 0;
- var connectedAgentRate = "0";
- connectedAgentRate = connected == 0 ? "0" : (connectedAgentCount / connected * 100).ToString("f2") + "%";
- var agentGroupStr = model.AgentGroupId == -999 ? "不转坐席" : "";
- var agentGroup = agentGroupList.SingleOrDefault(x => x.F_ZXZID == model.AgentGroupId);
- var agentCount = agentList.Where(x => x.F_SeartGroupID == (agentGroup?.F_ZXZID ?? 0)).Count();
- list.Add(new CallPlanDto
- {
- id = model.TaskID,
- name = model.TaskName,
- tasktype = model.TaskType == 1 ? "点击外呼" : "自动外呼",
- state = Enum.GetName(typeof(EnumTaskState), (model.State ?? -1)),
- addtime = Convert.ToDateTime(model.AddTime).ToString("yyyy-MM-dd HH:mm:ss"),
- talkid = model.y_TkModelId ?? 0,
- pre = model.Pre, //线路前缀
- concurrencytype = model.ConcurrencyType,
- concurrency = model.Concurrency,
- planstartdate = model.PlanStartDate.ToString("yyyy-MM-dd"),
- planenddate = model.PlanEndDate.ToString("yyyy-MM-dd"),
- starttime1 = model.StartTime1.ToString("HH:mm:ss"),
- endtime1 = model.EndTime1.ToString("HH:mm:ss"),
- starttime2 = model.StartTime2.ToString("HH:mm:ss"),
- endtime2 = model.EndTime2.ToString("HH:mm:ss"),
- agentgroup = agentGroup?.F_ZXZName ?? agentGroupStr,//坐席组
- agentgroupid = model.AgentGroupId,
- agentcount = agentCount,//坐席组人数
- allcount = model.y_HMCount ?? 0, //号码总数
- calledcount = model.y_HCCount ?? 0, //已呼个数
- calledrate = calledRate, //已完成百分比
- callleftcount = (int)(allcount - calledcount), //剩余个数
- connected = model.y_YJCount ?? 0, //总应答数
- connectedrate = connectedRate, //应答率
- connectedagentcount = (int)connectedAgentCount, //转坐席数
- connectedagentrate = connectedAgentRate, //转坐席率
- });
- }
- var obj = new
- {
- rows = list,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 获取实体
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public ActionResult GetModel(int id)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- var model = taskBLL.GetModel(id);
- if (model == null)
- return Error("预测外呼任务不存在");
- //计算数据
- string calledRate = "0";
- var allcount = model.y_HMCount ?? 0;
- float calledcount = model.y_HCCount ?? 0;
- calledRate = allcount == 0 ? "" : (calledcount / allcount * 100).ToString("f2") + "%";
- string connectedRate = "0";
- float connected = model.y_YJCount ?? 0;
- connectedRate = calledcount == 0 ? "0" : (connected / calledcount * 100).ToString("f2") + "%";
- var taskTellNumDt = taskTellNumBLL.GetList(" F_HCState=1 and F_YJState=1 and F_UserId>0 and F_TaskId=" + model.TaskID).Tables[0];
- float connectedAgentCount = taskTellNumDt?.Rows.Count ?? 0;
- var connectedAgentRate = "0";
- connectedAgentRate = connected == 0 ? "0" : (connectedAgentCount / connected * 100).ToString("f2") + "%";
- //查询坐席组
- var agentGroupList = seatGroupBLL.DataTableToList(seatGroupBLL.GetList("").Tables[0]);
- //查询坐席
- var agentList = userAccount.DataTableToList(userAccount.GetList(" F_DeleteFlag=0 ").Tables[0]);
- var agentGroupStr = model.AgentGroupId == -999 ? "不转坐席" : "";
- var agentGroup = agentGroupList.SingleOrDefault(x => x.F_ZXZID == model.AgentGroupId);
- var agentCount = agentList.Where(x => x.F_SeartGroupID == (agentGroup?.F_ZXZID ?? 0)).Count();
- return Success("获取成功", new CallPlanDto
- {
- id = model.TaskID,
- name = model.TaskName,
- tasktype = model.TaskType == 1 ? "点击外呼" : "自动外呼",
- state = "暂停",
- addtime = Convert.ToDateTime(model.AddTime).ToString("yyyy-MM-dd HH:mm:ss"),
- talkid = model.y_TkModelId ?? 0,
- pre = model.Pre, //线路前缀
- recordpathid = model.RecordFileId,
- concurrencytypestr = model.ConcurrencyType == 0 ? "并发数" : "并发速率",
- concurrencytype = model.ConcurrencyType,
- concurrency = model.Concurrency,
- planstartdate = model.PlanStartDate.ToString("yyyy-MM-dd"),
- planenddate = model.PlanEndDate.ToString("yyyy-MM-dd"),
- starttime1 = model.StartTime1.ToString("HH:mm"),
- endtime1 = model.EndTime1.ToString("HH:mm"),
- starttime2 = model.StartTime2.ToString("HH:mm"),
- endtime2 = model.EndTime2.ToString("HH:mm"),
- agentgroup = agentGroup?.F_ZXZName ?? agentGroupStr,//坐席组
- agentgroupid = model.AgentGroupId,
- agentcount = agentCount,//坐席组人数
- allcount = model.y_HMCount ?? 0, //号码总数
- calledcount = model.y_HCCount ?? 0, //已呼个数
- calledrate = calledRate, //已完成百分比
- callleftcount = (int)(allcount - calledcount), //剩余个数
- connected = model.y_YJCount ?? 0, //总应答数
- connectedrate = connectedRate, //应答率
- connectedagentcount = (int)connectedAgentCount, //转坐席数
- connectedagentrate = connectedAgentRate, //转坐席率
- });
- }
- /// <summary>
- /// 添加/修改
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public ActionResult CreateOrUpdate(CallPlanInput input)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- var model = new Model.T_CTI_Task();
- if (input.Id <= 0)
- {
- model.TaskName = input.Name;
- model.TaskType = input.Type;
- model.AgentGroupId = input.AgentGroupId;
- model.y_TkModelId = input.PagerId;
- model.Pre = input.Pre;
- if (input.ConcurrencyType == 0)
- {
- var num = 0;
- if (!int.TryParse(input.Concurrency.ToString(), out num))
- return Error("并发数必须为不小于1的整数");
- input.Concurrency = (int)input.Concurrency;
- }
- if (input.Concurrency < 1)
- return Error("输入的并发数和进号速率必须不小于1");
- model.ConcurrencyType = input.ConcurrencyType;
- model.Concurrency = input.ConcurrencyType == 0 ? (int)input.Concurrency : input.Concurrency;
- model.RecordFileId = input.RecordPathId;
- model.y_HMCount = 0;
- model.y_HCCount = 0;
- model.y_YJCount = 0;
- model.y_HTCount = 0;
- model.TrunkGroupID = 0;
- model.CallType = 1;
- model.State = 2;
- model.AddTime = DateTime.Now;
- model.y_PSort = 2;
- model.y_SXH = 0;
- model.y_FPCount = 0;
- model.y_HSCount = 0;
- model.y_OkCount = 0;
- model.y_RFCount = 0;
- model.y_ConsCount = 0;
- model.y_InvlCount = 0;
- model.y_NoAnswerCount = 0;
- model.y_ShutDownCount = 0;
- model.PlanStartDate = input.PlanStartDate ?? DateTime.Now;
- model.PlanEndDate = input.PlanEndDate?.AddDays(1).AddSeconds(-1) ?? DateTime.Now;
- model.StartTime1 = input.StartTime1 ?? DateTime.Now;
- model.EndTime1 = input.EndTime1 ?? DateTime.Now;
- model.StartTime2 = input.StartTime2 ?? DateTime.Now;
- model.EndTime2 = input.EndTime2 ?? DateTime.Now;
- var taskId = taskBLL.Add(model);
- if (taskId > 0)
- {
- try
- {
- pageFieldBLL.UpdateByTaskId(taskId);
- model.TaskID = taskId;
- DataTable dt = taskTellNumBLL.GetTableDesign();
- switch (input.ImportType)
- {
- case 1: //从文本文件导入
- var file = Request.Files[0];
- using (StreamReader sr = new StreamReader(file.InputStream))
- {
- String line;
- while ((line = sr.ReadLine()) != null)
- {
- var row = dt.NewRow();
- row["F_TaskId"] = model.TaskID;
- row["F_Phone"] = line.ToString();
- dt.Rows.Add(row);
- }
- }
- break;
- case 2: //从文本框中导入
- if (string.IsNullOrWhiteSpace(input.PhoneList))
- return Error("号码不可以为空");
- var arr = input.PhoneList.Split(new char[] { '\r', '\n', ',', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
- foreach (var p in arr)
- {
- var row = dt.NewRow();
- row["F_TaskId"] = model.TaskID;
- row["F_Phone"] = p;
- dt.Rows.Add(row);
- }
- break;
- case 3: //从号码段导入
- if (string.IsNullOrWhiteSpace(input.PhoneStr))
- return Error("号码不可以为空");
- double phoneInt = 0;
- if (!double.TryParse(input.PhoneStr, out phoneInt))
- return Error("请输入正确的手机号码段");
- phoneInt = phoneInt * 10000;
- for (int i = 1; i < 10000; i++)
- {
- var row = dt.NewRow();
- row["F_TaskId"] = model.TaskID;
- row["F_Phone"] = phoneInt + i;
- dt.Rows.Add(row);
- }
- break;
- case 4: //从Excel中导入
- string[] strArr = input.SelectIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- var idArr = strArr.Select(x => Convert.ToInt32(x)).ToArray();
- var fieldList = pageFieldBLL.DataTableToList(pageFieldBLL.GetList($"F_ID in ({string.Join(",", idArr)})").Tables[0]);
- NPOIHelper npoi = new NPOIHelper();
- var dtExcel = npoi.ExcelToTable(input.FilePath, 0);
- for (int i = 0; i < dtExcel.Rows.Count; i++)
- {
- var row = dt.NewRow();
- for (int j = 0; j < dtExcel.Columns.Count; j++)
- {
- if (fieldList.Count < (j + 1))
- break;
- row["F_TaskId"] = model.TaskID;
- var field = fieldList.SingleOrDefault(x => x.F_Id == idArr[j]);
- row[field.F_DBFieldlName] = dtExcel.Rows[i][j];
- }
- dt.Rows.Add(row);
- }
- break;
- }
- if (input.CheckFilter1)
- {
- PhoneNumFilter(dt);
- }
- if (input.CheckFilter2)
- {
- PhoneNumFilterMonth(dt);
- }
- taskTellNumBLL.SqlBulkCopy(dt);
- model.y_HMCount = dt.Rows.Count;
- if (taskBLL.Update(model))
- return Success("添加成功");
- return Error("添加失败");
- }
- catch (Exception e)
- {
- return Error(e.Message);
- }
- }
- return Error("添加失败");
- }
- model = taskBLL.GetModel(input.Id);
- if (model == null)
- return Error("当前外呼任务不存在");
- model.TaskName = input.Name;
- model.TaskType = input.Type;
- model.AgentGroupId = input.AgentGroupId;
- model.y_TkModelId = input.PagerId;
- //model.Pre = input.Pre;
- if (input.ConcurrencyType == 0)
- {
- var num = 0;
- if (!int.TryParse(input.Concurrency.ToString(), out num))
- return Error("并发数必须为不小于1的整数");
- input.Concurrency = (int)input.Concurrency;
- }
- if (input.Concurrency < 1)
- return Error("输入的并发数和进号速率必须不小于1");
- model.ConcurrencyType = input.ConcurrencyType;
- model.Concurrency = input.ConcurrencyType == 0 ? (int)input.Concurrency : input.Concurrency;
- model.PlanStartDate = input.PlanStartDate ?? DateTime.Now;
- model.PlanEndDate = input.PlanEndDate?.AddDays(1).AddSeconds(-1) ?? DateTime.Now;
- model.StartTime1 = input.StartTime1 ?? DateTime.Now;
- model.EndTime1 = input.EndTime1 ?? DateTime.Now;
- model.StartTime2 = input.StartTime2 ?? DateTime.Now;
- model.EndTime2 = input.EndTime2 ?? DateTime.Now;
- model.RecordFileId = input.RecordPathId;
- if (taskBLL.Update(model))
- return Success("修改成功");
- return Error("修改失败");
- }
- /// <summary>
- /// 更新状态
- /// </summary>
- /// <param name="id"></param>
- /// <param name="state"></param>
- /// <returns></returns>
- public ActionResult UpdateState(int[] ids, int state)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- var sql = "";
- if (ids.Length > 0)
- {
- sql += " TaskID in (" + string.Join(",", ids) + ") ";
- }
- var model = taskBLL.GetList(sql).Tables[0];
- foreach (DataRow item in model.Rows)
- {
- if (Convert.ToInt32(item["State"]) == -1)
- return Error("选择的任务存在已删除状态,执行失败");
- }
- if (taskBLL.UpdateStateBatch(sql, state))
- return Success("修改成功");
- return Error("修改失败");
- }
- /// <summary>
- /// 更新并发数
- /// </summary>
- /// <param name="id"></param>
- /// <param name="concurrency"></param>
- /// <returns></returns>
- public ActionResult UpdateConcurrency(long id, float concurrency, int concurrencyType = 0)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- var model = taskBLL.GetModel(id);
- if (model == null)
- return Error("该外呼任务不存在");
- if (concurrencyType == 0)
- {
- var num = 0;
- if (!int.TryParse(concurrency.ToString(), out num))
- return Error("并发数必须为不小于1的整数");
- concurrency = num;
- }
- if (concurrency < 1)
- return Error("输入的并发数和进号速率必须不小于1");
- model.ConcurrencyType = concurrencyType;
- model.Concurrency = concurrency;
- if (taskBLL.Update(model))
- return Success("修改成功");
- return Error("修改失败");
- }
- /// <summary>
- /// 清空号码
- /// </summary>
- /// <returns></returns>
- public ActionResult ClearPhone(long id)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- var num = taskBLL.DeletePhoneByTaskId(id);
- if (num > 0)
- {
- var task = taskBLL.GetModel(id);
- return Success("删除成功");
- }
- return Error("删除失败");
- }
- /// <summary>
- /// 去除号码前缀
- /// </summary>
- /// <param name="callId"></param>
- /// <param name="tel"></param>
- /// <returns></returns>
- public ActionResult RemovePre(string callId, string tel)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- var callResult = callResultBLL.GetModel(callId);
- if (callResult == null)
- return Error("通话记录未正常添加");
- var task = taskBLL.GetModel(callResult.TaskId);
- if (task == null)
- return Error("任务不存在");
- var len = task.Pre.Length;
- return Success("去除成功", tel.Substring(len));
- }
- /// <summary>
- /// 更新外呼任务状态
- /// </summary>
- /// <returns></returns>
- public ActionResult UpdateCallPlanState()
- {
- StringBuilder sb = new StringBuilder();
- var log = LogFactory.GetLogger(this.GetType().ToString());
- var list = taskBLL.DataTableToList(taskBLL.GetList(" state>=0 ").Tables[0]);
- foreach (var task in list)
- {
- if (task.PlanStartDate <= DateTime.Now && task.PlanEndDate > DateTime.Now)
- {
- if (task.State == 2)
- {
- if (task.PlanStartDate < DateTime.Now && DateTime.Now < task.StartTime1)
- {
- task.State = 0;
- if (!taskBLL.Update(task))
- return Error($"更新自动外呼任务状态为0=待处理失败,ID={task.TaskID},Name={task.TaskName}");
- log.Info($"更新自动外呼任务状态为0=待处理成功,ID={task.TaskID},Name={task.TaskName}");
- }
- }
- if (task.State == 0)
- {
- if ((DateTime.Now >= task.StartTime1 && DateTime.Now < task.EndTime1) || (DateTime.Now > task.StartTime2 && DateTime.Now < task.EndTime2))
- {
- task.State = 1;
- if (!taskBLL.Update(task))
- return Error($"更新自动外呼任务状态为1=处理中失败,ID={task.TaskID},Name={task.TaskName}");
- log.Info($"更新自动外呼任务状态为1=处理中成功,ID={task.TaskID},Name={task.TaskName}");
- }
- }
- if (task.State == 1)
- {
- if (task.PlanEndDate < DateTime.Now)
- {
- task.State = 0;
- if (!taskBLL.Update(task))
- return Error($"更新自动外呼任务状态为2=暂停失败,ID={task.TaskID},Name={task.TaskName}");
- log.Info($"更新自动外呼任务状态为2=暂停成功,ID={task.TaskID},Name={task.TaskName}");
- }
- }
- }
- }
- return Success("处理完成");
- }
- /// <summary>
- /// 获取号码
- /// </summary>
- /// <param name="id"></param>
- /// <param name="pageSize"></param>
- /// <param name="pageIndex"></param>
- /// <returns></returns>
- public ActionResult GetPhoneList(FilterCallPhone filter)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- var model = taskBLL.GetModel(filter.Id);
- if (model == null)
- return Error("外呼任务不存在");
- var sql = "";
- if (filter.UserId > 0)
- {
- sql += $" and F_UserId={filter.UserId} ";
- }
- if (!string.IsNullOrWhiteSpace(filter.Phone))
- {
- sql += $" and F_Phone like '%{filter.Phone}%'";
- }
- if (filter.FPState > -1)
- {
- sql += $" and F_FPState={filter.FPState} ";
- }
- if (filter.HCState > -1)
- {
- sql += $" and F_HCState={filter.HCState} ";
- }
- if (filter.YJState > -1)
- {
- sql += $" and F_YJState={filter.YJState} ";
- }
- var field = "F_Id,t.TaskName,F_Phone,F_FPState,F_HCState,F_YJState,F_Username,tn.F_CreateTime";
- if (filter.TaskType == 2)
- {
- field += " F_Phone,F_HCState,F_YJState";
- }
- var recordCount = 0;
- var dt = BLL.PagerBLL.GetListPager(
- " T_Call_TaskTelNum tn left join T_CTI_Task t on t.TaskID=tn.F_TaskId ",
- " F_Id ",
- field,
- " and F_TaskId=" + filter.Id + sql,
- "ORDER BY F_Id desc",
- filter.PageSize,
- filter.PageIndex,
- true,
- out recordCount);
- List<Model.T_Call_TaskTelNum> modelList = new BLL.T_Call_TaskTelNum().DataTableToListForShow(dt);
- var obj = new
- {
- rows = modelList.Select(x => new
- {
- taskname = x.TaskName,
- phone = x.F_Phone,
- agent = string.IsNullOrWhiteSpace(x.F_UserName) ? "" : x.F_UserName,
- isallot = x.F_FPState == null ? "" : (x.F_FPState > 0 ? "已分配" : "未分配"),
- iscalled = x.F_HCState > 0 ? "已呼叫" : "未呼叫",
- isconnected = x.F_YJState > 0 ? "已接通" : "未接通",
- createtime = Convert.ToDateTime(x.F_CreateTime).ToString("yyyy-MM-dd HH:mm:ss")
- }),
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 获取分配给当前登录坐席的号码
- /// </summary>
- /// <param name="filter"></param>
- /// <returns></returns>
- public ActionResult GetMyPhoneList(FilterCallPhone filter)
- {
- if (!Request.IsAuthenticated)
- return NoToken("未知错误,请重新登录");
- var sql = "";
- if (filter.Id > 0)
- {
- var model = taskBLL.GetModel(filter.Id);
- sql += " and F_TaskId=" + filter.Id;
- if (model == null)
- return Error("外呼任务不存在");
- }
- sql += $" and F_UserId={CurrentUser.UserData.F_UserId} ";
- if (!string.IsNullOrWhiteSpace(filter.Phone))
- {
- sql += $" and F_Phone like '%{filter.Phone}%'";
- }
- if (filter.FPState > -1)
- {
- sql += $" and F_FPState={filter.FPState} ";
- }
- if (filter.HCState > -1)
- {
- sql += $" and F_HCState={filter.HCState} ";
- }
- if (filter.YJState > -1)
- {
- sql += $" and F_YJState={filter.YJState} ";
- }
- var field = "F_Id,t.TaskName,F_Phone,F_FPState,F_HCState,F_YJState,F_Username,tn.F_CreateTime";
- if (filter.TaskType == 2)
- {
- field += " F_Phone,F_HCState,F_YJState";
- }
- var recordCount = 0;
- var dt = BLL.PagerBLL.GetListPager(
- " T_Call_TaskTelNum tn left join T_CTI_Task t on t.TaskID=tn.F_TaskId ",
- " F_Id ",
- field,
- sql,
- "ORDER BY F_Id desc",
- filter.PageSize,
- filter.PageIndex,
- true,
- out recordCount);
- List<Model.T_Call_TaskTelNum> modelList = new BLL.T_Call_TaskTelNum().DataTableToListForShow(dt);
- var obj = new
- {
- rows = modelList.Select(x => new
- {
- id = x.F_Id,
- taskname = x.TaskName,
- phone = x.F_Phone,
- agent = string.IsNullOrWhiteSpace(x.F_UserName) ? "" : x.F_UserName,
- isallot = x.F_FPState == null ? "" : (x.F_FPState > 0 ? "已分配" : "未分配"),
- iscalled = x.F_HCState > 0 ? "已呼叫" : "未呼叫",
- isconnected = x.F_YJState > 0 ? "已接通" : "未接通",
- createtime = Convert.ToDateTime(x.F_CreateTime).ToString("yyyy-MM-dd HH:mm:ss")
- }),
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 坐席自主获取号码(点击外呼分配号码)
- /// </summary>
- /// <param name="id">外呼任务ID</param>
- /// <param name="userId">坐席ID</param>
- /// <returns></returns>
- public ActionResult AllotPhoneList(int id, int count)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- if (count <= 0)
- return Error("参数错误");
- if (id <= 0)
- return Error("请选择外呼任务");
- var model = taskBLL.GetModel(id);
- if (model == null)
- return Error("外呼任务不存在");
- 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 ");
- var sum = obj == null ? 0 : Convert.ToInt32(obj);
- if (sum >= 50)
- return Error("请先完成已分配任务");
- 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)");
- if (res > 0)
- return Success($"获取到{res}条可用号码");
- return Error("未获取到可用号码");
- }
- public ActionResult GetMyCallPlan()
- {
- var taskList = taskBLL.DataTableToList(taskBLL.GetList("state=1").Tables[0]);
- return Success("获取成功", taskList.Select(x => new
- {
- id = x.TaskID,
- name = x.TaskName
- }));
- }
- public ActionResult GetCallNumDetail(int id)
- {
- var taskId = DbHelperSQL.GetSingle($"SELECT F_TaskId FROM T_Call_TaskTelNum WHERE F_ID={id}");
- if (taskId == null || Convert.ToInt32(taskId) <= 0)
- return Error("参数错误");
- var fieldList = pageFieldBLL.DataTableToList(pageFieldBLL.GetList($"F_TaskId={taskId}").Tables[0]);
- StringBuilder sb = new StringBuilder();
- Dictionary<string, string> dicTitle = new Dictionary<string, string>();
- foreach (var item in fieldList)
- {
- sb.Append(item.F_DBFieldlName + ",");
- dicTitle.Add(item.F_DBFieldlName, item.F_Name);
- }
- if (!string.IsNullOrWhiteSpace(sb.ToString()))
- {
- var callNum = DbHelperSQL.Query($"SELECT {sb.ToString().Trim(',')} FROM T_Call_TaskTelNum WHERE F_ID={id}").Tables[0];
- Dictionary<string, string> dic = new Dictionary<string, string>();
- for (int j = 0; j < callNum.Columns.Count; j++)
- {
- dic.Add(callNum.Columns[j].ColumnName, callNum.Rows[0][j].ToString());
- }
- return Success("获取成功", dic.Select(x => new
- {
- field = x.Key,
- text = dicTitle[x.Key],
- value = x.Value
- }));
- }
- return Success("");
- }
- #endregion
- #region 导入导出号码
- /// <summary>
- /// 导入号码信息
- /// </summary>
- /// <param name="type">导入方式:1=Excel; 2=txt .......</param>
- /// <returns></returns>
- public ActionResult ImportData(ImportDataInput input)
- {
- if (Request.Files.Count <= 0)
- return Error("请正确上传Excel文件");
- var file = Request.Files[0];
- if (!file.ContentType.Equals("application/vnd.ms-excel") && !file.ContentType.Equals("application/x-xls"))
- return Error("请正确上传Excel文件");
- var filePath = "";
- NPOIHelper npoi = new NPOIHelper();
- var dt = npoi.ExcelToTable(file, 0, out filePath);
- var obj = dt.AsEnumerable().Take(10).CopyToDataTable();
- var colCount = obj.Columns.Count;
- var rowCount = obj.Rows.Count;
- string[] headArr = new string[colCount];
- for (int i = 0; i < colCount; i++)
- {
- headArr[i] = obj.Columns[i].ToString();
- }
- string[][] itemArr = new string[rowCount][];
- itemArr[0] = new string[rowCount];
- for (int i = 0; i < rowCount; i++)
- {
- var row = obj.Rows[i];
- var itemArray = row.ItemArray;
- itemArr[i] = new string[itemArray.Count()];
- for (int j = 0; j < itemArray.Count(); j++)
- {
- itemArr[i][j] = itemArray[j].ToString();
- }
- }
- return Success("上传成功", new
- {
- filepath = filePath,
- heads = headArr,
- items = itemArr
- });
- }
- /// <summary>
- /// 导出号码信息
- /// </summary>
- /// <returns></returns>
- public ActionResult ExportData(long taskId, int type = 0)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- NPOIHelper npoi = new NPOIHelper();
- var task = taskBLL.GetModel(taskId);
- if (task == null)
- return Error("该外呼任务不存在");
- switch (type)
- {
- case 1:
- var dt1 = taskTellNumBLL.GetPhoneList(" F_TaskId=" + task.TaskID + " and F_HCState=1 and (F_YJState=0 or F_YJState is null) ").Tables[0];
- var msg1 = npoi.ExportToExcel(DateTime.Now.ToString("yyyyMMdd") + task.TaskName + "导出未接通号码", dt1);
- return !string.IsNullOrWhiteSpace(msg1) ? Error(msg1) : Success("导出成功");
- case 2:
- var dt2 = taskTellNumBLL.GetPhoneList(" F_TaskId=" + task.TaskID + " and F_HCState=1 and F_YJState=1 ").Tables[0];
- var msg2 = npoi.ExportToExcel(DateTime.Now.ToString("yyyyMMdd") + task.TaskName + "导出已接通号码", dt2);
- return !string.IsNullOrWhiteSpace(msg2) ? Error(msg2) : Success("导出成功");
- }
- return Error("参数错误");
- }
- #endregion
- #region 自动放音
- /// <summary>
- /// 获取自动放音文件
- /// </summary>
- /// <returns></returns>
- public ActionResult GetRecordDropList()
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- var list = taskRecordBLL.DataTableToList(taskRecordBLL.GetList("").Tables[0]).Select(x => new
- {
- id = x.Id,
- name = x.Name,
- });
- return Success("成功", list.ToList());
- }
- /// <summary>
- /// 获取自动放音文件
- /// </summary>
- /// <returns></returns>
- public ActionResult GetRecordList(FilterTalkRecord filter)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- var recordCount = 0;
- var dt = BLL.PagerBLL.GetListPager(
- "T_CTI_TaskRecord ",
- "id",
- "*",
- "",
- "ORDER BY id desc",
- filter.PageSize,
- filter.PageIndex,
- true,
- out recordCount);
- var list = taskRecordBLL.DataTableToList(dt).Select(x => new
- {
- id = x.Id,
- name = x.Name,
- recordpath = x.RecordPath,
- recordtime = x.RecordTime,
- });
- var obj = new
- {
- rows = list,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 获取录音
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public ActionResult GetRecord(int id)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- var x = taskRecordBLL.GetModel(id);
- return Success("成功", new
- {
- id = x.Id,
- name = x.Name,
- recordpath = x.RecordPath,
- recordtime = x.RecordTime,
- remark = x.Remark
- });
- }
- /// <summary>
- /// 添加/更新自动放音
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public ActionResult CreateOrUpdateRecord(Model.T_CTI_TaskRecord input)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- Model.T_CTI_TaskRecord model = new Model.T_CTI_TaskRecord();
- if (input.Id <= 0)
- {
- var dir = Server.MapPath("~/UploadRecord/");
- if (!Directory.Exists(dir))
- {
- Directory.CreateDirectory(dir);
- }
- var file = Request.Files[0];
- if (file.ContentType != "audio/x-wav" && file.ContentType != "audio/wav")
- return Error("上传录音格式必须为.wav");
- var name = DateTime.Now.ToString("yyyyMMddHHmmss") + Guid.NewGuid().ToString("N").Substring(0, 10) + ".wav";
- var path = dir + name;
- Request.Files[0].SaveAs(path);
- FileInfo fileInfo = new FileInfo(path);
- var fileName = FileUp.UploadFile(fileInfo, "/", "120.194.141.197", "Administrator", "hykj@800100");
- var sysConfig = systemConfigBLL.GetModel(40);
- if (sysConfig == null)
- return Error("自动放音录音路径查询失败");
- model.Name = input.Name;
- model.RecordPath = sysConfig.F_ParamValue + fileName;
- //model.RecordTime = input.RecordTime;
- model.Remark = input.Remark;
- if (taskRecordBLL.Add(model) > 0)
- return Success("添加成功");
- return Error("添加失败");
- }
- return Success("添加失败");
- }
- #endregion
- #region 话单查询
- /// <summary>
- /// 话务分析
- /// </summary>
- /// <returns></returns>
- public ActionResult GetTalkAnalysis(DateTime? start, DateTime? end)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- //var where = "";
- //if (start != null && end != null)
- //{
- // where += " PlanStartDate<'" + start.ToString() + "' and PlanEndDate>";
- //}
- var fir = taskPhonePartBLL.DataTableToList(taskPhonePartBLL.GetList("").Tables[0]);
- var sec = taskDailyBLL.DataTableToList(taskDailyBLL.GetList("").Tables[0]);
- var thi = taskDailyBLL.DataTableToList(taskDailyBLL.GetList().Tables[0]);
- var obj = new
- {
- fir = fir.Select(x => new
- {
- date = x.Date.ToString("yyyy-MM-dd"),
- phonepart = x.PhonePart,
- province = x.Province,
- city = x.City,
- connectedcount = x.CalledCount == 0 ? "" : (x.ConnectedCount / x.CalledCount * 100).ToString("f2") + "%",
- connectedagentcount = x.ConnectedCount == 0 ? "" : (x.ConnectedAgentCount / x.ConnectedCount * 100).ToString("f2") + "%",
- }),
- sec = sec.Select(x => new
- {
- date = x.Date.ToString("yyyy-MM-dd"),
- allcount = x.AllCount,
- calledcount = x.CalledCount,
- connectedcount = x.ConnectedCount,
- connectedagentcount = x.ConnectedAgentCount,
- connectedrate = x.CalledCount == 0 ? "" : (x.ConnectedCount / x.CalledCount * 100).ToString("f2") + "%",
- connectedagentrate = x.ConnectedCount == 0 ? "" : (x.ConnectedAgentCount / x.ConnectedCount * 100).ToString("f2") + "%",
- taskid = x.TaskId,
- taskname = x.TaskName
- }),
- thi = thi.Select(x => new
- {
- date = x.Date.ToString("yyyy-MM-dd"),
- allcount = x.AllCount,
- calledcount = x.CalledCount,
- connectedcount = x.ConnectedCount,
- connectedagentcount = x.ConnectedAgentCount,
- connectedrate = x.CalledCount == 0 ? "" : (x.ConnectedCount / x.CalledCount * 100).ToString("f2") + "%",
- connectedagentrate = x.ConnectedCount == 0 ? "" : (x.ConnectedAgentCount / x.ConnectedCount * 100).ToString("f2") + "%",
- taskid = x.TaskId,
- taskname = x.TaskName
- })
- };
- return Success("", obj);
- }
- /// <summary>
- /// 获取通话记录列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetTalkRecords(FilterTalkRecord filter)
- {
- //if (!Request.IsAuthenticated)
- // return NoToken("未知错误,请重新登录");
- var sort = "ORDER BY startdate desc";
- if (!string.IsNullOrWhiteSpace(filter.SortField))
- {
- var arr = filter.SortField.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- EnumTalkRecordsSortField e;
- if (!Enum.TryParse(arr[0], out e))
- return Error("排序字段参数错误");
- sort = "ORDER BY " + e.ToString() + " " + arr[1];
- }
- StringBuilder where = new StringBuilder();
- if (!string.IsNullOrWhiteSpace(filter.UserCode))
- {
- where.Append(" and agentid=" + filter.UserCode);
- }
- if (!string.IsNullOrWhiteSpace(filter.Phone))
- {
- where.Append(" and callee like '%" + filter.Phone + "%'");
- }
- if (filter.CallType != 0)
- {
- where.Append(" and calltype=" + filter.CallType);
- }
- if (!string.IsNullOrWhiteSpace(filter.TalkTime))
- {
- var arr = filter.TalkTime.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- if (arr.Length == 2)
- {
- if (arr[0] == "1")
- {
- where.Append(" and talktime>" + arr[1]);
- }
- else if (arr[0] == "2")
- {
- where.Append(" and talktime=" + arr[1]);
- }
- else if (arr[0] == "3")
- {
- where.Append(" and talktime<" + arr[1]);
- }
- else { }
- }
- }
- if (filter.StartTime == null || filter.EndTime == null)
- {
- filter.StartTime = DateTime.Now.AddDays(-3);
- filter.EndTime = DateTime.Now;
- }
- where.Append(" and datediff(s,'" + filter.StartTime + "',getdate())>=0 and datediff(s,getdate(),'" + filter.EndTime + "')>=0 ");
- // 全部=0
- // 未接通=1
- // 接通排队=2
- // 接通未转入坐席=3
- // 接通且分配坐席=4
- int recordCount = 0;
- Model.PageData<Model.CallResult> pageModel = new Model.PageData<Model.CallResult>();
- StringBuilder fields = new StringBuilder();
- var dt = BLL.PagerBLL.GetListPager(
- "V_AutoCallResult",
- "V_AutoCallResult.id",
- "V_AutoCallResult.id,itemid, callee, agentid, username,startdate,enddate,getinagentdate,calltype,talktime,RecordPath",
- where.ToString(),
- sort,
- filter.PageSize,
- filter.PageIndex,
- true,
- out recordCount);
- var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
- var callResultList = callResultBLL.DataTableToList(dt);
- var list = new List<AutoCallRecordDto>();
- callResultList.ForEach(x =>
- {
- var recordPath = "";
- if (!string.IsNullOrWhiteSpace(x.RecordPath) && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
- {
- var ym = config.F_ParamValue;
- if (ym.Substring(ym.Length - 1) == "/")
- {
- ym = ym.Substring(0, ym.Length - 1);
- }
- recordPath = ym + x.RecordPath.Substring(x.RecordPath.IndexOf(':') + 1).Replace('\\', '/');
- }
- list.Add(new AutoCallRecordDto
- {
- id = x.Id,
- taskid = x.TaskId,
- callnumber = x.CallNumber,
- usercode = x.Usercode == "0" ? "" : x.Usercode,
- startdate = x.StartDate?.ToString("yyyy-MM-dd HH:mm:ss") ?? "",
- getinagentdate = x.GetInAgentDate?.ToString("yyyy-MM-dd HH:mm:ss") ?? "",
- enddate = x.EndDate?.ToString("yyyy-MM-dd HH:mm:ss") ?? "",
- recordpath = recordPath,
- username = x.Username,
- state = x.State,
- talktime = x.TalkTime > 0 ? x.TalkTime.ToString() : ""
- });
- });
- var obj = new
- {
- rows = list,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- #endregion
- #region 过滤号码
- #region 过滤号码-数据源
- /// <summary>
- /// 过滤号码
- /// </summary>
- /// <param name="dt"></param>
- private DataTable PhoneNumFilter(DataTable dt)
- {
- var dtClone = dt.Copy();
- foreach (DataRow row in dtClone.Rows)
- {
- var rows = dt.Select("[F_Phone]='" + row["F_Phone"] + "'");
- if (rows.Length > 1)
- {
- for (int num = 0; num < rows.Count() - 1; num++)
- {
- dt.Rows.Remove(rows[num]);
- }
- }
- }
- return dt;
- }
- #endregion
- #region 过滤号码-前三个月
- private DataTable PhoneNumFilterMonth(DataTable dt, string phone = "F_Phone")
- {
- var taskTelNumDt = taskTellNumBLL.GetList(" datediff(mm,F_CreateTime,getdate())<=3 ").Tables[0];
- foreach (DataRow row in taskTelNumDt.Rows)
- {
- var rows = dt.Select("[" + phone + "]='" + row["F_Phone"] + "'");
- if (rows.Length > 1)
- {
- for (int num = 0; num < rows.Count() - 1; num++)
- {
- dt.Rows.Remove(rows[num]);
- }
- }
- }
- return dt;
- }
- #endregion
- #endregion
- }
- }
|