添加了导出excel并发送邮件功能
修改了查询全部
Showing
11 changed files
with
308 additions
and
63 deletions
This diff is collapsed.
Click to expand it.
1 | package com.hui.iqiyi.Util; | ||
2 | |||
3 | import java.io.File; | ||
4 | import java.io.InputStream; | ||
5 | |||
6 | public class TestFileUtil { | ||
7 | |||
8 | |||
9 | public static InputStream getResourcesFileInputStream(String fileName) { | ||
10 | return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName); | ||
11 | } | ||
12 | |||
13 | public static String getPath() { | ||
14 | return TestFileUtil.class.getResource("/").getPath(); | ||
15 | } | ||
16 | |||
17 | public static File createNewFile(String pathName) { | ||
18 | File file = new File(getPath() + pathName); | ||
19 | if (file.exists()) { | ||
20 | file.delete(); | ||
21 | } else { | ||
22 | if (!file.getParentFile().exists()) { | ||
23 | file.getParentFile().mkdirs(); | ||
24 | } | ||
25 | } | ||
26 | return file; | ||
27 | } | ||
28 | |||
29 | public static File readFile(String pathName) { | ||
30 | return new File(getPath() + pathName); | ||
31 | } | ||
32 | |||
33 | public static File readUserHomeFile(String pathName) { | ||
34 | return new File(System.getProperty("user.home") + File.separator + pathName); | ||
35 | } | ||
36 | } |
1 | package com.hui.iqiyi.controller; | 1 | package com.hui.iqiyi.controller; |
2 | 2 | ||
3 | 3 | ||
4 | import com.alibaba.excel.EasyExcel; | ||
5 | import com.alibaba.excel.ExcelWriter; | ||
6 | import com.alibaba.excel.write.metadata.WriteSheet; | ||
7 | import com.alibaba.excel.write.metadata.style.WriteCellStyle; | ||
8 | import com.github.pagehelper.PageHelper; | ||
9 | import com.github.pagehelper.PageInfo; | ||
10 | import com.hui.iqiyi.Util.TestFileUtil; | ||
11 | import com.hui.iqiyi.entity.Content; | ||
12 | import com.hui.iqiyi.entity.Movie; | 4 | import com.hui.iqiyi.entity.Movie; |
13 | import com.hui.iqiyi.excel.*; | ||
14 | import com.hui.iqiyi.request.ContentRequest; | ||
15 | import com.hui.iqiyi.request.ProRequest; | 5 | import com.hui.iqiyi.request.ProRequest; |
16 | import com.hui.iqiyi.response.ContentResponse; | ||
17 | import com.hui.iqiyi.response.MovieResponse; | 6 | import com.hui.iqiyi.response.MovieResponse; |
18 | import com.hui.iqiyi.response.ProgramSyResponse; | ||
19 | import com.hui.iqiyi.service.IMovieService; | 7 | import com.hui.iqiyi.service.IMovieService; |
20 | import com.hui.iqiyi.service.IProgramService; | 8 | import com.hui.iqiyi.service.IProgramService; |
21 | import io.swagger.annotations.Api; | 9 | import io.swagger.annotations.Api; |
22 | import io.swagger.annotations.ApiOperation; | 10 | import io.swagger.annotations.ApiOperation; |
23 | import org.apache.poi.ss.usermodel.HorizontalAlignment; | ||
24 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
25 | import org.springframework.web.bind.annotation.*; | 12 | import org.springframework.web.bind.annotation.*; |
26 | import org.testng.collections.Lists; | ||
27 | |||
28 | import javax.annotation.Resource; | 13 | import javax.annotation.Resource; |
29 | import java.util.ArrayList; | ||
30 | import java.util.List; | 14 | import java.util.List; |
31 | import java.util.Map; | 15 | |
32 | 16 | ||
33 | /** | 17 | /** |
34 | * <p> | 18 | * <p> |
... | @@ -56,52 +40,6 @@ public class MovieController { | ... | @@ -56,52 +40,6 @@ public class MovieController { |
56 | return iMovieService.selectAllPopulation(); | 40 | return iMovieService.selectAllPopulation(); |
57 | } | 41 | } |
58 | 42 | ||
59 | // @GetMapping("/selectAllPopulationn") | ||
60 | // @ApiOperation("查询总下载") | ||
61 | // @ResponseBody | ||
62 | // public void selectAllPopulationn(Movie Movie) { | ||
63 | // | ||
64 | // try { | ||
65 | // String path = "D:\\java\\爱奇艺下载情况.xlsx\\"; | ||
66 | // //新建ExcelWriter | ||
67 | // ExcelWriter excelWriter = EasyExcel.write(path).build(); | ||
68 | // //获取sheet0对象 | ||
69 | // WriteSheet mainSheet = EasyExcel.writerSheet(0, "介质文件下载统计文件").head(DownloadExcel.class).build(); | ||
70 | // //向sheet0写入数据 传入空list这样只导出表头 | ||
71 | // excelWriter.write(iMovieService.selectAllPopulation(), mainSheet); | ||
72 | // | ||
73 | // //获取sheet1对象 | ||
74 | // WriteSheet detailSheet = EasyExcel.writerSheet(1, "吉林关注片单").head(ProgramsExcel.class).build(); | ||
75 | // //向sheet1写入数据 传入空list这样只导出表头 | ||
76 | // List<ProgramSyResponse> programSyResponses = new ArrayList<>(); | ||
77 | // programSyResponses.add(iProgramService.selectAllProgramCount()); | ||
78 | // excelWriter.write(programSyResponses, detailSheet); | ||
79 | // | ||
80 | // //获取sheet1对象 | ||
81 | // WriteSheet detailSheet1 = EasyExcel.writerSheet(2, "剧集单片数量").head(ProgramAllExcel.class).build(); | ||
82 | // //向sheet1写入数据 传入空list这样只导出表头 | ||
83 | // List<ContentResponse> contentResponses = new ArrayList<>(); | ||
84 | // contentResponses.add(iProgramService.selectAllPrograms()); | ||
85 | // excelWriter.write(contentResponses, detailSheet1); | ||
86 | // | ||
87 | // //获取sheet2对象 | ||
88 | // WriteSheet SevenSheetDownload = EasyExcel.writerSheet(3, "近七日下载情况").head(ProsevenDownload.class).build(); | ||
89 | // //向sheet0写入数据 传入空list这样只导出表头 | ||
90 | // ProRequest proRequest = new ProRequest(); | ||
91 | // excelWriter.write(iProgramService.selectAllSeven(proRequest), SevenSheetDownload); | ||
92 | // | ||
93 | // //获取sheet2对象 | ||
94 | // WriteSheet SevenSheetzation= EasyExcel.writerSheet(4, "近七日同步情况").head(MoveExcel.class).build(); | ||
95 | // //向sheet0写入数据 传入空list这样只导出表头 | ||
96 | // ProRequest proRequest1 = new ProRequest(); | ||
97 | // excelWriter.write(iMovieService.selectAllSevenxz(proRequest1), SevenSheetzation); | ||
98 | // //关闭流 | ||
99 | // excelWriter.finish(); | ||
100 | // } catch (Exception e) { | ||
101 | // System.out.println("导出异常"+ e.getMessage()); | ||
102 | // } | ||
103 | // } | ||
104 | |||
105 | @GetMapping("/selectAllSevenXz") | 43 | @GetMapping("/selectAllSevenXz") |
106 | @ApiOperation("近七日同步情况") | 44 | @ApiOperation("近七日同步情况") |
107 | @ResponseBody | 45 | @ResponseBody | ... | ... |
1 | package com.hui.iqiyi.excel; | ||
2 | |||
3 | import com.alibaba.excel.annotation.ExcelProperty; | ||
4 | import com.alibaba.excel.annotation.write.style.ColumnWidth; | ||
5 | import com.alibaba.excel.annotation.write.style.ContentStyle; | ||
6 | import com.alibaba.excel.annotation.write.style.HeadStyle; | ||
7 | import lombok.Data; | ||
8 | import org.apache.poi.ss.usermodel.HorizontalAlignment; | ||
9 | |||
10 | @Data | ||
11 | @HeadStyle(horizontalAlignment = HorizontalAlignment.CENTER)//表头样式 | ||
12 | @ContentStyle(horizontalAlignment = HorizontalAlignment.CENTER)//内容样式 | ||
13 | @ColumnWidth(20)//表头宽度 | ||
14 | public class DownloadExcel { | ||
15 | @ExcelProperty("下载情况") | ||
16 | private String localStatuss; | ||
17 | @ExcelProperty("下载数量") | ||
18 | private Long number; | ||
19 | @ExcelProperty("下载容量") | ||
20 | private Long capacity; | ||
21 | @ExcelProperty("下载时长") | ||
22 | private Integer duration; | ||
23 | |||
24 | } |
1 | package com.hui.iqiyi.excel; | ||
2 | |||
3 | import com.alibaba.excel.annotation.ExcelProperty; | ||
4 | import com.alibaba.excel.annotation.write.style.ColumnWidth; | ||
5 | import com.alibaba.excel.annotation.write.style.ContentStyle; | ||
6 | import com.alibaba.excel.annotation.write.style.HeadStyle; | ||
7 | import lombok.Data; | ||
8 | import org.apache.poi.ss.usermodel.HorizontalAlignment; | ||
9 | |||
10 | import java.util.Date; | ||
11 | |||
12 | @Data | ||
13 | @HeadStyle(horizontalAlignment = HorizontalAlignment.CENTER)//表头样式 | ||
14 | @ContentStyle(horizontalAlignment = HorizontalAlignment.CENTER)//内容样式 | ||
15 | @ColumnWidth(20)//表头宽度 | ||
16 | public class MoveExcel { | ||
17 | |||
18 | @ExcelProperty("日期") | ||
19 | private String day1; | ||
20 | @ExcelProperty("节目同步数量") | ||
21 | private Long totlFee3; | ||
22 | @ExcelProperty("下载容量") | ||
23 | private Double totlSize2; | ||
24 | @ExcelProperty("下载时长") | ||
25 | private Double totlDuration4; | ||
26 | } |
1 | package com.hui.iqiyi.excel; | ||
2 | |||
3 | import com.alibaba.excel.annotation.ExcelProperty; | ||
4 | import com.alibaba.excel.annotation.write.style.ColumnWidth; | ||
5 | import com.alibaba.excel.annotation.write.style.ContentStyle; | ||
6 | import com.alibaba.excel.annotation.write.style.HeadStyle; | ||
7 | import lombok.Data; | ||
8 | import org.apache.poi.ss.usermodel.HorizontalAlignment; | ||
9 | |||
10 | @Data | ||
11 | @HeadStyle(horizontalAlignment = HorizontalAlignment.CENTER)//表头样式 | ||
12 | @ContentStyle(horizontalAlignment = HorizontalAlignment.CENTER)//内容样式 | ||
13 | @ColumnWidth(20)//表头宽度 | ||
14 | public class ProgramAllExcel { | ||
15 | @ExcelProperty("剧集数量") | ||
16 | private Integer drama; | ||
17 | @ExcelProperty("单片数量") | ||
18 | private Integer monolithic; | ||
19 | } |
1 | package com.hui.iqiyi.excel; | ||
2 | |||
3 | import com.alibaba.excel.annotation.ExcelProperty; | ||
4 | import com.alibaba.excel.annotation.write.style.ColumnWidth; | ||
5 | import com.alibaba.excel.annotation.write.style.ContentStyle; | ||
6 | import com.alibaba.excel.annotation.write.style.HeadStyle; | ||
7 | import lombok.Data; | ||
8 | import org.apache.poi.ss.usermodel.HorizontalAlignment; | ||
9 | |||
10 | @Data | ||
11 | @HeadStyle(horizontalAlignment = HorizontalAlignment.CENTER)//表头样式 | ||
12 | @ContentStyle(horizontalAlignment = HorizontalAlignment.CENTER)//内容样式 | ||
13 | @ColumnWidth(20)//表头宽度 | ||
14 | public class ProgramsExcel { | ||
15 | //剧集 | ||
16 | @ExcelProperty("剧集数量") | ||
17 | private Integer drama; | ||
18 | //单片 | ||
19 | @ExcelProperty("单片数量") | ||
20 | private Integer monolithic; | ||
21 | //下载数量 | ||
22 | @ExcelProperty("已下载数量") | ||
23 | private Long xzNumbe; | ||
24 | //下载容量 | ||
25 | @ExcelProperty("已下载容量(G)") | ||
26 | private Double xzSize; | ||
27 | //下载时长 | ||
28 | @ExcelProperty("已下载时长") | ||
29 | private Double totlDuration; | ||
30 | //下载失败的数量 | ||
31 | @ExcelProperty("下载失败数量") | ||
32 | private Long failSum; | ||
33 | //同步未下载数量 | ||
34 | @ExcelProperty("同步未下载数量") | ||
35 | private Long totlSize; | ||
36 | //未同步介质数量 | ||
37 | @ExcelProperty("未同步介质数量") | ||
38 | private Long totlFee; | ||
39 | } |
1 | package com.hui.iqiyi.excel; | ||
2 | |||
3 | import com.alibaba.excel.annotation.ExcelProperty; | ||
4 | import com.alibaba.excel.annotation.write.style.ColumnWidth; | ||
5 | import com.alibaba.excel.annotation.write.style.ContentStyle; | ||
6 | import com.alibaba.excel.annotation.write.style.HeadStyle; | ||
7 | import lombok.Data; | ||
8 | import org.apache.poi.ss.usermodel.HorizontalAlignment; | ||
9 | |||
10 | @Data | ||
11 | @HeadStyle(horizontalAlignment = HorizontalAlignment.CENTER)//表头样式 | ||
12 | @ContentStyle(horizontalAlignment = HorizontalAlignment.CENTER)//内容样式 | ||
13 | @ColumnWidth(20)//表头宽度 | ||
14 | public class ProsevenDownload { | ||
15 | |||
16 | @ExcelProperty("日期") | ||
17 | private String day; | ||
18 | @ExcelProperty("已下载数量") | ||
19 | private Long totlFee; | ||
20 | @ExcelProperty("已下载容量(G)") | ||
21 | private Double totlSize; | ||
22 | @ExcelProperty("已下载时长") | ||
23 | private Double totlDuration; | ||
24 | } |
1 | package com.hui.iqiyi.schedule; | ||
2 | |||
3 | import com.alibaba.excel.EasyExcel; | ||
4 | import com.alibaba.excel.ExcelWriter; | ||
5 | import com.alibaba.excel.write.metadata.WriteSheet; | ||
6 | import com.alibaba.excel.write.metadata.style.WriteCellStyle; | ||
7 | import com.hui.iqiyi.Util.MailUtil; | ||
8 | import com.hui.iqiyi.excel.*; | ||
9 | import com.hui.iqiyi.request.ProRequest; | ||
10 | import com.hui.iqiyi.response.ContentResponse; | ||
11 | import com.hui.iqiyi.response.ProgramSyResponse; | ||
12 | import com.hui.iqiyi.service.IMovieService; | ||
13 | import com.hui.iqiyi.service.IProgramService; | ||
14 | import org.apache.poi.ss.usermodel.HorizontalAlignment; | ||
15 | import org.springframework.beans.factory.annotation.Autowired; | ||
16 | import org.springframework.beans.factory.annotation.Value; | ||
17 | import org.springframework.scheduling.annotation.Scheduled; | ||
18 | import org.springframework.stereotype.Component; | ||
19 | |||
20 | import java.io.File; | ||
21 | import java.util.ArrayList; | ||
22 | import java.util.List; | ||
23 | |||
24 | @Component//注入bean | ||
25 | public class Timedtask { | ||
26 | |||
27 | @Autowired | ||
28 | private IMovieService iMovieService; | ||
29 | |||
30 | @Autowired | ||
31 | private IProgramService iProgramService; | ||
32 | |||
33 | @Value("${recievers.shoujianren}") | ||
34 | private String Youxiang; | ||
35 | |||
36 | @Value("${filePath}") | ||
37 | private String path; | ||
38 | //添加定时任务 | ||
39 | //@Scheduled(cron = "0 20 16 * * 5 ")//每周五16时20分发送 | ||
40 | //@Scheduled(cron = "0/5 * * * * ?") | ||
41 | public void Timedtask() { | ||
42 | |||
43 | try { | ||
44 | |||
45 | //新建ExcelWriter | ||
46 | ExcelWriter excelWriter = EasyExcel.write(path).build(); | ||
47 | //获取sheet0对象 | ||
48 | WriteSheet mainSheet = EasyExcel.writerSheet(0, "介质文件下载统计文件").head(DownloadExcel.class).build(); | ||
49 | //向sheet0写入数据 传入空list这样只导出表头 | ||
50 | excelWriter.write(iMovieService.selectAllPopulation(), mainSheet); | ||
51 | |||
52 | //获取sheet1对象 | ||
53 | WriteSheet detailSheet = EasyExcel.writerSheet(1, "吉林关注片单").head(ProgramsExcel.class).build(); | ||
54 | //向sheet1写入数据 传入空list这样只导出表头 | ||
55 | List<ProgramSyResponse> programSyResponses = new ArrayList<>(); | ||
56 | programSyResponses.add(iProgramService.selectAllProgramCount()); | ||
57 | excelWriter.write(programSyResponses, detailSheet); | ||
58 | //获取sheet1对象 | ||
59 | WriteSheet detailSheet1 = EasyExcel.writerSheet(2, "剧集单片数量").head(ProgramAllExcel.class).build(); | ||
60 | //向sheet1写入数据 传入空list这样只导出表头 | ||
61 | List<ContentResponse> contentResponses = new ArrayList<>(); | ||
62 | contentResponses.add(iProgramService.selectAllPrograms()); | ||
63 | excelWriter.write(contentResponses, detailSheet1); | ||
64 | |||
65 | //获取sheet2对象 | ||
66 | WriteSheet SevenSheetDownload = EasyExcel.writerSheet(3, "近七日下载情况").head(ProsevenDownload.class).build(); | ||
67 | //向sheet0写入数据 传入空list这样只导出表头 | ||
68 | ProRequest proRequest = new ProRequest(); | ||
69 | excelWriter.write(iProgramService.selectAllSeven(proRequest), SevenSheetDownload); | ||
70 | |||
71 | //获取sheet2对象 | ||
72 | WriteSheet SevenSheetzation = EasyExcel.writerSheet(4, "近七日同步情况").head(MoveExcel.class).build(); | ||
73 | //向sheet0写入数据 传入空list这样只导出表头 | ||
74 | ProRequest proRequest1 = new ProRequest(); | ||
75 | excelWriter.write(iMovieService.selectAllSevenxz(proRequest1), SevenSheetzation); | ||
76 | //关闭流 | ||
77 | excelWriter.finish(); | ||
78 | try { | ||
79 | //接收人放到配置文件里 | ||
80 | //String to="2292269071@qq.com"; | ||
81 | File file = new File(path); | ||
82 | MailUtil.sendText(Youxiang ,"爱奇艺统计", "各位好:\n" + | ||
83 | " 截止至 2021-06-15日 爱奇艺同步下载统计如下\n" + | ||
84 | " 剧集数量:25122 部;\n" + | ||
85 | " 单片数量:194412部;\n" + | ||
86 | " 介质下载 数量:280982集\n" + | ||
87 | " 容量:1678.34G\n" + | ||
88 | " 时长:21624小时\n" + | ||
89 | " 下载速度 大约 5 M/h\n" + | ||
90 | " 吉林片单中 :\n" + | ||
91 | " 剧集:158部\n" + | ||
92 | " 单片:118部\n" + | ||
93 | " 已下载数量:6505集\n" + | ||
94 | " 已下载容量:1252G\n" + | ||
95 | " 已下载时长:1610小时\n" + | ||
96 | " 未下载数量:6525集\n" + | ||
97 | " 未同步数量:6525集\n" + | ||
98 | " \n" + | ||
99 | " 预计容量:1359G\n" + | ||
100 | " 预计时长:2062小时\n" + | ||
101 | " 预计需要下载时间:10天\n" + | ||
102 | "\n" + | ||
103 | "详情见以下附件:", file); | ||
104 | } catch (Exception e) { | ||
105 | System.out.println("发送邮件失败{}"+ e.getMessage()); | ||
106 | } | ||
107 | } catch (Exception e) { | ||
108 | System.out.println("导出异常"+ e.getMessage()); | ||
109 | } | ||
110 | |||
111 | |||
112 | } | ||
113 | } |
-
Please register or sign in to post a comment