diff --git a/be/Hosts/Wms.Host/Win_in.Sfs.Wms.Store.HttpApi.Host/scripts/db.Microsoft.EntityFrameworkCore.SqlServer.StoreDbContext.sql b/be/Hosts/Wms.Host/Win_in.Sfs.Wms.Store.HttpApi.Host/scripts/db.Microsoft.EntityFrameworkCore.SqlServer.StoreDbContext.sql index 286935fff..6e6e46484 100644 --- a/be/Hosts/Wms.Host/Win_in.Sfs.Wms.Store.HttpApi.Host/scripts/db.Microsoft.EntityFrameworkCore.SqlServer.StoreDbContext.sql +++ b/be/Hosts/Wms.Host/Win_in.Sfs.Wms.Store.HttpApi.Host/scripts/db.Microsoft.EntityFrameworkCore.SqlServer.StoreDbContext.sql @@ -791,6 +791,7 @@ CREATE TABLE [Store_ExchangeData] ( [ErrorCode] nvarchar(64) NOT NULL, [ErrorMessage] nvarchar(3072) NULL, [RetryTimes] int NOT NULL, + [TyrpNumber] bigint NOT NULL, [ExtraProperties] nvarchar(max) NULL, [ConcurrencyStamp] nvarchar(40) NULL, [CreationTime] datetime2 NOT NULL, diff --git a/be/Modules/Shared/src/Win_in.Sfs.Shared.Host/ModuleBase.cs b/be/Modules/Shared/src/Win_in.Sfs.Shared.Host/ModuleBase.cs index a1e0b142d..a6cb8484c 100644 --- a/be/Modules/Shared/src/Win_in.Sfs.Shared.Host/ModuleBase.cs +++ b/be/Modules/Shared/src/Win_in.Sfs.Shared.Host/ModuleBase.cs @@ -145,76 +145,76 @@ public abstract class ModuleBase : AbpModule where T : AbpModule public virtual void CreateDatabase(ApplicationInitializationContext context) where TEfCoreDbContext : IEfCoreDbContext { - Console.WriteLine($"应用版本:{Assembly.GetEntryAssembly().GetFileVersion()}"); - //if (!context.GetEnvironment().IsDevelopment()) + //Console.WriteLine($"应用版本:{Assembly.GetEntryAssembly().GetFileVersion()}"); + ////if (!context.GetEnvironment().IsDevelopment()) + ////{ + //// Console.WriteLine($"生产模式不执行数据库初始化"); + //// return; + ////} + //using var scope = context.ServiceProvider.CreateScope(); + //var contextName = typeof(TEfCoreDbContext).Name; + ////var uowManager = scope.ServiceProvider.GetRequiredService(); + ////using var uow = uowManager.Begin(); + //var provider = scope.ServiceProvider.GetRequiredService>(); + ////using var dbContext = provider.GetDbContextAsync().Result; + //using var dbContext = scope.ServiceProvider.GetRequiredService(typeof(TEfCoreDbContext)) as DbContext; + //dbContext.Database.SetCommandTimeout(TimeSpan.FromMinutes(10)); + //var dbCreator = dbContext.GetService() as RelationalDatabaseCreator; + //var sql = dbCreator.GenerateCreateScript(); + //sql = dbContext.Database.ProviderName.Contains("SqlServer") ? Regex.Replace(sql, ";\\s+GO\\s", " ") : sql; + //var md5 = sql.Md5(); + //var path = Path.Combine(Directory.GetCurrentDirectory(), "scripts"); + //Directory.CreateDirectory(path); + //using var sw = File.CreateText(Path.Combine(path, $"db.{dbContext.Database.ProviderName}.{contextName}.sql")); + //sw.Write(sql); + //Console.WriteLine($"{contextName} 初始化开始"); + //Console.WriteLine($"ConnectionString:{dbContext.Database.GetConnectionString()}"); + ////创建数据库 + //if (!dbCreator.Exists()) //{ - // Console.WriteLine($"生产模式不执行数据库初始化"); - // return; + // dbCreator.Create(); + // var createSql = "CREATE TABLE EFDbContext(Id varchar(255) NOT NULL,Hash varchar(255) NOT NULL,PRIMARY KEY (Id));"; + // dbContext.Database.ExecuteSqlRaw(createSql); + //} + //// 查询当前DbContext是否已经初始化 + //using var conn = dbContext.Database.GetDbConnection(); + //var cmd = conn.CreateCommand(); + //conn.Open(); + //cmd.CommandText = $"SELECT Hash FROM EFDbContext where Id='{contextName}'"; + //var hash = cmd.ExecuteScalar(); + ////conn.Close(); + ////conn.Dispose(); + //if (hash == null) + //{ + // try + // { + // //dbContext.Database.BeginTransaction(); + // dbContext.Database.ExecuteSqlRaw(sql); + // dbContext.Database.ExecuteSqlRaw($"INSERT INTO EFDbContext VALUES ('{contextName}', '{md5}');"); + // context.ServiceProvider + // .GetRequiredService() + // .SeedAsync() + // .Wait(); + // //dbContext.Database.CommitTransaction(); + // Console.WriteLine($"{contextName} 初始化成功"); + // } + // catch (Exception ex) + // { + // //dbContext.Database.RollbackTransaction(); + // var message = $"{contextName} 初始化失败:{ex.Message}"; + // Console.WriteLine(message); + // Console.WriteLine(ex.ToString()); + // throw new Exception(message, ex); + // } + // finally + // { + // Console.WriteLine($"{contextName} 初始化结束"); + // } + //} + //else + //{ + // Console.WriteLine($"{contextName} 数据库结构{(hash.ToString() == md5 ? "正常" : "已过时")}"); //} - using var scope = context.ServiceProvider.CreateScope(); - var contextName = typeof(TEfCoreDbContext).Name; - //var uowManager = scope.ServiceProvider.GetRequiredService(); - //using var uow = uowManager.Begin(); - var provider = scope.ServiceProvider.GetRequiredService>(); - //using var dbContext = provider.GetDbContextAsync().Result; - using var dbContext = scope.ServiceProvider.GetRequiredService(typeof(TEfCoreDbContext)) as DbContext; - dbContext.Database.SetCommandTimeout(TimeSpan.FromMinutes(10)); - var dbCreator = dbContext.GetService() as RelationalDatabaseCreator; - var sql = dbCreator.GenerateCreateScript(); - sql = dbContext.Database.ProviderName.Contains("SqlServer") ? Regex.Replace(sql, ";\\s+GO\\s", " ") : sql; - var md5 = sql.Md5(); - var path = Path.Combine(Directory.GetCurrentDirectory(), "scripts"); - Directory.CreateDirectory(path); - using var sw = File.CreateText(Path.Combine(path, $"db.{dbContext.Database.ProviderName}.{contextName}.sql")); - sw.Write(sql); - Console.WriteLine($"{contextName} 初始化开始"); - Console.WriteLine($"ConnectionString:{dbContext.Database.GetConnectionString()}"); - //创建数据库 - if (!dbCreator.Exists()) - { - dbCreator.Create(); - var createSql = "CREATE TABLE EFDbContext(Id varchar(255) NOT NULL,Hash varchar(255) NOT NULL,PRIMARY KEY (Id));"; - dbContext.Database.ExecuteSqlRaw(createSql); - } - // 查询当前DbContext是否已经初始化 - using var conn = dbContext.Database.GetDbConnection(); - var cmd = conn.CreateCommand(); - conn.Open(); - cmd.CommandText = $"SELECT Hash FROM EFDbContext where Id='{contextName}'"; - var hash = cmd.ExecuteScalar(); - //conn.Close(); - //conn.Dispose(); - if (hash == null) - { - try - { - //dbContext.Database.BeginTransaction(); - dbContext.Database.ExecuteSqlRaw(sql); - dbContext.Database.ExecuteSqlRaw($"INSERT INTO EFDbContext VALUES ('{contextName}', '{md5}');"); - context.ServiceProvider - .GetRequiredService() - .SeedAsync() - .Wait(); - //dbContext.Database.CommitTransaction(); - Console.WriteLine($"{contextName} 初始化成功"); - } - catch (Exception ex) - { - //dbContext.Database.RollbackTransaction(); - var message = $"{contextName} 初始化失败:{ex.Message}"; - Console.WriteLine(message); - Console.WriteLine(ex.ToString()); - throw new Exception(message, ex); - } - finally - { - Console.WriteLine($"{contextName} 初始化结束"); - } - } - else - { - Console.WriteLine($"{contextName} 数据库结构{(hash.ToString() == md5 ? "正常" : "已过时")}"); - } //uow.CompleteAsync(); //conn.Close(); //conn.Dispose(); diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/DTOs/ExchangeDataDTO.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/DTOs/ExchangeDataDTO.cs index edf5121f8..5308dd237 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/DTOs/ExchangeDataDTO.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/DTOs/ExchangeDataDTO.cs @@ -52,4 +52,7 @@ public class ExchangeDataDTO : SfsBasicDTOBase //, IHasCode,IHasName /// [Display(Name = "来源系统")] public string SourceSystem { get; set; } + + [Display(Name = "Tyrp系统编号")] + public string TyrpNumber { get; set; } } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/IExchangeDataAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/IExchangeDataAppService.cs index ac5140f00..dd22afc56 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/IExchangeDataAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/IExchangeDataAppService.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Threading.Tasks; using Win_in.Sfs.Wms.Store.Application.Contracts; @@ -9,4 +10,5 @@ public interface IExchangeDataAppService { // Task ImportMergeAsync(IFormFile formFile, EnumFileType fileType = EnumFileType.Excel, EnumImportMethod method = EnumImportMethod.Update, bool isAllowPartImport = false); Task> GetToBeProcessedListAsync(int batchSize); + Task ReSendByNumberAsync(Guid id); } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/Inputs/ExchangeDataEditInput.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/Inputs/ExchangeDataEditInput.cs index 3eb93e96b..95beaaa33 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/Inputs/ExchangeDataEditInput.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/Inputs/ExchangeDataEditInput.cs @@ -45,5 +45,8 @@ public class ExchangeDataEditInput : SfsStoreCreateOrUpdateInputBase [Required(ErrorMessage = "{0}是必填项")] [StringLength(SfsEfCorePropertyConst.NameLength, ErrorMessage = "{0}最多输入{1}个字符")] public string Code { get; set; } + + [Display(Name = "Tyrp系统编号")] + public string TyrpNumber { get; set; } #endregion } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/Inputs/ExchangeDataImportInput.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/Inputs/ExchangeDataImportInput.cs index d61a1a4f1..35e74181e 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/Inputs/ExchangeDataImportInput.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/ExchangeDatas/Inputs/ExchangeDataImportInput.cs @@ -60,4 +60,6 @@ public class ExchangeDataImportInput : SfsStoreImportInputBase [StringLength(SfsEfCorePropertyConst.RemarkLength, ErrorMessage = "{0}最多输入{1}个字符")] public string Remark { get; set; } + [Display(Name = "Tyrp系统编号")] + public string TyrpNumber { get; set; } } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/ExchangeDatas/ExchangeDataAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/ExchangeDatas/ExchangeDataAppService.cs index b24ccfdbb..dd2845396 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/ExchangeDatas/ExchangeDataAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/ExchangeDatas/ExchangeDataAppService.cs @@ -1,7 +1,10 @@ +using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Volo.Abp; +using Volo.Abp.ObjectMapping; using Win_in.Sfs.Store.Application.Contracts; using Win_in.Sfs.Wms.Store.Application.Contracts; using Win_in.Sfs.Wms.Store.Domain; @@ -12,7 +15,8 @@ namespace Win_in.Sfs.Wms.Store.Application; [Authorize] [Route($"{StoreConsts.RootPath}exchange-data")] public class ExchangeDataAppService - : SfsStoreAppServiceBase + : SfsStoreAppServiceBase , IExchangeDataAppService { @@ -20,7 +24,7 @@ public class ExchangeDataAppService public ExchangeDataAppService( IExchangeDataRepository repository, IExchangeDataManager manager - ) : base(repository) + ) : base(repository) { base.CreatePolicyName = ExchangeDataPermissions.Create; base.UpdatePolicyName = ExchangeDataPermissions.Update; @@ -35,6 +39,37 @@ public class ExchangeDataAppService var entities = await _manager.GetToBeProcessedListAsync(batchSize).ConfigureAwait(false); var dtos = ObjectMapper.Map, List>(entities); return dtos; + } + + [HttpPost("re-send-by-id/{id}")] + public virtual async Task ReSendByNumberAsync(Guid id) + { + var exchangeDataOld = await _repository.GetAsync(id).ConfigureAwait(false); + if (exchangeDataOld == null) + { + throw new UserFriendlyException($"未找到ID为【{id.ToString()}】的数据"); + } + + exchangeDataOld.Status = EnumExchangeDataStatus.Error; + + var exchangeDataNew = new ExchangeData() + { + DataAction = exchangeDataOld.DataAction, + DataContent = exchangeDataOld.DataContent, + DataIdentityCode = exchangeDataOld.DataIdentityCode, + DataType = exchangeDataOld.DataType, + DestinationSystem = exchangeDataOld.DestinationSystem, + EffectiveDate = exchangeDataOld.EffectiveDate, + Remark = exchangeDataOld.Remark, + SourceSystem = exchangeDataOld.SourceSystem, + WriteTime = DateTime.Now, + Writer = null, + }; + var entityNew= await _repository.InsertAsync(exchangeDataNew).ConfigureAwait(false); + + exchangeDataOld.Remark = $"在【{DateTime.Now}】时,重新生成了新的接口数据:ID为【{entityNew.Id}】"; + await _repository.UpdateAsync(exchangeDataOld).ConfigureAwait(false); + return new ExchangeDataDTO() { Id = entityNew.Id }; } } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Domain/ExchangeDatas/ExchangeData.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Domain/ExchangeDatas/ExchangeData.cs index fb09033c9..cd0d145ac 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Domain/ExchangeDatas/ExchangeData.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Domain/ExchangeDatas/ExchangeData.cs @@ -1,5 +1,7 @@ using System; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using DocumentFormat.OpenXml.Wordprocessing; using Win_in.Sfs.Shared.Domain; namespace Win_in.Sfs.Wms.Store.Domain; @@ -29,7 +31,7 @@ public class ExchangeData : SfsAggregateRootBase /// /// 数据状态 /// - public EnumExchangeDataStatus Status { get; protected internal set; } = EnumExchangeDataStatus.Unread; + public EnumExchangeDataStatus Status { get;set; } = EnumExchangeDataStatus.Unread; /// /// 数据识别码 @@ -71,16 +73,19 @@ public class ExchangeData : SfsAggregateRootBase /// /// 错误代码 /// - public EnumExchangeDataErrorCode ErrorCode { get; protected internal set; } + public EnumExchangeDataErrorCode ErrorCode { get; set; } /// /// 错误信息 /// - public string ErrorMessage { get; protected internal set; } + public string ErrorMessage { get;set; } /// /// 重试次数 /// - public int RetryTimes { get; protected internal set; } + public int RetryTimes { get;set; } + + [Display(Name = "Tyrp系统编号")] + public string TyrpNumber { get; set; } /* public void SetEffectiveDate(DateTime newDate) diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/ExchangeData/ExchangeDataDbContextModelCreatingExtensions.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/ExchangeData/ExchangeDataDbContextModelCreatingExtensions.cs index a531ef33e..1321c944e 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/ExchangeData/ExchangeDataDbContextModelCreatingExtensions.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/ExchangeData/ExchangeDataDbContextModelCreatingExtensions.cs @@ -30,7 +30,7 @@ public static class ExchangeDataDbContextModelCreatingExtensions b.Property(p => p.ReadTime); b.Property(p => p.ErrorCode).IsRequired().HasMaxLength(SfsPropertyConst.NameLength).HasConversion(); b.Property(p => p.ErrorMessage).HasMaxLength(SfsPropertyConst.RemarkLength); - + b.Property(p => p.TyrpNumber).IsRequired().HasDefaultValueSql(); //Relations //Indexes