feat(settle report): download settle report excel from ui

master
yixian 5 years ago
parent c43a7e2816
commit 804fc0c9e8

@ -63,7 +63,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.format.number.CurrencyStyleFormatter;
import org.springframework.stereotype.Service;
@ -1376,7 +1375,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
.addStringColumn("bd_user_name").ok()
.addStringColumn("city").ok()
.addStringColumn("clean_days").ok()
.addColumn(Cell.CELL_TYPE_NUMERIC, "clearing_amount", json -> json.getBigDecimal("clearing_amount").setScale(2, RoundingMode.DOWN).toPlainString()).setCellStyle(ExcelTemplate.STYLE_RIGHT).ok()
.addColumn(Cell.CELL_TYPE_NUMERIC, "clearing_amount", json -> json.getBigDecimal("clearing_amount").setScale(2, RoundingMode.DOWN)).setCellStyle(ExcelTemplate.STYLE_RIGHT).ok()
.addDateColumn("yyyy-MM-dd", "settle_date_from").ok()
.addDateColumn("yyyy-MM-dd", "settle_date_to").ok()
.build();

@ -148,12 +148,8 @@ public class ExcelTemplate {
protected void buildCell(Row row, int columnNum, JSONObject data) {
Object value = valueProvider.getValue(data);
if (value == null) {
row.createCell(columnNum, Cell.CELL_TYPE_BLANK);
return;
}
if (columnType == null) {
columnType = PoiUtils.convertCellType(value.getClass());
columnType = PoiUtils.convertCellType(value);
}
CellStyle style = initCellStyle(row.getSheet().getWorkbook(), columnType);
Cell cell = row.createCell(columnNum, columnType);

@ -5,6 +5,7 @@ import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;
import java.math.BigDecimal;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalField;
@ -37,7 +38,11 @@ public class PoiUtils {
}
public static int convertCellType(Class<?> valueClass) {
public static int convertCellType(Object value) {
if (value == null) {
return Cell.CELL_TYPE_BLANK;
}
Class<?> valueClass = value.getClass();
if (valueClass.isPrimitive()) {
valueClass = PRIMITIVE_CLASSES.get(valueClass);
}
@ -54,12 +59,15 @@ public class PoiUtils {
}
public static void setCellValue(Cell cell, Object value) {
if (value == null) {
return;
}
Class valueClass = value.getClass();
if (valueClass.isPrimitive()) {
valueClass = PRIMITIVE_CLASSES.get(valueClass);
}
if (Number.class.isAssignableFrom(valueClass)) {
cell.setCellValue((double) value);
cell.setCellValue(((Number)value).doubleValue());
return;
}
if (Date.class.isAssignableFrom(valueClass)) {

Loading…
Cancel
Save