颐和api

Call_RecordsRepository.cs 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. using MadRunFabric.Common;
  2. using MadRunFabric.Model.CallCenterApi;
  3. using CallCenterApi.IRepositories;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using Microsoft.Extensions.Logging;
  8. using MadRunFabric.Common.Options;
  9. using Microsoft.Extensions.Options;
  10. using MongoDB.Driver;
  11. using MongoDB.Bson;
  12. using System.Linq;
  13. using MadRunFabric.Model;
  14. using MadRunFabric.Model.WorkOrderApi;
  15. using System.Threading.Tasks;
  16. namespace CallCenterApi.Repositories
  17. {
  18. public class Call_RecordsRepository : BaseRepository<mw_call_records, string>, ICall_RecordsRepository
  19. {
  20. protected readonly ILogger<BaseRepository<mw_call_records, string>> _logger;
  21. protected readonly IMongoCollection<mw_call_records> _collection_mw_call_records;
  22. protected readonly IMongoCollection<Sys_User_Account> _collection_sys_user_account;
  23. protected readonly IMongoCollection<Cus_Customer_Project> _collection_cus_customer_project;
  24. protected readonly IMongoCollection<Sys_SystemConfig> _sys_systemconfigRepository;
  25. protected readonly IMongoCollection<Call_MobileData> _call_mobiledataRepository;
  26. protected readonly IMongoCollection<Bus_WorkOrder_Base> _bus_workorder_baseRepository;
  27. public Call_RecordsRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<mw_call_records, string>> logger) : base(settings, logger)
  28. {
  29. _logger = logger;
  30. _collection_mw_call_records = _context.GetCollection<mw_call_records>();
  31. _collection_sys_user_account = _context.GetCollection<Sys_User_Account>();
  32. _collection_cus_customer_project = _context.GetCollection<Cus_Customer_Project>();
  33. _sys_systemconfigRepository = _context.GetCollection<Sys_SystemConfig>();
  34. _call_mobiledataRepository = _context.GetCollection<Call_MobileData>();
  35. _bus_workorder_baseRepository = _context.GetCollection<Bus_WorkOrder_Base>();
  36. }
  37. //测试
  38. public object GetCallRecordTotalTime(string agentcode,string tag, string start, string end)//, UserInfoModel userinfo)
  39. {
  40. string bxwhere = "";
  41. if (!string.IsNullOrEmpty(tag))
  42. {
  43. if (bxwhere != "")
  44. {
  45. bxwhere = bxwhere + ",{calltype:" + tag + "}";
  46. }
  47. else
  48. {
  49. bxwhere = "{calltype:" + tag + "}";
  50. }
  51. }
  52. if (!string.IsNullOrEmpty(agentcode))
  53. {
  54. if (bxwhere != "")
  55. {
  56. bxwhere = bxwhere + ",{agent_code:'" + agentcode + "'}";
  57. }
  58. else
  59. {
  60. bxwhere = "{agent_code:'" + agentcode + "'}";
  61. }
  62. }
  63. if (!string.IsNullOrEmpty(start))
  64. {
  65. if (bxwhere != "")
  66. {
  67. bxwhere = bxwhere + ",{begintime:{$gte:new Date('" + start + "')}}";
  68. }
  69. else
  70. {
  71. bxwhere = "{begintime:{$gte:new Date('" + start + "')}}";
  72. }
  73. }
  74. if (!string.IsNullOrEmpty(end))
  75. {
  76. if (bxwhere != "")
  77. {
  78. bxwhere = bxwhere + ",{begintime:{$lte:new Date('" + end + "')}}";
  79. }
  80. else
  81. {
  82. bxwhere = "{begintime:{$lte:new Date('" + end + "')}}";
  83. }
  84. }
  85. var bxstages = new List<IPipelineStageDefinition>();
  86. bxstages.Add(new JsonPipelineStageDefinition<mw_call_records, BsonDocument>("{$match:{$and:[" + bxwhere + "]}}"));//agent_code
  87. bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id:\"$id\", count: {$sum: 1},totalcount:{$sum:\"$longs_talk\"}}}"));//UserId,UserCode,UserName
  88. //bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id: {userid:\"$_id.userid\", usercode:\"$_id.usercode\",username:\"$_id. username\"}, count: {$sum: 1},totalcount:{$sum:\"$ longs_talk\"}}}"));//UserId,UserCode,UserName
  89. var bxpipeline = new PipelineStagePipelineDefinition<mw_call_records, BsonDocument>(bxstages);
  90. var bxresult = _collection_mw_call_records.Aggregate(bxpipeline).ToList();
  91. if (bxresult.Count > 0)
  92. {
  93. return bxresult[0]["count"] + "," + bxresult[0]["totalcount"];
  94. }
  95. else
  96. { return "0,0"; }
  97. #region
  98. var list = bxresult.Select(pro =>
  99. {
  100. var rts = pro.Values.ToArray();
  101. return new
  102. {
  103. agentcode = rts[0].ToString(),
  104. calloutcount = rts[1].ToString(),
  105. talksummarytime = rts[2].ToString()
  106. };
  107. });
  108. return list;
  109. #endregion
  110. return bxresult;
  111. /*int[] hours = Enumerable.Range(0, 24).ToArray<int>();
  112. int[] bxcounts = new int[24];//报修数量
  113. int[] clcounts = new int[24];//处理数量
  114. for (int i = 0; i < hours.Length; i++)
  115. {
  116. bxcounts[i] = 0;
  117. clcounts[i] = 0;
  118. var bx = bxresult.Where(p => p.Values.ToArray()[0].ToString() == i.ToString()).FirstOrDefault();
  119. if (bx != null)
  120. {
  121. bxcounts[i] = Int32.Parse(bx.Values.ToArray()[1].ToString());
  122. }
  123. var cl = clresult.Where(p => p.Values.ToArray()[0].ToString() == i.ToString()).FirstOrDefault();
  124. if (cl != null)
  125. {
  126. clcounts[i] = Int32.Parse(cl.Values.ToArray()[1].ToString());
  127. }
  128. }
  129. var obj = new
  130. {
  131. hours,
  132. bxcounts,
  133. clcounts
  134. };
  135. return obj;*/
  136. }
  137. public object GetCallRecordRingTime(string agentcode, string start, string end)//, UserInfoModel userinfo)
  138. {
  139. string bxwhere = "{calltype:1},{callstate:0}";
  140. if (!string.IsNullOrEmpty(agentcode))
  141. {
  142. bxwhere = bxwhere + ",{agent_code:'" + agentcode + "'}";
  143. }
  144. if (!string.IsNullOrEmpty(start))
  145. {
  146. bxwhere = bxwhere + ",{begintime:{$gte:new Date('" + start + "')}}";
  147. }
  148. if (!string.IsNullOrEmpty(end))
  149. {
  150. bxwhere = bxwhere + ",{begintime:{$lte:new Date('" + end + "')}}";
  151. }
  152. var bxstages = new List<IPipelineStageDefinition>();
  153. bxstages.Add(new JsonPipelineStageDefinition<mw_call_records, BsonDocument>("{$match:{$and:[" + bxwhere + "]}}"));
  154. bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id:\"$id\", count: {$sum: 1},totalcount:{$sum:\"$longs_ring\"}}}"));//UserId,UserCode,UserName
  155. //bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id: {userid:\"$_id.userid\", usercode:\"$_id.usercode\",username:\"$_id. username\"}, count: {$sum: 1},totalcount:{$sum:\"$ longs_talk\"}}}"));//UserId,UserCode,UserName
  156. var bxpipeline = new PipelineStagePipelineDefinition<mw_call_records, BsonDocument>(bxstages);
  157. var bxresult = _collection_mw_call_records.Aggregate(bxpipeline).ToList();
  158. if (bxresult.Count > 0)
  159. {
  160. return bxresult[0]["count"] + "," + bxresult[0]["totalcount"];
  161. }
  162. else
  163. { return "0,0"; }
  164. }
  165. public object GetHighChartData(string agentcode, string start, string end,string tag,string state)//, UserInfoModel userinfo)
  166. {
  167. //string bxwhere = "{calltype:1,callstate:0}";
  168. string bxwhere = "";
  169. if (!string.IsNullOrEmpty(tag))
  170. {
  171. if (bxwhere != "")
  172. {
  173. bxwhere = bxwhere + ",{calltype:" + tag + "}";
  174. }
  175. else
  176. {
  177. bxwhere = "{calltype:" + tag + "}";
  178. }
  179. }
  180. if (!string.IsNullOrEmpty(state))
  181. {
  182. if (bxwhere != "")
  183. {
  184. bxwhere = bxwhere + ",{callstate:" + state + "}";
  185. }
  186. else
  187. {
  188. bxwhere = "{callstate:" + state + "}";
  189. }
  190. }
  191. if (!string.IsNullOrEmpty(agentcode))
  192. {
  193. if (bxwhere != "")
  194. {
  195. bxwhere = bxwhere + ",{agent_code:'" + agentcode + "'}";
  196. }
  197. else
  198. {
  199. bxwhere = "{agent_code:'" + agentcode + "'}";
  200. }
  201. }
  202. if (!string.IsNullOrEmpty(start))
  203. {
  204. if (bxwhere != "")
  205. {
  206. bxwhere = bxwhere + ",{begintime:{$gte:new Date('" + start + "')}}";
  207. }
  208. else
  209. {
  210. bxwhere = "{begintime:{$gte:new Date('" + start + "')}}";
  211. }
  212. }
  213. if (!string.IsNullOrEmpty(end))
  214. {
  215. if (bxwhere != "")
  216. {
  217. bxwhere = bxwhere + ",{begintime:{$lte:new Date('" + end + "')}}";
  218. }
  219. else
  220. {
  221. bxwhere = "{begintime:{$lte:new Date('" + end + "')}}";
  222. }
  223. }
  224. var bxstages = new List<IPipelineStageDefinition>();
  225. bxstages.Add(new JsonPipelineStageDefinition<mw_call_records, BsonDocument>("{$match:{$and:[" + bxwhere + "]}}"));
  226. bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id:\"$id\", count: {$sum: 1}}}"));//UserId,UserCode,UserName
  227. //bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id: {userid:\"$_id.userid\", usercode:\"$_id.usercode\",username:\"$_id. username\"}, count: {$sum: 1},totalcount:{$sum:\"$ longs_talk\"}}}"));//UserId,UserCode,UserName
  228. var bxpipeline = new PipelineStagePipelineDefinition<mw_call_records, BsonDocument>(bxstages);
  229. var bxresult = _collection_mw_call_records.Aggregate(bxpipeline).ToList();
  230. if (bxresult.Count > 0)
  231. {
  232. return bxresult[0]["count"];
  233. }
  234. else
  235. { return "0"; }
  236. }
  237. /// <summary>
  238. /// 获取排行榜
  239. /// </summary>
  240. /// <param name="top"></param>
  241. /// <param name="stime"></param>
  242. /// <param name="etime"></param>
  243. /// <returns></returns>
  244. public object GetHWRank(int top, string stime, string etime)
  245. {
  246. var query = from p in _collection.AsQueryable()
  247. join u in _collection_sys_user_account.AsQueryable() on p.agent_code equals u.usercode into userinfo
  248. where (p.agent_code!="0" && p.agent_code !=null )//1 == 1
  249. select new
  250. {
  251. usercode = p.agent_code,
  252. username = userinfo.Count() > 0 ? userinfo.First().username : "",
  253. p.begintime
  254. };
  255. if (!string.IsNullOrEmpty(stime))
  256. query = query.Where(it => it.begintime >= Convert.ToDateTime(stime));
  257. if (!string.IsNullOrEmpty(etime))
  258. query = query.Where(it => it.begintime <= Convert.ToDateTime(etime));
  259. var ranklist = query.GroupBy(p => new { p.usercode, p.username }).Select(p => new
  260. {
  261. p.Key.usercode,
  262. p.Key.username,
  263. count = p.Count()
  264. }).OrderByDescending(p => p.count).ToList().Select((p, i) => new
  265. {
  266. p.usercode,
  267. p.username,
  268. p.count,
  269. rank = i + 1
  270. });
  271. return top == 0 ? ranklist : ranklist.Take(top);
  272. }
  273. /// <summary>
  274. /// 获取日周月年话务数据24小时统计
  275. /// </summary>
  276. /// <param name="stime"></param>
  277. /// <param name="etime"></param>
  278. /// <param name="optuser"></param>
  279. /// <returns></returns>
  280. public object GetHW24CountReport(string stime, string etime)
  281. {
  282. int[] hours = Enumerable.Range(0, 24).ToArray<int>();
  283. int[] counts = new int[24];
  284. int[] yjrcounts = new int[24];
  285. int[] wjrcounts = new int[24];
  286. var query = from p in _collection.AsQueryable() where 1 == 1 select p;
  287. if (!string.IsNullOrEmpty(stime))
  288. query = query.Where(it => it.begintime >= Convert.ToDateTime(stime));
  289. if (!string.IsNullOrEmpty(etime))
  290. query = query.Where(it => it.begintime <= Convert.ToDateTime(etime));
  291. var list = query.ToList();
  292. for (int i = 0; i < hours.Length; i++)
  293. {
  294. counts[i] = list.Where(it => it.begintime.Hour == i).Count();
  295. }
  296. #region 已接入
  297. var query1 = from p in _collection.AsQueryable() where p.callstate == 1 select p;
  298. if (!string.IsNullOrEmpty(stime))
  299. query1 = query1.Where(it => it.begintime >= Convert.ToDateTime(stime));
  300. if (!string.IsNullOrEmpty(etime))
  301. query1 = query1.Where(it => it.begintime <= Convert.ToDateTime(etime));
  302. var list1 = query1.ToList();
  303. for (int i = 0; i < hours.Length; i++)
  304. {
  305. yjrcounts[i] = list1.Where(it => it.begintime.Hour == i).Count();
  306. }
  307. #endregion
  308. #region 未接入
  309. var query2 = from p in _collection.AsQueryable() where p.callstate == 0 select p;
  310. if (!string.IsNullOrEmpty(stime))
  311. query2 = query2.Where(it => it.begintime >= Convert.ToDateTime(stime));
  312. if (!string.IsNullOrEmpty(etime))
  313. query2 = query2.Where(it => it.begintime <= Convert.ToDateTime(etime));
  314. var list2 = query2.ToList();
  315. for (int i = 0; i < hours.Length; i++)
  316. {
  317. wjrcounts[i] = list2.Where(it => it.begintime.Hour == i).Count();
  318. }
  319. #endregion
  320. var result = new
  321. {
  322. hours,
  323. counts,
  324. yjrcounts,
  325. wjrcounts
  326. };
  327. return result;
  328. }
  329. /// <summary>
  330. /// Linq 关联查询 - App
  331. /// </summary>
  332. /// <param name="keyword"></param>
  333. /// <param name="provincecode"></param>
  334. /// <param name="citycode"></param>
  335. /// <param name="projectid"></param>
  336. /// <param name="protype"></param>
  337. /// <param name="systemid"></param>
  338. /// <param name="pageIndex"></param>
  339. /// <param name="pageSize"></param>
  340. /// <param name="recordCount"></param>
  341. /// <returns></returns>
  342. public IEnumerable<object> GetLists(string stime, string etime, string keyword)
  343. {
  344. var query = from p in _collection.AsQueryable()
  345. join u in _collection_cus_customer_project.AsQueryable() on p.callnumber equals u.mobilephone into cusinfo
  346. join w in _bus_workorder_baseRepository.AsQueryable() on p.callnumber equals w.phone into orderinfo//GetCallOutprefix()
  347. where 1 == 1
  348. orderby p.id descending //(p.agent_code != "0" && p.agent_code != null)
  349. select new
  350. {
  351. p.id,
  352. p.unique_id,
  353. p.callnumber,
  354. p.agent_code,
  355. p.agent_extnumber,
  356. p.calltype,
  357. p.callstate,
  358. p.dealtype,
  359. p.opttype,
  360. p.bussinesstype,
  361. p.begintime,
  362. p.begintime_ivr,
  363. p.endtime_ivr,
  364. p.begintime_queue,
  365. p.endtime_queue,
  366. p.begintime_ring,
  367. p.endtime_ring,
  368. p.begintime_talk,
  369. p.endtime_talk,
  370. p.endtime,
  371. p.longs_ring,
  372. p.longs_ivr,
  373. p.longs_queue,
  374. p.longs_talk,
  375. p.longs,
  376. p.turnstate,
  377. p.begintime_opt,
  378. p.begintime_talk_opt,
  379. p.end_talk_opt,
  380. p.agent_code_turn,
  381. p.agent_extnumber_turn,
  382. p.evaluation,
  383. p.FilePath,
  384. p.callopttype,
  385. p.taskid,
  386. p.taskphoneid,
  387. cusname = cusinfo != null && cusinfo.Count() > 0 ? cusinfo.First().name : "",
  388. existorder=orderinfo != null && orderinfo.Count() > 0 ? "有" : "无",
  389. };
  390. #region 查询条件
  391. //query = query.Where(it => it.projectdelete == 0);
  392. if (!string.IsNullOrWhiteSpace(stime))
  393. {
  394. query = query.Where(s => s.begintime.CompareTo(DateTime.Parse(stime)) >= 0 || s.endtime.CompareTo(DateTime.Parse(stime)) >= 0);
  395. }
  396. if (!string.IsNullOrWhiteSpace(etime))
  397. {
  398. query = query.Where(s => s.begintime.CompareTo(DateTime.Parse(etime)) <= 0 || s.endtime.CompareTo(DateTime.Parse(etime)) <= 0);
  399. }
  400. //模糊查询
  401. if (!string.IsNullOrWhiteSpace(keyword))
  402. query = query.Where(s => s.callnumber.Contains(keyword));
  403. #endregion
  404. return query;
  405. }
  406. //获取自动外呼前缀
  407. public string GetCallOutprefix(string phone)
  408. {
  409. int i;
  410. bool isnum = int.TryParse(phone.Substring(0, 1), out i);//判断是否为数字
  411. if (!isnum)
  412. {
  413. return "";
  414. }
  415. string phone1 = phone;
  416. string tophone = phone1;
  417. string zipcode = ""; string bfix = "0"; string wfix = ""; string fix = "";
  418. string bxwhere = "{isdelete:false},{paramcode:ZDWHQZ}";
  419. var bxstages = new List<IPipelineStageDefinition>();
  420. bxstages.Add(new JsonPipelineStageDefinition<Sys_SystemConfig, BsonDocument>("{$match:{$and:[" + bxwhere + "]}}"));
  421. var bxpipeline = new PipelineStagePipelineDefinition<Sys_SystemConfig, BsonDocument>(bxstages);
  422. var bxresult = _sys_systemconfigRepository.Aggregate(bxpipeline).ToList();
  423. string whqz = "";
  424. //var dModel = await _sys_systemconfigRepository.GetSingle(s => s.paramcode.Equals("ZDWHQZ") & s.isdelete == false, null);
  425. if (bxresult.Count > 0)
  426. {
  427. whqz = bxresult[0]["paramvalue"].ToString();
  428. }
  429. if (whqz != "")
  430. {
  431. var typearr = whqz.Split('#');
  432. if (typearr.Length > 2)
  433. {
  434. zipcode = typearr[2];
  435. bfix = typearr[1];
  436. wfix = typearr[0];
  437. int zip = 0;
  438. #region
  439. if (phone.Trim().Length >= 7)
  440. {
  441. //7位及7位以上是固定电话或手机
  442. //判断是否手机
  443. if (phone.Trim().Length == 11 && phone[0] == '1')
  444. {//号码为11位,首位是1,为手机号
  445. //BLL.T_Sys_MobileData mobile_Bll = new BLL.T_Sys_MobileData();
  446. //Model.T_Sys_MobileData mobileModel = mobile_Bll.GetModelList("F_MobileNum='" + phone.Substring(0, 7) + "'").FirstOrDefault();
  447. //_call_mobiledataRepository
  448. string p = phone.Substring(0, 7);
  449. string bxwhere1 = "{mobilenum:"+p+"}";
  450. var bxstages1 = new List<IPipelineStageDefinition>();
  451. bxstages1.Add(new JsonPipelineStageDefinition<Call_MobileData, BsonDocument>("{$match:{$and:[" + bxwhere1 + "]}}"));
  452. var bxpipeline1 = new PipelineStagePipelineDefinition<Call_MobileData, BsonDocument>(bxstages1);
  453. var bxresult1 = _call_mobiledataRepository.Aggregate(bxpipeline1).ToList();
  454. //var mobileModel = await _call_mobiledataRepository.Get(x => x.mobilenum == phone.Substring(0, 7));
  455. if (bxresult1!=null&&bxresult1.Count >0)
  456. {
  457. foreach (var items in bxresult1)
  458. {
  459. if (items["zipcode"].Equals(zipcode))
  460. {
  461. zip = 1;
  462. }
  463. else
  464. {
  465. zip = 2;
  466. }
  467. }
  468. }
  469. }
  470. else
  471. {
  472. if (phone.Trim().Length == 11 && phone.Substring(0, 3).Equals(zipcode))
  473. {//号码为11位
  474. //截取前三位区号判断是否本地
  475. bool resbd3 = phone.Substring(0, 3).Equals(zipcode);
  476. //截取前四位区号判断是否本地
  477. bool resbd4 = phone.Substring(0, 4).Equals(zipcode);
  478. if (resbd3 || resbd4)
  479. {
  480. zip = 3;
  481. }
  482. else
  483. {
  484. zip = 4;
  485. }
  486. }
  487. else if (phone.Trim().Length < 11)
  488. {//号码小于11位,为本地
  489. zip = 3;
  490. }
  491. else if (phone.Trim().Length > 11 && phone.Substring(0, 4).Equals(zipcode))
  492. {//号码大于11位,截取前四位区号判断是否本地
  493. zip = 3;
  494. }
  495. else
  496. {
  497. zip = 4;
  498. }
  499. }
  500. }
  501. #endregion
  502. #region
  503. if (zip == 1)
  504. {//手机本地号码
  505. fix = bfix;
  506. }
  507. else if (zip == 2)
  508. {//手机外地号码
  509. fix = wfix;
  510. }
  511. else
  512. {
  513. tophone = phone1.TrimStart('0');
  514. if (zip == 3)
  515. {//本地固话去0加9 比如:988888517,937188888517
  516. fix = bfix;
  517. }
  518. else if (zip == 4)
  519. {//外地固话前加9 比如:9037188888517
  520. fix = wfix;
  521. }
  522. }
  523. #endregion
  524. //var obj = new
  525. //{
  526. // phone = fix + tophone,
  527. // fix = fix
  528. //};
  529. string y = fix + tophone;
  530. return y;
  531. }
  532. }
  533. else//默认本地
  534. {
  535. fix = bfix;
  536. string y = fix + tophone;
  537. return y;
  538. }
  539. return "";
  540. }
  541. //添加获取省市报表
  542. public object GetPCCallRecordTotalTime(string agentcode, string tag, string start, string end,string province,string city)//, UserInfoModel userinfo)
  543. {
  544. string bxwhere = "";
  545. if (!string.IsNullOrEmpty(tag))
  546. {
  547. if (bxwhere != "")
  548. {
  549. bxwhere = bxwhere + ",{calltype:" + tag + "}";
  550. }
  551. else
  552. {
  553. bxwhere = "{calltype:" + tag + "}";
  554. }
  555. }
  556. if (!string.IsNullOrEmpty(province))
  557. {
  558. if (bxwhere != "")
  559. {
  560. bxwhere = bxwhere + ",{city:/" + province + "/}";
  561. }
  562. else
  563. {
  564. bxwhere = "{city:/" + province + "/}";
  565. }
  566. }
  567. if (!string.IsNullOrEmpty(city))
  568. {
  569. if (bxwhere != "")
  570. {
  571. bxwhere = bxwhere + ",{city:/" + city + "/}";
  572. }
  573. else
  574. {
  575. bxwhere = "{city:/" + city + "/}";
  576. }
  577. }
  578. if (!string.IsNullOrEmpty(agentcode))
  579. {
  580. if (bxwhere != "")
  581. {
  582. bxwhere = bxwhere + ",{agent_code:'" + agentcode + "'}";
  583. }
  584. else
  585. {
  586. bxwhere = "{agent_code:'" + agentcode + "'}";
  587. }
  588. }
  589. if (!string.IsNullOrEmpty(start))
  590. {
  591. if (bxwhere != "")
  592. {
  593. bxwhere = bxwhere + ",{begintime:{$gte:new Date('" + start + "')}}";
  594. }
  595. else
  596. {
  597. bxwhere = "{begintime:{$gte:new Date('" + start + "')}}";
  598. }
  599. }
  600. if (!string.IsNullOrEmpty(end))
  601. {
  602. if (bxwhere != "")
  603. {
  604. bxwhere = bxwhere + ",{begintime:{$lte:new Date('" + end + "')}}";
  605. }
  606. else
  607. {
  608. bxwhere = "{begintime:{$lte:new Date('" + end + "')}}";
  609. }
  610. }
  611. var bxstages = new List<IPipelineStageDefinition>();
  612. bxstages.Add(new JsonPipelineStageDefinition<mw_call_records, BsonDocument>("{$match:{$and:[" + bxwhere + "]}}"));//agent_code
  613. bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id:\"$city\", count: {$sum: 1},totalcount:{$sum:\"$longs_talk\"}}}"));//UserId,UserCode,UserName
  614. //bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id: {userid:\"$_id.userid\", usercode:\"$_id.usercode\",username:\"$_id. username\"}, count: {$sum: 1},totalcount:{$sum:\"$ longs_talk\"}}}"));//UserId,UserCode,UserName
  615. var bxpipeline = new PipelineStagePipelineDefinition<mw_call_records, BsonDocument>(bxstages);
  616. var bxresult = _collection_mw_call_records.Aggregate(bxpipeline).ToList();
  617. if (bxresult.Count > 0)
  618. {
  619. return bxresult[0]["count"] + "," + bxresult[0]["totalcount"];
  620. }
  621. else
  622. { return "0,0"; }
  623. #region
  624. var list = bxresult.Select(pro =>
  625. {
  626. var rts = pro.Values.ToArray();
  627. return new
  628. {
  629. agentcode = rts[0].ToString(),
  630. calloutcount = rts[1].ToString(),
  631. talksummarytime = rts[2].ToString()
  632. };
  633. });
  634. return list;
  635. #endregion
  636. return bxresult;
  637. /*int[] hours = Enumerable.Range(0, 24).ToArray<int>();
  638. int[] bxcounts = new int[24];//报修数量
  639. int[] clcounts = new int[24];//处理数量
  640. for (int i = 0; i < hours.Length; i++)
  641. {
  642. bxcounts[i] = 0;
  643. clcounts[i] = 0;
  644. var bx = bxresult.Where(p => p.Values.ToArray()[0].ToString() == i.ToString()).FirstOrDefault();
  645. if (bx != null)
  646. {
  647. bxcounts[i] = Int32.Parse(bx.Values.ToArray()[1].ToString());
  648. }
  649. var cl = clresult.Where(p => p.Values.ToArray()[0].ToString() == i.ToString()).FirstOrDefault();
  650. if (cl != null)
  651. {
  652. clcounts[i] = Int32.Parse(cl.Values.ToArray()[1].ToString());
  653. }
  654. }
  655. var obj = new
  656. {
  657. hours,
  658. bxcounts,
  659. clcounts
  660. };
  661. return obj;*/
  662. }
  663. public object GetPCCallRecordRingTime(string agentcode, string start, string end, string province, string city)//, UserInfoModel userinfo)
  664. {
  665. string bxwhere = "{calltype:1},{callstate:0}";
  666. if (!string.IsNullOrEmpty(agentcode))
  667. {
  668. bxwhere = bxwhere + ",{agent_code:'" + agentcode + "'}";
  669. }
  670. if (!string.IsNullOrEmpty(province))
  671. {
  672. if (bxwhere != "")
  673. {
  674. bxwhere = bxwhere + ",{city:/" + province + "/}";
  675. }
  676. else
  677. {
  678. bxwhere = "{city:/" + province + "/}";
  679. }
  680. }
  681. if (!string.IsNullOrEmpty(city))
  682. {
  683. if (bxwhere != "")
  684. {
  685. bxwhere = bxwhere + ",{city:/" + city + "/}";
  686. }
  687. else
  688. {
  689. bxwhere = "{city:/" + city + "/}";
  690. }
  691. }
  692. if (!string.IsNullOrEmpty(start))
  693. {
  694. bxwhere = bxwhere + ",{begintime:{$gte:new Date('" + start + "')}}";
  695. }
  696. if (!string.IsNullOrEmpty(end))
  697. {
  698. bxwhere = bxwhere + ",{begintime:{$lte:new Date('" + end + "')}}";
  699. }
  700. var bxstages = new List<IPipelineStageDefinition>();
  701. bxstages.Add(new JsonPipelineStageDefinition<mw_call_records, BsonDocument>("{$match:{$and:[" + bxwhere + "]}}"));
  702. bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id:\"$city\", count: {$sum: 1},totalcount:{$sum:\"$longs_ring\"}}}"));//UserId,UserCode,UserName
  703. //bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id: {userid:\"$_id.userid\", usercode:\"$_id.usercode\",username:\"$_id. username\"}, count: {$sum: 1},totalcount:{$sum:\"$ longs_talk\"}}}"));//UserId,UserCode,UserName
  704. var bxpipeline = new PipelineStagePipelineDefinition<mw_call_records, BsonDocument>(bxstages);
  705. var bxresult = _collection_mw_call_records.Aggregate(bxpipeline).ToList();
  706. if (bxresult.Count > 0)
  707. {
  708. return bxresult[0]["count"] + "," + bxresult[0]["totalcount"];
  709. }
  710. else
  711. { return "0,0"; }
  712. }
  713. public object GetPCHighChartData(string agentcode, string start, string end, string tag, string state, string province, string city)//, UserInfoModel userinfo)
  714. {
  715. //string bxwhere = "{calltype:1,callstate:0}";
  716. string bxwhere = "";
  717. if (!string.IsNullOrEmpty(tag))
  718. {
  719. if (bxwhere != "")
  720. {
  721. bxwhere = bxwhere + ",{calltype:" + tag + "}";
  722. }
  723. else
  724. {
  725. bxwhere = "{calltype:" + tag + "}";
  726. }
  727. }
  728. if (!string.IsNullOrEmpty(province))
  729. {
  730. if (bxwhere != "")
  731. {
  732. bxwhere = bxwhere + ",{city:/" + province + "/}";
  733. }
  734. else
  735. {
  736. bxwhere = "{city:/" + province + "/}";
  737. }
  738. }
  739. if (!string.IsNullOrEmpty(city))
  740. {
  741. if (bxwhere != "")
  742. {
  743. bxwhere = bxwhere + ",{city:/" + city + "/}";
  744. }
  745. else
  746. {
  747. bxwhere = "{city:/" + city + "/}";
  748. }
  749. }
  750. if (!string.IsNullOrEmpty(state))
  751. {
  752. if (bxwhere != "")
  753. {
  754. bxwhere = bxwhere + ",{callstate:" + state + "}";
  755. }
  756. else
  757. {
  758. bxwhere = "{callstate:" + state + "}";
  759. }
  760. }
  761. if (!string.IsNullOrEmpty(agentcode))
  762. {
  763. if (bxwhere != "")
  764. {
  765. bxwhere = bxwhere + ",{agent_code:'" + agentcode + "'}";
  766. }
  767. else
  768. {
  769. bxwhere = "{agent_code:'" + agentcode + "'}";
  770. }
  771. }
  772. if (!string.IsNullOrEmpty(start))
  773. {
  774. if (bxwhere != "")
  775. {
  776. bxwhere = bxwhere + ",{begintime:{$gte:new Date('" + start + "')}}";
  777. }
  778. else
  779. {
  780. bxwhere = "{begintime:{$gte:new Date('" + start + "')}}";
  781. }
  782. }
  783. if (!string.IsNullOrEmpty(end))
  784. {
  785. if (bxwhere != "")
  786. {
  787. bxwhere = bxwhere + ",{begintime:{$lte:new Date('" + end + "')}}";
  788. }
  789. else
  790. {
  791. bxwhere = "{begintime:{$lte:new Date('" + end + "')}}";
  792. }
  793. }
  794. var bxstages = new List<IPipelineStageDefinition>();
  795. bxstages.Add(new JsonPipelineStageDefinition<mw_call_records, BsonDocument>("{$match:{$and:[" + bxwhere + "]}}"));
  796. bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id:\"$city\", count: {$sum: 1}}}"));//UserId,UserCode,UserName
  797. //bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id: {userid:\"$_id.userid\", usercode:\"$_id.usercode\",username:\"$_id. username\"}, count: {$sum: 1},totalcount:{$sum:\"$ longs_talk\"}}}"));//UserId,UserCode,UserName
  798. var bxpipeline = new PipelineStagePipelineDefinition<mw_call_records, BsonDocument>(bxstages);
  799. var bxresult = _collection_mw_call_records.Aggregate(bxpipeline).ToList();
  800. if (bxresult.Count > 0)
  801. {
  802. return bxresult[0]["count"];
  803. }
  804. else
  805. { return "0"; }
  806. }
  807. /// <summary>
  808. /// 获取列表
  809. /// </summary>
  810. /// <param name="top"></param>
  811. /// <param name="stime"></param>
  812. /// <param name="etime"></param>
  813. /// <returns></returns>
  814. public object GetDataList(int top, string stime, string etime)
  815. {
  816. var query = from p in _collection.AsQueryable()
  817. join u in _collection_sys_user_account.AsQueryable() on p.agent_code equals u.usercode into userinfo
  818. where (p.agent_code != "0" && p.agent_code != null)//1 == 1
  819. select new
  820. {
  821. usercode = p.agent_code,
  822. username = userinfo.Count() > 0 ? userinfo.First().username : "",
  823. p.begintime
  824. };
  825. if (!string.IsNullOrEmpty(stime))
  826. query = query.Where(it => it.begintime >= Convert.ToDateTime(stime));
  827. if (!string.IsNullOrEmpty(etime))
  828. query = query.Where(it => it.begintime <= Convert.ToDateTime(etime));
  829. var ranklist = query.GroupBy(p => new { p.usercode, p.username }).Select(p => new
  830. {
  831. p.Key.usercode,
  832. p.Key.username,
  833. count = p.Count()
  834. }).OrderByDescending(p => p.count).ToList().Select((p, i) => new
  835. {
  836. p.usercode,
  837. p.username,
  838. p.count,
  839. rank = i + 1
  840. });
  841. return top == 0 ? ranklist : ranklist.Take(top);
  842. }
  843. }
  844. }