牛尾培训讲师证件数据同步

master
xiaochanghai 5 months ago
parent 57a68d2bfa
commit fc0f34d427
  1. 22
      Tiobon.Core.Api/Controllers/CommonController.cs
  2. 3
      Tiobon.Core.Api/Tiobon.Core.xml
  3. 15
      Tiobon.Core.Common/Https/HttpPolly/HttpPollyHelper.cs
  4. 2
      Tiobon.Core.Common/Https/HttpPolly/IHttpPollyHelper.cs
  5. 4
      Tiobon.Core.Model/Insert/Ghre/Ghre_TeacherAttachment.Dto.InsertInput.cs
  6. 6
      Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs
  7. 90
      Tiobon.Core.Services/Ghre/Ghre_TeacherServices.cs
  8. 3
      Tiobon.Core/Tiobon.Core.xml

@ -2,6 +2,7 @@
using System.Data;
using Tiobon.Core.Common.DB.Dapper;
using Tiobon.Core.Common.DB.Dapper.DBManager;
using Tiobon.Core.Common.Https.HttpPolly;
namespace Tiobon.Core.Controllers;
@ -15,15 +16,20 @@ public class CommonController : BaseApiController
{
private readonly ILogger<TiobonController> _logger;
private readonly ICommonServices _commonServices;
private readonly IHttpPollyHelper _httpPollyHelper;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="logger"></param>
/// <param name="commonServices"></param>
public CommonController(ILogger<TiobonController> logger, ICommonServices commonServices)
/// <param name="httpPollyHelper"></param>
public CommonController(ILogger<TiobonController> logger,
ICommonServices commonServices,
IHttpPollyHelper httpPollyHelper)
{
_commonServices = commonServices;
_httpPollyHelper = httpPollyHelper;
_logger = logger;
}
@ -548,7 +554,8 @@ SELECT @SQL SQL;";
{
sb.AppendLine($"ALTER TABLE [dbo].[{t.TableName}]");
sb.AppendLine($"ALTER COLUMN [{t.ColumnName}] {t.DataType} COLLATE Chinese_PRC_CI_AS;\r\n");
}else if (t.DataType == "date" || t.DataType == "datetime" || t.DataType == "datet"|| t.DataType == "bigint" || t.DataType == "int")
}
else if (t.DataType == "date" || t.DataType == "datetime" || t.DataType == "datet" || t.DataType == "bigint" || t.DataType == "int")
{
sb.AppendLine($"ALTER TABLE [dbo].[{t.TableName}]");
sb.AppendLine($"ALTER COLUMN [{t.ColumnName}] {t.DataType};\r\n");
@ -740,6 +747,17 @@ SELECT @SQL SQL;";
}
[HttpGet, AllowAnonymous, Route("Test")]
public async Task<IActionResult> Test(Guid id)
{
await _httpPollyHelper.DownLoad("http://120.26.205.42:3002/DataUser/ImgAth/Upload/202152216596.png", $"/files/upload/{DateTimeHelper.ConvertToSecondString1(DateTime.Now)}.png");
return Ok("Success");
}
#region 表信息
/// <summary>
/// 表信息

@ -238,12 +238,13 @@
公共服务
</summary>
</member>
<member name="M:Tiobon.Core.Controllers.CommonController.#ctor(Microsoft.Extensions.Logging.ILogger{Tiobon.Core.Controllers.TiobonController},Tiobon.Core.IServices.ICommonServices)">
<member name="M:Tiobon.Core.Controllers.CommonController.#ctor(Microsoft.Extensions.Logging.ILogger{Tiobon.Core.Controllers.TiobonController},Tiobon.Core.IServices.ICommonServices,Tiobon.Core.Common.Https.HttpPolly.IHttpPollyHelper)">
<summary>
构造函数
</summary>
<param name="logger"></param>
<param name="commonServices"></param>
<param name="httpPollyHelper"></param>
</member>
<member name="M:Tiobon.Core.Controllers.CommonController.GetMenuAsync(Tiobon.Core.Model.MenuParam)">
<summary>

@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System.Text;
using Tiobon.Core.Common.Helper;
using Tiobon.Core.Model;
namespace Tiobon.Core.Common.Https.HttpPolly;
@ -346,4 +347,18 @@ public class HttpPollyHelper : IHttpPollyHelper
}
}
public async Task DownLoad(string fileUrl, string destinationPath)
{
var client = _clientFactory.CreateClient();
destinationPath = FileHelper.GetPhysicsPath() + destinationPath;
HttpResponseMessage response = await client.GetAsync(fileUrl, HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode(); // 确保请求成功
using (Stream contentStream = await response.Content.ReadAsStreamAsync(),
fileStream = new FileStream(destinationPath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true))
{
await contentStream.CopyToAsync(fileStream);
}
}
}

@ -13,4 +13,6 @@ public interface IHttpPollyHelper
Task<T> PutAsync<T, R>(HttpEnum httpEnum, string url, R request, Dictionary<string, string> headers = null);
Task<T> PutAsync<T>(HttpEnum httpEnum, string url, string request, Dictionary<string, string> headers = null);
Task<T> DeleteAsync<T>(HttpEnum httpEnum, string url, Dictionary<string, string> headers = null);
Task DownLoad(string fileUrl, string destinationPath);
}

@ -15,8 +15,6 @@
*
*/
using System.ComponentModel.DataAnnotations.Schema;
namespace Tiobon.Core.Model.Models;
@ -27,4 +25,6 @@ public class InsertGhre_TeacherAttachmentInput : Ghre_TeacherAttachmentBase
{
[NotMapped]
public List<InsertGhre_AttachmentInput> Attachments { get; set; }
public long? TeacherAttachmentID { get; set; }
}

@ -437,9 +437,9 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins
}
var result = await BaseDal.Update(entities);
if (status == Consts.DIC_COURSE_STATUS.RELEASED)
if (status == DIC_COURSE_STATUS.RELEASED)
return ServiceResult.OprateSuccess("发布成功!");
else if (status == Consts.DIC_COURSE_STATUS.DRAFT)
else if (status == DIC_COURSE_STATUS.DRAFT)
return ServiceResult.OprateSuccess("已启用成功,请进入草稿箱查看!");
else
return ServiceResult.OprateSuccess("停用成功!");
@ -450,7 +450,7 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins
{
entity.ExamPaperId = JsonHelper.ObjToJson(entity.ExamPaperIds);
entity.CourseClassId = JsonHelper.ObjToJson(entity.CourseClassIds);
entity.Status = Consts.DIC_COURSE_STATUS.DRAFT;
entity.Status = DIC_COURSE_STATUS.DRAFT;
entity.DefaultCoverImageName = entity.DefaultCoverImageName ?? "defaultCourseCover1";
entity.UseDefaultCoverImage = entity.UseDefaultCoverImage ?? true;
//entity.IsOpen = entity.IsOPenLabel == true ? "1" : "0";

@ -1,4 +1,5 @@
using Serilog;
using Tiobon.Core.Common.Https.HttpPolly;
using static Tiobon.Core.Model.Consts;
namespace Tiobon.Core.Services;
@ -11,9 +12,11 @@ public class Ghre_TeacherServices : BaseServices<Ghre_Teacher, Ghre_TeacherDto,
private readonly IBaseRepository<Ghre_Teacher> _dal;
private IGhre_AttachmentServices _ghre_AttachmentServices;
private IGhre_TeacherAttachmentServices _ghre_TeacherAttachmentServices;
private readonly IHttpPollyHelper _httpPollyHelper;
public Ghre_TeacherServices(ICaching caching,
IGhre_AttachmentServices ghre_AttachmentServices,
IGhre_TeacherAttachmentServices ghre_TeacherAttachmentServices,
IHttpPollyHelper httpPollyHelper,
IBaseRepository<Ghre_Teacher> dal)
{
this._dal = dal;
@ -21,6 +24,7 @@ public class Ghre_TeacherServices : BaseServices<Ghre_Teacher, Ghre_TeacherDto,
base._caching = caching;
_ghre_AttachmentServices = ghre_AttachmentServices;
_ghre_TeacherAttachmentServices = ghre_TeacherAttachmentServices;
_httpPollyHelper = httpPollyHelper;
}
public override async Task<ServicePageResult<Ghre_TeacherDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true)
@ -611,14 +615,14 @@ FROM (SELECT A.*,
A.Price,
A.SkillPoints,
A.ApplyReason,
C.StaffId SponsorId,A.WorkNo
C.StaffId SponsorId,A.WorkNo,A.WorkID
FROM [120.26.205.42].[GhrUshio].[dbo].Ushio_TrainTeacher A
LEFT JOIN Ghro_Dept B ON A.DeptNo = B.DeptNo
LEFT JOIN Ghra_Staff C ON A.TeacherNo = C.StaffNo
LEFT JOIN Ghra_Staff D ON A.ApplyStaffNo = D.StaffNo
WHERE WorkNo NOT IN (SELECT WorkNo
FROM Ghre_Teacher
WHERE WorkNo IS NOT NULL)";
WHERE WorkNo IS NOT NULL AND IsEnable=1)";
var dt = await Db.Ado.GetDataTableAsync(sql);
@ -633,15 +637,95 @@ FROM (SELECT A.*,
if (await base.AnyAsync(x => x.WorkNo == insert.WorkNo))
continue;
//Advanced
if (insert.SchoolId == 0) insert.SchoolId = null;
var photoUrl = $"/files/upload/{DateTimeHelper.ConvertToSecondString1(DateTime.Now)}.png";
try
{
await _httpPollyHelper.DownLoad("http://120.26.205.42:3002" + insert.PhotoUrl, photoUrl);
}
catch (Exception)
{
photoUrl = null;
}
var workId = insert.WorkID;
insert.PhotoUrl = "/Advanced" + photoUrl;
insert.Status = "Wait";
insert.WorkID = null;
var id = await base.Add(insert);
sql = $"SELECT ISNULL(MAX(id)+1,1) FROM Ghre_Teacher WHERE Id !='{id}'";
var id1 = await Db.Ado.GetLongAsync(sql);
sql = $"UPDATE Ghre_Teacher SET Id={id1} WHERE Id ='{id}'";
await Db.Ado.ExecuteCommandAsync(sql);
#region 同步证件
sql = $@"SELECT CertificateNo,
CertificateName,
EffectiveDate,
ExpirationDate,
TeacherAttachmentID
FROM [120.26.205.42].[GhrUshio].[dbo].Ushio_TeacherAttachment
WHERE WorkID = {workId}";
dt = await Db.Ado.GetDataTableAsync(sql);
var attachments = Db.Utilities.DataTableToList<InsertGhre_TeacherAttachmentInput>(dt);
Log.Information($"【牛尾培训讲师同步】查询到【{attachments.Count}】笔证件数据");
if (attachments.Any())
{
for (int j = 0; j < attachments.Count; j++)
{
attachments[j].TeacherId = id1;
var attachmentId = await _ghre_TeacherAttachmentServices.Add(attachments[j]);
sql = @$"SELECT AttachmentNo,
AttachmentName,
AttachmentName AttachFileName,
AttachFileSize,
FileUrl PhysicsPath,
AttachFileExtension
FROM [120.26.205.42].[GhrUshio].[dbo].Ghrs_Attachment
WHERE EnableYN = 'Y'
AND Reverse1 = 'Ghre_TeacherAttachment'
AND ReverseN1 = {attachments[j].TeacherAttachmentID}";
dt = await Db.Ado.GetDataTableAsync(sql);
var attachments1 = Db.Utilities.DataTableToList<InsertGhre_AttachmentInput>(dt);
if (attachments1.Any())
{
for (int m = 0; m < attachments1.Count; m++)
{
attachments1[m].TableName = attachmentId.ObjToString();
photoUrl = $"/files/upload/{DateTimeHelper.ConvertToSecondString1(DateTime.Now)}.png";
try
{
await _httpPollyHelper.DownLoad(attachments1[m].PhysicsPath, photoUrl);
attachments1[m].PhysicsPath = photoUrl;
attachments1[m].RelativePath = photoUrl;
attachments1[m].ThumbnailPath = photoUrl;
attachments1[m].FileURL = photoUrl;
await _ghre_AttachmentServices.Add(attachments1);
}
catch (Exception)
{
photoUrl = null;
}
}
}
}
}
#endregion
}
}
catch (Exception E)

@ -238,12 +238,13 @@
公共服务
</summary>
</member>
<member name="M:Tiobon.Core.Controllers.CommonController.#ctor(Microsoft.Extensions.Logging.ILogger{Tiobon.Core.Controllers.TiobonController},Tiobon.Core.IServices.ICommonServices)">
<member name="M:Tiobon.Core.Controllers.CommonController.#ctor(Microsoft.Extensions.Logging.ILogger{Tiobon.Core.Controllers.TiobonController},Tiobon.Core.IServices.ICommonServices,Tiobon.Core.Common.Https.HttpPolly.IHttpPollyHelper)">
<summary>
构造函数
</summary>
<param name="logger"></param>
<param name="commonServices"></param>
<param name="httpPollyHelper"></param>
</member>
<member name="M:Tiobon.Core.Controllers.CommonController.GetMenuAsync(Tiobon.Core.Model.MenuParam)">
<summary>

Loading…
Cancel
Save