kazelee
2 天以前 0ed390381862dea0c7fd0210d16017eb09f12da4
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
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>
        /// 检查容器类型
        /// </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>
        /// 
        /// </summary>
        /// <param name="locCode"></param>
        /// <param name="areas"></param>
        /// <param name="startLoc"></param>
        /// <returns></returns>
        public 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>
        /// 根据容器号 , 查找旧的货位 / 货位绑定 / 物料信息 ( 将待删除 / 更新数据写入 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 FindCntrOldInfo(CreateTaskObj obj, string cntrCode, bool skipCgDetail = true) {
            var oldLocCntrCg = WCSHelper.GetLocCntrCg(cntrCode, skipCgDetail);
            obj.Old = oldLocCntrCg;
            return oldLocCntrCg;
        }
        /// <summary>
        /// 绑定货位容器 ( 修改 [ 货位容器表 ] [ 货位类型 ] = cntrType ; 将 [ 待插入 ] 货位容器关系 加入到 obj 中 )
        /// </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;
        }
    }
}