kazelee
7 天以前 2ca90a404fa1ab94eb6374f50c6ddd47a2b7f0e6
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using HH.WCS.Mobox3.DSZSH.models;
using HH.WCS.Mobox3.DSZSH.util;
using Newtonsoft.Json;
using static HH.WCS.Mobox3.DSZSH.api.ApiModel;
using static HH.WCS.Mobox3.DSZSH.util.Config;
 
namespace HH.WCS.Mobox3.DSZSH.wms {
    /// <summary>
    /// [ 具体业务 ] 帮助类
    /// </summary>
    public class WMSHelper {
        /// <summary>
        /// 检查容器类型 ( 容器表 不存在 / 类型不匹配 时 , 返回 false )
        /// </summary>
        /// <param name="cntrCode"></param>
        /// <param name="cntrType"></param>
        /// <param name="cntr"></param>
        /// <returns></returns>
        public static (bool, string) CheckCntrType(string cntrCode, string cntrType, out TN_Container cntr) { 
            var db = new SqlHelper<object>().GetInstance();
 
            cntr = db.Queryable<TN_Container>().Where(c => c.S_CODE == cntrCode).First();
            if (cntr == null) {
                return (false, $"容器'{cntrCode}'在[容器表]中不存在,请在前台页面中维护!!");
            }
            if (cntr.S_TYPE != cntrType) {
                return (false, $"容器'{cntrCode}'在[容器表]中的类型为'{cntr.S_TYPE}',与当前流程所需容器类型'{cntrType}'不同!!");
            }
            return (true, "检查容器类型成功!!");
        }
        /// <summary>
        /// 根据容器号 , 查找旧的货位 / 货位绑定 / 物料信息 ( 将待删除 / 更新数据写入 obj )
        /// </summary>
        /// <remarks><code><![CDATA[obj.Old = oldLocCntrCg;]]></code></remarks>
        /// <param name="obj"></param>
        /// <param name="cntrCode"></param>
        /// <param name="skipCgDetail"></param>
        /// <returns></returns>
        public static LocCntrCg FindOldCntrInfo(CreateTaskObj obj, string cntrCode, bool skipCgDetail = true) {
            var oldLocCntrCg = WCSHelper.GetLocCntrCg(cntrCode, skipCgDetail);
            obj.Old = oldLocCntrCg;
            return oldLocCntrCg;
        }
        /// <summary>
        /// 绑定货位容器 ( 修改 [ 货位容器表 ] [ 货位类型 ] = cntrType ; 将 [ 待插入 ] 货位容器关系 加入到 obj 中 )<br/>
        /// 调用 <see cref="WCSHelper.BindLocCntr"/> 设置 loc.N_CURRENT_NUM = 1
        /// </summary>
        /// <remarks><code><![CDATA[obj.New = new LocCntrCg { LocCntrRel = locCntrRel };]]></code></remarks>
        /// <param name="obj"></param>
        /// <param name="loc"></param>
        /// <param name="cntrCode"></param>
        /// <param name="cntrType"></param>
        /// <returns></returns>
        public static TN_Loc_Container BindLocCntr(CreateTaskObj obj, TN_Location loc, string cntrCode, string cntrType = "") {
            var locCntrRel = WCSHelper.BindLocCntr(loc, cntrCode);
            if (!string.IsNullOrEmpty(cntrType)) {
                locCntrRel.S_CNTR_TYPE = cntrType;
            }
            obj.New = new LocCntrCg { LocCntrRel = locCntrRel };
            return locCntrRel;
        }
        /// <summary>
        /// 创建任务 ( 构造任务项 / 起点终点上锁 ; 将 插入任务 / 更新货位 的对象写入 obj )
        /// </summary>
        /// <remarks><code><![CDATA[
        /// obj.TaskToInsert = task;
        /// obj.StartLocToUpdate = startLoc;
        /// obj.EndLocToUpdate = endLoc;
        /// ]]></code></remarks>
        /// <param name="obj"></param>
        /// <param name="startLoc"></param>
        /// <param name="endLoc"></param>
        /// <param name="cntId"></param>
        /// <param name="type"></param>
        /// <param name="pri"></param>
        /// <param name="agv"></param>
        public static TN_Task CreateTask(CreateTaskObj obj, TN_Location startLoc, TN_Location endLoc, string cntId, string type,
            int pri = 3, int agv = 1) {
 
            var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, type, pri);
            WCSHelper.LockStartLoc(startLoc, task.S_CODE);
            WCSHelper.LockEndLoc(endLoc, task.S_CODE);
 
            obj.TaskToInsert = task;
            obj.StartLocToUpdate = startLoc;
            obj.EndLocToUpdate = endLoc;
 
            return task;
        }
 
        private const bool __查询语句封装__ = false; // 仅用于分段,没有实质意义(VS2022 v17.4.3 文档大纲)
        #region 查询语句(搁置,设为私有,查询需求变更多,封装不够灵活)
        /// <summary>
        /// 查询 [ 绑定前 ] 的起点货位
        /// </summary>
        /// <example><code><![CDATA[
        /// (ok, msg) = WMSHelper.FindStartLocUnbind(model.StartLoc, taskInfo.StartAreas, out var startLoc);
        /// if (!ok) return NewSimpleResult(2, preLog + msg);
        /// ]]></code></example>
        /// <param name="locCode"></param>
        /// <param name="areas"></param>
        /// <param name="startLoc"></param>
        /// <returns></returns>
        private static (bool, string) FindStartLocUnbind(string locCode, List<string> areas, out TN_Location startLoc) {
            var db = new SqlHelper<object>().GetInstance();
            startLoc = db.Queryable<TN_Location>().Where(DbExpr.StartLocUnbind(locCode, areas)).First();
            if (startLoc == null) {
                return (false, LogMsg.StartLocUnbindNotFound(locCode, areas));
            }
            return (true, "");
        }
        /// <summary>
        /// 查询 [ 绑定后 ] 的起点货位
        /// </summary>
        /// <example><code><![CDATA[
        /// (ok, msg) = WMSHelper.FindStartLoc(model.StartLoc, taskInfo.StartAreas, out var startLoc);
        /// if (!ok) return NewSimpleResult(2, preLog + msg);
        /// ]]></code></example>
        /// <param name="locCode"></param>
        /// <param name="areas"></param>
        /// <param name="startLoc"></param>
        /// <returns></returns>
        private static (bool, string) FindStartLoc(string locCode, List<string> areas, out TN_Location startLoc) {
            var db = new SqlHelper<object>().GetInstance();
            startLoc = db.Queryable<TN_Location>().Where(DbExpr.StartLoc(locCode, areas)).First();
            if (startLoc == null) {
                return (false, LogMsg.StartLocNotFound(locCode, areas));
            }
            return (true, "");
        }
        /// <summary>
        /// 查询终点货位
        /// </summary>
        /// <example><code><![CDATA[
        /// (ok, msg) = WMSHelper.FindEndLoc(areas: taskInfo.EndAreas, out var endLoc);
        /// if (!ok) return NewSimpleResult(3, preLog + msg);
        /// ]]></code></example>
        /// <param name="locCode"></param>
        /// <param name="areas"></param>
        /// <param name="endLoc"></param>
        /// <returns></returns>
        private static (bool, string) FindEndLoc(string locCode, List<string> areas, out TN_Location endLoc) {
            var db = new SqlHelper<object>().GetInstance();
            endLoc = db.Queryable<TN_Location>().Where(DbExpr.EndLoc(locCode, areas)).First();
            if (endLoc == null) {
                return (false, LogMsg.EndLocNotFound(locCode, areas));
            }
            return (true, "");
        }
        #endregion
    }
}