数据提交
This commit is contained in:
parent
aa1dce0c6c
commit
a085c284ff
@ -114,40 +114,52 @@ namespace YD_WeChatApplet.Api.Services.Impl
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var list = new List<SportsDataPushDto>
|
if (homeWorkEntities == null || homeWorkEntities.Count == 0)
|
||||||
{
|
{
|
||||||
new SportsDataPushDto
|
_logger.LogWarning("作业同步任务中,homeWorkEntities 为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pushList = new List<SportsDataPushDto>();
|
||||||
|
|
||||||
|
foreach (var homeWork in homeWorkEntities)
|
||||||
|
{
|
||||||
|
var dto = new SportsDataPushDto
|
||||||
{
|
{
|
||||||
StudentNo = UserLoginContext.Current.UserNo,
|
StudentNo = UserLoginContext.Current.UserNo,
|
||||||
SportsItem = AppSettings.JingShiTiJiao.SportsItem,
|
SportsItem = AppSettings.JingShiTiJiao.SportsItem,
|
||||||
SportsDate = DateTime.Parse(paramDto.StartTime).ToString("yyyy-MM-dd"),
|
SportsDate = homeWork.StartTime.ToString("yyyy-MM-dd"),
|
||||||
SportsService = AppSettings.JingShiTiJiao.Channel,
|
SportsService = AppSettings.JingShiTiJiao.Channel,
|
||||||
SportsScene = "addhomework",
|
SportsScene = "addhomework",
|
||||||
SportsDetail = JsonConvert.SerializeObject(homeWorkEntities, new JsonSerializerSettings
|
SportsDetail = JsonConvert.SerializeObject(
|
||||||
{
|
homeWork,
|
||||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
new JsonSerializerSettings
|
||||||
})
|
{
|
||||||
}
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||||
};
|
}
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
var res = await _jingShiTiJiaoService.PushSportsData(list);
|
pushList.Add(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
var res = await _jingShiTiJiaoService.PushSportsData(pushList);
|
||||||
|
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
_logger.LogInformation($"数据同步成功,{JsonConvert.SerializeObject(list)}");
|
_logger.LogInformation($"作业数据同步成功,共 {pushList.Count} 条");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogError($"数据同步失败,{JsonConvert.SerializeObject(list)}");
|
_logger.LogError($"作业数据同步失败,共 {pushList.Count} 条");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// ❗ 只记录日志,绝不抛出
|
// ❗ 只记录日志,绝不影响主流程
|
||||||
_logger.LogError(ex, "作业数据上传失败");
|
_logger.LogError(ex, "作业数据上传失败");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -52,12 +52,50 @@ namespace YD_WeChatApplet.Api.Services.Impl
|
|||||||
entity.UserId = UserLoginContext.Current.UserId;
|
entity.UserId = UserLoginContext.Current.UserId;
|
||||||
entity.UserName = UserLoginContext.Current.UserName;
|
entity.UserName = UserLoginContext.Current.UserName;
|
||||||
entity.CreateTime = DateTime.Now;
|
entity.CreateTime = DateTime.Now;
|
||||||
|
entity.StudentNo = UserLoginContext.Current.UserNo;
|
||||||
|
|
||||||
if (dto.HomeWorkId == 0)
|
if (dto.HomeWorkId == 0)
|
||||||
{
|
{
|
||||||
await _userContext.AddAsync(entity);
|
await _userContext.AddAsync(entity);
|
||||||
await _userContext.SaveChangesAsync();
|
await _userContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = new List<SportsDataPushDto>
|
||||||
|
{
|
||||||
|
new SportsDataPushDto
|
||||||
|
{
|
||||||
|
StudentNo = entity.StudentNo,
|
||||||
|
SportsItem = AppSettings.JingShiTiJiao.SportsItem,
|
||||||
|
SportsDate = entity.CreateTime.ToString("yyyy-MM-dd"),
|
||||||
|
SportsService = AppSettings.JingShiTiJiao.Channel,
|
||||||
|
SportsScene = "freetraining",
|
||||||
|
SportsDetail = JsonConvert.SerializeObject(entity)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var res = await _jingShiTiJiaoService.PushSportsData(list);
|
||||||
|
|
||||||
|
if (res)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"数据同步成功,{JsonConvert.SerializeObject(list)}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogError($"数据同步失败,{JsonConvert.SerializeObject(list)}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// ❗ 只记录日志,绝不抛出
|
||||||
|
_logger.LogError(ex,
|
||||||
|
"运动数据上传失败,StudentNo={StudentNo}, Id={Id}",
|
||||||
|
entity.StudentNo,
|
||||||
|
entity.Id);
|
||||||
|
}
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user