ThirdService.cs 38 KB

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