update 更改模块名称
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package com.jero.modules.split.common;
|
||||
|
||||
public class BasePage{
|
||||
private Integer page = 1;
|
||||
private Integer pageSize = 10;
|
||||
private Integer startIndex;
|
||||
private Integer endIndex;
|
||||
private String orderBy;
|
||||
private String order;
|
||||
private String q;
|
||||
private Pager pager = new Pager();
|
||||
|
||||
public BasePage() {
|
||||
}
|
||||
|
||||
public Pager getPager() {
|
||||
this.pager.setPageId(this.getPage());
|
||||
this.pager.setPageSize(this.getPageSize());
|
||||
String orderField = "";
|
||||
if (this.orderBy != null && this.orderBy.trim().length() > 0) {
|
||||
orderField = this.orderBy;
|
||||
}
|
||||
|
||||
if (orderField.trim().length() > 0 && this.order != null && this.order.trim().length() > 0) {
|
||||
orderField = orderField + " " + this.order;
|
||||
}
|
||||
|
||||
this.pager.setOrderField(orderField);
|
||||
return this.pager;
|
||||
}
|
||||
|
||||
public void setPager(Pager pager) {
|
||||
this.pager = pager;
|
||||
}
|
||||
|
||||
public Integer getPage() {
|
||||
return this.page;
|
||||
}
|
||||
|
||||
public void setPage(Integer page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return this.pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public String getOrderBy() {
|
||||
return this.orderBy;
|
||||
}
|
||||
|
||||
public void setOrderBy(String orderBy) {
|
||||
this.orderBy = orderBy;
|
||||
}
|
||||
|
||||
public String getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void setOrder(String order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public String getQ() {
|
||||
return this.q;
|
||||
}
|
||||
|
||||
public void setQ(String q) {
|
||||
this.q = q;
|
||||
}
|
||||
|
||||
public Integer getStartIndex() {
|
||||
return this.startIndex;
|
||||
}
|
||||
|
||||
public void setStartIndex(Integer startIndex) {
|
||||
this.startIndex = (this.page - 1) * this.pageSize + 1;
|
||||
}
|
||||
|
||||
public Integer getEndIndex() {
|
||||
return this.endIndex;
|
||||
}
|
||||
|
||||
public void setEndIndex(Integer endIndex) {
|
||||
this.endIndex = this.page * this.pageSize;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
package com.jero.modules.split.common;
|
||||
|
||||
import com.jero.modules.system.util.MyStringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
import org.apache.poi.hssf.util.HSSFColor;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellUtil;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: yangxuenan
|
||||
* date: 2020/2/26 10:10
|
||||
*/
|
||||
public class ConvertHtml2Excel {
|
||||
|
||||
/**
|
||||
* html表格转excel
|
||||
*/
|
||||
public static HSSFWorkbook table2Excel(String tableHtml,HSSFWorkbook wb,String sheetName) throws Exception {
|
||||
// HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet(sheetName);
|
||||
List<Integer> moneyCols =new ArrayList<>();
|
||||
moneyCols.add(1);
|
||||
int headEndRow = 1;
|
||||
List<CrossRangeCellMeta> crossRowEleMetaLs = new ArrayList<CrossRangeCellMeta>();
|
||||
int rowIndex = 0;
|
||||
try {
|
||||
Document data = DocumentHelper.parseText(tableHtml);
|
||||
HSSFCellStyle contentStyle = getContentStyle(wb);
|
||||
// 生成表头
|
||||
Element thead = data.getRootElement().element("thead");
|
||||
HSSFCellStyle titleStyle = getTitleStyle(wb);
|
||||
int ls = 0;//列数
|
||||
if (thead != null) {
|
||||
List<Element> trLs = thead.elements("tr");
|
||||
for (Element trEle : trLs) {
|
||||
HSSFCellStyle style = rowIndex<=headEndRow?titleStyle:contentStyle;
|
||||
style.setWrapText(true);
|
||||
HSSFRow row = sheet.createRow(rowIndex);
|
||||
List<Element> thLs = trEle.elements("th");
|
||||
if(ls<thLs.size()) {
|
||||
ls = thLs.size();
|
||||
}
|
||||
int cellIndex = makeRowCell(thLs, rowIndex, row, 0, style, crossRowEleMetaLs, true,moneyCols);
|
||||
List<Element> tdLs = trEle.elements("td");
|
||||
if(ls<ls+tdLs.size()) {
|
||||
ls = ls + tdLs.size();
|
||||
}
|
||||
makeRowCell(tdLs, rowIndex, row, cellIndex, style, crossRowEleMetaLs, true,moneyCols);
|
||||
rowIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
// 生成表体
|
||||
Element tbody = data.getRootElement().element("tbody");
|
||||
if (tbody != null) {
|
||||
List<Element> trBody = tbody.elements("tr");
|
||||
for (Element trEle : trBody) {
|
||||
HSSFCellStyle style = rowIndex<=headEndRow?titleStyle:contentStyle;
|
||||
style.setWrapText(true);
|
||||
HSSFRow row = sheet.createRow(rowIndex);
|
||||
List<Element> thLs = trEle.elements("th");
|
||||
if(ls<thLs.size()) {
|
||||
ls = thLs.size();
|
||||
}
|
||||
int cellIndex = makeRowCell(thLs, rowIndex, row, 0, style, crossRowEleMetaLs, false,moneyCols);
|
||||
List<Element> tdLs = trEle.elements("td");
|
||||
if(ls<ls+tdLs.size()) {
|
||||
ls = ls + tdLs.size();
|
||||
}
|
||||
makeRowCell(tdLs, rowIndex, row, cellIndex, style, crossRowEleMetaLs, false,moneyCols);
|
||||
rowIndex++;
|
||||
}
|
||||
}
|
||||
// 生成表体
|
||||
Element tfoot = data.getRootElement().element("tfoot");
|
||||
if (tfoot != null) {
|
||||
List<Element> trFoot = tfoot.elements("tr");
|
||||
for (Element trEle : trFoot) {
|
||||
HSSFCellStyle style = rowIndex<=headEndRow?titleStyle:contentStyle;
|
||||
style.setWrapText(true);
|
||||
HSSFRow row = sheet.createRow(rowIndex);
|
||||
List<Element> thLs = trEle.elements("th");
|
||||
if(ls<thLs.size()) {
|
||||
ls = thLs.size();
|
||||
}
|
||||
int cellIndex = makeRowCell(thLs, rowIndex, row, 0, style, crossRowEleMetaLs, false,moneyCols);
|
||||
List<Element> tdLs = trEle.elements("td");
|
||||
if(ls<ls+tdLs.size()) {
|
||||
ls = ls + tdLs.size();
|
||||
}
|
||||
makeRowCell(tdLs, rowIndex, row, cellIndex, style, crossRowEleMetaLs, false,moneyCols);
|
||||
rowIndex++;
|
||||
}
|
||||
}
|
||||
// 合并表头
|
||||
for (CrossRangeCellMeta crcm : crossRowEleMetaLs) {
|
||||
sheet.addMergedRegion(new CellRangeAddress(crcm.getFirstRow(), crcm.getLastRow(), crcm.getFirstCol(), crcm.getLastCol()));
|
||||
HSSFCellStyle mergeStyle;
|
||||
if (crcm.isInHead()) {
|
||||
mergeStyle = titleStyle;
|
||||
} else {
|
||||
mergeStyle = contentStyle;
|
||||
}
|
||||
mergeStyle.setWrapText(true);
|
||||
setRegionStyle(sheet, new CellRangeAddress(crcm.getFirstRow(), crcm.getLastRow(), crcm.getFirstCol(), crcm.getLastCol()), mergeStyle);
|
||||
}
|
||||
for (int i = 0; i < ls; i++) {
|
||||
sheet.autoSizeColumn(i, true);//设置列宽
|
||||
sheet.setColumnWidth(i,30*256);
|
||||
// sheet.setColumnWidth(i,sheet.getColumnWidth(i)*15/10);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return wb;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生产行内容
|
||||
*
|
||||
* @return 最后一列的cell index
|
||||
*/
|
||||
/**
|
||||
* @param tdLs th或者td集合
|
||||
* @param rowIndex 行号
|
||||
* @param row POI行对象
|
||||
* @param startCellIndex
|
||||
* @param cellStyle 样式
|
||||
* @param crossRowEleMetaLs 跨行元数据集合
|
||||
* @return
|
||||
*/
|
||||
private static int makeRowCell(List<Element> tdLs, int rowIndex, HSSFRow row, int startCellIndex, HSSFCellStyle cellStyle,
|
||||
List<CrossRangeCellMeta> crossRowEleMetaLs, boolean inHead, List<Integer> moneyCols) {
|
||||
int i = startCellIndex;
|
||||
for (int eleIndex = 0; eleIndex < tdLs.size(); i++, eleIndex++) {
|
||||
int captureCellSize = getCaptureCellSize(rowIndex, i, crossRowEleMetaLs);
|
||||
while (captureCellSize > 0) {
|
||||
for (int j = 0; j < captureCellSize; j++) {// 当前行跨列处理(补单元格)
|
||||
row.createCell(i);
|
||||
i++;
|
||||
}
|
||||
captureCellSize = getCaptureCellSize(rowIndex, i, crossRowEleMetaLs);
|
||||
}
|
||||
Element thEle = tdLs.get(eleIndex);
|
||||
String val = thEle.getText();
|
||||
if (MyStringUtils.isEmpty(val)) {
|
||||
Element e = thEle.element("a");
|
||||
if (e != null) {
|
||||
val = e.getText();
|
||||
}
|
||||
}
|
||||
HSSFCell c = row.createCell(i);
|
||||
if (NumberUtils.isNumber(val)) {
|
||||
if (moneyCols != null && moneyCols.contains(i)) {
|
||||
c.setCellType(CellType.STRING);
|
||||
c.setCellValue(val);
|
||||
} else {
|
||||
c.setCellValue(Double.parseDouble(val));
|
||||
c.setCellType(CellType.NUMERIC);
|
||||
}
|
||||
|
||||
} else {
|
||||
c.setCellType(CellType.STRING);
|
||||
c.setCellValue(new HSSFRichTextString(val));
|
||||
}
|
||||
int rowSpan = NumberUtils.toInt(thEle.attributeValue("rowspan"), 1);
|
||||
int colSpan = NumberUtils.toInt(thEle.attributeValue("colspan"), 1);
|
||||
c.setCellStyle(cellStyle);
|
||||
if (rowSpan > 1 || colSpan > 1) { // 存在跨行或跨列
|
||||
crossRowEleMetaLs.add(new CrossRangeCellMeta(rowIndex, i, rowSpan, colSpan, inHead));
|
||||
}
|
||||
if (colSpan > 1) {// 当前行跨列处理(补单元格)
|
||||
for (int j = 1; j < colSpan; j++) {
|
||||
i++;
|
||||
row.createCell(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置合并单元格的边框样式
|
||||
*
|
||||
* @param sheet
|
||||
* @param region
|
||||
* @param cs
|
||||
*/
|
||||
public static void setRegionStyle(HSSFSheet sheet, CellRangeAddress region, HSSFCellStyle cs) {
|
||||
for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) {
|
||||
Row row = CellUtil.getRow(i, sheet);
|
||||
for (int j = region.getFirstColumn(); j <= region.getLastColumn(); j++) {
|
||||
Cell cell = CellUtil.getCell(row, (short) j);
|
||||
cell.setCellStyle(cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得因rowSpan占据的单元格
|
||||
*
|
||||
* @param rowIndex 行号
|
||||
* @param colIndex 列号
|
||||
* @param crossRowEleMetaLs 跨行列元数据
|
||||
* @return 当前行在某列需要占据单元格
|
||||
*/
|
||||
private static int getCaptureCellSize(int rowIndex, int colIndex, List<CrossRangeCellMeta> crossRowEleMetaLs) {
|
||||
int captureCellSize = 0;
|
||||
for (CrossRangeCellMeta crossRangeCellMeta : crossRowEleMetaLs) {
|
||||
if (crossRangeCellMeta.getFirstRow() < rowIndex && crossRangeCellMeta.getLastRow() >= rowIndex) {
|
||||
if (crossRangeCellMeta.getFirstCol() <= colIndex && crossRangeCellMeta.getLastCol() >= colIndex) {
|
||||
captureCellSize = crossRangeCellMeta.getLastCol() - colIndex + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return captureCellSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得标题样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
private static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) {
|
||||
short titlebackgroundcolor = HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex();
|
||||
short fontSize = 11;
|
||||
String fontName = "宋体";
|
||||
HSSFCellStyle style = workbook.createCellStyle();
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
style.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
style.setBorderTop(BorderStyle.THIN);//上边框
|
||||
style.setBorderRight(BorderStyle.THIN);//右边框
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setFillForegroundColor(titlebackgroundcolor);// 背景色
|
||||
style.setWrapText(true);
|
||||
HSSFFont font = workbook.createFont();
|
||||
// font.setFontName(fontName);
|
||||
font.setFontHeightInPoints(fontSize);
|
||||
// font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
|
||||
style.setFont(font);
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得内容样式
|
||||
*
|
||||
* @param wb
|
||||
* @return
|
||||
*/
|
||||
private static HSSFCellStyle getContentStyle(HSSFWorkbook wb) {
|
||||
short fontSize = 11;
|
||||
// String fontName = "宋体";
|
||||
HSSFCellStyle style = wb.createCellStyle();
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBorderTop(BorderStyle.THIN);
|
||||
style.setBorderLeft(BorderStyle.THIN);
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
HSSFFont font = wb.createFont();
|
||||
// font.setFontName(fontName);
|
||||
font.setFontHeightInPoints(fontSize);
|
||||
style.setFont(font);
|
||||
style.setAlignment(HorizontalAlignment.CENTER);//水平居中
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
|
||||
return style;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String cnt = "\n";
|
||||
List<Integer> c =new ArrayList<>();
|
||||
c.add(1);
|
||||
String tableHtml = "<table><tbody><tr><td colspan='2'>11111111</td><td rowspan='3'>3333333333</td><td>444444444</td></tr><tr><td>5555555</td><td>66666</td><td></td></tr><tr><td></td><td>324234</td><td></td></tr></tbody></table>";
|
||||
tableHtml = tableHtml.replaceAll("<[\\s]*?br[^>]*?>|<[\\s]*?\\/[\\s]*?br[\\s]*?>", cnt);
|
||||
// HSSFWorkbook hssfWorkbook = ConvertHtml2Excel.table2Excel(tableHtml,c,1);
|
||||
// hssfWorkbook.write(FileUtils.openOutputStream(new File("D:\\test\\test1.xls")));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.jero.modules.split.common;
|
||||
|
||||
/**
|
||||
* @Description: table转excel 跨行元素元数据
|
||||
* @Author: yangxuenan
|
||||
* date: 2020/2/26 10:14
|
||||
*/
|
||||
public class CrossRangeCellMeta {
|
||||
|
||||
public CrossRangeCellMeta(int firstRowIndex, int firstColIndex, int rowSpan, int colSpan, boolean inHead) {
|
||||
super();
|
||||
this.firstRowIndex = firstRowIndex;
|
||||
this.firstColIndex = firstColIndex;
|
||||
this.rowSpan = rowSpan;
|
||||
this.colSpan = colSpan;
|
||||
this.inHead = inHead;
|
||||
}
|
||||
|
||||
private int firstRowIndex;
|
||||
private int firstColIndex;
|
||||
private int rowSpan;// 跨越行数
|
||||
private int colSpan;// 跨越列数
|
||||
private boolean inHead;
|
||||
|
||||
public boolean isInHead() {
|
||||
return inHead;
|
||||
}
|
||||
|
||||
public CrossRangeCellMeta setInHead(boolean inHead) {
|
||||
this.inHead = inHead;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getFirstRow() {
|
||||
return firstRowIndex;
|
||||
}
|
||||
|
||||
public int getLastRow() {
|
||||
return firstRowIndex + rowSpan - 1;
|
||||
}
|
||||
|
||||
public int getFirstCol() {
|
||||
return firstColIndex;
|
||||
}
|
||||
|
||||
public int getLastCol() {
|
||||
return firstColIndex + colSpan - 1;
|
||||
}
|
||||
|
||||
public int getColSpan() {
|
||||
return colSpan;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
package com.jero.modules.split.common;
|
||||
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import com.jero.modules.project.entity.ProjectLawsInventoryEO;
|
||||
import com.xkcoding.http.util.StringUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.tools.zip.ZipEntry;
|
||||
import org.apache.tools.zip.ZipFile;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
public class FileUnZip {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(FileUnZip.class);
|
||||
|
||||
/**
|
||||
* 解压zip文件
|
||||
*
|
||||
* @param sourceFile,待解压的zip文件; toFolder,解压后的存放路径
|
||||
* @throws Exception
|
||||
* @author gaoyan
|
||||
**/
|
||||
public static String unZipFiles(String sourceFile, String descDir) throws IOException {
|
||||
File zipFile = new File(sourceFile);
|
||||
|
||||
File pathFile = new File(descDir);
|
||||
if (!pathFile.exists()) {
|
||||
pathFile.mkdirs();
|
||||
}
|
||||
ZipFile zip = new ZipFile(zipFile,"gbk");
|
||||
String orgMkdirs = "";
|
||||
int count = 0;
|
||||
for (Enumeration entries = zip.getEntries(); entries.hasMoreElements(); ) {
|
||||
count ++;
|
||||
ZipEntry entry = (ZipEntry) entries.nextElement();
|
||||
String zipEntryName = entry.getName();
|
||||
String outPath = (descDir + "/" + zipEntryName).replaceAll("\\*", "/");
|
||||
if(count == 1){
|
||||
orgMkdirs = outPath.substring(0, outPath.lastIndexOf('/'));
|
||||
}
|
||||
//判断路径是否存在,不存在则创建文件路径
|
||||
File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
|
||||
if (!file.exists()) {
|
||||
// orgMkdirs = outPath.substring(0, outPath.lastIndexOf('/'));
|
||||
file.mkdirs();
|
||||
}else{
|
||||
// orgMkdirs = outPath.substring(0, outPath.lastIndexOf('/'));
|
||||
}
|
||||
//判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
|
||||
if (new File(outPath).isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
//输出文件路径信息
|
||||
// InputStream in = null;
|
||||
// OutputStream out = null;
|
||||
try(InputStream in =zip.getInputStream(entry);
|
||||
OutputStream out =new FileOutputStream(outPath)){
|
||||
byte[] buf1 = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf1)) > 0) {
|
||||
out.write(buf1, 0, len);
|
||||
}
|
||||
}catch(IOException e){
|
||||
logger.error(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
zip.close();
|
||||
return orgMkdirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压zip文件
|
||||
* 解决解压文件下有多个文件夹时,读不到orgMkdirs问题
|
||||
* @param sourceFile,待解压的zip文件; descDir,解压后的存放路径
|
||||
* @throws Exception
|
||||
* @author gaoyan
|
||||
**/
|
||||
public static String unZipFiles2(String sourceFile, String descDir) throws IOException {
|
||||
File zipFile = new File(sourceFile);
|
||||
|
||||
File pathFile = new File(descDir);
|
||||
if (!pathFile.exists()) {
|
||||
pathFile.mkdirs();
|
||||
}
|
||||
ZipFile zip = new ZipFile(zipFile,"gbk");
|
||||
String orgMkdirsLast = "";
|
||||
for (Enumeration entries = zip.getEntries(); entries.hasMoreElements(); ) {
|
||||
ZipEntry entry = (ZipEntry) entries.nextElement();
|
||||
String zipEntryName = entry.getName();
|
||||
String outPath = (descDir + "/" + zipEntryName).replaceAll("\\*", "/");
|
||||
orgMkdirsLast = zipEntryName.substring(0, zipEntryName.indexOf('/'));
|
||||
//判断路径是否存在,不存在则创建文件路径
|
||||
File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
//判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
|
||||
if (new File(outPath).isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
//输出文件路径信息
|
||||
// InputStream in = null;
|
||||
// OutputStream out = null;
|
||||
try(InputStream in =zip.getInputStream(entry);
|
||||
OutputStream out =new FileOutputStream(outPath)){
|
||||
byte[] buf1 = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf1)) > 0) {
|
||||
out.write(buf1, 0, len);
|
||||
}
|
||||
}catch(IOException e){
|
||||
logger.error(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
zip.close();
|
||||
String orgMkdirs = descDir + "/" + orgMkdirsLast;
|
||||
return orgMkdirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归删除文件及文件夹
|
||||
*
|
||||
* @throws Exception
|
||||
* @author gaoyan
|
||||
* toFolder,解压后的存放路径
|
||||
**/
|
||||
public static boolean deleteDir(File dir) {
|
||||
if (dir.isDirectory()) {
|
||||
String[] children = dir.list();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
boolean success = deleteDir(new File(dir, children[i]));
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}else if(dir.isFile()){
|
||||
return dir.delete();
|
||||
}
|
||||
// 目录此时为空,可以删除
|
||||
return dir.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取一个目录下所有的Excel文件
|
||||
* gaoyan
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
public static List<File> readExcelFile(String path) {
|
||||
File file = new File(path);
|
||||
List<File> resultlist = new ArrayList<>();
|
||||
if (file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
for (File fi : files) {
|
||||
// 对文件进行过滤,只读取Excel文件
|
||||
if (fi.getName().contains(".xls") || fi.getName().contains(".xlsx")) {
|
||||
resultlist.add(fi);
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件名称读取固定目录下文件
|
||||
* 适用范围:filename内容 dir/file
|
||||
* gaoyan
|
||||
* @param filename
|
||||
*/
|
||||
public static List<File> readFileByFilenameDataList(String path,
|
||||
String filename,
|
||||
String cut,
|
||||
String errorMsg,
|
||||
List<String> msgList,
|
||||
String nameCn,
|
||||
String nameEn,
|
||||
ProjectLawsInventoryEO projectLawsInventoryEO) {
|
||||
//法规清单列表数据导入的时候,交付物模板字段为文件属性,填写时需要在本文件同级目录下以标准号为名称建立文件夹,并在文件夹下放置文件,假设在AAA标准号下放置了B.docx,则应填写AAA/B.docx
|
||||
filename = projectLawsInventoryEO.getSerialNumber()+"/"+filename;
|
||||
String filenameOne = "";
|
||||
String filenameTwo = "";
|
||||
if(filename.contains("/")){
|
||||
filenameOne = filename.split("/")[0];
|
||||
filenameTwo = filename.split("/")[1];
|
||||
}
|
||||
List<File> resultlist = new ArrayList<>();
|
||||
if (StringUtil.isNotEmpty(path)){
|
||||
File file = new File(path);
|
||||
if (file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
for (File fi : files) {
|
||||
if(fi.isDirectory()){
|
||||
File[] filesTemp = fi.listFiles();
|
||||
for (File fileTemp : filesTemp) {
|
||||
// 对文件进行过滤
|
||||
if (fileTemp.getName().equals(filenameTwo) && fi.getName().equals(filenameOne) && StringUtils.isNotBlank(filenameOne)) {
|
||||
resultlist.add(fileTemp);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
// 对文件进行过滤
|
||||
if (fi.getName().equals(filenameTwo) && fi.getPath().contains(filenameOne) && StringUtils.isNotBlank(filenameOne)) {
|
||||
resultlist.add(fi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(resultlist.size() == 0){
|
||||
String name = "";
|
||||
if(filename.contains("/")){
|
||||
name = filenameTwo;
|
||||
}else{
|
||||
name = filename;
|
||||
}
|
||||
if(LanguageEnum.CN.getValue().equals(cut)){
|
||||
errorMsg += nameCn + name + "格式不正确或者压缩包中没有" + name + "文件,请参考模板下载中的说明";
|
||||
}else{
|
||||
errorMsg += nameEn + name + " Incorrect format or not present in compressed package " + name + " file please refer to the description in template download;";
|
||||
}
|
||||
if(msgList != null){
|
||||
msgList.add(errorMsg);
|
||||
}
|
||||
}
|
||||
return resultlist;
|
||||
}
|
||||
/**
|
||||
* 根据文件名称读取固定目录下文件
|
||||
* 适用范围:filename内容 dir/file
|
||||
* gaoyan
|
||||
* @param filename
|
||||
*/
|
||||
public static List<File> readFileByFilename(String path,
|
||||
String filename,
|
||||
String cut,
|
||||
String errorMsg,
|
||||
List<String> msgList,
|
||||
String nameCn,
|
||||
String nameEn) {
|
||||
String filenameOne = "";
|
||||
String filenameTwo = "";
|
||||
if(filename.contains("/")){
|
||||
String[] strs = filename.split("/");
|
||||
if(strs.length >= 2){
|
||||
filenameOne = strs[0];
|
||||
filenameTwo = strs[1];
|
||||
}
|
||||
}
|
||||
List<File> resultlist = new ArrayList<>();
|
||||
if (StringUtil.isNotEmpty(path)){
|
||||
File file = new File(path);
|
||||
if (file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
for (File fi : files) {
|
||||
if(fi.isDirectory()){
|
||||
File[] filesTemp = fi.listFiles();
|
||||
for (File fileTemp : filesTemp) {
|
||||
// 对文件进行过滤
|
||||
if (fileTemp.getName().equals(filenameTwo) && fi.getName().equals(filenameOne) && StringUtils.isNotBlank(filenameOne)) {
|
||||
resultlist.add(fileTemp);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
// 对文件进行过滤
|
||||
if (fi.getName().equals(filenameTwo) && fi.getPath().contains(filenameOne) && StringUtils.isNotBlank(filenameOne)) {
|
||||
resultlist.add(fi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(resultlist.size() == 0){
|
||||
String name = "";
|
||||
if(filename.contains("/")){
|
||||
name = filenameTwo;
|
||||
}else{
|
||||
name = filename;
|
||||
}
|
||||
if(LanguageEnum.CN.getValue().equals(cut)){
|
||||
errorMsg += nameCn + name + "格式不正确或者压缩包中没有" + name + "文件,请参考模板下载中的说明";
|
||||
}else{
|
||||
errorMsg += nameEn + name + " Incorrect format or not present in compressed package " + name + " file please refer to the description in template download;";
|
||||
}
|
||||
if(msgList != null){
|
||||
msgList.add(errorMsg);
|
||||
}
|
||||
}
|
||||
return resultlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件名称读取固定目录下文件
|
||||
* 适用范围:filename内容 dir/file; file
|
||||
* @param path
|
||||
* @param filename
|
||||
* @return
|
||||
*/
|
||||
public static List<File> readFileByFilename(String path,String filename) {
|
||||
List<File> resultlist = new ArrayList<>();
|
||||
if (StringUtil.isNotEmpty(path)){
|
||||
File file = new File(path);
|
||||
if (file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
for (File fi : files) {
|
||||
// 对文件进行过滤
|
||||
if (fi.getName().equals(filename)) {
|
||||
resultlist.add(fi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultlist;
|
||||
}
|
||||
|
||||
/**
|
||||
*@Description: 删除某个文件
|
||||
*@Param: [file]
|
||||
*@return: void
|
||||
*@Author: duyunbao
|
||||
*@date: 2019/5/23 20:31
|
||||
*/
|
||||
public static void delete(File file) {
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.isFile() || file.list() == null) {
|
||||
file.delete();
|
||||
logger.info("删除了" + file.getName());
|
||||
} else {
|
||||
File[] files = file.listFiles();
|
||||
for (File a : files) {
|
||||
delete(a);
|
||||
}
|
||||
file.delete();
|
||||
logger.info("删除了" + file.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static List<File> readImpExcelFile(String path) {
|
||||
File file = new File(path);
|
||||
List<File> resultlist = new ArrayList<>();
|
||||
if (file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
for (File fi : files) {
|
||||
// 对文件进行过滤,只读取Excel文件
|
||||
String name = fi.getName();
|
||||
// "导入模板".equals(fi.getName()) || "导入模板.xlsx".equals(fi.getName())
|
||||
if (name != null &&( fi.getName().contains(".xls") || fi.getName().contains(".xlsx") )){
|
||||
resultlist.add(fi);
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultlist;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package com.jero.modules.split.common;
|
||||
|
||||
/**
|
||||
* @Author: liyawei
|
||||
* @Description:
|
||||
* @Date: Created in 11:14 2022/3/2
|
||||
*/
|
||||
public class Pager {
|
||||
private int pageId = 1;
|
||||
private int rowCount = 0;
|
||||
private int pageSize = 10;
|
||||
private int pageCount = 0;
|
||||
private int pageOffset = 0;
|
||||
private int pageTail = 0;
|
||||
private String orderField;
|
||||
private boolean orderDirection = true;
|
||||
private boolean pageEnabled = true;
|
||||
private int length = 6;
|
||||
private int startIndex = 0;
|
||||
private int endIndex = 0;
|
||||
private int[] indexs;
|
||||
|
||||
public Pager() {
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public int[] getIndexs() {
|
||||
int len = this.getEndIndex() - this.getStartIndex() + 1;
|
||||
this.indexs = new int[len];
|
||||
|
||||
for(int i = 0; i < len; ++i) {
|
||||
this.indexs[i] = this.getStartIndex() + i;
|
||||
}
|
||||
|
||||
return this.indexs;
|
||||
}
|
||||
|
||||
public void setIndexs(int[] indexs) {
|
||||
this.indexs = indexs;
|
||||
}
|
||||
|
||||
public int getStartIndex() {
|
||||
this.startIndex = (this.pageId - 1) * this.pageSize + 1;
|
||||
return this.startIndex;
|
||||
}
|
||||
|
||||
public void setStartIndex(int startIndex) {
|
||||
System.out.println("startIndx:" + this.pageId + ":" + this.pageSize);
|
||||
this.startIndex = (this.pageId - 1) * this.pageSize + 1;
|
||||
}
|
||||
|
||||
public int getEndIndex() {
|
||||
this.endIndex = this.pageId * this.pageSize;
|
||||
return this.endIndex;
|
||||
}
|
||||
|
||||
public void setEndIndex(int endIndex) {
|
||||
this.endIndex = this.pageId * this.pageSize;
|
||||
}
|
||||
|
||||
protected void doPage() {
|
||||
this.pageCount = this.rowCount / this.pageSize + 1;
|
||||
if (this.rowCount % this.pageSize == 0 && this.pageCount > 1) {
|
||||
--this.pageCount;
|
||||
}
|
||||
|
||||
this.pageOffset = (this.pageId - 1) * this.pageSize;
|
||||
this.pageTail = this.pageOffset + this.pageSize;
|
||||
if (this.pageOffset + this.pageSize > this.rowCount) {
|
||||
this.pageTail = this.rowCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getOrderCondition() {
|
||||
String condition = "";
|
||||
if (this.orderField != null && this.orderField.length() != 0) {
|
||||
condition = " order by " + this.orderField + (this.orderDirection ? " " : " desc ");
|
||||
}
|
||||
|
||||
return condition;
|
||||
}
|
||||
|
||||
public String getMysqlQueryCondition() {
|
||||
String condition = "";
|
||||
if (this.pageEnabled) {
|
||||
}
|
||||
|
||||
return condition;
|
||||
}
|
||||
|
||||
public void setOrderDirection(boolean orderDirection) {
|
||||
this.orderDirection = orderDirection;
|
||||
}
|
||||
|
||||
public boolean isOrderDirection() {
|
||||
return this.orderDirection;
|
||||
}
|
||||
|
||||
public void setOrderField(String orderField) {
|
||||
this.orderField = orderField;
|
||||
}
|
||||
|
||||
public String getOrderField() {
|
||||
return this.orderField;
|
||||
}
|
||||
|
||||
public void setPageCount(int pageCount) {
|
||||
this.pageCount = pageCount;
|
||||
}
|
||||
|
||||
public int getPageCount() {
|
||||
return this.pageCount;
|
||||
}
|
||||
|
||||
public void setPageId(int pageId) {
|
||||
this.pageId = pageId;
|
||||
}
|
||||
|
||||
public int getPageId() {
|
||||
return this.pageId;
|
||||
}
|
||||
|
||||
public void setPageOffset(int pageOffset) {
|
||||
this.pageOffset = pageOffset;
|
||||
}
|
||||
|
||||
public int getPageOffset() {
|
||||
return this.pageOffset;
|
||||
}
|
||||
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public int getPageSize() {
|
||||
return this.pageSize;
|
||||
}
|
||||
|
||||
public void setPageTail(int pageTail) {
|
||||
this.pageTail = pageTail;
|
||||
}
|
||||
|
||||
public int getPageTail() {
|
||||
return this.pageTail;
|
||||
}
|
||||
|
||||
public void setRowCount(int rowCount) {
|
||||
this.rowCount = rowCount;
|
||||
this.doPage();
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return this.rowCount;
|
||||
}
|
||||
|
||||
public boolean isPageEnabled() {
|
||||
return this.pageEnabled;
|
||||
}
|
||||
|
||||
public void setPageEnabled(boolean pageEnabled) {
|
||||
this.pageEnabled = pageEnabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
package com.jero.modules.split.common;
|
||||
|
||||
import com.jero.modules.split.util.WDWUtil;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
/**
|
||||
* @des : excel信息读取
|
||||
* @author: duyunbao
|
||||
* @email: 1114808306@qq.com
|
||||
* @date 2017/10/27 17:06
|
||||
**/
|
||||
public class ReadExcel {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ReadExcel.class);
|
||||
|
||||
/**
|
||||
* 总行数
|
||||
*/
|
||||
private int totalRows = 0;
|
||||
/**
|
||||
* 总条数
|
||||
*/
|
||||
private int totalCells = 0;
|
||||
/**
|
||||
* 错误信息接收器
|
||||
*/
|
||||
private String errorMsg;
|
||||
|
||||
public ReadExcel() {
|
||||
// 不做操作
|
||||
}
|
||||
|
||||
public int getTotalRows() {
|
||||
return totalRows;
|
||||
}
|
||||
|
||||
public int getTotalCells() {
|
||||
return totalCells;
|
||||
}
|
||||
|
||||
public String getErrorInfo() {//获取错误信息
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method_name: validateExcel
|
||||
* @des : 验证excel格式
|
||||
* @author: duyunbao
|
||||
* @param: [filePath]
|
||||
* @return: boolean
|
||||
* @date: 2017/10/27 17:07
|
||||
**/
|
||||
public boolean validateExcel(String filePath) {
|
||||
if (filePath == null || !(WDWUtil.isExcel2003(filePath) || WDWUtil.isExcel2007(filePath))) {
|
||||
errorMsg = "文件名不是excel格式";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method_name: getExcelInfo
|
||||
* @des : 读EXCEL文件,获取信息集合
|
||||
* @author: duyunbao
|
||||
* @param: [fileName, Mfile]
|
||||
* @return: org.apache.poi.ss.usermodel.Workbook
|
||||
* @date: 2017/10/27 17:08
|
||||
**/
|
||||
public Workbook getExcelInfo(String fileName, MultipartFile Mfile) {
|
||||
Workbook wb = null;
|
||||
//把spring文件上传的MultipartFile转换成CommonsMultipartFile类型
|
||||
CommonsMultipartFile cf = (CommonsMultipartFile) Mfile; //获取本地存储路径
|
||||
//初始化输入流
|
||||
InputStream is = null;
|
||||
try {
|
||||
//根据文件名判断文件是2003版本还是2007版本
|
||||
boolean isExcel2003 = true;
|
||||
if (WDWUtil.isExcel2007(fileName)) {
|
||||
isExcel2003 = false;
|
||||
}
|
||||
is = cf.getInputStream();
|
||||
//根据excel里面的内容读取客户信息
|
||||
wb = getExcelInfo(is, isExcel2003, wb);
|
||||
is.close();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(),e);
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
is = null;
|
||||
logger.error(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return wb;
|
||||
}
|
||||
|
||||
/***
|
||||
* @method_name: getExcelInfo
|
||||
* @des : 判断excel版本
|
||||
* @author: duyunbao
|
||||
* @param: [is, isExcel2003, wb]
|
||||
* @return: org.apache.poi.ss.usermodel.Workbook
|
||||
* @date: 2017/10/27 17:08
|
||||
**/
|
||||
private Workbook getExcelInfo(InputStream is, boolean isExcel2003, Workbook wb) {
|
||||
Workbook workbook =wb;
|
||||
try {
|
||||
/** 根据版本选择创建Workbook的方式 */
|
||||
//当excel是2003时
|
||||
if (isExcel2003) {
|
||||
workbook = new HSSFWorkbook(is);
|
||||
} else {//当excel是2007时
|
||||
workbook = new XSSFWorkbook(is);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(),e);
|
||||
}
|
||||
return workbook;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取sheet的名称
|
||||
* @MethodName:getSheetName
|
||||
* @author: 马晓晨
|
||||
* @email: 747052172@qq.com
|
||||
* @date 2017年11月24日 上午9:49:22
|
||||
* @version V1.0
|
||||
* @param filename
|
||||
* @param file
|
||||
* @param sheetIndex
|
||||
* @return
|
||||
*/
|
||||
public String getSheetName(String filename, MultipartFile file, Integer sheetIndex) {
|
||||
Workbook wb = getExcelInfo(filename, file);
|
||||
return wb.getSheetName(sheetIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: encodeFileName
|
||||
* @Description: 导出文件转换文件名称编码
|
||||
* @param @param fileNames
|
||||
* @param @param request
|
||||
* @param @return 设定文件
|
||||
* @return String 返回类型
|
||||
* @throws
|
||||
*/
|
||||
public static String encodeFileName(String fileNames ,HttpServletRequest request) {
|
||||
try {
|
||||
String agent = request.getHeader("User-Agent");
|
||||
if (agent.contains("Firefox")) {
|
||||
fileNames = new String(fileNames.getBytes("UTF-8"), "ISO8859-1"); // firefox浏览器
|
||||
} else {
|
||||
fileNames = URLEncoder.encode(fileNames, "utf-8");
|
||||
//谷歌中空格变为+问题
|
||||
fileNames = fileNames.replaceAll("\\+","%20");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(),e);
|
||||
}
|
||||
return fileNames ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.jero.modules.split.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: yangxuenan
|
||||
* date: 2020/5/11 10:29
|
||||
*/
|
||||
@Data
|
||||
public class SplitTableInfo {
|
||||
private String tableName;
|
||||
|
||||
private String tableHtml;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.jero.modules.split.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: yangxuenan
|
||||
* date: 2020/1/9 18:59
|
||||
*/
|
||||
@Data
|
||||
public class UploadFileInfo {
|
||||
private String id;
|
||||
private String filePath;
|
||||
private String name;
|
||||
}
|
||||
Reference in New Issue
Block a user