Commit 05f55c28 by fudahua

feat:时间格式

parent 8236f0bd
......@@ -20,11 +20,10 @@ import com.google.common.collect.Lists;
import com.opencsv.CSVWriter;
import com.opencsv.ResultSetHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -604,6 +603,18 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
cell = row.createCell(j);
cell.setCellValue(colName);
}
//日期
CellStyle yyyyMMddhhmmss = wb.createCellStyle();
DataFormat dataFormat = wb.createDataFormat();
yyyyMMddhhmmss.setDataFormat(dataFormat.getFormat("yyyy-MM-dd HH:mm:ss"));
//日期
CellStyle yyyyMMdd = wb.createCellStyle();
DataFormat yyyyMMddDataFormat = wb.createDataFormat();
yyyyMMdd.setDataFormat(yyyyMMddDataFormat.getFormat("yyyy-MM-dd"));
// 遍历输出行
int rowCount = 0;
while (rowCount<limitSize&&rs.next()) {
......@@ -622,15 +633,62 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
}
} else {
int cType = rs.getMetaData().getColumnType(j + 1);
Cell midCell = row.createCell(j);
switch (cType) {
case Types.TIMESTAMP:
row.createCell(j).setCellValue(rs.getTimestamp(j + 1) != null ? datetimeFormatter.format(rs.getTimestamp(j + 1)) : "");
String s = rs.getTimestamp(j + 1) != null ? datetimeFormatter.format(rs.getTimestamp(j + 1)) : "";
if (StringUtils.isBlank(s)) {
midCell.setCellValue(s);
}else {
midCell.setCellStyle(yyyyMMddhhmmss);
midCell.setCellValue(DateUtils.parseDate(s,new String[]{"yyyy-MM-dd hh:mm:ss"}));
}
break;
case Types.DATE:
row.createCell(j).setCellValue(rs.getDate(j + 1) != null ? dateFormatter.format(rs.getDate(j + 1)) : "");
String mid = rs.getDate(j + 1) != null ? dateFormatter.format(rs.getDate(j + 1)) : "";
if (StringUtils.isBlank(mid)) {
midCell.setCellValue(mid);
}else {
midCell.setCellStyle(yyyyMMdd);
midCell.setCellValue(DateUtils.parseDate(mid,new String[]{"yyyy-MM-dd"}));
}
break;
case Types.TIME:
row.createCell(j).setCellValue(rs.getTimestamp(j + 1) != null ? timeFormatter.format(rs.getTimestamp(j + 1)) : "");
String timeStr = rs.getTimestamp(j + 1) != null ? timeFormatter.format(rs.getTimestamp(j + 1)) : "";
midCell.setCellValue(timeStr);
break;
case Types.INTEGER:
String intStr = rs.getString(j + 1);
if (StringUtils.isBlank(intStr)){
midCell.setCellValue(0);
}else {
midCell.setCellValue(Integer.valueOf(intStr));
}
break;
case Types.BIGINT:
String bigintStr = rs.getString(j + 1);
if (StringUtils.isBlank(bigintStr)){
midCell.setCellValue(0);
}else {
midCell.setCellValue(Long.valueOf(bigintStr));
}
break;
case Types.DOUBLE:
case Types.DECIMAL:
String doubleStr = rs.getString(j + 1);
if (StringUtils.isBlank(doubleStr)) {
midCell.setCellValue(0);
}else {
midCell.setCellValue(Double.valueOf(doubleStr));
}
break;
case Types.FLOAT:
String floatStr = rs.getString(j + 1);
if (StringUtils.isBlank(floatStr)) {
midCell.setCellValue(0);
}else {
midCell.setCellValue(Float.valueOf(floatStr));
}
break;
default:
String string = rs.getString(j + 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment