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.
 
 
 
 
 
 

348 lines
12 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. using Learun.Application.Organization;
  9. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  13. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2019-03-06 17:15
  16. /// 描 述:日志发送
  17. /// </summary>
  18. public class JournalSendService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// <summary>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<JournalSendEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT ");
  32. strSql.Append(@"
  33. JournalSendId, JTitle, JTypeId, JSenderId, JSender, JReceiveId, JReceive, JIsSend, JSendTime
  34. ");
  35. strSql.Append(" FROM JournalSend t ");
  36. strSql.Append(" WHERE 1=1 ");
  37. var queryParam = queryJson.ToJObject();
  38. // 虚拟参数
  39. var dp = new DynamicParameters(new { });
  40. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  41. {
  42. dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  43. dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
  44. strSql.Append(" AND ( JSendTime >= @startTime AND JSendTime <= @endTime ) ");
  45. }
  46. if (!queryParam["keyword"].IsEmpty())
  47. {
  48. dp.Add("keyword", "%" + queryParam["keyword"].ToString() + "%", DbType.String);
  49. strSql.Append(" AND JTitle Like @keyword ");
  50. }
  51. if (!queryParam["userId"].IsEmpty())
  52. {
  53. dp.Add("userId", "" + queryParam["userId"].ToString() + "", DbType.String);
  54. strSql.Append(" AND JSenderId=@userId ");
  55. }
  56. return this.BaseRepository().FindList<JournalSendEntity>(strSql.ToString(), dp, pagination);
  57. }
  58. catch (Exception ex)
  59. {
  60. if (ex is ExceptionEx)
  61. {
  62. throw;
  63. }
  64. else
  65. {
  66. throw ExceptionEx.ThrowServiceException(ex);
  67. }
  68. }
  69. }
  70. /// <summary>
  71. /// 获取页面显示列表数据
  72. /// <summary>
  73. /// <param name="queryJson">查询参数</param>
  74. /// <returns></returns>
  75. public IEnumerable<JournalSendEntity> GetList(string queryJson)
  76. {
  77. try
  78. {
  79. var strSql = new StringBuilder();
  80. strSql.Append("SELECT ");
  81. strSql.Append(@"
  82. t.JournalSendId,
  83. t.JTitle,
  84. t.JTypeId,
  85. t.JReceiveId,
  86. t.JContent
  87. ");
  88. strSql.Append(" FROM JournalSend t ");
  89. strSql.Append(" WHERE 1=1 ");
  90. var queryParam = queryJson.ToJObject();
  91. // 虚拟参数
  92. var dp = new DynamicParameters(new { });
  93. if (!queryParam["JTitle"].IsEmpty())
  94. {
  95. dp.Add("JTitle", "%" + queryParam["JTitle"].ToString() + "%", DbType.String);
  96. strSql.Append(" AND t.JTitle Like @JTitle ");
  97. }
  98. if (!queryParam["JTypeId"].IsEmpty())
  99. {
  100. dp.Add("JTypeId", queryParam["JTypeId"].ToString(), DbType.String);
  101. strSql.Append(" AND t.JTypeId = @JTypeId ");
  102. }
  103. if (!queryParam["JReceiveId"].IsEmpty())
  104. {
  105. dp.Add("JReceiveId", queryParam["JReceiveId"].ToString(), DbType.String);
  106. strSql.Append(" AND t.JReceiveId = @JReceiveId ");
  107. }
  108. return this.BaseRepository().FindList<JournalSendEntity>(strSql.ToString(), dp);
  109. }
  110. catch (Exception ex)
  111. {
  112. if (ex is ExceptionEx)
  113. {
  114. throw;
  115. }
  116. else
  117. {
  118. throw ExceptionEx.ThrowServiceException(ex);
  119. }
  120. }
  121. }
  122. /// <summary>
  123. /// 获取JournalSend表实体数据
  124. /// <param name="keyValue">主键</param>
  125. /// <summary>
  126. /// <returns></returns>
  127. public JournalSendEntity GetJournalSendEntity(string keyValue)
  128. {
  129. try
  130. {
  131. return this.BaseRepository().FindEntity<JournalSendEntity>(keyValue);
  132. }
  133. catch (Exception ex)
  134. {
  135. if (ex is ExceptionEx)
  136. {
  137. throw;
  138. }
  139. else
  140. {
  141. throw ExceptionEx.ThrowServiceException(ex);
  142. }
  143. }
  144. }
  145. /// <summary>
  146. /// 获取JournalSend表实体数据
  147. /// <param name="keyValue">主键</param>
  148. /// <summary>
  149. /// <returns></returns>
  150. public JournalSendEntity GetJournalSendEntityNoHtml(string keyValue)
  151. {
  152. try
  153. {
  154. var result = this.BaseRepository().FindEntity<JournalSendEntity>(keyValue);
  155. if (result != null)
  156. {
  157. result.JContent = Str.ReplaceHtml(result.JContent);
  158. }
  159. return result;
  160. }
  161. catch (Exception ex)
  162. {
  163. if (ex is ExceptionEx)
  164. {
  165. throw;
  166. }
  167. else
  168. {
  169. throw ExceptionEx.ThrowServiceException(ex);
  170. }
  171. }
  172. }
  173. #endregion
  174. #region 提交数据
  175. /// <summary>
  176. /// 删除实体数据
  177. /// <param name="keyValue">主键</param>
  178. /// <summary>
  179. /// <returns></returns>
  180. public void DeleteEntity(string keyValue)
  181. {
  182. try
  183. {
  184. this.BaseRepository().Delete<JournalSendEntity>(t => t.JournalSendId == keyValue);
  185. }
  186. catch (Exception ex)
  187. {
  188. if (ex is ExceptionEx)
  189. {
  190. throw;
  191. }
  192. else
  193. {
  194. throw ExceptionEx.ThrowServiceException(ex);
  195. }
  196. }
  197. }
  198. /// <summary>
  199. /// 保存实体数据(新增、修改)
  200. /// <param name="keyValue">主键</param>
  201. /// <summary>
  202. /// <returns></returns>
  203. public void SaveEntity(string keyValue, JournalSendEntity entity)
  204. {
  205. try
  206. {
  207. if (!string.IsNullOrEmpty(keyValue))
  208. {
  209. entity.Modify(keyValue);
  210. this.BaseRepository().Update(entity);
  211. }
  212. else
  213. {
  214. entity.Create();
  215. this.BaseRepository().Insert(entity);
  216. }
  217. }
  218. catch (Exception ex)
  219. {
  220. if (ex is ExceptionEx)
  221. {
  222. throw;
  223. }
  224. else
  225. {
  226. throw ExceptionEx.ThrowServiceException(ex);
  227. }
  228. }
  229. }
  230. /// <summary>
  231. /// 保存实体数据(新增、修改)
  232. /// <param name="keyValue">主键</param>
  233. /// <summary>
  234. /// <returns></returns>
  235. public void SaveEntity(UserInfo userInfo, string keyValue, JournalSendEntity entity)
  236. {
  237. try
  238. {
  239. if (!string.IsNullOrEmpty(keyValue))
  240. {
  241. entity.Modify(keyValue, userInfo);
  242. this.BaseRepository().Update(entity);
  243. }
  244. else
  245. {
  246. entity.Create(userInfo);
  247. this.BaseRepository().Insert(entity);
  248. }
  249. }
  250. catch (Exception ex)
  251. {
  252. if (ex is ExceptionEx)
  253. {
  254. throw;
  255. }
  256. else
  257. {
  258. throw ExceptionEx.ThrowServiceException(ex);
  259. }
  260. }
  261. }
  262. #endregion
  263. /// <summary>
  264. /// 发送
  265. /// </summary>
  266. /// <param name="journalSendId">日志发送主键</param>
  267. public void Send(string journalSendId)
  268. {
  269. var db = this.BaseRepository().BeginTrans();
  270. try
  271. {
  272. var messageentity = GetJournalSendEntity(journalSendId);
  273. if (messageentity != null)
  274. {
  275. messageentity.JIsSend = true;
  276. messageentity.JSendTime = DateTime.Now;
  277. db.Update(messageentity);
  278. if (!string.IsNullOrEmpty(messageentity.JReceiveId))
  279. {
  280. List<UserEntity> userInfos = new List<UserEntity>();
  281. if (messageentity.JReceiveId.IndexOf(',') == -1)
  282. {
  283. userInfos.Add(new UserEntity
  284. {
  285. F_UserId = messageentity.JReceiveId,
  286. F_RealName = db.FindEntity<UserEntity>(x => x.F_UserId == messageentity.JReceiveId)?.F_RealName
  287. });
  288. }
  289. else
  290. {
  291. foreach (var rid in messageentity.JReceiveId.Split(','))
  292. {
  293. userInfos.Add(new UserEntity
  294. {
  295. F_UserId = rid,
  296. F_RealName = db.FindEntity<UserEntity>(m => m.F_UserId == rid)?.F_RealName
  297. });
  298. }
  299. }
  300. foreach (var uitem in userInfos)
  301. {
  302. JournalReceiveEntity receiveMessageEntity = new JournalReceiveEntity();
  303. receiveMessageEntity.Create();
  304. receiveMessageEntity.JSenderId = messageentity.JSenderId;
  305. receiveMessageEntity.JSender = messageentity.JSender;
  306. receiveMessageEntity.JReceiveId = uitem.F_UserId;
  307. receiveMessageEntity.JReceive = uitem.F_RealName;
  308. receiveMessageEntity.JTitle = messageentity.JTitle;
  309. receiveMessageEntity.JTypeId = messageentity.JTypeId;
  310. receiveMessageEntity.JContent = messageentity.JContent;
  311. receiveMessageEntity.JIsRead = false;
  312. receiveMessageEntity.JSendTime = DateTime.Now;
  313. db.Insert(receiveMessageEntity);
  314. }
  315. }
  316. }
  317. db.Commit();
  318. }
  319. catch (Exception ex)
  320. {
  321. db.Rollback();
  322. if (ex is ExceptionEx)
  323. {
  324. throw;
  325. }
  326. else
  327. {
  328. throw ExceptionEx.ThrowServiceException(ex);
  329. }
  330. }
  331. }
  332. }
  333. }