StatisticsService.cs 29 KB

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