BatchAreaController.cs 52 KB

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