补传
This commit is contained in:
parent
94971e02db
commit
1d5b9367a4
@ -24,7 +24,10 @@ namespace YD_AllHeartRates.Api.Controllers
|
|||||||
_dataPushService = dataPushService;
|
_dataPushService = dataPushService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取Token
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpGet(nameof(GetToken))]
|
[HttpGet(nameof(GetToken))]
|
||||||
public async Task<string> GetToken()
|
public async Task<string> GetToken()
|
||||||
{
|
{
|
||||||
@ -32,6 +35,10 @@ namespace YD_AllHeartRates.Api.Controllers
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取学生EduId
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpPost(nameof(GetStudentEduId))]
|
[HttpPost(nameof(GetStudentEduId))]
|
||||||
public async Task<List<StudentEduDto>> GetStudentEduId()
|
public async Task<List<StudentEduDto>> GetStudentEduId()
|
||||||
{
|
{
|
||||||
@ -39,6 +46,10 @@ namespace YD_AllHeartRates.Api.Controllers
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 常规数据上报
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpPost(nameof(SportsRoutineReport))]
|
[HttpPost(nameof(SportsRoutineReport))]
|
||||||
public async Task<SportsRoutineReportResponse> SportsRoutineReport()
|
public async Task<SportsRoutineReportResponse> SportsRoutineReport()
|
||||||
{
|
{
|
||||||
@ -67,5 +78,70 @@ namespace YD_AllHeartRates.Api.Controllers
|
|||||||
var res = await _dataPushService.SportsRoutineReport(data);
|
var res = await _dataPushService.SportsRoutineReport(data);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异常数据上报
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost(nameof(SportsAbnormalReport))]
|
||||||
|
public async Task<SportsRoutineReportResponse> SportsAbnormalReport()
|
||||||
|
{
|
||||||
|
var data = new List<SportsAbnormalReportDto>
|
||||||
|
{
|
||||||
|
new SportsAbnormalReportDto
|
||||||
|
{
|
||||||
|
SBID = "1234567",
|
||||||
|
XSEDUID = "d1cd4ff5-6511-58b8-809f-22d102b3c20d",
|
||||||
|
HDSJ = new List<AbnormalHeartRateRecordDto>
|
||||||
|
{
|
||||||
|
new AbnormalHeartRateRecordDto { SJSJ = "2025-10-30 18:50:00", XL = 90, JXXL = 80, YCXX="心率过高", YCYY="持续剧烈运动" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new SportsAbnormalReportDto
|
||||||
|
{
|
||||||
|
SBID = "5678934",
|
||||||
|
XSEDUID = "d1cd4ff5-6511-58b8-809f-22d102b3c20e",
|
||||||
|
HDSJ = new List<AbnormalHeartRateRecordDto>
|
||||||
|
{
|
||||||
|
new AbnormalHeartRateRecordDto { SJSJ = "2025-10-30 18:50:00", XL = 88, JXXL = 78, YCXX="心率过高", YCYY="持续剧烈运动" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var res = await _dataPushService.SportsAbnormalReport(data);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 补传数据上报
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost(nameof(SportsDataReplay))]
|
||||||
|
public async Task<SportsRoutineReportResponse> SportsDataReplay()
|
||||||
|
{
|
||||||
|
var data = new List<StudentData>
|
||||||
|
{
|
||||||
|
new StudentData
|
||||||
|
{
|
||||||
|
SBID = "1234567",
|
||||||
|
XSEDUID = "d1cd4ff5-6511-58b8-809f-22d102b3c20d",
|
||||||
|
HDSJ = new List<HeartRateRecordDto>
|
||||||
|
{
|
||||||
|
new HeartRateRecordDto { SJSJ = "2025-10-29 14:50:00", XL = 90, JXXL = 80 },
|
||||||
|
new HeartRateRecordDto { SJSJ = "2025-10-29 14:51:00", XL = 92, JXXL = 80 }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new StudentData
|
||||||
|
{
|
||||||
|
SBID = "5678934",
|
||||||
|
XSEDUID = "d1cd4ff5-6511-58b8-809f-22d102b3c20e",
|
||||||
|
HDSJ = new List<HeartRateRecordDto>
|
||||||
|
{
|
||||||
|
new HeartRateRecordDto { SJSJ = "2025-10-29 14:50:00", XL = 88, JXXL = 78 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var res = await _dataPushService.SportsDataReplay(data);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -318,5 +318,251 @@ namespace YD_AllHeartRates.Api.Services.Impl
|
|||||||
}
|
}
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<SportsRoutineReportResponse> SportsAbnormalReport(List<SportsAbnormalReportDto> data)
|
||||||
|
{
|
||||||
|
SportsRoutineReportResponse resp = new SportsRoutineReportResponse();
|
||||||
|
if (data == null || data.Count == 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("data参数为空!");
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
var token = await GetToken();
|
||||||
|
if (string.IsNullOrWhiteSpace(token))
|
||||||
|
{
|
||||||
|
Console.WriteLine("获取token失败!");
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] Timestamp: {timestamp}");
|
||||||
|
|
||||||
|
var headers = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "token", token }
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1. 构造请求参数字典(有序保证 JSON 序列化顺序)
|
||||||
|
var package = new AbnormalHeartPackage
|
||||||
|
{
|
||||||
|
TOKEN = token,
|
||||||
|
APPID = AppSettings.DataPush.Appid,
|
||||||
|
SCSJ = timestamp,
|
||||||
|
SJCOUNT = data?.Count ?? 0,
|
||||||
|
CLIENT_ID = AppSettings.DataPush.ClientId,
|
||||||
|
DATA = data
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1. 序列化 package 对象为 JSON
|
||||||
|
string jsonPlain;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
jsonPlain = JsonConvert.SerializeObject(package, Formatting.None);
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] Package JSON: {jsonPlain}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] Package序列化失败: {ex}");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 压缩 + SM2 加密
|
||||||
|
string bodyEncrypted;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bodyEncrypted = DataEncryptHelper.EncryptSm2Zip(jsonPlain, AppSettings.DataPush.PublicKey);
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] Encrypted BODY (Hex): {bodyEncrypted}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] SM2加密失败: {ex}");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 构造 POST 请求 URL
|
||||||
|
string url = $"{AppSettings.DataPush.Hous}oauth2/sportsDataReplay";
|
||||||
|
|
||||||
|
// 5. 发送 POST 请求
|
||||||
|
string responseText;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
responseText = await HttpManager.HttpPostAsync(
|
||||||
|
url,
|
||||||
|
postData: bodyEncrypted,
|
||||||
|
contentType: "application/json",
|
||||||
|
headers: headers
|
||||||
|
);
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] Response: {responseText}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] HTTP请求失败: {ex}");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. 解析响应,返回对象数组
|
||||||
|
if (!string.IsNullOrWhiteSpace(responseText) && responseText.TrimStart().StartsWith("{"))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var json = JsonConvert.DeserializeObject<Dictionary<string, object>>(responseText);
|
||||||
|
|
||||||
|
if (json != null)
|
||||||
|
{
|
||||||
|
var codeStr = json.ContainsKey("code") ? json["code"]?.ToString() : null;
|
||||||
|
var msgStr = json.ContainsKey("msg") ? json["msg"]?.ToString() : null;
|
||||||
|
|
||||||
|
if (codeStr == "200")
|
||||||
|
{
|
||||||
|
// 成功返回固定响应
|
||||||
|
resp.code = 200;
|
||||||
|
resp.msg = "数据上报成功";
|
||||||
|
Console.WriteLine("[SportsRoutineReport] 数据上报成功");
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 接口返回错误
|
||||||
|
resp.code = 500;
|
||||||
|
resp.msg = $"接口返回错误: {msgStr}";
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] 接口返回错误: code={codeStr}, msg={msgStr}");
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
resp.code = 500;
|
||||||
|
resp.msg = "JSON解析异常";
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] JSON解析失败: {ex}");
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<SportsRoutineReportResponse> SportsDataReplay(List<StudentData> data)
|
||||||
|
{
|
||||||
|
SportsRoutineReportResponse resp = new SportsRoutineReportResponse();
|
||||||
|
if (data == null || data.Count == 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("data参数为空!");
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
var token = await GetToken();
|
||||||
|
if (string.IsNullOrWhiteSpace(token))
|
||||||
|
{
|
||||||
|
Console.WriteLine("获取token失败!");
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] Timestamp: {timestamp}");
|
||||||
|
|
||||||
|
var headers = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "token", token }
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1. 构造请求参数字典(有序保证 JSON 序列化顺序)
|
||||||
|
var package = new Package
|
||||||
|
{
|
||||||
|
TOKEN = token,
|
||||||
|
APPID = AppSettings.DataPush.Appid,
|
||||||
|
SCSJ = timestamp,
|
||||||
|
SJCOUNT = data?.Count ?? 0,
|
||||||
|
CLIENT_ID = AppSettings.DataPush.ClientId,
|
||||||
|
DATA = data
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1. 序列化 package 对象为 JSON
|
||||||
|
string jsonPlain;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
jsonPlain = JsonConvert.SerializeObject(package, Formatting.None);
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] Package JSON: {jsonPlain}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] Package序列化失败: {ex}");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 压缩 + SM2 加密
|
||||||
|
string bodyEncrypted;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bodyEncrypted = DataEncryptHelper.EncryptSm2Zip(jsonPlain, AppSettings.DataPush.PublicKey);
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] Encrypted BODY (Hex): {bodyEncrypted}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] SM2加密失败: {ex}");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 构造 POST 请求 URL
|
||||||
|
string url = $"{AppSettings.DataPush.Hous}oauth2/sportsDataReplay";
|
||||||
|
|
||||||
|
// 5. 发送 POST 请求
|
||||||
|
string responseText;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
responseText = await HttpManager.HttpPostAsync(
|
||||||
|
url,
|
||||||
|
postData: bodyEncrypted,
|
||||||
|
contentType: "application/json",
|
||||||
|
headers: headers
|
||||||
|
);
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] Response: {responseText}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] HTTP请求失败: {ex}");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. 解析响应,返回对象数组
|
||||||
|
if (!string.IsNullOrWhiteSpace(responseText) && responseText.TrimStart().StartsWith("{"))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var json = JsonConvert.DeserializeObject<Dictionary<string, object>>(responseText);
|
||||||
|
|
||||||
|
if (json != null)
|
||||||
|
{
|
||||||
|
var codeStr = json.ContainsKey("code") ? json["code"]?.ToString() : null;
|
||||||
|
var msgStr = json.ContainsKey("msg") ? json["msg"]?.ToString() : null;
|
||||||
|
|
||||||
|
if (codeStr == "200")
|
||||||
|
{
|
||||||
|
// 成功返回固定响应
|
||||||
|
resp.code = 200;
|
||||||
|
resp.msg = "数据上报成功";
|
||||||
|
Console.WriteLine("[SportsRoutineReport] 数据上报成功");
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 接口返回错误
|
||||||
|
resp.code = 500;
|
||||||
|
resp.msg = $"接口返回错误: {msgStr}";
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] 接口返回错误: code={codeStr}, msg={msgStr}");
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
resp.code = 500;
|
||||||
|
resp.msg = "JSON解析异常";
|
||||||
|
Console.WriteLine($"[SportsRoutineReport] JSON解析失败: {ex}");
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,10 +25,24 @@ namespace YD_AllHeartRates.Api.Services.Interface
|
|||||||
Task<List<StudentEduDto>> GetStudentEduId(string schoolName, string gradeName, string className, string realName, string xsId);
|
Task<List<StudentEduDto>> GetStudentEduId(string schoolName, string gradeName, string className, string realName, string xsId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 常规成绩上报
|
/// 常规数据上报
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data"></param>
|
/// <param name="data"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<SportsRoutineReportResponse> SportsRoutineReport(List<StudentData> data);
|
Task<SportsRoutineReportResponse> SportsRoutineReport(List<StudentData> data);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异常数据上报
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<SportsRoutineReportResponse> SportsAbnormalReport(List<SportsAbnormalReportDto> data);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 补传数据上报
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<SportsRoutineReportResponse> SportsDataReplay(List<StudentData> data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,12 +19,6 @@ namespace YD_AllHeartRates.Commons.Dto.DataPush
|
|||||||
public string XSEDUID { get; set; }
|
public string XSEDUID { get; set; }
|
||||||
public List<HeartRateRecordDto> HDSJ { get; set; }
|
public List<HeartRateRecordDto> HDSJ { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SportsRoutineReportResponse
|
|
||||||
{
|
|
||||||
public int code { get; set; }
|
|
||||||
public string msg { get; set; }
|
|
||||||
}
|
|
||||||
public class Package
|
public class Package
|
||||||
{
|
{
|
||||||
public string TOKEN { get; set; }
|
public string TOKEN { get; set; }
|
||||||
@ -34,4 +28,10 @@ namespace YD_AllHeartRates.Commons.Dto.DataPush
|
|||||||
public string CLIENT_ID { get; set; }
|
public string CLIENT_ID { get; set; }
|
||||||
public List<StudentData> DATA { get; set; }
|
public List<StudentData> DATA { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SportsRoutineReportResponse
|
||||||
|
{
|
||||||
|
public int code { get; set; }
|
||||||
|
public string msg { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace YD_AllHeartRates.Commons.Dto.DataPush
|
||||||
|
{
|
||||||
|
public class SportsAbnormalReportDto
|
||||||
|
{
|
||||||
|
public string SBID { get; set; }
|
||||||
|
public string XSEDUID { get; set; }
|
||||||
|
public List<AbnormalHeartRateRecordDto> HDSJ { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AbnormalHeartRateRecordDto
|
||||||
|
{
|
||||||
|
public string SJSJ { get; set; }
|
||||||
|
public int XL { get; set; }
|
||||||
|
public int JXXL { get; set; }
|
||||||
|
public string YCXX { get; set; }
|
||||||
|
public string YCYY { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AbnormalHeartPackage
|
||||||
|
{
|
||||||
|
public string TOKEN { get; set; }
|
||||||
|
public string APPID { get; set; }
|
||||||
|
public string SCSJ { get; set; }
|
||||||
|
public int SJCOUNT { get; set; }
|
||||||
|
public string CLIENT_ID { get; set; }
|
||||||
|
public List<SportsAbnormalReportDto> DATA { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("YD_AllHeartRates.Commons")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("YD_AllHeartRates.Commons")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+857eed77fc204c64ae8490450264180778bfa33e")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+94971e02db73531e4079a33ffae322fffa5f4e33")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("YD_AllHeartRates.Commons")]
|
[assembly: System.Reflection.AssemblyProductAttribute("YD_AllHeartRates.Commons")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("YD_AllHeartRates.Commons")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("YD_AllHeartRates.Commons")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
b5d32f6c572a27481cac1478a198112167f74a8eae290203e50a77f2f9f6e014
|
ff05671de86704e3e86a0d8b5edff7f82112b0109caf9ce5bbc08098bde6510e
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user