|
@@ -38,7 +38,7 @@ import com.yami.shop.common.exception.YamiShopBindException;
|
|
|
import com.yami.shop.common.util.Arith;
|
|
|
import com.yami.shop.common.util.Json;
|
|
|
import com.yami.shop.common.util.PageParam;
|
|
|
-import com.yami.shop.common.util.PoiExcelUtil;
|
|
|
+//import com.yami.shop.common.util.PoiExcelUtil;
|
|
|
import com.yami.shop.dao.*;
|
|
|
import com.yami.shop.service.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
@@ -487,174 +487,178 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
|
|
|
@Override
|
|
|
public Object parseFile(MultipartFile file, Long shopId) throws Exception {
|
|
|
- //读取工作簿
|
|
|
- Workbook workBook = WorkbookFactory.create(file.getInputStream());
|
|
|
- //读取工作表
|
|
|
- Sheet sheet = workBook.getSheetAt(0);
|
|
|
- int rowNumber = sheet.getPhysicalNumberOfRows();
|
|
|
-
|
|
|
- //校验是否填写内容
|
|
|
- if (rowNumber <= 2) {
|
|
|
- throw new GlobalException("文件无内容!");
|
|
|
- }
|
|
|
- // * 2.1不是Excel文件,直接返回提示信息
|
|
|
- if (!(file.getOriginalFilename().contains("xls") || file.getOriginalFilename().contains("xlsx"))) {
|
|
|
- // 格式错误
|
|
|
- throw new YamiShopBindException("文件格式错误");
|
|
|
- }
|
|
|
-
|
|
|
- //TODO 如果三级分类需要获取最底层的分类
|
|
|
- // 获取平台分类map
|
|
|
- List<Category> categories = categoryService.list(new LambdaQueryWrapper<Category>()
|
|
|
- .eq(Category::getShopId,0).eq(Category::getGrade,2));
|
|
|
- // 如果重复的key取最后一个的值
|
|
|
- Map<String, Long> categoryMap = categories.stream().collect(Collectors.toMap(Category::getCategoryName, Category::getCategoryId,(key1 , key2)-> key2));
|
|
|
-
|
|
|
- // 获取店铺分类map
|
|
|
- List<Category> shopCategories = categoryService.listByShopId(shopId);
|
|
|
- // 如果重复的key取最后一个的值
|
|
|
- Map<String, Long> shopCategoryMap = shopCategories.stream().collect(Collectors.toMap(Category::getCategoryName, Category::getCategoryId,(key1 , key2)-> key2));
|
|
|
-
|
|
|
- // 获取品牌map
|
|
|
- List<Brand> brands = brandService.list(new LambdaQueryWrapper<Brand>().eq(Brand::getStatus, 1));
|
|
|
- Map<String, Long> brandMap = brands.stream().collect(Collectors.toMap(Brand::getBrandName, Brand::getBrandId,(key1 , key2)-> key2));
|
|
|
-
|
|
|
- // 获取运费模板map
|
|
|
- List<TransportParam> transportParams = new ArrayList<>();
|
|
|
- applicationContext.publishEvent(new GetTransportNamesEvent(transportParams,shopId));
|
|
|
- Map<String, Long> transportMap = transportParams.stream().collect(Collectors.toMap(TransportParam::getTransName, TransportParam::getTransportId,(key1 , key2)-> key2));
|
|
|
-
|
|
|
- List<Product> products = new ArrayList<>();
|
|
|
- List<Sku> skuList = new ArrayList<>();
|
|
|
- Date date = new Date();
|
|
|
- Integer totalStocks = 0;
|
|
|
- double price = 0.0;
|
|
|
- double oriPrice = 0.0;
|
|
|
- Integer scorePrice = 0;
|
|
|
- int insertRows = 0;
|
|
|
- Product product = new Product();
|
|
|
- //循环读取每一行数据并校验
|
|
|
- for (int i = 2; i < rowNumber; i++) {
|
|
|
- try {
|
|
|
- //读取行
|
|
|
- Row row = sheet.getRow(i);
|
|
|
-// String[] hearder = { "产品名称", "平台分类", "店铺分类", "所属品牌", "产品卖点", "配送方式","运费设置",
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+// @Override
|
|
|
+// public Object parseFile(MultipartFile file, Long shopId) throws Exception {
|
|
|
+// //读取工作簿
|
|
|
+// Workbook workBook = WorkbookFactory.create(file.getInputStream());
|
|
|
+// //读取工作表
|
|
|
+// Sheet sheet = workBook.getSheetAt(0);
|
|
|
+// int rowNumber = sheet.getPhysicalNumberOfRows();
|
|
|
+//
|
|
|
+// //校验是否填写内容
|
|
|
+// if (rowNumber <= 2) {
|
|
|
+// throw new GlobalException("文件无内容!");
|
|
|
+// }
|
|
|
+// // * 2.1不是Excel文件,直接返回提示信息
|
|
|
+// if (!(file.getOriginalFilename().contains("xls") || file.getOriginalFilename().contains("xlsx"))) {
|
|
|
+// // 格式错误
|
|
|
+// throw new YamiShopBindException("文件格式错误");
|
|
|
+// }
|
|
|
+//
|
|
|
+// //TODO 如果三级分类需要获取最底层的分类
|
|
|
+// // 获取平台分类map
|
|
|
+// List<Category> categories = categoryService.list(new LambdaQueryWrapper<Category>()
|
|
|
+// .eq(Category::getShopId,0).eq(Category::getGrade,2));
|
|
|
+// // 如果重复的key取最后一个的值
|
|
|
+// Map<String, Long> categoryMap = categories.stream().collect(Collectors.toMap(Category::getCategoryName, Category::getCategoryId,(key1 , key2)-> key2));
|
|
|
+//
|
|
|
+// // 获取店铺分类map
|
|
|
+// List<Category> shopCategories = categoryService.listByShopId(shopId);
|
|
|
+// // 如果重复的key取最后一个的值
|
|
|
+// Map<String, Long> shopCategoryMap = shopCategories.stream().collect(Collectors.toMap(Category::getCategoryName, Category::getCategoryId,(key1 , key2)-> key2));
|
|
|
+//
|
|
|
+// // 获取品牌map
|
|
|
+// List<Brand> brands = brandService.list(new LambdaQueryWrapper<Brand>().eq(Brand::getStatus, 1));
|
|
|
+// Map<String, Long> brandMap = brands.stream().collect(Collectors.toMap(Brand::getBrandName, Brand::getBrandId,(key1 , key2)-> key2));
|
|
|
+//
|
|
|
+// // 获取运费模板map
|
|
|
+// List<TransportParam> transportParams = new ArrayList<>();
|
|
|
+// applicationContext.publishEvent(new GetTransportNamesEvent(transportParams,shopId));
|
|
|
+// Map<String, Long> transportMap = transportParams.stream().collect(Collectors.toMap(TransportParam::getTransName, TransportParam::getTransportId,(key1 , key2)-> key2));
|
|
|
+//
|
|
|
+// List<Product> products = new ArrayList<>();
|
|
|
+// List<Sku> skuList = new ArrayList<>();
|
|
|
+// Date date = new Date();
|
|
|
+// Integer totalStocks = 0;
|
|
|
+// double price = 0.0;
|
|
|
+// double oriPrice = 0.0;
|
|
|
+// Integer scorePrice = 0;
|
|
|
+// int insertRows = 0;
|
|
|
+// Product product = new Product();
|
|
|
+// //循环读取每一行数据并校验
|
|
|
+// for (int i = 2; i < rowNumber; i++) {
|
|
|
+// try {
|
|
|
+// //读取行
|
|
|
+// Row row = sheet.getRow(i);
|
|
|
+//// String[] hearder = { "产品名称", "平台分类", "店铺分类", "所属品牌", "产品卖点", "配送方式","运费设置",
|
|
|
+//// "规格名称","商品名称", "销售属性组合字符串 格式是p1:v1;p2:v2", "原价", "价格", "积分价格",
|
|
|
+//// "库存","商家编码","商品条形码" ,"商品重量", "商品体积","产品状态"};
|
|
|
+// String prodName = Objects.isNull(row.getCell(0))? "":row.getCell(0).getStringCellValue();
|
|
|
+// String category = Objects.isNull(row.getCell(1))? "":row.getCell(1).getStringCellValue();
|
|
|
+// String shopCategory = Objects.isNull(row.getCell(2))? "":row.getCell(2).getStringCellValue();
|
|
|
+// String brandName = Objects.isNull(row.getCell(3))? "":row.getCell(3).getStringCellValue();
|
|
|
+// String brif = Objects.isNull(row.getCell(4))? "":row.getCell(4).getStringCellValue();
|
|
|
+// String dvyType = Objects.isNull(row.getCell(5))? "":row.getCell(5).getStringCellValue();
|
|
|
+// String transportName = Objects.isNull(row.getCell(6))? "":row.getCell(6).getStringCellValue();
|
|
|
+// String statusStr = Objects.isNull(row.getCell(7))? "":row.getCell(7).getStringCellValue();
|
|
|
+// if(StrUtil.isNotBlank(prodName) || !PoiExcelUtil.isMergedRegion(sheet,i,0)) {
|
|
|
+// skuList = new ArrayList<>();
|
|
|
+// product = new Product();
|
|
|
+// totalStocks = 0;
|
|
|
+// oriPrice = 0.0;
|
|
|
+// scorePrice = 0;
|
|
|
+// price = 0.0;
|
|
|
+// insertRows++;
|
|
|
+// product.setShopId(shopId);
|
|
|
+// product.setProdName(prodName);
|
|
|
+// product.setCategoryId(categoryMap.get(category));
|
|
|
+// product.setShopCategoryId(shopCategoryMap.get(shopCategory));
|
|
|
+// product.setBrandId(brandMap.get(brandName));
|
|
|
+// product.setBrief(brif);
|
|
|
+// product.setDeliveryMode(getDvyType(dvyType));
|
|
|
+// product.setDeliveryTemplateId(transportMap.get(transportName));
|
|
|
+// //TODO 差商品的图片
|
|
|
+// product.setStatus(Objects.equals(statusStr, "上架") ? ProdStatusEnums.NORMAL.getValue() : ProdStatusEnums.SHOP_OFFLINE.getValue());
|
|
|
+// product.setPutawayTime(Objects.equals(statusStr, "上架") ? date : null);
|
|
|
+// product.setCreateTime(date);
|
|
|
+// product.setUpdateTime(date);
|
|
|
+// product.setVersion(0);
|
|
|
+// // 商品销量设置为0
|
|
|
+// product.setSoldNum(0);
|
|
|
+// product.setProdType(ProdType.PROD_TYPE_NORMAL.value());
|
|
|
+// product.setActivityId(0L);
|
|
|
+// product.setPic("2020/07/f29c335ff19746cda1025f363dcc00cf.png");
|
|
|
+// product.setImgs("2020/07/f29c335ff19746cda1025f363dcc00cf.png");
|
|
|
+//
|
|
|
+// products.add(product);
|
|
|
+// }
|
|
|
+// String[] hearder = { "产品名称", "平台分类", "店铺分类", "所属品牌", "产品卖点", "配送方式","运费设置","产品状态",
|
|
|
// "规格名称","商品名称", "销售属性组合字符串 格式是p1:v1;p2:v2", "原价", "价格", "积分价格",
|
|
|
-// "库存","商家编码","商品条形码" ,"商品重量", "商品体积","产品状态"};
|
|
|
- String prodName = Objects.isNull(row.getCell(0))? "":row.getCell(0).getStringCellValue();
|
|
|
- String category = Objects.isNull(row.getCell(1))? "":row.getCell(1).getStringCellValue();
|
|
|
- String shopCategory = Objects.isNull(row.getCell(2))? "":row.getCell(2).getStringCellValue();
|
|
|
- String brandName = Objects.isNull(row.getCell(3))? "":row.getCell(3).getStringCellValue();
|
|
|
- String brif = Objects.isNull(row.getCell(4))? "":row.getCell(4).getStringCellValue();
|
|
|
- String dvyType = Objects.isNull(row.getCell(5))? "":row.getCell(5).getStringCellValue();
|
|
|
- String transportName = Objects.isNull(row.getCell(6))? "":row.getCell(6).getStringCellValue();
|
|
|
- String statusStr = Objects.isNull(row.getCell(7))? "":row.getCell(7).getStringCellValue();
|
|
|
- if(StrUtil.isNotBlank(prodName) || !PoiExcelUtil.isMergedRegion(sheet,i,0)) {
|
|
|
- skuList = new ArrayList<>();
|
|
|
- product = new Product();
|
|
|
- totalStocks = 0;
|
|
|
- oriPrice = 0.0;
|
|
|
- scorePrice = 0;
|
|
|
- price = 0.0;
|
|
|
- insertRows++;
|
|
|
- product.setShopId(shopId);
|
|
|
- product.setProdName(prodName);
|
|
|
- product.setCategoryId(categoryMap.get(category));
|
|
|
- product.setShopCategoryId(shopCategoryMap.get(shopCategory));
|
|
|
- product.setBrandId(brandMap.get(brandName));
|
|
|
- product.setBrief(brif);
|
|
|
- product.setDeliveryMode(getDvyType(dvyType));
|
|
|
- product.setDeliveryTemplateId(transportMap.get(transportName));
|
|
|
- //TODO 差商品的图片
|
|
|
- product.setStatus(Objects.equals(statusStr, "上架") ? ProdStatusEnums.NORMAL.getValue() : ProdStatusEnums.SHOP_OFFLINE.getValue());
|
|
|
- product.setPutawayTime(Objects.equals(statusStr, "上架") ? date : null);
|
|
|
- product.setCreateTime(date);
|
|
|
- product.setUpdateTime(date);
|
|
|
- product.setVersion(0);
|
|
|
- // 商品销量设置为0
|
|
|
- product.setSoldNum(0);
|
|
|
- product.setProdType(ProdType.PROD_TYPE_NORMAL.value());
|
|
|
- product.setActivityId(0L);
|
|
|
- product.setPic("2020/07/f29c335ff19746cda1025f363dcc00cf.png");
|
|
|
- product.setImgs("2020/07/f29c335ff19746cda1025f363dcc00cf.png");
|
|
|
-
|
|
|
- products.add(product);
|
|
|
- }
|
|
|
- String[] hearder = { "产品名称", "平台分类", "店铺分类", "所属品牌", "产品卖点", "配送方式","运费设置","产品状态",
|
|
|
- "规格名称","商品名称", "销售属性组合字符串 格式是p1:v1;p2:v2", "原价", "价格", "积分价格",
|
|
|
- "库存","商家编码","商品条形码" ,"商品重量", "商品体积"};
|
|
|
- String skuName = Objects.isNull(row.getCell(8))? "":row.getCell(8).getStringCellValue();
|
|
|
- String skuProdName = Objects.isNull(row.getCell(9))? "":row.getCell(9).getStringCellValue();
|
|
|
- String properties = Objects.isNull(row.getCell(10))? "":row.getCell(10).getStringCellValue();
|
|
|
- double skuOriPrice = Objects.isNull(row.getCell(11))? 0.0:row.getCell(11).getNumericCellValue();
|
|
|
- double skuPrice = Objects.isNull(row.getCell(12))? 0.0:row.getCell(12).getNumericCellValue();
|
|
|
- Integer skuScorePrice = Integer.valueOf(StrUtil.isBlank(row.getCell(13).getStringCellValue())? "0":row.getCell(13).getStringCellValue());
|
|
|
- Integer stocks = Objects.isNull(row.getCell(14))? 0:(int)(row.getCell(14).getNumericCellValue());
|
|
|
- String partyCode = "";
|
|
|
- if(Objects.nonNull(row.getCell(15))) {
|
|
|
- row.getCell(15).setCellType(CellType.STRING);
|
|
|
- partyCode = row.getCell(15).getStringCellValue();
|
|
|
- }
|
|
|
- String modelId = "";
|
|
|
- if(Objects.nonNull(row.getCell(15))) {
|
|
|
- row.getCell(16).setCellType(CellType.STRING);
|
|
|
- modelId = row.getCell(15).getStringCellValue();
|
|
|
- }
|
|
|
- double weight = Objects.isNull(row.getCell(17))? 0.0:row.getCell(17).getNumericCellValue();
|
|
|
- double volume = Objects.isNull(row.getCell(18))? 0.0:row.getCell(18).getNumericCellValue();
|
|
|
- oriPrice = Objects.equals(oriPrice ,0.0) ? skuOriPrice:oriPrice;
|
|
|
- price = Objects.equals(price ,0.0) ? skuPrice:price;
|
|
|
-
|
|
|
- Sku sku = new Sku();
|
|
|
- sku.setSkuName(skuName);
|
|
|
- sku.setProdName(skuProdName);
|
|
|
- sku.setProperties(properties);
|
|
|
- sku.setOriPrice(skuOriPrice);
|
|
|
- sku.setPrice(skuPrice);
|
|
|
- sku.setStocks(stocks);
|
|
|
- sku.setSkuScore(skuScorePrice);
|
|
|
- sku.setModelId(modelId);
|
|
|
- sku.setPartyCode(partyCode);
|
|
|
- sku.setVolume(volume);
|
|
|
- sku.setUpdateTime(date);
|
|
|
- sku.setWeight(weight);
|
|
|
- sku.setVersion(1);
|
|
|
- sku.setIsDelete(0);
|
|
|
- sku.setStatus(1);
|
|
|
- skuList.add(sku);
|
|
|
- // 如果prodName为空并且为合并行则为一个prod
|
|
|
- totalStocks += stocks;
|
|
|
- if(price > skuPrice) {
|
|
|
- oriPrice = skuOriPrice;
|
|
|
- price = skuPrice;
|
|
|
- scorePrice = skuScorePrice;
|
|
|
- }
|
|
|
- product.setOriPrice(oriPrice);
|
|
|
- product.setScorePrice(scorePrice);
|
|
|
- product.setPrice(price);
|
|
|
- product.setTotalStocks(totalStocks);
|
|
|
- product.setSkuList(skuList);
|
|
|
- } catch (Exception e) {
|
|
|
- //错误信息提示
|
|
|
- System.out.println("第" + (i + 1) + "行数据有错误," + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- workBook.close();
|
|
|
- //不为空批量导入
|
|
|
- if(CollectionUtils.isNotEmpty(products)){
|
|
|
- saveBatch(products);
|
|
|
-// List<Sku> skuDb = new ArrayList<>();
|
|
|
- for (Product productDb : products) {
|
|
|
- List<Sku> skus = productDb.getSkuList();
|
|
|
- skuMapper.insertBatch(productDb.getProdId(),skus);
|
|
|
-// skus.forEach(sku -> sku.setProdId(product.getProdId()));
|
|
|
-// skuDb.addAll(skus);
|
|
|
- }
|
|
|
-// skuMapper.save(skuDb);
|
|
|
- return "检查到" + insertRows + "条商品,成功导入" + products.size() + "条卡密!";
|
|
|
- }
|
|
|
- return "数据错误!导入0条";
|
|
|
- }
|
|
|
+// "库存","商家编码","商品条形码" ,"商品重量", "商品体积"};
|
|
|
+// String skuName = Objects.isNull(row.getCell(8))? "":row.getCell(8).getStringCellValue();
|
|
|
+// String skuProdName = Objects.isNull(row.getCell(9))? "":row.getCell(9).getStringCellValue();
|
|
|
+// String properties = Objects.isNull(row.getCell(10))? "":row.getCell(10).getStringCellValue();
|
|
|
+// double skuOriPrice = Objects.isNull(row.getCell(11))? 0.0:row.getCell(11).getNumericCellValue();
|
|
|
+// double skuPrice = Objects.isNull(row.getCell(12))? 0.0:row.getCell(12).getNumericCellValue();
|
|
|
+// Integer skuScorePrice = Integer.valueOf(StrUtil.isBlank(row.getCell(13).getStringCellValue())? "0":row.getCell(13).getStringCellValue());
|
|
|
+// Integer stocks = Objects.isNull(row.getCell(14))? 0:(int)(row.getCell(14).getNumericCellValue());
|
|
|
+// String partyCode = "";
|
|
|
+// if(Objects.nonNull(row.getCell(15))) {
|
|
|
+// row.getCell(15).setCellType(CellType.STRING);
|
|
|
+// partyCode = row.getCell(15).getStringCellValue();
|
|
|
+// }
|
|
|
+// String modelId = "";
|
|
|
+// if(Objects.nonNull(row.getCell(15))) {
|
|
|
+// row.getCell(16).setCellType(CellType.STRING);
|
|
|
+// modelId = row.getCell(15).getStringCellValue();
|
|
|
+// }
|
|
|
+// double weight = Objects.isNull(row.getCell(17))? 0.0:row.getCell(17).getNumericCellValue();
|
|
|
+// double volume = Objects.isNull(row.getCell(18))? 0.0:row.getCell(18).getNumericCellValue();
|
|
|
+// oriPrice = Objects.equals(oriPrice ,0.0) ? skuOriPrice:oriPrice;
|
|
|
+// price = Objects.equals(price ,0.0) ? skuPrice:price;
|
|
|
+//
|
|
|
+// Sku sku = new Sku();
|
|
|
+// sku.setSkuName(skuName);
|
|
|
+// sku.setProdName(skuProdName);
|
|
|
+// sku.setProperties(properties);
|
|
|
+// sku.setOriPrice(skuOriPrice);
|
|
|
+// sku.setPrice(skuPrice);
|
|
|
+// sku.setStocks(stocks);
|
|
|
+// sku.setSkuScore(skuScorePrice);
|
|
|
+// sku.setModelId(modelId);
|
|
|
+// sku.setPartyCode(partyCode);
|
|
|
+// sku.setVolume(volume);
|
|
|
+// sku.setUpdateTime(date);
|
|
|
+// sku.setWeight(weight);
|
|
|
+// sku.setVersion(1);
|
|
|
+// sku.setIsDelete(0);
|
|
|
+// sku.setStatus(1);
|
|
|
+// skuList.add(sku);
|
|
|
+// // 如果prodName为空并且为合并行则为一个prod
|
|
|
+// totalStocks += stocks;
|
|
|
+// if(price > skuPrice) {
|
|
|
+// oriPrice = skuOriPrice;
|
|
|
+// price = skuPrice;
|
|
|
+// scorePrice = skuScorePrice;
|
|
|
+// }
|
|
|
+// product.setOriPrice(oriPrice);
|
|
|
+// product.setScorePrice(scorePrice);
|
|
|
+// product.setPrice(price);
|
|
|
+// product.setTotalStocks(totalStocks);
|
|
|
+// product.setSkuList(skuList);
|
|
|
+// } catch (Exception e) {
|
|
|
+// //错误信息提示
|
|
|
+// System.out.println("第" + (i + 1) + "行数据有错误," + e.getMessage());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// workBook.close();
|
|
|
+// //不为空批量导入
|
|
|
+// if(CollectionUtils.isNotEmpty(products)){
|
|
|
+// saveBatch(products);
|
|
|
+//// List<Sku> skuDb = new ArrayList<>();
|
|
|
+// for (Product productDb : products) {
|
|
|
+// List<Sku> skus = productDb.getSkuList();
|
|
|
+// skuMapper.insertBatch(productDb.getProdId(),skus);
|
|
|
+//// skus.forEach(sku -> sku.setProdId(product.getProdId()));
|
|
|
+//// skuDb.addAll(skus);
|
|
|
+// }
|
|
|
+//// skuMapper.save(skuDb);
|
|
|
+// return "检查到" + insertRows + "条商品,成功导入" + products.size() + "条卡密!";
|
|
|
+// }
|
|
|
+// return "数据错误!导入0条";
|
|
|
+// }
|
|
|
|
|
|
@Override
|
|
|
public IPage<Product> pageProducts(PageParam<Product> page, ProductParam product) {
|