StableVersion4.3/HL_FristAidPlatform_DataBase/Service/T_Service_NoticeReceivingDB.cs

172 lines
7.3 KiB
C#

using HL_FristAidPlatform_Help;
using HL_FristAidPlatform_IDataBase;
using HL_FristAidPlatform_Models;
using SqlSugar;
using System;
using System.Collections.Generic;
namespace HL_FristAidPlatform_DataBase
{
/// <summary>
/// 消息接收人
/// </summary>
public class T_Service_NoticeReceivingDB : BaseDB, IT_Service_NoticeReceiving
{
public SqlSugarClient db = GetClient();
/// <summary>
/// 增加一条数据
/// </summary>
public bool Add(T_Service_NoticeReceiving model)
{
return db.Insertable(model).ExecuteCommand() == 0 ? false : true;
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(T_Service_NoticeReceiving model)
{
return db.Updateable(model).ExecuteCommand() == 0 ? false : true;
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(long ID)
{
return db.Deleteable<T_Service_NoticeReceiving>(it => it.ID == ID).ExecuteCommand() == 0 ? false : true; ;
}
/// <summary>
/// 获得数据列表
/// </summary>
public TableModel<T_Service_NoticeReceiving> GetPageList(int pageIndex, int pageSize)
{
int total = 0;
List<T_Service_NoticeReceiving> data = db.Queryable<T_Service_NoticeReceiving>().ToPageList(pageIndex, pageSize, ref total);
TableModel<T_Service_NoticeReceiving> t = new TableModel<T_Service_NoticeReceiving>();
t.Code = 0;
t.PageCount = data.Count;
t.TotalNumber = total;
t.Data = data;
t.Msg = "成功";
return t;
}
/// <summary>
/// 获得前几行数据
/// </summary>
public T_Service_NoticeReceiving Get(long ID)
{
return db.Queryable<T_Service_NoticeReceiving>().First(it => it.ID == ID);
}
/// <summary>
/// 更改阅读状态
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int UpdateReadState(T_Service_NoticeReceiving model)
{
//return db.Updateable<T_Service_NoticeReceiving>().UpdateColumns(it => new T_Service_NoticeReceiving() { ReadState = 1, FirstReadingTime = model.FirstReadingTime, TotalReading = model.TotalReading + 1 }).Where(it => it.NoticeID == model.NoticeID && it.UserID == model.UserID).ExecuteCommand();
//return db.Updateable(model).UpdateColumns(it => new { ReadState = 1, FirstReadingTime = model.FirstReadingTime, TotalReading = model.TotalReading + 1 }).WhereColumns(it => it.NoticeID == model.NoticeID && it.UserID == model.UserID).ExecuteCommand();
return db.Updateable<T_Service_NoticeReceiving>().SetColumns(it => new T_Service_NoticeReceiving() { ReadState = model.ReadState, FirstReadingTime = model.FirstReadingTime, TotalReading = model.TotalReading }).Where(it => it.NoticeID == model.NoticeID && it.UserID == model.UserID).ExecuteCommand();
}
/// <summary>
/// 消息通知状态获取
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
public TableModel<T_Service_NoticeAndReadState> getNoticeAndReadState(int pageIndex, int pageSize, long UserID)
{
int total = 0;
List<T_Service_NoticeAndReadState> list = new List<T_Service_NoticeAndReadState>();
var data = db.Queryable<T_Service_Notice, T_Service_NoticeReceiving>((a, b) => new JoinQueryInfos(JoinType.Left, b.NoticeID == a.ID))
.Where((a, b) => b.UserID == UserID)
.OrderBy((a, b) => new { b.ReadState })
.OrderBy((a, b) => new { a.CreationDate }, OrderByType.Desc)
.Select((a, b) => new T_Service_NoticeAndReadState()
{
ReadState = b.ReadState,
Content = a.Content,
FirstReadingTime = b.FirstReadingTime,
TotalReading = b.TotalReading,
NoticeID = b.NoticeID,
ID = b.ID,
UserID = b.UserID
}).ToPageList(pageIndex, pageSize, ref total);
TableModel<T_Service_NoticeAndReadState> t = new TableModel<T_Service_NoticeAndReadState>();
t.Code = 0;
t.PageCount = data.Count;
t.TotalNumber = data.Count;
t.Data = data;
t.Msg = "成功";
return t;
}
/// <summary>
/// 用户未读/已读消息列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="UserID"></param>
/// <returns></returns>
public TableModel<T_Service_NoticeAndReadState> GetNoticeMsgList(int pageIndex, int pageSize, long UserID, int readState)
{
int total = 0;
List<T_Service_NoticeAndReadState> list = new List<T_Service_NoticeAndReadState>();
var data = db.Queryable<T_Service_Notice, T_Service_NoticeReceiving>((a, b) => new JoinQueryInfos(JoinType.Left, b.NoticeID == a.ID))
.Where((a, b) => b.UserID == UserID && b.ReadState == readState)
.OrderBy((a, b) => a.CreationDate, OrderByType.Desc)
.OrderBy((a, b) => b.FirstReadingTime, OrderByType.Desc)
.Select((a, b) => new T_Service_NoticeAndReadState()
{
ReadState = b.ReadState,
Content = a.Content,
FirstReadingTime = b.FirstReadingTime,
TotalReading = b.TotalReading,
NoticeID = b.NoticeID,
ID = b.ID,
UserID = b.UserID
}).ToPageList(pageIndex, pageSize, ref total);
TableModel<T_Service_NoticeAndReadState> t = new TableModel<T_Service_NoticeAndReadState>();
t.Code = 0;
t.PageCount = data.Count;
t.TotalNumber = total;
t.Data = data;
t.Msg = "成功";
return t;
}
public TableModel<T_Service_NoticeAndReadState> getReadStateByNoticeID(string NoticeID)
{
int total = 0;
List<T_Service_NoticeAndReadState> list = new List<T_Service_NoticeAndReadState>();
var data = db.Queryable<T_Service_Notice, T_Service_NoticeReceiving>((a, b) => new JoinQueryInfos(JoinType.Left, b.NoticeID == a.ID))
.Where((a, b) => b.ID == Convert.ToInt32(NoticeID))
.Select((a, b) => new T_Service_NoticeAndReadState()
{
ReadState = b.ReadState,
Content = a.Content,
FirstReadingTime = b.FirstReadingTime,
TotalReading = b.TotalReading,
ID = b.ID,
NoticeID = b.NoticeID,
UserID = b.UserID
}).ToList();
TableModel<T_Service_NoticeAndReadState> t = new TableModel<T_Service_NoticeAndReadState>();
t.Code = 0;
t.PageCount = data.Count;
t.TotalNumber = data.Count;
t.Data = data;
t.Msg = "成功";
return t;
}
}
}