|
@@ -20,6 +20,9 @@ using static TEAMModelOS.Controllers.AbilitySubController;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using TEAMModelOS.SDK.Models.Service;
|
|
|
using ScTeacher = TEAMModelOS.SDK.Models.ScTeacher;
|
|
|
+using static TEAMModelOS.SDK.StatisticsService;
|
|
|
+using Azure.Messaging.ServiceBus;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
|
{
|
|
@@ -36,14 +39,19 @@ namespace TEAMModelOS.Controllers
|
|
|
private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
private readonly HttpTrigger _httpTrigger;
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
- public AbilityStatisticsController(AzureStorageFactory azureStorage,HttpTrigger httpTrigger,CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option)
|
|
|
+ public IConfiguration _configuration { get; set; }
|
|
|
+ private readonly AzureServiceBusFactory _serviceBus;
|
|
|
+ public AbilityStatisticsController(AzureStorageFactory azureStorage, HttpTrigger httpTrigger, CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option,
|
|
|
+ AzureServiceBusFactory serviceBus, IConfiguration configuration)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_dingDing = dingDing;
|
|
|
_option = option?.Value;
|
|
|
- _coreAPIHttpService=coreAPIHttpService;
|
|
|
+ _coreAPIHttpService = coreAPIHttpService;
|
|
|
_httpTrigger = httpTrigger;
|
|
|
- _azureStorage = azureStorage;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
+ _serviceBus = serviceBus;
|
|
|
+ _configuration = configuration;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 更新教师最终学习分数。
|
|
@@ -122,9 +130,9 @@ namespace TEAMModelOS.Controllers
|
|
|
try
|
|
|
{
|
|
|
TeacherTrain teacherTrain = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<TeacherTrain>(userid, new PartitionKey($"TeacherTrain-{school}"));
|
|
|
- teacherTrain.nickname= name;
|
|
|
+ teacherTrain.nickname = name;
|
|
|
teacherTrain.name = name;
|
|
|
-
|
|
|
+
|
|
|
var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
|
|
|
List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "schoolCode", school }, { "tmdid", $"{teacherTrain.id}" } });
|
|
|
if (teachers.Any())
|
|
@@ -148,7 +156,8 @@ namespace TEAMModelOS.Controllers
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
- [HttpPost("statistics-area-simple")]
|
|
|
+ //[HttpPost("statistics-area-simple")]
|
|
|
+ [HttpPost("statistics-area-quick")]
|
|
|
[AuthToken(Roles = "teacher,admin,area")]
|
|
|
[Authorize(Roles = "IES")]
|
|
|
public async Task<IActionResult> StatisticsAreaSimple(JsonElement request)
|
|
@@ -208,7 +217,7 @@ namespace TEAMModelOS.Controllers
|
|
|
List<SchoolInfos> schoolInfos = new List<SchoolInfos>();
|
|
|
foreach (var school in schools)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
schoolInfos.Add(new SchoolInfos { schoolId = school.id, schoolName = school.name, picture = school.picture });
|
|
|
//增加评审人员总人数,学习总人数。
|
|
|
trains.Add(StatisticsService.StatisticsSchool(_coreAPIHttpService, school.id, setting, area, client, _dingDing, null));
|
|
@@ -288,7 +297,7 @@ namespace TEAMModelOS.Controllers
|
|
|
t.zpscore, t.xzscore, t.hpscore
|
|
|
}),
|
|
|
},
|
|
|
- offlineCountNo = x.offlineRecords.Where(o => o.haswork==1 && string.IsNullOrWhiteSpace(o.url)).Count(),
|
|
|
+ offlineCountNo = x.offlineRecords.Where(o => o.haswork == 1 && string.IsNullOrWhiteSpace(o.url)).Count(),
|
|
|
offlineCountOk = x.offlineRecords.Where(o => o.haswork == 1 && !string.IsNullOrWhiteSpace(o.url)).Count(),
|
|
|
teacherClasseCount = x.teacherClasses.Count
|
|
|
};
|
|
@@ -298,7 +307,7 @@ namespace TEAMModelOS.Controllers
|
|
|
//var ScTeachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", $"{setting.id}" } });
|
|
|
//var ttt = ScTeachers.Select(x => x.tmdid).Except(teacherTrains.Select(x => x.id));
|
|
|
|
|
|
- return Ok(new { teacherTrains= dynamics, setting, schools = schoolInfos, totalTime, hgcount, teacherCount = countArea, appraiseCount = appraiseArea });
|
|
|
+ return Ok(new { teacherTrains = dynamics, setting, schools = schoolInfos, totalTime, hgcount, teacherCount = countArea, appraiseCount = appraiseArea });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -309,13 +318,16 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 区级数据统计
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
- [HttpPost("statistics-area-quick")]
|
|
|
+ //[HttpPost("statistics-area-quick")]
|
|
|
+ [HttpPost("statistics-area-simple")]
|
|
|
[AuthToken(Roles = "teacher,admin,area")]
|
|
|
[Authorize(Roles = "IES")]
|
|
|
public async Task<IActionResult> StatisticsAreaQuick(JsonElement request) {
|
|
@@ -368,50 +380,37 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
schools.Add(item);
|
|
|
}
|
|
|
- List<Task<(List<TeacherTrain> trains, List<RGroupList> yxtrain)>> trains = new List<Task<(List<TeacherTrain> trains, List<RGroupList> yxtrain)>>();
|
|
|
+
|
|
|
int countArea = 0;
|
|
|
int appraiseArea = 0;
|
|
|
List<SchoolInfos> schoolInfos = new List<SchoolInfos>();
|
|
|
+ TeacherTrainChangeMsg msg = new TeacherTrainChangeMsg() { areaId=area.id};
|
|
|
foreach (var school in schools)
|
|
|
{
|
|
|
-
|
|
|
schoolInfos.Add(new SchoolInfos { schoolId = school.id, schoolName = school.name, picture = school.picture });
|
|
|
- //增加评审人员总人数,学习总人数。
|
|
|
- trains.Add(StatisticsService.StatisticsSchoolQuik(_coreAPIHttpService, school.id, setting, area, client, _dingDing, null));
|
|
|
- }
|
|
|
- int pagesize = 100;
|
|
|
- if (trains.Count <= pagesize)
|
|
|
- {
|
|
|
- (List<TeacherTrain> trains, List<RGroupList> yxtrain)[] tasks = await Task.WhenAll(trains);
|
|
|
- tasks.ToList().ForEach(x => {
|
|
|
- teacherTrains.AddRange(x.trains);
|
|
|
- schoolInfos.ForEach(y => {
|
|
|
- var list = x.yxtrain.Find(z => z.school.Equals(y.schoolId));
|
|
|
- if (list != null)
|
|
|
- {
|
|
|
- y.trainCount = list.members.Count;
|
|
|
- }
|
|
|
- });
|
|
|
+ (List<TeacherTrain> trains, List<RGroupList> yxtrain, List < TeacherTrain > updateTeacherTrains)= await StatisticsService.StatisticsSchoolQuik(_coreAPIHttpService, school.id, setting, area, client, _dingDing, null);
|
|
|
+ teacherTrains.AddRange( trains);
|
|
|
+ schoolInfos.ForEach(y => {
|
|
|
+ var list =yxtrain.Find(z => z.school.Equals(y.schoolId));
|
|
|
+ if (list != null)
|
|
|
+ {
|
|
|
+ y.trainCount = list.members.Count;
|
|
|
+ }
|
|
|
});
|
|
|
+ if (updateTeacherTrains.IsNotEmpty()) {
|
|
|
+ msg.schools.Add( new TeacherTrainChangeMsgSchoolTeachers { school = school.id, teachers = updateTeacherTrains.Select(z => z.id).ToList() });
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ bool isnew=false;
|
|
|
+ if (msg.schools.IsNotEmpty())
|
|
|
{
|
|
|
- int pages = (trains.Count + pagesize) / pagesize; //256是批量操作最大值,pages = (total + max -1) / max;
|
|
|
- for (int i = 0; i < pages; i++)
|
|
|
- {
|
|
|
- var listssb = trains.Skip((i) * pagesize).Take(pagesize).ToList();
|
|
|
- (List<TeacherTrain> trains, List<RGroupList> yxtrain)[] tasks = await Task.WhenAll(listssb);
|
|
|
- tasks.ToList().ForEach(x => {
|
|
|
- teacherTrains.AddRange(x.trains);
|
|
|
- schoolInfos.ForEach(y => {
|
|
|
- var list = x.yxtrain.Find(z => z.school.Equals(y.schoolId));
|
|
|
- if (list != null)
|
|
|
- {
|
|
|
- y.trainCount = list.members.Count;
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
+ var messageChange = new ServiceBusMessage(msg.ToJsonString());
|
|
|
+ messageChange.ApplicationProperties.Add("name", "TeacherTrainChange");
|
|
|
+ var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ isnew=true;
|
|
|
}
|
|
|
long totalTime = teacherTrains.Select(x => x.totalTime).Sum();
|
|
|
int hgcount = teacherTrains.Where(x => x.finalScore == 1 || x.finalScore == 2).Count();
|
|
@@ -461,7 +460,22 @@ namespace TEAMModelOS.Controllers
|
|
|
};
|
|
|
dynamics.Add(dynamic);
|
|
|
});
|
|
|
- return Ok(new { teacherTrains = dynamics, setting, schools = schoolInfos, totalTime, hgcount, teacherCount = countArea, appraiseCount = appraiseArea });
|
|
|
+ long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ if (area.updateTime == 0 && isnew ) {
|
|
|
+ area.updateTime = now ;
|
|
|
+ }
|
|
|
+ if (area.updateTime == 0 && !isnew)
|
|
|
+ {
|
|
|
+ area.updateTime = DateTimeOffset.UtcNow.Add(new TimeSpan(-1, 0, 0, 0)).ToUnixTimeMilliseconds();
|
|
|
+ }
|
|
|
+ //判断两个上次更新时间差
|
|
|
+ if (area.updateTime > 0 && !isnew) {
|
|
|
+ long timedis= 15 * 60 * 1000;//15分钟
|
|
|
+ if (now - area.updateTime<timedis) {
|
|
|
+ isnew= true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Ok(new { teacherTrains = dynamics, setting, schools = schoolInfos, totalTime, hgcount, teacherCount = countArea, appraiseCount = appraiseArea, isnew ,area.updateTime});
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|