diff --git a/src/WMS.Web.Core/Dto/OpsBoxRequest.cs b/src/WMS.Web.Core/Dto/OpsBoxRequest.cs index 4497d64b..7207ea30 100644 --- a/src/WMS.Web.Core/Dto/OpsBoxRequest.cs +++ b/src/WMS.Web.Core/Dto/OpsBoxRequest.cs @@ -9,6 +9,11 @@ namespace WMS.Web.Core.Dto /// public class OpsBoxRequest { + public OpsBoxRequest() { } + public OpsBoxRequest(DateTime strartTime,DateTime endTime) { + this.StrartTime = strartTime; + this.EndTime = endTime; + } public DateTime StrartTime { get; set; } public DateTime EndTime { get; set; } public string BoxBillNo { get; set; } diff --git a/src/WMS.Web.Domain/Infrastructure/IBoxRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IBoxRepositories.cs index 935d3894..120193a1 100644 --- a/src/WMS.Web.Domain/Infrastructure/IBoxRepositories.cs +++ b/src/WMS.Web.Domain/Infrastructure/IBoxRepositories.cs @@ -14,9 +14,18 @@ namespace WMS.Web.Domain.Infrastructure { Task Get(int id); Task GetByNo(string billNo); + //根据箱号搜索 用来比对确定是否箱号信息是否存在 + Task> GetByNos(List billNos); //根据箱号查询明细信息 Task> GetBox(List billNos); //批量修改 Task EditEntityList(List entitys, bool isTransaction = true); + /// + /// 批量添加 + /// + /// + /// + /// + Task AddRange(List entitys, bool isTransaction = true); } } diff --git a/src/WMS.Web.Domain/Mappers/BoxMapper.cs b/src/WMS.Web.Domain/Mappers/BoxMapper.cs index f4d6fe42..991368d2 100644 --- a/src/WMS.Web.Domain/Mappers/BoxMapper.cs +++ b/src/WMS.Web.Domain/Mappers/BoxMapper.cs @@ -16,6 +16,9 @@ namespace WMS.Web.Domain.Mappers { CreateMap(); CreateMap(); + + CreateMap(); + CreateMap(); } } } diff --git a/src/WMS.Web.Domain/Services/BoxService.cs b/src/WMS.Web.Domain/Services/BoxService.cs index 8972d03e..938232c2 100644 --- a/src/WMS.Web.Domain/Services/BoxService.cs +++ b/src/WMS.Web.Domain/Services/BoxService.cs @@ -1,9 +1,12 @@ using AutoMapper; using System; using System.Collections.Generic; +using System.Linq; using System.Text; using System.Threading.Tasks; +using WMS.Web.Core.Dto; using WMS.Web.Core.Internal.Results; +using WMS.Web.Domain.Entitys; using WMS.Web.Domain.Infrastructure; using WMS.Web.Domain.IService; using WMS.Web.Domain.IService.Public; @@ -13,7 +16,7 @@ namespace WMS.Web.Domain.Services /// /// 箱服务信息 /// - public class BoxService: IBoxService + public class BoxService : IBoxService { private readonly IMapper _mapper; private readonly ILoginService _loginService; @@ -31,9 +34,23 @@ namespace WMS.Web.Domain.Services _opsService = opsService; } - public Task Sync() + public async Task Sync() { - throw new NotImplementedException(); + OpsBoxRequest request = new OpsBoxRequest(DateTime.Now.AddYears(-1), DateTime.Now); + var list = await _opsService.GetBox(request); + var nos = list.Select(s => s.BoxBillNo).ToList(); + var old_nos=await _boxRepositories.GetByNos(nos); + foreach(var s in old_nos) + { + //数据库里已经存在箱信息 移除 + var box = list.FirstOrDefault(f => f.BoxBillNo.Equals(s)); + list.Remove(box); + } + var boxs = _mapper.Map>(list); + //批量添加 + await _boxRepositories.AddRange(boxs,true); + //需要添加序列号记录表 + return Result.ReSuccess(); } } } diff --git a/src/WMS.Web.Repositories/BoxRepositories.cs b/src/WMS.Web.Repositories/BoxRepositories.cs index 690f3261..110cb16a 100644 --- a/src/WMS.Web.Repositories/BoxRepositories.cs +++ b/src/WMS.Web.Repositories/BoxRepositories.cs @@ -107,5 +107,35 @@ namespace WMS.Web.Repositories return entity.Clone(); } + //根据箱号搜索 用来比对确定是否箱号信息是否存在 + public async Task> GetByNos(List billNos) + { + return await _context.Box + .Where(w => billNos.Contains(w.BoxBillNo)).Select(s=>s.BoxBillNo).ToListAsync(); + } + + public async Task AddRange(List entitys, bool isTransaction = true) + { + IDbContextTransaction _transaction = null; + if (isTransaction) + _transaction = _context.Database.BeginTransaction(); + try + { + if (entitys != null && entitys.Count != 0) + { + await _context.Box.AddRangeAsync(entitys); + await _context.SaveChangesAsync(); + } + if (_transaction != null) + _transaction.Commit(); + return true; + } + catch + { + if (_transaction != null) + _transaction.Rollback(); + return false; + } + } } }