浏览代码

处理创区创校的接口返回信息提示

Li 3 年之前
父节点
当前提交
081e81eade

+ 21 - 5
TEAMModelBI/Controllers/BISchool/BatchAreaController.cs

@@ -492,8 +492,16 @@ namespace TEAMModelBI.Controllers.BISchool
                 var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
                 messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
                 //var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
-                //await  _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile);
-                await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile);
+
+                try
+                {
+                    //await  _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile);
+                    await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile);
+                }
+                catch (Exception)
+                {
+                    return Ok(new { state = 201, msg = "能力点复制成功,复制能力点的文件失败," });
+                }
 
                 //发送消息实体
                 Notification notification = new Notification
@@ -557,12 +565,12 @@ namespace TEAMModelBI.Controllers.BISchool
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
                     tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
                     blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
-                    //serBusClient = _serviceBus.GetServiceBusClient(BIConst.GlobalSite);    //暂未确定使用默认 
+                    serBusClient = _serviceBus.GetServiceBusClient(BIConst.GlobalSite);    //暂未确定使用默认 
                     //activeTask = _configuration.GetValue<string>("GlobalAzure:ServiceBus:ActiveTask");  //暂未确定使用默认
                 }
                 var table = tableClient.GetTableReference("IESLogin");
                 //保存引用记录
-                await table.SaveOrUpdate<AreaQuoteRecord>(new AreaQuoteRecord() { PartitionKey = "QuoteRecord", RowKey = $"{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}", areaId = $"{_oldId}", quoteId = $"{_newId}", quoteName = $"{newName}", standard = $"{_newStandard}" });
+                //await table.SaveOrUpdate<AreaQuoteRecord>(new AreaQuoteRecord() { PartitionKey = "QuoteRecord", RowKey = $"{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}", areaId = $"{_oldId}", quoteId = $"{_newId}", quoteName = $"{newName}", standard = $"{_newStandard}" });
 
                 List<string> abilityIds = new List<string>();  //册别的ID集合
 
@@ -740,7 +748,15 @@ namespace TEAMModelBI.Controllers.BISchool
                 batchCopyFile.tmdName = $"{_tmdName}";
                 var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
                 messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");   //Function暂时还未写
-                await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile);  //先执行删除操作,在执行复制
+                try
+                {
+                    //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile);  //先执行删除操作,在执行复制  单一
+                    await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile);  //先执行删除操作,在执行复制
+                }
+                catch (Exception)
+                {
+                    return Ok(new { state = 201 ,msg = "能力点复制成功,复制能力点的文件失败," });
+                }
 
                 //发送消息实体
                 Notification notification = new Notification

+ 122 - 113
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -43,7 +43,6 @@ namespace TEAMModelBI.Controllers.BISchool
         private readonly IHttpClientFactory _http;
         //读取配置信息
         private readonly IConfiguration _configuration;
-        public readonly string mobel = "学校";
 
         public BatchSchoolController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, IHttpClientFactory http)
         {
@@ -141,12 +140,13 @@ namespace TEAMModelBI.Controllers.BISchool
             try
             {
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
-                List<BISchool> schools = new List<BISchool>();
+                List<BISchool> schools = new List<BISchool>(); 
+                List<BISchool> userScs = new List<BISchool>();
                 StringBuilder stringBuilder = new StringBuilder($"{_tmdName}【{_tmdId}】使用批量创校功能:");
                 var cosmosClient = _azureCosmos.GetCosmosClient();
                 var tableClient = _azureStorage.GetCloudTableClient();
                 var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
-                if (foundSchools.site.Equals(BIConst.GlobalSite))
+                if (BIConst.GlobalSite.Equals($"{foundSchools.site}"))
                 {
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
                     tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
@@ -180,131 +180,140 @@ namespace TEAMModelBI.Controllers.BISchool
                             }
 
                             string tmdId = !string.IsNullOrEmpty(tempTmdId) ? tempTmdId : bischool.admin;
-
-                            CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
-                            {
-                                province = bischool.province,
-                                id = "",
-                                name = bischool.name,
-                                city = bischool.city,
-                                aname = "",
-                                createCount = 0,
-                            };
-
-                            //生成学校ID
-                            bool tempStaus = true;
-                            do
-                            {
-                                createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
-                                var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
-                                if (schoolStatu.Status != 200) tempStaus = false;
-                                else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
-                            } while (tempStaus);
-
-                            if (createSchoolInfo.id != null)
+                            if (!string.IsNullOrEmpty(tmdId))
                             {
-                                string campusId = Guid.NewGuid().ToString();
-                                School upSchool = new School
+                                CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
                                 {
-                                    id = createSchoolInfo.id,
-                                    name = bischool.name,
-                                    size = bischool.size == 0 ? 100 : bischool.size,
-                                    code = "Base",
-                                    campuses = new List<Campus> { new Campus { name = bischool.name, id = campusId } },
-                                    region = bischool.region,
                                     province = bischool.province,
+                                    id = "",
+                                    name = bischool.name,
                                     city = bischool.city,
-                                    dist = bischool.dist,
-                                    address = bischool.address,
-                                    picture = "https://teammodelstorage.blob.core.chinacloudapi.cn/0-public/school/bbf54fb3-3fc8-43ae-a358-107281c174cc.png",
-                                    timeZone = new TEAMModelOS.SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
-                                    type = string.IsNullOrEmpty(bischool.type.ToString()) ? 1 : bischool.type,
-                                    pk = "School",
-                                    ttl = -1,
-                                    areaId = string.IsNullOrEmpty(bischool.areaId) ? "" : bischool.areaId,
-                                    standard = string.IsNullOrEmpty(bischool.standard) ? "" : bischool.standard,
-                                    schoolCode = createSchoolInfo.id,
-                                    period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
-                                    scale = bischool.size >= 300 ? 500 : 0,
-                                    createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
+                                    aname = "",
+                                    createCount = 0,
                                 };
 
-                                stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
-                                //创建学校
-                                await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
-                                Teacher teacher = null;
-                                try
+                                //生成学校ID
+                                bool tempStaus = true;
+                                do
                                 {
-                                    //查询该教师是否存在
-                                    teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{tmdId}", new PartitionKey("Base"));
-                                }
-                                catch
-                                {
-                                }
-                                if (teacher != null)
-                                {
-                                    //教师存在,在该教师信息中添加要管理的学校信息
-                                    teacher.schools.Add(new Teacher.TeacherSchool { areaId = string.IsNullOrEmpty(bischool.areaId) ? "" : bischool.areaId, schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
-                                    //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, tmdId, new PartitionKey("Base"));
-                                    SchoolTeacher schoolTeacher = new SchoolTeacher
-                                    {
-                                        id = tmdId,
-                                        code = $"Teacher-{createSchoolInfo.id}",
-                                        roles = new List<string> { "admin", "teacher" },
-                                        job = "管理员",
-                                        name = teacher.name,
-                                        picture = teacher.picture,
-                                        status = "join",
-                                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
-                                        pk = "Teacher",
-                                        ttl = -1
-                                    };
-                                    stringBuilder.Append($"教师信息:{schoolTeacher.name}【{schoolTeacher.id}】,教师权限:{string.Join(",", schoolTeacher.roles)}");
-                                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
-                                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
-                                }
-                                else
+                                    createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
+                                    var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
+                                    if (schoolStatu.Status != 200) tempStaus = false;
+                                    else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
+                                } while (tempStaus);
+
+                                if (createSchoolInfo.id != null)
                                 {
-                                    //不存在 新建教师和新建要管理的学校信息
-                                    Teacher addteacher = new Teacher
+                                    string campusId = Guid.NewGuid().ToString();
+                                    School upSchool = new School
                                     {
-                                        id = tmdId,
-                                        pk = "Base",
+                                        id = createSchoolInfo.id,
+                                        name = bischool.name,
+                                        size = bischool.size == 0 ? 100 : bischool.size,
                                         code = "Base",
-                                        name = $"{bischool.name}-管理员"?.ToString(),
-                                        picture = "",
-                                        //创建账号并第一次登录IES5则默认赠送1G
-                                        size = 1,
-                                        defaultSchool = createSchoolInfo.id,
-                                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
-                                        schools = new List<Teacher.TeacherSchool>() { new Teacher.TeacherSchool { schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() } }
+                                        campuses = new List<Campus> { new Campus { name = bischool.name, id = campusId } },
+                                        region = bischool.region,
+                                        province = bischool.province,
+                                        city = bischool.city,
+                                        dist = bischool.dist,
+                                        address = bischool.address,
+                                        picture = "https://teammodelstorage.blob.core.chinacloudapi.cn/0-public/school/bbf54fb3-3fc8-43ae-a358-107281c174cc.png",
+                                        timeZone = new TEAMModelOS.SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
+                                        type = string.IsNullOrEmpty(bischool.type.ToString()) ? 1 : bischool.type,
+                                        pk = "School",
+                                        ttl = -1,
+                                        areaId = string.IsNullOrEmpty(bischool.areaId) ? "" : bischool.areaId,
+                                        standard = string.IsNullOrEmpty(bischool.standard) ? "" : bischool.standard,
+                                        schoolCode = createSchoolInfo.id,
+                                        period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
+                                        scale = bischool.size >= 300 ? 500 : 0,
+                                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
                                     };
 
-                                    stringBuilder.Append($"没有该教师信息创建的教师信息:{addteacher.name}【{addteacher.id}】");
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
-                                    SchoolTeacher schoolTeacher = new SchoolTeacher
+                                    stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
+                                    //创建学校
+                                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
+                                    Teacher teacher = null;
+                                    try
                                     {
-                                        id = tmdId,
-                                        code = $"Teacher-{createSchoolInfo.id}",
-                                        roles = new List<string> { "admin", "teacher" },
-                                        job = "管理员",
-                                        name = $"{tmdId}-管理员",
-                                        picture = "",
-                                        status = "join",
-                                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
-                                        pk = "Teacher",
-                                        ttl = -1
-                                    };
+                                        //查询该教师是否存在
+                                        teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{tmdId}", new PartitionKey("Base"));
+                                    }
+                                    catch
+                                    {
+                                    }
+                                    if (teacher != null)
+                                    {
+                                        //教师存在,在该教师信息中添加要管理的学校信息
+                                        teacher.schools.Add(new Teacher.TeacherSchool { areaId = string.IsNullOrEmpty(bischool.areaId) ? "" : bischool.areaId, schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
+                                        //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, tmdId, new PartitionKey("Base"));
+                                        SchoolTeacher schoolTeacher = new SchoolTeacher
+                                        {
+                                            id = tmdId,
+                                            code = $"Teacher-{createSchoolInfo.id}",
+                                            roles = new List<string> { "admin", "teacher" },
+                                            job = "管理员",
+                                            name = teacher.name,
+                                            picture = teacher.picture,
+                                            status = "join",
+                                            createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                            pk = "Teacher",
+                                            ttl = -1
+                                        };
+                                        stringBuilder.Append($"教师信息:{schoolTeacher.name}【{schoolTeacher.id}】,教师权限:{string.Join(",", schoolTeacher.roles)}");
+                                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
+                                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
+                                    }
+                                    else
+                                    {
+                                        //不存在 新建教师和新建要管理的学校信息
+                                        Teacher addteacher = new Teacher
+                                        {
+                                            id = tmdId,
+                                            pk = "Base",
+                                            code = "Base",
+                                            name = $"{bischool.name}-管理员"?.ToString(),
+                                            picture = "",
+                                            //创建账号并第一次登录IES5则默认赠送1G
+                                            size = 1,
+                                            defaultSchool = createSchoolInfo.id,
+                                            createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                            schools = new List<Teacher.TeacherSchool>() { new Teacher.TeacherSchool { schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() } }
+                                        };
+
+                                        stringBuilder.Append($"没有该教师信息创建的教师信息:{addteacher.name}【{addteacher.id}】");
+                                        try
+                                        {
+                                            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
+                                        }
+                                        catch { }
+
+                                        SchoolTeacher schoolTeacher = new SchoolTeacher
+                                        {
+                                            id = tmdId,
+                                            code = $"Teacher-{createSchoolInfo.id}",
+                                            roles = new List<string> { "admin", "teacher" },
+                                            job = "管理员",
+                                            name = $"{tmdId}-管理员",
+                                            picture = "",
+                                            status = "join",
+                                            createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                            pk = "Teacher",
+                                            ttl = -1
+                                        };
 
-                                    stringBuilder.Append($"教师权限:{string.Join(",", schoolTeacher.roles)}");
-                                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
+                                        stringBuilder.Append($"教师权限:{string.Join(",", schoolTeacher.roles)}");
+                                        try
+                                        {
+                                            await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
+                                        }
+                                        catch { }
+                                    }
                                 }
                             }
+                            else userScs.Add(bischool);
                         }
-                        else 
-                        {
-                            schools.Add(bischool);
-                        }
+                        else schools.Add(bischool);
                     }
                 }
                 else return Ok(new { state = 1, message = "创校信息为空" });
@@ -312,8 +321,8 @@ namespace TEAMModelBI.Controllers.BISchool
                 //保存操作记录
                 //await _azureStorage.SaveBILog("school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
                 await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
-                if (schools.Count > 0)
-                    return Ok(new { state = 201, message = "已有部分学校批量创建成功;学校已经重复!请检查学校信息!", schools });
+                if (schools.Count > 0 || userScs.Count > 0)
+                    return Ok(new { state = 201, message = "已有部分学校批量创建成功;学校已经重复/或者学校信息有误!请检查学校信息!", schools, userScs });
                 else
                     return Ok(new { state = 200, message = "批量创校已全部完成" });
             }