BatchAreaController.cs 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  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 TEAMModelBI.Filter;
  20. using TEAMModelBI.Tool.Extension;
  21. using TEAMModelBI.Tool;
  22. using Azure.Storage.Blobs.Models;
  23. using Azure;
  24. using Azure.Storage.Blobs.Specialized;
  25. using System.Net.Http;
  26. using System.Net.Http.Json;
  27. using System.Net;
  28. using TEAMModelOS.SDK;
  29. using TEAMModelOS.SDK.Context.BI;
  30. using TEAMModelOS.SDK.DI.CoreAPI;
  31. using System.Text;
  32. using DocumentFormat.OpenXml.Bibliography;
  33. using Microsoft.Extensions.Hosting;
  34. using Microsoft.AspNetCore.Hosting;
  35. using static TEAMModelBI.Controllers.RepairApi.InitialAreaController;
  36. using TEAMModelOS.SDK.Context.Constant;
  37. using TEAMModelOS.SDK.Models.Service.BI;
  38. namespace TEAMModelBI.Controllers.BINormal
  39. {
  40. [Route("batcharea")]
  41. [ApiController]
  42. public class BatchAreaController : ControllerBase
  43. {
  44. private readonly AzureCosmosFactory _azureCosmos;
  45. private readonly DingDing _dingDing;
  46. private readonly Option _option;
  47. private readonly AzureStorageFactory _azureStorage;
  48. private readonly IConfiguration _configuration;
  49. private readonly NotificationService _notificationService;
  50. private readonly AzureServiceBusFactory _serviceBus;
  51. private readonly IHttpClientFactory _http;
  52. private readonly CoreAPIHttpService _coreAPIHttpService;
  53. private readonly IWebHostEnvironment _environment; //读取文件
  54. public BatchAreaController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, NotificationService notificationService, AzureServiceBusFactory serviceBus, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService, IWebHostEnvironment hostingEnvironment)
  55. {
  56. _azureCosmos = azureCosmos;
  57. _dingDing = dingDing;
  58. _azureStorage = azureStorage;
  59. _option = option?.Value;
  60. _configuration = configuration;
  61. _notificationService = notificationService;
  62. _serviceBus = serviceBus;
  63. _http = http;
  64. _coreAPIHttpService = coreAPIHttpService;
  65. _environment = hostingEnvironment;
  66. }
  67. /// <summary>
  68. /// 查询所有的区域标准 //已对接
  69. /// </summary>
  70. /// <returns></returns>
  71. [ProducesDefaultResponseType]
  72. [HttpPost("get-areas")]
  73. public async Task<IActionResult> GetArea(JsonElement jsonElement)
  74. {
  75. try
  76. {
  77. jsonElement.TryGetProperty("id", out JsonElement id);
  78. jsonElement.TryGetProperty("name", out JsonElement name);
  79. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  80. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  81. int? pageSize = 100; //默认不指定返回大小
  82. string continuationToken = string.Empty; //返给前端分页token
  83. string pageToken = default;//接受前端的分页Tolen
  84. bool iscontinuation = false;//是否需要进行分页查询,默认不分页
  85. if (jsonElement.TryGetProperty("pageSize", out JsonElement jsonPageSize))
  86. {
  87. if (!jsonPageSize.ValueKind.Equals(JsonValueKind.Undefined) && !jsonPageSize.ValueKind.Equals(JsonValueKind.Null) && jsonPageSize.TryGetInt32(out int tempPageSize))
  88. {
  89. pageSize = tempPageSize;
  90. }
  91. }
  92. if (pageSize != null && pageSize.Value > 0)
  93. {
  94. iscontinuation = true;
  95. }
  96. if (jsonElement.TryGetProperty("contToken", out JsonElement ContToken))
  97. {
  98. pageToken = ContToken.GetString();
  99. }
  100. List<RecArea> areas = new();
  101. var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
  102. var cosmosClient = _azureCosmos.GetCosmosClient();
  103. ////分开部署,就不需要,一站多用时,取消注释
  104. //if ($"{site}".Equals(BIConst.Global))
  105. //{
  106. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  107. // table = _azureStorage.GetCloudTableClient(BIConst.Global).GetTableReference("IESLogin");
  108. //}
  109. StringBuilder areaSql = new($"select c.id,c.code,c.pk,c.name,c.provCode,c.provName,c.cityCode,c.cityName,c.standard,c.standardName,c.institution,c.updateTime,c.quoteId from c");
  110. if (!string.IsNullOrEmpty($"{id}") && string.IsNullOrEmpty($"{name}"))
  111. areaSql.Append($" where c.id='{id}'");
  112. if (string.IsNullOrEmpty($"{id}") && !string.IsNullOrEmpty($"{name}"))
  113. areaSql.Append($" where Contains(c.name,'{name}')");
  114. if (!string.IsNullOrEmpty($"{tmdId}"))
  115. {
  116. List<string> schoolIds = new();
  117. schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}", roles: "assist", isMany: true);
  118. if (schoolIds.Count > 0)
  119. {
  120. string scsSql = BICommonWay.ManyScSql("c.id", schoolIds);
  121. StringBuilder scAreaIdSql = new($"select distinct value(c.areaId) from c where c.pk='School'");
  122. scAreaIdSql.Append($" and {scsSql} and (c.areaId!='' or c.areaId!='' or IS_DEFINED(c.areaId) = false)");
  123. List<string> areaIds = await CommonFind.GetValueSingle(cosmosClient, "School", scAreaIdSql.ToString(), "Base");
  124. if (areaIds.Count > 0)
  125. areaSql.Append(BICommonWay.ManyScSql(" where c.id", areaIds));
  126. }
  127. }
  128. await foreach (var itemArea in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryStreamIterator(queryText: areaSql.ToString(), continuationToken: pageToken, requestOptions: new QueryRequestOptions() { MaxItemCount = pageSize, PartitionKey = new PartitionKey("Base-Area") }))
  129. {
  130. using var json = await JsonDocument.ParseAsync(itemArea.ContentStream);
  131. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
  132. {
  133. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  134. {
  135. areas.Add(obj.ToObject<RecArea>());
  136. }
  137. if (iscontinuation)
  138. {
  139. continuationToken = itemArea.GetContinuationToken();
  140. break;
  141. }
  142. }
  143. }
  144. //areas.ForEach(async area =>
  145. //{
  146. // area.schoolCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(count(c.id)) from c where c.areaId='{area.id}' and c.standard='{area.standard}'", "Base");
  147. // area.aquoteRec = await table.QueryWhereString<AreaQuoteRecord>($"PartitionKey eq 'QuoteRecord' and areaId eq '{area.id}'");
  148. // //List<AreaQuoteRecord> aqr = await table.QueryWhereString<AreaQuoteRecord>($"PartitionKey eq 'QuoteRecord' and areaId eq '{area.id}'");
  149. // //aqr.Sort((x, y) => y.RowKey.CompareTo(x.RowKey));
  150. // await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<string>(queryText: $"select value(c.accessConfig) from c where c.id='{area.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("AreaSetting") }))
  151. // {
  152. // if (string.IsNullOrEmpty(item))
  153. // area.cutArea = false;
  154. // else
  155. // area.cutArea = true;
  156. // };
  157. //});
  158. foreach (var area in areas)
  159. {
  160. //select value(count(c.id)) from c where c.areaId='{area.id}' and c.standard='{area.standard}'
  161. area.schoolCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(count(c.id)) from c where c.areaId='{area.id}'", "Base");
  162. area.aquoteRec = await table.QueryWhereString<AreaQuoteRecord>($"PartitionKey eq 'QuoteRecord' and areaId eq '{area.id}'");
  163. //List<AreaQuoteRecord> aqr = await table.QueryWhereString<AreaQuoteRecord>($"PartitionKey eq 'QuoteRecord' and areaId eq '{area.id}'");
  164. //aqr.Sort((x, y) => y.RowKey.CompareTo(x.RowKey));
  165. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<string>(queryText: $"select value(c.accessConfig) from c where c.id='{area.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("AreaSetting") }))
  166. {
  167. if (string.IsNullOrEmpty(item))
  168. area.cutArea = false;
  169. else
  170. area.cutArea = true;
  171. };
  172. }
  173. return Ok(new { state = 200, areas, continuationToken });
  174. }
  175. catch (Exception ex)
  176. {
  177. await _dingDing.SendBotMsg($"BI,{_option.Location} batcharea/get-areas \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  178. return BadRequest();
  179. }
  180. }
  181. /// <summary>
  182. /// 批量创区 新接口 //已对接
  183. /// </summary>
  184. /// <param name="jsonElement"></param>
  185. /// <returns></returns>
  186. [ProducesDefaultResponseType]
  187. [AuthToken(Roles = "admin,rdc")]
  188. [HttpPost("batch-area")]
  189. public async Task<IActionResult> batchArea(JsonElement jsonElement)
  190. {
  191. try
  192. {
  193. if (!jsonElement.TryGetProperty("name", out JsonElement name)) return BadRequest();
  194. jsonElement.TryGetProperty("provCode", out JsonElement provCode);
  195. jsonElement.TryGetProperty("provName", out JsonElement provName);
  196. jsonElement.TryGetProperty("cityCode", out JsonElement cityCode);
  197. jsonElement.TryGetProperty("cityName", out JsonElement cityName);
  198. jsonElement.TryGetProperty("areaAdmin", out JsonElement areadAdmin);
  199. if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
  200. if (!jsonElement.TryGetProperty("standardName", out JsonElement standardName)) return BadRequest();
  201. jsonElement.TryGetProperty("institution", out JsonElement institution);
  202. jsonElement.TryGetProperty("oldId", out JsonElement _oldId);
  203. jsonElement.TryGetProperty("oldStandard", out JsonElement oldStandard);
  204. jsonElement.TryGetProperty("oldName", out JsonElement oldName);
  205. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  206. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  207. //操作记录实体
  208. var tempStandard = !string.IsNullOrEmpty($"{oldStandard}") && !string.IsNullOrEmpty($"{_oldId}") ? $"{oldStandard}" : "standard2";
  209. var cosmosClient = _azureCosmos.GetCosmosClient();//数据库连接
  210. var tableClient = _azureStorage.GetCloudTableClient();
  211. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  212. ServiceBusClient serBusClient;
  213. try
  214. {
  215. serBusClient = _serviceBus.GetServiceBusClient();
  216. }
  217. catch
  218. {
  219. return Ok(new { state = 403, msg = "Functionn未启动,请联系管理员" });
  220. }
  221. var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");//秘钥地址
  222. //分开部署,就不需要,一站多用时,取消注释
  223. //if ($"{site}".Equals(BIConst.Global))
  224. //{
  225. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  226. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  227. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", name: BIConst.Global);
  228. //}
  229. var table = tableClient.GetTableReference("IESLogin");
  230. //查询新的是否存在
  231. 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") }))
  232. {
  233. if (item.standard.Equals($"{standard}"))
  234. return Ok(new { state = 1, message = "新创区的standard已存在请检查" });
  235. }
  236. //查询新的区级名称是否存在
  237. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select value(c) from c where c.name='{name}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
  238. {
  239. if (item.name.Equals($"{standard}"))
  240. return Ok(new { state = 1, message = "区级名称相同,请检测区级名称!" });
  241. }
  242. //区级的ID
  243. string areaId = Guid.NewGuid().ToString();
  244. Area addArea = new()
  245. {
  246. id = areaId,
  247. code = $"Base-Area",
  248. name = $"{name}",
  249. provCode = $"{provCode}",
  250. provName = $"{provName}",
  251. cityCode = $"{cityCode}",
  252. cityName = $"{cityName}",
  253. standard = $"{standard}",
  254. standardName = $"{standardName}",
  255. institution = $"{institution}",
  256. quoteId = $"{_oldId}"
  257. };
  258. #region 区级管理员
  259. var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{areadAdmin}" } }, _option.Location, _configuration);
  260. if (coreUser == null || coreUser.id == null)
  261. return Ok(new { state = 404, msg = "未找到改账户的管理员" });
  262. //string tmdId = !string.IsNullOrEmpty(tempTmdId) ? tempTmdId : $"{areadAdmin}";
  263. Teacher teacher = null;
  264. try
  265. {
  266. //查询该教师是否存在
  267. teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{coreUser.id}", new PartitionKey("Base"));
  268. }
  269. catch
  270. {
  271. }
  272. if (teacher != null)
  273. {
  274. //教师存在,在该教师信息中添加要管理的学校信息
  275. teacher.areas.Add(new Teacher.TeacherArea { areaId = addArea.id, status = "join", name = addArea.name });
  276. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
  277. }
  278. else
  279. {
  280. teacher.id = coreUser.id;
  281. teacher.name = coreUser.name;
  282. teacher.picture = coreUser.picture;
  283. teacher.pk = "Base";
  284. teacher.code = "Base";
  285. teacher.size = 1;
  286. teacher.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  287. //教师存在,在该教师信息中添加要管理的学校信息
  288. teacher.areas.Add(new Teacher.TeacherArea { areaId = addArea.id, status = "join", name = addArea.name });
  289. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
  290. }
  291. #endregion
  292. //创建区域
  293. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync<Area>(addArea, new PartitionKey("Base-Area"));
  294. //保存引用记录
  295. await table.SaveOrUpdate<AreaQuoteRecord>(new AreaQuoteRecord() { PartitionKey = "QuoteRecord", RowKey = $"{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}", areaId = $"{areaId}", quoteId = $"{_oldId}", quoteName = $"{oldName}", standard = tempStandard });
  296. //消息分区键
  297. string partitionCode = "copyAbility-mark";
  298. #region 使用Function创区
  299. //string areaCode = "copyArea-mark";
  300. //BatchCopyAreaRelevant bCopyArea = new BatchCopyAreaRelevant()
  301. //{
  302. // tmdid = $"{_tmdId}",
  303. // tmdName = $"{_tmdName}",
  304. // codeKey = areaCode,
  305. // tmdIds = new List<string> { $"{_tmdId}"},
  306. // oldStandard = $"{oldStandard}",
  307. // oldId = $"{_oldId}",
  308. // standard = $"{standard}",
  309. // areaId = areaId,
  310. // cut="",
  311. //};
  312. //var messageBatchCopyArea = new ServiceBusMessage(bCopyArea.ToJsonString());
  313. //messageBatchCopyArea.ApplicationProperties.Add("name", "CopyAreaRelevant");
  314. //var activeTaskArea = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  315. //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTaskArea, messageBatchCopyArea);
  316. #endregion
  317. #region 旧的批量创区
  318. List<Task<ItemResponse<Ability>>> abilities = new List<Task<ItemResponse<Ability>>>(); //存储区域数据
  319. List<Task<ItemResponse<AbilityTask>>> abilityTasks = new List<Task<ItemResponse<AbilityTask>>>(); //存储章节
  320. if (!string.IsNullOrEmpty($"{oldStandard}") && !string.IsNullOrEmpty($"{_oldId}"))
  321. {
  322. //查询要复制区域的能力标准点
  323. 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}") }))
  324. {
  325. if (!string.IsNullOrEmpty(item.blob))
  326. {
  327. item.blob = item.blob.Replace($"/{oldStandard}/", $"/{standard}/");
  328. };
  329. item.standard = $"{standard}";
  330. item.code = $"Ability-{standard}";
  331. item.school = $"{standard}";
  332. //添加区能力标准点
  333. abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{standard}")));
  334. }
  335. try
  336. {
  337. if (abilities.Count < 256)
  338. {
  339. await Task.WhenAll(abilities);
  340. }
  341. else
  342. {
  343. int pages = (abilities.Count + 255) / 256;
  344. for (int i = 0; i < pages; i++)
  345. {
  346. List<Task<ItemResponse<Ability>>> tempAbility = abilities.Skip((i) * 256).Take(256).ToList();
  347. await Task.WhenAll(tempAbility);
  348. }
  349. }
  350. }
  351. catch
  352. {
  353. return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
  354. }
  355. try
  356. {
  357. //微能力点
  358. 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}") }))
  359. {
  360. List<Tnode> tnodes = new List<Tnode>();
  361. foreach (Tnode tnode in atask.children)
  362. {
  363. if (tnode.rnodes != null)
  364. {
  365. List<Rnode> rnodes = new List<Rnode>();
  366. foreach (Rnode rnode in tnode.rnodes)
  367. {
  368. if (!string.IsNullOrEmpty($"{rnode.link}"))
  369. {
  370. rnode.link = rnode.link.Replace($"/{oldStandard}/", $"/{standard}/");
  371. }
  372. rnodes.Add(rnode);
  373. }
  374. tnode.rnodes = rnodes;
  375. }
  376. tnodes.Add(tnode);
  377. }
  378. atask.children = tnodes;
  379. atask.code = $"AbilityTask-{standard}";
  380. atask.standard = $"{standard}";
  381. atask.codeval = $"{standard}";
  382. //添加区能力标准点中的节点
  383. //abilityTasks.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{standard}")));
  384. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{standard}"));
  385. }
  386. }
  387. catch
  388. {
  389. return Ok(new { state = 200, msg = "创区成功,能力标准创建成功,微能力点复制失败,遗留数据影响!" });
  390. }
  391. //if (abilityTasks.Count > 0)
  392. //{
  393. // for (int i = 0; i < abilityTasks.Count; i++)
  394. // {
  395. // List<Task<ItemResponse<AbilityTask>>> tempAbilityTasks = abilityTasks.Skip((i)).Take(1).ToList();
  396. // await Task.WhenAll(tempAbilityTasks);
  397. // }
  398. //}
  399. //新政策文件
  400. 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") }))
  401. {
  402. if (standardFile != null)
  403. {
  404. standardFile.standard = $"{standard}";
  405. standardFile.id = areaId;
  406. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(standardFile, new PartitionKey($"StandardFile"));
  407. }
  408. }
  409. //新的区域设置
  410. 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") }))
  411. {
  412. if (areaSetting != null)
  413. {
  414. areaSetting.accessConfig = null;
  415. areaSetting.id = areaId;
  416. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(areaSetting, new PartitionKey($"AreaSetting"));
  417. }
  418. }
  419. }
  420. else
  421. {
  422. Area area = null;
  423. 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") }))
  424. {
  425. area = tempArea;
  426. }
  427. if (area != null)
  428. {
  429. //查询要复制区域的能力标准点
  430. 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}") }))
  431. {
  432. if (!string.IsNullOrEmpty(item.blob))
  433. {
  434. item.blob = item.blob.Replace($"/{area.standard}/", $"/{standard}/");
  435. };
  436. item.standard = $"{standard}";
  437. item.code = $"Ability-{standard}";
  438. item.school = $"{standard}";
  439. //添加区能力标准点
  440. abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{standard}")));
  441. }
  442. try
  443. {
  444. if (abilities.Count < 256)
  445. {
  446. await Task.WhenAll(abilities);
  447. }
  448. else
  449. {
  450. int pages = (abilities.Count + 255) / 256;
  451. for (int i = 0; i < pages; i++)
  452. {
  453. List<Task<ItemResponse<Ability>>> tempAbility = abilities.Skip((i) * 256).Take(256).ToList();
  454. await Task.WhenAll(tempAbility);
  455. }
  456. }
  457. }
  458. catch
  459. {
  460. return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
  461. }
  462. try
  463. {
  464. //微能力点
  465. 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}") }))
  466. {
  467. List<Tnode> tnodes = new List<Tnode>();
  468. foreach (Tnode tnode in atask.children)
  469. {
  470. if (tnode.rnodes != null)
  471. {
  472. List<Rnode> rnodes = new List<Rnode>();
  473. foreach (Rnode rnode in tnode.rnodes)
  474. {
  475. if (!string.IsNullOrEmpty($"{rnode.link}"))
  476. {
  477. rnode.link = rnode.link.Replace($"/{area.standard}/", $"/{standard}/");
  478. }
  479. rnodes.Add(rnode);
  480. }
  481. tnode.rnodes = rnodes;
  482. }
  483. tnodes.Add(tnode);
  484. }
  485. atask.children = tnodes;
  486. atask.code = $"AbilityTask-{standard}";
  487. atask.standard = $"{standard}";
  488. atask.codeval = $"{standard}";
  489. //添加区能力标准点中的节点
  490. //abilityTasks.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{standard}")));
  491. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{standard}"));
  492. }
  493. }
  494. catch
  495. {
  496. return Ok(new { state = 200, msg = "创区成功,能力标准创建成功,微能力点复制失败,遗留数据影响!" });
  497. }
  498. //if (abilityTasks.Count > 0)
  499. //{
  500. // for (int i = 0; i < abilityTasks.Count; i++)
  501. // {
  502. // List<Task<ItemResponse<AbilityTask>>> tempAbilityTasks = abilityTasks.Skip(i).Take(1).ToList();
  503. // await Task.WhenAll(tempAbilityTasks);
  504. // }
  505. //}
  506. //新政策文件
  507. 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") }))
  508. {
  509. if (standardFile != null)
  510. {
  511. standardFile.standard = $"{standard}";
  512. standardFile.id = areaId;
  513. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(standardFile, new PartitionKey($"StandardFile"));
  514. }
  515. }
  516. //新的区域设置
  517. 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") }))
  518. {
  519. if (areaSetting != null)
  520. {
  521. areaSetting.accessConfig = null;
  522. areaSetting.id = areaId;
  523. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(areaSetting, new PartitionKey($"AreaSetting"));
  524. }
  525. }
  526. }
  527. else return Ok(new { state = 201, message = "未找到默认能力点!" });
  528. }
  529. #endregion
  530. //执行复制操作
  531. BatchCopyFile batchCopyFile = new BatchCopyFile();
  532. batchCopyFile.blobCntr = "teammodelos";
  533. batchCopyFile.oldFileName = $"{oldStandard}";
  534. batchCopyFile.newFileName = $"{standard}";
  535. batchCopyFile.tmdid = $"{_tmdId}";
  536. batchCopyFile.tmdIds = new List<string> { $"{ _tmdId}" };
  537. batchCopyFile.codeKey = partitionCode;
  538. batchCopyFile.tmdName = $"{_tmdName}";
  539. var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
  540. messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
  541. //var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  542. try
  543. {
  544. //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile);
  545. await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile);
  546. }
  547. catch (Exception)
  548. {
  549. return Ok(new { state = 201, msg = "能力点复制成功,复制能力点的文件失败," });
  550. }
  551. //发送消息实体
  552. Notification notification = new Notification
  553. {
  554. hubName = "hita",
  555. type = "msg",
  556. from = $"BI:{_option.Location}:private",
  557. to = new List<string> { $"{ _tmdId}" },
  558. label = $"{partitionCode}_start",
  559. body = new { location = _option.Location, biz = partitionCode, tmdid = $"{_tmdId}", tmdname = $"{_tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
  560. expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
  561. };
  562. var notiUrl = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
  563. var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
  564. var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
  565. var location = _option.Location;
  566. await _notificationService.SendNotification(clientID, clientSecret, location, notiUrl, notification); //站内发送消息
  567. //保存操作记录
  568. //await _azureStorage.SaveBILog("area-add", $"{_tmdName}【{_tmdId}】已操作创区功能模块:{name},当前标准【{standard}】,复制的微能力点:{tempStandard}", _dingDing, httpContext: HttpContext);
  569. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "area-add", $"{_tmdName}【{_tmdId}】已操作创区功能模块:{name},当前标准【{standard}】,复制的微能力点:{tempStandard}", _dingDing, httpContext: HttpContext);
  570. return Ok(new { state = 200, area = addArea });
  571. }
  572. catch (Exception ex)
  573. {
  574. await _dingDing.SendBotMsg($"BI,{_option.Location} /batcharea/batch-area \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  575. return BadRequest();
  576. }
  577. }
  578. /// <summary>
  579. /// 创区后切换能力点, 先删除原来的能力点,后复制新的能力点 //已对接
  580. /// </summary>
  581. /// <param name="jsonElement"></param>
  582. /// <returns></returns>
  583. [ProducesDefaultResponseType]
  584. [AuthToken(Roles = "admin,rdc")]
  585. [HttpPost("cut-standard")]
  586. public async Task<IActionResult> CutStandard(JsonElement jsonElement)
  587. {
  588. try
  589. {
  590. if (!jsonElement.TryGetProperty("oldId", out JsonElement _oldId)) return BadRequest();
  591. if (!jsonElement.TryGetProperty("oldStandard", out JsonElement _oldStandard)) return BadRequest();
  592. if (!jsonElement.TryGetProperty("newId", out JsonElement _newId)) return BadRequest();
  593. if (!jsonElement.TryGetProperty("newStandard", out JsonElement _newStandard)) return BadRequest();
  594. jsonElement.TryGetProperty("newName", out JsonElement newName);
  595. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  596. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  597. //操作记录实体
  598. string blobOrTable = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
  599. var tableClient = _azureStorage.GetCloudTableClient();
  600. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  601. var cosmosClient = _azureCosmos.GetCosmosClient();
  602. var serBusClient = _serviceBus.GetServiceBusClient();
  603. var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");//秘钥地址
  604. ////分开部署,就不需要,一站多用时,取消注释
  605. //if ($"{site}".Equals(BIConst.Global))
  606. //{
  607. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  608. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  609. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  610. // serBusClient = _serviceBus.GetServiceBusClient(BIConst.Global); //暂未确定使用默认
  611. // //activeTask = _configuration.GetValue<string>("GlobalAzure:ServiceBus:ActiveTask"); //暂未确定使用默认
  612. //}
  613. var table = tableClient.GetTableReference("IESLogin");
  614. var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{_oldId}", new PartitionKey("AreaSetting"));
  615. if (responseSet.Status == 200)
  616. {
  617. using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
  618. AreaSetting delSet = fileJson.ToObject<AreaSetting>();
  619. if (!string.IsNullOrEmpty(delSet.accessConfig))
  620. return Ok(new { state = 401, msg = "区域已经规定了,不能切换能能力" });
  621. }
  622. //保存引用记录
  623. await table.SaveOrUpdate<AreaQuoteRecord>(new AreaQuoteRecord() { PartitionKey = "QuoteRecord", RowKey = $"{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}", areaId = $"{_oldId}", quoteId = $"{_newId}", quoteName = $"{newName}", standard = $"{_newStandard}" });
  624. List<string> abilityIds = new(); //册别的ID集合
  625. //查询册别信息
  626. 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}") }))
  627. {
  628. abilityIds.Add(tempAbility.id); //查询出来册别ID添加册别ID集合
  629. }
  630. //删除册别
  631. if (abilityIds.IsNotEmpty())
  632. {
  633. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityIds, $"Ability-{_oldStandard}");
  634. }
  635. List<string> abilityTaskIds = new(); //章节ID集合
  636. 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}") }))
  637. {
  638. abilityTaskIds.Add(item.id); //查询出来的章节信息ID添加到战绩集合
  639. }
  640. //删除章节
  641. if (abilityTaskIds.IsNotEmpty())
  642. {
  643. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityTaskIds, $"AbilityTask-{_oldStandard}");
  644. }
  645. List<Task<ItemResponse<Ability>>> abilities = new(); //存储册别数据
  646. List<Task<ItemResponse<AbilityTask>>> abilityTasks = new(); //存储章节
  647. //查询要复制区域的能力标准点
  648. 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}") }))
  649. {
  650. if (!string.IsNullOrEmpty(item.blob))
  651. {
  652. item.blob = item.blob.Replace($"/{_newStandard}/", $"/{_oldStandard}/");
  653. };
  654. item.standard = $"{_oldStandard}";
  655. item.code = $"Ability-{_oldStandard}";
  656. item.school = $"{_oldStandard}";
  657. //添加区能力标准点
  658. abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}")));
  659. }
  660. try
  661. {
  662. if (abilities.Count < 256)
  663. {
  664. await Task.WhenAll(abilities);
  665. }
  666. else
  667. {
  668. int pages = (abilities.Count + 255) / 256;
  669. for (int i = 0; i < pages; i++)
  670. {
  671. List<Task<ItemResponse<Ability>>> tempAbility = abilities.Skip((i) * 256).Take(256).ToList();
  672. await Task.WhenAll(tempAbility);
  673. }
  674. }
  675. }
  676. catch
  677. {
  678. return Ok(new { state = 200, msg = "能力标准点复制失败,遗留数据影响!" });
  679. }
  680. try
  681. {
  682. //微能力点
  683. 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}") }))
  684. {
  685. List<Tnode> tnodes = new();
  686. foreach (Tnode tnode in atask.children)
  687. {
  688. if (tnode.rnodes != null)
  689. {
  690. List<Rnode> rnodes = new();
  691. foreach (Rnode rnode in tnode.rnodes)
  692. {
  693. if (!string.IsNullOrEmpty($"{rnode.link}"))
  694. {
  695. rnode.link = rnode.link.Replace($"/{_newStandard}/", $"/{_oldStandard}/");
  696. }
  697. rnodes.Add(rnode);
  698. }
  699. tnode.rnodes = rnodes;
  700. }
  701. tnodes.Add(tnode);
  702. }
  703. atask.children = tnodes;
  704. atask.code = $"AbilityTask-{_oldStandard}";
  705. atask.standard = $"{_oldStandard}";
  706. atask.codeval = $"{_oldStandard}";
  707. ////添加区能力标准点中的节点
  708. //abilityTasks.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}")));
  709. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}"));
  710. }
  711. }
  712. catch
  713. {
  714. return Ok(new { state = 200, msg = "能力标准创建成功,微能力点复制失败,遗留数据影响!" });
  715. }
  716. StandardFile saveFile = new();
  717. //新政策文件
  718. 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") }))
  719. {
  720. if (standardFile != null)
  721. {
  722. standardFile.standard = $"{_oldStandard}";
  723. standardFile.id = $"{_oldId}";
  724. saveFile = standardFile;
  725. }
  726. }
  727. StandardFile tempFile = new();
  728. if (saveFile.id != null)
  729. {
  730. var respFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveFile.id, new PartitionKey("StandardFile"));
  731. if (respFile.Status == 200)
  732. {
  733. using var json = await JsonDocument.ParseAsync(respFile.ContentStream);
  734. tempFile = json.ToObject<StandardFile>();
  735. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<StandardFile>(tempFile.id, new PartitionKey("StandardFile"));
  736. }
  737. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
  738. }
  739. //新的区域设置
  740. AreaSetting saveSetting = new AreaSetting();
  741. 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") }))
  742. {
  743. if (areaSetting != null)
  744. {
  745. areaSetting.accessConfig = null;
  746. areaSetting.id = $"{_oldId}";
  747. saveSetting = areaSetting;
  748. }
  749. }
  750. AreaSetting tempSetting = new();
  751. if (saveSetting.id != null)
  752. {
  753. var respSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveSetting.id, new PartitionKey("AreaSetting"));
  754. if (respSetting.Status == 200)
  755. {
  756. using var json = await JsonDocument.ParseAsync(respSetting.ContentStream);
  757. tempSetting = json.ToObject<AreaSetting>();
  758. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<AreaSetting>(tempFile.id, new PartitionKey("AreaSetting"));
  759. }
  760. tempSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting")); //需要删除原来的区域设置数据在进行添加
  761. }
  762. //修改切换区级能力引用id
  763. Area area = new();
  764. area = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Area>($"{_oldId}", new PartitionKey("Base-Area"));
  765. area.quoteId = $"{_newId}";
  766. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<Area>(area, area.id, new PartitionKey(area.code));
  767. //发送消息分区键
  768. string partitionCode = "DelBeforeCopyAbility-mark";
  769. //v2通知
  770. Teacher targetTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>($"{_tmdId}", new PartitionKey($"Base"));
  771. _coreAPIHttpService.PushNotify(new List<IdNameCode> { new IdNameCode { id = targetTeacher.id, name = targetTeacher.name, code = targetTeacher.lang } }, "copy-file_area", Constant.NotifyType_IES5_Management, new Dictionary<string, object> { { "tmdname", $"{_tmdName}" } }, _option.Location, _configuration, _dingDing, _environment.ContentRootPath);
  772. //执行复制操作
  773. BatchCopyFile batchCopyFile = new();
  774. batchCopyFile.blobCntr = "teammodelos";
  775. batchCopyFile.oldFileName = $"{_newStandard}";
  776. batchCopyFile.newFileName = $"{_oldStandard}";
  777. batchCopyFile.tmdid = $"{_tmdId}";
  778. batchCopyFile.tmdIds = new List<string> { $"{ _tmdId}" };
  779. batchCopyFile.codeKey = partitionCode;
  780. batchCopyFile.tmdName = $"{_tmdName}";
  781. var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
  782. messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
  783. try
  784. {
  785. //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile); //先执行删除操作,在执行复制 单一
  786. await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile); //先执行删除操作,在执行复制
  787. }
  788. catch (Exception)
  789. {
  790. return Ok(new { state = 201 ,msg = "能力点复制成功,复制能力点的文件失败," });
  791. }
  792. //发送消息实体
  793. Notification notification = new()
  794. {
  795. hubName = "hita",
  796. type = "msg",
  797. from = $"BI:{_option.Location}:private",
  798. to = new List<string> { $"{ _tmdId}" },
  799. label = $"{partitionCode}_start",
  800. body = new { location = _option.Location, biz = partitionCode, tmdid = $"{_tmdId}", tmdname = $"{_tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
  801. expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
  802. };
  803. var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
  804. var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
  805. var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
  806. var location = _option.Location;
  807. await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //发送站内发送消息
  808. //保存操作记录
  809. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "area-cut", $"{_tmdName}【{_tmdId}】已操作【{_oldStandard}】切换至{_newStandard}微能力点,复制标准:{_newStandard}", _dingDing, httpContext: HttpContext);
  810. return Ok(new { state = 200 });
  811. }
  812. catch (Exception ex)
  813. {
  814. await _dingDing.SendBotMsg($"BI,{_option.Location} batcharea/cut-standard \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  815. return BadRequest();
  816. }
  817. }
  818. /// <summary>
  819. /// 删除区域和区域的册别、能力点、区域文件、区域设置
  820. /// </summary>
  821. /// <param name="jsonElement"></param>
  822. /// <returns></returns>
  823. [ProducesDefaultResponseType]
  824. [HttpPost("del-area")]
  825. public async Task<IActionResult> DelArea(JsonElement jsonElement)
  826. {
  827. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  828. if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
  829. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  830. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "teammodelos");
  831. var cosmosClient = _azureCosmos.GetCosmosClient();
  832. ////分开部署,就不需要,一站多用时,取消注释
  833. //if ($"{site}".Equals(BIConst.Global))
  834. //{
  835. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  836. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "teammodelos", BIConst.Global);
  837. //}
  838. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{areaId}", new PartitionKey("Base-Area"));
  839. if (response.Status == 200)
  840. {
  841. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  842. Area area = json.ToObject<Area>();
  843. if (area.standard == $"{standard}")
  844. {
  845. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<Area>(area.id, new PartitionKey("Base-Area")); //删除区
  846. List<Teacher> teachers = new();
  847. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Teacher>(queryText: $"SELECT distinct value(c) FROM c join a in c.areas join s in c.schools where a.areaId='{area.id}' or s.areaId='{area.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  848. {
  849. teachers.Add(item);
  850. }
  851. foreach (var item in teachers)
  852. {
  853. var tempArea = item.areas.Find(f => f.areaId.Equals(area.id));
  854. if (tempArea != null)
  855. {
  856. item.areas.Remove(tempArea);
  857. }
  858. item.schools.ForEach(fe => { if (fe.areaId.Equals(area.id)) fe.areaId = ""; });
  859. await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(item, item.id, new PartitionKey("Base"));
  860. }
  861. List<string> scIds = await CommonFind.FindScIds(cosmosClient, $"select value(c.id) from c where c.areaId='{area.id}' and c.standard ='{area.standard}'", "Base");
  862. foreach (var item in scIds)
  863. {
  864. School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(item, new PartitionKey("Base"));
  865. school.areaId = "";
  866. school.standard = "";
  867. school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey("Base"));
  868. }
  869. List<string> abilityIds = new(); //册别的ID集合
  870. List<string> abilityTaskIds = new(); //章节ID集合
  871. //查询册别信息
  872. 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}") }))
  873. {
  874. abilityIds.Add(tempAbility.id); //查询出来册别ID添加册别ID集合
  875. }
  876. //删除册别
  877. if (abilityIds.IsNotEmpty())
  878. {
  879. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityIds, $"Ability-{area.standard}");
  880. }
  881. 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}") }))
  882. {
  883. abilityTaskIds.Add(item.id); //查询出来的章节信息ID添加到战绩集合
  884. }
  885. //删除章节
  886. if (abilityTaskIds.IsNotEmpty())
  887. {
  888. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityTaskIds, $"AbilityTask-{standard}");
  889. }
  890. //区域政策文件
  891. StandardFile delFile = new();
  892. var responseFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(area.id, new PartitionKey("StandardFile"));
  893. if(responseFile.Status == 200)
  894. {
  895. using var fileJson = await JsonDocument.ParseAsync(responseFile.ContentStream);
  896. delFile = fileJson.ToObject<StandardFile>();
  897. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<StandardFile>(delFile.id, new PartitionKey("StandardFile"));
  898. }
  899. //区域设置
  900. AreaSetting delSet = new();
  901. var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(area.id, new PartitionKey("AreaSetting"));
  902. if (responseSet.Status == 200)
  903. {
  904. using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
  905. delSet = fileJson.ToObject<AreaSetting>();
  906. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<AreaSetting>(delSet.id, new PartitionKey("AreaSetting"));
  907. }
  908. List<object> fileobj = new();
  909. //先删除原有的文件
  910. List<Task<Response<bool>>> DelList = new();
  911. await foreach (BlobItem blobItem in blobClient.GetBlobsAsync(BlobTraits.None, BlobStates.None, $"yxpt/{area.standard}/"))
  912. {
  913. fileobj.Add(blobItem.Name);
  914. DelList.Add(blobClient.GetBlobBaseClient(blobItem.Name).DeleteIfExistsAsync());
  915. }
  916. if (DelList.Count <= 256)
  917. {
  918. await Task.WhenAll(DelList);
  919. }
  920. else
  921. {
  922. int pages = (DelList.Count + 255) / 256;
  923. for (int i = 0; i < pages; i++)
  924. {
  925. List<Task<Response<bool>>> delList = DelList.Skip((i) * 256).Take(256).ToList();
  926. await Task.WhenAll(delList);
  927. }
  928. }
  929. return Ok(new { state = 200,area, scIds, abilityIds, abilityTaskIds, delFile, delSet, fileobj });
  930. }
  931. else return Ok(new { state = 400, msg = "id和standard不匹配!" });
  932. }
  933. else return Ok(new { state = 404,msg="依据Id未找到该区!" });
  934. }
  935. /// <summary>
  936. /// 同步两个区到新的区中
  937. /// </summary>
  938. /// <param name="jsonElement"></param>
  939. /// <returns></returns>
  940. [ProducesDefaultResponseType]
  941. [AuthToken(Roles = "admin")]
  942. [HttpPost("cut-full-statndard")]
  943. public async Task<IActionResult> CutFullStandard(JsonElement jsonElement)
  944. {
  945. try
  946. {
  947. string _oldId = "bde5c011-2ae4-461a-b46c-5483ba72ae45";
  948. //string _oldStandard = "standard27";
  949. string standardFileId = "02944f32-f534-3397-ea56-e6f1fc6c3714";
  950. string standard = "standard2";
  951. List<CopyStandard> copyStand = new()
  952. {
  953. new CopyStandard() { id = standardFileId, standard = standard },
  954. new CopyStandard() { id = "99a4a33b-e21b-44ac-80a1-b31dc40496e0", standard = "standard3" }
  955. };
  956. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  957. var tableClient = _azureStorage.GetCloudTableClient();
  958. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  959. var cosmosClient = _azureCosmos.GetCosmosClient();
  960. var serBusClient = _serviceBus.GetServiceBusClient();
  961. var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");//秘钥地址
  962. var table = tableClient.GetTableReference("IESLogin");
  963. Area area = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Area>($"{_oldId}", new PartitionKey("Base-Area"));
  964. if (area != null)
  965. {
  966. var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{_oldId}", new PartitionKey("AreaSetting"));
  967. if (responseSet.Status == 200)
  968. {
  969. using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
  970. AreaSetting delSet = fileJson.ToObject<AreaSetting>();
  971. if (!string.IsNullOrEmpty(delSet.accessConfig))
  972. return Ok(new { state = 401, msg = "区域已经规定了,不能切换能能力" });
  973. }
  974. List<string> abilityIds = new(); //册别的ID集合
  975. //查询册别信息
  976. 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}") }))
  977. {
  978. abilityIds.Add(tempAbility.id); //查询出来册别ID添加册别ID集合
  979. }
  980. //删除册别
  981. if (abilityIds.IsNotEmpty())
  982. {
  983. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityIds, $"Ability-{area.standard}");
  984. }
  985. List<string> abilityTaskIds = new List<string>(); //章节ID集合
  986. 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}") }))
  987. {
  988. abilityTaskIds.Add(item.id); //查询出来的章节信息ID添加到战绩集合
  989. }
  990. //删除章节
  991. if (abilityTaskIds.IsNotEmpty())
  992. {
  993. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityTaskIds, $"AbilityTask-{area.standard}");
  994. }
  995. List<Task<ItemResponse<Ability>>> abilities = new(); //存储册别数据
  996. List<Task<ItemResponse<AbilityTask>>> abilityTasks = new(); //存储章节
  997. List<string> repeatAbilityId = new();
  998. List<string> repeatAbilityTaskId = new();
  999. foreach (var newstand in copyStand)
  1000. {
  1001. try
  1002. {
  1003. //查询要复制区域的能力标准点
  1004. 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-{newstand.standard}") }))
  1005. {
  1006. if (!string.IsNullOrEmpty(item.blob))
  1007. item.blob = item.blob.Replace($"/{newstand.standard}/", $"/{area.standard}/");
  1008. item.standard = $"{area.standard}";
  1009. item.code = $"Ability-{area.standard}";
  1010. item.school = $"{area.standard}";
  1011. //添加区能力标准点
  1012. //abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}")));
  1013. //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}"));
  1014. var respond = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(item.id, new PartitionKey(item.code));
  1015. if (respond.Status != 200)
  1016. abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{area.standard}")));
  1017. else
  1018. repeatAbilityId.Add(item.id);
  1019. }
  1020. }
  1021. catch
  1022. {
  1023. return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
  1024. }
  1025. try
  1026. {
  1027. if (abilities.Count < 256)
  1028. {
  1029. await Task.WhenAll(abilities);
  1030. }
  1031. else
  1032. {
  1033. int pages = (abilities.Count + 255) / 256;
  1034. for (int i = 0; i < pages; i++)
  1035. {
  1036. List<Task<ItemResponse<Ability>>> tempAbility = abilities.Skip((i) * 256).Take(256).ToList();
  1037. await Task.WhenAll(tempAbility);
  1038. }
  1039. }
  1040. }
  1041. catch
  1042. {
  1043. return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
  1044. }
  1045. try
  1046. {
  1047. //微能力点
  1048. 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-{newstand.standard}") }))
  1049. {
  1050. List<Tnode> tnodes = new();
  1051. foreach (Tnode tnode in atask.children)
  1052. {
  1053. if (tnode.rnodes != null)
  1054. {
  1055. List<Rnode> rnodes = new();
  1056. foreach (Rnode rnode in tnode.rnodes)
  1057. {
  1058. if (!string.IsNullOrEmpty($"{rnode.link}"))
  1059. {
  1060. rnode.link = rnode.link.Replace($"/{newstand.standard}/", $"/{area.standard}/");
  1061. }
  1062. rnodes.Add(rnode);
  1063. }
  1064. tnode.rnodes = rnodes;
  1065. }
  1066. tnodes.Add(tnode);
  1067. }
  1068. atask.children = tnodes;
  1069. atask.code = $"AbilityTask-{area.standard}";
  1070. atask.standard = $"{area.standard}";
  1071. atask.codeval = $"{area.standard}";
  1072. var respond = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(atask.id, new PartitionKey(atask.code));
  1073. if (respond.Status != 200)
  1074. ////添加区能力标准点中的节点
  1075. //abilityTasks.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}")));
  1076. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{area.standard}"));
  1077. else
  1078. repeatAbilityTaskId.Add(atask.id);
  1079. }
  1080. }
  1081. catch
  1082. {
  1083. return Ok(new { state = 200, msg = "创区成功,能力标准创建成功,微能力点复制失败,遗留数据影响!" });
  1084. }
  1085. //发送消息分区键
  1086. string partitionCode = "DelBeforeCopyAbility-mark";
  1087. //执行复制操作
  1088. BatchCopyFile batchCopyFile = new();
  1089. batchCopyFile.blobCntr = "teammodelos";
  1090. batchCopyFile.oldFileName = $"{newstand.standard}";
  1091. batchCopyFile.newFileName = $"{area.standard}";
  1092. batchCopyFile.tmdid = $"{_tmdId}";
  1093. batchCopyFile.tmdIds = new List<string> { $"{_tmdId}" };
  1094. batchCopyFile.codeKey = partitionCode;
  1095. batchCopyFile.tmdName = $"{_tmdName}";
  1096. var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
  1097. messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
  1098. try
  1099. {
  1100. //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile); //先执行删除操作,在执行复制 单一
  1101. await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile); //先执行删除操作,在执行复制
  1102. }
  1103. catch (Exception)
  1104. {
  1105. return Ok(new { state = 201, msg = "能力点复制成功,复制能力点的文件失败," });
  1106. }
  1107. //发送消息实体
  1108. Notification notification = new()
  1109. {
  1110. hubName = "hita",
  1111. type = "msg",
  1112. from = $"BI:{_option.Location}:private",
  1113. to = new List<string> { $"{_tmdId}" },
  1114. label = $"{partitionCode}_start",
  1115. body = new { location = _option.Location, biz = partitionCode, tmdid = $"{_tmdId}", tmdname = $"{_tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
  1116. expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
  1117. };
  1118. var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
  1119. var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
  1120. var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
  1121. var location = _option.Location;
  1122. await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //发送站内发送消息
  1123. }
  1124. StandardFile saveFile = new();
  1125. //新政策文件
  1126. await foreach (StandardFile standardFile in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<StandardFile>(queryText: $"select value(c) from c where c.id='{standardFileId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StandardFile") }))
  1127. {
  1128. if (standardFile != null)
  1129. {
  1130. standardFile.standard = $"{area.standard}";
  1131. standardFile.id = $"{_oldId}";
  1132. saveFile = standardFile;
  1133. }
  1134. }
  1135. StandardFile tempFile = new();
  1136. if (saveFile.id != null)
  1137. {
  1138. var respFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveFile.id, new PartitionKey("StandardFile"));
  1139. if (respFile.Status == 200)
  1140. {
  1141. using var json = await JsonDocument.ParseAsync(respFile.ContentStream);
  1142. tempFile = json.ToObject<StandardFile>();
  1143. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<StandardFile>(tempFile.id, new PartitionKey("StandardFile"));
  1144. }
  1145. tempFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
  1146. }
  1147. //if (tempFile.id != null)
  1148. //{
  1149. // if (tempFile.id.Equals(saveFile.id))
  1150. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<StandardFile>(saveFile, saveFile.id, new PartitionKey("StandardFile")); //直接替换以前的数据
  1151. // else
  1152. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
  1153. //}
  1154. //新的区域设置
  1155. AreaSetting saveSetting = new();
  1156. await foreach (AreaSetting areaSetting in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AreaSetting>(queryText: $"select value(c) from c where c.id='{standardFileId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("AreaSetting") }))
  1157. {
  1158. if (areaSetting != null)
  1159. {
  1160. areaSetting.accessConfig = null;
  1161. areaSetting.id = $"{_oldId}";
  1162. saveSetting = areaSetting;
  1163. }
  1164. }
  1165. AreaSetting tempSetting = new();
  1166. if (saveSetting.id != null)
  1167. {
  1168. var respSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveSetting.id, new PartitionKey("AreaSetting"));
  1169. if (respSetting.Status == 200)
  1170. {
  1171. using var json = await JsonDocument.ParseAsync(respSetting.ContentStream);
  1172. tempSetting = json.ToObject<AreaSetting>();
  1173. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<AreaSetting>(saveSetting.id, new PartitionKey("AreaSetting"));
  1174. }
  1175. tempSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting")); //需要删除原来的区域设置数据在进行添加
  1176. }
  1177. //if (tempSetting.id != null)
  1178. //{
  1179. // if (tempSetting.id.Equals(saveSetting.id))
  1180. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<AreaSetting>(saveSetting, saveSetting.id, new PartitionKey($"AreaSetting")); //直接替换以前的数据
  1181. // else
  1182. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting")); //需要删除原来的区域设置数据在进行添加
  1183. //}
  1184. return Ok(new { state = RespondCode.Ok, repeatAbilityId, repeatAbilityTaskId });
  1185. }
  1186. else
  1187. return Ok(new { state = RespondCode.NotFound, msg = "标准为空"}) ;
  1188. }
  1189. catch (Exception ex)
  1190. {
  1191. await _dingDing.SendBotMsg($"BI,{_option.Location} batcharea/cut-full-statndard \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1192. return BadRequest();
  1193. }
  1194. }
  1195. /// <summary>
  1196. /// 区域列表
  1197. /// </summary>
  1198. public record RecArea
  1199. {
  1200. public string id { get; set; }
  1201. public string code { get; set; }
  1202. public string pk { get; set; }
  1203. public string name { get; set; }
  1204. public string provCode { get; set; }
  1205. public string provName { get; set; }
  1206. public string cityCode { get; set; }
  1207. public string cityName { get; set; }
  1208. public string standard { get; set; }
  1209. public string standardName { get; set; }
  1210. public string institution { get; set; }
  1211. public int schoolCount { get; set; }
  1212. public long updateTime { get; set; }
  1213. public string quoteId { get; set; } = null;
  1214. public bool cutArea { get; set; } = false;
  1215. public List<AreaQuoteRecord> aquoteRec { get; set; } = new List<AreaQuoteRecord>();
  1216. }
  1217. }
  1218. }