BatchAreaController.cs 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406
  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. BatchCopyFile batchCopyFile = new BatchCopyFile();
  543. batchCopyFile.blobCntr = "teammodelos";
  544. batchCopyFile.oldFileName = $"{oldStandard}";
  545. batchCopyFile.newFileName = $"{standard}";
  546. batchCopyFile.tmdid = $"{_tmdId}";
  547. batchCopyFile.tmdIds = new List<string> { $"{ _tmdId}" };
  548. batchCopyFile.codeKey = partitionCode;
  549. batchCopyFile.tmdName = $"{_tmdName}";
  550. var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
  551. messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
  552. //var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  553. try
  554. {
  555. //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile);
  556. await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile);
  557. }
  558. catch (Exception)
  559. {
  560. return Ok(new { state = 201, msg = "能力点复制成功,复制能力点的文件失败," });
  561. }
  562. //保存操作记录
  563. //await _azureStorage.SaveBILog("area-add", $"{_tmdName}【{_tmdId}】已操作创区功能模块:{name},当前标准【{standard}】,复制的微能力点:{tempStandard}", _dingDing, httpContext: HttpContext);
  564. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "area-add", $"{_tmdName}【{_tmdId}】已操作创区功能模块:{name},当前标准【{standard}】,复制的微能力点:{tempStandard}", _dingDing, httpContext: HttpContext);
  565. return Ok(new { state = 200, area = addArea });
  566. }
  567. catch (Exception ex)
  568. {
  569. await _dingDing.SendBotMsg($"BI,{_option.Location} /batcharea/batch-area \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  570. return BadRequest();
  571. }
  572. }
  573. /// <summary>
  574. /// 修改學區
  575. /// </summary>
  576. /// <param name="jsonElement"></param>
  577. /// <returns></returns>
  578. [ProducesDefaultResponseType]
  579. [AuthToken(Roles = "admin,rdc")]
  580. [HttpPost("upd-area")]
  581. public async Task<IActionResult> updArea(JsonElement jsonElement)
  582. {
  583. try
  584. {
  585. if (!jsonElement.TryGetProperty("id", out JsonElement _id)) return BadRequest();
  586. string id = _id.GetString();
  587. string shortCode = (jsonElement.TryGetProperty("shortCode", out JsonElement _shortCode)) ? _shortCode.GetString() : string.Empty;
  588. string name = (jsonElement.TryGetProperty("name", out JsonElement _name)) ? _name.GetString() : string.Empty;
  589. if(string.IsNullOrWhiteSpace(shortCode) && string.IsNullOrWhiteSpace(name))
  590. {
  591. return Ok(new { state = 1, message = "输入值有误,请检查输入值" });
  592. }
  593. var cosmosClient = _azureCosmos.GetCosmosClient();//数据库连接
  594. //學區取得
  595. Area area = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Area>(id, new PartitionKey($"Base-Area"));
  596. //輸入值重複檢驗
  597. string queryText = $"SELECT value(c) from c ";
  598. string queryWhere = string.Empty;
  599. if (!string.IsNullOrWhiteSpace(name))
  600. {
  601. if (!string.IsNullOrWhiteSpace(queryWhere)) queryWhere += " OR ";
  602. queryWhere += $"c.name='{name}'";
  603. }
  604. if (!string.IsNullOrWhiteSpace(shortCode))
  605. {
  606. if (!string.IsNullOrWhiteSpace(queryWhere)) queryWhere += " OR ";
  607. queryWhere += $"c.shortCode='{shortCode}'";
  608. }
  609. queryWhere = $"WHERE ({queryWhere}) AND c.id != '{id}'";
  610. queryText = $"{queryText}{queryWhere}";
  611. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"{queryText}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
  612. {
  613. //查询区级名称是否存在
  614. if (item.name.Equals($"{name}"))
  615. return Ok(new { state = 1, message = "区级名称相同,请检测区级名称!" });
  616. //查询學區簡碼是否存在
  617. if (item.shortCode.Equals($"{shortCode}"))
  618. return Ok(new { state = 1, message = "此学区简码已存在请检查" });
  619. }
  620. // 檢查是否有大寫或是中文字
  621. if (shortCode.Any(c => char.IsUpper(c)) || Regex.IsMatch(shortCode, @"[\u4e00-\u9fa5]"))
  622. {
  623. return Ok(new { state = 1, message = "此區級簡碼必須為小寫字母!" });
  624. }
  625. string sqlCheckRep = $"SELECT c.id FROM c WHERE c.shortCode = '{shortCode}'";
  626. var _azureCosmosClientCsv2Read = _azureCosmos.GetCosmosClient(name: "CoreServiceV2CnRead");
  627. await foreach (var item in _azureCosmosClientCsv2Read.GetContainer("Core", "School").GetItemQueryStreamIterator(queryText: sqlCheckRep, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("district") }))
  628. {
  629. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  630. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
  631. {
  632. return Ok(new { state = 1, message = "区级名称相同,请检测区级名称!" });
  633. }
  634. }
  635. //DB值更新
  636. if (!string.IsNullOrWhiteSpace(name)) area.name = name;
  637. if (!string.IsNullOrWhiteSpace(shortCode)) area.shortCode = shortCode;
  638. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<Area>(area, id);
  639. //保存操作记录
  640. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  641. var tableClient = _azureStorage.GetCloudTableClient();
  642. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  643. string BILogContent = string.Empty;
  644. BILogContent += $"学区ID:{id}, 更新资料: ";
  645. if (!string.IsNullOrWhiteSpace(name)) BILogContent += $"name:{name}, ";
  646. if (!string.IsNullOrWhiteSpace(shortCode)) BILogContent += $"shortCode:{shortCode}, ";
  647. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "upd-area", $"{_tmdName}【{_tmdId}】已更新學區資料 {BILogContent}", _dingDing, httpContext: HttpContext);
  648. return Ok(new { state = 200, area = area });
  649. }
  650. catch (Exception ex)
  651. {
  652. await _dingDing.SendBotMsg($"BI,{_option.Location} /batcharea/upd-area \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  653. return BadRequest();
  654. }
  655. }
  656. /// <summary>
  657. /// 创区后切换能力点, 先删除原来的能力点,后复制新的能力点 //已对接
  658. /// </summary>
  659. /// <param name="jsonElement"></param>
  660. /// <returns></returns>
  661. [ProducesDefaultResponseType]
  662. [AuthToken(Roles = "admin,rdc")]
  663. [HttpPost("cut-standard")]
  664. public async Task<IActionResult> CutStandard(JsonElement jsonElement)
  665. {
  666. try
  667. {
  668. if (!jsonElement.TryGetProperty("oldId", out JsonElement _oldId)) return BadRequest();
  669. if (!jsonElement.TryGetProperty("oldStandard", out JsonElement _oldStandard)) return BadRequest();
  670. if (!jsonElement.TryGetProperty("newId", out JsonElement _newId)) return BadRequest();
  671. if (!jsonElement.TryGetProperty("newStandard", out JsonElement _newStandard)) return BadRequest();
  672. jsonElement.TryGetProperty("newName", out JsonElement newName);
  673. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  674. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  675. //操作记录实体
  676. string blobOrTable = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
  677. var tableClient = _azureStorage.GetCloudTableClient();
  678. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  679. var cosmosClient = _azureCosmos.GetCosmosClient();
  680. var serBusClient = _serviceBus.GetServiceBusClient();
  681. var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");//秘钥地址
  682. ////分开部署,就不需要,一站多用时,取消注释
  683. //if ($"{site}".Equals(BIConst.Global))
  684. //{
  685. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  686. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  687. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  688. // serBusClient = _serviceBus.GetServiceBusClient(BIConst.Global); //暂未确定使用默认
  689. // //activeTask = _configuration.GetValue<string>("GlobalAzure:ServiceBus:ActiveTask"); //暂未确定使用默认
  690. //}
  691. var table = tableClient.GetTableReference("IESLogin");
  692. var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{_oldId}", new PartitionKey("AreaSetting"));
  693. if (responseSet.Status == 200)
  694. {
  695. using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
  696. AreaSetting delSet = fileJson.ToObject<AreaSetting>();
  697. if (!string.IsNullOrEmpty(delSet.accessConfig))
  698. return Ok(new { state = 401, msg = "区域已经规定了,不能切换能能力" });
  699. }
  700. //保存引用记录
  701. await table.SaveOrUpdate<AreaQuoteRecord>(new AreaQuoteRecord() { PartitionKey = "QuoteRecord", RowKey = $"{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}", areaId = $"{_oldId}", quoteId = $"{_newId}", quoteName = $"{newName}", standard = $"{_newStandard}" });
  702. List<string> abilityIds = new(); //册别的ID集合
  703. //查询册别信息
  704. 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}") }))
  705. {
  706. abilityIds.Add(tempAbility.id); //查询出来册别ID添加册别ID集合
  707. }
  708. //删除册别
  709. if (abilityIds.IsNotEmpty())
  710. {
  711. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityIds, $"Ability-{_oldStandard}");
  712. }
  713. List<string> abilityTaskIds = new(); //章节ID集合
  714. 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}") }))
  715. {
  716. abilityTaskIds.Add(item.id); //查询出来的章节信息ID添加到战绩集合
  717. }
  718. //删除章节
  719. if (abilityTaskIds.IsNotEmpty())
  720. {
  721. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityTaskIds, $"AbilityTask-{_oldStandard}");
  722. }
  723. List<Task<ItemResponse<Ability>>> abilities = new(); //存储册别数据
  724. List<Task<ItemResponse<AbilityTask>>> abilityTasks = new(); //存储章节
  725. //查询要复制区域的能力标准点
  726. 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}") }))
  727. {
  728. if (!string.IsNullOrEmpty(item.blob))
  729. {
  730. item.blob = item.blob.Replace($"/{_newStandard}/", $"/{_oldStandard}/");
  731. };
  732. item.standard = $"{_oldStandard}";
  733. item.code = $"Ability-{_oldStandard}";
  734. item.school = $"{_oldStandard}";
  735. //添加区能力标准点
  736. abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}")));
  737. }
  738. try
  739. {
  740. if (abilities.Count < 256)
  741. {
  742. await Task.WhenAll(abilities);
  743. }
  744. else
  745. {
  746. int pages = (abilities.Count + 255) / 256;
  747. for (int i = 0; i < pages; i++)
  748. {
  749. List<Task<ItemResponse<Ability>>> tempAbility = abilities.Skip((i) * 256).Take(256).ToList();
  750. await Task.WhenAll(tempAbility);
  751. }
  752. }
  753. }
  754. catch
  755. {
  756. return Ok(new { state = 200, msg = "能力标准点复制失败,遗留数据影响!" });
  757. }
  758. try
  759. {
  760. //微能力点
  761. 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}") }))
  762. {
  763. List<Tnode> tnodes = new();
  764. foreach (Tnode tnode in atask.children)
  765. {
  766. if (tnode.rnodes != null)
  767. {
  768. List<Rnode> rnodes = new();
  769. foreach (Rnode rnode in tnode.rnodes)
  770. {
  771. if (!string.IsNullOrEmpty($"{rnode.link}"))
  772. {
  773. rnode.link = rnode.link.Replace($"/{_newStandard}/", $"/{_oldStandard}/");
  774. }
  775. rnodes.Add(rnode);
  776. }
  777. tnode.rnodes = rnodes;
  778. }
  779. tnodes.Add(tnode);
  780. }
  781. atask.children = tnodes;
  782. atask.code = $"AbilityTask-{_oldStandard}";
  783. atask.standard = $"{_oldStandard}";
  784. atask.codeval = $"{_oldStandard}";
  785. ////添加区能力标准点中的节点
  786. //abilityTasks.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}")));
  787. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}"));
  788. }
  789. }
  790. catch
  791. {
  792. return Ok(new { state = 200, msg = "能力标准创建成功,微能力点复制失败,遗留数据影响!" });
  793. }
  794. StandardFile saveFile = new();
  795. //新政策文件
  796. 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") }))
  797. {
  798. if (standardFile != null)
  799. {
  800. standardFile.standard = $"{_oldStandard}";
  801. standardFile.id = $"{_oldId}";
  802. saveFile = standardFile;
  803. }
  804. }
  805. StandardFile tempFile = new();
  806. if (saveFile.id != null)
  807. {
  808. var respFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveFile.id, new PartitionKey("StandardFile"));
  809. if (respFile.Status == 200)
  810. {
  811. using var json = await JsonDocument.ParseAsync(respFile.ContentStream);
  812. tempFile = json.ToObject<StandardFile>();
  813. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<StandardFile>(tempFile.id, new PartitionKey("StandardFile"));
  814. }
  815. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
  816. }
  817. //新的区域设置
  818. AreaSetting saveSetting = new AreaSetting();
  819. 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") }))
  820. {
  821. if (areaSetting != null)
  822. {
  823. areaSetting.accessConfig = null;
  824. areaSetting.id = $"{_oldId}";
  825. saveSetting = areaSetting;
  826. }
  827. }
  828. AreaSetting tempSetting = new();
  829. if (saveSetting.id != null)
  830. {
  831. var respSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveSetting.id, new PartitionKey("AreaSetting"));
  832. if (respSetting.Status == 200)
  833. {
  834. using var json = await JsonDocument.ParseAsync(respSetting.ContentStream);
  835. tempSetting = json.ToObject<AreaSetting>();
  836. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<AreaSetting>(tempFile.id, new PartitionKey("AreaSetting"));
  837. }
  838. tempSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting")); //需要删除原来的区域设置数据在进行添加
  839. }
  840. //修改切换区级能力引用id
  841. Area area = new();
  842. area = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Area>($"{_oldId}", new PartitionKey("Base-Area"));
  843. area.quoteId = $"{_newId}";
  844. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<Area>(area, area.id, new PartitionKey(area.code));
  845. //发送消息分区键
  846. string partitionCode = "DelBeforeCopyAbility-mark";
  847. //v2通知
  848. Teacher targetTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>($"{_tmdId}", new PartitionKey($"Base"));
  849. _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);
  850. //执行复制操作
  851. BatchCopyFile batchCopyFile = new();
  852. batchCopyFile.blobCntr = "teammodelos";
  853. batchCopyFile.oldFileName = $"{_newStandard}";
  854. batchCopyFile.newFileName = $"{_oldStandard}";
  855. batchCopyFile.tmdid = $"{_tmdId}";
  856. batchCopyFile.tmdIds = new List<string> { $"{ _tmdId}" };
  857. batchCopyFile.codeKey = partitionCode;
  858. batchCopyFile.tmdName = $"{_tmdName}";
  859. var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
  860. messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
  861. try
  862. {
  863. //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile); //先执行删除操作,在执行复制 单一
  864. await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile); //先执行删除操作,在执行复制
  865. }
  866. catch (Exception)
  867. {
  868. return Ok(new { state = 201 ,msg = "能力点复制成功,复制能力点的文件失败," });
  869. }
  870. //保存操作记录
  871. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "area-cut", $"{_tmdName}【{_tmdId}】已操作【{_oldStandard}】切换至{_newStandard}微能力点,复制标准:{_newStandard}", _dingDing, httpContext: HttpContext);
  872. return Ok(new { state = 200 });
  873. }
  874. catch (Exception ex)
  875. {
  876. await _dingDing.SendBotMsg($"BI,{_option.Location} batcharea/cut-standard \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  877. return BadRequest();
  878. }
  879. }
  880. /// <summary>
  881. /// 删除区域和区域的册别、能力点、区域文件、区域设置
  882. /// </summary>
  883. /// <param name="jsonElement"></param>
  884. /// <returns></returns>
  885. [ProducesDefaultResponseType]
  886. [HttpPost("del-area")]
  887. public async Task<IActionResult> DelArea(JsonElement jsonElement)
  888. {
  889. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  890. if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
  891. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  892. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "teammodelos");
  893. var cosmosClient = _azureCosmos.GetCosmosClient();
  894. ////分开部署,就不需要,一站多用时,取消注释
  895. //if ($"{site}".Equals(BIConst.Global))
  896. //{
  897. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  898. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "teammodelos", BIConst.Global);
  899. //}
  900. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{areaId}", new PartitionKey("Base-Area"));
  901. if (response.Status == 200)
  902. {
  903. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  904. Area area = json.ToObject<Area>();
  905. if (area.standard == $"{standard}")
  906. {
  907. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<Area>(area.id, new PartitionKey("Base-Area")); //删除区
  908. List<Teacher> teachers = new();
  909. 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") }))
  910. {
  911. teachers.Add(item);
  912. }
  913. foreach (var item in teachers)
  914. {
  915. var tempArea = item.areas.Find(f => f.areaId.Equals(area.id));
  916. if (tempArea != null)
  917. {
  918. item.areas.Remove(tempArea);
  919. }
  920. item.schools.ForEach(fe => { if (fe.areaId.Equals(area.id)) fe.areaId = ""; });
  921. await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(item, item.id, new PartitionKey("Base"));
  922. }
  923. List<string> scIds = await CommonFind.FindScIds(cosmosClient, $"select value(c.id) from c where c.areaId='{area.id}' and c.standard ='{area.standard}'", "Base");
  924. foreach (var item in scIds)
  925. {
  926. School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(item, new PartitionKey("Base"));
  927. school.areaId = "";
  928. school.standard = "";
  929. school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey("Base"));
  930. }
  931. List<string> abilityIds = new(); //册别的ID集合
  932. List<string> abilityTaskIds = new(); //章节ID集合
  933. //查询册别信息
  934. 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}") }))
  935. {
  936. abilityIds.Add(tempAbility.id); //查询出来册别ID添加册别ID集合
  937. }
  938. //删除册别
  939. if (abilityIds.IsNotEmpty())
  940. {
  941. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityIds, $"Ability-{area.standard}");
  942. }
  943. 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}") }))
  944. {
  945. abilityTaskIds.Add(item.id); //查询出来的章节信息ID添加到战绩集合
  946. }
  947. //删除章节
  948. if (abilityTaskIds.IsNotEmpty())
  949. {
  950. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityTaskIds, $"AbilityTask-{standard}");
  951. }
  952. //区域政策文件
  953. StandardFile delFile = new();
  954. var responseFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(area.id, new PartitionKey("StandardFile"));
  955. if(responseFile.Status == 200)
  956. {
  957. using var fileJson = await JsonDocument.ParseAsync(responseFile.ContentStream);
  958. delFile = fileJson.ToObject<StandardFile>();
  959. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<StandardFile>(delFile.id, new PartitionKey("StandardFile"));
  960. }
  961. //区域设置
  962. AreaSetting delSet = new();
  963. var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(area.id, new PartitionKey("AreaSetting"));
  964. if (responseSet.Status == 200)
  965. {
  966. using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
  967. delSet = fileJson.ToObject<AreaSetting>();
  968. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<AreaSetting>(delSet.id, new PartitionKey("AreaSetting"));
  969. }
  970. List<object> fileobj = new();
  971. //先删除原有的文件
  972. List<Task<Response<bool>>> DelList = new();
  973. await foreach (BlobItem blobItem in blobClient.GetBlobsAsync(BlobTraits.None, BlobStates.None, $"yxpt/{area.standard}/"))
  974. {
  975. fileobj.Add(blobItem.Name);
  976. DelList.Add(blobClient.GetBlobBaseClient(blobItem.Name).DeleteIfExistsAsync());
  977. }
  978. if (DelList.Count <= 256)
  979. {
  980. await Task.WhenAll(DelList);
  981. }
  982. else
  983. {
  984. int pages = (DelList.Count + 255) / 256;
  985. for (int i = 0; i < pages; i++)
  986. {
  987. List<Task<Response<bool>>> delList = DelList.Skip((i) * 256).Take(256).ToList();
  988. await Task.WhenAll(delList);
  989. }
  990. }
  991. return Ok(new { state = 200,area, scIds, abilityIds, abilityTaskIds, delFile, delSet, fileobj });
  992. }
  993. else return Ok(new { state = 400, msg = "id和standard不匹配!" });
  994. }
  995. else return Ok(new { state = 404,msg="依据Id未找到该区!" });
  996. }
  997. /// <summary>
  998. /// 同步两个区到新的区中
  999. /// </summary>
  1000. /// <param name="jsonElement"></param>
  1001. /// <returns></returns>
  1002. [ProducesDefaultResponseType]
  1003. [AuthToken(Roles = "admin")]
  1004. [HttpPost("cut-full-statndard")]
  1005. public async Task<IActionResult> CutFullStandard(JsonElement jsonElement)
  1006. {
  1007. try
  1008. {
  1009. string _oldId = "bde5c011-2ae4-461a-b46c-5483ba72ae45";
  1010. //string _oldStandard = "standard27";
  1011. string standardFileId = "02944f32-f534-3397-ea56-e6f1fc6c3714";
  1012. string standard = "standard2";
  1013. List<CopyStandard> copyStand = new()
  1014. {
  1015. new CopyStandard() { id = standardFileId, standard = standard },
  1016. new CopyStandard() { id = "99a4a33b-e21b-44ac-80a1-b31dc40496e0", standard = "standard3" }
  1017. };
  1018. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  1019. var tableClient = _azureStorage.GetCloudTableClient();
  1020. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  1021. var cosmosClient = _azureCosmos.GetCosmosClient();
  1022. var serBusClient = _serviceBus.GetServiceBusClient();
  1023. var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");//秘钥地址
  1024. var table = tableClient.GetTableReference("IESLogin");
  1025. Area area = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Area>($"{_oldId}", new PartitionKey("Base-Area"));
  1026. if (area != null)
  1027. {
  1028. var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{_oldId}", new PartitionKey("AreaSetting"));
  1029. if (responseSet.Status == 200)
  1030. {
  1031. using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
  1032. AreaSetting delSet = fileJson.ToObject<AreaSetting>();
  1033. if (!string.IsNullOrEmpty(delSet.accessConfig))
  1034. return Ok(new { state = 401, msg = "区域已经规定了,不能切换能能力" });
  1035. }
  1036. List<string> abilityIds = new(); //册别的ID集合
  1037. //查询册别信息
  1038. 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}") }))
  1039. {
  1040. abilityIds.Add(tempAbility.id); //查询出来册别ID添加册别ID集合
  1041. }
  1042. //删除册别
  1043. if (abilityIds.IsNotEmpty())
  1044. {
  1045. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityIds, $"Ability-{area.standard}");
  1046. }
  1047. List<string> abilityTaskIds = new List<string>(); //章节ID集合
  1048. 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}") }))
  1049. {
  1050. abilityTaskIds.Add(item.id); //查询出来的章节信息ID添加到战绩集合
  1051. }
  1052. //删除章节
  1053. if (abilityTaskIds.IsNotEmpty())
  1054. {
  1055. var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityTaskIds, $"AbilityTask-{area.standard}");
  1056. }
  1057. List<Task<ItemResponse<Ability>>> abilities = new(); //存储册别数据
  1058. List<Task<ItemResponse<AbilityTask>>> abilityTasks = new(); //存储章节
  1059. List<string> repeatAbilityId = new();
  1060. List<string> repeatAbilityTaskId = new();
  1061. foreach (var newstand in copyStand)
  1062. {
  1063. try
  1064. {
  1065. //查询要复制区域的能力标准点
  1066. 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}") }))
  1067. {
  1068. if (!string.IsNullOrEmpty(item.blob))
  1069. item.blob = item.blob.Replace($"/{newstand.standard}/", $"/{area.standard}/");
  1070. item.standard = $"{area.standard}";
  1071. item.code = $"Ability-{area.standard}";
  1072. item.school = $"{area.standard}";
  1073. //添加区能力标准点
  1074. //abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}")));
  1075. //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}"));
  1076. var respond = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(item.id, new PartitionKey(item.code));
  1077. if (respond.Status != 200)
  1078. abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{area.standard}")));
  1079. else
  1080. repeatAbilityId.Add(item.id);
  1081. }
  1082. }
  1083. catch
  1084. {
  1085. return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
  1086. }
  1087. try
  1088. {
  1089. if (abilities.Count < 256)
  1090. {
  1091. await Task.WhenAll(abilities);
  1092. }
  1093. else
  1094. {
  1095. int pages = (abilities.Count + 255) / 256;
  1096. for (int i = 0; i < pages; i++)
  1097. {
  1098. List<Task<ItemResponse<Ability>>> tempAbility = abilities.Skip((i) * 256).Take(256).ToList();
  1099. await Task.WhenAll(tempAbility);
  1100. }
  1101. }
  1102. }
  1103. catch
  1104. {
  1105. return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
  1106. }
  1107. try
  1108. {
  1109. //微能力点
  1110. 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}") }))
  1111. {
  1112. List<Tnode> tnodes = new();
  1113. foreach (Tnode tnode in atask.children)
  1114. {
  1115. if (tnode.rnodes != null)
  1116. {
  1117. List<Rnode> rnodes = new();
  1118. foreach (Rnode rnode in tnode.rnodes)
  1119. {
  1120. if (!string.IsNullOrEmpty($"{rnode.link}"))
  1121. {
  1122. rnode.link = rnode.link.Replace($"/{newstand.standard}/", $"/{area.standard}/");
  1123. }
  1124. rnodes.Add(rnode);
  1125. }
  1126. tnode.rnodes = rnodes;
  1127. }
  1128. tnodes.Add(tnode);
  1129. }
  1130. atask.children = tnodes;
  1131. atask.code = $"AbilityTask-{area.standard}";
  1132. atask.standard = $"{area.standard}";
  1133. atask.codeval = $"{area.standard}";
  1134. var respond = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(atask.id, new PartitionKey(atask.code));
  1135. if (respond.Status != 200)
  1136. ////添加区能力标准点中的节点
  1137. //abilityTasks.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}")));
  1138. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{area.standard}"));
  1139. else
  1140. repeatAbilityTaskId.Add(atask.id);
  1141. }
  1142. }
  1143. catch
  1144. {
  1145. return Ok(new { state = 200, msg = "创区成功,能力标准创建成功,微能力点复制失败,遗留数据影响!" });
  1146. }
  1147. //发送消息分区键
  1148. string partitionCode = "DelBeforeCopyAbility-mark";
  1149. //执行复制操作
  1150. BatchCopyFile batchCopyFile = new();
  1151. batchCopyFile.blobCntr = "teammodelos";
  1152. batchCopyFile.oldFileName = $"{newstand.standard}";
  1153. batchCopyFile.newFileName = $"{area.standard}";
  1154. batchCopyFile.tmdid = $"{_tmdId}";
  1155. batchCopyFile.tmdIds = new List<string> { $"{_tmdId}" };
  1156. batchCopyFile.codeKey = partitionCode;
  1157. batchCopyFile.tmdName = $"{_tmdName}";
  1158. var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
  1159. messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
  1160. try
  1161. {
  1162. //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile); //先执行删除操作,在执行复制 单一
  1163. await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile); //先执行删除操作,在执行复制
  1164. }
  1165. catch (Exception)
  1166. {
  1167. return Ok(new { state = 201, msg = "能力点复制成功,复制能力点的文件失败," });
  1168. }
  1169. }
  1170. StandardFile saveFile = new();
  1171. //新政策文件
  1172. 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") }))
  1173. {
  1174. if (standardFile != null)
  1175. {
  1176. standardFile.standard = $"{area.standard}";
  1177. standardFile.id = $"{_oldId}";
  1178. saveFile = standardFile;
  1179. }
  1180. }
  1181. StandardFile tempFile = new();
  1182. if (saveFile.id != null)
  1183. {
  1184. var respFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveFile.id, new PartitionKey("StandardFile"));
  1185. if (respFile.Status == 200)
  1186. {
  1187. using var json = await JsonDocument.ParseAsync(respFile.ContentStream);
  1188. tempFile = json.ToObject<StandardFile>();
  1189. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<StandardFile>(tempFile.id, new PartitionKey("StandardFile"));
  1190. }
  1191. tempFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
  1192. }
  1193. //if (tempFile.id != null)
  1194. //{
  1195. // if (tempFile.id.Equals(saveFile.id))
  1196. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<StandardFile>(saveFile, saveFile.id, new PartitionKey("StandardFile")); //直接替换以前的数据
  1197. // else
  1198. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
  1199. //}
  1200. //新的区域设置
  1201. AreaSetting saveSetting = new();
  1202. 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") }))
  1203. {
  1204. if (areaSetting != null)
  1205. {
  1206. areaSetting.accessConfig = null;
  1207. areaSetting.id = $"{_oldId}";
  1208. saveSetting = areaSetting;
  1209. }
  1210. }
  1211. AreaSetting tempSetting = new();
  1212. if (saveSetting.id != null)
  1213. {
  1214. var respSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveSetting.id, new PartitionKey("AreaSetting"));
  1215. if (respSetting.Status == 200)
  1216. {
  1217. using var json = await JsonDocument.ParseAsync(respSetting.ContentStream);
  1218. tempSetting = json.ToObject<AreaSetting>();
  1219. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<AreaSetting>(saveSetting.id, new PartitionKey("AreaSetting"));
  1220. }
  1221. tempSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting")); //需要删除原来的区域设置数据在进行添加
  1222. }
  1223. //if (tempSetting.id != null)
  1224. //{
  1225. // if (tempSetting.id.Equals(saveSetting.id))
  1226. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<AreaSetting>(saveSetting, saveSetting.id, new PartitionKey($"AreaSetting")); //直接替换以前的数据
  1227. // else
  1228. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting")); //需要删除原来的区域设置数据在进行添加
  1229. //}
  1230. return Ok(new { state = RespondCode.Ok, repeatAbilityId, repeatAbilityTaskId });
  1231. }
  1232. else
  1233. return Ok(new { state = RespondCode.NotFound, msg = "标准为空"}) ;
  1234. }
  1235. catch (Exception ex)
  1236. {
  1237. await _dingDing.SendBotMsg($"BI,{_option.Location} batcharea/cut-full-statndard \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1238. return BadRequest();
  1239. }
  1240. }
  1241. /// <summary>
  1242. /// 区域列表
  1243. /// </summary>
  1244. public record RecArea
  1245. {
  1246. public string id { get; set; }
  1247. public string code { get; set; }
  1248. public string pk { get; set; }
  1249. public string shortCode { get; set; }
  1250. public string name { get; set; }
  1251. public string provCode { get; set; }
  1252. public string provName { get; set; }
  1253. public string cityCode { get; set; }
  1254. public string cityName { get; set; }
  1255. public string standard { get; set; }
  1256. public string standardName { get; set; }
  1257. public string institution { get; set; }
  1258. public int schoolCount { get; set; }
  1259. public long updateTime { get; set; }
  1260. public string quoteId { get; set; } = null;
  1261. public bool cutArea { get; set; } = false;
  1262. public List<AreaQuoteRecord> aquoteRec { get; set; } = new List<AreaQuoteRecord>();
  1263. }
  1264. }
  1265. }