|
|
@@ -0,0 +1,59 @@
|
|
|
+package com.etotem.cfc.controller.admin;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.Product;
|
|
|
+import com.etotem.cfc.mapper.ProductMapper;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/admin/product")
|
|
|
+public class AdminProductPickerController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ProductMapper productMapper;
|
|
|
+
|
|
|
+ @PostMapping("/linked/list")
|
|
|
+ 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 categoryId = params.get("categoryId") != null ? Long.valueOf(params.get("categoryId").toString()) : null;
|
|
|
+ String keyword = (String) params.get("keyword");
|
|
|
+ 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;
|
|
|
+
|
|
|
+ // 同分类限制:只返回同一分类的商品
|
|
|
+ if (categoryId == null && productId != null) {
|
|
|
+ Product product = productMapper.selectById(productId);
|
|
|
+ if (product != null) {
|
|
|
+ categoryId = product.getCategoryId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+
|
|
|
+ IPage<Product> pageResult = productMapper.selectPage(new Page<>(page, pageSize), wrapper);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("list", pageResult.getRecords());
|
|
|
+ result.put("total", pageResult.getTotal());
|
|
|
+ result.put("page", page);
|
|
|
+ result.put("pageSize", pageSize);
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+}
|