From cff854df2740e862a9255df58c7629e5c559d973 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期二, 21 十月 2025 19:54:04 +0800
Subject: [PATCH] 广告物料单价接口

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AssetAdMaterialPriceController.java |  110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 109 insertions(+), 1 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AssetAdMaterialPriceController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AssetAdMaterialPriceController.java
index b1ffd71..e5716e8 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AssetAdMaterialPriceController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AssetAdMaterialPriceController.java
@@ -1,8 +1,38 @@
 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.AssetAdMaterialPriceDTO;
+import com.ruoyi.system.query.AssetAdMaterialPriceQuery;
+import com.ruoyi.system.service.AssetAdMaterialPriceService;
+import com.ruoyi.system.vo.asset.AssetAdMaterialPriceVO;
+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>
@@ -12,9 +42,87 @@
  * @author WuGuanFengYue
  * @since 2025-09-15
  */
+@Api(tags = {"广告物料单价相关接口"})
+@Slf4j
+@Validated
 @RestController
 @RequestMapping("/asset-ad-material-price")
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class AssetAdMaterialPriceController {
 
+    private final AssetAdMaterialPriceService assetAdMaterialPriceService;
+
+    @ApiOperation(value = "新增广告物料单价")
+    @Log(title = "新增广告物料单价", businessType = BusinessType.INSERT)
+    @PostMapping("/add")
+    public R<?> addAssetAdMaterialPrice(@Valid @RequestBody AssetAdMaterialPriceDTO dto) {
+        assetAdMaterialPriceService.addAssetAdMaterialPrice(dto);
+        return R.ok();
+    }
+
+    @ApiOperation(value = "编辑广告物料单价")
+    @Log(title = "编辑广告物料单价", businessType = BusinessType.UPDATE)
+    @PostMapping("/edit")
+    public R<?> editAssetAdMaterialPrice(@Valid @RequestBody AssetAdMaterialPriceDTO dto) {
+        assetAdMaterialPriceService.editAssetAdMaterialPrice(dto);
+        return R.ok();
+    }
+
+    @ApiOperation("获取分页列表")
+    @PostMapping("/page")
+    public R<IPage<AssetAdMaterialPriceVO>> getPageList(@RequestBody AssetAdMaterialPriceQuery query) {
+        return R.ok(assetAdMaterialPriceService.getPageList(query));
+    }
+
+    @ApiOperation("详情")
+    @GetMapping("/detail/{id}")
+    public R<AssetAdMaterialPriceVO> getDetail(@ApiParam(name = "id", value = "广告物料单价ID") @PathVariable Integer id) {
+        return R.ok(assetAdMaterialPriceService.getDetail(id));
+    }
+
+    @ApiOperation("删除")
+    @Transactional(rollbackFor = Exception.class)
+    @DeleteMapping("/{id}")
+    public R<?> delete(@ApiParam(name = "id", value = "广告物料单价ID") @PathVariable Integer id) {
+        assetAdMaterialPriceService.removeById(id);
+        return R.ok();
+    }
+
+    @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);
+        }
+    }
+
+    @ApiOperation("导入")
+    @Log(title = "导入广告物料单价", businessType = BusinessType.IMPORT)
+    @PostMapping("/import")
+    public R<?> importAssetAdMaterialPrice(@RequestPart("file") MultipartFile file){
+        if (file.isEmpty()) {
+            return R.fail("请选择一个文件上传!");
+        }
+        try {
+            List<AssetAdMaterialPriceDTO> list = FastExcel.read(file.getInputStream())
+                    .head(AssetAdMaterialPriceDTO.class)
+                    .sheet()
+                    .doReadSync();
+            assetAdMaterialPriceService.importAssetAdMaterialPrice(list);
+            return R.ok();
+        } catch (IOException e) {
+            log.error("文件处理失败", e);
+            return R.fail("文件处理失败!");
+        }
+    }
 }
 

--
Gitblit v1.7.1