zoule 1 month ago
parent
commit
666cca53c6

+ 1 - 5
DbMigrate/DbMigrate.csproj

@@ -25,6 +25,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -42,11 +43,6 @@
     <Reference Include="Dapper, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
       <HintPath>..\packages\Dapper.2.1.66\lib\net461\Dapper.dll</HintPath>
     </Reference>
-    <Reference Include="DevExpress.Data.Desktop.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
-    <Reference Include="DevExpress.Data.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
-    <Reference Include="DevExpress.Drawing.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
-    <Reference Include="DevExpress.Printing.v23.2.Core, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
-    <Reference Include="DevExpress.Utils.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
     <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
       <HintPath>..\packages\EntityFramework.6.5.1\lib\net45\EntityFramework.dll</HintPath>
     </Reference>

+ 1 - 3
DbMigrate/Form1.cs

@@ -1,6 +1,4 @@
-using DevExpress.Drawing.Internal.Fonts.Interop;
-using DevExpress.Utils;
-using MySql.Data.MySqlClient;
+using MySql.Data.MySqlClient;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;

+ 2 - 0
DbMigrate/dwpt.sql

@@ -359,6 +359,8 @@ CREATE TABLE `taskinfo`  (
   `CapDirFormat` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
   `CreateTime` datetime(3) NOT NULL,
   `UpdateTime` datetime(3) NOT NULL,
+  `MaxSigTime` datetime(3) NULL,
+  `MinSigTime` datetime(3) NULL,
   PRIMARY KEY (`ID`) USING BTREE,
   UNIQUE INDEX `ID`(`ID` ASC) USING BTREE,
   INDEX `UpdateTime`(`UpdateTime` ASC) USING BTREE

+ 150 - 23
XdCxRhDW.App/Controllers/PosController.cs

@@ -18,6 +18,7 @@ using System.Diagnostics;
 using System.Configuration;
 using System.Data.Entity.Infrastructure;
 using XdCxRhDW.Framework;
+using Org.BouncyCastle.Asn1.X509;
 
 namespace XdCxRhDW.App.Controllers
 {
@@ -128,8 +129,16 @@ namespace XdCxRhDW.App.Controllers
                     PosResType = EnumPosResType.X1D1CX,
                 };
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
+                db.Entry(runTask).State = EntityState.Modified;
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, null));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -253,8 +262,15 @@ namespace XdCxRhDW.App.Controllers
                     PosResType = EnumPosResType.X1D1CX,
                 };
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, null));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -369,7 +385,7 @@ namespace XdCxRhDW.App.Controllers
                     TarFreqDown = dto.FreqDown,
                 });
 
-                var res = PosApi.X2D1_Pos(cgRes, StationRes,dto.Zone, dto.CalcConfidence);
+                var res = PosApi.X2D1_Pos(cgRes, StationRes, dto.Zone, dto.CalcConfidence);
 
                 PosRes posRes = new PosRes()
                 {
@@ -396,8 +412,15 @@ namespace XdCxRhDW.App.Controllers
 
                 }
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, target));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
 
@@ -563,7 +586,7 @@ namespace XdCxRhDW.App.Controllers
                     TarFreqDown = dto.FreqDown,
                 });
 
-                var res = PosApi.X2D1_Pos(cgRes, StationRes, dto.Zone,dto.CalcConfidence);
+                var res = PosApi.X2D1_Pos(cgRes, StationRes, dto.Zone, dto.CalcConfidence);
                 PosRes posRes = new PosRes()
                 {
                     FreqUpHz = (long)cgRes.TarFreqUp.Value,
@@ -606,8 +629,15 @@ namespace XdCxRhDW.App.Controllers
                     posRes.TargetInfoID = target.ID;
                 }
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, target));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -738,8 +768,15 @@ namespace XdCxRhDW.App.Controllers
                     posRes.TargetInfoID = target.ID;
                 }
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, target));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -915,8 +952,15 @@ namespace XdCxRhDW.App.Controllers
                     posRes.TargetInfoID = target.ID;
                 }
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, target));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -1035,8 +1079,15 @@ namespace XdCxRhDW.App.Controllers
                 if (dto.TheoryDfoCalc && posRes.PosLon != 999)
                     posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, null));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -1186,8 +1237,15 @@ namespace XdCxRhDW.App.Controllers
                 if (dto.TheoryDfoCalc && posRes.PosLon != 999)
                     posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, null));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -1331,8 +1389,15 @@ namespace XdCxRhDW.App.Controllers
                     posRes.TargetInfoID = target.ID;
                 }
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, target));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -1517,8 +1582,15 @@ namespace XdCxRhDW.App.Controllers
                     posRes.TargetInfoID = target.ID;
                 }
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, target));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
 
@@ -1654,8 +1726,15 @@ namespace XdCxRhDW.App.Controllers
                     posRes.TargetInfoID = target.ID;
                 }
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, target));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -1835,8 +1914,15 @@ namespace XdCxRhDW.App.Controllers
                     posRes.TargetInfoID = target.ID;
                 }
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, target));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
 
@@ -1961,8 +2047,15 @@ namespace XdCxRhDW.App.Controllers
                 if (dto.TheoryDfoCalc && posRes.PosLon != 999)
                     posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, null));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -2128,8 +2221,15 @@ namespace XdCxRhDW.App.Controllers
                 if (dto.TheoryDfoCalc && posRes.PosLon != 999)
                     posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, null));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -2246,8 +2346,15 @@ namespace XdCxRhDW.App.Controllers
                 if (dto.TheoryDfoCalc && posRes.PosLon != 999)
                     posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, null));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -2388,8 +2495,16 @@ namespace XdCxRhDW.App.Controllers
                 if (dto.TheoryDfoCalc && posRes.PosLon != 999)
                     posRes.TargetState = TheoryDtoDfoApi.TheoryDfo(cgRes, StationRes, posRes, SysConfig.Config.YDPZThreshold);
                 posRes = db.PosRes.Add(posRes);
+                var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskID);
+                if (task != null)
+                {
+
+                    if (task.MaxSigTime == null || task.MaxSigTime < dto.SigTime) task.MaxSigTime = dto.SigTime;
+                    if (task.MinSigTime == null || task.MinSigTime > dto.SigTime) task.MinSigTime = dto.SigTime;
+                    db.Entry(task).State = EntityState.Modified;
+                }
                 await db.SaveChangesAsync();
-                Messenger.Defalut.Pub("新增定位点", MapModel(posRes));
+                Messenger.Defalut.Pub("新增定位点", MapModel(posRes, cgRes, ckRes, null));
                 return Success(MapDto(posRes, cgRes, ckRes.UserName));
             }
         }
@@ -2426,9 +2541,9 @@ namespace XdCxRhDW.App.Controllers
         }
 
 
-        private ModelPosRes MapModel(PosRes res)
+        private ModelPosRes MapModel(PosRes res, CgRes cg, CheckRes ck, TargetInfo tar)
         {
-            return new ModelPosRes()
+            var model = new ModelPosRes()
             {
                 ID = res.ID,
                 FreqUpHz = res.FreqUpHz,
@@ -2443,15 +2558,27 @@ namespace XdCxRhDW.App.Controllers
                 CgResID = res.CgResID,
                 CheckRes = res.CheckRes,
                 CheckResID = res.CheckResID,
-                ColorKey = res.ColorKey,
+                ColorKey = tar?.TargeColor,
                 CreateTime = res.CreateTime,
                 CxResID = res.CxResID,
                 StationResID = res.StationResID,
-                TargetInfo = res.TargetInfo,
-                TargetInfoID = res.TargetInfoID,
+                TargetInfo = tar,
+                TargetInfoID = tar?.ID,
                 UpdateTime = res.UpdateTime,
                 Confidence = res.Confidence,
+                UserName = ck.UserName,
+                PosCheckType = ck.PosCheckType,
+                Snr1 = cg.Snr1,
+                Snr2 = cg.Snr2,
+                SnrCdb = cg.SnrCdb,
+                TargetName = tar?.TargetName,
+
             };
+            if (model.Snr2 == null && model.SnrCdb != null)
+            {
+                model.Snr2 = model.SnrCdb;
+            }
+            return model;
         }
 
     }

+ 13 - 2
XdCxRhDW.App/Controllers/ResultController.cs

@@ -324,8 +324,19 @@ namespace XdCxRhDW.App.Controllers
                 DateTime? max = null;
                 using (MySqlContext db = new MySqlContext())
                 {
-                    string sql = $"select max(SigTime) from PosRes where TaskInfoID={dto.TaskInfoID} and Deleted=0 ";
-                    var query = db.PosRes.Where(p => p.TaskInfoID == dto.TaskInfoID && p.Deleted == 0);
+                    var task = db.TaskInfos.FirstOrDefault(p => p.ID == dto.TaskInfoID);
+                    if (task == null) return Success(posList);
+                    string sql = $"select max(SigTime) from PosRes where 1=1 ";
+                    if (task.MaxSigTime != null)
+                    {
+                        sql = $"{sql} and SigTime<='{task.MaxSigTime:yyyy-MM-dd HH:mm:ss}' ";
+                    }
+                    if (task.MinSigTime != null)
+                    {
+                        sql = $"{sql} and SigTime>='{task.MinSigTime:yyyy-MM-dd HH:mm:ss}' ";
+
+                    }
+                    sql = $"{sql} and TaskInfoID={dto.TaskInfoID} and Deleted=0 ";
                     if (!dto.IncludeInvalidate)
                     {
                         sql = $"{sql} and PosLon!=999 ";

+ 7 - 4
XdCxRhDW.App/MainForm.cs

@@ -118,7 +118,7 @@ namespace XdCxRhDW
             //}
             using (MySqlContext ctx = new MySqlContext())
             {
-                SysConfig.Config =await ctx.SysSetings.FirstOrDefaultAsync();
+                SysConfig.Config = await ctx.SysSetings.FirstOrDefaultAsync();
             }
             this.ribbonPageGroup1.Enabled = true;
             this.ribbonPageGroup2.Enabled = true;
@@ -256,8 +256,9 @@ namespace XdCxRhDW
                                     File.Delete(newFile);
                                 File.Move(file, newFile);
                             }
-                            catch
+                            catch (Exception ex)
                             {
+                                await App.LogHelper.Error($"{file}导入完成后移动到备份目录失败",ex);
                             }
                         }
                         else
@@ -271,8 +272,9 @@ namespace XdCxRhDW
                                     File.Delete(newFile);
                                 File.Move(file, newFile);
                             }
-                            catch
+                            catch(Exception ex)
                             {
+                                await App.LogHelper.Error($"{file}导入失败后移动到备份目录失败",ex);
                             }
                         }
                     }
@@ -287,8 +289,9 @@ namespace XdCxRhDW
                                 File.Delete(newFile);
                             File.Move(file, newFile);
                         }
-                        catch
+                        catch(Exception ex2)
                         {
+                            await App.LogHelper.Error($"{file}导入失败后移动到备份目录失败", ex2);
                         }
                         await Task.Delay(5000);
                     }

+ 31 - 49
XdCxRhDW.App/UserControl/CtrlCgRes.cs

@@ -22,9 +22,11 @@ using System.Windows.Controls;
 using System.Windows.Documents;
 using System.Windows.Forms;
 using XdCxRhDW.App.Model;
+using XdCxRhDW.Dto;
 using XdCxRhDW.Entity;
 using XdCxRhDW.Framework;
 using XdCxRhDW.Repostory;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
 
 namespace XdCxRhDW.App.UserControl
 {
@@ -68,7 +70,7 @@ namespace XdCxRhDW.App.UserControl
                 foreach (var groupItem in groupItems)
                 {
                     var ids = groupItem.Select(m => m.ID).ToList();
-                    using (MySqlContext db=new MySqlContext())
+                    using (MySqlContext db = new MySqlContext())
                     {
                         if (db != null)
                         {
@@ -146,9 +148,9 @@ namespace XdCxRhDW.App.UserControl
         {
             try
             {
-
+                int taskId = ((TaskInfo)txtTask.EditValue).ID;
                 DateTime start = DateTime.MinValue;
-                DateTime end = DateTime.MinValue;
+                DateTime? end = DateTime.MinValue;
                 if (txtTimeCho.Text == "自定义")
                 {
                     start = txtStartTime.DateTime;
@@ -156,62 +158,42 @@ namespace XdCxRhDW.App.UserControl
                 }
                 else
                 {
-                    var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbPart");
-                    if (!Directory.Exists(dir)) return new List<CgRes>();
-                    var yearDirs = Directory.EnumerateDirectories(dir).OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name));//年目录,倒叙排列
-                    foreach (var yearDir in yearDirs)
+
+                    using (MySqlContext db = new MySqlContext())
                     {
-                        //每一天的db文件,倒序排列
-                        var dayFiles = Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, yearDir), "*.db").OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name.Substring(0, 4)));
-                        foreach (var dayFile in dayFiles)
+                        var task = db.TaskInfos.FirstOrDefault(p => p.ID == taskId);
+                        if (task == null) return new List<CgRes>();
+                        string sql = $"select max(SigTime) from CgRes where 1=1 ";
+                        if (task.MaxSigTime != null)
                         {
-                            using (MySqlContext db=new MySqlContext())
-                            {
-                                if (db == null) continue;
-                                if (db.CgRes.Any(p => p.TaskID == ((TaskInfo)txtTask.EditValue).ID))
-                                    end = await db.CgRes.Where(p => p.Deleted == 0 && p.TaskID == ((TaskInfo)txtTask.EditValue).ID).MaxAsync(p => p.SigTime);
-                            }
-                            if (end != DateTime.MinValue)
-                            {
-                                start = end.AddHours(-(int)txtTimeCho.EditValue);
-                                goto skip;
-                            }
+                            sql = $"{sql} and SigTime<='{task.MaxSigTime:yyyy-MM-dd HH:mm:ss}' ";
                         }
+                        if (task.MinSigTime != null)
+                        {
+                            sql = $"{sql} and SigTime>='{task.MinSigTime:yyyy-MM-dd HH:mm:ss}' ";
+
+                        }
+                        sql = $"{sql} and TaskId={taskId} and Deleted=0 ";
+                        end = await db.SqlQueryOneAsync<DateTime?>(sql);
+                    }
+                    if (end != null)
+                    {
+                        start = end.Value.AddHours(-(int)txtTimeCho.EditValue);
                     }
                 }
-            skip:
-                if (end == DateTime.MinValue)
+                if (end == null)
                 {
                     return new List<CgRes>();//没有数据不查询
                 }
-
-                DateTime endDay = new DateTime(end.Year, end.Month, end.Day);
-                DateTime startDay = new DateTime(start.Year, start.Month, start.Day);
-                List<CgRes> list = new List<CgRes>();
-                while (endDay >= startDay)
+                List<CgRes> list = null;
+                var startStr = start.ToString("yyyy-MM-dd HH:mm:ss");
+                var endStr = end.Value.ToString("yyyy-MM-dd HH:mm:ss");
+                using (MySqlContext db = new MySqlContext())
                 {
-                    using (MySqlContext db=new MySqlContext())
-                    {
-                        if (db != null)
-                        {
-                            for (int i = 0; i < 2; i++)
-                            {
-                                try
-                                {
-                                    var cgRes = await db.CgRes.Where(w => w.Deleted == 0 && w.SigTime >= start && w.SigTime <= end && w.TaskID == ((TaskInfo)txtTask.EditValue).ID).OrderByDescending(o => o.SigTime).ToListAsync();
-                                    list.AddRange(cgRes);
-                                    break;
-                                }
-                                catch (Exception ex)
-                                {
-                                    LogHelper.Error($"同步分区表结构异常,Time={endDay:yyyyMMdd}", ex).Wait(5000);
-                                    //db.SyncDb();
-                                }
-                            }
+                    string sql = $"select a.*,b.SatTxLon,b.SatTxLat,b.CdbTxLon,b.CdbTxLat,b.CxLon,b.CxLat,b.RefLon,b.RefLat from cgres a left join stationres b on a.StationResID=b.ID and b.SigTime>='{startStr}' and b.SigTime<='{endStr}' where a.SigTime>='{startStr}' and a.SigTime<='{endStr}' and a.Deleted=0 and a.TaskID={taskId} ";
 
-                        }
-                    }
-                    endDay = endDay.AddDays(-1);
+                    sql = $"{sql} order by SigTime desc ";
+                    list = await db.SqlQueryAsync<CgRes>(sql);
                 }
                 return list;
             }

+ 159 - 152
XdCxRhDW.App/UserControl/CtrlHome.cs

@@ -604,193 +604,200 @@ namespace XdCxRhDW.App.UserControl
 
         private async void btn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
         {
-            var tsk = gridView1.GetFocusedRow() as TaskInfo;
-            if (e.Item.Caption == "启动任务")
+            try
             {
-                try
+                var tsk = gridView1.GetFocusedRow() as TaskInfo;
+                if (e.Item.Caption == "启动任务")
                 {
-                    if (tsk.TaskType != EnumTaskType.Group)
+                    try
                     {
-                        TxInfo tx;
-                        TxInfo cdb;
-                        List<TaskSigDto> tskSigsDto = new List<TaskSigDto>();
-                        List<FixedStation> fixedStations = null;
-                        using (MySqlContext db = new MySqlContext())
+                        if (tsk.TaskType != EnumTaskType.Group)
                         {
-                            var dbSigs = await db.TaskSigs.Where(w => w.TaskInfoID == tsk.ID).Include(p => p.SigInfo).ToListAsync();
-                            if (!dbSigs.Any())
-                            {
-                                DxHelper.MsgBoxHelper.ShowWarning($"请添加任务信号");
-                                return;
-                            }
-                            foreach (var item in dbSigs)
+                            TxInfo tx;
+                            TxInfo cdb;
+                            List<TaskSigDto> tskSigsDto = new List<TaskSigDto>();
+                            List<FixedStation> fixedStations = null;
+                            using (MySqlContext db = new MySqlContext())
                             {
-                                TaskSigDto sigDto = new TaskSigDto()
+                                var dbSigs = await db.TaskSigs.Where(w => w.TaskInfoID == tsk.ID).Include(p => p.SigInfo).ToListAsync();
+                                if (!dbSigs.Any())
                                 {
-                                    FreqDown = item.SigInfo.FreqDown,
-                                    FreqUp = item.SigInfo.FreqUp,
-                                    SigType = (EnumSigCheckTypeDto)item.SigInfo.SigType,
-                                    Snr = item.SigInfo.Snr,
-                                    TaskInfoID = item.TaskInfoID,
-                                };
-                                if (item.SigInfo.Band != null && item.SigInfo.Band > 0)
-                                    sigDto.BandHz = item.SigInfo.Band.Value;
-                                else
-                                    sigDto.BandHz = 25000;
-                                var sigDelay = await db.SigDelays.Where(p => p.SigInfoId == item.SigInfo.ID).ToListAsync();
-
-                                sigDto.SigDelay.AddRange(sigDelay.MapTo<List<SigDelayDto>>());
-                                tskSigsDto.Add(sigDto);
+                                    DxHelper.MsgBoxHelper.ShowWarning($"请添加任务信号");
+                                    return;
+                                }
+                                foreach (var item in dbSigs)
+                                {
+                                    TaskSigDto sigDto = new TaskSigDto()
+                                    {
+                                        FreqDown = item.SigInfo.FreqDown,
+                                        FreqUp = item.SigInfo.FreqUp,
+                                        SigType = (EnumSigCheckTypeDto)item.SigInfo.SigType,
+                                        Snr = item.SigInfo.Snr,
+                                        TaskInfoID = item.TaskInfoID,
+                                    };
+                                    if (item.SigInfo.Band != null && item.SigInfo.Band > 0)
+                                        sigDto.BandHz = item.SigInfo.Band.Value;
+                                    else
+                                        sigDto.BandHz = 25000;
+                                    var sigDelay = await db.SigDelays.Where(p => p.SigInfoId == item.SigInfo.ID).ToListAsync();
+
+                                    sigDto.SigDelay.AddRange(sigDelay.MapTo<List<SigDelayDto>>());
+                                    tskSigsDto.Add(sigDto);
+                                }
+                                tx = db.TxInfos.FirstOrDefault(p => p.TxType == EnumTxType.Rec);
+                                cdb = db.TxInfos.FirstOrDefault(p => p.TxType == EnumTxType.Cdb);
+                                fixedStations = await db.FixedStation.Where(p => p.Enable).ToListAsync();
                             }
-                            tx = db.TxInfos.FirstOrDefault(p => p.TxType == EnumTxType.Rec);
-                            cdb = db.TxInfos.FirstOrDefault(p => p.TxType == EnumTxType.Cdb);
-                            fixedStations = await db.FixedStation.Where(p => p.Enable).ToListAsync();
-                        }
-                        if (tx == null || cdb == null)
-                        {
-                            DxHelper.MsgBoxHelper.ShowWarning($"未配置天线信息");
-                            return;
-                        }
-                        if (tsk.PosType == EnumPosType.X2D1)
-                        {
-                            //下发任务
-                            var svtItem = ServerContext.Instance.GetRandomOne(EnumSvrType.X2D1NoRefTask);
-                            if (svtItem == null)
+                            if (tx == null || cdb == null)
                             {
-                                DxHelper.MsgBoxHelper.ShowWarning($"未找到注册的两星一地处理服务");
+                                DxHelper.MsgBoxHelper.ShowWarning($"未配置天线信息");
                                 return;
                             }
-                            X2D1TaskHandleDto dto = new X2D1TaskHandleDto()
-                            {
-                                MainSatCode = tsk.MainSat,
-                                TaskType = (EnumTaskTypeDto)((int)tsk.TaskType),
-                                AdjaSatCode = tsk.Adja1Sat.Value,
-                                ID = tsk.ID,
-                                TaskName = tsk.TaskName,
-                                CapDir = tsk.CapDir,
-                                CapLon = tx.Lon,
-                                CapLat = tx.Lat,
-                                CdbLon = cdb.Lon,
-                                CdbLat = cdb.Lat,
-                                DateDirFormat = tsk.CapDirFormat,
-                                Sigs = tskSigsDto,
-                                ForTest = AppConfigHelper.Get("ForTest", false)
-                            };
-                            var fixedStation = fixedStations.FirstOrDefault(p => dto.Sigs.Any(t => t.FreqUp == p.FreqUpHz));
-                            if (fixedStation != null)
+                            if (tsk.PosType == EnumPosType.X2D1)
                             {
-                                dto.FixedStationDto = new X2D1FixedStationDto()
+                                //下发任务
+                                var svtItem = ServerContext.Instance.GetRandomOne(EnumSvrType.X2D1NoRefTask);
+                                if (svtItem == null)
+                                {
+                                    DxHelper.MsgBoxHelper.ShowWarning($"未找到注册的两星一地处理服务");
+                                    return;
+                                }
+                                X2D1TaskHandleDto dto = new X2D1TaskHandleDto()
                                 {
-                                    FixedStationId = fixedStation.ID,
-                                    FreqUp = fixedStation.FreqUpHz,
-                                    Lon = fixedStation.Lon,
-                                    Lat = fixedStation.Lat,
-                                    StationName = fixedStation.StationName,
-                                    Value = fixedStation.Value,
+                                    MainSatCode = tsk.MainSat,
+                                    TaskType = (EnumTaskTypeDto)((int)tsk.TaskType),
+                                    AdjaSatCode = tsk.Adja1Sat.Value,
+                                    ID = tsk.ID,
+                                    TaskName = tsk.TaskName,
+                                    CapDir = tsk.CapDir,
+                                    CapLon = tx.Lon,
+                                    CapLat = tx.Lat,
+                                    CdbLon = cdb.Lon,
+                                    CdbLat = cdb.Lat,
+                                    DateDirFormat = tsk.CapDirFormat,
+                                    Sigs = tskSigsDto,
+                                    ForTest = AppConfigHelper.Get("ForTest", false)
                                 };
+                                var fixedStation = fixedStations.FirstOrDefault(p => dto.Sigs.Any(t => t.FreqUp == p.FreqUpHz));
+                                if (fixedStation != null)
+                                {
+                                    dto.FixedStationDto = new X2D1FixedStationDto()
+                                    {
+                                        FixedStationId = fixedStation.ID,
+                                        FreqUp = fixedStation.FreqUpHz,
+                                        Lon = fixedStation.Lon,
+                                        Lat = fixedStation.Lat,
+                                        StationName = fixedStation.StationName,
+                                        Value = fixedStation.Value,
+                                    };
+                                }
+                                if (tsk.TaskType == EnumTaskType.History)
+                                {
+                                    TaskHistoryTimeEditor frm = new TaskHistoryTimeEditor(tsk);
+                                    if (frm.ShowDialog() != DialogResult.OK) return;
+                                    var startTime = frm.start;
+                                    var endTime = frm.end;
+                                    dto.StartTime = startTime;
+                                    dto.EndTime = endTime;
+                                }
+                                var res = await HttpHelper.PostRequestAsync<AjaxResult>(svtItem.BaseHttpAddr + "X2D1TaskProcessing/Run", dto);
+                                if (res.code != 200)
+                                {
+                                    XdCxRhDW.Framework.LogHelper.Error(res.msg);
+                                    DxHelper.MsgBoxHelper.ShowError($"{res.msg}");
+                                    return;
+                                }
+                                if (fixedStation != null)//有固定站
+                                {
+                                    var cts = new CancellationTokenSource();
+                                    PosWithRefFind refFind = new PosWithRefFind();
+                                    refFind.Start(dto.ID, cts.Token);
+                                    dicCts[dto.ID] = cts;
+                                }
+
                             }
-                            if (tsk.TaskType == EnumTaskType.History)
-                            {
-                                TaskHistoryTimeEditor frm = new TaskHistoryTimeEditor(tsk);
-                                if (frm.ShowDialog() != DialogResult.OK) return;
-                                var startTime = frm.start;
-                                var endTime = frm.end;
-                                dto.StartTime = startTime;
-                                dto.EndTime = endTime;
-                            }
-                            var res = await HttpHelper.PostRequestAsync<AjaxResult>(svtItem.BaseHttpAddr + "X2D1TaskProcessing/Run", dto);
-                            if (res.code != 200)
+                            else
                             {
-                                XdCxRhDW.Framework.LogHelper.Error(res.msg);
-                                DxHelper.MsgBoxHelper.ShowError($"{res.msg}");
+                                DxHelper.MsgBoxHelper.ShowError($"暂不支持{tsk.PosType.GetEnumDisplayName()}类型的任务");
                                 return;
                             }
-                            if (fixedStation != null)//有固定站
-                            {
-                                var cts = new CancellationTokenSource();
-                                PosWithRefFind refFind = new PosWithRefFind();
-                                refFind.Start(dto.ID, cts.Token);
-                                dicCts[dto.ID] = cts;
-                            }
-
                         }
-                        else
+                        using (MySqlContext db = new MySqlContext())
                         {
-                            DxHelper.MsgBoxHelper.ShowError($"暂不支持{tsk.PosType.GetEnumDisplayName()}类型的任务");
-                            return;
+                            var item = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == tsk.ID);
+                            item.TaskState = EnumTaskState.Running;
+                            await db.SaveChangesAsync();
+                            tsk.TaskState = EnumTaskState.Running;
                         }
+                        XdCxRhDW.Framework.LogHelper.Info($"用户启动了任务,ID={tsk.ID}");
                     }
-                    using (MySqlContext db = new MySqlContext())
+                    catch (Exception ex)
                     {
-                        var item = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == tsk.ID);
-                        item.TaskState = EnumTaskState.Running;
-                        await db.SaveChangesAsync();
-                        tsk.TaskState = EnumTaskState.Running;
+                        XdCxRhDW.Framework.LogHelper.Error("启动任务异常", ex);
+                        DxHelper.MsgBoxHelper.ShowError($"启动任务异常.{ex.Message}");
                     }
-                    XdCxRhDW.Framework.LogHelper.Info($"用户启动了任务,ID={tsk.ID}");
                 }
-                catch (Exception ex)
-                {
-                    XdCxRhDW.Framework.LogHelper.Error("启动任务异常", ex);
-                    DxHelper.MsgBoxHelper.ShowError($"启动任务异常.{ex.Message}");
-                }
-            }
-            else
-            {
-                try
+                else
                 {
-                    using (MySqlContext db = new MySqlContext())
-                    {
-                        var item = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == tsk.ID);
-                        item.TaskState = EnumTaskState.Stopped;
-                        await db.SaveChangesAsync();
-                    }
-                    tsk.TaskState = EnumTaskState.Stopped;
-                    string url = "";
-                    if (tsk.TaskType != EnumTaskType.Group)
+                    try
                     {
-                        ModelSvr svtItem = null;
-                        if (tsk.PosType == EnumPosType.X2D1)
-                        {
-                            svtItem = ServerContext.Instance.GetRandomOne(EnumSvrType.X2D1NoRefTask);
-                            url = "X2D1TaskProcessing";
-                        }
-                        if (svtItem == null)
+                        using (MySqlContext db = new MySqlContext())
                         {
-                            //DxHelper.MsgBoxHelper.ShowWarning($"未找到注册的处理服务");
-                            return;
+                            var item = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == tsk.ID);
+                            item.TaskState = EnumTaskState.Stopped;
+                            await db.SaveChangesAsync();
                         }
-                        TaskStopHandleDto dto = new TaskStopHandleDto();
-                        dto.TaskType = (EnumTaskTypeDto)((int)tsk.TaskType);
-                        dto.ID = tsk.ID;
-                        var res = await HttpHelper.PostRequestAsync<AjaxResult>(svtItem.BaseHttpAddr + $"{url}/Stop", dto);
-                        if (res.code != 200)
+                        tsk.TaskState = EnumTaskState.Stopped;
+                        string url = "";
+                        if (tsk.TaskType != EnumTaskType.Group)
                         {
-                            XdCxRhDW.Framework.LogHelper.Error(res.msg);
-                            DxHelper.MsgBoxHelper.ShowWarning(res.msg);
-                        }
+                            ModelSvr svtItem = null;
+                            if (tsk.PosType == EnumPosType.X2D1)
+                            {
+                                svtItem = ServerContext.Instance.GetRandomOne(EnumSvrType.X2D1NoRefTask);
+                                url = "X2D1TaskProcessing";
+                            }
+                            if (svtItem == null)
+                            {
+                                //DxHelper.MsgBoxHelper.ShowWarning($"未找到注册的处理服务");
+                                return;
+                            }
+                            TaskStopHandleDto dto = new TaskStopHandleDto();
+                            dto.TaskType = (EnumTaskTypeDto)((int)tsk.TaskType);
+                            dto.ID = tsk.ID;
+                            var res = await HttpHelper.PostRequestAsync<AjaxResult>(svtItem.BaseHttpAddr + $"{url}/Stop", dto);
+                            if (res.code != 200)
+                            {
+                                XdCxRhDW.Framework.LogHelper.Error(res.msg);
+                                DxHelper.MsgBoxHelper.ShowWarning(res.msg);
+                            }
 
-                        //停止查找参考信号
-                        if (dicCts.ContainsKey(dto.ID))
-                        {
-                            dicCts[dto.ID]?.Cancel();
-                            dicCts.Remove(dto.ID);
-                        }
+                            //停止查找参考信号
+                            if (dicCts.ContainsKey(dto.ID))
+                            {
+                                dicCts[dto.ID]?.Cancel();
+                                dicCts.Remove(dto.ID);
+                            }
 
 
+                        }
+                        XdCxRhDW.Framework.LogHelper.Warning($"用户停止了任务,ID={tsk.ID}");
+                    }
+                    catch (Exception ex)
+                    {
+                        XdCxRhDW.Framework.LogHelper.Error("停止任务异常", ex);
+                        DxHelper.MsgBoxHelper.ShowError($"停止任务异常.{ex.Message}");
                     }
-                    XdCxRhDW.Framework.LogHelper.Warning($"用户停止了任务,ID={tsk.ID}");
-                }
-                catch (Exception ex)
-                {
-                    XdCxRhDW.Framework.LogHelper.Error("停止任务异常", ex);
-                    DxHelper.MsgBoxHelper.ShowError($"停止任务异常.{ex.Message}");
                 }
+                var btnEdit = (layoutControlGroup1.CustomHeaderButtons[1] as GroupBoxButton);
+                var btnDel = (layoutControlGroup1.CustomHeaderButtons[2] as GroupBoxButton);
+                btnDel.Enabled = btnEdit.Enabled = tsk.TaskState != EnumTaskState.Running;
+
+            }
+            finally
+            {
+                gridView1.RefreshRow(gridView1.FocusedRowHandle);
             }
-            gridView1.RefreshRow(gridView1.FocusedRowHandle);
-            var btnEdit = (layoutControlGroup1.CustomHeaderButtons[1] as GroupBoxButton);
-            var btnDel = (layoutControlGroup1.CustomHeaderButtons[2] as GroupBoxButton);
-            btnDel.Enabled = btnEdit.Enabled = tsk.TaskState != EnumTaskState.Running;
         }
 
         private void txtFrequpMHz_SelectedIndexChanged(object sender, EventArgs e)

+ 6 - 2
XdCxRhDW.Entity/TaskInfo.cs

@@ -37,7 +37,7 @@ namespace XdCxRhDW.Entity
         [Display(Name = "邻星2", AutoGenerateField = false)]
         public int? Adja2Sat { get; set; }
 
-       
+
 
         /// <summary>
         /// 历史任务采集文件的目录
@@ -51,7 +51,11 @@ namespace XdCxRhDW.Entity
         [Display(AutoGenerateField = false)]
         public string CapDirFormat { get; set; }
 
-       
+        [Display(AutoGenerateField = false)]
+        public DateTime? MaxSigTime { get; set; }
+
+        [Display(AutoGenerateField = false)]
+        public DateTime? MinSigTime { get; set; }
 
     }
 }

+ 2 - 0
XdCxRhDW.Framework/ColorHelper.cs

@@ -20,6 +20,8 @@ public static class ColorHelper
     /// <returns></returns>
     public static bool IsHtmlColor(string color)
     {
+        if (color == null)
+            color = "#CC3333";
         if (!color.StartsWith("#")) return false;
         if (color.Length != 7) return false;
         string r = color.Substring(1, 2);