添加项目文件。
This commit is contained in:
1 parent
05e131ca4e
commit
514d6f5255
1162 files changed
+81255
No files matched your search
@@ -0,0 +1,37 @@
|
||||
using AutoMapper;
|
||||
using HHWMS.Web.Models;
|
||||
|
||||
namespace HHWMS.Web.Support.Profiles
|
||||
{
|
||||
public class MapToHisProfile : Profile
|
||||
{
|
||||
public MapToHisProfile()
|
||||
{
|
||||
CreateMap<ReceiptHeader, ReceiptHeaderHistory>();
|
||||
CreateMap<ReceiptDetail, ReceiptDetailHistory>();
|
||||
//.ForMember(
|
||||
// destinationMember => destinationMember.ReceiptHeaderHistoryId,
|
||||
// src => src.MapFrom(x => x.ReceiptHeaderId))
|
||||
//.ForMember(
|
||||
// destinationMember => destinationMember.ReceiptHeaderHistory,
|
||||
// src => src.MapFrom(x => x.ReceiptHeader))
|
||||
|
||||
CreateMap<ShipmentHeader, ShipmentHeaderHistory>();
|
||||
CreateMap<ShipmentDetail, ShipmentDetailHistory>();
|
||||
|
||||
CreateMap<TaskHeader, TaskHeaderHistory>();
|
||||
CreateMap<TaskDetail, TaskDetailHistory>();
|
||||
|
||||
// 任务明细 --> 库存交易
|
||||
CreateMap<TaskDetail, InventoryTransaction>()
|
||||
.ForMember(
|
||||
dest => dest.BillCode,
|
||||
src => src.MapFrom(x => x.OrderCode))
|
||||
.ForMember(
|
||||
dest => dest.BillDetailId,
|
||||
src => src.MapFrom(x => x.OrderDetailId))
|
||||
.ForMember(x => x.ID, opt => opt.Ignore())
|
||||
.ForMember(x => x.Status, opt => opt.Ignore());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using HHWMS.Web.Models;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using Quartz.Impl.Triggers;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Support.Quartz;
|
||||
|
||||
namespace HHWMS.Web.Support
|
||||
{
|
||||
public class QuartzService
|
||||
{
|
||||
private readonly IServiceProvider _sp;
|
||||
private readonly GlobalData _gd;
|
||||
private readonly IDataContext _context;
|
||||
private IScheduler _scheduler;
|
||||
private static Task<IScheduler> task_scheduler = StdSchedulerFactory.GetDefaultScheduler();
|
||||
private static readonly object objlock = new object();
|
||||
|
||||
public QuartzService(IServiceProvider sp, GlobalData gd, IDataContext context)
|
||||
{
|
||||
_sp = sp;
|
||||
_gd = gd;
|
||||
_context = context;
|
||||
if (_scheduler == null)
|
||||
{
|
||||
lock (objlock)
|
||||
{
|
||||
if (_scheduler == null)
|
||||
{
|
||||
_scheduler = task_scheduler.Result;
|
||||
if (!_scheduler.IsStarted)
|
||||
_scheduler.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task AddJob(SysJob jobDetail)
|
||||
{
|
||||
try
|
||||
{
|
||||
var test = _gd.AllAssembly.FirstOrDefault(x => x.FullName.Contains("HHWMS.Web"));
|
||||
var t = test.GetExportedTypes().FirstOrDefault(x => typeof(WtmJob).IsAssignableFrom(x) && x.Name == jobDetail.JobName);
|
||||
var ci = t.GetConstructor(Type.EmptyTypes);
|
||||
if (ci?.Invoke(null) as WtmJob != null)
|
||||
{
|
||||
string jobName = jobDetail.JobName;
|
||||
string groupName = jobDetail.JobName;
|
||||
if (await _scheduler.CheckExists(new JobKey(jobName, groupName)))
|
||||
{
|
||||
ModJob(jobDetail);
|
||||
return;
|
||||
}
|
||||
JobDataMap jobDataMap = new JobDataMap();
|
||||
jobDataMap.Add("Sp", _sp);
|
||||
|
||||
// 创建作业
|
||||
IJobDetail j = JobBuilder.Create(t)
|
||||
.WithIdentity(jobName, groupName)
|
||||
.UsingJobData(jobDataMap)
|
||||
.Build();
|
||||
|
||||
// 创建触发器
|
||||
ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
|
||||
.WithIdentity(jobName, groupName)
|
||||
.WithCronSchedule(jobDetail.CronExpression)
|
||||
.ForJob(new JobKey(jobName, groupName))
|
||||
.Build();
|
||||
|
||||
((CronTriggerImpl)trigger).MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;
|
||||
await _scheduler.ScheduleJob(j, trigger);
|
||||
|
||||
if (jobDetail.Status == SysJobEnum.stoped)
|
||||
_scheduler.PauseJob(new JobKey(jobName, groupName)).Wait();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public void DeleteJob(SysJob job)
|
||||
{
|
||||
_scheduler.PauseTrigger(new TriggerKey(job.JobName, job.JobGroup)).Wait();
|
||||
_scheduler.UnscheduleJob(new TriggerKey(job.JobName, job.JobGroup)).Wait();
|
||||
_scheduler.DeleteJob(new JobKey(job.JobName, job.JobGroup)).Wait();
|
||||
}
|
||||
|
||||
public void Execute(SysJob job)
|
||||
{
|
||||
_scheduler.TriggerJob(new JobKey(job.JobName, job.JobGroup)).Wait();
|
||||
}
|
||||
|
||||
public void ModJob(SysJob job)
|
||||
{
|
||||
TriggerKey triggerKey = new TriggerKey(job.JobName, job.JobGroup);
|
||||
ITrigger trigger = _scheduler.GetTrigger(triggerKey).Result;
|
||||
|
||||
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.CronSchedule(job.CronExpression);
|
||||
trigger = trigger.GetTriggerBuilder()
|
||||
.WithIdentity(triggerKey)
|
||||
.WithSchedule(scheduleBuilder.WithMisfireHandlingInstructionDoNothing())
|
||||
.Build();
|
||||
|
||||
_scheduler.RescheduleJob(triggerKey, trigger).Wait();
|
||||
if (job.Status == SysJobEnum.stoped)
|
||||
_scheduler.PauseJob(new JobKey(job.JobName, job.JobGroup));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace HHWMS.Web.Support
|
||||
{
|
||||
public static class SwaggerExtension
|
||||
{
|
||||
public static void AddSwaggerGenExt(this WebApplicationBuilder builder)
|
||||
{
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(
|
||||
option =>
|
||||
{
|
||||
option.SwaggerDoc("Sys", new OpenApiInfo { Title = "系统", Version = "v1" });
|
||||
option.SwaggerDoc("User", new OpenApiInfo { Title = "自定义", Version = "v1" });
|
||||
|
||||
option.DocInclusionPredicate((docName, apiDesc) =>
|
||||
{
|
||||
if (!apiDesc.TryGetMethodInfo(out MethodInfo methodInfo))
|
||||
return false;
|
||||
var versions = methodInfo.DeclaringType
|
||||
.GetCustomAttributes(true)
|
||||
.OfType<ApiExplorerSettingsAttribute>()
|
||||
.Select(x => x.GroupName);
|
||||
if (docName.ToLower() == "sys" && versions.FirstOrDefault() == null)
|
||||
return true; // 不写ApiExplorerSetting默认显示在Sys组
|
||||
|
||||
return versions.Any(x => x.ToString() == docName);
|
||||
});
|
||||
|
||||
var xml = Path.Combine(AppContext.BaseDirectory, "HHWMS.Web.xml");
|
||||
option.IncludeXmlComments(xml, true);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void UseSwaggerExt(this WebApplication app)
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(option =>
|
||||
{
|
||||
option.SwaggerEndpoint("/swagger/User/swagger.json", "自定义");
|
||||
option.SwaggerEndpoint("/swagger/Sys/swagger.json", "系统接口");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using HHWMS.Web.Models;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using Quartz.Impl.Triggers;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Support.Quartz;
|
||||
|
||||
namespace HHWMS.Web.Support
|
||||
{
|
||||
public static class WmsServicesExtension
|
||||
{
|
||||
public static IApplicationBuilder AddQuartzJobs(this IApplicationBuilder app)
|
||||
{
|
||||
var configs = app.ApplicationServices.GetRequiredService<IOptionsMonitor<Configs>>().CurrentValue;
|
||||
var gd = app.ApplicationServices.GetRequiredService<GlobalData>();
|
||||
var dc = configs.CreateDC();
|
||||
var sp = app.ApplicationServices.GetService<IServiceProvider>();
|
||||
|
||||
Task<IScheduler> task_scheduler = StdSchedulerFactory.GetDefaultScheduler();
|
||||
var _scheduler = task_scheduler.Result;
|
||||
|
||||
var jobList = dc.Set<SysJob>().ToList();
|
||||
|
||||
foreach (var job in jobList)
|
||||
{
|
||||
new QuartzService(sp, gd, dc).AddJob(job).Wait();
|
||||
}
|
||||
|
||||
var test = gd.AllAssembly.FirstOrDefault(x => x.FullName.Contains("HHWMS.Web"));
|
||||
var t = test.GetExportedTypes().Where(x => typeof(WtmJob).IsAssignableFrom(x) && x.Name != "WtmJob");
|
||||
foreach (var item in t)
|
||||
{
|
||||
var ci = item.GetConstructor(Type.EmptyTypes);
|
||||
var job = ci?.Invoke(null) as WtmJob;
|
||||
|
||||
if (job != null)
|
||||
{
|
||||
string jobName = item.Name;
|
||||
string groupName = item.Name;
|
||||
if (_scheduler.CheckExists(new JobKey(jobName, groupName)).Result)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
JobDataMap jobDataMap = new JobDataMap();
|
||||
jobDataMap.Add("Sp", sp);
|
||||
|
||||
// 创建作业
|
||||
IJobDetail j = JobBuilder.Create(item)
|
||||
.WithIdentity(jobName, groupName)
|
||||
.UsingJobData(jobDataMap)
|
||||
.Build();
|
||||
|
||||
// 创建触发器
|
||||
ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
|
||||
.WithIdentity(jobName, groupName)
|
||||
.WithCronSchedule("0 0 0 1 1 ? *")
|
||||
.ForJob(new JobKey(jobName, groupName))
|
||||
.Build();
|
||||
|
||||
((CronTriggerImpl)trigger).MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;
|
||||
_scheduler.ScheduleJob(j, trigger).Wait();
|
||||
|
||||
//var builder = TriggerBuilder.Create()
|
||||
// .WithIdentity(jobName, groupName)
|
||||
// .WithCronSchedule("0 0 0 1 1 ? *")
|
||||
// .ForJob(new JobKey(jobName, groupName));
|
||||
|
||||
//var trigger = builder.Build();
|
||||
//_scheduler.ScheduleJob(j, trigger).Wait();
|
||||
|
||||
//_scheduler.PauseJob(new JobKey(jobName, groupName)).Wait();
|
||||
}
|
||||
}
|
||||
if (!_scheduler.IsStarted) _scheduler.Start().Wait();
|
||||
|
||||
return app;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user