| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | import cn.idev.excel.FastExcel; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.domain.R; |
| | |
| | | import com.ruoyi.system.dto.asset.AssetAdMaterialPriceDTO; |
| | | import com.ruoyi.system.query.AssetAdMaterialPriceQuery; |
| | | import com.ruoyi.system.service.AssetAdMaterialPriceService; |
| | | import com.ruoyi.system.utils.FastExcelUtil; |
| | | import com.ruoyi.system.vo.asset.AssetAdMaterialPriceVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | |
| | | @ApiOperation("下载导入模板") |
| | | @GetMapping("/template") |
| | | public void getTemplate(HttpServletResponse response){ |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | String fileName = null; |
| | | try { |
| | | fileName = URLEncoder.encode("广告物料单价导入模板", "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | FastExcel.write(response.getOutputStream(), AssetAdMaterialPriceDTO.class) |
| | | .sheet("广告物料单价") |
| | | .doWrite(Collections.emptyList()); |
| | | } catch (IOException e) { |
| | | log.error("下载导入模板异常", e); |
| | | } |
| | | FastExcelUtil.exportData(response, "广告物料单价导入模板", "广告物料单价", AssetAdMaterialPriceDTO.class, Collections.emptyList()); |
| | | } |
| | | |
| | | @ApiOperation("导入") |
| | |
| | | return R.fail("请选择一个文件上传!"); |
| | | } |
| | | try { |
| | | List<AssetAdMaterialPriceDTO> list = FastExcel.read(file.getInputStream()) |
| | | .head(AssetAdMaterialPriceDTO.class) |
| | | .sheet() |
| | | .doReadSync(); |
| | | List<AssetAdMaterialPriceDTO> list = FastExcelUtil.readMultipartFile(file.getInputStream(), AssetAdMaterialPriceDTO.class); |
| | | assetAdMaterialPriceService.importAssetAdMaterialPrice(list); |
| | | return R.ok(); |
| | | } catch (IOException e) { |