ningshuxia
2022-12-12 4f1314cb69a47c22e52f1efdc4b4be6c1d55143d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IStation.Server
{
    /// <summary>
    /// 单个任务
    /// </summary>
    [DisallowConcurrentExecution]//此特性标识 必须等待这次任务执行完成后,才能执行下次任务
    internal class SingleJob : IJob
    {
        public const string ConfigureTagName = "Configure";
 
        public Task Execute(IJobExecutionContext context)
        {
 
            return Task.Run(() =>
            {
 
                //获取配置
                var dataMap = context.MergedJobDataMap;
                var configure = (Model.DataDockingConfigureExApi)dataMap[ConfigureTagName];
                if (configure == null)
                    return;
                try
                {
                    //映射关系
                    if (configure.Mappers == null || configure.Mappers.Count < 1)
                    {
                        LogHelper.Info($"Api数据对接任务中:{configure.Name},未进行映射关系配置!");
                        return;
                    }
 
                    //创建数据对接对象
                    var dataDocking = DataDockingApiFactory.CreateApi<IDataDockingApi.IHandleHelper>(configure.ConfigureParas.DependencyFile);
                    if (dataDocking == null)
                    {
                        LogHelper.Info($"Api数据对接任务中,{configure.Name},创建数据对接对象失败!!");
                        return;
                    }
 
                    dataDocking.HandleData(configure.Mappers, (receive_list) =>
                     {
                         if (receive_list == null || receive_list.Count < 1)
                         {
                             LogHelper.Info($"Api数据对接任务中,{configure.Name},接收数据为空!");
                             return;
                         }
 
                         var queue = new RabbitMqQueueHelper();
                         queue.Push(ConfigHelper.QueueName, new Model.MonitorDataDockingCorpRecord() { CorpID = configure.CorpID, ConfigureID = configure.ID, Records = receive_list });
 
                         LogHelper.Info($"api配置名称:{configure.Name},成功推入通道{receive_list.Count}条数据!");
                     });
                }
                catch (Exception ex)
                {
                    LogHelper.Error($"Api数据对接,任务执行出错,配置名称:{configure.Name}", ex);
                    var e = new JobExecutionException(ex);
                    throw e;
                }
            });
 
        }
 
 
 
    }
}