You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

218 lines
6.6 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace Learun.Application.OA
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创建人:陈彬彬
  12. /// 日 期:2017.04.17
  13. /// 描 述:公告管理
  14. /// </summary>
  15. public class NoticeService : RepositoryFactory
  16. {
  17. #region 获取数据
  18. /// <summary>
  19. /// 公告列表
  20. /// </summary>
  21. /// <param name="pagination">分页参数</param>
  22. /// <param name="keyword">关键词</param>
  23. /// <returns></returns>
  24. public IEnumerable<NewsEntity> GetPageList(Pagination pagination, string keyword)
  25. {
  26. try
  27. {
  28. var strSql = new StringBuilder();
  29. strSql.Append("SELECT * FROM LR_OA_News t WHERE t.F_TypeId = 2 ");
  30. if (!string.IsNullOrEmpty(keyword))
  31. {
  32. strSql.Append(" AND F_FullHead like @keyword");
  33. }
  34. return this.BaseRepository().FindList<NewsEntity>(strSql.ToString(), new { keyword = "%" + keyword + "%" }, pagination);
  35. }
  36. catch (Exception ex)
  37. {
  38. if (ex is ExceptionEx)
  39. {
  40. throw;
  41. }
  42. else
  43. {
  44. throw ExceptionEx.ThrowServiceException(ex);
  45. }
  46. }
  47. }
  48. /// <summary>
  49. /// 新闻公告实体
  50. /// </summary>
  51. /// <param name="keyValue">主键值</param>
  52. /// <returns></returns>
  53. public NewsEntity GetEntity(string keyValue)
  54. {
  55. try
  56. {
  57. return this.BaseRepository().FindEntity<NewsEntity>(keyValue);
  58. }
  59. catch (Exception ex)
  60. {
  61. if (ex is ExceptionEx)
  62. {
  63. throw;
  64. }
  65. else
  66. {
  67. throw ExceptionEx.ThrowServiceException(ex);
  68. }
  69. }
  70. }
  71. #endregion
  72. #region 提交数据
  73. /// <summary>
  74. /// 删除
  75. /// </summary>
  76. /// <param name="keyValue">主键</param>
  77. public void DeleteEntity(string keyValue)
  78. {
  79. var db = this.BaseRepository().BeginTrans();
  80. try
  81. {
  82. var list = keyValue.Split(',');
  83. foreach (var item in list)
  84. {
  85. var entity = db.FindEntity<NewsEntity>(x => x.F_NewsId == item);
  86. if (entity != null)
  87. {
  88. db.Delete(entity);
  89. }
  90. }
  91. db.Commit();
  92. }
  93. catch (Exception ex)
  94. {
  95. db.Rollback();
  96. if (ex is ExceptionEx)
  97. {
  98. throw;
  99. }
  100. else
  101. {
  102. throw ExceptionEx.ThrowServiceException(ex);
  103. }
  104. }
  105. }
  106. /// <summary>
  107. /// 保存(新增、修改)
  108. /// </summary>
  109. /// <param name="keyValue">主键值</param>
  110. /// <param name="newsEntity">新闻公告实体</param>
  111. /// <returns></returns>
  112. public void SaveEntity(string keyValue, NewsEntity newsEntity)
  113. {
  114. try
  115. {
  116. newsEntity.F_TypeId = 2;
  117. if (!string.IsNullOrEmpty(keyValue))
  118. {
  119. newsEntity.Modify(keyValue);
  120. this.BaseRepository().Update(newsEntity);
  121. }
  122. else
  123. {
  124. newsEntity.Create();
  125. this.BaseRepository().Insert(newsEntity);
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. if (ex is ExceptionEx)
  131. {
  132. throw;
  133. }
  134. else
  135. {
  136. throw ExceptionEx.ThrowServiceException(ex);
  137. }
  138. }
  139. }
  140. #endregion
  141. #region 扩展数据
  142. /// <summary>
  143. /// 公告列表
  144. /// </summary>
  145. /// <param name="keyword">关键词</param>
  146. /// <returns></returns>
  147. public IEnumerable<NewsEntity> GetList(string keyword, string userId, string categoryId = null)
  148. {
  149. try
  150. {
  151. var strSql = new StringBuilder();
  152. strSql.Append("SELECT t.*,r.RNewsId,r.RTime FROM LR_OA_News t ");
  153. strSql.Append(" left join LR_OA_NewsRead r on t.F_NewsId = r.NewsId and r.RUserId=@userId ");
  154. strSql.Append(" WHERE t.F_TypeId = 2 ");
  155. if (!string.IsNullOrEmpty(categoryId))
  156. {
  157. strSql.Append($" AND F_CategoryId = '{categoryId}'");
  158. }
  159. if (!string.IsNullOrEmpty(keyword))
  160. {
  161. strSql.Append(" AND F_FullHead like @keyword");
  162. }
  163. strSql.Append(" ORDER BY t.F_ReleaseTime DESC ");
  164. return this.BaseRepository().FindList<NewsEntity>(strSql.ToString(), new { keyword = "%" + keyword + "%", userId = userId });
  165. }
  166. catch (Exception ex)
  167. {
  168. if (ex is ExceptionEx)
  169. {
  170. throw;
  171. }
  172. else
  173. {
  174. throw ExceptionEx.ThrowServiceException(ex);
  175. }
  176. }
  177. }
  178. #endregion
  179. public void ChangeStatusById(string keyValue, int status, string processId)
  180. {
  181. try
  182. {
  183. BaseRepository().ExecuteBySql($"UPDATE dbo.LR_OA_News SET F_Status='{status}',F_ProgressId='{processId}' WHERE F_NewsId='{keyValue}'", null);
  184. }
  185. catch (Exception ex)
  186. {
  187. throw ExceptionEx.ThrowServiceException(ex);
  188. }
  189. }
  190. public NewsEntity GetEntityByProcessId(string processId)
  191. {
  192. try
  193. {
  194. return this.BaseRepository().FindEntity<NewsEntity>(t => t.F_ProgressId == processId);
  195. }
  196. catch (Exception ex)
  197. {
  198. if (ex is ExceptionEx)
  199. {
  200. throw;
  201. }
  202. else
  203. {
  204. throw ExceptionEx.ThrowServiceException(ex);
  205. }
  206. }
  207. }
  208. }
  209. }