BatchAreaController.cs 82 KB

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