ningshuxia
2022-12-12 e81ca048ef4e9345e904b74ffffd3e8413d18a7e
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Net.Http.Headers;
using Microsoft.Extensions.Hosting.Internal;
using Microsoft.AspNetCore.Http.Extensions;
using IStation.Untity;
using Furion.DynamicApiController;
using System.ComponentModel.DataAnnotations;
using Mapster;
using Microsoft.AspNetCore.Http;
 
namespace IStation.Application 
{
    /// <summary>
    /// InspectTemplate
    /// </summary>
    [Route("Inspect/Template/Mgr")]
    [ApiDescriptionSettings("Inspect", Name = "巡检模板项(管理)", Order = 991)]
    public class InspectTemplate_MgrController : IDynamicApiController
    {
        #region Query
        /// <summary>
        /// 通过 ProductType 获取
        /// </summary>
        [Route("GetItemsByProductType@V1.0")]
        [HttpGet]
        public Dto.InspectionTemplateBundle4MgrGetProductType GetItemsByProductType([FromQuery][Required] Dto.InspectionTemplateBundle4MgrGetProductType.Input input)
        {
            Service.ProductInspectionTemplateGrp the_grp_service = new Service.ProductInspectionTemplateGrp();
            var list_grp_models = the_grp_service.GetByProductType(input.ProductType);
            if (list_grp_models == null || list_grp_models.Count == 0)
                return null;
 
            Service.ProductInspectionTemplateItem the_item_service = new Service.ProductInspectionTemplateItem();
            var list_item_models = the_item_service.GetByProductType(input.ProductType);
 
 
            var vm = new Dto.InspectionTemplateBundle4MgrGetProductType();
            vm.GrpList = list_grp_models.Select(x => x.Adapt<Model.ProductInspectionTemplateGrp, Dto.InspectionTemplateGrp4MgrGetProductType>()).ToList();
 
            if (list_item_models != null && list_item_models.Count > 0)
                vm.ItemList = list_item_models?.Select(x => x.Adapt<Model.ProductInspectionTemplateItem, Dto.InspectionTemplateItem4MgrGetProductType>()).ToList();
 
            return vm;
        }
 
        /// <summary>
        /// 通过 ItemID 获取 值
        /// </summary>
        [Route("GetValuesByItemID@V1.0")]
        [HttpGet]
        public List<Dto.InspectionTemplateValue4MgrGet> GetValuesByItemID([FromQuery][Required] Dto.InspectionTemplateValue4MgrGet.Input input)
        {
            Service.ProductInspectionTemplateValue the_grp_service = new Service.ProductInspectionTemplateValue();
            var list_item_models = the_grp_service.GetByItemID(input.ItemID);
            if (list_item_models == null || list_item_models.Count == 0)
                return null;
 
            return list_item_models .Select(x => x.Adapt<Model.ProductInspectionTemplateValue , Dto.InspectionTemplateValue4MgrGet>()).ToList();
        }
 
        #endregion
 
 
        #region Insert
 
        /// <summary>
        /// 插入一条
        /// </summary>
        [Route("InsertGrp@V1.0")]
        [HttpPost]
        public long InsertGrp([Required] IStation.Dto.AddProductInspectionTemplateGrpInput input)
        {
            if (input == null)
                return default;
            var model = input.Adapt<IStation.Dto.AddProductInspectionTemplateGrpInput, Model.ProductInspectionTemplateGrp>();
            model.UseStatus = Model.ProductInspectionContentGrp.eUseStatus.有效;
            Service.ProductInspectionTemplateGrp the_service = new Service.ProductInspectionTemplateGrp();
            var id = the_service.Insert(model);
            return id;
        }
 
        /// <summary>
        /// 插入多条
        /// </summary>
        [Route("InsertGrps@V1.0")]
        [HttpPost]
        public bool InsertGrps([Required] List<IStation.Dto.AddProductInspectionTemplateGrpInput> inputList)
        {
            if (inputList == null || inputList.Count < 1)
                return false;
            var list = inputList.Select(x => x.Adapt<IStation.Dto.AddProductInspectionTemplateGrpInput, Model.ProductInspectionTemplateGrp>()).ToList();
            foreach (var item in list)
                item.UseStatus = Model.ProductInspectionContentGrp.eUseStatus.有效;
            Service.ProductInspectionTemplateGrp the_service = new Service.ProductInspectionTemplateGrp();
            var bol = the_service.Inserts(list);
            return bol;
        }
 
 
        /// <summary>
        /// 插入一条
        /// </summary>
        [Route("InsertItem@V1.0")]
        [HttpPost]
        public long InsertItem([Required] IStation.Dto.AddProductInspectionTemplateItemInput input)
        {
            if (input == null)
                return default;
            var model_item = input.Adapt<IStation.Dto.AddProductInspectionTemplateItemInput, Model.ProductInspectionTemplateItem>();
            model_item.UseStatus = Model.ProductInspectionContentItem.eUseStatus.有效;
            model_item.ProductType = input.ProductType;
 
            List<Model.ProductInspectionTemplateValue> list = null;
            if (input.ValueList != null && input.ValueList.Count > 0)
            {
                list = input.ValueList.Select(x => x.Adapt<IStation.Dto.AddProductInspectionTemplateValueInput, Model.ProductInspectionTemplateValue>()).ToList();
                foreach (var item in list)
                {
                    item.UseStatus = Model.ProductInspectionContentValue.eUseStatus.有效;
                    item.CreateUserID = input.CreateUserID;
                }
            }
  
               
 
 
            Service.ProductInspectionTemplateItem the_service = new Service.ProductInspectionTemplateItem();
            var id = the_service.Insert(model_item, list);
            return id;
        }
 
 
 
 
 
        #endregion
 
 
        #region Update
 
        /// <summary>
        /// 更新一条
        /// </summary>
        [Route("UpdateGrp@V1.0")]
        [HttpPut]
        public bool UpdateGrp([Required] IStation.Dto.UpdateProductInspectionTemplateGrpInput input)
        {
            if (input == null)
                return false;
            Service.ProductInspectionTemplateGrp the_service = new Service.ProductInspectionTemplateGrp();
            var model = input.Adapt<IStation.Dto.UpdateProductInspectionTemplateGrpInput, Model.ProductInspectionTemplateGrp>();
            var bol = the_service.Update(model);
            return bol;
        }
 
        /// <summary>
        /// 更新多条
        /// </summary>
        [Route("UpdateGrps@V1.0")]
        [HttpPut]
        public bool UpdateGrps([Required] List<IStation.Dto.UpdateProductInspectionTemplateGrpInput> inputList)
        {
            if (inputList == null || inputList.Count() < 1)
            {
                return false;
            }
            var corpIds = inputList.Select(x => x.CorpID).Distinct().ToList();
            if (corpIds.Count > 1)
                return false;
            Service.ProductInspectionTemplateGrp the_service = new Service.ProductInspectionTemplateGrp();
           
            List<Model.ProductInspectionTemplateGrp> model_list = new List<Model.ProductInspectionTemplateGrp>();
            inputList.ForEach(input =>
            {
                var model = input.Adapt<IStation.Dto.UpdateProductInspectionTemplateGrpInput, Model.ProductInspectionTemplateGrp>();
                model_list.Add(model);
            });
 
            var bol = the_service.Updates(model_list);
            return bol;
        }
 
 
        /// <summary>
        /// 更新一条
        /// </summary>
        [Route("UpdateItem@V1.0")]
        [HttpPut]
        public bool UpdateItem([Required] IStation.Dto.UpdateProductInspectionTemplateItemInput input)
        {
            if (input == null)
                return false;
            Service.ProductInspectionTemplateItem the_service = new Service.ProductInspectionTemplateItem();
            var model = input.Adapt<IStation.Dto.UpdateProductInspectionTemplateItemInput, Model.ProductInspectionTemplateItem>();
            if (model.ID <= 0)
                return false;
   
            List<Model.ProductInspectionTemplateValue> list = null;
            if (input.ValueList != null && input.ValueList.Count > 0)
            { 
                list = input.ValueList.Select(x => x.Adapt<IStation.Dto.UpdateProductInspectionTemplateValueInput, Model.ProductInspectionTemplateValue>()).ToList();
                foreach (var vvv in list)
                {
                    vvv.ItemID = model.ID;
                    if(vvv.ID <= 0)
                    {
                        vvv.CreateTime = DateTime.Now;
                        vvv.CreateUserID = input.UpdateUserID;
                    }
                    vvv.UpdateUserID = input.UpdateUserID;
                }
            }
 
               
            var bol = the_service.Update(model, list);
            return bol;
        }
 
 
 
 
 
        /// <summary>
        /// 更新排序码
        /// </summary>
        [Route("UpdateGrpSortCode@V1.0")]
        [HttpPut]
        public bool UpdateGrpSortCode([Required] UpdateSortCodeUnderCorpInput input)
        {
            Service.ProductInspectionTemplateGrp the_service = new Service.ProductInspectionTemplateGrp();
            var bol = the_service.UpdateSortCode(input.CorpID, input.ID, input.SortCode, UserManager.UserID );
            return bol;
        }
 
        /// <summary>
        /// 更新排序码
        /// </summary>
        [Route("UpdateItemSortCode@V1.0")]
        [HttpPut]
        public bool UpdateItemSortCode([Required] UpdateSortCodeUnderCorpInput input)
        {
            Service.ProductInspectionTemplateItem the_service = new Service.ProductInspectionTemplateItem();
            var bol = the_service.UpdateSortCode(input.CorpID, input.ID, input.SortCode, UserManager.UserID);
            return bol;
        }
 
        /// <summary>
        /// 更新排序码
        /// </summary>
        [Route("UpdateValueSortCode@V1.0")]
        [HttpPut]
        public bool UpdateValueSortCode([Required] UpdateSortCodeUnderCorpInput input)
        {
            Service.ProductInspectionTemplateValue the_service = new Service.ProductInspectionTemplateValue();
            var bol = the_service.UpdateSortCode(input.CorpID, input.ID, input.SortCode, UserManager.UserID);
            return bol;
        }
        /// <summary>
        /// 更新排序
        /// </summary>
        [Route("UpdateGrpSorter@V1.0")]
        [HttpPut]
        public bool UpdateGrpSorter([Required] UpdateSorterUnderCorpInput input)
        {
            if (input.Sorters == null || input.Sorters.Count < 1)
                return false;
            var list = input.Sorters.Select(x => x.Adapt<UpdateSortCodeInput, Model.TraceSorter>()).ToList();
            Service.ProductInspectionTemplateGrp the_service = new Service.ProductInspectionTemplateGrp();
            var bol = the_service.UpdateSorter(input.CorpID, list);
            return bol;
        }
 
        /// <summary>
        /// 更新排序
        /// </summary>
        [Route("UpdateItemSorter@V1.0")]
        [HttpPut]
        public bool UpdateItemSorter([Required] UpdateSorterUnderCorpInput input)
        {
            if (input.Sorters == null || input.Sorters.Count < 1)
                return false;
            var list = input.Sorters.Select(x => x.Adapt<UpdateSortCodeInput, Model.TraceSorter>()).ToList();
            Service.ProductInspectionTemplateItem the_service = new Service.ProductInspectionTemplateItem();
            var bol = the_service.UpdateSorter(input.CorpID, list);
            return bol;
        }
 
        /// <summary>
        /// 更新排序
        /// </summary>
        [Route("UpdateValueSorter@V1.0")]
        [HttpPut]
        public bool UpdateValueSorter([Required] UpdateSorterUnderCorpInput input)
        {
            if (input.Sorters == null || input.Sorters.Count < 1)
                return false;
            var list = input.Sorters.Select(x => x.Adapt<UpdateSortCodeInput, Model.TraceSorter>()).ToList();
            Service.ProductInspectionTemplateValue the_service = new Service.ProductInspectionTemplateValue();
            var bol = the_service.UpdateSorter(input.CorpID, list);
            return bol;
        }
        /// <summary>
        /// 更新使用状态
        /// </summary>
        [Route("UpdateGrpUseStatus@V1.0")]
        [HttpPut]
        public bool UpdateGrpUseStatus([Required] UpdateUseStatusUnderCorpInput input)
        {
            Service.ProductInspectionTemplateGrp the_service = new Service.ProductInspectionTemplateGrp();
            var bol = the_service.UpdateUseStatus(input.CorpID, input.ID, input.UseStatus, UserManager.UserID );
            return bol;
        }
 
        /// <summary>
        /// 更新使用状态
        /// </summary>
        [Route("UpdateItemUseStatus@V1.0")]
        [HttpPut]
        public bool UpdateItemUseStatus([Required] UpdateUseStatusUnderCorpInput input)
        {
            Service.ProductInspectionTemplateItem the_service = new Service.ProductInspectionTemplateItem();
            var bol = the_service.UpdateUseStatus(input.CorpID, input.ID, input.UseStatus, UserManager.UserID);
            return bol;
        }
 
        /// <summary>
        /// 更新使用状态
        /// </summary>
        [Route("UpdateValueUseStatus@V1.0")]
        [HttpPut]
        public bool UpdateValueUseStatus([Required] UpdateUseStatusUnderCorpInput input)
        {
            Service.ProductInspectionTemplateValue the_service = new Service.ProductInspectionTemplateValue();
            var bol = the_service.UpdateUseStatus(input.CorpID, input.ID, input.UseStatus, UserManager.UserID);
            return bol;
        }
 
        #endregion
 
 
        #region Delete
 
        /// <summary>
        /// 删除
        /// </summary>
        [Route("DeleteGrpByID@V1.0")]
        [HttpDelete]
        public DeleteReasonOutput DeleteGrpByID([FromQuery][Required] IDUnderCorpInput input)
        {
            Service.ProductInspectionTemplateGrp the_service = new Service.ProductInspectionTemplateGrp();
            var bol = the_service.DeleteByID(input.CorpID, input.ID, out string Msg);
            return new DeleteReasonOutput() { Success = bol, Reason = Msg };
        }
 
        /// <summary>
        /// 删除
        /// </summary>
        [Route("DeleteItemByID@V1.0")]
        [HttpDelete]
        public DeleteReasonOutput DeleteItemByID([FromQuery][Required] IDUnderCorpInput input)
        {
            Service.ProductInspectionTemplateItem the_service = new Service.ProductInspectionTemplateItem();
            var bol = the_service.DeleteByID(input.CorpID, input.ID, out string Msg);
            return new DeleteReasonOutput() { Success = bol, Reason = Msg };
        }
 
        /// <summary>
        /// 删除
        /// </summary>
        [Route("DeleteValueByID@V1.0")]
        [HttpDelete]
        public DeleteReasonOutput DeleteValueByID([FromQuery][Required] IDUnderCorpInput input)
        {
            Service.ProductInspectionTemplateValue the_service = new Service.ProductInspectionTemplateValue();
            var bol = the_service.DeleteByID(input.CorpID, input.ID, out string Msg);
            return new DeleteReasonOutput() { Success = bol, Reason = Msg };
        }
        #endregion
    }
}