| | |
| | | using SqlSugar; |
| | | using Microsoft.Data.SqlClient; |
| | | using Org.BouncyCastle.Bcpg.Sig; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core.Helper; |
| | |
| | | { |
| | | private readonly IBasicRepository _basicRepository; |
| | | public ILocationInfoRepository Repository => BaseDal; |
| | | private readonly static object _locker = new object(); |
| | | |
| | | public static List<LocationCache> locationCaches = new List<LocationCache>(); |
| | | |
| | | public LocationInfoService(ILocationInfoRepository BaseDal, IBasicRepository basicRepository) : base(BaseDal) |
| | | { |
| | |
| | | List<Dt_LocationInfo> locationInfos = Repository.QueryData(x => keys.Contains(x.Id)); |
| | | locationInfos.ForEach(x => |
| | | { |
| | | x.EnableStatus = EnableEnum.Enable.ObjToInt(); |
| | | x.EnableStatus = EnableStatusEnum.Normal.ObjToInt(); |
| | | }); |
| | | Repository.UpdateData(locationInfos); |
| | | |
| | |
| | | List<Dt_LocationInfo> locationInfos = Repository.QueryData(x => keys.Contains(x.Id)); |
| | | locationInfos.ForEach(x => |
| | | { |
| | | x.EnableStatus = EnableEnum.Disable.ObjToInt(); |
| | | x.EnableStatus = EnableStatusEnum.Disable.ObjToInt(); |
| | | }); |
| | | Repository.UpdateData(locationInfos); |
| | | |
| | |
| | | return LocationDisableStatus(new int[] { key }); |
| | | } |
| | | |
| | | |
| | | //ä¼ å
¥å··éå·2 è´§æ¶ç±»å10 |
| | | public Dt_LocationInfo? GetLocation(string roadway,int Locationtype) |
| | | { |
| | | lock (_locker) |
| | | { |
| | | List<LocationCache> removeItems = locationCaches.Where(x => (DateTime.Now - x.DateTime).TotalMinutes > 20).ToList();//æ¥è¯¢æ·»å éæåéè¶
è¿20åéçè´§ä½ |
| | | int count = removeItems.Count; |
| | | for (int i = 0; i < count; i++) |
| | | { |
| | | locationCaches.Remove(removeItems[i]);//ç§»é¤æ¥è¯¢æ·»å éæåéè¶
è¿5åéçè´§ä½ |
| | | } |
| | | |
| | | List<string> lockLocations = locationCaches.Select(x => x.LocationCode).ToList(); |
| | | |
| | | List<Dt_LocationInfo> locationInfos = BaseDal.QueryData(x => x.RoadwayNo == roadway && x.LocationType == Locationtype && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && !lockLocations.Contains(x.LocationCode));//æ¥è¯¢å··éææè´§ä½ä¿¡æ¯ |
| | | |
| | | |
| | | List<Dt_LocationInfo> emptyLocations = locationInfos.Where(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && !lockLocations.Contains(x.LocationCode)).OrderBy(x => x.Layer).ThenBy(x => x.Column).ThenByDescending(x => x.Depth).ThenBy(x => x.Row).ToList();//æ¥è¯¢ç©ºè´§ä½ä¿¡æ¯å¹¶æé¤20åéå
åé
çè´§ä½,æ ¹æ®å±ãåãæ·±åº¦ãè¡æåº |
| | | |
| | | |
| | | for (int i = 0; i < emptyLocations.Count; i++) |
| | | { |
| | | if (emptyLocations[i].Depth == 1)//夿æ¯å¦1æ·±è´§ä½ |
| | | { |
| | | Dt_LocationInfo? sencondDepthLocation = locationInfos.FirstOrDefault(x => Math.Abs(x.Row - emptyLocations[i].Row) == 1 && x.Layer == emptyLocations[i].Layer && x.Column == emptyLocations[i].Column);//æ¥è¯¢2深货ä½å¯¹åºç1æ·±è´§ä½æ¯å¦ä¸ºç©º,鲿¢åºç°åé
1深货ä½è2深货ä½ä¸ºç©ºçæ
åµ |
| | | if (sencondDepthLocation != null && sencondDepthLocation.LocationStatus == LocationStatusEnum.Free.ObjToInt()) |
| | | { |
| | | locationCaches.Add(new LocationCache { DateTime = DateTime.Now, LocationCode = sencondDepthLocation.LocationCode }); |
| | | return sencondDepthLocation;//1深货ä½å2深货ä½é½ä¸ºç©ºçæ
åµä¸,ä¼å
åé
2æ·±è´§ä½ |
| | | } |
| | | else |
| | | { |
| | | locationCaches.Add(new LocationCache { DateTime = DateTime.Now, LocationCode = emptyLocations[i].LocationCode }); |
| | | return emptyLocations[i]; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Dt_LocationInfo? sencondDepthLocation = locationInfos.FirstOrDefault(x => Math.Abs(x.Row - emptyLocations[i].Row) == 1 && x.Layer == emptyLocations[i].Layer && x.Column == emptyLocations[i].Column);//æ¥è¯¢2深货ä½å¯¹åºç1æ·±è´§ä½æ¯å¦ä¸ºç©º |
| | | if (sencondDepthLocation != null && sencondDepthLocation.LocationStatus == LocationStatusEnum.Free.ObjToInt()) |
| | | { |
| | | locationCaches.Add(new LocationCache { DateTime = DateTime.Now, LocationCode = emptyLocations[i].LocationCode }); |
| | | return emptyLocations[i]; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | public Dt_LocationInfo? GetLocation2(string roadway, int Locationtype,int Startingcolumn,int Terminationcolumn) |
| | | { |
| | | lock (_locker) |
| | | { |
| | | List<LocationCache> removeItems = locationCaches.Where(x => (DateTime.Now - x.DateTime).TotalMinutes > 20).ToList();//æ¥è¯¢æ·»å éæåéè¶
è¿5åéçè´§ä½ |
| | | int count = removeItems.Count; |
| | | for (int i = 0; i < count; i++) |
| | | { |
| | | locationCaches.Remove(removeItems[i]);//ç§»é¤æ¥è¯¢æ·»å éæåéè¶
è¿5åéçè´§ä½ |
| | | } |
| | | |
| | | List<string> lockLocations = locationCaches.Select(x => x.LocationCode).ToList(); |
| | | |
| | | List<Dt_LocationInfo> locationInfos = BaseDal.QueryData(x => x.RoadwayNo == roadway && x.LocationType == Locationtype && x.Column> Startingcolumn && x.Column< Terminationcolumn && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && !lockLocations.Contains(x.LocationCode));//æ¥è¯¢å··éææè´§ä½ä¿¡æ¯ |
| | | |
| | | |
| | | List<Dt_LocationInfo> emptyLocations = locationInfos.Where(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && !lockLocations.Contains(x.LocationCode)).OrderBy(x => x.Layer).ThenBy(x => x.Column).ThenByDescending(x => x.Depth).ThenBy(x => x.Row).ToList();//æ¥è¯¢ç©ºè´§ä½ä¿¡æ¯å¹¶æé¤5åéå
åé
çè´§ä½,æ ¹æ®å±ãåãæ·±åº¦ãè¡æåº |
| | | |
| | | |
| | | for (int i = 0; i < emptyLocations.Count; i++) |
| | | { |
| | | if (emptyLocations[i].Depth == 1)//夿æ¯å¦1æ·±è´§ä½ |
| | | { |
| | | Dt_LocationInfo? sencondDepthLocation = locationInfos.FirstOrDefault(x => Math.Abs(x.Row - emptyLocations[i].Row) == 1 && x.Layer == emptyLocations[i].Layer && x.Column == emptyLocations[i].Column);//æ¥è¯¢2深货ä½å¯¹åºç1æ·±è´§ä½æ¯å¦ä¸ºç©º,鲿¢åºç°åé
1深货ä½è2深货ä½ä¸ºç©ºçæ
åµ |
| | | if (sencondDepthLocation != null && sencondDepthLocation.LocationStatus == LocationStatusEnum.Free.ObjToInt()) |
| | | { |
| | | locationCaches.Add(new LocationCache { DateTime = DateTime.Now, LocationCode = sencondDepthLocation.LocationCode }); |
| | | return sencondDepthLocation;//1深货ä½å2深货ä½é½ä¸ºç©ºçæ
åµä¸,ä¼å
åé
2æ·±è´§ä½ |
| | | } |
| | | else |
| | | { |
| | | locationCaches.Add(new LocationCache { DateTime = DateTime.Now, LocationCode = emptyLocations[i].LocationCode }); |
| | | return emptyLocations[i]; |
| | | |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Dt_LocationInfo? sencondDepthLocation = locationInfos.FirstOrDefault(x => Math.Abs(x.Row - emptyLocations[i].Row) == 1 && x.Layer == emptyLocations[i].Layer && x.Column == emptyLocations[i].Column);//æ¥è¯¢2深货ä½å¯¹åºç1æ·±è´§ä½æ¯å¦ä¸ºç©º |
| | | if (sencondDepthLocation != null && sencondDepthLocation.LocationStatus == LocationStatusEnum.Free.ObjToInt()) |
| | | { |
| | | locationCaches.Add(new LocationCache { DateTime = DateTime.Now, LocationCode = emptyLocations[i].LocationCode }); |
| | | return emptyLocations[i]; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | public Dt_LocationInfo? GetLocationplatform(string LocationCode) |
| | | { |
| | | Dt_LocationInfo locationInfos = BaseDal.QueryFirst(x => x.LocationCode == LocationCode); |
| | | if(locationInfos !=null) |
| | | { |
| | | return locationInfos; |
| | | } |
| | | else |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | public WebResponseContent InitializationLocation(InitializationLocationDTO initializationLocationDTO) |
| | | { |
| | | try |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public class LocationCache |
| | | { |
| | | public string LocationCode { get; set; } |
| | | |
| | | public DateTime DateTime { get; set; } |
| | | } |
| | | } |
| | | } |