|
@@ -0,0 +1,270 @@
|
|
|
+using Microsoft.AspNetCore.Hosting;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
+using System.Net.Http;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK;
|
|
|
+using TEAMModelOS.Models;
|
|
|
+using System.Text.Json;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelOS.SDK.Context.Constant;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Text;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelBI.Models;
|
|
|
+using System.Linq;
|
|
|
+using TEAMModelBI.Filter;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
|
+using Azure.Cosmos;
|
|
|
+using System;
|
|
|
+using TEAMModelOS.SDK.Models.Service.BI;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
|
|
|
+using TEAMModelBI.Tool.Extension;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using DocumentFormat.OpenXml.Spreadsheet;
|
|
|
+using System.Net.Http.Json;
|
|
|
+
|
|
|
+namespace TEAMModelBI.Controllers.BICommon
|
|
|
+{
|
|
|
+ [Route("notice")]
|
|
|
+ [ApiController]
|
|
|
+ public class BINoticeController : ControllerBase
|
|
|
+ {
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly Option _option;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
+ private readonly IConfiguration _configuration;
|
|
|
+ private readonly AzureServiceBusFactory _serviceBus;
|
|
|
+ private readonly IHttpClientFactory _http;
|
|
|
+ private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
+ private readonly IWebHostEnvironment _environment; //读取文件
|
|
|
+ private readonly HttpClient _httpClient;
|
|
|
+
|
|
|
+ public BINoticeController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, AzureServiceBusFactory serviceBus, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService, IWebHostEnvironment hostingEnvironment, HttpClient httpClient)
|
|
|
+ {
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
+ _option = option?.Value;
|
|
|
+ _configuration = configuration;
|
|
|
+ _serviceBus = serviceBus;
|
|
|
+ _http = http;
|
|
|
+ _coreAPIHttpService = coreAPIHttpService;
|
|
|
+ _environment = hostingEnvironment;
|
|
|
+ _httpClient = httpClient;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询账户信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [AuthToken(Roles = "admin,rdc,assist,sales")]
|
|
|
+ [HttpPost("get-info")]
|
|
|
+ public async Task<IActionResult> GetInfo(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ jsonElement.TryGetProperty("ids", out JsonElement _ids);
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ List<string> ids = new();
|
|
|
+ ids = _ids.ToObject<List<string>>();
|
|
|
+ List<TmdUserinfo> userinfos = new();
|
|
|
+ List<string> noFound = new();
|
|
|
+ if (ids.Count > 0)
|
|
|
+ {
|
|
|
+ var content = new StringContent(ids.ToArray().ToJsonString(), Encoding.UTF8, "application/json");
|
|
|
+ string idJson = await _coreAPIHttpService.GetUserInfos(content);
|
|
|
+ userinfos = idJson.ToObject<List<TmdUserinfo>>();
|
|
|
+
|
|
|
+ foreach (var item in ids)
|
|
|
+ {
|
|
|
+ var tempId = userinfos.Where(s => s.id.Equals(item)).ToList();
|
|
|
+ var tempMail = userinfos.Where(s => !string.IsNullOrEmpty($"{s.mail}") && s.mail.Equals(item)).ToList();
|
|
|
+ var tempmobile = userinfos.Where(s => !string.IsNullOrEmpty($"{s.mobile}") && s.mobile.Equals(item)).ToList();
|
|
|
+ if (tempId.Count == 0 && tempMail.Count == 0 && tempmobile.Count == 0)
|
|
|
+ noFound.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, userinfos, noFound });
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 依据学校id查询学校教师信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ //[AuthToken(Roles = "admin,rdc,assist,sales")]
|
|
|
+ [HttpPost("get-tchinfos")]
|
|
|
+ public async Task<IActionResult> GetSchoolTeacher(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("scId", out JsonElement scId)) return BadRequest();
|
|
|
+
|
|
|
+ List<IdInfo> idInfos = new();
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS,"School").GetItemQueryIterator<IdInfo>(queryText: "select c.id,c.name,c.picture from c",requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{scId}") }))
|
|
|
+ {
|
|
|
+ idInfos.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, idInfos });
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// BI发布端外消息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [AuthToken(Roles = "admin,rdc,assist,sales")]
|
|
|
+ [HttpPost("push-info")]
|
|
|
+ public async Task<IActionResult> PushNotion(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var (_tmdId, _tmdName, _, _, _, _) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
|
|
|
+
|
|
|
+ jsonElement.TryGetProperty("type", out JsonElement type);
|
|
|
+ jsonElement.TryGetProperty("jumpUrl", out JsonElement jumpUrl);
|
|
|
+ jsonElement.TryGetProperty("callbackUrl", out JsonElement callbackUrl);
|
|
|
+ if (!jsonElement.TryGetProperty("theme", out JsonElement theme)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("content", out JsonElement content)) return BadRequest();
|
|
|
+ jsonElement.TryGetProperty("tmdIds", out JsonElement _tmdIds);
|
|
|
+ jsonElement.TryGetProperty("schoolIds", out JsonElement _schoolIds);
|
|
|
+ jsonElement.TryGetProperty("areaIds", out JsonElement _areaIds);
|
|
|
+ if (!jsonElement.TryGetProperty("crowdType", out JsonElement _crowdType)) return BadRequest();
|
|
|
+ jsonElement.TryGetProperty("sendTime", out JsonElement sendTime);
|
|
|
+ jsonElement.TryGetProperty("source", out JsonElement source);
|
|
|
+
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
|
+
|
|
|
+ List<IdNameCode> idNameCodes = new();
|
|
|
+ BINotice bINotice = new();
|
|
|
+ List<string> tmdIds = new();
|
|
|
+ List<string> schoolIds = new();
|
|
|
+ List<string> areaIds = new();
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{sendTime}"))
|
|
|
+ dateTime = DateTimeOffset.Parse($"{sendTime}");
|
|
|
+ if (string.IsNullOrEmpty($"{_tmdIds}") && string.IsNullOrEmpty($"{_schoolIds}") && string.IsNullOrEmpty($"{_areaIds}"))
|
|
|
+ return Ok(new { state = RespondCode.ParamsError, msg = "发送人群不能为空" });
|
|
|
+ if (!string.IsNullOrEmpty($"{_tmdIds}"))
|
|
|
+ tmdIds = _tmdIds.ToObject<List<string>>();
|
|
|
+ if (!string.IsNullOrEmpty($"{_schoolIds}"))
|
|
|
+ schoolIds = _schoolIds.ToObject<List<string>>();
|
|
|
+ if (!string.IsNullOrEmpty($"{_areaIds}"))
|
|
|
+ areaIds = _areaIds.ToObject<List<string>>();
|
|
|
+
|
|
|
+ Crowd crowd = new()
|
|
|
+ {
|
|
|
+ tmdIds = tmdIds.Count > 0 ? tmdIds : new List<string>(),
|
|
|
+ schoolIds = schoolIds.Count > 0 ? schoolIds : new List<string>(),
|
|
|
+ areaIds = areaIds.Count > 0 ? areaIds : new List<string>(),
|
|
|
+ type = $"{_crowdType}"
|
|
|
+ };
|
|
|
+
|
|
|
+ if (tmdIds.Count > 0)
|
|
|
+ {
|
|
|
+ StringBuilder tchSql = new($"select c.id, c.name,c.code,c.picture,c.nickname from c ");
|
|
|
+ if (tmdIds.Count > 0)
|
|
|
+ {
|
|
|
+ tchSql.Append(BICommonWay.ManyScSql(" where c.id ", tmdIds));
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<IdNameCode>(queryText: tchSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ var tempId = idNameCodes.FindAll(fa => fa.id.Equals(item)).ToList();
|
|
|
+ if (tempId.Count == 0)
|
|
|
+ idNameCodes.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (areaIds.Count > 0)
|
|
|
+ {
|
|
|
+ StringBuilder scAreaSql = new($"select value(c.id) from c");
|
|
|
+ if (schoolIds.Count > 0)
|
|
|
+ {
|
|
|
+ scAreaSql.Append(BICommonWay.ManyScSql(" where c.areaId", areaIds));
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<string>(queryText: scAreaSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ var tempScId = schoolIds.FindAll(fa => fa.Equals(item)).ToList();
|
|
|
+ if (tempScId.Count == 0)
|
|
|
+ schoolIds.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (schoolIds.Count > 0)
|
|
|
+ {
|
|
|
+ StringBuilder scTchSql = new($"select c.id, c.name, c.picture,c.nickname from c where c.pk='Teacher'");
|
|
|
+ if (schoolIds.Count > 0)
|
|
|
+ {
|
|
|
+ scTchSql.Append(BICommonWay.ManyScSql(" and c.code", schoolIds, $"Teacher-"));
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<IdNameCode>(queryText: scTchSql.ToString(), requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ var tempId = idNameCodes.FindAll(fa => fa.id.Equals(item)).ToList();
|
|
|
+ if (tempId.Count == 0)
|
|
|
+ idNameCodes.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ bINotice = new()
|
|
|
+ {
|
|
|
+ id = Guid.NewGuid().ToString(),
|
|
|
+ code = "BINotice",
|
|
|
+ type = !string.IsNullOrEmpty($"{type}") ? type.GetInt32() : 0,
|
|
|
+ jumpUrl = !string.IsNullOrEmpty($"{jumpUrl}") ? $"{jumpUrl}" : "",
|
|
|
+ callbackUrl = !string.IsNullOrEmpty($"{callbackUrl}") ? $"{callbackUrl}" : "",
|
|
|
+ theme = $"{theme}",
|
|
|
+ content = $"{content}",
|
|
|
+ crowd = crowd,
|
|
|
+ crowdIds = tmdIds,
|
|
|
+ createId = _tmdId,
|
|
|
+ sendTime = dateTime.ToUnixTimeMilliseconds(),//发布时间待解决
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ source = !string.IsNullOrEmpty($"{source}") ? $"{source}" : "BI"
|
|
|
+ };
|
|
|
+
|
|
|
+ bINotice = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync<BINotice>(bINotice, new PartitionKey("BINotice"));
|
|
|
+ //BI发送端外通知
|
|
|
+ _coreAPIHttpService.BIPushNotify(bINotice, new Dictionary<string, object> { { "tmdid", _tmdIds }, { "tmdname", _tmdName } }, _option.Location, _configuration, _dingDing);
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, bINotice });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _ = _dingDing.SendBotMsg($"BI, notion/PushNotion() \n{ex.Message}\n{ex.StackTrace}\n", GroupNames.成都开发測試群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询发布的消息信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [AuthToken(Roles = "admin,rdc,assist,sales")]
|
|
|
+ [HttpPost("get-infos")]
|
|
|
+ public async Task<IActionResult> GetInfos(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ jsonElement.TryGetProperty("id", out JsonElement id);
|
|
|
+
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ List<BINotice> bINotices = new();
|
|
|
+ StringBuilder sql = new("select value(c) from c");
|
|
|
+ if (!string.IsNullOrEmpty($"{id}"))
|
|
|
+ sql.Append($" where c.id='{id}'");
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS,"Common").GetItemQueryIterator<BINotice>(queryText:sql.ToString(),requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("BINotice") }))
|
|
|
+ {
|
|
|
+ bINotices.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, bINotices });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|