using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using IStation.Entity;
|
using System.Data.SqlClient;
|
using SqlSugar;
|
using System.Threading.Tasks;
|
using System.Data;
|
|
namespace IStation.DAL
|
{
|
/// <summary>
|
/// 用户关注
|
/// </summary>
|
public partial class UserAttention : BaseDAL<Entity.UserAttention>
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public override ConnectionConfig ConnectionConfig
|
{
|
get { return ConfigHelper.DefaultConnectionConfig; }
|
}
|
|
/// <summary>
|
/// 通过 UserID 获取
|
/// </summary>
|
public List<Entity.UserAttention> GetByUserID(long UserID)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.UserAttention>()
|
.Where(x => x.UserID == UserID).ToList();
|
}
|
}
|
|
/// <summary>
|
/// 通过 Object 获取
|
/// </summary>
|
public List<Entity.UserAttention> GetByObject(long CorpID, string ObjectType, long ObjectID)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.UserAttention>()
|
.Where(x => x.CorpID == CorpID&&x.ObjectType==ObjectType&&x.ObjectID==ObjectID).ToList();
|
}
|
}
|
|
/// <summary>
|
/// 设置
|
/// </summary>
|
public bool Set(long UserID, List<Entity.AttentionObjectSelected> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.BeginTran();
|
foreach (var item in list)
|
{
|
var bol = db.Queryable<Entity.UserAttention>()
|
.Where(x => x.UserID == UserID && x.CorpID==item.CorpID&& x.ObjectType == item.ObjectType && x.ObjectID == item.ObjectID)
|
.Count() > 0;
|
if (bol)//已存在
|
{
|
if (!item.Selected)//未选择
|
{
|
var result = db.Deleteable<Entity.UserAttention>()
|
.Where(x => x.UserID == UserID && x.CorpID==item.CorpID&& x.ObjectType == item.ObjectType && x.ObjectID == item.ObjectID)
|
.ExecuteCommandHasChange();
|
if (!result)
|
{
|
db.RollbackTran();
|
return false;
|
}
|
}
|
}
|
else//不存在
|
{
|
if (item.Selected)//选择
|
{
|
var entity = new Entity.UserAttention();
|
entity.UserID = UserID;
|
entity.CorpID = item.CorpID;
|
entity.ObjectType = item.ObjectType;
|
entity.ObjectID = item.ObjectID;
|
entity.AttentionTime = DateTime.Now;
|
var id = db.Insertable(entity).ExecuteReturnSnowflakeId();
|
if (id < 1)
|
{
|
db.RollbackTran();
|
return false;
|
}
|
}
|
}
|
}
|
db.CommitTran();
|
return true;
|
}
|
catch
|
{
|
db.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 通过 UserID 删除
|
/// </summary>
|
public bool DeleteByUserID(long UserID)
|
{
|
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Deleteable<Entity.UserAttention>()
|
.Where(x => x.UserID == UserID)
|
.ExecuteCommandHasChange();
|
}
|
}
|
|
/// <summary>
|
/// 通过 ObjectType 和 ObjectID 删除
|
/// </summary>
|
public bool DeleteByObject(long CorpID, string ObjectType, long ObjectID)
|
{
|
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Deleteable<Entity.UserAttention>()
|
.Where(x =>x.CorpID==CorpID&& x.ObjectType == ObjectType && x.ObjectID == ObjectID)
|
.ExecuteCommandHasChange();
|
}
|
}
|
|
|
}
|
}
|