using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Newtonsoft.Json;
|
using Quartz;
|
using WIDESEA_Model.Models.Basic;
|
using WIDESEAWCS_Core.BaseRepository;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_Core.HttpContextUser;
|
using WIDESEAWCS_Core.LogHelper;
|
using WIDESEAWCS_DTO.ERP;
|
using WIDESEAWCS_DTO.MES;
|
using WIDESEAWCS_Model.Models.ERP;
|
using WIDESEAWCS_QuartzJob;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
[DisallowConcurrentExecution]
|
public class ERPJob : JobBase, IJob
|
{
|
private readonly IRepository<Dt_ERP> _ERPRepository;
|
|
//秒
|
private static int shijian = 0;
|
|
public ERPJob(IRepository<Dt_ERP> ERPRepository)
|
{
|
_ERPRepository = ERPRepository;
|
}
|
|
public Task Execute(IJobExecutionContext context)
|
{
|
try
|
{
|
//一天获取一次校验码
|
Thread.Sleep(1000);
|
shijian = shijian - 1;
|
//获取ERP的token
|
if (shijian <= 0)
|
{
|
string ERP = AppSettings.Get("ERP");
|
if (!string.IsNullOrEmpty(ERP))
|
{
|
Dt_ERP Dt_ERP = _ERPRepository.QueryFirst(x => x.Id == 1);
|
|
AppERP appERP = new AppERP();
|
appERP.appTicket = Dt_ERP.appTicket;
|
appERP.certificate = Dt_ERP.certificate;
|
|
var headers = new Dictionary<string, string>();
|
headers.Add("AppKey", Dt_ERP.AppKey);
|
headers.Add("AppSecret", Dt_ERP.AppSecret);
|
ERPtoken s = JsonConvert.DeserializeObject<ERPtoken>(HttpHelper.Post($"{ERP}/v1/common/auth/selfBuiltApp/generateToken", appERP.Serialize(), "application/json", headers));
|
if (s.result.Equals("true"))
|
{
|
Dt_ERP.Token = s.value.accessToken;
|
shijian = 86400;
|
|
_ERPRepository.UpdateData(Dt_ERP);
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
//写入日志
|
LogLock.OutLogAOP("ERP日志", new string[] { "ERP", $"{ex.Message}" });
|
}
|
return Task.CompletedTask;
|
}
|
}
|
}
|