|
@@ -34,16 +34,63 @@ namespace IES.ExamServer.Controllers
|
|
_connectionService=connectionService;
|
|
_connectionService=connectionService;
|
|
_liteDBFactory=liteDBFactory;
|
|
_liteDBFactory=liteDBFactory;
|
|
}
|
|
}
|
|
|
|
+ [HttpPost("list-schools")]
|
|
|
|
+ public async Task<IActionResult> ListSchool(JsonNode json)
|
|
|
|
+ {
|
|
|
|
+ string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "package", "schools.json");
|
|
|
|
+ string schoolText = await System.IO.File.ReadAllTextAsync(filePath);
|
|
|
|
+ JsonNode? node = schoolText.ToObject<JsonNode>();
|
|
|
|
+ return Ok(new {code =200, schools= node?["schools"] });
|
|
|
|
+ }
|
|
[HttpPost("bind-school")]
|
|
[HttpPost("bind-school")]
|
|
public async Task<IActionResult> BindSchool(JsonNode json)
|
|
public async Task<IActionResult> BindSchool(JsonNode json)
|
|
{
|
|
{
|
|
string id=$"{json["id"]}";
|
|
string id=$"{json["id"]}";
|
|
string name= $"{json["name"]}";
|
|
string name= $"{json["name"]}";
|
|
- string picture = $"{json["picture"]}";
|
|
|
|
- string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "package", "schools.json");
|
|
|
|
- string schools = await System.IO.File.ReadAllTextAsync(filePath);
|
|
|
|
-
|
|
|
|
- return Ok();
|
|
|
|
|
|
+ string fp = $"{json["fp"]}";
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(id) && !string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(fp))
|
|
|
|
+ {
|
|
|
|
+ string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "package", "schools.json");
|
|
|
|
+ string schoolText = await System.IO.File.ReadAllTextAsync(filePath);
|
|
|
|
+ List<School>? schools = schoolText.ToObject<JsonNode>()?["schools"]?.ToObject<List<School>>();
|
|
|
|
+ School? school = schools?.Find(x => id.Equals(x.id) && name.Equals(x.name));
|
|
|
|
+ if (school!=null)
|
|
|
|
+ {
|
|
|
|
+ _liteDBFactory.GetLiteDatabase().GetCollection<School>().DeleteAll();
|
|
|
|
+ _liteDBFactory.GetLiteDatabase().GetCollection<School>().Upsert(school);
|
|
|
|
+ IEnumerable<School> schoolsDb = _liteDBFactory.GetLiteDatabase().GetCollection<School>().FindAll();
|
|
|
|
+ School? schoolDb = schools?.FirstOrDefault();
|
|
|
|
+ _memoryCache.TryGetValue(Constant._KeyServerDevice, out ServerDevice? server);
|
|
|
|
+ if (server!=null)
|
|
|
|
+ {
|
|
|
|
+ server.school = school;
|
|
|
|
+ }
|
|
|
|
+ string ip = GetIP();
|
|
|
|
+ var device = IndexService.GetDeviceInit(HttpContext, $"{fp}", ip, _memoryCache);
|
|
|
|
+ int hybrid = 0;
|
|
|
|
+ _memoryCache.Set(Constant._KeyServerDevice, server);
|
|
|
|
+ _memoryCache.TryGetValue(Constant._KeyServerCenter, out JsonNode? data);
|
|
|
|
+ _memoryCache.TryGetValue(Constant._KeyServerDevice, out server);
|
|
|
|
+ if (data!=null)
|
|
|
|
+ {
|
|
|
|
+ hybrid=1;
|
|
|
|
+ msg="云端服务连接成功!";
|
|
|
|
+ return Ok(new { code = 200, msg, data = new { hybrid, device, centerUrl = data["centerUrl"], region = data["region"], ip = data["ip"], nowtime = DateTimeOffset.Now.ToUnixTimeMilliseconds(), server } });
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ msg="云端服务未连接!";
|
|
|
|
+ return Ok(new { code = 200, msg, data = new { hybrid, device, centerUrl = "", region = "局域网·内网", ip = ip, nowtime = DateTimeOffset.Now.ToUnixTimeMilliseconds(), server } });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ return Ok(new { code = 400, msg = "绑定失败!" });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return Ok(new { code = 400, msg = "参数错误!" });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
[HttpPost("device")]
|
|
[HttpPost("device")]
|
|
public IActionResult Device(JsonElement json )
|
|
public IActionResult Device(JsonElement json )
|