StatisticsService.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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. 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, yxtrain);
  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. record.score = studyRecord.status;
  337. if (record.score >= 0)
  338. {
  339. record.done = 1;
  340. }
  341. else {
  342. record.score = -1;
  343. }
  344. //取消转换
  345. //if (studyRecord.status == 1)
  346. //{
  347. // record.score = 1;
  348. // record.done = 1;
  349. //}
  350. //if (studyRecord.status == 0)
  351. //{
  352. // record.score = -1;
  353. //}
  354. //if (studyRecord.status == 2)
  355. //{
  356. // record.score = 0;
  357. // record.done = 1;
  358. //}
  359. }
  360. if (null != attachment)
  361. {
  362. record.url = attachment.url;
  363. record.upload = 1;
  364. record.hash = attachment.hash;
  365. record.size = attachment.size;
  366. }
  367. offlines.Add(record);
  368. }
  369. });
  370. train.offlineRecords= offlines;
  371. return train;
  372. }
  373. /// <summary>
  374. /// 课堂实录更新
  375. /// </summary>
  376. /// <param name="train"></param>
  377. /// <param name="setting"></param>
  378. /// <param name="area"></param>
  379. /// <param name="client"></param>
  380. /// <param name="_school"></param>
  381. /// <param name="_tmdid"></param>
  382. /// <returns></returns>
  383. public static async Task<TeacherTrain> DoTeacherClass(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid)
  384. {
  385. string code = $"ClassVideo-{_school}";
  386. ClassVideo classVideo = null;
  387. try { classVideo = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ClassVideo>($"{_tmdid}", new PartitionKey(code));
  388. } catch (Exception ex) {
  389. classVideo = null;
  390. }
  391. if (classVideo != null && classVideo.files.IsNotEmpty())
  392. {
  393. //2021.11.17 15:05,与J哥确认,取课堂实录第一个。前端也只show第一个视频。
  394. var files = classVideo.files[0];
  395. if (files.score > 0)
  396. {
  397. train.classTime= 5;
  398. }
  399. train.teacherClasses= new List<TeacherClass> { new Models.TeacherClass { url = files.url, score = files.score, hash = files.hash, name = files.name, size = files.size } };
  400. }
  401. return train;
  402. }
  403. public static async Task<TeacherTrain> DoTeacherAility(TeacherTrain train, AreaSetting setting,Area area , CosmosClient client,string _school,string _tmdid) {
  404. //视频播放
  405. List<string> abilityIds = new List<string> ();
  406. TeacherFile file = null;
  407. try
  408. {
  409. file = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<TeacherFile>(_tmdid, new PartitionKey($"TeacherFile-{_school}"));
  410. }
  411. catch (CosmosException )
  412. {
  413. file = new TeacherFile
  414. {
  415. id = _tmdid,
  416. code = $"TeacherFile-{_school}",
  417. pk = "TeacherFile",
  418. ttl = -1,
  419. };
  420. await client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<TeacherFile>(file, new PartitionKey($"TeacherFile-{_school}"));
  421. }
  422. List<AbilitySub> abilitySubs= new List<AbilitySub> ();
  423. //认证材料
  424. await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
  425. .GetItemQueryIterator<AbilitySub>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilitySub-{_school}-{_tmdid}") }))
  426. {
  427. abilitySubs.Add(item);
  428. }
  429. List<Ability> abilities = new List<Ability>();
  430. string insql = "";
  431. if (abilitySubs.IsNotEmpty()) {
  432. insql =$" where c.id in ({string.Join(",", abilitySubs.Select(o => $"'{o.id}'"))})";
  433. }
  434. await foreach (var item in client.GetContainer("TEAMModelOS", "Normal")
  435. .GetItemQueryIterator<Ability>(queryText: $"select value(c) from c {insql} ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{area.standard}") }))
  436. {
  437. abilities.Add(item);
  438. }
  439. Currency currency= new Currency();
  440. Currency currencyAll = new Currency();
  441. abilitySubs.ForEach(item => {
  442. int currencyInt = item.from == 1 ? 1 : 0;
  443. Ability ability = abilities.Find(x=>x.id.Equals(item.id));
  444. if (ability != null)
  445. {
  446. currencyInt = item.from == 0 ? ability.currency : 1;
  447. }
  448. else
  449. {
  450. currencyInt = 0;
  451. }
  452. if (item.uploads.IsNotEmpty())
  453. {
  454. if (currencyInt == 1)
  455. {
  456. currency.uploadDone += item.uploads.Count;
  457. }
  458. currencyAll.uploadDone += item.uploads.Count;
  459. }
  460. if (item.exerciseScore > 0)
  461. {
  462. if (currencyInt == 1)
  463. {
  464. currency.exerciseAbility += 1;
  465. currency.learnAbility += item.abilityCount;
  466. }
  467. currencyAll.exerciseAbility += 1;
  468. currencyAll.learnAbility += item.abilityCount;
  469. }
  470. List<TeacherHprecord> hprecords = new List<TeacherHprecord>();
  471. TeacherAility teacherAility = new Models.TeacherAility
  472. {
  473. id = ability.id,
  474. currency = currencyInt,
  475. no = ability.no,
  476. name = ability.name,
  477. dimension = ability.dimension,
  478. zpscore = item.self,
  479. hprecord = hprecords,
  480. uploadHas = item.uploads.Count
  481. };
  482. if (file != null)
  483. {
  484. long view = 0;
  485. file.fileRecords.ForEach(record => {
  486. var abilityVideo = record.files.FindAll(x => x.abilityId.Equals(item.id));
  487. if (abilityVideo.IsNotEmpty())
  488. {
  489. view += record.view;
  490. }
  491. });
  492. //能力点学时限制
  493. int limit = ability.hour * setting.lessonMinutes;
  494. //如果超过 8* 45分钟学时,则直接赋值360(limit)分钟。
  495. view = view / 60;
  496. view=view > limit ? limit : view;
  497. teacherAility.videoTime = view;
  498. teacherAility.limitTime = ability.hour;
  499. teacherAility.onlineTime = view / setting.lessonMinutes;
  500. }
  501. if (item.otherScore.IsNotEmpty())
  502. {
  503. var schoolScore = item.otherScore.Where(x => x.roleType.Equals("school")).FirstOrDefault();
  504. if (schoolScore != null && schoolScore.score >= 0)
  505. {
  506. teacherAility.xzscore = schoolScore.score;
  507. teacherAility.xztime= schoolScore.time;
  508. teacherAility.xztmdid = schoolScore.tmdid;
  509. teacherAility.xztmdname= schoolScore.tmdname;
  510. }
  511. var hprecord = item.otherScore.FindAll(x => x.roleType.Equals("member")).Select(y => new TeacherHprecord { tmdid = y.tmdid, tmdname = y.tmdname, score = y.score });
  512. if (hprecord != null)
  513. {
  514. var no = hprecord.Where(x => x.score == 0) != null ? hprecord.Where(x => x.score == 0).Count() : 0;
  515. var hg = hprecord.Where(x => x.score == 1) != null ? hprecord.Where(x => x.score == 1).Count() : 0;
  516. var yx = hprecord.Where(x => x.score == 2) != null ? hprecord.Where(x => x.score == 2).Count() : 0;
  517. if (no == hg && hg == yx && no == 0)
  518. {
  519. teacherAility.hpscore = -1;
  520. }
  521. else if (no == hg && hg == yx && no != 0)
  522. {
  523. teacherAility.hpscore = 2;
  524. }
  525. else
  526. {
  527. bool ok = false;
  528. List<int> arr = new List<int>() { yx, hg, no };
  529. int max = arr.Max();
  530. if (max == yx && !ok)
  531. {
  532. teacherAility.hpscore = 2;
  533. ok = true;
  534. }
  535. if (max == hg && !ok)
  536. {
  537. teacherAility.hpscore = 1;
  538. ok = true;
  539. }
  540. if (max == no && !ok)
  541. {
  542. teacherAility.hpscore = 0;
  543. ok = true;
  544. }
  545. }
  546. teacherAility.hprecord.AddRange(hprecord);
  547. }
  548. }
  549. if (currencyInt == 1)
  550. {
  551. currency.subCount += 1;
  552. currency.uploadTotal += ability.stds.FindAll(x => x.task.IsNotEmpty()).Select(y => y.task).Count();
  553. currency.teacherAilities.Add(teacherAility);
  554. }
  555. currencyAll.subCount += 1;
  556. currencyAll.uploadTotal += ability.stds.FindAll(x => x.task.IsNotEmpty()).Select(y => y.task).Count();
  557. currencyAll.teacherAilities.Add(teacherAility);
  558. });
  559. train.currency = currency;
  560. train.currencyAll = currencyAll;
  561. //如果总分钟数超过20学时,则直接复制20学时。
  562. var videoTime = (int)train.currency.videoTime / setting.lessonMinutes;
  563. train.onlineTime = videoTime > setting.onlineTime ? setting.onlineTime:videoTime;
  564. var bhg = train.currency.teacherAilities.FindAll(x => x.xzscore > 0);
  565. if (bhg.IsNotEmpty()&& bhg.Count == train.currency.subCount)
  566. {
  567. ///要全部合格才能获得学时。
  568. train.currency.submitTime = setting.submitTime;
  569. train.currencyAll.submitTime = setting.submitTime;
  570. }
  571. return train;
  572. }
  573. }
  574. }