ThirdService.cs 37 KB

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