using HL_FristAidPlatform_Help;
using HL_FristAidPlatform_IDataBase;
using HL_FristAidPlatform_Models;
using Newtonsoft.Json;
using SqlSugar;
using System.Data;
namespace HL_FristAidPlatform_DataBase
{
///
/// 会议表
///
public class T_Service_MeetingDB : BaseDB, IT_Service_Meeting
{
public SqlSugarClient db = GetClient();
#region 增
///
/// 新增
///
/// 实体
///
public bool Add(T_Service_Meeting model)
{
return db.Insertable(model).ExecuteCommand() == 0 ? false : true;
}
///
/// 新增 仅更新赋值的字段
///
/// 实体类
///
public int AddNotNullColumns(T_Service_Meeting model)
{
return db.Insertable(model).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
///
/// 新增 仅更新赋值的字段
/// 用于移动端
///
/// 实体类
///
public int AddForApp(T_Service_Meeting model)
{
return db.Insertable(model).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
#endregion
#region 删
///
/// 删除一条数据
///
public bool Delete(long ID)
{
return db.Deleteable(it => it.ID == ID).ExecuteCommand() == 0 ? false : true; ;
}
///
/// 逻辑删除
///
/// 实体类
///
public int LogicalDelete(T_Service_Meeting model)
{
return db.Updateable(model).UpdateColumns(it => new { it.DeleteFlag, it.EditorID, it.Editor, it.EditTime }).ExecuteCommand();
}
///
/// 删除
/// 用于移动端
///
/// 实体类,ID必填
///
public int DeleteForApp(T_Service_Meeting model)
{
return db.Updateable(model).UpdateColumns(it => new { it.DeleteFlag, it.EditorID, it.Editor, it.EditTime }).ExecuteCommand();
}
#endregion
#region 改
///
/// 更新一条数据
///
public bool Update(T_Service_Meeting model)
{
return db.Updateable(model).ExecuteCommand() == 0 ? false : true;
}
///
/// 仅更新赋值的字段
///
/// 实体类
///
public int UpdateNotNullColumns(T_Service_Meeting model)
{
return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
}
///
/// 修改--仅更新赋值的字段
/// 用于移动端
///
/// 实体类
///
public int UpdateForApp(T_Service_Meeting model)
{
return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
}
#endregion
#region 查
///
/// 得到一个对象实体
///
public T_Service_Meeting GetModel(long ID)
{
return db.Queryable().First(it => it.ID == ID);
}
///
/// 得到一个对象实体
/// 用于移动端
///
/// 患者编号
/// GUID
///
public TableModel GetModelForApp(long id, string guid)
{
TableModel t = new TableModel();
var listMode = db.Queryable()
.Where(it => it.DeleteFlag == 0)
.WhereIF(id > 0, it => it.ID == id && it.DeleteFlag == 0)
.WhereIF(!string.IsNullOrEmpty(guid), it => it.GUID == guid).ToList();
t.Code = 0;
t.PageCount = listMode.Count;
t.TotalNumber = listMode.Count;
t.Data = listMode;
t.Msg = "成功";
return t;
}
///
/// 根据分页获得数据列表
///
/// 起始页
/// 每页条数
/// 院区编号
/// 所属系统
/// 会议类型 -1:全部 1:典型病例讨论会 2:质量分析会 3:联合例会 99:其他会议
/// 关键词
///
public TableModel GetPageList(int pageIndex, int pageSize, string hospitalGuid, long systemModuleID, int type, string keyWord)
{
int TotalNumber = 0;
TableModel t = new TableModel();
var listMode = db.Queryable()
.Where(it => it.HospitalGuid == hospitalGuid && it.SystemModuleID == systemModuleID && it.DeleteFlag == 0)
.WhereIF(type != -1, it => it.Type == type)
.WhereIF(!string.IsNullOrEmpty(keyWord), it => it.Name.Contains(keyWord) || it.Venue.Contains(keyWord) || it.Host.Contains(keyWord) || it.Content.Contains(keyWord) || it.Remark.Contains(keyWord))
.Select(it => new T_Service_Meeting
{
ID = it.ID,
GUID = it.GUID,
Type = it.Type,
Name = it.Name,
Venue = it.Venue,
Host = it.Host,
Content = it.Content,
Remark = it.Remark,
ScheduledDate = it.ScheduledDate,
ActualDate = it.ActualDate,
NoticeNumber = it.NoticeNumber,
NoticeDate = it.NoticeDate,
NotifierID = it.NotifierID,
Notifier = it.Notifier,
DeleteFlag = it.DeleteFlag,
CreationDate = it.CreationDate,
CreatorID = it.CreatorID,
Creator = it.Creator,
EditTime = it.EditTime,
EditorID = it.EditorID,
Editor = it.Editor,
}).OrderBy(it => it.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;
}
///
/// 根据分页获得数据列表
/// 用于移动端
///
/// 起始页
/// 每页条数
/// 院区编号
/// 所属系统
/// 会议类型 -1:全部 1:典型病例讨论会 2:质量分析会 3:联合例会 99:其他会议
/// 关键词
///
public TableModel GetPageListForApp(int pageIndex, int pageSize, string hospitalGuid, long systemModuleID, int type, string keyWord)
{
int TotalNumber = 0;
TableModel t = new TableModel();
var listMode = db.Queryable()
.Where(it => it.HospitalGuid == hospitalGuid && it.SystemModuleID == systemModuleID && it.DeleteFlag == 0)
.WhereIF(type != -1, it => it.Type == type)
.WhereIF(!string.IsNullOrEmpty(keyWord), it => it.Name.Contains(keyWord) || it.Venue.Contains(keyWord) || it.Host.Contains(keyWord) || it.Content.Contains(keyWord) || it.Remark.Contains(keyWord))
.Select(it => new T_Service_Meeting
{
ID = it.ID,
GUID = it.GUID,
Type = it.Type,
Name = it.Name,
Venue = it.Venue,
Host = it.Host,
Content = it.Content,
Remark = it.Remark,
ScheduledDate = it.ScheduledDate,
ActualDate = it.ActualDate,
NoticeNumber = it.NoticeNumber,
NoticeDate = it.NoticeDate,
NotifierID = it.NotifierID,
Notifier = it.Notifier,
DeleteFlag = it.DeleteFlag,
CreationDate = it.CreationDate,
CreatorID = it.CreatorID,
Creator = it.Creator,
EditTime = it.EditTime,
EditorID = it.EditorID,
Editor = it.Editor,
}).OrderBy(it => it.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;
}
///
/// 获得数据列表
///
/// 院区编号
/// 所属系统
/// 会议类型 -1:全部 1:典型病例讨论会 2:质量分析会 3:联合例会 99:其他会议
/// 取前N条,按预定召开时间排序
/// 关键词
///
public string GetList(string hospitalGuid, long systemModuleID, int type, int topNumber, string keyWord)
{
string StrWhere = string.Empty;
#region 上报状态
//会议类型 -1:全部 1:典型病例讨论会 2:质量分析会 3:联合例会 99:其他会议
if (type != -1)
{
StrWhere += " AND a.Type =" + type;
}
#endregion
#region 关键词
if (!string.IsNullOrEmpty(keyWord.Trim()))
{
StrWhere += " AND(a.Name LIKE '%" + keyWord + "%' OR a.Venue LIKE '%" + keyWord + "%' OR a.Host LIKE '%" + keyWord + "%' OR a.Content LIKE '%" + keyWord + "%' OR a.Remark LIKE '%" + keyWord + "%')";
}
#endregion
string SqlStr = string.Empty;
if (topNumber >= 0)
{
SqlStr = $"SELECT TOP {topNumber} a.*,CASE ISNULL(ActualDate,'') WHEN '' THEN DATEDIFF(DAY,GETDATE(),a.ScheduledDate) ELSE 9999 END AS SpecifiedDay " +
$"FROM dbo.T_Service_Meeting a " +
$"WHERE a.HospitalGuid = '{hospitalGuid}' AND a.SystemModuleID = '{systemModuleID}' AND a.DeleteFlag = 0 {StrWhere} " +
$"ORDER BY a.ScheduledDate DESC";
}
else
{
SqlStr = $"SELECT a.*,CASE ISNULL(ActualDate,'') WHEN '' THEN DATEDIFF(DAY,GETDATE(),a.ScheduledDate) ELSE 9999 END AS SpecifiedDay " +
$"FROM dbo.T_Service_Meeting a " +
$"WHERE a.HospitalGuid = '{hospitalGuid}' AND a.SystemModuleID = '{systemModuleID}' AND a.DeleteFlag = 0 {StrWhere} " +
$"ORDER BY a.ScheduledDate DESC";
}
DataTable dt = db.Ado.GetDataTable(SqlStr);
string items = "";
if (dt.Rows.Count > 0)
{
foreach (DataRow item in dt.Rows)
{
string row = "";
for (int i = 0; i < dt.Columns.Count; i++)
{
row += JsonConvert.SerializeObject(dt.Columns[i].ColumnName) + ":";
row += JsonConvert.SerializeObject(item[i]) + ",";
}
row = row.Remove(row.Length - 1);
items += "{" + row + "}" + ",";
}
items = items.Remove(items.Length - 1);
}
items = "[" + items + "]";
return items;
}
#endregion
}
}