BasBinService.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System;
  2. using SqlSugar;
  3. using Infrastructure.Attribute;
  4. using ZR.Model;
  5. using ZR.Repository;
  6. using System.Linq;
  7. using System.Collections.Generic;
  8. using ZR.Model.System;
  9. using Infrastructure;
  10. using Infrastructure.Extensions;
  11. using ZR.Common;
  12. using ZR.Service.Business.IBusinessService.BaseSet;
  13. using ZR.Model.Dto.BaseSet;
  14. using ZR.Model.Models.BaseSet;
  15. namespace ZR.Service.Business
  16. {
  17. /// <summary>
  18. /// 基础资料/库位信息表Service业务层处理
  19. ///
  20. /// @author admin
  21. /// @date 2023-04-11
  22. /// </summary>
  23. [AppService(ServiceType = typeof(IBasBinService), ServiceLifetime = LifeTime.Transient)]
  24. public class BasBinService : BaseService<BasBin>, IBasBinService
  25. {
  26. #region 业务逻辑代码
  27. /// <summary>
  28. /// 查询基础资料/库位信息表列表
  29. /// </summary>
  30. /// <param name="parm"></param>
  31. /// <returns></returns>
  32. public PagedInfo<BasBinDto> GetList(BasBinQueryDto parm)
  33. {
  34. //开始拼装查询条件
  35. var predicate = Expressionable.Create<BasBin>();
  36. predicate.AndIF(parm.RegionId > 0, b => b.RegionId == parm.RegionId);
  37. predicate.AndIF(!string.IsNullOrEmpty(parm.BinCode), b => b.BinCode.Contains(parm.BinCode));
  38. predicate.AndIF(parm.BinRow > 0, b => b.BinRow == parm.BinRow);
  39. predicate.AndIF(parm.BinColumn > 0, b => b.BinColumn == parm.BinColumn);
  40. predicate.AndIF(parm.BinLayer > 0, b => b.BinLayer == parm.BinLayer);
  41. predicate.AndIF(!string.IsNullOrEmpty(parm.BinType), b => b.BinType.Equals(parm.BinType));
  42. predicate.AndIF(!string.IsNullOrEmpty(parm.Status), b => b.Status.Equals(parm.Status));
  43. //搜索条件查询语法参考Sqlsugar
  44. var response = Queryable()
  45. .LeftJoin<BasRegion>((b, region) => b.RegionId == region.RegionId)
  46. .Where(predicate.ToExpression())
  47. .Select((b,region)=>new BasBin
  48. {
  49. RegionId = b.RegionId.SelectAll(),
  50. RegionName=region.RegionName,
  51. RegionCode=region.RegionCode,
  52. })
  53. .ToPage<BasBin, BasBinDto>(parm);
  54. return response;
  55. }
  56. /// <summary>
  57. /// 添加基础资料/库位信息表
  58. /// </summary>
  59. /// <param name="model"></param>
  60. /// <returns></returns>
  61. public int AddBasBin(BasBin model)
  62. {
  63. return Add(model, true);
  64. }
  65. /// <summary>
  66. /// 修改基础资料/库位信息表
  67. /// </summary>
  68. /// <param name="model"></param>
  69. /// <returns></returns>
  70. public int UpdateBasBin(BasBin model)
  71. {
  72. //var response = Update(w => w.BinId == model.BinId, it => new BasBin()
  73. //{
  74. // BinCode = model.BinCode,
  75. // BinName = model.BinName,
  76. // BinType = model.BinType,
  77. // RegionId = model.RegionId,
  78. // BinRow = model.BinRow,
  79. // BinColumn = model.BinColumn,
  80. // BinLayer = model.BinLayer,
  81. // Describe = model.Describe,
  82. // Visible = model.Visible,
  83. // Status = model.Status,
  84. // UpdateBy = model.UpdateBy,
  85. // UpdateTime = model.UpdateTime,
  86. // Remark = model.Remark,
  87. //});
  88. //return response;
  89. return Update(model, true);
  90. }
  91. /// <summary>
  92. /// 清空基础资料/库位信息表
  93. /// </summary>
  94. /// <returns></returns>
  95. public void TruncateBasBin()
  96. {
  97. Truncate();
  98. }
  99. /// <summary>
  100. /// 导入数据
  101. /// </summary>
  102. /// <param name="bins"></param>
  103. /// <returns></returns>
  104. public string ImportDatas(List<BasBin> bins)
  105. {
  106. bins.ForEach(x =>
  107. {
  108. x.CreateTime = DateTime.Now;
  109. x.Status = "0";
  110. x.Remark = "数据导入";
  111. });
  112. var x = Context.Storageable(bins)
  113. .SplitInsert(it => !it.Any())
  114. .ToStorage();
  115. var result = x.AsInsertable.ExecuteCommand();//插入可插入部分;
  116. string msg = string.Format(" 插入{0} 更新{1} 错误数据{2} 不计算数据{3} 删除数据{4},总共{5}",
  117. x.InsertList.Count,
  118. x.UpdateList.Count,
  119. x.ErrorList.Count,
  120. x.IgnoreList.Count,
  121. x.DeleteList.Count,
  122. x.TotalList.Count);
  123. //输出统计
  124. Console.WriteLine(msg);
  125. //输出错误信息
  126. foreach (var item in x.ErrorList)
  127. {
  128. Console.WriteLine("BinName为" + item.Item.BinName + " : " + item.StorageMessage);
  129. }
  130. return msg;
  131. }
  132. #endregion
  133. }
  134. }