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

Commit 3ea7b276 authored by 张国柄's avatar 张国柄

~API:商品管理:商品数据导出;

parent f6ecd6f8
......@@ -6,7 +6,6 @@ import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.common.exception.constant.ErrorCode;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.PagedResult;
......@@ -78,42 +77,41 @@ public class GoblinStoreMgtGoodsController {
}
@ApiOperationSupport(order = 2)
@ApiOperation(value = "SPU导出")
@ApiOperation(value = "SPU导出", notes = "#以POST模拟FORM表单请求该接口")
@PostMapping("export")
public void export(@Valid @RequestBody GoblinStoreMgtGoodsFilterParam storeMgtGoodsFilterParam,
HttpServletResponse response) {
public void export(@Valid GoblinStoreMgtGoodsFilterParam storeMgtGoodsFilterParam, HttpServletResponse response) {
String currentUid = CurrentUtil.getCurrentUid();
List<String> storeIds = goblinRedisUtils.getStoreIds(currentUid);
String storeId = storeMgtGoodsFilterParam.getStoreId();
boolean storeIdIsBlank = StringUtils.isBlank(storeId);
if (CollectionUtils.isEmpty(storeIds) || (
!storeIdIsBlank && !goblinRedisUtils.hasStoreId(currentUid, storeId)
)) {
return;
}
if (log.isDebugEnabled()) {
log.debug("商品管理:SPU导出:[UID={},GoblinStoreMgtGoodsFilterParam={}]", currentUid, JsonUtils.toJson(storeMgtGoodsFilterParam));
}
if (storeIdIsBlank) {
storeMgtGoodsFilterParam.setStoreId(storeIds.get(0));
}
try {
List<String> storeIds = goblinRedisUtils.getStoreIds(currentUid);
String storeId = storeMgtGoodsFilterParam.getStoreId();
boolean storeIdIsBlank = StringUtils.isBlank(storeId);
if (CollectionUtils.isEmpty(storeIds) || (
!storeIdIsBlank && !goblinRedisUtils.hasStoreId(currentUid, storeId)
)) {
return;
}
if (log.isDebugEnabled()) {
log.debug("商品管理:SPU导出:[UID={},GoblinStoreMgtGoodsFilterParam={}]", currentUid, JsonUtils.toJson(storeMgtGoodsFilterParam));
}
if (storeIdIsBlank) {
storeMgtGoodsFilterParam.setStoreId(storeIds.get(0));
}
storeMgtGoodsFilterParam.setPageNum(1);
storeMgtGoodsFilterParam.setPageSize(2000);
PagedResult<GoblinStoreMgtGoodsListVo> pagedResult = goblinstoreMgtGoodsService.goodsList(storeMgtGoodsFilterParam);
List<GoblinStoreMgtGoodsListVo> rows = pagedResult.getList();
ArrayList<GoblinStoreMgtGoodsListVoExcel> rowsToExcels = ObjectUtil.getGoblinStoreMgtGoodsListVoExcelArrayList();
rows.forEach(row -> rowsToExcels.add(GoblinStoreMgtGoodsListVoExcel.getNew().copy(row)));
storeMgtGoodsFilterParam.setPageNum(1);
storeMgtGoodsFilterParam.setPageSize(2000);
PagedResult<GoblinStoreMgtGoodsListVo> pagedResult = goblinstoreMgtGoodsService.goodsList(storeMgtGoodsFilterParam);
List<GoblinStoreMgtGoodsListVo> rows = pagedResult.getList();
List<GoblinStoreMgtGoodsListVoExcel> rowsToExcels = ObjectUtil.getGoblinStoreMgtGoodsListVoExcelArrayList();
rows.forEach(row -> rowsToExcels.add(GoblinStoreMgtGoodsListVoExcel.getNew().copy(row)));
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
String fileName = "商品数据" + DateUtil.Formatter.yyyyMMddHHmmssTrim.format(LocalDateTime.now());
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode("商品数据", "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
try {
EasyExcel.write(response.getOutputStream()).sheet("SPU").doWrite(rows);
EasyExcel.write(response.getOutputStream(), GoblinStoreMgtGoodsListVoExcel.class).sheet("SPU").doWrite(rowsToExcels);
} catch (IOException e) {
log.error("商品管理:SPU导出:异常[UID={},storeId={},ex.msg={}]", currentUid, storeId, e.getLocalizedMessage());
log.error("商品管理:SPU导出:异常[UID={},ex.msg={}]", currentUid, e.getLocalizedMessage());
}
}
......
......@@ -61,7 +61,9 @@ public class GoblinStoreMgtGoodsListVoExcel implements Serializable, Cloneable {
this.setSpuNo(source.getSpuNo());
this.setCoverPic(source.getCoverPic());
this.setName(source.getName());
this.setCateMerge(source.getCateFid() + "/" + source.getCateSid() + "/" + source.getCateTid());
this.setCateMerge(StringUtils.defaultString(source.getCateFid(), "") + "/"
+ StringUtils.defaultString(source.getCateSid(), "") + "/"
+ StringUtils.defaultString(source.getCateTid(), ""));
this.setPriceRange("¥" + source.getPriceGe().toString() + " - ¥" + source.getPriceLe().toString());
switch (source.getShelvesStatus()) {
case "0":
......
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