diff --git a/ruoyi-project/sql/project_collaboration.sql b/ruoyi-project/sql/project_collaboration.sql index af93ffa..7799c63 100644 --- a/ruoyi-project/sql/project_collaboration.sql +++ b/ruoyi-project/sql/project_collaboration.sql @@ -527,3 +527,40 @@ WHERE NOT EXISTS(SELECT 1 FROM sys_menu WHERE menu_id=2601); INSERT INTO sys_menu(menu_id,menu_name,parent_id,order_num,path,is_frame,is_cache,menu_type,visible,status,perms,create_by,create_time) SELECT 2602,'项目协作配置',2600,2,'#',1,0,'F','0','0','project:manage:admin','admin',CURRENT_TIMESTAMP WHERE NOT EXISTS(SELECT 1 FROM sys_menu WHERE menu_id=2602); + +-- 阶段组、同层执行图及父级历史组合 +ALTER TABLE pm_collab_project_stage + ADD COLUMN stage_kind VARCHAR(8) NOT NULL DEFAULT 'WORK' COMMENT '阶段类型:WORK工作阶段,GROUP阶段组', + ADD COLUMN parent_stage_id BIGINT NULL COMMENT '所属阶段组ID;空值表示迭代根画布', + ADD KEY idx_pm_stage_parent(project_id,iteration_id,parent_stage_id,deleted,id), + ADD CONSTRAINT fk_pm_stage_parent FOREIGN KEY(project_id,iteration_id,parent_stage_id) REFERENCES pm_collab_project_stage(project_id,iteration_id,id), + ADD CONSTRAINT ck_pm_stage_kind CHECK(stage_kind IN ('WORK','GROUP')), + ADD CONSTRAINT ck_pm_stage_parent CHECK(stage_kind<>'GROUP' OR parent_stage_id IS NULL); +ALTER TABLE pm_collab_stage_edge + ADD COLUMN parent_stage_id BIGINT NULL COMMENT '执行连线所属阶段组;空值表示迭代根画布', + ADD KEY idx_pm_edge_canvas(project_id,iteration_id,parent_stage_id,id), + ADD CONSTRAINT fk_pm_edge_canvas FOREIGN KEY(project_id,iteration_id,parent_stage_id) REFERENCES pm_collab_project_stage(project_id,iteration_id,id); +ALTER TABLE pm_collab_stage_revision + ADD COLUMN stage_kind_snapshot VARCHAR(8) NOT NULL DEFAULT 'WORK' COMMENT '本版本阶段类型快照', + ADD COLUMN parent_stage_snapshot_id BIGINT NULL COMMENT '本版本所属阶段组ID快照', + ADD COLUMN stage_description_snapshot TEXT NULL COMMENT '本版本阶段说明快照', + ADD COLUMN revision_reason VARCHAR(16) NOT NULL DEFAULT 'INITIAL' COMMENT '产生原因:INITIAL初建,REWORK整体重做,CHILD_REWORK子阶段换版汇总'; +CREATE TABLE pm_collab_stage_revision_member ( + id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID', + project_id BIGINT NOT NULL COMMENT '协作项目ID', + iteration_id BIGINT NOT NULL COMMENT '所属迭代ID', + parent_stage_id BIGINT NOT NULL COMMENT '所属阶段组ID', + parent_revision_id BIGINT NOT NULL COMMENT '父级汇总版本ID', + child_stage_id BIGINT NOT NULL COMMENT '子阶段ID', + child_revision_id BIGINT NOT NULL COMMENT '该汇总版本绑定的子执行版本ID', + snapshot_json LONGTEXT NULL COMMENT '冻结时的子阶段和工作项只读快照;不包含附件二进制及公开存储地址', + snapshot_format_version INT NOT NULL DEFAULT 1 COMMENT '历史快照数据格式版本', + frozen_at BIGINT NULL COMMENT '快照冻结时间(UTC微秒);空值表示当前实时组合', + PRIMARY KEY(id), + UNIQUE KEY uk_pm_group_revision_child(parent_revision_id,child_stage_id), + KEY idx_pm_group_child_revision(child_revision_id,parent_revision_id), + CONSTRAINT fk_pm_group_parent_revision FOREIGN KEY(project_id,iteration_id,parent_stage_id,parent_revision_id) REFERENCES pm_collab_stage_revision(project_id,iteration_id,stage_id,id), + CONSTRAINT fk_pm_group_child_revision FOREIGN KEY(project_id,iteration_id,child_stage_id,child_revision_id) REFERENCES pm_collab_stage_revision(project_id,iteration_id,stage_id,id), + CONSTRAINT ck_pm_group_snapshot CHECK((snapshot_json IS NULL AND frozen_at IS NULL) OR (snapshot_json IS NOT NULL AND frozen_at IS NOT NULL AND JSON_VALID(snapshot_json))), + CONSTRAINT ck_pm_group_self CHECK(parent_stage_id<>child_stage_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='项目协作:阶段组版本成员及冻结历史'; diff --git a/ruoyi-project/sql/upgrade/019_stage_groups.sql b/ruoyi-project/sql/upgrade/019_stage_groups.sql new file mode 100644 index 0000000..102f73b --- /dev/null +++ b/ruoyi-project/sql/upgrade/019_stage_groups.sql @@ -0,0 +1,38 @@ +-- 项目协作:两层阶段树、同层画布和阶段组历史快照。先备份,018 后执行一次。 +-- 保留已有阶段、工作项、版本及精确排期;旧阶段全部为根工作阶段。 +SET NAMES utf8mb4; +ALTER TABLE pm_collab_project_stage + ADD COLUMN stage_kind VARCHAR(8) NOT NULL DEFAULT 'WORK' COMMENT '阶段类型:WORK工作阶段,GROUP阶段组', + ADD COLUMN parent_stage_id BIGINT NULL COMMENT '所属阶段组ID;空值表示迭代根画布', + ADD KEY idx_pm_stage_parent(project_id,iteration_id,parent_stage_id,deleted,id), + ADD CONSTRAINT fk_pm_stage_parent FOREIGN KEY(project_id,iteration_id,parent_stage_id) REFERENCES pm_collab_project_stage(project_id,iteration_id,id), + ADD CONSTRAINT ck_pm_stage_kind CHECK(stage_kind IN ('WORK','GROUP')), + ADD CONSTRAINT ck_pm_stage_parent CHECK(stage_kind<>'GROUP' OR parent_stage_id IS NULL); +ALTER TABLE pm_collab_stage_edge + ADD COLUMN parent_stage_id BIGINT NULL COMMENT '执行连线所属阶段组;空值表示迭代根画布', + ADD KEY idx_pm_edge_canvas(project_id,iteration_id,parent_stage_id,id), + ADD CONSTRAINT fk_pm_edge_canvas FOREIGN KEY(project_id,iteration_id,parent_stage_id) REFERENCES pm_collab_project_stage(project_id,iteration_id,id); +ALTER TABLE pm_collab_stage_revision + ADD COLUMN stage_kind_snapshot VARCHAR(8) NOT NULL DEFAULT 'WORK' COMMENT '本版本阶段类型快照', + ADD COLUMN parent_stage_snapshot_id BIGINT NULL COMMENT '本版本所属阶段组ID快照', + ADD COLUMN stage_description_snapshot TEXT NULL COMMENT '本版本阶段说明快照', + ADD COLUMN revision_reason VARCHAR(16) NOT NULL DEFAULT 'INITIAL' COMMENT '产生原因:INITIAL初建,REWORK整体重做,CHILD_REWORK子阶段换版汇总'; +CREATE TABLE pm_collab_stage_revision_member ( + id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID', + project_id BIGINT NOT NULL COMMENT '协作项目ID', + iteration_id BIGINT NOT NULL COMMENT '所属迭代ID', + parent_stage_id BIGINT NOT NULL COMMENT '所属阶段组ID', + parent_revision_id BIGINT NOT NULL COMMENT '父级汇总版本ID', + child_stage_id BIGINT NOT NULL COMMENT '子阶段ID', + child_revision_id BIGINT NOT NULL COMMENT '该汇总版本绑定的子执行版本ID', + snapshot_json LONGTEXT NULL COMMENT '冻结时的子阶段和工作项只读快照;不包含附件二进制及公开存储地址', + snapshot_format_version INT NOT NULL DEFAULT 1 COMMENT '历史快照数据格式版本', + frozen_at BIGINT NULL COMMENT '快照冻结时间(UTC微秒);空值表示当前实时组合', + PRIMARY KEY(id), + UNIQUE KEY uk_pm_group_revision_child(parent_revision_id,child_stage_id), + KEY idx_pm_group_child_revision(child_revision_id,parent_revision_id), + CONSTRAINT fk_pm_group_parent_revision FOREIGN KEY(project_id,iteration_id,parent_stage_id,parent_revision_id) REFERENCES pm_collab_stage_revision(project_id,iteration_id,stage_id,id), + CONSTRAINT fk_pm_group_child_revision FOREIGN KEY(project_id,iteration_id,child_stage_id,child_revision_id) REFERENCES pm_collab_stage_revision(project_id,iteration_id,stage_id,id), + CONSTRAINT ck_pm_group_snapshot CHECK((snapshot_json IS NULL AND frozen_at IS NULL) OR (snapshot_json IS NOT NULL AND frozen_at IS NOT NULL AND JSON_VALID(snapshot_json))), + CONSTRAINT ck_pm_group_self CHECK(parent_stage_id<>child_stage_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='项目协作:阶段组版本成员及冻结历史'; diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/controller/PmReworkController.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/controller/PmReworkController.java index cad28ad..67ff5a5 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/controller/PmReworkController.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/controller/PmReworkController.java @@ -32,9 +32,12 @@ public class PmReworkController { /** 阶段历史列表分页且先检查项目、迭代和阶段的完整归属。 */ @GetMapping("/projects/{id}/iterations/{iterationId}/stages/{stageId}/revisions") public Map iterationRevisions(@PathVariable long id,@PathVariable long iterationId,@PathVariable long stageId,@RequestParam(defaultValue="1") int page,@RequestParam(defaultValue="50") int pageSize) { return ok(service.revisionPage(id,iterationId,stageId,page,pageSize)); } - /** 历史工作项按选定版本分页,可通过原工作项详情 ID 查看只读记录。 */ + /** 历史工作项按选定版本分页;阶段组详情需继续携带父级版本,防止读取保留分支的后续变化。 */ @GetMapping("/projects/{id}/iterations/{iterationId}/stages/{stageId}/revisions/{revisionId}") public Map iterationRevision(@PathVariable long id,@PathVariable long iterationId,@PathVariable long stageId,@PathVariable long revisionId,@RequestParam(defaultValue="1") int page,@RequestParam(defaultValue="50") int pageSize) { return ok(service.revisionItemsPage(id,iterationId,stageId,revisionId,page,pageSize)); } + /** 历史父级组合的工作项详情不追随仍活跃的并行分支,权限仍按当前项目成员核验。 */ + @GetMapping("/projects/{id}/iterations/{iterationId}/stages/{stageId}/revisions/{revisionId}/items/{itemId}") + public Map snapshot(@PathVariable long id,@PathVariable long iterationId,@PathVariable long stageId,@PathVariable long revisionId,@PathVariable long itemId) { return ok(service.itemSnapshot(id,iterationId,stageId,revisionId,itemId)); } /** 当前项目阶段轮次列表,旧轮次不混入普通流程图。 */ @GetMapping("/projects/{id}/stages/{stageId}/revisions") public Map revisions(@PathVariable long id,@PathVariable long stageId) { return ok(service.revisions(id,stageId)); } /** 轮次的只读工作项快照。 */ diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/controller/PmStageController.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/controller/PmStageController.java index 3877619..104641b 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/controller/PmStageController.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/controller/PmStageController.java @@ -17,6 +17,12 @@ import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/project/manage") public class PmStageController { + /** 结构预览不写成功记录;接口仍复验项目管理者和迭代状态。 */ + @PostMapping("/projects/{id}/iterations/{iterationId}/stage-structure/preview") + public Map structurePreview(@PathVariable long id,@PathVariable long iterationId,@RequestBody JsonNode body) { return ok(service.structure(id,iterationId,decode(body,com.ruoyi.project.manage.dto.StageStructureInput.class),false)); } + /** 提交显式最终结构并复算预览图版本,不开放跨层自动迁移。 */ + @PostMapping("/projects/{id}/iterations/{iterationId}/stage-structure") + public Map structureCommit(@PathVariable long id,@PathVariable long iterationId,@RequestBody JsonNode body) { return ok(service.structure(id,iterationId,decode(body,com.ruoyi.project.manage.dto.StageStructureInput.class),true)); } private final IPmStageService service; private final ObjectMapper strict; /** 复用项目动作鉴权服务,独立解码器同时校验所有嵌套展示字段白名单。 */ diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/domain/Graph.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/domain/Graph.java index d3398e7..2cc0f07 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/domain/Graph.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/domain/Graph.java @@ -3,7 +3,11 @@ package com.ruoyi.project.manage.domain; import java.util.*; /** 事务内可替换的最终依赖图,用于统一排期、实际状态和循环校验。 */ -public record Graph(Map items,List dependencies,Map stageNames,List stageLinks,Map stageRevisions,IterationScope iteration) { +public record Graph(Map items,List dependencies,Map stageNames,List stageLinks,Map stageRevisions,IterationScope iteration,Map hierarchy) { + /** 兼容原平级调用,缺省组织信息明确解释为根工作阶段,不补造父级。 */ + public Graph(Map items,List dependencies,Map stageNames,List stageLinks,Map stageRevisions,IterationScope iteration) { this(items,dependencies,stageNames,stageLinks,stageRevisions,iteration,new LinkedHashMap<>()); } + /** 候选图替换组织结构用于最终态校验,不修改原事务快照。 */ + public Graph withHierarchy(Map values) { return new Graph(items,dependencies,stageNames,stageLinks,stageRevisions,iteration,new LinkedHashMap<>(values)); } /** 纯规则和历史快照可省略迭代上下文;生产当前图始终显式携带数据库迭代。 */ public Graph(Map items,List dependencies,Map stageNames,List stageLinks,Map stageRevisions) { this(items,dependencies,stageNames,stageLinks,stageRevisions,null); } /** 旧的纯任务规则测试无需构造阶段;生产图始终由数据库加载有效阶段。 */ @@ -13,5 +17,5 @@ public record Graph(Map items,List dependencies,Map items,List dependencies,Map stageNames,List stageLinks) { this(items,dependencies,stageNames,stageLinks,new LinkedHashMap<>()); } /** 为事务内最终态验证创建独立容器,不修改已读取的原始快照。 */ - public Graph copy() { return new Graph(new LinkedHashMap<>(items),new ArrayList<>(dependencies),new LinkedHashMap<>(stageNames),new ArrayList<>(stageLinks),new LinkedHashMap<>(stageRevisions),iteration); } + public Graph copy() { return new Graph(new LinkedHashMap<>(items),new ArrayList<>(dependencies),new LinkedHashMap<>(stageNames),new ArrayList<>(stageLinks),new LinkedHashMap<>(stageRevisions),iteration,new LinkedHashMap<>(hierarchy)); } } diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/domain/StageInfo.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/domain/StageInfo.java new file mode 100644 index 0000000..b01b972 --- /dev/null +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/domain/StageInfo.java @@ -0,0 +1,7 @@ +package com.ruoyi.project.manage.domain; + +/** 阶段组织身份与执行版本分离;父级表达包含关系,执行先后仍由显式边决定。 */ +public record StageInfo(long id,String kind,Long parentId,String description) { + /** 容器只承载子阶段,不能接受工作项,避免完成规则出现两种来源。 */ + public boolean group() { return "GROUP".equals(kind); } +} diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/dto/StageInput.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/dto/StageInput.java index e40c4ed..cee53d2 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/dto/StageInput.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/dto/StageInput.java @@ -1,4 +1,7 @@ package com.ruoyi.project.manage.dto; -/** 阶段组织元数据,不承载执行流程或节点状态。 */ -public record StageInput(String name,Integer sortOrder,Long ownerId,String description,Integer version) { } +/** 阶段创建同时提交组织身份和整日计划;编辑不允许通过元数据接口偷偷迁移父级。 */ +public record StageInput(String name,Integer sortOrder,Long ownerId,String description,Integer version,String stageKind,Long parentStageId,String plannedStartAt,String plannedEndAt) { + /** 原内部元数据调用省略结构字段;创建入口仍要求显式有效计划。 */ + public StageInput(String name,Integer sortOrder,Long ownerId,String description,Integer version) { this(name,sortOrder,ownerId,description,version,null,null,null,null); } +} diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/dto/StageStructureInput.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/dto/StageStructureInput.java new file mode 100644 index 0000000..d05bd88 --- /dev/null +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/dto/StageStructureInput.java @@ -0,0 +1,9 @@ +package com.ruoyi.project.manage.dto; + +import java.util.List; + +/** 结构预览与提交使用同一明确最终态:只移动列出的阶段,执行边列表完整替换,不自动猜测跨层连接。 */ +public record StageStructureInput(Long graphVersion,List stages,List edges) { + /** 未执行工作阶段的明确父级变更;空父级表示回到外层画布。 */ + public record Move(long id,Integer version,Long parentStageId) { } +} diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/mapper/PmGroupMapper.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/mapper/PmGroupMapper.java new file mode 100644 index 0000000..78b7dcf --- /dev/null +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/mapper/PmGroupMapper.java @@ -0,0 +1,21 @@ +package com.ruoyi.project.manage.mapper; + +import java.util.*; +import org.apache.ibatis.annotations.*; + +/** 阶段组当前版本组合与冻结历史的唯一存储入口;写入由统一项目锁事务保护。 */ +@Mapper +public interface PmGroupMapper { + /** 冻结时批量读取当前分工名称,避免负责人改名或离开成员清单后历史显示成未分配。 */ + java.util.List> selectItemOwners(@Param("projectId") long projectId,@Param("iterationId") long iterationId); + /** 查询指定汇总版本的成员,历史读取不能改用子阶段的最新指针。 */ + List> selectMembers(@Param("revisionId") long revisionId); + /** 当前组合在首次执行前可补齐成员;已冻结快照不能覆盖。 */ + int bindMember(@Param("projectId") long projectId,@Param("iterationId") long iterationId,@Param("parentId") long parentId,@Param("revisionId") long revisionId,@Param("childId") long childId,@Param("childRevisionId") long childRevisionId); + /** 清理未执行阶段结构调整留下的旧成员;冻结数据永久保留。 */ + int deleteDraftMembers(@Param("revisionId") long revisionId); + /** 冻结一次成员视图,后续执行不能改变旧版本的工作项、评论及附件元数据。 */ + int freezeMember(@Param("id") long id,@Param("snapshot") String snapshot,@Param("at") long at); + /** 精确写入汇总时间,局部回退的新组合不能沿用错误的 COALESCE 旧开始时间。 */ + int updateGroupState(@Param("revisionId") long revisionId,@Param("start") Long start,@Param("end") Long end); +} diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/mapper/PmStageMapper.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/mapper/PmStageMapper.java index 7e0ebfc..ded90af 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/mapper/PmStageMapper.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/mapper/PmStageMapper.java @@ -9,6 +9,10 @@ import org.apache.ibatis.annotations.Param; /** 项目协作对象访问接口;固定 SQL 位于同名 XML,服务层负责权限、事务与规则。 */ @Mapper public interface PmStageMapper { + /** 未执行版本随显式结构调整更新身份,已启动快照保持原值用于追溯。 */ + int refreshDraftRevisionIdentity(@Param("revisionId") long revisionId,@Param("kind") String kind,@Param("parentId") Long parentId,@Param("description") String description); + /** 结构提交在完整最终态校验后替换本迭代全部执行边,历史定义快照保留原边。 */ + int deleteIterationEdges(@Param("projectId") long projectId,@Param("iterationId") long iterationId); /** 移除成员前检查其是否负责有效阶段。 */ Map selectOwnedStage(@Param("projectId") long projectId, @Param("userId") Long userId); diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/notification/PmNotificationPlanner.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/notification/PmNotificationPlanner.java index 4ffb1b3..dfacd75 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/notification/PmNotificationPlanner.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/notification/PmNotificationPlanner.java @@ -11,19 +11,23 @@ import static com.ruoyi.project.manage.util.PmValues.*; /** 在业务提交前固定通知内容及分工,实际投递由 outbox 调度,不在持锁事务内连接邮件服务器。 */ @Service public class PmNotificationPlanner { + // 操作历史与个人站内消息是两条链路;评论和附件也必须进入此白名单,才能随 outbox 投递给业务分工人员。 private static final Map ITEM_ACTIONS=Map.ofEntries( Map.entry("ITEM_CREATED","工作项已创建"),Map.entry("CHILD_CREATED","子任务已创建"), Map.entry("ITEM_EDITED","工作项已修改"),Map.entry("ITEM_STAGE_CHANGED","工作项所属阶段已修改"), Map.entry("STATUS_CHANGED","工作项状态已修改"),Map.entry("TASK_STARTED","工作项已开始"), Map.entry("SCHEDULE_CHANGED","工作项排期已修改"),Map.entry("SCHEDULE_REVIEWED","工作项排期已确认"), - Map.entry("DEPENDENCY_SAVED","工作项前置依赖已修改"),Map.entry("DEPENDENCY_REMOVED","工作项前置依赖已移除")); + Map.entry("DEPENDENCY_SAVED","工作项前置依赖已修改"),Map.entry("DEPENDENCY_REMOVED","工作项前置依赖已移除"), + Map.entry("COMMENT_ADDED","工作项新增评论"),Map.entry("ATTACHMENT_ADDED","工作项新增附件"), + Map.entry("ATTACHMENT_DELETED","工作项附件已删除")); private final PmNotificationMapper mapper; /** 注入本模块的受控读取入口;通知内容不接受客户端提交的收件地址或模板。 */ public PmNotificationPlanner(PmNotificationMapper mapper) { this.mapper=mapper; } /** - * 为创建、修改和回退生成一个通知计划,阶段回退对整个新版本取人员并集,不为复制出的每项生成邮件。 + * 为工作项创建、修改、评论、附件变更及回退生成通知计划,收件人为去重后的负责人和协作人。 + * 阶段回退对整个新版本取人员并集;评论和附件入口沿用未勾选邮件时仅发站内消息的默认规则。 * @param projectId 调用方已鉴权并锁定的协作项目 * @param iterationId 业务事件所属迭代,项目级其他操作不产生个人提醒 * @param itemId 普通工作项事件的真实 ID;阶段回退为空 diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmRules.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmRules.java index 1e42077..1cec624 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmRules.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmRules.java @@ -133,6 +133,7 @@ public final class PmRules { /** 用 DFS 三色法检查各类型工作项、父子和阶段执行图;阶段进入/完成拆点,才能检测跨阶段执行死锁。 */ public static void validateAcyclic(Graph graph) { + PmStageHierarchyRules.validate(graph); Map> edges = new LinkedHashMap<>(); for (Dependency d : graph.dependencies()) edge(edges,"T"+d.taskId(),"T"+d.successorId()); // 父完成等待所有子任务结束,因此子完成→父完成也是执行图中的边。 @@ -141,6 +142,11 @@ public final class PmRules { // 进入阶段后才可启动工作项;阶段所有工作项完成后才可进入下游。 // 空阶段仍有进入→完成边,使纯阶段环及混合任务环使用同一检测算法。 for(Long stageId:graph.stageNames().keySet()) edge(edges,"I"+stageId,"O"+stageId); + // 父级进入只代表准入;父级完成等待每个子阶段,独立分支也不能漏掉。 + for(Long stageId:graph.stageNames().keySet()) { + Long parent=PmStageHierarchyRules.info(graph,stageId).parentId(); + if(parent!=null) { edge(edges,"I"+parent,"I"+stageId); edge(edges,"O"+stageId,"O"+parent); } + } for(Item item:graph.items().values()) if(!item.deleted()&&item.stageId()!=null&&graph.stageNames().containsKey(item.stageId())) { edge(edges,"I"+item.stageId(),"T"+item.id()); edge(edges,"T"+item.id(),"O"+item.stageId()); } diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmScheduleReviewRules.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmScheduleReviewRules.java index 7fa8541..4a55f1f 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmScheduleReviewRules.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmScheduleReviewRules.java @@ -18,9 +18,15 @@ public final class PmScheduleReviewRules { * @return 稳定顺序的复核集合及可理解的阻塞原因;不修改原图 */ public static Impact affected(Graph graph,Set replaced) { + return affected(graph,replaced,Set.of()); + } + + /** 汇总换版保留有效父计划;只有正式计划被清空的执行阶段才传播排期复核,版本号变化本身不使后继计划失效。 */ + public static Impact affected(Graph graph,Set replaced,Set aggregates) { + Set changed=new HashSet<>(replaced); changed.addAll(aggregates); Set stages=new TreeSet<>(); - for(Long id:graph.stageNames().keySet()) if(!replaced.contains(id)&&PmStageRules.ancestors(graph,id).stream().anyMatch(replaced::contains)) stages.add(id); - return closure(graph,replaced,stages,Set.of()); + for(Long id:graph.stageNames().keySet()) if(!changed.contains(id)&&PmStageRules.ancestors(graph,id).stream().anyMatch(replaced::contains)) stages.add(id); + return closure(graph,changed,stages,Set.of()); } /** @@ -40,6 +46,8 @@ public final class PmScheduleReviewRules { do { int before=stages.size()+items.size(); for(Long stage:graph.stageNames().keySet()) if(!replaced.contains(stage)&&PmStageRules.ancestors(graph,stage).stream().anyMatch(stages::contains)) stages.add(stage); + // 只有父级正式计划也失效时才传播到全部子级;汇总版本本身保留计划时不扩大无关分支。 + for(Long stage:List.copyOf(stages)) for(Long child:PmStageHierarchyRules.children(graph,stage)) if(!replaced.contains(child)) stages.add(child); for(Item item:graph.items().values()) if(!item.deleted()&&(item.stageId()==null||!replaced.contains(item.stageId()))) { if(item.stageId()!=null&&stages.contains(item.stageId())||items.contains(item.id())||item.parentTaskId()!=null&&items.contains(item.parentTaskId())) { items.add(item.id()); if(item.stageId()!=null) stages.add(item.stageId()); diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmStageHierarchyRules.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmStageHierarchyRules.java new file mode 100644 index 0000000..45b551f --- /dev/null +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmStageHierarchyRules.java @@ -0,0 +1,58 @@ +package com.ruoyi.project.manage.rule; + +import com.ruoyi.project.manage.domain.*; +import com.ruoyi.project.manage.exception.PmException; +import java.util.*; +import static com.ruoyi.project.manage.util.PmValues.*; + +/** 包含树与执行图分开验证;首版只允许根阶段组包含工作阶段,不能通过跨层连线制造隐式准入。 */ +public final class PmStageHierarchyRules { + /** 纯规则没有数据库或全局可变状态。 */ + private PmStageHierarchyRules() { } + + /** 旧平级快照按根工作阶段兼容,生产加载始终提供真实组织身份。 */ + public static StageInfo info(Graph graph,long id) { return graph.hierarchy().getOrDefault(id,new StageInfo(id,"WORK",null,null)); } + + /** 返回有效直接子阶段的稳定顺序,空容器返回空列表而非自动完成。 */ + public static List children(Graph graph,long id) { return graph.stageNames().keySet().stream().filter(child->Objects.equals(info(graph,child).parentId(),id)).sorted().toList(); } + + /** 所属父级链不包含阶段自身;损坏的历史组织关系明确拒绝,不能无限递归。 */ + public static List parents(Graph graph,long id) { + List result=new ArrayList<>(); Set seen=new HashSet<>(); seen.add(id); + Long next=info(graph,id).parentId(); + while(next!=null) { + if(!seen.add(next)||!graph.stageNames().containsKey(next)) throw PmException.conflict("STAGE_HIERARCHY_INVALID","阶段父级无效或形成包含循环"); + result.add(next); next=info(graph,next).parentId(); + } + return result; + } + + /** 用于组筛选和汇总的阶段集合包含自身;不从展示筛选结果推导执行范围。 */ + public static Set subtree(Graph graph,long id) { + Set result=new LinkedHashSet<>(); result.add(id); + for(Long child:graph.stageNames().keySet()) if(parents(graph,child).contains(id)) result.add(child); + return result; + } + + /** 验证层级、同层边及工作项归属;调用者在项目锁内传入整批最终图。 */ + public static void validate(Graph graph) { + for(Long id:graph.stageNames().keySet()) { + StageInfo stage=info(graph,id); List parents=parents(graph,id); + if(!Set.of("WORK","GROUP").contains(stage.kind())||parents.size()>1||stage.group()&&!parents.isEmpty() + ||!parents.isEmpty()&&!info(graph,parents.get(0)).group()) + throw new PmException(409,"STAGE_HIERARCHY_INVALID","仅支持外层阶段组包含工作阶段",map("stageId",id)); + } + for(StageLink edge:graph.stageLinks()) if(!graph.stageNames().containsKey(edge.predecessorStageId())||!graph.stageNames().containsKey(edge.successorStageId()) + ||!Objects.equals(info(graph,edge.predecessorStageId()).parentId(),info(graph,edge.successorStageId()).parentId())) + throw PmException.conflict("STAGE_EDGE_SCOPE_CONFLICT","执行连线两端必须位于同一画布"); + for(Item item:graph.items().values()) if(!item.deleted()&&item.stageId()!=null&&(!graph.stageNames().containsKey(item.stageId())||info(graph,item.stageId()).group())) + throw new PmException(409,"WORK_ITEM_STAGE_INVALID","工作项只能归入有效工作阶段",map("taskId",item.id())); + } + + /** 完整阶段路径供列表、看板及错误提示共用,旧根阶段仍只显示自身名称。 */ + public static String path(Graph graph,long id) { + var names=new ArrayList(); var parents=new ArrayList<>(parents(graph,id)); Collections.reverse(parents); + for(Long parent:parents) names.add(graph.stageNames().get(parent)); names.add(graph.stageNames().get(id)); + return String.join(" / ",names); + } +} diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmStageRules.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmStageRules.java index 9fca0fa..f2f0c21 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmStageRules.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmStageRules.java @@ -25,10 +25,16 @@ public final class PmStageRules { return blockedStage(graph,item.stageId()); } - /** 当前版至少有一项有效工作项且全部完成或关闭,才可视为完成;历史兼容事实单独展示。 */ + /** 工作阶段按当前工作项、阶段组按全部子阶段汇总;空节点不自动放行,迁移事实保持只读兼容。 */ public static String executionStatus(Graph graph,long stageId) { var revision=graph.stageRevisions().get(stageId); if(revision!=null&&revision.legacyPassedAt()!=null) return "LEGACY_PASSED"; + if(PmStageHierarchyRules.info(graph,stageId).group()) { + List children=PmStageHierarchyRules.children(graph,stageId); + if(!children.isEmpty()&&children.stream().allMatch(id->Set.of("COMPLETED","LEGACY_PASSED").contains(executionStatus(graph,id)))) return "COMPLETED"; + if(children.stream().anyMatch(id->!"NOT_STARTED".equals(executionStatus(graph,id)))) return "IN_PROGRESS"; + return "NOT_STARTED"; + } List items=graph.items().values().stream().filter(i->!i.deleted()&&Objects.equals(i.stageId(),stageId)).toList(); if(!items.isEmpty()&&items.stream().allMatch(PmRules::completed)) return "COMPLETED"; if(revision!=null&&revision.startedAt()!=null || items.stream().anyMatch(i->Set.of("IN_PROGRESS","COMPLETED","CLOSED").contains(i.status()))) return "IN_PROGRESS"; @@ -62,17 +68,19 @@ public final class PmStageRules { return List.of(); } - /** 阶段的全部直接和间接前置都要完成;空新阶段不能放行后继。 */ + /** 阶段及父级的准入前置均需完成;不等待父级完成,避免父子相互等待。 */ public static List> blockedStage(Graph graph,long stageId) { Map> incoming=new HashMap<>(); for(StageLink link:graph.stageLinks()) incoming.computeIfAbsent(link.successorStageId(),unused->new ArrayList<>()).add(link.predecessorStageId()); List> reasons=new ArrayList<>(); Set visited=new HashSet<>(); Deque queue=new ArrayDeque<>(incoming.getOrDefault(stageId,List.of())); + for(Long parent:PmStageHierarchyRules.parents(graph,stageId)) queue.addAll(incoming.getOrDefault(parent,List.of())); while(!queue.isEmpty()) { long predecessorId=queue.removeFirst(); if(!visited.add(predecessorId)) continue; - List unfinished=graph.items().values().stream().filter(candidate->!candidate.deleted()&&Objects.equals(candidate.stageId(),predecessorId)&&!PmRules.completed(candidate)).toList(); + Set scope=PmStageHierarchyRules.subtree(graph,predecessorId); + List unfinished=graph.items().values().stream().filter(candidate->!candidate.deleted()&&scope.contains(candidate.stageId())&&!PmRules.completed(candidate)).toList(); String status=executionStatus(graph,predecessorId); - if(!Set.of("COMPLETED","LEGACY_PASSED").contains(status)) reasons.add(map("code","PREDECESSOR_STAGE_INCOMPLETE","stageId",predecessorId,"sourceName",graph.stageNames().get(predecessorId),"currentStatus",status,"expectedStatus","COMPLETED","message",unfinished.isEmpty()?"前置阶段尚无已完成的当前工作项":"前置阶段还有未完成工作项","unfinishedCount",unfinished.size(),"unfinishedItemIds",unfinished.stream().map(Item::id).toList())); + if(!Set.of("COMPLETED","LEGACY_PASSED").contains(status)) reasons.add(map("code","PREDECESSOR_STAGE_INCOMPLETE","stageId",predecessorId,"sourceName",PmStageHierarchyRules.path(graph,predecessorId),"currentStatus",status,"expectedStatus","COMPLETED","message","前置阶段或其子阶段尚未完成","unfinishedCount",unfinished.size(),"unfinishedItemIds",unfinished.stream().map(Item::id).toList())); queue.addAll(incoming.getOrDefault(predecessorId,List.of())); } return reasons; @@ -104,7 +112,10 @@ public final class PmStageRules { List changed=new ArrayList<>(); for(Long stageId:before.stageNames().keySet()) { if("NOT_STARTED".equals(executionStatus(before,stageId))) continue; - if(!ancestors(before,stageId).equals(ancestors(after,stageId))) changed.add(stageId); + if(!after.stageNames().containsKey(stageId)||!ancestors(before,stageId).equals(ancestors(after,stageId)) + ||!Objects.equals(PmStageHierarchyRules.info(before,stageId).parentId(),PmStageHierarchyRules.info(after,stageId).parentId()) + ||!PmStageHierarchyRules.info(before,stageId).kind().equals(PmStageHierarchyRules.info(after,stageId).kind()) + ||!PmStageHierarchyRules.children(before,stageId).equals(PmStageHierarchyRules.children(after,stageId))) changed.add(stageId); } if(!changed.isEmpty()) throw new PmException(409,"STAGE_TOPOLOGY_LOCKED","已执行阶段的前置关系不能改写;请先回退或只编辑未开始的后续流程",map("stageIds",changed)); } diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmStageScheduleRules.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmStageScheduleRules.java index 499b0d3..7a7ba68 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmStageScheduleRules.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/rule/PmStageScheduleRules.java @@ -21,6 +21,18 @@ public final class PmStageScheduleRules { StageRevision r=graph.stageRevisions().get(stageId); List> sources=new ArrayList<>(),missing=new ArrayList<>(),conflicts=new ArrayList<>(); Long earliest=null; + Long parentId=PmStageHierarchyRules.info(graph,stageId).parentId(); + if(parentId!=null) { + StageRevision parent=graph.stageRevisions().get(parentId); + if(parent==null||parent.plannedStart()==null||parent.plannedEnd()==null||parent.scheduleReviewReworkId()!=null) + missing.add(map("code","PARENT_STAGE_UNSCHEDULED","stageId",parentId,"message","请先确认父阶段组计划,或同批调整父子计划")); + else { + earliest=parent.plannedStart(); + sources.add(map("kind","PARENT_RANGE","stageId",parentId,"sourceName",graph.stageNames().get(parentId),"plannedStartAt",time(parent.plannedStart()),"plannedEndAt",time(parent.plannedEnd()))); + if(r!=null&&(r.plannedStart()!=null&&r.plannedStart()parent.plannedEnd())) + conflicts.add(map("code","CHILD_STAGE_OUTSIDE_PARENT","stageId",parentId,"sourceName",graph.stageNames().get(parentId),"message","子阶段预计日期超出父阶段组范围")); + } + } for(StageLink edge:graph.stageLinks()) if(edge.successorStageId()==stageId) { StageRevision p=graph.stageRevisions().get(edge.predecessorStageId()); Map source=map("stageId",edge.predecessorStageId(),"sourceName",graph.stageNames().get(edge.predecessorStageId()), @@ -43,10 +55,23 @@ public final class PmStageScheduleRules { boolean finished=Set.of("COMPLETED","LEGACY_PASSED").contains(PmStageRules.executionStatus(graph,stageId)); String status=!conflicts.isEmpty()?"CONFLICT":r==null||r.plannedStart()==null||!missing.isEmpty()||review?"INCOMPLETE":"VALID"; Map result=times(r); - result.putAll(map("earliestPlannedStartAt",missing.isEmpty()?time(earliest):null,"sources",sources,"unresolvedSources",missing, + StageRevision parentRevision=parentId==null?null:graph.stageRevisions().get(parentId); + result.putAll(map("earliestPlannedStartAt",missing.isEmpty()?time(earliest):null,"latestPlannedEndAt",parentRevision==null?null:time(parentRevision.plannedEnd()),"sources",sources,"unresolvedSources",missing, "conflicts",conflicts,"scheduleBlockedReasons",concat(missing,conflicts),"scheduleValidationStatus",status, "scheduleReviewRequired",review,"scheduleReviewClosed",review&&finished, "overdue",r!=null&&!finished&&!review&&r.plannedEnd()!=null&&PmTime.now()>=r.plannedEnd())); + String subtreeStatus=status; + for(Long child:PmStageHierarchyRules.children(graph,stageId)) { + String childStatus=(String)summary(graph,child).get("subtreeScheduleValidationStatus"); + if("CONFLICT".equals(childStatus)) subtreeStatus="CONFLICT"; + else if(!"VALID".equals(childStatus)&&!"CONFLICT".equals(subtreeStatus)) subtreeStatus="INCOMPLETE"; + } + for(Item item:graph.items().values()) if(!item.deleted()&&Objects.equals(item.stageId(),stageId)) { + String itemStatus=(String)PmRules.schedule(graph,item,"Asia/Shanghai").get("scheduleValidationStatus"); + if("CONFLICT".equals(itemStatus)) subtreeStatus="CONFLICT"; + else if(!"VALID".equals(itemStatus)&&!"CONFLICT".equals(subtreeStatus)) subtreeStatus="INCOMPLETE"; + } + result.put("subtreeScheduleValidationStatus",subtreeStatus); return result; } diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/IPmReworkService.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/IPmReworkService.java index 7c94f55..2456822 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/IPmReworkService.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/IPmReworkService.java @@ -20,7 +20,7 @@ public interface IPmReworkService { List> revisions(long projectId,long iterationId,long stageId); /** 旧历史列表入口要求明确迭代,不能只凭阶段 ID 绕过范围校验。 */ default List> revisions(long projectId,long stageId) { throw new PmException(400,"ITERATION_REQUIRED","请明确选择迭代",Map.of()); } - /** 历史轮次与工作项只读返回,评论和操作记录由旧工作项详情提供。 */ + /** 历史轮次只读返回;叶阶段使用旧工作项详情,阶段组使用带父级版本上下文的冻结详情。 */ Map revision(long projectId,long iterationId,long stageId,long revisionId); /** 旧历史详情入口缺少迭代边界时拒绝。 */ default Map revision(long projectId,long stageId,long revisionId) { throw new PmException(400,"ITERATION_REQUIRED","请明确选择迭代",Map.of()); } @@ -30,4 +30,6 @@ public interface IPmReworkService { Map revisionPage(long projectId,long iterationId,long stageId,int page,int pageSize); /** 分页读取指定历史轮次的工作项,返回总数与只读版本元数据。 */ Map revisionItemsPage(long projectId,long iterationId,long stageId,long revisionId,int page,int pageSize); + /** 在父级版本上下文读取冻结的工作项详情,不能将实时详情作为旧父级的内容。 */ + Map itemSnapshot(long projectId,long iterationId,long stageId,long revisionId,long itemId); } diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/IPmStageService.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/IPmStageService.java index f515793..be112ca 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/IPmStageService.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/IPmStageService.java @@ -10,6 +10,8 @@ import java.util.*; /** 显式阶段执行图与展示布局契约;不恢复已停用的流程节点依赖。 */ public interface IPmStageService { + /** 项目管理者预览或提交明确阶段层级及全部连线最终态,预览不产生成功历史。 */ + Map structure(long projectId,long iterationId,com.ruoyi.project.manage.dto.StageStructureInput input,boolean commit); /** * 在项目锁内读取单迭代阶段、显式阶段边和工作项计数;画布不返回完整工作项。 * diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmIterationServiceImpl.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmIterationServiceImpl.java index b7faa9d..2ab8660 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmIterationServiceImpl.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmIterationServiceImpl.java @@ -39,10 +39,12 @@ public class PmIterationServiceImpl implements IPmIterationService { private final IPmService business; private final PmJson codec; private final ObjectMapper json; + private final com.ruoyi.project.manage.service.support.PmGroupVersionService groups; /** 所有依赖共享上层事务连接;取消复用现有最终图校验,避免直接批量改状态。 */ public PmIterationServiceImpl(PmIterationMapper mapper,PmWorkspaceMapper workspace,PmAccess access,PmIterationAccess iterations, - PmGraphService graphs,PmAuditService audit,IPmService business,PmJson codec,ObjectMapper json) { + PmGraphService graphs,PmAuditService audit,IPmService business,PmJson codec,ObjectMapper json,com.ruoyi.project.manage.service.support.PmGroupVersionService groups) { + this.groups=groups; this.mapper=mapper; this.workspace=workspace; this.access=access; this.iterations=iterations; this.graphs=graphs; this.audit=audit; this.business=business; this.codec=codec; this.json=json; } @@ -229,7 +231,9 @@ public class PmIterationServiceImpl implements IPmIterationService { warnings.add(map("sourceStageId",number(stage,"id"),"sourceStageName",text(stage,"name"),"ownerId",owner,"message","阶段“"+text(stage,"name")+"”的原负责人已不可分配,新阶段负责人已清空")); owner=null; } - Map values=map("project_id",projectId,"iteration_id",target,"name",stage.get("name"),"sort_order",stage.get("sort_order"),"owner_id",owner,"description",stage.get("description"),"created_by",actor,"created_at",now); + Long oldParent=nullable(stage,"parent_stage_id"),parent=oldParent==null?null:ids.get(oldParent); + if(oldParent!=null&&parent==null) throw new IllegalStateException("复制来源的父阶段组缺失"); + Map values=map("project_id",projectId,"iteration_id",target,"name",stage.get("name"),"sort_order",stage.get("sort_order"),"owner_id",owner,"description",stage.get("description"),"stage_kind",stage.get("stage_kind"),"parent_stage_id",parent,"created_by",actor,"created_at",now); long id=mapper.insertCopiedStage(values); ids.put(number(stage,"id"),id); values.put("stage_id",id); values.remove("id"); long revision=mapper.insertCopiedRevision(values); @@ -241,6 +245,7 @@ public class PmIterationServiceImpl implements IPmIterationService { mapper.insertCopiedEdge(map("project_id",projectId,"iteration_id",target,"predecessor_stage_id",predecessor,"successor_stage_id",successor,"created_by",actor,"created_at",now)); } mapper.insertCopiedDefinition(map("project_id",projectId,"iteration_id",target,"graph_json",codec.encode(map("stages",mapper.selectCopyStages(projectId,target),"stageEdges",mapper.selectCopyEdges(projectId,target))),"created_by",actor,"created_at",now)); + groups.bind(projectId,target); return warnings; } diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmReworkServiceImpl.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmReworkServiceImpl.java index 8994b39..394a4cd 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmReworkServiceImpl.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmReworkServiceImpl.java @@ -17,6 +17,8 @@ import com.ruoyi.project.manage.mapper.PmWorkItemMapper; import com.ruoyi.project.manage.mapper.PmWorkspaceMapper; import com.ruoyi.project.manage.rule.PmRules; import com.ruoyi.project.manage.rule.PmStageRules; +import com.ruoyi.project.manage.rule.PmStageHierarchyRules; +import com.ruoyi.project.manage.service.support.PmGroupVersionService; import com.ruoyi.project.manage.security.PmAccess; import com.ruoyi.project.manage.security.PmIterationAccess; import com.ruoyi.project.manage.service.IPmReworkService; @@ -48,18 +50,20 @@ public class PmReworkServiceImpl implements IPmReworkService { private final PmJson json; private final ObjectMapper decoder; private final PmParticipantService participants; + private final PmGroupVersionService groups; /** 只注入本模块 Mapper 和统一鉴权,事务失败时版本、工作项与 outbox 一同回滚。 */ public PmReworkServiceImpl(PmWorkspaceMapper workspace,PmStageMapper stages,PmWorkItemMapper workItems, PmDependencyMapper dependencies,PmRevisionMapper revisions,PmGraphService graphs, - PmAuditService audit,PmAccess access,PmJson json,ObjectMapper decoder,PmIterationAccess iterationAccess,com.ruoyi.project.manage.mapper.PmScheduleMapper schedules,com.ruoyi.project.manage.service.IPmScheduleService scheduleService,PmParticipantService participants) { + PmAuditService audit,PmAccess access,PmJson json,ObjectMapper decoder,PmIterationAccess iterationAccess,com.ruoyi.project.manage.mapper.PmScheduleMapper schedules,com.ruoyi.project.manage.service.IPmScheduleService scheduleService,PmParticipantService participants,PmGroupVersionService groups) { + this.groups=groups; this.participants=participants; this.schedules=schedules; this.scheduleService=scheduleService; this.iterationAccess=iterationAccess; this.workspace=workspace; this.stages=stages; this.workItems=workItems; this.dependencies=dependencies; this.revisions=revisions; this.graphs=graphs; this.audit=audit; this.access=access; this.json=json; this.decoder=decoder; } - private record Plan(Graph graph,List affected,List copies,List> excluded, + private record Plan(Graph graph,List affected,List aggregates,List copies,List> excluded, List> missingAssignees,List> missingCollaborators,List> blockers,List reviewStages,List reviewItems, Set members) { } @@ -94,18 +98,27 @@ public class PmReworkServiceImpl implements IPmReworkService { long at=PmTime.now(),actor=access.actor(); Map saved=map("projectId",projectId,"iterationId",iterationId,"sourceStageId",input.sourceStageId(),"targetStageId",input.targetStageId(), - "graphVersion",version+1,"affectedStageIds",plan.affected(),"itemMapping",new LinkedHashMap(), + "graphVersion",version+1,"affectedStageIds",plan.affected(),"aggregateStageIds",plan.aggregates(),"itemMapping",new LinkedHashMap(), "requestAdditionsJson",additionsJson(input),"sendEmail",Boolean.TRUE.equals(input.sendEmail())); long reworkId=revisions.insertRework(map("project_id",projectId,"iteration_id",iterationId,"source_stage_id",input.sourceStageId(),"target_stage_id",input.targetStageId(), "reason",input.reason().trim(),"idempotency_key",input.idempotencyKey(),"preview_graph_version",version, "impact_json","{}","created_by",actor,"created_at",at)); Map nextRevisions=new LinkedHashMap<>(); - for(Long stageId:plan.affected()) { + Set versioned=new LinkedHashSet<>(plan.affected()); versioned.addAll(plan.aggregates()); + // 必须先冻结旧父级组合,再切换任何子指针。并行保留分支继续执行后也不能改变旧父版本。 + for(Long stageId:versioned) if(PmStageHierarchyRules.info(before,stageId).group()) groups.freeze(before,stageId); + for(Long stageId:versioned) { var old=before.stageRevisions().get(stageId); Map stage=stages.selectActiveStage(stageId,projectId,iterationId); + boolean aggregate=plan.aggregates().contains(stageId); long next=revisions.insertRevision(map("project_id",projectId,"iteration_id",iterationId,"stage_id",stageId,"revision_no",old.revisionNo()+1, "rework_id",reworkId,"previous_revision_id",old.id(),"flow_definition_revision_id",null, - "stage_name_snapshot",text(stage,"name"),"stage_owner_snapshot",nullable(stage,"owner_id"),"created_by",actor,"created_at",at)); + "stage_name_snapshot",text(stage,"name"),"stage_owner_snapshot",nullable(stage,"owner_id"), + "stage_kind_snapshot",text(stage,"stage_kind"),"parent_stage_snapshot_id",nullable(stage,"parent_stage_id"),"stage_description_snapshot",text(stage,"description"), + "revision_reason",aggregate?"CHILD_REWORK":"REWORK","planned_start_at",aggregate?old.plannedStart():null,"planned_end_at",aggregate?old.plannedEnd():null,"plan_source",aggregate?old.planSource():null,"plan_recorded_at",aggregate?old.planRecordedAt():null, + "reference_planned_start_at",aggregate?old.referenceStart():old.plannedStart()==null?old.referenceStart():old.plannedStart(), + "reference_planned_end_at",aggregate?old.referenceEnd():old.plannedEnd()==null?old.referenceEnd():old.plannedEnd(), + "schedule_review_rework_id",aggregate?old.scheduleReviewReworkId():Long.valueOf(reworkId),"created_by",actor,"created_at",at)); nextRevisions.put(stageId,next); } Map mapped=new LinkedHashMap<>(); @@ -116,6 +129,7 @@ public class PmReworkServiceImpl implements IPmReworkService { long next=workItems.insertWorkItem(map("project_id",projectId,"iteration_id",iterationId,"type",old.type(),"title",old.title(),"description",old.description(), "assignee_id",old.assigneeId()!=null&&plan.members().contains(old.assigneeId())?old.assigneeId():null, "priority",old.priority(),"status","READY","planned_start_at",null,"planned_end_at",null,"actual_start_at",null,"actual_end_at",null, + "schedule_review_rework_id",reworkId,"reference_planned_start_at",old.start()==null?old.referenceStart():old.start(),"reference_planned_end_at",old.end()==null?old.referenceEnd():old.end(), "stage_id",old.stageId(),"stage_revision_id",nextRevisions.get(old.stageId()),"parent_task_id",parent, "origin_work_item_id",old.id(),"created_by",actor,"created_at",at)); mapped.put(old.id(),next); @@ -134,13 +148,14 @@ public class PmReworkServiceImpl implements IPmReworkService { dependencies.insertDependency(map("project_id",projectId,"iteration_id",iterationId,"successor_task_id",mapped.get(dependency.successorId()), "condition_type","WORK_ITEM_COMPLETED","predecessor_task_id",predecessor,"expected_status","COMPLETED","created_by",actor,"created_at",at)); } - for(Long stageId:plan.affected()) { + for(Long stageId:versioned) { long old=before.stageRevisions().get(stageId).id(); if(revisions.supersedeRevision(old,at)!=1||revisions.switchCurrentRevision(projectId,stageId,old,nextRevisions.get(stageId))!=1) throw PmException.conflict("GRAPH_VERSION_CONFLICT","阶段版本已变化,请重新预览"); } for(Long stageId:plan.reviewStages()) if(schedules.markStageReview(before.stageRevisions().get(stageId).id(),reworkId)!=1) throw PmException.conflict("VERSION_CONFLICT","阶段计划已变化"); for(Long itemId:plan.reviewItems()) if(revisions.markScheduleReview(itemId,reworkId)!=1) throw PmException.conflict("VERSION_CONFLICT","工作项计划已变化"); + groups.bind(projectId,iterationId); groups.sync(projectId,iterationId); Graph after=graphs.load(projectId,iterationId); for(Dependency dependency:after.dependencies()) if(!after.items().containsKey(dependency.taskId())) throw PmException.conflict("REWORK_DEPENDENCY_CONFLICT","当前工作项不能引用历史前置工作项"); PmRules.validateAcyclic(after); PmRules.validateSchedules(after,"Asia/Shanghai"); PmRules.validateActual(after,"Asia/Shanghai"); @@ -159,20 +174,30 @@ public class PmReworkServiceImpl implements IPmReworkService { return rows; } - /** 只读历史轮次及其中工作项;详情 ID 仍可打开评论、附件和原审计。 */ + /** 叶阶段保留原工作项详情;阶段组必须读取绑定子版本的冻结组合,不能用保留分支的实时详情替代历史。 */ public Map revision(long projectId,long iterationId,long stageId,long revisionId) { locked(projectId,iterationId,"read"); stage(projectId,iterationId,stageId); Map row=revisions.selectRevision(projectId,iterationId,stageId,revisionId); if(row==null) throw PmAccess.denied(); revisionTimes(row); - List> items=revisions.selectRevisionItems(revisionId); + boolean group="GROUP".equals(text(row,"stage_kind_snapshot")); + List> items=group?groups.versionItems(projectId,iterationId,stageId,revisionId):revisions.selectRevisionItems(revisionId); for(Map item:items) { + if(group) continue; item.put("plannedStartAt",PmTime.format(nullable(item,"planned_start_at"),"Asia/Shanghai")); item.put("plannedEndAt",PmTime.format(nullable(item,"planned_end_at"),"Asia/Shanghai")); item.put("actualStartAt",PmTime.format(nullable(item,"actual_start_at"),"Asia/Shanghai")); item.put("actualEndAt",PmTime.format(nullable(item,"actual_end_at"),"Asia/Shanghai")); item.put("historical",true); item.put("referencePlannedStartAt",PmTime.format(nullable(item,"reference_planned_start_at"),"Asia/Shanghai")); item.put("referencePlannedEndAt",PmTime.format(nullable(item,"reference_planned_end_at"),"Asia/Shanghai")); } - return map("revision",row,"items",items,"flowDefinition",definitionSnapshot(projectId,iterationId,row),"readOnly",true); + return map("revision",row,"items",items,"frozenSnapshot",group,"childStages",group?groups.versionStages(projectId,iterationId,stageId,revisionId):List.of(),"flowDefinition",definitionSnapshot(projectId,iterationId,row),"readOnly",true); + } + + /** 父级历史详情从指定组合的冻结内容读取,禁止用仍在执行的子项实时数据替代历史。 */ + public Map itemSnapshot(long projectId,long iterationId,long stageId,long revisionId,long itemId) { + locked(projectId,iterationId,"read"); stage(projectId,iterationId,stageId); + var revision=revisions.selectRevision(projectId,iterationId,stageId,revisionId); + if(revision==null||!"GROUP".equals(text(revision,"stage_kind_snapshot"))) throw PmAccess.denied(); + return groups.itemSnapshot(projectId,iterationId,stageId,revisionId,itemId); } /** 列表与详情统一输出版本自身的 ISO 时间,避免历史抽屉误用数据库微秒列或当前阶段计划。 */ @@ -240,6 +265,7 @@ public class PmReworkServiceImpl implements IPmReworkService { private Plan plan(long projectId,long iterationId,ReworkInput input,Graph graph) { if(input==null||input.sourceStageId()==null||input.targetStageId()==null) throw PmException.bad("来源和目标阶段不能为空"); long source=input.sourceStageId(),target=input.targetStageId(); stage(projectId,iterationId,source); stage(projectId,iterationId,target); + if(!Objects.equals(PmStageHierarchyRules.info(graph,source).parentId(),PmStageHierarchyRules.info(graph,target).parentId())) throw PmException.conflict("REWORK_SCOPE_INVALID","只能回退到同一画布的严格上游阶段"); List> sourceBlocked=PmStageRules.reworkBlocked(graph,source); if(!sourceBlocked.isEmpty()) throw new PmException(409,text(sourceBlocked.get(0),"code"),text(sourceBlocked.get(0),"message"),map("blockedReasons",sourceBlocked)); if(!PmStageRules.ancestors(graph,source).contains(target)) throw PmException.conflict("REWORK_TARGET_INVALID","只能回退到当前阶段的上游阶段,不能选择自身"); @@ -249,8 +275,12 @@ public class PmReworkServiceImpl implements IPmReworkService { boolean changed; do { changed=false; + for(Long id:List.copyOf(affected)) if(PmStageHierarchyRules.info(graph,id).group()) changed|=affected.addAll(PmStageHierarchyRules.subtree(graph,id)); + Set invalidated=new HashSet<>(affected); + for(Long id:affected) invalidated.addAll(PmStageHierarchyRules.parents(graph,id)); for(Long id:graph.stageNames().keySet()) if(!affected.contains(id)&&!"NOT_STARTED".equals(PmStageRules.executionStatus(graph,id)) - &&affected.stream().anyMatch(ancestor->sourceEqualsOrDescends(graph,ancestor,id))) changed|=affected.add(id); + &&invalidated.stream().anyMatch(ancestor->PmStageRules.ancestors(graph,id).contains(ancestor) + ||PmStageHierarchyRules.parents(graph,id).stream().anyMatch(parent->PmStageRules.ancestors(graph,parent).contains(ancestor)))) changed|=affected.add(id); for(Dependency dependency:graph.dependencies()) { Item predecessor=graph.items().get(dependency.taskId()),successor=graph.items().get(dependency.successorId()); if(predecessor==null||successor==null) { blockers.add(map("code","HISTORICAL_DEPENDENCY","message","当前依赖引用了历史或无效工作项","dependencyId",dependency.id())); continue; } @@ -272,27 +302,30 @@ public class PmReworkServiceImpl implements IPmReworkService { if(predecessor==null||predecessor.stageId()!=null&&affected.contains(predecessor.stageId())&&!copiedIds.contains(predecessor.id())) blockers.add(map("code","REWORK_DEPENDENCY_CONFLICT","dependencyId",dependency.id(),"message","前置工作项已取消或不属于当前版本,需要先处理依赖")); } - for(Long id:additions(input).keySet()) if(!affected.contains(id)) blockers.add(map("code","ADDITION_STAGE_INVALID","stageId",id,"message","补录工作项只能归入受影响阶段")); + for(Long id:additions(input).keySet()) if(!affected.contains(id)||PmStageHierarchyRules.info(graph,id).group()) blockers.add(map("code","ADDITION_STAGE_INVALID","stageId",id,"message","补录工作项只能归入受影响的工作阶段,阶段组不能直接放工作项")); for(var entry:additions(input).entrySet()) for(ReworkItemInput added:entry.getValue()) validateAddition(projectId,added); - for(Long id:affected) if(copies.stream().noneMatch(i->Objects.equals(i.stageId(),id))&&additions(input).getOrDefault(id,List.of()).isEmpty()) - blockers.add(map("code","REWORK_STAGE_EMPTY","stageId",id,"sourceName",graph.stageNames().get(id),"message","该阶段无可复制工作项,请至少补录一项")); + // 空版本仍是未执行且阻塞后继,允许先回退再补工作项,不能强制生成虚假任务。 + Set aggregates=new TreeSet<>(); + for(Long id:affected) aggregates.addAll(PmStageHierarchyRules.parents(graph,id)); + aggregates.removeAll(affected); Set members=new HashSet<>(); for(Map row:workspace.selectMembers(projectId)) members.add(number(row,"userId")); List> missingAssignees=copies.stream().filter(i->i.assigneeId()!=null&&!members.contains(i.assigneeId())) .map(i->map("taskId",i.id(),"taskName",i.title(),"assigneeId",i.assigneeId(),"message","负责人已不是项目成员,新版将不分配负责人")).toList(); List> missingCollaborators=new ArrayList<>(); for(Item item:copies)for(var collaborator:item.collaborators())if(!members.contains(collaborator.userId()))missingCollaborators.add(map("taskId",item.id(),"taskName",item.title(),"userId",collaborator.userId(),"name",collaborator.name(),"message","协作人已不是有效项目成员,新版不再关联,旧版本保留原分工")); - var review=com.ruoyi.project.manage.rule.PmScheduleReviewRules.affected(graph,affected); + var review=com.ruoyi.project.manage.rule.PmScheduleReviewRules.affected(graph,affected,aggregates); blockers.addAll(review.blockers()); - return new Plan(graph,List.copyOf(affected),copies,excluded,missingAssignees,missingCollaborators,blockers,review.stageIds(),review.itemIds(),members); + return new Plan(graph,List.copyOf(affected),List.copyOf(aggregates),copies,excluded,missingAssignees,missingCollaborators,blockers,review.stageIds(),review.itemIds(),members); } /** 预览完整解释版本替换、排期失效和不能提交的原因,不把警告当作成功。 */ private Map previewValue(long projectId,long iterationId,ReworkInput input,Plan plan,long graphVersion) { List> stages=plan.affected().stream().map(id->map("stageId",id,"name",plan.graph().stageNames().get(id), + "stageKind",PmStageHierarchyRules.info(plan.graph(),id).kind(),"stagePath",PmStageHierarchyRules.path(plan.graph(),id), "revisionNo",plan.graph().stageRevisions().get(id).revisionNo(),"copyCount",plan.copies().stream().filter(i->Objects.equals(i.stageId(),id)).count(), "additionalCount",additions(input).getOrDefault(id,List.of()).size())).toList(); return map("projectId",projectId,"iterationId",iterationId,"sourceStageId",input.sourceStageId(),"targetStageId",input.targetStageId(),"graphVersion",graphVersion, - "affectedStageIds",plan.affected(),"affectedStages",stages,"excludedItems",plan.excluded(),"missingAssignees",plan.missingAssignees(),"missingCollaborators",plan.missingCollaborators(), + "affectedStageIds",plan.affected(),"affectedStages",stages,"aggregateStageIds",plan.aggregates(),"excludedItems",plan.excluded(),"missingAssignees",plan.missingAssignees(),"missingCollaborators",plan.missingCollaborators(), "scheduleReviewStageIds",plan.reviewStages(),"scheduleReviewItemIds",plan.reviewItems(),"blockedReasons",plan.blockers(),"canCommit",plan.blockers().isEmpty(), "message","旧版工作项和历史保持只读,新版工作项重新开始且需要重新排期"); } diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmServiceImpl.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmServiceImpl.java index b00db41..60606ca 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmServiceImpl.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmServiceImpl.java @@ -59,9 +59,11 @@ public class PmServiceImpl implements IPmService { private final PmJson jsonCodec; private final com.ruoyi.project.manage.service.IPmScheduleService schedules; private final com.ruoyi.project.manage.service.support.PmAttachmentStorage attachmentStorage; + private final com.ruoyi.project.manage.service.support.PmGroupVersionService groups; /** 注入对象 Mapper、统一权限和事务支持,不允许 Controller 直接持有存储或实现。 */ - public PmServiceImpl(PmWorkspaceMapper workspaceMapper,PmWorkItemMapper workItemMapper,PmDependencyMapper dependencyMapper,PmStageMapper stageMapper,PmActivityMapper activityMapper,PmEventMapper eventMapper,PmRevisionMapper revisionMapper,PmUserMapper userMapper,PmGraphService graphService,PmAuditService auditService,PmAccess access,PmJson jsonCodec,PmIterationAccess iterationAccess,com.ruoyi.project.manage.service.IPmScheduleService schedules,PmParticipantService participants,com.ruoyi.project.manage.service.support.PmAttachmentStorage attachmentStorage) { + public PmServiceImpl(PmWorkspaceMapper workspaceMapper,PmWorkItemMapper workItemMapper,PmDependencyMapper dependencyMapper,PmStageMapper stageMapper,PmActivityMapper activityMapper,PmEventMapper eventMapper,PmRevisionMapper revisionMapper,PmUserMapper userMapper,PmGraphService graphService,PmAuditService auditService,PmAccess access,PmJson jsonCodec,PmIterationAccess iterationAccess,com.ruoyi.project.manage.service.IPmScheduleService schedules,PmParticipantService participants,com.ruoyi.project.manage.service.support.PmAttachmentStorage attachmentStorage,com.ruoyi.project.manage.service.support.PmGroupVersionService groups) { + this.groups=groups; this.attachmentStorage=attachmentStorage; this.participants=participants; this.schedules=schedules; @@ -229,6 +231,7 @@ public class PmServiceImpl implements IPmService { /** 普通编辑原子更新分工、字段及本次通知选择;省略协作人则保留,邮件选择省略则不发。 */ public void edit(long id,ItemInput input) { long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"write"); Graph graph=graphService.load(projectId,iterationId); Item existing=writableItem(graph,id); version(input.version(),existing.version()); validateFields(projectId,iterationId,input); requireStageMutable(graph,input.stageId()); + if(!Objects.equals(existing.stageId(),input.stageId())) throw PmException.bad("请通过项目管理者的阶段归属入口移动工作项"); if(input.predecessorWorkItemIds()!=null) throw PmException.bad("编辑前置条件请使用依赖管理入口"); List collaboratorIds=participants.validate(projectId,input.collaboratorIds()); if(!existing.type().equals(input.type())) throw PmException.bad("工作项类型创建后不可直接变更"); @@ -248,12 +251,15 @@ public class PmServiceImpl implements IPmService { /** * 所有阶段调整共用父子继承校验,版本、归属和历史在同一项目锁事务中提交。 + * 仅项目管理者可以移动待开始项,普通编辑不能清空阶段来绕过执行门禁。 * @param id 当前有效工作项 ID;子任务不能脱离父阶段 * @param input 目标同项目阶段及工作项版本,null 阶段代表未分配 * 注意:先校验父子整体排期是否落在目标阶段内,再同步版本和审计;相同阶段不重复更新。 */ public void assignStage(long id,StageAssignment input) { long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"write"); Graph graph=graphService.load(projectId,iterationId); Item existing=writableItem(graph,id); version(input.version(),existing.version()); + access.project(projectId,"admin"); + if(!"READY".equals(existing.status())) throw PmException.conflict("ITEM_STAGE_LOCKED","只有待开始工作项可以调整阶段"); if(input.stageId()!=null&&stageMapper.selectActiveStageId(input.stageId(),projectId,iterationId)==null) throw PmAccess.denied(); requireStageMutable(graph,input.stageId()); validateInheritedStage(graph,existing,input.stageId()); if(Objects.equals(existing.stageId(),input.stageId())) return; Graph before=graph.copy(); simulateStage(graph,existing,input.stageId()); @@ -513,7 +519,7 @@ public class PmServiceImpl implements IPmService { (keyword.isEmpty()||text(row,"title").toLowerCase(Locale.ROOT).contains(keyword)) &&(query.type()==null||query.type().isBlank()||query.type().equals(row.get("type"))) &&(!Boolean.TRUE.equals(query.blockedOnly())||Boolean.TRUE.equals(row.get("dependencyBlocked"))) - &&(query.stageId()==null||(query.stageId()==0?row.get("stageId")==null:query.stageId().equals(nullable(row,"stageId")))) + &&(query.stageId()==null||(query.stageId()==0?row.get("stageId")==null:query.stageId().equals(nullable(row,"stageId"))||query.stageId().equals(nullable(row,"stageGroupId")))) &&matchesMembers(row,memberIds) &&(!"gantt".equals(mode)||overlaps(row,from,to))).toList(); Map counts=new LinkedHashMap<>(); @@ -605,6 +611,8 @@ public class PmServiceImpl implements IPmService { private Map view(Graph graph,Item item,String zone,boolean writable) { Map response=map("id",item.id(),"projectId",item.projectId(),"type",item.type(),"title",item.title(),"description",item.description(),"assigneeId",item.assigneeId(),"priority",item.priority(),"status",item.status(),"version",item.version(),"timezone",zone,"plannedStartAt",PmTime.format(item.start(),zone),"plannedEndAt",PmTime.format(item.end(),zone),"actualStartAt",PmTime.format(item.actualStart(),zone),"actualEndAt",PmTime.format(item.actualEnd(),zone)); response.put("collaboratorIds",item.collaborators().stream().map(c->c.userId()).toList()); + response.put("stagePath",item.stageId()==null?"未分配":com.ruoyi.project.manage.rule.PmStageHierarchyRules.path(graph,item.stageId())); + response.put("stageGroupId",item.stageId()==null?null:com.ruoyi.project.manage.rule.PmStageHierarchyRules.info(graph,item.stageId()).parentId()); response.put("collaborators",item.collaborators()); boolean mutable=graph.iteration()!=null&&graph.iteration().mutable(); response.putAll(map("iterationId",graph.iteration()==null?null:graph.iteration().id(),"iterationStatus",graph.iteration()==null?null:graph.iteration().status(),"iterationReadOnly",!mutable)); @@ -657,6 +665,7 @@ public class PmServiceImpl implements IPmService { /** 已完成或迁移放行阶段不可增减和改写工作项,重做必须走经理回退入口。 */ private static void requireStageMutable(Graph graph,Long stageId) { if(stageId==null) return; + if(com.ruoyi.project.manage.rule.PmStageHierarchyRules.info(graph,stageId).group()) throw PmException.bad("阶段组承载子阶段,请选择具体工作阶段"); String status=PmStageRules.executionStatus(graph,stageId); if(Set.of("COMPLETED","LEGACY_PASSED").contains(status)) throw PmException.conflict("STAGE_REVISION_FROZEN","阶段已完成,需由项目经理创建回退版本后重做"); } @@ -678,7 +687,8 @@ public class PmServiceImpl implements IPmService { private void syncStage(long projectId,long iterationId,Long stageId,String previousStatus) { if(stageId==null) return; Graph after=graphService.load(projectId,iterationId); String status=PmStageRules.executionStatus(after,stageId); - if(status.equals(previousStatus)) return; + if(com.ruoyi.project.manage.rule.PmStageHierarchyRules.info(after,stageId).group()) { groups.sync(projectId,iterationId); return; } + if(status.equals(previousStatus)) { groups.sync(projectId,iterationId); return; } var revision=after.stageRevisions().get(stageId); if(revision==null) return; Long now=PmTime.now(); revisionMapper.updateRevisionState(revision.id(),"IN_PROGRESS".equals(status)||"COMPLETED".equals(status)?now:null,"COMPLETED".equals(status)?now:null); @@ -692,6 +702,7 @@ public class PmServiceImpl implements IPmService { } else revisionMapper.bindStartedDefinition(revision.id(),number(latest,"id")); } auditService.record(projectId,iterationId,null,"STAGE_STATUS_CHANGED",map("stageId",stageId,"from",previousStatus,"to",status,"revisionId",revision.id()),access.actor()); + groups.sync(projectId,iterationId); } /** 仅取路由所需项目 ID,所有标题和业务内容在项目鉴权之后加载。 */ diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmStageServiceImpl.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmStageServiceImpl.java index 82b9780..27946fd 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmStageServiceImpl.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/impl/PmStageServiceImpl.java @@ -43,9 +43,11 @@ public class PmStageServiceImpl implements IPmStageService { private final PmAccess access; private final PmIterationAccess iterationAccess; private final IPmService business; + private final com.ruoyi.project.manage.service.support.PmGroupVersionService groups; /** 注入当前阶段业务需要的 Mapper 和规则,浏览器布局不再依赖数据库 Mapper。 */ - public PmStageServiceImpl(PmWorkspaceMapper workspaceMapper,PmWorkItemMapper workItemMapper,PmStageMapper stageMapper,PmRevisionMapper revisionMapper,PmGraphService graphService,PmAuditService auditService,PmJson jsonCodec,PmAccess access,IPmService business,PmIterationAccess iterationAccess,com.ruoyi.project.manage.mapper.PmScheduleMapper schedules) { + public PmStageServiceImpl(PmWorkspaceMapper workspaceMapper,PmWorkItemMapper workItemMapper,PmStageMapper stageMapper,PmRevisionMapper revisionMapper,PmGraphService graphService,PmAuditService auditService,PmJson jsonCodec,PmAccess access,IPmService business,PmIterationAccess iterationAccess,com.ruoyi.project.manage.mapper.PmScheduleMapper schedules,com.ruoyi.project.manage.service.support.PmGroupVersionService groups) { + this.groups=groups; this.schedules=schedules; this.iterationAccess=iterationAccess; this.workspaceMapper=workspaceMapper; @@ -77,12 +79,17 @@ public class PmStageServiceImpl implements IPmStageService { try { access.project(projectId,"admin"); } catch(PmException error) { if(error.getHttpStatus()!=403) throw error; canManage=false; } } + boolean canWrite=graph.iteration()!=null&&graph.iteration().mutable()&&access.canWrite(projectId); for(Map stage:stages) { - long stageId=number(stage,"id"); stage.putAll(summary(items,stageId)); + long stageId=number(stage,"id"); stage.putAll(summary(items,stageId,graph)); String executionStatus=PmStageRules.executionStatus(graph,stageId); stage.put("executionStatus",executionStatus); stage.putAll(com.ruoyi.project.manage.rule.PmStageScheduleRules.summary(graph,stageId)); stage.put("complete","COMPLETED".equals(executionStatus)); + var children=com.ruoyi.project.manage.rule.PmStageHierarchyRules.children(graph,stageId); + boolean group=com.ruoyi.project.manage.rule.PmStageHierarchyRules.info(graph,stageId).group(); + boolean topologyMutable=canManage&&"NOT_STARTED".equals(executionStatus)&&!flag(stage,"executionHistory"); + stage.putAll(map("childStageCount",children.size(),"completedChildStageCount",children.stream().filter(child->Set.of("COMPLETED","LEGACY_PASSED").contains(PmStageRules.executionStatus(graph,child))).count(),"stagePath",com.ruoyi.project.manage.rule.PmStageHierarchyRules.path(graph,stageId),"canCreateWorkItem",canWrite&&!group&&!Set.of("COMPLETED","LEGACY_PASSED").contains(executionStatus),"canCreateChildStage",topologyMutable&&group,"canEditStructure",topologyMutable)); stage.put("blockedReasons",PmStageRules.blockedStage(graph,stageId)); List> reworkBlocked=PmStageRules.reworkBlocked(graph,stageId); stage.put("isCurrent",PmStageRules.isCurrent(graph,stageId)); @@ -95,16 +102,29 @@ public class PmStageServiceImpl implements IPmStageService { }).toList(); List> reworkEdges=schedules.selectReworkEdges(projectId,iterationId); for(Map edge:reworkEdges) edge.put("latestReworkAt",PmTime.format(nullable(edge,"latestReworkAt"),"Asia/Shanghai")); - return map("reworkEdges",reworkEdges,"iterationId",iterationId,"graphVersion",number(revisionMapper.selectGraphVersion(projectId,iterationId),"graph_version"),"stages",stages,"stageEdges",stageEdges,"unassigned",summary(items,null),"items",List.of(),"dependencies",List.of()); + return map("reworkEdges",reworkEdges,"iterationId",iterationId,"graphVersion",number(revisionMapper.selectGraphVersion(projectId,iterationId),"graph_version"),"stages",stages,"stageEdges",stageEdges,"unassigned",summary(items,null,graph),"items",List.of(),"dependencies",List.of()); } - /** 阶段经理维护入口;名称和展示顺序不隐式产生连线,执行顺序只由显式边决定。 */ + /** 创建空阶段时原子保存首版计划和父级组合;手工创建必须填写日期,系统换版使用独立内部入口。 */ public long createStage(long projectId,long iterationId,StageInput input) { locked(projectId,iterationId,"admin"); validateStage(projectId,input); + String kind=input.stageKind()==null?"WORK":input.stageKind(); + if(!Set.of("WORK","GROUP").contains(kind)) throw PmException.bad("阶段类型无效"); + if("GROUP".equals(kind)&&input.parentStageId()!=null) throw PmException.conflict("STAGE_HIERARCHY_INVALID","阶段组只能创建在根画布,不支持第三层阶段"); + var plan=PmTime.planned(input.plannedStartAt(),input.plannedEndAt()); + if(plan.start()==null||plan.end()==null||plan.end() existing=stage(projectId,iterationId,id); version(input.version(),(int)number(existing,"version")); validateStage(projectId,input); - stageMapper.updateStage(id,(int)number(existing,"version"),map("name",input.name().trim(),"sort_order",input.sortOrder()==null?0:input.sortOrder(),"owner_id",input.ownerId(),"description",input.description())); - snapshotDefinition(projectId,iterationId); + Graph before=graphService.load(projectId,iterationId),after=before.copy(); + String kind=input.stageKind()==null?text(existing,"stage_kind"):input.stageKind(); + if(!Set.of("WORK","GROUP").contains(kind)) throw PmException.bad("阶段类型无效"); + if(input.parentStageId()!=null&&!Objects.equals(input.parentStageId(),nullable(existing,"parent_stage_id"))) throw PmException.bad("请使用结构调整入口修改父级"); + if(!kind.equals(text(existing,"stage_kind"))&&(workItemMapper.selectItemInStage(projectId,id)!=null||!com.ruoyi.project.manage.rule.PmStageHierarchyRules.children(before,id).isEmpty()||!"NOT_STARTED".equals(PmStageRules.executionStatus(before,id)))) throw PmException.conflict("STAGE_KIND_LOCKED","仅未执行的空阶段可以转换类型"); + if(!kind.equals(text(existing,"stage_kind"))&&revisionMapper.selectStageRevisions(projectId,iterationId,id).stream().anyMatch(row->nullable(row,"started_at")!=null)) throw PmException.conflict("STAGE_KIND_LOCKED","曾执行的阶段不能转换类型"); + if(input.plannedStartAt()!=null||input.plannedEndAt()!=null) throw PmException.bad("阶段改期请使用版本排期入口"); + after.hierarchy().put(id,new com.ruoyi.project.manage.domain.StageInfo(id,kind,nullable(existing,"parent_stage_id"),input.description())); + PmRules.validateAcyclic(after); PmStageRules.validateExecutedAncestors(before,after); + stageMapper.updateStage(id,(int)number(existing,"version"),map("stage_kind",kind,"name",input.name().trim(),"sort_order",input.sortOrder()==null?0:input.sortOrder(),"owner_id",input.ownerId(),"description",input.description())); + stageMapper.refreshDraftRevisionIdentity(number(existing,"current_revision_id"),kind,nullable(existing,"parent_stage_id"),input.description()); + groups.bind(projectId,iterationId); snapshotDefinition(projectId,iterationId); auditService.record(projectId,iterationId,null,"STAGE_EDITED",map("stageId",id,"name",input.name().trim()),access.actor()); } /** 非空阶段拒绝删除;空阶段的连线先移除,再软删阶段并原子保存历史与事件。 */ public void deleteStage(long projectId,long iterationId,long id,VersionInput input) { locked(projectId,iterationId,"admin"); Map existing=stage(projectId,iterationId,id); version(input.version(),(int)number(existing,"version")); + if(!com.ruoyi.project.manage.rule.PmStageHierarchyRules.children(graphService.load(projectId,iterationId),id).isEmpty()) throw PmException.conflict("STAGE_NOT_EMPTY","阶段组仍有子阶段,不能删除"); if(workItemMapper.selectItemInStage(projectId,id)!=null) throw PmException.conflict("STAGE_NOT_EMPTY","阶段仍有未删除工作项,请先调整这些工作项的阶段"); Graph before=graphService.load(projectId,iterationId),after=before.copy(); - after.stageNames().remove(id); after.stageLinks().removeIf(link->link.predecessorStageId()==id||link.successorStageId()==id); + requireNoExecutionHistory(projectId,iterationId,id); + Long parent=com.ruoyi.project.manage.rule.PmStageHierarchyRules.info(before,id).parentId(); + if(parent!=null) requireNoExecutionHistory(projectId,iterationId,parent); + after.stageNames().remove(id); after.hierarchy().remove(id); after.stageLinks().removeIf(link->link.predecessorStageId()==id||link.successorStageId()==id); PmStageRules.validateExecutedAncestors(before,after); stageMapper.deleteEdgesForStage(projectId,id); stageMapper.updateStage(id,(int)number(existing,"version"),map("deleted",true)); + groups.bind(projectId,iterationId); snapshotDefinition(projectId,iterationId); auditService.record(projectId,iterationId,null,"STAGE_DELETED",map("stageId",id,"name",text(existing,"name")),access.actor()); } @@ -169,6 +204,48 @@ public class PmStageServiceImpl implements IPmStageService { business.assignStage(id,input); } + /** 预览/提交明确的结构最终态;只迁移未执行阶段,全部边由管理者明确提供,不自动重写跨层语义。 */ + public Map structure(long projectId,long iterationId,com.ruoyi.project.manage.dto.StageStructureInput input,boolean commit) { + locked(projectId,iterationId,"read"); access.project(projectId,"admin"); iterationAccess.require(projectId,iterationId,"admin"); + long graphVersion=number(revisionMapper.selectGraphVersion(projectId,iterationId),"graph_version"); + if(input==null||input.graphVersion()==null||input.graphVersion()!=graphVersion) throw PmException.conflict("GRAPH_VERSION_CONFLICT","流程已变化,请刷新结构后重新预览"); + if(input.stages()==null||input.edges()==null||input.stages().size()>200||input.edges().size()>1000) throw PmException.bad("请提交阶段移动和完整连线列表"); + Graph before=graphService.load(projectId,iterationId),after=before.copy(); Set seen=new HashSet<>(); + for(var move:input.stages()) { + if(move==null||!seen.add(move.id())) throw PmException.bad("阶段移动为空或重复"); + Map row=stage(projectId,iterationId,move.id()); version(move.version(),(int)number(row,"version")); + if(!"NOT_STARTED".equals(PmStageRules.executionStatus(before,move.id()))||revisionMapper.selectStageRevisions(projectId,iterationId,move.id()).stream().anyMatch(r->nullable(r,"started_at")!=null)) throw PmException.conflict("STAGE_TOPOLOGY_LOCKED","已有执行历史的阶段不能迁移层级"); + if(move.parentStageId()!=null) stage(projectId,iterationId,move.parentStageId()); + var old=com.ruoyi.project.manage.rule.PmStageHierarchyRules.info(before,move.id()); + if(old.parentId()!=null) requireNoExecutionHistory(projectId,iterationId,old.parentId()); + if(move.parentStageId()!=null) requireNoExecutionHistory(projectId,iterationId,move.parentStageId()); + after.hierarchy().put(move.id(),new com.ruoyi.project.manage.domain.StageInfo(move.id(),old.kind(),move.parentStageId(),old.description())); + } + after.stageLinks().clear(); Set edges=new HashSet<>(); long temporary=-1; + for(var edge:input.edges()) { + if(edge==null||edge.predecessorStageId()==null||edge.successorStageId()==null||edge.predecessorStageId().equals(edge.successorStageId())||!edges.add(edge.predecessorStageId()+":"+edge.successorStageId())) throw PmException.bad("执行边无效或重复"); + after.stageLinks().add(new StageLink(temporary--,projectId,edge.predecessorStageId(),edge.successorStageId(),0)); + } + PmRules.validateAcyclic(after); PmRules.validateSchedules(after,"Asia/Shanghai"); PmStageRules.validateRegression(before,after); PmStageRules.validateExecutedAncestors(before,after); + if(commit) { + for(var move:input.stages()) { + stageMapper.updateStage(move.id(),move.version(),map("parent_stage_id",move.parentStageId())); + var info=after.hierarchy().get(move.id()); + stageMapper.refreshDraftRevisionIdentity(after.stageRevisions().get(move.id()).id(),info.kind(),info.parentId(),info.description()); + } + stageMapper.deleteIterationEdges(projectId,iterationId); + for(StageLink edge:after.stageLinks()) stageMapper.insertStageEdge(map("project_id",projectId,"iteration_id",iterationId,"predecessor_stage_id",edge.predecessorStageId(),"successor_stage_id",edge.successorStageId(),"created_by",access.actor(),"created_at",PmTime.now())); + groups.bind(projectId,iterationId); revisionMapper.advanceGraphVersion(projectId,iterationId); snapshotDefinition(projectId,iterationId); + auditService.record(projectId,iterationId,null,"STAGE_STRUCTURE_CHANGED",map("moves",input.stages(),"edges",input.edges()),access.actor()); + } + return map("canCommit",true,"graphVersion",graphVersion,"moves",input.stages(),"edges",input.edges(),"committed",commit); + } + + /** 回退产生待开始新版本也不能解冻已有的阶段组结构,避免换版后绕过旧执行事实。 */ + private void requireNoExecutionHistory(long projectId,long iterationId,long stageId) { + if(revisionMapper.selectStageRevisions(projectId,iterationId,stageId).stream().anyMatch(row->nullable(row,"started_at")!=null||nullable(row,"legacy_passed_at")!=null)) throw PmException.conflict("STAGE_TOPOLOGY_LOCKED","曾执行的阶段及阶段组不能调整层级或增减子阶段"); + } + /** 读取阶段元数据和负责人昵称,时间统一为带偏移 ISO;调用方已取得项目锁并校验数据权限。 */ private List> stageRows(long projectId,long iterationId) { List> rows=stageMapper.selectVisibleStages(projectId,iterationId); @@ -177,8 +254,9 @@ public class PmStageServiceImpl implements IPmStageService { } /** 按全部有效工作项汇总,不受画布筛选影响;取消不计入完成,时间覆盖单独返回。 */ - private Map summary(List> items,Long stageId) { - List> group=items.stream().filter(i->Objects.equals(nullable(i,"stageId"),stageId)).toList(); + private Map summary(List> items,Long stageId,Graph graph) { + Set scope=stageId==null?Set.of():com.ruoyi.project.manage.rule.PmStageHierarchyRules.subtree(graph,stageId); + List> group=items.stream().filter(i->stageId==null?nullable(i,"stageId")==null:scope.contains(nullable(i,"stageId"))).toList(); Map counts=map("total",group.size()); for(String state:List.of("READY","IN_PROGRESS","COMPLETED","CANCELLED","CLOSED")) counts.put(state,group.stream().filter(i->state.equals(i.get("status"))).count()); counts.put("overdue",group.stream().filter(i->Boolean.TRUE.equals(i.get("overdue"))).count()); @@ -196,6 +274,7 @@ public class PmStageServiceImpl implements IPmStageService { /** 校验阶段引用、负责人及大小限制;同项目软删除检查不能仅依赖物理外键。 */ private void validateStage(long projectId,StageInput input) { + if(input==null) throw PmException.bad("阶段内容不能为空"); if(input.name()==null||input.name().isBlank()||input.name().trim().length()>120) throw PmException.bad("阶段名称需为 1—120 个字符"); if(input.description()!=null&&input.description().length()>10000) throw PmException.bad("阶段描述过长"); if(input.sortOrder()!=null&&(input.sortOrder()<0||input.sortOrder()>100000)) throw PmException.bad("阶段顺序需在 0—100000 之间"); diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/support/PmGraphService.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/support/PmGraphService.java index e1b2818..fe34ccb 100644 --- a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/support/PmGraphService.java +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/support/PmGraphService.java @@ -26,8 +26,9 @@ public class PmGraphService { private final PmRevisionMapper revisionMapper; private final PmIterationMapper iterationMapper; private final PmParticipantService participants; + private final com.ruoyi.project.manage.mapper.PmGroupMapper groupMapper; /** 注入只负责数据库访问的 Mapper,不在加载过程中触发业务写入。 */ - public PmGraphService(PmWorkItemMapper workItemMapper,PmDependencyMapper dependencyMapper,PmStageMapper stageMapper,PmRevisionMapper revisionMapper,PmIterationMapper iterationMapper,PmParticipantService participants) { this.workItemMapper=workItemMapper; this.dependencyMapper=dependencyMapper; this.stageMapper=stageMapper; this.revisionMapper=revisionMapper; this.iterationMapper=iterationMapper; this.participants=participants; } + public PmGraphService(PmWorkItemMapper workItemMapper,PmDependencyMapper dependencyMapper,PmStageMapper stageMapper,PmRevisionMapper revisionMapper,PmIterationMapper iterationMapper,PmParticipantService participants,com.ruoyi.project.manage.mapper.PmGroupMapper groupMapper) { this.groupMapper=groupMapper; this.workItemMapper=workItemMapper; this.dependencyMapper=dependencyMapper; this.stageMapper=stageMapper; this.revisionMapper=revisionMapper; this.iterationMapper=iterationMapper; this.participants=participants; } /** 旧项目图入口拒绝隐式选取迭代,内部调用也不能意外加载多个迭代的任务。 */ public Graph load(long projectId) { throw new PmException(400,"ITERATION_REQUIRED","请明确选择迭代",Map.of()); } /** @@ -49,8 +50,11 @@ public class PmGraphService { // 两种条件标识表达同一工作项完成规则;历史任务条件与新增统一条件必须一起参与图校验。 List dependencies=new ArrayList<>(); for(Map r:dependencyMapper.selectGraphDependencies(projectId,iterationId)) dependencies.add(new Dependency(number(r,"id"),projectId,number(r,"successor_task_id"),text(r,"condition_type"),nullable(r,"predecessor_task_id"),text(r,"expected_status"),(int)number(r,"version"))); - Map names=new LinkedHashMap<>(); - for(Map row:stageMapper.selectVisibleStages(projectId,iterationId)) names.put(number(row,"id"),text(row,"name")); + Map names=new LinkedHashMap<>(); Map hierarchy=new LinkedHashMap<>(); + for(Map row:stageMapper.selectVisibleStages(projectId,iterationId)) { + long id=number(row,"id"); names.put(id,text(row,"name")); + hierarchy.put(id,new com.ruoyi.project.manage.domain.StageInfo(id,text(row,"stageKind"),nullable(row,"parentStageId"),text(row,"description"))); + } List links=new ArrayList<>(); for(Map row:stageMapper.selectStageEdges(projectId,iterationId)) links.add(new StageLink(number(row,"id"),projectId,number(row,"predecessor_stage_id"),number(row,"successor_stage_id"),(int)number(row,"version"))); Map revisions=new LinkedHashMap<>(); @@ -58,7 +62,16 @@ public class PmGraphService { StageRevision revision=revision(row); revisions.put(revision.stageId(),revision); } - return new Graph(items,dependencies,names,links,revisions,new IterationScope(iterationId,projectId,text(iteration,"status"),nullable(iteration,"archived_at")!=null)); + Graph graph=new Graph(items,dependencies,names,links,revisions,new IterationScope(iterationId,projectId,text(iteration,"status"),nullable(iteration,"archived_at")!=null),hierarchy); + com.ruoyi.project.manage.rule.PmStageHierarchyRules.validate(graph); + // 父级必须引用精确的当前子版本。禁止读时自动修复,否则历史组合错误会被悄悄覆盖。 + for(var entry:hierarchy.entrySet()) if(entry.getValue().group()) { + Map expected=new TreeMap<>(),actual=new TreeMap<>(); + for(Long child:com.ruoyi.project.manage.rule.PmStageHierarchyRules.children(graph,entry.getKey())) expected.put(child,revisions.get(child).id()); + for(var member:groupMapper.selectMembers(revisions.get(entry.getKey()).id())) actual.put(number(member,"child_stage_id"),number(member,"child_revision_id")); + if(!expected.equals(actual)) throw new IllegalStateException("阶段组当前子版本组合不一致"); + } + return graph; } /** 当前与历史版本使用相同字段解码,但历史不会被加入当前依赖图。 */ public static StageRevision revision(Map row) { return new StageRevision(number(row,"id"),number(row,"stage_id"),(int)number(row,"revision_no"),nullable(row,"started_at"),nullable(row,"completed_at"),nullable(row,"legacy_passed_at"),nullable(row,"planned_start_at"),nullable(row,"planned_end_at"),nullable(row,"reference_planned_start_at"),nullable(row,"reference_planned_end_at"),nullable(row,"schedule_review_rework_id"),text(row,"plan_source"),nullable(row,"plan_recorded_at"),(int)number(row,"version")); } diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/support/PmGroupVersionService.java b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/support/PmGroupVersionService.java new file mode 100644 index 0000000..83a8bc2 --- /dev/null +++ b/ruoyi-project/src/main/java/com/ruoyi/project/manage/service/support/PmGroupVersionService.java @@ -0,0 +1,153 @@ +package com.ruoyi.project.manage.service.support; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.ruoyi.project.manage.domain.*; +import com.ruoyi.project.manage.mapper.*; +import com.ruoyi.project.manage.rule.*; +import com.ruoyi.project.manage.exception.PmException; +import com.ruoyi.project.manage.security.PmAccess; +import com.ruoyi.project.manage.util.*; +import java.util.*; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.*; +import static com.ruoyi.project.manage.util.PmValues.*; + +/** 阶段组汇总版本不复制无关分支;冻结旧视图时保存实际内容,避免引用仍可变化的子执行版本。 */ +@Service +@Transactional(propagation=Propagation.MANDATORY) +public class PmGroupVersionService { + private final PmGroupMapper mapper; + private final PmStageMapper stages; + private final PmRevisionMapper revisions; + private final PmActivityMapper activities; + private final PmGraphService graphs; + private final PmJson json; + private final ObjectMapper decoder; + private final PmAuditService audit; + private final PmAccess access; + /** 只在调用方已持项目图锁时使用,不创建独立事务或读取用户提交的快照。 */ + public PmGroupVersionService(PmGroupMapper mapper,PmStageMapper stages,PmRevisionMapper revisions,PmActivityMapper activities,PmGraphService graphs,PmJson json,ObjectMapper decoder,PmAuditService audit,PmAccess access) { + this.audit=audit;this.access=access; + this.mapper=mapper;this.stages=stages;this.revisions=revisions;this.activities=activities;this.graphs=graphs;this.json=json;this.decoder=decoder; + } + + /** 结构创建或换版后原子绑定当前子版本;冻结成员不允许被普通结构编辑替换。 */ + public void bind(long projectId,long iterationId) { + List> rows=stages.selectVisibleStages(projectId,iterationId); + for(Map group:rows) if("GROUP".equals(text(group,"stageKind"))) { + long id=number(group,"id"),revision=number(group,"currentRevisionId"); + var expected=new TreeMap(); + for(Map child:rows) if(Objects.equals(nullable(child,"parentStageId"),id)) expected.put(number(child,"id"),number(child,"currentRevisionId")); + List> members=mapper.selectMembers(revision); + var actual=new TreeMap();for(var member:members)actual.put(number(member,"child_stage_id"),number(member,"child_revision_id")); + if(expected.equals(actual)) continue; + if(members.stream().anyMatch(m->nullable(m,"frozen_at")!=null)) throw PmException.conflict("STAGE_REVISION_FROZEN","已冻结的阶段组结构不能改写"); + mapper.deleteDraftMembers(revision); + expected.forEach((child,childRevision)->mapper.bindMember(projectId,iterationId,id,revision,child,childRevision)); + } + } + + /** 子阶段状态改变后按当前组合汇总父级实际时间;完成时冻结该组合的全部可读内容。 */ + public void sync(long projectId,long iterationId) { + Graph graph=graphs.load(projectId,iterationId); + for(Long id:graph.stageNames().keySet()) if(PmStageHierarchyRules.info(graph,id).group()) { + StageRevision old=graph.stageRevisions().get(id); Long first=null,last=null; + for(Long child:PmStageHierarchyRules.children(graph,id)) { + StageRevision r=graph.stageRevisions().get(child); + if(r.startedAt()!=null)first=first==null?r.startedAt():Math.min(first,r.startedAt()); + if(r.completedAt()!=null)last=last==null?r.completedAt():Math.max(last,r.completedAt()); + } + if(!"COMPLETED".equals(PmStageRules.executionStatus(graph,id)))last=null; + if(!Objects.equals(first,old.startedAt())||!Objects.equals(last,old.completedAt())) { + if(first!=null&&old.startedAt()==null) { + var stage=stages.selectActiveStage(id,projectId,iterationId); + revisions.refreshStartedIdentity(old.id(),text(stage,"name"),nullable(stage,"owner_id")); + var definition=revisions.selectLatestDefinition(projectId,iterationId); + if(definition!=null)revisions.bindStartedDefinition(old.id(),number(definition,"id")); + } + mapper.updateGroupState(old.id(),first,last); + String previous=old.completedAt()!=null?"COMPLETED":old.startedAt()!=null?"IN_PROGRESS":"NOT_STARTED"; + audit.record(projectId,iterationId,null,"STAGE_STATUS_CHANGED",map("stageId",id,"from",previous,"to",PmStageRules.executionStatus(graph,id),"revisionId",old.id(),"aggregate",true),access.actor()); + } + if(last!=null)freeze(graph,id); + } + } + + /** 在任何子指针改变前冻结父版本;保留分支日后继续执行时,旧父版本不会读取到未来数据。 */ + public void freeze(Graph before,long groupId) { + StageRevision parent=before.stageRevisions().get(groupId); if(parent==null)return; + Map owners=ownerNames(before); + for(Map member:mapper.selectMembers(parent.id())) if(nullable(member,"frozen_at")==null) { + long child=number(member,"child_stage_id"); + if(before.stageRevisions().get(child).id()!=number(member,"child_revision_id"))throw new IllegalStateException("父子阶段版本组合不一致"); + mapper.freezeMember(number(member,"id"),json.encode(snapshot(before,child,owners)),PmTime.now()); + } + } + + /** 以明确父版本读取组合;当前组合可实时构造,缺失的历史冻结数据不能用当前状态补造。 */ + private List> versionSnapshots(long projectId,long iterationId,long groupId,long revisionId) { + Map revision=revisions.selectRevision(projectId,iterationId,groupId,revisionId); if(revision==null)throw PmAccess.denied(); + Graph current=null;Map owners=null;List> result=new ArrayList<>(); + for(var member:mapper.selectMembers(revisionId)) { + Map saved; + if(text(member,"snapshot_json")!=null) { + if(number(member,"snapshot_format_version")!=1)throw new IllegalStateException("不支持的阶段组历史快照格式"); + saved=decode(text(member,"snapshot_json")); + } + else { + if(nullable(revision,"superseded_at")!=null)throw new IllegalStateException("历史阶段组缺少冻结快照"); + if(current==null) {current=graphs.load(projectId,iterationId);owners=ownerNames(current);} + if(current.stageRevisions().get(number(member,"child_stage_id")).id()!=number(member,"child_revision_id"))throw new IllegalStateException("阶段组实时成员版本不一致"); + saved=snapshot(current,number(member,"child_stage_id"),owners); + } + saved.put("snapshotFrozen",nullable(member,"frozen_at")!=null);result.add(saved); + } + return result; + } + + /** 父级列表按工作项去重展开精确子版本组合,冻结标记供界面区分历史与当前只读查询。 */ + public List> versionItems(long projectId,long iterationId,long groupId,long revisionId) { + Map> items=new LinkedHashMap<>(); + for(var snapshot:versionSnapshots(projectId,iterationId,groupId,revisionId))for(Object item:(List)snapshot.get("items")) { + var row=stringMap((Map)item);row.put("snapshotFrozen",snapshot.get("snapshotFrozen"));items.put(number(row,"id"),row); + } + return List.copyOf(items.values()); + } + + /** 子阶段版本和计划取当时快照,返回计数而非重复携带整份工作项列表。 */ + public List> versionStages(long projectId,long iterationId,long groupId,long revisionId) { + List> rows=new ArrayList<>(); + for(var snapshot:versionSnapshots(projectId,iterationId,groupId,revisionId)) {var row=new LinkedHashMap<>(snapshot);row.put("itemCount",((List)row.remove("items")).size());rows.add(row);} + return rows; + } + + /** 历史工作项详情必须属于精确的父汇总版本,不能仅传当前工作项ID绕过版本上下文。 */ + public Map itemSnapshot(long projectId,long iterationId,long groupId,long revisionId,long itemId) { + return versionItems(projectId,iterationId,groupId,revisionId).stream().filter(row->number(row,"id")==itemId).findFirst().orElseThrow(PmAccess::denied); + } + + /** 为单个子执行版本截取完整只读展示,附件仅保存受鉴权下载所需元信息,不含存储对象键。 */ + private Map snapshot(Graph graph,long childId,Map owners) { + List> items=new ArrayList<>(); + for(Item item:graph.items().values()) if(!item.deleted()&&Objects.equals(item.stageId(),childId)) { + var row=map("id",item.id(),"title",item.title(),"type",item.type(),"description",item.description(),"status",item.status(),"priority",item.priority(),"assigneeId",item.assigneeId(),"collaborators",item.collaborators(),"parent_task_id",item.parentTaskId(),"parentTaskId",item.parentTaskId(),"stageId",childId,"stagePath",PmStageHierarchyRules.path(graph,childId),"version",item.version(),"plannedStartAt",time(item.start()),"plannedEndAt",time(item.end()),"actualStartAt",time(item.actualStart()),"actualEndAt",time(item.actualEnd()),"historical",true,"readOnly",true,"dependencyConditions",PmRules.conditions(graph,item.id(),"Asia/Shanghai")); + row.put("projectId",graph.iteration().projectId());row.put("iterationId",graph.iteration().id()); + row.put("assigneeName",owners.get(item.id())); + row.put("comments",activityTimes(activities.selectComments(item.id())));row.put("attachments",activities.selectAttachments(item.id()));row.put("history",activityTimes(activities.selectHistory(item.id()))); + items.add(row); + } + Map result=map("stageId",childId,"name",graph.stageNames().get(childId),"description",PmStageHierarchyRules.info(graph,childId).description(),"revisionId",graph.stageRevisions().get(childId).id(),"revisionNo",graph.stageRevisions().get(childId).revisionNo(),"executionStatus",PmStageRules.executionStatus(graph,childId),"items",items); + result.putAll(PmStageScheduleRules.times(graph.stageRevisions().get(childId)));return result; + } + /** JSON 仅来自服务器保存的冻结内容,解码失败使历史查询明确失败而非退回实时内容。 */ + private Map decode(String value) { try{return decoder.readValue(value,new TypeReference>(){});}catch(Exception failure){throw new IllegalStateException("阶段组快照无法读取",failure);} } + /** 将内部快照键安全转换为字符串,避免不受控泛型转换。 */ + private static Map stringMap(Map source) {Map row=new LinkedHashMap<>();source.forEach((key,value)->row.put(String.valueOf(key),value));return row;} + /** 时间展示继续使用北京时间,保存与比较保持UTC微秒。 */ + private static String time(Long value){return PmTime.format(value,"Asia/Shanghai");} + /** 审计时间在冻结前转换为标准ISO字段,历史客户端无需猜测数据库微秒的精度。 */ + private static List> activityTimes(List> rows) {for(var row:rows)row.put("createdAt",time(nullable(row,"createdAt")));return rows;} + /** 一次读取整个已鉴权迭代,避免逐工作项查询负责人而放大冻结事务的锁持有时间。 */ + private Map ownerNames(Graph graph) {Map names=new HashMap<>();for(var row:mapper.selectItemOwners(graph.iteration().projectId(),graph.iteration().id()))names.put(number(row,"id"),text(row,"name"));return names;} +} diff --git a/ruoyi-project/src/main/resources/mapper/project/manage/PmGroupMapper.xml b/ruoyi-project/src/main/resources/mapper/project/manage/PmGroupMapper.xml new file mode 100644 index 0000000..18bedea --- /dev/null +++ b/ruoyi-project/src/main/resources/mapper/project/manage/PmGroupMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + INSERT INTO pm_collab_stage_revision_member(project_id,iteration_id,parent_stage_id,parent_revision_id,child_stage_id,child_revision_id) + VALUES(#{projectId},#{iterationId},#{parentId},#{revisionId},#{childId},#{childRevisionId}) + + + DELETE FROM pm_collab_stage_revision_member WHERE parent_revision_id=#{revisionId} AND frozen_at IS NULL + + + UPDATE pm_collab_stage_revision_member SET snapshot_json=#{snapshot},frozen_at=#{at} WHERE id=#{id} AND frozen_at IS NULL + + + UPDATE pm_collab_stage_revision SET started_at=#{start},completed_at=#{end},version=version+1 WHERE id=#{revisionId} AND superseded_at IS NULL + + diff --git a/ruoyi-project/src/main/resources/mapper/project/manage/PmIterationMapper.xml b/ruoyi-project/src/main/resources/mapper/project/manage/PmIterationMapper.xml index 28d9ba5..6e1f44f 100644 --- a/ruoyi-project/src/main/resources/mapper/project/manage/PmIterationMapper.xml +++ b/ruoyi-project/src/main/resources/mapper/project/manage/PmIterationMapper.xml @@ -53,8 +53,8 @@ OR completed_at IS NOT NULL OR superseded_at IS NOT NULL OR legacy_passed_at IS NOT NULL)) - INSERT INTO pm_collab_project_stage(project_id,iteration_id,name,sort_order,owner_id,description,created_by,created_at) - VALUES(#{values.project_id},#{values.iteration_id},#{values.name},#{values.sort_order},#{values.owner_id},#{values.description},#{values.created_by},#{values.created_at}) + INSERT INTO pm_collab_project_stage(project_id,iteration_id,name,sort_order,owner_id,description,stage_kind,parent_stage_id,created_by,created_at) + VALUES(#{values.project_id},#{values.iteration_id},#{values.name},#{values.sort_order},#{values.owner_id},#{values.description},#{values.stage_kind},#{values.parent_stage_id},#{values.created_by},#{values.created_at}) - INSERT INTO pm_collab_stage_revision(project_id,iteration_id,stage_id,revision_no,stage_name_snapshot,stage_owner_snapshot,created_by,created_at) - VALUES(#{values.project_id},#{values.iteration_id},#{values.stage_id},1,#{values.name},#{values.owner_id},#{values.created_by},#{values.created_at}) + INSERT INTO pm_collab_stage_revision(project_id,iteration_id,stage_id,revision_no,stage_name_snapshot,stage_owner_snapshot,stage_kind_snapshot,parent_stage_snapshot_id,stage_description_snapshot,created_by,created_at) + VALUES(#{values.project_id},#{values.iteration_id},#{values.stage_id},1,#{values.name},#{values.owner_id},#{values.stage_kind},#{values.parent_stage_id},#{values.description},#{values.created_by},#{values.created_at}) UPDATE pm_collab_project_stage SET current_revision_id=#{revisionId} WHERE id=#{stageId} AND current_revision_id IS NULL - INSERT INTO pm_collab_stage_edge(project_id,iteration_id,predecessor_stage_id,successor_stage_id,created_by,created_at) - VALUES(#{values.project_id},#{values.iteration_id},#{values.predecessor_stage_id},#{values.successor_stage_id},#{values.created_by},#{values.created_at}) + INSERT INTO pm_collab_stage_edge(project_id,iteration_id,predecessor_stage_id,successor_stage_id,parent_stage_id,created_by,created_at) + VALUES(#{values.project_id},#{values.iteration_id},#{values.predecessor_stage_id},#{values.successor_stage_id},(SELECT parent_stage_id FROM pm_collab_project_stage WHERE id=#{values.predecessor_stage_id}),#{values.created_by},#{values.created_at}) INSERT INTO pm_collab_flow_definition_revision(project_id,iteration_id,revision_no,graph_json,created_by,created_at) diff --git a/ruoyi-project/src/main/resources/mapper/project/manage/PmRevisionMapper.xml b/ruoyi-project/src/main/resources/mapper/project/manage/PmRevisionMapper.xml index 8a024b2..da8f7f0 100644 --- a/ruoyi-project/src/main/resources/mapper/project/manage/PmRevisionMapper.xml +++ b/ruoyi-project/src/main/resources/mapper/project/manage/PmRevisionMapper.xml @@ -17,8 +17,8 @@ SELECT * FROM pm_collab_work_item WHERE stage_revision_id=#{revisionId} ORDER BY id - INSERT INTO pm_collab_stage_revision(project_id,iteration_id,stage_id,revision_no,rework_id,previous_revision_id,flow_definition_revision_id,stage_name_snapshot,stage_owner_snapshot,created_by,created_at) - VALUES(#{values.project_id},#{values.iteration_id},#{values.stage_id},#{values.revision_no},#{values.rework_id},#{values.previous_revision_id},#{values.flow_definition_revision_id},#{values.stage_name_snapshot},#{values.stage_owner_snapshot},#{values.created_by},#{values.created_at}) + INSERT INTO pm_collab_stage_revision(project_id,iteration_id,stage_id,revision_no,rework_id,previous_revision_id,flow_definition_revision_id,stage_name_snapshot,stage_owner_snapshot,stage_kind_snapshot,parent_stage_snapshot_id,stage_description_snapshot,revision_reason,planned_start_at,planned_end_at,plan_source,plan_recorded_at,reference_planned_start_at,reference_planned_end_at,schedule_review_rework_id,created_by,created_at) + VALUES(#{values.project_id},#{values.iteration_id},#{values.stage_id},#{values.revision_no},#{values.rework_id},#{values.previous_revision_id},#{values.flow_definition_revision_id},#{values.stage_name_snapshot},#{values.stage_owner_snapshot},COALESCE(#{values.stage_kind_snapshot},'WORK'),#{values.parent_stage_snapshot_id},#{values.stage_description_snapshot},COALESCE(#{values.revision_reason},'INITIAL'),#{values.planned_start_at},#{values.planned_end_at},#{values.plan_source},#{values.plan_recorded_at},#{values.reference_planned_start_at},#{values.reference_planned_end_at},#{values.schedule_review_rework_id},#{values.created_by},#{values.created_at}) UPDATE pm_collab_project_stage SET current_revision_id=#{nextId},version=version+1 diff --git a/ruoyi-project/src/main/resources/mapper/project/manage/PmStageMapper.xml b/ruoyi-project/src/main/resources/mapper/project/manage/PmStageMapper.xml index 16a3986..22f8eb7 100644 --- a/ruoyi-project/src/main/resources/mapper/project/manage/PmStageMapper.xml +++ b/ruoyi-project/src/main/resources/mapper/project/manage/PmStageMapper.xml @@ -3,6 +3,11 @@ + + UPDATE pm_collab_stage_revision SET stage_kind_snapshot=#{kind},parent_stage_snapshot_id=#{parentId},stage_description_snapshot=#{description} + WHERE id=#{revisionId} AND started_at IS NULL AND superseded_at IS NULL + + DELETE FROM pm_collab_stage_edge WHERE project_id=#{projectId} AND iteration_id=#{iterationId} @@ -13,7 +18,8 @@ - SELECT e.id,e.project_id,e.predecessor_stage_id,e.successor_stage_id,e.version + SELECT e.id,e.parent_stage_id,e.project_id,e.predecessor_stage_id,e.successor_stage_id,e.version FROM pm_collab_stage_edge e JOIN pm_collab_project_stage source ON source.id=e.predecessor_stage_id AND source.deleted=false JOIN pm_collab_project_stage target ON target.id=e.successor_stage_id AND target.deleted=false @@ -81,8 +93,8 @@ - INSERT INTO pm_collab_stage_edge(project_id,iteration_id,predecessor_stage_id,successor_stage_id,created_by,created_at) - VALUES(#{values.project_id},#{values.iteration_id},#{values.predecessor_stage_id},#{values.successor_stage_id},#{values.created_by},#{values.created_at}) + INSERT INTO pm_collab_stage_edge(project_id,iteration_id,predecessor_stage_id,successor_stage_id,parent_stage_id,created_by,created_at) + VALUES(#{values.project_id},#{values.iteration_id},#{values.predecessor_stage_id},#{values.successor_stage_id},(SELECT parent_stage_id FROM pm_collab_project_stage WHERE id=#{values.predecessor_stage_id}),#{values.created_by},#{values.created_at}) diff --git a/ruoyi-project/src/main/resources/mapper/project/manage/PmWorkItemMapper.xml b/ruoyi-project/src/main/resources/mapper/project/manage/PmWorkItemMapper.xml index d827fff..b5f1392 100644 --- a/ruoyi-project/src/main/resources/mapper/project/manage/PmWorkItemMapper.xml +++ b/ruoyi-project/src/main/resources/mapper/project/manage/PmWorkItemMapper.xml @@ -36,6 +36,8 @@ stage_revision_id, origin_work_item_id, schedule_review_rework_id, + reference_planned_start_at, + reference_planned_end_at, parent_task_id, version, deleted, @@ -60,6 +62,8 @@ #{values.stage_revision_id}, #{values.origin_work_item_id}, #{values.schedule_review_rework_id}, + #{values.reference_planned_start_at}, + #{values.reference_planned_end_at}, #{values.parent_task_id}, #{values.version}, #{values.deleted}, diff --git a/ruoyi-ui-vue3/src/views/project/manage/api/stages.ts b/ruoyi-ui-vue3/src/views/project/manage/api/stages.ts index 75ec2a6..dea16ef 100644 --- a/ruoyi-ui-vue3/src/views/project/manage/api/stages.ts +++ b/ruoyi-ui-vue3/src/views/project/manage/api/stages.ts @@ -1,8 +1,14 @@ import { request } from './client' import { iterationPath } from './paths' -import type { FlowView, ReworkInput, ReworkPreview, StageRevision, StageRevisionDetail, StageInput } from '../types' +import type { FlowView, ReworkInput, ReworkPreview, StageRevision, StageRevisionDetail, StageInput, StageStructureInput, WorkItem } from '../types' export const stageApi = { + /** 精确父级组合下读取冻结详情,不用实时子项替代历史数据。 */ + stageItemSnapshot: (id: number, iterationId: number, stageId: number, revisionId: number, itemId: number) => request('get', iterationPath(id, iterationId, `stages/${stageId}/revisions/${revisionId}/items/${itemId}`)), + /** 迁入迁出未执行阶段前预览完整最终结构,调用方明确提供全部保留边。 */ + previewStageStructure: (id: number, iterationId: number, input: StageStructureInput) => request<{ canCommit: boolean; graphVersion: number }>('post', iterationPath(id, iterationId, 'stage-structure/preview'), input), + /** 以同一图版本确认已预览的结构;历史和已执行阶段由后端保护。 */ + commitStageStructure: (id: number, iterationId: number, input: StageStructureInput) => request('post', iterationPath(id, iterationId, 'stage-structure'), input), /** 仅读取当前迭代阶段及计数摘要;工作项由各视图独立分页查询。 */ flowView: (id: number, iterationId?: number) => request('get', iterationPath(id, iterationId, `flow-view`)), /** 回退预览从项目锁下的最新图计算影响范围,界面只展示后端裁定结果。 */ diff --git a/ruoyi-ui-vue3/src/views/project/manage/composables/useProjectCollaboration.ts b/ruoyi-ui-vue3/src/views/project/manage/composables/useProjectCollaboration.ts index dc541d2..260a024 100644 --- a/ruoyi-ui-vue3/src/views/project/manage/composables/useProjectCollaboration.ts +++ b/ruoyi-ui-vue3/src/views/project/manage/composables/useProjectCollaboration.ts @@ -65,6 +65,7 @@ export function useProjectCollaboration() { const keyword = ref('') const typeFilter = ref(null) const blockedOnly = ref(false) + const stageFilter = ref(null) const detailId = ref(null) const refreshKey = ref(0) const selection = ref([]) @@ -163,7 +164,7 @@ export function useProjectCollaboration() { /** 分页筛选交由服务端;甘特独有的成员条件不传给列表、看板或前置选择器。 */ function query(view: ItemQuery['view']): ItemQuery { - return { view, page: page.value, pageSize, keyword: keyword.value, type: typeFilter.value, blockedOnly: blockedOnly.value, ...(view === 'gantt' ? { from: ganttFrom.value, to: ganttTo.value, memberIds: [...ganttMemberIds.value] } : {}) } + return { view, page: page.value, pageSize, keyword: keyword.value, type: typeFilter.value, blockedOnly: blockedOnly.value, stageId: stageFilter.value, ...(view === 'gantt' ? { from: ganttFrom.value, to: ganttTo.value, memberIds: [...ganttMemberIds.value] } : {}) } } /** 用户主动刷新或业务操作完成时显示加载状态;独立包装避免分页事件的页码被当作后台标志。 */ @@ -270,7 +271,7 @@ export function useProjectCollaboration() { flowView.value = null selection.value = [] members.value = [] - ganttMemberIds.value = [] + ganttMemberIds.value = []; stageFilter.value = null detailId.value = null editing.value = null creatingParent.value = null @@ -476,7 +477,7 @@ export function useProjectCollaboration() { finally { polling = false } } - watch([tab, keyword, typeFilter, blockedOnly], () => { + watch([tab, keyword, typeFilter, blockedOnly, stageFilter], () => { page.value = 1 void refresh() }) @@ -598,7 +599,7 @@ export function useProjectCollaboration() { return { projectId, iterations, iterationId, includeArchived, items, members, flowView, current, selectedIteration, zone, canWrite, canCreate, canExecute, - loading, failure, tab, keyword, typeFilter, blockedOnly, detailId, refreshKey, selection, + loading, failure, tab, keyword, typeFilter, blockedOnly, stageFilter, detailId, refreshKey, selection, editing, editorOpen, creatingParent, defaultStageId, page, pageSize, total, boardCounts, ganttFrom, ganttTo, ganttMemberIds, membersOpen, inviteUser, inviteRole, userCandidates, batchOpen, notifications, statCards, userStore, diff --git a/ruoyi-ui-vue3/src/views/project/manage/docs/stage-groups-implementation.md b/ruoyi-ui-vue3/src/views/project/manage/docs/stage-groups-implementation.md new file mode 100644 index 0000000..83d51cf --- /dev/null +++ b/ruoyi-ui-vue3/src/views/project/manage/docs/stage-groups-implementation.md @@ -0,0 +1,58 @@ +# 阶段组与子流程实施计划 + +**目标**:在现有协作中实现两层阶段树、同层执行图、整日阶段计划、局部回退和稳定的父级历史。 + +**规格**:本会话最终审查方案(用户已授权实施)。WORK 承载工作项,GROUP 承载 WORK 子阶段;空节点不放行。实际准入与预计排期分开。局部回退只重做相关执行分支,父级汇总独立换版。 + +**范围**:前端仅 manage 目录;后端仅 ruoyi-project。复用项目权限、MyBatis、项目图锁、UTC 微秒存储、北京时间日期控件及 outbox;不更改其他模块。 + +**验证重点**:父级阻塞不能绕过;无关并行分支不误复制;父级旧快照不随保留分支变化;空节点可回退但不自动放行;有效整批父子排期可以原子提交。 + +## 任务与进度 + +- [x] 1. 层级模型和迁移:StageInfo、Graph 层级快照、StageInput 日期/类型/父级、019 升级 SQL、Mapper XML。 +- [x] 2. 执行与排期:PmStageHierarchyRules 校验两层及同层连线,PmStageRules 聚合状态/父级准入,PmRules 混合环,PmStageScheduleRules 父子范围及内部排期状态。 +- [x] 3. 阶段管理和结构预览:新建首版同时保存计划;父级可写性;管理者明确调整未执行阶段父级和边;工作项阶段归属不能用普通字段更新绕过。 +- [x] 4. 版本与回退:阶段组成员表、冻结快照和历史详情;重做与汇总集合分离;空阶段回退;排期复核及任务前置映射。 +- [x] 5. 子流程画布:GROUP 自适应父节点、WORK 子节点、同层边、折叠偏好、统一创建表单及阶段/历史抽屉。 +- [x] 6. 跨视图兼容:阶段路径、组筛选、甘特层级、迭代结构复制和结束预览、合并通知。 +- [x] 7. 验收:规则红绿测试、真实 MySQL 事务/并发测试、前端交互、严格类型检查和前后端构建;逐项复核需求、注释和范围;删除临时测试。 + +每项按失败测试→实现→相关验证推进。临时验证代码放在模块 target 或 manage/tests,验收结束清理;不提交或推送本次改动。当前工作区是用户正在使用的仓库,直接按用户指定路径实施,不另开会影响 IDEA 的目录或重启用户服务。 + +## 业务边界与约束 + +FR-001:根画布可创建工作阶段或阶段组;组内只支持工作阶段,不支持第三层。空阶段不自动完成。父级入边约束子阶段进入,父级完成依据全部子阶段,防止父子互相等待。 + +FR-002:手工创建阶段须填写整日计划;子阶段在父组范围内,同层执行边使用完成后开始约束。未连线的同级节点可并行。保留已有精确排期,实际开始不必等预计日期。 + +FR-003:回退限当前阶段及同一画布严格上游。重做执行阶段、父级汇总换版和排期复核为三个集合。显式重做组会重做整个子树;仅子阶段换版不会复制无关并行分支。父组有效计划未变时不清空外层后继计划。 + +FR-004:父级版本绑定精确子执行版本组合。在子指针变动前冻结旧组合;冻结名称、工作项字段、分工、依赖情况及当时详情展示的评论、附件元数据和历史。附件不复制二进制和存储对象键,下载仍遵守当前权限和软删除规则。 + +FR-005:项目图行锁与原项目共享锁协调所有业务写入,使用稳定的原项目→协作图锁序。回退幂等键和图版本保护预览;业务、版本、历史、outbox 同事务提交。异步通知继续合并为每人一次回退提醒,邮件仍须明确勾选。 + +FR-006:所有成员共享阶段树和内容;位置、视口、折叠和坐标所属画布只保存在当前浏览器。阶段层级改变后废弃该节点原坐标,不把根画布位置当成子画布相对坐标。 + +## 迁移与使用 + +- 已安装环境在 018 之后执行后端 `sql/upgrade/019_stage_groups.sql` 一次;全新环境使用完整安装文件,不再重复执行 019。 +- 当前开发库 `cmvr-project-dev` 已执行 019,升级只增列、索引、约束及 `pm_collab_stage_revision_member`,未删除业务数据。原阶段保持根工作阶段。 +- 原三个表的升级前结构保存在 `E:/workspace/cmvr-wms-recovery/20261020-170237-stage-groups`。 +- 新建阶段从画布拖入;选择阶段组后可在组内拖入/创建子阶段。管理阶段提供未执行结构的预览与确认入口;已有执行历史的阶段组冻结父级和子阶段集合。 +- 列表、看板和甘特显示完整阶段路径并支持组筛选;组抽屉聚合工作项,历史页可查看当时子版本组合和冻结工作项详情。 +- 后端继续通过 ruoyi-admin 启动,前端沿用原项目启动方式。升级完成后重启后端并刷新前端;不由 ORM 或应用启动执行建表。 + +## 验收记录 + +- FR-001~FR-006:PASS;AC-001 层级与门禁、AC-002 父子排期、AC-003 局部回退与稳定历史、AC-004 并发一致性、AC-005 子画布交互及跨视图:PASS。 +- 临时 `StageRulesCheck`:PASS,覆盖组状态、父级准入、并行汇总、取消与空阶段、混合环、父子计划范围、自身计划与内部冲突区分。 +- 临时 `StageIntegrationCheck`:PASS。使用独立 MySQL 8 临时数据库安装完整结构、外键和真实 MyBatis/Spring 事务服务,覆盖局部回退不复制并行分支、旧父快照不随标题及评论变化、精确子版本绑定、幂等、组完成后放行、实际时间汇总、结构预览不写入、迭代结构复制、空阶段回退及非成员拒绝。并发验证反向加边、父子排期修改、开始与回退;拒绝的操作不产生成功事件。临时库已删除。 +- 临时 Chrome 浏览器脚本:PASS,覆盖子节点边界及避让、相对坐标拖动、折叠刷新后恢复、明暗主题、精确父级历史详情接口、只读日期控件及整日提交、结构变更后预览失效。交互验收使用受控 API 响应;后端业务由上述真实数据库测试验证。 +- 实际开发库 019 结构及新增 7 个字段的中文注释:PASS。 +- 后端构建:`mvn -pl ruoyi-admin -am -DskipTests package`:PASS;该命令不代表运行 Maven 测试,规则与数据库用例单独执行。 +- 前端严格检查:`npx --no-install vue-tsc --noEmit -p src/views/project/manage/tsconfig.json --noUnusedLocals --noUnusedParameters`:PASS。 +- 前端构建:`npm run build:prod`:PASS;清理临时页面后再次构建,避免测试页面进入动态路由产物。 +- 未单独执行 Lint。新增与修改方法的中文说明、复杂图与快照注释已复核。Scope Drift:NONE;Requirement Drift:NONE。 + +按用户约定,上述临时用例、辅助类、测试页面、截图、日志及专用缓存均在验收后删除;临时用例名称是执行记录,不是保留的测试入口。 diff --git a/ruoyi-ui-vue3/src/views/project/manage/features/schedules/components/ScheduleBatchDialog.vue b/ruoyi-ui-vue3/src/views/project/manage/features/schedules/components/ScheduleBatchDialog.vue index 1871f70..0d01236 100644 --- a/ruoyi-ui-vue3/src/views/project/manage/features/schedules/components/ScheduleBatchDialog.vue +++ b/ruoyi-ui-vue3/src/views/project/manage/features/schedules/components/ScheduleBatchDialog.vue @@ -48,7 +48,7 @@ watch(() => [props.visible, props.projectId, props.iterationId], async () => { const view = await api.flowView(props.projectId, props.iterationId) if (request !== sequence) return stages.value = view.stages; graphVersion.value = view.graphVersion - stageRows.value = view.stages.filter(stage => !frozen(stage.id)).map(stage => ({ ...draft(stage.id, stage.revisionVersion ?? 0, stage.name, stage), revisionId: stage.revisionId ?? stage.currentRevisionId })) + stageRows.value = view.stages.filter(stage => !frozen(stage.id)).map(stage => ({ ...draft(stage.id, stage.revisionVersion ?? 0, stage.stagePath || stage.name, stage), revisionId: stage.revisionId ?? stage.currentRevisionId })) await loadMore() } catch (error) { if (request === sequence) failure.value = errorText(error) } finally { if (request === sequence) loading.value = false } diff --git a/ruoyi-ui-vue3/src/views/project/manage/features/schedules/components/StageSchedulePanel.vue b/ruoyi-ui-vue3/src/views/project/manage/features/schedules/components/StageSchedulePanel.vue index 250cfd1..3cbf1bc 100644 --- a/ruoyi-ui-vue3/src/views/project/manage/features/schedules/components/StageSchedulePanel.vue +++ b/ruoyi-ui-vue3/src/views/project/manage/features/schedules/components/StageSchedulePanel.vue @@ -1,6 +1,7 @@ diff --git a/ruoyi-ui-vue3/src/views/project/manage/views/flow/components/FlowStageNode.vue b/ruoyi-ui-vue3/src/views/project/manage/views/flow/components/FlowStageNode.vue index b57bbf6..749c6f0 100644 --- a/ruoyi-ui-vue3/src/views/project/manage/views/flow/components/FlowStageNode.vue +++ b/ruoyi-ui-vue3/src/views/project/manage/views/flow/components/FlowStageNode.vue @@ -1,11 +1,12 @@