1
huanghongfeng
2025-09-12 a1a0c91857b670152ec7d4afa7bc4140953a5e98
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
using Castle.Components.DictionaryAdapter.Xml;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.Log;
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_Core.Utilities;
using WIDESEA_ISystemRepository;
using WIDESEA_ISystemService;
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.System;
 
namespace WIDESEA_SystemService
{
    public class Dt_RepairService : ServiceBase<Dt_Repair, IDt_RepairRepository>, IDt_RepairService
    {
        public readonly ISys_UserRepository _UserRepository;
        public Dt_RepairService(IDt_RepairRepository BaseDal, ISys_UserRepository userRepository) : base(BaseDal)
        {
            _UserRepository = userRepository;
        }
 
        public IDt_RepairRepository Repository => BaseDal;
 
 
        public WebResponseContent GetBarcodeMessage(string barocde)
        {
            List<Dt_Repair> dt_Repairs = BaseDal.QueryData(x => x.Current_PalletCode == barocde && (x.Current_Static == (int)StockStatusEmun.检修出库锁定 || x.Current_Static == (int)StockStatusEmun.检修中)).ToList();
            foreach (var item in dt_Repairs)
            {
                switch (item.CreateSta)
                {
                    case "1010":
                        item.CreateSta = "1号站台";
                        break;
                    case "1014":
                        item.CreateSta = "2号站台";
                        break;
                    case "1020":
                        item.CreateSta = "3号站台";
                        break;
                    case "1024":
                        item.CreateSta = "4号站台";
                        break;
                    case "1030":
                        item.CreateSta = "5号站台";
                        break;
                    case "1034":
                        item.CreateSta = "6号站台";
                        break;
                    case "1040":
                        item.CreateSta = "7号站台";
                        break;
                    case "1044":
                        item.CreateSta = "8号站台";
                        break;
                    default:
                        break;
                }
            }
 
            int useriddep = _UserRepository.GetDeptId(App.User.UserName);
            if (useriddep == 0)
            {
                dt_Repairs = dt_Repairs.Where(x => x.Creater == App.User.UserName).ToList();
            }
            
            return WebResponseContent.Instance.OK(data: dt_Repairs);
        }
 
        public WebResponseContent UpdateBarcode(string barocde)
        {
            List<Dt_Repair> dt_Repairs = BaseDal.QueryData(x => x.Current_PalletCode == barocde && x.Current_Static == (int)StockStatusEmun.检修出库锁定).ToList();
            foreach (var item in dt_Repairs)
            {
                item.ModifyDate = DateTime.Now;
                item.Current_Static = (int)StockStatusEmun.检修中;
                BaseDal.UpdateData(item);
            }
 
            List<Sys_CreateTask> Craet = BaseDal._CreateTaskRepository.QueryData(x => x.Current_PalletCode == barocde && x.Current_Static == (int)StockStatusEmun.检修出库锁定).ToList();
            foreach (var item in Craet)
            {
                item.Current_Static = (int)StockStatusEmun.检修中;
                BaseDal._CreateTaskRepository.UpdateData(item);
            }
            return WebResponseContent.Instance.OK();
        }
 
        public string ToWcsWriteBrplc = WIDESEA_Core.Helper.AppSettings.Configuration["ToWcsWriteBrplc"];
 
        public WebResponseContent UpdateBarcoend(string barocde,int wcount,int selectvalue)
        {
            try
            {
                List<Dt_Repair> dt_Repairs = BaseDal.QueryData(x => x.Current_PalletCode == barocde && x.Current_Static == (int)StockStatusEmun.检修中).ToList();
 
                foreach (var item in dt_Repairs)
                {
                    item.Current_begin = DateTime.Now;
                    item.Current_Outcome = selectvalue == 1 ? "合格" : "半检修";
                    item.Current_alter = wcount;
                    item.Current_Static = (int)StockStatusEmun.检修完成;
                    BaseDal.UpdateData(item);
                }
                if (wcount >= 0)
                {
                    List<Dt_StockInfo> dt_StockInfos = BaseDal._stockInfoRepository.QueryData(x => x.PalletCode == barocde).ToList();
                    foreach (var item in dt_StockInfos)
                    {
                        item.Wlstatus = selectvalue == 1 ? (int)InventoryMaterialStatus.合格 : (int)InventoryMaterialStatus.半检修;
                        item.Materialweight = item.Materialweight - wcount;
                        BaseDal._stockInfoRepository.UpdateData(item);
                    }
                }
 
                string CreateSta = "";
                List<Sys_CreateTask> Craet = BaseDal._CreateTaskRepository.QueryData(x => x.Current_PalletCode == barocde).ToList();
                if (Craet.Count != 0)
                {
                    CreateSta = Craet[0].CreateSta;
                    BaseDal._CreateTaskRepository.DeleteData(Craet);
                }
                else
                {
                    CreateSta = dt_Repairs[0].CreateSta;
                }
 
 
                HttpHelper.Post<WebResponseContent>(ToWcsWriteBrplc, CreateSta, "入库任务下发");
 
 
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error();
                throw;
            }
        }
 
        public WebResponseContent UpdateBarcoendwj(string barocde)
        {
            try
            {
                List<Dt_Repair> dt_Repairs = BaseDal.QueryData(x => x.Current_PalletCode == barocde && x.Current_Static == (int)StockStatusEmun.检修出库锁定 && x.Current_Static != (int)StockStatusEmun.检修中).ToList();
 
                if (dt_Repairs.Count ==0)
                {
                    return WebResponseContent.Instance.Error("未检回库失败!");
                }
 
                foreach (var item in dt_Repairs)
                {
                    item.Current_begin = DateTime.Now;
                    item.Current_Outcome = "未检回库";
                    item.Current_alter = item.Current_count;
                    item.Current_Static = (int)StockStatusEmun.检修完成;
                    BaseDal.UpdateData(item);
                }
 
                string CreateSta = "";
                List<Sys_CreateTask> Craet = BaseDal._CreateTaskRepository.QueryData(x => x.Current_PalletCode == barocde).ToList();
                if (Craet.Count != 0)
                {
                    CreateSta = Craet[0].CreateSta;
                    BaseDal._CreateTaskRepository.DeleteData(Craet);
                }
                else
                {
                    CreateSta = dt_Repairs[0].CreateSta;
                }
 
                HttpHelper.Post<WebResponseContent>(ToWcsWriteBrplc, CreateSta, "入库任务下发");
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
                throw;
            }
        }
 
 
        public virtual PageGridData<Dt_Repair> GetPageData(PageDataOptions options)
        {
            string wheres = options.ValidatePageOptions(TProperties);
            int useriddep = _UserRepository.GetDeptId(App.User.UserName);
            if (useriddep == 0)
            {
                if (wheres != "")
                {
                    wheres += $" and Creater='{App.User.UserName}'";
                }
                else
                {
                    wheres += $"Creater='{App.User.UserName}'";
                }
            }
            //获取排序字段
            Dictionary<string, OrderByType> orderbyDic = options.GetPageDataSort(TProperties);
 
            PageGridData<Dt_Repair> pageGridData = new PageGridData<Dt_Repair>();
            pageGridData = BaseDal.QueryPage(wheres, options.Page, options.Rows, orderbyDic);
            return pageGridData;
        }
 
 
        
 
 
        public object NumberOverhauls()
        {
            var startDate = DateTime.Today.AddDays(-7); // 获取当前日期之前15天的日期
            var today = DateTime.Today;
            var dateRange = Enumerable.Range(0, 7).Select(offset => today.AddDays(-offset)); // 获取最近15天的日期范围
 
            var data2 = BaseDal.QueryData(x => x.CreateDate >= startDate && x.CreateDate < today.AddDays(1)).ToList();
 
            var result = dateRange.Reverse().Select(date =>
            {
                // 统计当日入库数量
                var dayInventory = data2.Where(x => x.CreateDate >= date && x.CreateDate < date.AddDays(1) && x.Current_Static == (int)StockStatusEmun.检修完成 && x.Current_Outcome == "合格").Count();
 
                // 统计当日出库数量
                var dayOutbound = data2.Where(x => x.CreateDate >= date && x.CreateDate < date.AddDays(1) && x.Current_Static == (int)StockStatusEmun.检修完成 && x.Current_Outcome == "合格").Sum(x => x.Current_alter);
 
                return new
                {
                    Date = date.ToString("MM-dd"),
                    Day_inventory = dayInventory,
                    Day_outbound = dayOutbound
                };
            });
 
            var data = new
            {
                Daily_statistics = result.ToList(),
            };
            return data;
        }
 
 
        public override WebResponseContent UpdateData(SaveModel saveModel)
        {
            try
            {
                List<string>? list = UpdateIgnoreColOnExecute?.Invoke(saveModel);
                if (saveModel == null || saveModel.MainData == null || saveModel.MainData.Count == 0)//判断参数是否传入
                {
                    return WebResponseContent.Instance.Error("传参错误,参数不能为空");
                }
                string validResult = typeof(Dt_Repair).ValidateDicInEntity(saveModel.MainData, false, TProperties, list?.ToArray() ?? null);
 
                if (!string.IsNullOrEmpty(validResult))
                {
                    return WebResponseContent.Instance.Error(validResult);
                }
 
                PropertyInfo keyPro = typeof(Dt_Repair).GetKeyProperty();
                if (keyPro == null)
                {
                    return WebResponseContent.Instance.Error("请先设置主键");
                }
 
                Dt_Repair entity = saveModel.MainData.DicToModel<Dt_Repair>();
 
                entity.ModifyDate = null;
                entity.Modifier=null;
                entity.Current_begin = null;
 
                List<string> listCol = new List<string>();
                foreach (var item in saveModel.MainData)
                {
                    PropertyInfo? propertyInfo = typeof(Dt_Repair).GetProperty(item.Key);
                    if (propertyInfo == null)
                    {
                        propertyInfo = typeof(Dt_Repair).GetProperty(item.Key.FirstLetterToLower());
                        if (propertyInfo == null)
                        {
                            propertyInfo = typeof(Dt_Repair).GetProperty(item.Key.FirstLetterToUpper());
                        }
                    }
 
                    listCol.Add(propertyInfo?.Name);
                }
 
                if (saveModel.DetailData == null || saveModel.DetailData.Count == 0)
                {
                    if (list != null)
                        listCol = listCol.Where(x => !list.Contains(x)).ToList();
                    bool result = BaseDal.UpdateData(entity, listCol, list);
                    return WebResponseContent.Instance.OK();
                }
 
                if (typeof(Dt_Repair).GetNavigatePro() == null)
                {
                    return WebResponseContent.Instance.Error("未配置导航属性");
                }
 
                Type detailType = typeof(Dt_Repair).GetDetailType();
                MethodInfo? methodInfo = GetType().GetMethod("UpdateDataInculdesDetail");
                methodInfo = methodInfo?.MakeGenericMethod(new Type[] { detailType });
                object? obj = methodInfo?.Invoke(this, new object[] { entity, detailType, saveModel.DetailData, saveModel.DelKeys });
 
                
 
                return obj as WebResponseContent;
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
    }
}