Browse Source

添加检测接口

wyq 1 year ago
parent
commit
056dac301f

+ 69 - 30
XdCxRhDW.App/CorTools/DetectToolForm.cs

@@ -20,6 +20,8 @@ using System.Threading.Tasks;
 using System.Web.Http.Results;
 using System.Web.UI.WebControls;
 using System.Windows.Forms;
+using XdCxRhDw.Dto;
+using XdCxRhDW.App.CpuCgTools;
 using XdCxRhDW.App.EFContext;
 using XdCxRhDW.App.WebAPI;
 using static XdCxRhDW.App.WebAPI.BaseController;
@@ -98,6 +100,7 @@ namespace XdCxRhDW.App.CorTools
         private async void MainForm_Load(object sender, EventArgs e)
         {
             this.gridControl1.DataSource = gridSource;
+            btnCheck.Enabled = !ckKY.Checked && !ckIBS.Checked && !chkDama.Checked ? false : true;
             ReadIni();
         }
 
@@ -200,26 +203,66 @@ namespace XdCxRhDW.App.CorTools
             {
                 return;
             }
-            var dmcResult = await XcorrUtils.DmcCheckAsync(btnFile1.Text, double.Parse(tefs.Text));
-            gridSource.Clear();
-
-            foreach (var dmcItem in dmcResult)
+            DmcType dmcType = DmcType.DAMA;
+            if (ckKY.Checked)
+            {
+                dmcType = DmcType.Ky5758;
+            }
+            else if (ckIBS.Checked)
+            {
+                dmcType = DmcType.IBS;
+            }
+            else if (chkDama.Checked)
+            {
+                dmcType = DmcType.DAMA;
+            }
+            DetectDto dto = new DetectDto();
+            dto.dmcType = dmcType;
+            try
             {
-                gridSource.Add(new CafResult()
+                using (RHDWContext db = new RHDWContext())
                 {
-                    file1 = btnFile1.Text,
-                    file2 = btnFile2.Text,
-                    smpstart = dmcItem.Start,
-                    smplen = dmcItem.Length
-                });
+                    var res = await db.SysSetings.FirstOrDefaultAsync();
+                    if (res != null)
+                    {
+                        uploadUrL = $"http://{res.ServerIp}:{res.HttpPort}/api/DetectCg";
+                    }
+                }
+                dto.file1  = UpLoadFile(btnFile1.Text);
+                // 构建上传请求的 Uri
+                string uploadUri = $"{uploadUrL}/DetectCalc";
+
+                var content = new StringContent(JsonConvert.SerializeObject(dto), System.Text.Encoding.UTF8, "application/json");
+                var dmcResult = PostRequest<IEnumerable<DetectResDto>> (uploadUri, content);
+                if (dmcResult!=null)
+                {
+                    //var dmcResult = await XcorrUtils.DmcCheckAsync(btnFile1.Text, dmcType);// double.Parse(tefs.Text),
+                    gridSource.Clear();
+                    foreach (var dmcItem in dmcResult)
+                    {
+                        gridSource.Add(new CafResult()
+                        {
+                            file1 = btnFile1.Text,
+                            file2 = btnFile2.Text,
+                            smpstart = dmcItem.Start,
+                            smplen = dmcItem.Length
+                        });
+                    }
+                }
+                WriteIni();
             }
-            WriteIni();
+            catch (Exception ex)
+            {
+                DxHelper.MsgBoxHelper.ShowError($"检测计算错误{ex.Message}");
+            }
+           
         }
 
         private void chkDama_CheckedChanged(object sender, EventArgs e)
         {
             lciStartPos.Visibility = lciSampleLength.Visibility = ckKY.Checked | ckIBS.Checked | chkDama.Checked ? LayoutVisibility.Never : LayoutVisibility.Always;
             btnCalc.Enabled = ckKY.Checked | ckIBS.Checked | chkDama.Checked ? false : true;
+            btnCheck.Enabled = !ckKY.Checked && !ckIBS.Checked && !chkDama.Checked ? false : true;
             if (chkDama.Checked)
             {
                 ckIBS.Checked = false;
@@ -230,6 +273,7 @@ namespace XdCxRhDW.App.CorTools
         {
             lciStartPos.Visibility = lciSampleLength.Visibility = ckKY.Checked | ckIBS.Checked | chkDama.Checked ? LayoutVisibility.Never : LayoutVisibility.Always;
             btnCalc.Enabled = ckKY.Checked | ckIBS.Checked | chkDama.Checked ? false : true;
+            btnCheck.Enabled = !ckKY.Checked && !ckIBS.Checked && !chkDama.Checked ? false : true;
             if (ckIBS.Checked)
             {
 
@@ -242,6 +286,7 @@ namespace XdCxRhDW.App.CorTools
         {
             lciStartPos.Visibility = lciSampleLength.Visibility = ckKY.Checked | ckIBS.Checked | chkDama.Checked ? LayoutVisibility.Never : LayoutVisibility.Always;
             btnCalc.Enabled = ckKY.Checked | ckIBS.Checked | chkDama.Checked ? false : true;
+            btnCheck.Enabled = !ckKY.Checked && !ckIBS.Checked && !chkDama.Checked ? false : true;
             if (ckKY.Checked)
             {
                 ckIBS.Checked = false;
@@ -319,27 +364,21 @@ namespace XdCxRhDW.App.CorTools
                 string uploadUri = $"{uploadUrL}/EstimationCalc";
 
                 var content = new StringContent(JsonConvert.SerializeObject(xcitem), System.Text.Encoding.UTF8, "application/json");
-                var result = PostRequest<CafResult>(uploadUri, content);
-                // var result = await ExecuteCorAsync(xcitem);
-                if (result != null)
+                try
+                {
+                    var result = PostRequest<CafResult>(uploadUri, content);
+                    // var result = await ExecuteCorAsync(xcitem);
+                    if (result != null)
+                    {
+                        gridSource.Add(result);
+                        gridView1.FocusedRowHandle = gridSource.Count - 1;
+                    }
+                }
+                catch (Exception)
                 {
-                    //var smitemindex = gridSource.FindIndex(m => m.smpstart == xcitem.smpStart && m.smplen == xcitem.smpCount);
-                    //if (smitemindex == -1)
-                    //{
-                    gridSource.Add(result);
-                    gridView1.FocusedRowHandle = gridSource.Count - 1;
-                    //}
-                    //else
-                    //{
-                    //    var smitem = gridSource[smitemindex];
-                    //    smitem.dt = result.dt;
-                    //    smitem.df = result.df;
-                    //    smitem.snr = result.snr;
-                    //    smitem.tm = result.tm;
-                    //    gridView1.RefreshData();
-                    //    gridView1.FocusedRowHandle = smitemindex;
-                    //}
+                    continue;
                 }
+               
 
             }
 

+ 18 - 2
XdCxRhDW.App/CorTools/XcorrUtils.cs

@@ -11,6 +11,7 @@ using System.Collections.Generic;
 using DevExpress.Drawing.Internal.Fonts.Interop;
 using System.Windows.Documents;
 using XdCxRhDW.App.WebAPI.DTO;
+using XdCxRhDw.Dto;
 
 namespace XdCxRhDW.App.CorTools
 {
@@ -75,12 +76,27 @@ namespace XdCxRhDW.App.CorTools
             return res;
         }
 
-        public static async Task<IEnumerable<DmcResult>> DmcCheckAsync(string fileName, double fs)
+        public static async Task<IEnumerable<DmcResult>> DmcCheckAsync(string fileName,  DmcType dmcType)
         {
+            string dmcCmd = "all";
+            switch (dmcType)
+            {
+                case DmcType.DAMA:
+                    dmcCmd = "dm";
+                    break;
+                case DmcType.IBS:
+                    dmcCmd = "nd";
+                    break;
+                case DmcType.Ky5758:
+                    throw new Exception("ky未实现!");
+                    break;
+                default:
+                    break;
+            }
             return await Task.Run(() =>
              {
                  p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "xcorr\\dmc.exe");
-                 p.StartInfo.Arguments = $"all \"{fileName}\" -f {fs} -c --dmfirst";
+                 p.StartInfo.Arguments = $"{dmcCmd} \"{fileName}\"";// -f {fs}" -c --dmfirst";
                  p.StartInfo.CreateNoWindow = true;
                  p.StartInfo.RedirectStandardError = true;
                  p.StartInfo.RedirectStandardOutput = true;

+ 1 - 0
XdCxRhDW.App/CpuCgTools/DmcResult.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;

+ 1 - 1
XdCxRhDW.App/WebAPI/Controllers/BaseController.cs

@@ -73,7 +73,7 @@ namespace XdCxRhDW.App.WebAPI
                 }
                 else
                 {
-                    return default(T);
+                    throw new Exception(AjaxResult.msg);
                 }
             }
             catch (Exception ex)

+ 72 - 0
XdCxRhDW.App/WebAPI/Controllers/DetectCgController.cs

@@ -11,6 +11,8 @@ using System.Web.Http;
 using XdCxRhDw.Dto;
 using XdCxRhDW.App.CorTools;
 using System.Web;
+using Newtonsoft.Json.Linq;
+using XdCxRhDW.App.CpuCgTools;
 namespace XdCxRhDW.App.WebAPI
 {
     /// <summary>
@@ -130,6 +132,76 @@ namespace XdCxRhDW.App.WebAPI
         }
 
 
+        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>
+        /// 检测计算
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<AjaxResult<IEnumerable<DetectResDto>>> DetectCalc(DetectDto dto)
+        {
+            var vpres = ValidateDetectParam(dto);
+            if (!vpres.Item1)
+            {
+                Serilog.Log.Warning(vpres.Item2);
+                return Error<IEnumerable<DetectResDto>>(vpres.Item2);
+            }
+            List<DetectResDto> list = new List<DetectResDto>();
+            try
+            {
+                var dmcResult = await XcorrUtils.DmcCheckAsync(dto.file1, dto.dmcType);
+                foreach (var dmcItem in dmcResult)
+                {
+                    DetectResDto detectRes = new DetectResDto(dmcItem.Start, dmcItem.Length, dmcItem.UserName);
+                    detectRes.File1 = dto.file1;
+                    list.Add(detectRes);
+
+                }
+            }
+            catch (Exception ex)
+            {
+                return Error<IEnumerable<DetectResDto>>($"执行检测计算异常,{ex.Message}");
+            }
+            finally
+            {
+                try
+                {
+                    //删除检测的文件
+                    File.Delete(dto.file1);
+                }
+                catch
+                {
+                }
+            }
+           
+            return Success<IEnumerable<DetectResDto>>(list);
+
+        }
+
+
         /// <summary>
         /// 上传文件
         /// </summary>

+ 32 - 0
XdCxRhDw.Dto/DetectDto.cs

@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace XdCxRhDw.Dto
+{
+  /// <summary>
+  /// 检测计算DTO
+  /// </summary>
+    public class DetectDto
+    {
+        /// <summary>
+        /// 数据文件1
+        /// </summary>
+        public String file1 { get; set; }
+        
+        public DmcType dmcType { get; set; }
+
+    }
+    /// <summary>
+    /// 检测类型
+    /// </summary>
+    public enum DmcType
+    {
+        DAMA=1,
+        IBS=2,
+        Ky5758=3
+    }
+}

+ 53 - 0
XdCxRhDw.Dto/DetectResDto.cs

@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace XdCxRhDw.Dto
+{
+    /// <summary>
+    /// 检测结果Dto
+    /// </summary>
+    public class DetectResDto
+    {
+        /// <summary>
+        /// 检测结果
+        /// </summary>
+        public DetectResDto()
+        {
+        }
+        /// <summary>
+        /// 检测结果
+        /// </summary>
+        /// <param name="start"></param>
+        /// <param name="length"></param>
+        /// <param name="userName"></param>
+        public DetectResDto(int start, int length, string userName)
+        {
+            Start = start;
+            Length = length;
+            UserName = userName;
+        }
+
+        /// <summary>
+        /// 检测开始样点
+        /// </summary>
+        public int Start { get; set; }
+        /// <summary>
+        /// 检测样点长度
+        /// </summary>
+        public int Length { get; set; }
+        /// <summary>
+        /// 检测用户名称
+        /// </summary>
+
+        public string UserName { get; set; }
+
+        /// <summary>
+        /// 数据文件
+        /// </summary>
+        public String File1 { get; set; }
+
+    }
+}

+ 2 - 0
XdCxRhDw.Dto/XdCxRhDw.Dto.csproj

@@ -47,6 +47,8 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="CalcDto.cs" />
+    <Compile Include="DetectDto.cs" />
+    <Compile Include="DetectResDto.cs" />
     <Compile Include="EstimationResDto.cs" />
     <Compile Include="PosResQueryDto.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />