调整金蝶同步

This commit is contained in:
18942506660
2023-11-06 14:56:17 +08:00
parent 78db8b7f24
commit c4e4b1a59b
9 changed files with 158 additions and 12 deletions

View File

@@ -49,5 +49,9 @@ namespace WMS.Web.Core.Dto.Erp.OutStock
/// 创建时间erp那边的创建时间
///</summary>
public DateTime? CreateTime { get; set; }
/// <summary>
/// 用来自动构建单据类型 跟OutStockType 一致
/// </summary>
public int Type { get; set; }
}
}

View File

@@ -44,7 +44,7 @@ namespace WMS.Web.Domain.Entitys
/// 单据类型
/// </summary>
[Column("Type")]
public OrderType Type { get; set; } = OrderType.Sal_Out;
public OutStockType Type { get; set; } = OutStockType.Sal;
/// <summary>
/// 发货组织
///</summary>
@@ -78,7 +78,7 @@ namespace WMS.Web.Domain.Entitys
/// 创建
/// </summary>
/// <param name="creatorId"></param>
public void Create(int creatorId,int taskId, OrderType type)
public void Create(int creatorId,int taskId, OutStockType type)
{
this.TaskId = taskId;
this.Type = type;

View File

@@ -51,7 +51,7 @@ namespace WMS.Web.Domain.Entitys
/// 单据类型
/// </summary>
[Column("Type")]
public OrderType Type { get; set; } = OrderType.Sal_Out;
public OutStockType Type { get; set; } = OutStockType.Sal;
/// <summary>
/// 操作人(出库人)
/// </summary>
@@ -71,6 +71,14 @@ namespace WMS.Web.Domain.Entitys
/// 明细
/// </summary>
public List<OutStockTaskDetails> Details = new List<OutStockTaskDetails>();
public void Create(OutStockType type, string sourceBillNo, int deliveryOrgId, int receiptCustomerId, DateTime createTime)
{
this.Type = type;
this.SourceBillNo = sourceBillNo;
this.DeliveryOrgId = deliveryOrgId;
this.ReceiptCustomerId = receiptCustomerId;
this.CreateTime = createTime;
}
/// <summary>
/// 生成单据号
/// </summary>
@@ -114,7 +122,7 @@ namespace WMS.Web.Domain.Entitys
{
// 符合合并数据逻辑:出库状态为”待拣货”+出库类型为:销售出库+发货组织一致+收货客户一致+发货仓库一致
if (list.Where(w => w.Status != OutStockStatus.Wait).Any()) return Result.ReFailure(ResultCodes.MergeStatusError);
if (list.Where(w => w.Type != OrderType.Sal_Out).Any()) return Result.ReFailure(ResultCodes.MergeStatusError);
if (list.Where(w => w.Type != OutStockType.Sal).Any()) return Result.ReFailure(ResultCodes.MergeStatusError);
if (list.GroupBy(g => g.DeliveryOrgId).Count() > 1) return Result.ReFailure(ResultCodes.MergeStatusError);
if (list.GroupBy(g => g.ReceiptCustomerId).Count() > 1) return Result.ReFailure(ResultCodes.MergeStatusError);
@@ -131,7 +139,7 @@ namespace WMS.Web.Domain.Entitys
this.OperatorId = creatorId;
this.OperateTime = DateTime.Now;
this.Status = OutStockStatus.Wait;
this.Type = OrderType.Sal_Out;
this.Type = OutStockType.Sal;
this.Details = details;
return Result.ReSuccess();

View File

@@ -18,7 +18,7 @@ namespace WMS.Web.Domain.IService.Public
/// </summary>
/// <param name="isTransaction"></param>
/// <returns></returns>
Task<Result> SsynDeliveryNoticeOutStock(bool isTransaction);
Task<Result> SsynDeliveryNoticeOutStock(bool isTransaction,List<string> sourceBillNos = null);
//出库任务作废
Task<Result> Repeal(OperateRequest dto, LoginInDto loginInfo);
//出库任务作废

View File

@@ -11,10 +11,23 @@ namespace WMS.Web.Domain.Infrastructure
{
// 新增
Task<OutStockTask> Add(OutStockTask entity, bool isTransaction = true);
/// <summary>
/// 批量添加
/// </summary>
/// <param name="entitys"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
Task<bool> AddRange(List<OutStockTask> entitys, bool isTransaction = true);
// 获取列表
Task<(List<OutStockTaskQueryInfoResponse> list, int total)> GetListAsync(OutStockTaskQueryRequest dto);
/// 查询实体集合
Task<List<OutStockTask>> GetEntityList(List<int> ids);
/// <summary>
/// 列表-根据明细中的来源单号
/// </summary>
/// <param name="sourceBillNos"></param>
/// <returns></returns>
Task<List<OutStockTask>> GetListBySourceBillNo(List<string> sourceBillNos);
/// 修改实体集合
Task<bool> EditEntityList(List<OutStockTask> entitys, bool isTransaction = true);
//编辑

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using WMS.Web.Core.Dto.Erp.OutStock;
using WMS.Web.Core.Dto.OutStock;
using WMS.Web.Core.Dto.OutStockTask;
using WMS.Web.Domain.Entitys;
@@ -22,6 +23,8 @@ namespace WMS.Web.Domain.Mappers
CreateMap<OutStockTask, GetOutStockTaskByNoResponse>();
CreateMap<OutStockTaskDetails, GetOutStockTaskByNoDetailsResponse>();
CreateMap<ErpDeliveryNoticeOutStockResultDto, OutStockTaskDetails>();
}
}
}

View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WMS.Web.Core.Dto;
using WMS.Web.Core.Dto.Erp.OutStock;
using WMS.Web.Core.Dto.Erp.Purchase;
using WMS.Web.Core.Dto.Login;
using WMS.Web.Core.Internal.Results;
@@ -20,7 +21,7 @@ namespace WMS.Web.Domain.Services
/// <summary>
/// 出库任务
/// </summary>
public class OutStockTaskService: IOutStockTaskService
public class OutStockTaskService : IOutStockTaskService
{
private readonly IMapper _mapper;
private readonly IErpService _erpService;
@@ -85,20 +86,86 @@ namespace WMS.Web.Domain.Services
return Result.ReSuccess();
}
/// <summary>
/// erp数据转化wms 执行数据库操作
/// </summary>
/// <param name="erp_list"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
public async Task<Result> SsynDate(List<ErpDeliveryNoticeOutStockResultDto> erp_list, bool isTransaction)
{
//2.通过单据编号找到wms系统现有的任务单并修改
var erp_removeList = new List<ErpDeliveryNoticeOutStockResultDto>();
var SourceBillNo_list = erp_list.GroupBy(x => x.SourceBillNo).Select(x => x.Key).ToList();
var data_list = await _outStockTaskRepositories.GetListBySourceBillNo(SourceBillNo_list);
if (data_list.Count != 0)
{
//2.1提取出wms任务单明细信息
foreach (var e in erp_list)
{
//代表单据已经存在 那么就对单据进行修改
var data = data_list.FirstOrDefault(f => f.SourceBillNo == e.SourceBillNo);
var detail = data.Details.FirstOrDefault(w => w.MaterialId == e.MaterialId);
//存在就修改,没有就添加
if (detail != null)
detail.AccruedQty = e.AccruedQty;
else
data.Details.Add(_mapper.Map<OutStockTaskDetails>(e));
erp_removeList.Add(e);
}
//2.2.提交修改
var isSuccess = await _outStockTaskRepositories.EditEntityList(data_list, isTransaction);
if (!isSuccess)
return Result.ReFailure(ResultCodes.DateWriteError);
//2.3剔除:已修改的单据
foreach (var item in erp_removeList)
erp_list.Remove(item);
//3.wms任务单的来源单据编号不存在于erp中那么就新增
if (erp_list.Count != 0)
{
var add_entitys = new List<OutStockTask>();
var billNos = erp_list.GroupBy(x => x.SourceBillNo).Select(x => x.Key).ToList();
foreach (var item in billNos)
{
var e = erp_list.FirstOrDefault(f => f.SourceBillNo == item);
var dto = new OutStockTask();
dto.SourceBillNo = e.SourceBillNo;
dto.Create((OutStockType)e.Type, e.SourceBillNo, e.DeliveryOrgId, e.ReceiptCustomerId, (DateTime)e.CreateTime);
//找到当前对应来源单据编号的集合数据
var current_erp_details = erp_list.Where(x => x.SourceBillNo == item).ToList();
//给到dto的实体明细中
dto.Details = _mapper.Map<List<OutStockTaskDetails>>(current_erp_details);
add_entitys.Add(dto);
}
//3.1提交新增
isSuccess = await _outStockTaskRepositories.AddRange(add_entitys, isTransaction);
if (!isSuccess)
return Result.ReFailure(ResultCodes.DateWriteError);
}
}
return Result.ReSuccess();
}
/// <summary>
/// 发货通知单同步数据
/// </summary>
/// <param name="isTransaction"></param>
/// <returns></returns>
public async Task<Result> SsynDeliveryNoticeOutStock(bool isTransaction)
public async Task<Result> SsynDeliveryNoticeOutStock(bool isTransaction, List<string> sourceBillNos = null)
{
//1.获取金蝶数据:采购订单数据
var erp_result = await _erpService.BillQueryForPurchaseInStock();
var erp_result = await _erpService.BillQueryForDeliveryNoticeOutStock(sourceBillNos);
if (!erp_result.IsSuccess)
return Result.ReFailure(erp_result.Message, erp_result.Status);
var erp_list = erp_result.Data;
return Result.ReSuccess();
return await this.SsynDate(erp_result.Data.ToList(), isTransaction);
}
}
}

View File

@@ -424,6 +424,7 @@ namespace WMS.Web.Domain.Services.Public
lis.AccruedQty = Convert.ToDecimal(item[7]);
lis.Remark = item[8];
lis.CreateTime = Convert.ToDateTime(item[9]);
lis.Type = (int)OutStockType.Sal;
erp_list.Add(lis);
}
return ResultList<ErpDeliveryNoticeOutStockResultDto>.ReSuccess(erp_list);

View File

@@ -225,7 +225,7 @@ namespace WMS.Web.Repositories
if (!string.IsNullOrEmpty(dto.SourceBillNo))
query = query.Where(w => EF.Functions.Like(w.order.SourceBillNo, "%" + dto.SourceBillNo + "%"));
if (dto.Type != null)
query = query.Where(w => w.order.Type == (OrderType)dto.Type);
query = query.Where(w => w.order.Type == (OutStockType)dto.Type);
if (dto.Status != null)
query = query.Where(w => w.order.Status == (OutStockStatus)dto.Status);
if (dto.DeliveryOrgId != null)
@@ -273,5 +273,55 @@ namespace WMS.Web.Repositories
var mIds = entity.Details.Select(s => s.MaterialId).ToList();
return response;
}
/// <summary>
/// 根据来源单号搜索
/// </summary>
/// <param name="sourceBillNos"></param>
/// <returns></returns>
public async Task<List<OutStockTask>> GetListBySourceBillNo(List<string> sourceBillNos)
{
var entitys = await _context.OutStockTask
.Include(s => s.Details)
.Where(w => sourceBillNos.Contains(w.SourceBillNo))
.ToListAsync();
return entitys.Clone();
}
/// <summary>
/// 批量添加
/// </summary>
/// <param name="entitys"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
public async Task<bool> AddRange(List<OutStockTask> entitys, bool isTransaction = true)
{
IDbContextTransaction _transaction = null;
if (isTransaction)
_transaction = _context.Database.BeginTransaction();
try
{
if (entitys != null && entitys.Count != 0)
{
await _context.OutStockTask.AddRangeAsync(entitys);
await _context.SaveChangesAsync();
foreach (var item in entitys)
{
if (string.IsNullOrEmpty(item.BillNo))
//自动生成单据编号
item.GenerateNo();
}
await _context.SaveChangesAsync();
}
if (_transaction != null)
_transaction.Commit();
return true;
}
catch
{
if (_transaction != null)
_transaction.Rollback();
return false;
}
}
}
}