BatchAreaController.cs 77 KB

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