杨前锦
2025-07-07 c8f338feee0b6003d8f069b1d37fd9b90dd1b7f4
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
using HH.WCS.Mobox3.YNJT_BZP.util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static HH.WCS.Mobox3.YNJT_BZP.api.ApiHelper;
using static HH.WCS.Mobox3.YNJT_BZP.wms.LocationHelper;
 
namespace HH.WCS.Mobox3.YNJT_BZP.wms {
    internal class ItemHelper {
        private static Dictionary<string,ItemInfo > itemInfos = null;
 
        static ItemHelper() {
            try {
                //初始化Location加入到字典缓存
                itemInfos = new Dictionary<string, ItemInfo>();
                var list = GetAllItemList();
                if (list.Count > 0) {
                    list.ForEach(a => {
                        if (!itemInfos.ContainsKey(a.S_ITEM_CODE)) {
                            itemInfos.Add(a.S_ITEM_CODE, a);
                        }
                    });
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
        internal static ItemInfo GetItemInfo(string code) {
            if (itemInfos.ContainsKey(code)) {
                return itemInfos[code];
            }
            else {
                return null;
            }
        }
        internal static List<ItemInfo> GetAllItemList() {
            var db = new SqlHelper<object>().GetInstance();
            return db.Queryable<ItemInfo>().ToList();
        }
 
        internal static CntrItemRel GetCntrItem(string itemCode)
        {
            var db = new SqlHelper<object>().GetInstance();
            return db.Queryable<CntrItemRel>().Where(a => a.S_ITEM_CODE == itemCode).First();
        }
 
        public static bool addCntrItem(string cntrCode,List<GTItemInfo> itemInfos) 
        {
            var db = new SqlHelper<object>().GetInstance();
            var cntrItemRels = db.Queryable<CntrItemRel>().Where(a => a.S_CNTR_CODE == cntrCode).ToList();
            if (cntrItemRels.Count > 0)
            {
                ContainerHelper.deleteCntrItem(cntrCode);
            }
            if (itemInfos != null && itemInfos.Count > 0)
            {
                foreach (var itemInfo in itemInfos)
                {
                    DateTime txndate = DateTime.Parse(itemInfo.txndate);
                    DateTime minTime = txndate.AddHours(itemInfo.minhour);
                    DateTime maxTime = txndate.AddDays(itemInfo.overage);
                    var effective_time = minTime.ToString("yyyy-MM-dd HH:mm:ss");
                    var expiration_time = maxTime.ToString("yyyy-MM-dd HH:mm:ss");
 
                    CntrItemRel cntrItemRel = new CntrItemRel()
                    {
                        S_CNTR_CODE = cntrCode,
                        S_ITEM_CODE = itemInfo.item,
                        S_CG_ID = itemInfo.bc_entried,
                        S_MCN = itemInfo.mcn,
                        S_ITEM_STATE = itemInfo.jdge,
                        F_QTY = itemInfo.qty,
                        S_TXNDATE = itemInfo.txndate,
                        S_SHIFT = itemInfo.shift,
                        S_EFFECTIVE_TIME = effective_time,
                        S_EXPIRATION_TIME = expiration_time,
                        N_PRODUCT_TYPE_CODE = itemInfo.productTypeCode
                    };
                    ContainerHelper.addCntrItem(cntrCode, cntrItemRel);
                }
            }
            return true;
        }
    }
}