| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import cn.idev.excel.FastExcel; |
| | | import cn.afterturn.easypoi.excel.ExcelImportUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.domain.R; |
| | |
| | | import com.ruoyi.system.query.AssetAdQuery; |
| | | import com.ruoyi.system.service.AssetAdRentalRecordService; |
| | | import com.ruoyi.system.service.AssetAdService; |
| | | import com.ruoyi.system.utils.FastExcelUtil; |
| | | import com.ruoyi.system.vo.asset.AssetAdDetailVO; |
| | | import com.ruoyi.system.vo.asset.AssetAdVO; |
| | | import com.ruoyi.web.controller.listener.AssetAdValidatorListener; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | |
| | | 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; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @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(), AssetAdDTO.class) |
| | | .sheet("广告无形资产") |
| | | .doWrite(Collections.emptyList()); |
| | | } catch (IOException e) { |
| | | log.error("下载导入模板异常", e); |
| | | } |
| | | FastExcelUtil.exportData(response, "广告无形资产导入模板", "广告无形资产", AssetAdDTO.class, Collections.emptyList()); |
| | | } |
| | | |
| | | @ApiOperation("导入") |
| | |
| | | return R.fail("请选择一个文件上传!"); |
| | | } |
| | | try { |
| | | List<AssetAdDTO> list = FastExcel.read(file.getInputStream(), AssetAdDTO.class, new AssetAdValidatorListener()) |
| | | .sheet() |
| | | .doReadSync(); |
| | | assetAdService.importAssetAd(list); |
| | | //List<AssetAdDTO> list = FastExcelUtil.readMultipartFile(file.getInputStream(), AssetAdDTO.class); |
| | | //assetAdService.importAssetAd(list); |
| | | ExcelImportUtil.importExcel(file.getInputStream(), AssetAdDTO.class, null); |
| | | return R.ok(); |
| | | } catch (IOException e) { |
| | | log.error("文件处理失败", e); |
| | | return R.fail("文件处理失败!"); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |