mitao
12 小时以前 42131eb034e559dc361fe75d653e4d904aa6a316
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
113
114
115
116
117
118
119
120
121
package com.ruoyi.web.controller.api;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Lists;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.dto.asset.AssetAdMaterialSporadicSettlementDTO;
import com.ruoyi.system.dto.asset.AssetAdMaterialSporadicSettlementImportDTO;
import com.ruoyi.system.export.AssetAdMaterialSporadicSettlementImport;
import com.ruoyi.system.query.AssetAdMaterialSporadicSettlementQuery;
import com.ruoyi.system.service.AssetAdMaterialSporadicSettlementService;
import com.ruoyi.system.vo.asset.AssetAdMaterialSporadicSettlementDetailVO;
import com.ruoyi.system.vo.asset.AssetAdMaterialSporadicSettlementVO;
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.apache.poi.ss.usermodel.Workbook;
import org.springframework.context.annotation.Lazy;
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.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.net.URLEncoder;
 
/**
 * <p>
 * 广告物料零星结算表 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2025-10-17
 */
@Slf4j
@Validated
@Api(tags = {"广告物料零星结算相关接口"})
@RestController
@RequestMapping("/asset-ad-material-sporadic-settlement")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class AssetAdMaterialSporadicSettlementController {
 
    private final AssetAdMaterialSporadicSettlementService assetAdMaterialSporadicSettlementService;
 
    @ApiOperation("下载导入模板")
    @GetMapping("/template")
    public void downloadTemplate(HttpServletResponse response) {
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), AssetAdMaterialSporadicSettlementImport.class,
                Lists.newArrayList(new AssetAdMaterialSporadicSettlementImport()));
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("广告物料零星结算导入模板.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setHeader("content-Type", "application/vnd.ms-excel");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            log.error("房屋巡检导入模板下载失败!", e);
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
    @ApiOperation("导入零星资产结算数据")
    @PostMapping("/import")
    public R<?> importData(@RequestPart("file") MultipartFile file, @Valid AssetAdMaterialSporadicSettlementImportDTO dto) {
        assetAdMaterialSporadicSettlementService.importData(file, dto);
        return R.ok();
    }
 
    @ApiOperation("分页列表")
    @PostMapping("/page")
    public R<IPage<AssetAdMaterialSporadicSettlementVO>> getPageList(@RequestBody AssetAdMaterialSporadicSettlementQuery query){
        return R.ok(assetAdMaterialSporadicSettlementService.getPageList(query));
    }
 
    @ApiOperation("新增")
    @PostMapping("/add")
    public R<Boolean> add(@Valid @RequestBody AssetAdMaterialSporadicSettlementDTO dto){
        return R.ok(assetAdMaterialSporadicSettlementService.add(dto));
    }
 
    @ApiOperation("编辑")
    @PostMapping("/edit")
    public R<?> edit(@Valid @RequestBody AssetAdMaterialSporadicSettlementDTO dto){
        assetAdMaterialSporadicSettlementService.edit(dto);
        return R.ok();
    }
 
    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public R<?> deleteById(@ApiParam(name = "id", value = "主键") @PathVariable Integer id) {
        assetAdMaterialSporadicSettlementService.deleteById(id);
        return R.ok();
    }
 
    @ApiOperation("详情")
    @GetMapping("/detail/{id}")
    public R<AssetAdMaterialSporadicSettlementDetailVO> getDetail(@ApiParam(name = "id", value = "主键") @PathVariable Integer id) {
        return R.ok(assetAdMaterialSporadicSettlementService.getDetail(id));
    }
}