Shuxia Ning
2024-12-27 f94a4ed8e9f5400e73bad84be023096585cb0498
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
namespace IStation.Application
{
    /// <summary>
    /// 输水调度配置
    /// </summary>
    [AllowAnonymous]
    [Route("OpenApi/Dispatch/Config")]
    [ApiDescriptionSettings("Schedule", Name = "调度配置", Order = 1)]
    public class ScheduleConfig_Controller : IDynamicApiController, ITransient
    { 
        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 = "调度配置";
            ScheduleLog.Info(request_id, log_title, "获取!");
            var schedule_config = _service_schedule_config.Get();
            if (schedule_config == null)
            {
                ScheduleLog.Info(request_id, log_title, "获取:ScheduleConfig文件缺失!");
                return default;
            }
            var dto = schedule_config.Adapt<Model.ChScheduleConfig, ChScheduleConfigDto>();
            return dto;
        } 
 
 
        /// <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 = "调度配置";
            ScheduleLog.Info(request_id, log_title, "保存!");
            ScheduleLog.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)
            {
                ScheduleLog.Info(request_id, log_title, $"保存失败:Save()");
                return new SaveChScheduleConfigOutput() { Result = false, Msg = "保存失败:Save()" };
            }
 
            ScheduleLog.Info(request_id, log_title, $"保存成功!");
            return new SaveChScheduleConfigOutput() { Result = true, Msg = "保存成功!" };
        }
 
    }
}