fix 组织架构同步代码删除
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using ConfigurationManager = System.Configuration.ConfigurationManager;
|
||||
using Kurisu.Core.ConfigurableOptions.Attributes;
|
||||
|
||||
|
||||
namespace Dlhis.ScheduledTask.Configurations
|
||||
{
|
||||
[Configuration]
|
||||
public class ServiceSettings
|
||||
{
|
||||
public string ServerUrl { get; private set; }
|
||||
@@ -46,24 +45,24 @@ namespace Dlhis.ScheduledTask.Configurations
|
||||
public string RestPassword { get; set; }
|
||||
public ServiceSettings()
|
||||
{
|
||||
ServerUrl = ConfigurationManager.AppSettings[nameof(ServerUrl)];
|
||||
UserName = ConfigurationManager.AppSettings[nameof(UserName)];
|
||||
Password = ConfigurationManager.AppSettings[nameof(Password)];
|
||||
SyncTime = ConfigurationManager.AppSettings[nameof(SyncTime)];
|
||||
DlhisDatabase = ConfigurationManager.AppSettings[nameof(DlhisDatabase)];
|
||||
AttendanceUploadUrl = ConfigurationManager.AppSettings[nameof(AttendanceUploadUrl)];
|
||||
AttendanceUploadInterval = SafeParseInt(ConfigurationManager.AppSettings[nameof(AttendanceUploadInterval)]);
|
||||
Werks = ConfigurationManager.AppSettings[nameof(Werks)];
|
||||
BeginSyncDate = SafeParseDate(ConfigurationManager.AppSettings[nameof(BeginSyncDate)], DateTime.Today);
|
||||
ApiPort = SafeParseInt(ConfigurationManager.AppSettings[nameof(ApiPort)], 8099);
|
||||
EHRWebServiceUserName = ConfigurationManager.AppSettings[nameof(EHRWebServiceUserName)];
|
||||
EHRWebServicePassword = ConfigurationManager.AppSettings[nameof(EHRWebServicePassword)];
|
||||
EHRInsertRecordApiUrl = ConfigurationManager.AppSettings[nameof(EHRInsertRecordApiUrl)];
|
||||
EHRDeleteRecordApiUrl = ConfigurationManager.AppSettings[nameof(EHRDeleteRecordApiUrl)];
|
||||
EHRSavePhotoApiUrl = ConfigurationManager.AppSettings[nameof(EHRSavePhotoApiUrl)];
|
||||
EHR_GET_WORK_CARD_INFOApiUrl = ConfigurationManager.AppSettings[nameof(EHR_GET_WORK_CARD_INFOApiUrl)];
|
||||
RestUserName = ConfigurationManager.AppSettings[nameof(RestUserName)];
|
||||
RestPassword = ConfigurationManager.AppSettings[nameof(RestPassword)];
|
||||
//ServerUrl = ConfigurationManager.AppSettings[nameof(ServerUrl)];
|
||||
//UserName = ConfigurationManager.AppSettings[nameof(UserName)];
|
||||
//Password = ConfigurationManager.AppSettings[nameof(Password)];
|
||||
//SyncTime = ConfigurationManager.AppSettings[nameof(SyncTime)];
|
||||
//DlhisDatabase = ConfigurationManager.AppSettings[nameof(DlhisDatabase)];
|
||||
//AttendanceUploadUrl = ConfigurationManager.AppSettings[nameof(AttendanceUploadUrl)];
|
||||
//AttendanceUploadInterval = SafeParseInt(ConfigurationManager.AppSettings[nameof(AttendanceUploadInterval)]);
|
||||
//Werks = ConfigurationManager.AppSettings[nameof(Werks)];
|
||||
//BeginSyncDate = SafeParseDate(ConfigurationManager.AppSettings[nameof(BeginSyncDate)], DateTime.Today);
|
||||
//ApiPort = SafeParseInt(ConfigurationManager.AppSettings[nameof(ApiPort)], 8099);
|
||||
//EHRWebServiceUserName = ConfigurationManager.AppSettings[nameof(EHRWebServiceUserName)];
|
||||
//EHRWebServicePassword = ConfigurationManager.AppSettings[nameof(EHRWebServicePassword)];
|
||||
//EHRInsertRecordApiUrl = ConfigurationManager.AppSettings[nameof(EHRInsertRecordApiUrl)];
|
||||
//EHRDeleteRecordApiUrl = ConfigurationManager.AppSettings[nameof(EHRDeleteRecordApiUrl)];
|
||||
//EHRSavePhotoApiUrl = ConfigurationManager.AppSettings[nameof(EHRSavePhotoApiUrl)];
|
||||
//EHR_GET_WORK_CARD_INFOApiUrl = ConfigurationManager.AppSettings[nameof(EHR_GET_WORK_CARD_INFOApiUrl)];
|
||||
//RestUserName = ConfigurationManager.AppSettings[nameof(RestUserName)];
|
||||
//RestPassword = ConfigurationManager.AppSettings[nameof(RestPassword)];
|
||||
}
|
||||
|
||||
private static int SafeParseInt(string value, int defaultValue = 0)
|
||||
@@ -74,6 +73,7 @@ namespace Dlhis.ScheduledTask.Configurations
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private static bool SafeParseBoolean(string value, bool defaultValue = false)
|
||||
{
|
||||
if (bool.TryParse(value, out var b))
|
||||
@@ -82,6 +82,7 @@ namespace Dlhis.ScheduledTask.Configurations
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private static DateTime SafeParseDate(string value, DateTime defaultValue)
|
||||
{
|
||||
if (DateTime.TryParse(value, out var b))
|
||||
@@ -90,13 +91,5 @@ namespace Dlhis.ScheduledTask.Configurations
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void SetBeginSyncDate(DateTime beginSyncDate)
|
||||
{
|
||||
BeginSyncDate = beginSyncDate;
|
||||
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
config.AppSettings.Settings[nameof(BeginSyncDate)].Value = beginSyncDate.ToString("yyyy-MM-dd");
|
||||
config.Save(ConfigurationSaveMode.Modified);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<Nullable>disable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<DockerfileContext>..\..</DockerfileContext>
|
||||
@@ -21,8 +21,6 @@
|
||||
<PackageReference Include="Hangfire.Dashboard.BasicAuthorization" Version="1.0.2" />
|
||||
<PackageReference Include="Hangfire.MySqlStorage" Version="2.0.3" />
|
||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.7" />
|
||||
<PackageReference Include="log4net" Version="2.0.15" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
using log4net;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
using Dlhis.ScheduledTask.Job;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Extensions
|
||||
{
|
||||
public static class DbConnectionExtensions
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(JinkoHrJob));
|
||||
|
||||
public static void BulkcopyInsert<T>(this IDbConnection conn, string tableName, List<T> data)
|
||||
{
|
||||
using (var bulkcopy = new SqlBulkCopy(conn as SqlConnection))
|
||||
{
|
||||
bulkcopy.BatchSize = 10000;
|
||||
bulkcopy.BulkCopyTimeout = 60;
|
||||
bulkcopy.DestinationTableName = tableName;
|
||||
var dt = ToDataTable(data);
|
||||
foreach (DataColumn column in dt.Columns)
|
||||
{
|
||||
bulkcopy.ColumnMappings.Add(new SqlBulkCopyColumnMapping(column.ColumnName, column.ColumnName));
|
||||
}
|
||||
|
||||
bulkcopy.WriteToServer(dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static DataTable ToDataTable<T>(List<T> data)
|
||||
{
|
||||
var dt = new DataTable();
|
||||
var properties = typeof(T).GetProperties();//.Where(x => x.IsDefined(typeof(CopyAttribute), false));
|
||||
|
||||
foreach (var property in properties)
|
||||
{
|
||||
dt.Columns.Add(property.Name, Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType);
|
||||
}
|
||||
|
||||
foreach (var item in data)
|
||||
{
|
||||
var values = new object[properties.Length];
|
||||
for (int i = 0; i < properties.Length; i++)
|
||||
{
|
||||
if (properties[i].PropertyType == typeof(DateTime?))
|
||||
{
|
||||
var o = (DateTime?)properties[i].GetValue(item);
|
||||
if (!o.HasValue || o.Value == DateTime.MinValue)
|
||||
{
|
||||
o = new DateTime(1900, 1, 1);
|
||||
}
|
||||
values[i] = o;
|
||||
}
|
||||
else
|
||||
{
|
||||
var o = properties[i].GetValue(item);
|
||||
values[i] = o;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dt.Rows.Add(values);
|
||||
}
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void BulkcopyUpdate<T>(this IDbConnection conn, string targetTableName, List<T> data)
|
||||
{
|
||||
var tmpTable = "#tmp_" + targetTableName;
|
||||
try
|
||||
{
|
||||
//go 语法错误 ???
|
||||
conn.Execute($@"
|
||||
if object_id('tempdb..{tmpTable}') is not null
|
||||
drop table {tmpTable}");
|
||||
|
||||
conn.Execute($@"
|
||||
select *
|
||||
into {tmpTable}
|
||||
from {targetTableName} where 1=2 ;");
|
||||
|
||||
conn.BulkcopyInsert(tmpTable, data);
|
||||
|
||||
var properties = typeof(T).GetProperties();
|
||||
var updates = properties.Where(x => !x.Name.Equals("ename"))
|
||||
.Where(x => !x.Name.Equals("id"))
|
||||
.Where(x => !x.Name.Equals("timeid"))
|
||||
.Select(x =>
|
||||
{
|
||||
return $"T.{x.Name}=S.{x.Name}";
|
||||
});
|
||||
|
||||
var updateScript = string.Join(",", updates);
|
||||
|
||||
var merge = $@"
|
||||
Merge into {targetTableName} AS T
|
||||
Using {tmpTable} AS S
|
||||
ON T.ename = S.ename
|
||||
WHEN MATCHED
|
||||
THEN UPDATE SET {updateScript} ;
|
||||
";
|
||||
|
||||
conn.Execute(merge);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error($"批量更新失败:{ex.Message}", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
conn.Execute($@"
|
||||
drop table {tmpTable}
|
||||
"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
namespace Dlhis.ScheduledTask.Extensions
|
||||
{
|
||||
public static class EnumerableExtensions
|
||||
{
|
||||
public static IEnumerable<IEnumerable<T>> Chunk<T>(this IEnumerable<T> arr, int size)
|
||||
{
|
||||
for (var i = 0; i < arr.Count() / size + 1; i++)
|
||||
{
|
||||
yield return arr.Skip(i * size).Take(size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,85 +3,30 @@ using Dlhis.ScheduledTask.Dto;
|
||||
using Dlhis.ScheduledTask.Entities;
|
||||
using Dlhis.ScheduledTask.Response;
|
||||
using Hangfire.Logging;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.DependencyModel;
|
||||
using Newtonsoft.Json;
|
||||
using Serilog;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using static Dapper.SqlMapper;
|
||||
using Dlhis.ScheduledTask.WsProxy;
|
||||
using log4net;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Job
|
||||
{
|
||||
public class JinkoHrJob
|
||||
{
|
||||
private IDisposable webApp;
|
||||
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(JinkoHrJob));
|
||||
const string ORG_CACHE_FILE = "org.json";
|
||||
const string POSITION_CACHE_FILE = "position.json";
|
||||
const string PERSON_CACHE_FILE = "person.json";
|
||||
|
||||
private List<PersonDetail> lastUpdatedPersonList = new List<PersonDetail>();
|
||||
private List<ZHRS_ORG> lastUpdatedOrgList = new List<ZHRS_ORG>();
|
||||
private List<ZHRS_POST> lastUpdatedPositionList = new List<ZHRS_POST>();
|
||||
private readonly ZHRF_SYN_01 orgClient;
|
||||
private readonly ZHRF_SYN_02 positionClient;
|
||||
private readonly ZHRF_SYN_03N archivesClient;
|
||||
private readonly ZHRF_SWIPE_DATA_SAVE_CLIENT dataSaveClient;
|
||||
private readonly SI_DLDM2EHR_InsertRecord_OutServiceClient insertRecord_OutService;
|
||||
private readonly SI_DLDM2EHR_DeleteRecord_OutServiceClient deleteRecord_OutService;
|
||||
|
||||
public ServiceSettings Settings { get; }
|
||||
private readonly ZHRS_WERKS[] werks;
|
||||
volatile bool started = false;
|
||||
public JinkoHrJob(ServiceSettings settings)
|
||||
{
|
||||
Settings = settings;
|
||||
var list = new List<ZHRS_WERKS>();
|
||||
if (!string.IsNullOrWhiteSpace(Settings.Werks))
|
||||
{
|
||||
var ss = Settings.Werks.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var w in ss)
|
||||
{
|
||||
list.Add(new ZHRS_WERKS() { WERKS = w });
|
||||
}
|
||||
werks = list.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
werks = Array.Empty<ZHRS_WERKS>();
|
||||
}
|
||||
orgClient = new ZHRF_SYN_01()
|
||||
{
|
||||
Url = Settings.ServerUrl + "/sap/bc/srt/rfc/sap/zhrf_syn_01/800/zhrf_syn_01/zhrf_syn_01",
|
||||
Credentials = new NetworkCredential(Settings.UserName, Settings.Password),
|
||||
Timeout = 10000000,
|
||||
};
|
||||
positionClient = new ZHRF_SYaN_02()
|
||||
{
|
||||
Url = Settings.ServerUrl + "/sap/bc/srt/rfc/sap/zhrf_syn_02/800/zhrf_syn_02/zhrf_syn_02",
|
||||
Credentials = new NetworkCredential(Settings.UserName, Settings.Password),
|
||||
Timeout = 10000000
|
||||
};
|
||||
private readonly ILogger<JinkoHrJob> _logger;
|
||||
private readonly ServiceSettings _serviceSettings;
|
||||
|
||||
archivesClient = new ZHRF_SYN_03N()
|
||||
public JinkoHrJob(ILogger<JinkoHrJob> logger, IOptions<ServiceSettings> options)
|
||||
{
|
||||
Url = Settings.ServerUrl + "/sap/bc/srt/rfc/sap/zhrf_syn_03n/800/zhrf_syn_03n/zhrf_syn_03n",
|
||||
Credentials = new NetworkCredential(Settings.UserName, Settings.Password),
|
||||
Timeout = 10000000
|
||||
};
|
||||
|
||||
dataSaveClient = new ZHRF_SWIPE_DATA_SAVE_CLIENT()
|
||||
{
|
||||
Credentials = new NetworkCredential(Settings.UserName, Settings.Password),
|
||||
Url = settings.AttendanceUploadUrl,
|
||||
Timeout = 10000000
|
||||
};
|
||||
_logger = logger;
|
||||
_serviceSettings = options.Value;
|
||||
}
|
||||
|
||||
private PersonResult GetPersons()
|
||||
@@ -124,7 +69,7 @@ namespace Dlhis.ScheduledTask.Job
|
||||
if (personResp?.T_PERSON?.item?.Any() == true)
|
||||
{
|
||||
persons.AddRange(personResp.T_PERSON.item);
|
||||
log.Info($"人事范围[{item.WERKS}]获取{personResp.T_PERSON.item.Count}条数据");
|
||||
//log.Info($"人事范围[{item.WERKS}]获取{personResp.T_PERSON.item.Count}条数据");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -142,7 +87,7 @@ namespace Dlhis.ScheduledTask.Job
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error($"人事范围[{item.WERKS}]获取失败:{ex.Message}", ex);
|
||||
// log.Error($"人事范围[{item.WERKS}]获取失败:{ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +141,7 @@ namespace Dlhis.ScheduledTask.Job
|
||||
if (originUpdates.Count + originInserts.Count <= count)
|
||||
{
|
||||
var currentTotal = originUpdates.Count + originInserts.Count;
|
||||
log.Debug($"正在进行第{index}批次,需要处理{currentTotal}条数据");
|
||||
//log.Debug($"正在进行第{index}批次,需要处理{currentTotal}条数据");
|
||||
|
||||
var updates = ToGainfoSap(originUpdates);
|
||||
var inserts = ToGainfoSap(originInserts);
|
||||
@@ -209,12 +154,12 @@ namespace Dlhis.ScheduledTask.Job
|
||||
conn.Execute(SqlGeneration.InsertSql, item);
|
||||
// 模拟触发器业务逻辑
|
||||
SimulateTriggerBusinessLogic(item);
|
||||
log.Debug($"执行新增{i}/{currentTotal} name:{item.gname},ename:{item.ename}");
|
||||
// log.Debug($"执行新增{i}/{currentTotal} name:{item.gname},ename:{item.ename}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
failure++;
|
||||
log.Error($"执行新增{i}/{currentTotal} name:{item.gname},ename:{item.ename}失败 \r\n{ex.Message}");
|
||||
//log.Error($"执行新增{i}/{currentTotal} name:{item.gname},ename:{item.ename}失败 \r\n{ex.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -230,12 +175,12 @@ namespace Dlhis.ScheduledTask.Job
|
||||
conn.Execute(SqlGeneration.UpdateSql, item);
|
||||
// 手动执行触发器的业务逻辑
|
||||
UpdateExecuteTriggerBusinessLogic(originUpdates);
|
||||
log.Debug($"执行更新{i}/{currentTotal} name:{item.gname},ename:{item.ename}");
|
||||
//log.Debug($"执行更新{i}/{currentTotal} name:{item.gname},ename:{item.ename}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
failure++;
|
||||
log.Error($"执行更新{i}/{currentTotal} name:{item.gname},ename:{item.ename}失败 \r\n{ex.Message}");
|
||||
//log.Error($"执行更新{i}/{currentTotal} name:{item.gname},ename:{item.ename}失败 \r\n{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,6 +306,7 @@ namespace Dlhis.ScheduledTask.Job
|
||||
}
|
||||
private void ExecuteUpdateLogic(GainfoSap updatedItem)
|
||||
{
|
||||
//todo 下发任务
|
||||
// 获取 accnt
|
||||
string accnt = GetAccnt();
|
||||
|
||||
@@ -454,23 +400,6 @@ namespace Dlhis.ScheduledTask.Job
|
||||
log.Error("同步人员信息失败", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private IDbConnection OpenDlDbConnection()
|
||||
{
|
||||
try
|
||||
{
|
||||
IDbConnection conn = new SqlConnection(Settings.DlhisDatabase);
|
||||
if (conn.State != ConnectionState.Open)
|
||||
{
|
||||
conn.Open();
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"打开迪联数据库错误:{ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
"ConnectionStrings": {
|
||||
"HangfireConnection": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=Hangfire;charset=utf8mb4;Allow User Variables=true;"
|
||||
},
|
||||
"ServiceSettings": {
|
||||
"ServerUrl": ""
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
|
||||
Reference in New Issue
Block a user