增加同步时间
This commit is contained in:
@@ -56,6 +56,13 @@ namespace WMS.Web.Repositories.Configuration
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
//序列号操作记录
|
||||
builder.Entity<ErpOpsSyncDate>(ent =>
|
||||
{
|
||||
ent.ToTable("t_wms_sync_date");
|
||||
});
|
||||
|
||||
|
||||
#region 出库单
|
||||
builder.Entity<OutStock>(ent =>
|
||||
{
|
||||
@@ -230,6 +237,7 @@ namespace WMS.Web.Repositories.Configuration
|
||||
base.OnModelCreating(builder);
|
||||
}
|
||||
|
||||
public DbSet<ErpOpsSyncDate> ErpOpsSyncDate { get; set; }
|
||||
public DbSet<SerialNumberOperate> SerialNumberOperate { get; set; }
|
||||
public DbSet<ChangeBoxRecord> ChangeBoxRecord { get; set; }
|
||||
public DbSet<MoveBoxRecord> MoveBoxRecord { get; set; }
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
services.AddTransient<IOutStockRepositories, OutStockRepositories>();
|
||||
services.AddTransient<IOutStockTaskRepositories, OutStockTaskRepositories>();
|
||||
services.AddTransient<ITakeStockRepositories, TakeStockRepositories>();
|
||||
services.AddTransient<IErpOpsSyncDateRepositories, ErpOpsSyncDateRepositories>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
75
src/WMS.Web.Repositories/ErpOpsSyncDateRepositories.cs
Normal file
75
src/WMS.Web.Repositories/ErpOpsSyncDateRepositories.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
using WMS.Web.Domain.Values;
|
||||
using WMS.Web.Repositories.Configuration;
|
||||
|
||||
namespace WMS.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 定时任务最新一次时间管理
|
||||
/// </summary>
|
||||
public class ErpOpsSyncDateRepositories : IErpOpsSyncDateRepositories
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly RepositoryDbContext _context;
|
||||
|
||||
public ErpOpsSyncDateRepositories(RepositoryDbContext context, IMapper mapper, IServiceProvider serviceProvider)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
/// <summary>
|
||||
/// 定时任务执行后更新时间
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> Edit(ErpOpsSyncType type, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var res = await _context.ErpOpsSyncDate
|
||||
.FirstOrDefaultAsync(f => f.Type == type);
|
||||
if (res == null) return false;
|
||||
|
||||
res.SyncTime = DateTime.Now;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取最新一次更新时间
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<DateTime> Get(ErpOpsSyncType type)
|
||||
{
|
||||
var res = await _context.ErpOpsSyncDate
|
||||
.FirstOrDefaultAsync(f => f.Type == type);
|
||||
return res == null ? DateTime.Now : res.SyncTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user