WCSCachelineService.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using SqlSugar;
  2. using WMS.BZModels;
  3. using WMS.BZModels.Dto.KLHC.WCSCachelineDtos;
  4. using WMS.BZModels.Models.KLHC;
  5. using WMS.BZSqlSugar;
  6. using WMS.Info;
  7. namespace WMS.BZServices.KLHC
  8. {
  9. public class WCSCachelineService
  10. {
  11. private readonly Repository<WCS_CacheLine> _WCSCachelineRepository;
  12. private readonly Repository<WCS_CacheLineLoc> _WCSCachelinelocRepository;
  13. private readonly Repository<BaseWarehouse> _wareHouserepository;
  14. public WCSCachelineService(Repository<WCS_CacheLine> wCSCachelineRepository, Repository<BaseWarehouse> wareHouserepository, Repository<WCS_CacheLineLoc> wCSCachelinelocRepository)
  15. {
  16. _WCSCachelineRepository = wCSCachelineRepository;
  17. _wareHouserepository = wareHouserepository;
  18. _WCSCachelinelocRepository = wCSCachelinelocRepository;
  19. }
  20. public PagedInfo<WCSCachelineDto> GetPageList(Pagination pagination, WCSCachelineQueryDto wcsCachelineQueryDto)
  21. {
  22. var predicate = Expressionable.Create<WCS_CacheLine>();
  23. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.Id), m => m.Id.ToString().Contains(wcsCachelineQueryDto.Id));
  24. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.KeyWord), m => m.Id.ToString().Contains(wcsCachelineQueryDto.KeyWord) || m.TargetCacheLine.ToString().Contains(wcsCachelineQueryDto.KeyWord) || m.WheelType.Contains(wcsCachelineQueryDto.KeyWord));
  25. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.LocationNo), m => m.TargetCacheLine.ToString().Contains(wcsCachelineQueryDto.LocationNo));
  26. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.Truss), m => m.Truss.Contains(wcsCachelineQueryDto.Truss));
  27. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.Quantity), m => m.ExistingSpoolCount.ToString().Contains(wcsCachelineQueryDto.Quantity));
  28. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.WheelType), m => m.WheelType.ToString().Contains(wcsCachelineQueryDto.WheelType));
  29. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.IsCompleted), m => m.IsCompleted.Equals(wcsCachelineQueryDto.IsCompleted));
  30. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrEmpty(wcsCachelineQueryDto?.IsTruss), m => m.IsTruss.Equals(wcsCachelineQueryDto.IsTruss));
  31. predicate = predicate.AndIF(wcsCachelineQueryDto != null && wcsCachelineQueryDto.AddTimeFrom.HasValue, m => m.AddTime >= wcsCachelineQueryDto.AddTimeFrom);
  32. predicate = predicate.AndIF(wcsCachelineQueryDto != null && wcsCachelineQueryDto.AddTimeTo.HasValue, m => m.AddTime <= wcsCachelineQueryDto.AddTimeTo);
  33. predicate = predicate.AndIF(wcsCachelineQueryDto != null && !string.IsNullOrWhiteSpace(wcsCachelineQueryDto.TaskId), m => m.Id.ToString().Contains(wcsCachelineQueryDto.TaskId));
  34. var list = _WCSCachelineRepository.Queryable().Where(predicate.ToExpression())
  35. .ToPage<WCS_CacheLine, WCSCachelineDto>(pagination);
  36. return list;
  37. }
  38. public void Delete(List<int> ids)
  39. {
  40. if (ids == null || !ids.Any()) throw new ArgumentException("参数错误!");
  41. var entitys = _WCSCachelineRepository.Queryable().Where(o => ids.Contains(o.Id)).ToList();
  42. if (!entitys.Any())
  43. {
  44. throw new ArgumentException("没有找到数据!");
  45. }
  46. foreach (var entity in entitys)
  47. {
  48. _WCSCachelineRepository.UseTranAction(() =>
  49. {
  50. _WCSCachelineRepository.Deleteable().Where(it => it.Id == entity.Id).ExecuteCommand();
  51. _WCSCachelinelocRepository.Deleteable().Where(it => it.CacheLineId == entity.Id).ExecuteCommand();
  52. });
  53. }
  54. }
  55. }
  56. }