sinake
2 天以前 d6e936e3dcb645658fa7e0c3e02c1daa30bfeb68
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package com.ruoyi.web.controller.project;
 
import java.io.File;
import java.util.Arrays;
import java.util.List;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.ServiceDocumentfiles;
import com.ruoyi.project.service.IServiceDocumentfilesService;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.config.ServerConfig;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
 
/**
 * 捐献附件Controller
 *
 * @author ruoyi
 * @date 2022-04-08
 */
@Slf4j
@Api("捐献附件")
@RestController
@RequestMapping("/project/documentfiles")
public class ServiceDocumentfilesController extends BaseController {
    @Autowired
    private IServiceDocumentfilesService serviceDocumentfilesService;
 
    @Autowired
    private ServerConfig serverConfig;
 
    /**
     * 政策文件上传(**不限文件类型**)。
     *
     * <p>2026-10-09 业务要求:政策文件模块允许上传/下载任意文件类型。
     *
     * <p>为什么不直接用 {@code /common/upload}:通用上传走
     * {@code FileUploadUtils.upload(baseDir, file)},会按 {@code MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION}
     * 白名单校验扩展名,非白名单类型(如 dwg、7z、ofd、eml 等)会被拒绝。
     * 这里把 allowedExtension 显式传 {@code null} —— {@code assertAllowed} 的判断是
     * {@code allowedExtension != null && !isAllowedExtension(...)},传 null 即跳过扩展名校验,
     * 同时**仍保留** 500MB 大小限制、文件名长度限制与存储路径安全处理。
     *
     * <p>仅政策文件模块使用本接口;{@code /common/upload} 与其他模块的白名单保持不变。
     *
     * @param file 上传文件
     * @return 与 {@code /common/upload} 一致的返回体(code/msg/fileName/url)
     */
    @ApiOperation("政策文件上传(不限文件类型)")
    @PostMapping("/upload")
    public AjaxResult uploadFile(MultipartFile file) {
        String originalFilename = file == null ? null : file.getOriginalFilename();
        try {
            if (file == null || file.isEmpty()) {
                return AjaxResult.error("上传文件为空,请重新选择文件");
            }
            // 上传文件路径
            String filePath = RuoYiConfig.getUploadPath();
 
            // 同名文件处理:加时间戳重命名,避免覆盖已上传文件(与通用上传保持一致)
            String filename = originalFilename == null ? "" : originalFilename.trim();
            String pathFileName = FileUploadUtils.extractFilename(file);
            File target = new File(filePath + "/" + pathFileName);
            if (target.exists()) {
                int i = filename.lastIndexOf(".");
                if (i > -1) {
                    String startStr = filename.substring(0, i);
                    String endStr = filename.substring(i);
                    String newFilename = startStr + System.currentTimeMillis() + endStr;
                    file = new MockMultipartFile(newFilename, newFilename, file.getContentType(), file.getBytes());
                }
            }
 
            // allowedExtension 传 null:不做扩展名校验,允许任意文件类型
            String relativePath = FileUploadUtils.upload(filePath, file, null);
 
            // 与通用上传一致的 url 处理(部分部署下 8032 需要带 /prod-api 前缀)
            String url = serverConfig.getUrl();
            if (url != null && url.contains("8032")) {
                url = url.replace("8032", "8032/prod-api");
            }
 
            log.info("政策文件上传成功:原始文件名={},存储路径={}", filename, relativePath);
            AjaxResult ajax = AjaxResult.success();
            ajax.put("fileName", relativePath);
            ajax.put("url", url + relativePath);
            return ajax;
        } catch (Exception e) {
            // 返回 AjaxResult(HTTP 200 + code=500),前端 uploadSccess 的 else 分支会把原因弹出来
            log.error("政策文件上传失败:原始文件名={}", originalFilename, e);
            return AjaxResult.error("上传失败:" + e.getMessage());
        }
    }
 
    /**
     * 查询捐献附件列表
     */
    @ApiOperation("查询捐献附件列表")
    @GetMapping("/list")
    public TableDataInfo list(ServiceDocumentfiles serviceDocumentfiles) {
        log.info("查询捐献附件列表:{}", serviceDocumentfiles);
        startPage();
        //List<ServiceDocumentfiles> list = serviceDocumentfilesService.queryList(serviceDocumentfiles);
        List<ServiceDocumentfiles> list = serviceDocumentfilesService.selectList(serviceDocumentfiles);
        return getDataTable(list);
    }
 
    /**
     * 导出捐献附件列表
     */
    @ApiOperation("导出捐献附件列表")
    @Log(title = "捐献附件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ServiceDocumentfiles serviceDocumentfiles) {
        log.info("导出捐献附件列表:{}", serviceDocumentfiles);
        List<ServiceDocumentfiles> list = serviceDocumentfilesService.queryList(serviceDocumentfiles);
        ExcelUtil<ServiceDocumentfiles> util = new ExcelUtil<ServiceDocumentfiles>(ServiceDocumentfiles.class);
        return util.exportExcel(list, "捐献附件数据");
    }
 
    /**
     * 获取捐献附件详细信息
     */
    @ApiOperation("获取捐献附件详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        log.info("获取捐献附件详细信息:{}", id);
        return AjaxResult.success(serviceDocumentfilesService.getById(id));
    }
 
    /**
     * 新增捐献附件
     */
    @ApiOperation("新增捐献附件")
    @Log(title = "捐献附件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @RepeatSubmit
    public AjaxResult add(@RequestBody ServiceDocumentfiles serviceDocumentfiles) {
        log.info("新增捐献附件:{}", serviceDocumentfiles);
        boolean save = serviceDocumentfilesService.save(serviceDocumentfiles);
        log.info("新增捐献附件serviceDocumentfiles的id:{}", serviceDocumentfiles.getId());
        return AjaxResult.success(serviceDocumentfiles);
    }
 
    /**
     * 修改捐献附件
     */
    @ApiOperation("修改捐献附件")
    @Log(title = "捐献附件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @RepeatSubmit
    public AjaxResult edit(@RequestBody ServiceDocumentfiles serviceDocumentfiles) {
        log.info("修改捐献附件:{}", serviceDocumentfiles);
        return toAjax(serviceDocumentfilesService.updateById(serviceDocumentfiles));
    }
 
    /**
     * 删除捐献附件
     */
    @ApiOperation("删除捐献附件")
    @Log(title = "捐献附件", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        log.info("删除捐献附件:{}", ids);
        return toAjax(serviceDocumentfilesService.removeByIds(Arrays.asList(ids)));
    }
}