|
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.etotem.cfc.common.Result;
|
|
import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.entity.Product;
|
|
import com.etotem.cfc.entity.Product;
|
|
|
|
|
+import com.etotem.cfc.entity.ProductSku;
|
|
|
|
|
+import com.etotem.cfc.entity.ProductSkuComboItem;
|
|
|
import com.etotem.cfc.mapper.ProductMapper;
|
|
import com.etotem.cfc.mapper.ProductMapper;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -22,6 +24,11 @@ public class AdminProductPickerController {
|
|
|
@Resource
|
|
@Resource
|
|
|
private ProductMapper productMapper;
|
|
private ProductMapper productMapper;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private com.etotem.cfc.mapper.ProductSkuMapper productSkuMapper;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private com.etotem.cfc.mapper.ProductSkuComboItemMapper comboItemMapper;
|
|
|
|
|
+
|
|
|
@PostMapping("/linked/list")
|
|
@PostMapping("/linked/list")
|
|
|
public Result<Map<String, Object>> linkedList(@RequestBody Map<String, Object> params) {
|
|
public Result<Map<String, Object>> linkedList(@RequestBody Map<String, Object> params) {
|
|
|
Long productId = params.get("productId") != null ? Long.valueOf(params.get("productId").toString()) : null;
|
|
Long productId = params.get("productId") != null ? Long.valueOf(params.get("productId").toString()) : null;
|
|
@@ -30,30 +37,69 @@ public class AdminProductPickerController {
|
|
|
Integer page = params.get("page") != null ? Integer.valueOf(params.get("page").toString()) : 1;
|
|
Integer page = params.get("page") != null ? Integer.valueOf(params.get("page").toString()) : 1;
|
|
|
Integer pageSize = params.get("pageSize") != null ? Integer.valueOf(params.get("pageSize").toString()) : 20;
|
|
Integer pageSize = params.get("pageSize") != null ? Integer.valueOf(params.get("pageSize").toString()) : 20;
|
|
|
|
|
|
|
|
- // 同分类限制:只返回同一分类的商品
|
|
|
|
|
- if (categoryId == null && productId != null) {
|
|
|
|
|
- Product product = productMapper.selectById(productId);
|
|
|
|
|
- if (product != null) {
|
|
|
|
|
- categoryId = product.getCategoryId();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ boolean crossCategory = Boolean.parseBoolean(String.valueOf(params.getOrDefault("crossCategory", "false")));
|
|
|
|
|
|
|
|
LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(Product::getStatus, "on_shelf");
|
|
wrapper.eq(Product::getStatus, "on_shelf");
|
|
|
- if (categoryId != null) {
|
|
|
|
|
- wrapper.eq(Product::getCategoryId, categoryId);
|
|
|
|
|
- }
|
|
|
|
|
- if (keyword != null && !keyword.trim().isEmpty()) {
|
|
|
|
|
- wrapper.like(Product::getName, keyword.trim());
|
|
|
|
|
|
|
+ if (!crossCategory) {
|
|
|
|
|
+ if (categoryId == null && productId != null) {
|
|
|
|
|
+ Product product = productMapper.selectById(productId);
|
|
|
|
|
+ if (product != null) categoryId = product.getCategoryId();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (categoryId != null) wrapper.eq(Product::getCategoryId, categoryId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (productId != null) wrapper.ne(Product::getId, productId);
|
|
|
|
|
+ wrapper.ne(Product::getProductType, "bundle");
|
|
|
}
|
|
}
|
|
|
|
|
+ if (keyword != null && !keyword.trim().isEmpty()) wrapper.like(Product::getName, keyword.trim());
|
|
|
|
|
|
|
|
IPage<Product> pageResult = productMapper.selectPage(new Page<>(page, pageSize), wrapper);
|
|
IPage<Product> pageResult = productMapper.selectPage(new Page<>(page, pageSize), wrapper);
|
|
|
|
|
|
|
|
|
|
+ java.util.List<java.util.Map<String, Object>> list = new java.util.ArrayList<>();
|
|
|
|
|
+ for (Product p : pageResult.getRecords()) {
|
|
|
|
|
+ java.util.Map<String, Object> m = new java.util.LinkedHashMap<>();
|
|
|
|
|
+ m.put("id", p.getId());
|
|
|
|
|
+ m.put("name", p.getName());
|
|
|
|
|
+ m.put("coverImage", p.getCoverImage());
|
|
|
|
|
+ m.put("price", p.getPrice());
|
|
|
|
|
+ m.put("stock", p.getStock());
|
|
|
|
|
+ m.put("categoryId", p.getCategoryId());
|
|
|
|
|
+ m.put("productType", p.getProductType());
|
|
|
|
|
+ if (crossCategory) {
|
|
|
|
|
+ java.util.List<ProductSku> allSkus = productSkuMapper.findByProductIdAll(p.getId()).stream()
|
|
|
|
|
+ .filter(s -> s.getEnabled() != null && s.getEnabled() == 1)
|
|
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
|
|
+ m.put("hasSkus", !allSkus.isEmpty());
|
|
|
|
|
+ java.util.Set<Long> comboSkuIds = java.util.Collections.emptySet();
|
|
|
|
|
+ if (!allSkus.isEmpty()) {
|
|
|
|
|
+ java.util.List<Long> ids = allSkus.stream().map(ProductSku::getId)
|
|
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
|
|
+ comboSkuIds = comboItemMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<ProductSkuComboItem>()
|
|
|
|
|
+ .in(ProductSkuComboItem::getSkuId, ids)).stream()
|
|
|
|
|
+ .map(ProductSkuComboItem::getSkuId)
|
|
|
|
|
+ .collect(java.util.stream.Collectors.toSet());
|
|
|
|
|
+ }
|
|
|
|
|
+ java.util.List<java.util.Map<String, Object>> skuList = new java.util.ArrayList<>();
|
|
|
|
|
+ for (ProductSku s : allSkus) {
|
|
|
|
|
+ if (comboSkuIds.contains(s.getId())) continue;
|
|
|
|
|
+ java.util.Map<String, Object> sm = new java.util.LinkedHashMap<>();
|
|
|
|
|
+ sm.put("id", s.getId());
|
|
|
|
|
+ sm.put("specs", s.getSpecs());
|
|
|
|
|
+ sm.put("price", s.getPrice());
|
|
|
|
|
+ sm.put("stock", s.getStock());
|
|
|
|
|
+ skuList.add(sm);
|
|
|
|
|
+ }
|
|
|
|
|
+ m.put("skus", skuList);
|
|
|
|
|
+ }
|
|
|
|
|
+ list.add(m);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("list", pageResult.getRecords());
|
|
|
|
|
|
|
+ result.put("list", list);
|
|
|
result.put("total", pageResult.getTotal());
|
|
result.put("total", pageResult.getTotal());
|
|
|
result.put("page", page);
|
|
result.put("page", page);
|
|
|
result.put("pageSize", pageSize);
|
|
result.put("pageSize", pageSize);
|
|
|
return Result.success(result);
|
|
return Result.success(result);
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|