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.

NoticeService.cs 7.7 KiB

4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 and F_DeleteMark=0 ");
  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. entity.F_DeleteMark = 1;
  89. db.Update(entity);
  90. //db.Delete(entity);
  91. }
  92. string sql = $"delete MessageRemind where InstanceId='{entity.F_NewsId}'";
  93. db.ExecuteBySql(sql);
  94. }
  95. db.Commit();
  96. }
  97. catch (Exception ex)
  98. {
  99. db.Rollback();
  100. if (ex is ExceptionEx)
  101. {
  102. throw;
  103. }
  104. else
  105. {
  106. throw ExceptionEx.ThrowServiceException(ex);
  107. }
  108. }
  109. }
  110. /// <summary>
  111. /// 保存(新增、修改)
  112. /// </summary>
  113. /// <param name="keyValue">主键值</param>
  114. /// <param name="newsEntity">新闻公告实体</param>
  115. /// <returns></returns>
  116. public void SaveEntity(string keyValue, NewsEntity newsEntity)
  117. {
  118. try
  119. {
  120. newsEntity.F_TypeId = 2;
  121. if (!string.IsNullOrEmpty(keyValue))
  122. {
  123. newsEntity.Modify(keyValue);
  124. this.BaseRepository().Update(newsEntity);
  125. }
  126. else
  127. {
  128. newsEntity.Create();
  129. this.BaseRepository().Insert(newsEntity);
  130. }
  131. }
  132. catch (Exception ex)
  133. {
  134. if (ex is ExceptionEx)
  135. {
  136. throw;
  137. }
  138. else
  139. {
  140. throw ExceptionEx.ThrowServiceException(ex);
  141. }
  142. }
  143. }
  144. #endregion
  145. #region 扩展数据
  146. /// <summary>
  147. /// 公告列表
  148. /// </summary>
  149. /// <param name="keyword">关键词</param>
  150. /// <returns></returns>
  151. public IEnumerable<NewsEntity> GetList(string keyword, string userId, string categoryId = null)
  152. {
  153. try
  154. {
  155. var strSql = new StringBuilder();
  156. strSql.Append("SELECT t.*,r.RNewsId,r.RTime FROM LR_OA_News t ");
  157. strSql.Append(" left join LR_OA_NewsRead r on t.F_NewsId = r.NewsId and r.RUserId=@userId ");
  158. strSql.Append(" WHERE t.F_TypeId = 2 and t.F_DeleteMark=0 ");
  159. if (!string.IsNullOrEmpty(categoryId))
  160. {
  161. strSql.Append($" AND F_CategoryId = '{categoryId}'");
  162. }
  163. if (!string.IsNullOrEmpty(keyword))
  164. {
  165. strSql.Append(" AND F_FullHead like @keyword");
  166. }
  167. strSql.Append(" ORDER BY t.F_ReleaseTime DESC ");
  168. return this.BaseRepository().FindList<NewsEntity>(strSql.ToString(), new { keyword = "%" + keyword + "%", userId = userId });
  169. }
  170. catch (Exception ex)
  171. {
  172. if (ex is ExceptionEx)
  173. {
  174. throw;
  175. }
  176. else
  177. {
  178. throw ExceptionEx.ThrowServiceException(ex);
  179. }
  180. }
  181. }
  182. #endregion
  183. public void ChangeStatusById(string keyValue, int status, string processId)
  184. {
  185. try
  186. {
  187. BaseRepository().ExecuteBySql($"UPDATE dbo.LR_OA_News SET F_Status='{status}',F_ProgressId='{processId}' WHERE F_NewsId='{keyValue}'", null);
  188. }
  189. catch (Exception ex)
  190. {
  191. throw ExceptionEx.ThrowServiceException(ex);
  192. }
  193. }
  194. public NewsEntity GetEntityByProcessId(string processId)
  195. {
  196. try
  197. {
  198. return this.BaseRepository().FindEntity<NewsEntity>(t => t.F_ProgressId == processId);
  199. }
  200. catch (Exception ex)
  201. {
  202. if (ex is ExceptionEx)
  203. {
  204. throw;
  205. }
  206. else
  207. {
  208. throw ExceptionEx.ThrowServiceException(ex);
  209. }
  210. }
  211. }
  212. public void SaveFormAndSubmit(string keyValue, NewsEntity entity)
  213. {
  214. try
  215. {
  216. entity.F_TypeId = 2;
  217. if (!string.IsNullOrEmpty(keyValue))
  218. {
  219. entity.Modify(keyValue);
  220. this.BaseRepository().Update(entity);
  221. }
  222. else
  223. {
  224. entity.Create();
  225. entity.F_EnabledMark = 1;
  226. this.BaseRepository().Insert(entity);
  227. }
  228. }
  229. catch (Exception ex)
  230. {
  231. if (ex is ExceptionEx)
  232. {
  233. throw;
  234. }
  235. else
  236. {
  237. throw ExceptionEx.ThrowServiceException(ex);
  238. }
  239. }
  240. }
  241. }
  242. }