牛尾培训需求老版本同步,测试

master
xiaochanghai 5 months ago
parent 18607e0265
commit 9bde10b0c0
  1. 47
      Tiobon.Core.Common/DB/Dapper/Extensions/GenericExtension.cs
  2. 2
      Tiobon.Core.IServices/Ghre/IGhre_RequestServices.cs
  3. 8
      Tiobon.Core.Model/View/Ghre/Ghre_Request.Dto.View.cs
  4. 69
      Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs
  5. 2
      Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs
  6. 8
      Tiobon.Core.Tasks/QuartzNet/Jobs/Job_Ushio_TrainRequest_Sync_Quartz.cs

@ -54,5 +54,52 @@ public static class GenericExtension
}
return dtReturn;
}
public static List<T> ToList<T>(this DataTable dt) where T : class, new()
{
Type t = typeof(T);
PropertyInfo[] propertys = t.GetProperties();
List<T> lst = new List<T>();
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;
}
}

@ -15,4 +15,6 @@ public interface IGhre_RequestServices : IBaseServices<Ghre_Request, Ghre_Reques
Task<ServiceResult<long>> InsertByStatus(InsertGhre_RequestInput insertModel, string status);
Task<ServicePageResult<Ghre_RequestDto>> QueryGroup(QueryBody filter, string type);
Task Ushio_Sync();
}

@ -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; }
}

@ -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<Ghre_RequestDto>(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<InsertGhre_RequestInput>();
if (await base.AnyAsync(x => x.RequestNo == insert.RequestNo))
continue;
if (list[i].DeptNo.IsNotEmptyOrNull())
insert.DeptId = (await Db.Queryable<Ghro_Dept>().Where(x => x.DeptNo == list[i].DeptNo).FirstAsync())?.DeptID;
if (list[i].SponsorNo.IsNotEmptyOrNull())
insert.SponsorId = (await Db.Queryable<Ghra_Staff>().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<Ghra_Staff>().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<Ghre_Config>().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
}

@ -1393,7 +1393,7 @@ WHERE A.Id = '{id}'";
var wareAttachmentCount = await Db.Queryable<Ghre_CourseWareAttachment>().Where(x => courseWareIds.Contains(x.CourseWareId)).CountAsync();
if (wareAttachmentCount != detailWareAttachmentCount)
if (wareAttachmentCount > detailWareAttachmentCount)
studyProgress = 99;
}

@ -8,12 +8,12 @@ namespace Tiobon.Core.Tasks;
/// </summary>
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();
}
}

Loading…
Cancel
Save