using Learun.DataBase.Repository;
using Learun.Util;
using System;
using System.Collections.Generic;
using System.Text;
namespace Learun.Application.OA
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创建人:陈彬彬
/// 日 期:2017.04.17
/// 描 述:公告管理
///
public class NoticeService : RepositoryFactory
{
#region 获取数据
///
/// 公告列表
///
/// 分页参数
/// 关键词
///
public IEnumerable GetPageList(Pagination pagination, string keyword)
{
try
{
var strSql = new StringBuilder();
strSql.Append("SELECT * FROM LR_OA_News t WHERE t.F_TypeId = 2 ");
if (!string.IsNullOrEmpty(keyword))
{
strSql.Append(" AND F_FullHead like @keyword");
}
return this.BaseRepository().FindList(strSql.ToString(), new { keyword = "%" + keyword + "%" }, pagination);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 新闻公告实体
///
/// 主键值
///
public NewsEntity GetEntity(string keyValue)
{
try
{
return this.BaseRepository().FindEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 删除
///
/// 主键
public void DeleteEntity(string keyValue)
{
var db = this.BaseRepository().BeginTrans();
try
{
var list = keyValue.Split(',');
foreach (var item in list)
{
var entity = db.FindEntity(x => x.F_NewsId == item);
if (entity != null)
{
db.Delete(entity);
}
}
db.Commit();
}
catch (Exception ex)
{
db.Rollback();
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存(新增、修改)
///
/// 主键值
/// 新闻公告实体
///
public void SaveEntity(string keyValue, NewsEntity newsEntity)
{
try
{
newsEntity.F_TypeId = 2;
if (!string.IsNullOrEmpty(keyValue))
{
newsEntity.Modify(keyValue);
this.BaseRepository().Update(newsEntity);
}
else
{
newsEntity.Create();
this.BaseRepository().Insert(newsEntity);
}
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 扩展数据
///
/// 公告列表
///
/// 关键词
///
public IEnumerable GetList(string keyword, string userId, string categoryId = null)
{
try
{
var strSql = new StringBuilder();
strSql.Append("SELECT t.*,r.RNewsId,r.RTime FROM LR_OA_News t ");
strSql.Append(" left join LR_OA_NewsRead r on t.F_NewsId = r.NewsId and r.RUserId=@userId ");
strSql.Append(" WHERE t.F_TypeId = 2 ");
if (!string.IsNullOrEmpty(categoryId))
{
strSql.Append($" AND F_CategoryId = '{categoryId}'");
}
if (!string.IsNullOrEmpty(keyword))
{
strSql.Append(" AND F_FullHead like @keyword");
}
strSql.Append(" ORDER BY t.F_ReleaseTime DESC ");
return this.BaseRepository().FindList(strSql.ToString(), new { keyword = "%" + keyword + "%", userId = userId });
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
public void ChangeStatusById(string keyValue, int status, string processId)
{
try
{
BaseRepository().ExecuteBySql($"UPDATE dbo.LR_OA_News SET F_Status='{status}',F_ProgressId='{processId}' WHERE F_NewsId='{keyValue}'", null);
}
catch (Exception ex)
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
public NewsEntity GetEntityByProcessId(string processId)
{
try
{
return this.BaseRepository().FindEntity(t => t.F_ProgressId == processId);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
}
}