Shuxia Ning
2024-08-06 1d5b344c8be498c9989f3fe2e9846b1dcc919cb8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
namespace IStation.Application
{
    /// <summary>
    /// 陈行输水调度配置
    /// </summary>
    [AllowAnonymous]
    [Route("OpenApi/Dispatch/Config")]
    [ApiDescriptionSettings("Schedule", Name = "调度配置", Order = 1)]
    public class ScheduleConfig_Controller : IDynamicApiController, ITransient
    {
        private readonly Service.Station _service_station = new();
        private readonly Service.ScheduleConfig _service_schedule_config = new();
 
 
        /// <summary>
        /// 获取配置
        /// </summary>
        [Route("Get")]
        [HttpGet]
        [NonUnify]
        public ChScheduleConfigDto Get()
        {
            var request_id = Yw.YitIdHelper.NextId(); 
            var log_title = "调度配置";
            Log.Info(request_id, log_title, "获取!");
            var schedule_config = _service_schedule_config.Get();
            if (schedule_config == null)
            {
                Log.Info(request_id, log_title, "获取:ScheduleConfig文件缺失!");
                return default;
            }
            var dto = schedule_config.Adapt<Model.ChScheduleConfig, ChScheduleConfigDto>();
            return dto;
        }
 
 
        /// <summary>
        /// 更新配置
        /// </summary>
        [Route("Update")]
        [HttpGet]
        [NonUnify]
        public SaveChScheduleConfigOutput Update()
        {
            var update_id = Yw.YitIdHelper.NextId();
            var log_title = "调度配置";
            Log.Info(update_id, log_title, "更新!");
 
            try
            {
                var schedule_config = _service_schedule_config.Get();
                if (schedule_config == null)
                {
                    Log.Info(update_id, log_title, "更新失败:ScheduleConfig文件缺失!");
                    return new SaveChScheduleConfigOutput() { Result = false, Msg = "ScheduleConfig文件缺失!" };
                }
 
                var msg = GlobalHelper.GetFlagCumulativeRuntimeDict(out Dictionary<int, double> station1_flag_cumulative_run_time_dict, out Dictionary<int, double> station2_flag_cumulative_run_time_dict, 35);
                if (!string.IsNullOrEmpty(msg))
                {
                    Log.Info(update_id, log_title, $"更新失败:{msg}");
                    return new SaveChScheduleConfigOutput() { Result = false, Msg = $"更新失败:{msg}" };
                }
 
                schedule_config.Station1.FlagCumulativeRuntimeDict = station1_flag_cumulative_run_time_dict;
                schedule_config.Station2.FlagCumulativeRuntimeDict = station2_flag_cumulative_run_time_dict;
                var bol = _service_schedule_config.Save(schedule_config);
                if (!bol)
                {
                    Log.Info(update_id, log_title, $"更新失败:Save()");
                    return new SaveChScheduleConfigOutput() { Result = false, Msg = "更新失败:Save()" };
                }
 
                Log.Info(update_id, log_title, $"更新成功!");
                Log.Debug(update_id, log_title, JsonHelper.Object2Json(schedule_config));
 
            }
            catch (Exception ex)
            {
                Log.Error(update_id, log_title, "更新失败!", ex);
                return new SaveChScheduleConfigOutput() { Result = false, Msg = ex.Message };
            }
 
            return new SaveChScheduleConfigOutput() { Result = true, Msg = "更新成功!" };
 
        }
 
 
        /// <summary>
        /// 保存配置
        /// </summary>
        [AllowAnonymous]
        [Route("Save")]
        [HttpPost]
        [NonUnify]
        public SaveChScheduleConfigOutput Save([Required] ChScheduleConfigInput input)
        {
            if (input == null)
            {
                return new SaveChScheduleConfigOutput() { Result = false, Msg = "入参不能为空!" };
            }
 
            var request_id = Yw.YitIdHelper.NextId();
            var log_title = "调度配置";
            Log.Info(request_id, log_title, "保存!");
            Log.Debug(request_id, log_title, JsonHelper.Object2Json(input));
 
            var schedule_config = input.Adapt<ChScheduleConfigInput, Model.ChScheduleConfig>();
            var bol = _service_schedule_config.Save(schedule_config);
            if (!bol)
            {
                Log.Info(request_id, log_title, $"保存失败:Save()");
                return new SaveChScheduleConfigOutput() { Result = false, Msg = "保存失败:Save()" };
            }
 
            Log.Info(request_id, log_title, $"保存成功!");
            return new SaveChScheduleConfigOutput() { Result = true, Msg = "保存成功!" };
        }
 
    }
}