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:
@@ -0,0 +1,238 @@
|
||||
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.StdApplication;
|
||||
import com.kaidi.oa.repository.StdApplicationRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
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.LocalDate;
|
||||
import java.time.Year;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 标准申请辅助(知识产权部,需求功能9 — 补深 LOGIC_GAP)。
|
||||
*
|
||||
* 补深三项审计缺口:
|
||||
* (1) 模板化字段:预置标准名称/类型/起草单位/计划编号/技术内容/起草人/归口单位,附件含草案+编制说明;
|
||||
* (2) 进度阶段状态机:提交 → 受理 → 审查 → 报批 → 发布,流转时回填本阶段开始日并设默认预计耗时;
|
||||
* (3) 各阶段预计耗时自动计算 + 逾期提醒:按内置默认/自定义阶段耗时算预计完成日,alerts 端点列出
|
||||
* 逾期或临近的在办标准申请。
|
||||
*
|
||||
* 写口默认受保护(新控制器默认受 AuthInterceptor 保护),无需进财务前缀。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/oa/std-applications")
|
||||
public class StdApplicationController {
|
||||
|
||||
private final StdApplicationRepository repo;
|
||||
|
||||
public StdApplicationController(StdApplicationRepository repo) {
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
private static final List<String> STAGES = List.of("提交", "受理", "审查", "报批", "发布");
|
||||
|
||||
/** 各阶段默认预计耗时(天)——内置标准制修订经验值,可在流转时覆盖。 */
|
||||
private static final Map<String, Integer> DEFAULT_DAYS = Map.of(
|
||||
"提交", 10, "受理", 20, "审查", 60, "报批", 30, "发布", 15);
|
||||
|
||||
// ---------- 台账 CRUD ----------
|
||||
|
||||
@GetMapping
|
||||
public ApiResp<List<StdApplication>> list(@RequestParam(required = false) String stage,
|
||||
@RequestParam(required = false) String stdType) {
|
||||
if (stage != null && !stage.isBlank()) {
|
||||
return ApiResp.ok(repo.findByStage(stage));
|
||||
}
|
||||
if (stdType != null && !stdType.isBlank()) {
|
||||
return ApiResp.ok(repo.findByStdType(stdType));
|
||||
}
|
||||
return ApiResp.ok(repo.findAll());
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ApiResp<StdApplication> get(@PathVariable Long id) {
|
||||
return ApiResp.ok(find(id));
|
||||
}
|
||||
|
||||
public record StdRequest(String stdName, String stdType, String draftingUnit, String planNo,
|
||||
String techContent, String drafters, String supervisor, String attachments,
|
||||
Long rdProjectId, String owner, String remark) {
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Transactional
|
||||
public ApiResp<StdApplication> create(@RequestBody StdRequest req) {
|
||||
if (req.stdName() == null || req.stdName().isBlank()) {
|
||||
throw new ApiException(400, "标准名称不能为空");
|
||||
}
|
||||
StdApplication s = new StdApplication();
|
||||
s.setCode(nextCode());
|
||||
apply(s, req);
|
||||
s.setStage("提交");
|
||||
s.setStageStartDate(LocalDate.now().toString());
|
||||
s.setStageExpectedDays(DEFAULT_DAYS.get("提交"));
|
||||
s.setCreatedAt(java.time.Instant.now());
|
||||
s.setUpdatedAt(java.time.Instant.now());
|
||||
return ApiResp.ok(repo.save(s));
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}")
|
||||
@Transactional
|
||||
public ApiResp<StdApplication> update(@PathVariable Long id, @RequestBody StdRequest req) {
|
||||
StdApplication s = find(id);
|
||||
apply(s, req);
|
||||
s.setUpdatedAt(java.time.Instant.now());
|
||||
return ApiResp.ok(repo.save(s));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@Transactional
|
||||
public ApiResp<Void> delete(@PathVariable Long id) {
|
||||
StdApplication s = find(id);
|
||||
if (!"提交".equals(s.getStage())) {
|
||||
throw new ApiException(409, "已进入受理及以后阶段的标准申请不可删除");
|
||||
}
|
||||
repo.deleteById(id);
|
||||
return ApiResp.ok(null);
|
||||
}
|
||||
|
||||
// ---------- 阶段流转(状态机 + 预计耗时) ----------
|
||||
|
||||
public record AdvanceRequest(Integer expectedDays, String note) {
|
||||
}
|
||||
|
||||
/** 进入下一阶段(提交→受理→审查→报批→发布),回填本阶段开始日并设预计耗时(默认/自定义)。 */
|
||||
@PostMapping("/{id}/advance")
|
||||
@Transactional
|
||||
public ApiResp<StdApplication> advance(@PathVariable Long id, @RequestBody AdvanceRequest req) {
|
||||
StdApplication s = find(id);
|
||||
int idx = STAGES.indexOf(s.getStage());
|
||||
if (idx < 0 || idx >= STAGES.size() - 1) {
|
||||
throw new ApiException(409, "当前阶段「" + s.getStage() + "」已是终态,无法继续推进");
|
||||
}
|
||||
String next = STAGES.get(idx + 1);
|
||||
s.setStage(next);
|
||||
s.setStageStartDate(LocalDate.now().toString());
|
||||
s.setStageExpectedDays(req.expectedDays() != null && req.expectedDays() > 0
|
||||
? req.expectedDays() : DEFAULT_DAYS.getOrDefault(next, 30));
|
||||
s.setUpdatedAt(java.time.Instant.now());
|
||||
return ApiResp.ok(repo.save(s));
|
||||
}
|
||||
|
||||
// ---------- 各阶段预计完成日 + 逾期提醒 ----------
|
||||
|
||||
public record StagePlan(String stage, int expectedDays, String startDate,
|
||||
String expectedDoneDate, long daysElapsed, long daysRemaining, String level) {
|
||||
}
|
||||
|
||||
/** 某标准申请的当前阶段进度计算:已耗天数 / 剩余天数 / 预计完成日 / 提醒级别。 */
|
||||
@GetMapping("/{id}/progress")
|
||||
public ApiResp<StagePlan> progress(@PathVariable Long id) {
|
||||
StdApplication s = find(id);
|
||||
return ApiResp.ok(planOf(s));
|
||||
}
|
||||
|
||||
public record StdAlert(Long id, String code, String stdName, String stage,
|
||||
String expectedDoneDate, long daysRemaining, String level, String owner) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 在办标准申请的阶段逾期/临近提醒:对非「发布」终态、阶段预计完成日落在窗口内的申请,
|
||||
* 给出 逾期 / 紧急(<=3天) / 临近(<=7天) / 提醒(<=days) 分级。
|
||||
*/
|
||||
@GetMapping("/alerts")
|
||||
public ApiResp<List<StdAlert>> alerts(@RequestParam(required = false, defaultValue = "15") int days) {
|
||||
List<StdAlert> out = new ArrayList<>();
|
||||
for (StdApplication s : repo.findAll()) {
|
||||
if ("发布".equals(s.getStage())) {
|
||||
continue;
|
||||
}
|
||||
StagePlan plan = planOf(s);
|
||||
if (plan.expectedDoneDate() == null) {
|
||||
continue;
|
||||
}
|
||||
if (plan.daysRemaining() > days) {
|
||||
continue;
|
||||
}
|
||||
out.add(new StdAlert(s.getId(), s.getCode(), s.getStdName(), s.getStage(),
|
||||
plan.expectedDoneDate(), plan.daysRemaining(), plan.level(), s.getOwner()));
|
||||
}
|
||||
out.sort((a, b) -> Long.compare(a.daysRemaining(), b.daysRemaining()));
|
||||
return ApiResp.ok(out);
|
||||
}
|
||||
|
||||
// ---------- helpers ----------
|
||||
|
||||
private StagePlan planOf(StdApplication s) {
|
||||
int expected = s.getStageExpectedDays() == null
|
||||
? DEFAULT_DAYS.getOrDefault(s.getStage(), 30) : s.getStageExpectedDays();
|
||||
LocalDate start = parseDateOrNull(s.getStageStartDate());
|
||||
if (start == null) {
|
||||
return new StagePlan(s.getStage(), expected, s.getStageStartDate(), null, 0, 0, "未开始");
|
||||
}
|
||||
LocalDate done = start.plusDays(expected);
|
||||
LocalDate today = LocalDate.now();
|
||||
long elapsed = ChronoUnit.DAYS.between(start, today);
|
||||
long remaining = ChronoUnit.DAYS.between(today, done);
|
||||
String level = "发布".equals(s.getStage()) ? "已完成"
|
||||
: remaining < 0 ? "逾期" : remaining <= 3 ? "紧急" : remaining <= 7 ? "临近" : "正常";
|
||||
return new StagePlan(s.getStage(), expected, s.getStageStartDate(), done.toString(),
|
||||
elapsed, remaining, level);
|
||||
}
|
||||
|
||||
private StdApplication find(Long id) {
|
||||
return repo.findById(id)
|
||||
.orElseThrow(() -> new NotFoundException("标准申请不存在:" + id));
|
||||
}
|
||||
|
||||
private void apply(StdApplication s, StdRequest req) {
|
||||
if (req.stdName() != null && !req.stdName().isBlank()) s.setStdName(req.stdName());
|
||||
if (req.stdType() != null) s.setStdType(req.stdType() == null || req.stdType().isBlank() ? "团体" : req.stdType());
|
||||
if (req.draftingUnit() != null) s.setDraftingUnit(req.draftingUnit());
|
||||
if (req.planNo() != null) s.setPlanNo(req.planNo());
|
||||
if (req.techContent() != null) s.setTechContent(req.techContent());
|
||||
if (req.drafters() != null) s.setDrafters(req.drafters());
|
||||
if (req.supervisor() != null) s.setSupervisor(req.supervisor());
|
||||
if (req.attachments() != null) s.setAttachments(req.attachments());
|
||||
if (req.rdProjectId() != null) s.setRdProjectId(req.rdProjectId());
|
||||
if (req.owner() != null) s.setOwner(req.owner());
|
||||
if (req.remark() != null) s.setRemark(req.remark());
|
||||
if (s.getStdType() == null || s.getStdType().isBlank()) {
|
||||
s.setStdType("团体");
|
||||
}
|
||||
}
|
||||
|
||||
private String nextCode() {
|
||||
String prefix = "STD-" + Year.now().getValue() + "-";
|
||||
long n = repo.countByCodeStartingWith(prefix) + 1;
|
||||
return prefix + String.format("%03d", n);
|
||||
}
|
||||
|
||||
private static LocalDate parseDateOrNull(String s) {
|
||||
if (s == null || s.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
String t = s.trim();
|
||||
return LocalDate.parse(t.substring(0, Math.min(10, t.length())));
|
||||
} catch (DateTimeParseException | IndexOutOfBoundsException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user