فهرست منبع

fix:新增导入数据和获取导入模板接口

qingwudarao 6 ماه پیش
والد
کامیت
d43a4205a4

+ 20 - 4
ruoyi-modules/ruoyi-commodityManagement/src/main/java/org/dromara/commodityManagement/controller/DaHuoNumberController.java

@@ -5,16 +5,20 @@ import cn.hutool.core.collection.CollUtil;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.RequiredArgsConstructor;
 import org.dromara.commodityManagement.domain.bo.DaHuoNumberBo;
+import org.dromara.commodityManagement.domain.vo.DaHuoNumberImportVo;
 import org.dromara.commodityManagement.domain.vo.DaHuoNumberVo;
 import org.dromara.commodityManagement.service.DaHuoNumberService;
 import org.dromara.common.core.domain.R;
+import org.dromara.common.excel.core.ExcelResult;
 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.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 
 /**
@@ -68,12 +72,24 @@ public class DaHuoNumberController extends BaseController {
         return toAjax(daHuoNumberService.deleteDaHuoNumberByIds(daHuoNumberIds));
     }
 
+    @PostMapping("/importExcel")
+    public R<Void> importExcel(@RequestPart("file") MultipartFile file) throws Exception {
+        ExcelResult<DaHuoNumberImportVo> result = ExcelUtil.importExcel(file.getInputStream(), DaHuoNumberImportVo.class,false);
+        daHuoNumberService.insertImportExcel(result);
+        return R.ok(result.getAnalysis());
+    }
+
+    @GetMapping("/exampleExcel")
+    public void getExampleExcel(HttpServletResponse response){
+        ExcelUtil.exportExcel(new ArrayList<>(), "大货编号导入模板", DaHuoNumberImportVo.class, response);
+    }
+
     /**
      * 根据大货编号Ids导出Excel
      * @param response 响应对象
      */
-    @GetMapping("/exportExcelByIds")
-    public void exportDiBuExcel(@RequestParam("ids") Long[] daHuoNumberIds , HttpServletResponse response) {
+//    @GetMapping("/exportExcelByIds")
+    public void exportDaHuoExcel(@RequestParam("ids") Long[] daHuoNumberIds , HttpServletResponse response) {
         ExcelUtil.exportTemplate(CollUtil.newArrayList(new HashMap<>(),daHuoNumberService.selectDaHuoNumberListByIds(daHuoNumberIds)), "大货编号列表","excel/大货编号导出模板.xlsx", response);
     }
 
@@ -81,8 +97,8 @@ public class DaHuoNumberController extends BaseController {
      * 通过Excel导出所有大货编号数据
      * @param response 响应对象
      */
-    @GetMapping("/exportExcel")
-    public void exportDiBuExcel(HttpServletResponse response) {
+//    @GetMapping("/exportExcel")
+    public void exportDaHuoExcel(HttpServletResponse response) {
         ExcelUtil.exportTemplate(CollUtil.newArrayList(new HashMap<>(),daHuoNumberService.selectDaHuoNumberList()), "大货编号列表","excel/大货编号导出模板.xlsx", response);
     }
 }