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

Commit 72892b21 authored by 张国柄's avatar 张国柄

~api:店铺商品管理:批量导入数据;

parent 3fc7d2f6
......@@ -8,26 +8,31 @@ import java.util.List;
@Data
public class GoblinGoodsImportDto {
@ExcelProperty(value = "商品编码")
@ExcelProperty(value = "商品编码", index = 0)
private String spuCode;
@ExcelProperty(value = "商品名称")
@ExcelProperty(value = "商品名称", index = 1)
private String spuName;
@ExcelProperty(value = "商品图片")
@ExcelProperty(value = "商品图片", index = 2)
private String spuImgs;
private List<String> spuImgList;
@ExcelProperty(value = "商品规格")
private List<String> spuImgList;//
@ExcelProperty(value = "商品规格", index = 3)
private String skuSpec;
private List<GoblinGoodsSpecDto> skuSpecDtos;
@ExcelProperty(value = "规格编码")
private List<GoblinGoodsSpecDto> skuSpecDtos;//
@ExcelProperty(value = "规格编码", index = 4)
private String skuCode;
@ExcelProperty(value = "价格")
@ExcelProperty(value = "价格", index = 5)
private BigDecimal price;
@ExcelProperty(value = "库存")
@ExcelProperty(value = "库存", index = 6)
private Integer stock;
@ExcelProperty(value = "规格图片")
@ExcelProperty(value = "规格图片", index = 7)
private String skuImg;
@ExcelProperty(value = "规格条码")
@ExcelProperty(value = "规格条码", index = 8)
private String skuBarCode;
// @ExcelProperty(value = "商品条码")
// private String spuBarCode;
private String failureReason;//
}
......@@ -48,10 +48,11 @@ public class GoblinStoreMgtGoodsImportController {
if (!goblinRedisUtils.redisUtil.lock(GoblinRedisConst.BASIC_GOODS_SKU.concat("lk").concat(storeId), 1, 30)) {
return ResponseDto.failure(ErrorMapping.get("140000"));
}
String analysisResultMsg;
try {
switch (dataType) {
case 1:
goblinStoreMgtGoodsImportService.goodsInformationDataAnalysisProcessing(file, currentUid, storeId);
analysisResultMsg = goblinStoreMgtGoodsImportService.goodsInformationDataAnalysisProcessing(file, currentUid, storeId);
break;
case 2:
default:
......@@ -61,8 +62,8 @@ public class GoblinStoreMgtGoodsImportController {
return ResponseDto.failure(e.getMessage());
} catch (IOException e) {
log.warn("店铺商品管理:批量导入数据:异常[UID={},dataType={},fileName={}]", currentUid, dataType, file.getOriginalFilename(), e);
return ResponseDto.failure("数据误,解析失败");
return ResponseDto.failure("数据误,解析失败");
}
return ResponseDto.success();
return ResponseDto.success(analysisResultMsg);
}
}
......@@ -158,12 +158,12 @@ public class GoblinStoreMgtGoodsImportService {
/* 校验|------------------------------------------------------------------------------ */
}
public void goodsInformationDataAnalysisProcessing(MultipartFile file, String uid, String storeId) throws IOException {
List<String> skuBarCodeTmpList = CollectionUtil.arrayListString();
List<GoblinGoodsInfoVo> goodsInfoVos = ObjectUtil.goblinGoodsInfoVoArrayList();
List<GoblinGoodsSkuInfoVo> goodsSkuInfoVos = ObjectUtil.getGoblinGoodsSkuInfoVoArrayList();
EasyExcel.read(file.getInputStream(), GoblinGoodsImportDto.class, new AnalysisEventListener<GoblinGoodsImportDto>() {
public String goodsInformationDataAnalysisProcessing(MultipartFile file, String uid, String storeId) throws IOException {
AnalysisEventListener<GoblinGoodsImportDto> analysisEventListener = new AnalysisEventListener<GoblinGoodsImportDto>() {
List<GoblinGoodsSkuInfoVo> goodsSkuInfoVos;
List<GoblinGoodsInfoVo> goodsInfoVos;
List<String> skuBarCodeTmpList;
LocalDateTime now;
@Override
public void onException(Exception exception, AnalysisContext context) throws Exception {
......@@ -181,7 +181,14 @@ public class GoblinStoreMgtGoodsImportService {
if (approximateTotalRowNumber > 501) {
log.warn("店铺商品管理:批量导入数据:异常[UID={},storeId={},totalRowNumber={}]", uid, storeId, approximateTotalRowNumber);
throw new LiquidnetServiceException("-1", "超出总行数限制500");
} else if (approximateTotalRowNumber <= 1) {
throw new LiquidnetServiceException("-1", "导入文件不能为空");
}
goodsSkuInfoVos = ObjectUtil.getGoblinGoodsSkuInfoVoArrayList();
goodsInfoVos = ObjectUtil.goblinGoodsInfoVoArrayList();
skuBarCodeTmpList = CollectionUtil.arrayListString();
now = LocalDateTime.now();
super.invokeHead(headMap, context);
}
......@@ -192,19 +199,27 @@ public class GoblinStoreMgtGoodsImportService {
goodsInformationDataAnalysisProcessingValid(dto, skuBarCodeTmpList, rowIndex + 1);
GoblinGoodsInfoVo lastGoodsInfoVo = CollectionUtils.isEmpty(goodsInfoVos) ? null : goodsInfoVos.get(goodsInfoVos.size() - 1);
GoblinGoodsInfoVo goodsInfoVo = goodsInformationDataAnalysisProcessingForSpu(dto, lastGoodsInfoVo, uid, storeId, LocalDateTime.now(), goodsSkuInfoVos);
GoblinGoodsInfoVo goodsInfoVo = goodsInformationDataAnalysisProcessingForSpu(dto, lastGoodsInfoVo, uid, storeId, now, goodsSkuInfoVos);
if (null != goodsInfoVo) {
if (log.isDebugEnabled()) {
log.debug("dt2:{}", goodsInfoVo);
}
goodsInfoVos.add(goodsInfoVo);
}
dto.setSkuSpecDtos(null);
dto.setSpuImgList(null);
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {// 解析完成...
if (log.isDebugEnabled()) {
log.debug("dt3-1:{}", JsonUtils.toJson(goodsInfoVos));
log.debug("dt3-2:{}", JsonUtils.toJson(goodsSkuInfoVos));
}
if (!CollectionUtils.isEmpty(goodsInfoVos)) {
List<String> existGoodsSkuNoList = goblinMongoUtils.existGoodsSkuNoBySkuNoList(storeId, skuBarCodeTmpList);
if (!CollectionUtils.isEmpty(existGoodsSkuNoList)) {
if (existGoodsSkuNoList.size() > 3) {
......@@ -271,13 +286,25 @@ public class GoblinStoreMgtGoodsImportService {
if (initGoodsSkuObjs.size() > 0) {
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_GOODS.getKey(), SqlMapping.gets(toMqSqls, initGoodsSkuObjs, initGoodsSkuSpecValueObjs));
}
}
}
}).sheet(0).doReadSync();
};
List<GoblinGoodsImportDto> readDtoList = EasyExcel.read(file.getInputStream(), GoblinGoodsImportDto.class, analysisEventListener).sheet(0).doReadSync();
if (CollectionUtils.isEmpty(readDtoList)) {
throw new LiquidnetServiceException("-1", "导入文件不能为空");
}
long failureRows = readDtoList.stream().filter(r -> StringUtils.isNotEmpty(r.getFailureReason())).count();
String analysisResultMsg = String.format("导入成功%s条数据,导入失败%s条数据", readDtoList.size() - failureRows, failureRows);
log.info("DT-IN:[storeId={},uid={},fileName={},readResult:{}]", uid, storeId, file.getOriginalFilename(), analysisResultMsg);
return analysisResultMsg;
}
private GoblinGoodsInfoVo goodsInformationDataAnalysisProcessingForSpu(GoblinGoodsImportDto dt, GoblinGoodsInfoVo lastGoodsInfoVo, String uid, String storeId, LocalDateTime now, List<GoblinGoodsSkuInfoVo> goodsSkuInfoVos) {
if (log.isDebugEnabled()) {
log.debug("dt1:{}", dt.toString());
}
boolean tobeNextSpuFlg = false;
if (null == lastGoodsInfoVo || !lastGoodsInfoVo.getName().equals(dt.getSpuName())) {
......
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