12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009 |
- 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();
- 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(),
- };
- 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);
- //手動追加商業模組的部分先封印,商業模組需要經過訂單系統下單控管。
- //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());
- //修改学校
- 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>
- /// 手动增加的模块 ["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; }
- }
- }
- }
|