tangxu
2023-04-12 ac2a648ea67669eab6de9a1864c07f6475511dd2
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
73
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(() =>
            {
                //获取MiddleLib配置
                var dataMap = context.MergedJobDataMap;
                var configure = (Model.DataDockingConfigureExMiddleLib)dataMap[ConfigureTagName];
                if (configure == null)
                    return;
                try
                {
                    if (configure.Mappers == null || configure.Mappers.Count < 1)
                    {
                        LogHelper.Info($"中间库数据对接中:{configure.Name},未配置映射关系!");
                        return;
                    }
 
                    //创建对接对象
                    var dataDocking = DataDockingMiddleLibFactory.CreateMiddleLib<IDataDockingMiddleLib.IHandleHelper>(configure.ConfigureParas.DependencyFile);
                    if (dataDocking == null)
                    {
                        LogHelper.Info($"中间库数据对接中:{configure.Name} ,创建对接对象失败!");
                        return;
                    }
                    dataDocking.HandleData(configure.Mappers, (receive_list) =>
                    {
                        if (receive_list == null || receive_list.Count < 1)
                        {
                            LogHelper.Info($"中间库数据对接中:{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($"中间库数据对接中:{configure.Name},成功推入通道{receive_list.Count}条数据!");
                    });
 
 
 
                }
                catch (Exception ex)
                {
                    LogHelper.Error($"中间数据库对接,任务执行出错,配置名称:{configure.Name}!", ex);
                    var e = new JobExecutionException(ex);
                    throw e;
                }
            });
 
 
        }
 
 
 
    }
}