|
|
|
|
@@ -13,13 +13,18 @@ import com.njcn.gather.system.log.pojo.param.SysLogParam;
|
|
|
|
|
import com.njcn.gather.system.log.pojo.po.SysLogAudit;
|
|
|
|
|
import com.njcn.gather.system.log.service.ISysLogAuditService;
|
|
|
|
|
import com.njcn.gather.system.log.util.CSVUtil;
|
|
|
|
|
import com.njcn.gather.user.user.service.ISysUserService;
|
|
|
|
|
import com.njcn.web.factory.PageFactory;
|
|
|
|
|
import com.njcn.web.utils.HttpServletUtil;
|
|
|
|
|
import com.njcn.web.utils.RequestUtil;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.poi.ss.usermodel.ClientAnchor;
|
|
|
|
|
import org.apache.poi.xddf.usermodel.chart.*;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFChart;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFDrawing;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieSer;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
@@ -53,7 +58,8 @@ public class SysLogAuditServiceImpl extends ServiceImpl<SysLogAuditMapper, SysLo
|
|
|
|
|
.like(StrUtil.isNotBlank(param.getCreateBy()), "sys_log_audit.Create_By", param.getCreateBy())
|
|
|
|
|
.between(StrUtil.isAllNotBlank(param.getSearchBeginTime(), param.getSearchEndTime()), "sys_log_audit.Create_Time", param.getSearchBeginTime(), param.getSearchEndTime());
|
|
|
|
|
}
|
|
|
|
|
queryWrapper.orderByDesc("sys_log_audit.Sort");
|
|
|
|
|
queryWrapper.orderByDesc("sys_log_audit.Sort")
|
|
|
|
|
.orderByDesc("sys_log_audit.Create_Time");
|
|
|
|
|
return this.page(new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param)), queryWrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -142,12 +148,12 @@ public class SysLogAuditServiceImpl extends ServiceImpl<SysLogAuditMapper, SysLo
|
|
|
|
|
.between(StrUtil.isAllNotBlank(param.getSearchBeginTime(), param.getSearchEndTime()), "sys_log_audit.Create_Time", param.getSearchBeginTime(), param.getSearchEndTime());
|
|
|
|
|
}
|
|
|
|
|
List<SysLogAudit> list = this.list(queryWrapper);
|
|
|
|
|
Map<String, List<SysLogAudit>> collect = list.stream().collect(Collectors.groupingBy(SysLogAudit::getCreateBy, Collectors.toList()));
|
|
|
|
|
Map<String, Long> collect = list.stream().collect(Collectors.groupingBy(SysLogAudit::getCreateBy, Collectors.counting()));
|
|
|
|
|
|
|
|
|
|
this.exportAnalyseExcel("分析结果", collect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void exportAnalyseExcel(String fileName, Map<String, List<SysLogAudit>> collect) {
|
|
|
|
|
private void exportAnalyseExcel(String fileName, Map<String, Long> collect) {
|
|
|
|
|
HttpServletResponse response = HttpServletUtil.getResponse();
|
|
|
|
|
XSSFWorkbook wb = new XSSFWorkbook();
|
|
|
|
|
|
|
|
|
|
@@ -157,7 +163,9 @@ public class SysLogAuditServiceImpl extends ServiceImpl<SysLogAuditMapper, SysLo
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
|
|
|
|
response.setContentType("application/octet-stream;charset=UTF-8");
|
|
|
|
|
|
|
|
|
|
XSSFSheet sheet = wb.createSheet("sheet1");
|
|
|
|
|
|
|
|
|
|
createPieChart(sheet, collect.keySet().stream().collect(Collectors.toList()), collect.values().stream().collect(Collectors.toList()));
|
|
|
|
|
|
|
|
|
|
wb.write(outputStream);
|
|
|
|
|
wb.close();
|
|
|
|
|
@@ -165,4 +173,96 @@ public class SysLogAuditServiceImpl extends ServiceImpl<SysLogAuditMapper, SysLo
|
|
|
|
|
log.error(">>> 导出数据异常:{}", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建饼图
|
|
|
|
|
*
|
|
|
|
|
* @param sheet
|
|
|
|
|
* @param categoryList
|
|
|
|
|
* @param sheetDataList
|
|
|
|
|
*/
|
|
|
|
|
private void createPieChart(XSSFSheet sheet, List<String> categoryList, List<Long> sheetDataList) {
|
|
|
|
|
int row1 = 0;
|
|
|
|
|
int row2 = 8;
|
|
|
|
|
int col1 = 0;
|
|
|
|
|
int col2 = 30;
|
|
|
|
|
// 设置图表列宽
|
|
|
|
|
for (int i = 0; i < row2; i++) {
|
|
|
|
|
sheet.setColumnWidth(i, 6000);
|
|
|
|
|
}
|
|
|
|
|
//y轴显示数据
|
|
|
|
|
String[] headArray = categoryList.stream().collect(Collectors.toList()).toArray(new String[]{});
|
|
|
|
|
|
|
|
|
|
// Create a chart
|
|
|
|
|
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
|
|
|
|
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, col1, row1, row2, col2);
|
|
|
|
|
XSSFChart chart = drawing.createChart(anchor);
|
|
|
|
|
//标题是否覆盖图表
|
|
|
|
|
chart.setTitleOverlay(false);
|
|
|
|
|
//设置图表标题
|
|
|
|
|
chart.setTitleText("分析结果");
|
|
|
|
|
// 创建图表系列
|
|
|
|
|
XDDFChartLegend legend = chart.getOrAddLegend();
|
|
|
|
|
legend.setPosition(LegendPosition.TOP);
|
|
|
|
|
|
|
|
|
|
//动态数据
|
|
|
|
|
//x轴数据
|
|
|
|
|
XDDFDataSource<String> xData = XDDFDataSourcesFactory.fromArray(headArray);
|
|
|
|
|
//饼图数据
|
|
|
|
|
XDDFPieChartData data = (XDDFPieChartData) chart.createData(ChartTypes.PIE, null, null);
|
|
|
|
|
data.setVaryColors(true);
|
|
|
|
|
|
|
|
|
|
Double[] yArray = sheetDataList.stream().collect(Collectors.toList()).toArray(new Double[]{});
|
|
|
|
|
//y轴数据
|
|
|
|
|
XDDFNumericalDataSource<Double> yData = XDDFDataSourcesFactory.fromArray(yArray);
|
|
|
|
|
XDDFChartData.Series series = data.addSeries(xData, yData);
|
|
|
|
|
|
|
|
|
|
//series.setTitle("title", null);
|
|
|
|
|
series.setShowLeaderLines(true);
|
|
|
|
|
// 隐藏图例标识、系列名称、分类名称和数值
|
|
|
|
|
XDDFPieChartData.Series s = (XDDFPieChartData.Series) series;
|
|
|
|
|
CTPieSer ctPieSer = s.getCTPieSer();
|
|
|
|
|
showCateName(ctPieSer, false);
|
|
|
|
|
showVal(ctPieSer, false);
|
|
|
|
|
showLegendKey(ctPieSer, false);
|
|
|
|
|
showSerName(ctPieSer, false);
|
|
|
|
|
|
|
|
|
|
chart.plot(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 控制值系列名称是否显示
|
|
|
|
|
private void showSerName(CTPieSer series, boolean val) {
|
|
|
|
|
if (series.getDLbls().isSetShowSerName()) {
|
|
|
|
|
series.getDLbls().getShowSerName().setVal(val);
|
|
|
|
|
} else {
|
|
|
|
|
series.getDLbls().addNewShowSerName().setVal(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 控制分类名称是否显示
|
|
|
|
|
private void showCateName(CTPieSer series, boolean val) {
|
|
|
|
|
if (series.getDLbls().isSetShowCatName()) {
|
|
|
|
|
series.getDLbls().getShowCatName().setVal(val);
|
|
|
|
|
} else {
|
|
|
|
|
series.getDLbls().addNewShowCatName().setVal(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 控制值是否显示
|
|
|
|
|
private void showVal(CTPieSer series, boolean val) {
|
|
|
|
|
if (series.getDLbls().isSetShowVal()) {
|
|
|
|
|
series.getDLbls().getShowVal().setVal(val);
|
|
|
|
|
} else {
|
|
|
|
|
series.getDLbls().addNewShowVal().setVal(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 控制图例标识是否显示
|
|
|
|
|
private void showLegendKey(CTPieSer series, boolean val) {
|
|
|
|
|
if (series.getDLbls().isSetShowLegendKey()) {
|
|
|
|
|
series.getDLbls().getShowLegendKey().setVal(val);
|
|
|
|
|
} else {
|
|
|
|
|
series.getDLbls().addNewShowLegendKey().setVal(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|