StatisticsService.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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<TeacherTrain> > StatisticsArea(AreaSetting setting, Area area, CosmosClient client, DingDing _dingDing, HashSet<string> updates)
  44. {
  45. List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
  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 (var tarain in GetStatisticsSchool(schools, setting, area, client,_dingDing,updates))
  53. {
  54. teacherTrains.AddRange(tarain);
  55. }
  56. return teacherTrains;
  57. }
  58. private static async IAsyncEnumerable<List<TeacherTrain>> 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>> 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. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher")
  69. .GetItemQueryIterator<TeacherTrain>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{school}") })) {
  70. trains.Add(item);
  71. }
  72. if (updates != null) {
  73. foreach (var up in updates)
  74. {
  75. trains.ForEach(x => x.updateProperty.Add(up));
  76. }
  77. }
  78. var update = trains.FindAll(x => x.updateProperty.Count() > 0);
  79. var noupdate = trains.FindAll(x => x.updateProperty.Count() <=0);
  80. var members= yxtrain.SelectMany(x => x.members).ToList();
  81. var unStatistics = members.Select(x => x.id).Except(trains.Select(x => x.id));
  82. List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
  83. List<TeacherTrain> returnTrains = new List<TeacherTrain>();
  84. if (update.IsNotEmpty()) {
  85. teacherTrains.AddRange(update);
  86. }
  87. if (unStatistics != null) {
  88. foreach (string x in unStatistics) {
  89. var member = members.Find(y => y.id.Equals(x));
  90. teacherTrains.Add(new TeacherTrain
  91. {
  92. id = x,
  93. code = $"TeacherTrain-{school}",
  94. tmdid = x,
  95. name = member.name,
  96. picture=member.picture,
  97. school = school,
  98. updateProperty = new HashSet<string> { TeacherAility,TeacherClass,OfflineRecord }
  99. });
  100. }
  101. }
  102. List<Study> studies = new List<Study>();
  103. await foreach (var item in client.GetContainer("TEAMModelOS", "Common")
  104. .GetItemQueryIterator<Study>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{school}") }))
  105. {
  106. studies.Add(item);
  107. }
  108. returnTrains = await GetStatisticsTeacher(teacherTrains, setting, area, client,studies);
  109. //await foreach (var tarain in GetStatisticsTeacher(teacherTrains, setting, area, client))
  110. //{
  111. // returnTrains.Add(tarain);
  112. //}
  113. if (noupdate.IsNotEmpty())
  114. {
  115. returnTrains.AddRange(noupdate);
  116. }
  117. returnTrains.ForEach(x => x.groupName = members.Find(y => y.id.Equals(x.id))?.groupName);
  118. return returnTrains;
  119. }
  120. private static async Task<List<TeacherTrain>> GetStatisticsTeacher(List<TeacherTrain> trains, AreaSetting setting, Area area, CosmosClient client, List<Study> studies)
  121. {
  122. List<Task<TeacherTrain>> teachers = new List<Task<TeacherTrain>>();
  123. foreach (var train in trains)
  124. {
  125. teachers.Add(StatisticsTeacher(train, setting, area, client,studies)); //yield return await StatisticsTeacher( train, setting, area, client);
  126. }
  127. await Task.WhenAll(teachers);
  128. return trains;
  129. }
  130. public static async Task<TeacherTrain> StatisticsTeacher(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client,List<Study> studies) {
  131. string _school = train.school;
  132. string _tmdid = train.tmdid;
  133. // TeacherTrain teacher_train = null;
  134. List<Task<TeacherTrain>> teachers = new List<Task<TeacherTrain>>();
  135. if (train.updateProperty.Count > 0) {
  136. foreach (string property in train.updateProperty) {
  137. teachers.Add(DoProperty(train.updateProperty, property, setting, area, client, train,studies));
  138. }
  139. await Task.WhenAll(teachers);
  140. }
  141. //每次都统计活动相关的数据。
  142. train= await DoActivity(train, setting, area, client, _school, _tmdid);
  143. train.totalTime = train.onlineTime + train.classTime + train.currency.submitTime + train.offlineTime;
  144. await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<TeacherTrain>(train, new PartitionKey($"TeacherTrain-{_school}"));
  145. return train;
  146. }
  147. private static async Task<TeacherTrain> DoProperty(HashSet<string> updateProperty,string property, AreaSetting setting, Area area, CosmosClient client, TeacherTrain train ,List<Study> studies )
  148. {
  149. string _school = train.school;
  150. string _tmdid = train.tmdid;
  151. switch (property) {
  152. case TeacherAility:
  153. train = await DoTeacherAility(train, setting, area, client, _school, _tmdid);
  154. train.updateProperty.Remove(TeacherAility);
  155. break;
  156. //课堂实录更新
  157. case TeacherClass:
  158. train = await DoTeacherClass(train, setting, area, client, _school, _tmdid);
  159. train.updateProperty.Remove(TeacherClass);
  160. break;
  161. //线下研修
  162. case OfflineRecord:
  163. train = await DoOfflineRecord(train, setting, area, client, _school, _tmdid,studies);
  164. train.updateProperty.Remove(OfflineRecord);
  165. break;
  166. default:
  167. train.updateProperty.Remove(property);
  168. break;
  169. }
  170. return train;
  171. }
  172. public static async Task<TeacherTrain> DoActivity(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid) {
  173. //问卷调查
  174. int surveyJoin=0;
  175. int voteJoin = 0;
  176. int examJoin = 0;
  177. int surveyDone = 0;
  178. int voteDone = 0;
  179. int examDone = 0;
  180. int surveyAreaJoin = 0;
  181. int voteAreaJoin = 0;
  182. int examAreaJoin = 0;
  183. int surveyAreaDone = 0;
  184. int voteAreaDone = 0;
  185. int examAreaDone = 0;
  186. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher")
  187. .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'Survey' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
  188. {
  189. if (!string.IsNullOrEmpty(item.owner))
  190. {
  191. if (item.owner.Equals("school"))
  192. {
  193. surveyJoin += 1;
  194. if (item.taskStatus > 0)
  195. {
  196. surveyDone += 1;
  197. }
  198. }
  199. else if (item.owner.Equals("area"))
  200. {
  201. surveyAreaJoin += 1;
  202. if (item.taskStatus > 0)
  203. {
  204. surveyAreaDone += 1;
  205. }
  206. }
  207. }
  208. }
  209. //评量检测
  210. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  211. .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'ExamLite' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
  212. {
  213. if (!string.IsNullOrEmpty(item.owner))
  214. {
  215. if (item.owner.Equals("school"))
  216. {
  217. examJoin += 1;
  218. if (item.taskStatus > 0)
  219. {
  220. examDone += 1;
  221. }
  222. }
  223. else if (item.owner.Equals("area"))
  224. {
  225. examAreaJoin += 1;
  226. if (item.taskStatus > 0)
  227. {
  228. examAreaDone += 1;
  229. }
  230. }
  231. }
  232. }
  233. //投票活动
  234. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  235. .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'Vote' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
  236. {
  237. if (!string.IsNullOrEmpty(item.owner))
  238. {
  239. if (item.owner.Equals("school"))
  240. {
  241. voteJoin += 1;
  242. if (item.taskStatus > 0)
  243. {
  244. voteDone += 1;
  245. }
  246. }
  247. else if (item.owner.Equals("area"))
  248. {
  249. voteAreaJoin += 1;
  250. if (item.taskStatus > 0)
  251. {
  252. voteAreaDone += 1;
  253. }
  254. }
  255. }
  256. }
  257. train.surveyJoin = surveyJoin;
  258. train.voteJoin = voteJoin;
  259. train.examJoin = examJoin;
  260. train.surveyDone = surveyDone;
  261. train.voteDone = voteDone;
  262. train.examDone = examDone;
  263. train.surveyAreaJoin = surveyAreaJoin;
  264. train.voteAreaJoin = voteAreaJoin;
  265. train.examAreaJoin = examAreaJoin;
  266. train.surveyAreaDone = surveyAreaDone;
  267. train.voteAreaDone = voteAreaDone;
  268. train.examAreaDone = examAreaDone;
  269. return train;
  270. }
  271. /// <summary>
  272. /// 课堂实录更新
  273. /// </summary>
  274. /// <param name="train"></param>
  275. /// <param name="setting"></param>
  276. /// <param name="area"></param>
  277. /// <param name="client"></param>
  278. /// <param name="_school"></param>
  279. /// <param name="_tmdid"></param>
  280. /// <returns></returns>
  281. public static async Task<TeacherTrain> DoOfflineRecord(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid, List<Study> studies) {
  282. //owner: school area
  283. //线下 学校研修活动
  284. List<StuActivity> activities = new List<StuActivity>();
  285. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  286. .GetItemQueryIterator<StuActivity>(queryText: $"select value(c) from c where c.type = 'Study' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
  287. {
  288. activities.Add(item);
  289. }
  290. string insql = "";
  291. if (studies.IsEmpty()) {
  292. studies = new List<Study>();
  293. if (activities.IsNotEmpty())
  294. {
  295. insql = $" where c.id in ({string.Join(",", activities.Select(o => $"'{o.id}'"))})";
  296. }
  297. await foreach (var item in client.GetContainer("TEAMModelOS", "Common")
  298. .GetItemQueryIterator<Study>(queryText: $"select value(c) from c {insql} ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{_school}") }))
  299. {
  300. studies.Add(item);
  301. }
  302. }
  303. List<StudyRecord> studyRecords = new List<StudyRecord>();
  304. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  305. .GetItemQueryIterator<StudyRecord>(queryText: $"select value(c) from c {insql} ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StudyRecord-{_tmdid}") }))
  306. {
  307. studyRecords.Add(item);
  308. }
  309. List<HomeworkRecord> homeworkRecords = new List<HomeworkRecord>();
  310. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  311. .GetItemQueryIterator<HomeworkRecord>(queryText: $"select value(c) from c {insql} ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"HomeworkRecord-{_tmdid}") }))
  312. {
  313. homeworkRecords.Add(item);
  314. }
  315. List<OfflineRecord> offlines = new List<OfflineRecord>();
  316. activities.ForEach(item => {
  317. Study study = studies.Find(y=>y.id.Equals(item.id));
  318. StudyRecord studyRecord= studyRecords.Find(y => y.id.Equals(item.id));
  319. HomeworkRecord homeworkRecord= homeworkRecords.Find(y => y.id.Equals(item.id));
  320. Attachment attachment = homeworkRecord!=null ? homeworkRecord.content.Find(x => x.prime):null;
  321. if (!string.IsNullOrEmpty(item.owner) && study != null )
  322. {
  323. OfflineRecord record = new OfflineRecord
  324. {
  325. id = item.id,
  326. name = item.name,
  327. done = item.taskStatus,
  328. owner = item.owner
  329. };
  330. record.sethour = study.hour;
  331. if (null != studyRecord)
  332. {
  333. //通过获得学时
  334. record.hour = studyRecord.status == 1 ? study.hour : 0;
  335. train.offlineTime = record.hour;
  336. if (studyRecord.status == 1)
  337. {
  338. record.score = 1;
  339. record.done = 1;
  340. }
  341. if (studyRecord.status == 0)
  342. {
  343. record.score = -1;
  344. }
  345. if (studyRecord.status == 2)
  346. {
  347. record.score = 0;
  348. record.done = 1;
  349. }
  350. }
  351. if (null != attachment)
  352. {
  353. record.url = attachment.url;
  354. record.upload = 1;
  355. record.hash = attachment.hash;
  356. record.size = attachment.size;
  357. }
  358. offlines.Add(record);
  359. }
  360. });
  361. train.offlineRecords= offlines;
  362. return train;
  363. }
  364. /// <summary>
  365. /// 课堂实录更新
  366. /// </summary>
  367. /// <param name="train"></param>
  368. /// <param name="setting"></param>
  369. /// <param name="area"></param>
  370. /// <param name="client"></param>
  371. /// <param name="_school"></param>
  372. /// <param name="_tmdid"></param>
  373. /// <returns></returns>
  374. public static async Task<TeacherTrain> DoTeacherClass(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid)
  375. {
  376. string code = $"ClassVideo-{_school}";
  377. ClassVideo classVideo = null;
  378. try { classVideo = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ClassVideo>($"{_tmdid}", new PartitionKey(code));
  379. } catch (Exception ex) {
  380. classVideo = null;
  381. }
  382. if (classVideo != null && classVideo.files.IsNotEmpty())
  383. {
  384. //2021.11.17 15:05,与J哥确认,取课堂实录第一个。前端也只show第一个视频。
  385. var files = classVideo.files[0];
  386. if (files.score > 0)
  387. {
  388. train.classTime += 5;
  389. }
  390. train.teacherClasses= new List<TeacherClass> { new Models.TeacherClass { url = files.url, score = files.score, hash = files.hash, name = files.name, size = files.size } };
  391. }
  392. return train;
  393. }
  394. public static async Task<TeacherTrain> DoTeacherAility(TeacherTrain train, AreaSetting setting,Area area , CosmosClient client,string _school,string _tmdid) {
  395. //视频播放
  396. List<string> abilityIds = new List<string> ();
  397. TeacherFile file = null;
  398. try
  399. {
  400. file = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<TeacherFile>(_tmdid, new PartitionKey($"TeacherFile-{_school}"));
  401. }
  402. catch (CosmosException )
  403. {
  404. file = new TeacherFile
  405. {
  406. id = _tmdid,
  407. code = $"TeacherFile-{_school}",
  408. pk = "TeacherFile",
  409. ttl = -1,
  410. };
  411. await client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<TeacherFile>(file, new PartitionKey($"TeacherFile-{_school}"));
  412. }
  413. List<AbilitySub> abilitySubs= new List<AbilitySub> ();
  414. //认证材料
  415. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  416. .GetItemQueryIterator<AbilitySub>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilitySub-{_school}-{_tmdid}") }))
  417. {
  418. abilitySubs.Add(item);
  419. }
  420. List<Ability> abilities = new List<Ability>();
  421. string insql = "";
  422. if (abilitySubs.IsNotEmpty()) {
  423. insql =$" where c.id in ({string.Join(",", abilitySubs.Select(o => $"'{o.id}'"))})";
  424. }
  425. await foreach (var item in client.GetContainer("TEAMModelOS", "Normal")
  426. .GetItemQueryIterator<Ability>(queryText: $"select value(c) from c {insql} ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{area.standard}") }))
  427. {
  428. abilities.Add(item);
  429. }
  430. Currency currency= new Currency();
  431. Currency currencyAll = new Currency();
  432. abilitySubs.ForEach(item => {
  433. int currencyInt = item.from == 1 ? 1 : 0;
  434. Ability ability = abilities.Find(x=>x.id.Equals(item.id));
  435. if (ability != null)
  436. {
  437. currencyInt = item.from == 0 ? ability.currency : 1;
  438. }
  439. else
  440. {
  441. currencyInt = 0;
  442. }
  443. if (item.uploads.IsNotEmpty())
  444. {
  445. if (currencyInt == 1)
  446. {
  447. currency.uploadDone += item.uploads.Count;
  448. }
  449. currencyAll.uploadDone += item.uploads.Count;
  450. }
  451. if (item.exerciseScore > 0)
  452. {
  453. if (currencyInt == 1)
  454. {
  455. currency.exerciseAbility += 1;
  456. currency.learnAbility += item.abilityCount;
  457. }
  458. currencyAll.exerciseAbility += 1;
  459. currencyAll.learnAbility += item.abilityCount;
  460. }
  461. List<TeacherHprecord> hprecords = new List<TeacherHprecord>();
  462. TeacherAility teacherAility = new Models.TeacherAility
  463. {
  464. id = ability.id,
  465. currency = currencyInt,
  466. no = ability.no,
  467. name = ability.name,
  468. dimension = ability.dimension,
  469. zpscore = item.self,
  470. hprecord = hprecords,
  471. uploadHas = item.uploads.Count
  472. };
  473. if (file != null)
  474. {
  475. long view = 0;
  476. file.fileRecords.ForEach(record => {
  477. var abilityVideo = record.files.FindAll(x => x.abilityId.Equals(item.id));
  478. if (abilityVideo.IsNotEmpty())
  479. {
  480. view += record.view;
  481. }
  482. });
  483. //能力点学时限制
  484. int limit = ability.hour * setting.lessonMinutes;
  485. //如果超过 8* 45分钟学时,则直接赋值360(limit)分钟。
  486. view = view/60 > limit ? limit : view;
  487. teacherAility.videoTime = view;
  488. teacherAility.limitTime = ability.hour;
  489. teacherAility.onlineTime = view / setting.lessonMinutes;
  490. }
  491. if (item.otherScore.IsNotEmpty())
  492. {
  493. var schoolScore = item.otherScore.Where(x => x.roleType.Equals("school")).FirstOrDefault();
  494. if (schoolScore != null && schoolScore.score > 0)
  495. {
  496. teacherAility.xzscore = schoolScore.score;
  497. }
  498. var hprecord = item.otherScore.FindAll(x => x.roleType.Equals("member")).Select(y => new TeacherHprecord { tmdid = y.tmdid, tmdname = y.tmdname, score = y.score });
  499. if (hprecord != null)
  500. {
  501. var no = hprecord.Where(x => x.score == 0) != null ? hprecord.Where(x => x.score == 0).Count() : 0;
  502. var hg = hprecord.Where(x => x.score == 1) != null ? hprecord.Where(x => x.score == 1).Count() : 0;
  503. var yx = hprecord.Where(x => x.score == 2) != null ? hprecord.Where(x => x.score == 2).Count() : 0;
  504. if (no == hg && hg == yx && no == 0)
  505. {
  506. teacherAility.hpscore = -1;
  507. }
  508. else if (no == hg && hg == yx && no != 0)
  509. {
  510. teacherAility.hpscore = 2;
  511. }
  512. else
  513. {
  514. bool ok = false;
  515. List<int> arr = new List<int>() { yx, hg, no };
  516. int max = arr.Max();
  517. if (max == yx && !ok)
  518. {
  519. teacherAility.hpscore = 2;
  520. ok = true;
  521. }
  522. if (max == hg && !ok)
  523. {
  524. teacherAility.hpscore = 1;
  525. ok = true;
  526. }
  527. if (max == no && !ok)
  528. {
  529. teacherAility.hpscore = 0;
  530. ok = true;
  531. }
  532. }
  533. teacherAility.hprecord.AddRange(hprecord);
  534. }
  535. }
  536. if (currencyInt == 1)
  537. {
  538. currency.subCount += 1;
  539. currency.uploadTotal += ability.stds.FindAll(x => x.task.IsNotEmpty()).Select(y => y.task).Count();
  540. currency.teacherAilities.Add(teacherAility);
  541. }
  542. currencyAll.subCount += 1;
  543. currencyAll.uploadTotal += ability.stds.FindAll(x => x.task.IsNotEmpty()).Select(y => y.task).Count();
  544. currencyAll.teacherAilities.Add(teacherAility);
  545. });
  546. train.currency = currency;
  547. train.currencyAll = currencyAll;
  548. //如果总分钟数超过20学时,则直接复制20学时。
  549. var videoTime = (int)train.currency.videoTime / setting.lessonMinutes;
  550. train.onlineTime = videoTime > setting.onlineTime ? setting.onlineTime:videoTime;
  551. var bhg = train.currency.teacherAilities.FindAll(x => x.xzscore > 0);
  552. if (bhg.IsNotEmpty()&& bhg.Count == train.currency.subCount)
  553. {
  554. ///要全部合格才能获得学时。
  555. train.currency.submitTime = setting.submitTime;
  556. train.currencyAll.submitTime = setting.submitTime;
  557. }
  558. return train;
  559. }
  560. }
  561. }