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

Commit 6378838a authored by 张国柄's avatar 张国柄

+pom:easyexcel;

parent 4bf8d222
......@@ -55,6 +55,10 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
</dependency>
</dependencies>
<build>
......
package com.liquidnet.service.goblin.controller.manage;
import com.alibaba.excel.EasyExcel;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
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;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.GoblinGoodsSpecDto;
import com.liquidnet.service.goblin.dto.GoblinStoreMgtGoodsListVoExcel;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsActionParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsAddParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsEditSkuParam;
......@@ -33,9 +36,12 @@ import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
......@@ -74,23 +80,41 @@ public class GoblinStoreMgtGoodsController {
@ApiOperationSupport(order = 2)
@ApiOperation(value = "SPU导出")
@PostMapping("export")
public void export(@Valid @RequestBody GoblinStoreMgtGoodsFilterParam storeMgtGoodsFilterParam) {
List<String> storeIds = goblinRedisUtils.getStoreIds(CurrentUtil.getCurrentUid());
boolean storeIdIsBlank = StringUtils.isBlank(storeMgtGoodsFilterParam.getStoreId());
public void export(@Valid @RequestBody 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(CurrentUtil.getCurrentUid(), storeMgtGoodsFilterParam.getStoreId())
!storeIdIsBlank && !goblinRedisUtils.hasStoreId(currentUid, storeId)
)) {
return;
}
if (log.isDebugEnabled()) {
log.debug("商品管理:SPU导出:[GoblinStoreMgtGoodsFilterParam={}]", JsonUtils.toJson(storeMgtGoodsFilterParam));
log.debug("商品管理:SPU导出:[UID={},GoblinStoreMgtGoodsFilterParam={}]", currentUid, JsonUtils.toJson(storeMgtGoodsFilterParam));
}
if (storeIdIsBlank) {
storeMgtGoodsFilterParam.setStoreId(storeIds.get(0));
}
log.info("商品管理:SPU导出...");
// TODO: 2021/12/28 zhanggb==
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)));
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");
try {
EasyExcel.write(response.getOutputStream()).sheet("SPU").doWrite(rows);
} catch (IOException e) {
log.error("商品管理:SPU导出:异常[UID={},storeId={},ex.msg={}]", currentUid, storeId, e.getLocalizedMessage());
}
}
@ApiOperationSupport(order = 3)
......
package com.liquidnet.service.goblin.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsInfoVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsListVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.math.BigDecimal;
@Getter
@Setter
@EqualsAndHashCode
public class GoblinStoreMgtGoodsListVoExcel implements Serializable, Cloneable {
private static final long serialVersionUID = -5926827517337445529L;
@ExcelProperty("店铺ID")
private String storeId;
@ExcelProperty("商品ID")
private String spuId;
@ExcelProperty("商品编码")
private String spuNo;
@ExcelProperty("封面图片")
private String coverPic;
@ExcelProperty("商品名称")
private String name;
@ExcelProperty("分类")
private String cateMerge;
@ExcelProperty("价格区间")
private String priceRange;
// @ExcelProperty("审核状态")
// private String status;
// @ExcelProperty("审核拒绝原因")
// private String reason;
@ExcelProperty("上架状态")
private String shelvesStatus;
@ExcelProperty("总库存")
private Integer totalStock;
@ExcelProperty("剩余库存")
private Integer surplusStock;
private static final GoblinStoreMgtGoodsListVoExcel obj = new GoblinStoreMgtGoodsListVoExcel();
public static GoblinStoreMgtGoodsListVoExcel getNew() {
try {
return (GoblinStoreMgtGoodsListVoExcel) obj.clone();
} catch (CloneNotSupportedException e) {
return new GoblinStoreMgtGoodsListVoExcel();
}
}
public GoblinStoreMgtGoodsListVoExcel copy(GoblinStoreMgtGoodsListVo source) {
if (null == source) return this;
this.setStoreId(source.getStoreId());
this.setSpuId(source.getSpuId());
this.setSpuNo(source.getSpuNo());
this.setCoverPic(source.getCoverPic());
this.setName(source.getName());
this.setCateMerge(source.getCateFid() + "/" + source.getCateSid() + "/" + source.getCateTid());
this.setPriceRange("¥" + source.getPriceGe().toString() + " - ¥" + source.getPriceLe().toString());
switch (source.getShelvesStatus()) {
case "0":
this.setShelvesStatus("待上架");break;
case "1":
this.setShelvesStatus("已下架");break;
case "2":
this.setShelvesStatus("违规");break;
case "3":
this.setShelvesStatus("已上架");break;
default:
this.setShelvesStatus("其它");break;
}
this.setTotalStock(source.getTotalStock());
this.setSurplusStock(source.getSurplusStock());
return this;
}
}
......@@ -278,7 +278,7 @@ public class GoblinMongoUtils {
Query query = Query.query(Criteria.where("storeName").regex("^.*" + storeName + ".*$").and("delFlg").is("0").and("status").in("3", "5"));
query.fields().include("storeId");
List<GoblinStoreInfoVo> voList = mongoTemplate.find(query, GoblinStoreInfoVo.class, GoblinStoreInfoVo.class.getSimpleName());
ArrayList<String> list=ObjectUtil.getStringList();
ArrayList<String> list = CollectionUtil.arrayListString();
for(GoblinStoreInfoVo goblinStoreInfoVo:voList){
list.add(goblinStoreInfoVo.getStoreId());
}
......
......@@ -2,6 +2,7 @@ package com.liquidnet.service.goblin.util;
import com.liquidnet.service.base.PagedResult;
import com.liquidnet.service.goblin.dto.GoblinGoodsSpecDto;
import com.liquidnet.service.goblin.dto.GoblinStoreMgtGoodsListVoExcel;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsListVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtThumbVo;
import com.liquidnet.service.goblin.dto.vo.*;
......@@ -61,7 +62,7 @@ public class ObjectUtil {
private static final ArrayList<GoblinFrontNavigationVo> goblinFrontNavigationVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinGoodsSkuInfoDetailVo> goblinGoodsSkuInfoDetailVos = new ArrayList<>();
private static final ArrayList<GoblinGoodsInfoListVo> goblinGoodsInfoListVo = new ArrayList<>();
private static final ArrayList<String> stringList = new ArrayList<>();
private static final ArrayList<GoblinStoreMgtGoodsListVoExcel> goblinStoreMgtGoodsListVoExcelArrayList = new ArrayList<>();
private static final BasicDBObject basicDBObject = new BasicDBObject();
private static final ArrayList<WriteModel<Document>> writeModelDocumentArrayList = new ArrayList<>();
......@@ -73,15 +74,19 @@ public class ObjectUtil {
public static PagedResult<GoblinStoreNoticeVo> getGoblinStoreNoticeVoPagedResult() {
return goblinStoreNoticeVoPagedResult.clone();
}
public static ArrayList<String> getStringList() {
return (ArrayList<String>) stringList.clone();
}
public static ArrayList<GoblinGoodsInfoListVo> getGoblinGoodsInfoListVo() {
return (ArrayList<GoblinGoodsInfoListVo>) goblinGoodsInfoListVo.clone();
}
public static ArrayList<GoblinStoreMgtGoodsListVoExcel> getGoblinStoreMgtGoodsListVoExcelArrayList() {
return (ArrayList<GoblinStoreMgtGoodsListVoExcel>) goblinStoreMgtGoodsListVoExcelArrayList.clone();
}
public static ArrayList<GoblinGoodsSkuInfoDetailVo> goblinGoodsSkuInfoDetailVos() {
return (ArrayList<GoblinGoodsSkuInfoDetailVo>) goblinGoodsSkuInfoDetailVos.clone();
}
public static ArrayList<GoblinBackOrderVo> goblinBackOrderVoArrayList() {
return (ArrayList<GoblinBackOrderVo>) goblinBackOrderVoArrayList.clone();
}
......
......@@ -134,7 +134,12 @@
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.10.2</version>
<version>${aliyun-sdk-oss.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>${easyexcel.version}</version>
</dependency>
</dependencies>
......
......@@ -52,6 +52,9 @@
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-surefire-plugin.version>2.1</maven-surefire-plugin.version>
<findbugs-maven-plugin.version>3.0.1</findbugs-maven-plugin.version>
<aliyun-sdk-oss.version>3.10.2</aliyun-sdk-oss.version>
<easyexcel.version>3.0.5</easyexcel.version>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
......
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