BatchAreaController.cs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Configuration;
  4. using Microsoft.Extensions.Options;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using TEAMModelOS.Models;
  10. using TEAMModelOS.SDK.DI;
  11. using TEAMModelOS.SDK.Models;
  12. using Azure.Cosmos;
  13. using System.Text.Json;
  14. using HTEXLib.COMM.Helpers;
  15. using TEAMModelOS.SDK.Models.Cosmos.Common;
  16. using TEAMModelOS.SDK.Models.Cosmos.BI;
  17. using Azure.Messaging.ServiceBus;
  18. using TEAMModelOS.SDK.Extension;
  19. using TEAMModelOS.SDK.Models.Service;
  20. using TEAMModelBI.Filter;
  21. using TEAMModelBI.Tool.Extension;
  22. using TEAMModelBI.Tool;
  23. using TEAMModelBI.Tool.Context;
  24. using TEAMModelBI.DI.BIAzureStorage;
  25. using Azure.Storage.Blobs.Models;
  26. using Azure;
  27. using Azure.Storage.Blobs.Specialized;
  28. using System.Net.Http;
  29. using System.Net.Http.Json;
  30. using System.Net;
  31. using TEAMModelOS.SDK;
  32. namespace TEAMModelBI.Controllers.BISchool
  33. {
  34. [Route("batcharea")]
  35. [ApiController]
  36. public class BatchAreaController : ControllerBase
  37. {
  38. private readonly AzureCosmosFactory _azureCosmos;
  39. private readonly DingDing _dingDing;
  40. private readonly Option _option;
  41. private readonly AzureStorageFactory _azureStorage;
  42. private readonly IConfiguration _configuration;
  43. private readonly NotificationService _notificationService;
  44. private readonly AzureServiceBusFactory _serviceBus;
  45. private readonly IHttpClientFactory _http;
  46. private readonly CoreAPIHttpService _coreAPIHttpService;
  47. public BatchAreaController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, NotificationService notificationService, AzureServiceBusFactory serviceBus, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService)
  48. {
  49. _azureCosmos = azureCosmos;
  50. _dingDing = dingDing;
  51. _azureStorage = azureStorage;
  52. _option = option?.Value;
  53. _configuration = configuration;
  54. _notificationService = notificationService;
  55. _serviceBus = serviceBus;
  56. _http = http;
  57. _coreAPIHttpService = coreAPIHttpService;
  58. }
  59. /// <summary>
  60. /// 查询所有的区域标准
  61. /// </summary>
  62. /// <returns></returns>
  63. [ProducesDefaultResponseType]
  64. [HttpPost("get-areas")]
  65. public async Task<IActionResult> GetArea(JsonElement jsonElement)
  66. {
  67. try
  68. {
  69. jsonElement.TryGetProperty("site", out JsonElement site);
  70. List<RecArea> areas = new();
  71. var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
  72. var azureClient = _azureCosmos.GetCosmosClient();
  73. if ($"{site}".Equals(BIConst.Global))
  74. {
  75. azureClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  76. table = _azureStorage.GetCloudTableClient(BIConst.Global).GetTableReference("IESLogin");
  77. }
  78. await foreach (var item in azureClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<RecArea>(queryText: $"select c.id,c.code,c.pk,c.name,c.provCode,c.provName,c.cityCode,c.cityName,c.standard,c.standardName,c.institution from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
  79. {
  80. areas.Add(item);
  81. }
  82. foreach (var recArea in areas)
  83. {
  84. recArea.schoolCount = await CommonFind.GetSqlValueCount(azureClient, "School", $"select value(count(c.id)) from c where c.areaId='{recArea.id}' and c.standard='{recArea.standard}'", "Base");
  85. List<AreaQuoteRecord> aqr = await table.QueryWhereString<AreaQuoteRecord>($"PartitionKey eq 'QuoteRecord' and areaId eq '{recArea.id}'");
  86. aqr.Sort((x, y) => y.RowKey.CompareTo(x.RowKey));
  87. await foreach (var item in azureClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<string>(queryText: $"select value(c.accessConfig) from c where c.id='{recArea.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("AreaSetting") }))
  88. {
  89. if (string.IsNullOrEmpty(item))
  90. recArea.cutArea = false;
  91. else
  92. recArea.cutArea = true;
  93. };
  94. }
  95. return Ok(new { state = 200, areas });
  96. }
  97. catch (Exception ex)
  98. {
  99. await _dingDing.SendBotMsg($"BI,{_option.Location} batcharea/get-areas \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  100. return BadRequest();
  101. }
  102. }
  103. /// <summary>
  104. /// 批量创区 新接口
  105. /// </summary>
  106. /// <param name="jsonElement"></param>
  107. /// <returns></returns>
  108. [ProducesDefaultResponseType]
  109. [AuthToken(Roles = "admin,rdc")]
  110. [HttpPost("batch-area")]
  111. public async Task<IActionResult> batchArea(JsonElement jsonElement)
  112. {
  113. try
  114. {
  115. if (!jsonElement.TryGetProperty("name", out JsonElement name)) return BadRequest();
  116. jsonElement.TryGetProperty("provCode", out JsonElement provCode);
  117. jsonElement.TryGetProperty("provName", out JsonElement provName);
  118. jsonElement.TryGetProperty("cityCode", out JsonElement cityCode);
  119. jsonElement.TryGetProperty("cityName", out JsonElement cityName);
  120. jsonElement.TryGetProperty("areaAdmin", out JsonElement areadAdmin);
  121. if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
  122. if (!jsonElement.TryGetProperty("standardName", out JsonElement standardName)) return BadRequest();
  123. jsonElement.TryGetProperty("institution", out JsonElement institution);
  124. jsonElement.TryGetProperty("oldId", out JsonElement _oldId);
  125. jsonElement.TryGetProperty("oldStandard", out JsonElement oldStandard);
  126. jsonElement.TryGetProperty("oldName", out JsonElement oldName);
  127. jsonElement.TryGetProperty("site", out JsonElement site);
  128. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  129. //操作记录实体
  130. var tempStandard = !string.IsNullOrEmpty($"{oldStandard}") && !string.IsNullOrEmpty($"{_oldId}") ? $"{oldStandard}" : "standard2";
  131. //var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
  132. var cosmosClient = _azureCosmos.GetCosmosClient();//数据库连接
  133. var tableClient = _azureStorage.GetCloudTableClient();
  134. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  135. ServiceBusClient serBusClient;
  136. try
  137. {
  138. serBusClient = _serviceBus.GetServiceBusClient();
  139. }
  140. catch
  141. {
  142. return Ok(new { state = 403, msg = "Functionn未启动,请联系管理员" });
  143. }
  144. var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");//秘钥地址
  145. if ($"{site}".Equals(BIConst.Global))
  146. {
  147. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  148. tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  149. blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", name: BIConst.Global);
  150. //serBusClient = _serviceBus.GetServiceBusClient(BIConst.Global); //暂未确定使用默认
  151. //activeTask = _configuration.GetValue<string>("GlobalAzure:ServiceBus:ActiveTask"); //暂未确定使用默认
  152. }
  153. var table = tableClient.GetTableReference("IESLogin");
  154. //查询新的是否存在
  155. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select value(c) from c where c.standard='{standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
  156. {
  157. if (item.standard.Equals($"{standard}"))
  158. return Ok(new { state = 1, message = "新创区的standard已存在请检查" });
  159. }
  160. //区级的ID
  161. string areaId = Guid.NewGuid().ToString();
  162. Area addArea = new Area()
  163. {
  164. id = areaId,
  165. code = $"Base-Area",
  166. name = $"{name}",
  167. provCode = $"{provCode}",
  168. provName = $"{provName}",
  169. cityCode = $"{cityCode}",
  170. cityName = $"{cityName}",
  171. standard = $"{standard}",
  172. standardName = $"{standardName}",
  173. institution = $"{institution}"
  174. };
  175. #region 区级管理员
  176. var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{areadAdmin}" } }, _option.Location, _configuration);
  177. if (coreUser == null || coreUser.id == null)
  178. return Ok(new { state = 404, msg = "未找到改账户的管理员" });
  179. //string tmdId = !string.IsNullOrEmpty(tempTmdId) ? tempTmdId : $"{areadAdmin}";
  180. Teacher teacher = null;
  181. try
  182. {
  183. //查询该教师是否存在
  184. teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{coreUser.id}", new PartitionKey("Base"));
  185. }
  186. catch
  187. {
  188. }
  189. if (teacher != null)
  190. {
  191. //教师存在,在该教师信息中添加要管理的学校信息
  192. teacher.areas.Add(new Teacher.TeacherArea { areaId = addArea.id, status = "join", name = addArea.name });
  193. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
  194. }
  195. else
  196. {
  197. teacher.id = coreUser.id;
  198. teacher.name = coreUser.name;
  199. teacher.picture = coreUser.picture;
  200. teacher.pk = "Base";
  201. teacher.code = "Base";
  202. teacher.size = 1;
  203. teacher.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  204. //教师存在,在该教师信息中添加要管理的学校信息
  205. teacher.areas.Add(new Teacher.TeacherArea { areaId = addArea.id, status = "join", name = addArea.name });
  206. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
  207. }
  208. #endregion
  209. //创建区域
  210. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync<Area>(addArea, new PartitionKey("Base-Area"));
  211. //保存引用记录
  212. await table.SaveOrUpdate<AreaQuoteRecord>(new AreaQuoteRecord() { PartitionKey = "QuoteRecord", RowKey = $"{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}", areaId = $"{areaId}", quoteId = $"{_oldId}", quoteName = $"{oldName}", standard = tempStandard });
  213. //消息分区键
  214. string partitionCode = "copyAbility-mark";
  215. #region 使用Function创区
  216. //string areaCode = "copyArea-mark";
  217. //BatchCopyAreaRelevant bCopyArea = new BatchCopyAreaRelevant()
  218. //{
  219. // tmdid = $"{_tmdId}",
  220. // tmdName = $"{_tmdName}",
  221. // codeKey = areaCode,
  222. // tmdIds = new List<string> { $"{_tmdId}"},
  223. // oldStandard = $"{oldStandard}",
  224. // oldId = $"{_oldId}",
  225. // standard = $"{standard}",
  226. // areaId = areaId,
  227. // cut="",
  228. //};
  229. //var messageBatchCopyArea = new ServiceBusMessage(bCopyArea.ToJsonString());
  230. //messageBatchCopyArea.ApplicationProperties.Add("name", "CopyAreaRelevant");
  231. //var activeTaskArea = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  232. //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTaskArea, messageBatchCopyArea);
  233. #endregion
  234. #region 旧的批量创区
  235. List<Task<ItemResponse<Ability>>> abilities = new List<Task<ItemResponse<Ability>>>(); //存储区域数据
  236. List<Task<ItemResponse<AbilityTask>>> abilityTasks = new List<Task<ItemResponse<AbilityTask>>>(); //存储章节
  237. if (!string.IsNullOrEmpty($"{oldStandard}") && !string.IsNullOrEmpty($"{_oldId}"))
  238. {
  239. //查询要复制区域的能力标准点
  240. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{oldStandard}") }))
  241. {
  242. if (!string.IsNullOrEmpty(item.blob))
  243. {
  244. item.blob = item.blob.Replace($"/{oldStandard}/", $"/{standard}/");
  245. };
  246. item.standard = $"{standard}";
  247. item.code = $"Ability-{standard}";
  248. item.school = $"{standard}";
  249. //添加区能力标准点
  250. abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{standard}")));
  251. }
  252. try
  253. {
  254. if (abilities.Count < 256)
  255. {
  256. await Task.WhenAll(abilities);
  257. }
  258. else
  259. {
  260. int pages = (abilities.Count + 255) / 256;
  261. for (int i = 0; i < pages; i++)
  262. {
  263. List<Task<ItemResponse<Ability>>> tempAbility = abilities.Skip((i) * 256).Take(256).ToList();
  264. await Task.WhenAll(tempAbility);
  265. }
  266. }
  267. }
  268. catch
  269. {
  270. return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
  271. }
  272. try
  273. {
  274. //微能力点
  275. await foreach (var atask in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{oldStandard}") }))
  276. {
  277. List<Tnode> tnodes = new List<Tnode>();
  278. foreach (Tnode tnode in atask.children)
  279. {
  280. if (tnode.rnodes != null)
  281. {
  282. List<Rnode> rnodes = new List<Rnode>();
  283. foreach (Rnode rnode in tnode.rnodes)
  284. {
  285. if (!string.IsNullOrEmpty($"{rnode.link}"))
  286. {
  287. rnode.link = rnode.link.Replace($"/{oldStandard}/", $"/{standard}/");
  288. }
  289. rnodes.Add(rnode);
  290. }
  291. tnode.rnodes = rnodes;
  292. }
  293. tnodes.Add(tnode);
  294. }
  295. atask.children = tnodes;
  296. atask.code = $"AbilityTask-{standard}";
  297. atask.standard = $"{standard}";
  298. atask.codeval = $"{standard}";
  299. //添加区能力标准点中的节点
  300. //abilityTasks.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{standard}")));
  301. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{standard}"));
  302. }
  303. }
  304. catch
  305. {
  306. return Ok(new { state = 200, msg = "创区成功,能力标准创建成功,微能力点复制失败,遗留数据影响!" });
  307. }
  308. //if (abilityTasks.Count > 0)
  309. //{
  310. // for (int i = 0; i < abilityTasks.Count; i++)
  311. // {
  312. // List<Task<ItemResponse<AbilityTask>>> tempAbilityTasks = abilityTasks.Skip((i)).Take(1).ToList();
  313. // await Task.WhenAll(tempAbilityTasks);
  314. // }
  315. //}
  316. //新政策文件
  317. await foreach (StandardFile standardFile in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<StandardFile>(queryText: $"select value(c) from c where c.id='{_oldId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StandardFile") }))
  318. {
  319. if (standardFile != null)
  320. {
  321. standardFile.standard = $"{standard}";
  322. standardFile.id = areaId;
  323. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(standardFile, new PartitionKey($"StandardFile"));
  324. }
  325. }
  326. //新的区域设置
  327. await foreach (AreaSetting areaSetting in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AreaSetting>(queryText: $"select value(c) from c where c.id='{_oldId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("AreaSetting") }))
  328. {
  329. if (areaSetting != null)
  330. {
  331. areaSetting.accessConfig = null;
  332. areaSetting.id = areaId;
  333. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(areaSetting, new PartitionKey($"AreaSetting"));
  334. }
  335. }
  336. }
  337. else
  338. {
  339. Area area = null;
  340. await foreach (var tempArea in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select value(c) from c where c.standard='standard2'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
  341. {
  342. area = tempArea;
  343. }
  344. if (area != null)
  345. {
  346. //查询要复制区域的能力标准点
  347. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{area.standard}") }))
  348. {
  349. if (!string.IsNullOrEmpty(item.blob))
  350. {
  351. item.blob = item.blob.Replace($"/{area.standard}/", $"/{standard}/");
  352. };
  353. item.standard = $"{standard}";
  354. item.code = $"Ability-{standard}";
  355. item.school = $"{standard}";
  356. //添加区能力标准点
  357. abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{standard}")));
  358. }
  359. try
  360. {
  361. if (abilities.Count < 256)
  362. {
  363. await Task.WhenAll(abilities);
  364. }
  365. else
  366. {
  367. int pages = (abilities.Count + 255) / 256;
  368. for (int i = 0; i < pages; i++)
  369. {
  370. List<Task<ItemResponse<Ability>>> tempAbility = abilities.Skip((i) * 256).Take(256).ToList();
  371. await Task.WhenAll(tempAbility);
  372. }
  373. }
  374. }
  375. catch
  376. {
  377. return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
  378. }
  379. try
  380. {
  381. //微能力点
  382. await foreach (var atask in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{area.standard}") }))
  383. {
  384. List<Tnode> tnodes = new List<Tnode>();
  385. foreach (Tnode tnode in atask.children)
  386. {
  387. if (tnode.rnodes != null)
  388. {
  389. List<Rnode> rnodes = new List<Rnode>();
  390. foreach (Rnode rnode in tnode.rnodes)
  391. {
  392. if (!string.IsNullOrEmpty($"{rnode.link}"))
  393. {
  394. rnode.link = rnode.link.Replace($"/{area.standard}/", $"/{standard}/");
  395. }
  396. rnodes.Add(rnode);
  397. }
  398. tnode.rnodes = rnodes;
  399. }
  400. tnodes.Add(tnode);
  401. }
  402. atask.children = tnodes;
  403. atask.code = $"AbilityTask-{standard}";
  404. atask.standard = $"{standard}";
  405. atask.codeval = $"{standard}";
  406. //添加区能力标准点中的节点
  407. //abilityTasks.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{standard}")));
  408. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{standard}"));
  409. }
  410. }
  411. catch
  412. {
  413. return Ok(new { state = 200, msg = "创区成功,能力标准创建成功,微能力点复制失败,遗留数据影响!" });
  414. }
  415. //if (abilityTasks.Count > 0)
  416. //{
  417. // for (int i = 0; i < abilityTasks.Count; i++)
  418. // {
  419. // List<Task<ItemResponse<AbilityTask>>> tempAbilityTasks = abilityTasks.Skip(i).Take(1).ToList();
  420. // await Task.WhenAll(tempAbilityTasks);
  421. // }
  422. //}
  423. //新政策文件
  424. await foreach (StandardFile standardFile in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<StandardFile>(queryText: $"select value(c) from c where c.id='{area.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StandardFile") }))
  425. {
  426. if (standardFile != null)
  427. {
  428. standardFile.standard = $"{standard}";
  429. standardFile.id = areaId;
  430. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(standardFile, new PartitionKey($"StandardFile"));
  431. }
  432. }
  433. //新的区域设置
  434. await foreach (AreaSetting areaSetting in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AreaSetting>(queryText: $"select value(c) from c where c.id='{area.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("AreaSetting") }))
  435. {
  436. if (areaSetting != null)
  437. {
  438. areaSetting.accessConfig = null;
  439. areaSetting.id = areaId;
  440. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(areaSetting, new PartitionKey($"AreaSetting"));
  441. }
  442. }
  443. }
  444. else return Ok(new { state = 201, message = "未找到默认能力点!" });
  445. }
  446. #endregion
  447. //执行复制操作
  448. BatchCopyFile batchCopyFile = new BatchCopyFile();
  449. batchCopyFile.blobCntr = "teammodelos";
  450. batchCopyFile.oldFileName = $"{oldStandard}";
  451. batchCopyFile.newFileName = $"{standard}";
  452. batchCopyFile.tmdid = $"{_tmdId}";
  453. batchCopyFile.tmdIds = new List<string> { $"{ _tmdId}" };
  454. batchCopyFile.codeKey = partitionCode;
  455. batchCopyFile.tmdName = $"{_tmdName}";
  456. var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
  457. messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
  458. //var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  459. try
  460. {
  461. //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile);
  462. await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile);
  463. }
  464. catch (Exception)
  465. {
  466. return Ok(new { state = 201, msg = "能力点复制成功,复制能力点的文件失败," });
  467. }
  468. //发送消息实体
  469. Notification notification = new Notification
  470. {
  471. hubName = "hita",
  472. type = "msg",
  473. from = $"BI:{_option.Location}:private",
  474. to = new List<string> { $"{ _tmdId}" },
  475. label = $"{partitionCode}_start",
  476. body = new { location = _option.Location, biz = partitionCode, tmdid = $"{_tmdId}", tmdname = $"{_tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
  477. expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
  478. };
  479. var notiUrl = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
  480. var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
  481. var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
  482. var location = _option.Location;
  483. await _notificationService.SendNotification(clientID, clientSecret, location, notiUrl, notification); //站内发送消息
  484. //保存操作记录
  485. //await _azureStorage.SaveBILog("area-add", $"{_tmdName}【{_tmdId}】已操作创区功能模块:{name},当前标准【{standard}】,复制的微能力点:{tempStandard}", _dingDing, httpContext: HttpContext);
  486. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "area-add", $"{_tmdName}【{_tmdId}】已操作创区功能模块:{name},当前标准【{standard}】,复制的微能力点:{tempStandard}", _dingDing, httpContext: HttpContext);
  487. return Ok(new { state = 200, area = addArea });
  488. }
  489. catch (Exception ex)
  490. {
  491. await _dingDing.SendBotMsg($"BI,{_option.Location} /batcharea/batch-area \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  492. return BadRequest();
  493. }
  494. }
  495. /// <summary>
  496. /// 创区后切换能力点, 先删除原来的能力点,后复制新的能力点
  497. /// </summary>
  498. /// <param name="jsonElement"></param>
  499. /// <returns></returns>
  500. [ProducesDefaultResponseType]
  501. [AuthToken(Roles = "admin,rdc")]
  502. [HttpPost("cut-standard")]
  503. public async Task<IActionResult> CutStandard(JsonElement jsonElement)
  504. {
  505. try
  506. {
  507. if (!jsonElement.TryGetProperty("oldId", out JsonElement _oldId)) return BadRequest();
  508. if (!jsonElement.TryGetProperty("oldStandard", out JsonElement _oldStandard)) return BadRequest();
  509. if (!jsonElement.TryGetProperty("newId", out JsonElement _newId)) return BadRequest();
  510. if (!jsonElement.TryGetProperty("newStandard", out JsonElement _newStandard)) return BadRequest();
  511. jsonElement.TryGetProperty("newName", out JsonElement newName);
  512. jsonElement.TryGetProperty("site", out JsonElement site);
  513. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  514. //操作记录实体
  515. string blobOrTable = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
  516. var tableClient = _azureStorage.GetCloudTableClient();
  517. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  518. var cosmosClient = _azureCosmos.GetCosmosClient();
  519. var serBusClient = _serviceBus.GetServiceBusClient();
  520. var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");//秘钥地址
  521. if ($"{site}".Equals(BIConst.Global))
  522. {
  523. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  524. tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  525. blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  526. serBusClient = _serviceBus.GetServiceBusClient(BIConst.Global); //暂未确定使用默认
  527. //activeTask = _configuration.GetValue<string>("GlobalAzure:ServiceBus:ActiveTask"); //暂未确定使用默认
  528. }
  529. var table = tableClient.GetTableReference("IESLogin");
  530. var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{_oldId}", new PartitionKey("AreaSetting"));
  531. if (responseSet.Status == 200)
  532. {
  533. using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
  534. AreaSetting delSet = fileJson.ToObject<AreaSetting>();
  535. if (!string.IsNullOrEmpty(delSet.accessConfig))
  536. return Ok(new { state = 401, msg = "区域已经规定了,不能切换能能力" });
  537. }
  538. //保存引用记录
  539. //await table.SaveOrUpdate<AreaQuoteRecord>(new AreaQuoteRecord() { PartitionKey = "QuoteRecord", RowKey = $"{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}", areaId = $"{_oldId}", quoteId = $"{_newId}", quoteName = $"{newName}", standard = $"{_newStandard}" });
  540. List<string> abilityIds = new List<string>(); //册别的ID集合
  541. //查询册别信息
  542. await foreach (var tempAbility in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{_oldStandard}") }))
  543. {
  544. abilityIds.Add(tempAbility.id); //查询出来册别ID添加册别ID集合
  545. }
  546. //删除册别
  547. if (abilityIds.IsNotEmpty())
  548. {
  549. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityIds, $"Ability-{_oldStandard}");
  550. }
  551. List<string> abilityTaskIds = new List<string>(); //章节ID集合
  552. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{_oldStandard}") }))
  553. {
  554. abilityTaskIds.Add(item.id); //查询出来的章节信息ID添加到战绩集合
  555. }
  556. //删除章节
  557. if (abilityTaskIds.IsNotEmpty())
  558. {
  559. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityTaskIds, $"AbilityTask-{_oldStandard}");
  560. }
  561. List<Task<ItemResponse<Ability>>> abilities = new List<Task<ItemResponse<Ability>>>(); //存储册别数据
  562. List<Task<ItemResponse<AbilityTask>>> abilityTasks = new List<Task<ItemResponse<AbilityTask>>>(); //存储章节
  563. //查询要复制区域的能力标准点
  564. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{_newStandard}") }))
  565. {
  566. if (!string.IsNullOrEmpty(item.blob))
  567. {
  568. item.blob = item.blob.Replace($"/{_newStandard}/", $"/{_oldStandard}/");
  569. };
  570. item.standard = $"{_oldStandard}";
  571. item.code = $"Ability-{_oldStandard}";
  572. item.school = $"{_oldStandard}";
  573. //添加区能力标准点
  574. abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}")));
  575. }
  576. try
  577. {
  578. if (abilities.Count < 256)
  579. {
  580. await Task.WhenAll(abilities);
  581. }
  582. else
  583. {
  584. int pages = (abilities.Count + 255) / 256;
  585. for (int i = 0; i < pages; i++)
  586. {
  587. List<Task<ItemResponse<Ability>>> tempAbility = abilities.Skip((i) * 256).Take(256).ToList();
  588. await Task.WhenAll(tempAbility);
  589. }
  590. }
  591. }
  592. catch
  593. {
  594. return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
  595. }
  596. try
  597. {
  598. //微能力点
  599. await foreach (var atask in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{_newStandard}") }))
  600. {
  601. List<Tnode> tnodes = new();
  602. foreach (Tnode tnode in atask.children)
  603. {
  604. if (tnode.rnodes != null)
  605. {
  606. List<Rnode> rnodes = new();
  607. foreach (Rnode rnode in tnode.rnodes)
  608. {
  609. if (!string.IsNullOrEmpty($"{rnode.link}"))
  610. {
  611. rnode.link = rnode.link.Replace($"/{_newStandard}/", $"/{_oldStandard}/");
  612. }
  613. rnodes.Add(rnode);
  614. }
  615. tnode.rnodes = rnodes;
  616. }
  617. tnodes.Add(tnode);
  618. }
  619. atask.children = tnodes;
  620. atask.code = $"AbilityTask-{_oldStandard}";
  621. atask.standard = $"{_oldStandard}";
  622. atask.codeval = $"{_oldStandard}";
  623. ////添加区能力标准点中的节点
  624. //abilityTasks.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}")));
  625. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}"));
  626. }
  627. }
  628. catch
  629. {
  630. return Ok(new { state = 200, msg = "创区成功,能力标准创建成功,微能力点复制失败,遗留数据影响!" });
  631. }
  632. StandardFile saveFile = new();
  633. //新政策文件
  634. await foreach (StandardFile standardFile in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<StandardFile>(queryText: $"select value(c) from c where c.id='{_newId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StandardFile") }))
  635. {
  636. if (standardFile != null)
  637. {
  638. standardFile.standard = $"{_oldStandard}";
  639. standardFile.id = $"{_oldId}";
  640. saveFile = standardFile;
  641. }
  642. }
  643. StandardFile tempFile = new();
  644. try
  645. {
  646. tempFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<StandardFile>(saveFile.id, new PartitionKey("StandardFile"));
  647. }
  648. catch
  649. {
  650. }
  651. if (tempFile.id != null)
  652. {
  653. if (tempFile.id.Equals(saveFile.id))
  654. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<StandardFile>(saveFile, saveFile.id, new PartitionKey("StandardFile")); //直接替换以前的数据
  655. else
  656. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
  657. }
  658. //新的区域设置
  659. AreaSetting saveSetting = new AreaSetting();
  660. await foreach (AreaSetting areaSetting in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AreaSetting>(queryText: $"select value(c) from c where c.id='{_newId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("AreaSetting") }))
  661. {
  662. if (areaSetting != null)
  663. {
  664. areaSetting.accessConfig = null;
  665. areaSetting.id = $"{_oldId}";
  666. saveSetting = areaSetting;
  667. }
  668. }
  669. AreaSetting tempSetting = new();
  670. try
  671. {
  672. tempSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>(saveSetting.id, new PartitionKey("StandardFile"));
  673. }
  674. catch
  675. {
  676. }
  677. if (tempSetting.id != null)
  678. {
  679. if (tempSetting.id.Equals(saveSetting.id))
  680. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<AreaSetting>(saveSetting, saveSetting.id, new PartitionKey($"AreaSetting")); //直接替换以前的数据
  681. else
  682. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting")); //需要删除原来的区域设置数据在进行添加
  683. }
  684. //发送消息分区键
  685. string partitionCode = "DelBeforeCopyAbility-mark";
  686. //执行复制操作
  687. BatchCopyFile batchCopyFile = new BatchCopyFile();
  688. batchCopyFile.blobCntr = "teammodelos";
  689. batchCopyFile.oldFileName = $"{_newStandard}";
  690. batchCopyFile.newFileName = $"{_oldStandard}";
  691. batchCopyFile.tmdid = $"{_tmdId}";
  692. batchCopyFile.tmdIds = new List<string> { $"{ _tmdId}" };
  693. batchCopyFile.codeKey = partitionCode;
  694. batchCopyFile.tmdName = $"{_tmdName}";
  695. var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
  696. messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
  697. try
  698. {
  699. //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile); //先执行删除操作,在执行复制 单一
  700. await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile); //先执行删除操作,在执行复制
  701. }
  702. catch (Exception)
  703. {
  704. return Ok(new { state = 201 ,msg = "能力点复制成功,复制能力点的文件失败," });
  705. }
  706. //发送消息实体
  707. Notification notification = new Notification
  708. {
  709. hubName = "hita",
  710. type = "msg",
  711. from = $"BI:{_option.Location}:private",
  712. to = new List<string> { $"{ _tmdId}" },
  713. label = $"{partitionCode}_start",
  714. body = new { location = _option.Location, biz = partitionCode, tmdid = $"{_tmdId}", tmdname = $"{_tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
  715. expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
  716. };
  717. var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
  718. var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
  719. var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
  720. var location = _option.Location;
  721. await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //发送站内发送消息
  722. //保存操作记录
  723. //await _azureStorage.SaveBILog("area-cut", $"{_tmdName}【{_tmdId}】已操作【{_oldStandard}】切换至{_newStandard}微能力点,复制标准:{_newStandard}", _dingDing, httpContext: HttpContext);
  724. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "area-cut", $"{_tmdName}【{_tmdId}】已操作【{_oldStandard}】切换至{_newStandard}微能力点,复制标准:{_newStandard}", _dingDing, httpContext: HttpContext);
  725. return Ok(new { state = 200 });
  726. }
  727. catch (Exception ex)
  728. {
  729. await _dingDing.SendBotMsg($"BI,{_option.Location} batcharea/cut-standard \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  730. return BadRequest();
  731. }
  732. }
  733. /// <summary>
  734. /// 删除区域和区域的册别、能力点、区域文件、区域设置
  735. /// </summary>
  736. /// <param name="jsonElement"></param>
  737. /// <returns></returns>
  738. [HttpPost("del-area")]
  739. public async Task<IActionResult> DelArea(JsonElement jsonElement)
  740. {
  741. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  742. if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
  743. jsonElement.TryGetProperty("site", out JsonElement site);
  744. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "teammodelos");
  745. var cosmosClient = _azureCosmos.GetCosmosClient();
  746. if ($"{site}".Equals(BIConst.Global))
  747. {
  748. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  749. blobClient = _azureStorage.GetBlobContainerClient(containerName: "teammodelos", BIConst.Global);
  750. }
  751. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{areaId}", new PartitionKey("Base-Area"));
  752. if (response.Status == 200)
  753. {
  754. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  755. Area area = json.ToObject<Area>();
  756. if (area.standard == $"{standard}")
  757. {
  758. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<Area>(area.id, new PartitionKey("Base-Area")); //删除区
  759. List<string> scIds = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c where c.areaId='{area.id}' and c.standard ='{area.standard}'", "Base");
  760. foreach (var item in scIds)
  761. {
  762. School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(item, new PartitionKey("Base"));
  763. school.areaId = "";
  764. school.standard = "";
  765. school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey("Base"));
  766. }
  767. List<string> abilityIds = new(); //册别的ID集合
  768. List<string> abilityTaskIds = new(); //章节ID集合
  769. //查询册别信息
  770. await foreach (var tempAbility in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{area.standard}") }))
  771. {
  772. abilityIds.Add(tempAbility.id); //查询出来册别ID添加册别ID集合
  773. }
  774. //删除册别
  775. if (abilityIds.IsNotEmpty())
  776. {
  777. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityIds, $"Ability-{area.standard}");
  778. }
  779. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{area.standard}") }))
  780. {
  781. abilityTaskIds.Add(item.id); //查询出来的章节信息ID添加到战绩集合
  782. }
  783. //删除章节
  784. if (abilityTaskIds.IsNotEmpty())
  785. {
  786. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityTaskIds, $"AbilityTask-{standard}");
  787. }
  788. //区域政策文件
  789. StandardFile delFile = new();
  790. var responseFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(area.id, new PartitionKey("StandardFile"));
  791. if(responseFile.Status == 200)
  792. {
  793. using var fileJson = await JsonDocument.ParseAsync(responseFile.ContentStream);
  794. delFile = fileJson.ToObject<StandardFile>();
  795. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<StandardFile>(delFile.id, new PartitionKey("StandardFile"));
  796. }
  797. //区域设置
  798. AreaSetting delSet = new();
  799. var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(area.id, new PartitionKey("AreaSetting"));
  800. if (responseSet.Status == 200)
  801. {
  802. using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
  803. delSet = fileJson.ToObject<AreaSetting>();
  804. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<AreaSetting>(delSet.id, new PartitionKey("AreaSetting"));
  805. }
  806. List<object> fileobj = new();
  807. //先删除原有的文件
  808. List<Task<Response<bool>>> DelList = new List<Task<Response<bool>>>();
  809. await foreach (BlobItem blobItem in blobClient.GetBlobsAsync(BlobTraits.None, BlobStates.None, $"yxpt/{area.standard}/"))
  810. {
  811. fileobj.Add(blobItem.Name);
  812. DelList.Add(blobClient.GetBlobBaseClient(blobItem.Name).DeleteIfExistsAsync());
  813. }
  814. if (DelList.Count <= 256)
  815. {
  816. await Task.WhenAll(DelList);
  817. }
  818. else
  819. {
  820. int pages = (DelList.Count + 255) / 256;
  821. for (int i = 0; i < pages; i++)
  822. {
  823. List<Task<Response<bool>>> delList = DelList.Skip((i) * 256).Take(256).ToList();
  824. await Task.WhenAll(delList);
  825. }
  826. }
  827. return Ok(new { state = 200,area, scIds, abilityIds, abilityTaskIds, delFile, delSet, fileobj });
  828. }
  829. else return Ok(new { state = 400, msg = "id和standard不匹配!" });
  830. }
  831. else return Ok(new { state = 404,msg="依据Id未找到该区!" });
  832. }
  833. /// <summary>
  834. /// 区域列表
  835. /// </summary>
  836. public record RecArea
  837. {
  838. public string id { get; set; }
  839. public string code { get; set; }
  840. public string pk { get; set; }
  841. public string name { get; set; }
  842. public string provCode { get; set; }
  843. public string provName { get; set; }
  844. public string cityCode { get; set; }
  845. public string cityName { get; set; }
  846. public string standard { get; set; }
  847. public string standardName { get; set; }
  848. public string institution { get; set; }
  849. public int schoolCount { get; set; }
  850. public bool cutArea { get; set; } = false;
  851. public List<AreaQuoteRecord> aquoteRec { get; set; } = new List<AreaQuoteRecord>();
  852. }
  853. }
  854. }