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.
 
 
 
 
 
 

266 lines
8.1 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.Linq;
  8. using System.Text;
  9. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
  13. /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2021-09-27 10:33
  16. /// 描 述:学金类型
  17. /// </summary>
  18. public class ScholarshipService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// </summary>
  24. /// <param name="pagination">查询参数</param>
  25. /// <param name="queryJson">查询参数</param>
  26. /// <returns></returns>
  27. public IEnumerable<ScholarshipEntity> GetPageList(Pagination pagination, string queryJson)
  28. {
  29. try
  30. {
  31. var strSql = new StringBuilder();
  32. strSql.Append("SELECT ");
  33. strSql.Append(@" * ");
  34. strSql.Append(" FROM Scholarship t ");
  35. strSql.Append(" WHERE 1=1 and IsDel ='0' ");
  36. var queryParam = queryJson.ToJObject();
  37. // 虚拟参数
  38. var dp = new DynamicParameters(new { });
  39. if (!queryParam["ItemName"].IsEmpty())
  40. {
  41. dp.Add("ItemName", "%" + queryParam["ItemName"].ToString() + "%", DbType.String);
  42. strSql.Append(" AND t.ItemName Like @ItemName ");
  43. }
  44. if (!queryParam["ItemCode"].IsEmpty())
  45. {
  46. dp.Add("ItemCode", "%" + queryParam["ItemCode"].ToString().ToUpperInvariant() + "%", DbType.String);
  47. strSql.Append(" AND t.ItemCode Like @ItemCode ");
  48. }
  49. if (!queryParam["IsValid"].IsEmpty())
  50. {
  51. dp.Add("IsValid", queryParam["IsValid"].ToString(), DbType.String);
  52. strSql.Append(" AND t.IsValid = @IsValid ");
  53. }
  54. if (!queryParam["IsType"].IsEmpty())
  55. {
  56. dp.Add("IsType", queryParam["IsType"].ToString(), DbType.String);
  57. strSql.Append(" AND t.IsType = @IsType ");
  58. }
  59. return this.BaseRepository("CollegeMIS").FindList<ScholarshipEntity>(strSql.ToString(), dp, pagination);
  60. }
  61. catch (Exception ex)
  62. {
  63. if (ex is ExceptionEx)
  64. {
  65. throw;
  66. }
  67. else
  68. {
  69. throw ExceptionEx.ThrowServiceException(ex);
  70. }
  71. }
  72. }
  73. /// <summary>
  74. /// 获取Scholarship表实体数据
  75. /// </summary>
  76. /// <param name="keyValue">主键</param>
  77. /// <returns></returns>
  78. public ScholarshipEntity GetScholarshipEntity(string keyValue)
  79. {
  80. try
  81. {
  82. return this.BaseRepository("CollegeMIS").FindEntity<ScholarshipEntity>(keyValue);
  83. }
  84. catch (Exception ex)
  85. {
  86. if (ex is ExceptionEx)
  87. {
  88. throw;
  89. }
  90. else
  91. {
  92. throw ExceptionEx.ThrowServiceException(ex);
  93. }
  94. }
  95. }
  96. #endregion
  97. #region 提交数据
  98. /// <summary>
  99. /// 删除实体数据
  100. /// </summary>
  101. /// <param name="keyValue">主键</param>
  102. public void DeleteEntity(string keyValue)
  103. {
  104. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  105. try
  106. {
  107. var IdList = keyValue.Split(',');
  108. foreach (var item in IdList)
  109. {
  110. var entity = db.FindEntity<ScholarshipEntity>(x => x.Id == item);
  111. entity.IsDel = 1;
  112. db.Update(entity);
  113. }
  114. db.Commit();
  115. }
  116. catch (Exception ex)
  117. {
  118. if (ex is ExceptionEx)
  119. {
  120. throw;
  121. }
  122. else
  123. {
  124. throw ExceptionEx.ThrowServiceException(ex);
  125. }
  126. }
  127. }
  128. /// <summary>
  129. /// 保存实体数据(新增、修改)
  130. /// </summary>
  131. /// <param name="keyValue">主键</param>
  132. /// <param name="entity">实体</param>
  133. public void SaveEntity(string keyValue, ScholarshipEntity entity)
  134. {
  135. try
  136. {
  137. if (!string.IsNullOrEmpty(keyValue))
  138. {
  139. entity.Modify(keyValue);
  140. this.BaseRepository("CollegeMIS").Update(entity);
  141. }
  142. else
  143. {
  144. entity.Create();
  145. this.BaseRepository("CollegeMIS").Insert(entity);
  146. }
  147. }
  148. catch (Exception ex)
  149. {
  150. if (ex is ExceptionEx)
  151. {
  152. throw;
  153. }
  154. else
  155. {
  156. throw ExceptionEx.ThrowServiceException(ex);
  157. }
  158. }
  159. }
  160. #endregion
  161. #region 扩展数据
  162. #region 判断重复
  163. /// <summary>
  164. /// 判断重复
  165. /// </summary>
  166. /// <param name="ItemName">名称</param>
  167. /// <param name="ItemCode">编码</param>
  168. /// <param name="IsType">类型</param>
  169. /// <returns></returns>
  170. public ScholarshipEntity NameOrCode(string ItemName, string ItemCode, int? IsType)
  171. {
  172. try
  173. {
  174. return this.BaseRepository("CollegeMIS").FindEntity<ScholarshipEntity>(x =>
  175. (x.ItemCode == ItemCode || x.ItemName == ItemName) && x.IsValid == IsType && x.IsDel == 0);
  176. }
  177. catch (Exception ex)
  178. {
  179. if (ex is ExceptionEx)
  180. {
  181. throw;
  182. }
  183. else
  184. {
  185. throw ExceptionEx.ThrowServiceException(ex);
  186. }
  187. }
  188. }
  189. #endregion
  190. #region 启用和禁用
  191. /// <summary>
  192. /// 启用和禁用
  193. /// </summary>
  194. /// <param name="keyValue"></param>
  195. /// <param name="status"></param>
  196. public void EnableDisable(string keyValue, string status)
  197. {
  198. var db = BaseRepository("CollegeMIS").BeginTrans();
  199. try
  200. {
  201. List<string> Ids = keyValue.Split(',').ToList();
  202. List<ScholarshipEntity> ScholList = new List<ScholarshipEntity>();
  203. if (status == "1")
  204. {
  205. foreach (var item in Ids)
  206. {
  207. var list = this.BaseRepository("CollegeMIS").FindEntity<ScholarshipEntity>(x => x.Id == item);
  208. if (list != null)
  209. {
  210. list.IsValid = 1;
  211. ScholList.Add(list);
  212. }
  213. }
  214. }
  215. else
  216. {
  217. foreach (var item in Ids)
  218. {
  219. var list = this.BaseRepository("CollegeMIS").FindEntity<ScholarshipEntity>(x => x.Id == item);
  220. if (list != null)
  221. {
  222. list.IsValid = 0;
  223. ScholList.Add(list);
  224. }
  225. }
  226. }
  227. db.Update(ScholList);
  228. db.Commit();
  229. }
  230. catch (Exception ex)
  231. {
  232. if (ex is ExceptionEx)
  233. {
  234. throw;
  235. }
  236. else
  237. {
  238. throw ExceptionEx.ThrowServiceException(ex);
  239. }
  240. }
  241. }
  242. #endregion
  243. #endregion
  244. }
  245. }