diff --git a/src/Shentun.ColumnReferencePlugIns/SyncAsbitemPrice/SyncAsbitemPricePlugInsBase.cs b/src/Shentun.ColumnReferencePlugIns/SyncAsbitemPrice/SyncAsbitemPricePlugInsBase.cs index ca8500c2..3611c605 100644 --- a/src/Shentun.ColumnReferencePlugIns/SyncAsbitemPrice/SyncAsbitemPricePlugInsBase.cs +++ b/src/Shentun.ColumnReferencePlugIns/SyncAsbitemPrice/SyncAsbitemPricePlugInsBase.cs @@ -30,7 +30,7 @@ namespace Shentun.Peis.PlugIns.SyncAsbitemPrice using (DbConnection conn = new NpgsqlConnection(AppConnctionStr)) { string sql; - sql = @" select * from asbitem + sql = @" select * from asbitem where is_active = 'Y' "; var asbitems = (await conn.QueryAsync(sql )).ToList(); diff --git a/src/Shentun.ColumnReferencePlugIns/SyncAsbitemPrice/SyncAsbitemPricePlugInsDbBase.cs b/src/Shentun.ColumnReferencePlugIns/SyncAsbitemPrice/SyncAsbitemPricePlugInsDbBase.cs index 8f6f848a..3141efe0 100644 --- a/src/Shentun.ColumnReferencePlugIns/SyncAsbitemPrice/SyncAsbitemPricePlugInsDbBase.cs +++ b/src/Shentun.ColumnReferencePlugIns/SyncAsbitemPrice/SyncAsbitemPricePlugInsDbBase.cs @@ -30,9 +30,13 @@ namespace Shentun.Peis.PlugIns.SyncAsbitemPrice { foreach (var asbItem in asbitems) { - var interfaceAsbitemId = await GetColumnReferenceInterfaceCodeValuesAsync(AsbitemColumnReferenceId, asbItem.Id.ToString()); + var columnReferenceInterfaceCodeValues = await GetColumnReferenceInterfaceCodeValuesAsync(AsbitemColumnReferenceId, asbItem.Id.ToString()); + if(columnReferenceInterfaceCodeValues == null || !columnReferenceInterfaceCodeValues.Any()) + { + continue; + } string sql; - sql = InterfaceSql + " where " + InterfaceSqlKeyColumn + " = '" + interfaceAsbitemId + "'"; + sql = InterfaceSql + " where " + InterfaceSqlKeyColumn + " = '" + columnReferenceInterfaceCodeValues[0].InterfaceCodeValue + "'"; var interfaceAsbitems = (await conn.QueryAsync(sql)).ToList(); if (interfaceAsbitems == null || !interfaceAsbitems.Any()) { @@ -51,6 +55,18 @@ namespace Shentun.Peis.PlugIns.SyncAsbitemPrice } + public async Task> GetInterfaceAsbitems() + { + using (DbConnection conn = CreateInterfaceDbConnect()) + { + string sql; + sql = InterfaceSql; + var interfaceAsbitems = (await conn.QueryAsync(sql)).ToList(); + return interfaceAsbitems; + } + } + + } } diff --git a/src/Shentun.Peis.Domain.Shared/Enums/ThirdInterfaceTypeFlag.cs b/src/Shentun.Peis.Domain.Shared/Enums/ThirdInterfaceTypeFlag.cs index c4c8b7cd..2b0feedd 100644 --- a/src/Shentun.Peis.Domain.Shared/Enums/ThirdInterfaceTypeFlag.cs +++ b/src/Shentun.Peis.Domain.Shared/Enums/ThirdInterfaceTypeFlag.cs @@ -32,5 +32,8 @@ namespace Shentun.Peis.Enums [Description("心电图")] public const string Electrocardiogram = "08"; + + [Description("同步组合项目价格")] + public const string SyncAsbitemPrice = "09"; } } diff --git a/src/Shentun.Peis.HttpApi.Host/PeisHttpApiHostModule.cs b/src/Shentun.Peis.HttpApi.Host/PeisHttpApiHostModule.cs index 3f0a1d77..4391bdf7 100644 --- a/src/Shentun.Peis.HttpApi.Host/PeisHttpApiHostModule.cs +++ b/src/Shentun.Peis.HttpApi.Host/PeisHttpApiHostModule.cs @@ -662,6 +662,11 @@ public class PeisHttpApiHostModule : AbpModule //心电图 RecurringJob.AddOrUpdate(thirdInterfaceDto.DisplayName, o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local); } + else if (thirdInterfaceDto.ThirdInterfaceType == "09") + { + //同步组合项目价格 + RecurringJob.AddOrUpdate(thirdInterfaceDto.DisplayName, o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local); + } } } diff --git a/src/Shentun.Peis.HttpApi.Host/Schedulers/SyncAsbitemPriceInterfaceWorker.cs b/src/Shentun.Peis.HttpApi.Host/Schedulers/SyncAsbitemPriceInterfaceWorker.cs new file mode 100644 index 00000000..ebd00bee --- /dev/null +++ b/src/Shentun.Peis.HttpApi.Host/Schedulers/SyncAsbitemPriceInterfaceWorker.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Shentun.Peis.ThirdInterfaces; +using Shentun.Utilities; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace Shentun.Peis.Schedulers +{ + + public interface ISyncAsbitemPriceInterfaceWorker + { + public void DoWork(Guid interfaceId); + public void DoWork(); + } + public class SyncAsbitemPriceInterfaceWorker : ThirdInterfaceWorkerBase, ISyncAsbitemPriceInterfaceWorker + { + private static long i; + private static bool _isRunning = false; + private static readonly object lockObject = new object(); + private readonly IConfiguration _configuration; + public SyncAsbitemPriceInterfaceWorker(IConfiguration configuration) + { + _configuration = configuration; + } + public virtual void DoWork(Guid interfaceId) + { + if (_isRunning) return; + //lock (lockObject) + //{ + _isRunning = true; + try + { + var backJobTypeIds = _configuration.GetSection("BackJobTypeId").Value; + + //Logger.LogInformation("Executed" + GetType().Name + "..!"); + var appServiceHelper = new AppServiceHelper(); + //appServiceHelper.Login(); + var thirdInterfaceDtos = appServiceHelper.CallAppService>("api/app/ThirdInterface/GetList", null); + var thirdInterfaceDto = thirdInterfaceDtos.Where(o => o.Id == interfaceId).FirstOrDefault(); + if (thirdInterfaceDto == null) + { + _isRunning = false; + return; + } + + if (!backJobTypeIds.Contains(thirdInterfaceDto.ThirdInterfaceType)) + { + _isRunning = false; + return; + } + + if (thirdInterfaceDto.IsActive != 'Y') + { + _isRunning = false; + return; + } + var parmValue = thirdInterfaceDto.ParmValue; + if (!string.IsNullOrWhiteSpace(parmValue)) + { + var configurationBuilder = new ConfigurationBuilder() + .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue))); + var interfaceConfig = configurationBuilder.Build(); + + var isActive = interfaceConfig.GetSection("Interface").GetSection("Scheduler") + .GetSection("IsActive").Value; + if (isActive != "Y") + { + _isRunning = false; + return; + } + var assemblyName = interfaceConfig.GetSection("Interface").GetSection("AssemblyName").Value; + var className = interfaceConfig.GetSection("Interface").GetSection("ClassName").Value; + var funName = "DoWork"; + object[] classConstructorArg = new object[] { thirdInterfaceDto.Id }; + ReflectionHelper.Invoke(assemblyName, className, classConstructorArg, funName); + } + + + } + catch (Exception ex) + { + _isRunning = false; + Logger.LogError("Executed " + GetType().Name + " Error" + ex.Message); + } + _isRunning = false; + return; + //} + } + + + public void DoWork() + { + throw new NotImplementedException(); + } + } +} diff --git a/test/Shentun.Peis.ColumnReference.Tests/SyncAsbitemPricePlugInsTest.cs b/test/Shentun.Peis.ColumnReference.Tests/SyncAsbitemPricePlugInsTest.cs new file mode 100644 index 00000000..87001ecd --- /dev/null +++ b/test/Shentun.Peis.ColumnReference.Tests/SyncAsbitemPricePlugInsTest.cs @@ -0,0 +1,48 @@ +using Shentun.Peis.PlugIns.ImportLisResults; +using Shentun.Peis.PlugIns.SyncAsbitemPrice; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit.Abstractions; + +namespace Shentun.Peis.PlugIns.Tests +{ + public class SyncAsbitemPricePlugInsTest + { + private readonly ITestOutputHelper _output; + public SyncAsbitemPricePlugInsTest(ITestOutputHelper testOutputHelper) + { + _output = testOutputHelper; + + } + + [Fact] + public async Task DoWorkAsync() + { + + var input = new SyncAsbitemPricePlugInsDbBase(new Guid("8742ccb6-ab93-4e4d-aad9-873b69fafd8c")); + await input.DoWork(); + + + + } + + + [Fact] + public async Task GetInterfaceAsbitems() + { + + var input = new SyncAsbitemPricePlugInsDbBase(new Guid("8742ccb6-ab93-4e4d-aad9-873b69fafd8c")); + var list = await input.GetInterfaceAsbitems(); + foreach (var item in list) + { + _output.WriteLine(item.AsbitemId + "," + item.AsbitemName + "," + item.Price.ToString()); + } + + + + } + } +}