箱信息同步
This commit is contained in:
@@ -9,6 +9,11 @@ namespace WMS.Web.Core.Dto
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
@@ -14,9 +14,18 @@ namespace WMS.Web.Domain.Infrastructure
|
||||
{
|
||||
Task<Box> Get(int id);
|
||||
Task<Box> GetByNo(string billNo);
|
||||
//根据箱号搜索 用来比对确定是否箱号信息是否存在
|
||||
Task<List<string>> GetByNos(List<string> billNos);
|
||||
//根据箱号查询明细信息
|
||||
Task<List<BoxResponse>> GetBox(List<string> billNos);
|
||||
//批量修改
|
||||
Task<bool> EditEntityList(List<Box> entitys, bool isTransaction = true);
|
||||
/// <summary>
|
||||
/// 批量添加
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> AddRange(List<Box> entitys, bool isTransaction = true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ namespace WMS.Web.Domain.Mappers
|
||||
{
|
||||
CreateMap<Box, BoxResponse>();
|
||||
CreateMap<BoxDetails, BoxDetailResponse>();
|
||||
|
||||
CreateMap<OpsBoxResponse, Box>();
|
||||
CreateMap<OpsBoxDetailsResponse, BoxDetails>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// 箱服务信息
|
||||
/// </summary>
|
||||
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<Result> Sync()
|
||||
public async Task<Result> 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<Box>>(list);
|
||||
//批量添加
|
||||
await _boxRepositories.AddRange(boxs,true);
|
||||
//需要添加序列号记录表
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,5 +107,35 @@ namespace WMS.Web.Repositories
|
||||
|
||||
return entity.Clone();
|
||||
}
|
||||
//根据箱号搜索 用来比对确定是否箱号信息是否存在
|
||||
public async Task<List<string>> GetByNos(List<string> billNos)
|
||||
{
|
||||
return await _context.Box
|
||||
.Where(w => billNos.Contains(w.BoxBillNo)).Select(s=>s.BoxBillNo).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> AddRange(List<Box> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user