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.
 
 
 
 
 
 

207 lines
6.3 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. namespace Learun.Application.CRM
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创 建:超级管理员
  12. /// 日 期:2017-07-11 09:43
  13. /// 描 述:客户管理
  14. /// </summary>
  15. public class CrmCustomerService : RepositoryFactory
  16. {
  17. #region 获取数据
  18. /// <summary>
  19. /// 获取列表
  20. /// </summary>
  21. /// <returns></returns>
  22. public IEnumerable<CrmCustomerEntity> GetList()
  23. {
  24. try
  25. {
  26. return this.BaseRepository().FindList<CrmCustomerEntity>();
  27. }
  28. catch (Exception ex)
  29. {
  30. if (ex is ExceptionEx)
  31. {
  32. throw;
  33. }
  34. else
  35. {
  36. throw ExceptionEx.ThrowServiceException(ex);
  37. }
  38. }
  39. }
  40. /// <summary>
  41. /// 获取列表
  42. /// </summary>
  43. /// <param name="pagination">分页</param>
  44. /// <param name="queryJson">查询参数</param>
  45. /// <returns>返回分页列表</returns>
  46. public IEnumerable<CrmCustomerEntity> GetPageList(Pagination pagination, string queryJson)
  47. {
  48. try
  49. {
  50. var expression = LinqExtensions.True<CrmCustomerEntity>();
  51. var queryParam = queryJson.ToJObject();
  52. //查询条件
  53. if (!queryParam["keyword"].IsEmpty())
  54. {
  55. string keyword = queryParam["keyword"].ToString();
  56. expression = expression.And(t => t.F_EnCode.Contains(keyword) || t.F_FullName.Contains(keyword) || t.F_Contact.Contains(keyword) || t.F_TraceUserName.Contains(keyword));
  57. }
  58. return this.BaseRepository().FindList(expression, pagination);
  59. }
  60. catch (Exception ex)
  61. {
  62. if (ex is ExceptionEx)
  63. {
  64. throw;
  65. }
  66. else
  67. {
  68. throw ExceptionEx.ThrowServiceException(ex);
  69. }
  70. }
  71. }
  72. /// <summary>
  73. /// 获取实体
  74. /// </summary>
  75. /// <param name="keyValue">主键值</param>
  76. /// <returns></returns>
  77. public CrmCustomerEntity GetEntity(string keyValue)
  78. {
  79. try
  80. {
  81. return this.BaseRepository().FindEntity<CrmCustomerEntity>(keyValue);
  82. }
  83. catch (Exception ex)
  84. {
  85. if (ex is ExceptionEx)
  86. {
  87. throw;
  88. }
  89. else
  90. {
  91. throw ExceptionEx.ThrowServiceException(ex);
  92. }
  93. }
  94. }
  95. #endregion
  96. #region 验证数据
  97. /// <summary>
  98. /// 客户名称不能重复
  99. /// </summary>
  100. /// <param name="fullName">名称</param>
  101. /// <param name="keyValue">主键</param>
  102. /// <returns></returns>
  103. public bool ExistFullName(string fullName, string keyValue)
  104. {
  105. try
  106. {
  107. var expression = LinqExtensions.True<CrmCustomerEntity>();
  108. expression = expression.And(t => t.F_FullName == fullName);
  109. if (!string.IsNullOrEmpty(keyValue))
  110. {
  111. expression = expression.And(t => t.F_CustomerId != keyValue);
  112. }
  113. return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
  114. }
  115. catch (Exception ex)
  116. {
  117. if (ex is ExceptionEx)
  118. {
  119. throw;
  120. }
  121. else
  122. {
  123. throw ExceptionEx.ThrowServiceException(ex);
  124. }
  125. }
  126. }
  127. #endregion
  128. #region 提交数据
  129. /// <summary>
  130. /// 删除数据
  131. /// </summary>
  132. /// <param name="keyValue">主键</param>
  133. public void DeleteEntity(string keyValue)
  134. {
  135. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  136. try
  137. {
  138. db.Delete<CrmCustomerEntity>(t => t.F_CustomerId.Equals(keyValue));
  139. db.Delete<CrmTrailRecordEntity>(t => t.F_ObjectId.Equals(keyValue));
  140. db.Delete<CrmCustomerContactEntity>(t => t.F_CustomerId.Equals(keyValue));
  141. db.Commit();
  142. }
  143. catch (Exception ex)
  144. {
  145. db.Rollback();
  146. if (ex is ExceptionEx)
  147. {
  148. throw;
  149. }
  150. else
  151. {
  152. throw ExceptionEx.ThrowServiceException(ex);
  153. }
  154. }
  155. }
  156. /// <summary>
  157. /// 保存表单(新增、修改)
  158. /// </summary>
  159. /// <param name="keyValue">主键值</param>
  160. /// <param name="entity">实体对象</param>
  161. /// <returns></returns>
  162. public void SaveEntity(string keyValue, CrmCustomerEntity entity)
  163. {
  164. try
  165. {
  166. if (!string.IsNullOrEmpty(keyValue))
  167. {
  168. entity.Modify(keyValue);
  169. this.BaseRepository().Update(entity);
  170. }
  171. else
  172. {
  173. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  174. try
  175. {
  176. entity.Create();
  177. db.Insert(entity);
  178. db.Commit();
  179. }
  180. catch (Exception)
  181. {
  182. db.Rollback();
  183. throw;
  184. }
  185. }
  186. }
  187. catch (Exception ex)
  188. {
  189. if (ex is ExceptionEx)
  190. {
  191. throw;
  192. }
  193. else
  194. {
  195. throw ExceptionEx.ThrowServiceException(ex);
  196. }
  197. }
  198. }
  199. #endregion
  200. }
  201. }