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.
 
 
 
 
 
 

194 lines
5.5 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.TwoDevelopment.LogisticsManagement
  9. {
  10. /// <summary>
  11. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  12. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  13. /// 创 建:超级管理员
  14. /// 日 期:2020-06-12 11:21
  15. /// 描 述:校区新闻
  16. /// </summary>
  17. public class CompanyNewsService : RepositoryFactory
  18. {
  19. #region 获取数据
  20. /// <summary>
  21. /// 获取页面显示列表数据
  22. /// <summary>
  23. /// <param name="queryJson">查询参数</param>
  24. /// <returns></returns>
  25. public IEnumerable<CompanyNewsEntity> GetPageList(Pagination pagination, string queryJson)
  26. {
  27. try
  28. {
  29. var strSql = new StringBuilder();
  30. strSql.Append("SELECT ");
  31. strSql.Append(@"
  32. t.ID,
  33. t.CompanyID,
  34. t.NewType,
  35. t.Title,
  36. t.Content
  37. ");
  38. strSql.Append(" FROM CompanyNews t ");
  39. strSql.Append(" WHERE 1=1 ");
  40. var queryParam = queryJson.ToJObject();
  41. // 虚拟参数
  42. var dp = new DynamicParameters(new { });
  43. if (!queryParam["CompanyID"].IsEmpty())
  44. {
  45. dp.Add("CompanyID",queryParam["CompanyID"].ToString(), DbType.String);
  46. strSql.Append(" AND t.CompanyID = @CompanyID ");
  47. }
  48. return this.BaseRepository().FindList<CompanyNewsEntity>(strSql.ToString(),dp, pagination);
  49. }
  50. catch (Exception ex)
  51. {
  52. if (ex is ExceptionEx)
  53. {
  54. throw;
  55. }
  56. else
  57. {
  58. throw ExceptionEx.ThrowServiceException(ex);
  59. }
  60. }
  61. }
  62. /// <summary>
  63. /// 根据校区id获取新闻列表
  64. /// <summary>
  65. /// <returns></returns>
  66. public IEnumerable<CompanyNewsEntity> GetListByCompanyID(string companyID)
  67. {
  68. try
  69. {
  70. return this.BaseRepository().FindList<CompanyNewsEntity>(a=>a.CompanyID==companyID);
  71. }
  72. catch (Exception ex)
  73. {
  74. if (ex is ExceptionEx)
  75. {
  76. throw;
  77. }
  78. else
  79. {
  80. throw ExceptionEx.ThrowServiceException(ex);
  81. }
  82. }
  83. }
  84. /// <summary>
  85. /// 获取CompanyNews表实体数据
  86. /// <param name="keyValue">主键</param>
  87. /// <summary>
  88. /// <returns></returns>
  89. public CompanyNewsEntity GetCompanyNewsEntity(string keyValue)
  90. {
  91. try
  92. {
  93. return this.BaseRepository().FindEntity<CompanyNewsEntity>(keyValue);
  94. }
  95. catch (Exception ex)
  96. {
  97. if (ex is ExceptionEx)
  98. {
  99. throw;
  100. }
  101. else
  102. {
  103. throw ExceptionEx.ThrowServiceException(ex);
  104. }
  105. }
  106. }
  107. public CompanyNewsEntity GetCompanyNewsEntityByCompanyID(string company)
  108. {
  109. try
  110. {
  111. return this.BaseRepository().FindEntity<CompanyNewsEntity>(a=>a.CompanyID==company);
  112. }
  113. catch (Exception ex)
  114. {
  115. if (ex is ExceptionEx)
  116. {
  117. throw;
  118. }
  119. else
  120. {
  121. throw ExceptionEx.ThrowServiceException(ex);
  122. }
  123. }
  124. }
  125. #endregion
  126. #region 提交数据
  127. /// <summary>
  128. /// 删除实体数据
  129. /// <param name="keyValue">主键</param>
  130. /// <summary>
  131. /// <returns></returns>
  132. public void DeleteEntity(string keyValue)
  133. {
  134. try
  135. {
  136. this.BaseRepository().Delete<CompanyNewsEntity>(t=>t.ID == keyValue);
  137. }
  138. catch (Exception ex)
  139. {
  140. if (ex is ExceptionEx)
  141. {
  142. throw;
  143. }
  144. else
  145. {
  146. throw ExceptionEx.ThrowServiceException(ex);
  147. }
  148. }
  149. }
  150. /// <summary>
  151. /// 保存实体数据(新增、修改)
  152. /// <param name="keyValue">主键</param>
  153. /// <summary>
  154. /// <returns></returns>
  155. public void SaveEntity(string keyValue, CompanyNewsEntity entity)
  156. {
  157. try
  158. {
  159. if (!string.IsNullOrEmpty(keyValue))
  160. {
  161. entity.Modify(keyValue);
  162. this.BaseRepository().Update(entity);
  163. }
  164. else
  165. {
  166. entity.Create();
  167. this.BaseRepository().Insert(entity);
  168. }
  169. }
  170. catch (Exception ex)
  171. {
  172. if (ex is ExceptionEx)
  173. {
  174. throw;
  175. }
  176. else
  177. {
  178. throw ExceptionEx.ThrowServiceException(ex);
  179. }
  180. }
  181. }
  182. #endregion
  183. }
  184. }