Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

545 linhas
20 KiB

  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 queryParam = queryJson.ToJObject();
  61. var sql = new StringBuilder(@"select t.*,u.F_Account,u.f_realname,f_departmentid from ");
  62. sql.Append("(");
  63. sql.Append("select t1.ruserid,isnull(srnum,0) as srnum,isnull(rnum,0) as rnum from (");
  64. sql.Append(
  65. @"select ruserid,COUNT(1) as srnum from LR_OA_News t left join LR_OA_NewsShouldRead s on s.newsid=t.f_newsid
  66. left join lr_base_user u on s.RUserId=u.F_UserId
  67. WHERE t.F_TypeId = 2 and t.F_DeleteMark=0 and t.F_EnabledMark=1
  68. and u.F_Account like '20%'
  69. and t.F_ReleaseTime>CONVERT(datetime,SUBSTRING(u.F_Account,1,4)+'-08-31',120) ");
  70. if (!queryParam["Year"].IsEmpty() && !queryParam["Month"].IsEmpty())
  71. {
  72. sql.Append($" and year(t.F_ReleaseTime)='{queryParam["Year"].ToString()}' and month(t.F_ReleaseTime)='{queryParam["Month"].ToString()}'");
  73. }
  74. sql.Append(" group by ruserid ) t1 left join (");
  75. sql.Append(
  76. @" select ruserid,COUNT(1) as rnum from LR_OA_News t left join LR_OA_NewsRead r on r.newsid=t.f_newsid
  77. left join lr_base_user u on r.RUserId=u.F_UserId
  78. WHERE t.F_TypeId = 2 and t.F_DeleteMark=0 and t.F_EnabledMark=1
  79. and u.F_Account like '20%'
  80. and t.F_ReleaseTime>CONVERT(datetime,SUBSTRING(u.F_Account,1,4)+'-08-31',120)
  81. and DATEDIFF(HOUR,t.F_ReleaseTime,r.RTime)<=24*7 ");
  82. if (!queryParam["Year"].IsEmpty() && !queryParam["Month"].IsEmpty())
  83. {
  84. sql.Append($" and year(t.F_ReleaseTime)='{queryParam["Year"].ToString()}' and month(t.F_ReleaseTime)='{queryParam["Month"].ToString()}'");
  85. }
  86. sql.Append(" group by ruserid ) t2 on t1.ruserid=t2.ruserid ");
  87. sql.Append(") t");
  88. sql.Append(" left join lr_base_user u on t.ruserid=u.f_userid where 1=1 ");
  89. // 虚拟参数
  90. var dp = new DynamicParameters(new { });
  91. if (queryParam.HasValues)
  92. {
  93. if (!queryParam["F_Encode"].IsEmpty())
  94. {
  95. sql.Append($" AND u.f_encode like '%{queryParam["F_Encode"].ToString()}%' ");
  96. }
  97. if (!queryParam["F_RealName"].IsEmpty())
  98. {
  99. sql.Append($" AND u.f_realname like '%{queryParam["F_RealName"].ToString()}%' ");
  100. }
  101. if (!queryParam["F_Departmentid"].IsEmpty())
  102. {
  103. sql.Append($" AND f_departmentid = '{queryParam["F_Departmentid"].ToString()}' ");
  104. }
  105. }
  106. var list = this.BaseRepository().FindList<NewsEntity>(sql.ToString(), pagination);
  107. return list;
  108. }
  109. catch (Exception ex)
  110. {
  111. if (ex is ExceptionEx)
  112. {
  113. throw;
  114. }
  115. else
  116. {
  117. throw ExceptionEx.ThrowServiceException(ex);
  118. }
  119. }
  120. }
  121. /// <summary>
  122. /// 保存通知公告应读人员
  123. /// </summary>
  124. public void SaveNewsShouldRead()
  125. {
  126. var db = this.BaseRepository();
  127. try
  128. {
  129. db.BeginTrans();
  130. var sql =
  131. @"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,
  132. F_SendDeptId,F_SendPostId,* FROM LR_OA_News t WHERE t.F_TypeId = 2 and t.F_DeleteMark=0 and t.F_EnabledMark=1
  133. and t.f_Newsid not in (SELECT distinct Newsid from [dbo].[LR_OA_NewsShouldRead])";
  134. var list = db.FindList<NewsEntity>(sql);
  135. foreach (var news in list)
  136. {
  137. if (!string.IsNullOrEmpty(news.F_Send) && news.F_Send == "1")
  138. {
  139. //接收人是全部教师
  140. db.ExecuteBySql($@"insert into LR_OA_NewsShouldRead
  141. SELECT newid(),'{news.F_NewsId}',f_userid from lr_base_user where f_description='教师' and
  142. f_userid not in (
  143. SELECT ruserid from [dbo].[LR_OA_NewsShouldRead] where newsid='{news.F_NewsId}'
  144. )
  145. ");
  146. }
  147. else
  148. {
  149. //接收部门
  150. if (!string.IsNullOrEmpty(news.F_SendDeptId))
  151. {
  152. var deptids = string.Join("','", news.F_SendDeptId.Split(','));
  153. db.ExecuteBySql($@"insert into LR_OA_NewsShouldRead
  154. SELECT newid(),'{news.F_NewsId}',f_userid from lr_base_user where f_description='教师' and F_DepartmentId in ('{deptids}')
  155. and f_userid not in (
  156. SELECT ruserid from [dbo].[LR_OA_NewsShouldRead] where newsid='{news.F_NewsId}'
  157. )");
  158. //岗位
  159. if (!string.IsNullOrEmpty(news.F_SendPostId))
  160. {
  161. var postids = string.Join("','", news.F_SendPostId.Split(','));
  162. db.ExecuteBySql($@"insert into LR_OA_NewsShouldRead
  163. SELECT newid(),'{news.F_NewsId}',t.f_userid from lr_base_user t
  164. join LR_Base_UserRelation r on r.f_category='2' and t.F_UserId=r.f_userid
  165. where t.f_description='教师' and r.f_objectid in ('{postids}')
  166. and t.F_DepartmentId not in ('{deptids}')
  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. if (string.IsNullOrEmpty(news.F_SendDeptId) && !string.IsNullOrEmpty(news.F_SendPostId))
  174. {
  175. var postids = string.Join("','", news.F_SendPostId.Split(','));
  176. db.ExecuteBySql($@"insert into LR_OA_NewsShouldRead
  177. SELECT newid(),'{news.F_NewsId}',t.f_userid from lr_base_user t
  178. join LR_Base_UserRelation r on r.f_category='2' and t.F_UserId=r.f_userid
  179. where t.f_description='教师' and r.f_objectid in ('{postids}')
  180. and t.f_userid not in (
  181. SELECT ruserid from [dbo].[LR_OA_NewsShouldRead] where newsid='{news.F_NewsId}'
  182. )");
  183. }
  184. }
  185. }
  186. db.Commit();
  187. }
  188. catch (Exception ex)
  189. {
  190. if (ex is ExceptionEx)
  191. {
  192. throw;
  193. }
  194. else
  195. {
  196. throw ExceptionEx.ThrowServiceException(ex);
  197. }
  198. }
  199. }
  200. /// <summary>
  201. /// 新闻公告实体
  202. /// </summary>
  203. /// <param name="keyValue">主键值</param>
  204. /// <returns></returns>
  205. public NewsEntity GetEntity(string keyValue)
  206. {
  207. try
  208. {
  209. return this.BaseRepository().FindEntity<NewsEntity>(keyValue);
  210. }
  211. catch (Exception ex)
  212. {
  213. if (ex is ExceptionEx)
  214. {
  215. throw;
  216. }
  217. else
  218. {
  219. throw ExceptionEx.ThrowServiceException(ex);
  220. }
  221. }
  222. }
  223. #endregion
  224. #region 提交数据
  225. /// <summary>
  226. /// 删除
  227. /// </summary>
  228. /// <param name="keyValue">主键</param>
  229. public void DeleteEntity(string keyValue)
  230. {
  231. var db = this.BaseRepository().BeginTrans();
  232. try
  233. {
  234. var list = keyValue.Split(',');
  235. foreach (var item in list)
  236. {
  237. var entity = db.FindEntity<NewsEntity>(x => x.F_NewsId == item);
  238. if (entity != null)
  239. {
  240. entity.F_DeleteMark = 1;
  241. db.Update(entity);
  242. //db.Delete(entity);
  243. }
  244. string sql = $"delete MessageRemind where InstanceId='{entity.F_NewsId}'";
  245. db.ExecuteBySql(sql);
  246. }
  247. db.Commit();
  248. }
  249. catch (Exception ex)
  250. {
  251. db.Rollback();
  252. if (ex is ExceptionEx)
  253. {
  254. throw;
  255. }
  256. else
  257. {
  258. throw ExceptionEx.ThrowServiceException(ex);
  259. }
  260. }
  261. }
  262. /// <summary>
  263. /// 保存(新增、修改)
  264. /// </summary>
  265. /// <param name="keyValue">主键值</param>
  266. /// <param name="newsEntity">新闻公告实体</param>
  267. /// <returns></returns>
  268. public void SaveEntity(string keyValue, NewsEntity newsEntity)
  269. {
  270. try
  271. {
  272. newsEntity.F_TypeId = 2;
  273. if (!string.IsNullOrEmpty(keyValue))
  274. {
  275. newsEntity.Modify(keyValue);
  276. this.BaseRepository().Update(newsEntity);
  277. }
  278. else
  279. {
  280. newsEntity.Create();
  281. this.BaseRepository().Insert(newsEntity);
  282. }
  283. }
  284. catch (Exception ex)
  285. {
  286. if (ex is ExceptionEx)
  287. {
  288. throw;
  289. }
  290. else
  291. {
  292. throw ExceptionEx.ThrowServiceException(ex);
  293. }
  294. }
  295. }
  296. #endregion
  297. #region 扩展数据
  298. /// <summary>
  299. /// 公告列表
  300. /// </summary>
  301. /// <param name="keyword">关键词</param>
  302. /// <returns></returns>
  303. public IEnumerable<NewsEntity> GetList(string keyword, string categoryId = null)
  304. {
  305. try
  306. {
  307. var userinfo = LoginUserInfo.Get();
  308. var userId = userinfo.userId;
  309. var deptId = userinfo.departmentId;
  310. var postIds = userinfo.postIds;
  311. var strSql = new StringBuilder();
  312. strSql.Append("SELECT t.*,r.RNewsId,r.RTime FROM LR_OA_News t ");
  313. strSql.Append(" left join LR_OA_NewsRead r on t.F_NewsId = r.NewsId and r.RUserId=@userId ");
  314. strSql.Append(" left join lr_base_user u on u.F_UserId=@userId ");
  315. strSql.Append(" WHERE t.F_TypeId = 2 and t.F_DeleteMark=0 and t.F_EnabledMark=1 ");
  316. //if (userinfo.account.Contains("20"))
  317. //{
  318. // strSql.Append(" and t.F_ReleaseTime>CONVERT(datetime,SUBSTRING(u.F_Account,1,4)+'-08-31',120) ");
  319. //}
  320. strSql.Append($@" and (
  321. ((t.F_SendDeptId is null or len(t.F_SendDeptId)=0) and (t.F_SendPostId is null or len(t.F_SendPostId)=0))
  322. ");
  323. if (!string.IsNullOrEmpty(deptId))
  324. {
  325. strSql.Append($" or (t.F_SendDeptId is not null and t.F_SendDeptId like '%{deptId}%')");
  326. }
  327. if (!string.IsNullOrEmpty(postIds))
  328. {
  329. strSql.Append(" or (t.F_SendPostId is not null and ");
  330. if (postIds.Contains(","))
  331. {
  332. string postidSql = " (";
  333. foreach (var postId in postIds)
  334. {
  335. postidSql += $" t.F_SendPostId like '%{postId}%' or";
  336. }
  337. postidSql = postidSql.Substring(0, postidSql.LastIndexOf("or")) + ")";
  338. strSql.Append(postidSql);
  339. }
  340. else
  341. {
  342. strSql.Append($" t.F_SendPostId like '%{postIds}%'");
  343. }
  344. strSql.Append(")");
  345. }
  346. strSql.Append(") ");
  347. if (!string.IsNullOrEmpty(categoryId))
  348. {
  349. strSql.Append($" AND t.F_CategoryId = '{categoryId}'");
  350. }
  351. if (!string.IsNullOrEmpty(keyword))
  352. {
  353. strSql.Append(" AND t.F_FullHead like @keyword");
  354. }
  355. strSql.Append(" ORDER BY t.F_ReleaseTime DESC ");
  356. return this.BaseRepository().FindList<NewsEntity>(strSql.ToString(), new { keyword = "%" + keyword + "%", userId = userId });
  357. }
  358. catch (Exception ex)
  359. {
  360. if (ex is ExceptionEx)
  361. {
  362. throw;
  363. }
  364. else
  365. {
  366. throw ExceptionEx.ThrowServiceException(ex);
  367. }
  368. }
  369. }
  370. public IEnumerable<NewsEntity> GetListOfSelf(string queryJson)
  371. {
  372. try
  373. {
  374. var userinfo = LoginUserInfo.Get();
  375. var userId = userinfo.userId;
  376. var deptId = userinfo.departmentId;
  377. var postIds = userinfo.postIds;
  378. var strSql = new StringBuilder();
  379. strSql.Append("SELECT t.*,r.RNewsId,r.RTime,d.F_FullName FROM LR_OA_News t ");
  380. strSql.Append(" left join LR_OA_NewsRead r on t.F_NewsId = r.NewsId and r.RUserId=@userId ");
  381. strSql.Append(" left join lr_base_user u on u.F_UserId=@userId ");
  382. strSql.Append(" left join LR_BASE_DEPARTMENT d on d.F_DepartmentId = t.F_SendDeptId ");
  383. strSql.Append(" WHERE t.F_TypeId = 2 and t.F_DeleteMark=0 and t.F_EnabledMark=1 ");
  384. //去掉用户入职时间条件
  385. //if (userinfo.account.Contains("20"))
  386. //{
  387. // strSql.Append(" and t.F_ReleaseTime>CONVERT(datetime,SUBSTRING(u.F_Account,1,4)+'-08-31',120) ");
  388. //}
  389. strSql.Append($@" and (
  390. ((t.F_SendDeptId is null or len(t.F_SendDeptId)=0) and (t.F_SendPostId is null or len(t.F_SendPostId)=0))
  391. ");
  392. if (!string.IsNullOrEmpty(deptId))
  393. {
  394. strSql.Append($" or (t.F_SendDeptId is not null and t.F_SendDeptId like '%{deptId}%')");
  395. }
  396. if (!string.IsNullOrEmpty(postIds))
  397. {
  398. strSql.Append(" or (t.F_SendPostId is not null and ");
  399. if (postIds.Contains(","))
  400. {
  401. string postidSql = " (";
  402. foreach (var postId in postIds)
  403. {
  404. postidSql += $" t.F_SendPostId like '%{postId}%' or";
  405. }
  406. postidSql = postidSql.Substring(0, postidSql.LastIndexOf("or")) + ")";
  407. strSql.Append(postidSql);
  408. }
  409. else
  410. {
  411. strSql.Append($" t.F_SendPostId like '%{postIds}%'");
  412. }
  413. strSql.Append(")");
  414. }
  415. strSql.Append(") ");
  416. var queryParam = queryJson.ToJObject();
  417. // 虚拟参数
  418. var dp = new DynamicParameters(new { });
  419. if (!queryParam["keyword"].IsEmpty())
  420. {
  421. var keyword = "%" + queryParam["keyword"].ToString() + "%";
  422. strSql.Append(@" AND ( t.F_FullHead like '" + keyword + "' or t.F_Category like '" + keyword + "' or t.F_CreateUserName like '" + keyword
  423. + "' or t.F_SourceName like'"+ keyword + "' or t.F_SourceAddress like '"+ keyword + "' )");
  424. }
  425. if (!queryParam["categoryId"].IsEmpty())
  426. {
  427. strSql.Append($" AND t.F_CategoryId = '{queryParam["categoryId"].ToString()}'");
  428. }
  429. if (!queryParam["IsRead"].IsEmpty())
  430. {
  431. var IsRead = queryParam["IsRead"].ToString().Trim();
  432. if (IsRead == "1")
  433. {
  434. strSql.Append($" AND (r.RNewsId is not null and len(r.RNewsId)>0)");
  435. }
  436. else
  437. {
  438. strSql.Append($" AND (r.RNewsId is null or len(r.RNewsId)=0)");
  439. }
  440. }
  441. strSql.Append(" ORDER BY t.F_ReleaseTime DESC ");
  442. return this.BaseRepository().FindList<NewsEntity>(strSql.ToString(), new { userId = userId });
  443. }
  444. catch (Exception ex)
  445. {
  446. if (ex is ExceptionEx)
  447. {
  448. throw;
  449. }
  450. else
  451. {
  452. throw ExceptionEx.ThrowServiceException(ex);
  453. }
  454. }
  455. }
  456. #endregion
  457. public void ChangeStatusById(string keyValue, int status, string processId)
  458. {
  459. try
  460. {
  461. BaseRepository().ExecuteBySql($"UPDATE dbo.LR_OA_News SET F_Status='{status}',F_ProgressId='{processId}' WHERE F_NewsId='{keyValue}'", null);
  462. }
  463. catch (Exception ex)
  464. {
  465. throw ExceptionEx.ThrowServiceException(ex);
  466. }
  467. }
  468. public NewsEntity GetEntityByProcessId(string processId)
  469. {
  470. try
  471. {
  472. return this.BaseRepository().FindEntity<NewsEntity>(t => t.F_ProgressId == processId);
  473. }
  474. catch (Exception ex)
  475. {
  476. if (ex is ExceptionEx)
  477. {
  478. throw;
  479. }
  480. else
  481. {
  482. throw ExceptionEx.ThrowServiceException(ex);
  483. }
  484. }
  485. }
  486. public void SaveFormAndSubmit(string keyValue, NewsEntity entity)
  487. {
  488. try
  489. {
  490. entity.F_TypeId = 2;
  491. if (!string.IsNullOrEmpty(keyValue))
  492. {
  493. entity.Modify(keyValue);
  494. this.BaseRepository().Update(entity);
  495. }
  496. else
  497. {
  498. entity.Create();
  499. entity.F_EnabledMark = 1;
  500. this.BaseRepository().Insert(entity);
  501. }
  502. }
  503. catch (Exception ex)
  504. {
  505. if (ex is ExceptionEx)
  506. {
  507. throw;
  508. }
  509. else
  510. {
  511. throw ExceptionEx.ThrowServiceException(ex);
  512. }
  513. }
  514. }
  515. }
  516. }