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.
 
 
 
 
 
 

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