BatchAreaController.cs 52 KB

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