diff --git a/Txgy.RBS.DTO/ProjectInfoDTO.cs b/Txgy.RBS.DTO/ProjectInfoDTO.cs index aeedf09..b2a309f 100644 --- a/Txgy.RBS.DTO/ProjectInfoDTO.cs +++ b/Txgy.RBS.DTO/ProjectInfoDTO.cs @@ -1,6 +1,8 @@ -using System; +using SqlSugar; +using System; using System.Linq; using System.Text; +using Txgy.RBS.DbModel.Models; namespace Txgy.RBS.DTO { @@ -19,6 +21,9 @@ namespace Txgy.RBS.DTO /// public int id { get; set; } + + public int project_id { get; set; } + /// /// Desc: /// Default: @@ -179,6 +184,9 @@ namespace Txgy.RBS.DTO /// Nullable:False /// public int push_wx_company_id { get; set; } + + public StationFileDTO stationFile { get; set; } + public TimeTabDTO timeTab { get; set; } } } diff --git a/Txgy.RBS.DTO/ResultDTO.cs b/Txgy.RBS.DTO/ResultDTO.cs index 4fb8742..8e46042 100644 --- a/Txgy.RBS.DTO/ResultDTO.cs +++ b/Txgy.RBS.DTO/ResultDTO.cs @@ -40,14 +40,8 @@ namespace Txgy.RBS.DTO /// Default: /// Nullable:True /// - public double? e { get; set; } + public double? ylat { get; set; } - /// - /// Desc: - /// Default: - /// Nullable:True - /// - public double? n { get; set; } /// /// Desc: diff --git a/Txgy.RBS.DTO/ResultJsonDTO.cs b/Txgy.RBS.DTO/ResultJsonDTO.cs deleted file mode 100644 index aab1f9e..0000000 --- a/Txgy.RBS.DTO/ResultJsonDTO.cs +++ /dev/null @@ -1,17 +0,0 @@ -using SqlSugar; - -namespace Txgy.RBS.DTO -{ - /// - /// - /// - public partial class ResultJsonDTO - { - public int Id { get; set; } - - public int ResultId { get; set; } - - public string Json { get; set; } - - } -} diff --git a/Txgy.RBS.DTO/StationsDTO.cs b/Txgy.RBS.DTO/StationDTO.cs similarity index 95% rename from Txgy.RBS.DTO/StationsDTO.cs rename to Txgy.RBS.DTO/StationDTO.cs index 92a35c8..50b85d1 100644 --- a/Txgy.RBS.DTO/StationsDTO.cs +++ b/Txgy.RBS.DTO/StationDTO.cs @@ -7,9 +7,9 @@ namespace Txgy.RBS.DTO /// /// /// - public partial class StationsDTO + public class StationDTO { - public StationsDTO() + public StationDTO() { @@ -68,7 +68,7 @@ namespace Txgy.RBS.DTO /// Default:3200000000 /// Nullable:False /// - public int sens { get; set; } + public double sens { get; set; } /// /// Desc: diff --git a/Txgy.RBS.DTO/StationFileDTO.cs b/Txgy.RBS.DTO/StationFileDTO.cs index 478dea3..c581318 100644 --- a/Txgy.RBS.DTO/StationFileDTO.cs +++ b/Txgy.RBS.DTO/StationFileDTO.cs @@ -1,19 +1,15 @@ using System; using System.Linq; using System.Text; +using Txgy.RBS.DbModel.Models; namespace Txgy.RBS.DTO { /// /// /// - public partial class StationFileDTO + public class StationFileDTO { - public StationFileDTO() - { - - - } /// /// Desc: /// Default: @@ -35,5 +31,6 @@ namespace Txgy.RBS.DTO /// public string file_name { get; set; } + public List stations { get; set; } } } diff --git a/Txgy.RBS.DTO/StationNumVpnDTO.cs b/Txgy.RBS.DTO/StationNumVpnDTO.cs index e1dbc57..c1d2f4b 100644 --- a/Txgy.RBS.DTO/StationNumVpnDTO.cs +++ b/Txgy.RBS.DTO/StationNumVpnDTO.cs @@ -7,7 +7,7 @@ namespace Txgy.RBS.DTO /// /// /// - public partial class StationNumVpnDTO + public class StationNumVpnDTO { public StationNumVpnDTO() { diff --git a/Txgy.RBS.DbModel/Models/project_info.cs b/Txgy.RBS.DbModel/Models/project_info.cs index 207fdf9..231a9a0 100644 --- a/Txgy.RBS.DbModel/Models/project_info.cs +++ b/Txgy.RBS.DbModel/Models/project_info.cs @@ -8,13 +8,8 @@ namespace Txgy.RBS.DbModel.Models /// /// /// - public partial class project_info + public class project_info { - public project_info() - { - - - } /// /// Desc: /// Default: @@ -23,6 +18,8 @@ namespace Txgy.RBS.DbModel.Models [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public int id { get; set; } + public int project_id { get; set; } + /// /// Desc: /// Default: @@ -184,5 +181,11 @@ namespace Txgy.RBS.DbModel.Models /// public int push_wx_company_id { get; set; } + [Navigate(NavigateType.OneToOne, nameof(project_id))] + public station_file stationFile { get; set; } + + + [Navigate(NavigateType.OneToOne, nameof(project_id))] + public time_tab time_tab { get; set; } } } diff --git a/Txgy.RBS.DbModel/Models/project_used.cs b/Txgy.RBS.DbModel/Models/project_used.cs index df9433c..10836e4 100644 --- a/Txgy.RBS.DbModel/Models/project_used.cs +++ b/Txgy.RBS.DbModel/Models/project_used.cs @@ -1,4 +1,5 @@ -using System; +using SqlSugar; +using System; using System.Linq; using System.Text; @@ -18,7 +19,8 @@ namespace Txgy.RBS.DbModel.Models /// Desc: /// Default: /// Nullable:False - /// + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public int current_project_id { get; set; } diff --git a/Txgy.RBS.DbModel/Models/result.cs b/Txgy.RBS.DbModel/Models/result.cs index 0454d3c..0e989ea 100644 --- a/Txgy.RBS.DbModel/Models/result.cs +++ b/Txgy.RBS.DbModel/Models/result.cs @@ -8,7 +8,7 @@ namespace Txgy.RBS.DbModel.Models /// /// /// - public partial class result + public class result { public result() { @@ -42,14 +42,14 @@ namespace Txgy.RBS.DbModel.Models /// Default: /// Nullable:True /// - public double? e { get; set; } + public double? xlon { get; set; } /// /// Desc: /// Default: /// Nullable:True /// - public double? n { get; set; } + public double? ylat { get; set; } /// /// Desc: @@ -107,5 +107,8 @@ namespace Txgy.RBS.DbModel.Models /// public double? seismic_direction { get; set; } + + public string json_str { set; get; } + } } diff --git a/Txgy.RBS.DbModel/Models/result_json.cs b/Txgy.RBS.DbModel/Models/result_json.cs deleted file mode 100644 index 95c52dd..0000000 --- a/Txgy.RBS.DbModel/Models/result_json.cs +++ /dev/null @@ -1,41 +0,0 @@ -using SqlSugar; -using System; -using System.Linq; -using System.Text; - -namespace Txgy.RBS.DbModel.Models -{ - /// - /// - /// - public partial class result_json - { - public result_json() - { - - - } - /// - /// Desc: - /// Default: - /// Nullable:False - /// - [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] - public int id { get; set; } - - /// - /// Desc: - /// Default: - /// Nullable:True - /// - public int? result_id { get; set; } - - /// - /// Desc: - /// Default: - /// Nullable:True - /// - public string json { get; set; } - - } -} diff --git a/Txgy.RBS.DbModel/Models/stations.cs b/Txgy.RBS.DbModel/Models/station.cs similarity index 95% rename from Txgy.RBS.DbModel/Models/stations.cs rename to Txgy.RBS.DbModel/Models/station.cs index 3ebcdcc..e706436 100644 --- a/Txgy.RBS.DbModel/Models/stations.cs +++ b/Txgy.RBS.DbModel/Models/station.cs @@ -8,9 +8,9 @@ namespace Txgy.RBS.DbModel.Models /// /// /// - public partial class stations + public partial class station { - public stations() + public station() { @@ -70,7 +70,7 @@ namespace Txgy.RBS.DbModel.Models /// Default:3200000000 /// Nullable:False /// - public int sens { get; set; } + public double sens { get; set; } /// /// Desc: diff --git a/Txgy.RBS.DbModel/Models/station_file.cs b/Txgy.RBS.DbModel/Models/station_file.cs index f6f9d7f..0a64b1c 100644 --- a/Txgy.RBS.DbModel/Models/station_file.cs +++ b/Txgy.RBS.DbModel/Models/station_file.cs @@ -8,19 +8,14 @@ namespace Txgy.RBS.DbModel.Models /// /// /// - public partial class station_file + public class station_file { - public station_file() - { - - - } /// /// Desc: /// Default: /// Nullable:True /// - [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + [SugarColumn(IsPrimaryKey = true,IsIdentity =true)] public int id { get; set; } /// @@ -37,5 +32,9 @@ namespace Txgy.RBS.DbModel.Models /// public string file_name { get; set; } + + [Navigate(NavigateType.OneToMany, nameof(station.project_id))] + public List stations { get; set; } + } } diff --git a/Txgy.RBS.Framework/Api/ApiResult.cs b/Txgy.RBS.Framework/Api/ApiResult.cs index 2665ac5..d0189c6 100644 --- a/Txgy.RBS.Framework/Api/ApiResult.cs +++ b/Txgy.RBS.Framework/Api/ApiResult.cs @@ -1,6 +1,8 @@ -using System; +using ServiceStack.Text; +using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; @@ -19,7 +21,7 @@ namespace Txgy.RBS.Framework.Api } } - public ReponseCodeEnum Code { get; set; } + public HttpStatusCode Code { get; set; } /// /// 特指错误消息 diff --git a/Txgy.RBS.Framework/CommonData.cs b/Txgy.RBS.Framework/CommonData.cs new file mode 100644 index 0000000..461a8d7 --- /dev/null +++ b/Txgy.RBS.Framework/CommonData.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; + +namespace Txgy.RBS.Framework +{ + public class CommonData + { + public static string BaseProjectPath { get; set; } = "d:\\Project"; + public static string ApmsDefaultPath { get; set; } = "program\\apms\\gw.apms.json"; + public static string RecvDefaultPath { get; set; } = "program\\recvmqtt\\gw.recvmqtt.json"; + + + /// //From:www.13le.com + /// 复制文件夹下所有文件 + /// + /// 原文件路径 + /// 目标文件路径 + + public static void CopyFolder(string sourceFolder, string destFolder) + { + + //如果目标路径不存在,则创建目标路径 + if (!System.IO.Directory.Exists(destFolder)) + { + System.IO.Directory.CreateDirectory(destFolder); + } + //得到原文件根目录下的所有文件 + string[] files = System.IO.Directory.GetFiles(sourceFolder); + foreach (string file in files) + { + string name = System.IO.Path.GetFileName(file); + string dest = System.IO.Path.Combine(destFolder, name); + System.IO.File.Copy(file, dest);//复制文件 + } + //得到原文件根目录下的所有文件夹 + string[] folders = System.IO.Directory.GetDirectories(sourceFolder); + foreach (string folder in folders) + { + string name = System.IO.Path.GetFileName(folder); + string dest = System.IO.Path.Combine(destFolder, name); + CopyFolder(folder, dest);//构建目标路径,递归复制文件 + } + } + + } +} diff --git a/Txgy.RBS.Framework/Models/ApmsModel.cs b/Txgy.RBS.Framework/Models/ApmsModel.cs new file mode 100644 index 0000000..36c8718 --- /dev/null +++ b/Txgy.RBS.Framework/Models/ApmsModel.cs @@ -0,0 +1,124 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Txgy.RBS.Framework.Models +{ + public class ApmsModel + { + private string station1; + private List ttime1; + private string push2wx1; + private string savepath1; + private float xmin1; + private float xmax1; + private float ymin1; + private float ymax1; + private float zref1; + private float zmin1; + private float zmax1; + private float minstep1; + private List channels1; + + [JsonProperty("station")] + public string station { get => station1; set => station1 = value; }//根据station表生成 + [JsonProperty("ttime")] + public List ttime { get => ttime1; set => ttime1 = value; }//客户端上传 + [JsonProperty("Main.log_level")] + public string log_level { get; set; } + [JsonProperty("Main.slice_seconds")] + public int slice_seconds { get; set; } + [JsonProperty("Main.overlap_seconds")] + public int overlap_seconds { get; set; } + [JsonProperty("Main.is_mag")] + public string is_mag { get; set; } + [JsonProperty("Main.is_write_slice")] //Apms配置:存储结果 + public string is_write_slice { get; set; } + [JsonProperty("Main.lon")] + public double lon { get; set; } + [JsonProperty("Main.lat")] + public double lat { get; set; } + [JsonProperty("Main.height")] + public double height { get; set; } + [JsonProperty("Main.savepath")] //Apms配置:处理结果存储目录,由基础路径+工程名称+"result"拼接 + public string savepath { get => savepath1; set => savepath1 = value; } + [JsonProperty("Main.push2wx")] //Apms配置:微信推送,暂时不开放 + public string push2wx { get => push2wx1; set => push2wx1 = value; } + [JsonProperty("Main.push_url")] + public string push_url { get; set; } + [JsonProperty("Main.push_mag")] //Apms配置:推送阈值 + public double push_mag { get; set; } + [JsonProperty("Main.message_id")] + public int message_id { get; set; } + [JsonProperty("Main.company_id")] + public int company_id { get; set; } + [JsonProperty("Main.area_id")] + public int area_id { get; set; } + [JsonProperty("Main.content")] + public string content { get; set; } + [JsonProperty("Main.push_key")] + public string push_key { get; set; } + [JsonProperty("RServer.host")] + public string host { get; set; } + public List channels { get => channels1; set => channels1 = value; } + + [JsonProperty("Locate.log_level")] + public string llog_level { get; set; } + [JsonProperty("Locate.work_path")] + public string work_path { get; set; } + [JsonProperty("Locate.xmin")] + public float xmin { get => xmin1; set => xmin1 = value; } + [JsonProperty("Locate.xmax")] + public float xmax { get => xmax1; set => xmax1 = value; } + [JsonProperty("Locate.ymin")] + public float ymin { get => ymin1; set => ymin1 = value; } + [JsonProperty("Locate.ymax")] + public float ymax { get => ymax1; set => ymax1 = value; } + [JsonProperty("Locate.zref")] + public float zref { get => zref1; set => zref1 = value; } + [JsonProperty("Locate.zmin")] + public float zmin { get => zmin1; set => zmin1 = value; } + [JsonProperty("Locate.zmax")] + public float zmax { get => zmax1; set => zmax1 = value; } + [JsonProperty("Locate.minstep")] + public float minstep { get => minstep1; set => minstep1 = value; } + [JsonProperty("Locate.method")] + public string method { get; set; } + [JsonProperty("Locate.clusted_otime")] + public double clusted_otime { get; set; } + + } + + public class TTime + { + private string ttime2d1; + + [JsonProperty("station")] + public string station { get; set; } + + // [JsonProperty("ttime")] + // public string ttime { get; set; } + + [JsonProperty("ttime2d")] + public string ttime2d + { + get => ttime2d1; + set => ttime2d1 = value; + } + } + public class StationChannelsModel + { + public string network { get; set; } + + public string location { get; set; } + + public string channels { get; set; } + + public string station { get; set; } + } +} diff --git a/Txgy.RBS.Framework/Models/MsEventModel.cs b/Txgy.RBS.Framework/Models/MsEventModel.cs new file mode 100644 index 0000000..7b5fe2a --- /dev/null +++ b/Txgy.RBS.Framework/Models/MsEventModel.cs @@ -0,0 +1,40 @@ +using System; +using System.Reflection; + +namespace Txgy.RBS.Framework.Models +{ + public class MsEventModel + { + public int ID { get; set; } + public DateTime CurrentTime { get; set; } + public DateTime OriginTime { get; set; } + public double EastCoordinate { get; set; } + public double NorthCoordinate { get; set; } + public double Depth { get; set; } + + public double ML { get; set; } + public double Energy { get; set; } + + public int EarthquakeSource { get; set; } + + public bool IsSend { get => isSend; set => isSend = value; } + public MsEventModel(string message) + { + eventMessage = message; + string[] evtS = message.Trim(' ').Split(new char[] { ' ' }); + CurrentTime = DateTime.Now; + OriginTime = DateTime.Parse(evtS[0]); + EastCoordinate = double.Parse(evtS[2]); + NorthCoordinate = double.Parse(evtS[1]); + Depth = double.Parse(evtS[3]); + ML = evtS.Length == 7 ? -10 : double.Parse(evtS[5]); + } + private string eventMessage; + private bool isSend = false; + + public override string ToString() + { + return eventMessage; + } + } +} diff --git a/Txgy.RBS.Framework/Models/RecvMqttModel.cs b/Txgy.RBS.Framework/Models/RecvMqttModel.cs new file mode 100644 index 0000000..6cd6dbe --- /dev/null +++ b/Txgy.RBS.Framework/Models/RecvMqttModel.cs @@ -0,0 +1,29 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Txgy.RBS.Framework.Models +{ + //recv配置:波形数据存储目录,由基础路径+工程名称+"wavesdata"拼接 + public class RecvMqttModel + { + public string savepath { get; set; } + [JsonProperty("log_level")] + public string log_level { get; set; } + [JsonProperty("send2server")] //recv配置:Send2Redis + public string send2server { get; set; } + [JsonProperty("MQTT.Server")] //recv配置:MqttServer + public string Server { get; set; } + [JsonProperty("MQTT.Stations")] + public string Stations { get; set; } + [JsonProperty("MQTT.Send81")] + public string Send81 { get; set; } + [JsonProperty("dirstruct")] + public string dirstruct { get; set; } + [JsonProperty("Help")] + public string Help { get; set; } + } +} diff --git a/Txgy.RBS.Framework/ProcessConfig.cs b/Txgy.RBS.Framework/ProcessConfig.cs new file mode 100644 index 0000000..f246270 --- /dev/null +++ b/Txgy.RBS.Framework/ProcessConfig.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Txgy.RBS.Framework +{ + public class ProcessConfig + { + /// + /// server程序 + /// + public ProcessInfo Server { get; set; } + /// + /// Recv程序 + /// + public ProcessInfo RecvMqtt { get; set; } + /// + /// Apms(定位程序)程序 + /// + public ProcessInfo Apms { get; set; } + + } +} diff --git a/Txgy.RBS.Framework/ProcessInfo.cs b/Txgy.RBS.Framework/ProcessInfo.cs index f0b4e22..28e35f3 100644 --- a/Txgy.RBS.Framework/ProcessInfo.cs +++ b/Txgy.RBS.Framework/ProcessInfo.cs @@ -1,4 +1,6 @@ -using Newtonsoft.Json; + + +using System.Text.Json.Serialization; namespace Txgy.RBS.Framework { @@ -8,7 +10,6 @@ namespace Txgy.RBS.Framework /// /// 程序路径 /// - [JsonProperty] public string ProName { get { return proName; } @@ -18,7 +19,6 @@ namespace Txgy.RBS.Framework /// /// 程序路径 /// - [JsonProperty] public string ProTitle { get { return proTitle; } @@ -35,7 +35,6 @@ namespace Txgy.RBS.Framework /// /// 程序路径 /// - [JsonProperty] public string ProPath { get { return proPath; } @@ -46,7 +45,6 @@ namespace Txgy.RBS.Framework /// /// 启动参数 /// - [JsonProperty] public string ProParams { get { return proParams; } @@ -56,7 +54,6 @@ namespace Txgy.RBS.Framework /// /// 配置文件路径 /// - [JsonProperty] public string JsonPath { get; set; } private int pid; @@ -74,5 +71,12 @@ namespace Txgy.RBS.Framework get { return operationStr; } set { operationStr = value; } } + + [JsonIgnore] + public DateTime StartTime { set; get; } + + [JsonIgnore] + public bool State { set; get; } + } } diff --git a/Txgy.RBS.Framework/Txgy.RBS.Framework.csproj b/Txgy.RBS.Framework/Txgy.RBS.Framework.csproj index 99b0833..3cbffaa 100644 --- a/Txgy.RBS.Framework/Txgy.RBS.Framework.csproj +++ b/Txgy.RBS.Framework/Txgy.RBS.Framework.csproj @@ -7,7 +7,10 @@ + + + diff --git a/Txgy.RBS.IServices/AutoMapObject.cs b/Txgy.RBS.IServices/AutoMapObject.cs index 1410d12..b88ed01 100644 --- a/Txgy.RBS.IServices/AutoMapObject.cs +++ b/Txgy.RBS.IServices/AutoMapObject.cs @@ -11,10 +11,14 @@ namespace Txgy.RBS.IServices { public AutoMapObject() { - CreateMap().ReverseMap(); - CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap() + .ForMember(p => p.timeTab, pd => pd.MapFrom(s => s.time_tab)) + .ForMember(p => p.stationFile, pd => pd.MapFrom(s => s.stationFile)).ReverseMap(); CreateMap().ReverseMap(); - CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); } diff --git a/Txgy.RBS.IServices/IGlobalConfigService.cs b/Txgy.RBS.IServices/IGlobalConfigService.cs index 390c3c3..31a34e1 100644 --- a/Txgy.RBS.IServices/IGlobalConfigService.cs +++ b/Txgy.RBS.IServices/IGlobalConfigService.cs @@ -19,8 +19,5 @@ namespace Txgy.RBS.IServices GlobalConfigDTO GetGlobalConfig(int id); List GetAllGlobalConfig(); - - int StartProcess(ProcessInfo proInfo); - } } diff --git a/Txgy.RBS.IServices/IProjectInfoService.cs b/Txgy.RBS.IServices/IProjectInfoService.cs index 66cb0bd..accb449 100644 --- a/Txgy.RBS.IServices/IProjectInfoService.cs +++ b/Txgy.RBS.IServices/IProjectInfoService.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Txgy.RBS.DTO; +using Txgy.RBS.Framework; using Txgy.RBS.Framework.Api; using Txgy.RBS.IServices; @@ -23,6 +24,14 @@ namespace Txgy.RBS.IServices ProjectUsedDTO GetCurrentProjectUsed(); - ApiResult StartProject(bool isStart); + ApiResult UpdateCurrentProjectUsed(ProjectUsedDTO projectUsed); + + ApiResult StartProject(string projectName, ProcessConfig processConfig); + + ApiResult StopProject(string ProjectName); + + ApiResult GetState(string projectName,int id); + + ApiResult ExportCSV(string fileName, List stations); } } diff --git a/Txgy.RBS.IServices/IResultInfoService.cs b/Txgy.RBS.IServices/IResultInfoService.cs index 4e70673..fa2649f 100644 --- a/Txgy.RBS.IServices/IResultInfoService.cs +++ b/Txgy.RBS.IServices/IResultInfoService.cs @@ -12,15 +12,15 @@ namespace Txgy.RBS.IServices { public interface IResultInfoService : IBaseService { - ApiResult AddResultInfo(ResultJsonDTO resultJsonDTO); + ApiResult AddResultInfo(ResultDTO resultJsonDTO); ApiResult DeleteResultInfo(int id); - ApiResult UpdateResultInfo(ResultJsonDTO resultJsonDTO); + ApiResult UpdateResultInfo(ResultDTO resultJsonDTO); - ResultJsonDTO GetResultInfo(int id); + ResultDTO GetResultInfo(int id); - List GetAllResultInfo(); + List GetAllResultInfo(); } } diff --git a/Txgy.RBS.IServices/IStationsService.cs b/Txgy.RBS.IServices/IStationsService.cs index 19ac1b2..4628be0 100644 --- a/Txgy.RBS.IServices/IStationsService.cs +++ b/Txgy.RBS.IServices/IStationsService.cs @@ -11,15 +11,17 @@ namespace Txgy.RBS.IServices { public interface IStationsService : IBaseService { - ApiResult AddStations(StationsDTO stationsDTO); + ApiResult AddStations(StationDTO stationsDTO); ApiResult DeleteStations(int id); - ApiResult UpdateStations(StationsDTO stationsDTO); + ApiResult UpdateStations(StationDTO stationsDTO); - StationsDTO GetStations(int id); + StationDTO GetStations(int id); - List GetAllStations(); - + List GetAllStations(); + + List GetStationNumVpn(); + } } diff --git a/Txgy.RBS.IServices/Txgy.RBS.IServices.csproj b/Txgy.RBS.IServices/Txgy.RBS.IServices.csproj index 793175b..5d6174e 100644 --- a/Txgy.RBS.IServices/Txgy.RBS.IServices.csproj +++ b/Txgy.RBS.IServices/Txgy.RBS.IServices.csproj @@ -8,6 +8,8 @@ + + diff --git a/Txgy.RBS.Server.WebApi/Controllers/ProjectInfoController.cs b/Txgy.RBS.Server.WebApi/Controllers/ProjectInfoController.cs index e46c191..ecdb3bc 100644 --- a/Txgy.RBS.Server.WebApi/Controllers/ProjectInfoController.cs +++ b/Txgy.RBS.Server.WebApi/Controllers/ProjectInfoController.cs @@ -1,6 +1,12 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; +using Newtonsoft.Json; +using System.IO; +using System.Security.Policy; using Txgy.RBS.DTO; +using Txgy.RBS.Framework; using Txgy.RBS.Framework.Api; +using Txgy.RBS.Framework.Models; using Txgy.RBS.IServices; using Txgy.RBS.Services; @@ -13,18 +19,22 @@ namespace Txgy.RBS.Server.WebApi.Controllers public class ProjectInfoController : ControllerBase { private readonly IProjectInfoService _projectInfoService; + private readonly IStationsService _stationsService; + private readonly ProcessConfig _processConfig; - public ProjectInfoController(ILogger logger, IProjectInfoService projectInfoService) + public ProjectInfoController(ILogger logger, IProjectInfoService projectInfoService,IStationsService stationsService, IConfiguration configuration) { this._projectInfoService = projectInfoService; + this._stationsService = stationsService; + this._processConfig = configuration.GetSection("process").Get(); } - + [HttpPost] public ApiResult AddProjectInfo(ProjectInfoDTO project) { return _projectInfoService.AddProjectInfo(project); } - + [HttpDelete("{id}")] public ApiResult DeleteProjectInfo(int id) { @@ -46,7 +56,7 @@ namespace Txgy.RBS.Server.WebApi.Controllers [HttpGet] public List GetAllProjectInfo() { - return _projectInfoService.GetAllProjectInfo(); + return _projectInfoService.GetAllProjectInfo(); } [HttpGet] @@ -55,11 +65,114 @@ namespace Txgy.RBS.Server.WebApi.Controllers return _projectInfoService.GetCurrentProjectUsed(); } - //[HttpPost] - //public void Post([FromBody] string value) - //{ + [HttpPost] + public ApiResult StartProject(ProjectUsedDTO usedDTO) + { + // 更新当前项目配置 + var res = _projectInfoService.UpdateCurrentProjectUsed(usedDTO); + + var curProject = this.GetProjectInfo(usedDTO.current_project_id); + var staVpn = _stationsService.GetStationNumVpn(); + + if (res.Success && curProject != null) + { + + string path = Path.Combine(CommonData.BaseProjectPath, curProject.project_name); + if (!Directory.Exists(path)) + { + var direc = Directory.CreateDirectory(path); + } + string apmApp = Path.Combine(path, _processConfig.Apms.ProPath, _processConfig.Apms.ProName + ".exe"); + if (!System.IO.File.Exists(apmApp)) + { + string sourceFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "program"); + CommonData.CopyFolder(sourceFile, Path.Combine(path, "program")); + } + // 修改配置文件 + string str = System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + CommonData.ApmsDefaultPath); + ApmsModel apm = JsonConvert.DeserializeObject(str); + //station.csv + apm.station = curProject.stationFile.file_name; + _projectInfoService.ExportCSV(Path.Combine(path, "program\\apms", apm.station), curProject.stationFile.stations); + //time_tab + apm.ttime[0].ttime2d = curProject.timeTab.filename; + System.IO.File.WriteAllText(Path.Combine(path, "program\\apms", curProject.timeTab.filename), curProject.timeTab.file_content); - //} + apm.is_write_slice = (curProject.local_save_result == 1) ? "YES" : "NO"; + apm.savepath = Path.Combine(CommonData.BaseProjectPath, curProject.project_name, curProject.save_result_path) ; + apm.push_mag = curProject.push_wx_value; + apm.channels = new List + { + new StationChannelsModel + { + channels = curProject.channels, + location = curProject.location, + network = curProject.network, + station=string.Join(",", curProject.stationFile.stations.Select(p=>p.num)), + } + }; + apm.xmin = (float)curProject.xmin; + apm.xmax = (float)curProject.xmax; + apm.ymin = (float)curProject.ymin; + apm.ymax = (float)curProject.ymax; + apm.zmin = (float)curProject.zmin; + apm.zmax = (float)curProject.zmax; + string apmJson = JsonConvert.SerializeObject(apm, Formatting.Indented); + System.IO.File.WriteAllText(Path.Combine(path, CommonData.ApmsDefaultPath), apmJson); + _processConfig.Apms.ProPath = Path.Combine(path, _processConfig.Apms.ProPath); + + //修改recvMqtt配置 + str = System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + CommonData.RecvDefaultPath); + var rec = JsonConvert.DeserializeObject(str); + if (rec != null) + { + rec.savepath = Path.Combine(CommonData.BaseProjectPath, curProject.project_name, curProject.save_waves_path); + rec.send2server = (curProject.send_redis == 1) ? "YES" : "NO"; + rec.Server = curProject.mqtt_server; + List< StationNumVpnDTO> vpnList=new List< StationNumVpnDTO>(); + foreach (var item in curProject.stationFile.stations) + { + var v= staVpn.Where(p => p.num == item.num).FirstOrDefault(); + if (v != null) + { + vpnList.Add(v); + } + } + rec.Stations = string.Join(",", vpnList.Select(p => p.vpn_name)); + rec.dirstruct = curProject.local_save_waves == 1 ? "NMDHM" : "NMDHM0"; + string recvJson = JsonConvert.SerializeObject(rec, Formatting.Indented); + System.IO.File.WriteAllText(Path.Combine(path, CommonData.RecvDefaultPath), recvJson); + _processConfig.RecvMqtt.ProPath = Path.Combine(path, _processConfig.RecvMqtt.ProPath); + } + _processConfig.Server.ProPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _processConfig.Server.ProPath); + res= _projectInfoService.StartProject(curProject.project_name, _processConfig); + res.Data = curProject; + } + return res; + } + [HttpPost] + public ApiResult StopProject(ProjectUsedDTO usedDTO) + { + // 更新当前项目配置 + var res = _projectInfoService.UpdateCurrentProjectUsed(usedDTO); + var curProject = this.GetProjectInfo(usedDTO.current_project_id); + if (res.Success && curProject != null) + { + res= _projectInfoService.StopProject(curProject.project_name); + res.Data = curProject; + } + return res; + } + [HttpGet] + public ApiResult GetProjectProcessState(string projectName, int id) + { + ApiResult result = new ApiResult(); + + result = _projectInfoService.GetState(projectName, id); + return result; + } + } + } diff --git a/Txgy.RBS.Server.WebApi/Controllers/ResultInfoController.cs b/Txgy.RBS.Server.WebApi/Controllers/ResultInfoController.cs index 9893d75..fde3b5b 100644 --- a/Txgy.RBS.Server.WebApi/Controllers/ResultInfoController.cs +++ b/Txgy.RBS.Server.WebApi/Controllers/ResultInfoController.cs @@ -19,9 +19,9 @@ namespace Txgy.RBS.Server.WebApi.Controllers this._resultInfoService = resultInfoService; } [HttpPost] - public ApiResult AddProjectInfo(ResultJsonDTO resultJsonDTO) + public ApiResult AddProjectInfo(ResultDTO resultDTO) { - return _resultInfoService.AddResultInfo(resultJsonDTO); + return _resultInfoService.AddResultInfo(resultDTO); } [HttpDelete("{id}")] @@ -31,19 +31,19 @@ namespace Txgy.RBS.Server.WebApi.Controllers } [HttpPost] - public ApiResult UpdateResultInfo(ResultJsonDTO resultJsonDTO) + public ApiResult UpdateResultInfo(ResultDTO resultDTO) { - return _resultInfoService.UpdateResultInfo(resultJsonDTO); + return _resultInfoService.UpdateResultInfo(resultDTO); } [HttpGet("{id}")] - public ResultJsonDTO GetProjectInfo(int id) + public ResultDTO GetResultInfo(int id) { return _resultInfoService.GetResultInfo(id); } [HttpGet] - public List GetAllResultInfo() + public List GetAllResultInfo() { return _resultInfoService.GetAllResultInfo(); } diff --git a/Txgy.RBS.Server.WebApi/Controllers/StationsController.cs b/Txgy.RBS.Server.WebApi/Controllers/StationsController.cs index 28e41d4..7bc5904 100644 --- a/Txgy.RBS.Server.WebApi/Controllers/StationsController.cs +++ b/Txgy.RBS.Server.WebApi/Controllers/StationsController.cs @@ -19,7 +19,7 @@ namespace Txgy.RBS.Server.WebApi.Controllers } [HttpPost] - public ApiResult AddStations(StationsDTO stationsDTO) + public ApiResult AddStations(StationDTO stationsDTO) { return _stationsService.AddStations(stationsDTO); } @@ -31,21 +31,27 @@ namespace Txgy.RBS.Server.WebApi.Controllers } [HttpPost] - public ApiResult UpdateStations(StationsDTO stationsDTO) + public ApiResult UpdateStations(StationDTO stationsDTO) { return _stationsService.UpdateStations(stationsDTO); } [HttpGet("{id}")] - public StationsDTO GetStations(int id) + public StationDTO GetStations(int id) { return _stationsService.GetStations(id); } [HttpGet] - public List GetAllStationss() + public List GetAllStationss() { return _stationsService.GetAllStations(); } + + [HttpGet] + public List GetStationNumVpn() + { + return _stationsService.GetStationNumVpn(); + } } } diff --git a/Txgy.RBS.Server.WebApi/Program.cs b/Txgy.RBS.Server.WebApi/Program.cs index 65d878a..69a7765 100644 --- a/Txgy.RBS.Server.WebApi/Program.cs +++ b/Txgy.RBS.Server.WebApi/Program.cs @@ -17,7 +17,8 @@ builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); - +// ñػ +builder.Services.AddMemoryCache(); var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/Txgy.RBS.Server.WebApi/Register/HostBuilderExtend.cs b/Txgy.RBS.Server.WebApi/Register/HostBuilderExtend.cs index 54ba832..5869b67 100644 --- a/Txgy.RBS.Server.WebApi/Register/HostBuilderExtend.cs +++ b/Txgy.RBS.Server.WebApi/Register/HostBuilderExtend.cs @@ -1,9 +1,12 @@ using Autofac; using Autofac.Extensions.DependencyInjection; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; using SqlSugar; using System.Reflection; +using Txgy.RBS.Framework; using Txgy.RBS.Framework.RedisHelper.Service; +using Txgy.RBS.Services; namespace Txgy.RBS.Server.WebApi.Register { @@ -23,7 +26,8 @@ namespace Txgy.RBS.Server.WebApi.Register Assembly serviceAssembly = Assembly.Load("Txgy.RBS.IServices"); ConfigurationBinder.RegisterAssemblyTypes(interfaceAssembly, serviceAssembly).AsImplementedInterfaces(); #endregion - + var pro= applicationBuilder.Configuration.GetSection("process").Get(); + ConfigurationBinder.RegisterType().SingleInstance(); #region 注册每个控制器和抽象之间的关系 var controllerBaseType = typeof(ControllerBase); ConfigurationBinder.RegisterAssemblyTypes(typeof(Program).Assembly) diff --git a/Txgy.RBS.Server.WebApi/Txgy.RBS.Server.WebApi.csproj b/Txgy.RBS.Server.WebApi/Txgy.RBS.Server.WebApi.csproj index 3513498..11418b6 100644 --- a/Txgy.RBS.Server.WebApi/Txgy.RBS.Server.WebApi.csproj +++ b/Txgy.RBS.Server.WebApi/Txgy.RBS.Server.WebApi.csproj @@ -9,6 +9,8 @@ + + diff --git a/Txgy.RBS.Server.WebApi/appsettings.json b/Txgy.RBS.Server.WebApi/appsettings.json index 7101cda..cfff6b9 100644 --- a/Txgy.RBS.Server.WebApi/appsettings.json +++ b/Txgy.RBS.Server.WebApi/appsettings.json @@ -10,38 +10,41 @@ "ConnectionSqlite": "Data Source=rbs_server_db.db", "ConnectionType": "0" }, - "Server": { - "ProName": "server", - "ProTitle": "服务", - "IsEnable": true, - "ProPath": "program\\server\\", - "ProParams": "service.conf", - "JsonPath": null, - "Pid": 0, - "OperationStr": "open", - "ShowState": 0 - }, - "RecvMqtt": { - "ProName": "gw.recvmqtt", - "ProTitle": "数据接收", - "IsEnable": true, - "ProPath": "program\\recvmqtt\\", - "ProParams": "-cfg gw.recvmqtt.all.json >outRecv.txt", - "JsonPath": "gw.recvmqtt.json", - "Pid": 0, - "OperationStr": "open", - "ShowState": 0 - }, - "Apms": { - "ProName": "gw.apms", - "ProTitle": "实时处理", - "IsEnable": true, - "ProPath": "program\\apms\\", - "ProParams": "-cfg apms.json >outApms.txt", - "JsonPath": "apms.json", - "Pid": 0, - "OperationStr": "open", - "ShowState": 0 + "process": { + + "Server": { + "ProName": "server", + "ProTitle": "服务", + "IsEnable": true, + "ProPath": "program\\server\\", + "ProParams": "service.conf", + "JsonPath": null, + "Pid": 0, + "OperationStr": "open", + "ShowState": 0 + }, + "RecvMqtt": { + "ProName": "gw.recvmqtt", + "ProTitle": "数据接收", + "IsEnable": true, + "ProPath": "program\\recvmqtt\\", + "ProParams": "-cfg gw.recvmqtt.json >outRecv.txt", + "JsonPath": "gw.recvmqtt.json", + "Pid": 0, + "OperationStr": "open", + "ShowState": 0 + }, + "Apms": { + "ProName": "gw.apms", + "ProTitle": "实时处理", + "IsEnable": true, + "ProPath": "program\\apms\\", + "ProParams": "-cfg gw.apms.json >outApms.txt", + "JsonPath": "gw.apms.json", + "Pid": 0, + "OperationStr": "open", + "ShowState": 0 + } }, "AllowedHosts": "*" } diff --git a/Txgy.RBS.Server.WebApi/rbs_server_db.db b/Txgy.RBS.Server.WebApi/rbs_server_db.db index bf2acf2..8325613 100644 Binary files a/Txgy.RBS.Server.WebApi/rbs_server_db.db and b/Txgy.RBS.Server.WebApi/rbs_server_db.db differ diff --git a/Txgy.RBS.Services/GlobalConfigService.cs b/Txgy.RBS.Services/GlobalConfigService.cs index 3e2feb7..759f412 100644 --- a/Txgy.RBS.Services/GlobalConfigService.cs +++ b/Txgy.RBS.Services/GlobalConfigService.cs @@ -66,162 +66,5 @@ namespace Txgy.RBS.Services } return new ApiResult() { Message = "更新失败" }; } - - #region 方法 - private bool CMDStartProcess(ProcessInfo proInfo) - { - //* Create your Process - Process process = new Process(); - process.Exited += Process_Exited; - process.EnableRaisingEvents = true; - process.StartInfo.FileName = Path.GetFullPath(proInfo.ProPath + proInfo.ProName + ".exe"); - process.StartInfo.WorkingDirectory = Path.GetFullPath(proInfo.ProPath); - process.StartInfo.Arguments = proInfo.ProParams; - Debug.WriteLine($"*******name:{process.StartInfo.FileName}, arguments:{process.StartInfo.Arguments}*********"); - process.StartInfo.UseShellExecute = false; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.RedirectStandardError = true; - process.StartInfo.CreateNoWindow = true; - //* Set your output and error (asynchronous) handlers - { - process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler); - process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler); - } - //* Start process and handlers - bool res = process.Start(); - process.BeginOutputReadLine(); - process.BeginErrorReadLine(); - // process.WaitForExit(); - return res; - } - - private void Process_Exited(object? sender, EventArgs e) - { - - } - - void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine) - { - Debug.WriteLine("output*************:{0},{1}", sendingProcess.ToString(), outLine.Data); - if (string.IsNullOrEmpty(outLine.Data)) return; - if (outLine.Data.Contains("ProcessSlice:")) - { - var pro = sendingProcess as Process; - if (pro != null) - { - - } - } - else if (outLine.Data.Contains("ML ")) - { - var pro = sendingProcess as Process; - if (pro != null) - { - - } - } - } - - - public int StartProcess(ProcessInfo proInfo) - { - bool res = CMDStartProcess(proInfo); - int seInd = res ? 0 : 37; - return seInd; - } - /// - /// 结束进程 - /// - /// - /// 0=成功;1=未找到进程;-1=失败 - private int KillProcess(ProcessInfo processInfo) - { - int ri = 0; - if (processInfo != null) - { - if (processInfo.ProName != null) - { - try - { - Process[] localByName = Process.GetProcessesByName(processInfo.ProName); - if (localByName.Length == 0) - { - ri = 1; - return ri; - } - foreach (var item in localByName) - { - Console.WriteLine(item.Id); - item.Kill(); - } - return ri; - } - catch (Exception) - { - return -1; - } - } - else - { - return 0; - } - } - else - { - return 0; - } - } - - /// - /// 查找进程 - /// - /// - /// 0=正在运行;1=未运行;-1=系统错误 - private int FindProcess(ProcessInfo processInfo) - { - int ri = 0; - try - { - Process[] localByName = Process.GetProcessesByName(processInfo.ProName); - if (localByName.Length == 0) - { - ri = 1; - return ri; - } - return ri; - } - catch (Exception) - { - return -1; - } - } - - public string ProcessStatus { get; set; } - - public void GetState(List< ProcessInfo> processes) - { - foreach (var item in processes) - { - var pro = item; - if (pro != null ) - { - int sfp = FindProcess(pro); - - if (sfp == 0) - { - ProcessStatus = "正常运行"; - } - else - { - ProcessStatus = "重启中"; - StartProcess(pro); - Thread.Sleep(20); - } - } - } - } - - #endregion - } } diff --git a/Txgy.RBS.Services/ProcessManagerService.cs b/Txgy.RBS.Services/ProcessManagerService.cs new file mode 100644 index 0000000..a437174 --- /dev/null +++ b/Txgy.RBS.Services/ProcessManagerService.cs @@ -0,0 +1,396 @@ +using System.Diagnostics; +using Txgy.RBS.Framework.Api; +using Txgy.RBS.Framework; +using Microsoft.Extensions.Caching.Memory; +using System.Collections.Concurrent; +using ServiceStack; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using Newtonsoft.Json.Linq; +using System.Data; +using Txgy.RBS.DTO; +using Aspose.Cells; +using Txgy.RBS.Framework.Models; + +namespace Txgy.RBS.Services +{ + public class ProcessManagerService + { + private readonly IMemoryCache _cache; + + public ProcessManagerService( IMemoryCache cache) + { + _cache = cache; + MoniTimer.Interval = 10000; + MoniTimer.Elapsed += MoniTimer_Elapsed; + MoniTimer.Start(); + } + + private void MoniTimer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e) + { + foreach (var item in ProjectMonitor) + { + foreach (var proValue in item.Value.GetType().GetProperties()) + { + var pro = proValue.GetValue(item.Value) as ProcessInfo; + if (pro != null) + { + int sfp = FindProcess(pro); + if (sfp != 0) + { + Console.WriteLine($"{pro.ProName}程序重启中,path:{pro.ProPath}"); + StartProcess(pro); + Thread.Sleep(20); + } + } + } + } + } + + public ConcurrentDictionary ProjectMonitor = new ConcurrentDictionary(); + + public void StartMointor(string projectName, ProcessConfig processInfo) + { + if (!ProjectMonitor.ContainsKey(projectName)) + { + ProjectMonitor.TryAdd(projectName, processInfo); + } + } + System.Timers.Timer MoniTimer { get; set; } = new System.Timers.Timer(); + public void StopMointor(string projectName) + { + if (ProjectMonitor.ContainsKey(projectName)) + { + ProjectMonitor.TryRemove(projectName, out ProcessConfig pro); + } + } + + #region 方法 + + public ApiResult StartProject(string projectName, ProcessConfig processConfig) + { + int res = 0; + if (ProjectMonitor.ContainsKey(projectName)) new ApiResult(); + foreach (var item in processConfig.GetType().GetProperties()) + { + var pro = item.GetValue(processConfig) as ProcessInfo; + if (pro != null && pro.IsEnable) + { + res = StartProcess(pro); + if (res != 0) + { + break; + } + pro.StartTime = DateTime.Now; + pro.State = true; + _cache.Set(pro.ProPath, pro); + Thread.Sleep(10); + } + } + StartMointor(projectName, processConfig); + + if (res == 0) + { + return new ApiResult(); + } + return new ApiResult() { Message = "操作失败" }; + + } + + public ApiResult StopProject(string projectName) + { + int res = 0; + ProjectMonitor.TryGetValue(projectName, out ProcessConfig process); + if(process == null) { return new ApiResult(); } + foreach (var item in process.GetType().GetProperties()) + { + var pro = item.GetValue(process) as ProcessInfo; + if (pro != null && pro.IsEnable) + { + res = KillProcess(pro); + if (res != 0) + { + break; + } + pro.State = false; + _cache.Set(pro.ProPath, pro); + Thread.Sleep(10); + } + } + StopMointor(projectName); + if (res == 0) + { + return new ApiResult(); + } + return new ApiResult() { Message = "操作失败" }; + } + + private bool CMDStartProcess(ProcessInfo proInfo) + { + //* Create your Process + Process process = new Process(); + process.Exited += Process_Exited; + process.EnableRaisingEvents = true; + process.StartInfo.FileName = Path.GetFullPath(Path.Combine(proInfo.ProPath, proInfo.ProName + ".exe")); + process.StartInfo.WorkingDirectory = Path.GetFullPath(proInfo.ProPath); + process.StartInfo.Arguments = proInfo.ProParams; + Debug.WriteLine($"*******ProcessName:{process.StartInfo.FileName}, arguments:{process.StartInfo.Arguments}*********"); + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = true; + process.StartInfo.CreateNoWindow = true; + //* Set your output and error (asynchronous) handlers + { + process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler); + process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler); + } + //* Start process and handlers + bool res = process.Start(); + process.BeginOutputReadLine(); + process.BeginErrorReadLine(); + // process.WaitForExit(); + return res; + } + + private void Process_Exited(object? sender, EventArgs e) + { + + } + + void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine) + { + Debug.WriteLine("output*************:{0},{1}", sendingProcess.ToString(), outLine.Data); + if (string.IsNullOrEmpty(outLine.Data)) return; + if (outLine.Data.Contains("ProcessSlice:")) + { + var pro = sendingProcess as Process; + if (pro != null) + { + + } + } + else if (outLine.Data.Contains("ML ")) + { + var pro = sendingProcess as Process; + if (pro != null) + { + var msEvent= new MsEventModel(outLine.Data) { CurrentTime = DateTime.Now }; + Console.WriteLine($"processName:{pro.ProcessName},message:{outLine.Data}"); + } + } + } + + public int StartProcess(ProcessInfo proInfo) + { + bool res = CMDStartProcess(proInfo); + int seInd = res ? 0 : 1; + return seInd; + } + /// + /// 结束进程 + /// + /// + /// 0=成功;1=未找到进程;-1=失败 + private int KillProcess(ProcessInfo processInfo) + { + int ri = 0; + if (processInfo != null) + { + if (processInfo.ProName != null) + { + try + { + Process[] localByName = Process.GetProcessesByName(processInfo.ProName); + if (localByName.Length == 0) + { + ri = 1; + return ri; + } + foreach (var item in localByName) + { + item.Kill(); + } + return ri; + } + catch (Exception) + { + return -1; + } + } + else + { + return 0; + } + } + else + { + return 0; + } + } + + /// + /// 查找进程 + /// + /// + /// 0=正在运行;1=未运行;-1=系统错误 + private int FindProcess(ProcessInfo processInfo) + { + int ri = 0; + try + { + Process[] localByName = Process.GetProcessesByName(processInfo.ProName); + if (localByName.Length == 0) + { + ri = 1; + return ri; + } + else + { + var pro= localByName.Where(p => p.MainModule.FileName.Contains(processInfo.ProPath)); + if (!pro.Any()) + { + ri = 1; + } + return ri; + } + } + catch (Exception) + { + return -1; + } + } + + public string ProcessStatus { get; set; } + + + public ApiResult GetState(string projectName, int id) + { + ProjectMonitor.TryGetValue(projectName, out ProcessConfig process); + if (process == null|| (id<1 || id>3)) { return new ApiResult(); } + ProcessInfo pro = id == 1 ? process.Server : id == 2 ? process.Apms : process.RecvMqtt; + int sfp = FindProcess(pro); + if (sfp != 0) + { + return new ApiResult { Code = System.Net.HttpStatusCode.NotFound }; + } + return new ApiResult + { + Code = System.Net.HttpStatusCode.OK, Data = new + { + name=pro.ProName, + state= sfp == 0 ? 1 : 0, + start_time=pro.StartTime, + running_time=(DateTime.Now-pro.StartTime).TotalSeconds, + } + }; + } + + #endregion + + + + public ApiResult ExportCSV(string fileName, List stations) + { + DataTable dataTable = new DataTable(); + string[] header = new string[] { "project_id", "net", "sta"," x2000", "y2000", "z2000", "sens", "begin", "stop", "sitenum" }; + DataColumn da = new DataColumn(); + foreach (var item in header) + { + dataTable.Columns.Add(item, typeof(string)); + } + foreach (var sta in stations) + { + dataTable.Rows.Add(sta.project_id, sta.network,sta.num,sta.coord_e,sta.coord_n,sta.altitude,sta.sens,sta.begin_time,sta.end_time,sta.site_number); + } + return ExportExcel(fileName,dataTable, header); + } + /// 导出csv表格 + /// + /// 数据集合 + /// 数据表头 + /// 标题 + /// + private ApiResult ExportExcel(string fileName, DataTable dt, string[] header, string title = null) + { + Workbook wb = new Workbook(); + try + { + Worksheet sheet = wb.Worksheets[0]; + sheet.Name = "station数据"; + if (dt.Rows.Count <= 0) + { + return new ApiResult() { Code= System.Net.HttpStatusCode.NoContent,Message="没有数据"}; + } + // 为单元格添加样式 + Aspose.Cells.Style style = wb.CreateStyle(); + //style.HorizontalAlignment = Aspose.Cells.TextAlignmentType.Center; //设置居中 + style.Font.Size = 20;//文字大小 + style.Font.IsBold = true;//粗体 + style.HorizontalAlignment = TextAlignmentType.Center;//文字居中 + + // 为合计单元格样式 + Aspose.Cells.Style sumstyle = wb.CreateStyle(); + sumstyle.Font.Size = 12;//文字大小 + sumstyle.Font.IsBold = true;//粗体 + sumstyle.Font.Color = System.Drawing.Color.Red; //颜色 + //style.HorizontalAlignment = TextAlignmentType.Center;//文字居中 + + //添加标题 + int rowIndex = 0; + sheet.Cells.SetRowHeight(rowIndex, 40); //设置行高 + if (title != null) + { + sheet.Cells[rowIndex, 0].PutValue(title); + sheet.Cells[rowIndex, 0].SetStyle(style); + sheet.Cells.Merge(0, 0, 1, header.Length); //合并行 Merge(1, 1,1, 5); 第一行 第一列 到 第一行 第 5列 + //Merge切记后两位参数不能是 0 + rowIndex++; + } + //添加表头 + style.Font.Size = 12;//文字大小 + sheet.Cells.SetRowHeight(rowIndex, 20); //设置行高 + for (int c = 0; c < header.Length; c++) + { + sheet.Cells[rowIndex, c].PutValue(header[c]); + sheet.Cells[rowIndex, c].SetStyle(style); + sheet.Cells.SetColumnWidth(c, 20);//设置宽度 + } + rowIndex++; + + //添加内容 + for (int r = 0; r < dt.Rows.Count; r++)//遍历DataTable行 + { + for (int c = 0; c < header.Length; c++) //列只遍历到和表头数量相等的列,其余的列不导出 + { + //自动把数字变量转出后 单元格变为数字类型。 + try + { + //把添加变量转字符类型存储 + sheet.Cells[r + rowIndex, c].PutValue(dt.Rows[r][c].ToString()); + + // sheet.Cells[r + rowIndex, c].PutValue(Convert.ToDecimal(dt.Rows[r][c])); //要导出数字列是数字类型,必须把添加变量转数字类型。 + } + catch + { + //把添加变量转字符类型存储 + sheet.Cells[r + rowIndex, c].PutValue(dt.Rows[r][c].ToString()); + } + } + } + //输出到Excel + wb.Save(fileName, new OoxmlSaveOptions(SaveFormat.Csv)); + //保存成97或2003写法 + //workbook.Save(“output.xls, New XlsSaveOptions(SaveFormat.Excel97To2003)) + // 释放Excel对象 + sheet.Dispose(); + wb.Dispose(); + } + catch (Exception e) + { + return new ApiResult() { Code = System.Net.HttpStatusCode.NoContent, Message = $"保存{fileName}文件异常:{e.Message}" }; + } + return new ApiResult(); + } + + } +} diff --git a/Txgy.RBS.Services/ProjectInfoService.cs b/Txgy.RBS.Services/ProjectInfoService.cs index 1547d28..879c5e6 100644 --- a/Txgy.RBS.Services/ProjectInfoService.cs +++ b/Txgy.RBS.Services/ProjectInfoService.cs @@ -1,12 +1,15 @@ using AutoMapper; +using Microsoft.Extensions.Caching.Memory; using SqlSugar; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using Txgy.RBS.DbModel.Models; using Txgy.RBS.DTO; +using Txgy.RBS.Framework; using Txgy.RBS.Framework.Api; using Txgy.RBS.IServices; @@ -15,19 +18,22 @@ namespace Txgy.RBS.Services public class ProjectInfoService : BaseService, IProjectInfoService { private readonly IMapper _iMapper; + private readonly ProcessManagerService _processManager; + private readonly IMemoryCache _cache; - public ProjectInfoService(ISqlSugarClient client, IMapper iMapper) : base(client) + public ProjectInfoService(ISqlSugarClient client, IMapper iMapper, ProcessManagerService processManager) : base(client) { this._iMapper = iMapper; + this._processManager = processManager; } public ApiResult AddProjectInfo(ProjectInfoDTO project) { - int res = 0; project_info project_Info = _iMapper.Map(project); - res = _Client.Insertable(project_Info).ExecuteCommand(); - if (res > 0) + var pro = _Client.InsertNav(project_Info).Include(p=>p.stationFile).ThenInclude(t=>t.stations) + .Include(time => time.time_tab).ExecuteCommand(); + if (pro) { return new ApiResult(); } @@ -36,8 +42,9 @@ namespace Txgy.RBS.Services public ApiResult DeleteProjectInfo(int id) { - int res= _Client.Deleteable(p=>p.id==id).ExecuteCommand(); - if (res > 0) + var res = _Client.DeleteNav(p => p.id == id).Include(p => p.stationFile).ThenInclude(t => t.stations) + .Include(time => time.time_tab).ExecuteCommand(); + if (res) { return new ApiResult(); } @@ -46,8 +53,10 @@ namespace Txgy.RBS.Services public List GetAllProjectInfo() { - var projects = _Client.Queryable().ToList(); - return _iMapper.Map>(projects); + var projects = _Client.Queryable().Includes(x => x.stationFile, t=>t.stations) + .Includes(ti=>ti.time_tab).ToList(); + var projectDTOs= _iMapper.Map>(projects); + return projectDTOs; } public ProjectUsedDTO GetCurrentProjectUsed() @@ -57,44 +66,69 @@ namespace Txgy.RBS.Services return projectUse; } - //public ProjectInfoDTO GetCurrentProjectInfo() - //{ - // var curProject = _Client.Queryable().First(); - // project_info projectInfo = _Client.Queryable().First(c => c.id == curProject.current_project_id); - // ProjectInfoDTO projectInfoDTO = _iMapper.Map(projectInfo); - // return projectInfoDTO; - //} - - - + public ApiResult UpdateProjectInfo(ProjectInfoDTO project) + { + project_info projectInfo = _iMapper.Map(project); + var res = _Client.UpdateNav(projectInfo).Include(p => p.stationFile).ThenInclude(t => t.stations) + .Include(time => time.time_tab).ExecuteCommand(); + if (res) + { + return new ApiResult(); + } + return new ApiResult() { Message = "更新失败" }; + } + public ProjectInfoDTO GetProjectInfo(int id) { - project_info projectInfo = _Client.Queryable().First(c => c.id == id); + project_info projectInfo = _Client.Queryable().Includes(x => x.stationFile, t => t.stations).Includes(ti => ti.time_tab).Where(p => p.id == id).First(); ProjectInfoDTO projectInfoDTO = _iMapper.Map(projectInfo); + + //test + //if (projectInfoDTO != null) + //{ + // projectInfoDTO.id = 6; + // projectInfoDTO.project_id = 9; + // projectInfoDTO.project_name = "tea"; + // projectInfoDTO.moni_layer = 1; + // projectInfoDTO.moni_num = 8; + // var a = UpdateProjectInfo(projectInfoDTO); + //} return projectInfoDTO; } - public ApiResult StartProject(bool isStart) - { - int res = 0; - if (res == 0) + public ApiResult UpdateCurrentProjectUsed(ProjectUsedDTO projectUsed) + { + var pro=_iMapper.Map(projectUsed); + var res= _Client.Updateable(pro).ExecuteCommand(); + if (res>0) { return new ApiResult(); } return new ApiResult() { Message = "更新失败" }; + } + public ApiResult StartProject(string projectName, ProcessConfig processConfig) + { + var res = _processManager.StartProject(projectName, processConfig); + return res; + } + public ApiResult StopProject(string projectName) + { + var res = _processManager.StopProject(projectName); + return res; } + public ApiResult GetState(string projectName, int id) + { - public ApiResult UpdateProjectInfo(ProjectInfoDTO project) + return _processManager.GetState(projectName, id); + } + + + public ApiResult ExportCSV(string fileName, List stations) { - project_info projectInfo = _iMapper.Map (project); - int res= _Client.Updateable(projectInfo).ExecuteCommand(); - if(res > 0) - { - return new ApiResult(); - } - return new ApiResult() { Message = "更新失败" }; + return _processManager.ExportCSV(fileName, stations); } + } } diff --git a/Txgy.RBS.Services/ResultInfoService.cs b/Txgy.RBS.Services/ResultInfoService.cs index 42c84d4..647411e 100644 --- a/Txgy.RBS.Services/ResultInfoService.cs +++ b/Txgy.RBS.Services/ResultInfoService.cs @@ -21,10 +21,10 @@ namespace Txgy.RBS.Services this._iMapper = iMapper; } - public ApiResult AddResultInfo(ResultJsonDTO resultJsonDTO) + public ApiResult AddResultInfo(ResultDTO resultJsonDTO) { int res = 0; - result_json result_Json = _iMapper.Map(resultJsonDTO); + result result_Json = _iMapper.Map(resultJsonDTO); res = _Client.Insertable(result_Json).ExecuteCommand(); if (res > 0) @@ -36,7 +36,7 @@ namespace Txgy.RBS.Services public ApiResult DeleteResultInfo(int id) { - int res= _Client.Deleteable(p=>p.id==id).ExecuteCommand(); + int res= _Client.Deleteable(p=>p.id==id).ExecuteCommand(); if (res > 0) { return new ApiResult(); @@ -44,24 +44,24 @@ namespace Txgy.RBS.Services return new ApiResult() { Message = "删除失败" }; } - public List GetAllResultInfo() + public List GetAllResultInfo() { - var projects = _Client.Queryable().ToList(); - return _iMapper.Map>(projects); + var projects = _Client.Queryable().ToList(); + return _iMapper.Map>(projects); } - public ResultJsonDTO GetResultInfo(int id) + public ResultDTO GetResultInfo(int id) { - result_json result_Json = _Client.Queryable().First(c => c.id == id); - ResultJsonDTO resultJsonDTO = _iMapper.Map(result_Json); + result result_Json = _Client.Queryable().First(c => c.id == id); + ResultDTO resultJsonDTO = _iMapper.Map(result_Json); return resultJsonDTO; } - public ApiResult UpdateResultInfo(ResultJsonDTO resultJsonDTO) + public ApiResult UpdateResultInfo(ResultDTO resultJsonDTO) { - result_json result_Json = _iMapper.Map (resultJsonDTO); - int res= _Client.Updateable(result_Json).ExecuteCommand(); + result result_Json = _iMapper.Map (resultJsonDTO); + int res= _Client.Updateable(result_Json).ExecuteCommand(); if(res > 0) { return new ApiResult(); diff --git a/Txgy.RBS.Services/StationsService.cs b/Txgy.RBS.Services/StationsService.cs index 6206904..9abc570 100644 --- a/Txgy.RBS.Services/StationsService.cs +++ b/Txgy.RBS.Services/StationsService.cs @@ -21,10 +21,10 @@ namespace Txgy.RBS.Services this._iMapper = iMapper; } - public ApiResult AddStations(StationsDTO stationsDTO) + public ApiResult AddStations(StationDTO stationsDTO) { int res = 0; - stations station = _iMapper.Map(stationsDTO); + station station = _iMapper.Map(stationsDTO); res = _Client.Insertable(station).ExecuteCommand(); if (res > 0) @@ -36,7 +36,7 @@ namespace Txgy.RBS.Services public ApiResult DeleteStations(int id) { - int res= _Client.Deleteable(p=>p.id==id).ExecuteCommand(); + int res= _Client.Deleteable(p=>p.id==id).ExecuteCommand(); if (res > 0) { return new ApiResult(); @@ -44,24 +44,30 @@ namespace Txgy.RBS.Services return new ApiResult() { Message = "删除失败" }; } - public List GetAllStations() + public List GetAllStations() { - var projects = _Client.Queryable().ToList(); - return _iMapper.Map>(projects); + var projects = _Client.Queryable().ToList(); + return _iMapper.Map>(projects); } + public List GetStationNumVpn() + { + var station = _Client.Queryable().ToList(); + var stationsDTO = _iMapper.Map>(station); + return stationsDTO; + } - public StationsDTO GetStations(int id) + public StationDTO GetStations(int id) { - stations station = _Client.Queryable().First(c => c.id == id); - StationsDTO stationsDTO = _iMapper.Map(station); + station station = _Client.Queryable().First(c => c.id == id); + StationDTO stationsDTO = _iMapper.Map(station); return stationsDTO; } - public ApiResult UpdateStations(StationsDTO stationsDTO) + public ApiResult UpdateStations(StationDTO stationsDTO) { - stations station = _iMapper.Map (stationsDTO); - int res= _Client.Updateable(station).ExecuteCommand(); + station station = _iMapper.Map (stationsDTO); + int res= _Client.Updateable(station).ExecuteCommand(); if(res > 0) { return new ApiResult(); diff --git a/Txgy.RBS.Services/Txgy.RBS.Services.csproj b/Txgy.RBS.Services/Txgy.RBS.Services.csproj index 7a495c9..6defbd2 100644 --- a/Txgy.RBS.Services/Txgy.RBS.Services.csproj +++ b/Txgy.RBS.Services/Txgy.RBS.Services.csproj @@ -7,7 +7,10 @@ + + + diff --git a/program/apms/gw.apms.bat b/program/apms/gw.apms.bat index c0648cc..b69e5c9 100644 --- a/program/apms/gw.apms.bat +++ b/program/apms/gw.apms.bat @@ -1 +1 @@ -start /min gw.apms.exe -cfg gw.apms3.json >out.txt \ No newline at end of file +start /min gw.apms.exe -cfg gw.apms.json >out.txt \ No newline at end of file diff --git a/program/server/server_log.txt b/program/server/server_log.txt index 55a46f1..b3167ca 100644 --- a/program/server/server_log.txt +++ b/program/server/server_log.txt @@ -60,3 +60,9 @@ [4504] 16 Mar 13:33:12.690 # Server initialized [4504] 16 Mar 13:33:12.691 * Ready to accept connections [4504] 19 Mar 15:52:42.085 # Client id=258 addr=116.235.70.136:52939 fd=13 name= age=1945 idle=295 flags=P db=1 sub=33 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=16226 oll=515 omem=10559560 events=rw cmd=subscribe scheduled to be closed ASAP for overcoming of output buffer limits. +[37440] 17 Apr 14:21:54.831 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo +[37440] 17 Apr 14:21:54.832 # Redis version=5.0.10, bits=64, commit=1c047b68, modified=0, pid=37440, just started +[37440] 17 Apr 14:21:54.832 # Configuration loaded +[37440] 17 Apr 14:21:54.835 * Running mode=standalone, port=6379. +[37440] 17 Apr 14:21:54.835 # Server initialized +[37440] 17 Apr 14:21:54.836 * Ready to accept connections