ThirdService.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. using Azure.Cosmos;
  2. using HTEXLib.COMM.Helpers;
  3. using Microsoft.Extensions.Configuration;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.Json;
  9. using System.Threading.Tasks;
  10. using TEAMModelOS.Models;
  11. using TEAMModelOS.SDK.DI;
  12. using TEAMModelOS.SDK.Extension;
  13. using static TEAMModelOS.SDK.Models.Teacher;
  14. namespace TEAMModelOS.SDK.Models
  15. {
  16. public static class ThirdService
  17. {
  18. //自动加入学校,加入培训名单,并根据学科进行分组
  19. public static async Task<ScTeacher> GetScTeacher(ScBindData scBind, Teacher teacher, AzureStorageFactory _azureStorage, AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, IConfiguration _configuration, DingDing _dingDing)
  20. {
  21. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  22. List<ScSchool> schools = await table.FindListByDict<ScSchool>(new Dictionary<string, object> { { "PartitionKey", "ScSchool" }, { "RowKey", scBind.sid } });
  23. List<ScTeacher> scTeachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "TID", scBind.userid }, { "RowKey", $"{scBind.pxid}" } });
  24. if (schools.IsNotEmpty())
  25. {
  26. ScSchool scSchool = schools[0];
  27. if (!string.IsNullOrEmpty(scSchool.schoolCode))
  28. {
  29. try
  30. {
  31. School school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(scSchool.schoolCode, new PartitionKey("Base"));
  32. if (school != null)
  33. {
  34. if (scTeachers.IsNotEmpty())
  35. {
  36. if (string.IsNullOrEmpty(scTeachers[0].tmdid))
  37. {
  38. scTeachers[0].tmdid = teacher.id;
  39. scTeachers[0].schoolCode = scSchool.schoolCode;
  40. scTeachers[0].areaId = school.areaId;
  41. await table.SaveOrUpdate<ScTeacher>(scTeachers[0]);
  42. }
  43. }
  44. var sc = teacher.schools.Find(x => x.schoolId.Equals(scSchool.schoolCode));
  45. if (sc != null)
  46. {
  47. if (string.IsNullOrEmpty(sc.status) || !sc.status.Equals("join"))
  48. {
  49. sc.status = "join";
  50. try
  51. {
  52. SchoolTeacher schoolTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolTeacher>(teacher.id, new PartitionKey($"Teacher-{school.id}"));
  53. if (schoolTeacher != null)
  54. {
  55. if (schoolTeacher.roles.IsEmpty() || !schoolTeacher.roles.Contains("teacher"))
  56. {
  57. schoolTeacher.roles = new List<string> { "teacher" };
  58. }
  59. schoolTeacher.status = "join";
  60. schoolTeacher.pk = "Teacher";
  61. schoolTeacher.name = teacher.name;
  62. schoolTeacher.picture = teacher.picture;
  63. schoolTeacher.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  64. schoolTeacher.ttl = -1;
  65. schoolTeacher.permissions = schoolTeacher.permissions.IsNotEmpty() ? schoolTeacher.permissions : new List<string>();
  66. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync(schoolTeacher);
  67. }
  68. }
  69. catch (CosmosException)
  70. {
  71. SchoolTeacher schoolTeacher = new SchoolTeacher
  72. {
  73. id = teacher.id,
  74. code = $"Teacher-{school.id}",
  75. roles = new List<string> { "teacher" },
  76. permissions = new List<string>(),
  77. pk = "Teacher",
  78. name = teacher.name,
  79. picture = teacher.picture,
  80. status = "join",
  81. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  82. ttl = -1
  83. };
  84. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync(schoolTeacher);
  85. }
  86. }
  87. }
  88. else
  89. {
  90. teacher.schools.Add(new Teacher.TeacherSchool { schoolId = school.id, name = school.name, areaId = school.areaId, picture = school.picture, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), status = "join" });
  91. SchoolTeacher schoolTeacher = new SchoolTeacher
  92. {
  93. id = teacher.id,
  94. code = $"Teacher-{school.id}",
  95. roles = new List<string> { "teacher" },
  96. permissions = new List<string>(),
  97. pk = "Teacher",
  98. name = teacher.name,
  99. picture = teacher.picture,
  100. status = "join",
  101. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  102. };
  103. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync(schoolTeacher);
  104. }
  105. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(teacher, teacher.id, new PartitionKey("Base"));
  106. //处理培训名单
  107. StringBuilder queryText = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='yxtrain'");
  108. List<GroupList> yxtrain = new List<GroupList>();
  109. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: queryText.ToString(),
  110. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{scSchool.schoolCode}") }))
  111. {
  112. yxtrain.Add(item);
  113. }
  114. if (yxtrain.IsNotEmpty())
  115. {
  116. string nickname = teacher.name;
  117. string groupName = null;
  118. string groupId = Guid.NewGuid().ToString();
  119. if (scTeachers.IsNotEmpty())
  120. {
  121. groupName = scTeachers[0].TeacherXK;
  122. nickname = scTeachers[0].TeacherName;
  123. if (!string.IsNullOrEmpty(groupName))
  124. {
  125. var mebers = yxtrain.SelectMany(x => x.members).Where(y => !string.IsNullOrEmpty(y.groupName) && y.groupName.Equals(groupName));
  126. if (mebers != null && mebers.Count() > 0)
  127. {
  128. groupId = mebers.First().groupId;
  129. }
  130. }
  131. else { groupId = null; }
  132. }
  133. else { groupId = null; }
  134. var meber = yxtrain.SelectMany(x => x.members).Where(y => y.id.Equals(teacher.id));
  135. //不在研修名单
  136. if (meber == null || !meber.Any())
  137. {
  138. yxtrain[0].members.Add(new Member { id = teacher.id, type = 1, groupId = groupId, groupName = groupName,nickname= nickname });
  139. await GroupListService.UpsertList(yxtrain[0], _azureCosmos, _configuration, _serviceBus);
  140. }
  141. else
  142. {
  143. if (string.IsNullOrEmpty(meber.First().groupId) || string.IsNullOrEmpty(meber.First().groupName))
  144. {
  145. meber.ToList().ForEach(x => { x.groupId = groupId; x.groupName = groupName;x.nickname = string.IsNullOrWhiteSpace(x.nickname)? nickname:x.nickname; });
  146. await GroupListService.UpsertList(yxtrain[0], _azureCosmos, _configuration, _serviceBus);
  147. }
  148. }
  149. }
  150. else
  151. {
  152. string nickname = teacher.name;
  153. string groupName = null;
  154. if (scTeachers.IsNotEmpty())
  155. {
  156. groupName = scTeachers[0].TeacherXK;
  157. nickname = scTeachers[0].TeacherName;
  158. }
  159. string groupId = null;
  160. if (!string.IsNullOrEmpty(groupName))
  161. {
  162. groupId = Guid.NewGuid().ToString();
  163. }
  164. GroupList groupList = new()
  165. {
  166. id = Guid.NewGuid().ToString(),
  167. code = $"GroupList-{scSchool.schoolCode}",
  168. creatorId = teacher.id,
  169. type = "yxtrain",
  170. year = DateTimeOffset.UtcNow.Year,
  171. members = new List<Member> { new Member { id = teacher.id, type = 1, groupId = groupId, groupName = groupName, nickname = nickname } },
  172. scope = "school",
  173. school = scSchool.schoolCode,
  174. name = "研修名单",
  175. pk = "GroupList",
  176. ttl = -1
  177. };
  178. await GroupListService.UpsertList(groupList, _azureCosmos, _configuration, _serviceBus);
  179. }
  180. }
  181. }
  182. catch (Exception ex)
  183. {
  184. await _dingDing.SendBotMsg($"OS\n自动加入学校,加入研修名单出现异常:,{ex.Message}\n{ex.StackTrace}GetScTeacher", GroupNames.醍摩豆服務運維群組);
  185. }
  186. }
  187. }
  188. return null;
  189. }
  190. public static async Task<(string accessConfig, Area area, AreaSetting setting)> GetAccessConfig(CosmosClient client, string standard)
  191. {
  192. Area area = null;
  193. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").
  194. GetItemQueryIterator<Area>($"select value(c) from c where c.standard='{standard}'", requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base-Area") }))
  195. {
  196. area = item;
  197. break;
  198. }
  199. AreaSetting setting = null;
  200. if (area != null)
  201. {
  202. try
  203. {
  204. setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>(area.id, new PartitionKey("AreaSetting"));
  205. }
  206. catch (CosmosException)
  207. {
  208. setting = null;
  209. }
  210. }
  211. if (setting == null || string.IsNullOrEmpty(setting.accessConfig))
  212. {
  213. return (null, null, null);
  214. }
  215. else
  216. {
  217. return (setting.accessConfig, area, setting);
  218. }
  219. }
  220. public static async Task<List<Ability>> GetDiagnosisList(CosmosClient client, string standard, DingDing dingDing, AreaSetting setting, HttpTrigger httpTrigger, Teacher teacher, TEAMModelOS.Models.Option _option, AzureStorageFactory _azureStorage)
  221. {
  222. List<string> abilityNos = new();
  223. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  224. setting.accessConfig.ToObject<JsonElement>().TryGetProperty("config", out JsonElement _config);
  225. if ($"{_config}".Equals("scsyxpt"))
  226. {
  227. var binds = teacher.binds.FindAll(x => x.type.Equals("scsyxpt"));
  228. var datas = binds.SelectMany(x => x.data).Where(y => y.Contains("scsyxpt"));
  229. HashSet<string> pxids = new();
  230. if (datas != null)
  231. {
  232. datas.ToList().ForEach(x =>
  233. {
  234. var data = x.ToObject<ScBindData>();
  235. if (!string.IsNullOrEmpty(data?.pxid))
  236. {
  237. pxids.Add(data.pxid);
  238. }
  239. });
  240. }
  241. foreach (var pxid in pxids)
  242. {
  243. List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "PXID", pxid } });
  244. Dictionary<string, object> dict = new();
  245. if (teachers.IsNotEmpty())
  246. {
  247. dict = new Dictionary<string, object>() { { "accessConfig", setting.accessConfig }, { "pxid", pxid }, { "areaId", setting.id }, { "schoolCode", teachers[0].schoolCode } };
  248. }
  249. else
  250. {
  251. dict = new Dictionary<string, object>() { { "accessConfig", setting.accessConfig }, { "pxid", pxid }, { "areaId", setting.id } };
  252. }
  253. (int status, string json) = await httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetDiagnosisListByProject_V2");
  254. if (status == 200)
  255. {
  256. List<string> nos = json.ToObject<List<string>>();
  257. if (nos.IsNotEmpty())
  258. {
  259. abilityNos.AddRange(nos);
  260. }
  261. }
  262. }
  263. }
  264. //获取能力点
  265. List<Ability> abilities = null;
  266. if (abilityNos.IsNotEmpty())
  267. {
  268. abilities = new List<Ability>();
  269. StringBuilder sql = new StringBuilder($"select value(c) from c where c.no in ({string.Join(",", abilityNos.Select(x => $"'{x}'"))})");
  270. await foreach (var item in client.GetContainer("TEAMModelOS", "Normal")
  271. .GetItemQueryIterator<Ability>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{standard}") }))
  272. {
  273. abilities.Add(item);
  274. }
  275. }
  276. return abilities;
  277. }
  278. public static async Task<string> SchoolDataPush( AreaSetting setting, HttpTrigger httpTrigger, List<string> pushTeachers, Option _option, string school)
  279. {
  280. setting.accessConfig.ToObject<JsonElement>().TryGetProperty("config", out JsonElement _config);
  281. if ($"{_config}".Equals("scsyxpt")) {
  282. Dictionary<string, object> dict = new Dictionary<string, object>() { { "accessConfig", setting.accessConfig }, { "pushTeachers", pushTeachers }, { "school", school } };
  283. (int status, string json) = await httpTrigger.RequestHttpTrigger(dict, _option.Location, "SchoolDataPush");
  284. return json;
  285. }
  286. return null ;
  287. }
  288. //5.3.1.22学员校本教研PDF(每人可以返回多条)批量回写-UploadSBTARPDFListV2
  289. public async static Task<(int t53122OK, List<KeyValuePair<string, string>> msgs)> check53122(TeacherTrain teacherTrain, List<KeyValuePair<string, string>> msgs,string school,
  290. string schoolPrefix,string sas, AzureStorageFactory _azureStorage)
  291. {
  292. int t53122OK = 1;
  293. if (teacherTrain.offlineRecords.Count <= 0)
  294. {
  295. t53122OK = 0;
  296. msgs.Add(new KeyValuePair<string, string>("offlineRecord-count", $"文件个数为0"));
  297. }
  298. var hasUrl = teacherTrain.offlineRecords.Where(x => !string.IsNullOrWhiteSpace(x.url) && x.size > 0);
  299. if (!hasUrl.Any())
  300. {
  301. t53122OK = 0;
  302. msgs.Add(new KeyValuePair<string, string>("offlineRecord-url", $"需要上传的校本研修作业至少有一个。"));
  303. }
  304. if (teacherTrain.offlineReport==null) {
  305. t53122OK = 0;
  306. msgs.Add(new KeyValuePair<string, string>("offlineReport", $"校本研修汇总报告未生成。"));
  307. }
  308. List<string> unexistUrl = new List<string>();
  309. foreach (var url in hasUrl) {
  310. string blobItem = url.url.Replace($"{schoolPrefix}/", "");
  311. bool Exist = await _azureStorage.GetBlobContainerClient(school).GetBlobClient(blobItem).ExistsAsync();
  312. if (!Exist)
  313. {
  314. unexistUrl.Add($"{url.url}?{sas}");
  315. }
  316. }
  317. if (unexistUrl.Any())
  318. {
  319. t53122OK = 0;
  320. msgs.Add(new KeyValuePair<string, string>("offlineRecord-url-unexist", $"校本研修文件不存在,{string.Join(" , " ,unexistUrl)}"));
  321. }
  322. //不需要检查每一个校本研修的文件记录。
  323. //teacherTrain.offlineRecords.ForEach(x => {
  324. // if (string.IsNullOrEmpty(x.url)) {
  325. // msgs.Add(new KeyValuePair<string, string>("offlineRecord-url", $"链接为空"));
  326. // }
  327. // if (x.size<=0)
  328. // {
  329. // msgs.Add(new KeyValuePair<string, string>("offlineRecord-size", $"文件大小"));
  330. // }
  331. //});
  332. return (t53122OK, msgs);
  333. }
  334. //5.3.1.17学员课堂实录批量回写-UploadKTSLList
  335. public async static Task<(int t53117OK, List<KeyValuePair<string, string>> msgs)> check53117(TeacherTrain teacherTrain, List<KeyValuePair<string, string>> msgs, string school,
  336. string schoolPrefix, string sas, AzureStorageFactory _azureStorage)
  337. {
  338. //校验 基本情况是否满足
  339. int t53117OK = 1;
  340. if (teacherTrain.classTime <= 0)
  341. {
  342. msgs.Add(new KeyValuePair<string, string>("classTime", $"未获得学时:{teacherTrain.classTime}"));
  343. t53117OK = 0;
  344. }
  345. if (teacherTrain.teacherClasses.Count() <= 0)
  346. {
  347. msgs.Add(new KeyValuePair<string, string>("teacherClasses", $"未上传课堂实录:{teacherTrain.teacherClasses.Count()}个视频"));
  348. t53117OK = 0;
  349. }
  350. teacherTrain.teacherClasses.ForEach(x => {
  351. if (string.IsNullOrWhiteSpace(x.url))
  352. {
  353. t53117OK = 0;
  354. msgs.Add(new KeyValuePair<string, string>("teacherClasses", $"课堂实录链接无效"));
  355. }
  356. });
  357. List<string> unexistUrl = new List<string>();
  358. foreach (var url in teacherTrain.teacherClasses)
  359. {
  360. string blobItem = url.url.Replace($"{schoolPrefix}/", "");
  361. bool Exist = await _azureStorage.GetBlobContainerClient(school).GetBlobClient(blobItem).ExistsAsync();
  362. if (!Exist)
  363. {
  364. unexistUrl.Add($"{url.url}?{sas}");
  365. }
  366. }
  367. if (unexistUrl.Any())
  368. {
  369. t53117OK = 0;
  370. msgs.Add(new KeyValuePair<string, string>("teacherClasses-url-unexist", $"课堂实录文件不存在,{string.Join(" , ", unexistUrl)}"));
  371. }
  372. return (t53117OK, msgs);
  373. }
  374. //5.3.1.12学员培训基本情况批量回写-UpdateTeacherListSituation
  375. public static (int t53112OK, List<KeyValuePair<string, string>> msgs) check53112(TeacherTrain teacherTrain, List<KeyValuePair<string, string>> msgs)
  376. {
  377. //校验 基本情况是否满足
  378. int t53112OK = 1;
  379. if (teacherTrain.finalScore < 0)
  380. {
  381. //总体认定结果0、未认定 1、合格 2、优秀 3、不合格 4、其他
  382. msgs.Add(new KeyValuePair<string, string>("finalScore", $"最终评定结果参数:{teacherTrain.finalScore}"));
  383. t53112OK = 0;
  384. }
  385. //if (string.IsNullOrEmpty(teacherTrain.summary) || teacherTrain.summary.Length > 300)
  386. //{
  387. // string msg = string.IsNullOrEmpty(teacherTrain.summary) ? "未填写" : teacherTrain.summary.Length > 300 ? "字数超过300." : "";
  388. // msgs.Add(new KeyValuePair<string, string>("summary", $"教师培训总结:{msg}"));
  389. // t53112OK = 0;
  390. //}
  391. if (!string.IsNullOrEmpty(teacherTrain.summary) && teacherTrain.summary.Length > 300)
  392. {
  393. //string msg = string.IsNullOrEmpty(teacherTrain.summary) ? "未填写" : teacherTrain.summary.Length > 300 ? "字数超过300." : "";
  394. msgs.Add(new KeyValuePair<string, string>("summary", $"教师培训总结:字数超过300."));
  395. t53112OK = 0;
  396. }
  397. if (teacherTrain.totalTime <= 0)
  398. {
  399. msgs.Add(new KeyValuePair<string, string>("totalTime", $"未获得学时:{teacherTrain.totalTime}"));
  400. t53112OK = 0;
  401. }
  402. return (t53112OK, msgs);
  403. }
  404. //5.3.1.13学员能力点测评结果批量回写-UpdateTeacherListDiagnosis
  405. public async static Task<(int t53113OK, List<KeyValuePair<string, string>> msgs, List<AbilitySub> abilitySubs, List<AbilitySub> allRightAbility)> check53113(AzureCosmosFactory _azureCosmos,TeacherTrain teacherTrain, ScTeacherDiagnosis diagnosis,
  406. List<KeyValuePair<string, string>> msgs, string school,
  407. string schoolPrefix, string sas, AzureStorageFactory _azureStorage)
  408. {
  409. //校验 基本情况是否满足
  410. int t53113OK = 1;
  411. List<AbilitySub> allRightAbility = new List<AbilitySub>();
  412. List<AbilitySub> abilitySubs = new List<AbilitySub>();
  413. if (teacherTrain.currency.videoTime < 0)
  414. {
  415. msgs.Add(new KeyValuePair<string, string>("videoTime", $"视频学习时长:{teacherTrain.currency.videoTime}"));
  416. t53113OK = 0;
  417. }
  418. if (teacherTrain.currency.submitTime < 0)
  419. {
  420. msgs.Add(new KeyValuePair<string, string>("submitTime", $"认证材料学习:{teacherTrain.currency.submitTime}"));
  421. t53113OK = 0;
  422. }
  423. if (teacherTrain.currency.teacherAilities.Count <= 0)
  424. {
  425. msgs.Add(new KeyValuePair<string, string>("teacherAilities", $"已学习能力点:0"));
  426. t53113OK = 0;
  427. }
  428. try {
  429. if (diagnosis != null)
  430. {
  431. if (!string.IsNullOrWhiteSpace(diagnosis.abilityNos))
  432. {
  433. List<string> nos = diagnosis.abilityNos.ToObject<List<string>>();
  434. if (nos.Count > 0 && teacherTrain.currency.teacherAilities.Count > 0)
  435. {
  436. var notin = nos.Except(teacherTrain.currency.teacherAilities.Select(x => x.no).Where(z => !string.IsNullOrWhiteSpace(z)));
  437. if (notin.Any())
  438. {
  439. msgs.Add(new KeyValuePair<string, string>("diagnosisNos", $"省平台勾选的能力点编号为学习完成:省平台:{string.Join(",", nos.OrderBy(x => x))}" + $" ,已学习:{string.Join(",", teacherTrain.currency.teacherAilities.Select(x => x.no).OrderBy(x => x))} "));
  440. t53113OK = 0;
  441. }
  442. else
  443. {
  444. string insql = "";
  445. if (teacherTrain.currency.teacherAilities.IsNotEmpty())
  446. {
  447. var abilites = teacherTrain.currency.teacherAilities.Where(c => !string.IsNullOrWhiteSpace(c.no) && nos.Contains(c.no));
  448. insql = $" where c.id in ({string.Join(",", abilites.Select(o => $"'{o.id}'"))})";
  449. }
  450. //认证材料
  451. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher")
  452. .GetItemQueryIterator<AbilitySub>(queryText: $"select value(c) from c {insql}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilitySub-{teacherTrain.school}-{teacherTrain.id}") }))
  453. {
  454. abilitySubs.Add(item);
  455. }
  456. if (abilitySubs.Count() <= 3)
  457. {
  458. teacherTrain.currency.teacherAilities.ForEach(x =>
  459. {
  460. var abilitySub = abilitySubs.Find(z => z.id.Equals(x.id));
  461. if (abilitySub == null || !abilitySub.uploads.Any())
  462. {
  463. t53113OK = 0;
  464. msgs.Add(new KeyValuePair<string, string>("uploads", $"未上传认证材料:{x.no},{x.name}"));
  465. }
  466. if (x.zpscore <= 0)
  467. {
  468. t53113OK = 0;
  469. msgs.Add(new KeyValuePair<string, string>("zpscore", $"认证材料,没有完成自评:{x.no},{x.name},{x.zpscore}"));
  470. }
  471. if (x.hpscore <= 0)
  472. {
  473. //t53113OK = 0;
  474. //如果只有三个,且互评为未评状态,则直接为合格。
  475. x.hpscore = 1;
  476. // msgs.Add(new KeyValuePair<string, string>("hpscore", $"认证材料,没有完成互评:{x.no},{x.name},{x.hpscore}"));
  477. }
  478. if (x.xzscore <= 0)
  479. {
  480. //t53113OK = 0;
  481. x.xzscore = 1;
  482. //msgs.Add(new KeyValuePair<string, string>("xzscore", $"认证材料,没有完成小组评:{x.no},{x.name},{x.xzscore}"));
  483. }
  484. });
  485. foreach (AbilitySub abilitySub in abilitySubs)
  486. {
  487. //当前能力点上传的文件是否完全有效
  488. bool isAllRight = true;
  489. List<string> urlUn = new List<string>();
  490. foreach (var subUpload in abilitySub.uploads)
  491. {
  492. foreach (var url in subUpload.urls)
  493. {
  494. string blobItem = url.url.Replace($"{schoolPrefix}/", "");
  495. bool Exist = await _azureStorage.GetBlobContainerClient(school).GetBlobClient(blobItem).ExistsAsync();
  496. if (!Exist)
  497. {
  498. isAllRight = false;
  499. urlUn.Add($"{url.url}?{sas}");
  500. }
  501. }
  502. }
  503. if (isAllRight)
  504. {
  505. allRightAbility.Add(abilitySub);
  506. }
  507. else
  508. {
  509. t53113OK = 0;
  510. var x = teacherTrain.currency.teacherAilities.Find(x => x.id.Equals(abilitySub.id));
  511. msgs.Add(new KeyValuePair<string, string>("uploads-url", $"{x.no},{x.name}上传的认证材料文件失效:{string.Join(" , ", urlUn)}"));
  512. }
  513. }
  514. }
  515. else
  516. {
  517. //一个都没上传
  518. if (!abilitySubs.SelectMany(upsl => upsl.uploads).Any())
  519. {
  520. t53113OK = 0;
  521. msgs.Add(new KeyValuePair<string, string>("uploads-all", $"没有上传认证材料。"));
  522. }
  523. else
  524. {
  525. //检查上传了认证材料的能力点,超过三个的。
  526. var uploaded = abilitySubs.FindAll(x => x.uploads.Count > 0);
  527. //不足三个的则需要记录
  528. if (uploaded.Count < 3)
  529. {
  530. t53113OK = 0;
  531. ///少于三个的,需要判断另外的不满足情况的
  532. abilitySubs.RemoveAll(x => x.uploads.Count > 0);
  533. abilitySubs.ForEach(ab => {
  534. var x = teacherTrain.currency.teacherAilities.Find(x => x.id.Equals(ab.id));
  535. if (x == null || !ab.uploads.Any())
  536. {
  537. t53113OK = 0;
  538. msgs.Add(new KeyValuePair<string, string>("uploads", $"未上传认证材料:{x.no},{x.name}"));
  539. }
  540. if (x.zpscore <= 0)
  541. {
  542. t53113OK = 0;
  543. msgs.Add(new KeyValuePair<string, string>("zpscore", $"认证材料,没有完成自评:{x.no},{x.name},{x.zpscore}"));
  544. }
  545. if (x.hpscore <= 0)
  546. {
  547. t53113OK = 0;
  548. //如果只有三个,且互评为未评状态,则直接为合格。
  549. x.hpscore = 1;
  550. msgs.Add(new KeyValuePair<string, string>("hpscore", $"认证材料,没有完成互评:{x.no},{x.name},{x.hpscore}"));
  551. }
  552. if (x.xzscore <= 0)
  553. {
  554. t53113OK = 0;
  555. msgs.Add(new KeyValuePair<string, string>("xzscore", $"认证材料,没有完成小组评:{x.no},{x.name},{x.xzscore}"));
  556. }
  557. });
  558. }
  559. //检查已经上传的文件是否正确。
  560. foreach (AbilitySub abilitySub in uploaded)
  561. {
  562. //当前能力点上传的文件是否完全有效
  563. bool isAllRight = true;
  564. List<string> urlUn = new List<string>();
  565. foreach (var subUpload in abilitySub.uploads)
  566. {
  567. foreach (var url in subUpload.urls)
  568. {
  569. string blobItem = url.url.Replace($"{schoolPrefix}/", "");
  570. bool Exist = await _azureStorage.GetBlobContainerClient(school).GetBlobClient(blobItem).ExistsAsync();
  571. if (!Exist)
  572. {
  573. isAllRight = false;
  574. urlUn.Add($"{url.url}?{sas}");
  575. }
  576. }
  577. }
  578. if (isAllRight)
  579. {
  580. allRightAbility.Add(abilitySub);
  581. }
  582. else
  583. {
  584. t53113OK = 0;
  585. var x = teacherTrain.currency.teacherAilities.Find(x => x.id.Equals(abilitySub.id));
  586. msgs.Add(new KeyValuePair<string, string>("uploads-url", $"{x.no},{x.name}上传的认证材料文件失效:{string.Join(" , ", urlUn)}"));
  587. }
  588. }
  589. }
  590. }
  591. if (t53113OK != 1)
  592. {
  593. msgs.Add(new KeyValuePair<string, string>("diagnosisNos", $"省平台勾选的能力点编号为学习完成:省平台:{string.Join(",", nos.OrderBy(x => x))}" + $" ,已学习:{string.Join(",", teacherTrain.currency.teacherAilities.Select(x => x.no).OrderBy(x => x))} "));
  594. }
  595. }
  596. }
  597. else
  598. {
  599. msgs.Add(new KeyValuePair<string, string>("teacherAilities", $"未同步省平台挑选的能力点"));
  600. t53113OK = 0;
  601. }
  602. }
  603. else
  604. {
  605. msgs.Add(new KeyValuePair<string, string>("teacherAilities", $"未同步省平台挑选的能力点"));
  606. t53113OK = 0;
  607. }
  608. }
  609. else
  610. {
  611. msgs.Add(new KeyValuePair<string, string>("teacherAilities", $"未同步省平台挑选的能力点"));
  612. t53113OK = 0;
  613. }
  614. } catch (Exception ex) {
  615. throw new Exception($"{ex.StackTrace},{ex.Message}");
  616. }
  617. if (allRightAbility.Count < 3)
  618. {
  619. t53113OK = 0;
  620. msgs.Add(new KeyValuePair<string, string>("uploads-count", $"完整上传且有效的认证材料的 能力点数量小于3,当前数量:{allRightAbility.Count}"));
  621. }
  622. return (t53113OK, msgs, abilitySubs, allRightAbility);
  623. }
  624. }
  625. }