kazelee
3 天以前 63e94e068622d4ef843cee0d19d4f2d231316304
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
using System;
using System.Collections.Generic;
using System.Linq;
 
using HH.WCS.Mobox3.DSZSH.models;
using HH.WCS.Mobox3.DSZSH.util;
 
using Newtonsoft.Json;
 
using SqlSugar;
 
namespace HH.WCS.Mobox3.DSZSH.wms {
    /// <summary>
    /// 货位帮助类(包含货位-容器关系的处理) 
    /// </summary>
    public class LocationHelper
    {
        private static Dictionary<string, TN_Location> _locationDict = null;
 
        static LocationHelper()
        {
            try
            {
                //初始化Location加入到字典缓存
                _locationDict = new Dictionary<string, TN_Location>();
                var list = GetAllLocList();
                if (list.Count > 0)
                {
                    list.ForEach(a =>
                    {
                        if (!_locationDict.ContainsKey(a.S_CODE))
                        {
                            _locationDict.Add(a.S_CODE, a);
                        }
                    });
                }
                //初始化LocationExt加入到集合缓存
                //LocationExts = new Dictionary<string, LocationExt>();
                //var exts = GetAllLocExtList();
                //if (exts.Count > 0) {
                //    exts.ForEach(a => {
                //        LocationExts.Add($"{a.S_LOC_CODE.Trim()}_{a.S_PICKUP_POINT.Trim()}", a);
                //    });
                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 
        /// <summary>
        /// 获取所有货位信息
        /// </summary>
        /// <returns></returns>
        internal static List<TN_Location> GetAllLocList()
        {
            var db = new SqlHelper<object>().GetInstance();
            return db.Queryable<TN_Location>().ToList();
        }
 
 
        internal static TN_Location GetLocation(string loc)
        {
            if (_locationDict.Keys.Contains(loc))
            {
                return _locationDict[loc.Trim()];
            }
            return null;
        }
 
        //public static bool IsStartLocFound(string startLocCode, ref )
 
        /// <summary>
        /// 获取货位站点信息
        /// </summary>
        /// <param name="loc"></param>
        /// <param name="isEmpty">是否属于人工空托区到空托缓存库区</param>
        /// <returns></returns>
        internal static string GetAgvSite(string loc, bool isEmpty = false) {
            var site = "0";
            if (_locationDict.Keys.Contains(loc.Trim()) && !isEmpty) {
                var Location = _locationDict[loc.Trim()];
                site = Location.S_AGV_SITE;
            }
            else {
                var Location = GetLoc(loc.Trim());
                if (Location != null) {
                    site = Location.S_AGV_SITE;
 
                    if (isEmpty) {
                        if (Location.N_CURRENT_NUM == 0) {
                            site = Location.S_AGV_SITE;
                        }
                    }
                }
            }
            return site;
        }
 
        internal static TN_Location GetLoc(string code) {
            var db = new SqlHelper<object>().GetInstance();
            return db.Queryable<TN_Location>().Where(a => a.S_CODE.Trim() == code).First();
        }
 
        
    }
}