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.
 
 
 
 
 
 

238 lines
7.3 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.AssetManagementSystem
  9. {
  10. /// <summary>
  11. /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
  12. /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  13. /// 创 建:超级管理员
  14. /// 日 期:2022-11-07 14:25
  15. /// 描 述:经费开支申报
  16. /// </summary>
  17. public class FundsApplyService : RepositoryFactory
  18. {
  19. #region 获取数据
  20. /// <summary>
  21. /// 获取页面显示列表数据
  22. /// </summary>
  23. /// <param name="pagination">分页参数</param>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<FundsApplyEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT ");
  32. strSql.Append(@"
  33. t.*
  34. ");
  35. strSql.Append(" FROM FundsApply 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 ( t.ApplyTime >= @startTime AND t.ApplyTime <= @endTime ) ");
  45. }
  46. if (!queryParam["ApplyUser"].IsEmpty())
  47. {
  48. dp.Add("ApplyUser", queryParam["ApplyUser"].ToString(), DbType.String);
  49. strSql.Append(" AND t.ApplyUser = @ApplyUser ");
  50. }
  51. return this.BaseRepository("CollegeMIS").FindList<FundsApplyEntity>(strSql.ToString(), dp, pagination);
  52. }
  53. catch (Exception ex)
  54. {
  55. if (ex is ExceptionEx)
  56. {
  57. throw;
  58. }
  59. else
  60. {
  61. throw ExceptionEx.ThrowServiceException(ex);
  62. }
  63. }
  64. }
  65. /// <summary>
  66. /// 获取FundsApply表实体数据
  67. /// </summary>
  68. /// <param name="keyValue">主键</param>
  69. /// <returns></returns>
  70. public FundsApplyEntity GetFundsApplyEntity(string keyValue)
  71. {
  72. try
  73. {
  74. return this.BaseRepository("CollegeMIS").FindEntity<FundsApplyEntity>(keyValue);
  75. }
  76. catch (Exception ex)
  77. {
  78. if (ex is ExceptionEx)
  79. {
  80. throw;
  81. }
  82. else
  83. {
  84. throw ExceptionEx.ThrowServiceException(ex);
  85. }
  86. }
  87. }
  88. /// <summary>
  89. /// 获取主表实体数据
  90. /// </summary>
  91. /// <param name="processId">流程实例ID</param>
  92. /// <returns></returns>
  93. public FundsApplyEntity GetEntityByProcessId(string processId)
  94. {
  95. try
  96. {
  97. return this.BaseRepository("CollegeMIS").FindEntity<FundsApplyEntity>(t => t.ProcessId == processId);
  98. }
  99. catch (Exception ex)
  100. {
  101. if (ex is ExceptionEx)
  102. {
  103. throw;
  104. }
  105. else
  106. {
  107. throw ExceptionEx.ThrowServiceException(ex);
  108. }
  109. }
  110. }
  111. #endregion
  112. #region 提交数据
  113. /// <summary>
  114. /// 删除实体数据
  115. /// </summary>
  116. /// <param name="keyValue">主键</param>
  117. public void DeleteEntity(string keyValue)
  118. {
  119. try
  120. {
  121. this.BaseRepository("CollegeMIS").Delete<FundsApplyEntity>(t => t.Id == keyValue);
  122. this.BaseRepository("CollegeMIS").Delete<FundsApplyDetailEntity>(t => t.ApplyId == keyValue);
  123. }
  124. catch (Exception ex)
  125. {
  126. if (ex is ExceptionEx)
  127. {
  128. throw;
  129. }
  130. else
  131. {
  132. throw ExceptionEx.ThrowServiceException(ex);
  133. }
  134. }
  135. }
  136. /// <summary>
  137. /// 保存实体数据(新增、修改)
  138. /// </summary>
  139. /// <param name="keyValue">主键</param>
  140. /// <param name="entity">实体</param>
  141. /// <returns></returns>
  142. public void SaveEntity(string keyValue, FundsApplyEntity entity, List<FundsApplyDetailEntity> detailList)
  143. {
  144. var db = this.BaseRepository("CollegeMIS");
  145. try
  146. {
  147. db.BeginTrans();
  148. if (!string.IsNullOrEmpty(keyValue))
  149. {
  150. entity.Modify(keyValue);
  151. db.Update(entity);
  152. }
  153. else
  154. {
  155. entity.Create();
  156. db.Insert(entity);
  157. }
  158. //子表
  159. db.ExecuteBySql($"delete FundsApplyDetail where ApplyId='{entity.Id}'");
  160. foreach (var detail in detailList)
  161. {
  162. detail.Create();
  163. detail.ApplyId = entity.Id;
  164. db.Insert(detail);
  165. }
  166. db.Commit();
  167. }
  168. catch (Exception ex)
  169. {
  170. db.Rollback();
  171. if (ex is ExceptionEx)
  172. {
  173. throw;
  174. }
  175. else
  176. {
  177. throw ExceptionEx.ThrowServiceException(ex);
  178. }
  179. }
  180. }
  181. /// <summary>
  182. ///
  183. /// </summary>
  184. /// <param name="keyValue"></param>
  185. /// <param name="status"></param>
  186. /// <param name="processId"></param>
  187. public void ChangeStatusById(string keyValue, int status, string processId)
  188. {
  189. try
  190. {
  191. this.BaseRepository("CollegeMIS").ExecuteBySql($"update FundsApply set ProcessId='{processId}',status='{status}' where Id='{keyValue}'");
  192. }
  193. catch (Exception ex)
  194. {
  195. if (ex is ExceptionEx)
  196. {
  197. throw;
  198. }
  199. else
  200. {
  201. throw ExceptionEx.ThrowServiceException(ex);
  202. }
  203. }
  204. }
  205. public void ChangeStatusByProcessId(string processId, int status)
  206. {
  207. try
  208. {
  209. this.BaseRepository("CollegeMIS").ExecuteBySql($"update FundsApply set status='{status}' where ProcessId='{processId}'");
  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. }
  225. }