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
package com.ruoyi.web.controller.api;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.google.common.collect.Lists;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.dto.asset.AssetAdMaterialSporadicSettlementDTO;
import com.ruoyi.system.export.AssetAdMaterialSporadicSettlementImport;
import com.ruoyi.system.service.AssetAdMaterialSporadicSettlementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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 AssetAdMaterialSporadicSettlementDTO dto) {
        assetAdMaterialSporadicSettlementService.importData(file, dto);
        return R.ok();
    }
 
}