diff --git a/Tiobon.Core.Api/Controllers/CommonController.cs b/Tiobon.Core.Api/Controllers/CommonController.cs index 8143fe9f..66c4369e 100644 --- a/Tiobon.Core.Api/Controllers/CommonController.cs +++ b/Tiobon.Core.Api/Controllers/CommonController.cs @@ -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 _logger; private readonly ICommonServices _commonServices; + private readonly IHttpPollyHelper _httpPollyHelper; /// /// 构造函数 /// /// /// - public CommonController(ILogger logger, ICommonServices commonServices) + /// + public CommonController(ILogger 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 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 表信息 /// /// 表信息 diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml index 7c38ced3..2129b5e8 100644 --- a/Tiobon.Core.Api/Tiobon.Core.xml +++ b/Tiobon.Core.Api/Tiobon.Core.xml @@ -238,12 +238,13 @@ 公共服务 - + 构造函数 + diff --git a/Tiobon.Core.Common/Https/HttpPolly/HttpPollyHelper.cs b/Tiobon.Core.Common/Https/HttpPolly/HttpPollyHelper.cs index 83d9ad8d..552db3bb 100644 --- a/Tiobon.Core.Common/Https/HttpPolly/HttpPollyHelper.cs +++ b/Tiobon.Core.Common/Https/HttpPolly/HttpPollyHelper.cs @@ -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); + } + } } diff --git a/Tiobon.Core.Common/Https/HttpPolly/IHttpPollyHelper.cs b/Tiobon.Core.Common/Https/HttpPolly/IHttpPollyHelper.cs index f9b61b2c..91f3c014 100644 --- a/Tiobon.Core.Common/Https/HttpPolly/IHttpPollyHelper.cs +++ b/Tiobon.Core.Common/Https/HttpPolly/IHttpPollyHelper.cs @@ -13,4 +13,6 @@ public interface IHttpPollyHelper Task PutAsync(HttpEnum httpEnum, string url, R request, Dictionary headers = null); Task PutAsync(HttpEnum httpEnum, string url, string request, Dictionary headers = null); Task DeleteAsync(HttpEnum httpEnum, string url, Dictionary headers = null); + + Task DownLoad(string fileUrl, string destinationPath); } diff --git a/Tiobon.Core.Model/Insert/Ghre/Ghre_TeacherAttachment.Dto.InsertInput.cs b/Tiobon.Core.Model/Insert/Ghre/Ghre_TeacherAttachment.Dto.InsertInput.cs index 89fd379a..801c83f7 100644 --- a/Tiobon.Core.Model/Insert/Ghre/Ghre_TeacherAttachment.Dto.InsertInput.cs +++ b/Tiobon.Core.Model/Insert/Ghre/Ghre_TeacherAttachment.Dto.InsertInput.cs @@ -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 Attachments { get; set; } + + public long? TeacherAttachmentID { get; set; } } diff --git a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs index 3fd6f925..6a4cd3a3 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs @@ -437,9 +437,9 @@ public class Ghre_CourseServices : BaseServices _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 dal) { this._dal = dal; @@ -21,6 +24,7 @@ public class Ghre_TeacherServices : BaseServices> 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(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(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) diff --git a/Tiobon.Core/Tiobon.Core.xml b/Tiobon.Core/Tiobon.Core.xml index 7c38ced3..2129b5e8 100644 --- a/Tiobon.Core/Tiobon.Core.xml +++ b/Tiobon.Core/Tiobon.Core.xml @@ -238,12 +238,13 @@ 公共服务 - + 构造函数 +