ThirdService.cs 37 KB

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