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>
This commit is contained in:
Qiufeng
2026-06-15 19:19:15 +08:00
co-authored by Claude Opus 4.8
commit 5e51dc3f56
10584 changed files with 2501339 additions and 0 deletions
@@ -0,0 +1,160 @@
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.ArchiveReservation;
import com.kaidi.oa.repository.ArchiveRepository;
import com.kaidi.oa.repository.ArchiveReservationRepository;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.Instant;
import java.time.LocalDate;
import java.util.List;
/**
* 资料室·预约与续借管理(Module 5「预约与续借」缺口补深)。
* 档案被借出时,其他用户可排队预约;归还后按预约队列通知可借(状态「排队中→可借」)。
* 预约人再发起正式借阅后状态置「已转借阅」。补审计「预约与续借完全缺」缺口。
*
* <p>状态机:
* <pre>
* 排队中 ──(档案归还通知)notify──▶ 可借 ──(预约人发起借阅)convert──▶ 已转借阅(终态)
* 排队中 / 可借 ──cancel──▶ 已取消(终态)
* </pre>
*
* <p>排队序号(queueNo):同一档案下先到先得,新预约自动取当前最大序号+1。
* 写口受 default-deny(ADMIN/APPROVER) 保护。
*/
@RestController
@RequestMapping("/api/oa/archive-reservations")
public class ArchiveReservationController {
private final ArchiveReservationRepository reserveRepo;
private final ArchiveRepository archiveRepo;
public ArchiveReservationController(ArchiveReservationRepository reserveRepo,
ArchiveRepository archiveRepo) {
this.reserveRepo = reserveRepo;
this.archiveRepo = archiveRepo;
}
@GetMapping
public ApiResp<List<ArchiveReservation>> list(@RequestParam(required = false) String status) {
if (status != null && !status.isBlank()) {
return ApiResp.ok(reserveRepo.findByStatus(status));
}
return ApiResp.ok(reserveRepo.findAll());
}
/** 某档案的预约队列(按排队序号升序)。 */
@GetMapping("/by-archive/{archiveId}")
public ApiResp<List<ArchiveReservation>> byArchive(@PathVariable Long archiveId) {
return ApiResp.ok(reserveRepo.findByArchiveIdOrderByQueueNoAsc(archiveId));
}
@GetMapping("/{id}")
public ApiResp<ArchiveReservation> get(@PathVariable Long id) {
return ApiResp.ok(require(id));
}
public record CreateRequest(
Long archiveId, String requester, String requesterDept, String purpose) {
}
/**
* 发起预约(排队中)。自动计算排队序号(同档案现有非终止预约数+1)。
* 同一用户对同一档案只可有一条「排队中/可借」预约(防重复排队)。
*/
@PostMapping
@Transactional
public ApiResp<ArchiveReservation> create(@RequestBody CreateRequest req) {
if (req.archiveId() == null) {
throw new ApiException(400, "档案 id(archiveId) 不能为空");
}
if (req.requester() == null || req.requester().isBlank()) {
throw new ApiException(400, "预约人(requester) 不能为空");
}
Archive arch = archiveRepo.findById(req.archiveId())
.orElseThrow(() -> new NotFoundException("archive not found: " + req.archiveId()));
// 防重复:同用户对同档案只能有一条活跃预约
List<ArchiveReservation> existing = reserveRepo.findByArchiveIdOrderByQueueNoAsc(req.archiveId())
.stream()
.filter(r -> req.requester().equals(r.getRequester())
&& ("排队中".equals(r.getStatus()) || "可借".equals(r.getStatus())))
.toList();
if (!existing.isEmpty()) {
throw new ApiException(409, "您已对该档案有一条预约(序号 " + existing.get(0).getQueueNo() + "),请勿重复预约");
}
// 队尾排号
long activeCount = reserveRepo.findByArchiveIdOrderByQueueNoAsc(req.archiveId())
.stream()
.filter(r -> "排队中".equals(r.getStatus()) || "可借".equals(r.getStatus()))
.count();
ArchiveReservation rsv = new ArchiveReservation();
rsv.setCode("YY-" + (reserveRepo.count() + 1));
rsv.setArchiveId(arch.getId());
rsv.setArchiveTitle(arch.getTitle());
rsv.setRequester(req.requester().trim());
rsv.setRequesterDept(req.requesterDept());
rsv.setPurpose(req.purpose());
rsv.setQueueNo((int) activeCount + 1);
rsv.setStatus("排队中");
rsv.setReserveDate(LocalDate.now().toString());
rsv.setCreatedAt(Instant.now());
return ApiResp.ok(reserveRepo.save(rsv));
}
/**
* 通知可借(排队中 → 可借)。档案归还后,资料室管理员调此端点通知队首预约人可借阅。
* 自动取该档案队首(最小 queueNo 且状态=排队中)通知;也可指定 id 直接通知。
*/
@PostMapping("/{id}/notify")
public ApiResp<ArchiveReservation> notify(@PathVariable Long id) {
ArchiveReservation rsv = require(id);
if (!"排队中".equals(rsv.getStatus())) {
throw new ApiException(409, "仅「排队中」可通知,当前:" + rsv.getStatus());
}
rsv.setStatus("可借");
rsv.setNotifyDate(LocalDate.now().toString());
return ApiResp.ok(reserveRepo.save(rsv));
}
/** 转为已借阅(可借 → 已转借阅)。预约人发起正式借阅后由系统调用,闭合预约。 */
@PostMapping("/{id}/convert")
public ApiResp<ArchiveReservation> convert(@PathVariable Long id) {
ArchiveReservation rsv = require(id);
if (!"可借".equals(rsv.getStatus())) {
throw new ApiException(409, "仅「可借」状态可转借阅,当前:" + rsv.getStatus());
}
rsv.setStatus("已转借阅");
return ApiResp.ok(reserveRepo.save(rsv));
}
/** 取消预约(排队中/可借 → 已取消)。 */
@PostMapping("/{id}/cancel")
public ApiResp<ArchiveReservation> cancel(@PathVariable Long id) {
ArchiveReservation rsv = require(id);
if ("已转借阅".equals(rsv.getStatus()) || "已取消".equals(rsv.getStatus())) {
throw new ApiException(409, "" + rsv.getStatus() + "」状态不可取消");
}
rsv.setStatus("已取消");
return ApiResp.ok(reserveRepo.save(rsv));
}
private ArchiveReservation require(Long id) {
return reserveRepo.findById(id)
.orElseThrow(() -> new NotFoundException("archive reservation not found: " + id));
}
}