| | |
| | | package com.ruoyi.order.controller; |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.dto.ChargingOrderGroup; |
| | | import com.ruoyi.common.core.dto.ChargingPercentProvinceDto; |
| | | import com.ruoyi.common.core.utils.WebUtils; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.order.dto.GetImportOrderDTO; |
| | | import com.ruoyi.order.export.ChargeOrderExport; |
| | | import com.ruoyi.order.model.ChargeOrder; |
| | | import com.ruoyi.order.service.ChargeOrderService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Api(tags = "充电订单") |
| | |
| | | * 导入充电信息 |
| | | */ |
| | | @PostMapping("/importExpress") |
| | | @ApiOperation(value = "导入充电信息", tags = "后台-充电订单-导入充电信息") |
| | | public R importExpress(@RequestParam("file") MultipartFile file) { |
| | | /* JSONObject jsonObject = JSONObject.parseObject(url); |
| | | String url2 = jsonObject.getString("url");*/ |
| | | if (file.isEmpty()) { |
| | | return R.fail("请选择要上传的文件"); |
| | | } |
| | | |
| | | return chargeOrderService.importExpress(file); |
| | | } |
| | | |
| | |
| | | |
| | | return R.ok(pageInfo); |
| | | } |
| | | |
| | | @ApiOperation(value = "充电订单导入模板下载", tags = "后台-充电订单") |
| | | @GetMapping("/importChargeOrder") |
| | | public void importChargeOrder() { |
| | | List<ChargeOrderExport> chargeOrderExports = new ArrayList<>(); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), ChargeOrderExport.class, chargeOrderExports); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("充电订单导入模板.xls", "utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setHeader("content-Type", "application/vnd.ms-excel"); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | System.out.println("充电订单导入模板下载失败!"); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |