Files
ERP/oa-backend/src/main/java/com/kaidi/oa/web/ArchiveVersionController.java
T
QiufengandClaude Opus 4.8 5e51dc3f56 SNAPSHOT W7 已部署稳定态 — 凯迪ERP+OA一体化平台 (MET 73.3%)
恢复点(restore point)。别人改崩后可 git reset --hard 回到此提交。

== 此快照内容 ==
- 后端 oa-backend: 734 控制器 / 711 实体 (Spring Boot 3.2.5 + SQLite, 端口8091)
- 前端 modern-ui/app: Vue3+Vite, 约700页 (构建产物已在 oa-backend/src/main/resources/static)
- 数据库 oa-backend/data/oa.db: 含全部演示数据 (强制入库, 6.6MB)
- 交接文档 go.md + go-code-reference/endpoints/entities/database.md
- 多代理建设脚本 .claude/wf-*.js

== 状态 ==
- 对 凯迪科技ERP_20260507.xlsx 合规 MET ~73.3% (PARTIAL 75: 34可建+6种子/bug+35外部硬天花板)
- 安全: 5轮红队+5轮复检, default-deny分级鉴权, 连续零可利用
- W3~W7 累计补完436缺口; W8末轮(40缺口)为半成品(源码树可编译但未集成)
- 运行: cd oa-backend; java -jar build/libs/oa-backend-0.1.0.jar --server.port=8091; admin/123456

== 排除(gitignore, 可再生) ==
node_modules / oa-backend/build / .jdks / *.log / Backup-ERP-* / 弃用的OFBiz核心(只保留modern-ui)
完整文件夹备份见同目录 Backup-ERP-20260615-191517/ (含上述全部, 仅缺 node_modules)

时间戳: 20260615-191517

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 19:19:15 +08:00

135 lines
5.5 KiB
Java

package com.kaidi.oa.web;
import com.kaidi.oa.common.ApiException;
import com.kaidi.oa.common.ApiResp;
import com.kaidi.oa.common.NotFoundException;
import com.kaidi.oa.domain.Archive;
import com.kaidi.oa.domain.ArchiveVersion;
import com.kaidi.oa.repository.ArchiveRepository;
import com.kaidi.oa.repository.ArchiveVersionRepository;
import org.springframework.transaction.annotation.Transactional;
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.RestController;
import java.time.Instant;
import java.time.LocalDate;
import java.util.List;
/**
* 资料室·电子档案版本控制(Module 3「版本控制」缺口补深)。
* 同一档案可存在多个版本(图纸 V1.0、V2.0);当前有效版本标记「现行」,
* 旧版本自动置「作废」但保留(保留历史可追溯)。
* 补审计「Archive 无 version/现行/作废字段、DocumentController 恒置 setVersion(1)」缺口。
*
* <p>规则:
* <ul>
* <li>publish(发布新版)时,同一 archiveId 下所有现行版本自动置「作废」,新版置「现行」;</li>
* <li>deprecate(手动作废):只能作废现行版(将无现行版,需重新 publish);</li>
* <li>list/{archiveId}:列出某档案全部版本历史;</li>
* <li>current/{archiveId}:取当前现行版本。</li>
* </ul>
* 写口受 default-deny(ADMIN/APPROVER) 保护。
*/
@RestController
@RequestMapping("/api/oa/archive-versions")
public class ArchiveVersionController {
private final ArchiveVersionRepository versionRepo;
private final ArchiveRepository archiveRepo;
public ArchiveVersionController(ArchiveVersionRepository versionRepo,
ArchiveRepository archiveRepo) {
this.versionRepo = versionRepo;
this.archiveRepo = archiveRepo;
}
/** 某档案的全版本历史(降序,最新在前)。 */
@GetMapping("/by-archive/{archiveId}")
public ApiResp<List<ArchiveVersion>> listByArchive(@PathVariable Long archiveId) {
return ApiResp.ok(versionRepo.findByArchiveIdOrderByIdDesc(archiveId));
}
/** 某档案的现行版本(唯一)。 */
@GetMapping("/current/{archiveId}")
public ApiResp<ArchiveVersion> current(@PathVariable Long archiveId) {
return ApiResp.ok(versionRepo.findByArchiveIdAndIsCurrentTrue(archiveId)
.orElseThrow(() -> new NotFoundException("该档案暂无现行版本:archiveId=" + archiveId)));
}
@GetMapping("/{id}")
public ApiResp<ArchiveVersion> get(@PathVariable Long id) {
return ApiResp.ok(require(id));
}
public record PublishRequest(
Long archiveId, String versionNo, String changeNote,
Long storedFileId, String fileName, String author) {
}
/**
* 发布新版本:自动把同一档案下所有现行版本置「作废」,新版置「现行」。
* versionNo 形如 V1.0 / V2.0,若不填则自动生成(V{当前数量+1}.0)。
*/
@PostMapping("/publish")
@Transactional
public ApiResp<ArchiveVersion> publish(@RequestBody PublishRequest req) {
if (req.archiveId() == null) {
throw new ApiException(400, "档案 id(archiveId) 不能为空");
}
Archive arch = archiveRepo.findById(req.archiveId())
.orElseThrow(() -> new NotFoundException("archive not found: " + req.archiveId()));
// 旧现行版本全部置「作废」
List<ArchiveVersion> old = versionRepo.findByArchiveIdOrderByIdDesc(req.archiveId());
for (ArchiveVersion ov : old) {
if (Boolean.TRUE.equals(ov.getIsCurrent())) {
ov.setIsCurrent(Boolean.FALSE);
ov.setStatus("作废");
versionRepo.save(ov);
}
}
// 自动生成版本号
String verNo = req.versionNo();
if (verNo == null || verNo.isBlank()) {
long cnt = versionRepo.countByArchiveId(req.archiveId());
verNo = "V" + (cnt + 1) + ".0";
}
ArchiveVersion v = new ArchiveVersion();
v.setArchiveId(arch.getId());
v.setArchiveTitle(arch.getTitle());
v.setVersionNo(verNo.trim());
v.setIsCurrent(Boolean.TRUE);
v.setStatus("现行");
v.setChangeNote(req.changeNote());
v.setStoredFileId(req.storedFileId());
v.setFileName(req.fileName());
v.setAuthor(req.author());
v.setVersionDate(LocalDate.now().toString());
v.setCreatedAt(Instant.now());
return ApiResp.ok(versionRepo.save(v));
}
/** 手动作废某版本(现行版→作废;其他状态版本直接设作废)。 */
@PostMapping("/{id}/deprecate")
public ApiResp<ArchiveVersion> deprecate(@PathVariable Long id) {
ArchiveVersion v = require(id);
if ("作废".equals(v.getStatus())) {
throw new ApiException(409, "该版本已是「作废」状态");
}
v.setIsCurrent(Boolean.FALSE);
v.setStatus("作废");
return ApiResp.ok(versionRepo.save(v));
}
private ArchiveVersion require(Long id) {
return versionRepo.findById(id)
.orElseThrow(() -> new NotFoundException("archive version not found: " + id));
}
}