😎新增OA问题报告回传OA接口、定时任务

This commit is contained in:
bairubing 2025-01-16 17:44:19 +08:00
parent f531b6b286
commit 20f3383f8f
4 changed files with 161 additions and 45 deletions

View File

@ -0,0 +1,57 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vistar.Application.Entity;
using Vistar.Application.Service.OaOpenInterface;
namespace Vistar.Application.Job.OaOpenInterface;
[JobDetail("job_SyncProblemReportingFileToOa", Description = "问题报告回传OA", GroupName = "default", Concurrent = false)]
[PeriodMinutes(10, TriggerId = "trigger_SyncProblemReportingFileToOa", Description = "问题报告回传OA", RunOnStart = false)]
public class SyncProblemReportingFileToOa : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
public OaOpenInterfaceService _oaOpenInterface;
public SyncProblemReportingFileToOa(IServiceScopeFactory scopeFactory, OaOpenInterfaceService oaOpenInterface)
{
_scopeFactory = scopeFactory;
_oaOpenInterface = oaOpenInterface;
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("1300000000001").CopyNew();
DateTime startTime = DateTime.Now;
var sapOutputs = await _oaOpenInterface.SyncProblemReportingFileToOa();
var json = JsonConvert.SerializeObject(sapOutputs);
string output = json;
var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds;
if (sapOutputs.Count == 0)
{
output = "未查询到符合条件的记录";
}
db.CopyNew().Insertable<ScheduledTaskLog>(new
{
TaskName = "问题报告回传OA",
LogDateTime = DateTime.Now,
ReturnResult = output,
Elapsed = elapsedMilliseconds.ToLong()
}).ExecuteCommand();
}
}

View File

@ -13,6 +13,7 @@ using System.Threading.Tasks;
namespace Vistar.Application.Service.OaOpenInterface.Dto;
public class OaUploadFileOutput
{
public string EcnNum { get; set; }
public string success { get; set; }
public string message { get; set; }
public string data { get; set; }

View File

@ -65,8 +65,8 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
_solidWorksManageService = solidWorksManageService;
_objectFieldsGroupsRep = objectFieldsGroupsRep;
_fieldGroupDefaultRep = fieldGroupDefaultRep;
_obj81Rep= obj81Rep;
_obj118Rep= obj118Rep;
_obj81Rep = obj81Rep;
_obj118Rep = obj118Rep;
_scopeFactory = scopeFactory;
}
@ -200,7 +200,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
string.IsNullOrWhiteSpace(input.fld005850) ||
input.fld005852 == default(DateTime) ||
//string.IsNullOrWhiteSpace(input.fld005852.ToString("yyyy-MM-dd HH:mm:ss")) ||
string.IsNullOrWhiteSpace(input.fld005853)
string.IsNullOrWhiteSpace(input.fld005853)
)
{
response.Success = true;
@ -279,12 +279,12 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
fields = fieldList
};
response = await _solidWorksManageService.CreateProcess(data);
if (response.Success== true && response.Message== "记录 已成功保存!")
if (response.Success == true && response.Message == "记录 已成功保存!")
{
var projectData = await _obj140Rep.AsQueryable().Where(x => x._System_objNBS == input._System_objNBS && x.deleted == false).OrderByDescending(x=>x.VersionIndex).FirstAsync();
var projectData = await _obj140Rep.AsQueryable().Where(x => x._System_objNBS == input._System_objNBS && x.deleted == false).OrderByDescending(x => x.VersionIndex).FirstAsync();
long? fld005835 = null;
string fld005835_Rec = "";
var responsiblePersonOaData = await _obj81Rep.AsQueryable().Where(x => x.fld004900 == input.fld005836 && x.deleted == false).ToListAsync();
if (responsiblePersonOaData.Count != 0)
{
@ -292,7 +292,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
fld005835_Rec = responsiblePersonOaData[0].RecordGuid;
}
long? fld007039 = null;
string fld007039_Rec = "";
@ -307,7 +307,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
}
}
long? fld005848 = null;
string fld005848_Rec = "";
@ -315,7 +315,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
if (createPersonOaData.Count != 0)
{
fld005848 = 81;
fld005848_Rec= createPersonOaData[0].RecordGuid;
fld005848_Rec = createPersonOaData[0].RecordGuid;
}
long? fld005851 = null;
@ -324,7 +324,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
if (reviewerOaData.Count != 0)
{
fld005851 = 81;
fld005851_Rec= reviewerOaData[0].RecordGuid;
fld005851_Rec = reviewerOaData[0].RecordGuid;
}
long? fld005837 = null;
@ -335,7 +335,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
if (mechanicalProblemHandlerOaId.Count != 0)
{
fld005837 = 81;
fld005837_Rec= mechanicalProblemHandlerOaId[0].RecordGuid;
fld005837_Rec = mechanicalProblemHandlerOaId[0].RecordGuid;
}
}
@ -367,7 +367,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
.SetColumns(it => new Obj140
{
fld005835 = fld005835,
fld005835_Rec= fld005835_Rec,
fld005835_Rec = fld005835_Rec,
fld007039 = fld007039,
fld007039_Rec = fld007039_Rec,
fld005848 = fld005848,
@ -400,7 +400,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
response.Message = "编码已存在";
}
return response;
return response;
}
/// <summary>
@ -411,11 +411,11 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
[ApiDescriptionSettings(Name = "OaAddRelatedFiles"), HttpPost]
[DisplayName("OA创建问题报告文件")]
public async Task<ManageResponse> OaAddRelatedFiles(OaAddRelatedFilesInput input)
public async Task<ManageResponse> OaAddRelatedFiles(OaAddRelatedFilesInput input)
{
var response = new ManageResponse();
if (input.object_id == 0||string.IsNullOrEmpty(input._System_objNBS)|| input.file_structure_id ==0 || string.IsNullOrEmpty(input.file_name))
if (input.object_id == 0 || string.IsNullOrEmpty(input._System_objNBS) || input.file_structure_id == 0 || string.IsNullOrEmpty(input.file_name))
{
response.Success = true;
response.Message = "必填项不能为空";
@ -426,9 +426,9 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
//string base64String = Convert.ToBase64String(bytes);
byte[] bytes = Convert.FromBase64String(input.file);
var AddRelatedFiles=new List<AddRelatedFilesInput>();
var AddRelatedFiles = new List<AddRelatedFilesInput>();
var data=await _obj140Rep.AsQueryable().Where(x=>x._System_objNBS==input._System_objNBS && x.deleted==false).OrderByDescending(x=>x.idRecord).ToListAsync();
var data = await _obj140Rep.AsQueryable().Where(x => x._System_objNBS == input._System_objNBS && x.deleted == false).OrderByDescending(x => x.idRecord).ToListAsync();
if (data.Count > 0)
{
var CheckData = new CheckDataInput()
@ -438,7 +438,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
bom_level = 1
};
await _solidWorksManageService.CheckOut(CheckData);
var latestData = await _obj140Rep.AsQueryable().Where(x => x._System_objNBS == input._System_objNBS && x.deleted == false).OrderByDescending(x => x.idRecord).ToListAsync();
var AddRelatedFilesData = new AddRelatedFilesInput
{
@ -451,7 +451,8 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
response = await _solidWorksManageService.AddRelatedFiles(AddRelatedFilesData);
await _solidWorksManageService.CheckIn(CheckData);
}
else {
else
{
response.Success = false;
response.Message = "编码不存在";
}
@ -463,13 +464,12 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
/// <returns></returns>
[ApiDescriptionSettings(Name = "SyncEcnAttach"), HttpGet]
[DisplayName("ecn同步文件")]
[AllowAnonymous]
public async Task<List<OaUploadFileOutput>> SyncEcnAttach()
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
var data=await db.CopyNew().Queryable<Obj118>().Where(x=>x.deleted==false&&x.fld006778=="A"&&x._System_CurrentStage=="结束"&&!string.IsNullOrEmpty(x.fld006310_Rec)).ToListAsync();
var data = await db.CopyNew().Queryable<Obj118>().Where(x => x.deleted == false && x.fld006778 == "A" && x._System_CurrentStage == "结束" && !string.IsNullOrEmpty(x.fld006310_Rec)).ToListAsync();
var groupedData = data.GroupBy(item => item.RecordGuid)
.Select(group => group.OrderByDescending(item => item.idRecord).First())
@ -480,26 +480,28 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
var id = item.idRecord;
var input = new ExportRelatedFilesInput
{
record_id=id,
object_id=118
record_id = id,
object_id = 118
};
var manageOutput= await _solidWorksManageService.ExportRelatedFiles(input);
if (manageOutput.State=="成功")
var manageOutput = await _solidWorksManageService.ExportRelatedFiles(input);
if (manageOutput.State == "成功")
{
var problemReport= await db.CopyNew().Queryable<Obj140>().Where(x=>x.RecordGuid==item.fld006310_Rec&&x.deleted==false).FirstAsync();
if (problemReport != null)
var problemReport = await db.CopyNew().Queryable<Obj140>().Where(x => x.RecordGuid == item.fld006310_Rec && x.deleted == false).FirstAsync();
if (problemReport != null)
{
var oaUploadFileOutput = await OaUploadFile(problemReport._System_objNBS, manageOutput);
var oaUploadFileOutput = await OaUploadFile(problemReport._System_objNBS, manageOutput, "");
var EcnNum = problemReport._System_objNBS;
oaUploadFileOutput.EcnNum = EcnNum;
output.Add(oaUploadFileOutput);
db.CopyNew().Updateable<Obj118>()
.SetColumns(it => new Obj118
{
fld006778="N",
fld006780=DateTime.Now,
fld006779= oaUploadFileOutput.message
})
.Where(it => it.idRecord == id)
.ExecuteCommand();
db.CopyNew().Updateable<Obj118>()
.SetColumns(it => new Obj118
{
fld006778 = "N",
fld006780 = DateTime.Now,
fld006779 = oaUploadFileOutput.message
})
.Where(it => it.idRecord == id)
.ExecuteCommand();
}
}
}
@ -511,18 +513,27 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
/// </summary>
/// <param name="problemNum"></param>
/// <param name="input"></param>
/// <param name="fld006992"></param>
/// <returns></returns>
public async Task<OaUploadFileOutput> OaUploadFile(string problemNum, ExportRelatedFilesOutput input)
public async Task<OaUploadFileOutput> OaUploadFile(string problemNum, ExportRelatedFilesOutput input, string? fld006992)
{
//string url = "http://223.113.253.60:8000/papi/secondev/workflow/uploadFileByReportNo";
string url = "http://192.168.10.35:8000/papi/secondev/workflow/uploadFileByReportNo";
// 构建请求参数字典
string FileName = "";
string FileBate = "";
if (input != null)
{
FileName = input.FileName;
FileBate = input.FileBate;
}
var requestData = new
{
num = problemNum,
filename=input.FileName,
filesize="",
base64 = input.FileBate
filename = FileName,
filesize = "",
base64 = FileBate,
jjfa = fld006992
};
var output = new OaUploadFileOutput();
using (HttpClient client = new HttpClient())
@ -533,7 +544,7 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
string json = JsonConvert.SerializeObject(requestData);
// 创建HttpContent设置为JSON格式的内容
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(url,content);
HttpResponseMessage response = await client.PostAsync(url, content);
if (response.IsSuccessStatusCode)
{
string contentOutput = await response.Content.ReadAsStringAsync();
@ -548,4 +559,51 @@ public class OaOpenInterfaceService : IDynamicApiController, ITransient
}
return output;
}
/// <summary>
/// 问题报告回传OA
/// </summary>
/// <returns></returns>
public async Task<List<OaUploadFileOutput>> SyncProblemReportingFileToOa()
{
using var serviceScope = _scopeFactory.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
var data = await db.CopyNew().Queryable<Obj140>().Where(x => x.CheckedStatus == false && x.IsLatestVersion == true && x._System_CurrentStage == "问题关闭" && x.fld005841 == "不需要" && x.fld007055 == "A").ToListAsync();
var output = new List<OaUploadFileOutput>();
foreach (var item in data)
{
if (!string.IsNullOrEmpty(item.fld006992))
{
var oaOutput = await OaUploadFile(item._System_objNBS, null, item.fld006992);
var EcnNum = item._System_objNBS;
oaOutput.EcnNum = EcnNum;
output.Add(oaOutput);
if (oaOutput.success == "true")
{
db.CopyNew().Updateable<Obj140>().SetColumns(it => new Obj140
{
fld007055 = "N",
fld007058 = DateTime.Now,
fld007057 = oaOutput.message,
fld007056 = "成功"
}).Where(it => it.idRecord == item.idRecord)
.ExecuteCommand();
}
else
{
db.CopyNew().Updateable<Obj140>().SetColumns(it => new Obj140
{
fld007055 = "N",
fld007058 = DateTime.Now,
fld007057 = oaOutput.message,
fld007056 = "失败"
}).Where(it => it.idRecord == item.idRecord)
.ExecuteCommand();
}
}
}
return output;
}
}

View File

@ -14,7 +14,7 @@ using System.Threading.Tasks;
namespace Vistar.Application.SolidWorksManageService.Dto;
public class ExportRelatedFilesOutput
{
public string State { get; set; }
public string FileName { get; set; }
public string FileBate { get; set; }
public string? State { get; set; }
public string? FileName { get; set; }
public string? FileBate { get; set; }
}