ningshuxia
2022-12-12 e81ca048ef4e9345e904b74ffffd3e8413d18a7e
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.Service
{
    /// <summary>
    /// 
    /// </summary>
    public class InspectionContentBundle
    {
        /// <summary>
        /// 通过 CorpID 获取缓存
        /// </summary>
        /// <param name="CorpID"></param>
        /// <returns></returns>
        private List<Model.ProductInspectionContentViewModel> GetCorpCache(long CorpID)
        {
            return InspectionContentBundleCacheHelper.GetSet(CorpID, () =>
            {
                var service_grp = new Service.ProductInspectionContentGrp();
                var model_grp_list = service_grp.GetByCorpID(CorpID);
                if (model_grp_list == null)
                {
                    return new List<Model.ProductInspectionContentViewModel>();
                }
 
                var service_item = new Service.ProductInspectionContentItem();
                var model_item_list = service_item.GetByCorpID(CorpID);
                if (model_item_list == null)
                {
                    return new List<Model.ProductInspectionContentViewModel>();
                }
 
                var service_value = new Service.ProductInspectionContentValue();
                var model_value_list = service_value.GetByCorpID(CorpID);
                if (model_value_list == null)
                {
                    model_value_list = new List<Model.ProductInspectionContentValue>();
                }
 
 
                List<Model.ProductInspectionContentViewModel> v_list = new List<Model.ProductInspectionContentViewModel>();
 
                foreach(var grp in model_grp_list)
                {
                    if (grp.UseStatus != Model.ProductInspectionContentGrp.eUseStatus.有效)
                        continue;
 
                    foreach (var item in model_item_list)
                    {
                        if (item.GroupID != grp.ID)
                            continue;
 
                        if (item.UseStatus != Model.ProductInspectionContentItem.eUseStatus.有效)
                            continue;
                        var v_item = new Model.ProductInspectionContentViewModel(item);
                        v_item.GroupName = grp.Name;
 
                        var vvv = model_value_list.Where(x => x.ItemID == item.ID);
                        if (vvv.Count() > 0)
                        {
                            v_item.ValueList = new List<Model.ProductInspectionContentValue.BaseInfo>();
                            foreach(var v in vvv)
                            {
                                if(v.UseStatus == Model.ProductInspectionContentValue.eUseStatus.有效)
                                    v_item.ValueList.Add(new Model.ProductInspectionContentValue.BaseInfo(v));
                            }
                        }
                      
 
 
                        v_list.Add(v_item);
                    }
                }
                
 
                return v_list;
            }, ConfigHelper.CacheKeepTime, ConfigHelper.CacheRandomTime);
        }
       
        /// <summary>
        /// 
        /// </summary>
        /// <param name="CorpID"></param>
        /// <param name="ProductID"></param>
        /// <returns></returns>
        public List<IStation.Model.ProductInspectionContentViewModel> GetByProductID(long CorpID, long ProductID)
        {
            var all = GetCorpCache(CorpID);
            if (all == null || all.Count == 0)
                return null;
 
            return (from x in all where x.ProductID == ProductID   select x).ToList();
        }
 
        /// <summary>
        /// 获取哪些已经配置的产品ID列表
        /// </summary>
        /// <param name="CorpID"></param>
        /// <returns></returns>
        public List<long> GetProductIDList(long CorpID)
        {
            var all = GetCorpCache(CorpID);
            return (from x in all select x.ProductID).Distinct().ToList();
        }
 
 
    }
}