|
@@ -3,7 +3,9 @@ package com.fs.hisStore.service.impl;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
|
|
|
+import com.fs.hisStore.domain.FsStoreProductUserEndCategory;
|
|
|
import com.fs.hisStore.domain.FsStoreUserEndCategoryScrm;
|
|
import com.fs.hisStore.domain.FsStoreUserEndCategoryScrm;
|
|
|
|
|
+import com.fs.hisStore.dto.FsStoreProductSortItemDTO;
|
|
|
import com.fs.hisStore.mapper.FsStoreProductScrmMapper;
|
|
import com.fs.hisStore.mapper.FsStoreProductScrmMapper;
|
|
|
import com.fs.hisStore.mapper.FsStoreProductTagRelationScrmMapper;
|
|
import com.fs.hisStore.mapper.FsStoreProductTagRelationScrmMapper;
|
|
|
import com.fs.hisStore.mapper.FsStoreProductUserEndCategoryMapper;
|
|
import com.fs.hisStore.mapper.FsStoreProductUserEndCategoryMapper;
|
|
@@ -15,6 +17,7 @@ import com.github.pagehelper.Page;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
@@ -69,13 +72,15 @@ public class FsStoreUserEndCategoryScrmServiceImpl implements IFsStoreUserEndCat
|
|
|
tagVoMap.computeIfAbsent(tn.getProductId(), k -> new ArrayList<>()).add(tn);
|
|
tagVoMap.computeIfAbsent(tn.getProductId(), k -> new ArrayList<>()).add(tn);
|
|
|
}
|
|
}
|
|
|
// 转换为标签名称列表,已按sort排序(SQL已排序)
|
|
// 转换为标签名称列表,已按sort排序(SQL已排序)
|
|
|
- Map<Long, List<String>> tagMap = new LinkedHashMap<>();
|
|
|
|
|
|
|
+ Map<Long, List<String>> tagMap = new LinkedHashMap<>();
|
|
|
for (Map.Entry<Long, List<FsStoreProductTagNameVO>> entry : tagVoMap.entrySet()) {
|
|
for (Map.Entry<Long, List<FsStoreProductTagNameVO>> entry : tagVoMap.entrySet()) {
|
|
|
List<String> tagNameList = entry.getValue().stream()
|
|
List<String> tagNameList = entry.getValue().stream()
|
|
|
.map(FsStoreProductTagNameVO::getTagName)
|
|
.map(FsStoreProductTagNameVO::getTagName)
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
tagMap.put(entry.getKey(), tagNameList);
|
|
tagMap.put(entry.getKey(), tagNameList);
|
|
|
}
|
|
}
|
|
|
|
|
+ Map<Long, Long> relSortMap = toRelationSortMap(
|
|
|
|
|
+ productUserEndCategoryMapper.selectSortByCategoryAndProductIds(categoryId, productIds));
|
|
|
List<FsStoreUserEndCategoryProductVO> result = new ArrayList<>();
|
|
List<FsStoreUserEndCategoryProductVO> result = new ArrayList<>();
|
|
|
for (Long pid : productIds) {
|
|
for (Long pid : productIds) {
|
|
|
FsStoreProductScrm p = productMap.get(pid);
|
|
FsStoreProductScrm p = productMap.get(pid);
|
|
@@ -87,6 +92,7 @@ public class FsStoreUserEndCategoryScrmServiceImpl implements IFsStoreUserEndCat
|
|
|
vo.setPrice(p.getPrice());
|
|
vo.setPrice(p.getPrice());
|
|
|
vo.setOtPrice(p.getOtPrice());
|
|
vo.setOtPrice(p.getOtPrice());
|
|
|
vo.setSales(p.getSales());
|
|
vo.setSales(p.getSales());
|
|
|
|
|
+ vo.setSort(relSortMap.getOrDefault(pid, 0L));
|
|
|
vo.setTagList(tagMap.getOrDefault(pid, new ArrayList<>()));
|
|
vo.setTagList(tagMap.getOrDefault(pid, new ArrayList<>()));
|
|
|
result.add(vo);
|
|
result.add(vo);
|
|
|
}
|
|
}
|
|
@@ -97,6 +103,29 @@ public class FsStoreUserEndCategoryScrmServiceImpl implements IFsStoreUserEndCat
|
|
|
return pageResult;
|
|
return pageResult;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public int saveProductsSort(Long userEndCategoryId, List<FsStoreProductSortItemDTO> items) {
|
|
|
|
|
+ if (userEndCategoryId == null || items == null || items.isEmpty()) {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ int n = 0;
|
|
|
|
|
+ for (FsStoreProductSortItemDTO item : items) {
|
|
|
|
|
+ if (item == null || item.getProductId() == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ long s = item.getSort() == null ? 0L : item.getSort();
|
|
|
|
|
+ if (s < 0) {
|
|
|
|
|
+ s = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (s > 9999) {
|
|
|
|
|
+ s = 9999;
|
|
|
|
|
+ }
|
|
|
|
|
+ n += productUserEndCategoryMapper.updateRelSortByCategoryAndProduct(userEndCategoryId, item.getProductId(), s);
|
|
|
|
|
+ }
|
|
|
|
|
+ return n;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Map<String, Object> listProductsForApp(Long id, String keyword, Integer pageNum, Integer pageSize, Long storeId, Integer position) {
|
|
public Map<String, Object> listProductsForApp(Long id, String keyword, Integer pageNum, Integer pageSize, Long storeId, Integer position) {
|
|
|
Map<String, Object> out = new HashMap<>();
|
|
Map<String, Object> out = new HashMap<>();
|
|
@@ -136,6 +165,7 @@ public class FsStoreUserEndCategoryScrmServiceImpl implements IFsStoreUserEndCat
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
tagMap.put(entry.getKey(), tagNameList);
|
|
tagMap.put(entry.getKey(), tagNameList);
|
|
|
}
|
|
}
|
|
|
|
|
+ Map<Long, Long> relSortMap = relationSortMapForApp(id, storeId, position, productIds);
|
|
|
List<FsStoreUserEndCategoryProductVO> result = new ArrayList<>();
|
|
List<FsStoreUserEndCategoryProductVO> result = new ArrayList<>();
|
|
|
for (Long pid : productIds) {
|
|
for (Long pid : productIds) {
|
|
|
FsStoreProductScrm p = productMap.get(pid);
|
|
FsStoreProductScrm p = productMap.get(pid);
|
|
@@ -147,6 +177,7 @@ public class FsStoreUserEndCategoryScrmServiceImpl implements IFsStoreUserEndCat
|
|
|
vo.setPrice(p.getPrice());
|
|
vo.setPrice(p.getPrice());
|
|
|
vo.setOtPrice(p.getOtPrice());
|
|
vo.setOtPrice(p.getOtPrice());
|
|
|
vo.setSales(p.getSales());
|
|
vo.setSales(p.getSales());
|
|
|
|
|
+ vo.setSort(relSortMap.getOrDefault(pid, 0L));
|
|
|
vo.setTagList(tagMap.getOrDefault(pid, new ArrayList<>()));
|
|
vo.setTagList(tagMap.getOrDefault(pid, new ArrayList<>()));
|
|
|
vo.setPositiveRating(getFixedPositiveRating(p.getProductId()));
|
|
vo.setPositiveRating(getFixedPositiveRating(p.getProductId()));
|
|
|
result.add(vo);
|
|
result.add(vo);
|
|
@@ -207,6 +238,39 @@ public class FsStoreUserEndCategoryScrmServiceImpl implements IFsStoreUserEndCat
|
|
|
return mapper.deleteByIds(ids);
|
|
return mapper.deleteByIds(ids);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private Map<Long, Long> relationSortMapForApp(Long categoryId, Long storeId, Integer position, List<Long> productIds) {
|
|
|
|
|
+ if (productIds == null || productIds.isEmpty()) {
|
|
|
|
|
+ return new HashMap<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (position != null && (position == 1 || position == 2)) {
|
|
|
|
|
+ if (categoryId != null && categoryId != 0L) {
|
|
|
|
|
+ return toRelationSortMap(
|
|
|
|
|
+ productUserEndCategoryMapper.selectSortByCategoryAndProductIds(categoryId, productIds));
|
|
|
|
|
+ }
|
|
|
|
|
+ return toRelationSortMap(
|
|
|
|
|
+ productUserEndCategoryMapper.selectAggSortByPositionAndProductIds(storeId, position, productIds));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (categoryId != null && categoryId != 0L) {
|
|
|
|
|
+ return toRelationSortMap(
|
|
|
|
|
+ productUserEndCategoryMapper.selectSortByCategoryAndProductIds(categoryId, productIds));
|
|
|
|
|
+ }
|
|
|
|
|
+ return toRelationSortMap(productUserEndCategoryMapper.selectAggSortGlobalAndProductIds(productIds));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static Map<Long, Long> toRelationSortMap(List<FsStoreProductUserEndCategory> rows) {
|
|
|
|
|
+ Map<Long, Long> m = new HashMap<>();
|
|
|
|
|
+ if (rows == null) {
|
|
|
|
|
+ return m;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (FsStoreProductUserEndCategory row : rows) {
|
|
|
|
|
+ if (row.getProductId() == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ m.put(row.getProductId(), row.getSort() != null ? row.getSort() : 0L);
|
|
|
|
|
+ }
|
|
|
|
|
+ return m;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取固定的好评率随机值
|
|
* 获取固定的好评率随机值
|
|
|
* 先从 Redis 获取,如果不存在则生成随机值并保存到 Redis(永久保存)
|
|
* 先从 Redis 获取,如果不存在则生成随机值并保存到 Redis(永久保存)
|