|
@@ -10,7 +10,6 @@ using System.Web.Http;
|
|
|
using XdCxRhDw.Dto;
|
|
|
using XdCxRhDW.Core.Api;
|
|
|
using XdCxRhDW.WebApi;
|
|
|
-using XdCxRhDW.WebApi.Service;
|
|
|
|
|
|
namespace XdCxRhDW.WebApi.Controllers
|
|
|
{
|
|
@@ -20,72 +19,30 @@ namespace XdCxRhDW.WebApi.Controllers
|
|
|
public class DetectCgController : BaseController
|
|
|
{
|
|
|
private readonly string uploadFolder;
|
|
|
- private readonly DetectService service;
|
|
|
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
|
- /// <param name="service"></param>
|
|
|
- public DetectCgController(DetectService service)
|
|
|
+ public DetectCgController()
|
|
|
{
|
|
|
this.uploadFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot");
|
|
|
- this.service = service;
|
|
|
}
|
|
|
- private static readonly object thisLock = new object();
|
|
|
- Dictionary<string, XcorrUtils> keyValues = new Dictionary<string, XcorrUtils>();
|
|
|
|
|
|
- private (bool, string) ValidateCalcParam(CalcDto dto)
|
|
|
- {
|
|
|
- if (dto == null)
|
|
|
- {
|
|
|
- return (false, "参估计算参数格式错误!");
|
|
|
- }
|
|
|
- if (string.IsNullOrEmpty(dto.file1))
|
|
|
- {
|
|
|
- return (false, "参估计算参数数据文件[file1]不能为空!");
|
|
|
- }
|
|
|
- if (string.IsNullOrEmpty(dto.file2))
|
|
|
- {
|
|
|
- return (false, "参估计算参数数据文件[file2]不能为空!");
|
|
|
- }
|
|
|
- if (!File.Exists(dto.file1))
|
|
|
- {
|
|
|
- return (false, $"参估计算参数数据文件[{dto.file1}]不存在!");
|
|
|
- }
|
|
|
- if (!File.Exists(dto.file2))
|
|
|
- {
|
|
|
- return (false, $"参估计算参数数据文件[{dto.file2}]不存在!");
|
|
|
- }
|
|
|
- if (dto.dtRange <= 0)
|
|
|
- {
|
|
|
- return (false, "参估计算参数时差范围[dtRange]不能小于等于0!");
|
|
|
- }
|
|
|
- if (dto.smpStart < 0)
|
|
|
- {
|
|
|
- return (false, "参估计算参数开始样点[smpStart]不能小于0!");
|
|
|
- }
|
|
|
- if (dto.smpCount < 0)
|
|
|
- {
|
|
|
- return (false, "参估计算参数样点数[smpCount]不能小于0!");
|
|
|
- }
|
|
|
- return (true, string.Empty);
|
|
|
- }
|
|
|
/// <summary>
|
|
|
/// CPU参估计算
|
|
|
/// </summary>
|
|
|
- /// <param name="dto"></param>
|
|
|
+ /// <param name="dto">CPU参估参数</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost]
|
|
|
- public async Task<AjaxResult<EstimationResDto>> EstimationCalc(CalcDto dto)
|
|
|
+ public async Task<AjaxResult<CpuCgResDto>> CpuCgCalc(CpuCgDto dto)
|
|
|
{
|
|
|
- var token = Request.GetCorrelationId().ToString();
|
|
|
dto.file1 = Path.Combine(uploadFolder, dto.file1);
|
|
|
dto.file2 = Path.Combine(uploadFolder, dto.file2);
|
|
|
var vpres = ValidateCalcParam(dto);
|
|
|
if (!vpres.Item1)
|
|
|
{
|
|
|
Serilog.Log.Warning(vpres.Item2);
|
|
|
- return Error<EstimationResDto>(vpres.Item2);
|
|
|
+ return Error<CpuCgResDto>(vpres.Item2);
|
|
|
}
|
|
|
XcorrStruct xItem = new XcorrStruct();
|
|
|
xItem.file1 = dto.file1;
|
|
@@ -109,27 +66,22 @@ namespace XdCxRhDW.WebApi.Controllers
|
|
|
xItem.smpStart = dto.smpStart;
|
|
|
xItem.snrThreshold = dto.snrThreshold;
|
|
|
|
|
|
- EstimationResDto resDto = new EstimationResDto();
|
|
|
+ CpuCgResDto resDto = new CpuCgResDto();
|
|
|
try
|
|
|
{
|
|
|
XcorrUtils xcorr = new XcorrUtils();
|
|
|
- lock (thisLock)
|
|
|
- {
|
|
|
- keyValues.Add(token, xcorr);
|
|
|
- }
|
|
|
var result = await xcorr.Calc(xItem);
|
|
|
//开始计算
|
|
|
if (result.flag == -2)
|
|
|
{
|
|
|
Serilog.Log.Warning("参估计算内部错误!");
|
|
|
- return Error<EstimationResDto>("参估计算内部错误!");
|
|
|
+ return Error<CpuCgResDto>("参估计算内部错误!");
|
|
|
}
|
|
|
else if (result.flag == -1)
|
|
|
{
|
|
|
Serilog.Log.Warning("参估计算所需数据超出文件范围!");
|
|
|
- return Error<EstimationResDto>("参估计算所需数据超出文件范围!");
|
|
|
+ return Error<CpuCgResDto>("参估计算所需数据超出文件范围!");
|
|
|
}
|
|
|
- resDto.Token = token;
|
|
|
resDto.TimeMs = result.tm;
|
|
|
resDto.Smpstart = result.smpstart;
|
|
|
resDto.Smplen = result.smplen;
|
|
@@ -146,14 +98,10 @@ namespace XdCxRhDW.WebApi.Controllers
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- return Error<EstimationResDto>($"执行参估计算异常,{ex.Message}");
|
|
|
+ return Error<CpuCgResDto>($"执行参估计算异常,{ex.Message}");
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
- lock (thisLock)
|
|
|
- {
|
|
|
- keyValues.Remove(token);
|
|
|
- }
|
|
|
try
|
|
|
{
|
|
|
//删除计算得文件
|
|
@@ -168,61 +116,10 @@ namespace XdCxRhDW.WebApi.Controllers
|
|
|
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 参估计算停止
|
|
|
- /// </summary>
|
|
|
- /// <param name="token"></param>
|
|
|
- /// <returns></returns>
|
|
|
- //[HttpPost]
|
|
|
- //public async Task<AjaxResult<bool>> StopEstimationCalc(string token)
|
|
|
- //{
|
|
|
- // return await Task.Run(() =>
|
|
|
- // {
|
|
|
- // lock (thisLock)
|
|
|
- // {
|
|
|
- // if (keyValues.ContainsKey(token))
|
|
|
- // {
|
|
|
- // keyValues[token].StopCalc();
|
|
|
- // return Success(true);
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // return Success(false);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
-
|
|
|
- //}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private (bool, string) ValidateDetectParam(DetectDto dto)
|
|
|
- {
|
|
|
- if (dto == null)
|
|
|
- {
|
|
|
- return (false, "检测计算参数格式错误!");
|
|
|
- }
|
|
|
- if (string.IsNullOrEmpty(dto.file1))
|
|
|
- {
|
|
|
- return (false, "检测计算参数数据文件[file1]不能为空!");
|
|
|
- }
|
|
|
- if (!File.Exists(dto.file1))
|
|
|
- {
|
|
|
- return (false, $"检测计算参数数据文件[{dto.file1}]不存在!");
|
|
|
- }
|
|
|
- bool containsValue = Enum.IsDefined(typeof(DmcType), dto.dmcType);
|
|
|
- if (!containsValue)
|
|
|
- {
|
|
|
- return (false, $"检测计算参数[dmcType]检测类型值{dto.dmcType}不存在!");
|
|
|
- }
|
|
|
-
|
|
|
- return (true, string.Empty);
|
|
|
- }
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 信号检测(支持DAMA、IBS、能量检测)
|
|
|
/// </summary>
|
|
|
- /// <param name="dto"></param>
|
|
|
+ /// <param name="dto">信号检测参数</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost]
|
|
|
public async Task<AjaxResult<IEnumerable<DetectResDto>>> DetectCalc(DetectDto dto)
|
|
@@ -239,10 +136,6 @@ namespace XdCxRhDW.WebApi.Controllers
|
|
|
try
|
|
|
{
|
|
|
XcorrUtils xcorr = new XcorrUtils();
|
|
|
- lock (thisLock)
|
|
|
- {
|
|
|
- keyValues.Add(token, xcorr);
|
|
|
- }
|
|
|
var dmcResult = await xcorr.DmcCheckAsync(dto.file1, dto.fsHz, dto.dmcType);
|
|
|
foreach (var dmcItem in dmcResult)
|
|
|
{
|
|
@@ -260,10 +153,6 @@ namespace XdCxRhDW.WebApi.Controllers
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
- lock (thisLock)
|
|
|
- {
|
|
|
- //keyValues.Remove(token);
|
|
|
- }
|
|
|
try
|
|
|
{
|
|
|
//删除检测的文件
|
|
@@ -273,37 +162,69 @@ namespace XdCxRhDW.WebApi.Controllers
|
|
|
{
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return Success<IEnumerable<DetectResDto>>(list);
|
|
|
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 信号检测停止
|
|
|
- /// </summary>
|
|
|
- /// <param name="token"></param>
|
|
|
- /// <returns></returns>
|
|
|
- //[HttpPost]
|
|
|
- //public async Task<AjaxResult<bool>> StopDetectCalc(string token)
|
|
|
- //{
|
|
|
- // return await Task.Run(() =>
|
|
|
- // {
|
|
|
- // lock (thisLock)
|
|
|
- // {
|
|
|
- // if (keyValues.ContainsKey(token))
|
|
|
- // {
|
|
|
- // keyValues[token].StopDm();
|
|
|
- // return Success(true);
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // return Success(false);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
+ private (bool, string) ValidateCalcParam(CpuCgDto dto)
|
|
|
+ {
|
|
|
+ if (dto == null)
|
|
|
+ {
|
|
|
+ return (false, "参估计算参数格式错误!");
|
|
|
+ }
|
|
|
+ if (string.IsNullOrEmpty(dto.file1))
|
|
|
+ {
|
|
|
+ return (false, "参估计算参数数据文件[file1]不能为空!");
|
|
|
+ }
|
|
|
+ if (string.IsNullOrEmpty(dto.file2))
|
|
|
+ {
|
|
|
+ return (false, "参估计算参数数据文件[file2]不能为空!");
|
|
|
+ }
|
|
|
+ if (!File.Exists(dto.file1))
|
|
|
+ {
|
|
|
+ return (false, $"参估计算参数数据文件[{Path.GetFileName(dto.file1)}]不存在!");
|
|
|
+ }
|
|
|
+ if (!File.Exists(dto.file2))
|
|
|
+ {
|
|
|
+ return (false, $"参估计算参数数据文件[{Path.GetFileName(dto.file2)}]不存在!");
|
|
|
+ }
|
|
|
+ if (dto.dtRange <= 0)
|
|
|
+ {
|
|
|
+ return (false, "参估计算参数时差范围[dtRange]不能小于等于0!");
|
|
|
+ }
|
|
|
+ if (dto.smpStart < 0)
|
|
|
+ {
|
|
|
+ return (false, "参估计算参数开始样点[smpStart]不能小于0!");
|
|
|
+ }
|
|
|
+ if (dto.smpCount < 0)
|
|
|
+ {
|
|
|
+ return (false, "参估计算参数样点数[smpCount]不能小于0!");
|
|
|
+ }
|
|
|
+ return (true, string.Empty);
|
|
|
+ }
|
|
|
|
|
|
- //}
|
|
|
+ private (bool, string) ValidateDetectParam(DetectDto dto)
|
|
|
+ {
|
|
|
+ if (dto == null)
|
|
|
+ {
|
|
|
+ return (false, "检测计算参数格式错误!");
|
|
|
+ }
|
|
|
+ if (string.IsNullOrEmpty(dto.file1))
|
|
|
+ {
|
|
|
+ return (false, "检测计算参数数据文件[file1]不能为空!");
|
|
|
+ }
|
|
|
+ if (!File.Exists(dto.file1))
|
|
|
+ {
|
|
|
+ return (false, $"检测计算参数数据文件[{dto.file1}]不存在!");
|
|
|
+ }
|
|
|
+ bool containsValue = Enum.IsDefined(typeof(DmcType), dto.dmcType);
|
|
|
+ if (!containsValue)
|
|
|
+ {
|
|
|
+ return (false, $"检测计算参数[dmcType]检测类型值{dto.dmcType}不存在!");
|
|
|
+ }
|
|
|
|
|
|
+ return (true, string.Empty);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|