using Core.Web.App_Start; using Core.Web.WebHelper; using CRM.Core.BLL.Application.SoftProduct; using CRM.Core.BLL.Csvr; using CRM.Core.BLL.Util; using CRM.Core.Common; using CRM.Core.Common.Layui; using CRM.Core.Common.WebHelper; using CRM.Core.Model.Entity; using CRM.Core.Model.Enum; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using WX.CRM.Common; using WX.CRM.WebHelper; namespace Core.Web.Controllers { public class AiRecordController : BaseController { private Csvr_AiCallTask_BL _task = new Csvr_AiCallTask_BL(); private CACHE_BL cache_BL = new CACHE_BL(); private WX.CRM.Common.ValidationErrors errors = new WX.CRM.Common.ValidationErrors(); private readonly SoftProductService _softProductService = new SoftProductService(); public AiRecordController() { } [AuthorizeRedirect(RightsConfig.CONST_自动外呼日志, ToolBarConfig.CONST_NotButton, true)] [HttpGet] public ActionResult Index(int type = -1, string robotId = "") { ViewBag.rightCode = RightsConfig.CONST_自动外呼日志; List containState = new List() { (int) EnumAiCallState.AI外呼成功, (int) EnumAiCallState.AI外呼失败未答完, (int) EnumAiCallState.AI外呼未接通, (int) EnumAiCallState.AI外呼失败挂断, }; List aiCallType = new List(); var dicType = cache_BL.GetAiStatus(1).Select(n => new SelectListItem { Text = n.Text, Value = n.Value.ToString() }).ToList(); foreach (var item in dicType) { if (containState.Contains(Convert.ToInt32(item.Value.ToString()))) { aiCallType.Add(new SelectListItem { Text = item.Text, Value = item.Value }); } } List robotSelect = new List(); var robotList = cache_BL.GetAiRobotList(); foreach (var item in robotList) { robotSelect.Add(new SelectListItem { Text = item.RobotName, Value = item.Robot }); } ViewBag.robotList = robotSelect; ViewBag.aiCallType = aiCallType; ViewBag.companyList = cache_BL.GetCompanyVirtual(); ViewBag.type = type; ViewBag.robotId = robotId; return View(); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_自动外呼日志, ToolBarConfig.CONST_NotButton, false)] public JsonResult Index(Laypage pager, string columns, AiRecordQueryDto dto) { try { var list = _task.GetList(ref pager, dto); list.ForEach(l => l.sid = AESHelper.encyptData(l.Id.ToString(), "UPWEBSITE")); var data = new LayuiData() { msg = "数据加载成功!", count = pager.count, code = 0, data = list }; return Json(data, JsonRequestBehavior.AllowGet); } catch (Exception ex) { CRM.Core.Common.LogHelper.Error(ex.ToString()); return Json(new { }, JsonRequestBehavior.AllowGet); } } [AuthorizeRedirect(RightsConfig.CONST_自动外呼明细, ToolBarConfig.CONST_NotButton, true)] [HttpGet] public ActionResult RecordDetail(int type = 2, string robotId = "") { ViewBag.rightCode = RightsConfig.CONST_自动外呼明细; List aiCallType = new List(); var dicType = cache_BL.GetAiStatus(1).Select(n => new SelectListItem { Text = n.Text, Value = n.Value.ToString() }).ToList(); foreach (var item in dicType) { aiCallType.Add(new SelectListItem { Text = item.Text, Value = item.Value }); } var robotList = cache_BL.GetAiRobotList(); List robotSelect = new List(); foreach(var item in robotList) { robotSelect.Add(new SelectListItem {Text = item.RobotName,Value = item.Robot }); } ViewBag.robotList = robotSelect; ViewBag.aiCallType = aiCallType; ViewBag.companyList = cache_BL.GetCompanyVirtual(); ViewBag.type = type; ViewBag.robotId = robotId; return View(); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_自动外呼明细, ToolBarConfig.CONST_NotButton, false)] public JsonResult RecordDetail(Laypage pager, string columns, AiRecordQueryDto dto) { try { var list = _task.GetList(ref pager, dto); list.ForEach(l => l.sid = AESHelper.encyptData(l.Id.ToString(), "UPWEBSITE")); var data = new LayuiData() { msg = "数据加载成功!", count = pager.count, code = 0, data = list }; return Json(data, JsonRequestBehavior.AllowGet); } catch (Exception ex) { CRM.Core.Common.LogHelper.Error(ex.ToString()); return Json(new { }, JsonRequestBehavior.AllowGet); } } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_自动外呼日志, ToolBarConfig.CONST_NotButton, false)] public FileResult ExportData(string Channel, string resId, decimal? orderId, string cname, int aistatus,int hasCall,DateTime? xstime, DateTime? xetime,string robot,int type = 0) { Laypage pager = new Laypage { limit = 100000, page = 1 }; AiRecordQueryDto dto = new AiRecordQueryDto { channel = Channel , resId = resId, orderId = orderId, cname = cname, aistatus = aistatus, hasCall = hasCall, xstime = xstime, xetime = xetime, robot = robot, type = type }; var list = _task.GetList(ref pager, dto); if(type == -1) { List res = new List(); foreach (var item in list) { res.Add(new AiCallTaskExportView { RobotName = item.RobotName, Id = item.Id, Remark = item.Remark, RESID = item.RESID, CallNo = item.CallNo, CNAME = item.CNAME, AiStatusName = item.AiStatusName, StartTime = item.StartTime, EndTime = item.EndTime, Audio = item.Audio, SvcTime = item.SvcTime, ORDERID = item.ORDERID, CHANNELNAME = item.CHANNELNAME, HasCallName = item.HasCallName, Rounds = item.Rounds }); } String file = string.Format("AiCallTaskExport{0}.xls", DateTime.Now.ToLocalTime().ToString("yyyyMMddHHmmssfffff")); return File(ExcelHelper.ExportListModelToExcel(res, "AiCallTask", 30000, null), "application/ms-excel", file); } else { List res = new List(); foreach (var item in list) { res.Add(new AiCallTaskDetailExportView { RESID = item.RESID, CallNo = item.CallNo, CNAME = item.CNAME, AiStatusName = item.AiStatusName, StartTime = item.StartTime, Id = item.Id, EndTime = item.EndTime, Audio = item.Audio, SvcTime = item.SvcTime, ORDERID = item.ORDERID, CHANNELNAME = item.CHANNELNAME, HasCallName = item.HasCallName, Rounds = item.Rounds }); } String file = string.Format("AiCallTaskExport{0}.xls", DateTime.Now.ToLocalTime().ToString("yyyyMMddHHmmssfffff")); return File(ExcelHelper.ExportListModelToExcel(res, "AiCallTaskDetail", 30000, null), "application/ms-excel", file); } } [AuthorizeRedirect(RightsConfig.CONST_自动外呼服务, ToolBarConfig.CONST_NotButton, true)] public ActionResult AiService() { ViewBag.rightCode = RightsConfig.CONST_自动外呼服务; ViewBag.companyList = cache_BL.GetCompanyVirtual(); var robotList = cache_BL.GetAiRobotList(); List robotSelect = new List(); foreach (var item in robotList) { robotSelect.Add(new SelectListItem { Text = item.RobotName, Value = item.Robot }); } ViewBag.robotList = robotSelect; return View(); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_自动外呼服务, ToolBarConfig.CONST_NotButton, false)] public JsonResult AiService(Laypage pager, AiRecordQueryDto dto) { try { var list = _task.GetAiRecordSum(ref pager, dto); var data = new LayuiData() { msg = "数据加载成功!", count = pager.count, code = 0, data = list }; return Json(data, JsonRequestBehavior.AllowGet); } catch (Exception ex) { CRM.Core.Common.LogHelper.Error(ex.ToString()); return Json(new { }, JsonRequestBehavior.AllowGet); } } [AuthorizeRedirect(RightsConfig.CONST_自动外呼服务, ToolBarConfig.CONST_Add, true)] public ActionResult AiServiceAdd() { return View(); } [AuthorizeRedirect(RightsConfig.CONST_自动外呼服务, ToolBarConfig.CONST_Edit, true)] public ActionResult AiServiceEdit() { var list = cache_BL.GetAICallTaskConfigList(); var model = list.FirstOrDefault(); var noContainChannel = model.IgnoreHitConfigs.Where(x => x.HitKey == "Channel").Select(x => x.NoContain).FirstOrDefault(); var allChannel = GetAllChannel(); var noContainSubproductid = model.IgnoreHitConfigs.Where(x => x.HitKey == "Subproductid").Select(x => x.NoContain).FirstOrDefault(); var serviceModel = new AiServiceModel { RobotName = model.RobotName, Remark = model.Remark, Channel = noContainChannel, Subproductid = string.Join(",", noContainSubproductid), Sms = model.Sms }; ViewBag.AllChannel = JsonHelper.ToJson(allChannel); ViewBag.ModelJson = JsonHelper.ToJson(serviceModel); return View(); } [AuthorizeRedirect(RightsConfig.CONST_自动外呼服务, ToolBarConfig.CONST_Edit, false)] public JsonResult EditSave(AiServiceModel model) { var list = cache_BL.GetAICallTaskConfigList(); var config = list.FirstOrDefault(); var noContainChannel = config.IgnoreHitConfigs.Where(x => x.HitKey == "Channel").FirstOrDefault(); var noContainSubproductid = config.IgnoreHitConfigs.Where(x => x.HitKey == "Subproductid").FirstOrDefault(); config.RobotName = model.RobotName; config.Remark = model.Remark; noContainChannel.NoContain = model.Channel.FirstOrDefault().Split(',').ToList(); noContainSubproductid.NoContain = string.IsNullOrEmpty(model.Subproductid) ? new List() : model.Subproductid.Split(',').ToList(); config.Sms = model.Sms; var result = cache_BL.UpdateAICallTaskConfigList(ref errors, list); return JsonResult(errors); } [AuthorizeRedirect(RightsConfig.CONST_自动外呼服务, ToolBarConfig.CONST_Edit, false)] public JsonResult EditSaveRule(AiServiceRuleModel model) { var list = cache_BL.GetAICallTaskConfigList(); var config = list.FirstOrDefault(); var noContainChannel = config.IgnoreHitConfigs.Where(x => x.HitKey == "Channel").FirstOrDefault(); var noContainSubproductid = config.IgnoreHitConfigs.Where(x => x.HitKey == "Subproductid").FirstOrDefault(); var reCallMins = new List(); for (var i = 1; model.ReCallCount > i; i++) { reCallMins.Add(model.ReCallMin); } config.ReCallMins = reCallMins; if (model.ReCall) { config.ReCallStatus.Add(7); } else { config.ReCallStatus.Remove(7); } config.HgrecordEtime = model.HgrecordEtime; config.HgrecordStime = model.HgrecordStime; var result = cache_BL.UpdateAICallTaskConfigList(ref errors, list); return JsonResult(errors); } [AuthorizeRedirect(RightsConfig.CONST_自动外呼服务, ToolBarConfig.CONST_NotButton, true)] public ActionResult AiServiceRule() { var list = cache_BL.GetAICallTaskConfigList(); var model = list.FirstOrDefault(); var hgrecordStime = DateTime.Parse(model.HgrecordStime).ToString("HH:mm:ss"); var hgrecordEtime = DateTime.Parse(model.HgrecordEtime).ToString("HH:mm:ss"); var serviceModel = new AiServiceRuleModel { ReCallCount = model.ReCallMins.Count + 1, ReCallMin = model.ReCallMins.FirstOrDefault(), ReCall = model.ReCallStatus.Any(x => x == 7), HgrecordEtime = hgrecordEtime, HgrecordStime = hgrecordStime }; ViewBag.ModelJson = JsonHelper.ToJson(serviceModel); return View(); } /// /// 获取channelItem /// /// /// private static ChannelItem GetChannelItem(string ChannelStr) { ChannelItem channelItem = new ChannelItem { Max = 0, Min = 0 }; try { int min = 0; int max = 0; var c = ChannelStr.Split('|'); int.TryParse(c[0], out min); int.TryParse(c[1], out max); channelItem.Max = max; channelItem.Min = min; } catch (Exception ex) { return channelItem; } return channelItem; } private List> GetAllChannel() { var list = new List>(); var channel = new Dictionary { { "name", "北京软件一中心" }, { "value", "2000|2199" } }; list.Add(channel); var channel2 = new Dictionary { { "name", "北京软件二中心" }, { "value", "2200|2399" } }; list.Add(channel2); var channel3 = new Dictionary { { "name", "东方平台运营中心" }, { "value", "25000|26199" } }; list.Add(channel3); var channel4 = new Dictionary { { "name", "新媒体一部" }, { "value", "26200|26299" } }; list.Add(channel4); var channel5 = new Dictionary { { "name", "投顾联邦事业部" }, { "value", "1100|1100" } }; list.Add(channel5); var channel6 = new Dictionary { { "name", "投顾联邦事业部" }, { "value", "26600|26699" } }; list.Add(channel6); var channel7 = new Dictionary { { "name", "投顾联邦事业部" }, { "value", "26700|26799" } }; list.Add(channel7); var channel8 = new Dictionary { { "name", "呱呱平台运营中心" }, { "value", "26800|26899" } }; list.Add(channel8); var channel9 = new Dictionary { { "name", "投顾联邦事业部" }, { "value", "26900|26999" } }; list.Add(channel9); var channel10 = new Dictionary { { "name", "软件业务三中心" }, { "value", "1000|1099" } }; list.Add(channel10); var channel11 = new Dictionary { { "name", "东方软件一中心" }, { "value", "2500|2599" } }; list.Add(channel11); var channel12 = new Dictionary { { "name", "东方软件一中心" }, { "value", "3000|3099" } }; list.Add(channel12); var channel13 = new Dictionary { { "name", "首华平台运营中心" }, { "value", "27100|27199" } }; list.Add(channel13); var channel14 = new Dictionary { { "name", "新媒体四部" }, { "value", "27200|27299" } }; list.Add(channel14); var channel15 = new Dictionary { { "name", "东方软件三中心" }, { "value", "4000|4999" } }; list.Add(channel15); var channel16 = new Dictionary { { "name", "东方软件二中心" }, { "value", "5000|5999" } }; list.Add(channel16); var channel17 = new Dictionary { { "name", "六合软件一中心" }, { "value", "7000|7299" } }; list.Add(channel17); var channel18 = new Dictionary { { "name", "六合软件二中心" }, { "value", "7300|7599" } }; list.Add(channel18); var channel19 = new Dictionary { { "name", "新媒体运营二中心" }, { "value", "7600|7999" } }; list.Add(channel19); var channel20 = new Dictionary { { "name", "新媒体一部" }, { "value", "28000|28999" } }; list.Add(channel20); var channel21 = new Dictionary { { "name", "通联" }, { "value", "3900|3999" } }; list.Add(channel21); return list; } } public class AiServiceModel { public string RobotName { get; set; } public string Remark { get; set; } public List Channel { get; set; } public string Subproductid { get; set; } public int Sms { get; set; } } public class AiServiceRuleModel { /// /// 重拨次数 /// public int ReCallCount { get; set; } /// /// 重拨时间间隔 /// public int ReCallMin { get; set; } /// /// 外呼挂断是否启动外呼 /// public bool ReCall { get; set; } /// /// 允许外拨时间段 /// public string HgrecordStime { get; set; } /// /// 允许外拨时间段 /// public string HgrecordEtime { get; set; } } }