diff --git a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/controller/BasicdataPriceController.java b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/controller/BasicdataPriceController.java index b6e9ac560..75003dc30 100644 --- a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/controller/BasicdataPriceController.java +++ b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/controller/BasicdataPriceController.java @@ -16,8 +16,19 @@ */ package com.logpm.basicdata.controller; +import cn.hutool.core.date.DateUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.metadata.WriteTable; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.logpm.basicdata.excel.price.BasicdataPriceCategoryBasicExcel; +import com.logpm.basicdata.excel.price.BasicdataPriceCategoryDispatchExcel; +import com.logpm.basicdata.excel.price.BasicdataPriceCategoryWarehouseExcel; +import com.logpm.basicdata.excel.price.BasicdataPriceExcel; +import com.logpm.basicdata.excel.price.BasicdataPriceFullVehicleExcel; +import com.logpm.basicdata.excel.price.BasicdataPriceGeneralExcel; import com.logpm.basicdata.service.IBasicdataPriceService; import com.logpm.basicdata.vo.BasicdatPriceApiVO; import com.logpm.basicdata.vo.BasicdataPriceBasicUpdateVO; @@ -29,6 +40,7 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; +import org.apache.commons.codec.Charsets; import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; @@ -40,12 +52,18 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import springfox.documentation.annotations.ApiIgnore; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; -import java.io.InputStream; +import java.io.IOException; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Map; /** * 基础价格表 控制器 @@ -129,4 +147,39 @@ public class BasicdataPriceController extends BladeController { return R.data(detail); } + @GetMapping("/export") + @ApiOperationSupport(order = 8) + @ApiOperation(value = "导出", notes = "导出") + public void export(@ApiIgnore @RequestParam Map map, HttpServletResponse response) { + try { + String fileName = "基础价格表" + DateUtil.today(); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding(Charsets.UTF_8.name()); + fileName = URLEncoder.encode(fileName, Charsets.UTF_8.name()); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build(); + WriteTable table1 = EasyExcel.writerTable(0).head(BasicdataPriceExcel.class).build(); + WriteTable table2 = EasyExcel.writerTable(1).head(BasicdataPriceCategoryBasicExcel.class).build(); + WriteTable table3 = EasyExcel.writerTable(2).head(BasicdataPriceCategoryWarehouseExcel.class).build(); + WriteTable table4 = EasyExcel.writerTable(3).head(BasicdataPriceCategoryDispatchExcel.class).build(); + WriteTable table5 = EasyExcel.writerTable(4).head(BasicdataPriceFullVehicleExcel.class).build(); + WriteTable table6 = EasyExcel.writerTable(5).head(BasicdataPriceGeneralExcel.class).build(); + WriteSheet writeSheet1 = EasyExcel.writerSheet(0, "客户信息").build(); + WriteSheet writeSheet2 = EasyExcel.writerSheet(1, "提货干线按品类计费").build(); + WriteSheet writeSheet3 = EasyExcel.writerSheet(2, "仓储按品类计费").build(); + WriteSheet writeSheet4 = EasyExcel.writerSheet(3, "配送按品类计费").build(); + WriteSheet writeSheet5 = EasyExcel.writerSheet(4, "最低计费").build(); + WriteSheet writeSheet6 = EasyExcel.writerSheet(5, "整车").build(); + excelWriter.write(new ArrayList(), writeSheet1, table1); + excelWriter.write(new ArrayList(), writeSheet2, table2); + excelWriter.write(new ArrayList(), writeSheet3, table3); + excelWriter.write(new ArrayList(), writeSheet4, table4); + excelWriter.write(new ArrayList(), writeSheet5, table5); + excelWriter.write(new ArrayList(), writeSheet6, table6); + excelWriter.finish(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }