序列号添加
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using WMS.Web.Core.Internal.Results;
|
using WMS.Web.Core.Internal.Results;
|
||||||
|
using WMS.Web.Domain.Entitys;
|
||||||
|
|
||||||
namespace WMS.Web.Domain.IService
|
namespace WMS.Web.Domain.IService
|
||||||
{
|
{
|
||||||
@@ -11,5 +12,6 @@ namespace WMS.Web.Domain.IService
|
|||||||
{
|
{
|
||||||
// 同步老Ops箱信息
|
// 同步老Ops箱信息
|
||||||
Task<Result> Sync();
|
Task<Result> Sync();
|
||||||
|
Task<Result> SerialNumberOperate(List<SerialNumberOperate> list, bool isTransaction = true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -10,6 +11,7 @@ using WMS.Web.Domain.Entitys;
|
|||||||
using WMS.Web.Domain.Infrastructure;
|
using WMS.Web.Domain.Infrastructure;
|
||||||
using WMS.Web.Domain.IService;
|
using WMS.Web.Domain.IService;
|
||||||
using WMS.Web.Domain.IService.Public;
|
using WMS.Web.Domain.IService.Public;
|
||||||
|
using WMS.Web.Domain.Values;
|
||||||
|
|
||||||
namespace WMS.Web.Domain.Services
|
namespace WMS.Web.Domain.Services
|
||||||
{
|
{
|
||||||
@@ -23,15 +25,17 @@ namespace WMS.Web.Domain.Services
|
|||||||
public readonly IBasicsRepositories _transactionRepositories;
|
public readonly IBasicsRepositories _transactionRepositories;
|
||||||
private readonly IBoxRepositories _boxRepositories;
|
private readonly IBoxRepositories _boxRepositories;
|
||||||
private readonly IOpsService _opsService;
|
private readonly IOpsService _opsService;
|
||||||
|
private readonly ISerialNumberOperateRepositories _serialNumberOperateRepositories;
|
||||||
public BoxService(IMapper mapper, ILoginService loginService,
|
public BoxService(IMapper mapper, ILoginService loginService,
|
||||||
IBasicsRepositories transactionRepositories,
|
IBasicsRepositories transactionRepositories,
|
||||||
IBoxRepositories boxRepositories, IOpsService opsService)
|
IBoxRepositories boxRepositories, IOpsService opsService, ISerialNumberOperateRepositories serialNumberOperateRepositories)
|
||||||
{
|
{
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
_loginService = loginService;
|
_loginService = loginService;
|
||||||
_transactionRepositories = transactionRepositories;
|
_transactionRepositories = transactionRepositories;
|
||||||
_boxRepositories = boxRepositories;
|
_boxRepositories = boxRepositories;
|
||||||
_opsService = opsService;
|
_opsService = opsService;
|
||||||
|
_serialNumberOperateRepositories = serialNumberOperateRepositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Result> Sync()
|
public async Task<Result> Sync()
|
||||||
@@ -47,9 +51,45 @@ namespace WMS.Web.Domain.Services
|
|||||||
list.Remove(box);
|
list.Remove(box);
|
||||||
}
|
}
|
||||||
var boxs = _mapper.Map<List<Box>>(list);
|
var boxs = _mapper.Map<List<Box>>(list);
|
||||||
//批量添加
|
|
||||||
await _boxRepositories.AddRange(boxs,true);
|
|
||||||
//需要添加序列号记录表
|
//需要添加序列号记录表
|
||||||
|
List<SerialNumberOperate> sList = new List<SerialNumberOperate>();
|
||||||
|
foreach (var b in boxs)
|
||||||
|
{
|
||||||
|
foreach (var sn in b.Details.SelectMany(s => s.SerialNumbers))
|
||||||
|
{
|
||||||
|
SerialNumberOperate s = new SerialNumberOperate(sn, SerialNumberOperateType.Generate, b.CreateUser, "", b.SupplierId, b.OrgId, null, b.CreateTime);
|
||||||
|
sList.Add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IDbContextTransaction _transaction = _transactionRepositories.GetTransaction();
|
||||||
|
bool isRollback = false;
|
||||||
|
bool isSuccess = true;
|
||||||
|
//批量添加
|
||||||
|
isSuccess = await _boxRepositories.AddRange(boxs, false);
|
||||||
|
if (!isSuccess) isRollback = true;
|
||||||
|
//序列号操作记录
|
||||||
|
var res = await this.SerialNumberOperate(sList, false);
|
||||||
|
if (!res.Success) isRollback = true;
|
||||||
|
|
||||||
|
//提交事务
|
||||||
|
isSuccess = _transactionRepositories.CommitTransaction(isRollback, _transaction);
|
||||||
|
if (!isSuccess)
|
||||||
|
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||||
|
|
||||||
|
return Result.ReSuccess();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 序列号操作记录日志
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="list"></param>
|
||||||
|
/// <param name="isTransaction"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<Result> SerialNumberOperate(List<SerialNumberOperate> list, bool isTransaction = true)
|
||||||
|
{
|
||||||
|
var isSuccess = await _serialNumberOperateRepositories.AddRange(list, isTransaction);
|
||||||
|
if (!isSuccess) return Result.ReFailure(ResultCodes.DateWriteError);
|
||||||
return Result.ReSuccess();
|
return Result.ReSuccess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user