BatchSchoolController.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. using Azure.Cosmos;
  2. using HTEXLib.COMM.Helpers;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Options;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Dynamic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Text.Json;
  12. using System.Threading.Tasks;
  13. using TEAMModelOS.Models;
  14. using TEAMModelOS.SDK.DI;
  15. using TEAMModelOS.SDK.Extension;
  16. using TEAMModelOS.SDK.Models;
  17. using TEAMModelOS.SDK.Models.Cosmos.BI;
  18. using Microsoft.AspNetCore.Hosting; //引用读取文件
  19. using TEAMModelOS.SDK.Models.Service;
  20. using System.IO;
  21. using System.Net.Http;
  22. using Microsoft.Extensions.Configuration;
  23. using System.Net.Http.Json;
  24. using System.Net;
  25. using TEAMModelBI.Filter;
  26. using TEAMModelBI.Tool.Extension;
  27. using TEAMModelBI.Tool;
  28. using TEAMModelBI.Models;
  29. namespace TEAMModelBI.Controllers.BISchool
  30. {
  31. [Route("batchschool")]
  32. [ApiController]
  33. public class BatchSchoolController : ControllerBase
  34. {
  35. private readonly AzureCosmosFactory _azureCosmos;
  36. private readonly DingDing _dingDing;
  37. private readonly Option _option;
  38. private readonly AzureStorageFactory _azureStorage;
  39. private readonly IWebHostEnvironment _environment; //读取文件
  40. private readonly IHttpClientFactory _http;
  41. //读取配置信息
  42. private readonly IConfiguration _configuration;
  43. public readonly string mobel = "学校";
  44. public BatchSchoolController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, IHttpClientFactory http)
  45. {
  46. _azureCosmos = azureCosmos;
  47. _dingDing = dingDing;
  48. _azureStorage = azureStorage;
  49. _option = option?.Value;
  50. _environment = hostingEnvironment;
  51. _configuration = configuration;
  52. _http = http;
  53. }
  54. /// <summary>
  55. /// 获取BI权限列表
  56. /// </summary>
  57. /// <returns></returns>
  58. [ProducesDefaultResponseType]
  59. [HttpPost("get-teacher-authoritybilist")]
  60. public async Task<IActionResult> GetAuthorityBIList()
  61. {
  62. Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", "authority-bi" } };
  63. var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
  64. List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);
  65. return Ok(new { authorityBIList });
  66. }
  67. /// <summary>
  68. /// 通过教师的id和学校的code查询权限
  69. /// </summary>
  70. /// <param name="jsonElement"></param>
  71. /// <returns></returns>
  72. [ProducesDefaultResponseType]
  73. [HttpPost("get-teacherroles")]
  74. public async Task<IActionResult> GetTeacherRoles(JsonElement jsonElement)
  75. {
  76. try
  77. {
  78. if (!jsonElement.TryGetProperty("id", out JsonElement id)) return Ok(new { state = 1, message = "参数错误!" });
  79. if (!jsonElement.TryGetProperty("schoolcode", out JsonElement schoolcode)) return Ok(new { state = 1, message = "参数错误!" });
  80. var client = _azureCosmos.GetCosmosClient();
  81. string sqltxt = $"select * from c where c.id='{id}'";
  82. List<string> roles = new List<string>();//角色列表
  83. List<string> permissions = new List<string>();//权限列表
  84. var schoolRoles = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{id}", new PartitionKey($"Teacher-{schoolcode}"));
  85. if (schoolRoles.Status == 200)
  86. {
  87. using var json = await JsonDocument.ParseAsync(schoolRoles.ContentStream);
  88. if (json.RootElement.TryGetProperty("roles", out JsonElement _roles) && _roles.ValueKind != JsonValueKind.Null)
  89. {
  90. foreach (var obj in _roles.EnumerateArray())
  91. {
  92. roles.Add(obj.GetString());
  93. }
  94. }
  95. if (json.RootElement.TryGetProperty("permissions", out JsonElement _permissions) && _permissions.ValueKind != JsonValueKind.Null)
  96. {
  97. foreach (var obj in _permissions.EnumerateArray())
  98. {
  99. permissions.Add(obj.GetString());
  100. }
  101. }
  102. }
  103. return Ok(new { state = 200, roles = roles, permissions = permissions });
  104. }
  105. catch (Exception ex)
  106. {
  107. await _dingDing.SendBotMsg($"BI,{_option.Location}, /batchschool/get-teacherroles \n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  108. return BadRequest();
  109. }
  110. }
  111. /// <summary>
  112. /// 依据传输的数据更新和删除权限
  113. /// </summary>
  114. /// <param name="jsonElement"></param>
  115. /// <returns></returns>
  116. [ProducesDefaultResponseType]
  117. [AuthToken(Roles = "assist")]
  118. [HttpPost("upd-permissions")]
  119. public async Task<IActionResult> SetSchoolPermissions(JsonElement jsonElement)
  120. {
  121. try
  122. {
  123. if (!jsonElement.TryGetProperty("ids", out JsonElement ids)) return Ok(new { state = 1, message = "ids参数错误!" });
  124. if (!jsonElement.TryGetProperty("school_code", out JsonElement school_code)) return Ok(new { state = 1, message = "school_code参数错误!" });
  125. if (!jsonElement.TryGetProperty("mode", out JsonElement mode)) return Ok(new { state = 1, message = "mode参数错误!" }); //del删除权限 up更新权限
  126. if (!jsonElement.TryGetProperty("paramPower", out JsonElement paramPower)) return Ok(new { state = 1, message = "paramPower参数错误!" });
  127. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  128. List<Exist> havepower = new(); //已存在的
  129. var client = _azureCosmos.GetCosmosClient();
  130. StringBuilder stringBuilder = new StringBuilder($"{_tmdName}【{_tmdId}】账户操作:");
  131. //更新权限
  132. foreach (var id in ids.EnumerateArray())
  133. {
  134. SchoolTeacher st = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolTeacher>($"{id}", new PartitionKey($"Teacher-{school_code}"));
  135. if (mode.GetString().Equals("del"))
  136. {
  137. stringBuilder.Append($"{st.name}【{st.id}】的权限,删除权限有:");
  138. foreach (var pm in paramPower.EnumerateArray())
  139. {
  140. var bools = st.permissions.Find(x => x.Equals($"{pm}"));
  141. if (!string.IsNullOrEmpty($"{bools}"))
  142. {
  143. st.permissions.RemoveAll(x => x.Equals($"{bools}"));
  144. stringBuilder.Append(pm);
  145. }
  146. }
  147. }
  148. else if (mode.GetString().Equals("up"))
  149. {
  150. stringBuilder.Append($"{st.name}【{st.id}】的权限,更新权限有:");
  151. var stes = st.roles.Find(x => x.Equals("assistant"));
  152. if (string.IsNullOrEmpty($"{stes}"))
  153. {
  154. st.roles.Add("assistant");
  155. }
  156. foreach (var pm in paramPower.EnumerateArray())
  157. {
  158. var bools = st.permissions.Find(x => x.Equals($"{pm}"));
  159. if (!string.IsNullOrEmpty($"{bools}"))
  160. {
  161. havepower.Add(new Exist { ID = id.GetString(), name = bools });
  162. }
  163. else
  164. {
  165. st.permissions.Add(pm.GetString());
  166. stringBuilder.Append(pm);
  167. }
  168. }
  169. if (havepower.Count > 0)
  170. {
  171. stringBuilder.Append($";已存在的权限:{havepower}");
  172. }
  173. }
  174. else { return Ok(new { state = 1, message = "mode参数错误!" }); }
  175. await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(st, id.GetString(), new PartitionKey($"Teacher-{school_code}"));
  176. }
  177. //保存操作记录
  178. await _azureStorage.SaveBILog("school-update", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
  179. return Ok(new { state = 200, havepower });
  180. }
  181. catch (Exception ex)
  182. {
  183. await _dingDing.SendBotMsg($"BI,{_option.Location}, /batchschool/upd-permissions \n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  184. return BadRequest();
  185. }
  186. }
  187. /// <summary>
  188. /// 批量创校
  189. /// </summary>
  190. /// <param name="school"></param>
  191. /// <returns></returns>
  192. [ProducesDefaultResponseType]
  193. [AuthToken(Roles = "assist")]
  194. [HttpPost("batch-school")]
  195. public async Task<IActionResult> BatchCreateSchool(FoundSchools foundSchools)
  196. {
  197. try
  198. {
  199. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  200. List<BISchool> schools = new List<BISchool>();
  201. StringBuilder stringBuilder = new StringBuilder($"{_tmdName}【{_tmdId}】使用批量创校功能:");
  202. if (foundSchools.biSchools.Count > 0)
  203. {
  204. var cosmosClient = _azureCosmos.GetCosmosClient();
  205. foreach (BISchool bischool in foundSchools.biSchools)
  206. {
  207. string tempTmdId = null;
  208. HttpClient httpClient = _http.CreateClient();
  209. string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
  210. List<string> mobile = new List<string>() { bischool.admin };
  211. HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, mobile);
  212. if (responseMessage.StatusCode == HttpStatusCode.OK)
  213. {
  214. string temp = responseMessage.Content.ReadAsStringAsync().Result;
  215. List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
  216. foreach (var item in json_id)
  217. {
  218. tempTmdId = item.GetProperty("id").ToString();
  219. }
  220. }
  221. string tmdId = !string.IsNullOrEmpty(tempTmdId) ? tempTmdId : bischool.admin;
  222. CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
  223. {
  224. province = bischool.province,
  225. id = "",
  226. name = bischool.name,
  227. city = bischool.city,
  228. aname = "",
  229. createCount = 0,
  230. };
  231. //生成学校ID
  232. bool tempStaus = true;
  233. do
  234. {
  235. createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
  236. var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
  237. if (schoolStatu.Status != 200) tempStaus = false;
  238. else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
  239. } while (tempStaus);
  240. if (createSchoolInfo.id != null)
  241. {
  242. string campusId = Guid.NewGuid().ToString();
  243. School upSchool = new School
  244. {
  245. id = createSchoolInfo.id,
  246. name = bischool.name,
  247. size = bischool.size == 0 ? 100 : bischool.size,
  248. code = "Base",
  249. campuses = new List<Campus> { new Campus { name = bischool.name, id = campusId } },
  250. region = bischool.region,
  251. province = bischool.province,
  252. city = bischool.city,
  253. dist = bischool.dist,
  254. address = bischool.address,
  255. picture = "https://teammodelstorage.blob.core.chinacloudapi.cn/0-public/school/bbf54fb3-3fc8-43ae-a358-107281c174cc.png",
  256. timeZone = new TEAMModelOS.SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
  257. type = bischool.type,
  258. pk = "School",
  259. ttl = -1,
  260. areaId = string.IsNullOrEmpty(bischool.areaId) ? "" : bischool.areaId,
  261. schoolCode = createSchoolInfo.id,
  262. period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
  263. scale = bischool.size >= 300 ? 500 : 0
  264. };
  265. stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
  266. //创建学校
  267. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
  268. Teacher teacher = null;
  269. try
  270. {
  271. //查询该教师是否存在
  272. teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{tmdId}", new PartitionKey("Base"));
  273. }
  274. catch
  275. {
  276. }
  277. if (teacher != null)
  278. {
  279. //教师存在,在该教师信息中添加要管理的学校信息
  280. 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() });
  281. //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, tmdId, new PartitionKey("Base"));
  282. SchoolTeacher schoolTeacher = new SchoolTeacher
  283. {
  284. id = tmdId,
  285. code = $"Teacher-{createSchoolInfo.id}",
  286. roles = new List<string> { "admin", "teacher" },
  287. job = "管理员",
  288. name = teacher.name,
  289. picture = teacher.picture,
  290. status = "join",
  291. createTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
  292. pk = "Teacher",
  293. ttl = -1
  294. };
  295. stringBuilder.Append($"教师信息:{schoolTeacher.name}【{schoolTeacher.id}】,教师权限:{string.Join(",", schoolTeacher.roles)}");
  296. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
  297. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
  298. }
  299. else
  300. {
  301. //不存在 新建教师和新建要管理的学校信息
  302. Teacher addteacher = new Teacher
  303. {
  304. id = tmdId,
  305. pk = "Base",
  306. code = "Base",
  307. name = $"{bischool.name}-管理员"?.ToString(),
  308. picture = "",
  309. //创建账号并第一次登录IES5则默认赠送1G
  310. size = 1,
  311. defaultSchool = createSchoolInfo.id,
  312. schools = new List<Teacher.TeacherSchool>() { new Teacher.TeacherSchool { schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() } }
  313. };
  314. stringBuilder.Append($"没有该教师信息创建的教师信息:{addteacher.name}【{addteacher.id}】");
  315. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
  316. SchoolTeacher schoolTeacher = new SchoolTeacher
  317. {
  318. id = tmdId,
  319. code = $"Teacher-{createSchoolInfo.id}",
  320. roles = new List<string> { "admin", "teacher" },
  321. job = "管理员",
  322. name = $"{tmdId}-管理员",
  323. picture = "",
  324. status = "join",
  325. createTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
  326. pk = "Teacher",
  327. ttl = -1
  328. };
  329. stringBuilder.Append($"教师权限:{string.Join(",", schoolTeacher.roles)}");
  330. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
  331. }
  332. }
  333. }
  334. }
  335. else return Ok(new { state = 1, message = "创校信息为空" });
  336. //保存操作记录
  337. await _azureStorage.SaveBILog("school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
  338. if (schools.Count > 0)
  339. return Ok(new { state = 201, message = "已有部分学校批量创建成功;学校编号已经重复!请检查学校编号!", schools });
  340. else
  341. return Ok(new { state = 200, message = "批量创校已全部完成" });
  342. }
  343. catch (Exception ex)
  344. {
  345. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/batch-school \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  346. return BadRequest();
  347. }
  348. }
  349. /// <summary>
  350. /// 依据学校编号查询学校信息;若是没有传学校编号,则查询所有学校信息
  351. /// </summary>
  352. /// <param name="jsonElement"></param>
  353. /// <returns></returns>
  354. [ProducesDefaultResponseType]
  355. [HttpPost("get-schoolsinfo")]
  356. public async Task<IActionResult> GetSchoolsInfo(JsonElement jsonElement)
  357. {
  358. try
  359. {
  360. jsonElement.TryGetProperty("schoolCode", out JsonElement _schoolCode);
  361. var cosmosClient = _azureCosmos.GetCosmosClient();
  362. List<SchoolAssist> schoolAssists = new();
  363. //StringBuilder stringBuilder = new StringBuilder("select value(c) from c");
  364. StringBuilder stringBuilder = new StringBuilder("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");
  365. if (!string.IsNullOrEmpty($"{_schoolCode}"))
  366. {
  367. stringBuilder.Append($" where c.id='{_schoolCode}'");
  368. }
  369. //await foreach (var itemSchool in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  370. //{
  371. // SchoolAssist schoolAssist = new()
  372. // {
  373. // id = itemSchool.id,
  374. // code = itemSchool.code,
  375. // schoolCode = itemSchool.schoolCode,
  376. // name = itemSchool.name,
  377. // region = itemSchool.region,
  378. // province = itemSchool.province,
  379. // city = itemSchool.city,
  380. // dist = itemSchool.dist,
  381. // size = itemSchool.size,
  382. // address = itemSchool.address,
  383. // picture = itemSchool.picture,
  384. // type = itemSchool.type,
  385. // scale = itemSchool.scale,
  386. // areaId = itemSchool.areaId,
  387. // standard = itemSchool.standard
  388. // };
  389. // var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(itemSchool.id, new PartitionKey("ProductSum"));
  390. // if (response.Status == 200)
  391. // {
  392. // using var json = await JsonDocument.ParseAsync(response.ContentStream);
  393. // schoolAssist.serial = json.RootElement.GetProperty("serial").GetArrayLength();
  394. // schoolAssist.service = json.RootElement.GetProperty("service").GetArrayLength();
  395. // schoolAssist.hard = json.RootElement.GetProperty("hard").GetArrayLength();
  396. // }
  397. // schoolAssist.assists = await CommonFind.FindSchoolRoles(cosmosClient, itemSchool.id, "assist");
  398. // schoolAssists.Add(schoolAssist);
  399. //}
  400. //return Ok(new { state = 200, schoolAssists });
  401. await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  402. {
  403. using var jsonSchool = await JsonDocument.ParseAsync(itemSchool.ContentStream);
  404. foreach (var objSchool in jsonSchool.RootElement.GetProperty("Documents").EnumerateArray())
  405. {
  406. var schoolId = objSchool.GetProperty("id").GetString();
  407. SchoolAssist schoolAssist = new()
  408. {
  409. id = schoolId,
  410. code = objSchool.GetProperty("code").GetString(),
  411. schoolCode = objSchool.GetProperty("schoolCode").GetString(),
  412. name = objSchool.GetProperty("name").GetString(),
  413. region = objSchool.GetProperty("region").GetString(),
  414. province = objSchool.GetProperty("province").GetString(),
  415. city = objSchool.GetProperty("city").GetString(),
  416. dist = objSchool.GetProperty("dist").GetString(),
  417. size = objSchool.GetProperty("size").GetInt32(),
  418. address = objSchool.GetProperty("address").GetString(),
  419. picture = objSchool.GetProperty("picture").GetString(),
  420. type = objSchool.GetProperty("type").GetInt32(),
  421. //scale = objSchool.GetProperty("scale").GetInt32(),
  422. areaId = objSchool.GetProperty("areaId").GetString(),
  423. standard = objSchool.GetProperty("standard").GetString(),
  424. };
  425. try { schoolAssist.scale = objSchool.GetProperty("scale").GetInt32(); }
  426. catch { schoolAssist.scale = 0; }
  427. //var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolId, new PartitionKey("ProductSum"));
  428. //if (response.Status == 200)
  429. //{
  430. // using var json = await JsonDocument.ParseAsync(response.ContentStream);
  431. // schoolAssist.serial = json.RootElement.GetProperty("serial").GetArrayLength();
  432. // schoolAssist.service = json.RootElement.GetProperty("service").GetArrayLength();
  433. // schoolAssist.hard = json.RootElement.GetProperty("hard").GetArrayLength();
  434. //}
  435. //schoolAssist.assists = await CommonFind.FindSchoolRoles(cosmosClient, schoolId, "assist");
  436. schoolAssists.Add(schoolAssist);
  437. }
  438. }
  439. List<SchoolAssist> tempSchoolAssists = new();
  440. await foreach (var temp in GetSchools(cosmosClient, schoolAssists))
  441. {
  442. tempSchoolAssists.AddRange(temp);
  443. }
  444. return Ok(new { state = 200, schoolAssists = tempSchoolAssists });
  445. }
  446. catch (Exception ex)
  447. {
  448. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-schoolsinfo \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  449. return BadRequest();
  450. }
  451. }
  452. /// <summary>
  453. /// 使用yieId 关键字 本地效率未测出
  454. /// </summary>
  455. /// <param name="cosmosClient"></param>
  456. /// <param name="schoolAssists"></param>
  457. /// <returns></returns>
  458. private async IAsyncEnumerable<List<SchoolAssist>> GetSchools(CosmosClient cosmosClient,List<SchoolAssist> schoolAssists)
  459. {
  460. List<SchoolAssist> tempSchoolAssists = new();
  461. foreach (var temp in schoolAssists)
  462. {
  463. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(temp.id, new PartitionKey("ProductSum"));
  464. if (response.Status == 200)
  465. {
  466. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  467. temp.serial = json.RootElement.GetProperty("serial").GetArrayLength();
  468. temp.service = json.RootElement.GetProperty("service").GetArrayLength();
  469. temp.hard = json.RootElement.GetProperty("hard").GetArrayLength();
  470. }
  471. temp.assists = await CommonFind.FindSchoolRoles(cosmosClient, temp.id, "assist");
  472. tempSchoolAssists.Add(temp);
  473. }
  474. yield return tempSchoolAssists;
  475. }
  476. /// <summary>
  477. /// 取得学校所有顾问列表
  478. /// </summary>
  479. /// <returns></returns>
  480. [ProducesDefaultResponseType]
  481. [HttpPost("get-schoolassist")]
  482. public async Task<IActionResult> GetSchoolAssist(JsonElement jsonElement)
  483. {
  484. try
  485. {
  486. string schoolId = (jsonElement.TryGetProperty("schoolId", out JsonElement _schoolId)) ? _schoolId.GetString() : string.Empty;
  487. Dictionary<string, List<Dictionary<string, string>>> haveSchoolManger = new Dictionary<string, List<Dictionary<string, string>>>();
  488. string managerWhereOption = (!string.IsNullOrWhiteSpace(schoolId)) ? $" AND c.code = 'Teacher-{schoolId}'" : string.Empty;
  489. //查询学校的顾问
  490. 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}";
  491. var cosmosClent = _azureCosmos.GetCosmosClient();
  492. await foreach (var item in cosmosClent.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: managerSql, requestOptions: new QueryRequestOptions() { }))
  493. {
  494. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  495. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  496. {
  497. string id = obj.GetProperty("id").GetString(); //管理员ID
  498. string name = obj.GetProperty("name").GetString(); //管理员姓名
  499. string tempSchoolId = obj.GetProperty("schoolId").GetString(); //学校ID
  500. Dictionary<string, string> managerDic = new Dictionary<string, string>();
  501. managerDic.Add("id", id);
  502. managerDic.Add("name", name);
  503. if (haveSchoolManger.ContainsKey(tempSchoolId))
  504. {
  505. haveSchoolManger[tempSchoolId].Add(managerDic);
  506. }
  507. else
  508. {
  509. List<Dictionary<string, string>> managerList = new List<Dictionary<string, string>>();
  510. managerList.Add(managerDic);
  511. haveSchoolManger.Add(tempSchoolId, managerList);
  512. }
  513. }
  514. }
  515. //管理模组学校
  516. List<string> baseModuleSchoos = new List<string>();
  517. string baseWhereOption = (!string.IsNullOrEmpty(schoolId)) ? $" and c.id='{schoolId}'" : string.Empty;
  518. await foreach (var item in cosmosClent.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") }))
  519. {
  520. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  521. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  522. {
  523. string tempSchoolId = obj.GetProperty("id").GetString(); //学校ID
  524. baseModuleSchoos.Add(tempSchoolId);
  525. }
  526. }
  527. //学校信息
  528. List<object> schools = new List<object>();
  529. string schoolWhereOption = (!string.IsNullOrEmpty(schoolId)) ? $" where c.id='{schoolId}'" : string.Empty;
  530. await foreach (var item in cosmosClent.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") }))
  531. {
  532. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  533. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  534. {
  535. dynamic schoolExpando = new ExpandoObject();
  536. schoolExpando.id = obj.GetProperty("id").GetString();
  537. schoolExpando.name = obj.GetProperty("name").GetString();
  538. //schoolExpando.period = obj.GetProperty("period");
  539. schoolExpando.schoolCode = obj.GetProperty("schoolCode").GetString();
  540. schoolExpando.region = obj.GetProperty("region").GetString();
  541. schoolExpando.province = obj.GetProperty("province").GetString();
  542. schoolExpando.city = obj.GetProperty("city").GetString();
  543. schoolExpando.picture = obj.GetProperty("picture").GetString();
  544. if (haveSchoolManger.ContainsKey(schoolExpando.id))
  545. {
  546. schoolExpando.hasMarger = true;
  547. schoolExpando.managers = haveSchoolManger[schoolExpando.id];
  548. }
  549. else
  550. {
  551. schoolExpando.hasMarger = false;
  552. schoolExpando.managers = new List<object>();
  553. }
  554. schoolExpando.hasBaseModule = (baseModuleSchoos.Contains(schoolExpando.id)) ? true : false;
  555. schools.Add(schoolExpando);
  556. }
  557. }
  558. return Ok(new { state = 200, schools });
  559. }
  560. catch (Exception ex)
  561. {
  562. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-schools \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  563. return BadRequest();
  564. }
  565. }
  566. /// <summary>
  567. /// 修改学校信息和顾问信息
  568. /// </summary>
  569. /// <param name="jsonElement"></param>
  570. /// <returns></returns>
  571. [ProducesDefaultResponseType]
  572. [AuthToken(Roles = "assist")]
  573. [HttpPost("upd-schoolassist")]
  574. public async Task<IActionResult> UpdSchoolAssist(JsonElement jsonElement)
  575. {
  576. try
  577. {
  578. if (!jsonElement.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
  579. if (!jsonElement.TryGetProperty("name", out JsonElement schoolName)) return BadRequest();
  580. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  581. if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
  582. //if (!jsonElement.TryGetProperty("period", out JsonElement period)) return BadRequest();
  583. if (!jsonElement.TryGetProperty("picture", out JsonElement picture)) return BadRequest();
  584. if (!jsonElement.TryGetProperty("size", out JsonElement size)) return BadRequest();
  585. if (!jsonElement.TryGetProperty("scale", out JsonElement scale)) return BadRequest();
  586. if (!jsonElement.TryGetProperty("assistId", out JsonElement _assistId)) return BadRequest();
  587. if (!jsonElement.TryGetProperty("type", out JsonElement _type)) return BadRequest();
  588. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  589. List<string> assistId = _assistId.ToObject<List<string>>();
  590. //List<string> periodS = period.ToObject<List<string>>();
  591. Dictionary<string, List<Dictionary<string, string>>> haveSchoolManger = new Dictionary<string, List<Dictionary<string, string>>>();
  592. var cosmosClient = _azureCosmos.GetCosmosClient();
  593. School tempShool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
  594. if (tempShool != null)
  595. {
  596. List<Period> periods = new List<Period>();
  597. string campusId = Guid.NewGuid().ToString();
  598. //periodS.ForEach(x =>
  599. //{
  600. // periods.Add(new Period { id = Guid.NewGuid().ToString(), name = x.ToString(), campusId = campusId });
  601. //});
  602. //tempShool.period = periods;
  603. tempShool.size = !string.IsNullOrEmpty($"{size}") ? int.Parse($"{size}") : tempShool.size;
  604. tempShool.scale = !string.IsNullOrEmpty($"{scale}") ? int.Parse($"{scale}") : tempShool.scale;
  605. tempShool.picture = $"{picture}";
  606. tempShool.type = int.Parse($"{_type}");
  607. tempShool.name = $"{schoolName}";
  608. tempShool.areaId = $"{areaId}";
  609. tempShool.standard = $"{standard}";
  610. //修改学校
  611. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempShool, tempShool.id, new PartitionKey("Base"));
  612. //修改学校教师关联的信息
  613. string sql = $"SELECT distinct value(c) FROM c join A1 in c.schools where A1.schoolId='{tempShool.id}'";
  614. List<Teacher> teachers = new List<Teacher>();
  615. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  616. {
  617. teachers.Add(item);
  618. }
  619. foreach (var item in teachers)
  620. {
  621. Teacher.TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(tempShool.id));
  622. if (teacherSchool != null)
  623. {
  624. teacherSchool.name = tempShool.name;
  625. teacherSchool.picture = tempShool.picture;
  626. teacherSchool.areaId = tempShool.areaId;
  627. }
  628. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
  629. }
  630. //修改学校顾问
  631. string sqlTxt = $"SELECT value(c) From c WHERE ARRAY_CONTAINS(c.roles,'assist',true)";
  632. List<SchoolTeacher> schoolTeachers = new List<SchoolTeacher>();
  633. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<SchoolTeacher>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{tempShool.id}") }))
  634. {
  635. if (!assistId.Contains(item.id))
  636. {
  637. if (item.roles.Contains("assist"))
  638. {
  639. item.roles.Remove("assist");
  640. if (item.roles.Count > 0)
  641. {
  642. await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(item, item.id, new PartitionKey(item.code));
  643. }
  644. else
  645. {
  646. await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemAsync<SchoolTeacher>(item.id, new PartitionKey(item.code));
  647. }
  648. }
  649. }
  650. }
  651. if (assistId.Count > 0)
  652. {
  653. foreach (var itemTeacher in assistId)
  654. {
  655. Teacher tempTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{itemTeacher}", new PartitionKey("Base"));
  656. if (tempTeacher != null)
  657. {
  658. var haveTeacher = tempTeacher.schools.Find(x => x.schoolId.Equals($"{_schoolId}"));
  659. if (haveTeacher != null)
  660. {
  661. //查询该教师是否存在该校
  662. SchoolTeacher schoolTeacher = null;
  663. try
  664. {
  665. schoolTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolTeacher>($"{itemTeacher}", new PartitionKey($"Teacher-{tempShool.id}"));
  666. }
  667. catch
  668. {
  669. }
  670. if (schoolTeacher != null)
  671. {
  672. if (!schoolTeacher.roles.Contains("assist"))
  673. {
  674. schoolTeacher.roles.Add("assist");
  675. //添加顾问权限
  676. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{tempShool.id}"));
  677. }
  678. }
  679. else
  680. {
  681. SchoolTeacher addSchoolTeacher = new SchoolTeacher
  682. {
  683. id = itemTeacher,
  684. code = $"Teacher-{tempShool.id}",
  685. pk = "Teacher",
  686. status = "join",
  687. roles = new List<string>() { "assist" },
  688. name = tempTeacher.name,
  689. job = $"{tempShool.name}-顾问",
  690. size = 0,
  691. createTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
  692. };
  693. //添加学校顾问
  694. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{tempShool.id}"));
  695. }
  696. }
  697. else
  698. {
  699. Teacher.TeacherSchool teacherSchool = new Teacher.TeacherSchool
  700. {
  701. schoolId = tempShool.id,
  702. name = tempShool.name,
  703. status = "join",
  704. time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
  705. picture = tempShool.picture,
  706. areaId = tempShool.areaId
  707. };
  708. tempTeacher.schools.Add(teacherSchool);
  709. //给醍摩豆顾问添加学校
  710. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(tempTeacher, tempTeacher.id, new PartitionKey($"Base"));
  711. //不存在则在原来的基础上添加顾问角色
  712. SchoolTeacher addSchoolTeacher = new SchoolTeacher
  713. {
  714. id = itemTeacher,
  715. code = $"Teacher-{tempShool.id}",
  716. pk = "Teacher",
  717. status = "join",
  718. roles = new List<string>() { "assist" },
  719. name = tempTeacher.name,
  720. job = $"{tempShool.name}-顾问",
  721. size = 0,
  722. createTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
  723. };
  724. //添加学校学校顾问
  725. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{tempShool.id}"));
  726. }
  727. }
  728. }
  729. }
  730. }
  731. //保存操作记录
  732. await _azureStorage.SaveBILog("TeacherRoles-update", $"{_tmdName}【{_tmdId}】修改学校功能,修改的学校:{_schoolId},{_type},{picture},{size},{string.Join("|", assistId.ToArray())}", _dingDing, httpContext: HttpContext);
  733. return Ok(new { state = 200 });
  734. }
  735. catch (Exception ex)
  736. {
  737. await _dingDing.SendBotMsg($"BI, {_option.Location} /batchschool/upd-schoolassist \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  738. return BadRequest();
  739. }
  740. }
  741. /// <summary>
  742. /// 查询区域的学校
  743. /// </summary>
  744. /// <param name="jsonElement"></param>
  745. /// <returns></returns>
  746. [ProducesDefaultResponseType]
  747. [HttpPost("get-schooldist")]
  748. public async Task<IActionResult> GetSchoolDist(JsonElement jsonElement)
  749. {
  750. try
  751. {
  752. if (!jsonElement.TryGetProperty("dist", out JsonElement _dist)) return BadRequest();
  753. var cosmosClient = _azureCosmos.GetCosmosClient();
  754. string sqltxt = $"SELECT * FROM c where c.dist='{_dist}'";
  755. List<School> schools = new List<School>();
  756. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  757. {
  758. schools.Add(item);
  759. }
  760. return Ok(new { state = 200, schools });
  761. }
  762. catch (Exception ex)
  763. {
  764. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-schooldist \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  765. return BadRequest();
  766. }
  767. }
  768. /// <summary>
  769. /// 分页学校和顾问信息
  770. /// </summary>
  771. /// <param name="jsonElement"></param>
  772. /// <returns></returns>
  773. [HttpPost("get-schools")]
  774. public async Task<IActionResult> GetSchools(JsonElement jsonElement)
  775. {
  776. //List<School> schools = new List<School>();
  777. List<SchoolAssist> schoolAssists = new List<SchoolAssist>();
  778. var cosmosClient = _azureCosmos.GetCosmosClient();
  779. if (!jsonElement.TryGetProperty("endPosition", out JsonElement endPosition)) return BadRequest();
  780. if (!jsonElement.TryGetProperty("pageSize", out JsonElement pageSize)) return BadRequest();
  781. string sqltxt = $"SELECT * FROM c order by c.id offset {endPosition} limit {pageSize}";
  782. await foreach (var itemSchool in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  783. {
  784. SchoolAssist schoolAssist = new SchoolAssist()
  785. {
  786. id = itemSchool.id,
  787. code = itemSchool.code,
  788. schoolCode = itemSchool.schoolCode,
  789. name = itemSchool.name,
  790. region = itemSchool.region,
  791. province = itemSchool.province,
  792. city = itemSchool.city,
  793. dist = itemSchool.dist,
  794. size = itemSchool.size,
  795. address = itemSchool.address,
  796. picture = itemSchool.picture,
  797. type = itemSchool.type,
  798. scale = itemSchool.scale,
  799. areaId = itemSchool.areaId,
  800. standard = itemSchool.standard
  801. };
  802. schoolAssist.assists = await CommonFind.FindSchoolRoles(cosmosClient, itemSchool.id, "assist");
  803. //List<Assist> assists = new List<Assist>();
  804. ////查询学校的顾问
  805. //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' AND c.code = 'Teacher-{itemSchool.id}'";
  806. //var cosmosClent = _azureCosmos.GetCosmosClient();
  807. //await foreach (var item in cosmosClent.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: managerSql, requestOptions: new QueryRequestOptions() { }))
  808. //{
  809. // using var json = await JsonDocument.ParseAsync(item.ContentStream);
  810. // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  811. // {
  812. // Assist assist = new Assist
  813. // {
  814. // tmdId = obj.GetProperty("id").GetString(),
  815. // tmdName = obj.GetProperty("name").GetString()
  816. // };
  817. // assists.Add(assist);
  818. // }
  819. //}
  820. //schoolAssist.assists = assists;
  821. schoolAssists.Add(schoolAssist);
  822. }
  823. return Ok(new { state = 200, schoolAssists });
  824. }
  825. #region 预设学校基础信息 多语言
  826. /// <summary>
  827. /// 预设学校基础信息 多语言
  828. /// </summary>
  829. /// <param name="period"></param>
  830. /// <param name="Language"></param>
  831. /// <param name="campusId"></param>
  832. /// <returns></returns>
  833. public List<Period> PresetSchoolPeriod(List<string> period, string Language, string campusId)
  834. {
  835. var builder = $"{_environment.ContentRootPath}/JsonFile/Preset/LangSchoolConfig.json";
  836. StreamReader streamReader = new StreamReader(new FileStream(builder, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
  837. StringBuilder stringBuilder = new StringBuilder();
  838. string text;
  839. while ((text = streamReader.ReadLine()) != null)
  840. {
  841. stringBuilder.Append(text.ToString());
  842. }
  843. streamReader.Close();
  844. string input = stringBuilder.ToString();
  845. List<SchoolConfig> schoolConfigs = input.ToObject<List<SchoolConfig>>();
  846. SchoolConfig schoolConfig = schoolConfigs.Find(x => x.Lang.Contains($"{Language}"));
  847. if (schoolConfig == null)
  848. {
  849. if (Language.Contains("en"))
  850. schoolConfig = schoolConfigs.Find(x => x.Lang.Contains("en-US"));
  851. else
  852. schoolConfig = schoolConfigs.Find(x => x.Lang.Contains("zh-CN"));
  853. }
  854. List<Period> periods = new List<Period>();
  855. period.ForEach(x =>
  856. {
  857. periods.Add(new Period
  858. {
  859. id = Guid.NewGuid().ToString(),
  860. name = x,
  861. campusId = campusId,
  862. 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() },
  863. 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() } },
  864. subjects = new List<Subject>() {
  865. new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
  866. new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
  867. new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
  868. },
  869. grades = schoolConfig.grades,
  870. analysis = new Analysis()
  871. {
  872. type = new List<ExamSimple>() { new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[0].name },
  873. new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[1].name },
  874. new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[2].name },
  875. new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[3].name } },
  876. income = schoolConfig.PresetExam[0].income,
  877. eugenics = schoolConfig.PresetExam[0].eugenics,
  878. touch = schoolConfig.PresetExam[0].touch
  879. }
  880. });
  881. });
  882. return periods;
  883. }
  884. public record SchoolConfig
  885. {
  886. public string Lang { get; set; }
  887. public List<semester> semester { get; set; }
  888. public List<string> grades { get; set; }
  889. public List<PresetSubject> PresetSubject { get; set; }
  890. public List<PresetExam> PresetExam { get; set; }
  891. }
  892. public record semester
  893. {
  894. public string id { get; set; } = Guid.NewGuid().ToString();
  895. public string term { get; set; }
  896. public int start { get; set; }
  897. public int month { get; set; }
  898. public int day { get; set; }
  899. }
  900. public record PresetSubject
  901. {
  902. public string id { get; set; } = Guid.NewGuid().ToString();
  903. public string name { get; set; }
  904. public int type { get; set; }
  905. }
  906. public record PresetExam
  907. {
  908. public List<StudyType> type { get; set; }
  909. public int income { get; set; }
  910. public int eugenics { get; set; }
  911. public int touch { get; set; }
  912. }
  913. public record StudyType
  914. {
  915. public string id { get; set; } = Guid.NewGuid().ToString();
  916. public string name { get; set; }
  917. }
  918. #endregion
  919. public class SchoolAssist
  920. {
  921. public string id { get; set; }
  922. public string code { get; set; }
  923. public string schoolCode { get; set; }
  924. public string name { get; set; }
  925. public string region { get; set; }
  926. public string province { get; set; }
  927. public string city { get; set; }
  928. public string dist { get; set; }
  929. public int size { get; set; }
  930. public string address { get; set; }
  931. public string picture { get; set; }
  932. public int type { get; set; }
  933. public int scale { get; set; }
  934. public string standard { get; set; }
  935. public string areaId { get; set; }
  936. public List<SchoolTeacherRoles> assists { get; set; }
  937. public int serial { get; set; } //软体
  938. public int service { get; set; } //服务
  939. public int hard { get; set; } //硬体
  940. //public List<SchoolProductSumData> serial { get; set; } //软体
  941. //public List<SchoolProductSumData> service { get; set; } //服务
  942. //public List<SchoolProductSumDataHard> hard { get; set; } //硬体
  943. }
  944. /// <summary>
  945. /// 创建多个学校实体
  946. /// </summary>
  947. public record FoundSchools()
  948. {
  949. /// <summary>
  950. /// 语系
  951. /// </summary>
  952. public string lang { get; set; }
  953. /// <summary>
  954. /// 批量创校的数据结构
  955. /// </summary>
  956. public List<BISchool> biSchools { get; set; } = new List<BISchool>();
  957. }
  958. /// <summary>
  959. /// 批量创校的数据结构
  960. /// </summary>
  961. public record BISchool()
  962. {
  963. /// <summary>
  964. /// 学校名称
  965. /// </summary>
  966. public string name { get; set; }
  967. /// <summary>
  968. /// 学校管理员
  969. /// </summary>
  970. public string admin { get; set; }
  971. /// <summary>
  972. /// 学校的学段
  973. /// </summary>
  974. public List<string> period { get; set; }
  975. /// <summary>
  976. /// 学校空间大小
  977. /// </summary>
  978. public int size { get; set; }
  979. /// <summary>
  980. /// 地区
  981. /// </summary>
  982. public string region { get; set; }
  983. /// <summary>
  984. /// 省份
  985. /// </summary>
  986. public string province { get; set; }
  987. /// <summary>
  988. /// 城市
  989. /// </summary>
  990. public string city { get; set; }
  991. /// <summary>
  992. /// 县,区,郡
  993. /// </summary>
  994. public string dist { get; set; }
  995. /// <summary>
  996. /// 学校详细地址
  997. /// </summary>
  998. public string address { get; set; }
  999. /// <summary>
  1000. /// 学校类型
  1001. /// </summary>
  1002. public int type { get; set; }
  1003. /// <summary>
  1004. /// 区域ID
  1005. /// </summary>
  1006. public string areaId { get; set; }
  1007. }
  1008. public record Exist()
  1009. {
  1010. public string ID { get; set; }
  1011. public string name { get; set; }
  1012. }
  1013. }
  1014. }