ningshuxia
2022-08-19 153da1eef16b51d75442779a3964a1c5413132e4
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IStation.Calculation;
 
namespace IStation.Server
{
    /// <Standardmary>
    /// 能效标准业务日计划任务
    /// </Standardmary>
    [DisallowConcurrentExecution]//此特性标识 必须等待这次任务执行完成后,才能执行下次任务
    public class EtaStandardLogicDayCronJob : IJob
    {
        /// <Standardmary>
        /// 
        /// </Standardmary>
        public Task Execute(IJobExecutionContext context)
        {
            return Task.Run(() =>
            {
                try
                {
 
                    #region 标准日期
 
                    var day = DateTime.Now.AddDays(-1).Date;
 
                    #endregion
 
                    #region 加载目标客户
 
                    var corpIds = CorpHelper.GetCorpIds();
                    if (corpIds == null || corpIds.Count < 1)
                    {
                        LogHelper.Info("能效标准业务日计划任务中,未检索到目标客户信息");
                        return;
                    }
 
                    #endregion
 
                    #region 加载配置
 
                    var service_configure = new Service.EtaAnalyConfigure();
                    var configure_list = service_configure.GetByCorpIds(corpIds);
                    if (configure_list == null || configure_list.Count < 1)
                    {
                        LogHelper.Info("能效标准业务日计划任务中,未检索到能效分析配置信息!");
                        return;
                    }
                    configure_list = configure_list.Where(x => x.UseStatus == Model.eUseStatus.Enable).ToList();
                    if (configure_list.Count < 1)
                    {
                        LogHelper.Info("能效标准业务日计划任务中,未检索到有效能效分析配置信息!");
                        return;
                    }
 
                    #endregion
 
                    #region 遍历标准
 
                    foreach (var configure in configure_list)
                    {
                        var standard_configure_list=new Service.EtaStandardConfigure().GetByCorpID(configure.CorpID);
                        if (standard_configure_list == null || standard_configure_list.Count < 1)
                            continue;
                        var record_list = new Service.EtaLogicRealRecord().GetByCorpIDOfDay(configure.CorpID, day);
                        if (record_list == null || record_list.Count < 1)
                            continue;
                        var group_list = record_list.GroupBy(x => new { x.CorpID, x.ObjectType, x.ObjectID }).ToList();
                        var standard_record_list = new List<Model.EtaStandardLogicDayRecord>();
                        foreach (var group in group_list)
                        {
                            var standard_record = EtaStandardLogicDayHelper.Standard(group.Key.CorpID, group.Key.ObjectType, group.Key.ObjectID, day,standard_configure_list, group);
                            if (standard_record != null )
                            {
                                standard_record_list.AddRange(standard_record);
                            }
                        }
                        if (standard_record_list.Count < 1)
                            continue;
                        var bol = new Service.EtaStandardLogicRecord().Inserts(standard_record_list);
                        if (!bol)
                        {
                            LogHelper.Info("能效标准业务日计划任务中,数据保存失败!");
                            return;
                        }
                    }
 
                    #endregion
 
 
 
                }
                catch (Exception ex)
                {
                    LogHelper.Error("能效标准业务日计划任务中,出错", ex);
                    var e = new JobExecutionException(ex);
                    throw e;
                }
            });
        }
    }
}