schangxiang@126.com
2025-09-18 4b02d54422910170d2cedabf6866b6e6bec20dac
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using logtxtWrite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using wcftest.BussinessExtension.Common;
using wcftest.BussinessExtension.Handle;
using wcftest.EnumDefine;
using wcftest.EnumDefine.Sys;
using wcftest.Model;
using wcftest.orm;
 
namespace wcftest.BussinessExtension
{
    public class ExtendHelper
    {
        /// <summary>
        /// 验证库位号是否规范正确
        /// </summary>
        /// <param name="positionName"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool ValidateIsRightForPositionName(string positionName, ref string msg)
        {
            if (positionName != SysGlole.PositionName_SHZCQ)
            {//正常库位 1-01-02-06
                string[] arr_positionName = positionName.Trim().Split('-');
                if (arr_positionName.Length != 4)
                {
                    msg = "库位号不符合长度!" + positionName;
                    return false;
                }
            }
            return true;
        }
 
        /// <summary>
        /// 拼盘出库,清空库存
        /// </summary>
        /// <param name="mod"></param>
        /// <param name="containerCode"></param>
        /// <param name="creator"></param>
        public static void RemoveProductPositionForPinPan(dbModel mod, string containerCode, string creator)
        {
            List<Base_ProductPosition> productPositionList = mod.Base_ProductPosition.Where(x => x.PlateCode == containerCode).ToList();
            if (productPositionList.Count < 1)
            {
                logtxt.txtWrite("类名:taskApi,函数名:madeDish  Base_ProductPosition组盘出库 找不到托盘数据:" + containerCode, 2);
                throw new Exception("根据托盘号" + containerCode + "没有找到库存,无法将拼盘出库的库存清空");
            }
            foreach (var itemRemove in productPositionList)
            {
                mod.Base_ProductPosition.Remove(itemRemove);
                //增加出入库记录 【EditBy shaocx,2022-03-07】
                OutInStockTaskHandler.AddOutInStockTask22(creator, mod, OutInStockTaskName.清库任务, itemRemove.ProductStorage, itemRemove, "拼盘,清空库存", "", "");
            }
        }
 
        /// <summary>
        /// 获取入库日期
        /// </summary>
        /// <param name="shelve"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public static DateTime GetInStorageDate(Purchase_Shelve shelve, Purchase_ShelveList item)
        {
            DateTime dt = DateTime.Now;
            if (shelve.ShelveType == ShelveTypeEnum.拼盘上架.ToString())
            {
                if (item.InStorageDate != null)
                {
                    dt = (DateTime)item.InStorageDate;
                }
            }
            return dt;
        }
 
        /// <summary>
        /// 转换PLC任务号
        /// </summary>
        /// <param name="taskId"></param>
        /// <returns></returns>
        public static int ConvertPlcNO(int taskId)
        {
            if (taskId >= 65535)
            {
                taskId %= 65535;
            }
            taskId += 1;//自增加1
            if (taskId <= 0)// 增加验证 【Editby shaocx,2023-03-18】
            {
                throw new Exception("生成的任务号不能为0!");
            }
            if (taskId > 65535)// 增加验证 【Editby shaocx,2023-03-18】
            {
                throw new Exception("生成的任务号不能大于65535!");
            }
            return taskId;
        }
 
        /// <summary>
        /// 获取基础数据的叠盘机编号
        /// </summary>
        /// <param name="plateType"></param>
        /// <returns></returns>
        public static DiePanJiModel GetDeviceCodeForDiePanJi(int plateType)
        {
            DiePanJiModel model = null;
            //根据表Base_Equipment的配置得来
            Sys_containerType _Sys_containerType = (Sys_containerType)Enum.Parse(typeof(Sys_containerType), plateType.ToString());
            switch (_Sys_containerType)
            {
                case Sys_containerType.大托盘:
                    model = new DiePanJiModel()
                    {
                        DeviceCode = "D001",
                        DeviceName = "大叠盘机",
                        FullQuantity = 8
                    };
                    break;
                case Sys_containerType.小托盘:
                    model = new DiePanJiModel()
                    {
                        DeviceCode = "D002",
                        DeviceName = "小叠盘机",
                        FullQuantity = 10
                    };
                    break;
            }
 
            return model;
        }
 
        /// <summary>
        /// 获取要更新OnShelveStatus字段的失败字符串
        /// </summary>
        /// <param name="checkHeight"></param>
        /// <param name="height"></param>
        /// <param name="findEmptyReason"></param>
        /// <returns></returns>
        public static string GetOnShelveStatusFailMsg(int checkHeight, int height, string findEmptyReason)
        {
            return "找不到可用空库位-" + "光电检测高度:" + checkHeight + ",系统校验高度:" + height + "," + findEmptyReason;
        }
 
        //    /// <summary>
        //    /// 根据光电检测高度,得出库区1的高度
        //    /// </summary>
        //    /// <param name="checkHeight">光电检测高度</param>
        //    /// <returns></returns>
        //    public static int ConvertHeightForArea1(int checkHeight)
        //    {
        //        /*
        //         * 小堆垛机:
        //高度 1、2、3 ,去往 0-975
        //高度 4、5、6,去往 975-1850
        //         */
        //        return checkHeight > 3 ? 2 : 1;//因为库区1的高度只有两种,所以就转换成了1,2两种
        //    }
 
        //    /// <summary>
        //    /// 根据光电检测高度,得出库区2的高度
        //    /// </summary>
        //    /// <param name="checkHeight">光电检测高度</param>
        //    /// <returns></returns>
        //    public static int ConvertHeightForArea2(int checkHeight)
        //    {
        //        return checkHeight > 3 ? checkHeight - 1 : checkHeight;//因为库区2的高度只有四种,所以就转换成了1,2,3,4四种
        //    }
 
        /// <summary>
        /// 根据光电检测高度,得出库区的高度
        /// </summary>
        /// <param name="checkHeight">光电检测高度</param>
        /// <returns></returns>
        public static int ConvertHeightByArea(int areaCode, int checkHeight)
        {
            if (areaCode == 1)
            {//库区1
                /*
            * 小堆垛机:
   高度 1、2、3 ,去往 0-975
   高度 4、5、6,去往 975-1850
            */
                return checkHeight > 3 ? 2 : 1;//因为库区1的高度只有两种,所以就转换成了1,2两种
            }
            else if (areaCode == 2)
            {//库区2
                return checkHeight > 3 ? checkHeight - 1 : checkHeight;//因为库区2的高度只有四种,所以就转换成了1,2,3,4四种
            }
            else
            {
                throw new Exception("无效的库区" + areaCode);
            }
        }
    }
}