|
@@ -2,12 +2,14 @@ package com.iohao.mmo.excel.controller;
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.iohao.mmo.common.kit.Result;
|
|
|
+import com.iohao.mmo.equip.entity.EquipEntry;
|
|
|
+import com.iohao.mmo.equip.entity.EquipEntryTemplate;
|
|
|
import com.iohao.mmo.excel.dto.DemoExcelDTO;
|
|
|
-import com.iohao.mmo.excel.entity.DemoExcel;
|
|
|
+import com.iohao.mmo.excel.dto.EquipEntryTemplateExcelDTO;
|
|
|
import com.iohao.mmo.excel.kit.ExcelKit;
|
|
|
+import com.iohao.mmo.excel.listener.EquipEntryTemplateExcelListener;
|
|
|
import com.iohao.mmo.excel.listener.ExcelDataCustomListener;
|
|
|
-import com.iohao.mmo.excel.listener.ExcelDataListener;
|
|
|
-import com.iohao.mmo.excel.service.DemoExcelService;
|
|
|
+import com.iohao.mmo.excel.service.EquipEntryTemplateExcelService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
@@ -16,7 +18,6 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
-import java.time.LocalTime;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -30,33 +31,19 @@ import java.util.Map;
|
|
|
@RequestMapping("/equipexcel")
|
|
|
@Tag(name = "EquipExcelController", description = "装备excel数据")
|
|
|
public class EquipExcelController {
|
|
|
- private final DemoExcelService demoExcelService;
|
|
|
+ private final EquipEntryTemplateExcelService equipEntryTemplateExcelService;
|
|
|
|
|
|
/**
|
|
|
- * 通用导出示例
|
|
|
+ * 导出
|
|
|
* @param params
|
|
|
* @param response
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- @Operation(summary = "通用导出示例",description = "通用导出示例")
|
|
|
- @GetMapping("exportdemo")
|
|
|
- public void exportDemo(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception{
|
|
|
- List<DemoExcel> list = demoExcelService.list(params,DemoExcel.class);
|
|
|
- ExcelKit.exportExcelToTarget(response, null, "Excel示例", list, DemoExcelDTO.class);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 通用导入示例
|
|
|
- * @param file
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @PostMapping(value = "importdemo", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
- @Operation(summary = "通用导入示例",description = "通用导入示例")
|
|
|
- public Result importDemo(@RequestPart("file") @Parameter(description = "文件")MultipartFile file) throws Exception {
|
|
|
- //通用读取
|
|
|
- EasyExcel.read(file.getInputStream(), DemoExcelDTO.class, new ExcelDataListener<>(demoExcelService)).sheet(0).doRead();
|
|
|
- return new Result().ok("导入成功!");
|
|
|
+ @Operation(summary = "导出",description = "导出")
|
|
|
+ @GetMapping("exportExcel")
|
|
|
+ public void exportExcel(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception{
|
|
|
+ List<EquipEntryTemplate> list = equipEntryTemplateExcelService.list(params,EquipEntryTemplate.class);
|
|
|
+ ExcelKit.exportExcelToTarget(response, null, "装备词条", list, DemoExcelDTO.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -65,11 +52,11 @@ public class EquipExcelController {
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- @PostMapping(value = "importcustom", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
+ @PostMapping(value = "importExcel", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
@Operation(summary = "导入数据自定义处理示例",description = "导入数据自定义处理示例")
|
|
|
- public Result importCustom(@RequestPart("file") @Parameter(description = "文件")MultipartFile file) throws Exception {
|
|
|
+ public Result importExcel(@RequestPart("file") @Parameter(description = "文件")MultipartFile file) throws Exception {
|
|
|
//自定义读取
|
|
|
- EasyExcel.read(file.getInputStream(), DemoExcelDTO.class, new ExcelDataCustomListener<>(demoExcelService)).sheet(0).doRead();
|
|
|
+ EasyExcel.read(file.getInputStream(), EquipEntryTemplateExcelDTO.class, new EquipEntryTemplateExcelListener<>(equipEntryTemplateExcelService)).sheet(0).doRead();
|
|
|
return new Result().ok("导入成功!");
|
|
|
}
|
|
|
}
|