Parcourir la source

feat:新增导出Excel功能

qingwudarao il y a 6 mois
Parent
commit
b5905baf8a

+ 23 - 0
ruoyi-modules/ruoyi-commodityManagement/src/main/java/org/dromara/commodityManagement/controller/BrandController.java

@@ -1,15 +1,20 @@
 package org.dromara.commodityManagement.controller;
 
+import cn.hutool.core.collection.CollUtil;
+import jakarta.servlet.http.HttpServletResponse;
 import lombok.RequiredArgsConstructor;
 import org.dromara.commodityManagement.domain.bo.BrandBo;
 import org.dromara.commodityManagement.domain.vo.BrandVo;
 import org.dromara.commodityManagement.service.BrandService;
 import org.dromara.common.core.domain.R;
+import org.dromara.common.excel.utils.ExcelUtil;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.web.core.BaseController;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
+
 /**
  * 品牌组接口
  */
@@ -59,4 +64,22 @@ public class BrandController extends BaseController {
     public R<Void> deleteBrandByIds(@PathVariable Long[] brandIds) {
         return toAjax(brandService.deleteBrandById(brandIds));
     }
+
+    /**
+     * 根据品牌Ids导出Excel
+     * @param response 响应对象
+     */
+    @GetMapping("/exportExcelByIds")
+    public void exportDiBuExcel(@RequestParam("ids") Long[] brandIds , HttpServletResponse response) {
+        ExcelUtil.exportTemplate(CollUtil.newArrayList(new HashMap<>(),brandService.selectBrandListByIds(brandIds)), "品牌列表.xlsx","excel/品牌导出模板.xlsx", response);
+    }
+
+    /**
+     * 通过Excel导出所有品牌数据
+     * @param response 响应对象
+     */
+    @GetMapping("/exportExcel")
+    public void exportDiBuExcel(HttpServletResponse response) {
+        ExcelUtil.exportTemplate(CollUtil.newArrayList(new HashMap<>(),brandService.selectBrandList()), "品牌列表.xlsx","excel/品牌导出模板.xlsx", response);
+    }
 }

+ 15 - 0
ruoyi-modules/ruoyi-commodityManagement/src/main/java/org/dromara/commodityManagement/service/BrandService.java

@@ -1,10 +1,13 @@
 package org.dromara.commodityManagement.service;
 
+import org.dromara.commodityManagement.domain.Brand;
 import org.dromara.commodityManagement.domain.bo.BrandBo;
 import org.dromara.commodityManagement.domain.vo.BrandVo;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 
+import java.util.List;
+
 /**
  * 品牌管理服务
  */
@@ -37,4 +40,16 @@ public interface BrandService {
      * @return 影响行数
      */
     int deleteBrandById(Long[] brandId);
+
+    /**
+     * 根据底布Ids查询底布列表
+     * @return 底布列表
+     */
+    List<Brand> selectBrandListByIds(Long[] brandIds);
+
+    /**
+     * 查询底布列表
+     * @return 底布列表
+     */
+    List<Brand> selectBrandList();
 }

+ 34 - 0
ruoyi-modules/ruoyi-commodityManagement/src/main/java/org/dromara/commodityManagement/service/impl/BrandServiceImpl.java

@@ -16,6 +16,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.springframework.stereotype.Service;
 
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * 品牌服务实现
@@ -83,6 +84,25 @@ public class BrandServiceImpl implements BrandService {
         return brandMapper.deleteByIds(Arrays.asList(brandIds));
     }
 
+    /**
+     * 根据品牌ID查询品牌
+     * @param brandIds BrandID列表
+     * @return Brand列表
+     */
+    @Override
+    public List<Brand> selectBrandListByIds(Long[] brandIds) {
+        return selectBrandsByIdOrChooseAll(brandIds);
+    }
+
+    /**
+     * 查询品牌列表
+     * @return Brand列表
+     */
+    @Override
+    public List<Brand> selectBrandList() {
+        return selectBrandsByIdOrChooseAll(null);
+    }
+
     /**
      * 保存前校验
      * @param entity Brand实体对象
@@ -97,4 +117,18 @@ public class BrandServiceImpl implements BrandService {
         }
     }
 
+    /**
+     * 根据是否传入品牌ID列表查询品牌
+     * @param brandIds BrandID列表
+     * @return Brand列表
+     */
+    private List<Brand> selectBrandsByIdOrChooseAll(Long[] brandIds){
+        QueryWrapper<Brand> qw = new QueryWrapper<>();
+        qw.eq("type",2);
+        if (brandIds != null) {
+            qw.in("id",Arrays.asList(brandIds));
+        }
+        return MapstructUtils.convert(brandMapper.selectVoList(qw), Brand.class);
+    }
+
 }

BIN
ruoyi-modules/ruoyi-commodityManagement/src/main/resources/excel/品牌导出模板.xlsx