Browse Source

急救相关数据关联数据库

liyang 3 months ago
parent
commit
b51c9a40e9

+ 22 - 2
Models/SimulationCommon/AircraftDB.cs

@@ -67,11 +67,31 @@ public class AircraftDB
 public class YLDB
 {
     public string msg;
+    public tbCommonsDto tbCommonsDto;
     public int code;
-    public string data;
+    public YLDBData[] data;
+}
+
+
+public class tbCommonsDto
+{
+    public string id;
+    public string pid;
+    public string fscene;
+    public string ftype;
+    public string fsubtype;
+    public string fifzs;
+    public string fsubtypeId;
 }
 
 public class YLDBData
 {
-    public double time;
+    public string id;
+    public string tbId;
+    public string fFieldname;
+    public string fFieldalias; //疾病名称 最小黄金救援时间 最大黄金救援时间 优先级 抢救时间
+    public string fFieldtype;
+    public string fFieldunit;
+    public string fValue; //心梗 90 120 1 2
+    public string fPort; 
 }

+ 0 - 3
SimulationServer/Entity/AircraftEntity.cs

@@ -20,8 +20,6 @@ public class AircraftEntity : Entity
     public double TaskResponseTime { get; set; } = 600; // 任务响应时间
     public double EffMisTime { get; set; } // 单机有效任务时长
 
-    public YLDBData ylDb { get; set; } // 医疗数据库参数
-
     public string AircraftType { get; set; } // 飞机类型
 
     //搜索时间
@@ -40,7 +38,6 @@ public class AircraftEntity : Entity
     public void Awake()
     {
         Db = Util.GetAircraftDefine(FlightPlanEditor.aircraftparameter.AircraftType, FlightPlanEditor.aircraftparameter.AircraftSubType, FlightPlanEditor.aircraftparameter.AircraftID);
-        //ylDb = Util.GetYL("20");
 
         if (Db.f_zdqfzl != null)
             FlightPlanEditor.aircraftparameter.MaxTakeoffWeight = double.Parse(Db.f_zdqfzl.ToString());

+ 51 - 82
SimulationServer/Entity/AircraftXCJJ.cs

@@ -27,6 +27,7 @@ public class AircraftXCJJ : AircraftEntity
 
     public string hospitalAirport;
 
+    private Dictionary<string, DiseaseInfo> diseaseDatabase = new Dictionary<string, DiseaseInfo>();
 
     public override void End()
     {
@@ -46,6 +47,22 @@ public class AircraftXCJJ : AircraftEntity
 
     public override void Start()
     {
+        for (int i = 1; i < 19; i++)
+        {
+            string s = Utils.Util.GetYL(i.ToString());
+            string[] r = s.Split('-');
+            diseaseDatabase.Add(r[0], new DiseaseInfo { MinGoldenHour = Convert.ToDouble(r[1]), MaxGoldenHour = Convert.ToDouble(r[2]), Priority = Convert.ToDouble(r[3]), RescueTime = Convert.ToDouble(r[4]) });
+        }
+
+        foreach (var item in diseaseDatabase)
+        {
+            Console.WriteLine("疾病类型:" + item.Key);
+            Console.WriteLine("最小黄金救援时间:" + item.Value.MinGoldenHour);
+            Console.WriteLine("最大黄金救援时间:" + item.Value.MaxGoldenHour);
+            Console.WriteLine("优先级:" + item.Value.Priority);
+            Console.WriteLine("抢救时间:" + item.Value.RescueTime);
+        }
+
         FlightPlanEditor.missionpoint.MissionPointLatitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
         FlightPlanEditor.missionpoint.MissionPointLongitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
         FlightPlanEditor.missionpoint.MissionPointHeight = FlightPlanEditor.medicalTargetPoint[0].TargetPointHeight;
@@ -89,10 +106,10 @@ public class AircraftXCJJ : AircraftEntity
             });
         }
 
-        patients = MedicalRescue.ProcessPatients(patients, rand);
+        patients = ProcessPatients(patients, rand);
 
         // 对患者进行排序  
-        var sortedPatients = patients.OrderBy(p => DiseasePriorityService.GetPriority(p.DiseaseType))
+        var sortedPatients = patients.OrderBy(p => GetPriority(p.DiseaseType))
                                     .ThenBy(p => p.GoldenHour)
                                     .ToList();
 
@@ -172,7 +189,7 @@ public class AircraftXCJJ : AircraftEntity
                     TurningPoints[i + 1].TurningPointLongitude, TurningPoints[i].TurningPointLatitude, TurningPoints[i + 1].TurningPointLatitude);
         }
         reportInfo.Add("单机导航使用情况", zhc.ToString()); //飞行总距离
-        if(load.FirstAid != null)
+        if (load.FirstAid != null)
         {
             for (int i = 0; i < load.FirstAid.Length; i++)
             {
@@ -239,7 +256,7 @@ public class AircraftXCJJ : AircraftEntity
         End();
     }
 
-    static double CalculateTotalEmergencyTime(List<string> diseaseTypes)
+    public double CalculateTotalEmergencyTime(List<string> diseaseTypes)
     {
         double totalTime = 0;
 
@@ -254,25 +271,13 @@ public class AircraftXCJJ : AircraftEntity
     }
 
     // 模拟从数据库获取急救时间的方法  
-    static double GetEmergencyTimeFromDatabase(string diseaseType)
+    public double GetEmergencyTimeFromDatabase(string diseaseType)
     {
-        // 这里应该是实际的数据库查询逻辑  
-        // 但为了示例,我们直接返回一个模拟值  
-        switch (diseaseType)
+        if (diseaseDatabase.ContainsKey(diseaseType))
         {
-            case "aa": //HeartAttack
-                return 2; // 心脏病急救时间为2分钟  
-            case "bb": //Stroke
-                return 5; // 中风急救时间为5分钟  
-            case "cc": //Trauma
-                return 10; // 创伤急救时间为10分钟  
-            case "dd":
-                return 15;
-            case "ee":
-                return 20;
-            default:
-                return 0;
+            return diseaseDatabase[diseaseType].RescueTime;
         }
+        throw new ArgumentException("Unknown disease type.");
     }
 
     // 假设从前端接收到的数据结构  
@@ -285,86 +290,50 @@ public class AircraftXCJJ : AircraftEntity
 
     public class DiseaseInfo
     {
-        public string DiseaseType { get; set; }
         public double MinGoldenHour { get; set; }
         public double MaxGoldenHour { get; set; }
+
+        public double Priority { get; set; }
+        public double RescueTime { get; set; }
     }
 
-    public class MedicalRescue
+    public List<Patient> ProcessPatients(List<Patient> patients, Random rand)
     {
-        private static Dictionary<string, DiseaseInfo> diseaseDatabase = new Dictionary<string, DiseaseInfo>
-        {
-            { "aa", new DiseaseInfo { DiseaseType = "aa", MinGoldenHour = 1, MaxGoldenHour = 3 } },
-            { "bb", new DiseaseInfo { DiseaseType = "bb", MinGoldenHour = 2, MaxGoldenHour = 4 } },
-            { "cc", new DiseaseInfo { DiseaseType = "cc", MinGoldenHour = 3, MaxGoldenHour = 5 } },
-            { "dd", new DiseaseInfo { DiseaseType = "dd", MinGoldenHour = 4, MaxGoldenHour = 6 } },
-            { "ee", new DiseaseInfo { DiseaseType = "ee", MinGoldenHour = 5, MaxGoldenHour = 7 } },  
-        // 添加更多疾病类型
-        };
-
-        public static List<Patient> ProcessPatients(List<Patient> patients, Random rand)
+        foreach (var patient in patients)
         {
-            foreach (var patient in patients)
-            {
-                var diseaseInfo = GetDiseaseInfo(patient.DiseaseType); // MinGoldenHour MaxGoldenHour 数据库读取
-                double goldenHour = GenerateRandomGoldenHour(rand, diseaseInfo.MinGoldenHour, diseaseInfo.MaxGoldenHour);
-                Console.WriteLine($"Patient ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {goldenHour:F2}");
-                patient.GoldenHour = goldenHour;
-            }
-            return patients;
-        }
-
-        public static DiseaseInfo GetDiseaseInfo(string diseaseType)
-        {
-            if (diseaseDatabase.ContainsKey(diseaseType))
-            {
-                return diseaseDatabase[diseaseType];
-            }
-            throw new ArgumentException("Unknown disease type.");
+            var diseaseInfo = GetDiseaseInfo(patient.DiseaseType); // MinGoldenHour MaxGoldenHour 数据库读取
+            double goldenHour = GenerateRandomGoldenHour(rand, diseaseInfo.MinGoldenHour, diseaseInfo.MaxGoldenHour);
+            Console.WriteLine($"Patient ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {goldenHour:F2}");
+            patient.GoldenHour = goldenHour;
         }
+        return patients;
+    }
 
-        public static double GenerateRandomGoldenHour(Random rand, double min, double max)
+    public DiseaseInfo GetDiseaseInfo(string diseaseType)
+    {
+        if (diseaseDatabase.ContainsKey(diseaseType))
         {
-            double mu = (max + min) / 2;
-            double sigma = (max - min) / 6;
-            var normal = new Normal(mu, sigma);
-            return normal.Sample();
+            return diseaseDatabase[diseaseType];
         }
+        throw new ArgumentException("Unknown disease type.");
     }
 
-    // 假设数据库中的疾病优先级信息  
-    public class DiseasePriority
+    public static double GenerateRandomGoldenHour(Random rand, double min, double max)
     {
-        public string DiseaseType { get; set; }
-        public int Priority { get; set; } // 优先级,数字越小优先级越高  
+        double mu = (max + min) / 2;
+        double sigma = (max - min) / 6;
+        var normal = new Normal(mu, sigma);
+        return normal.Sample();
     }
 
-    // 静态类,包含与疾病优先级相关的静态方法  
-    public static class DiseasePriorityService
+    public double GetPriority(string diseaseType)
     {
-        // 数据库查询(实际项目中应该是从数据库读取)  
-        public static List<DiseasePriority> GetDiseasePriorities()
+    
+        if (diseaseDatabase.ContainsKey(diseaseType))
         {
-            return new List<DiseasePriority>
-            {
-                new DiseasePriority { DiseaseType = "aa", Priority = 5 },
-                new DiseasePriority { DiseaseType = "bb", Priority = 4 },
-                new DiseasePriority { DiseaseType = "cc", Priority = 3 },
-                new DiseasePriority { DiseaseType = "dd", Priority = 2 },
-                new DiseasePriority { DiseaseType = "ee", Priority = 5 },
-            };
-        }
-
-        // 根据疾病类型获取优先级  
-        public static int GetPriority(string diseaseType)
-        {
-            var priorities = GetDiseasePriorities().ToDictionary(dp => dp.DiseaseType, dp => dp.Priority);
-            if (priorities.TryGetValue(diseaseType, out int priority))
-            {
-                return priority;
-            }
-            return int.MaxValue; // 如果没有找到,返回一个很大的数作为默认优先级  
+            return diseaseDatabase[diseaseType].Priority;
         }
+        throw new ArgumentException("Unknown disease type.");
     }
 
     public string TargetQiXiangInfoSave(string s, int hour)

+ 16 - 16
SimulationServer/EventHandler/ServerStartEventHandler.cs

@@ -198,23 +198,23 @@ public class ServerStartEventHandler : AEvent<ServerStart>
             //break;
         }
 
-        //医疗转运任务
-        foreach (var YLZYTask in taskConfig.YLZYTasks)
-        {
-            taskSys.missionCount++;
-            Game.EventSystem.Publish(new CreateYLZYTask
-            { EditorConfig = editorConfig, YLZYTask = YLZYTask });
-            //break;
-        }
+        ////医疗转运任务
+        //foreach (var YLZYTask in taskConfig.YLZYTasks)
+        //{
+        //    taskSys.missionCount++;
+        //    Game.EventSystem.Publish(new CreateYLZYTask
+        //    { EditorConfig = editorConfig, YLZYTask = YLZYTask });
+        //    //break;
+        //}
 
-        //医疗物品运送
-        foreach (var YLWPYSTask in taskConfig.YLWPYSTasks)
-        {
-            taskSys.missionCount++;
-            Game.EventSystem.Publish(new CreateYLWPYSTask
-            { EditorConfig = editorConfig, YLWPYSTask = YLWPYSTask });
-            //break;
-        }
+        ////医疗物品运送
+        //foreach (var YLWPYSTask in taskConfig.YLWPYSTasks)
+        //{
+        //    taskSys.missionCount++;
+        //    Game.EventSystem.Publish(new CreateYLWPYSTask
+        //    { EditorConfig = editorConfig, YLWPYSTask = YLWPYSTask });
+        //    //break;
+        //}
 
         ////绞车吊载转运任务
         //foreach (var JCDZZYTask in taskConfig.JCDZZYTasks)

+ 35 - 28
SimulationServer/Utils/Util.cs

@@ -23,9 +23,9 @@ public class Util
 
         return distance;
     }
-    
-    
-    
+
+
+
     /// <summary>
     /// 根据 shape 解析出 经纬度
     /// </summary>
@@ -42,17 +42,17 @@ public class Util
         }
         return result;
     }
-    
+
     public static AircraftDB GetAircraftDefine(string aircraftType, string aircraftSubType, string aircraftID)
     {
-        string content = HttpManager.Get(HttpInterface.aircraft ,new List<string>
+        string content = HttpManager.Get(HttpInterface.aircraft, new List<string>
         {
             "fType","fSubtype","fName","limit"
         }, new List<string>
         {
             aircraftType,aircraftSubType,aircraftID,"1"
         });
-        
+
         //Log.Debug($"Type = {aircraftType}, SubType = {aircraftSubType}, ID = {aircraftID}");
         var define = JsonHelper.FromJson<AircraftDefine>(content);
 
@@ -61,13 +61,13 @@ public class Util
             //Log.Debug($"没有找到对应 [{aircraftID}] 的飞机信息");
             return new AircraftDB();
         }
-            
-    
+
+
         return define.zs[0];
     }
 
     // 医疗
-    public static YLDBData GetYL(string id)
+    public static string GetYL(string id)
     {
         string content = HttpManager.Get(HttpInterface.yl, new List<string>
         {
@@ -76,15 +76,22 @@ public class Util
         {
             "136",id //"航空医疗","","136","10"
         });
-        Console.WriteLine("YL:" + content);
+        //Console.WriteLine("YL:" + content);
         var yl = JsonHelper.FromJson<YLDB>(content);
-        var result = JsonHelper.FromJson<YLDBData>(yl.data);
+        string result = string.Empty;
+        for (int i = 0; i < yl.data.Length; i++)
+        {
+            //Console.WriteLine(yl.data[i].fValue);
+            result += yl.data[i].fValue;
+            if (i != yl.data.Length - 1)
+                result += "-";
+        }
         return result;
     }
 
     public static Weather GetWeather(string province_name, string city_name, string data)
     {
-        string content = HttpManager.Get(HttpInterface.weather ,new List<string>
+        string content = HttpManager.Get(HttpInterface.weather, new List<string>
         {
             "province_name","city_name","weather_date"
         }, new List<string>
@@ -94,24 +101,24 @@ public class Util
         var weather = JsonHelper.FromJson<WeatherDB>(content);
         var result = JsonHelper.FromJson<WeatherData>(weather.data).result;
         return result;
-        
+
     }
-    
+
     public static double GetSlope(double lon, double lat, int gridCount)
     {
-        string content = HttpManager.Get(HttpInterface.slope ,new List<string>
+        string content = HttpManager.Get(HttpInterface.slope, new List<string>
         {
             "lon","lat","gridCount"
         }, new List<string>
         {
             lon.ToString(),lat.ToString(),gridCount.ToString()
         });
-        
+
         var slope = JsonHelper.FromJson<SlopeDb>(content);
-        
+
         return Math.Atan(Math.Abs(slope.average.s1)) * (180.0 / Math.PI);
     }
-    
+
     /// <summary>
     /// 获取当前位置的温度
     /// </summary>
@@ -122,36 +129,36 @@ public class Util
     /// <returns></returns>
     public static double GetTemperature(double lon, double lat)
     {
-        string content = HttpManager.Get(HttpInterface.temperature ,new List<string>
+        string content = HttpManager.Get(HttpInterface.temperature, new List<string>
         {
             "varName","centerLon","centerLat","weather_date"
         }, new List<string>
         {
             "t2m",lon.ToString(),lat.ToString(),"2024-01-01 12:00:00"
         });
-        
+
         var temp = JsonHelper.FromJson<Temperature>(content);
-        
+
         return temp.vale - 273;
     }
-    
+
     //
     public static Fuel GetFuel(string fName, string fType, string fState, string fTemperature, string fHeight, string fWeight)
     {
-        string content = HttpManager.Get(HttpInterface.fuel ,new List<string>
+        string content = HttpManager.Get(HttpInterface.fuel, new List<string>
         {
             "fname","ftype","fstate","ftemperature","fheight","fweight"
         }, new List<string>
         {
             fName,fType,fState,fTemperature,fHeight,fWeight
         });
-        
+
         var fuel = JsonHelper.FromJson<FuelDB>(content);
-        
+
         return fuel.data[0];
     }
-    
-    public static EntitySheetReportValue GetSheetReportValue(string name,Dictionary<string, Dictionary<string, List<string>>> report)
+
+    public static EntitySheetReportValue GetSheetReportValue(string name, Dictionary<string, Dictionary<string, List<string>>> report)
     {
         EntitySheetReportValue aircraftValue = new EntitySheetReportValue();
         aircraftValue.Name = name;
@@ -172,5 +179,5 @@ public class Util
         }
         return aircraftValue;
     }
-    
+
 }

+ 10 - 10
SimulationServer/bin/Debug/net7.0/Missions/editor_config.json

@@ -209,11 +209,11 @@
                 "类型": "急救目标",
                 "人员数量": 5,
                 "疾病类型": [
-                    "aa",
-                    "bb",
-                    "cc",
-                    "dd",
-                    "ee"
+                    "急性大面积肺栓塞",
+                    "急性胰腺炎",
+                    "胸部外伤",
+                    "四肢骨折",
+                    "一氧化碳中毒"
                 ]
             }
         },
@@ -255,11 +255,11 @@
                 "类型": "转运目标",
                 "人员数量": 5,
                 "疾病类型": [
-                    "aa",
-                    "bb",
-                    "cc",
-                    "dd",
-                    "ee"
+                    "急性大面积肺栓塞",
+                    "急性胰腺炎",
+                    "胸部外伤",
+                    "四肢骨折",
+                    "一氧化碳中毒"
                 ]
             }
         }

BIN
SimulationServer/bin/Debug/net7.0/SimulationCommon.dll


BIN
SimulationServer/bin/Debug/net7.0/SimulationCommon.pdb


BIN
SimulationServer/bin/Debug/net7.0/SimulationServer.dll


BIN
SimulationServer/bin/Debug/net7.0/SimulationServer.exe


BIN
SimulationServer/bin/Debug/net7.0/SimulationServer.pdb