|
@@ -13,7 +13,6 @@ import com.ym.mec.biz.dal.dao.SellOrderDao;
|
|
|
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.dto.SubjectGoodsDto;
|
|
|
import com.ym.mec.biz.dal.entity.Goods;
|
|
|
import com.ym.mec.biz.dal.entity.GoodsProcurement;
|
|
|
import com.ym.mec.biz.dal.entity.GoodsSub;
|
|
@@ -48,6 +47,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;
|
|
@@ -73,18 +73,9 @@ import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.BufferedWriter;
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.FileWriter;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.io.OutputStream;
|
|
|
-import java.io.OutputStreamWriter;
|
|
|
+import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
-import java.nio.file.Files;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
@@ -302,7 +293,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
throw new BizException("{}等商品还在销售中", goodsNames);
|
|
|
}
|
|
|
}
|
|
|
- List<GoodsWrapper.GoodsSub> goodsSubs = queryGoodsSub(goodsId);
|
|
|
+ List<GoodsWrapper.GoodsSub> goodsSubs = queryGoodsSubByGoodId(goodsId);
|
|
|
if (!CollectionUtils.isEmpty(goodsSubs) && status == 1) {
|
|
|
long falseSize = goodsSubs.stream().map(GoodsWrapper.GoodsSub::getGoodsStatus).filter(Boolean.FALSE::equals).count();
|
|
|
if (falseSize > 0) {
|
|
@@ -323,7 +314,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
goodsDao.update(goods);
|
|
|
}
|
|
|
|
|
|
- private List<GoodsWrapper.GoodsSub> queryGoodsSub(Integer goodsId) {
|
|
|
+ private List<GoodsWrapper.GoodsSub> queryGoodsSubByGoodId(Integer goodsId) {
|
|
|
// 从管乐迷商城组合的商品
|
|
|
QueryWrapper<GoodsSub> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("goods_id_", goodsId);
|
|
@@ -331,7 +322,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
if (goodsSubs.isEmpty()) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
- List<String> skuList = goodsSubs.stream().map(next -> next.getSku().toString()).distinct().collect(Collectors.toList());
|
|
|
+// List<String> skuList = goodsSubs.stream().map(next -> next.getSku().toString()).distinct().collect(Collectors.toList());
|
|
|
List<GoodsWrapper.GoodsSub> goodsSubList = goodsSubs.stream().map(next -> {
|
|
|
GoodsWrapper.GoodsSub goodsSub = new GoodsWrapper.GoodsSub();
|
|
|
goodsSub.setId(next.getId());
|
|
@@ -342,13 +333,15 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
goodsSub.setGoodsPrice(next.getGoodsPrice());
|
|
|
return goodsSub;
|
|
|
}).collect(Collectors.toList());
|
|
|
+ List<String> goodIdList = goodsSubs.stream().map(next -> next.getMallGoodsId().toString()).distinct().collect(Collectors.toList());
|
|
|
PmsProductQueryParamDto build = PmsProductQueryParamDto.builder()
|
|
|
- .skuStockIds(String.join(",", skuList))
|
|
|
+ .productIds(String.join(",", goodIdList))
|
|
|
.pageSize(9999)
|
|
|
.pageNum(1).build();
|
|
|
build.setJson(JSON.toJSONString(build));
|
|
|
- Map<Integer, PmsProductDto> map = mallFeignService.getProductList(build)
|
|
|
- .getRows().stream().collect(Collectors.toMap(PmsProductDto::getSkuStockId, Function.identity()));
|
|
|
+ List<PmsProductDto> rows = mallFeignService.getProductList(build).getRows();
|
|
|
+ Map<Integer, PmsProductDto> map = rows.stream().collect(Collectors.toMap(PmsProductDto::getSkuStockId, Function.identity()));
|
|
|
+ Map<Long, List<PmsProductDto>> groupByGoodId = rows.stream().collect(Collectors.groupingBy(PmsProductDto::getGoodsId));
|
|
|
goodsSubList.forEach(next -> {
|
|
|
PmsProductDto dto = map.get(next.getSku());
|
|
|
if (dto != null) {
|
|
@@ -358,8 +351,11 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
} else {
|
|
|
next.setGoodsStatus(dto.getPublishStatus() == 1);
|
|
|
}
|
|
|
- next.setMallGoodsName(dto.getName());
|
|
|
- next.setProductSn(dto.getProductSn());
|
|
|
+ }
|
|
|
+ if(groupByGoodId.containsKey(Long.valueOf(next.getMallGoodsId()))){
|
|
|
+ PmsProductDto dto1 = groupByGoodId.get(Long.valueOf(next.getMallGoodsId())).get(0);
|
|
|
+ next.setMallGoodsName(dto1.getName());
|
|
|
+ next.setProductSn(dto1.getProductSn());
|
|
|
}
|
|
|
});
|
|
|
return goodsSubList;
|
|
@@ -385,6 +381,24 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
public List<Goods> importGoods(MultipartFile file, Integer operatorId) throws Exception {
|
|
|
Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
|
|
@@ -600,8 +614,11 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
goodsCategoryQueryInfo.setDelFlag(YesOrNoEnum.NO);
|
|
|
goodsCategoryQueryInfo.setPage(1);
|
|
|
goodsCategoryQueryInfo.setRows(9999);
|
|
|
- Map<String, Integer> categoryIdNameMap = goodsCategoryService.querySubjectGoods(goodsCategoryQueryInfo).getRows()
|
|
|
- .stream().collect(Collectors.toMap(SubjectGoodsDto::getGoodsCategoryName, SubjectGoodsDto::getGoodsCategoryId));
|
|
|
+
|
|
|
+ List<ProductCategoryDto> categoryList = mallFeignService.listWithChildren();
|
|
|
+ List<ProductCategoryDto> allCategoryList = treeToList(categoryList);
|
|
|
+ Map<String, Long> categoryIdNameMap = allCategoryList
|
|
|
+ .stream().collect(Collectors.toMap(ProductCategoryDto::getName, ProductCategoryDto::getId));
|
|
|
Set<String> categoryNames = categoryIdNameMap.keySet();
|
|
|
|
|
|
// 查询员工机构
|
|
@@ -612,14 +629,14 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
|
|
|
Map<String, String> columns = IniFileUtil.readIniFile(inputStream, TemplateTypeEnum.GOODS_GROUP.getMsg());
|
|
|
|
|
|
- List<Map<String, Object>> firstSheet = sheetsListMap.get(0);
|
|
|
+ List<Map<String, Object>> firstSheet = sheetsListMap.entrySet().iterator().next().getValue();
|
|
|
List<String> skuList = firstSheet.stream().map(next -> next.get("SKU").toString()).distinct().collect(Collectors.toList());
|
|
|
|
|
|
List<PmsProductDto> subGoods;
|
|
|
try {
|
|
|
// 查询SKU对应商品
|
|
|
PmsProductQueryParamDto dto = PmsProductQueryParamDto.builder()
|
|
|
- .skuStockIds(String.join(",", skuList))
|
|
|
+ .skuStockCodes(String.join(",", skuList))
|
|
|
.pageNum(1)
|
|
|
.pageSize(9999)
|
|
|
.build();
|
|
@@ -629,11 +646,15 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
errList.add("商城服务调用失败");
|
|
|
return getExportErrLogFile(errList);
|
|
|
}
|
|
|
- Map<String, PmsProductDto>skuMap = subGoods.stream().collect(Collectors.toMap(next -> (next.getName() + "_" + next.getSkuCode()), Function.identity()));
|
|
|
+ Map<String, PmsProductDto> skuMap = new HashMap<>();
|
|
|
+ subGoods.forEach(next -> {
|
|
|
+ String key = next.getName() + "_" + next.getSkuCode();
|
|
|
+ if (!skuMap.containsKey(key)) { // 处理出现重复key问题
|
|
|
+ skuMap.put(key, next);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
-// List<GoodsWrapper.Goods> goodsList = new ArrayList<>();
|
|
|
List<JSONObject> jsonObjectList = new ArrayList<>();
|
|
|
- Set<String> snSet = new HashSet<>();
|
|
|
for (Map.Entry<String, List<Map<String, Object>>> sheetData : sheetsListMap.entrySet()) {
|
|
|
List<Map<String, Object>> rows = sheetData.getValue();
|
|
|
if (rows.isEmpty()) {
|
|
@@ -642,26 +663,24 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
Map<String, Object> firstRow = rows.get(0);
|
|
|
// 缺省字段
|
|
|
Set<String> templateFields = columns.keySet();
|
|
|
- List<String> defaultField = templateFields.stream().filter(firstRow::containsKey).collect(Collectors.toList());
|
|
|
+ List<String> defaultField = templateFields.stream().filter(next->!firstRow.containsKey(next)).collect(Collectors.toList());
|
|
|
if (!defaultField.isEmpty()) {
|
|
|
errList.add("导入字段缺省:" + String.join(",", defaultField));
|
|
|
return getExportErrLogFile(errList);
|
|
|
}
|
|
|
|
|
|
- String lineErrMsg = "第%s行存在错误:%s";
|
|
|
+ String lineErrMsg = "错误行号:第%s行,%s";
|
|
|
Map<String, String> beforeGoods = new HashMap<>();
|
|
|
|
|
|
- JSONObject objectMap = new JSONObject();
|
|
|
- String subGoodsName = null;
|
|
|
- String subGoodsSku = null;
|
|
|
for (int i = 0; i < rows.size(); i++) {
|
|
|
+ JSONObject objectMap = new JSONObject();
|
|
|
int rowNum = i + 2;
|
|
|
-// GoodsWrapper.Goods goods = new GoodsWrapper.Goods();
|
|
|
-// GoodsWrapper.GoodsSub goodsSub = new GoodsWrapper.GoodsSub();
|
|
|
Map<String, Object> row = rows.get(i);
|
|
|
if (row.size() == 0) {
|
|
|
continue;
|
|
|
}
|
|
|
+ String subGoodsName = null;
|
|
|
+ String subGoodsSku = null;
|
|
|
List<String> lineErrList = new ArrayList<>();
|
|
|
for (Map.Entry<String, Object> entry : row.entrySet()) {
|
|
|
String fieldName = entry.getKey();
|
|
@@ -710,17 +729,17 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
} else if ("type".equals(fieldCode)) {
|
|
|
String tempValue = value;
|
|
|
- boolean match = Arrays.stream(GoodsType.values()).allMatch(next -> next.getDesc().equals(tempValue));
|
|
|
- if (match) {
|
|
|
- objectMap.put(fieldCode, value);
|
|
|
+ Optional<GoodsType> first = Arrays.stream(GoodsType.values()).filter(next -> next.getDesc().equals(tempValue)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ objectMap.put(fieldCode, first.get().getCode());
|
|
|
} else {
|
|
|
lineErrList.add("字段‘" + fieldName + "’类型不支持");
|
|
|
}
|
|
|
} else if ("goodsCategoryName".equals(fieldCode)) {
|
|
|
if(categoryNames.contains(value)){
|
|
|
- objectMap.put("goodsCategoryId", categoryIdNameMap.get(value));
|
|
|
+ objectMap.put("goodsCategoryId", categoryIdNameMap.get(value).intValue());
|
|
|
}else {
|
|
|
- lineErrList.add("字段‘" + fieldName + "’类型不支持");
|
|
|
+ lineErrList.add("字段‘" + fieldName + "’不支持");
|
|
|
}
|
|
|
} else if ("educationShowOrganName".equals(fieldCode)
|
|
|
|| "courseFeeShowOrganName".equals(fieldCode)
|
|
@@ -750,7 +769,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
objectMap.put("stock", dto.getStock());
|
|
|
objectMap.put("goodsStatus", dto.getPublishStatus()==1);
|
|
|
} else {
|
|
|
- lineErrList.add("子商品‘" + value + "[" + subGoodsSku + "]’不存在");
|
|
|
+ lineErrList.add("子商品‘" + subGoodsName + "[" + subGoodsSku + "]’不存在");
|
|
|
}
|
|
|
}
|
|
|
} else if ("sku".equals(fieldCode)) {
|
|
@@ -764,7 +783,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
objectMap.put("stock", dto.getStock());
|
|
|
objectMap.put("goodsStatus", dto.getPublishStatus()==1);
|
|
|
} else {
|
|
|
- lineErrList.add("子商品‘" + value + "[" + subGoodsSku + "]’不存在");
|
|
|
+ lineErrList.add("子商品‘" + subGoodsName + "[" + subGoodsSku + "]’不存在");
|
|
|
}
|
|
|
}
|
|
|
} else if ("subGoodsPrice".equals(fieldCode)) {
|
|
@@ -802,7 +821,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
return goods;
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
- Map<String, List<GoodsWrapper.Goods>> goodsGroup = goodsList.stream().collect(Collectors.groupingBy(next -> next.getClass() + "_" + next.getSn()));
|
|
|
+ Map<String, List<GoodsWrapper.Goods>> goodsGroup = goodsList.stream().collect(Collectors.groupingBy(next -> next.getName() + "_" + next.getSn()));
|
|
|
//
|
|
|
//
|
|
|
// // 数据合并
|
|
@@ -1104,7 +1123,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
goods.setFreeFeeShowOrganName(StringUtils.join(organizationDao.findByOrganIds(goods.getFreeFeeShowOrganId()),","));
|
|
|
}
|
|
|
GoodsWrapper.Goods detail = JSON.parseObject(JSON.toJSONString(goods), GoodsWrapper.Goods.class);
|
|
|
- detail.setGoodsSubList(queryGoodsSub(goodsId));
|
|
|
+ detail.setGoodsSubList(queryGoodsSubByGoodId(goodsId));
|
|
|
return detail;
|
|
|
}
|
|
|
|
|
@@ -1299,7 +1318,10 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
try {
|
|
|
- BufferedWriter csvFileOutputStream = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8), 1024);
|
|
|
+ FileOutputStream out = new FileOutputStream(file);
|
|
|
+ byte[] uft8bom = {(byte) 0xef, (byte) 0xbb, (byte) 0xbf}; // 处理乱码
|
|
|
+ out.write(uft8bom);
|
|
|
+ BufferedWriter csvFileOutputStream = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
|
|
|
|
|
for (String errMsg : errList) {
|
|
|
csvFileOutputStream.write(errMsg);
|
|
@@ -1314,4 +1336,21 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
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;
|
|
|
+ }
|
|
|
}
|