| | |
| | | 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 org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | 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> |
| | |
| | | public R<AssetAdDetailVO> getDetail(@ApiParam(name = "id", value = "广告无形资产ID") @PathVariable Integer id) { |
| | | return R.ok(assetAdService.getDetail(id)); |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("导入") |
| | | @Log(title = "导入广告无形资产", businessType = BusinessType.IMPORT) |
| | | @PostMapping("/import") |
| | | public R<?> importAssetAd(@RequestPart("file") MultipartFile file){ |
| | | //TODO 待完成 |
| | | return R.ok(); |
| | | if (file.isEmpty()) { |
| | | return R.fail("请选择一个文件上传!"); |
| | | } |
| | | try { |
| | | List<AssetAdDTO> list = FastExcel.read(file.getInputStream()).head(AssetAdDTO.class) |
| | | .sheet() |
| | | .doReadSync(); |
| | | assetAdService.importAssetAd(list); |
| | | return R.ok(); |
| | | } catch (IOException e) { |
| | | log.error("文件处理失败", e); |
| | | return R.fail("文件处理失败!"); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("删除") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @DeleteMapping("/{id}") |