StatisticsService.cs 30 KB

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