| using SqlSugar; | 
| using System; | 
| using System.Collections.Generic; | 
| using System.Linq; | 
| using System.Text; | 
| using System.Threading.Tasks; | 
| using WIDESEA_Common.LocationEnum; | 
| using WIDESEA_Core; | 
| using WIDESEA_Core.BaseServices; | 
| using WIDESEA_Core.DB; | 
| using WIDESEA_Core.Enums; | 
| using WIDESEA_Core.Helper; | 
| using WIDESEA_Core.Seed; | 
| using WIDESEA_IRecordRepository; | 
| using WIDESEA_IRecordService; | 
| using WIDESEA_Model.Models; | 
|   | 
| namespace WIDESEA_RecordService | 
| { | 
|     public partial class LocationStatusChangeRecordService : ServiceBase<Dt_LocationStatusChangeRecord, ILocationStatusChangeRecordRepository>, ILocationStatusChangeRecordService | 
|     { | 
|         public void AddLocationStatusChangeRecord(Dt_LocationInfo locationInfo, LocationStatusEnum lastStatus, LocationStatusEnum newStatus, LocationChangeType changeType, string? orderNo = null, int? taskNum = null) | 
|         { | 
|             try | 
|             { | 
|                 Dt_LocationStatusChangeRecord locationStatusChangeRecord = new Dt_LocationStatusChangeRecord() | 
|                 { | 
|                     AfterStatus = newStatus.ObjToInt(), | 
|                     BeforeStatus = lastStatus.ObjToInt(), | 
|                     ChangeType = changeType.ObjToInt(), | 
|                     LocationCode = locationInfo.LocationCode, | 
|                     LocationId = locationInfo.Id, | 
|                     TaskNum = taskNum, | 
|                     OrderNo = orderNo ?? "", | 
|                     Creater = App.User.UserId == 0 ? "" : "WCS", | 
|                     CreateDate = App.User.UserId == 0 ? DateTime.Now : DateTime.Now, | 
|                 }; | 
|   | 
|                 BaseDal.AddData(locationStatusChangeRecord); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 throw new Exception($"{ex.Message}"); | 
|             } | 
|         } | 
|   | 
|         public void AddLocationStatusChangeRecord(List<Dt_LocationInfo> locationInfos, LocationStatusEnum newStatus, LocationChangeType changeType, string? orderNo = null, List<int>? taskNums = null) | 
|         { | 
|             try | 
|             { | 
|                 List<Dt_LocationStatusChangeRecord> records = new List<Dt_LocationStatusChangeRecord>(); | 
|                 for (int i = 0; i < locationInfos.Count; i++) | 
|                 { | 
|                     Dt_LocationInfo locationInfo = locationInfos[i]; | 
|                     int? taskNum = (taskNums != null && taskNums.Count > 0 && taskNums.Count == locationInfos.Count) ? taskNums[i] : null; | 
|                     Dt_LocationStatusChangeRecord locationStatusChangeRecord = new Dt_LocationStatusChangeRecord() | 
|                     { | 
|                         AfterStatus = newStatus.ObjToInt(), | 
|                         BeforeStatus = locationInfo.LocationStatus, | 
|                         ChangeType = changeType.ObjToInt(), | 
|                         LocationCode = locationInfo.LocationCode, | 
|                         LocationId = locationInfo.Id, | 
|                         TaskNum = taskNum, | 
|                         OrderNo = orderNo ?? "" | 
|                     }; | 
|                     records.Add(locationStatusChangeRecord); | 
|                 } | 
|   | 
|   | 
|                 BaseDal.AddData(records); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 throw new Exception($"{ex.Message}"); | 
|             } | 
|         } | 
|   | 
|         public WebResponseContent GetLocationState(int id) | 
|         { | 
|             WebResponseContent content = new WebResponseContent(); | 
|             try | 
|             { | 
|                 List<Dt_LocationStatusChangeRecord> location = BaseDal.QueryData(x => x.LocationId == id).OrderByDescending(x => x.CreateDate).ToList(); | 
|   | 
|                 return content = WebResponseContent.Instance.OK(data: location); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 return content = WebResponseContent.Instance.Error(ex.Message); | 
|             } | 
|         } | 
|     } | 
| } |