BatchAreaController.cs 77 KB

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