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.
 
 
 
 
 
 

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