2025-07-12 16:58:00 +08:00

94 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using MyCode.Project.Domain.Message.Request.JackYun;
using MyCode.Project.Domain.Model;
using MyCode.Project.Domain.Repositories;
using MyCode.Project.Domain.Repositories.ZHMDRepositories;
using MyCode.Project.Domain.ZHMDModel;
using MyCode.Project.Infrastructure.Common;
using MyCode.Project.Infrastructure.Enumeration;
using MyCode.Project.Infrastructure.Exceptions;
using MyCode.Project.Infrastructure.JackYun;
using MyCode.Project.Repositories;
using MyCode.Project.Repositories.Common;
using MyCode.Project.Repositories.ZHMD;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace MyCode.Project.Services.Implementation
{
public class WMSService : ServiceBase , IWMSService
{
DateTime startTime = DateTime.Parse("2025-06-01");
private IWMStoJackyunInventoryMovementView1Repository _wMStoJackyunInventoryMovementView3Repository;
private IRepository _repository;
public WMSService(IWMStoJackyunInventoryMovementView1Repository wMStoJackyunInventoryMovementView3Repository, IRepository repository )
{
_wMStoJackyunInventoryMovementView3Repository = wMStoJackyunInventoryMovementView3Repository;
_repository = repository;
}
public List<WMStoJackyunInventoryMovementView1> GetList(DateTime now)
{
if (now < startTime)
now = startTime;
var list= _wMStoJackyunInventoryMovementView3Repository.GetList(now);
SetWMSOrder(list);
return list;
}
#region SetWMSOrder(WMS订单存进本地数据库)
/// <summary>
/// 把WMS订单存进本地数据库
/// </summary>
/// <param name="trades"></param>
[TransactionCallHandler]
public void SetWMSOrder(List<WMStoJackyunInventoryMovementView1> trades)
{
var ids = trades.Select(t => t.).ToList();
var oldids = _repository.Queryable<WMStoJackyunInventoryMovementView1>().Where(t => ids.Contains(t.))
.Select(t => new { t., t. }).ToList();
if (oldids.Count > 0)
{
//trades = (from p in trades
// join k in oldids on new { p.WMS单号, p.单据行号 } equals new { k.WMS单号, k.单据行号 }
// where k.单据行号 == null
// select p).ToList();
// 方法1使用左外连接推荐 - 高效且符合SQL思维
trades = (
from p in trades
join k in oldids
on new { p., p. }
equals new { k., k. }
into temp
from k in temp.DefaultIfEmpty()
where k == null // 只保留未匹配的记录
select p
).ToList();
//// 方法2使用Any()进行条件过滤(更简洁)
//var excludedTrades = trades
// .Where(p => !oldids.Any(k =>
// k.WMS单号 == p.WMS单号 &&
// k.单据行号 == p.单据行号))
// .ToList();
//trades = trades.Where(t => !oldids.Contains(new { t.WMS单号, t.单据行号 })).ToList();
}
_repository.Add<WMStoJackyunInventoryMovementView1>(trades);
}
#endregion
}
}