ningshuxia
2024-04-09 51730f13db4aa7e353be3c8133e8429bf19ea3b1
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
namespace IStation.DAL
{
    /// <summary>
    /// 测点映射
    /// </summary>    
    public class MonitorPointMapping : BaseDAL<Entity.MonitorPointMapping>
    {
        /// <summary>
        /// 
        /// </summary>
        public override string FileName
        {
            get { return FileHelper.GetFilePath<Entity.MonitorPointMapping>(); }
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取
        /// </summary>
        public List<Entity.MonitorPointMapping> GetByMonitorPointID(long monitorPointId)
        {
            var all = GetAll();
            var list = all?.Where(x => x.MonitorPointID == monitorPointId).ToList();
            return list;
        }
 
        /// <summary>
        /// 通过 MappingType 和 MappingID 获取
        /// </summary>
        public List<Entity.MonitorPointMapping> GetByMappingTypeAndMappingID(string mappingType, long mappingId)
        {
            var all = GetAll();
            var list = all?.Where(x => x.MappingType == mappingType && x.MappingID == mappingId).ToList();
            return list;
        }
 
 
        /// <summary>
        /// 设置
        /// </summary>
        public bool SetOfObject(string mappingType, long mappingId, List<Entity.MonitorPointMapping> list)
        {
            if (list == null || list.Count() < 1)
            {
                return DeleteByMappingTypeAndMappingID(mappingType, mappingId);
            }
            var all = GetAll();
            if (all == null)
                all = new List<Entity.MonitorPointMapping>();
            all.RemoveAll(x => x.MappingType == mappingType && x.MappingID == mappingId);
            list.ToList().ForEach(x =>
            {
                if (x.ID < 1)
                    x.ID = Yw.YitIdHelper.NextId();
            });
            all.AddRange(list);
            Covers(all);
            return true;
        }
 
 
        /// <summary>
        /// 通过 MonitorPointID 删除
        /// </summary>
        public bool DeleteByMonitorPointID(long monitorPointId)
        {
            var all = GetAll();
            if (all == null || all.Count < 1)
                return false;
            all.RemoveAll(x => x.MonitorPointID == monitorPointId);
            Covers(all);
            return true;
        }
 
        /// <summary>
        /// 通过 MappingType 和 MappingID 删除
        /// </summary>
        public bool DeleteByMappingTypeAndMappingID(string mappingType, long mappingId)
        {
            var all = GetAll();
            if (all == null || all.Count < 1)
                return false;
            all.RemoveAll(x => x.MappingType == mappingType && x.MappingID == mappingId);
            Covers(all);
            return true;
        }
 
        /// <summary>
        /// 通过 MappingType 和 MappingIds 删除
        /// </summary>
        public bool DeleteByMappingTypeAndMappingIds(string mappingType, List<long> mappingIds)
        {
            if (mappingIds == null || mappingIds.Count() < 1)
                return false;
            var all = GetAll();
            if (all == null || all.Count < 1)
                return false;
            all.RemoveAll(x => x.MappingType == mappingType && mappingIds.Contains(x.MappingID));
            Covers(all);
            return true;
        }
 
    }
}