记得上下班打卡 | git大法好,push需谨慎

Commit dd97d844 authored by 张国柄's avatar 张国柄

~opt:导出调整参数接收form改body;

parent ebd6bd30
...@@ -5,6 +5,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; ...@@ -5,6 +5,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport; import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.common.exception.constant.ErrorCode; import com.liquidnet.common.exception.constant.ErrorCode;
import com.liquidnet.commons.lang.util.CurrentUtil; import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.JsonUtils; import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ErrorMapping; import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.PagedResult; import com.liquidnet.service.base.PagedResult;
...@@ -30,10 +31,13 @@ import io.swagger.annotations.ApiOperation; ...@@ -30,10 +31,13 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
...@@ -41,6 +45,7 @@ import javax.validation.constraints.NotNull; ...@@ -41,6 +45,7 @@ import javax.validation.constraints.NotNull;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
...@@ -74,10 +79,11 @@ public class GoblinStoreMgtCouponController { ...@@ -74,10 +79,11 @@ public class GoblinStoreMgtCouponController {
} }
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@ApiOperation(value = "优惠券导出", notes = "#以POST模拟FORM表单请求该接口") @ApiOperation(value = "优惠券导出")
@PostMapping("export") @PostMapping("export")
public void export(@Valid GoblinStoreMgtCouponFilterParam mgtCouponFilterParam, HttpServletResponse response) { public void export(@Valid @RequestBody GoblinStoreMgtCouponFilterParam mgtCouponFilterParam, HttpServletResponse response) {
String currentUid = CurrentUtil.getCurrentUid(); String currentUid = CurrentUtil.getCurrentUid();
ServletOutputStream servletOutputStream = null;
try { try {
if (!goblinRedisUtils.hasStoreId(currentUid, mgtCouponFilterParam.getStoreId())) { if (!goblinRedisUtils.hasStoreId(currentUid, mgtCouponFilterParam.getStoreId())) {
log.warn("商铺活动:优惠券导出:无权操作该店铺,请核实[UID={},GoblinStoreMgtCouponFilterParam={}]", currentUid, JsonUtils.toJson(mgtCouponFilterParam)); log.warn("商铺活动:优惠券导出:无权操作该店铺,请核实[UID={},GoblinStoreMgtCouponFilterParam={}]", currentUid, JsonUtils.toJson(mgtCouponFilterParam));
...@@ -86,23 +92,29 @@ public class GoblinStoreMgtCouponController { ...@@ -86,23 +92,29 @@ public class GoblinStoreMgtCouponController {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("商铺活动:优惠券导出:[mgtCouponFilterParam={}]", JsonUtils.toJson(mgtCouponFilterParam)); log.debug("商铺活动:优惠券导出:[mgtCouponFilterParam={}]", JsonUtils.toJson(mgtCouponFilterParam));
} }
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + DateUtil.Formatter.ddHHmmssTrim.format(LocalDateTime.now())
+ new String(("优惠券数据").getBytes("gb2312"), StandardCharsets.ISO_8859_1) + ".xls");
response.setContentType(MediaType.MULTIPART_FORM_DATA_VALUE);
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
servletOutputStream = response.getOutputStream();
mgtCouponFilterParam.setPageNum(1); mgtCouponFilterParam.setPageNum(1);
mgtCouponFilterParam.setPageSize(2000); mgtCouponFilterParam.setPageSize(5000);
PagedResult<GoblinStoreMgtCouponListVo> pagedResult = goblinstoreMgtCouponService.couponList(mgtCouponFilterParam); PagedResult<GoblinStoreMgtCouponListVo> pagedResult = goblinstoreMgtCouponService.couponList(mgtCouponFilterParam);
List<GoblinStoreMgtCouponListVo> rows = pagedResult.getList(); List<GoblinStoreMgtCouponListVo> rows = pagedResult.getList();
List<GoblinStoreMgtCouponListVoExcel> rowsToExcels = ObjectUtil.getGoblinStoreMgtCouponListVoExcelArrayList(); List<GoblinStoreMgtCouponListVoExcel> rowsToExcels = ObjectUtil.getGoblinStoreMgtCouponListVoExcelArrayList();
rows.forEach(row -> rowsToExcels.add(GoblinStoreMgtCouponListVoExcel.getNew().copy(row))); rows.forEach(row -> rowsToExcels.add(GoblinStoreMgtCouponListVoExcel.getNew().copy(row)));
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); EasyExcel.write(servletOutputStream, GoblinStoreMgtGoodsListVoExcel.class).sheet("优惠券数据").doWrite(rowsToExcels);
response.setCharacterEncoding("utf-8"); } catch (IOException e) {
String fileName = URLEncoder.encode("商铺活动-优惠券数据", "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
EasyExcel.write(response.getOutputStream(), GoblinStoreMgtGoodsListVoExcel.class).sheet("优惠券活动").doWrite(rowsToExcels);
} catch (
IOException e) {
log.error("商品管理:SPU导出:异常[UID={},ex.msg={}]", currentUid, e.getLocalizedMessage()); log.error("商品管理:SPU导出:异常[UID={},ex.msg={}]", currentUid, e.getLocalizedMessage());
} finally {
if (null != servletOutputStream) {
try {
servletOutputStream.close();
} catch (Exception e) {
}
}
} }
} }
......
...@@ -6,6 +6,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiSupport; ...@@ -6,6 +6,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.common.exception.constant.ErrorCode; import com.liquidnet.common.exception.constant.ErrorCode;
import com.liquidnet.commons.lang.util.CollectionUtil; import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.CurrentUtil; import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.JsonUtils; import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ErrorMapping; import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.PagedResult; import com.liquidnet.service.base.PagedResult;
...@@ -31,16 +32,19 @@ import io.swagger.annotations.ApiOperation; ...@@ -31,16 +32,19 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URLEncoder; import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -77,10 +81,11 @@ public class GoblinStoreMgtGoodsController { ...@@ -77,10 +81,11 @@ public class GoblinStoreMgtGoodsController {
} }
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@ApiOperation(value = "SPU导出", notes = "#以POST模拟FORM表单请求该接口") @ApiOperation(value = "SPU导出")
@PostMapping("export") @PostMapping("export")
public void export(@Valid GoblinStoreMgtGoodsFilterParam storeMgtGoodsFilterParam, HttpServletResponse response) { public void export(@Valid @RequestBody GoblinStoreMgtGoodsFilterParam storeMgtGoodsFilterParam, HttpServletResponse response) {
String currentUid = CurrentUtil.getCurrentUid(); String currentUid = CurrentUtil.getCurrentUid();
ServletOutputStream servletOutputStream = null;
try { try {
if (!goblinRedisUtils.hasStoreId(currentUid, storeMgtGoodsFilterParam.getStoreId())) { if (!goblinRedisUtils.hasStoreId(currentUid, storeMgtGoodsFilterParam.getStoreId())) {
log.warn("商品管理:SPU导出:无权操作该店铺,请核实[UID={},GoblinStoreMgtGoodsFilterParam={}]", currentUid, JsonUtils.toJson(storeMgtGoodsFilterParam)); log.warn("商品管理:SPU导出:无权操作该店铺,请核实[UID={},GoblinStoreMgtGoodsFilterParam={}]", currentUid, JsonUtils.toJson(storeMgtGoodsFilterParam));
...@@ -89,22 +94,29 @@ public class GoblinStoreMgtGoodsController { ...@@ -89,22 +94,29 @@ public class GoblinStoreMgtGoodsController {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("商品管理:SPU导出:[UID={},GoblinStoreMgtGoodsFilterParam={}]", currentUid, JsonUtils.toJson(storeMgtGoodsFilterParam)); log.debug("商品管理:SPU导出:[UID={},GoblinStoreMgtGoodsFilterParam={}]", currentUid, JsonUtils.toJson(storeMgtGoodsFilterParam));
} }
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + DateUtil.Formatter.ddHHmmssTrim.format(LocalDateTime.now())
+ new String(("商品数据").getBytes("gb2312"), StandardCharsets.ISO_8859_1) + ".xls");
response.setContentType(MediaType.MULTIPART_FORM_DATA_VALUE);
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
servletOutputStream = response.getOutputStream();
storeMgtGoodsFilterParam.setPageNum(1); storeMgtGoodsFilterParam.setPageNum(1);
storeMgtGoodsFilterParam.setPageSize(2000); storeMgtGoodsFilterParam.setPageSize(5000);
PagedResult<GoblinStoreMgtGoodsListVo> pagedResult = goblinstoreMgtGoodsService.goodsList(storeMgtGoodsFilterParam); PagedResult<GoblinStoreMgtGoodsListVo> pagedResult = goblinstoreMgtGoodsService.goodsList(storeMgtGoodsFilterParam);
List<GoblinStoreMgtGoodsListVo> rows = pagedResult.getList(); List<GoblinStoreMgtGoodsListVo> rows = pagedResult.getList();
List<GoblinStoreMgtGoodsListVoExcel> rowsToExcels = ObjectUtil.getGoblinStoreMgtGoodsListVoExcelArrayList(); List<GoblinStoreMgtGoodsListVoExcel> rowsToExcels = ObjectUtil.getGoblinStoreMgtGoodsListVoExcelArrayList();
rows.forEach(row -> rowsToExcels.add(GoblinStoreMgtGoodsListVoExcel.getNew().copy(row))); rows.forEach(row -> rowsToExcels.add(GoblinStoreMgtGoodsListVoExcel.getNew().copy(row)));
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); EasyExcel.write(servletOutputStream, GoblinStoreMgtGoodsListVoExcel.class).sheet("商品数据").doWrite(rowsToExcels);
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode("商品数据", "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
EasyExcel.write(response.getOutputStream(), GoblinStoreMgtGoodsListVoExcel.class).sheet("SPU").doWrite(rowsToExcels);
} catch (IOException e) { } catch (IOException e) {
log.error("商品管理:SPU导出:异常[UID={},ex.msg={}]", currentUid, e.getLocalizedMessage()); log.error("商品管理:SPU导出:异常[UID={},ex.msg={}]", currentUid, e.getLocalizedMessage());
} finally {
if (null != servletOutputStream) {
try {
servletOutputStream.close();
} catch (Exception e) {
}
}
} }
} }
......
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