| | |
| | | package com.ruoyi.project.controller; |
| | | 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 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 |
| | | { |
| | | 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) |
| | | { |
| | | public TableDataInfo list(ServiceDocumentfiles serviceDocumentfiles) { |
| | | log.info("查询捐献附件列表:{}", serviceDocumentfiles); |
| | | startPage(); |
| | | //List<ServiceDocumentfiles> list = serviceDocumentfilesService.queryList(serviceDocumentfiles); |
| | | List<ServiceDocumentfiles> list = serviceDocumentfilesService.selectList(serviceDocumentfiles); |
| | |
| | | @ApiOperation("导出捐献附件列表") |
| | | @Log(title = "捐献附件", businessType = BusinessType.EXPORT) |
| | | @GetMapping("/export") |
| | | public AjaxResult export(ServiceDocumentfiles serviceDocumentfiles) |
| | | { |
| | | 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) |
| | | { |
| | | public AjaxResult getInfo(@PathVariable("id") Long id) { |
| | | log.info("获取捐献附件详细信息:{}", id); |
| | | return AjaxResult.success(serviceDocumentfilesService.getById(id)); |
| | | } |
| | | |
| | |
| | | */ |
| | | @ApiOperation("新增捐献附件") |
| | | @Log(title = "捐献附件", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | @PostMapping("/add") |
| | | @RepeatSubmit |
| | | public AjaxResult add(@RequestBody ServiceDocumentfiles serviceDocumentfiles) |
| | | { |
| | | return toAjax(serviceDocumentfilesService.save(serviceDocumentfiles)); |
| | | 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) |
| | | @PutMapping |
| | | @RepeatSubmit |
| | | public AjaxResult edit(@RequestBody ServiceDocumentfiles serviceDocumentfiles) |
| | | { |
| | | @PostMapping("/edit") |
| | | @RepeatSubmit |
| | | public AjaxResult edit(@RequestBody ServiceDocumentfiles serviceDocumentfiles) { |
| | | log.info("修改捐献附件:{}", serviceDocumentfiles); |
| | | return toAjax(serviceDocumentfilesService.updateById(serviceDocumentfiles)); |
| | | } |
| | | |
| | |
| | | */ |
| | | @ApiOperation("删除捐献附件") |
| | | @Log(title = "捐献附件", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{ids}") |
| | | public AjaxResult remove(@PathVariable Long[] ids) |
| | | { |
| | | @GetMapping("/remove/{ids}") |
| | | public AjaxResult remove(@PathVariable Long[] ids) { |
| | | log.info("删除捐献附件:{}", ids); |
| | | return toAjax(serviceDocumentfilesService.removeByIds(Arrays.asList(ids))); |
| | | } |
| | | } |