tangxu
2023-04-21 473084031d410d95db66e81f4d1761f9a2d1b8e5
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
using IStation.DataDockingSocket;
using IStation.Untity;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
 
namespace IStation.Server
{
    /// <summary>
    /// 用户登录日志报表任务
    /// </summary>
    [DisallowConcurrentExecution]//此特性标识 必须等待这次任务执行完成后,才能执行下次任务
    public class UserLoginLogReportJob : IJob
    {
        /// <summary>
        /// 
        /// </summary>
        public Task Execute(IJobExecutionContext context)
        {
            var otherDay = DateTime.Today.AddDays(-AppParasHelper.UserLoginLog.OtherDay);
            return Task.Run(() =>
            {
                try
                {
                    try
                    {
                        LogHelper.Info("调用API");
                        var url = $" {AppParasHelper.UserLoginLog.GenerateUrl}{otherDay}";
                        var responseText = HttpRequestHelper.Post(url);
                        var result = JsonHelper.Json2Object<Result>(responseText);
                        if (result.Code != 0)
                        {
                            throw new Exception(result.Message);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error(ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error($"用户登陆日志统计,保存{otherDay.ToString("d")}数据出错", ex);
                    var e = new JobExecutionException(ex);
                    throw e;
                }
            });
        }
    }
}