|
@@ -1,53 +1,64 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
-import com.ym.mec.biz.dal.dao.GoodsCategoryDao;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.ym.mec.biz.dal.dao.SubjectDao;
|
|
|
import com.ym.mec.biz.dal.dao.SubjectGoodsMapperDao;
|
|
|
import com.ym.mec.biz.dal.dto.SubjectGoodsDto;
|
|
|
-import com.ym.mec.biz.dal.entity.Goods;
|
|
|
import com.ym.mec.biz.dal.entity.GoodsCategory;
|
|
|
+import com.ym.mec.biz.dal.entity.Subject;
|
|
|
import com.ym.mec.biz.dal.entity.SubjectGoodsMapper;
|
|
|
-import com.ym.mec.biz.dal.enums.AccountType;
|
|
|
import com.ym.mec.biz.dal.enums.GoodsType;
|
|
|
import com.ym.mec.biz.dal.page.GoodsCategoryQueryInfo;
|
|
|
import com.ym.mec.biz.service.GoodsCategoryService;
|
|
|
-import com.ym.mec.biz.service.GoodsService;
|
|
|
-import com.ym.mec.common.dal.BaseDAO;
|
|
|
+import com.ym.mec.common.dto.ProductCategoryDto;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
-import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
+import com.ym.mec.mall.MallFeignService;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
-public class GoodsCategoryServiceImpl extends BaseServiceImpl<Integer, GoodsCategory> implements GoodsCategoryService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private GoodsCategoryDao goodsCategoryDao;
|
|
|
+//public class GoodsCategoryServiceImpl extends BaseServiceImpl<Integer, GoodsCategory> implements GoodsCategoryService {
|
|
|
+public class GoodsCategoryServiceImpl implements GoodsCategoryService {
|
|
|
+
|
|
|
+// @Autowired
|
|
|
+// private GoodsCategoryDao goodsCategoryDao;
|
|
|
@Autowired
|
|
|
private SubjectGoodsMapperDao subjectGoodsMapperDao;
|
|
|
|
|
|
- @Override
|
|
|
- public BaseDAO<Integer, GoodsCategory> getDAO() {
|
|
|
- return goodsCategoryDao;
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private MallFeignService mallFeignService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SubjectDao subjectDao;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void upsetGoodsCategory(GoodsCategory goodsCategory) {
|
|
|
- goodsCategory.setParentId(0);
|
|
|
+// goodsCategory.setParentId(0);
|
|
|
if(goodsCategory.getId() != null){
|
|
|
- goodsCategory.setUpdateTime(new Date());
|
|
|
- goodsCategoryDao.update(goodsCategory);
|
|
|
+// goodsCategory.setUpdateTime(new Date());
|
|
|
+// goodsCategoryDao.update(goodsCategory);
|
|
|
//删除关联
|
|
|
subjectGoodsMapperDao.delByGoodsCategoryId(goodsCategory.getId());
|
|
|
- }else {
|
|
|
- goodsCategoryDao.insert(goodsCategory);
|
|
|
}
|
|
|
+// else {
|
|
|
+// goodsCategoryDao.insert(goodsCategory);
|
|
|
+// }
|
|
|
List<Integer> subjectIds = goodsCategory.getSubjectIds();
|
|
|
subjectGoodsMapperDao.batchAdd(goodsCategory.getId(),subjectIds, goodsCategory.getTenantId());
|
|
|
}
|
|
@@ -64,7 +75,9 @@ public class GoodsCategoryServiceImpl extends BaseServiceImpl<Integer, GoodsCate
|
|
|
pageInfo.setTotal(count);
|
|
|
params.put("offset", pageInfo.getOffset());
|
|
|
dataList = subjectGoodsMapperDao.querySubjectGoods(params);
|
|
|
+ Map<Integer, String> nameMap = getNameMap();
|
|
|
dataList.forEach(e->{
|
|
|
+ e.setGoodsCategoryName(nameMap.getOrDefault(e.getGoodsCategoryId(),""));
|
|
|
e.setInstrument(e.getGoodsList().stream().filter(goods -> goods.getType() == GoodsType.INSTRUMENT).collect(Collectors.toList()));
|
|
|
e.setAccessories(e.getGoodsList().stream().filter(goods -> goods.getType() == GoodsType.ACCESSORIES).collect(Collectors.toList()));
|
|
|
e.setGoodsList(null);
|
|
@@ -85,4 +98,70 @@ public class GoodsCategoryServiceImpl extends BaseServiceImpl<Integer, GoodsCate
|
|
|
subjectGoodsMapper.setUpdateTime(new Date());
|
|
|
subjectGoodsMapperDao.update(subjectGoodsMapper);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GoodsCategory get(Integer goodsCategoryId) {
|
|
|
+ mallFeignService.listWithChildren();
|
|
|
+ List<ProductCategoryDto> productCategoryDtos = treeToList(mallFeignService.listWithChildren());
|
|
|
+ Optional<ProductCategoryDto> first = productCategoryDtos.stream().filter(next -> next.getId().equals(Long.valueOf(goodsCategoryId))).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ ProductCategoryDto productCategoryDto = first.get();
|
|
|
+ GoodsCategory goodsCategory = new GoodsCategory();
|
|
|
+ goodsCategory.setId(goodsCategoryId);
|
|
|
+ goodsCategory.setName(productCategoryDto.getName());
|
|
|
+ return goodsCategory;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<GoodsCategory> queryPage(GoodsCategoryQueryInfo queryInfo) {
|
|
|
+ List<ProductCategoryDto> productCategoryDtos = treeToList(mallFeignService.listWithChildren());
|
|
|
+ List<ProductCategoryDto> childrens = productCategoryDtos.stream().map(ProductCategoryDto::getChildren).flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
+ List<GoodsCategory> goodsCategories = JSON.parseArray(JSON.toJSONString(childrens), GoodsCategory.class);
|
|
|
+
|
|
|
+ List<Integer> categoryIdList = goodsCategories.stream().map(GoodsCategory::getId).distinct().collect(Collectors.toList());
|
|
|
+ if (!categoryIdList.isEmpty()) {
|
|
|
+ List<SubjectGoodsMapper> mappers = subjectGoodsMapperDao.queryByCategoryIds(categoryIdList);
|
|
|
+
|
|
|
+ List<Integer> subjectIdList = mappers.stream().filter(next -> !StringUtils.isEmpty(next.getSubjectId()))
|
|
|
+ .map(next -> Integer.valueOf(next.getSubjectId())).distinct().collect(Collectors.toList());
|
|
|
+ Map<Integer, Subject> subjectIfdNameMap = subjectDao.findBySubjectIds(subjectIdList).stream().collect(Collectors.toMap(Subject::getId, Function.identity()));
|
|
|
+
|
|
|
+ Map<Integer, List<SubjectGoodsMapper>> groupByCategoryId = mappers.stream().collect(Collectors.groupingBy(SubjectGoodsMapper::getGoodsCategoryId));
|
|
|
+
|
|
|
+ goodsCategories.forEach(next -> {
|
|
|
+ List<SubjectGoodsMapper> goodsMappers = groupByCategoryId.getOrDefault(next.getId(), new ArrayList<>());
|
|
|
+ if (!goodsMappers.isEmpty()) {
|
|
|
+ List<Subject> subjectList =
|
|
|
+ goodsMappers.stream().filter(o -> subjectIfdNameMap.containsKey(Integer.valueOf(o.getSubjectId()))).map(o -> subjectIfdNameMap.get(Integer.valueOf(o.getSubjectId()))).collect(Collectors.toList());
|
|
|
+ next.setSubjects(subjectList);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return goodsCategories;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<Integer, String> getNameMap() {
|
|
|
+ return treeToList(mallFeignService.listWithChildren()).stream()
|
|
|
+ .collect(Collectors.toMap(next->next.getId().intValue(), ProductCategoryDto::getName));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|