修复漏洞问题
This commit is contained in:
parent
29f7075079
commit
76d3f3083d
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-api</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-common</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,12 @@ import com.bonus.common.core.utils.poi.ExcelHandlerAdapter;
|
|||
@Target(ElementType.FIELD)
|
||||
public @interface Excel
|
||||
{
|
||||
/**
|
||||
* 是否是序号
|
||||
* @return
|
||||
*/
|
||||
public boolean isSequence() default false;
|
||||
|
||||
/**
|
||||
* 导出时在excel中排序
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package com.bonus.common.core.utils.poi;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
|
|
@ -20,6 +22,8 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.RegExUtils;
|
||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||
|
|
@ -580,6 +584,7 @@ public class ExcelUtil<T>
|
|||
int startNo = index * SHEETSIZE;
|
||||
int endNo = Math.min(startNo + SHEETSIZE, list.size());
|
||||
int rowNo = (1 + rownum) - startNo;
|
||||
int sequence=1;
|
||||
for (int i = startNo; i < endNo; i++)
|
||||
{
|
||||
rowNo = isSubList() ? (i > 1 ? rowNo + 1 : rowNo + i) : i + 1 + rownum - startNo;
|
||||
|
|
@ -623,7 +628,7 @@ public class ExcelUtil<T>
|
|||
{
|
||||
subField.setAccessible(true);
|
||||
Excel attr = subField.getAnnotation(Excel.class);
|
||||
this.addCell(attr, row, (T) obj, subField, column + subIndex);
|
||||
this.addCell(attr, row, (T) obj, subField, column + subIndex,sequence);
|
||||
}
|
||||
subIndex++;
|
||||
}
|
||||
|
|
@ -633,9 +638,10 @@ public class ExcelUtil<T>
|
|||
}
|
||||
else
|
||||
{
|
||||
this.addCell(excel, row, vo, field, column++);
|
||||
this.addCell(excel, row, vo, field, column++,sequence);
|
||||
}
|
||||
}
|
||||
sequence++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -932,7 +938,7 @@ public class ExcelUtil<T>
|
|||
/**
|
||||
* 添加单元格
|
||||
*/
|
||||
public Cell addCell(Excel attr, Row row, T vo, Field field, int column)
|
||||
public Cell addCell(Excel attr, Row row, T vo, Field field, int column, int sequence)
|
||||
{
|
||||
Cell cell = null;
|
||||
try
|
||||
|
|
@ -956,7 +962,11 @@ public class ExcelUtil<T>
|
|||
String dateFormat = attr.dateFormat();
|
||||
String readConverterExp = attr.readConverterExp();
|
||||
String separator = attr.separator();
|
||||
if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
||||
if(attr.isSequence()){
|
||||
cell.setCellValue(sequence);
|
||||
}
|
||||
|
||||
else if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
||||
{
|
||||
cell.setCellValue(parseDateToStr(dateFormat, value));
|
||||
}
|
||||
|
|
@ -1551,4 +1561,74 @@ public class ExcelUtil<T>
|
|||
}
|
||||
return method;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
* @param filePath 返回本地excel文件路径
|
||||
* @param list 导出数据集合
|
||||
* @param sheetName 工作表的名称
|
||||
* @param title 标题
|
||||
*/
|
||||
public AjaxResult exportExcelToLocalFile(String filePath, List<T> list, String sheetName, String title)
|
||||
{
|
||||
this.init(list, sheetName, title, Type.EXPORT);
|
||||
if (StringUtils.isNotBlank(filePath))
|
||||
return exportExcelToLocalFile(filePath);
|
||||
else
|
||||
return exportExcelToLocalFile(sheetName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导出到excel表单
|
||||
doNothing().when(excelUtil).init(null, sheetName, title, Type.EXPORT);
|
||||
doNothing().when(excelUtil).exportExcelToLocalFile(filePath);
|
||||
|
||||
// Act
|
||||
excelUtil.exportExcelToLocalFile(filePath, null, sheetName, title);
|
||||
|
||||
// Assert
|
||||
File file = new File(filePath);
|
||||
assertTrue(file.exists());
|
||||
|
||||
// Clean up
|
||||
file.delete();
|
||||
}
|
||||
|
||||
@Excel
|
||||
public static class User {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String sex;
|
||||
private Integer age;
|
||||
private Date birthday;
|
||||
|
||||
// Getters and Setters
|
||||
}
|
||||
}
|
||||
*/
|
||||
private AjaxResult exportExcelToLocalFile(String filePath)
|
||||
{
|
||||
OutputStream out = null;
|
||||
try
|
||||
{
|
||||
writeSheet();
|
||||
// 将文档写入文件
|
||||
out = new FileOutputStream(filePath);
|
||||
wb.write(out);
|
||||
System.out.println("excel document export successfully.");
|
||||
return AjaxResult.success(filePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("导出Excel异常{}", e.getMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(wb);
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
return AjaxResult.error("导出Excel失败,请联系网站管理员!");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
import org.apache.poi.util.Units;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class WordUtil {
|
||||
|
||||
private XWPFDocument document;
|
||||
|
||||
public WordUtil() {
|
||||
this.document = new XWPFDocument();
|
||||
}
|
||||
|
||||
// 创建段落
|
||||
public void addParagraph(String text, int fontSize) {
|
||||
XWPFParagraph paragraph = document.createParagraph();
|
||||
XWPFRun run = paragraph.createRun();
|
||||
run.setText(text);
|
||||
run.setFontSize(fontSize);
|
||||
}
|
||||
|
||||
// 插入图片
|
||||
public void insertImage(String imgFilePath, int width, int height) {
|
||||
try (InputStream is = new FileInputStream(imgFilePath)) {
|
||||
XWPFParagraph paragraph = document.createParagraph();
|
||||
XWPFRun run = paragraph.createRun();
|
||||
run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, imgFilePath, Units.toEMU(width), Units.toEMU(height));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 创建表格
|
||||
public void createTable(int rows, int cols) {
|
||||
XWPFTable table = document.createTable(rows, cols);
|
||||
for (int row = 0; row < rows; row++) {
|
||||
XWPFTableRow tableRow = table.getRow(row);
|
||||
for (int cell = 0; cell < cols; cell++) {
|
||||
XWPFTableCell tableCell = tableRow.getCell(cell);
|
||||
tableCell.setText("Row " + row + ", Cell " + cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 保存文档
|
||||
public void saveDocument(String filePath) {
|
||||
try (FileOutputStream out = new FileOutputStream(filePath)) {
|
||||
document.write(out);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭文档
|
||||
public void closeDocument() {
|
||||
try {
|
||||
document.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
WordUtil wordUtil = new WordUtil();
|
||||
wordUtil.addParagraph("这是一个段落。", 16);
|
||||
wordUtil.insertImage("path/to/image.png", 200, 200);
|
||||
wordUtil.createTable(3, 3);
|
||||
wordUtil.saveDocument("example.docx");
|
||||
wordUtil.closeDocument();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,5 @@
|
|||
package com.bonus.common.core.constant;
|
||||
|
||||
//import com.alibaba.nacos.common.JustForTest;
|
||||
//import com.bonus.common.core.utils.ServletUtils;
|
||||
//import com.bonus.common.core.utils.StringUtils;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import java.net.InetAddress;
|
||||
//import java.net.UnknownHostException;
|
||||
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.utils.ip.IpUtils;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,6 @@
|
|||
package com.bonus.common.core.utils.ip;
|
||||
|
||||
//import com.alibaba.nacos.common.JustForTest;
|
||||
//import com.bonus.common.core.utils.ServletUtils;
|
||||
//import com.bonus.common.core.utils.StringUtils;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import java.net.InetAddress;
|
||||
//import java.net.UnknownHostException;
|
||||
import com.bonus.common.core.utils.ip.IpUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package com.bonus.common.core.utils.poi;
|
||||
import com.bonus.common.core.utils.poi.ExcelUtil;
|
||||
import org.junit.Test;
|
||||
import com.bonus.common.core.annotation.Excel;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
public class ExcelUtilTests {
|
||||
@Test
|
||||
public void testImportExcel() {
|
||||
String currentPath = System.getProperty("user.dir");
|
||||
System.out.println("当前执行路径: " + currentPath);
|
||||
ExcelUtil excelUtil = new ExcelUtil<Person>(Person.class);
|
||||
currentPath +="/src/test/java/com/bonus/common/core/utils/poi/test.xlsx";
|
||||
try (FileInputStream fileInputStream = new FileInputStream(currentPath)) {
|
||||
List<Person> persionList = excelUtil.importExcel(fileInputStream);
|
||||
assertTrue(persionList.size() == 4);
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExportExcel() {
|
||||
String currentPath = System.getProperty("user.dir");
|
||||
System.out.println("当前执行路径: " + currentPath);
|
||||
ExcelUtil excelUtil = new ExcelUtil<Person>(Person.class);
|
||||
Person p1 = new Person("admin",10);
|
||||
Person p2 = new Person("admin2",20);
|
||||
|
||||
List <Person> personList = new ArrayList<>();
|
||||
personList.add(p1);
|
||||
personList.add(p2);
|
||||
currentPath +="/src/test/java/com/bonus/common/core/utils/poi/testExport.xlsx";
|
||||
excelUtil.exportExcelToLocalFile(currentPath,personList, "sheet1", null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.bonus.common.core.utils.poi;
|
||||
|
||||
import com.bonus.common.core.annotation.Excel;
|
||||
|
||||
public class Person {
|
||||
@Excel(name = "序号", isSequence = true, cellType = Excel.ColumnType.NUMERIC, type = Excel.Type.EXPORT)
|
||||
int sequence;
|
||||
@Excel(name = "姓名", cellType = Excel.ColumnType.STRING)
|
||||
String name;
|
||||
@Excel(name = "年龄", isStatistics = true, cellType = Excel.ColumnType.NUMERIC)
|
||||
int age;
|
||||
|
||||
// 公共无参构造函数
|
||||
public Person() {
|
||||
}
|
||||
|
||||
// 带参数的构造函数
|
||||
public Person(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {return age;}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-common</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-common</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-common</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-common</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-common</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-common</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-common</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-common</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-modules</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-modules</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-modules</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-modules</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bonus-modules-mongodb</artifactId>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-modules</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bonus-modules-obs</artifactId>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-modules</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bonus-oss</artifactId>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-modules</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-visual</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
4
pom.xml
4
pom.xml
|
|
@ -6,14 +6,14 @@
|
|||
|
||||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus</artifactId>
|
||||
<version>24.7.1</version>
|
||||
<version>24.8.0</version>
|
||||
|
||||
<name>bonus</name>
|
||||
<url>http://www.ahbonus.cn</url>
|
||||
<description>博诺思微服务系统</description>
|
||||
|
||||
<properties>
|
||||
<bonus.version>24.7.1</bonus.version>
|
||||
<bonus.version>24.8.0</bonus.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
|
|
|
|||
Loading…
Reference in New Issue