StableVersion4.3/HL_FristAidPlatform_DataBase/Service/T_Service_NoticeDB.cs

171 lines
7.6 KiB
C#

using HL_FristAidPlatform_Help;
using HL_FristAidPlatform_IDataBase;
using HL_FristAidPlatform_Models;
using SqlSugar;
namespace HL_FristAidPlatform_DataBase
{
/// <summary>
/// 通知、消息
/// </summary>
public class T_Service_NoticeDB : BaseDB, IT_Service_Notice
{
public SqlSugarClient db = GetClient();
/// <summary>
/// 增加一条数据
/// </summary>
public T_Service_Notice Add(T_Service_Notice model)
{
return db.Insertable(model).IgnoreColumns(it => new { it.GUID }).ExecuteReturnEntity();
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(T_Service_Notice model)
{
return db.Updateable(model).ExecuteCommand() == 0 ? false : true;
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(long ID)
{
return db.Deleteable<T_Service_Notice>(it => it.ID == ID).ExecuteCommand() == 0 ? false : true; ;
}
/// <summary>
/// 获取分页列表
/// </summary>
/// <param name="pageIndex">起始页</param>
/// <param name="pageSize">每页大小</param>
/// <param name="noticeTypeID">消息类型编号</param>
/// <param name="readState">阅读状态</param>
/// <param name="userID">用户编号</param>
/// <param name="keyWord">查询关键词</param>
/// <returns></returns>
public TableModel<T_Service_NoticeModel> GetPageList(int pageIndex, int pageSize, long noticeTypeID, int readState, long userID, string keyWord)
{
int TotalNumber = 0;
TableModel<T_Service_NoticeModel> t = new TableModel<T_Service_NoticeModel>();
var listMode = db.Queryable<T_Service_Notice, T_Service_NoticeReceiving, T_Base_NoticeType>((Notice, Receiving, NoticeType) => new object[] {
JoinType.Left,Receiving.NoticeID==Notice.ID,
JoinType.Left,Notice.TypeID==NoticeType.ID,
}).Where((Notice, Receiving, NoticeType) => Notice.DeleteFlag == 0).WhereIF(userID > 0, (Notice, Receiving, NoticeType) => Receiving.UserID == userID).WhereIF(noticeTypeID > 0, (Notice, Receiving, NoticeType) => Notice.TypeID == noticeTypeID).WhereIF(readState != -1, (Notice, Receiving, NoticeType) => Receiving.ReadState == readState).WhereIF(!string.IsNullOrEmpty(keyWord), (Notice, Receiving, NoticeType) => Notice.Content.Contains(keyWord) || NoticeType.TypeName.Contains(keyWord))
.Select((Notice, Receiving, NoticeType) => new T_Service_NoticeModel
{
ID = Notice.ID,
GUID = Notice.GUID.ToString(),
Content = Notice.Content,
TypeID = Notice.TypeID,
IsSendSMS = Notice.IsSendSMS,
CreatorID = Notice.CreatorID,
Creator = Notice.Creator,
CreationDate = Notice.CreationDate,
DeleteFlag = Notice.DeleteFlag,
TypeName = NoticeType.TypeName,
ReadState = Receiving.ReadState,
ReadStateCase = Receiving.ReadState.ToString(),
FirstReadingTime = Receiving.FirstReadingTime,
TotalReading = Receiving.TotalReading,
}).OrderBy(Notice => Notice.CreationDate, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref TotalNumber);
t.Code = 0;
t.PageCount = listMode.Count;
t.TotalNumber = TotalNumber;
t.Data = listMode;
t.Msg = "成功";
return t;
}
/// <summary>
/// 获得前几行数据
/// </summary>
public T_Service_Notice Get(long ID)
{
return db.Queryable<T_Service_Notice>().First(it => it.ID == ID);
}
/// <summary>
/// 根据用户编号和阅读表示获取消息列表
/// </summary>
/// <param name="userID">用户编号</param>
/// <param name="readState">阅读标识-1全部0未读1已读</param>
/// <param name="topNumber">前多少条</param>
/// <returns></returns>
public TableModel<T_Service_NoticeModel> GetListByUserID(long userID, int readState, int topNumber)
{
TableModel<T_Service_NoticeModel> t = new TableModel<T_Service_NoticeModel>();
//取指定条数
if (topNumber > 0)
{
var listMode = db.Queryable<T_Service_Notice, T_Service_NoticeReceiving, T_Base_NoticeType>((Notice, Receiving, NoticeType) => new object[] {
JoinType.Left,Notice.ID==Receiving.NoticeID,
JoinType.Left,Notice.TypeID==NoticeType.ID,
})
.Where((Notice, Receiving, NoticeType) => Receiving.UserID == userID && Notice.DeleteFlag == 0)
.WhereIF(readState != -1, (Notice, Receiving, NoticeType) => Receiving.ReadState == readState)
.Select((Notice, Receiving, NoticeType) => new T_Service_NoticeModel
{
ID = Notice.ID,
GUID = Notice.GUID.ToString(),
PatientGuid = Notice.PatientGuid,
Content = Notice.Content,
TypeID = Notice.TypeID,
IsSendSMS = Notice.IsSendSMS,
CreatorID = Notice.CreatorID,
Creator = Notice.Creator,
CreationDate = Notice.CreationDate,
DeleteFlag = Notice.DeleteFlag,
TypeName = NoticeType.TypeName,
ReadState = Receiving.ReadState,
ReadStateCase = Receiving.ReadState.ToString(),
FirstReadingTime = Receiving.FirstReadingTime,
TotalReading = Receiving.TotalReading,
}).Take(topNumber).OrderBy((Notice) => Notice.CreationDate, OrderByType.Desc).ToList();
t.Code = 0;
t.TotalNumber = listMode.Count;
t.Data = listMode;
t.Msg = "成功";
return t;
}
//取所有
else
{
var listMode = db.Queryable<T_Service_Notice, T_Service_NoticeReceiving, T_Base_NoticeType>((Notice, Receiving, NoticeType) => new object[] {
JoinType.Left,Notice.ID==Receiving.NoticeID,
JoinType.Left,Notice.TypeID==NoticeType.ID,
})
.Where((Notice, Receiving, NoticeType) => Receiving.UserID == userID && Notice.DeleteFlag == 0)
.WhereIF(readState != -1, (Notice, Receiving, NoticeType) => Receiving.ReadState == readState)
.Select((Notice, Receiving, NoticeType) => new T_Service_NoticeModel
{
ID = Notice.ID,
GUID = Notice.GUID.ToString(),
Content = Notice.Content,
TypeID = Notice.TypeID,
IsSendSMS = Notice.IsSendSMS,
CreatorID = Notice.CreatorID,
Creator = Notice.Creator,
CreationDate = Notice.CreationDate,
DeleteFlag = Notice.DeleteFlag,
TypeName = NoticeType.TypeName,
ReadState = Receiving.ReadState,
ReadStateCase = Receiving.ReadState.ToString(),
FirstReadingTime = Receiving.FirstReadingTime,
TotalReading = Receiving.TotalReading,
}).OrderBy((Notice) => Notice.CreationDate, OrderByType.Desc).ToList();
t.Code = 0;
t.TotalNumber = listMode.Count;
t.Data = listMode;
t.Msg = "成功";
return t;
}
}
}
}