|
|
@@ -0,0 +1,163 @@
|
|
|
+package com.fs.hisStore.service.impl;
|
|
|
+
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
|
+import com.fs.hisStore.domain.FsStoreUserEndCategoryScrm;
|
|
|
+import com.fs.hisStore.mapper.FsStoreProductScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsStoreProductTagRelationScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsStoreProductUserEndCategoryMapper;
|
|
|
+import com.fs.hisStore.mapper.FsStoreUserEndCategoryScrmMapper;
|
|
|
+import com.fs.hisStore.service.IFsStoreUserEndCategoryScrmService;
|
|
|
+import com.fs.hisStore.vo.FsStoreProductTagNameVO;
|
|
|
+import com.fs.hisStore.vo.FsStoreUserEndCategoryProductVO;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 商品用户分端类 Service 实现
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class FsStoreUserEndCategoryScrmServiceImpl implements IFsStoreUserEndCategoryScrmService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsStoreUserEndCategoryScrmMapper mapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsStoreProductUserEndCategoryMapper productUserEndCategoryMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsStoreProductScrmMapper fsStoreProductScrmMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsStoreProductTagRelationScrmMapper productTagRelationMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FsStoreUserEndCategoryProductVO> listProductsByCategoryId(Long categoryId) {
|
|
|
+ if (categoryId == null) return new ArrayList<>();
|
|
|
+ List<Long> productIds = productUserEndCategoryMapper.selectDistinctProductIdsByCategoryId(categoryId);
|
|
|
+ if (productIds == null || productIds.isEmpty()) return new ArrayList<>();
|
|
|
+ List<FsStoreProductScrm> products = fsStoreProductScrmMapper.getStoreProductInProductIds(productIds);
|
|
|
+ Map<Long, FsStoreProductScrm> productMap = products.stream().collect(Collectors.toMap(FsStoreProductScrm::getProductId, p -> p, (a, b) -> a));
|
|
|
+ List<FsStoreProductTagNameVO> tagNames = productTagRelationMapper.selectProductTagNamesByProductIds(productIds);
|
|
|
+ Map<Long, List<String>> tagMap = new LinkedHashMap<>();
|
|
|
+ for (FsStoreProductTagNameVO tn : tagNames) {
|
|
|
+ tagMap.computeIfAbsent(tn.getProductId(), k -> new ArrayList<>()).add(tn.getTagName());
|
|
|
+ }
|
|
|
+ List<FsStoreUserEndCategoryProductVO> result = new ArrayList<>();
|
|
|
+ for (Long pid : productIds) {
|
|
|
+ FsStoreProductScrm p = productMap.get(pid);
|
|
|
+ if (p == null) continue;
|
|
|
+ FsStoreUserEndCategoryProductVO vo = new FsStoreUserEndCategoryProductVO();
|
|
|
+ vo.setProductId(p.getProductId());
|
|
|
+ vo.setProductName(p.getProductName());
|
|
|
+ vo.setImage(p.getImage());
|
|
|
+ vo.setPrice(p.getPrice());
|
|
|
+ vo.setOtPrice(p.getOtPrice());
|
|
|
+ vo.setSales(p.getSales());
|
|
|
+ vo.setTagList(tagMap.getOrDefault(pid, new ArrayList<>()));
|
|
|
+ result.add(vo);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> listProductsForApp(Long id, Integer pageNum, Integer pageSize) {
|
|
|
+ Map<String, Object> out = new HashMap<>();
|
|
|
+ out.put("list", new ArrayList<FsStoreUserEndCategoryProductVO>());
|
|
|
+ out.put("total", 0L);
|
|
|
+ if (pageNum == null || pageSize == null || pageSize <= 0) return out;
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ List<Long> productIds = (id != null && id != 0L)
|
|
|
+ ? productUserEndCategoryMapper.selectDistinctProductIdsByCategoryId(id)
|
|
|
+ : productUserEndCategoryMapper.selectDistinctProductIds();
|
|
|
+ long total = productIds instanceof Page ? ((Page<?>) productIds).getTotal() : (productIds != null ? productIds.size() : 0);
|
|
|
+ if (productIds == null || productIds.isEmpty()) {
|
|
|
+ out.put("total", total);
|
|
|
+ return out;
|
|
|
+ }
|
|
|
+ List<FsStoreProductScrm> products = fsStoreProductScrmMapper.getStoreProductInProductIdsForApp(productIds);
|
|
|
+ Map<Long, FsStoreProductScrm> productMap = products.stream().collect(Collectors.toMap(FsStoreProductScrm::getProductId, p -> p, (a, b) -> a));
|
|
|
+ List<FsStoreProductTagNameVO> tagNames = productTagRelationMapper.selectProductTagNamesByProductIds(productIds);
|
|
|
+ Map<Long, List<String>> tagMap = new LinkedHashMap<>();
|
|
|
+ for (FsStoreProductTagNameVO tn : tagNames) {
|
|
|
+ tagMap.computeIfAbsent(tn.getProductId(), k -> new ArrayList<>()).add(tn.getTagName());
|
|
|
+ }
|
|
|
+ List<FsStoreUserEndCategoryProductVO> result = new ArrayList<>();
|
|
|
+ for (Long pid : productIds) {
|
|
|
+ FsStoreProductScrm p = productMap.get(pid);
|
|
|
+ if (p == null) continue;
|
|
|
+ FsStoreUserEndCategoryProductVO vo = new FsStoreUserEndCategoryProductVO();
|
|
|
+ vo.setProductId(p.getProductId());
|
|
|
+ vo.setProductName(p.getProductName());
|
|
|
+ vo.setImage(p.getImage());
|
|
|
+ vo.setPrice(p.getPrice());
|
|
|
+ vo.setOtPrice(p.getOtPrice());
|
|
|
+ vo.setSales(p.getSales());
|
|
|
+ vo.setTagList(tagMap.getOrDefault(pid, new ArrayList<>()));
|
|
|
+ result.add(vo);
|
|
|
+ }
|
|
|
+ out.put("list", result);
|
|
|
+ out.put("total", total);
|
|
|
+ return out;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FsStoreUserEndCategoryScrm selectById(Long id) {
|
|
|
+ return mapper.selectById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FsStoreUserEndCategoryScrm> selectList(FsStoreUserEndCategoryScrm query) {
|
|
|
+ return mapper.selectList(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FsStoreUserEndCategoryScrm> selectListPage(FsStoreUserEndCategoryScrm query) {
|
|
|
+ return mapper.selectList(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FsStoreUserEndCategoryScrm> selectListForProduct(Long storeId) {
|
|
|
+ return mapper.selectListForProduct(storeId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FsStoreUserEndCategoryScrm> selectTop8ByPosition(Long storeId, Integer position) {
|
|
|
+ return mapper.selectTop8ByPosition(storeId, position);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int insert(FsStoreUserEndCategoryScrm entity) {
|
|
|
+ entity.setCreateTime(DateUtils.getNowDate());
|
|
|
+ entity.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ return mapper.insert(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int update(FsStoreUserEndCategoryScrm entity) {
|
|
|
+ entity.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ return mapper.update(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int deleteById(Long id) {
|
|
|
+ productUserEndCategoryMapper.deleteByCategoryIds(new Long[]{id});
|
|
|
+ return mapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int deleteByIds(Long[] ids) {
|
|
|
+ if (ids == null || ids.length == 0) return 0;
|
|
|
+ productUserEndCategoryMapper.deleteByCategoryIds(ids);
|
|
|
+ return mapper.deleteByIds(ids);
|
|
|
+ }
|
|
|
+}
|