颐和api

QC_CheckListRepository.cs 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. using MadRunFabric.Common;
  2. using MadRunFabric.Model;
  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 System.Linq;
  11. using MongoDB.Driver;
  12. using MadRunFabric.Model.CallCenterApi;
  13. namespace CallCenterApi.Repositories
  14. {
  15. public class QC_CheckListRepository : BaseRepository<QC_CheckList, string>, IQC_CheckListRepository
  16. {
  17. protected readonly ILogger<BaseRepository<QC_CheckList, string>> _logger;
  18. protected readonly IMongoCollection<mw_call_records> _collection_mw_call_records;
  19. protected readonly IMongoCollection<QC_CheckType> _collection_qc_checktype;
  20. protected readonly IMongoCollection<QC_CheckScore> _collection_qc_checkscore;
  21. protected readonly IMongoCollection<Sys_SystemConfig> _collection_sys_systemconfig;
  22. protected readonly IMongoCollection<Sys_User_Account> _collection_sys_user_account;
  23. public QC_CheckListRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<QC_CheckList, string>> logger) : base(settings, logger)
  24. {
  25. _logger = logger;
  26. _collection_mw_call_records = _context.GetCollection<mw_call_records>();
  27. _collection_qc_checktype = _context.GetCollection<QC_CheckType>();
  28. _collection_qc_checkscore = _context.GetCollection<QC_CheckScore>();
  29. _collection_sys_systemconfig = _context.GetCollection<Sys_SystemConfig>();
  30. _collection_sys_user_account = _context.GetCollection<Sys_User_Account>();
  31. }
  32. /// <summary>
  33. /// 分页列表 - 根据分页查询数据列表 包含查询条件,显示字段,排序
  34. /// </summary>
  35. /// <param name="usercode"></param>
  36. /// <param name="calltype"></param>
  37. /// <param name="telephone"></param>
  38. /// <param name="checktype"></param>
  39. /// <param name="stime"></param>
  40. /// <param name="etime"></param>
  41. /// <param name="pageindex"></param>
  42. /// <param name="pagesize"></param>
  43. /// <param name="recordcount"></param>
  44. /// <returns></returns>
  45. public IEnumerable<object> GetListsByPage(string usercode, int calltype, string telephone, int checktype,
  46. string stime, string etime, int pageindex, int pagesize, out int recordcount)
  47. {
  48. var query = from p in _collection_mw_call_records.AsQueryable()
  49. join c in _collection.AsQueryable() on p.id equals c.recordid into checkinfo
  50. join u in _collection_sys_user_account.AsQueryable() on p.agent_code equals u.usercode into userinfo
  51. select new
  52. {
  53. p.id,
  54. p.unique_id,
  55. p.callnumber,
  56. p.calltype,
  57. p.callstate,
  58. p.agent_code,
  59. username = userinfo.Count() > 0 ? userinfo.First().username : "",
  60. p.FilePath,
  61. p.begintime,
  62. p.begintime_ivr,
  63. p.endtime_ivr,
  64. p.longs_ivr,
  65. p.begintime_ring,
  66. p.endtime_ring,
  67. p.longs_ring,
  68. p.begintime_talk,
  69. p.endtime_talk,
  70. p.longs_talk,
  71. p.endtime,
  72. p.longs,
  73. checktype = checkinfo.Count() > 0 ? 1 : 0,
  74. checkdate = checkinfo.Count() > 0 ? checkinfo.First().createtime : DateTime.MinValue,
  75. checkscore = checkinfo.Count() > 0 ? checkinfo.First().qctotalscore : 0
  76. };
  77. #region 查询条件
  78. if (!string.IsNullOrEmpty(telephone))
  79. query = query.Where(it => it.callnumber.Contains(telephone));
  80. if (!string.IsNullOrEmpty(usercode))
  81. query = query.Where(it => it.agent_code .Contains ( usercode));
  82. if (calltype != -1)
  83. query = query.Where(it => it.calltype == calltype);
  84. if (checktype != -1)
  85. query = query.Where(it => it.checktype == checktype);
  86. if (!string.IsNullOrEmpty(stime))
  87. query = query.Where(it => it.begintime >= Convert.ToDateTime(stime + " 00:00:00"));
  88. if (!string.IsNullOrEmpty(etime))
  89. query = query.Where(it => it.begintime <= Convert.ToDateTime(etime + " 23:59:59"));
  90. #endregion
  91. recordcount = query.Count();
  92. var list = query.OrderByDescending(p => p.id).Skip((pageindex - 1) * pagesize).Take(pagesize).ToList();
  93. return list;
  94. }
  95. /// <summary>
  96. /// 详情 - 获取详情
  97. /// </summary>
  98. /// <param name="id"></param>
  99. /// <returns></returns>
  100. public object GetDetails(string id)
  101. {
  102. //var recordmodel = _collection_mw_call_records.Find(p => p.id == id).FirstOrDefault();
  103. var query = from p in _collection_mw_call_records.AsQueryable()
  104. join u in _collection_sys_user_account.AsQueryable() on p.agent_code equals u.usercode into userinfo
  105. where p.id == id
  106. select new
  107. {
  108. p.id,
  109. p.unique_id,
  110. p.callnumber,
  111. p.calltype,
  112. p.callstate,
  113. p.agent_code,
  114. username = userinfo.Count() > 0 ? userinfo.First().username : "",
  115. p.FilePath,
  116. p.begintime,
  117. p.begintime_ivr,
  118. p.endtime_ivr,
  119. p.longs_ivr,
  120. p.begintime_ring,
  121. p.endtime_ring,
  122. p.longs_ring,
  123. p.begintime_talk,
  124. p.endtime_talk,
  125. p.longs_talk,
  126. p.endtime,
  127. p.longs
  128. };
  129. var recordmodel = query.FirstOrDefault();
  130. if (recordmodel != null)
  131. {
  132. var pathmodel = _collection_sys_systemconfig.Find(p => p.paramcode == "PlayPath" && p.isdelete == false).FirstOrDefault();
  133. var recordpath = pathmodel?.paramvalue ?? "";
  134. var scoremodel = _collection.Find(p => p.recordid == recordmodel.id).FirstOrDefault();
  135. if (scoremodel != null)
  136. {
  137. var obj = new
  138. {
  139. recordmodel,
  140. recordpath,
  141. scoremodel,
  142. checktype = 1
  143. };
  144. return obj;
  145. }
  146. else
  147. {
  148. var typelist = _collection_qc_checktype.Find(p => p.isdelete == 0).ToList();
  149. var scorelist = _collection_qc_checkscore.Find(p => p.isdelete == 0).ToList();
  150. var checkmodel = typelist.Where(p => p.parentid == null).Select(p =>
  151. {
  152. var tlist = typelist.Where(s => s.parentid == p.id).Select(s =>
  153. {
  154. var slist = scorelist.Where(o => o.typeid == s.id);
  155. return new
  156. {
  157. s.name,
  158. s.sort,
  159. score = slist.Sum(o => o.score),
  160. qcscore = 0,
  161. item = slist.Select(o => new
  162. {
  163. name = o.title,
  164. o.sort,
  165. o.score,
  166. qcscore = 0
  167. }).OrderBy(o => o.sort)
  168. };
  169. }).OrderBy(s => s.sort);
  170. return new
  171. {
  172. p.name,
  173. p.sort,
  174. score = tlist.Sum(s => s.score),
  175. qcscore = 0,
  176. item = tlist
  177. };
  178. }).OrderBy(p => p.sort);
  179. var obj = new
  180. {
  181. recordmodel,
  182. recordpath,
  183. checkmodel,
  184. checktype = 0
  185. };
  186. return obj;
  187. }
  188. }
  189. return null;
  190. }
  191. /// <summary>
  192. /// 获取坐席统计数据
  193. /// </summary>
  194. /// <param name="stime"></param>
  195. /// <param name="etime"></param>
  196. /// <returns></returns>
  197. public object GetSeatTotal(string stime, string etime, string usercode)
  198. {
  199. var query = from p in _collection_mw_call_records.AsQueryable()
  200. join c in _collection.AsQueryable() on p.id equals c.recordid into checkinfo
  201. join u in _collection_sys_user_account.AsQueryable() on p.agent_code equals u.usercode into userinfo
  202. select new
  203. {
  204. p.id,
  205. p.agent_code,
  206. username = userinfo.Count() > 0 ? userinfo.First().username : "",
  207. p.begintime,
  208. checktype = checkinfo.Count() > 0 ? 1 : 0,
  209. checkscore = checkinfo.Count() > 0 ? checkinfo.First().qctotalscore : 0
  210. };
  211. #region 查询条件
  212. if (!string.IsNullOrEmpty(stime))
  213. query = query.Where(it => it.begintime >= Convert.ToDateTime(stime + " 00:00:00"));
  214. if (!string.IsNullOrEmpty(etime))
  215. query = query.Where(it => it.begintime <= Convert.ToDateTime(etime + " 23:59:59"));
  216. if (!string.IsNullOrEmpty(usercode))
  217. query = query.Where(it => it.agent_code == usercode);
  218. #endregion
  219. var checklist = query.Where(p => p.checktype == 1);
  220. if (checklist.Count() > 0)
  221. {
  222. var obj = new
  223. {
  224. callcount = query.Count(),
  225. checkcount = checklist.Count(),
  226. avgscore = Math.Round(checklist.Average(p => p.checkscore), 2),
  227. maxscore = checklist.Max(p => p.checkscore),
  228. minscore = checklist.Min(p => p.checkscore)
  229. };
  230. return obj;
  231. }
  232. else
  233. {
  234. var obj = new
  235. {
  236. callcount = query.Count(),
  237. checkcount = checklist.Count(),
  238. avgscore = 0,
  239. maxscore = 0,
  240. minscore = 0
  241. };
  242. return obj;
  243. }
  244. }
  245. /// <summary>
  246. /// 获取坐席月度排行
  247. /// </summary>
  248. /// <param name="stime"></param>
  249. /// <param name="etime"></param>
  250. /// <param name="usercode"></param>
  251. /// <returns></returns>
  252. public object GetSeatMonthRank(string stime, string etime, string usercode)
  253. {
  254. var query = from p in _collection_mw_call_records.AsQueryable()
  255. join c in _collection.AsQueryable() on p.id equals c.recordid into checkinfo
  256. join u in _collection_sys_user_account.AsQueryable() on p.agent_code equals u.usercode into userinfo
  257. select new
  258. {
  259. p.id,
  260. p.agent_code,
  261. username = userinfo.Count() > 0 ? userinfo.First().username : "",
  262. p.begintime,
  263. checktype = checkinfo.Count() > 0 ? 1 : 0,
  264. checkscore = checkinfo.Count() > 0 ? checkinfo.First().qctotalscore : 0
  265. };
  266. #region 查询条件
  267. if (!string.IsNullOrEmpty(stime))
  268. query = query.Where(it => it.begintime >= Convert.ToDateTime(stime + " 00:00:00"));
  269. if (!string.IsNullOrEmpty(etime))
  270. query = query.Where(it => it.begintime <= Convert.ToDateTime(etime + " 23:59:59"));
  271. #endregion
  272. var checklist = query.Where(p => p.checktype == 1);
  273. if (checklist.Count() > 0)
  274. {
  275. var ranklist = checklist.GroupBy(p => new { p.agent_code, p.username }).Select(p => new
  276. {
  277. usercode = p.Key.agent_code,
  278. p.Key.username,
  279. avgscore = p.Average(q => q.checkscore),
  280. maxscore = p.Max(q => q.checkscore),
  281. minscore = p.Min(q => q.checkscore)
  282. }).OrderByDescending(p => p.avgscore).ToList().Select((p, i) => new
  283. {
  284. p.usercode,
  285. p.username,
  286. avgscore = Math.Round(p.avgscore, 2),
  287. p.maxscore,
  288. p.minscore,
  289. rank = i + 1
  290. });
  291. int rank = 0;
  292. if (!string.IsNullOrEmpty(usercode))
  293. {
  294. var rankmodel = ranklist.Where(p => p.usercode == usercode).FirstOrDefault();
  295. rank = rankmodel?.rank ?? 0;
  296. query = query.Where(it => it.agent_code == usercode);
  297. var total = new
  298. {
  299. callcount = query.Count(),
  300. checkcount = checklist.Count(),
  301. rank,
  302. avgscore = Math.Round(checklist.Average(p => p.checkscore), 2),
  303. maxscore = checklist.Max(p => p.checkscore),
  304. minscore = checklist.Min(p => p.checkscore)
  305. };
  306. var obj = new
  307. {
  308. total,
  309. ranklist
  310. };
  311. return obj;
  312. }
  313. else
  314. {
  315. var total = new
  316. {
  317. callcount = query.Count(),
  318. checkcount = checklist.Count(),
  319. maxscore = ranklist.Max(p => p.avgscore),
  320. minscore = ranklist.Min(p => p.avgscore)
  321. };
  322. var obj = new
  323. {
  324. total,
  325. ranklist
  326. };
  327. return obj;
  328. }
  329. }
  330. else
  331. {
  332. if (!string.IsNullOrEmpty(usercode))
  333. {
  334. query = query.Where(it => it.agent_code == usercode);
  335. var total = new
  336. {
  337. callcount = query.Count(),
  338. checkcount = 0,
  339. rank = 0,
  340. avgscore = 0,
  341. maxscore = 0,
  342. minscore = 0,
  343. };
  344. var obj = new
  345. {
  346. total,
  347. ranklist = new List<string>()
  348. };
  349. return obj;
  350. }
  351. else
  352. {
  353. var total = new
  354. {
  355. callcount = query.Count(),
  356. checkcount = checklist.Count(),
  357. maxscore = 0,
  358. minscore = 0
  359. };
  360. var obj = new
  361. {
  362. total,
  363. ranklist = new List<string>()
  364. };
  365. return obj;
  366. }
  367. }
  368. }
  369. /// <summary>
  370. /// 获取坐席月度分布图
  371. /// </summary>
  372. /// <param name="stime"></param>
  373. /// <param name="etime"></param>
  374. /// <returns></returns>
  375. public object GetSeatMonthChart(string stime, string etime)
  376. {
  377. var query = from p in _collection_mw_call_records.AsQueryable()
  378. join c in _collection.AsQueryable() on p.id equals c.recordid into checkinfo
  379. join u in _collection_sys_user_account.AsQueryable() on p.agent_code equals u.usercode into userinfo
  380. select new
  381. {
  382. p.id,
  383. p.agent_code,
  384. username = userinfo.Count() > 0 ? userinfo.First().username : "",
  385. p.begintime,
  386. checktype = checkinfo.Count() > 0 ? 1 : 0,
  387. checkscore = checkinfo.Count() > 0 ? checkinfo.First().qctotalscore : 0
  388. };
  389. #region 查询条件
  390. if (!string.IsNullOrEmpty(stime))
  391. query = query.Where(it => it.begintime >= Convert.ToDateTime(stime + " 00:00:00"));
  392. if (!string.IsNullOrEmpty(etime))
  393. query = query.Where(it => it.begintime <= Convert.ToDateTime(etime + " 23:59:59"));
  394. #endregion
  395. var checklist = query.Where(p => p.checktype == 1);
  396. if (checklist.Count() > 0)
  397. {
  398. var totalavgscore = checklist.Average(p => p.checkscore);
  399. var seatlist = checklist.GroupBy(p => new { p.agent_code, p.username }).Select(p => new
  400. {
  401. usercode = p.Key.agent_code,
  402. p.Key.username,
  403. avgscore = p.Average(q => q.checkscore)
  404. }).ToList().Select(p => new
  405. {
  406. p.usercode,
  407. p.username,
  408. avgscore = Math.Round(p.avgscore, 2),
  409. checkscore = checklist.Where(c => c.agent_code == p.usercode).Select(c => c.checkscore)
  410. });
  411. var obj = new
  412. {
  413. totalavgscore,
  414. seatlist
  415. };
  416. return obj;
  417. }
  418. else
  419. {
  420. var obj = new
  421. {
  422. totalavgscore = 0,
  423. seatlist = new List<string>()
  424. };
  425. return obj;
  426. }
  427. }
  428. //(string usercode, int calltype, string dept, int checktype,
  429. //string stime, string etime, int pageindex, int pagesize, out int recordcount)
  430. public IEnumerable<object> GetLists( string dept,string stime, string etime, int pageindex, int pagesize, out int recordcount)
  431. {
  432. var query = from p in _collection_mw_call_records.AsQueryable()
  433. join c in _collection.AsQueryable() on p.id equals c.recordid into checkinfo
  434. join u in _collection_sys_user_account.AsQueryable() on p.agent_code equals u.usercode into userinfo
  435. select new
  436. {
  437. p.id,
  438. createuser = checkinfo.Count() > 0 ? checkinfo.First().createusername : "",
  439. username = userinfo.Count() > 0 ? userinfo.First().username : "",
  440. p.agent_code,
  441. checkcount=1,
  442. deptid= userinfo.Count() > 0 ? userinfo.First().dept_id : "",
  443. p.begintime,
  444. checktype = checkinfo.Count() > 0 ? 1 : 0,
  445. checkdate = checkinfo.Count() > 0 ? checkinfo.First().createtime : DateTime.MinValue,
  446. checkscore = checkinfo.Count() > 0 ? checkinfo.First().qctotalscore : 0,
  447. checkresult = checkinfo.Count() > 0 ? checkinfo.First().result : null
  448. };
  449. #region 查询条件
  450. query = query.Where(it => it.checkresult!=null );
  451. if (!string.IsNullOrEmpty(dept))
  452. query = query.Where(it => it.deptid.Contains(dept));
  453. if (!string.IsNullOrEmpty(stime))
  454. query = query.Where(it => it.begintime >= Convert.ToDateTime(stime + " 00:00:00"));
  455. if (!string.IsNullOrEmpty(etime))
  456. query = query.Where(it => it.begintime <= Convert.ToDateTime(etime + " 23:59:59"));
  457. #endregion
  458. recordcount = query.Count();
  459. var list = query.OrderByDescending(p => p.id).Skip((pageindex - 1) * pagesize).Take(pagesize).ToList();
  460. return list;
  461. }
  462. }
  463. }