Skip to content

Commit

Permalink
refactor($starter): hook for before downloading excel
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Aug 28, 2021
1 parent 5e4f58f commit 80512ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;

import static com.baomidou.mybatisplus.annotation.FieldFill.INSERT;
Expand Down Expand Up @@ -72,7 +73,7 @@ public class User {
* Birthday
*/
@TableField(value = COL_BIRTHDAY)
private LocalDateTime birthday;
private LocalDate birthday;
/**
* 26 gender options
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import cn.hutool.core.util.ObjectUtil;
import lombok.val;
import org.springframework.http.server.reactive.ServerHttpRequest;

/**
Expand All @@ -23,9 +24,9 @@ public class RequestUtil {
* @date 2/15/20 9:52 PM
*/
public static String getRequesterIpAndPort(ServerHttpRequest request) {
var requestRemoteAddress = request.getRemoteAddress();
val requestRemoteAddress = request.getRemoteAddress();
if (ObjectUtil.isNotNull(requestRemoteAddress)) {
return requestRemoteAddress.toString().substring(1);
return requestRemoteAddress.toString();
}
return "Unknown Requester";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,23 @@ protected void afterExecute() {
*/
protected abstract List<T> getListForExporting();

/**
* Before download to configure ExcelWriter. Such as hiding column.
*
* @param excelWriter the excel writer
*/
protected void beforeDownload(ExcelWriter excelWriter) {
}

@GetMapping("/stat/excel-template")
@ApiOperation(value = "Download template excel file", notes = "Download template excel file")
public ResponseEntity<StreamingResponseBody> downloadRoleStat() {
@Cleanup val excelWriter = new ExcelWriter(true);
public ResponseEntity<StreamingResponseBody> downloadExcelTemplate() {
val excelWriter = new ExcelWriter(true);
excelWriter.setHeaderAlias(this.exportingFieldAliasMap);
excelWriter.write(this.getListForExporting());
excelWriter.setFreezePane(1);
excelWriter.autoSizeColumnAll();
this.beforeDownload(excelWriter);
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION,
ContentDisposition.builder("attachment").filename(
Expand Down

0 comments on commit 80512ef

Please sign in to comment.