1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020 |
- using Azure.Cosmos;
- using HTEXLib.COMM.Helpers;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Options;
- using System;
- using System.Collections.Generic;
- using System.Dynamic;
- using System.Linq;
- using System.Text;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Models.Cosmos.BI;
- using Microsoft.AspNetCore.Hosting; //引用读取文件
- using TEAMModelOS.SDK.Models.Service;
- using System.IO;
- using System.Net.Http;
- using Microsoft.Extensions.Configuration;
- using System.Net.Http.Json;
- using System.Net;
- using TEAMModelBI.Filter;
- using TEAMModelBI.Tool.Extension;
- using TEAMModelBI.Tool;
- using TEAMModelBI.Models;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.Context.BI;
- using TEAMModelOS.SDK.Context.Constant;
- using Pipelines.Sockets.Unofficial.Arenas;
- using Microsoft.Identity.Client;
- using TEAMModelOS.SDK.Models.Dtos;
- using DocumentFormat.OpenXml.Spreadsheet;
- using DocumentFormat.OpenXml.Wordprocessing;
- using DocumentFormat.OpenXml.Bibliography;
- using HTEXLib;
- using TEAMModelOS.SDK.Models.Service.BI;
- using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
- using DocumentFormat.OpenXml.Vml.Office;
- namespace TEAMModelBI.Controllers.BISchool
- {
- [Route("batchschool")]
- [ApiController]
- public class BatchSchoolController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly AzureStorageFactory _azureStorage;
- private readonly IWebHostEnvironment _environment; //读取文件
- private readonly IHttpClientFactory _http;
- //读取配置信息
- private readonly IConfiguration _configuration;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly HttpTrigger _httpTrigger;
- public BatchSchoolController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService, HttpTrigger httpTrigger)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _azureStorage = azureStorage;
- _option = option?.Value;
- _environment = hostingEnvironment;
- _configuration = configuration;
- _http = http;
- _coreAPIHttpService = coreAPIHttpService;
- _httpTrigger = httpTrigger;
- }
- /// <summary>
- /// 获取BI权限列表 //已对接
- /// </summary>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-teacher-authoritybilist")]
- public async Task<IActionResult> GetAuthorityBIList(JsonElement jsonElement)
- {
- //jsonElement.TryGetProperty("site", out JsonElement site);
- Dictionary<string, object> dic = new() { { "PartitionKey", "authority-bi" } };
- var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
- ////分开部署,就不需要,一站多用时,取消注释
- //if ($"{site}".Equals(BIConst.Global))
- // table = _azureStorage.GetCloudTableClient(BIConst.Global).GetTableReference("SchoolSetting");
- List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);
- return Ok(new { authorityBIList });
- }
- /// <summary>
- /// 生成学校Code信息
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "admin,rdc")]
- [HttpPost("get-schoolcode")]
- public async Task<IActionResult> GetSchoolCode(JsonElement jsonElement)
- {
- if (!jsonElement.TryGetProperty("schools", out JsonElement schools)) return BadRequest();
- var cosmosClient = _azureCosmos.GetCosmosClient();
- List<CreateSchoolInfo> cSchools = schools.ToObject<List<CreateSchoolInfo>>();
- List<CreateSchoolInfo> createScInfo = new(); //生成好的学校Codd信息
- foreach (var item in cSchools)
- {
- CreateSchoolInfo createSchoolInfo = item;
- //生成学校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);
- createScInfo.Add(createSchoolInfo);
- }
- return Ok(new { state = RespondCode.Ok, createScInfo });
- }
- /// <summary>
- /// 批量创校 //已对接
- /// </summary>
- /// <param name="school"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "admin,rdc")]
- [HttpPost("batch-school")]
- public async Task<IActionResult> BatchCreateSchool(FoundSchools foundSchools)
- {
- try
- {
- var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
- List<BISchool> schools = new();
- List<BISchool> userScs = new();
- List<BISchool> cutArea = new();
- List<CreateSchoolInfo> scInfos = new();
- List<string> upSc = new();
- StringBuilder stringBuilder = new($"{_tmdName}【{_tmdId}】使用批量创校功能:");
- StringBuilder vsSql = new();
- StringBuilder noticeDD = new(); //创校信息通知
- var cosmosClient = _azureCosmos.GetCosmosClient();
- var tableClient = _azureStorage.GetCloudTableClient();
- var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
- //if (BIConst.Global.Equals($"{foundSchools.site}"))
- //{
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
- // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
- //}
- if (foundSchools.biSchools.Count > 0)
- {
- #region 新版直接创建
- foreach (BISchool bischool in foundSchools.biSchools)
- {
- Area area = null;
- //查询区是否存在
- var respAreaId = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{bischool.areaId}", new PartitionKey("Base-Area"));
- if (respAreaId.Status == 200)
- {
- using var areaBase = await JsonDocument.ParseAsync(respAreaId.ContentStream);
- area = areaBase.ToObject<Area>();
- }
- CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
- {
- province = bischool.province,
- id = bischool.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)
- {
- string campusId = Guid.NewGuid().ToString();
- TEAMModelOS.SDK.Models.Edition edition = new();
- edition.scaleVersion = bischool.scaleVersion;
- School upSchool = new()
- {
- 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,
- 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 = area == null ? "" : area.id,
- standard = area == null ? "" : area.standard,
- schoolCode = createSchoolInfo.id,
- period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
- scale = bischool.size >= 300 ? 500 : 0,
- isinit = true,
- //modules=bischool.modules,
- openLessonRecord = (_option.Location.Contains("Global")) ? false : true,
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
- edition = edition
- };
- scInfos.Add(createSchoolInfo);
- vsSql.Append($"{upSchool.name}【{upSchool.id}】,");
- stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
- noticeDD.Append($"{upSchool.name}【{upSchool.id}】 \r 学校管理员信息:");
- upSc.Add(upSchool.id);
- //创建学校
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
- //创建学校信息中间件
- //_ = _httpTrigger.RequestHttpTrigger(new { school = $"{upSchool}" }, _option.Location, "set-sc-birelation");
- await BIStats.SetSchoolBIRelation(cosmosClient, blobClient, tableClient, _dingDing, upSchool);
- //创建BI和统计信息
- await BIStats.SetScStatsInfo(cosmosClient, _dingDing,upSchool);
- var content = new StringContent(bischool.admin.ToArray().ToJsonString(), Encoding.UTF8, "application/json");
- string json = await _coreAPIHttpService.GetUserInfos(content);
- List<TmdUserinfo> tmdInfos = json.ToObject<List<TmdUserinfo>>();
- foreach (var tmdIndo in tmdInfos)
- {
- Teacher teacher = new();
- var resTeache = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{tmdIndo.id}", new PartitionKey("Base"));
- if (resTeache.Status == 200)
- {
- using var tchJson = await JsonDocument.ParseAsync(resTeache.ContentStream);
- teacher = tchJson.ToObject<Teacher>();
- Teacher.TeacherSchool tchSc = null;
- //var tempTch = teacher.schools.Select(x => x.schoolId.Equals(upSchool.id)).ToString();
- tchSc = teacher.schools.Find(x => x.schoolId.Equals(upSchool.id));
- if (tchSc == 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, coreUser.id, new PartitionKey("Base"));
- SchoolTeacher schoolTeacher = new()
- {
- id = tmdIndo.id,
- 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)}】");
- noticeDD.Append($"{schoolTeacher.name}【{schoolTeacher.id}】");
- 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()
- {
- id = tmdIndo.id,
- pk = "Base",
- code = "Base",
- name = $"{tmdIndo.name}",
- picture = $"{tmdIndo.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}】");
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
- SchoolTeacher schoolTeacher = new()
- {
- id = tmdIndo.id,
- code = $"Teacher-{createSchoolInfo.id}",
- roles = new List<string> { "admin", "teacher" },
- job = "管理员",
- name = $"{tmdIndo.name}",
- picture = "",
- status = "join",
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
- pk = "Teacher",
- ttl = -1
- };
- stringBuilder.Append($"权限:{string.Join(",", schoolTeacher.roles)}】");
- noticeDD.Append($"{schoolTeacher.name}【{schoolTeacher.id}】");
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
- }
- }
- }
- }
- #endregion
- #region 旧版先检测 在创建
- //foreach (BISchool bischool in foundSchools.biSchools)
- //{
- // List<string> scName = new();
- // //查询学校名称是否全字段匹配
- // await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: $"select value(c.name) from c where c.name='{bischool.name}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- // {
- // scName.Add(item);
- // }
- // Area area = null;
- // //查询区是否存在
- // var respAreaId = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{bischool.areaId}", new PartitionKey("Base-Area"));
- // if (respAreaId.Status == 200)
- // {
- // using var areaBase = await JsonDocument.ParseAsync(respAreaId.ContentStream);
- // area = areaBase.ToObject<Area>();
- // }
- // bool isSYNCArea = false;
- // //查询去是否同步省平台
- // var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{bischool.areaId}", 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))
- // isSYNCArea = true;
- // }
- // if (scName.Count <= 0)
- // {
- // if (isSYNCArea == false)
- // {
- // var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{bischool.admin}" } }, _option.Location, _configuration);
- // if (coreUser != null && coreUser.id != null)
- // {
- // 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)
- // {
- // string campusId = Guid.NewGuid().ToString();
- // School upSchool = new()
- // {
- // 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,
- // 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 = area == null ? "" : area.id,
- // standard = area == null ? "" : area.standard,
- // schoolCode = createSchoolInfo.id,
- // period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
- // scale = bischool.size >= 300 ? 500 : 0,
- // createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
- // };
- // stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
- // noticeDD.Append($"【ID:{upSchool.id}|名称:{upSchool.name}】 ");
- // upSc.Add(upSchool.id);
- // //创建学校
- // await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
- // //创建学校管理员
- // Teacher teacher = null;
- // var resTeache = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{coreUser.id}", new PartitionKey("Base"));
- // if (resTeache.Status == 200)
- // {
- // using var tchJson = await JsonDocument.ParseAsync(resTeache.ContentStream);
- // teacher = tchJson.ToObject<Teacher>();
- // //教师存在,在该教师信息中添加要管理的学校信息
- // 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, coreUser.id, new PartitionKey("Base"));
- // SchoolTeacher schoolTeacher = new()
- // {
- // id = coreUser.id,
- // 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()
- // {
- // id = coreUser.id,
- // pk = "Base",
- // code = "Base",
- // name = $"{coreUser.name}",
- // picture = $"{coreUser.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}】");
- // await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
- // SchoolTeacher schoolTeacher = new()
- // {
- // id = coreUser.id,
- // code = $"Teacher-{createSchoolInfo.id}",
- // roles = new List<string> { "admin", "teacher" },
- // job = "管理员",
- // name = $"{coreUser.name}",
- // 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));
- // }
- // }
- // }
- // else userScs.Add(bischool);
- // }
- // else cutArea.Add(bischool);
- // }
- // else schools.Add(bischool);
- //}
- #endregion
- }
- else return Ok(new { state = 1, message = "创校信息为空" });
- if (upSc.Count > 1)
- await _dingDing.SendBotMsg($"BI,{_option.Location} \n 批量建校信息:{noticeDD}", GroupNames.成都开发測試群組);
- else if (upSc.Count == 1)
- await _dingDing.SendBotMsg($"BI,{_option.Location} \n 单个建校信息:{noticeDD}", GroupNames.成都开发測試群組);
- ////v2通知
- //Teacher targetTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>($"{_tmdId}", new PartitionKey($"Base"));
- //_coreAPIHttpService.PushNotify(new List<IdNameCode> { new IdNameCode { id = targetTeacher.id, name = targetTeacher.name, code = targetTeacher.lang } }, "create-school", Constant.NotifyType_IES5_Management, new Dictionary<string, object> { { "tmdname", $"{_tmdName}" }, { "schooName", $"{vsSql}" } }, _option.Location, _configuration, _dingDing, _environment.ContentRootPath);
- //保存操作记录
- await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
- if (schools.Count == foundSchools.biSchools.Count || userScs.Count == foundSchools.biSchools.Count)
- return Ok(new { state = RespondCode.CreateFailed, message = "已有部分学校批量创建成功;学校已经重复/学校信息有误!请检查学校信息!", schools, userScs });
- else
- {
- if (schools.Count > 0 || userScs.Count > 0 || cutArea.Count > 0)
- return Ok(new { state = RespondCode.Created, message = "已有部分学校批量创建成功;学校已经重复/学校信息有误/区域已在研修不能加区!请检查学校信息!", schools, userScs, cutArea });
- else
- return Ok(new { state = RespondCode.Ok, message = "批量创校已全部完成", scInfos });
- }
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/batch-school \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 依据学校编号查询学校信息;若是没有传学校编号,则查询所有学校信息 //已对接
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-schoolsinfo")]
- public async Task<IActionResult> GetSchoolsInfo(JsonElement jsonElement)
- {
- try
- {
- jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
- jsonElement.TryGetProperty("role", out JsonElement role);
- jsonElement.TryGetProperty("scId", out JsonElement scId);
- jsonElement.TryGetProperty("name", out JsonElement name);
- jsonElement.TryGetProperty("order", out JsonElement order);
- jsonElement.TryGetProperty("province", out JsonElement province);
- jsonElement.TryGetProperty("city", out JsonElement city);
- jsonElement.TryGetProperty("dist", out JsonElement dist);
- //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
- var cosmosClient = _azureCosmos.GetCosmosClient();
- ////分开部署,就不需要,一站多用时,取消注释
- //if ($"{site}".Equals(BIConst.Global))
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- int scCnt = 0;
- int? pageSize = 100; //默认不指定返回大小
- string continuationToken = string.Empty; //返给前端分页token
- string pageToken = default;//接受前端的分页Tolen
- bool iscontinuation = false;//是否需要进行分页查询,默认不分页
- List<AssistSchool> schoolAssists = new(); //返回学校列表集合
- List<string> schoolIds = new();
- StringBuilder stringBuilder = new("select c.id,c.code,c.schoolCode,c.name,c.region,c.province,c.city,c.dist,c.size,c.address,c.picture,c.type,c.scale,c.areaId,c.standard from c ");
- StringBuilder scCntSql = new($"select value(count(c.id)) from c");
- if (jsonElement.TryGetProperty("pageSize", out JsonElement jsonPageSize))
- {
- if (!jsonPageSize.ValueKind.Equals(JsonValueKind.Undefined) && !jsonPageSize.ValueKind.Equals(JsonValueKind.Null) && jsonPageSize.TryGetInt32(out int tempPageSize))
- pageSize = tempPageSize;
- }
- if (pageSize != null && pageSize.Value > 0)
- iscontinuation = true;
- if (jsonElement.TryGetProperty("contToken", out JsonElement ContToken))
- pageToken = ContToken.GetString();
- if (!string.IsNullOrEmpty($"{scId}") && string.IsNullOrEmpty($"{name}"))
- {
- stringBuilder.Append($" where c.id='{scId}'");
- scCntSql.Append($" where c.id='{scId}'");
- }
- if (string.IsNullOrEmpty($"{scId}") && !string.IsNullOrEmpty($"{name}"))
- {
- stringBuilder.Append($" where Contains(c.name,'{name}')");
- scCntSql.Append($" where Contains(c.name,'{name}')");
- }
- if (!string.IsNullOrEmpty($"{province}") && string.IsNullOrEmpty($"{city}") && string.IsNullOrEmpty($"{dist}"))
- {
- stringBuilder.Append($" where Contains(c.province,'{province}')");
- scCntSql.Append($" where Contains(c.province,'{province}')");
- }
- if (!string.IsNullOrEmpty($"{city}") && !string.IsNullOrEmpty($"{city}") && string.IsNullOrEmpty($"{dist}"))
- {
- stringBuilder.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}')");
- scCntSql.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}')");
- }
- if (!string.IsNullOrEmpty($"{dist}") && !string.IsNullOrEmpty($"{city}") && !string.IsNullOrEmpty($"{dist}"))
- {
- stringBuilder.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}') and Contains(c.dist,'{dist}')");
- scCntSql.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}') and Contains(c.dist,'{dist}')");
- }
- if ($"{order}".Equals("desc"))
- stringBuilder.Append(" order by c.createTime desc");
- if (!string.IsNullOrEmpty($"{tmdId}"))
- {
- schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}", roles: !string.IsNullOrEmpty($"{role}") ? $"{role}" : "assist", isMany: true);
- string scsSql = BICommonWay.ManyScSql("c.id", schoolIds);
- scCntSql.Append($" where {scsSql}");
- scCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", scCntSql.ToString(), "Base");
- foreach (var id in schoolIds)
- {
- StringBuilder sqlTxt = new($"select c.id,c.code,c.schoolCode,c.name,c.region,c.province,c.city,c.dist,c.size,c.address,c.picture,c.type,c.scale,c.areaId,c.standard from c where c.id='{id}'");
- if ($"{order}".Equals("desc"))
- sqlTxt.Append(" order by c.createTime desc");
- else
- sqlTxt.Append(" order by c.createTime asc");
- await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AssistSchool>(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- schoolAssists.Add(itemSchool);
- }
- }
- }
- else
- {
- scCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", scCntSql.ToString(), "Base");
- await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: stringBuilder.ToString(), continuationToken: pageToken, requestOptions: new QueryRequestOptions() { MaxItemCount = pageSize, PartitionKey = new PartitionKey("Base") }))
- {
- using var json = await JsonDocument.ParseAsync(itemSchool.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- schoolAssists.Add(obj.ToObject<AssistSchool>());
- }
- if (iscontinuation)
- {
- continuationToken = itemSchool.GetContinuationToken();
- break;
- }
- }
- }
- }
- //if (schoolIds.Count > 0)
- //{
- // scCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", scCntSql.ToString(), "Base");
- // foreach (var id in schoolIds)
- // {
- // StringBuilder sqlTxt = new($"select c.id,c.code,c.schoolCode,c.name,c.region,c.province,c.city,c.dist,c.size,c.address,c.picture,c.type,c.scale,c.areaId,c.standard from c where c.id='{id}'");
- // if ($"{order}".Equals("desc"))
- // sqlTxt.Append(" order by c.createTime desc");
- // await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AssistSchool>(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- // {
- // schoolAssists.Add(itemSchool);
- // }
- // }
- //}
- //else
- //{
- // if (!string.IsNullOrEmpty($"{scId}") && string.IsNullOrEmpty($"{name}"))
- // {
- // stringBuilder.Append($" where c.id='{scId}'");
- // scCntSql.Append($" where c.id='{scId}'");
- // }
- // if (string.IsNullOrEmpty($"{scId}") && !string.IsNullOrEmpty($"{name}"))
- // {
- // stringBuilder.Append($" where Contains(c.name,'{name}')");
- // scCntSql.Append($" where Contains(c.name,'{name}')");
- // }
- // if (!string.IsNullOrEmpty($"{province}") && string.IsNullOrEmpty($"{city}") && string.IsNullOrEmpty($"{dist}"))
- // {
- // stringBuilder.Append($" where Contains(c.province,'{province}')");
- // scCntSql.Append($" where Contains(c.province,'{province}')");
- // }
- // if (!string.IsNullOrEmpty($"{city}") && !string.IsNullOrEmpty($"{city}") && string.IsNullOrEmpty($"{dist}"))
- // {
- // stringBuilder.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}')");
- // scCntSql.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}')");
- // }
- // if (!string.IsNullOrEmpty($"{dist}") && !string.IsNullOrEmpty($"{city}") && !string.IsNullOrEmpty($"{dist}"))
- // {
- // stringBuilder.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}') and Contains(c.dist,'{dist}')");
- // scCntSql.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}') and Contains(c.dist,'{dist}')");
- // }
- // if ($"{order}".Equals("desc"))
- // stringBuilder.Append(" order by c.createTime desc");
- // scCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", scCntSql.ToString(), "Base");
- // await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: stringBuilder.ToString(), continuationToken: pageToken, requestOptions: new QueryRequestOptions() { MaxItemCount = pageSize, PartitionKey = new PartitionKey("Base") }))
- // {
- // using var json = await JsonDocument.ParseAsync(itemSchool.ContentStream);
- // if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
- // {
- // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- // {
- // schoolAssists.Add(obj.ToObject<AssistSchool>());
- // }
- // if (iscontinuation)
- // {
- // continuationToken = itemSchool.GetContinuationToken();
- // break;
- // }
- // }
- // }
- //}
- foreach (var item in schoolAssists)
- {
- var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(item.id, new PartitionKey("ProductSum"));
- if (response.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
- if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
- item.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
- if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
- item.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
- if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
- item.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
- }
- item.assists = await CommonFind.FindSchoolRoles(cosmosClient, item.id, "assist");
- item.scAdmin = await CommonFind.FindSchoolRoles(cosmosClient, item.id, "admin");
- item.lessonCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(count(c.id)) from c ", $"LessonRecord-{item.id}");
- }
- //schoolAssists.ForEach(async school =>
- //{
- // var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school.id, new PartitionKey("ProductSum"));
- // if (response.Status == 200)
- // {
- // using var json = await JsonDocument.ParseAsync(response.ContentStream);
- // if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
- // {
- // school.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
- // }
- // if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
- // {
- // school.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
- // }
- // if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
- // {
- // school.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
- // }
- // }
- // school.assists = await CommonFind.FindSchoolRoles(cosmosClient, school.id, "assist");
- // school.lessonCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(count(c.id)) from c ", $"LessonRecord-{school.id}");
- //});
- return Ok(new { state = 200, scCnt, continuationToken, schoolAssists });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-schoolsinfo \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 所有信息
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-allscinfo")]
- public async Task<IActionResult> GetAllScsInfo(JsonElement jsonElement)
- {
- try
- {
- jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
- jsonElement.TryGetProperty("role", out JsonElement role);
- jsonElement.TryGetProperty("scId", out JsonElement scId);
- jsonElement.TryGetProperty("name", out JsonElement name);
- jsonElement.TryGetProperty("order", out JsonElement order);
- jsonElement.TryGetProperty("province", out JsonElement province);
- jsonElement.TryGetProperty("city", out JsonElement city);
- jsonElement.TryGetProperty("dist", out JsonElement dist);
- //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
- var cosmosClient = _azureCosmos.GetCosmosClient();
- ////分开部署,就不需要,一站多用时,取消注释
- //if ($"{site}".Equals(BIConst.Global))
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- int scCnt = 0;
- List<AssistSchool> schoolAssists = new(); //返回学校列表集合
- List<string> schoolIds = new();
- StringBuilder stringBuilder = new("select c.id,c.code,c.schoolCode,c.name,c.region,c.province,c.city,c.dist,c.size,c.address,c.picture,c.type,c.scale,c.areaId,c.standard from c ");
- StringBuilder scCntSql = new($"select value(count(c.id)) from c");
- if (!string.IsNullOrEmpty($"{scId}") && string.IsNullOrEmpty($"{name}"))
- {
- stringBuilder.Append($" where c.id='{scId}'");
- scCntSql.Append($" where c.id='{scId}'");
- }
- if (string.IsNullOrEmpty($"{scId}") && !string.IsNullOrEmpty($"{name}"))
- {
- stringBuilder.Append($" where Contains(c.name,'{name}')");
- scCntSql.Append($" where Contains(c.name,'{name}')");
- }
- if (!string.IsNullOrEmpty($"{province}") && string.IsNullOrEmpty($"{city}") && string.IsNullOrEmpty($"{dist}"))
- {
- stringBuilder.Append($" where Contains(c.province,'{province}')");
- scCntSql.Append($" where Contains(c.province,'{province}')");
- }
- if (!string.IsNullOrEmpty($"{city}") && !string.IsNullOrEmpty($"{city}") && string.IsNullOrEmpty($"{dist}"))
- {
- stringBuilder.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}')");
- scCntSql.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}')");
- }
- if (!string.IsNullOrEmpty($"{dist}") && !string.IsNullOrEmpty($"{city}") && !string.IsNullOrEmpty($"{dist}"))
- {
- stringBuilder.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}') and Contains(c.dist,'{dist}')");
- scCntSql.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}') and Contains(c.dist,'{dist}')");
- }
- if (!string.IsNullOrEmpty($"{tmdId}"))
- {
- schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}", roles: !string.IsNullOrEmpty($"{role}") ? $"{role}" : "assist", isMany: true);
- string scsSql = BICommonWay.ManyScSql("c.id", schoolIds);
- scCntSql.Append($" where {scsSql}");
- scCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", scCntSql.ToString(), "Base");
- foreach (var id in schoolIds)
- {
- StringBuilder sqlTxt = new($"select c.id,c.code,c.schoolCode,c.name,c.region,c.province,c.city,c.dist,c.size,c.address,c.picture,c.type,c.scale,c.areaId,c.standard from c where c.id='{id}'");
- if ($"{order}".Equals("desc"))
- sqlTxt.Append(" order by c.createTime desc");
- await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AssistSchool>(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- schoolAssists.Add(itemSchool);
- }
- }
- }
- else
- {
- if ($"{order}".Equals("desc"))
- stringBuilder.Append(" order by c.createTime desc");
- scCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", scCntSql.ToString(), "Base");
- await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- using var json = await JsonDocument.ParseAsync(itemSchool.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- schoolAssists.Add(obj.ToObject<AssistSchool>());
- }
- }
- }
- }
- foreach (var item in schoolAssists)
- {
- var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(item.id, new PartitionKey("ProductSum"));
- if (response.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
- if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
- item.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
- if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
- item.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
- if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
- item.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
- }
- item.assists = await CommonFind.FindSchoolRoles(cosmosClient, item.id, "assist");
- item.scAdmin = await CommonFind.FindSchoolRoles(cosmosClient, item.id, "admin");
- item.lessonCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(count(c.id)) from c ", $"LessonRecord-{item.id}");
- }
- return Ok(new { state = 200, scCnt, schoolAssists });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-allscinfo() \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 使用yieId 关键字 本地效率未测出
- /// </summary>
- /// <param name="cosmosClient"></param>
- /// <param name="schoolAssists"></param>
- /// <returns></returns>
- private async IAsyncEnumerable<List<AssistSchool>> GetSchools(CosmosClient cosmosClient, List<AssistSchool> schoolAssists)
- {
- List<AssistSchool> tempSchoolAssists = new();
- foreach (var temp in schoolAssists)
- {
- var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(temp.id, new PartitionKey("ProductSum"));
- if (response.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
- if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
- {
- temp.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
- }
- if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
- {
- temp.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
- }
- if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
- {
- temp.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
- }
- }
- temp.assists = await CommonFind.FindSchoolRoles(cosmosClient, temp.id, "assist");
- tempSchoolAssists.Add(temp);
- }
- yield return tempSchoolAssists;
- }
- /// <summary>
- /// 取得学校所有顾问列表
- /// </summary>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-schoolassist")]
- public async Task<IActionResult> GetSchoolAssist(JsonElement jsonElement)
- {
- try
- {
- //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
- string schoolId = (jsonElement.TryGetProperty("schoolId", out JsonElement _schoolId)) ? _schoolId.GetString() : string.Empty;
- Dictionary<string, List<Dictionary<string, string>>> haveSchoolManger = new();
- string managerWhereOption = (!string.IsNullOrWhiteSpace(schoolId)) ? $" AND c.code = 'Teacher-{schoolId}'" : string.Empty;
- //查询学校的顾问
- string managerSql = $"SELECT DISTINCT REPLACE(c.code, 'Teacher-', '') AS schoolId, c.id, c.name FROM c WHERE ARRAY_CONTAINS(c.roles, 'assist', true) AND c.pk = 'Teacher' AND c.status = 'join'{managerWhereOption}";
- var cosmosClient = _azureCosmos.GetCosmosClient();
- //if ($"{site}".Equals(BIConst.Global))
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: managerSql, requestOptions: new QueryRequestOptions() { }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- string id = obj.GetProperty("id").GetString(); //管理员ID
- string name = obj.GetProperty("name").GetString(); //管理员姓名
- string tempSchoolId = obj.GetProperty("schoolId").GetString(); //学校ID
- Dictionary<string, string> managerDic = new();
- managerDic.Add("id", id);
- managerDic.Add("name", name);
- if (haveSchoolManger.ContainsKey(tempSchoolId))
- {
- haveSchoolManger[tempSchoolId].Add(managerDic);
- }
- else
- {
- List<Dictionary<string, string>> managerList = new List<Dictionary<string, string>>();
- managerList.Add(managerDic);
- haveSchoolManger.Add(tempSchoolId, managerList);
- }
- }
- }
- //管理模组学校
- List<string> baseModuleSchoos = new List<string>();
- string baseWhereOption = (!string.IsNullOrEmpty(schoolId)) ? $" and c.id='{schoolId}'" : string.Empty;
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c join serviceProduct in c.service.product where serviceProduct.prodCode = 'IPDYZYLC' {baseWhereOption}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Product") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- string tempSchoolId = obj.GetProperty("id").GetString(); //学校ID
- baseModuleSchoos.Add(tempSchoolId);
- }
- }
- //学校信息
- List<object> schools = new List<object>();
- string schoolWhereOption = (!string.IsNullOrEmpty(schoolId)) ? $" where c.id='{schoolId}'" : string.Empty;
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id,c.name,c.period,c.schoolCode,c.region,c.province,c.city,c.picture from c {schoolWhereOption}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- dynamic schoolExpando = new ExpandoObject();
- schoolExpando.id = obj.GetProperty("id").GetString();
- schoolExpando.name = obj.GetProperty("name").GetString();
- //schoolExpando.period = obj.GetProperty("period");
- schoolExpando.schoolCode = obj.GetProperty("schoolCode").GetString();
- schoolExpando.region = obj.GetProperty("region").GetString();
- schoolExpando.province = obj.GetProperty("province").GetString();
- schoolExpando.city = obj.GetProperty("city").GetString();
- schoolExpando.picture = obj.GetProperty("picture").GetString();
- if (haveSchoolManger.ContainsKey(schoolExpando.id))
- {
- schoolExpando.hasMarger = true;
- schoolExpando.managers = haveSchoolManger[schoolExpando.id];
- }
- else
- {
- schoolExpando.hasMarger = false;
- schoolExpando.managers = new List<object>();
- }
- schoolExpando.hasBaseModule = (baseModuleSchoos.Contains(schoolExpando.id)) ? true : false;
- schools.Add(schoolExpando);
- }
- }
- return Ok(new { state = 200, schools });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-schools \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 修改学校信息和顾问信息 //已经对接
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "admin,rdc")]
- [HttpPost("upd-schoolassist")]
- public async Task<IActionResult> UpdSchoolAssist(JsonElement jsonElement)
- {
- try
- {
- if (!jsonElement.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
- if (!jsonElement.TryGetProperty("name", out JsonElement schoolName)) return BadRequest();
- if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
- if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
- //if (!jsonElement.TryGetProperty("period", out JsonElement period)) return BadRequest();
- if (!jsonElement.TryGetProperty("picture", out JsonElement picture)) return BadRequest();
- if (!jsonElement.TryGetProperty("size", out JsonElement size)) return BadRequest();
- if (!jsonElement.TryGetProperty("scale", out JsonElement scale)) return BadRequest();
- if (!jsonElement.TryGetProperty("type", out JsonElement _type)) return BadRequest();
- jsonElement.TryGetProperty("province", out JsonElement province);
- jsonElement.TryGetProperty("city", out JsonElement city);
- jsonElement.TryGetProperty("dist", out JsonElement dist);
- jsonElement.TryGetProperty("address", out JsonElement address);
- string code = (jsonElement.TryGetProperty("code", out JsonElement _code))? _code.GetString() : string.Empty;
- jsonElement.TryGetProperty("assist", out JsonElement assist);
- jsonElement.TryGetProperty("scaleVersion", out JsonElement scaleVersion);
- //手動追加商業模組的部分先封印,商業模組需要經過訂單系統下單控管。
- //List<string> modules = null ;
- //if (!jsonElement.TryGetProperty("modules ", out JsonElement _modules))
- //{
- // return BadRequest();
- //}
- //else {
- // modules= _modules.ToObject<List<string>>();
- //}
- List<IdInfo> idInfos = assist.ToObject<List<IdInfo>>();
- //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
- var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- var tableClient = _azureStorage.GetCloudTableClient();
- var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
- //if ($"{site}".Equals(BIConst.Global))
- //{
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
- // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
- //}
- //IES5 實體學校變更
- if (!code.Equals("VirtualBase"))
- {
- School tempShool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
- if (tempShool != null)
- {
- List<Period> periods = new();
- string campusId = Guid.NewGuid().ToString();
- //periodS.ForEach(x =>
- //{
- // periods.Add(new Period { id = Guid.NewGuid().ToString(), name = x.ToString(), campusId = campusId });
- //});
- //tempShool.period = periods;
- //if (modules!=null) {
- // tempShool.modules=modules;
- //}
- tempShool.size = !string.IsNullOrEmpty($"{size}") ? int.Parse($"{size}") : tempShool.size;
- tempShool.scale = !string.IsNullOrEmpty($"{scale}") ? int.Parse($"{scale}") : tempShool.scale;
- tempShool.picture = $"{picture}";
- tempShool.type = int.Parse($"{_type}");
- tempShool.name = $"{schoolName}";
- tempShool.areaId = $"{areaId}";
- tempShool.standard = $"{standard}";
- tempShool.province = string.IsNullOrEmpty($"{province}") ? tempShool.province : $"{province}";
- tempShool.city = string.IsNullOrEmpty($"{city}") ? tempShool.city : $"{city}";
- tempShool.dist = string.IsNullOrEmpty($"{dist}") ? tempShool.dist : $"{dist}";
- tempShool.address = string.IsNullOrEmpty($"{address}") ? tempShool.address : $"{address}";
-
- //計算學校版本
- List<SchoolProductSumData> services = new List<SchoolProductSumData>();
- Azure.Response productSumResponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{_schoolId}", new PartitionKey("ProductSum"));
- if (productSumResponse.Status == 200)
- {
- var doc = JsonDocument.Parse(productSumResponse.Content);
- if (doc.RootElement.TryGetProperty("service", out JsonElement service))
- {
- services.AddRange(service.ToObject<List<SchoolProductSumData>>());
- }
- }
- tempShool.edition = BISchoolService.calSchoolEdition(tempShool, services.Select(s => s.prodCode).ToList());
- tempShool.edition.scaleVersion = string.IsNullOrEmpty($"{scaleVersion}") ? tempShool.edition.scaleVersion : $"{scaleVersion}";
- //修改学校
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempShool, tempShool.id, new PartitionKey("Base"));
- //创建学校信息中间件
- await BIStats.SetSchoolBIRelation(cosmosClient, blobClient, tableClient, _dingDing, tempShool);
- //修改学校教师关联的信息
- string sql = $"SELECT distinct value(c) FROM c join A1 in c.schools where A1.schoolId='{tempShool.id}'";
- List<Teacher> teachers = new();
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
- {
- teachers.Add(item);
- }
- foreach (var item in teachers)
- {
- Teacher.TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(tempShool.id));
- if (teacherSchool != null)
- {
- teacherSchool.name = tempShool.name;
- teacherSchool.picture = tempShool.picture;
- teacherSchool.areaId = tempShool.areaId;
- }
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
- }
- //学校信息中间件更新
- BIRelation biRel = new();
- var respRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(tempShool.id, new PartitionKey("BIRel"));
- if (respRel.Status == 200)
- {
- using var fileJson = await JsonDocument.ParseAsync(respRel.ContentStream);
- biRel = fileJson.ToObject<BIRelation>();
- }
- else
- {
- biRel.id = tempShool.id;
- }
- string aName = null;
- if (!string.IsNullOrEmpty($"{tempShool.areaId}"))
- {
- aName = await CosmosQueryHelper.GetStr(cosmosClient, "Normal", $"select value(c.name) from c where c.id='{tempShool.areaId}'", "Base-Area");
- }
- biRel.name = tempShool.name;
- biRel.picture = tempShool.picture;
- biRel.region = tempShool.region;
- biRel.province = tempShool.province;
- biRel.city = tempShool.city;
- biRel.dist = tempShool.dist;
- biRel.address = tempShool.address;
- biRel.areaId = tempShool.areaId;
- biRel.size = tempShool.size;
- biRel.scale = tempShool.scale;
- biRel.upDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- biRel.areaName = aName;
- biRel.edition = tempShool.edition;
- if (idInfos.Count > 0)
- {
- foreach (var item in idInfos)
- {
- var tempAss = biRel.assists.Find(f => f.id.Equals(item.id));
- if (tempAss == null)
- biRel.assists.Add(item);
- }
- }
- else
- {
- biRel.assists = idInfos;
- }
- if (respRel.Status == 200)
- {
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(biRel, biRel.id, new PartitionKey("BIRel"));
- }
- else
- {
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<BIRelation>(biRel, new PartitionKey("BIRel"));
- }
- }
-
- //保存操作记录
- await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】修改学校功能,修改的学校:{_schoolId},{_type},{picture},{size},{idInfos.ToArray()}", _dingDing, httpContext: HttpContext);
- return Ok(new { state = 200 });
- }
- //IES5 虛擬學校變更
- else
- {
- VirtualBase tempVirtual = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<VirtualBase>($"{_schoolId}", new PartitionKey("VirtualBase"));
- if (tempVirtual != null)
- {
- tempVirtual.picture = $"{picture}";
- tempVirtual.type = int.Parse($"{_type}");
- tempVirtual.name = $"{schoolName}";
- tempVirtual.areaId = $"{areaId}";
- tempVirtual.standard = $"{standard}";
- tempVirtual.province = string.IsNullOrEmpty($"{province}") ? tempVirtual.province : $"{province}";
- tempVirtual.city = string.IsNullOrEmpty($"{city}") ? tempVirtual.city : $"{city}";
- tempVirtual.dist = string.IsNullOrEmpty($"{dist}") ? tempVirtual.dist : $"{dist}";
- tempVirtual.address = string.IsNullOrEmpty($"{address}") ? tempVirtual.address : $"{address}";
- string aName = null;
- if (!string.IsNullOrEmpty($"{tempVirtual.areaId}"))
- {
- aName = await CosmosQueryHelper.GetStr(cosmosClient, "Normal", $"select value(c.name) from c where c.id='{tempVirtual.areaId}'", "Base-Area");
- }
- tempVirtual.areaName = aName;
- //修改学校
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<VirtualBase>(tempVirtual, tempVirtual.id, new PartitionKey("VirtualBase"));
- }
- // 保存操作记录
- await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】修改学校功能,修改的学校:{_schoolId},{_type},{picture},{size},{idInfos.ToArray()}", _dingDing, httpContext: HttpContext);
- return Ok(new { state = 200 });
- }
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI, {_option.Location} /batchschool/upd-schoolassist \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 查询区域的学校
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-schooldist")]
- public async Task<IActionResult> GetSchoolDist(JsonElement jsonElement)
- {
- try
- {
- if (!jsonElement.TryGetProperty("dist", out JsonElement _dist)) return BadRequest();
- //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
- var cosmosClient = _azureCosmos.GetCosmosClient();
- //if ($"{site}".Equals(BIConst.Global))
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- string sqltxt = $"SELECT * FROM c where c.dist='{_dist}'";
- List<School> schools = new List<School>();
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- schools.Add(item);
- }
- return Ok(new { state = 200, schools });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-schooldist \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 分页学校和顾问信息
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-schools")]
- public async Task<IActionResult> GetSchools(JsonElement jsonElement)
- {
- //List<School> schools = new List<School>();
- List<AssistSchool> schoolAssists = new List<AssistSchool>();
- if (!jsonElement.TryGetProperty("endPosition", out JsonElement endPosition)) return BadRequest();
- if (!jsonElement.TryGetProperty("pageSize", out JsonElement pageSize)) return BadRequest();
- //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
- var cosmosClient = _azureCosmos.GetCosmosClient();
- //if ($"{site}".Equals(BIConst.Global))
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- string sqltxt = $"SELECT * FROM c order by c.id offset {endPosition} limit {pageSize}";
- await foreach (var itemSchool in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- AssistSchool schoolAssist = new()
- {
- id = itemSchool.id,
- code = itemSchool.code,
- schoolCode = itemSchool.schoolCode,
- name = itemSchool.name,
- region = itemSchool.region,
- province = itemSchool.province,
- city = itemSchool.city,
- dist = itemSchool.dist,
- size = itemSchool.size,
- address = itemSchool.address,
- picture = itemSchool.picture,
- type = itemSchool.type,
- scale = itemSchool.scale,
- areaId = itemSchool.areaId,
- standard = itemSchool.standard
- };
- schoolAssist.assists = await CommonFind.FindSchoolRoles(cosmosClient, itemSchool.id, "assist");
- schoolAssists.Add(schoolAssist);
- }
- return Ok(new { state = 200, schoolAssists });
- }
- /// <summary>
- /// 创校前检查数据
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-checlkexist")]
- public async Task<IActionResult> GetCheckExist(JsonElement jsonElement)
- {
- if (!jsonElement.TryGetProperty("scNames", out JsonElement _scNames)) return BadRequest();
- if (!jsonElement.TryGetProperty("accounts", out JsonElement _accounts)) return BadRequest();
- if (!jsonElement.TryGetProperty("areaIds", out JsonElement _areaIds)) return BadRequest();
- jsonElement.TryGetProperty("schools", out JsonElement schools);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- List<CreateSchoolInfo> cSchools = new();
- if (!string.IsNullOrEmpty($"{schools}"))
- cSchools = schools.ToObject<List<CreateSchoolInfo>>();
- List<string> scNames = _scNames.ToObject<List<string>>();
- List<string> accounts = _accounts.ToObject<List<string>>();
- List<string> areaIds = _areaIds.ToObject<List<string>>();
- List<string> existScNames = new(); //存在的学校
- List<string> noAccounts = new(); // 不存在的账户
- List<string> noAreaIds = new(); //不存在的学区
- List<string> synPro = new(); //已同步省平台
- List<CreateSchoolInfo> createScInfo = new(); //学校简码信息
- if (scNames.Count > 0)
- {
- foreach (var item in scNames)
- {
- //查询学校名称是否全字段匹配
- await foreach (var sc in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: $"select value(c.name) from c where c.name='{item}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- existScNames.Add(item);
- }
- }
- }
- if (accounts.Count > 0)
- {
- var content = new StringContent(_accounts.ToString(), Encoding.UTF8, "application/json");
- string json = await _coreAPIHttpService.GetUserInfos(content);
- List<TmdUserinfo> tmdInfos = json.ToObject<List<TmdUserinfo>>();
- accounts.ForEach(ac =>
- {
- TmdUserinfo noTmdInfo = null;
- tmdInfos.ForEach(tmd =>
- {
- if (!string.IsNullOrEmpty(tmd.id))
- if (tmd.id.Equals($"{ac}"))
- noTmdInfo = tmd;
- if (!string.IsNullOrEmpty(tmd.mobile))
- if (tmd.mobile.Equals($"{ac}"))
- noTmdInfo = tmd;
- if (!string.IsNullOrEmpty(tmd.mail))
- if (tmd.mail.Equals($"{ac}"))
- noTmdInfo = tmd;
- });
- //noTmdInfo = tmdInfos.Find(f => f.id.Equals($"{ac}") || f.mail.Equals($"{ac}") || f.mobile.Equals($"{ac}"));
- if (noTmdInfo == null)
- noAccounts.Add(ac);
- });
- }
- if (areaIds.Count > 0)
- {
- foreach (var item in areaIds)
- {
- //查询区是否存在
- var respAreaId = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{item}", new PartitionKey("Base-Area"));
- if (respAreaId.Status != 200)
- {
- noAreaIds.Add(item);
- }
- //查询去是否同步省平台
- var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{item}", 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))
- synPro.Add(item);
- }
- }
- }
- foreach (var item in cSchools)
- {
- CreateSchoolInfo createSchoolInfo = item;
- //生成学校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);
- createScInfo.Add(createSchoolInfo);
- }
- if (existScNames.Count > 0 || noAccounts.Count > 0 || noAreaIds.Count > 0 || synPro.Count > 0)
- return Ok(new { state = RespondCode.Created, existScNames, noAccounts, noAreaIds, synPro, createScInfo });
- else
- return Ok(new { state = RespondCode.Ok, createScInfo });
- }
- /// <summary>
- /// 批量创校前检查数据
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-checkexists")]
- public async Task<IActionResult> GetCheckExists(JsonElement jsonElement)
- {
- if (!jsonElement.TryGetProperty("checkScs", out JsonElement checkScs)) return BadRequest();
- List<BISchool> bISchools = checkScs.ToObject<List<BISchool>>();
- var cosmosClient = _azureCosmos.GetCosmosClient();
- List<BISchool> existScNames = new(); //存在的学校
- List<BISchool> noAccounts = new(); // 不存在的账户
- List<BISchool> noAreaIds = new(); //不存在的学区
- List<BISchool> synPro = new(); //已同步省平台
- List<BISchool> createScInfo = new(); //学校简码信息
- foreach (BISchool bISchool in bISchools)
- {
- //查询学校名称是否全字段匹配
- await foreach (var sc in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: $"select value(c.name) from c where c.name='{bISchool.name}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- existScNames.Add(bISchool);
- }
- var content = new StringContent(bISchool.admin.ToJsonString(), Encoding.UTF8, "application/json");
- string json = await _coreAPIHttpService.GetUserInfos(content);
- List<TmdUserinfo> tmdInfos = json.ToObject<List<TmdUserinfo>>();
- bISchool.admin.ForEach(ac =>
- {
- TmdUserinfo noTmdInfo = null;
- tmdInfos.ForEach(tmd =>
- {
- if (!string.IsNullOrEmpty(tmd.id))
- if (tmd.id.Equals($"{ac}"))
- noTmdInfo = tmd;
- if (!string.IsNullOrEmpty(tmd.mobile))
- if (tmd.mobile.Equals($"{ac}"))
- noTmdInfo = tmd;
- if (!string.IsNullOrEmpty(tmd.mail))
- if (tmd.mail.Equals($"{ac}"))
- noTmdInfo = tmd;
- });
- //noTmdInfo = tmdInfos.Find(f => f.id.Equals($"{ac}") || f.mail.Equals($"{ac}") || f.mobile.Equals($"{ac}"));
- if (noTmdInfo == null)
- noAccounts.Add(bISchool);
- });
- if (!string.IsNullOrEmpty(bISchool.areaId))
- {
- //查询区是否存在
- var respAreaId = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{bISchool.areaId}", new PartitionKey("Base-Area"));
- if (respAreaId.Status != 200)
- {
- noAreaIds.Add(bISchool);
- }
- //查询去是否同步省平台
- var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{bISchool.areaId}", 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))
- synPro.Add(bISchool);
- }
- }
- 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);
- bISchool.id = createSchoolInfo.id;
- createScInfo.Add(bISchool);
- }
- if (existScNames.Count > 0 || noAccounts.Count > 0 || noAreaIds.Count > 0 || synPro.Count > 0)
- return Ok(new { state = RespondCode.Created, existScNames, noAccounts, noAreaIds, synPro, createScInfo });
- else
- return Ok(new { state = RespondCode.Ok, createScInfo });
- }
- /// <summary>
- /// 添加多个学校添加多个管理员
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("set-batchmanage")]
- public async Task<IActionResult> SetBatchManage(JsonElement jsonElement)
- {
- if (!jsonElement.TryGetProperty("scIds", out JsonElement _scIds)) return BadRequest();
- if (!jsonElement.TryGetProperty("manages", out JsonElement _manages)) return BadRequest();
- var cosmosClient = _azureCosmos.GetCosmosClient();
- List<string> scIds = _scIds.ToObject<List<string>>();
- List<string> manages = _manages.ToObject<List<string>>();
- List<ExistScManage> existScManages = new();
- if (scIds.Count > 0 && manages.Count > 0)
- {
- foreach (var scId in scIds)
- {
- foreach (var msId in manages)
- {
- //不存在则在原来的基础上添加顾问角色
- Teacher tempTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{msId}", new PartitionKey("Base"));
- if (tempTeacher != null)
- {
- var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{msId}", new PartitionKey($"Teacher-{scId}"));
- if (response.Status == 200)
- {
- using var tchJson = await JsonDocument.ParseAsync(response.ContentStream);
- SchoolTeacher tchSc = tchJson.ToObject<SchoolTeacher>();
- if (tchSc.roles.Contains("admin"))
- {
- tchSc.roles.Add("admin");
- //添加顾问权限
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(tchSc, tchSc.id, new PartitionKey($"Teacher-{scId}"));
- }
- else
- existScManages.Add(new ExistScManage() { scId = scId, tmdId = msId });
- }
- else
- {
- SchoolTeacher addSchoolTeacher = new()
- {
- id = tempTeacher.id,
- code = $"Teacher-{scId}",
- pk = "Teacher",
- status = "join",
- roles = new List<string>() { "admin" },
- name = tempTeacher.name,
- job = $"管理员",
- size = 0,
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
- };
- var haveTeacher = tempTeacher.schools.Find(x => x.schoolId.Equals($"{scId}"));
- if (haveTeacher == null)
- {
- School school = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(scId, new PartitionKey("Base"));
- //教师存在,在该教师信息中添加要管理的学校信息
- tempTeacher.schools.Add(new Teacher.TeacherSchool { areaId = string.IsNullOrEmpty(school.areaId) ? "" : school.areaId, schoolId = school.id, name = school.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
- tempTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(tempTeacher, msId, new PartitionKey("Base"));
- }
- //添加学校学校管理员
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{scId}"));
- }
- }
- else
- {
- CoreUser coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{msId}" } }, _option.Location, _configuration);
- Teacher teacher = new() { id = coreUser.id, name = coreUser.name, picture = coreUser.picture, pk = "Base", code = "Base", size = 1, createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() };
- var responseSc = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(scId, new PartitionKey("Base"));
- if (responseSc.Status == 200)
- {
- using var tchJson = await JsonDocument.ParseAsync(responseSc.ContentStream);
- School scInfo = tchJson.ToObject<School>();
- teacher.schools.Add(new() { schoolId = scInfo.id, name = scInfo.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = scInfo.picture, areaId = scInfo.areaId });
- }
- teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
- SchoolTeacher addSchoolTeacher = new()
- {
- id = coreUser.id,
- code = $"Teacher-{scId}",
- pk = "Teacher",
- status = "join",
- roles = new List<string>() { "admin" },
- name = coreUser.name,
- job = $"管理员",
- size = 0,
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
- };
- //添加学校学校管理员
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{scId}"));
- }
- }
- }
- }
- if (existScManages.Count > 0)
- return Ok(new { state = RespondCode.Created, existScManages });
- else
- return Ok(new { state = RespondCode.Ok });
- }
- /// <summary>
- /// 批量设置学校集合中学校多个管理员
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "admin")]
- [HttpPost("batch-scmanage")]
- public async Task<IActionResult> BatchScManage(JsonElement jsonElement)
- {
- if (!jsonElement.TryGetProperty("scManages", out JsonElement _scManages)) return BadRequest();
- var cosmosClient = _azureCosmos.GetCosmosClient();
- List<ScManages> scManages = _scManages.ToObject<List<ScManages>>();
- List<ScManages> error = new(); //异常数据
- foreach (var item in scManages)
- {
- School school = new();
- var resSc = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{item.id}", new PartitionKey("Base"));
- if (resSc.Status == 200)
- {
- using var sJson = await JsonDocument.ParseAsync(resSc.ContentStream);
- school = sJson.ToObject<School>();
- //CoreUser coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"19940828843" } }, _option.Location, _configuration);
- var content = new StringContent(item.mobiles.ToArray().ToJsonString(), Encoding.UTF8, "application/json");
- string json = await _coreAPIHttpService.GetUserInfos(content);
- List<TmdUserinfo> tmdInfos = json.ToObject<List<TmdUserinfo>>();
- Teacher teacher = new();
- foreach (var tmd in tmdInfos)
- {
- var respone = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{tmd.id}", new PartitionKey("Base"));
- if (respone.Status == 200)
- {
- using var tchJson = await JsonDocument.ParseAsync(respone.ContentStream);
- teacher = tchJson.ToObject<Teacher>();
- var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{tmd.id}", new PartitionKey($"Teacher-{item.id}"));
- if (response.Status == 200)
- {
- using var scTchJson = await JsonDocument.ParseAsync(response.ContentStream);
- SchoolTeacher tchSc = scTchJson.ToObject<SchoolTeacher>();
- if (tchSc.roles.Contains("admin"))
- {
- tchSc.roles.Add("admin");
- //添加顾问权限
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(tchSc, tchSc.id, new PartitionKey($"Teacher-{item.id}"));
- }
- else
- {
- var exsitI = error.Find(f => f.id.Equals(item.id));
- if (exsitI != null)
- {
- var replacts = error.Where(w => w.id.Equals(item.id)).FirstOrDefault();
- replacts.mobiles.Add($"{item.id}");
- }
- else
- error.Add(new ScManages { id = item.id, name = item.name, mobiles = new List<string>() { $"{tmd.id}" } });
- }
- }
- else
- {
- SchoolTeacher addSchoolTeacher = new()
- {
- id = tmd.id,
- code = $"Teacher-{item.id}",
- pk = "Teacher",
- status = "join",
- roles = new List<string>() { "admin" },
- name = tmd.name,
- job = $"管理员",
- size = 0,
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
- };
- var haveTeacher = teacher.schools.Find(x => x.schoolId.Equals($"{item.id}"));
- if (haveTeacher == null)
- {
- //教师存在,在该教师信息中添加要管理的学校信息
- teacher.schools.Add(new Teacher.TeacherSchool { areaId = string.IsNullOrEmpty(school.areaId) ? "" : school.areaId, schoolId = school.id, name = school.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
- teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
- }
- //添加学校学校顾问
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{item.id}"));
- }
- }
- else
- {
- teacher = new()
- {
- id = $"{tmd.id}",
- name = $"{tmd.name}",
- picture = $"{tmd.picture}",
- pk = "Base",
- code = "Base",
- size = 1,
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
- schools = new List<Teacher.TeacherSchool>() { new Teacher.TeacherSchool { schoolId = $"{school.id}", name = $"{school.name}", status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = school.province, areaId = school.areaId } }
- };
- teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
- SchoolTeacher addSchoolTeacher = new()
- {
- id = tmd.id,
- code = $"Teacher-{item.id}",
- pk = "Teacher",
- status = "join",
- roles = new List<string>() { "admin" },
- name = tmd.name,
- job = $"管理员",
- size = 0,
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
- };
- //添加学校学校管理员
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{item.id}"));
- }
- }
- }
- else
- error.Add(new ScManages { id = item.id, name = item.name, mobiles = new List<string>() });
- }
- return Ok(new { state = RespondCode.Ok, error });
- }
- #region 预设学校基础信息 多语言
- /// <summary>
- /// 预设学校基础信息 多语言
- /// </summary>
- /// <param name="period"></param>
- /// <param name="Language"></param>
- /// <param name="campusId"></param>
- /// <returns></returns>
- public List<Period> PresetSchoolPeriod(List<PeriodType> period, string Language, string campusId)
- {
- var builder = $"{_environment.ContentRootPath}/JsonFile/Preset/LangSchoolConfig.json";
- StreamReader streamReader = new(new FileStream(builder, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
- StringBuilder stringBuilder = new();
- string text;
- while ((text = streamReader.ReadLine()) != null)
- {
- stringBuilder.Append(text.ToString());
- }
- streamReader.Close();
- string input = stringBuilder.ToString();
- List<SchoolConfig> schoolConfigs = input.ToObject<List<SchoolConfig>>();
- SchoolConfig schoolConfig = schoolConfigs.Find(x => x.Lang.Contains($"{Language}"));
- if (schoolConfig == null)
- {
- if (Language.Contains("en"))
- schoolConfig = schoolConfigs.Find(x => x.Lang.Contains("en-US"));
- else
- schoolConfig = schoolConfigs.Find(x => x.Lang.Contains("zh-CN"));
- }
- List<Period> periods = new();
- if (period.Count > 0)
- {
- period.ForEach(x =>
- {
- periods.Add(new Period
- {
- id = Guid.NewGuid().ToString(),
- name = x.name,
- campusId = campusId,
- semesters = new List<Semester>() { new Semester { name = schoolConfig.semester[0].term, start = schoolConfig.semester[0].start, month = schoolConfig.semester[0].month, day = schoolConfig.semester[0].day, id = Guid.NewGuid().ToString() },
- new Semester { name = schoolConfig.semester[1].term, start = schoolConfig.semester[1].start, month = schoolConfig.semester[1].month, day = schoolConfig.semester[1].day, id = Guid.NewGuid().ToString() } },
- subjects = new List<Subject>() {
- new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
- new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
- new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
- },
- grades = schoolConfig.grades,
- analysis = new Analysis()
- {
- type = new List<ExamSimple>() { new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[0].name },
- new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[1].name },
- new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[2].name },
- new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[3].name } },
- income = schoolConfig.PresetExam[0].income,
- eugenics = schoolConfig.PresetExam[0].eugenics,
- touch = schoolConfig.PresetExam[0].touch
- },
- periodType = x.value
- });
- });
- }
- else
- {
- periods.Add(new Period
- {
- id = Guid.NewGuid().ToString(),
- name = "默认学段",
- campusId = campusId,
- semesters = new List<Semester>() { new Semester { name = schoolConfig.semester[0].term, start = schoolConfig.semester[0].start, month = schoolConfig.semester[0].month, day = schoolConfig.semester[0].day, id = Guid.NewGuid().ToString() },
- new Semester { name = schoolConfig.semester[1].term, start = schoolConfig.semester[1].start, month = schoolConfig.semester[1].month, day = schoolConfig.semester[1].day, id = Guid.NewGuid().ToString() } },
- subjects = new List<Subject>() {
- new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
- new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
- new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
- },
- grades = schoolConfig.grades,
- analysis = new Analysis()
- {
- type = new List<ExamSimple>() { new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[0].name },
- new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[1].name },
- new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[2].name },
- new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[3].name } },
- income = schoolConfig.PresetExam[0].income,
- eugenics = schoolConfig.PresetExam[0].eugenics,
- touch = schoolConfig.PresetExam[0].touch
- }
- });
- }
- return periods;
- }
- #endregion
- //public class SchoolAssist
- //{
- // public string id { get; set; }
- // public string code { get; set; }
- // public string schoolCode { get; set; }
- // public string name { get; set; }
- // public string region { get; set; }
- // public string province { get; set; }
- // public string city { get; set; }
- // public string dist { get; set; }
- // public int size { get; set; }
- // public string address { get; set; }
- // public string picture { get; set; }
- // public int type { get; set; }
- // public int scale { get; set; }
- // public string standard { get; set; }
- // public string areaId { get; set; }
- // public List<SchoolTeacherRoles> assists { get; set; }
- // public int serial { get; set; } //软体
- // public int service { get; set; } //服务
- // public int hard { get; set; } //硬体
- // //public List<SchoolProductSumData> serial { get; set; } //软体
- // //public List<SchoolProductSumData> service { get; set; } //服务
- // //public List<SchoolProductSumDataHard> hard { get; set; } //硬体
- //}
- /// <summary>
- /// 创建多个学校实体
- /// </summary>
- public record FoundSchools()
- {
- /// <summary>
- /// 语系
- /// </summary>
- public string lang { get; set; }
- /// <summary>
- /// 站点
- /// </summary>
- public string site { get; set; }
- /// <summary>
- /// 批量创校的数据结构
- /// </summary>
- public List<BISchool> biSchools { get; set; } = new List<BISchool>();
- }
- /// <summary>
- /// 批量创校的数据结构
- /// </summary>
- public record BISchool()
- {
- public string id { get; set; }
- /// <summary>
- /// 学校名称
- /// </summary>
- public string name { get; set; }
- /// <summary>
- /// 学校管理员
- /// </summary>
- public List<string> admin { get; set; }
- /// <summary>
- /// 学校的学段
- /// </summary>
- public List<PeriodType> period { get; set; }
- /// <summary>
- /// 学校空间大小
- /// </summary>
- public int size { get; set; }
- /// <summary>
- /// 地区
- /// </summary>
- public string region { get; set; }
- /// <summary>
- /// 省份
- /// </summary>
- public string province { get; set; }
- /// <summary>
- /// 城市
- /// </summary>
- public string city { get; set; }
- /// <summary>
- /// 县,区,郡
- /// </summary>
- public string dist { get; set; }
- /// <summary>
- /// 学校详细地址
- /// </summary>
- public string address { get; set; }
- /// <summary>
- /// 学校类型
- /// </summary>
- public int type { get; set; }
- /// <summary>
- /// 区域ID
- /// </summary>
- public string areaId { get; set; }
- /// <summary>
- /// 区域标准
- /// </summary>
- public string standard { get; set; }
- /// <summary>
- /// 規模版本
- /// </summary>
- public string scaleVersion { get; set; }
- /// <summary>
- /// 手动增加的模块 ["art"]
- /// </summary>
- //public List<string> modules { get; set; } = new List<string>();
- }
-
- /// <summary>
- /// 学段类型和学段名称
- /// </summary>
- public record PeriodType
- {
- public string name { get; set; }
- public string value { get; set; }
- }
- /// <summary>
- /// 存在的学校
- /// </summary>
- public record ExistScManage
- {
- public string scId { get; set; }
- public string tmdId { get; set; }
- }
- /// <summary>
- /// 管理员
- /// </summary>
- public record ScManages
- {
- public string id { get; set; }
- public string name { get; set; }
- public List<string> mobiles { get; set; }
- }
- }
- }
|