足力健后端,使用.netcore版本,合并1个项目使用

CallFunctionController.cs 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Common;
  4. using System.IRepositories;
  5. using System.IRepositories.Call;
  6. using System.IRepositories.Sys;
  7. using System.Linq;
  8. using System.Model;
  9. using System.Model.Call;
  10. using System.Model.Sys;
  11. using System.Security.Claims;
  12. using System.Threading.Tasks;
  13. using System.Utility;
  14. using Microsoft.AspNetCore.Authorization;
  15. using Microsoft.AspNetCore.Mvc;
  16. using Microsoft.Extensions.Configuration;
  17. using SqlSugar;
  18. using Utility;
  19. namespace TVShoppingCallCenter_ZLJ.Controllers.CallCenter
  20. {
  21. /// <summary>
  22. /// 呼叫中心关联方法
  23. /// </summary>
  24. [Authorize]
  25. [Produces("application/json")]
  26. [Route("api/[controller]")]
  27. public class CallFunctionController : BaseController
  28. {
  29. private readonly IConfiguration config;
  30. private readonly ISys_MobileDataRepository busMobileDataRepository;
  31. private readonly ICall_CallRecordsRepository busCallRecordsRepository;
  32. private readonly ICall_CallOutboundRepository CallOutboundRecordsRepository;
  33. private readonly ICDRRepository busCdrRepository;
  34. private readonly Iauto_cdrRepository auto_cdrRepository;
  35. private readonly ItaskRepository taskRepository;
  36. private readonly ISys_AutoDialRepository sys_autodialrepository;
  37. private readonly ISys_SystemConfigRepository busSystemConfigRepository;
  38. private readonly ICus_VipInfoRepository _cus_vip_infoRepository;//客户
  39. private readonly Ipoint_agentRepository _point_agentrepository;
  40. public CallFunctionController(ISys_SystemConfigRepository _busSystemConfigRepository,ICDRRepository _busCdrRepository,ICall_CallRecordsRepository _busCallRecordsRepository,IConfiguration _configuration, ISys_MobileDataRepository _busMobileDataRepository, ICus_VipInfoRepository cus_vip_infoRepository,
  41. ICall_CallOutboundRepository _CallOutboundRecordsRepository, Iauto_cdrRepository _auto_cdrRepository
  42. , ItaskRepository _taskRepository, ISys_AutoDialRepository _sys_autodialrepository,
  43. Ipoint_agentRepository point_agentrepository)
  44. {
  45. busSystemConfigRepository = _busSystemConfigRepository;
  46. busCdrRepository = _busCdrRepository;
  47. busCallRecordsRepository = _busCallRecordsRepository;
  48. config = _configuration;
  49. busMobileDataRepository = _busMobileDataRepository;
  50. _cus_vip_infoRepository = cus_vip_infoRepository;
  51. CallOutboundRecordsRepository = _CallOutboundRecordsRepository;
  52. auto_cdrRepository = _auto_cdrRepository;
  53. taskRepository = _taskRepository;
  54. sys_autodialrepository = _sys_autodialrepository;
  55. _point_agentrepository = point_agentrepository;
  56. }
  57. /// <summary>
  58. /// 电话归属地查询
  59. /// </summary>
  60. /// <param name="tel"></param>
  61. /// <returns></returns>
  62. [HttpPost("GetTelLocation")]
  63. public async Task<IActionResult> GetTelLocation(string tel, int type = 0)
  64. {
  65. string location = await GetLocationFunc(tel, type);
  66. return Success("归属地加载成功", location);
  67. }
  68. /// <summary>
  69. /// 获取电话归属地
  70. /// </summary>
  71. /// <param name="tel"></param>
  72. /// <param name="type"></param>
  73. /// <returns></returns>
  74. [NonAction]
  75. internal async Task<string> GetLocationFunc(string tel, int type = 0)
  76. {
  77. string location = "未知";
  78. if (tel.Trim().Length == 11 && tel.Substring(0, 1) != "0")
  79. {
  80. T_Sys_MobileData mobile_Bll = new T_Sys_MobileData();
  81. T_Sys_MobileData mobileModel = await busMobileDataRepository.GetFirst(q => q.F_MobileNum == tel.Substring(0, 7));
  82. if (mobileModel != null)
  83. {
  84. location = mobileModel.F_CityDes;
  85. if (type == 0)
  86. {
  87. location += mobileModel.F_CardDes;
  88. }
  89. }
  90. }
  91. else
  92. {
  93. T_Sys_MobileData mobile_Bll = new T_Sys_MobileData();
  94. T_Sys_MobileData mobileModel = await busMobileDataRepository.GetFirst(q => q.F_ZipCode == tel.Substring(0, 4));
  95. if (mobileModel == null)
  96. {
  97. mobileModel = await busMobileDataRepository.GetFirst(q => q.F_ZipCode == tel.Substring(0, 3));
  98. }
  99. if (mobileModel != null)
  100. {
  101. location = mobileModel.F_CityDes;
  102. if (type == 0)
  103. {
  104. location += mobileModel.F_CardDes;
  105. }
  106. }
  107. }
  108. return location;
  109. }
  110. #region 同步通话记录
  111. /// <summary>
  112. /// 同步通话记录
  113. /// </summary>
  114. /// <returns></returns>
  115. [NonAction]
  116. internal async Task<string> SyncCallRecord()
  117. {
  118. DateTime dtime = DateTime.Now.AddYears(-10);
  119. int maxid = 0;
  120. T_Call_CallRecords modelCallRecord = await busCallRecordsRepository.GetFirst(q => q.CdrId > 0, o => new { o.CdrId }, OrderByType.Desc);
  121. if (modelCallRecord != null)
  122. {
  123. maxid = modelCallRecord.CdrId;
  124. }
  125. modelCallRecord = await busCallRecordsRepository.GetFirst(q => q.CdrId > 0, o => new { o.EndTime }, OrderByType.Desc);
  126. if (modelCallRecord != null)
  127. {
  128. if (modelCallRecord.EndTime != null)
  129. dtime = modelCallRecord.EndTime.GetValueOrDefault();
  130. }
  131. List<cdr> modellist = await busCdrRepository.GetListALL(q => q.id > maxid || q.end_time >= dtime);
  132. int totle = 0;
  133. int n = 0;
  134. int n1 = 0;
  135. if (modellist != null && modellist.Count > 0)
  136. {
  137. string url = "请配置videoURL/";
  138. T_Sys_SystemConfig model =await busSystemConfigRepository.GetSingle(q=>q.F_ParamCode== "videoURL");
  139. if (model != null)
  140. {
  141. url = model.F_ParamValue;
  142. }
  143. totle = modellist.Count;
  144. List<T_Call_CallRecords> modelRecordList = new List<T_Call_CallRecords>();
  145. foreach (cdr modelcdr in modellist)
  146. {
  147. T_Call_CallRecords modelRecord = new T_Call_CallRecords();
  148. modelRecord.ActionID = modelcdr.action_id;
  149. modelRecord.TalkStartTime = modelcdr.answer_time;
  150. modelRecord.Callee = modelcdr.callee;
  151. if (modelcdr.call_type==0)
  152. {
  153. string tel = modelcdr.caller.TrimStart('0');
  154. modelRecord.UserCode = modelcdr.callee_agent;
  155. var cus = await _cus_vip_infoRepository.GetListALL(x => x.F_State == 1 && x.F_Phone
  156. == modelcdr.caller || x.F_Phone
  157. == tel);
  158. if (cus!=null&&cus.Count >0 )
  159. {
  160. modelRecord.CusCode = cus.FirstOrDefault ().F_Name ;
  161. modelRecord.CusId = cus.FirstOrDefault().F_ID ;
  162. var point = await _point_agentrepository.GetListALL(x => x.agent == modelcdr.callee_agent);
  163. if (point==null && point.Count ()<=0)
  164. {
  165. point_agent point_Agent = new point_agent();
  166. point_Agent.caller = modelcdr.caller;
  167. point_Agent.agent = modelcdr.callee_agent;
  168. var res = _point_agentrepository.Add(point_Agent);
  169. }
  170. }
  171. }
  172. else
  173. {
  174. modelRecord.UserCode = modelcdr.caller_agent;
  175. string tel = modelcdr.callee.TrimStart('0');
  176. modelRecord.UserCode = modelcdr.callee_agent;
  177. var cus = await _cus_vip_infoRepository.GetListALL(x => x.F_State == 1 && x.F_Phone
  178. == modelcdr.caller || x.F_Phone
  179. == tel);
  180. if (cus != null && cus.Count > 0)
  181. {
  182. modelRecord.CusCode = cus.FirstOrDefault().F_Name;
  183. modelRecord.CusId = cus.FirstOrDefault().F_ID;
  184. }
  185. }
  186. modelRecord.Caller = modelcdr.caller;
  187. modelRecord.CallType = modelcdr.call_type;
  188. modelRecord.BeginTime = modelcdr.create_time;
  189. modelRecord.EndTime = modelcdr.end_time;
  190. modelRecord.CallState = modelcdr.is_answer;
  191. // modelcdr.hangup_cause;挂机原因不赋值 HangUpReason
  192. // modelcdr.leave_path 留言 赋值给了FilePath
  193. modelRecord.IvrEndTime = modelcdr.hangup_time;
  194. modelRecord.Id = modelcdr.id;
  195. modelRecord.MYD = modelcdr.myd;
  196. modelRecord.Remark = modelcdr.note;
  197. modelRecord.OperateType = modelcdr.op_type;
  198. modelRecord.FilePath = url+ modelcdr.record_path;
  199. if (string.IsNullOrEmpty(modelcdr.record_path) && !string.IsNullOrEmpty(modelcdr.leave_path))
  200. {
  201. modelRecord.FilePath = url+ modelcdr.leave_path;
  202. }
  203. modelRecord.RingStartTime = modelcdr.ring_time;
  204. modelRecord.RelayNumber = modelcdr.trunk_num;
  205. modelRecord.CallId = modelcdr.uuid;
  206. modelRecord.CdrId = modelcdr.id;
  207. modelRecord.Location = await GetLocationFunc(modelcdr.caller, 1);
  208. #region 计算时长
  209. modelRecord.LongTime = (int)DateTimeConvert.DateDiff(DateInterval.Second, modelcdr.create_time.GetValueOrDefault(), modelcdr.end_time.GetValueOrDefault());
  210. if (modelcdr.answer_time != null)
  211. modelRecord.TalkLongTime = (int)DateTimeConvert.DateDiff(DateInterval.Second, modelcdr.answer_time.GetValueOrDefault(), modelcdr.end_time.GetValueOrDefault());
  212. else
  213. modelRecord.TalkLongTime = 0;
  214. #endregion
  215. n++;
  216. n1++;
  217. modelRecordList.Add(modelRecord);
  218. if (n >= 2000)
  219. {
  220. await busCallRecordsRepository.AddAndUpdateList(modelRecordList);
  221. modelRecordList.Clear();
  222. n = 0;
  223. }
  224. }
  225. //T_Call_CallRecords modelreturn= await busCallRecordsRepository.AddAndUpdateList(modelRecordList,s=>new {s.EndTime,s.TalkEndTime,s.IvrEndTime });
  226. //T_Call_CallRecords modelreturn =
  227. await busCallRecordsRepository.AddAndUpdateList(modelRecordList);
  228. }
  229. return $"同步情况 成功/总数 = {n1}/{totle}";
  230. }
  231. /// <summary>
  232. /// 同步自动外呼通话记录
  233. /// </summary>
  234. /// <returns></returns>
  235. [NonAction]
  236. internal async Task<string> SyncOutbound()
  237. {
  238. DateTime dtime = DateTime.Now.AddYears(-10);
  239. int maxid = 0;
  240. T_Call_CallOutbound modelCallRecord = await CallOutboundRecordsRepository.GetFirst(q => q.CdrId > 0, o => new { o.CdrId }, OrderByType.Desc);
  241. if (modelCallRecord != null)
  242. {
  243. maxid = modelCallRecord.CdrId;
  244. }
  245. modelCallRecord = await CallOutboundRecordsRepository.GetFirst(q => q.CdrId > 0, o => new { o.EndTime }, OrderByType.Desc);
  246. if (modelCallRecord != null)
  247. {
  248. if (modelCallRecord.EndTime != null)
  249. dtime = modelCallRecord.EndTime.GetValueOrDefault();
  250. }
  251. List<auto_cdr > modellist = await auto_cdrRepository.GetListALL(q => q.id > maxid || q.end_time >= dtime);
  252. int totle = 0;
  253. int n = 0;
  254. int n1 = 0;
  255. if (modellist != null && modellist.Count > 0)
  256. {
  257. string url = "请配置videoURL/";
  258. T_Sys_SystemConfig model = await busSystemConfigRepository.GetSingle(q => q.F_ParamCode == "videoURL");
  259. if (model != null)
  260. {
  261. url = model.F_ParamValue;
  262. }
  263. totle = modellist.Count;
  264. List<T_Call_CallOutbound> modelRecordList = new List<T_Call_CallOutbound>();
  265. foreach (auto_cdr modelcdr in modellist)
  266. {
  267. T_Call_CallOutbound modelRecord = new T_Call_CallOutbound();
  268. modelRecord.ActionID =1;
  269. modelRecord.TalkStartTime = modelcdr.answer_time;
  270. modelRecord.Callee = modelcdr.callee;
  271. modelRecord.UserCode = modelcdr.agent ;
  272. string tel = modelcdr.callee.TrimStart('0');
  273. modelRecord.UserCode = modelcdr.agent;
  274. var cus = await _cus_vip_infoRepository.GetListALL(x => x.F_State == 1 && x.F_Phone
  275. == modelcdr.caller || x.F_Phone
  276. == tel);
  277. if (cus != null && cus.Count > 0)
  278. {
  279. modelRecord.CusCode = cus.FirstOrDefault().F_Name;
  280. modelRecord.CusId = cus.FirstOrDefault().F_ID;
  281. }
  282. modelRecord.Caller = modelcdr.caller;
  283. modelRecord.CallType = 1;
  284. modelRecord.BeginTime = modelcdr.create_time;
  285. modelRecord.EndTime = modelcdr.end_time;
  286. // modelcdr.hangup_cause;挂机原因不赋值 HangUpReason
  287. // modelcdr.leave_path 留言 赋值给了FilePath
  288. modelRecord.FilePath = url + modelcdr.record_path;
  289. if (string.IsNullOrEmpty(modelcdr.record_path))
  290. {
  291. modelRecord.FilePath = url + modelcdr.record_path;
  292. }
  293. modelRecord.RingStartTime = modelcdr.ring_time;
  294. modelRecord.CallId = modelcdr.uuid;
  295. modelRecord.Location = await GetLocationFunc(modelcdr.caller, 1);
  296. #region 计算时长
  297. modelRecord.LongTime = (int)DateTimeConvert.DateDiff(DateInterval.Second, modelcdr.create_time.GetValueOrDefault(), modelcdr.end_time.GetValueOrDefault());
  298. if (modelcdr.answer_time != null)
  299. modelRecord.TalkLongTime = (int)DateTimeConvert.DateDiff(DateInterval.Second, modelcdr.answer_time.GetValueOrDefault(), modelcdr.end_time.GetValueOrDefault());
  300. else
  301. modelRecord.TalkLongTime = 0;
  302. #endregion
  303. n++;
  304. n1++;
  305. modelRecordList.Add(modelRecord);
  306. if (n >= 2000)
  307. {
  308. await CallOutboundRecordsRepository.AddAndUpdateList(modelRecordList);
  309. modelRecordList.Clear();
  310. n = 0;
  311. }
  312. }
  313. await CallOutboundRecordsRepository.AddAndUpdateList(modelRecordList);
  314. }
  315. return $"同步情况 成功/总数 = {n1}/{totle}";
  316. }
  317. /// <summary>
  318. /// 同步外呼状态
  319. /// </summary>
  320. /// <returns></returns>
  321. [NonAction]
  322. internal async Task<string> SyncAutodial()
  323. {
  324. List<task > modellist = await taskRepository.GetListALL(q => q.status ==0 &&q .state ==1);
  325. int totle = 0;
  326. int n = 0;
  327. int n1 = 0;
  328. if (modellist != null && modellist.Count > 0)
  329. {
  330. List<T_Sys_AutoDial> modelAutoDial = new List<T_Sys_AutoDial>();
  331. List<task> taskList = new List<task>();
  332. foreach (task it in modellist)
  333. {
  334. var AutoDial = await sys_autodialrepository.GetSingle (q => q.F_ID == it.outbound_id );
  335. if (AutoDial!=null )
  336. {
  337. AutoDial.F_ISOutbound = 1;
  338. modelAutoDial.Add(AutoDial);
  339. n++;
  340. }
  341. it.status = 1;
  342. taskList.Add(it);
  343. #endregion
  344. n1++;
  345. if (n >= 2000)
  346. {
  347. await sys_autodialrepository.AddAndUpdateList(modelAutoDial);
  348. modelAutoDial.Clear();
  349. n = 0;
  350. }
  351. if (n1 >=2000)
  352. {
  353. await taskRepository.AddAndUpdateList(taskList);
  354. taskList.Clear();
  355. n1 = 0;
  356. }
  357. }
  358. await sys_autodialrepository.AddAndUpdateList(modelAutoDial);
  359. await taskRepository.AddAndUpdateList(taskList);
  360. }
  361. return $"同步情况 成功/总数 = {n1}/{totle}";
  362. }
  363. }
  364. }