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

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

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

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