ningshuxia
2025-04-03 4917fb959e2befec07a693e72d7010c09494ec7c
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
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace IStation.DAL
{
    /// <summary>
    /// 设备监测映射
    /// </summary>    
    public class EquipmentMonitorMapping : BaseDAL<Entity.EquipmentMonitorMapping>
    {
        public override ConnectionConfig ConnectionConfig
        {
            get { return ConnectionFactory.BasicConnection(SettingsD.Project.ID); }
        }
 
 
        /// <summary>
        /// 通过 EquipmentID 获取
        /// </summary>
        public List<Entity.EquipmentMonitorMapping> GetByEquipmentID(long equipmentId)
        {
            if (equipmentId < 1)
                return default;
            using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.EquipmentMonitorMapping>()
                    .Where(x => x.EquipmentID == equipmentId)
                    .ToList();
            }
        }
 
        /// <summary>
        /// 设置
        /// </summary>
        public bool SetOfObject(long equipmentId, List<Entity.EquipmentMonitorMapping> list)
        {
            if (equipmentId < 1)
                return default;
 
            using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
            {
                try
                {
                    db.Ado.BeginTran();
                    var existList = db.Queryable<Entity.EquipmentMonitorMapping>()
                        .Where(x => x.EquipmentID == equipmentId)
                        .ToList();
                    if (existList.Count > 0)
                    {
                        var bol = db.Deleteable(existList).ExecuteCommand() > 0;
                        if (!bol)
                        {
                            db.Ado.RollbackTran();
                            return false;
                        }
                    }
 
                    if (list != null && list.Any())
                    {
                        list.ForEach(x => x.ID = SnowflakeIdHelper.NextId());
                        var bol = db.Insertable(list).ExecuteCommand() > 0;
                        if (!bol)
                        {
                            db.Ado.RollbackTran();
                            return false;
                        }
                    }
                    db.Ado.CommitTran();
                }
                catch (Exception ex)
                {
                    db.Ado.RollbackTran();
                    throw ex;
                }
            }
            return true;
        }
 
 
        /// <summary>
        /// 通过 EquipmentID 删除
        /// </summary>
        public bool DeleteByEquipmentID(long equipmentId)
        {
            if (equipmentId < 1)
                return default;
            using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Deleteable<Entity.EquipmentMonitorMapping>().Where(x => x.EquipmentID == equipmentId).ExecuteCommand() > 0;
            }
        }
 
        /// <summary>
        /// 通过 EquipmentIs 删除
        /// </summary>
        public bool DeleteByEquipmentIds(List<long> equipmentIds)
        {
            if (equipmentIds == null || equipmentIds.Count() < 1)
                return false;
            using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Deleteable<Entity.EquipmentMonitorMapping>().Where(x => equipmentIds.Contains(x.ID)).ExecuteCommand() > 0;
            }
        }
 
    }
 
}