From 18813ca83b94c807e35756a8a5f52effa5b99ba8 Mon Sep 17 00:00:00 2001
From: zepengdev <lzpsmith@outlook.com>
Date: Tue, 17 Jun 2025 16:00:42 +0800
Subject: [PATCH] feat(product): 新增商品批量查询接口

---
 oying-system/src/main/java/com/oying/modules/pc/product/service/impl/ProductLabelServiceImpl.java |  133 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 133 insertions(+), 0 deletions(-)

diff --git a/oying-system/src/main/java/com/oying/modules/pc/product/service/impl/ProductLabelServiceImpl.java b/oying-system/src/main/java/com/oying/modules/pc/product/service/impl/ProductLabelServiceImpl.java
new file mode 100644
index 0000000..5b0048a
--- /dev/null
+++ b/oying-system/src/main/java/com/oying/modules/pc/product/service/impl/ProductLabelServiceImpl.java
@@ -0,0 +1,133 @@
+package com.oying.modules.pc.product.service.impl;
+
+import cn.hutool.core.collection.ListUtil;
+import cn.hutool.core.util.ObjUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.oying.exception.EntityExistException;
+import com.oying.exception.EntityNotFoundException;
+import com.oying.modules.pc.product.domain.ProductLabel;
+import com.oying.modules.pc.product.domain.dto.ProductLabelQueryCriteria;
+import com.oying.modules.pc.product.mapper.ProductLabelMapper;
+import com.oying.modules.pc.product.service.ProductLabelService;
+import com.oying.utils.FileUtil;
+import com.oying.utils.PageResult;
+import com.oying.utils.PageUtil;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @author lzp
+ * @description 服务实现
+ * @date 2025-05-28
+ **/
+@Service
+@RequiredArgsConstructor
+public class ProductLabelServiceImpl extends ServiceImpl<ProductLabelMapper, ProductLabel> implements ProductLabelService {
+
+    private final ProductLabelMapper productLabelMapper;
+
+    @Override
+    public PageResult<ProductLabel> queryAll(ProductLabelQueryCriteria criteria, Page<Object> page) {
+        return PageUtil.toPage(productLabelMapper.findAll(criteria, page));
+    }
+
+    @Override
+    public List<ProductLabel> queryAll(ProductLabelQueryCriteria criteria) {
+        return productLabelMapper.findAll(criteria);
+    }
+
+    @Override
+    public List<ProductLabel> queryBatchIds(List<Long> ids) {
+        LambdaQueryWrapper<ProductLabel> wrapper = new LambdaQueryWrapper<>();
+        wrapper.in(ProductLabel::getLabelId, ids);
+        return productLabelMapper.selectList(wrapper);
+    }
+
+    @Override
+    public List<ProductLabel> queryLabelsByProductId(Long productId) {
+        if (productId == null) {
+            return ListUtil.empty();
+        }
+        LambdaQueryWrapper<ProductLabel> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(ProductLabel::getProductId, productId);
+        return productLabelMapper.selectList(wrapper);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void create(ProductLabel resources) {
+        productLabelMapper.insert(resources);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void batchCreate(List<ProductLabel> resources) {
+        this.saveBatch(resources);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void update(ProductLabel resources) {
+        ProductLabel productLabel = getById(resources.getLabelId());
+        productLabel.copy(resources);
+        productLabelMapper.updateById(productLabel);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void batchUpdate(List<ProductLabel> resources) {
+
+        List<Long> updateIds = resources.stream().map(ProductLabel::getLabelId).collect(Collectors.toList());
+        List<ProductLabel> existingProductLabels = this.queryBatchIds(updateIds);
+        if (ObjUtil.isEmpty(existingProductLabels)) {
+            throw new EntityNotFoundException(ProductLabel.class, "labelId", updateIds.toString());
+        }
+
+        Map<Long, ProductLabel> longProductLabelMap = resources.stream()
+                .collect(Collectors.toMap(
+                        ProductLabel::getLabelId,
+                        productLabel -> productLabel)
+                );
+
+        for (ProductLabel existingProductLabel : existingProductLabels) {
+            existingProductLabel.copy(longProductLabelMap.get(existingProductLabel.getLabelId()));
+        }
+
+        this.updateBatchById(existingProductLabels);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteAll(List<Long> ids) {
+        productLabelMapper.deleteBatchIds(ids);
+    }
+
+    @Override
+    public void download(List<ProductLabel> all, HttpServletResponse response) throws IOException {
+        List<Map<String, Object>> list = new ArrayList<>();
+        for (ProductLabel productLabel : all) {
+            Map<String, Object> map = new LinkedHashMap<>();
+            map.put("商品ID", productLabel.getProductId());
+            map.put(" categoryName", productLabel.getCategoryName());
+            map.put("标签名称", productLabel.getLabelName());
+            map.put("标签值", productLabel.getLabelValue());
+            map.put("创建人", productLabel.getCreateBy());
+            map.put("创建时间", productLabel.getCreateTime());
+            map.put("修改人", productLabel.getUpdateBy());
+            map.put("修改时间", productLabel.getUpdateTime());
+            list.add(map);
+        }
+        FileUtil.downloadExcel(list, response);
+    }
+}

--
Gitblit v1.9.3