ThirdService.cs 37 KB

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