| | |
| | | public override ConnectionConfig ConnectionConfig |
| | | { |
| | | get { return ConfigHelper.DefaultConnectionConfig; } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过 ObjectType 和 ObjectID 获取 |
| | | /// </summary> |
| | | public List<Entity.SpecialPropertyValue> GetByObjectTypeAndObjectID(long CorpID, string ObjectType, long ObjectID) |
| | | { |
| | | using (var db = new SqlSugarClient(ConnectionConfig)) |
| | | { |
| | | return db.Queryable<Entity.SpecialPropertyValue>() |
| | | .Where(x => x.CorpID == CorpID && x.ObjectType==IStation.ObjectType.Station&&x.ObjectID==ObjectID).ToList(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过 Object 和 PropertyID 获取 |
| | | /// </summary> |
| | | public Entity.SpecialPropertyValue GetObjectAndPropertyID(long CorpID, string ObjectType, long ObjectID, long PropertyID) |
| | | { |
| | | using (var db = new SqlSugarClient(ConnectionConfig)) |
| | | { |
| | | return db.Queryable<Entity.SpecialPropertyValue>() |
| | | .First(x => x.CorpID == CorpID && x.ObjectType == IStation.ObjectType.Station && x.ObjectID == ObjectID&&x.PropertyID== PropertyID); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过 PropertyID 获取 |
| | | /// </summary> |
| | | public List<Entity.SpecialPropertyValue> GetByPropertyID(long CorpID, long PropertyID) |
| | | { |
| | | using (var db = new SqlSugarClient(ConnectionConfig)) |
| | | { |
| | | return db.Queryable<Entity.SpecialPropertyValue>() |
| | | .Where(x => x.CorpID == CorpID && x.PropertyID==PropertyID).ToList(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过 PropertyIds 获取 |
| | | /// </summary> |
| | | public List<Entity.SpecialPropertyValue> GetByPropertyIds(long CorpID, List<long> PropertyIds) |
| | | { |
| | | if (PropertyIds == null || PropertyIds.Count < 1) |
| | | return default; |
| | | using (var db = new SqlSugarClient(ConnectionConfig)) |
| | | { |
| | | return db.Queryable<Entity.SpecialPropertyValue>() |
| | | .Where(x => x.CorpID == CorpID && PropertyIds.Contains(x.PropertyID)).ToList(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置 |
| | | /// </summary> |
| | | public bool Set(List<Entity.SpecialPropertyValueSetter> list) |
| | | { |
| | | if (list == null || list.Count() < 1) |
| | | return false; |
| | | var corpIds = list.Select(x => x.CorpID).Distinct().ToList(); |
| | | if (corpIds.Count != 1) |
| | | return false; |
| | | using (var db = new SqlSugarClient(ConnectionConfig)) |
| | | { |
| | | try |
| | | { |
| | | db.BeginTran(); |
| | | foreach (var item in list) |
| | | { |
| | | var bol = db.Queryable<Entity.SpecialPropertyValue>() |
| | | .Where(x => x.CorpID == item.CorpID && x.ObjectType == item.ObjectType && x.ObjectID==item.ObjectID && x.PropertyID == item.PropertyID).Count() > 0; |
| | | if (bol)//已存在 |
| | | { |
| | | var result = db.Updateable<Entity.SpecialPropertyValue>() |
| | | .SetColumns(x => x.PropertyValue== item.PropertyValue) |
| | | .Where(x => x.CorpID == item.CorpID&&x.ObjectType==item.ObjectType&&x.ObjectID==item.ObjectID && x.PropertyID == item.PropertyID) |
| | | .ExecuteCommand() > 0; |
| | | if (!result) |
| | | { |
| | | db.RollbackTran(); |
| | | return false; |
| | | } |
| | | } |
| | | else//不存在 |
| | | { |
| | | var entity = new Entity.SpecialPropertyValue(); |
| | | entity.CorpID = item.CorpID; |
| | | entity.ObjectType = item.ObjectType; |
| | | entity.ObjectID = item.ObjectID; |
| | | entity.PropertyID = item.PropertyID; |
| | | entity.PropertyValue = item.PropertyValue; |
| | | var id = db.Insertable(entity).ExecuteReturnSnowflakeId(); |
| | | if (id < 1) |
| | | { |
| | | db.RollbackTran(); |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | db.CommitTran(); |
| | | return true; |
| | | } |
| | | catch |
| | | { |
| | | db.RollbackTran(); |
| | | throw; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |