wangxinhui
2024-09-23 a3eb67538c4716aef9967f1e6301720cce095e3c
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
using System;
using WIDESEA_Common.DBHelper;
using WIDESEA_Common.EquipmentEnum;
using WIDESEA_Entity.DomainModels;
 
namespace WIDESEA_WCS.JobsPart.Public
{
    public partial class WCSCommon
    {
        public static FreeDB freeDB = new FreeDB();
 
        /// <summary>
        /// 获取起点或终点位置
        /// </summary>
        /// <param name="address">目的或来源地址</param>
        /// <param name="isIn">放入缓存架或从缓存架取走</param>
        /// <param name="type">提升机叫料物料类型</param>
        /// <returns></returns>
        /// <summary>
        public static string GetAddress(string address, bool isIn = true, string type = "")
        {
            dt_stationinfo res = null;
            if (isIn)
            {
                //路由表配置了路由且当前没有任务
                res = freeDB.Select<dt_stationinfo>()
                  .Where(t => t.enable
                           && t.getStatus == (int)StationEnum.Empty
                           && t.getLastTime != null
                           && (DateTime.Now - t.getLastTime).TotalSeconds <= 5)
                  .Where(@"exists (select route_id from base_routing_table where route_began=@address and route_end=a.stationCode)", new { address })
                  .Where(@"not EXISTS
                        (
                        SELECT address from
                            (
                            (select agv_fromaddress address from dt_agvtask)
                            UNION all 
                            (select agv_toaddress address from dt_agvtask)
                            ) t
                        where address=a.stationCode)")
                  .OrderBy(t => t.sort)
                  .ToOne();
            }
            else
            {
                res = freeDB.Select<dt_stationinfo>()
                   .Where(t => t.enable
                            && t.getStatus == (int)StationEnum.Stroge
                            && t.getLastTime != null
                            && (DateTime.Now - t.getLastTime).TotalSeconds <= 5)
                   .WhereIf(!string.IsNullOrEmpty(type), t => t.stationType == type)
                   .Where(@"exists (select route_id from base_routing_table where route_end=@address and route_began=a.stationCode)", new { address })
                   .Where(@"not EXISTS
                        (
                        SELECT address from
                            (
                            (select agv_fromaddress address from dt_agvtask)
                            UNION all 
                            (select agv_toaddress address from dt_agvtask)
                            ) t
                        where address=a.stationCode)")
                   .OrderBy(t => t.lastUpdateTime)
                   .ToOne();
            }
            if (res == null)
            {
                throw new Exception("无可用缓存架");
            }
            return res.stationCode;
        }
    }
}