25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

293 lines
9.3 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 user = LoginUserInfo.Get();
  29. var strSql = new StringBuilder();
  30. strSql.Append("SELECT * FROM LR_OA_News t WHERE t.F_TypeId = 2 and F_DeleteMark=0 ");
  31. if (!string.IsNullOrEmpty(keyword))
  32. {
  33. strSql.Append(" AND F_FullHead like @keyword");
  34. }
  35. if (user.Description != "超级管理员")
  36. {
  37. strSql.Append(" AND F_CreateUserName ='" + user.realName + "'");
  38. }
  39. return this.BaseRepository().FindList<NewsEntity>(strSql.ToString(), new { keyword = "%" + keyword + "%" }, pagination);
  40. }
  41. catch (Exception ex)
  42. {
  43. if (ex is ExceptionEx)
  44. {
  45. throw;
  46. }
  47. else
  48. {
  49. throw ExceptionEx.ThrowServiceException(ex);
  50. }
  51. }
  52. }
  53. /// <summary>
  54. /// 新闻公告实体
  55. /// </summary>
  56. /// <param name="keyValue">主键值</param>
  57. /// <returns></returns>
  58. public NewsEntity GetEntity(string keyValue)
  59. {
  60. try
  61. {
  62. return this.BaseRepository().FindEntity<NewsEntity>(keyValue);
  63. }
  64. catch (Exception ex)
  65. {
  66. if (ex is ExceptionEx)
  67. {
  68. throw;
  69. }
  70. else
  71. {
  72. throw ExceptionEx.ThrowServiceException(ex);
  73. }
  74. }
  75. }
  76. #endregion
  77. #region 提交数据
  78. /// <summary>
  79. /// 删除
  80. /// </summary>
  81. /// <param name="keyValue">主键</param>
  82. public void DeleteEntity(string keyValue)
  83. {
  84. var db = this.BaseRepository().BeginTrans();
  85. try
  86. {
  87. var list = keyValue.Split(',');
  88. foreach (var item in list)
  89. {
  90. var entity = db.FindEntity<NewsEntity>(x => x.F_NewsId == item);
  91. if (entity != null)
  92. {
  93. entity.F_DeleteMark = 1;
  94. db.Update(entity);
  95. //db.Delete(entity);
  96. }
  97. string sql = $"delete MessageRemind where InstanceId='{entity.F_NewsId}'";
  98. db.ExecuteBySql(sql);
  99. }
  100. db.Commit();
  101. }
  102. catch (Exception ex)
  103. {
  104. db.Rollback();
  105. if (ex is ExceptionEx)
  106. {
  107. throw;
  108. }
  109. else
  110. {
  111. throw ExceptionEx.ThrowServiceException(ex);
  112. }
  113. }
  114. }
  115. /// <summary>
  116. /// 保存(新增、修改)
  117. /// </summary>
  118. /// <param name="keyValue">主键值</param>
  119. /// <param name="newsEntity">新闻公告实体</param>
  120. /// <returns></returns>
  121. public void SaveEntity(string keyValue, NewsEntity newsEntity)
  122. {
  123. try
  124. {
  125. newsEntity.F_TypeId = 2;
  126. if (!string.IsNullOrEmpty(keyValue))
  127. {
  128. newsEntity.Modify(keyValue);
  129. this.BaseRepository().Update(newsEntity);
  130. }
  131. else
  132. {
  133. newsEntity.Create();
  134. this.BaseRepository().Insert(newsEntity);
  135. }
  136. }
  137. catch (Exception ex)
  138. {
  139. if (ex is ExceptionEx)
  140. {
  141. throw;
  142. }
  143. else
  144. {
  145. throw ExceptionEx.ThrowServiceException(ex);
  146. }
  147. }
  148. }
  149. #endregion
  150. #region 扩展数据
  151. /// <summary>
  152. /// 公告列表
  153. /// </summary>
  154. /// <param name="keyword">关键词</param>
  155. /// <returns></returns>
  156. public IEnumerable<NewsEntity> GetList(string keyword, string categoryId = null)
  157. {
  158. try
  159. {
  160. var userinfo = LoginUserInfo.Get();
  161. var userId = userinfo.userId;
  162. var deptId = userinfo.departmentId;
  163. var postIds = userinfo.postIds;
  164. var strSql = new StringBuilder();
  165. strSql.Append("SELECT t.*,r.RNewsId,r.RTime FROM LR_OA_News t ");
  166. strSql.Append(" left join LR_OA_NewsRead r on t.F_NewsId = r.NewsId and r.RUserId=@userId ");
  167. strSql.Append(" WHERE t.F_TypeId = 2 and t.F_DeleteMark=0 and t.F_EnabledMark=1 ");
  168. strSql.Append($@" and (
  169. ((t.F_SendDeptId is null or len(t.F_SendDeptId)=0) and (t.F_SendPostId is null or len(t.F_SendPostId)=0))
  170. ");
  171. if (!string.IsNullOrEmpty(deptId))
  172. {
  173. strSql.Append($" or (t.F_SendDeptId is not null and t.F_SendDeptId like '%{deptId}%')");
  174. }
  175. if (!string.IsNullOrEmpty(postIds))
  176. {
  177. strSql.Append(" or (t.F_SendPostId is not null and ");
  178. if (postIds.Contains(","))
  179. {
  180. string postidSql = " (";
  181. foreach (var postId in postIds)
  182. {
  183. postidSql += $" t.F_SendPostId like '%{postId}%' or";
  184. }
  185. postidSql = postidSql.Substring(0, postidSql.LastIndexOf("or")) + ")";
  186. strSql.Append(postidSql);
  187. }
  188. else
  189. {
  190. strSql.Append($" t.F_SendPostId like '%{postIds}%'");
  191. }
  192. strSql.Append(")");
  193. }
  194. strSql.Append(") ");
  195. if (!string.IsNullOrEmpty(categoryId))
  196. {
  197. strSql.Append($" AND t.F_CategoryId = '{categoryId}'");
  198. }
  199. if (!string.IsNullOrEmpty(keyword))
  200. {
  201. strSql.Append(" AND t.F_FullHead like @keyword");
  202. }
  203. strSql.Append(" ORDER BY t.F_ReleaseTime DESC ");
  204. return this.BaseRepository().FindList<NewsEntity>(strSql.ToString(), new { keyword = "%" + keyword + "%", userId = userId });
  205. }
  206. catch (Exception ex)
  207. {
  208. if (ex is ExceptionEx)
  209. {
  210. throw;
  211. }
  212. else
  213. {
  214. throw ExceptionEx.ThrowServiceException(ex);
  215. }
  216. }
  217. }
  218. #endregion
  219. public void ChangeStatusById(string keyValue, int status, string processId)
  220. {
  221. try
  222. {
  223. BaseRepository().ExecuteBySql($"UPDATE dbo.LR_OA_News SET F_Status='{status}',F_ProgressId='{processId}' WHERE F_NewsId='{keyValue}'", null);
  224. }
  225. catch (Exception ex)
  226. {
  227. throw ExceptionEx.ThrowServiceException(ex);
  228. }
  229. }
  230. public NewsEntity GetEntityByProcessId(string processId)
  231. {
  232. try
  233. {
  234. return this.BaseRepository().FindEntity<NewsEntity>(t => t.F_ProgressId == processId);
  235. }
  236. catch (Exception ex)
  237. {
  238. if (ex is ExceptionEx)
  239. {
  240. throw;
  241. }
  242. else
  243. {
  244. throw ExceptionEx.ThrowServiceException(ex);
  245. }
  246. }
  247. }
  248. public void SaveFormAndSubmit(string keyValue, NewsEntity entity)
  249. {
  250. try
  251. {
  252. entity.F_TypeId = 2;
  253. if (!string.IsNullOrEmpty(keyValue))
  254. {
  255. entity.Modify(keyValue);
  256. this.BaseRepository().Update(entity);
  257. }
  258. else
  259. {
  260. entity.Create();
  261. entity.F_EnabledMark = 1;
  262. this.BaseRepository().Insert(entity);
  263. }
  264. }
  265. catch (Exception ex)
  266. {
  267. if (ex is ExceptionEx)
  268. {
  269. throw;
  270. }
  271. else
  272. {
  273. throw ExceptionEx.ThrowServiceException(ex);
  274. }
  275. }
  276. }
  277. }
  278. }