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.
 
 
 
 
 
 

178 lines
5.6 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace Learun.Application.CRM
  6. {
  7. /// <summary>
  8. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  9. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  10. /// 创 建:超级管理员
  11. /// 日 期:2017-07-11 14:28
  12. /// 描 述:费用支出
  13. /// </summary>
  14. public class CrmExpensesService : RepositoryFactory
  15. {
  16. #region 获取数据
  17. /// <summary>
  18. /// 获取列表
  19. /// </summary>
  20. /// <param name="pagination">分页</param>
  21. /// <param name="queryJson">查询参数</param>
  22. /// <returns>返回分页列表</returns>
  23. public IEnumerable<CrmExpensesEntity> GetPageList(Pagination pagination, string queryJson)
  24. {
  25. try
  26. {
  27. var expression = LinqExtensions.True<CrmExpensesEntity>();
  28. var queryParam = queryJson.ToJObject();
  29. //支出日期
  30. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  31. {
  32. DateTime startTime = queryParam["StartTime"].ToDate();
  33. DateTime endTime = queryParam["EndTime"].ToDate().AddDays(1);
  34. expression = expression.And(t => t.F_ExpensesDate >= startTime && t.F_ExpensesDate <= endTime);
  35. }
  36. //支出种类
  37. if (!queryParam["ExpensesType"].IsEmpty())
  38. {
  39. string CustomerName = queryParam["ExpensesType"].ToString();
  40. expression = expression.And(t => t.F_ExpensesType.Equals(CustomerName));
  41. }
  42. //经手人
  43. if (!queryParam["Managers"].IsEmpty())
  44. {
  45. string SellerName = queryParam["Managers"].ToString();
  46. expression = expression.And(t => t.F_Managers.Contains(SellerName));
  47. }
  48. return this.BaseRepository().FindList(expression, 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. /// 获取列表
  64. /// </summary>
  65. /// <param name="queryJson">查询参数</param>
  66. /// <returns>返回列表</returns>
  67. public IEnumerable<CrmExpensesEntity> GetList(string queryJson)
  68. {
  69. try
  70. {
  71. return this.BaseRepository().FindList<CrmExpensesEntity>();
  72. }
  73. catch (Exception ex)
  74. {
  75. if (ex is ExceptionEx)
  76. {
  77. throw;
  78. }
  79. else
  80. {
  81. throw ExceptionEx.ThrowServiceException(ex);
  82. }
  83. }
  84. }
  85. /// <summary>
  86. /// 获取实体
  87. /// </summary>
  88. /// <param name="keyValue">主键值</param>
  89. /// <returns></returns>
  90. public CrmExpensesEntity GetEntity(string keyValue)
  91. {
  92. try
  93. {
  94. return this.BaseRepository().FindEntity<CrmExpensesEntity>(keyValue);
  95. }
  96. catch (Exception ex)
  97. {
  98. if (ex is ExceptionEx)
  99. {
  100. throw;
  101. }
  102. else
  103. {
  104. throw ExceptionEx.ThrowServiceException(ex);
  105. }
  106. }
  107. }
  108. #endregion
  109. #region 提交数据
  110. /// <summary>
  111. /// 删除数据
  112. /// </summary>
  113. /// <param name="keyValue">主键</param>
  114. public void DeleteEntity(string keyValue)
  115. {
  116. try
  117. {
  118. this.BaseRepository().Delete(keyValue);
  119. }
  120. catch (Exception ex)
  121. {
  122. if (ex is ExceptionEx)
  123. {
  124. throw;
  125. }
  126. else
  127. {
  128. throw ExceptionEx.ThrowServiceException(ex);
  129. }
  130. }
  131. }
  132. /// <summary>
  133. /// 保存表单(新增)
  134. /// </summary>
  135. /// <param name="entity">实体对象</param>
  136. /// <returns></returns>
  137. public void SaveEntity(CrmExpensesEntity entity)
  138. {
  139. CrmCashBalanceService crmCashBalanceService = new CrmCashBalanceService();
  140. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  141. try
  142. {
  143. //支出
  144. entity.Create();
  145. db.Insert(entity);
  146. //添加账户余额
  147. crmCashBalanceService.AddBalance(db, new CrmCashBalanceEntity
  148. {
  149. F_ObjectId = entity.F_ExpensesId,
  150. F_ExecutionDate = entity.F_ExpensesDate,
  151. F_CashAccount = entity.F_ExpensesAccount,
  152. F_Expenses = entity.F_ExpensesPrice,
  153. F_Abstract = entity.F_ExpensesAbstract
  154. });
  155. db.Commit();
  156. }
  157. catch (Exception ex)
  158. {
  159. db.Rollback();
  160. if (ex is ExceptionEx)
  161. {
  162. throw;
  163. }
  164. else
  165. {
  166. throw ExceptionEx.ThrowServiceException(ex);
  167. }
  168. }
  169. }
  170. #endregion
  171. }
  172. }