143 lines
4.2 KiB
C#
143 lines
4.2 KiB
C#
using Learun.Util;
|
||
using Learun.Util.SqlSugar;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
|
||
namespace Learun.Application.OA
|
||
{
|
||
/// <summary>
|
||
/// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
|
||
/// Copyright (c) 2013-2018 Hexagon PPM
|
||
/// 创建人:研发部
|
||
/// 日 期:2017.04.17
|
||
/// 描 述:公告管理
|
||
/// </summary>
|
||
public class NoticeService
|
||
{
|
||
#region 仓储
|
||
Repository<NewsEntity> _newsRepository => new Repository<NewsEntity>();
|
||
#endregion
|
||
#region 获取数据
|
||
/// <summary>
|
||
/// 公告列表
|
||
/// </summary>
|
||
/// <param name="pagination">分页参数</param>
|
||
/// <param name="keyword">关键词</param>
|
||
/// <returns></returns>
|
||
public IEnumerable<NewsEntity> 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<NewsEntity>(strSql.ToString(), new { keyword = "%" + keyword + "%" }, pagination);
|
||
return SqlSugarHelper.Db.SqlQueryable<NewsEntity>(strSql.ToString()).AddParameters(new { keyword = "%" + keyword + "%" }).ToPageList(pagination.page, pagination.rows);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
if (ex is ExceptionEx)
|
||
{
|
||
throw;
|
||
}
|
||
else
|
||
{
|
||
throw ExceptionEx.ThrowServiceException(ex);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 新闻公告实体
|
||
/// </summary>
|
||
/// <param name="keyValue">主键值</param>
|
||
/// <returns></returns>
|
||
public NewsEntity GetEntity(string keyValue)
|
||
{
|
||
try
|
||
{
|
||
return _newsRepository.GetById(keyValue);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
if (ex is ExceptionEx)
|
||
{
|
||
throw;
|
||
}
|
||
else
|
||
{
|
||
throw ExceptionEx.ThrowServiceException(ex);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 提交数据
|
||
/// <summary>
|
||
/// 删除
|
||
/// </summary>
|
||
/// <param name="keyValue">主键</param>
|
||
public void DeleteEntity(string keyValue)
|
||
{
|
||
try
|
||
{
|
||
NewsEntity entity = new NewsEntity()
|
||
{
|
||
F_NewsId = keyValue,
|
||
};
|
||
_newsRepository.Delete(entity);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
if (ex is ExceptionEx)
|
||
{
|
||
throw;
|
||
}
|
||
else
|
||
{
|
||
throw ExceptionEx.ThrowServiceException(ex);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 保存(新增、修改)
|
||
/// </summary>
|
||
/// <param name="keyValue">主键值</param>
|
||
/// <param name="newsEntity">新闻公告实体</param>
|
||
/// <returns></returns>
|
||
public void SaveEntity(string keyValue, NewsEntity newsEntity)
|
||
{
|
||
try
|
||
{
|
||
newsEntity.F_TypeId = 2;
|
||
if (!string.IsNullOrEmpty(keyValue))
|
||
{
|
||
newsEntity.Modify(keyValue);
|
||
_newsRepository.Update(newsEntity);
|
||
}
|
||
else
|
||
{
|
||
newsEntity.Create();
|
||
_newsRepository.Insert(newsEntity);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
if (ex is ExceptionEx)
|
||
{
|
||
throw;
|
||
}
|
||
else
|
||
{
|
||
throw ExceptionEx.ThrowServiceException(ex);
|
||
}
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
}
|
||
}
|