Timedtask.java
5.13 KB
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
107
108
109
110
111
112
113
package com.hui.iqiyi.schedule;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.hui.iqiyi.Util.MailUtil;
import com.hui.iqiyi.excel.*;
import com.hui.iqiyi.request.ProRequest;
import com.hui.iqiyi.response.ContentResponse;
import com.hui.iqiyi.response.ProgramSyResponse;
import com.hui.iqiyi.service.IMovieService;
import com.hui.iqiyi.service.IProgramService;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@Component//注入bean
public class Timedtask {
@Autowired
private IMovieService iMovieService;
@Autowired
private IProgramService iProgramService;
@Value("${recievers.shoujianren}")
private String Youxiang;
@Value("${filePath}")
private String path;
//添加定时任务
//@Scheduled(cron = "0 20 16 * * 5 ")//每周五16时20分发送
//@Scheduled(cron = "0/5 * * * * ?")
public void Timedtask() {
try {
//新建ExcelWriter
ExcelWriter excelWriter = EasyExcel.write(path).build();
//获取sheet0对象
WriteSheet mainSheet = EasyExcel.writerSheet(0, "介质文件下载统计文件").head(DownloadExcel.class).build();
//向sheet0写入数据 传入空list这样只导出表头
excelWriter.write(iMovieService.selectAllPopulation(), mainSheet);
//获取sheet1对象
WriteSheet detailSheet = EasyExcel.writerSheet(1, "吉林关注片单").head(ProgramsExcel.class).build();
//向sheet1写入数据 传入空list这样只导出表头
List<ProgramSyResponse> programSyResponses = new ArrayList<>();
programSyResponses.add(iProgramService.selectAllProgramCount());
excelWriter.write(programSyResponses, detailSheet);
//获取sheet1对象
WriteSheet detailSheet1 = EasyExcel.writerSheet(2, "剧集单片数量").head(ProgramAllExcel.class).build();
//向sheet1写入数据 传入空list这样只导出表头
List<ContentResponse> contentResponses = new ArrayList<>();
contentResponses.add(iProgramService.selectAllPrograms());
excelWriter.write(contentResponses, detailSheet1);
//获取sheet2对象
WriteSheet SevenSheetDownload = EasyExcel.writerSheet(3, "近七日下载情况").head(ProsevenDownload.class).build();
//向sheet0写入数据 传入空list这样只导出表头
ProRequest proRequest = new ProRequest();
excelWriter.write(iProgramService.selectAllSeven(proRequest), SevenSheetDownload);
//获取sheet2对象
WriteSheet SevenSheetzation = EasyExcel.writerSheet(4, "近七日同步情况").head(MoveExcel.class).build();
//向sheet0写入数据 传入空list这样只导出表头
ProRequest proRequest1 = new ProRequest();
excelWriter.write(iMovieService.selectAllSevenxz(proRequest1), SevenSheetzation);
//关闭流
excelWriter.finish();
try {
//接收人放到配置文件里
//String to="2292269071@qq.com";
File file = new File(path);
MailUtil.sendText(Youxiang ,"爱奇艺统计", "各位好:\n" +
" 截止至 2021-06-15日 爱奇艺同步下载统计如下\n" +
" 剧集数量:25122 部;\n" +
" 单片数量:194412部;\n" +
" 介质下载 数量:280982集\n" +
" 容量:1678.34G\n" +
" 时长:21624小时\n" +
" 下载速度 大约 5 M/h\n" +
" 吉林片单中 :\n" +
" 剧集:158部\n" +
" 单片:118部\n" +
" 已下载数量:6505集\n" +
" 已下载容量:1252G\n" +
" 已下载时长:1610小时\n" +
" 未下载数量:6525集\n" +
" 未同步数量:6525集\n" +
" \n" +
" 预计容量:1359G\n" +
" 预计时长:2062小时\n" +
" 预计需要下载时间:10天\n" +
"\n" +
"详情见以下附件:", file);
} catch (Exception e) {
System.out.println("发送邮件失败{}"+ e.getMessage());
}
} catch (Exception e) {
System.out.println("导出异常"+ e.getMessage());
}
}
}