|
@@ -634,6 +634,75 @@ namespace TEAMModelBI.Controllers.BINormal
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 修改學區
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "admin,rdc")]
|
|
|
+ [HttpPost("upd-area")]
|
|
|
+ public async Task<IActionResult> updArea(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("id", out JsonElement _id)) return BadRequest();
|
|
|
+ string id = _id.GetString();
|
|
|
+ string shortCode = (jsonElement.TryGetProperty("shortCode", out JsonElement _shortCode)) ? _shortCode.GetString() : string.Empty;
|
|
|
+ string name = (jsonElement.TryGetProperty("name", out JsonElement _name)) ? _name.GetString() : string.Empty;
|
|
|
+ if(string.IsNullOrWhiteSpace(shortCode) && string.IsNullOrWhiteSpace(name))
|
|
|
+ {
|
|
|
+ return Ok(new { state = 1, message = "输入值有误,请检查输入值" });
|
|
|
+ }
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();//数据库连接
|
|
|
+ //學區取得
|
|
|
+ Area area = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Area>(id, new PartitionKey($"Base-Area"));
|
|
|
+ //輸入值重複檢驗
|
|
|
+ string queryText = $"SELECT value(c) from c ";
|
|
|
+ string queryWhere = string.Empty;
|
|
|
+ if (!string.IsNullOrWhiteSpace(name))
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrWhiteSpace(queryWhere)) queryWhere += " OR ";
|
|
|
+ queryWhere += $"c.name='{name}'";
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace(shortCode))
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrWhiteSpace(queryWhere)) queryWhere += " OR ";
|
|
|
+ queryWhere += $"c.shortCode='{shortCode}'";
|
|
|
+ }
|
|
|
+ queryWhere = $"WHERE ({queryWhere}) AND c.id != '{id}'";
|
|
|
+ queryText = $"{queryText}{queryWhere}";
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"{queryText}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
|
|
|
+ {
|
|
|
+ //查询区级名称是否存在
|
|
|
+ if (item.name.Equals($"{name}"))
|
|
|
+ return Ok(new { state = 1, message = "区级名称相同,请检测区级名称!" });
|
|
|
+ //查询學區簡碼是否存在
|
|
|
+ if (item.shortCode.Equals($"{shortCode}"))
|
|
|
+ return Ok(new { state = 1, message = "此学区简码已存在请检查" });
|
|
|
+ }
|
|
|
+ //DB值更新
|
|
|
+ if (!string.IsNullOrWhiteSpace(name)) area.name = name;
|
|
|
+ if (!string.IsNullOrWhiteSpace(shortCode)) area.shortCode = shortCode;
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<Area>(area, id);
|
|
|
+ //保存操作记录
|
|
|
+ var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
|
|
|
+ var tableClient = _azureStorage.GetCloudTableClient();
|
|
|
+ var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
|
|
|
+ string BILogContent = string.Empty;
|
|
|
+ BILogContent += $"学区ID:{id}, 更新资料: ";
|
|
|
+ if (!string.IsNullOrWhiteSpace(name)) BILogContent += $"name:{name}, ";
|
|
|
+ if (!string.IsNullOrWhiteSpace(shortCode)) BILogContent += $"shortCode:{shortCode}, ";
|
|
|
+ await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "upd-area", $"{_tmdName}【{_tmdId}】已更新學區資料 {BILogContent}", _dingDing, httpContext: HttpContext);
|
|
|
+ return Ok(new { state = 200, area = area });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"BI,{_option.Location} /batcharea/upd-area \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 创区后切换能力点, 先删除原来的能力点,后复制新的能力点 //已对接
|
|
|
/// </summary>
|