WCSCachelineService.cs 6.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using Org.BouncyCastle.Crypto;
  2. using SqlSugar;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using wms.sqlsugar.model.fj;
  10. using WMS.BZModels;
  11. using WMS.BZModels.Dto.FJ.WCSCachelineDtos;
  12. using WMS.BZSqlSugar;
  13. using WMS.Info;
  14. namespace WMS.BZServices.FJ
  15. {
  16. public class WCSCachelineService
  17. {
  18. private readonly Repository<WCSCacheline> _WCSCachelineRepository;
  19. private readonly Repository<WCSCachelineloc> _WCSCachelinelocRepository;
  20. private readonly Repository<BaseWarehouse> _wareHouserepository;
  21. public WCSCachelineService(Repository<WCSCacheline> wCSCachelineRepository, Repository<BaseWarehouse> wareHouserepository, Repository<WCSCachelineloc> wCSCachelinelocRepository)
  22. {
  23. _WCSCachelineRepository = wCSCachelineRepository;
  24. _wareHouserepository = wareHouserepository;
  25. _WCSCachelinelocRepository = wCSCachelinelocRepository;
  26. }
  27. public PagedInfo<WCSCachelineDto> GetPageList(Pagination pagination, WCSCachelineQueryDto wcsCachelineQueryDto)
  28. {
  29. var predicate = Expressionable.Create<WCSCacheline>();
  30. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.Id), m => m.Id.ToString().Contains(wcsCachelineQueryDto.Id));
  31. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.KeyWord), m => m.Id.ToString().Contains(wcsCachelineQueryDto.KeyWord) || m.LocationNo.ToString().Contains(wcsCachelineQueryDto.KeyWord) || m.MatCodeList.Contains(wcsCachelineQueryDto.KeyWord) || m.TargetAddress.ToString().Contains(wcsCachelineQueryDto.KeyWord));
  32. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.LocationNo), m => m.LocationNo.ToString().Contains(wcsCachelineQueryDto.LocationNo));
  33. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.TargetAddress), m => m.TargetAddress.ToString().Contains(wcsCachelineQueryDto.TargetAddress));
  34. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.PalletizingRowId), m => m.PalletizingRowId.ToString().Contains(wcsCachelineQueryDto.PalletizingRowId));
  35. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.Put), m => m.Put.Equals(wcsCachelineQueryDto.Put));
  36. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.Quantity), m => m.Quantity.ToString().Contains(wcsCachelineQueryDto.Quantity));
  37. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.MatCodeList), m => m.MatCodeList.ToString().Contains(wcsCachelineQueryDto.MatCodeList));
  38. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.InStock), m => m.InStock.Equals(wcsCachelineQueryDto.InStock));
  39. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.IsTruss), m => m.IsTruss.Equals(wcsCachelineQueryDto.IsTruss));
  40. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.WarehouseCode), m => m.WarehouseCode.Equals(wcsCachelineQueryDto.WarehouseCode));
  41. predicate = predicate.AndIF(wcsCachelineQueryDto != null && wcsCachelineQueryDto.AddTimeFrom.HasValue, m => m.AddTime >= wcsCachelineQueryDto.AddTimeFrom);
  42. predicate = predicate.AndIF(wcsCachelineQueryDto != null && wcsCachelineQueryDto.AddTimeTo.HasValue, m => m.AddTime <= wcsCachelineQueryDto.AddTimeTo);
  43. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrWhiteSpace(wcsCachelineQueryDto.TaskId), m => SqlFunc.Subqueryable<WCSCachelineloc>().Where(s => s.CacheLineId == m.Id && s.TaskId.ToString().Contains(wcsCachelineQueryDto.TaskId)).Any());
  44. var list = _WCSCachelineRepository.Queryable().Where(predicate.ToExpression())
  45. .ToPage<WCSCacheline, WCSCachelineDto>(pagination);
  46. var wareHouses = _wareHouserepository.Queryable().Where(o => o.IsStop == 0).ToList();
  47. list.Result.ForEach(o =>
  48. {
  49. o.WarehouseName = wareHouses.FirstOrDefault(v => v.Code == o.WarehouseCode)?.Name ?? "";
  50. });
  51. return list;
  52. }
  53. public void Delete(List<int> ids)
  54. {
  55. if (ids==null || !ids.Any()) throw new ArgumentException("参数错误!");
  56. var entitys = _WCSCachelineRepository.Queryable().Where(o =>ids.Contains(o.Id )).ToList() ;
  57. if (!entitys.Any() )
  58. {
  59. throw new ArgumentException("没有找到数据!");
  60. }
  61. foreach ( var entity in entitys )
  62. {
  63. _WCSCachelineRepository.UseTranAction(() =>
  64. {
  65. _WCSCachelineRepository.Deleteable().Where(it => it.Id == entity.Id).ExecuteCommand();
  66. _WCSCachelinelocRepository.Deleteable().Where(it => it.CacheLineId == entity.Id).ExecuteCommand();
  67. });
  68. }
  69. }
  70. public bool UpdateOvertime(List<int> ids)
  71. {
  72. if (ids == null || !ids.Any()) throw new ArgumentException("参数错误!");
  73. var list = _WCSCachelineRepository.Queryable().Where(o => ids.Contains(o.Id)).ToList();
  74. if (!list.Any())
  75. {
  76. throw new ArgumentException("没有找到该缓存信息!");
  77. }
  78. list.ForEach(o =>
  79. {
  80. o.AddTime = o.AddTime.AddHours(-12);
  81. o.EditTime = DateTime.Now;
  82. });
  83. var result = _WCSCachelineRepository.UpdateRange(list.ToArray());
  84. return result;
  85. }
  86. }
  87. }