StatisticsService.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. using Azure.Cosmos;
  2. using Azure.Messaging.ServiceBus;
  3. using HTEXLib.COMM.Helpers;
  4. using Microsoft.Extensions.Configuration;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using TEAMModelOS.SDK.DI;
  11. using TEAMModelOS.SDK.Extension;
  12. using TEAMModelOS.SDK.Models;
  13. namespace TEAMModelOS.SDK
  14. {
  15. public static class StatisticsService
  16. {
  17. /// <summary>
  18. /// 教师能力点操作
  19. /// </summary>
  20. public const string TeacherAility = "TeacherAility";
  21. /// <summary>
  22. /// 课堂实录
  23. /// </summary>
  24. public const string TeacherClass = "TeacherClass";
  25. /// <summary>
  26. /// 线下研修
  27. /// </summary>
  28. public const string OfflineRecord = "OfflineRecord";
  29. public static async Task SendServiceBus(string standard,string tmdid,string school,string update,int statistics, IConfiguration _configuration, AzureServiceBusFactory _serviceBus) {
  30. TeacherTrainChange change = new TeacherTrainChange
  31. {
  32. standard = standard,
  33. tmdid =tmdid,
  34. school =school,
  35. update = new HashSet<string>(new List<string> { update }),
  36. statistics = statistics
  37. };
  38. var messageChange = new ServiceBusMessage(change.ToJsonString());
  39. messageChange.ApplicationProperties.Add("name", "TeacherTrainChange");
  40. var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  41. await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
  42. }
  43. public static async Task<List<(List<TeacherTrain> trains, List<RGroupList> yxtrain)>> StatisticsArea(AreaSetting setting, Area area, CosmosClient client, DingDing _dingDing, HashSet<string> updates)
  44. {
  45. List<(List<TeacherTrain> trains, List<RGroupList> yxtrain)> teacherTrains = new List<(List<TeacherTrain> trains, List<RGroupList> yxtrain)>() ;
  46. List<School> schools = new List<School>();
  47. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School")
  48. .GetItemQueryIterator<School>(queryText: $"select value(c) from c where c.areaId='{area.id}' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  49. {
  50. schools.Add(item);
  51. }
  52. await foreach ((List<TeacherTrain> trains, List<RGroupList> yxtrain) tarain in GetStatisticsSchool(schools, setting, area, client,_dingDing,updates))
  53. {
  54. teacherTrains.Add(tarain);
  55. }
  56. return teacherTrains;
  57. }
  58. private static async IAsyncEnumerable<(List<TeacherTrain> trains, List<RGroupList> yxtrain)> GetStatisticsSchool(List<School> schools, AreaSetting setting, Area area, CosmosClient client, DingDing _dingDing, HashSet<string> updates)
  59. {
  60. foreach (var school in schools)
  61. {
  62. yield return await StatisticsSchool(school.id, setting, area, client,_dingDing,updates);
  63. }
  64. }
  65. public static async Task<(List<TeacherTrain> trains, List<RGroupList> yxtrain)> StatisticsSchool(string school, AreaSetting setting, Area area, CosmosClient client,DingDing _dingDing,HashSet<string> updates) {
  66. List<RGroupList> yxtrain = await GroupListService.GetGroupListMemberByType(client, "yxtrain", new List<string> { "school" }, $"{school}", _dingDing);
  67. List<TeacherTrain> trains = new List<TeacherTrain>();
  68. var members = yxtrain.SelectMany(x => x.members).ToList();
  69. if (members.Count <= 0)
  70. {
  71. return (trains, yxtrain);
  72. }
  73. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher")
  74. .GetItemQueryIterator<TeacherTrain>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{school}") })) {
  75. trains.Add(item);
  76. }
  77. if (updates != null) {
  78. foreach (var up in updates)
  79. {
  80. trains.ForEach(x => x.updateProperty.Add(up));
  81. }
  82. }
  83. var update = trains.FindAll(x => x.updateProperty.Count() > 0);
  84. var noupdate = trains.FindAll(x => x.updateProperty.Count() <=0);
  85. var unStatistics = members.Select(x => x.id).Except(trains.Select(x => x.id));
  86. List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
  87. List<TeacherTrain> returnTrains = new List<TeacherTrain>();
  88. if (update.IsNotEmpty()) {
  89. teacherTrains.AddRange(update);
  90. }
  91. if (unStatistics != null) {
  92. foreach (string x in unStatistics) {
  93. var member = members.Find(y => y.id.Equals(x));
  94. teacherTrains.Add(new TeacherTrain
  95. {
  96. pk = "TeacherTrain",
  97. id = x,
  98. code = $"TeacherTrain-{school}",
  99. tmdid = x,
  100. name = member.name,
  101. picture=member.picture,
  102. school = school,
  103. updateProperty = new HashSet<string> { TeacherAility,TeacherClass,OfflineRecord }
  104. });
  105. }
  106. }
  107. List<Study> studies = new List<Study>();
  108. await foreach (var item in client.GetContainer("TEAMModelOS", "Common")
  109. .GetItemQueryIterator<Study>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{school}") }))
  110. {
  111. studies.Add(item);
  112. }
  113. returnTrains = await GetStatisticsTeacher(teacherTrains, setting, area, client,studies);
  114. //await foreach (var tarain in GetStatisticsTeacher(teacherTrains, setting, area, client))
  115. //{
  116. // returnTrains.Add(tarain);
  117. //}
  118. if (noupdate.IsNotEmpty())
  119. {
  120. returnTrains.AddRange(noupdate);
  121. }
  122. returnTrains.ForEach(x => {
  123. var mbm= members.Find(y => y.id.Equals(x.id));
  124. x.groupName = mbm?.groupName;
  125. x.name = mbm?.name;
  126. x.picture = mbm?.picture;
  127. });
  128. return (returnTrains, yxtrain);
  129. }
  130. private static async Task<List<TeacherTrain>> GetStatisticsTeacher(List<TeacherTrain> trains, AreaSetting setting, Area area, CosmosClient client, List<Study> studies)
  131. {
  132. List<Task<TeacherTrain>> teachers = new List<Task<TeacherTrain>>();
  133. foreach (var train in trains)
  134. {
  135. teachers.Add(StatisticsTeacher(train, setting, area, client,studies)); //yield return await StatisticsTeacher( train, setting, area, client);
  136. }
  137. int pagesize = 50;
  138. if (teachers.Count <= pagesize)
  139. {
  140. await Task.WhenAll(teachers);
  141. }
  142. else
  143. {
  144. int pages = (teachers.Count + pagesize) / pagesize; //256是批量操作最大值,pages = (total + max -1) / max;
  145. for (int i = 0; i < pages; i++)
  146. {
  147. var lists = teachers.Skip((i) * pagesize).Take(pagesize).ToList();
  148. await Task.WhenAll(lists);
  149. }
  150. }
  151. return trains;
  152. }
  153. public static async Task<TeacherTrain> StatisticsTeacher(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client,List<Study> studies) {
  154. string _school = train.school;
  155. string _tmdid = train.tmdid;
  156. // TeacherTrain teacher_train = null;
  157. List<Task<TeacherTrain>> teachers = new List<Task<TeacherTrain>>();
  158. if (train.updateProperty.Count > 0) {
  159. foreach (string property in train.updateProperty) {
  160. teachers.Add(DoProperty(train.updateProperty, property, setting, area, client, train,studies));
  161. }
  162. int pagesize = 50;
  163. if (teachers.Count <= pagesize)
  164. {
  165. await Task.WhenAll(teachers);
  166. }
  167. else
  168. {
  169. int pages = (teachers.Count + pagesize) / pagesize; //256是批量操作最大值,pages = (total + max -1) / max;
  170. for (int i = 0; i < pages; i++)
  171. {
  172. var lists = teachers.Skip((i) * pagesize).Take(pagesize).ToList();
  173. await Task.WhenAll(lists);
  174. }
  175. }
  176. }
  177. //每次都统计活动相关的数据。
  178. train= await DoActivity(train, setting, area, client, _school, _tmdid);
  179. train.totalTime = train.onlineTime + train.classTime + train.currency.submitTime + train.offlineTime;
  180. if (train.totalTime >= setting.allTime)
  181. {
  182. //如果总学生超过50 且不是优秀则至少是合格。
  183. if (train.finalScore != 2)
  184. {
  185. train.finalScore = 1;
  186. }
  187. }
  188. // 50> 学时>0 是不合格
  189. else if (train.totalTime < setting.allTime && train.totalTime > 0)
  190. {
  191. train.finalScore = 0;
  192. }
  193. else {
  194. //学时<=0 则是为
  195. train.finalScore = -1;
  196. }
  197. await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<TeacherTrain>(train, new PartitionKey($"TeacherTrain-{_school}"));
  198. return train;
  199. }
  200. private static async Task<TeacherTrain> DoProperty(HashSet<string> updateProperty,string property, AreaSetting setting, Area area, CosmosClient client, TeacherTrain train ,List<Study> studies )
  201. {
  202. string _school = train.school;
  203. string _tmdid = train.tmdid;
  204. switch (property) {
  205. case TeacherAility:
  206. train = await DoTeacherAility(train, setting, area, client, _school, _tmdid);
  207. train.updateProperty.Remove(TeacherAility);
  208. break;
  209. //课堂实录更新
  210. case TeacherClass:
  211. train = await DoTeacherClass(train, setting, area, client, _school, _tmdid);
  212. train.updateProperty.Remove(TeacherClass);
  213. break;
  214. //线下研修
  215. case OfflineRecord:
  216. train = await DoOfflineRecord(train, setting, area, client, _school, _tmdid,studies);
  217. train.updateProperty.Remove(OfflineRecord);
  218. break;
  219. default:
  220. train.updateProperty.Remove(property);
  221. break;
  222. }
  223. return train;
  224. }
  225. public static async Task<TeacherTrain> DoActivity(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid) {
  226. //问卷调查
  227. int surveyJoin=0;
  228. int voteJoin = 0;
  229. int examJoin = 0;
  230. int surveyDone = 0;
  231. int voteDone = 0;
  232. int examDone = 0;
  233. int surveyAreaJoin = 0;
  234. int voteAreaJoin = 0;
  235. int examAreaJoin = 0;
  236. int surveyAreaDone = 0;
  237. int voteAreaDone = 0;
  238. int examAreaDone = 0;
  239. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher")
  240. .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'Survey' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
  241. {
  242. if (!string.IsNullOrEmpty(item.owner))
  243. {
  244. if (item.owner.Equals("school"))
  245. {
  246. surveyJoin += 1;
  247. if (item.taskStatus > 0)
  248. {
  249. surveyDone += 1;
  250. }
  251. }
  252. else if (item.owner.Equals("area"))
  253. {
  254. surveyAreaJoin += 1;
  255. if (item.taskStatus > 0)
  256. {
  257. surveyAreaDone += 1;
  258. }
  259. }
  260. }
  261. }
  262. //评量检测
  263. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  264. .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'ExamLite' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
  265. {
  266. if (!string.IsNullOrEmpty(item.owner))
  267. {
  268. if (item.owner.Equals("school"))
  269. {
  270. examJoin += 1;
  271. if (item.taskStatus > 0)
  272. {
  273. examDone += 1;
  274. }
  275. }
  276. else if (item.owner.Equals("area"))
  277. {
  278. examAreaJoin += 1;
  279. if (item.taskStatus > 0)
  280. {
  281. examAreaDone += 1;
  282. }
  283. }
  284. }
  285. }
  286. //投票活动
  287. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  288. .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'Vote' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
  289. {
  290. if (!string.IsNullOrEmpty(item.owner))
  291. {
  292. if (item.owner.Equals("school"))
  293. {
  294. voteJoin += 1;
  295. if (item.taskStatus > 0)
  296. {
  297. voteDone += 1;
  298. }
  299. }
  300. else if (item.owner.Equals("area"))
  301. {
  302. voteAreaJoin += 1;
  303. if (item.taskStatus > 0)
  304. {
  305. voteAreaDone += 1;
  306. }
  307. }
  308. }
  309. }
  310. train.surveyJoin = surveyJoin;
  311. train.voteJoin = voteJoin;
  312. train.examJoin = examJoin;
  313. train.surveyDone = surveyDone;
  314. train.voteDone = voteDone;
  315. train.examDone = examDone;
  316. train.surveyAreaJoin = surveyAreaJoin;
  317. train.voteAreaJoin = voteAreaJoin;
  318. train.examAreaJoin = examAreaJoin;
  319. train.surveyAreaDone = surveyAreaDone;
  320. train.voteAreaDone = voteAreaDone;
  321. train.examAreaDone = examAreaDone;
  322. return train;
  323. }
  324. /// <summary>
  325. /// 课堂实录更新
  326. /// </summary>
  327. /// <param name="train"></param>
  328. /// <param name="setting"></param>
  329. /// <param name="area"></param>
  330. /// <param name="client"></param>
  331. /// <param name="_school"></param>
  332. /// <param name="_tmdid"></param>
  333. /// <returns></returns>
  334. public static async Task<TeacherTrain> DoOfflineRecord(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid, List<Study> studies) {
  335. //owner: school area
  336. //线下 学校研修活动
  337. List<StuActivity> activities = new List<StuActivity>();
  338. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  339. .GetItemQueryIterator<StuActivity>(queryText: $"select value(c) from c where c.type = 'Study' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
  340. {
  341. activities.Add(item);
  342. }
  343. string insql = "";
  344. if (studies.IsEmpty()) {
  345. studies = new List<Study>();
  346. if (activities.IsNotEmpty())
  347. {
  348. insql = $" where c.id in ({string.Join(",", activities.Select(o => $"'{o.id}'"))})";
  349. }
  350. await foreach (var item in client.GetContainer("TEAMModelOS", "Common")
  351. .GetItemQueryIterator<Study>(queryText: $"select value(c) from c {insql} ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{_school}") }))
  352. {
  353. studies.Add(item);
  354. }
  355. }
  356. List<StudyRecord> studyRecords = new List<StudyRecord>();
  357. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  358. .GetItemQueryIterator<StudyRecord>(queryText: $"select value(c) from c {insql} ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StudyRecord-{_tmdid}") }))
  359. {
  360. studyRecords.Add(item);
  361. }
  362. List<HomeworkRecord> homeworkRecords = new List<HomeworkRecord>();
  363. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  364. .GetItemQueryIterator<HomeworkRecord>(queryText: $"select value(c) from c {insql} ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"HomeworkRecord-{_tmdid}") }))
  365. {
  366. homeworkRecords.Add(item);
  367. }
  368. List<OfflineRecord> offlines = new List<OfflineRecord>();
  369. activities.ForEach(item => {
  370. Study study = studies.Find(y=>y.id.Equals(item.id));
  371. StudyRecord studyRecord= studyRecords.Find(y => y.id.Equals(item.id));
  372. HomeworkRecord homeworkRecord= homeworkRecords.Find(y => y.id.Equals(item.id));
  373. Attachment attachment = homeworkRecord!=null ? homeworkRecord.content.Find(x => x.prime):null;
  374. if (!string.IsNullOrEmpty(item.owner) && study != null && !item.owner.Equals("area") )
  375. {
  376. OfflineRecord record = new OfflineRecord
  377. {
  378. id = item.id,
  379. name = item.name,
  380. done = item.taskStatus,
  381. owner = item.owner
  382. };
  383. record.sethour = study.hour;
  384. if (!string.IsNullOrEmpty(study.workId) ) {
  385. record.haswork = 1;
  386. }
  387. if (null != studyRecord)
  388. {
  389. //通过获得学时
  390. record.hour = studyRecord.status == 1 ? study.hour : 0;
  391. record.score = studyRecord.status;
  392. if (record.score >= 0)
  393. {
  394. record.done = 1;
  395. }
  396. else {
  397. record.score = -1;
  398. }
  399. //取消转换
  400. //if (studyRecord.status == 1)
  401. //{
  402. // record.score = 1;
  403. // record.done = 1;
  404. //}
  405. //if (studyRecord.status == 0)
  406. //{
  407. // record.score = -1;
  408. //}
  409. //if (studyRecord.status == 2)
  410. //{
  411. // record.score = 0;
  412. // record.done = 1;
  413. //}
  414. }
  415. if (null != attachment)
  416. {
  417. record.url = attachment.url;
  418. record.upload = 1;
  419. record.hash = attachment.hash;
  420. record.size = attachment.size;
  421. }
  422. offlines.Add(record);
  423. }
  424. });
  425. int sum = offlines.Select(x => x.hour).Sum();
  426. train.offlineTime =sum >setting.offlineTime?setting.offlineTime: sum;
  427. train.offlineRecords= offlines;
  428. return train;
  429. }
  430. /// <summary>
  431. /// 课堂实录更新
  432. /// </summary>
  433. /// <param name="train"></param>
  434. /// <param name="setting"></param>
  435. /// <param name="area"></param>
  436. /// <param name="client"></param>
  437. /// <param name="_school"></param>
  438. /// <param name="_tmdid"></param>
  439. /// <returns></returns>
  440. public static async Task<TeacherTrain> DoTeacherClass(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid)
  441. {
  442. string code = $"ClassVideo-{_school}";
  443. ClassVideo classVideo = null;
  444. try { classVideo = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ClassVideo>($"{_tmdid}", new PartitionKey(code));
  445. } catch (Exception ex) {
  446. classVideo = null;
  447. }
  448. if (classVideo != null && classVideo.files.IsNotEmpty())
  449. {
  450. //2021.11.17 15:05,与J哥确认,取课堂实录第一个。前端也只show第一个视频。
  451. var files = classVideo.files[0];
  452. if (files.score > 0)
  453. {
  454. train.classTime=setting.classTime;
  455. }
  456. train.teacherClasses= new List<TeacherClass> { new Models.TeacherClass { url = files.url, score = files.score, hash = files.hash, name = files.name, size = files.size } };
  457. }
  458. return train;
  459. }
  460. public static async Task<TeacherTrain> DoTeacherAility(TeacherTrain train, AreaSetting setting,Area area , CosmosClient client,string _school,string _tmdid) {
  461. //视频播放
  462. List<string> abilityIds = new List<string> ();
  463. TeacherFile file = null;
  464. try
  465. {
  466. file = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<TeacherFile>(_tmdid, new PartitionKey($"TeacherFile-{_school}"));
  467. }
  468. catch (CosmosException )
  469. {
  470. file = new TeacherFile
  471. {
  472. id = _tmdid,
  473. code = $"TeacherFile-{_school}",
  474. pk = "TeacherFile",
  475. ttl = -1,
  476. };
  477. await client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<TeacherFile>(file, new PartitionKey($"TeacherFile-{_school}"));
  478. }
  479. List<AbilitySub> abilitySubs= new List<AbilitySub> ();
  480. //认证材料
  481. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  482. .GetItemQueryIterator<AbilitySub>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilitySub-{_school}-{_tmdid}") }))
  483. {
  484. abilitySubs.Add(item);
  485. }
  486. List<Ability> abilities = new List<Ability>();
  487. string insql = "";
  488. if (abilitySubs.IsNotEmpty()) {
  489. insql =$" where c.id in ({string.Join(",", abilitySubs.Select(o => $"'{o.id}'"))})";
  490. }
  491. await foreach (var item in client.GetContainer("TEAMModelOS", "Normal")
  492. .GetItemQueryIterator<Ability>(queryText: $"select c.id,c.name,c.currency,c.no,c.dimension,c.hour,c.stds from c {insql} ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{area.standard}") }))
  493. {
  494. abilities.Add(item);
  495. }
  496. Currency currency= new Currency();
  497. Currency currencyAll = new Currency();
  498. abilitySubs.ForEach(item => {
  499. int currencyInt = item.from == 1 ? 1 : 0;
  500. Ability ability = abilities.Find(x=>x.id.Equals(item.id));
  501. if (ability != null) {
  502. if (ability != null)
  503. {
  504. currencyInt = item.from == 0 ? ability.currency : 1;
  505. }
  506. else
  507. {
  508. currencyInt = 0;
  509. }
  510. if (item.uploads.IsNotEmpty())
  511. {
  512. if (currencyInt == 1)
  513. {
  514. currency.uploadDone += item.uploads.Count;
  515. }
  516. currencyAll.uploadDone += item.uploads.Count;
  517. }
  518. if (item.exerciseScore > 0)
  519. {
  520. if (currencyInt == 1)
  521. {
  522. currency.exerciseAbility += 1;
  523. currency.learnAbility += item.abilityCount;
  524. }
  525. currencyAll.exerciseAbility += 1;
  526. currencyAll.learnAbility += item.abilityCount;
  527. }
  528. List<TeacherHprecord> hprecords = new List<TeacherHprecord>();
  529. TeacherAility teacherAility = new Models.TeacherAility
  530. {
  531. id = ability.id,
  532. currency = currencyInt,
  533. no = ability.no,
  534. name = ability.name,
  535. dimension = ability.dimension,
  536. zpscore = item.self,
  537. hprecord = hprecords,
  538. uploadHas = item.uploads.Count
  539. };
  540. if (file != null)
  541. {
  542. long view = 0;
  543. file.fileRecords.ForEach(record => {
  544. var abilityVideo = record.files.FindAll(x => x.abilityId.Equals(item.id));
  545. if (abilityVideo.IsNotEmpty())
  546. {
  547. view += record.view;
  548. }
  549. });
  550. //能力点学时限制
  551. int limit = ability.hour * setting.lessonMinutes;
  552. //如果超过 8* 45分钟学时,则直接赋值360(limit)分钟。
  553. view = view / 60;
  554. view = view > limit ? limit : view;
  555. teacherAility.videoTime = view;
  556. teacherAility.limitTime = ability.hour;
  557. teacherAility.onlineTime = view / setting.lessonMinutes;
  558. }
  559. if (item.otherScore.IsNotEmpty())
  560. {
  561. var schoolScore = item.otherScore.Where(x => x.roleType.Equals("school")).FirstOrDefault();
  562. if (schoolScore != null && schoolScore.score >= 0)
  563. {
  564. teacherAility.xzscore = schoolScore.score;
  565. teacherAility.xztime = schoolScore.time;
  566. teacherAility.xztmdid = schoolScore.tmdid;
  567. teacherAility.xztmdname = schoolScore.tmdname;
  568. }
  569. var hprecord = item.otherScore.FindAll(x => x.roleType.Equals("member")).Select(y => new TeacherHprecord { tmdid = y.tmdid, tmdname = y.tmdname, score = y.score });
  570. if (hprecord != null)
  571. {
  572. var no = hprecord.Where(x => x.score == 0) != null ? hprecord.Where(x => x.score == 0).Count() : 0;
  573. var hg = hprecord.Where(x => x.score == 1) != null ? hprecord.Where(x => x.score == 1).Count() : 0;
  574. var yx = hprecord.Where(x => x.score == 2) != null ? hprecord.Where(x => x.score == 2).Count() : 0;
  575. if (no == hg && hg == yx && no == 0)
  576. {
  577. teacherAility.hpscore = -1;
  578. }
  579. else if (no == hg && hg == yx && no != 0)
  580. {
  581. teacherAility.hpscore = 2;
  582. }
  583. else
  584. {
  585. bool ok = false;
  586. List<int> arr = new List<int>() { yx, hg, no };
  587. int max = arr.Max();
  588. if (max == yx && !ok)
  589. {
  590. teacherAility.hpscore = 2;
  591. ok = true;
  592. }
  593. if (max == hg && !ok)
  594. {
  595. teacherAility.hpscore = 1;
  596. ok = true;
  597. }
  598. if (max == no && !ok)
  599. {
  600. teacherAility.hpscore = 0;
  601. ok = true;
  602. }
  603. }
  604. teacherAility.hprecord.AddRange(hprecord);
  605. }
  606. }
  607. if (currencyInt == 1)
  608. {
  609. currency.subCount += 1;
  610. currency.uploadTotal += ability.stds.FindAll(x => x.task.IsNotEmpty()).Select(y => y.task).Count();
  611. currency.teacherAilities.Add(teacherAility);
  612. }
  613. currencyAll.subCount += 1;
  614. currencyAll.uploadTotal += ability.stds.FindAll(x => x.task.IsNotEmpty()).Select(y => y.task).Count();
  615. currencyAll.teacherAilities.Add(teacherAility);
  616. }
  617. });
  618. train.currency = currency;
  619. train.currencyAll = currencyAll;
  620. train.currency.videoTime = train.currency.teacherAilities.Select(x => x.videoTime).Sum();
  621. train.currencyAll.videoTime= train.currencyAll.teacherAilities.Select(x => x.videoTime).Sum();
  622. //如果总分钟数超过20学时,则直接复制20学时。
  623. var videoTime = (int)train.currency.videoTime / setting.lessonMinutes;
  624. train.onlineTime = videoTime > setting.onlineTime ? setting.onlineTime:videoTime;
  625. var bhg = train.currency.teacherAilities.FindAll(x => x.xzscore > 0);
  626. if (bhg.IsNotEmpty()&& bhg.Count == train.currency.subCount)
  627. {
  628. ///要全部合格才能获得学时。
  629. train.currency.submitTime = setting.submitTime;
  630. train.currencyAll.submitTime = setting.submitTime;
  631. }
  632. return train;
  633. }
  634. }
  635. }