From 9bde10b0c0654c48fb0447994457aa52a1225d32 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Fri, 24 Jan 2025 16:08:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=9B=E5=B0=BE=E5=9F=B9=E8=AE=AD=E9=9C=80?= =?UTF-8?q?=E6=B1=82=E8=80=81=E7=89=88=E6=9C=AC=E5=90=8C=E6=AD=A5=EF=BC=8C?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DB/Dapper/Extensions/GenericExtension.cs | 47 +++++++++++++ .../Ghre/IGhre_RequestServices.cs | 2 + .../View/Ghre/Ghre_Request.Dto.View.cs | 8 ++- .../Ghre/Ghre_RequestServices.cs | 69 ++++++++++++++++++- .../Ghre/Ghre_StudyRecordServices.cs | 2 +- .../Job_Ushio_TrainRequest_Sync_Quartz.cs | 8 +-- 6 files changed, 128 insertions(+), 8 deletions(-) diff --git a/Tiobon.Core.Common/DB/Dapper/Extensions/GenericExtension.cs b/Tiobon.Core.Common/DB/Dapper/Extensions/GenericExtension.cs index b1c091fd..91d71865 100644 --- a/Tiobon.Core.Common/DB/Dapper/Extensions/GenericExtension.cs +++ b/Tiobon.Core.Common/DB/Dapper/Extensions/GenericExtension.cs @@ -54,5 +54,52 @@ public static class GenericExtension } return dtReturn; } + public static List ToList(this DataTable dt) where T : class, new() + { + Type t = typeof(T); + PropertyInfo[] propertys = t.GetProperties(); + List lst = new List(); + string typeName = string.Empty; + foreach (DataRow dr in dt.Rows) + { + T entity = new T(); + foreach (PropertyInfo pi in propertys) + { + typeName = pi.Name; + if (dt.Columns.Contains(typeName)) + { + if (!pi.CanWrite) continue; + object value = dr[typeName]; + if (value == DBNull.Value) continue; + if (pi.PropertyType == typeof(string)) + { + pi.SetValue(entity, value.ToString(), null); + } + else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(int?)) + { + pi.SetValue(entity, int.Parse(value.ToString()), null); + } + else if (pi.PropertyType == typeof(DateTime?) || pi.PropertyType == typeof(DateTime)) + { + pi.SetValue(entity, DateTime.Parse(value.ToString()), null); + } + else if (pi.PropertyType == typeof(float)) + { + pi.SetValue(entity, float.Parse(value.ToString()), null); + } + else if (pi.PropertyType == typeof(double)) + { + pi.SetValue(entity, double.Parse(value.ToString()), null); + } + else + { + pi.SetValue(entity, value, null); + } + } + } + lst.Add(entity); + } + return lst; + } } diff --git a/Tiobon.Core.IServices/Ghre/IGhre_RequestServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_RequestServices.cs index b5c29e5a..97d479cc 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_RequestServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_RequestServices.cs @@ -15,4 +15,6 @@ public interface IGhre_RequestServices : IBaseServices> InsertByStatus(InsertGhre_RequestInput insertModel, string status); Task> QueryGroup(QueryBody filter, string type); + + Task Ushio_Sync(); } \ No newline at end of file diff --git a/Tiobon.Core.Model/View/Ghre/Ghre_Request.Dto.View.cs b/Tiobon.Core.Model/View/Ghre/Ghre_Request.Dto.View.cs index 20338468..e6b05094 100644 --- a/Tiobon.Core.Model/View/Ghre/Ghre_Request.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghre/Ghre_Request.Dto.View.cs @@ -50,12 +50,16 @@ public class Ghre_RequestDto : Ghre_Request public string TrainStaffNames { get; set; } public string AgreeUserName { get; set; } - + public string RefuseUserName { get; set; } - + public string WorkStateLabel { get; set; } public string YearMonthLabel { get; set; } public string MonthLabel { get; set; } + public string DeptNo { get; set; } + public string TrainStaffId1 { get; set; } + public string SponsorNo { get; set; } + } diff --git a/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs b/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs index a8d4e4f2..0c498750 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs @@ -1,4 +1,6 @@ -using static Tiobon.Core.Model.Consts; +using Mapster; +using Serilog; +using static Tiobon.Core.Model.Consts; namespace Tiobon.Core.Services; @@ -315,4 +317,69 @@ FROM Ghre_Request A } + + #region 牛尾培训需求同步 + public async Task Ushio_Sync() + { + Log.Information($"【牛尾培训需求同步】开始同步"); + try + { + + + string sql = @"SELECT *, TrainStaffId TrainStaffId1 + FROM [120.26.205.42].[GhrUshio].[dbo].Ghrz_Ushio_TrainRequestApply_GHR50_V + WHERE RequestNo NOT IN (SELECT RequestNo FROM Ghre_Request)"; + + var dt = await Db.Ado.GetDataTableAsync(sql); + + var list = Db.Utilities.DataTableToList(dt); + + Log.Information($"【牛尾培训需求同步】查询到待同步{list.Count}条数据"); + for (int i = 0; i < list.Count; i++) + { + Log.Information($"【牛尾培训需求同步】同步队列{i + 1}/{list.Count}"); + + var insert = Mapper.Map(list[i]).ToANew(); + + if (await base.AnyAsync(x => x.RequestNo == insert.RequestNo)) + continue; + if (list[i].DeptNo.IsNotEmptyOrNull()) + insert.DeptId = (await Db.Queryable().Where(x => x.DeptNo == list[i].DeptNo).FirstAsync())?.DeptID; + + if (list[i].SponsorNo.IsNotEmptyOrNull()) + insert.SponsorId = (await Db.Queryable().Where(x => x.StaffNo == list[i].SponsorNo).FirstAsync())?.StaffID; + if (list[i].TrainStaffId1.IsNotEmptyOrNull()) + { + var staffNos = list[i].TrainStaffId1.Split(',').ToList(); + + if (staffNos.Any()) + { + var staffIds = await Db.Queryable().Where(x => staffNos.Contains(x.StaffNo)).Select(x => x.StaffID).ToListAsync(); + insert.TrainStaffId = JsonHelper.ObjToJson(staffIds); + } + } + + insert.WorkNo = insert.RequestNo; + + if (insert.CourseId == 0) insert.CourseId = null; + + #region 根据参数 处理数据默认状态 + var config = await Db.Queryable().FirstAsync(x => x.ConfigCode == "ESS_Request_Apply_Status"); + if (config != null) + insert.Status = config.ConfigValue; + + #endregion + + await base.Add(insert); + } + } + catch (Exception E) + { + Log.Information($"【牛尾培训需求同步】发生错误:{E.Message}"); + Log.Information($"【牛尾培训需求同步】发生错误行:{E.StackTrace}"); + } + Log.Information($"【牛尾培训需求同步】结束同步"); + } + #endregion + } \ No newline at end of file diff --git a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs index 9e20df45..8e10cacc 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs @@ -1393,7 +1393,7 @@ WHERE A.Id = '{id}'"; var wareAttachmentCount = await Db.Queryable().Where(x => courseWareIds.Contains(x.CourseWareId)).CountAsync(); - if (wareAttachmentCount != detailWareAttachmentCount) + if (wareAttachmentCount > detailWareAttachmentCount) studyProgress = 99; } diff --git a/Tiobon.Core.Tasks/QuartzNet/Jobs/Job_Ushio_TrainRequest_Sync_Quartz.cs b/Tiobon.Core.Tasks/QuartzNet/Jobs/Job_Ushio_TrainRequest_Sync_Quartz.cs index ceef3904..e26ee902 100644 --- a/Tiobon.Core.Tasks/QuartzNet/Jobs/Job_Ushio_TrainRequest_Sync_Quartz.cs +++ b/Tiobon.Core.Tasks/QuartzNet/Jobs/Job_Ushio_TrainRequest_Sync_Quartz.cs @@ -8,12 +8,12 @@ namespace Tiobon.Core.Tasks; /// public class Job_Ushio_TrainRequest_Sync_Quartz : JobBase, IJob { - private readonly IGhrh_ResumeServices _ghrh_ResumeServices; + private readonly IGhre_RequestServices _ghre_RequestServices; - public Job_Ushio_TrainRequest_Sync_Quartz(IGhrh_ResumeServices ghrh_ResumeServices, ITasksQzServices tasksQzServices, ITasksLogServices tasksLogServices) + public Job_Ushio_TrainRequest_Sync_Quartz(IGhre_RequestServices ghre_RequestServices, ITasksQzServices tasksQzServices, ITasksLogServices tasksLogServices) : base(tasksQzServices, tasksLogServices) { - _ghrh_ResumeServices = ghrh_ResumeServices; + _ghre_RequestServices = ghre_RequestServices; } public async Task Execute(IJobExecutionContext context) { @@ -22,6 +22,6 @@ public class Job_Ushio_TrainRequest_Sync_Quartz : JobBase, IJob public async Task Run(IJobExecutionContext context) { Console.WriteLine($"Job_Ushio_TrainRequest_Sync_Quartz 执行 {DateTime.Now.ToShortTimeString()}"); - await _ghrh_ResumeServices.Shihua_OA_Sync(); + await _ghre_RequestServices.Ushio_Sync(); } }