瀏覽代碼

Merge branch 'PL/develop-BI' into develop

Li 2 年之前
父節點
當前提交
3035e38164

+ 205 - 200
TEAMModelBI/Controllers/BINormal/BatchAreaController.cs

@@ -1028,7 +1028,7 @@ namespace TEAMModelBI.Controllers.BINormal
             try
             {
                 string _oldId = "bde5c011-2ae4-461a-b46c-5483ba72ae45";
-                string _oldStandard = "standard27";
+                //string _oldStandard = "standard27";
                 string standardFileId = "02944f32-f534-3397-ea56-e6f1fc6c3714";
                 string standard = "standard2";
 
@@ -1047,252 +1047,257 @@ namespace TEAMModelBI.Controllers.BINormal
 
                 var table = tableClient.GetTableReference("IESLogin");
 
-                var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{_oldId}", new PartitionKey("AreaSetting"));
-                if (responseSet.Status == 200)
-                {
-                    using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
-                    AreaSetting delSet = fileJson.ToObject<AreaSetting>();
-                    if (!string.IsNullOrEmpty(delSet.accessConfig))
-                        return Ok(new { state = 401, msg = "区域已经规定了,不能切换能能力" });
-                }
-
-                List<string> abilityIds = new List<string>();  //册别的ID集合
-
-                //查询册别信息
-                await foreach (var tempAbility in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{_oldStandard}") }))
-                {
-                    abilityIds.Add(tempAbility.id);  //查询出来册别ID添加册别ID集合
-                }
-                //删除册别
-                if (abilityIds.IsNotEmpty())
-                {
-                    var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityIds, $"Ability-{_oldStandard}");
-                }
-
-                List<string> abilityTaskIds = new List<string>();  //章节ID集合
-                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{_oldStandard}") }))
-                {
-                    abilityTaskIds.Add(item.id);   //查询出来的章节信息ID添加到战绩集合
-                }
-                //删除章节
-                if (abilityTaskIds.IsNotEmpty())
+                Area area = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Area>($"{_oldId}", new PartitionKey("Base-Area"));
+                if (area != null)
                 {
-                    var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityTaskIds, $"AbilityTask-{_oldStandard}");
-                }
-                List<Task<ItemResponse<Ability>>> abilities = new();      //存储册别数据
-                List<Task<ItemResponse<AbilityTask>>> abilityTasks = new();  //存储章节
-
-                List<string> repeatAbilityId = new();
-                List<string> repeatAbilityTaskId = new();
-
-                foreach (var newstand in copyStand)
-                {
-                    try
+                    var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{_oldId}", new PartitionKey("AreaSetting"));
+                    if (responseSet.Status == 200)
                     {
-                        //查询要复制区域的能力标准点 
-                        await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{newstand.standard}") }))
-                        {
-                            if (!string.IsNullOrEmpty(item.blob))
-                                item.blob = item.blob.Replace($"/{newstand.standard}/", $"/{_oldStandard}/");
+                        using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
+                        AreaSetting delSet = fileJson.ToObject<AreaSetting>();
+                        if (!string.IsNullOrEmpty(delSet.accessConfig))
+                            return Ok(new { state = 401, msg = "区域已经规定了,不能切换能能力" });
+                    }
 
-                            item.standard = $"{_oldStandard}";
-                            item.code = $"Ability-{_oldStandard}";
-                            item.school = $"{_oldStandard}";
+                    List<string> abilityIds = new();  //册别的ID集合
 
-                            //添加区能力标准点
-                            //abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}")));
-                            //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}"));
+                    //查询册别信息
+                    await foreach (var tempAbility in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{area.standard}") }))
+                    {
+                        abilityIds.Add(tempAbility.id);  //查询出来册别ID添加册别ID集合
+                    }
+                    //删除册别
+                    if (abilityIds.IsNotEmpty())
+                    {
+                        var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityIds, $"Ability-{area.standard}");
+                    }
 
-                            var respond = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(item.id, new PartitionKey(item.code));
-                            if (respond.Status != 200)
-                                abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}")));
-                            else
-                                repeatAbilityId.Add(item.id);
-                        }
+                    List<string> abilityTaskIds = new List<string>();  //章节ID集合
+                    await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{area.standard}") }))
+                    {
+                        abilityTaskIds.Add(item.id);   //查询出来的章节信息ID添加到战绩集合
                     }
-                    catch
+                    //删除章节
+                    if (abilityTaskIds.IsNotEmpty())
                     {
-                        return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
+                        var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(abilityTaskIds, $"AbilityTask-{area.standard}");
                     }
+                    List<Task<ItemResponse<Ability>>> abilities = new();      //存储册别数据
+                    List<Task<ItemResponse<AbilityTask>>> abilityTasks = new();  //存储章节
 
-                    try
+                    List<string> repeatAbilityId = new();
+                    List<string> repeatAbilityTaskId = new();
+
+                    foreach (var newstand in copyStand)
                     {
-                        if (abilities.Count < 256)
+                        try
                         {
-                            await Task.WhenAll(abilities);
+                            //查询要复制区域的能力标准点 
+                            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{newstand.standard}") }))
+                            {
+                                if (!string.IsNullOrEmpty(item.blob))
+                                    item.blob = item.blob.Replace($"/{newstand.standard}/", $"/{area.standard}/");
+
+                                item.standard = $"{area.standard}";
+                                item.code = $"Ability-{area.standard}";
+                                item.school = $"{area.standard}";
+
+                                //添加区能力标准点
+                                //abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}")));
+                                //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{_oldStandard}"));
+
+                                var respond = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(item.id, new PartitionKey(item.code));
+                                if (respond.Status != 200)
+                                    abilities.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(item, new PartitionKey($"Ability-{area.standard}")));
+                                else
+                                    repeatAbilityId.Add(item.id);
+                            }
                         }
-                        else
+                        catch
                         {
-                            int pages = (abilities.Count + 255) / 256;
-                            for (int i = 0; i < pages; i++)
+                            return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
+                        }
+
+                        try
+                        {
+                            if (abilities.Count < 256)
                             {
-                                List<Task<ItemResponse<Ability>>> tempAbility = abilities.Skip((i) * 256).Take(256).ToList();
-                                await Task.WhenAll(tempAbility);
+                                await Task.WhenAll(abilities);
+                            }
+                            else
+                            {
+                                int pages = (abilities.Count + 255) / 256;
+                                for (int i = 0; i < pages; i++)
+                                {
+                                    List<Task<ItemResponse<Ability>>> tempAbility = abilities.Skip((i) * 256).Take(256).ToList();
+                                    await Task.WhenAll(tempAbility);
+                                }
                             }
                         }
-                    }
-                    catch
-                    {
-                        return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
-                    }
+                        catch
+                        {
+                            return Ok(new { state = 200, msg = "创区成功,能力标准点复制失败,遗留数据影响!" });
+                        }
 
-                    try
-                    {
-                        //微能力点
-                        await foreach (var atask in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{newstand.standard}") }))
+                        try
                         {
-                            List<Tnode> tnodes = new();
-                            foreach (Tnode tnode in atask.children)
+                            //微能力点
+                            await foreach (var atask in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{newstand.standard}") }))
                             {
-                                if (tnode.rnodes != null)
+                                List<Tnode> tnodes = new();
+                                foreach (Tnode tnode in atask.children)
                                 {
-                                    List<Rnode> rnodes = new();
-                                    foreach (Rnode rnode in tnode.rnodes)
+                                    if (tnode.rnodes != null)
                                     {
-                                        if (!string.IsNullOrEmpty($"{rnode.link}"))
+                                        List<Rnode> rnodes = new();
+                                        foreach (Rnode rnode in tnode.rnodes)
                                         {
-                                            rnode.link = rnode.link.Replace($"/{newstand.standard}/", $"/{_oldStandard}/");
+                                            if (!string.IsNullOrEmpty($"{rnode.link}"))
+                                            {
+                                                rnode.link = rnode.link.Replace($"/{newstand.standard}/", $"/{area.standard}/");
+                                            }
+                                            rnodes.Add(rnode);
                                         }
-                                        rnodes.Add(rnode);
+                                        tnode.rnodes = rnodes;
                                     }
-                                    tnode.rnodes = rnodes;
+                                    tnodes.Add(tnode);
                                 }
-                                tnodes.Add(tnode);
-                            }
 
-                            atask.children = tnodes;
-                            atask.code = $"AbilityTask-{_oldStandard}";
-                            atask.standard = $"{_oldStandard}";
-                            atask.codeval = $"{_oldStandard}";
-
-                            var respond = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(atask.id, new PartitionKey(atask.code));
-                            if (respond.Status != 200)
-                                ////添加区能力标准点中的节点 
-                                //abilityTasks.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}")));
-                                await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}"));
-                            else
-                                repeatAbilityTaskId.Add(atask.id);
+                                atask.children = tnodes;
+                                atask.code = $"AbilityTask-{area.standard}";
+                                atask.standard = $"{area.standard}";
+                                atask.codeval = $"{area.standard}";
+
+                                var respond = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(atask.id, new PartitionKey(atask.code));
+                                if (respond.Status != 200)
+                                    ////添加区能力标准点中的节点 
+                                    //abilityTasks.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{_oldStandard}")));
+                                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(atask, new PartitionKey($"AbilityTask-{area.standard}"));
+                                else
+                                    repeatAbilityTaskId.Add(atask.id);
+                            }
+                        }
+                        catch
+                        {
+                            return Ok(new { state = 200, msg = "创区成功,能力标准创建成功,微能力点复制失败,遗留数据影响!" });
                         }
-                    }
-                    catch
-                    {
-                        return Ok(new { state = 200, msg = "创区成功,能力标准创建成功,微能力点复制失败,遗留数据影响!" });
-                    }
 
-                    //发送消息分区键
-                    string partitionCode = "DelBeforeCopyAbility-mark";
-
-                    //执行复制操作
-                    BatchCopyFile batchCopyFile = new();
-                    batchCopyFile.blobCntr = "teammodelos";
-                    batchCopyFile.oldFileName = $"{newstand.standard}";
-                    batchCopyFile.newFileName = $"{_oldStandard}";
-                    batchCopyFile.tmdid = $"{_tmdId}";
-                    batchCopyFile.tmdIds = new List<string> { $"{_tmdId}" };
-                    batchCopyFile.codeKey = partitionCode;
-                    batchCopyFile.tmdName = $"{_tmdName}";
-                    var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
-                    messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
-                    try
-                    {
-                        //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile);  //先执行删除操作,在执行复制  单一
-                        await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile);  //先执行删除操作,在执行复制
-                    }
-                    catch (Exception)
-                    {
-                        return Ok(new { state = 201, msg = "能力点复制成功,复制能力点的文件失败," });
-                    }
+                        //发送消息分区键
+                        string partitionCode = "DelBeforeCopyAbility-mark";
+
+                        //执行复制操作
+                        BatchCopyFile batchCopyFile = new();
+                        batchCopyFile.blobCntr = "teammodelos";
+                        batchCopyFile.oldFileName = $"{newstand.standard}";
+                        batchCopyFile.newFileName = $"{area.standard}";
+                        batchCopyFile.tmdid = $"{_tmdId}";
+                        batchCopyFile.tmdIds = new List<string> { $"{_tmdId}" };
+                        batchCopyFile.codeKey = partitionCode;
+                        batchCopyFile.tmdName = $"{_tmdName}";
+                        var messageBatchCopyFile = new ServiceBusMessage(batchCopyFile.ToJsonString());
+                        messageBatchCopyFile.ApplicationProperties.Add("name", "CopyStandardFile");
+                        try
+                        {
+                            //await _serviceBus.GetServiceBusClient().SendMessageAsync(activeTask, messageBatchCopyFile);  //先执行删除操作,在执行复制  单一
+                            await serBusClient.SendMessageAsync(activeTask, messageBatchCopyFile);  //先执行删除操作,在执行复制
+                        }
+                        catch (Exception)
+                        {
+                            return Ok(new { state = 201, msg = "能力点复制成功,复制能力点的文件失败," });
+                        }
 
-                    //发送消息实体
-                    Notification notification = new()
-                    {
-                        hubName = "hita",
-                        type = "msg",
-                        from = $"BI:{_option.Location}:private",
-                        to = new List<string> { $"{_tmdId}" },
-                        label = $"{partitionCode}_start",
-                        body = new { location = _option.Location, biz = partitionCode, tmdid = $"{_tmdId}", tmdname = $"{_tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
-                        expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
-                    };
+                        //发送消息实体
+                        Notification notification = new()
+                        {
+                            hubName = "hita",
+                            type = "msg",
+                            from = $"BI:{_option.Location}:private",
+                            to = new List<string> { $"{_tmdId}" },
+                            label = $"{partitionCode}_start",
+                            body = new { location = _option.Location, biz = partitionCode, tmdid = $"{_tmdId}", tmdname = $"{_tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
+                            expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
+                        };
 
-                    var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
-                    var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
-                    var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
-                    var location = _option.Location;
-                    await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //发送站内发送消息
-                }
+                        var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
+                        var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
+                        var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
+                        var location = _option.Location;
+                        await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //发送站内发送消息
+                    }
 
-                StandardFile saveFile = new();
-                //新政策文件
-                await foreach (StandardFile standardFile in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<StandardFile>(queryText: $"select value(c) from c where  c.id='{standardFileId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StandardFile") }))
-                {
-                    if (standardFile != null)
+                    StandardFile saveFile = new();
+                    //新政策文件
+                    await foreach (StandardFile standardFile in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<StandardFile>(queryText: $"select value(c) from c where  c.id='{standardFileId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StandardFile") }))
                     {
-                        standardFile.standard = $"{_oldStandard}";
-                        standardFile.id = $"{_oldId}";
+                        if (standardFile != null)
+                        {
+                            standardFile.standard = $"{area.standard}";
+                            standardFile.id = $"{_oldId}";
 
-                        saveFile = standardFile;
+                            saveFile = standardFile;
+                        }
                     }
-                }
 
-                StandardFile tempFile = new();
-                if (saveFile.id != null)
-                {
-                    var respFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveFile.id, new PartitionKey("StandardFile"));
-                    if (respFile.Status == 200)
+                    StandardFile tempFile = new();
+                    if (saveFile.id != null)
                     {
-                        using var json = await JsonDocument.ParseAsync(respFile.ContentStream);
-                        tempFile = json.ToObject<StandardFile>();
-                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<StandardFile>(tempFile.id, new PartitionKey("StandardFile"));
-                    }
+                        var respFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveFile.id, new PartitionKey("StandardFile"));
+                        if (respFile.Status == 200)
+                        {
+                            using var json = await JsonDocument.ParseAsync(respFile.ContentStream);
+                            tempFile = json.ToObject<StandardFile>();
+                            await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<StandardFile>(tempFile.id, new PartitionKey("StandardFile"));
+                        }
 
-                    tempFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
-                }
+                        tempFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
+                    }
 
-                //if (tempFile.id != null)
-                //{
-                //    if (tempFile.id.Equals(saveFile.id))
-                //        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<StandardFile>(saveFile, saveFile.id, new PartitionKey("StandardFile")); //直接替换以前的数据
-                //    else
-                //        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
-                //}
+                    //if (tempFile.id != null)
+                    //{
+                    //    if (tempFile.id.Equals(saveFile.id))
+                    //        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<StandardFile>(saveFile, saveFile.id, new PartitionKey("StandardFile")); //直接替换以前的数据
+                    //    else
+                    //        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveFile, new PartitionKey($"StandardFile")); // 需要删除原来的政策文件数据在进行添加
+                    //}
 
-                //新的区域设置
-                AreaSetting saveSetting = new();
-                await foreach (AreaSetting areaSetting in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AreaSetting>(queryText: $"select value(c) from c where c.id='{standardFileId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("AreaSetting") }))
-                {
-                    if (areaSetting != null)
+                    //新的区域设置
+                    AreaSetting saveSetting = new();
+                    await foreach (AreaSetting areaSetting in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AreaSetting>(queryText: $"select value(c) from c where c.id='{standardFileId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("AreaSetting") }))
                     {
-                        areaSetting.accessConfig = null;
-                        areaSetting.id = $"{_oldId}";
+                        if (areaSetting != null)
+                        {
+                            areaSetting.accessConfig = null;
+                            areaSetting.id = $"{_oldId}";
 
-                        saveSetting = areaSetting;
+                            saveSetting = areaSetting;
+                        }
                     }
-                }
 
-                AreaSetting tempSetting = new();
-                if (saveSetting.id != null)
-                {
-                    var respSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveSetting.id, new PartitionKey("AreaSetting"));
-                    if (respSetting.Status == 200)
+                    AreaSetting tempSetting = new();
+                    if (saveSetting.id != null)
                     {
-                        using var json = await JsonDocument.ParseAsync(respSetting.ContentStream);
-                        tempSetting = json.ToObject<AreaSetting>();
-                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<AreaSetting>(saveSetting.id, new PartitionKey("AreaSetting"));
+                        var respSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(saveSetting.id, new PartitionKey("AreaSetting"));
+                        if (respSetting.Status == 200)
+                        {
+                            using var json = await JsonDocument.ParseAsync(respSetting.ContentStream);
+                            tempSetting = json.ToObject<AreaSetting>();
+                            await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemAsync<AreaSetting>(saveSetting.id, new PartitionKey("AreaSetting"));
+                        }
+
+                        tempSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting"));  //需要删除原来的区域设置数据在进行添加
                     }
+                    //if (tempSetting.id != null)
+                    //{
+                    //    if (tempSetting.id.Equals(saveSetting.id))
+                    //        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<AreaSetting>(saveSetting, saveSetting.id, new PartitionKey($"AreaSetting"));   //直接替换以前的数据
+                    //    else
+                    //        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting"));  //需要删除原来的区域设置数据在进行添加
+                    //}
 
-                    tempSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting"));  //需要删除原来的区域设置数据在进行添加
+                    return Ok(new { state = RespondCode.Ok, repeatAbilityId, repeatAbilityTaskId });
                 }
-
-                //if (tempSetting.id != null)
-                //{
-                //    if (tempSetting.id.Equals(saveSetting.id))
-                //        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<AreaSetting>(saveSetting, saveSetting.id, new PartitionKey($"AreaSetting"));   //直接替换以前的数据
-                //    else
-                //        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync(saveSetting, new PartitionKey($"AreaSetting"));  //需要删除原来的区域设置数据在进行添加
-                //}
-
-                return Ok(new { state = RespondCode.Ok, repeatAbilityId, repeatAbilityTaskId });
+                else
+                    return Ok(new { state = RespondCode.NotFound, msg = "标准为空"}) ;
 
             }
             catch (Exception ex)

+ 115 - 0
TEAMModelBI/Controllers/Census/ItemSticsController.cs

@@ -13,6 +13,10 @@ using System.Text;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Context.BI;
+using Azure.Core;
+using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
+using TEAMModelOS.SDK.Context.Constant;
+using DocumentFormat.OpenXml.Wordprocessing;
 
 namespace TEAMModelBI.Controllers.Census
 {
@@ -33,6 +37,117 @@ namespace TEAMModelBI.Controllers.Census
             _option = option?.Value;
         }
 
+        /// <summary>
+        /// 查询学校试题
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-list")]
+        public async Task<IActionResult> GetList(JsonElement jsonElement) 
+        {
+            if (!jsonElement.TryGetProperty("code", out JsonElement code)) return BadRequest();
+            jsonElement.TryGetProperty("scope", out JsonElement scope);
+            Dictionary<string, object> dic = new();
+            if (jsonElement.TryGetProperty("periodId", out JsonElement periodId))
+                dic.Add("periodId", periodId);
+            if (jsonElement.TryGetProperty("subjectId", out JsonElement subjectId))
+                dic.Add("subjectId", subjectId);
+            if (jsonElement.TryGetProperty("gradeIds", out JsonElement gradeIds))
+                dic.Add("gradeIds", gradeIds);
+            if (jsonElement.TryGetProperty("type", out JsonElement type))
+                dic.Add("type", type);
+            if (jsonElement.TryGetProperty("level", out JsonElement level))
+                dic.Add("level", level);
+            if (jsonElement.TryGetProperty("field", out JsonElement field))
+                dic.Add("field", field);
+            if (jsonElement.TryGetProperty("isSort", out JsonElement isSort))
+            {
+                if (!string.IsNullOrEmpty($"{isSort}"))
+                {
+                    if (bool.Parse($"{isSort}") == true)
+                        dic.Add("@DESC", "createTime");
+                    else
+                        dic.Add("@ASC", "createTime");
+                }
+                else
+                    dic.Add("@ASC", "createTime");
+            }
+            if (jsonElement.TryGetProperty("pid", out JsonElement pd))
+            {
+                if (pd.ValueKind != JsonValueKind.Null)
+                    dic.Add("pid", pd.ToString());
+                else
+                    dic.Add("pid", null);
+            }
+
+            var cosmosClinet = _azureCosmos.GetCosmosClient();
+            StringBuilder sql = new("select c.id,c.code,c.repairResource, c.periodId,c.question,c.useCount,c.level,c.field,c.knowledge,c.type,c.option,c.createTime,c.answer,c.explain,c.children,c.score,c.gradeIds,c.subjectId,c.blob,c.scope from c ");
+            AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dic, sql);
+            List<object> items = new();
+            if (scope.ToString().Equals("private"))
+            {
+                await foreach (var item in cosmosClinet.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
+                {
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            items.Add(obj.ToObject<object>());
+                        }
+                    }
+                }
+            }
+            else if (scope.ToString().Equals("school"))
+            {
+                await foreach (var item in cosmosClinet.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
+                {
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            items.Add(obj.ToObject<object>());
+                        }
+                    }
+                }
+            }
+            else
+            {
+                await foreach (var item in cosmosClinet.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
+                {
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            items.Add(obj.ToObject<object>());
+                        }
+                    }
+                }
+
+                await foreach (var item in cosmosClinet.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
+                {
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            items.Add(obj.ToObject<object>());
+                        }
+                    }
+                }
+            }
+
+            return Ok(new { state = RespondCode.Ok ,cnt = items.Count, items });
+        }
+
+
         /// <summary>
         /// 查询所有试题数量
         /// </summary>

+ 85 - 1
TEAMModelBI/Controllers/Census/PaperController.cs

@@ -11,7 +11,9 @@ using TEAMModelBI.Models;
 using TEAMModelBI.Tool;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.Context.BI;
+using TEAMModelOS.SDK.Context.Constant;
 using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 
@@ -37,6 +39,88 @@ namespace TEAMModelBI.Controllers.Census
             _option = option?.Value;
         }
 
+        /// <summary>
+        /// 查询学校试卷列表
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-list")]
+        public async Task<IActionResult> GetList(JsonElement jsonElement) 
+        {
+            if (!jsonElement.TryGetProperty("code", out JsonElement code)) return BadRequest();
+            jsonElement.TryGetProperty("scope", out JsonElement scope);
+            Dictionary<string, object> dic = new();
+            if (jsonElement.TryGetProperty("periodId", out JsonElement periodId))
+                dic.Add("periodId", periodId);
+            if (jsonElement.TryGetProperty("subjectId", out JsonElement subjectId))
+                dic.Add("subjectId", subjectId);
+            if (jsonElement.TryGetProperty("gradeIds", out JsonElement gradeIds))
+                dic.Add("gradeIds", gradeIds);
+            if (jsonElement.TryGetProperty("isSort", out JsonElement isSort))
+            {
+                if (!string.IsNullOrEmpty($"{isSort}"))
+                {
+                    if (bool.Parse($"{isSort}") == true)
+                        dic.Add("@DESC", "createTime");
+                    else
+                        dic.Add("@ASC", "createTime");
+                }
+                else
+                    dic.Add("@ASC", "createTime");
+            }
+
+            var cosmosClinet = _azureCosmos.GetCosmosClient();
+            StringBuilder sql = new("select value(c) from c ");
+            AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dic, sql);
+
+            List<Paper> papers = new();
+            if (scope.ToString().Equals("school"))
+            {
+                await foreach (var item in cosmosClinet.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Paper>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{code}") }))
+                {
+                    papers.Add(item);
+                }
+            }
+            else if (scope.ToString().Equals("private"))
+            {
+                await foreach (var item in cosmosClinet.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Paper>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{code}") }))
+                {
+                    papers.Add(item);
+                }
+            }
+            else
+            {
+                await foreach (var item in cosmosClinet.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Paper>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{code}") }))
+                {
+                    papers.Add(item);
+                }
+                await foreach (var item in cosmosClinet.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Paper>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{code}") }))
+                {
+                    papers.Add(item);
+                }
+            }
+
+            return Ok(new { state = RespondCode.Ok,cnt = papers.Count, papers });
+        }
+
+        /// <summary>
+        /// 复制试卷信息到另外一个学校
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("copy-infos")]
+        public async Task<IActionResult> CopyInfos(JsonElement jsonElement) 
+        {
+
+
+
+
+            return Ok(new { state = RespondCode.Ok});
+        }
+
+
         /// <summary>
         /// 查询试卷的数量统计集合
         /// </summary>
@@ -315,7 +399,7 @@ namespace TEAMModelBI.Controllers.Census
             //if ($"{site}".Equals(BIConst.Global))
             //    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
 
-            List<object> paperInfos = new List<object>();
+            List<object> paperInfos = new();
             string sqlTxt = $"select * from c where c.id='{paperId}' and c.pk='Paper'";
 
             if (!string.IsNullOrEmpty($"{isPersonal}"))

+ 3 - 3
TEAMModelBI/TEAMModelBI.csproj

@@ -59,9 +59,9 @@
 		<SpaRoot>ClientApp\</SpaRoot>
 		<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
 		<UserSecretsId>078b5d89-7d90-4f6a-88fc-7d96025990a8</UserSecretsId>
-		<Version>1.2210.14</Version>
-		<AssemblyVersion>1.2210.14.1</AssemblyVersion>
-		<FileVersion>1.2210.14.1</FileVersion>
+		<Version>1.2210.19</Version>
+		<AssemblyVersion>1.2210.19.1</AssemblyVersion>
+		<FileVersion>1.2210.19.1</FileVersion>
 		<Description>TEAMModelBI(BI)</Description>
 		<PackageReleaseNotes>BI版本说明版本切换标记2022000908</PackageReleaseNotes>
 		<PackageId>TEAMModelBI</PackageId>