Files
YschcmsService/src/main/java/com/yunhai/cms/controller/api/AttachmentController.java
T
chenxing b4822a7f38 feat(B2): 附件引用模型-cms_attachment 增 ref_type/ref_id,消灭孤儿误报
- 实体/双 SQL 加列+idx_att_ref;upload 增 scene 白名单(banner/link/site)
- AttachmentService 新增 markUsed/release/markSiteConfigUsed(webUrl 反查,幂等)
- 未使用=articleId 与 refType 均空;page 返回 unusedCount(前后端同步改名无兼容别名)
- Banner/Link 保存先解引用再回写(换图旧图回未使用);Site 配置 logo/favicon 引用回写(@Lazy 解循环依赖)
- 新增13例(Attachment6/Banner3/Link2/Site2)+既有语义断言更新;mvn -o test 全绿
2026-09-07 19:40:14 +08:00

58 lines
2.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.yunhai.cms.controller.api;
import com.yunhai.cms.model.dto.DeleteRequest;
import com.yunhai.cms.model.vo.AttachmentVo;
import com.yunhai.cms.service.impl.AttachmentService;
import com.yunhai.platform.utils.model.BoaUser;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.util.Map;
/**
* 附件管理(方案 §9.2):编辑器图片/附件/轮播图/友链 Logo 复用同一上传接口。
*/
@RestController
@RequestMapping("/api/attachment")
@RequiredArgsConstructor
public class AttachmentController {
private final AttachmentService attachmentService;
/** 上传(multipart:file 必填;articleId 可空;scene 可空 banner/link/site,B2 初步标记) */
@PostMapping("/upload")
public AttachmentVo upload(BoaUser authUserWithDept,
@RequestParam("siteId") Integer siteId,
@RequestParam(value = "articleId", required = false) Integer articleId,
@RequestParam(value = "scene", required = false) String scene,
@RequestParam("file") MultipartFile file) {
return attachmentService.upload(authUserWithDept, siteId, articleId, scene, file);
}
/** 附件列表(orphanOnly=true 仅孤儿) */
@GetMapping("/page")
public Map<String, Object> page(BoaUser authUserWithDept,
@RequestParam("siteId") Integer siteId,
@RequestParam(value = "orphanOnly", required = false,
defaultValue = "false") boolean orphanOnly,
@RequestParam(value = "page", required = false,
defaultValue = "1") Integer page,
@RequestParam(value = "pageSize", required = false,
defaultValue = "10") Integer pageSize) {
return attachmentService.page(authUserWithDept, siteId, orphanOnly, page, pageSize);
}
/** 删除附件记录(物理文件运维定期清理) */
@PostMapping("/delete")
public void delete(BoaUser authUserWithDept, @Valid @RequestBody DeleteRequest request) {
attachmentService.delete(authUserWithDept, request);
}
}