|
@@ -14,6 +14,7 @@ import com.ym.mec.biz.dal.dao.TeacherDao;
|
|
|
import com.ym.mec.biz.dal.dto.BasicUserDto;
|
|
|
import com.ym.mec.biz.dal.dto.GoodsSellDto;
|
|
|
import com.ym.mec.biz.dal.entity.Goods;
|
|
|
+import com.ym.mec.biz.dal.entity.GoodsCategory;
|
|
|
import com.ym.mec.biz.dal.entity.GoodsProcurement;
|
|
|
import com.ym.mec.biz.dal.entity.GoodsSub;
|
|
|
import com.ym.mec.biz.dal.entity.Organization;
|
|
@@ -42,6 +43,7 @@ import com.ym.mec.common.entity.GoodsSubStockModel;
|
|
|
import com.ym.mec.common.entity.UploadReturnBean;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
+import com.ym.mec.common.page.QueryInfo;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.common.tenant.TenantContextHolder;
|
|
@@ -67,6 +69,8 @@ import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
@@ -101,7 +105,8 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
private OrganizationDao organizationDao;
|
|
|
@Resource
|
|
|
private MallFeignService mallFeignService;
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ private GoodsCategoryService goodsCategoryService;
|
|
|
@Resource
|
|
|
private GoodsSubService goodsSubService;
|
|
|
@Resource
|
|
@@ -119,13 +124,9 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
if (CollectionUtils.isEmpty(rows)) {
|
|
|
throw new BizException("没有查询到商品信息");
|
|
|
}
|
|
|
- List<ProductCategoryDto> productCategoryDtos = treeToList(queryGoodsCategoryList());
|
|
|
- Map<Long, String> IdNamemap = productCategoryDtos.stream().collect(Collectors.toMap(ProductCategoryDto::getId, ProductCategoryDto::getName));
|
|
|
-
|
|
|
List<Organization> all = organizationDao.findAll(params);
|
|
|
Map<Integer, String> organizationMap = all.stream().collect(Collectors.toMap(Organization::getId, Organization::getName));
|
|
|
for (Goods goods : rows) {
|
|
|
- goods.setGoodsCategoryName(IdNamemap.getOrDefault(Long.valueOf(goods.getGoodsCategoryId()),""));
|
|
|
if(StringUtils.isNotEmpty(goods.getStudentShowOrganId())){
|
|
|
String[] split = goods.getStudentShowOrganId().split(",");
|
|
|
StringBuffer sb = new StringBuffer();
|
|
@@ -340,6 +341,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
PmsProductDto dto = map.get(next.getSku());
|
|
|
if (dto != null) {
|
|
|
next.setPrice(dto.getPrice());
|
|
|
+ next.setSkuCode(dto.getSkuCode());
|
|
|
if (1 == dto.getDeleteStatus()) {
|
|
|
next.setGoodsStatus(false);
|
|
|
} else {
|
|
@@ -375,29 +377,14 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public PageInfo<Goods> queryPage(GoodsQueryInfo queryInfo) {
|
|
|
- Integer goodsCategoryId = queryInfo.getGoodsCategoryId();
|
|
|
- if (goodsCategoryId != null) {
|
|
|
- Map<Long, ProductCategoryDto> idCategoryMap = mallFeignService.listWithChildren().stream().collect(Collectors.toMap(ProductCategoryDto::getId, Function.identity()));
|
|
|
- if (idCategoryMap.containsKey(Long.valueOf(goodsCategoryId))) {
|
|
|
- ProductCategoryDto productCategoryDto = idCategoryMap.get(Long.valueOf(goodsCategoryId));
|
|
|
- List<String> categoryIdList = productCategoryDto.getChildren().stream().map(ProductCategoryDto::getId).map(String::valueOf).distinct().collect(Collectors.toList());
|
|
|
- categoryIdList.add(goodsCategoryId.toString());
|
|
|
- queryInfo.setGoodsCategoryIds(String.join(",", categoryIdList));
|
|
|
- queryInfo.setGoodsCategoryId(null);
|
|
|
- }
|
|
|
- }
|
|
|
+ public PageInfo<Goods> queryPage(QueryInfo queryInfo) {
|
|
|
PageInfo<Goods> page = super.queryPage(queryInfo);
|
|
|
|
|
|
List<Goods> rows = page.getRows();
|
|
|
if (!rows.isEmpty()) {
|
|
|
Map<String, String> brandIdNameMap = this.queryGoodsBrandList().stream().collect(Collectors.toMap(next -> next.getId().toString(), BrandDto::getName));
|
|
|
- List<ProductCategoryDto> productCategoryDtos = treeToList(this.queryGoodsCategoryList());
|
|
|
- Map<Integer, String> categoryIdNameMap = productCategoryDtos.stream().collect(Collectors.toMap(next -> next.getId().intValue(), ProductCategoryDto::getName));
|
|
|
-
|
|
|
for (Goods row : rows) {
|
|
|
row.setBrandName(brandIdNameMap.getOrDefault(row.getBrand(), row.getBrand()));
|
|
|
- row.setGoodsCategoryName(categoryIdNameMap.getOrDefault(row.getGoodsCategoryId(), ""));
|
|
|
}
|
|
|
}
|
|
|
return page;
|
|
@@ -620,10 +607,10 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
goodsCategoryQueryInfo.setPage(1);
|
|
|
goodsCategoryQueryInfo.setRows(9999);
|
|
|
|
|
|
- List<ProductCategoryDto> categoryList = mallFeignService.listWithChildren();
|
|
|
- List<ProductCategoryDto> allCategoryList = categoryList.stream().map(ProductCategoryDto::getChildren).filter(next->!next.isEmpty()).flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
- Map<String, Long> categoryIdNameMap = allCategoryList
|
|
|
- .stream().collect(Collectors.toMap(ProductCategoryDto::getName, ProductCategoryDto::getId));
|
|
|
+
|
|
|
+ List<GoodsCategory> categoryList = goodsCategoryService.findAll(new HashMap<>()).stream().filter(next -> YesOrNoEnum.NO.equals(next.getDelFlag())).collect(Collectors.toList());
|
|
|
+ Map<String, Integer> categoryIdNameMap = categoryList
|
|
|
+ .stream().collect(Collectors.toMap(GoodsCategory::getName, GoodsCategory::getId));
|
|
|
Set<String> categoryNames = categoryIdNameMap.keySet();
|
|
|
|
|
|
// 查询员工机构
|
|
@@ -659,12 +646,18 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- List<String> snSet = firstSheet.stream().map(next -> next.get("组合商品货号").toString()).filter(StringUtils::isNotEmpty).distinct().collect(Collectors.toList());
|
|
|
- List<String> existSnList = goodsDao.findBySns(snSet).stream().map(Goods::getSn).distinct().collect(Collectors.toList());
|
|
|
+ // excel中所有的sn
|
|
|
+ List<String> snSet = firstSheet.stream().map(next -> next.get("组合商品货号").toString()).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
|
|
|
+ // 获取重复的货号
|
|
|
+ List<String> repeatSnList = snSet.stream().collect(Collectors.groupingBy(e -> e, Collectors.counting()))
|
|
|
+ .entrySet().stream().filter(e -> e.getValue() > 1)
|
|
|
+ .map(Map.Entry::getKey).collect(Collectors.toList());
|
|
|
+ List<String> existSnList = goodsDao.findBySns(snSet.stream().distinct().collect(Collectors.toList())).stream().map(Goods::getSn).distinct().collect(Collectors.toList());
|
|
|
|
|
|
Map<String, Long> brandNameIdMap = mallFeignService.getList().stream().collect(Collectors.toMap(BrandDto::getName, BrandDto::getId));
|
|
|
|
|
|
List<JSONObject> jsonObjectList = new ArrayList<>();
|
|
|
+ Map<String, byte[]> snImageMap = new HashMap<>();
|
|
|
for (Map.Entry<String, List<Map<String, Object>>> sheetData : sheetsListMap.entrySet()) {
|
|
|
List<Map<String, Object>> rows = sheetData.getValue();
|
|
|
if (rows.isEmpty()) {
|
|
@@ -680,9 +673,8 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
|
|
|
String lineErrMsg = "错误行号:第%s行,%s";
|
|
|
- Map<String, String> beforeGoods = new HashMap<>();
|
|
|
-
|
|
|
- Map<String, String> snNameMap = new HashMap<>();
|
|
|
+ Map<String, Object> beforeGoods = new HashMap<>();
|
|
|
+ Map<String, Set<String>> snSubGoodsMap = new HashMap<>();
|
|
|
for (int i = 0; i < rows.size(); i++) {
|
|
|
JSONObject objectMap = new JSONObject();
|
|
|
int rowNum = i + 2;
|
|
@@ -690,6 +682,11 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
if (row.size() == 0) {
|
|
|
continue;
|
|
|
}
|
|
|
+ // 新商品标志
|
|
|
+ String sn = row.get("组合商品货号").toString();
|
|
|
+ if (StringUtils.isNotEmpty(sn)) {
|
|
|
+ beforeGoods.clear();
|
|
|
+ }
|
|
|
String subGoodsName = null;
|
|
|
String subGoodsSku = null;
|
|
|
List<String> lineErrList = new ArrayList<>();
|
|
@@ -699,10 +696,10 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
continue;
|
|
|
}
|
|
|
String fieldCode = columns.get(fieldName);
|
|
|
- String value = entry.getValue().toString();
|
|
|
+ Object value = entry.getValue();
|
|
|
|
|
|
// 非子商品字段为空,往上一行获取值
|
|
|
- if (StringUtils.isEmpty(value)) {
|
|
|
+ if (StringUtils.isEmpty(value.toString())) {
|
|
|
if ("subGoodsName".equals(fieldCode) || "sku".equals(fieldCode) || "subGoodsPrice".equals(fieldCode)) {
|
|
|
lineErrList.add("字段‘" + fieldName + "’为空");
|
|
|
} else {
|
|
@@ -720,27 +717,28 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
+ if ("image".equals(fieldCode) && value instanceof List) { // 图片数组 取第一个
|
|
|
+ Object data = ((List<?>) value).get(0);
|
|
|
+ if (data instanceof PictureData) {
|
|
|
+ value = ((PictureData) data).getData();
|
|
|
+ }
|
|
|
+ }
|
|
|
beforeGoods.put(fieldCode, value);
|
|
|
}
|
|
|
- if("sn".equals(fieldCode)){
|
|
|
- if (existSnList.contains(value)) {
|
|
|
+ if ("sn".equals(fieldCode)) {
|
|
|
+ if (existSnList.contains(value.toString())) {
|
|
|
lineErrList.add("货号[" + value + "]已存在");
|
|
|
} else {
|
|
|
- String goodsName = row.get("组合商品名称").toString();
|
|
|
- if (snNameMap.containsKey(value) && !snNameMap.get(value).equals(goodsName)) {
|
|
|
+ if (repeatSnList.contains(value.toString())) {
|
|
|
lineErrList.add("货号[" + value + "]重复");
|
|
|
- } else {
|
|
|
- snNameMap.put(value, goodsName);
|
|
|
}
|
|
|
- objectMap.put(fieldCode, value);
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- if ("marketPrice".equals(fieldCode)
|
|
|
+ objectMap.put(fieldCode, value);
|
|
|
+ } else if ("marketPrice".equals(fieldCode)
|
|
|
|| "discountPrice".equals(fieldCode)
|
|
|
|| "groupPurchasePrice".equals(fieldCode)) {
|
|
|
- if (NumberUtils.isNumber(value)) {
|
|
|
- BigDecimal prize = new BigDecimal(value);
|
|
|
+ if (NumberUtils.isNumber(value.toString())) {
|
|
|
+ BigDecimal prize = new BigDecimal(value.toString());
|
|
|
if (BigDecimal.ZERO.compareTo(prize) > 0) {
|
|
|
lineErrList.add("字段‘" + fieldName + "’不能为负数");
|
|
|
} else {
|
|
@@ -751,7 +749,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
|
|
|
}
|
|
|
} else if ("type".equals(fieldCode)) {
|
|
|
- String tempValue = value;
|
|
|
+ String tempValue = value.toString();
|
|
|
Optional<GoodsType> first = Arrays.stream(GoodsType.values()).filter(next -> next.getDesc().equals(tempValue)).findFirst();
|
|
|
if (first.isPresent()) {
|
|
|
objectMap.put(fieldCode, first.get().getCode());
|
|
@@ -759,8 +757,8 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
lineErrList.add("字段‘" + fieldName + "’类型不支持");
|
|
|
}
|
|
|
} else if ("goodsCategoryName".equals(fieldCode)) {
|
|
|
- if(categoryNames.contains(value)){
|
|
|
- objectMap.put("goodsCategoryId", categoryIdNameMap.get(value).intValue());
|
|
|
+ if(categoryNames.contains(value.toString())){
|
|
|
+ objectMap.put("goodsCategoryId", categoryIdNameMap.get(value.toString()));
|
|
|
}else {
|
|
|
lineErrList.add("字段‘" + fieldName + "’不支持");
|
|
|
}
|
|
@@ -770,9 +768,9 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
|| "freeFeeShowOrganName".equals(fieldCode)
|
|
|
|| "replacementShowOrganName".equals(fieldCode)
|
|
|
) {
|
|
|
- if (StringUtils.isNotEmpty(value)) {
|
|
|
+ if (StringUtils.isNotEmpty(value.toString())) {
|
|
|
List<String> orgIds = new ArrayList<>();
|
|
|
- for (String orgName : value.split("[,,]")) {
|
|
|
+ for (String orgName : value.toString().split("[,,]")) {
|
|
|
if (!orgNameIdMap.containsKey(orgName)) {
|
|
|
lineErrList.add("字段‘" + fieldName + "’:‘" + value + "’分部不支持");
|
|
|
} else {
|
|
@@ -784,7 +782,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
objectMap.put(fieldKey, join);
|
|
|
}
|
|
|
} else if ("subGoodsName".equals(fieldCode)) {
|
|
|
- subGoodsName = value;
|
|
|
+ subGoodsName = value.toString();
|
|
|
if (StringUtils.isNotEmpty(subGoodsSku)) {
|
|
|
String key = subGoodsName + "_" + subGoodsSku;
|
|
|
if (skuMap.containsKey(key)) {
|
|
@@ -798,7 +796,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
}
|
|
|
} else if ("sku".equals(fieldCode)) {
|
|
|
- subGoodsSku = value;
|
|
|
+ subGoodsSku = value.toString();
|
|
|
if (StringUtils.isNotEmpty(subGoodsName)) {
|
|
|
String key = subGoodsName + "_" + subGoodsSku;
|
|
|
if (skuMap.containsKey(key)) {
|
|
@@ -812,13 +810,13 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
}
|
|
|
} else if ("subGoodsPrice".equals(fieldCode)) {
|
|
|
- BigDecimal subGoodsPrice = new BigDecimal(value);
|
|
|
+ BigDecimal subGoodsPrice = new BigDecimal(value.toString());
|
|
|
if (BigDecimal.ZERO.compareTo(subGoodsPrice) > 0) {
|
|
|
lineErrList.add("字段‘" + fieldName + "’不能为负数");
|
|
|
}
|
|
|
} else if ("brand".equals(fieldCode)) {
|
|
|
- if (brandNameIdMap.containsKey(value)) {
|
|
|
- objectMap.put("brand", brandNameIdMap.get(value));
|
|
|
+ if (brandNameIdMap.containsKey(value.toString())) {
|
|
|
+ objectMap.put("brand", brandNameIdMap.get(value.toString()));
|
|
|
} else {
|
|
|
lineErrList.add("组合商品品牌‘" + value + "’不支持");
|
|
|
}
|
|
@@ -833,8 +831,23 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
!objectMap.containsKey("memberFeeShowOrganId") &&
|
|
|
!objectMap.containsKey("freeFeeShowOrganId") &&
|
|
|
!objectMap.containsKey("replacementShowOrganId")) {
|
|
|
- lineErrList.add("可售分部至少需要选择一个");
|
|
|
+ lineErrList.add("可售分部至少需要填写一个");
|
|
|
+ }
|
|
|
+ // 校验子商品sku是否重复
|
|
|
+ String tempSn = objectMap.get("sn").toString();
|
|
|
+ String tempSku = objectMap.get("sku").toString();
|
|
|
+ byte[] images = objectMap.getBytes("image");
|
|
|
+ snImageMap.put(tempSn, images);
|
|
|
+ if (StringUtils.isNotEmpty(tempSn) && StringUtils.isNotEmpty(tempSku)) {
|
|
|
+ Set<String> set = snSubGoodsMap.getOrDefault(tempSn, new HashSet<>());
|
|
|
+ if (set.contains(tempSku)) {
|
|
|
+ lineErrList.add("子商品SKU重复");
|
|
|
+ } else {
|
|
|
+ set.add(tempSku);
|
|
|
+ snSubGoodsMap.put(tempSn, set);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if (!lineErrList.isEmpty()) {
|
|
|
errList.add(String.format(lineErrMsg, rowNum, String.join(",", lineErrList)));
|
|
|
}
|
|
@@ -852,8 +865,10 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
|
|
|
List<GoodsWrapper.Goods> goodsList = jsonObjectList.stream().map(next -> {
|
|
|
+ next.remove("image");
|
|
|
String jsonString = next.toJSONString();
|
|
|
GoodsWrapper.Goods goods = JSON.parseObject(jsonString, GoodsWrapper.Goods.class);
|
|
|
+ goods.setSellCount(0);
|
|
|
GoodsWrapper.GoodsSub goodsSub = JSON.parseObject(jsonString, GoodsWrapper.GoodsSub.class);
|
|
|
ArrayList<GoodsWrapper.GoodsSub> arrayList = new ArrayList<>();
|
|
|
arrayList.add(goodsSub);
|
|
@@ -867,8 +882,21 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
// // 数据合并
|
|
|
Map<Integer, Integer> skuIdMap = subGoods.stream().collect(Collectors.toMap(PmsProductDto::getSkuStockId, PmsProductDto::getStock));
|
|
|
|
|
|
- goodsGroup.forEach((key, value) -> {
|
|
|
+ for (Map.Entry<String, List<GoodsWrapper.Goods>> entry : goodsGroup.entrySet()) {
|
|
|
+ List<GoodsWrapper.Goods> value = entry.getValue();
|
|
|
GoodsWrapper.Goods good = value.get(0);
|
|
|
+ String sn = good.getSn();
|
|
|
+
|
|
|
+ // 图片上传
|
|
|
+ byte[] images = snImageMap.get(sn);
|
|
|
+ if (images != null && images.length > 0) {
|
|
|
+ File imgFile = createImportGoodsTempFile(UUID.randomUUID().toString().replaceAll("-","") + ".png");
|
|
|
+ BufferedImage read = ImageIO.read(new ByteArrayInputStream((images)));
|
|
|
+ ImageIO.write(read, "png", imgFile);
|
|
|
+ String url = ossPluginContext.getPluginService(TencentOssPlugin.PLUGIN_NAME).uploadFile("daya/" + UploadUtil.getFileFloder(), imgFile);
|
|
|
+ good.setImage(url);
|
|
|
+ imgFile.deleteOnExit();
|
|
|
+ }
|
|
|
List<GoodsWrapper.GoodsSub> goodsSubList = value.stream().map(GoodsWrapper.Goods::getGoodsSubList).flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
Integer stock = goodsSubList.stream().map(next -> skuIdMap.get(next.getSku())).min(Integer::compareTo).orElse(0);
|
|
|
|
|
@@ -886,8 +914,30 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
sub.setGoodsPrice(next.getGoodsPrice());
|
|
|
return sub;
|
|
|
}).collect(Collectors.toList());
|
|
|
- goodsSubService.saveBatch(subList);
|
|
|
- });
|
|
|
+ goodsSubService.saveBatch(subList);
|
|
|
+ }
|
|
|
+
|
|
|
+// goodsGroup.forEach((key, value) -> {
|
|
|
+// GoodsWrapper.Goods good = value.get(0);
|
|
|
+// List<GoodsWrapper.GoodsSub> goodsSubList = value.stream().map(GoodsWrapper.Goods::getGoodsSubList).flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
+// Integer stock = goodsSubList.stream().map(next -> skuIdMap.get(next.getSku())).min(Integer::compareTo).orElse(0);
|
|
|
+//
|
|
|
+// Goods goods = JSON.parseObject(JSON.toJSONString(good), Goods.class);
|
|
|
+// goods.setStatus(YesOrNoEnum.NO);
|
|
|
+// goods.setStockCount(stock);
|
|
|
+// this.insert(goods);
|
|
|
+//
|
|
|
+// List<GoodsSub> subList = goodsSubList.stream().map(next -> {
|
|
|
+// GoodsSub sub = new GoodsSub();
|
|
|
+// sub.setGoodsId(goods.getId());
|
|
|
+// sub.setMallGoodsId(next.getMallGoodsId());
|
|
|
+// sub.setSku(next.getSku());
|
|
|
+// sub.setGoodsStatus(next.getGoodsStatus());
|
|
|
+// sub.setGoodsPrice(next.getGoodsPrice());
|
|
|
+// return sub;
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+// goodsSubMapper.saveBatch(subList);
|
|
|
+// });
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -1194,10 +1244,6 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
GoodsWrapper.Goods detail = JSON.parseObject(JSON.toJSONString(goods), GoodsWrapper.Goods.class);
|
|
|
detail.setGoodsSubList(queryGoodsSubByGoodId(goodsId));
|
|
|
-
|
|
|
- List<ProductCategoryDto> productCategoryDtos = treeToList(queryGoodsCategoryList());
|
|
|
- Map<Long, String> IdNamemap = productCategoryDtos.stream().collect(Collectors.toMap(ProductCategoryDto::getId, ProductCategoryDto::getName));
|
|
|
- detail.setGoodsCategoryName(IdNamemap.getOrDefault(Long.valueOf(detail.getGoodsCategoryId()), ""));
|
|
|
return detail;
|
|
|
}
|
|
|
|
|
@@ -1390,22 +1436,27 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
return mallFeignService.listWithChildren();
|
|
|
}
|
|
|
|
|
|
- private String getExportErrLogFile(List<String> errList) {
|
|
|
- if (CollectionUtils.isEmpty(errList)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
+ private File createImportGoodsTempFile(String fileName) {
|
|
|
String basePath = new ApplicationHome(this.getClass()).getSource().getParentFile().getPath();
|
|
|
- String format = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
|
|
|
- File file = new File(basePath + File.separator + format + ".csv");
|
|
|
+ File file = new File(basePath + File.separator + "daya" + File.separator + "importGoods" + File.separator + fileName);
|
|
|
try {
|
|
|
if (!file.getParentFile().exists()) {
|
|
|
file.getParentFile().mkdirs();
|
|
|
}
|
|
|
file.createNewFile();
|
|
|
+ return file;
|
|
|
} catch (IOException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ throw new BizException("导入失败,回执文件上传失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getExportErrLogFile(List<String> errList) {
|
|
|
+ if (CollectionUtils.isEmpty(errList)) {
|
|
|
+ return null;
|
|
|
}
|
|
|
+
|
|
|
+ String format = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
|
|
|
+ File file = createImportGoodsTempFile(format + ".csv");
|
|
|
try {
|
|
|
FileOutputStream out = new FileOutputStream(file);
|
|
|
byte[] uft8bom = {(byte) 0xef, (byte) 0xbb, (byte) 0xbf}; // 处理乱码
|
|
@@ -1421,25 +1472,12 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
String folder = "daya/download/" + UploadUtil.getFileFloder();
|
|
|
return ossPluginContext.getPluginService(TencentOssPlugin.PLUGIN_NAME).uploadFile(folder, file);
|
|
|
} catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("上传错误回执文件失败:{}",e.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (file.exists()) {
|
|
|
+ file.deleteOnExit();
|
|
|
+ }
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
-
|
|
|
- public List<ProductCategoryDto> treeToList(List<ProductCategoryDto> categoryList) {
|
|
|
- if (categoryList.isEmpty()) {
|
|
|
- return new ArrayList<>();
|
|
|
- }
|
|
|
- List<ProductCategoryDto> result = new ArrayList<>();
|
|
|
- categoryList.forEach(next -> {
|
|
|
- result.add(next);
|
|
|
- String name = next.getName();
|
|
|
- List<ProductCategoryDto> children = next.getChildren();
|
|
|
- if (!CollectionUtils.isEmpty(children)) {
|
|
|
- children.forEach(c -> c.setName(name + "/" + c.getName()));
|
|
|
- result.addAll(children);
|
|
|
- }
|
|
|
- });
|
|
|
- return result;
|
|
|
- }
|
|
|
}
|