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 14 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. using Dapper;
  2. using Learun.DataBase.Repository;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Text;
  8. namespace Learun.Application.OA
  9. {
  10. /// <summary>
  11. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  12. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  13. /// 创建人:陈彬彬
  14. /// 日 期:2017.04.17
  15. /// 描 述:公告管理
  16. /// </summary>
  17. public class NoticeService : RepositoryFactory
  18. {
  19. #region 获取数据
  20. /// <summary>
  21. /// 公告列表
  22. /// </summary>
  23. /// <param name="pagination">分页参数</param>
  24. /// <param name="keyword">关键词</param>
  25. /// <returns></returns>
  26. public IEnumerable<NewsEntity> GetPageList(Pagination pagination, string keyword)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT * FROM LR_OA_News t WHERE t.F_TypeId = 2 and F_DeleteMark=0 ");
  32. if (!string.IsNullOrEmpty(keyword))
  33. {
  34. strSql.Append(" AND F_FullHead like @keyword");
  35. }
  36. return this.BaseRepository().FindList<NewsEntity>(strSql.ToString(), new { keyword = "%" + keyword + "%" }, pagination);
  37. }
  38. catch (Exception ex)
  39. {
  40. if (ex is ExceptionEx)
  41. {
  42. throw;
  43. }
  44. else
  45. {
  46. throw ExceptionEx.ThrowServiceException(ex);
  47. }
  48. }
  49. }
  50. /// <summary>
  51. /// 通知公告阅读统计
  52. /// </summary>
  53. /// <param name="pagination"></param>
  54. /// <param name="queryJson"></param>
  55. /// <returns></returns>
  56. public IEnumerable<NewsEntity> GetPageListForStatistics(Pagination pagination, string queryJson)
  57. {
  58. try
  59. {
  60. var sql = new StringBuilder(@"select t.*,u.f_encode,u.f_realname,f_departmentid from (
  61. select t1.ruserid,isnull(srnum,0) as srnum,isnull(rnum,0) as rnum from (
  62. select ruserid,COUNT(1) as srnum from LR_OA_News t left join LR_OA_NewsShouldRead s on s.newsid=t.f_newsid
  63. WHERE t.F_TypeId = 2 and t.F_DeleteMark=0 and t.F_EnabledMark=1 group by ruserid
  64. ) t1
  65. left join (
  66. select ruserid,COUNT(1) as rnum from LR_OA_News t left join LR_OA_NewsRead r on r.newsid=t.f_newsid
  67. WHERE t.F_TypeId = 2 and t.F_DeleteMark=0 and t.F_EnabledMark=1 and DATEDIFF(HOUR,t.F_ReleaseTime,r.RTime)<=24*7 group by ruserid
  68. ) t2 on t1.ruserid=t2.ruserid
  69. ) t
  70. left join lr_base_user u on t.ruserid=u.f_userid where 1=1
  71. ");
  72. var queryParam = queryJson.ToJObject();
  73. // 虚拟参数
  74. var dp = new DynamicParameters(new { });
  75. if (queryParam.HasValues)
  76. {
  77. if (!queryParam["F_Encode"].IsEmpty())
  78. {
  79. dp.Add("F_Encode", "%" + queryParam["F_Encode"].ToString() + "%", DbType.String);
  80. sql.Append(" AND u.f_encode like @F_Encode ");
  81. }
  82. if (!queryParam["F_RealName"].IsEmpty())
  83. {
  84. dp.Add("F_RealName", "%" + queryParam["F_RealName"].ToString() + "%", DbType.String);
  85. sql.Append(" AND u.f_realname like @F_RealName ");
  86. }
  87. if (!queryParam["F_Departmentid"].IsEmpty())
  88. {
  89. dp.Add("F_Departmentid", queryParam["F_Departmentid"].ToString(), DbType.String);
  90. sql.Append(" AND f_departmentid like @F_Departmentid ");
  91. }
  92. }
  93. var list = this.BaseRepository().FindList<NewsEntity>(sql.ToString(), pagination);
  94. return list;
  95. }
  96. catch (Exception ex)
  97. {
  98. if (ex is ExceptionEx)
  99. {
  100. throw;
  101. }
  102. else
  103. {
  104. throw ExceptionEx.ThrowServiceException(ex);
  105. }
  106. }
  107. }
  108. /// <summary>
  109. /// 保存通知公告应读人员
  110. /// </summary>
  111. public void SaveNewsShouldRead()
  112. {
  113. var db = this.BaseRepository();
  114. try
  115. {
  116. db.BeginTrans();
  117. var sql =
  118. @"SELECT case when (F_SendDeptId is null or len(F_SendDeptId)=0) and (F_SendPostId is null or len(F_SendDeptId)=0) then '1' else '' end as F_Send,
  119. F_SendDeptId,F_SendPostId,* FROM LR_OA_News t WHERE t.F_TypeId = 2 and t.F_DeleteMark=0 and t.F_EnabledMark=1
  120. and t.f_Newsid not in (SELECT distinct Newsid from [dbo].[LR_OA_NewsShouldRead])";
  121. var list = db.FindList<NewsEntity>(sql);
  122. foreach (var news in list)
  123. {
  124. if (!string.IsNullOrEmpty(news.F_Send) && news.F_Send == "1")
  125. {
  126. //接收人是全部教师
  127. db.ExecuteBySql($@"insert into LR_OA_NewsShouldRead
  128. SELECT newid(),'{news.F_NewsId}',f_userid from lr_base_user where f_description='教师' and
  129. f_userid not in (
  130. SELECT ruserid from [dbo].[LR_OA_NewsShouldRead] where newsid='{news.F_NewsId}'
  131. )
  132. ");
  133. }
  134. else
  135. {
  136. //接收部门
  137. if (!string.IsNullOrEmpty(news.F_SendDeptId))
  138. {
  139. var deptids = string.Join("','", news.F_SendDeptId.Split(','));
  140. db.ExecuteBySql($@"insert into LR_OA_NewsShouldRead
  141. SELECT newid(),'{news.F_NewsId}',f_userid from lr_base_user where f_description='教师' and F_DepartmentId in ('{deptids}')
  142. and f_userid not in (
  143. SELECT ruserid from [dbo].[LR_OA_NewsShouldRead] where newsid='{news.F_NewsId}'
  144. )");
  145. //岗位
  146. if (!string.IsNullOrEmpty(news.F_SendPostId))
  147. {
  148. var postids = string.Join("','", news.F_SendPostId.Split(','));
  149. db.ExecuteBySql($@"insert into LR_OA_NewsShouldRead
  150. SELECT newid(),'{news.F_NewsId}',t.f_userid from lr_base_user t
  151. join LR_Base_UserRelation r on r.f_category='2' and t.F_UserId=r.f_userid
  152. where t.f_description='教师' and r.f_objectid in ('{postids}')
  153. and t.F_DepartmentId not in ('{deptids}')
  154. and t.f_userid not in (
  155. SELECT ruserid from [dbo].[LR_OA_NewsShouldRead] where newsid='{news.F_NewsId}'
  156. )");
  157. }
  158. }
  159. //接收部门空 , 接收岗位不为空
  160. if (string.IsNullOrEmpty(news.F_SendDeptId) && !string.IsNullOrEmpty(news.F_SendPostId))
  161. {
  162. var postids = string.Join("','", news.F_SendPostId.Split(','));
  163. db.ExecuteBySql($@"insert into LR_OA_NewsShouldRead
  164. SELECT newid(),'{news.F_NewsId}',t.f_userid from lr_base_user t
  165. join LR_Base_UserRelation r on r.f_category='2' and t.F_UserId=r.f_userid
  166. where t.f_description='教师' and r.f_objectid in ('{postids}')
  167. and t.f_userid not in (
  168. SELECT ruserid from [dbo].[LR_OA_NewsShouldRead] where newsid='{news.F_NewsId}'
  169. )");
  170. }
  171. }
  172. }
  173. db.Commit();
  174. }
  175. catch (Exception ex)
  176. {
  177. if (ex is ExceptionEx)
  178. {
  179. throw;
  180. }
  181. else
  182. {
  183. throw ExceptionEx.ThrowServiceException(ex);
  184. }
  185. }
  186. }
  187. /// <summary>
  188. /// 新闻公告实体
  189. /// </summary>
  190. /// <param name="keyValue">主键值</param>
  191. /// <returns></returns>
  192. public NewsEntity GetEntity(string keyValue)
  193. {
  194. try
  195. {
  196. return this.BaseRepository().FindEntity<NewsEntity>(keyValue);
  197. }
  198. catch (Exception ex)
  199. {
  200. if (ex is ExceptionEx)
  201. {
  202. throw;
  203. }
  204. else
  205. {
  206. throw ExceptionEx.ThrowServiceException(ex);
  207. }
  208. }
  209. }
  210. #endregion
  211. #region 提交数据
  212. /// <summary>
  213. /// 删除
  214. /// </summary>
  215. /// <param name="keyValue">主键</param>
  216. public void DeleteEntity(string keyValue)
  217. {
  218. var db = this.BaseRepository().BeginTrans();
  219. try
  220. {
  221. var list = keyValue.Split(',');
  222. foreach (var item in list)
  223. {
  224. var entity = db.FindEntity<NewsEntity>(x => x.F_NewsId == item);
  225. if (entity != null)
  226. {
  227. entity.F_DeleteMark = 1;
  228. db.Update(entity);
  229. //db.Delete(entity);
  230. }
  231. string sql = $"delete MessageRemind where InstanceId='{entity.F_NewsId}'";
  232. db.ExecuteBySql(sql);
  233. }
  234. db.Commit();
  235. }
  236. catch (Exception ex)
  237. {
  238. db.Rollback();
  239. if (ex is ExceptionEx)
  240. {
  241. throw;
  242. }
  243. else
  244. {
  245. throw ExceptionEx.ThrowServiceException(ex);
  246. }
  247. }
  248. }
  249. /// <summary>
  250. /// 保存(新增、修改)
  251. /// </summary>
  252. /// <param name="keyValue">主键值</param>
  253. /// <param name="newsEntity">新闻公告实体</param>
  254. /// <returns></returns>
  255. public void SaveEntity(string keyValue, NewsEntity newsEntity)
  256. {
  257. try
  258. {
  259. newsEntity.F_TypeId = 2;
  260. if (!string.IsNullOrEmpty(keyValue))
  261. {
  262. newsEntity.Modify(keyValue);
  263. this.BaseRepository().Update(newsEntity);
  264. }
  265. else
  266. {
  267. newsEntity.Create();
  268. this.BaseRepository().Insert(newsEntity);
  269. }
  270. }
  271. catch (Exception ex)
  272. {
  273. if (ex is ExceptionEx)
  274. {
  275. throw;
  276. }
  277. else
  278. {
  279. throw ExceptionEx.ThrowServiceException(ex);
  280. }
  281. }
  282. }
  283. #endregion
  284. #region 扩展数据
  285. /// <summary>
  286. /// 公告列表
  287. /// </summary>
  288. /// <param name="keyword">关键词</param>
  289. /// <returns></returns>
  290. public IEnumerable<NewsEntity> GetList(string keyword, string userId, string categoryId = null)
  291. {
  292. try
  293. {
  294. var strSql = new StringBuilder();
  295. strSql.Append("SELECT t.*,r.RNewsId,r.RTime FROM LR_OA_News t ");
  296. strSql.Append(" left join LR_OA_NewsRead r on t.F_NewsId = r.NewsId and r.RUserId=@userId ");
  297. strSql.Append(" WHERE t.F_TypeId = 2 and t.F_DeleteMark=0 ");
  298. if (!string.IsNullOrEmpty(categoryId))
  299. {
  300. strSql.Append($" AND F_CategoryId = '{categoryId}'");
  301. }
  302. if (!string.IsNullOrEmpty(keyword))
  303. {
  304. strSql.Append(" AND F_FullHead like @keyword");
  305. }
  306. strSql.Append(" ORDER BY t.F_ReleaseTime DESC ");
  307. return this.BaseRepository().FindList<NewsEntity>(strSql.ToString(), new { keyword = "%" + keyword + "%", userId = userId });
  308. }
  309. catch (Exception ex)
  310. {
  311. if (ex is ExceptionEx)
  312. {
  313. throw;
  314. }
  315. else
  316. {
  317. throw ExceptionEx.ThrowServiceException(ex);
  318. }
  319. }
  320. }
  321. #endregion
  322. public void ChangeStatusById(string keyValue, int status, string processId)
  323. {
  324. try
  325. {
  326. BaseRepository().ExecuteBySql($"UPDATE dbo.LR_OA_News SET F_Status='{status}',F_ProgressId='{processId}' WHERE F_NewsId='{keyValue}'", null);
  327. }
  328. catch (Exception ex)
  329. {
  330. throw ExceptionEx.ThrowServiceException(ex);
  331. }
  332. }
  333. public NewsEntity GetEntityByProcessId(string processId)
  334. {
  335. try
  336. {
  337. return this.BaseRepository().FindEntity<NewsEntity>(t => t.F_ProgressId == processId);
  338. }
  339. catch (Exception ex)
  340. {
  341. if (ex is ExceptionEx)
  342. {
  343. throw;
  344. }
  345. else
  346. {
  347. throw ExceptionEx.ThrowServiceException(ex);
  348. }
  349. }
  350. }
  351. public void SaveFormAndSubmit(string keyValue, NewsEntity entity)
  352. {
  353. try
  354. {
  355. entity.F_TypeId = 2;
  356. if (!string.IsNullOrEmpty(keyValue))
  357. {
  358. entity.Modify(keyValue);
  359. this.BaseRepository().Update(entity);
  360. }
  361. else
  362. {
  363. entity.Create();
  364. entity.F_EnabledMark = 1;
  365. this.BaseRepository().Insert(entity);
  366. }
  367. }
  368. catch (Exception ex)
  369. {
  370. if (ex is ExceptionEx)
  371. {
  372. throw;
  373. }
  374. else
  375. {
  376. throw ExceptionEx.ThrowServiceException(ex);
  377. }
  378. }
  379. }
  380. }
  381. }