lixiaojun
2024-03-27 56b519c5ee0ee0615400c7df8d455f9766fa600b
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
namespace Yw.Application
{
    /// <summary>
    /// PumpCurveExMapping
    /// </summary>
    [Route("Curve/Pump/Mapping/Extension")]
    [ApiDescriptionSettings("Curve", Name = "泵曲线映射拓展", Order = 8000)]
    public partial class PumpCurveExMapping_Controller : IDynamicApiController
    {
        private readonly Service.PumpCurveExMapping _service = new();
 
        #region Query
 
        /// <summary>
        /// 通过 PumpID 获取
        /// </summary>
        [Route("GetByPumpID@V1.0")]
        [HttpGet]
        public List<PumpCurveExMappingDto> GetByPumpID([FromQuery][Required] PumpIDInput input)
        {
            var list = _service.GetByPumpID(input.PumpID);
            var vmList = list?.Select(x => new PumpCurveExMappingDto(x.Item1, x.Item2)).ToList();
            return vmList;
        }
 
        /// <summary>
        /// 通过 PumpIds 获取
        /// </summary>
        [Route("GetByPumpIds@V1.0")]
        [HttpGet]
        public List<PumpCurveExMappingDto> GetByPumpIds([FromQuery][Required] PumpIdsInput input)
        {
            var ids = LongListHelper.ToList(input.PumpIds);
            var list = _service.GetByPumpIds(ids);
            var vmList = list?.Select(x => new PumpCurveExMappingDto(x.Item1, x.Item2)).ToList();
            return vmList;
        }
 
        /// <summary>
        /// 通过 ID 获取
        /// </summary>
        [Route("GetByID@V1.0")]
        [HttpGet]
        public PumpCurveExMappingDto GetByID([FromQuery][Required] IDInput input)
        {
            var model = _service.GetByID(input.ID);
            return model == null ? null : new PumpCurveExMappingDto(model.Item1, model.Item2);
        }
 
        /// <summary>
        /// 通过 Ids 获取
        /// </summary>
        [Route("GetByIds@V1.0")]
        [HttpGet]
        public List<PumpCurveExMappingDto> GetByIds([FromQuery][Required] IdsInput input)
        {
            var ids = LongListHelper.ToList(input.Ids);
            var list = _service.GetByIds(ids);
            var vmList = list?.Select(x => new PumpCurveExMappingDto(x.Item1, x.Item2)).ToList();
            return vmList;
        }
 
        /// <summary>
        ///  通过 PumpID 获取工作曲线
        /// </summary>
        [Route("GetWorkingByPumpID@V1.0")]
        [HttpGet]
        public PumpCurveExMappingDto GetWorkingByPumpID([FromQuery][Required] PumpIDInput input)
        {
            var model = _service.GetWorkingByPumpID(input.PumpID);
            return model == null ? null : new PumpCurveExMappingDto(model.Item1, model.Item2);
        }
 
        /// <summary>
        ///  通过 PumpID 获取默认曲线
        /// </summary>
        [Route("GetDefaultByPumpID@V1.0")]
        [HttpGet]
        public PumpCurveExMappingDto GetDefaultByPumpID([FromQuery][Required] PumpIDInput input)
        {
            var model = _service.GetDefaultByPumpID(input.PumpID);
            return model == null ? null : new PumpCurveExMappingDto(model.Item1, model.Item2);
        }
 
        #endregion
 
        #region Insert
 
        /// <summary>
        /// 插入一条
        /// </summary>
        [Route("Insert@V1.0")]
        [HttpPost]
        public long Insert([Required] AddPumpCurveExMappingInput input)
        {
            var curve = input.Adapt<AddPumpCurveExMappingInput, Model.PumpCurve>();
            var mapping = input.Adapt<AddPumpCurveExMappingInput, Model.PumpCurveMapping>();
            mapping.SortCode = new Service.PumpCurveMapping().GetMaxSortCodeByPumpID(input.PumpID) + 1;
            var id = _service.Insert(curve, mapping);
            return id;
        }
 
        #endregion
 
        #region Update
 
        /// <summary>
        /// 更新一条
        /// </summary>
        [Route("Update@V1.0")]
        [HttpPut]
        public bool Update([Required] UpdatePumpCurveExMappingInput input)
        {
            var curveModel = new Service.PumpCurve().GetByID(input.CurveID);
            if (curveModel == null)
            {
                throw YOops.Oh(eResultCode.Alert, ErrorCodes.D001, $"CurveID:{input.CurveID} 数据不存在");
            }
            var curveRhs = new Model.PumpCurve(curveModel);
            var mappingModel = new Service.PumpCurveMapping().GetByID(input.MappingID);
            if (mappingModel == null)
            {
                throw YOops.Oh(eResultCode.Alert, ErrorCodes.D001, $"MappingID:{input.MappingID} 数据不存在");
            }
            var mappingRhs = new Model.PumpCurveMapping(mappingModel);
 
            input.Adapt(curveRhs);
            input.Adapt(mappingRhs);
 
            var bol = _service.Update(curveRhs, mappingRhs);
            return bol;
        }
 
        #endregion
 
        #region Delete
 
        /// <summary>
        /// 通过 ID 删除(如果曲线没有其他关联关系,则同时删除曲线)
        /// </summary>
        public bool DeleteByID(long ID)
        {
            var bol = new Service.PumpCurveMapping().DeleteExByID(ID, out string Msg);
            if (!bol)
            {
                throw YOops.Oh(eResultCode.Alert, ErrorCodes.D999, Msg);
            }
            return bol;
        }
 
        #endregion
 
    }
}