BatchAreaController.cs 82 KB

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