mitao
2 天以前 e8e30e5474c1fd0c14390710066e40c17155ad37
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.ruoyi.web.controller.api;
 
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.utils.FastExcelUtil;
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.util.Collections;
import java.util.List;
 
/**
 * <p>
 * 广告物料单价参考表 前端控制器
 * </p>
 *
 * @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){
        FastExcelUtil.exportData(response, "广告物料单价导入模板", "广告物料单价", AssetAdMaterialPriceDTO.class, Collections.emptyList());
    }
 
    @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 = FastExcelUtil.readMultipartFile(file.getInputStream(), AssetAdMaterialPriceDTO.class);
            assetAdMaterialPriceService.importAssetAdMaterialPrice(list);
            return R.ok();
        } catch (IOException e) {
            log.error("文件处理失败", e);
            return R.fail("文件处理失败!");
        }
    }
}