| | |
| | | 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.common.enums.BusinessType; |
| | | import com.ruoyi.system.dto.asset.AssetAdDTO; |
| | | import com.ruoyi.system.dto.asset.AssetAdRentalRecordDTO; |
| | | import com.ruoyi.system.model.AssetAdRentalRecord; |
| | | import com.ruoyi.system.query.AssetAdQuery; |
| | | import com.ruoyi.system.service.AssetAdRentalRecordService; |
| | | import com.ruoyi.system.service.AssetAdService; |
| | | import com.ruoyi.system.vo.asset.AssetAdDetailVO; |
| | | import com.ruoyi.system.vo.asset.AssetAdVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestPart; |
| | | 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 class AssetAdController { |
| | | |
| | | private final AssetAdService assetAdService; |
| | | private final AssetAdRentalRecordService assetAdRentalRecordService; |
| | | |
| | | @PostMapping("/add") |
| | | @ApiOperation(value = "新增广告无形资产") |
| | | @Log(title = "新增广告无形资产", businessType = BusinessType.INSERT) |
| | | @PostMapping("/add") |
| | | public R<?> addAssetAd(@Valid @RequestBody AssetAdDTO dto) { |
| | | assetAdService.addAssetAd(dto); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "编辑广告无形资产") |
| | | @Log(title = "编辑广告无形资产", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/edit") |
| | | @ApiOperation(value = "新增广告无形资产") |
| | | public R<?> editAssetAd(@Valid @RequestBody AssetAdDTO dto) { |
| | | assetAdService.editAssetAd(dto); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation("获取分页列表") |
| | | @PostMapping("/page") |
| | | public R<IPage<AssetAdVO>> getPageList(@RequestBody AssetAdQuery query) { |
| | | return R.ok(assetAdService.getPageList(query)); |
| | | } |
| | | |
| | | @ApiOperation("详情") |
| | | @GetMapping("/detail/{id}") |
| | | 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){ |
| | | 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}") |
| | | public R<?> delete(@ApiParam(name = "id", value = "广告无形资产ID") @PathVariable Integer id) { |
| | | assetAdService.removeById(id); |
| | | assetAdRentalRecordService.lambdaUpdate().eq(AssetAdRentalRecord::getAssetAdId, id).remove(); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation("添加出租记录") |
| | | @PostMapping("/rental/add") |
| | | public R<?> addRentalRecord(@Valid @RequestBody AssetAdRentalRecordDTO dto){ |
| | | assetAdRentalRecordService.addRentalRecord(dto); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation("编辑出租记录") |
| | | @PostMapping("/rental/edit") |
| | | public R<?> editRentalRecord(@Valid @RequestBody AssetAdRentalRecordDTO dto){ |
| | | assetAdRentalRecordService.editRentalRecord(dto); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation("删除出租记录") |
| | | @DeleteMapping("/rental/delete/{id}") |
| | | public R<?> deleteRentalRecord(@ApiParam(name = "id", value = "广告无形资产ID") @PathVariable Integer id){ |
| | | assetAdRentalRecordService.removeById(id); |
| | | return R.ok(); |
| | | } |
| | | } |
| | | |