OrderService.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using LeaRun.Application.Entity.CustomerManage;
  2. using LeaRun.Application.IService.CustomerManage;
  3. using LeaRun.Data.Repository;
  4. using LeaRun.Util.Extension;
  5. using LeaRun.Util.WebControl;
  6. using LeaRun.Util;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System;
  10. using LeaRun.Application.Service.SystemManage;
  11. using LeaRun.Application.IService.SystemManage;
  12. using LeaRun.Application.Code;
  13. namespace LeaRun.Application.Service.CustomerManage
  14. {
  15. /// <summary>
  16. /// 版 本 6.1
  17. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  18. /// 创 建:佘赐雄
  19. /// 日 期:2016-03-16 13:54
  20. /// 描 述:订单管理
  21. /// </summary>
  22. public class OrderService : RepositoryFactory<OrderEntity>, IOrderService
  23. {
  24. private ICodeRuleService coderuleService = new CodeRuleService();
  25. #region 获取数据
  26. /// <summary>
  27. /// 获取列表
  28. /// </summary>
  29. /// <param name="pagination">分页</param>
  30. /// <param name="queryJson">查询参数</param>
  31. /// <returns>返回分页列表</returns>
  32. public IEnumerable<OrderEntity> GetPageList(Pagination pagination, string queryJson)
  33. {
  34. var expression = LinqExtensions.True<OrderEntity>();
  35. var queryParam = queryJson.ToJObject();
  36. //单据日期
  37. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  38. {
  39. DateTime startTime = queryParam["StartTime"].ToDate();
  40. DateTime endTime = queryParam["EndTime"].ToDate().AddDays(1);
  41. expression = expression.And(t => t.OrderDate >= startTime && t.OrderDate <= endTime);
  42. }
  43. //单据编号
  44. if (!queryParam["OrderCode"].IsEmpty())
  45. {
  46. string OrderCode = queryParam["OrderCode"].ToString();
  47. expression = expression.And(t => t.OrderCode.Contains(OrderCode));
  48. }
  49. //客户名称
  50. if (!queryParam["CustomerName"].IsEmpty())
  51. {
  52. string CustomerName = queryParam["CustomerName"].ToString();
  53. expression = expression.And(t => t.CustomerName.Contains(CustomerName));
  54. }
  55. //销售人员
  56. if (!queryParam["SellerName"].IsEmpty())
  57. {
  58. string SellerName = queryParam["SellerName"].ToString();
  59. expression = expression.And(t => t.SellerName.Contains(SellerName));
  60. }
  61. //收款状态
  62. if (!queryParam["PaymentState"].IsEmpty())
  63. {
  64. int PaymentState = queryParam["PaymentState"].ToInt();
  65. expression = expression.And(t => t.PaymentState == PaymentState);
  66. }
  67. return this.BaseRepository().FindList(expression, pagination);
  68. }
  69. /// <summary>
  70. /// 获取实体
  71. /// </summary>
  72. /// <param name="keyValue">主键值</param>
  73. /// <returns></returns>
  74. public OrderEntity GetEntity(string keyValue)
  75. {
  76. return this.BaseRepository().FindEntity(keyValue);
  77. }
  78. /// <summary>
  79. /// 获取前单、后单 数据
  80. /// </summary>
  81. /// <param name="keyValue">主键值</param>
  82. /// <param name="type">类型(1-前单;2-后单)</param>
  83. /// <returns>返回实体</returns>
  84. public OrderEntity GetPrevOrNextEntity(string keyValue, int type)
  85. {
  86. OrderEntity entity = this.GetEntity(keyValue);
  87. if (type == 1)
  88. {
  89. entity = this.BaseRepository().IQueryable().Where(t => t.CreateDate >entity.CreateDate).OrderBy(t => t.CreateDate).FirstOrDefault();
  90. }
  91. else if (type == 2)
  92. {
  93. entity = this.BaseRepository().IQueryable().Where(t => t.CreateDate < entity.CreateDate).OrderByDescending(t => t.CreateDate).FirstOrDefault();
  94. }
  95. return entity;
  96. }
  97. #endregion
  98. #region 提交数据
  99. /// <summary>
  100. /// 删除数据
  101. /// </summary>
  102. /// <param name="keyValue">主键</param>
  103. public void RemoveForm(string keyValue)
  104. {
  105. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  106. try
  107. {
  108. db.Delete<OrderEntity>(keyValue);
  109. db.Delete<OrderEntryEntity>(t => t.OrderId.Equals(keyValue));
  110. db.Commit();
  111. }
  112. catch (Exception)
  113. {
  114. db.Rollback();
  115. throw;
  116. }
  117. }
  118. /// <summary>
  119. /// 保存表单(新增、修改)
  120. /// </summary>
  121. /// <param name="keyValue">主键值</param>
  122. /// <param name="orderEntity">实体对象</param>
  123. /// <param name="orderEntryList">明细实体对象</param>
  124. /// <returns></returns>
  125. public void SaveForm(string keyValue, OrderEntity orderEntity, List<OrderEntryEntity> orderEntryList)
  126. {
  127. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  128. try
  129. {
  130. if (!string.IsNullOrEmpty(keyValue))
  131. {
  132. //主表
  133. orderEntity.Modify(keyValue);
  134. db.Update(orderEntity);
  135. //明细
  136. db.Delete<OrderEntryEntity>(t => t.OrderId.Equals(keyValue));
  137. foreach (OrderEntryEntity orderEntryEntity in orderEntryList)
  138. {
  139. orderEntryEntity.OrderId = orderEntity.OrderId;
  140. db.Insert(orderEntryEntity);
  141. }
  142. }
  143. else
  144. {
  145. //主表
  146. orderEntity.Create();
  147. db.Insert(orderEntity);
  148. coderuleService.UseRuleSeed(orderEntity.CreateUserId, "", ((int)CodeRuleEnum.Customer_OrderCode).ToString(), db);//占用单据号
  149. //明细
  150. foreach (OrderEntryEntity orderEntryEntity in orderEntryList)
  151. {
  152. orderEntryEntity.Create();
  153. orderEntryEntity.OrderId = orderEntity.OrderId;
  154. db.Insert(orderEntryEntity);
  155. }
  156. }
  157. db.Commit();
  158. }
  159. catch (Exception)
  160. {
  161. db.Rollback();
  162. throw;
  163. }
  164. }
  165. #endregion
  166. }
  167. }