浏览代码

Merge branch 'PL/develop-BI' into develop

Li 2 年之前
父节点
当前提交
17f8dd4509

+ 6 - 8
TEAMModelBI/Controllers/Core/BlobController.cs

@@ -14,7 +14,7 @@ using TEAMModelOS.SDK.Context.BI;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 
-namespace TEAMModelBI.Controllers.Core
+namespace TEAMModelBI.Controllers.BISystem
 {
     [Route("blob")]
     [ApiController]
@@ -52,19 +52,20 @@ namespace TEAMModelBI.Controllers.Core
         [HttpPost("upload-public")]
         [AuthToken(Roles = "admin,rdc,assist,sales")]
         [RequestSizeLimit(102_400_000_00)]//最大10000m左右
-        public async Task<IActionResult> UploadPublic([FromForm] IFormFile file,[FromHeader]string site)
+        public async Task<IActionResult> UploadPublic([FromForm] IFormFile file, [FromHeader] string upType)
         {
             var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
             string fileExt = FileType.GetExtention(file.FileName).ToLower();
             var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
-            if ($"{site}".Equals(BIConst.Global))
-                blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
+            string typeName = "school";
+            if ($"{upType}".Equals("biz"))
+                typeName = "business";
 
             if (ContentTypeDict.dict.ContainsKey($".{fileExt}"))
             {
                 //var url = await _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global).UploadFileByContainer("0-public", file.OpenReadStream(), "school", $"{Guid.NewGuid()}.{fileExt}", false);
                 //var url = await BIAzureStorageBlobExtensions.UploadFileByContainer(blobClient, file.OpenReadStream(), "school", $"{Guid.NewGuid()}.{fileExt}");
-                var url = await AzureStorageBlobExtensions.UploadFileByContainer(blobClient, file.OpenReadStream(), "school", $"{Guid.NewGuid()}.{fileExt}");
+                var url = await blobClient.UploadFileByContainer(file.OpenReadStream(), typeName, $"{Guid.NewGuid()}.{fileExt}");
                 return Ok(new { url });
             }
             else
@@ -73,8 +74,5 @@ namespace TEAMModelBI.Controllers.Core
             }
         }
 
-
-
-
     }
 }

+ 169 - 0
TEAMModelBI/Controllers/RepairApi/InitialAreaController.cs

@@ -0,0 +1,169 @@
+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 Azure.Messaging.ServiceBus;
+using TEAMModelBI.Tool.Extension;
+using TEAMModelOS.SDK.Extension;
+using Microsoft.AspNetCore.Hosting;
+using TEAMModelOS.SDK.DI.CoreAPI;
+using TEAMModelOS.SDK.Models;
+using Azure.Cosmos;
+using System;
+using System.Collections.Generic;
+
+namespace TEAMModelBI.Controllers.RepairApi
+{
+    [Route("initialarea")]
+    [ApiController]
+    public class InitialAreaController : ControllerBase
+    {
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+        private readonly AzureStorageFactory _azureStorage;
+        private readonly IConfiguration _configuration;
+        private readonly NotificationService _notificationService;
+        private readonly AzureServiceBusFactory _serviceBus;
+        private readonly IHttpClientFactory _http;
+        private readonly CoreAPIHttpService _coreAPIHttpService;
+        private readonly IWebHostEnvironment _environment; //读取文件
+
+        public InitialAreaController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, NotificationService notificationService, AzureServiceBusFactory serviceBus, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService, IWebHostEnvironment hostingEnvironment)
+        {
+            _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
+            _azureStorage = azureStorage;
+            _option = option?.Value;
+            _configuration = configuration;
+            _notificationService = notificationService;
+            _serviceBus = serviceBus;
+            _http = http;
+            _coreAPIHttpService = coreAPIHttpService;
+            _environment = hostingEnvironment;
+        }
+
+        /// <summary>
+        /// 创建完整版的学区初始化
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [HttpPost("create-full-version")]
+        public async Task<IActionResult> CreateFullVersion(JsonElement jsonElement) 
+        {
+            if (!jsonElement.TryGetProperty("name", out JsonElement name)) return BadRequest();
+            jsonElement.TryGetProperty("provCode", out JsonElement provCode);
+            jsonElement.TryGetProperty("provName", out JsonElement provName);
+            jsonElement.TryGetProperty("cityCode", out JsonElement cityCode);
+            jsonElement.TryGetProperty("cityName", out JsonElement cityName);
+            jsonElement.TryGetProperty("areaAdmin", out JsonElement areadAdmin);
+            if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
+            if (!jsonElement.TryGetProperty("standardName", out JsonElement standardName)) return BadRequest();
+            jsonElement.TryGetProperty("institution", out JsonElement institution);
+            jsonElement.TryGetProperty("oldId", out JsonElement _oldId);
+            jsonElement.TryGetProperty("oldStandard", out JsonElement oldStandard);
+            jsonElement.TryGetProperty("oldName", out JsonElement oldName);
+            //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
+
+            var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
+
+            //操作记录实体
+            var tempStandard = !string.IsNullOrEmpty($"{oldStandard}") && !string.IsNullOrEmpty($"{_oldId}") ? $"{oldStandard}" : "standard2";
+
+            var cosmosClient = _azureCosmos.GetCosmosClient();  //数据库连接
+            var tableClient = _azureStorage.GetCloudTableClient();
+            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+
+            ServiceBusClient serBusClient;
+            try
+            {
+                serBusClient = _serviceBus.GetServiceBusClient();
+            }
+            catch
+            {
+                return Ok(new { state = 403, msg = "Functionn未启动,请联系管理员" });
+            }
+
+            var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+            var table = tableClient.GetTableReference("IESLogin");
+
+            //查询新的是否存在
+            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") }))
+            {
+                if (item.standard.Equals($"{standard}"))
+                    return Ok(new { state = 1, message = "新创区的standard已存在请检查" });
+            }
+
+            //区级的ID
+            string areaId = Guid.NewGuid().ToString();
+            Area addArea = new()
+            {
+                id = areaId,
+                code = $"Base-Area",
+                name = $"{name}",
+                provCode = $"{provCode}",
+                provName = $"{provName}",
+                cityCode = $"{cityCode}",
+                cityName = $"{cityName}",
+                standard = $"{standard}",
+                standardName = $"{standardName}",
+                institution = $"{institution}"
+            };
+
+
+            #region  区级管理员
+
+            var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{areadAdmin}" } }, _option.Location, _configuration);
+            if (coreUser == null || coreUser.id == null)
+                return Ok(new { state = 404, msg = "未找到改账户的管理员" });
+
+            //string tmdId = !string.IsNullOrEmpty(tempTmdId) ? tempTmdId : $"{areadAdmin}";
+            Teacher teacher = null;
+            try
+            {
+                //查询该教师是否存在
+                teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{coreUser.id}", new PartitionKey("Base"));
+            }
+            catch
+            {
+            }
+
+            if (teacher != null)
+            {
+                //教师存在,在该教师信息中添加要管理的学校信息
+                teacher.areas.Add(new Teacher.TeacherArea { areaId = addArea.id, status = "join", name = addArea.name });
+                await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
+            }
+            else
+            {
+                teacher.id = coreUser.id;
+                teacher.name = coreUser.name;
+                teacher.picture = coreUser.picture;
+                teacher.pk = "Base";
+                teacher.code = "Base";
+                teacher.size = 1;
+                teacher.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                //教师存在,在该教师信息中添加要管理的学校信息
+                teacher.areas.Add(new Teacher.TeacherArea { areaId = addArea.id, status = "join", name = addArea.name });
+                await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
+            }
+
+            #endregion
+
+
+            return Ok(new { sate = RespondCode.Ok });
+        }
+
+
+
+
+
+    }
+}

+ 90 - 2
TEAMModelOS/Controllers/OpenApi/Init/BizUsersController.cs

@@ -6,10 +6,13 @@ using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Options;
 using System;
 using System.Collections.Generic;
+using System.Security.Policy;
+using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.Context.BI;
 using TEAMModelOS.SDK.Context.Constant;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
@@ -198,8 +201,6 @@ namespace TEAMModelOS.Controllers
             }
         }
 
-
-
         /// <summary>
         /// 重置秘钥
         /// </summary>
@@ -283,5 +284,92 @@ namespace TEAMModelOS.Controllers
             List<OpenApi> apis = await table.FindListByDict<OpenApi>(new Dictionary<string, object>() { { "PartitionKey", "IES5-API-business" } });
             return Ok(new { state = RespondCode.Ok, apis });
         }
+
+        /// <summary>
+        /// 修改和新增企业信息
+        /// </summary>
+        /// <param name="bizConfig"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("set-info")]
+        public async Task<IActionResult> SetInfo(BizConfig bizConfig)
+        {
+            StringBuilder strMsg = new();
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            var tableClient = _azureStorage.GetCloudTableClient();
+            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+            string salt = Utils.CreatSaltString(8);
+            List<BizUsers> bizUsers = new();
+            string type = "";
+
+            //新增企业信息
+            if (string.IsNullOrEmpty(bizConfig.id))
+            {
+                bizConfig.id = Guid.NewGuid().ToString();
+                bizConfig.code = "BizConfig";
+                bizConfig.pk = "BizConfig";
+                bizConfig.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                var auth_token = JwtAuthExtension.CreateBusinessApiToken(_option.Location, bizConfig.id, _option.JwtSecretKey);
+                bizConfig.jti = auth_token.jti;
+                bizConfig.token = auth_token.jwt;
+
+                await cosmosClient.GetContainer("TEAMModelOS", "Normal").CreateItemAsync<BizConfig>(bizConfig, new PartitionKey("BizConfig"));
+
+                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryIterator<BizUsers>(queryText: $"select value(c) from c where c.mobile ={bizConfig.mobile}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("BizUsers") }))
+                {
+                    bizUsers.Add(item);
+                }
+
+                BizRel bizRel = new() { bizId = bizConfig.id, role = new List<string>() { "admin" } };
+                if (bizUsers.Count > 0)
+                {
+                    foreach (var item in bizUsers)
+                    {
+                        BizRel temp = item.relation.Find(f => f.bizId.Equals(bizConfig.id));
+                        if (temp == null)
+                        {
+                            item.relation.Add(bizRel);
+                            await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<BizUsers>(item, item.id, new PartitionKey("BizUsers"));
+                        }
+                    }
+                }
+                else
+                {
+                    BizUsers tBizUsers = new() { id = Guid.NewGuid().ToString(), code = "BizUsers", name = bizConfig.mobile.ToString(), mobile = bizConfig.mobile, salt = salt, pwd = Utils.HashedPassword($"{bizConfig.mobile}", salt), relation = new List<BizRel>() { { bizRel } } };
+
+                    await cosmosClient.GetContainer("TEAMModelOS", "Normal").CreateItemAsync<BizUsers>(tBizUsers, new PartitionKey("BizUsers"));
+                }
+
+                strMsg.Append($"{bizConfig.name}【{bizConfig.id}】新增企业基础信息。");
+                type = "bizconfig-add";
+            }
+            //修改企业信息
+            else
+            {
+                var response = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync(bizConfig.id, new PartitionKey("BizConfig"));
+                if (response.Status == 200)
+                {
+                    using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                    BizConfig tempBizConfig = json.ToObject<BizConfig>();
+
+                    bizConfig.pk = "BizConfig";
+                    bizConfig.code = "BizConfig";
+                    bizConfig.ttl = -1;
+
+                    bizConfig.createTime = tempBizConfig.createTime;
+                    bizConfig.jti = tempBizConfig.jti;
+                    bizConfig.token = tempBizConfig.token;
+
+                    bizConfig = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<BizConfig>(bizConfig, bizConfig.id, new PartitionKey("BizConfig"));
+                    strMsg.Append($"{bizConfig.name}【{bizConfig.id}】修改企业基础信息。");
+                    type = "bizconfig-update";
+                }
+            }
+
+            //保存操作记录
+            await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
+            return Ok(new { state = RespondCode.Ok, bizConfig });
+        }
+
     }
 }