Merge remote-tracking branch 'origin/project' into project
# Conflicts: # ruoyi-ui-vue3/package-lock.json
This commit is contained in:
commit
7e6dafcaf5
3
.gitignore
vendored
3
.gitignore
vendored
@ -84,3 +84,6 @@ ruoyi-ui/yarn-error.log*
|
||||
!*/build/*.java
|
||||
!*/build/*.html
|
||||
!*/build/*.xml
|
||||
|
||||
.agents
|
||||
/AGENTS.md
|
||||
|
||||
1
pom.xml
1
pom.xml
@ -180,6 +180,7 @@
|
||||
<module>ruoyi-quartz</module>
|
||||
<module>ruoyi-generator</module>
|
||||
<module>ruoyi-common</module>
|
||||
<module>ruoyi-project</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
||||
@ -17,6 +17,9 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- 项目协作代码独立放在 ruoyi-project,只在启动模块接入运行时依赖。 -->
|
||||
<dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-project</artifactId><version>${ruoyi.version}</version></dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
37
ruoyi-project/pom.xml
Normal file
37
ruoyi-project/pom.xml
Normal file
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>cmvr-wms-parent</artifactId>
|
||||
<version>3.9.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ruoyi-project</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common</artifactId><version>${ruoyi.version}</version></dependency>
|
||||
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency>
|
||||
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId></dependency>
|
||||
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
|
||||
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId></dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
<!-- 沿用框架的 MyBatis 资源扫描;安装和升级 SQL 位于模块 sql 目录,不参与运行资源输出。 -->
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
561
ruoyi-project/sql/project_collaboration.sql
Normal file
561
ruoyi-project/sql/project_collaboration.sql
Normal file
@ -0,0 +1,561 @@
|
||||
-- target-database: cmvr-project-dev
|
||||
|
||||
-- 项目协作当前完整安装结构(MySQL 8),仅供从未安装 pm_collab_* 的环境。
|
||||
-- 前置:已安装若依 sys_user、sys_menu 及项目管理父菜单 2100。连接到目标库后执行。
|
||||
-- 不包含 DROP、TRUNCATE 或旧数据回填;已有协作库只执行 upgrade 下的注释补丁。
|
||||
-- 先建立全部表及索引,再添加外键,解决阶段与执行版本双向引用;全程不关闭外键检查。
|
||||
-- 任一错误立即停止,禁止客户端启用忽略错误继续执行模式。
|
||||
-- 后端与 ruoyi-system 一样启动 ruoyi-admin;本文件人工部署,不由 MyBatis 或服务启动执行。
|
||||
-- 当前开发库已安装并补齐中文注释,无需再次执行。本文件不负责006~009旧数据或中断升级的转换。
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
-- 项目协作:工作项附件
|
||||
CREATE TABLE `pm_collab_attachment` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`work_item_id` bigint NOT NULL COMMENT '关联工作项ID',
|
||||
`name` varchar(255) NOT NULL COMMENT '附件原文件名',
|
||||
`media_type` varchar(120) NOT NULL COMMENT '附件媒体类型',
|
||||
`content` longblob NOT NULL COMMENT '附件二进制内容,需经项目权限校验后访问',
|
||||
`size` bigint NOT NULL COMMENT '附件大小(字节)',
|
||||
`created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_pm_collab_attachment` (`work_item_id`,`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:工作项附件';
|
||||
|
||||
-- 项目协作:工作项评论
|
||||
CREATE TABLE `pm_collab_comment` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`work_item_id` bigint NOT NULL COMMENT '关联工作项ID',
|
||||
`body` text NOT NULL COMMENT '评论正文',
|
||||
`created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_pm_collab_comment` (`work_item_id`,`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:工作项评论';
|
||||
|
||||
-- 项目协作:任务前置依赖条件
|
||||
CREATE TABLE `pm_collab_dependency_condition` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`successor_task_id` bigint NOT NULL COMMENT '受约束的后续任务ID',
|
||||
`condition_type` varchar(32) NOT NULL COMMENT '条件类型(TASK_COMPLETED:前置任务完成)',
|
||||
`predecessor_task_id` bigint NOT NULL COMMENT '前置任务ID',
|
||||
`expected_status` varchar(32) NOT NULL DEFAULT 'COMPLETED' COMMENT '目标状态(COMPLETED;业务判断已关闭也满足完成条件)',
|
||||
`created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
`version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
`iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_dep_task` (`successor_task_id`,`predecessor_task_id`),
|
||||
KEY `idx_pm_collab_dep_task` (`predecessor_task_id`,`successor_task_id`),
|
||||
KEY `project_id` (`project_id`,`successor_task_id`),
|
||||
KEY `project_id_2` (`project_id`,`predecessor_task_id`),
|
||||
KEY `fk_pm_iter_dep_pre` (`project_id`,`iteration_id`,`predecessor_task_id`),
|
||||
KEY `fk_pm_iter_dep_next` (`project_id`,`iteration_id`,`successor_task_id`),
|
||||
CONSTRAINT `ck_pm_collab_dep_self` CHECK ((`predecessor_task_id` <> `successor_task_id`)),
|
||||
CONSTRAINT `ck_pm_collab_dep_type` CHECK (((`condition_type` = _utf8mb4'TASK_COMPLETED') and (`expected_status` = _utf8mb4'COMPLETED')))
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:任务前置依赖条件';
|
||||
|
||||
-- 项目协作:阶段执行图定义快照
|
||||
CREATE TABLE `pm_collab_flow_definition_revision` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`revision_no` bigint NOT NULL COMMENT '迭代内执行图定义版本号',
|
||||
`graph_json` longtext NOT NULL COMMENT '首次执行时冻结的阶段和连线快照(JSON)',
|
||||
`created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
`iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_definition_iteration` (`project_id`,`iteration_id`,`id`),
|
||||
UNIQUE KEY `uk_pm_collab_flow_definition_scope` (`project_id`,`iteration_id`,`revision_no`),
|
||||
KEY `created_by` (`created_by`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:阶段执行图定义快照';
|
||||
|
||||
-- 项目协作:流程画布布局(历史兼容,当前视图不使用)
|
||||
CREATE TABLE `pm_collab_graph_layout` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`owner_id` bigint NOT NULL COMMENT '布局所属用户ID(0为旧共享布局),当前画布使用浏览器存储',
|
||||
`layout_json` json NOT NULL COMMENT '旧画布节点位置、折叠及视口数据(JSON)',
|
||||
`version` int NOT NULL DEFAULT '1' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
`updated_by` bigint NOT NULL COMMENT '最后更新人用户ID',
|
||||
`updated_at` bigint NOT NULL COMMENT '最后更新时间(UTC时间戳,微秒)',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_layout_owner` (`project_id`,`owner_id`),
|
||||
KEY `updated_by` (`updated_by`),
|
||||
CONSTRAINT `ck_pm_collab_layout_owner` CHECK ((`owner_id` >= 0))
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:流程画布布局(历史兼容,当前视图不使用)';
|
||||
|
||||
-- 项目协作:操作历史
|
||||
CREATE TABLE `pm_collab_history` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`work_item_id` bigint DEFAULT NULL COMMENT '关联工作项ID,项目或阶段级操作可为空',
|
||||
`action` varchar(40) NOT NULL COMMENT '业务操作类型',
|
||||
`detail` json NOT NULL COMMENT '操作详情及变更记录(JSON)',
|
||||
`created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
`iteration_id` bigint DEFAULT NULL COMMENT '所属迭代ID,项目级历史可为空',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_pm_collab_history` (`work_item_id`,`id`),
|
||||
KEY `idx_pm_collab_history_iteration` (`project_id`,`iteration_id`,`id`),
|
||||
KEY `fk_pm_iter_history_item` (`project_id`,`iteration_id`,`work_item_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:操作历史';
|
||||
|
||||
-- 项目协作:项目迭代
|
||||
CREATE TABLE `pm_collab_iteration` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`iteration_code` varchar(64) NOT NULL COMMENT '项目内唯一的迭代编号',
|
||||
`name` varchar(200) NOT NULL COMMENT '迭代名称',
|
||||
`goal` text COMMENT '迭代目标',
|
||||
`status` varchar(16) NOT NULL DEFAULT 'PLANNED' COMMENT '迭代状态(PLANNED筹备,ACTIVE进行,FINISHED结束,CANCELLED取消)',
|
||||
`finish_result` varchar(24) DEFAULT NULL COMMENT '结束结果(COMPLETED正常完成,WITH_EXCEPTIONS含例外)',
|
||||
`finish_note` varchar(2000) DEFAULT NULL COMMENT '结束或取消的原因及例外说明',
|
||||
`planned_start_at` bigint DEFAULT NULL COMMENT '预计开始时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
`planned_end_at` bigint DEFAULT NULL COMMENT '预计结束时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
`actual_start_at` bigint DEFAULT NULL COMMENT '实际开始时间(UTC时间戳,微秒;尚未开始为空)',
|
||||
`actual_end_at` bigint DEFAULT NULL COMMENT '实际结束时间(UTC时间戳,微秒;尚未结束为空)',
|
||||
`sort_order` int NOT NULL DEFAULT '0' COMMENT '迭代展示排序值',
|
||||
`version` bigint NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
`graph_version` bigint NOT NULL DEFAULT '0' COMMENT '执行图版本号,用于校验预览与提交的一致性',
|
||||
`archived_at` bigint DEFAULT NULL COMMENT '归档时间(UTC时间戳,微秒;未归档为空)',
|
||||
`archived_by` bigint DEFAULT NULL COMMENT '归档操作者用户ID',
|
||||
`deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,1已删除)',
|
||||
`created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
`updated_by` bigint NOT NULL COMMENT '最后更新人用户ID',
|
||||
`updated_at` bigint NOT NULL COMMENT '最后更新时间(UTC时间戳,微秒)',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_iteration_code` (`project_id`,`iteration_code`),
|
||||
UNIQUE KEY `uk_pm_collab_iteration_scope` (`project_id`,`id`),
|
||||
KEY `idx_pm_collab_iteration_list` (`project_id`,`deleted`,`archived_at`,`sort_order`,`id`),
|
||||
KEY `created_by` (`created_by`),
|
||||
KEY `updated_by` (`updated_by`),
|
||||
KEY `archived_by` (`archived_by`),
|
||||
CONSTRAINT `ck_pm_collab_iteration_archive` CHECK (((`archived_at` is null) or (`status` in (_utf8mb4'FINISHED',_utf8mb4'CANCELLED')))),
|
||||
CONSTRAINT `ck_pm_collab_iteration_dates` CHECK (((`planned_start_at` is null) or (`planned_end_at` is null) or (`planned_end_at` >= `planned_start_at`))),
|
||||
CONSTRAINT `ck_pm_collab_iteration_finished` CHECK ((((`status` = _utf8mb4'FINISHED') and (`finish_result` is not null)) or ((`status` <> _utf8mb4'FINISHED') and (`finish_result` is null)))),
|
||||
CONSTRAINT `ck_pm_collab_iteration_result` CHECK (((`finish_result` is null) or (`finish_result` in (_utf8mb4'COMPLETED',_utf8mb4'WITH_EXCEPTIONS')))),
|
||||
CONSTRAINT `ck_pm_collab_iteration_sort` CHECK ((`sort_order` between 0 and 1000000)),
|
||||
CONSTRAINT `ck_pm_collab_iteration_status` CHECK ((`status` in (_utf8mb4'PLANNED',_utf8mb4'ACTIVE',_utf8mb4'FINISHED',_utf8mb4'CANCELLED')))
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:项目迭代';
|
||||
|
||||
-- 项目协作:迭代操作幂等记录
|
||||
CREATE TABLE `pm_collab_iteration_request` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
`idempotency_key` varchar(100) NOT NULL COMMENT '请求幂等键,避免重试重复执行业务',
|
||||
`action` varchar(24) NOT NULL COMMENT '业务操作类型',
|
||||
`request_hash` char(64) NOT NULL COMMENT '请求参数的SHA-256摘要,防止同一幂等键被用于不同请求',
|
||||
`result_json` longtext NOT NULL COMMENT '已提交操作的响应快照(JSON),用于幂等重试返回',
|
||||
`created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_iteration_request` (`project_id`,`created_by`,`idempotency_key`),
|
||||
KEY `project_id` (`project_id`,`iteration_id`),
|
||||
KEY `created_by` (`created_by`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:迭代操作幂等记录';
|
||||
|
||||
-- 项目协作:成员通知
|
||||
CREATE TABLE `pm_collab_notification` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`event_id` bigint NOT NULL COMMENT '来源事务事件ID,与用户ID共同保证通知幂等',
|
||||
`user_id` bigint NOT NULL COMMENT '用户ID,关联系统账号',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`work_item_id` bigint DEFAULT NULL COMMENT '关联工作项ID,无关联工作项时为空',
|
||||
`message` varchar(255) NOT NULL COMMENT '通知内容摘要',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
`iteration_id` bigint DEFAULT NULL COMMENT '所属迭代ID,项目级通知可为空',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_notice` (`event_id`,`user_id`),
|
||||
KEY `idx_pm_collab_notice_user` (`user_id`,`id`),
|
||||
KEY `idx_pm_collab_notice_iteration` (`project_id`,`iteration_id`,`user_id`,`id`),
|
||||
KEY `fk_pm_iter_notification_item` (`project_id`,`iteration_id`,`work_item_id`),
|
||||
KEY `fk_pm_iter_notice_event` (`project_id`,`iteration_id`,`event_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:成员通知';
|
||||
|
||||
-- 项目协作:事务事件发件箱
|
||||
CREATE TABLE `pm_collab_outbox` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`work_item_id` bigint DEFAULT NULL COMMENT '关联工作项ID,无关联工作项时为空',
|
||||
`event_type` varchar(40) NOT NULL COMMENT '事务事件类型',
|
||||
`payload` json NOT NULL COMMENT '已提交业务事件内容(JSON)',
|
||||
`attempts` int NOT NULL DEFAULT '0' COMMENT '通知投递失败后的重试次数',
|
||||
`next_attempt_at` bigint NOT NULL COMMENT '下次允许投递时间(UTC时间戳,微秒)',
|
||||
`delivered_at` bigint DEFAULT NULL COMMENT '成功投递时间(UTC时间戳,微秒;未投递为空)',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
`iteration_id` bigint DEFAULT NULL COMMENT '所属迭代ID,项目级事件可为空',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_outbox_iteration` (`project_id`,`iteration_id`,`id`),
|
||||
KEY `idx_pm_collab_outbox_pending` (`delivered_at`,`next_attempt_at`),
|
||||
KEY `fk_pm_iter_outbox_item` (`project_id`,`iteration_id`,`work_item_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:事务事件发件箱';
|
||||
|
||||
-- 项目协作:独立项目
|
||||
CREATE TABLE `pm_collab_project` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_code` varchar(64) NOT NULL COMMENT '独立协作项目编号,不关联项目列表编号',
|
||||
`project_name` varchar(200) NOT NULL COMMENT '独立协作项目名称',
|
||||
`manager_id` bigint NOT NULL COMMENT '项目经理用户ID',
|
||||
`version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,2已删除)',
|
||||
`create_by` varchar(64) NOT NULL COMMENT '创建人账号',
|
||||
`create_time` datetime(6) NOT NULL COMMENT '创建时间(日期时间,微秒精度)',
|
||||
`update_by` varchar(64) DEFAULT NULL COMMENT '最后更新人账号',
|
||||
`update_time` datetime(6) DEFAULT NULL COMMENT '最后更新时间(日期时间,微秒精度)',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_project_code` (`project_code`),
|
||||
KEY `manager_id` (`manager_id`),
|
||||
CONSTRAINT `ck_pm_collab_project_deleted` CHECK ((`del_flag` in (_utf8mb4'0',_utf8mb4'2')))
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:独立项目';
|
||||
|
||||
-- 项目协作:项目空间及创建人配置
|
||||
CREATE TABLE `pm_collab_project_config` (
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`space_id` bigint NOT NULL COMMENT '所属协作空间ID',
|
||||
`creator_id` bigint NOT NULL COMMENT '项目创建人用户ID,创建人专属维护权限依据',
|
||||
`timezone` varchar(64) NOT NULL DEFAULT 'Asia/Shanghai' COMMENT '历史时区兼容字段,当前界面统一使用北京时间',
|
||||
`version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
PRIMARY KEY (`project_id`),
|
||||
KEY `space_id` (`space_id`),
|
||||
KEY `creator_id` (`creator_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:项目空间及创建人配置';
|
||||
|
||||
-- 项目协作:项目事务互斥锁
|
||||
CREATE TABLE `pm_collab_project_lock` (
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID;写事务通过此行锁串行化跨记录校验',
|
||||
`graph_version` bigint NOT NULL DEFAULT '0' COMMENT '旧项目级图版本兼容字段,当前执行图版本存于迭代',
|
||||
PRIMARY KEY (`project_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:项目事务互斥锁';
|
||||
|
||||
-- 项目协作:项目成员
|
||||
CREATE TABLE `pm_collab_project_member` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`user_id` bigint NOT NULL COMMENT '用户ID,关联系统账号',
|
||||
`member_role` varchar(32) NOT NULL DEFAULT 'MEMBER' COMMENT '成员角色(MANAGER项目管理者,MEMBER普通成员)',
|
||||
`create_by` varchar(64) NOT NULL COMMENT '创建人账号',
|
||||
`create_time` datetime(6) NOT NULL COMMENT '创建时间(日期时间,微秒精度)',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_member` (`project_id`,`user_id`),
|
||||
KEY `idx_pm_collab_member_user` (`user_id`,`project_id`),
|
||||
CONSTRAINT `ck_pm_collab_member_role` CHECK ((`member_role` in (_utf8mb4'MANAGER',_utf8mb4'MEMBER')))
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:项目成员';
|
||||
|
||||
-- 项目协作:流程阶段
|
||||
CREATE TABLE `pm_collab_project_stage` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`name` varchar(120) NOT NULL COMMENT '阶段名称',
|
||||
`sort_order` int NOT NULL DEFAULT '0' COMMENT '展示排序值,不代表阶段执行依赖',
|
||||
`owner_id` bigint DEFAULT NULL COMMENT '阶段负责人用户ID,未分配时为空',
|
||||
`description` text COMMENT '详细说明',
|
||||
`version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
`deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,1已删除)',
|
||||
`created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
`current_revision_id` bigint DEFAULT NULL COMMENT '当前阶段执行版本ID,默认视图仅展示该版本',
|
||||
`iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_stage_project` (`project_id`,`id`),
|
||||
UNIQUE KEY `uk_pm_collab_stage_iteration` (`project_id`,`iteration_id`,`id`),
|
||||
KEY `idx_pm_collab_stage_list` (`project_id`,`deleted`,`sort_order`,`id`),
|
||||
KEY `owner_id` (`owner_id`),
|
||||
KEY `created_by` (`created_by`),
|
||||
KEY `fk_pm_collab_stage_current_revision` (`project_id`,`id`,`current_revision_id`),
|
||||
KEY `idx_pm_collab_stage_iteration_list` (`project_id`,`iteration_id`,`deleted`,`sort_order`,`id`),
|
||||
KEY `fk_pm_iter_stage_current` (`project_id`,`iteration_id`,`id`,`current_revision_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:流程阶段';
|
||||
|
||||
-- 项目协作:历史数据库升级记录
|
||||
CREATE TABLE `pm_collab_schema_migration` (
|
||||
`name` varchar(80) NOT NULL COMMENT '历史升级唯一标识',
|
||||
`applied_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '历史升级完成时间(数据库自动记录)',
|
||||
PRIMARY KEY (`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:历史数据库升级记录';
|
||||
|
||||
-- 项目协作:协作空间
|
||||
CREATE TABLE `pm_collab_space` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`name` varchar(120) NOT NULL COMMENT '空间名称',
|
||||
`owner_id` bigint NOT NULL COMMENT '空间创建人用户ID,创建人专属维护权限依据',
|
||||
`version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
`deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,1已删除)',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `owner_id` (`owner_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:协作空间';
|
||||
|
||||
-- 项目协作:阶段执行依赖连线
|
||||
CREATE TABLE `pm_collab_stage_edge` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`predecessor_stage_id` bigint NOT NULL COMMENT '前置阶段ID,其完成后解锁后续阶段',
|
||||
`successor_stage_id` bigint NOT NULL COMMENT '后续阶段ID,全部上游完成后才允许执行',
|
||||
`version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
`created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
`iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_stage_edge` (`project_id`,`predecessor_stage_id`,`successor_stage_id`),
|
||||
KEY `idx_pm_collab_stage_edge_successor` (`project_id`,`successor_stage_id`,`predecessor_stage_id`),
|
||||
KEY `idx_pm_collab_stage_edge_predecessor` (`project_id`,`predecessor_stage_id`,`successor_stage_id`),
|
||||
KEY `created_by` (`created_by`),
|
||||
KEY `fk_pm_iter_edge_pre` (`project_id`,`iteration_id`,`predecessor_stage_id`),
|
||||
KEY `fk_pm_iter_edge_next` (`project_id`,`iteration_id`,`successor_stage_id`),
|
||||
CONSTRAINT `ck_pm_collab_stage_edge_self` CHECK ((`predecessor_stage_id` <> `successor_stage_id`))
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:阶段执行依赖连线';
|
||||
|
||||
-- 项目协作:阶段执行版本
|
||||
CREATE TABLE `pm_collab_stage_revision` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`stage_id` bigint NOT NULL COMMENT '所属流程阶段ID',
|
||||
`revision_no` int NOT NULL COMMENT '阶段执行版本号,从1开始,回退后递增',
|
||||
`rework_id` bigint DEFAULT NULL COMMENT '创建本版本的回退事件ID,初始版本为空',
|
||||
`previous_revision_id` bigint DEFAULT NULL COMMENT '同阶段的上一执行版本ID',
|
||||
`flow_definition_revision_id` bigint DEFAULT NULL COMMENT '本版本首次执行时的执行图定义快照ID',
|
||||
`stage_name_snapshot` varchar(120) NOT NULL COMMENT '本执行版本的阶段名称快照',
|
||||
`stage_owner_snapshot` bigint DEFAULT NULL COMMENT '本执行版本的阶段负责人用户ID快照',
|
||||
`started_at` bigint DEFAULT NULL COMMENT '本版本首次执行时间(UTC时间戳,微秒)',
|
||||
`completed_at` bigint DEFAULT NULL COMMENT '本版本全部有效工作项完成或关闭的时间(UTC微秒)',
|
||||
`superseded_at` bigint DEFAULT NULL COMMENT '被新版本替代的时间(UTC微秒;当前版本为空)',
|
||||
`legacy_passed_at` bigint DEFAULT NULL COMMENT '历史迁移确认的空阶段兼容放行时间(UTC微秒)',
|
||||
`created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
`version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
`iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
`planned_start_at` bigint DEFAULT NULL COMMENT '预计开始时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
`planned_end_at` bigint DEFAULT NULL COMMENT '预计结束时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
`reference_planned_start_at` bigint DEFAULT NULL COMMENT '失效排期的原开始时间(UTC微秒),仅供复核参考',
|
||||
`reference_planned_end_at` bigint DEFAULT NULL COMMENT '失效排期的原结束时间(UTC微秒),仅供复核参考',
|
||||
`schedule_review_rework_id` bigint DEFAULT NULL COMMENT '导致排期待复核的回退事件ID,空值表示无需复核',
|
||||
`plan_source` varchar(20) DEFAULT NULL COMMENT '阶段计划来源(NORMAL正常排期,BACKFILLED完成后补录)',
|
||||
`plan_recorded_at` bigint DEFAULT NULL COMMENT '阶段计划最近登记时间(UTC时间戳,微秒)',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_stage_revision` (`project_id`,`stage_id`,`revision_no`),
|
||||
UNIQUE KEY `uk_pm_collab_stage_revision_reference` (`project_id`,`stage_id`,`id`),
|
||||
UNIQUE KEY `uk_pm_collab_revision_iteration` (`project_id`,`iteration_id`,`id`),
|
||||
UNIQUE KEY `uk_pm_collab_revision_stage_iteration` (`project_id`,`iteration_id`,`stage_id`,`id`),
|
||||
KEY `idx_pm_collab_stage_revision_rework` (`rework_id`),
|
||||
KEY `previous_revision_id` (`previous_revision_id`),
|
||||
KEY `flow_definition_revision_id` (`flow_definition_revision_id`),
|
||||
KEY `created_by` (`created_by`),
|
||||
KEY `fk_pm_iter_revision_previous` (`project_id`,`iteration_id`,`stage_id`,`previous_revision_id`),
|
||||
KEY `fk_pm_iter_revision_rework` (`project_id`,`iteration_id`,`rework_id`),
|
||||
KEY `fk_pm_iter_revision_definition` (`project_id`,`iteration_id`,`flow_definition_revision_id`),
|
||||
KEY `fk_pm_stage_schedule_review` (`project_id`,`iteration_id`,`schedule_review_rework_id`),
|
||||
CONSTRAINT `ck_pm_stage_schedule_pair` CHECK ((((`planned_start_at` is null) and (`planned_end_at` is null)) or ((`planned_start_at` is not null) and (`planned_end_at` is not null) and (`planned_end_at` >= `planned_start_at`))))
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:阶段执行版本';
|
||||
|
||||
-- 项目协作:阶段回退事件
|
||||
CREATE TABLE `pm_collab_stage_rework` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`source_stage_id` bigint NOT NULL COMMENT '发起回退的阶段ID',
|
||||
`target_stage_id` bigint NOT NULL COMMENT '回退目标上游阶段ID',
|
||||
`reason` varchar(2000) NOT NULL COMMENT '阶段回退原因',
|
||||
`idempotency_key` varchar(100) NOT NULL COMMENT '请求幂等键,避免重试重复执行业务',
|
||||
`preview_graph_version` bigint NOT NULL COMMENT '提交时确认的迭代执行图版本号',
|
||||
`impact_json` longtext NOT NULL COMMENT '回退影响范围和新旧版本对应关系(JSON)',
|
||||
`created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
`iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_rework_iteration` (`project_id`,`iteration_id`,`id`),
|
||||
UNIQUE KEY `uk_pm_collab_rework_request_scope` (`project_id`,`iteration_id`,`idempotency_key`),
|
||||
KEY `idx_pm_collab_rework_project` (`project_id`,`id`),
|
||||
KEY `project_id` (`project_id`,`source_stage_id`),
|
||||
KEY `project_id_2` (`project_id`,`target_stage_id`),
|
||||
KEY `created_by` (`created_by`),
|
||||
KEY `fk_pm_iter_rework_target` (`project_id`,`iteration_id`,`target_stage_id`),
|
||||
KEY `idx_pm_rework_edges` (`project_id`,`iteration_id`,`source_stage_id`,`target_stage_id`,`created_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:阶段回退事件';
|
||||
|
||||
-- 项目协作:工作项
|
||||
CREATE TABLE `pm_collab_work_item` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
`type` varchar(16) NOT NULL COMMENT '工作项类型(REQUIREMENT需求,TASK任务,BUG缺陷)',
|
||||
`title` varchar(200) NOT NULL COMMENT '工作项标题',
|
||||
`description` text COMMENT '详细说明',
|
||||
`assignee_id` bigint DEFAULT NULL COMMENT '负责人用户ID,未分配时为空',
|
||||
`priority` varchar(16) NOT NULL DEFAULT 'MEDIUM' COMMENT '优先级(LOW低,MEDIUM中,HIGH高,URGENT紧急)',
|
||||
`status` varchar(16) NOT NULL DEFAULT 'READY' COMMENT '生命周期(READY待开始,IN_PROGRESS进行中,COMPLETED已完成,CLOSED已关闭,CANCELLED已取消);超期实时计算',
|
||||
`planned_start_at` bigint DEFAULT NULL COMMENT '预计开始时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
`planned_end_at` bigint DEFAULT NULL COMMENT '预计结束时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
`actual_start_at` bigint DEFAULT NULL COMMENT '实际开始时间(UTC时间戳,微秒;尚未开始为空)',
|
||||
`actual_end_at` bigint DEFAULT NULL COMMENT '实际结束时间(UTC时间戳,微秒;尚未结束为空)',
|
||||
`stage_id` bigint DEFAULT NULL COMMENT '所属流程阶段ID',
|
||||
`parent_task_id` bigint DEFAULT NULL COMMENT '父任务ID,空值为顶层任务;仅支持一层子任务',
|
||||
`version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
`deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,1已删除)',
|
||||
`created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
`created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
`stage_revision_id` bigint DEFAULT NULL COMMENT '工作项所属阶段执行版本ID,历史版本保持只读',
|
||||
`origin_work_item_id` bigint DEFAULT NULL COMMENT '回退复制时的来源工作项ID,保留历史追溯关系',
|
||||
`schedule_review_rework_id` bigint DEFAULT NULL COMMENT '导致排期待复核的回退事件ID,空值表示无需复核',
|
||||
`iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
`reference_planned_start_at` bigint DEFAULT NULL COMMENT '失效排期的原开始时间(UTC微秒),仅供复核参考',
|
||||
`reference_planned_end_at` bigint DEFAULT NULL COMMENT '失效排期的原结束时间(UTC微秒),仅供复核参考',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_pm_collab_item_project` (`project_id`,`id`),
|
||||
UNIQUE KEY `uk_pm_collab_item_iteration` (`project_id`,`iteration_id`,`id`),
|
||||
KEY `idx_pm_collab_item_list` (`project_id`,`deleted`,`status`,`type`),
|
||||
KEY `idx_pm_collab_item_stage` (`project_id`,`stage_id`,`deleted`),
|
||||
KEY `idx_pm_collab_child` (`project_id`,`parent_task_id`,`deleted`),
|
||||
KEY `assignee_id` (`assignee_id`),
|
||||
KEY `fk_pm_collab_item_stage_revision` (`project_id`,`stage_id`,`stage_revision_id`),
|
||||
KEY `idx_pm_collab_item_iteration_list` (`project_id`,`iteration_id`,`deleted`,`status`,`type`,`id`),
|
||||
KEY `idx_pm_collab_item_iteration_parent` (`project_id`,`iteration_id`,`parent_task_id`,`deleted`,`id`),
|
||||
KEY `idx_pm_collab_item_iteration_stage` (`project_id`,`iteration_id`,`stage_id`,`deleted`,`id`),
|
||||
KEY `fk_pm_iter_item_revision` (`project_id`,`iteration_id`,`stage_id`,`stage_revision_id`),
|
||||
KEY `fk_pm_iter_item_origin` (`project_id`,`iteration_id`,`origin_work_item_id`),
|
||||
KEY `fk_pm_iter_item_review` (`project_id`,`iteration_id`,`schedule_review_rework_id`),
|
||||
CONSTRAINT `ck_pm_collab_item_dates` CHECK (((`planned_start_at` is null) or (`planned_end_at` is null) or (`planned_end_at` >= `planned_start_at`))),
|
||||
CONSTRAINT `ck_pm_collab_item_priority` CHECK ((`priority` in (_utf8mb4'LOW',_utf8mb4'MEDIUM',_utf8mb4'HIGH',_utf8mb4'URGENT'))),
|
||||
CONSTRAINT `ck_pm_collab_item_status` CHECK ((`status` in (_utf8mb4'READY',_utf8mb4'IN_PROGRESS',_utf8mb4'COMPLETED',_utf8mb4'CLOSED',_utf8mb4'CANCELLED'))),
|
||||
CONSTRAINT `ck_pm_collab_item_type` CHECK ((`type` in (_utf8mb4'REQUIREMENT',_utf8mb4'TASK',_utf8mb4'BUG')))
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='项目协作:工作项';
|
||||
|
||||
-- 外键完整性:与现有业务库保持相同的项目、迭代和历史版本约束。
|
||||
ALTER TABLE `pm_collab_attachment`
|
||||
ADD CONSTRAINT `pm_collab_attachment_ibfk_1` FOREIGN KEY (`work_item_id`) REFERENCES `pm_collab_work_item` (`id`);
|
||||
|
||||
ALTER TABLE `pm_collab_comment`
|
||||
ADD CONSTRAINT `pm_collab_comment_ibfk_1` FOREIGN KEY (`work_item_id`) REFERENCES `pm_collab_work_item` (`id`);
|
||||
|
||||
ALTER TABLE `pm_collab_dependency_condition`
|
||||
ADD CONSTRAINT `fk_pm_iter_dep_next` FOREIGN KEY (`project_id`, `iteration_id`, `successor_task_id`) REFERENCES `pm_collab_work_item` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_dep_pre` FOREIGN KEY (`project_id`, `iteration_id`, `predecessor_task_id`) REFERENCES `pm_collab_work_item` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_dependency_condition` FOREIGN KEY (`project_id`, `iteration_id`) REFERENCES `pm_collab_iteration` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_dependency_condition_ibfk_1` FOREIGN KEY (`project_id`, `successor_task_id`) REFERENCES `pm_collab_work_item` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_dependency_condition_ibfk_2` FOREIGN KEY (`project_id`, `predecessor_task_id`) REFERENCES `pm_collab_work_item` (`project_id`, `id`);
|
||||
|
||||
ALTER TABLE `pm_collab_flow_definition_revision`
|
||||
ADD CONSTRAINT `fk_pm_iter_flow_definition_revision` FOREIGN KEY (`project_id`, `iteration_id`) REFERENCES `pm_collab_iteration` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_flow_definition_revision_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `pm_collab_project` (`id`),
|
||||
ADD CONSTRAINT `pm_collab_flow_definition_revision_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `sys_user` (`user_id`);
|
||||
|
||||
ALTER TABLE `pm_collab_graph_layout`
|
||||
ADD CONSTRAINT `pm_collab_graph_layout_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `pm_collab_project` (`id`),
|
||||
ADD CONSTRAINT `pm_collab_graph_layout_ibfk_2` FOREIGN KEY (`updated_by`) REFERENCES `sys_user` (`user_id`);
|
||||
|
||||
ALTER TABLE `pm_collab_history`
|
||||
ADD CONSTRAINT `fk_pm_iter_history` FOREIGN KEY (`project_id`, `iteration_id`) REFERENCES `pm_collab_iteration` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_history_item` FOREIGN KEY (`project_id`, `iteration_id`, `work_item_id`) REFERENCES `pm_collab_work_item` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_history_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `pm_collab_project` (`id`);
|
||||
|
||||
ALTER TABLE `pm_collab_iteration`
|
||||
ADD CONSTRAINT `pm_collab_iteration_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `pm_collab_project` (`id`),
|
||||
ADD CONSTRAINT `pm_collab_iteration_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `sys_user` (`user_id`),
|
||||
ADD CONSTRAINT `pm_collab_iteration_ibfk_3` FOREIGN KEY (`updated_by`) REFERENCES `sys_user` (`user_id`),
|
||||
ADD CONSTRAINT `pm_collab_iteration_ibfk_4` FOREIGN KEY (`archived_by`) REFERENCES `sys_user` (`user_id`);
|
||||
|
||||
ALTER TABLE `pm_collab_iteration_request`
|
||||
ADD CONSTRAINT `pm_collab_iteration_request_ibfk_1` FOREIGN KEY (`project_id`, `iteration_id`) REFERENCES `pm_collab_iteration` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_iteration_request_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `sys_user` (`user_id`);
|
||||
|
||||
ALTER TABLE `pm_collab_notification`
|
||||
ADD CONSTRAINT `fk_pm_iter_notice_event` FOREIGN KEY (`project_id`, `iteration_id`, `event_id`) REFERENCES `pm_collab_outbox` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_notification` FOREIGN KEY (`project_id`, `iteration_id`) REFERENCES `pm_collab_iteration` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_notification_item` FOREIGN KEY (`project_id`, `iteration_id`, `work_item_id`) REFERENCES `pm_collab_work_item` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_notification_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `pm_collab_outbox` (`id`),
|
||||
ADD CONSTRAINT `pm_collab_notification_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `sys_user` (`user_id`),
|
||||
ADD CONSTRAINT `pm_collab_notification_ibfk_3` FOREIGN KEY (`project_id`) REFERENCES `pm_collab_project` (`id`);
|
||||
|
||||
ALTER TABLE `pm_collab_outbox`
|
||||
ADD CONSTRAINT `fk_pm_iter_outbox` FOREIGN KEY (`project_id`, `iteration_id`) REFERENCES `pm_collab_iteration` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_outbox_item` FOREIGN KEY (`project_id`, `iteration_id`, `work_item_id`) REFERENCES `pm_collab_work_item` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_outbox_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `pm_collab_project` (`id`);
|
||||
|
||||
ALTER TABLE `pm_collab_project`
|
||||
ADD CONSTRAINT `pm_collab_project_ibfk_1` FOREIGN KEY (`manager_id`) REFERENCES `sys_user` (`user_id`);
|
||||
|
||||
ALTER TABLE `pm_collab_project_config`
|
||||
ADD CONSTRAINT `pm_collab_project_config_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `pm_collab_project` (`id`),
|
||||
ADD CONSTRAINT `pm_collab_project_config_ibfk_2` FOREIGN KEY (`space_id`) REFERENCES `pm_collab_space` (`id`),
|
||||
ADD CONSTRAINT `pm_collab_project_config_ibfk_3` FOREIGN KEY (`creator_id`) REFERENCES `sys_user` (`user_id`);
|
||||
|
||||
ALTER TABLE `pm_collab_project_lock`
|
||||
ADD CONSTRAINT `pm_collab_project_lock_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `pm_collab_project` (`id`);
|
||||
|
||||
ALTER TABLE `pm_collab_project_member`
|
||||
ADD CONSTRAINT `pm_collab_project_member_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `pm_collab_project` (`id`),
|
||||
ADD CONSTRAINT `pm_collab_project_member_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `sys_user` (`user_id`);
|
||||
|
||||
ALTER TABLE `pm_collab_project_stage`
|
||||
ADD CONSTRAINT `fk_pm_collab_stage_current_revision` FOREIGN KEY (`project_id`, `id`, `current_revision_id`) REFERENCES `pm_collab_stage_revision` (`project_id`, `stage_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_project_stage` FOREIGN KEY (`project_id`, `iteration_id`) REFERENCES `pm_collab_iteration` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_stage_current` FOREIGN KEY (`project_id`, `iteration_id`, `id`, `current_revision_id`) REFERENCES `pm_collab_stage_revision` (`project_id`, `iteration_id`, `stage_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_project_stage_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `pm_collab_project` (`id`),
|
||||
ADD CONSTRAINT `pm_collab_project_stage_ibfk_2` FOREIGN KEY (`owner_id`) REFERENCES `sys_user` (`user_id`),
|
||||
ADD CONSTRAINT `pm_collab_project_stage_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `sys_user` (`user_id`);
|
||||
|
||||
ALTER TABLE `pm_collab_space`
|
||||
ADD CONSTRAINT `pm_collab_space_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `sys_user` (`user_id`);
|
||||
|
||||
ALTER TABLE `pm_collab_stage_edge`
|
||||
ADD CONSTRAINT `fk_pm_iter_edge_next` FOREIGN KEY (`project_id`, `iteration_id`, `successor_stage_id`) REFERENCES `pm_collab_project_stage` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_edge_pre` FOREIGN KEY (`project_id`, `iteration_id`, `predecessor_stage_id`) REFERENCES `pm_collab_project_stage` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_stage_edge` FOREIGN KEY (`project_id`, `iteration_id`) REFERENCES `pm_collab_iteration` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_stage_edge_ibfk_1` FOREIGN KEY (`project_id`, `predecessor_stage_id`) REFERENCES `pm_collab_project_stage` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_stage_edge_ibfk_2` FOREIGN KEY (`project_id`, `successor_stage_id`) REFERENCES `pm_collab_project_stage` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_stage_edge_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `sys_user` (`user_id`);
|
||||
|
||||
ALTER TABLE `pm_collab_stage_revision`
|
||||
ADD CONSTRAINT `fk_pm_iter_revision_definition` FOREIGN KEY (`project_id`, `iteration_id`, `flow_definition_revision_id`) REFERENCES `pm_collab_flow_definition_revision` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_revision_previous` FOREIGN KEY (`project_id`, `iteration_id`, `stage_id`, `previous_revision_id`) REFERENCES `pm_collab_stage_revision` (`project_id`, `iteration_id`, `stage_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_revision_rework` FOREIGN KEY (`project_id`, `iteration_id`, `rework_id`) REFERENCES `pm_collab_stage_rework` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_revision_stage` FOREIGN KEY (`project_id`, `iteration_id`, `stage_id`) REFERENCES `pm_collab_project_stage` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_stage_revision` FOREIGN KEY (`project_id`, `iteration_id`) REFERENCES `pm_collab_iteration` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_stage_schedule_review` FOREIGN KEY (`project_id`, `iteration_id`, `schedule_review_rework_id`) REFERENCES `pm_collab_stage_rework` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_stage_revision_ibfk_1` FOREIGN KEY (`project_id`, `stage_id`) REFERENCES `pm_collab_project_stage` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_stage_revision_ibfk_2` FOREIGN KEY (`rework_id`) REFERENCES `pm_collab_stage_rework` (`id`),
|
||||
ADD CONSTRAINT `pm_collab_stage_revision_ibfk_3` FOREIGN KEY (`previous_revision_id`) REFERENCES `pm_collab_stage_revision` (`id`),
|
||||
ADD CONSTRAINT `pm_collab_stage_revision_ibfk_4` FOREIGN KEY (`flow_definition_revision_id`) REFERENCES `pm_collab_flow_definition_revision` (`id`),
|
||||
ADD CONSTRAINT `pm_collab_stage_revision_ibfk_5` FOREIGN KEY (`created_by`) REFERENCES `sys_user` (`user_id`);
|
||||
|
||||
ALTER TABLE `pm_collab_stage_rework`
|
||||
ADD CONSTRAINT `fk_pm_iter_rework_source` FOREIGN KEY (`project_id`, `iteration_id`, `source_stage_id`) REFERENCES `pm_collab_project_stage` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_rework_target` FOREIGN KEY (`project_id`, `iteration_id`, `target_stage_id`) REFERENCES `pm_collab_project_stage` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_stage_rework` FOREIGN KEY (`project_id`, `iteration_id`) REFERENCES `pm_collab_iteration` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_stage_rework_ibfk_1` FOREIGN KEY (`project_id`, `source_stage_id`) REFERENCES `pm_collab_project_stage` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_stage_rework_ibfk_2` FOREIGN KEY (`project_id`, `target_stage_id`) REFERENCES `pm_collab_project_stage` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_stage_rework_ibfk_3` FOREIGN KEY (`created_by`) REFERENCES `sys_user` (`user_id`);
|
||||
|
||||
ALTER TABLE `pm_collab_work_item`
|
||||
ADD CONSTRAINT `fk_pm_collab_item_stage_revision` FOREIGN KEY (`project_id`, `stage_id`, `stage_revision_id`) REFERENCES `pm_collab_stage_revision` (`project_id`, `stage_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_item_origin` FOREIGN KEY (`project_id`, `iteration_id`, `origin_work_item_id`) REFERENCES `pm_collab_work_item` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_item_parent` FOREIGN KEY (`project_id`, `iteration_id`, `parent_task_id`) REFERENCES `pm_collab_work_item` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_item_review` FOREIGN KEY (`project_id`, `iteration_id`, `schedule_review_rework_id`) REFERENCES `pm_collab_stage_rework` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_item_revision` FOREIGN KEY (`project_id`, `iteration_id`, `stage_id`, `stage_revision_id`) REFERENCES `pm_collab_stage_revision` (`project_id`, `iteration_id`, `stage_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_item_stage` FOREIGN KEY (`project_id`, `iteration_id`, `stage_id`) REFERENCES `pm_collab_project_stage` (`project_id`, `iteration_id`, `id`),
|
||||
ADD CONSTRAINT `fk_pm_iter_work_item` FOREIGN KEY (`project_id`, `iteration_id`) REFERENCES `pm_collab_iteration` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_work_item_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `pm_collab_project` (`id`),
|
||||
ADD CONSTRAINT `pm_collab_work_item_ibfk_2` FOREIGN KEY (`assignee_id`) REFERENCES `sys_user` (`user_id`),
|
||||
ADD CONSTRAINT `pm_collab_work_item_ibfk_3` FOREIGN KEY (`project_id`, `stage_id`) REFERENCES `pm_collab_project_stage` (`project_id`, `id`),
|
||||
ADD CONSTRAINT `pm_collab_work_item_ibfk_4` FOREIGN KEY (`project_id`, `parent_task_id`) REFERENCES `pm_collab_work_item` (`project_id`, `id`);
|
||||
|
||||
-- 新安装直接具备历史版本全部结构,无旧数据需要回填;标记保持发布兼容。
|
||||
INSERT INTO pm_collab_schema_migration(name) VALUES
|
||||
('007_stage_execution_graph'),
|
||||
('008_stage_revisions'),
|
||||
('009_project_iterations'),
|
||||
('010_stage_schedules'),
|
||||
('010_stage_schedule_review_closure_v1');
|
||||
|
||||
-- 只注册协作菜单和动作权限,不授予角色,不关联项目列表。
|
||||
INSERT INTO sys_menu(menu_id,menu_name,parent_id,order_num,path,component,is_frame,is_cache,menu_type,visible,status,perms,icon,create_by,create_time)
|
||||
SELECT 2600,'项目协作',2100,2,'collaboration','project/manage/index',1,0,'C','0','0','project:manage:read','tree','admin',CURRENT_TIMESTAMP
|
||||
WHERE NOT EXISTS(SELECT 1 FROM sys_menu WHERE menu_id=2600);
|
||||
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 2601,'工作项维护',2600,1,'#',1,0,'F','0','0','project:manage:write','admin',CURRENT_TIMESTAMP
|
||||
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);
|
||||
301
ruoyi-project/sql/upgrade/011_collaboration_comments.sql
Normal file
301
ruoyi-project/sql/upgrade/011_collaboration_comments.sql
Normal file
@ -0,0 +1,301 @@
|
||||
-- target-database: cmvr-project-dev
|
||||
|
||||
-- 010 及复核闭包升级完成后,为当前 21 张协作表补齐中文注释。
|
||||
-- 执行前核对 pm_collab_schema_migration 包含010_stage_schedules及010_stage_schedule_review_closure_v1。
|
||||
-- 当前开发库已执行,无需重复安装建表文件。失败后关闭部署会话以恢复会话参数。
|
||||
-- 适用于本文档对应的完整列定义;结构不一致时停止并核对,不能套用旧类型覆盖新列。
|
||||
-- 每列保留原类型、空值、默认值和额外属性;仅 COMMENT 发生变化。
|
||||
-- DDL 自动提交,可重复执行;禁止删索引或关闭外键来强行继续。
|
||||
SET NAMES utf8mb4;
|
||||
SET @pm_comment_lock_wait_timeout = @@SESSION.lock_wait_timeout;
|
||||
SET SESSION lock_wait_timeout = 10;
|
||||
|
||||
-- 项目协作:工作项附件
|
||||
ALTER TABLE `pm_collab_attachment`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `work_item_id` bigint NOT NULL COMMENT '关联工作项ID',
|
||||
MODIFY COLUMN `name` varchar(255) NOT NULL COMMENT '附件原文件名',
|
||||
MODIFY COLUMN `media_type` varchar(120) NOT NULL COMMENT '附件媒体类型',
|
||||
MODIFY COLUMN `content` longblob NOT NULL COMMENT '附件二进制内容,需经项目权限校验后访问',
|
||||
MODIFY COLUMN `size` bigint NOT NULL COMMENT '附件大小(字节)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
COMMENT='项目协作:工作项附件', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:工作项评论
|
||||
ALTER TABLE `pm_collab_comment`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `work_item_id` bigint NOT NULL COMMENT '关联工作项ID',
|
||||
MODIFY COLUMN `body` text NOT NULL COMMENT '评论正文',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
COMMENT='项目协作:工作项评论', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:任务前置依赖条件
|
||||
ALTER TABLE `pm_collab_dependency_condition`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `successor_task_id` bigint NOT NULL COMMENT '受约束的后续任务ID',
|
||||
MODIFY COLUMN `condition_type` varchar(32) NOT NULL COMMENT '条件类型(TASK_COMPLETED:前置任务完成)',
|
||||
MODIFY COLUMN `predecessor_task_id` bigint NOT NULL COMMENT '前置任务ID',
|
||||
MODIFY COLUMN `expected_status` varchar(32) NOT NULL DEFAULT 'COMPLETED' COMMENT '目标状态(COMPLETED;业务判断已关闭也满足完成条件)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
COMMENT='项目协作:任务前置依赖条件', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:阶段执行图定义快照
|
||||
ALTER TABLE `pm_collab_flow_definition_revision`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `revision_no` bigint NOT NULL COMMENT '迭代内执行图定义版本号',
|
||||
MODIFY COLUMN `graph_json` longtext NOT NULL COMMENT '首次执行时冻结的阶段和连线快照(JSON)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
COMMENT='项目协作:阶段执行图定义快照', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:流程画布布局(历史兼容,当前视图不使用)
|
||||
ALTER TABLE `pm_collab_graph_layout`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `owner_id` bigint NOT NULL COMMENT '布局所属用户ID(0为旧共享布局),当前画布使用浏览器存储',
|
||||
MODIFY COLUMN `layout_json` json NOT NULL COMMENT '旧画布节点位置、折叠及视口数据(JSON)',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '1' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `updated_by` bigint NOT NULL COMMENT '最后更新人用户ID',
|
||||
MODIFY COLUMN `updated_at` bigint NOT NULL COMMENT '最后更新时间(UTC时间戳,微秒)',
|
||||
COMMENT='项目协作:流程画布布局(历史兼容,当前视图不使用)', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:操作历史
|
||||
ALTER TABLE `pm_collab_history`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `work_item_id` bigint DEFAULT NULL COMMENT '关联工作项ID,项目或阶段级操作可为空',
|
||||
MODIFY COLUMN `action` varchar(40) NOT NULL COMMENT '业务操作类型',
|
||||
MODIFY COLUMN `detail` json NOT NULL COMMENT '操作详情及变更记录(JSON)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `iteration_id` bigint DEFAULT NULL COMMENT '所属迭代ID,项目级历史可为空',
|
||||
COMMENT='项目协作:操作历史', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:项目迭代
|
||||
ALTER TABLE `pm_collab_iteration`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `iteration_code` varchar(64) NOT NULL COMMENT '项目内唯一的迭代编号',
|
||||
MODIFY COLUMN `name` varchar(200) NOT NULL COMMENT '迭代名称',
|
||||
MODIFY COLUMN `goal` text COMMENT '迭代目标',
|
||||
MODIFY COLUMN `status` varchar(16) NOT NULL DEFAULT 'PLANNED' COMMENT '迭代状态(PLANNED筹备,ACTIVE进行,FINISHED结束,CANCELLED取消)',
|
||||
MODIFY COLUMN `finish_result` varchar(24) DEFAULT NULL COMMENT '结束结果(COMPLETED正常完成,WITH_EXCEPTIONS含例外)',
|
||||
MODIFY COLUMN `finish_note` varchar(2000) DEFAULT NULL COMMENT '结束或取消的原因及例外说明',
|
||||
MODIFY COLUMN `planned_start_at` bigint DEFAULT NULL COMMENT '预计开始时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
MODIFY COLUMN `planned_end_at` bigint DEFAULT NULL COMMENT '预计结束时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
MODIFY COLUMN `actual_start_at` bigint DEFAULT NULL COMMENT '实际开始时间(UTC时间戳,微秒;尚未开始为空)',
|
||||
MODIFY COLUMN `actual_end_at` bigint DEFAULT NULL COMMENT '实际结束时间(UTC时间戳,微秒;尚未结束为空)',
|
||||
MODIFY COLUMN `sort_order` int NOT NULL DEFAULT '0' COMMENT '迭代展示排序值',
|
||||
MODIFY COLUMN `version` bigint NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `graph_version` bigint NOT NULL DEFAULT '0' COMMENT '执行图版本号,用于校验预览与提交的一致性',
|
||||
MODIFY COLUMN `archived_at` bigint DEFAULT NULL COMMENT '归档时间(UTC时间戳,微秒;未归档为空)',
|
||||
MODIFY COLUMN `archived_by` bigint DEFAULT NULL COMMENT '归档操作者用户ID',
|
||||
MODIFY COLUMN `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,1已删除)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `updated_by` bigint NOT NULL COMMENT '最后更新人用户ID',
|
||||
MODIFY COLUMN `updated_at` bigint NOT NULL COMMENT '最后更新时间(UTC时间戳,微秒)',
|
||||
COMMENT='项目协作:项目迭代', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:迭代操作幂等记录
|
||||
ALTER TABLE `pm_collab_iteration_request`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
MODIFY COLUMN `idempotency_key` varchar(100) NOT NULL COMMENT '请求幂等键,避免重试重复执行业务',
|
||||
MODIFY COLUMN `action` varchar(24) NOT NULL COMMENT '业务操作类型',
|
||||
MODIFY COLUMN `request_hash` char(64) NOT NULL COMMENT '请求参数的SHA-256摘要,防止同一幂等键被用于不同请求',
|
||||
MODIFY COLUMN `result_json` longtext NOT NULL COMMENT '已提交操作的响应快照(JSON),用于幂等重试返回',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
COMMENT='项目协作:迭代操作幂等记录', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:成员通知
|
||||
ALTER TABLE `pm_collab_notification`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `event_id` bigint NOT NULL COMMENT '来源事务事件ID,与用户ID共同保证通知幂等',
|
||||
MODIFY COLUMN `user_id` bigint NOT NULL COMMENT '用户ID,关联系统账号',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `work_item_id` bigint DEFAULT NULL COMMENT '关联工作项ID,无关联工作项时为空',
|
||||
MODIFY COLUMN `message` varchar(255) NOT NULL COMMENT '通知内容摘要',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `iteration_id` bigint DEFAULT NULL COMMENT '所属迭代ID,项目级通知可为空',
|
||||
COMMENT='项目协作:成员通知', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:事务事件发件箱
|
||||
ALTER TABLE `pm_collab_outbox`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `work_item_id` bigint DEFAULT NULL COMMENT '关联工作项ID,无关联工作项时为空',
|
||||
MODIFY COLUMN `event_type` varchar(40) NOT NULL COMMENT '事务事件类型',
|
||||
MODIFY COLUMN `payload` json NOT NULL COMMENT '已提交业务事件内容(JSON)',
|
||||
MODIFY COLUMN `attempts` int NOT NULL DEFAULT '0' COMMENT '通知投递失败后的重试次数',
|
||||
MODIFY COLUMN `next_attempt_at` bigint NOT NULL COMMENT '下次允许投递时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `delivered_at` bigint DEFAULT NULL COMMENT '成功投递时间(UTC时间戳,微秒;未投递为空)',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `iteration_id` bigint DEFAULT NULL COMMENT '所属迭代ID,项目级事件可为空',
|
||||
COMMENT='项目协作:事务事件发件箱', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:独立项目
|
||||
ALTER TABLE `pm_collab_project`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_code` varchar(64) NOT NULL COMMENT '独立协作项目编号,不关联项目列表编号',
|
||||
MODIFY COLUMN `project_name` varchar(200) NOT NULL COMMENT '独立协作项目名称',
|
||||
MODIFY COLUMN `manager_id` bigint NOT NULL COMMENT '项目经理用户ID',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,2已删除)',
|
||||
MODIFY COLUMN `create_by` varchar(64) NOT NULL COMMENT '创建人账号',
|
||||
MODIFY COLUMN `create_time` datetime(6) NOT NULL COMMENT '创建时间(日期时间,微秒精度)',
|
||||
MODIFY COLUMN `update_by` varchar(64) DEFAULT NULL COMMENT '最后更新人账号',
|
||||
MODIFY COLUMN `update_time` datetime(6) DEFAULT NULL COMMENT '最后更新时间(日期时间,微秒精度)',
|
||||
COMMENT='项目协作:独立项目', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:项目空间及创建人配置
|
||||
ALTER TABLE `pm_collab_project_config`
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `space_id` bigint NOT NULL COMMENT '所属协作空间ID',
|
||||
MODIFY COLUMN `creator_id` bigint NOT NULL COMMENT '项目创建人用户ID,创建人专属维护权限依据',
|
||||
MODIFY COLUMN `timezone` varchar(64) NOT NULL DEFAULT 'Asia/Shanghai' COMMENT '历史时区兼容字段,当前界面统一使用北京时间',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
COMMENT='项目协作:项目空间及创建人配置', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:项目事务互斥锁
|
||||
ALTER TABLE `pm_collab_project_lock`
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID;写事务通过此行锁串行化跨记录校验',
|
||||
MODIFY COLUMN `graph_version` bigint NOT NULL DEFAULT '0' COMMENT '旧项目级图版本兼容字段,当前执行图版本存于迭代',
|
||||
COMMENT='项目协作:项目事务互斥锁', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:项目成员
|
||||
ALTER TABLE `pm_collab_project_member`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `user_id` bigint NOT NULL COMMENT '用户ID,关联系统账号',
|
||||
MODIFY COLUMN `member_role` varchar(32) NOT NULL DEFAULT 'MEMBER' COMMENT '成员角色(MANAGER项目管理者,MEMBER普通成员)',
|
||||
MODIFY COLUMN `create_by` varchar(64) NOT NULL COMMENT '创建人账号',
|
||||
MODIFY COLUMN `create_time` datetime(6) NOT NULL COMMENT '创建时间(日期时间,微秒精度)',
|
||||
COMMENT='项目协作:项目成员', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:流程阶段
|
||||
ALTER TABLE `pm_collab_project_stage`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `name` varchar(120) NOT NULL COMMENT '阶段名称',
|
||||
MODIFY COLUMN `sort_order` int NOT NULL DEFAULT '0' COMMENT '展示排序值,不代表阶段执行依赖',
|
||||
MODIFY COLUMN `owner_id` bigint DEFAULT NULL COMMENT '阶段负责人用户ID,未分配时为空',
|
||||
MODIFY COLUMN `description` text COMMENT '详细说明',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,1已删除)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `current_revision_id` bigint DEFAULT NULL COMMENT '当前阶段执行版本ID,默认视图仅展示该版本',
|
||||
MODIFY COLUMN `iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
COMMENT='项目协作:流程阶段', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:历史数据库升级记录
|
||||
ALTER TABLE `pm_collab_schema_migration`
|
||||
MODIFY COLUMN `name` varchar(80) NOT NULL COMMENT '历史升级唯一标识',
|
||||
MODIFY COLUMN `applied_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '历史升级完成时间(数据库自动记录)',
|
||||
COMMENT='项目协作:历史数据库升级记录', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:协作空间
|
||||
ALTER TABLE `pm_collab_space`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `name` varchar(120) NOT NULL COMMENT '空间名称',
|
||||
MODIFY COLUMN `owner_id` bigint NOT NULL COMMENT '空间创建人用户ID,创建人专属维护权限依据',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,1已删除)',
|
||||
COMMENT='项目协作:协作空间', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:阶段执行依赖连线
|
||||
ALTER TABLE `pm_collab_stage_edge`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `predecessor_stage_id` bigint NOT NULL COMMENT '前置阶段ID,其完成后解锁后续阶段',
|
||||
MODIFY COLUMN `successor_stage_id` bigint NOT NULL COMMENT '后续阶段ID,全部上游完成后才允许执行',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
COMMENT='项目协作:阶段执行依赖连线', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:阶段执行版本
|
||||
ALTER TABLE `pm_collab_stage_revision`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `stage_id` bigint NOT NULL COMMENT '所属流程阶段ID',
|
||||
MODIFY COLUMN `revision_no` int NOT NULL COMMENT '阶段执行版本号,从1开始,回退后递增',
|
||||
MODIFY COLUMN `rework_id` bigint DEFAULT NULL COMMENT '创建本版本的回退事件ID,初始版本为空',
|
||||
MODIFY COLUMN `previous_revision_id` bigint DEFAULT NULL COMMENT '同阶段的上一执行版本ID',
|
||||
MODIFY COLUMN `flow_definition_revision_id` bigint DEFAULT NULL COMMENT '本版本首次执行时的执行图定义快照ID',
|
||||
MODIFY COLUMN `stage_name_snapshot` varchar(120) NOT NULL COMMENT '本执行版本的阶段名称快照',
|
||||
MODIFY COLUMN `stage_owner_snapshot` bigint DEFAULT NULL COMMENT '本执行版本的阶段负责人用户ID快照',
|
||||
MODIFY COLUMN `started_at` bigint DEFAULT NULL COMMENT '本版本首次执行时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `completed_at` bigint DEFAULT NULL COMMENT '本版本全部有效工作项完成或关闭的时间(UTC微秒)',
|
||||
MODIFY COLUMN `superseded_at` bigint DEFAULT NULL COMMENT '被新版本替代的时间(UTC微秒;当前版本为空)',
|
||||
MODIFY COLUMN `legacy_passed_at` bigint DEFAULT NULL COMMENT '历史迁移确认的空阶段兼容放行时间(UTC微秒)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
MODIFY COLUMN `planned_start_at` bigint DEFAULT NULL COMMENT '预计开始时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
MODIFY COLUMN `planned_end_at` bigint DEFAULT NULL COMMENT '预计结束时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
MODIFY COLUMN `reference_planned_start_at` bigint DEFAULT NULL COMMENT '失效排期的原开始时间(UTC微秒),仅供复核参考',
|
||||
MODIFY COLUMN `reference_planned_end_at` bigint DEFAULT NULL COMMENT '失效排期的原结束时间(UTC微秒),仅供复核参考',
|
||||
MODIFY COLUMN `schedule_review_rework_id` bigint DEFAULT NULL COMMENT '导致排期待复核的回退事件ID,空值表示无需复核',
|
||||
MODIFY COLUMN `plan_source` varchar(20) DEFAULT NULL COMMENT '阶段计划来源(NORMAL正常排期,BACKFILLED完成后补录)',
|
||||
MODIFY COLUMN `plan_recorded_at` bigint DEFAULT NULL COMMENT '阶段计划最近登记时间(UTC时间戳,微秒)',
|
||||
COMMENT='项目协作:阶段执行版本', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:阶段回退事件
|
||||
ALTER TABLE `pm_collab_stage_rework`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `source_stage_id` bigint NOT NULL COMMENT '发起回退的阶段ID',
|
||||
MODIFY COLUMN `target_stage_id` bigint NOT NULL COMMENT '回退目标上游阶段ID',
|
||||
MODIFY COLUMN `reason` varchar(2000) NOT NULL COMMENT '阶段回退原因',
|
||||
MODIFY COLUMN `idempotency_key` varchar(100) NOT NULL COMMENT '请求幂等键,避免重试重复执行业务',
|
||||
MODIFY COLUMN `preview_graph_version` bigint NOT NULL COMMENT '提交时确认的迭代执行图版本号',
|
||||
MODIFY COLUMN `impact_json` longtext NOT NULL COMMENT '回退影响范围和新旧版本对应关系(JSON)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
COMMENT='项目协作:阶段回退事件', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 项目协作:工作项
|
||||
ALTER TABLE `pm_collab_work_item`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '独立协作项目ID',
|
||||
MODIFY COLUMN `type` varchar(16) NOT NULL COMMENT '工作项类型(REQUIREMENT需求,TASK任务,BUG缺陷)',
|
||||
MODIFY COLUMN `title` varchar(200) NOT NULL COMMENT '工作项标题',
|
||||
MODIFY COLUMN `description` text COMMENT '详细说明',
|
||||
MODIFY COLUMN `assignee_id` bigint DEFAULT NULL COMMENT '负责人用户ID,未分配时为空',
|
||||
MODIFY COLUMN `priority` varchar(16) NOT NULL DEFAULT 'MEDIUM' COMMENT '优先级(LOW低,MEDIUM中,HIGH高,URGENT紧急)',
|
||||
MODIFY COLUMN `status` varchar(16) NOT NULL DEFAULT 'READY' COMMENT '生命周期(READY待开始,IN_PROGRESS进行中,COMPLETED已完成,CLOSED已关闭,CANCELLED已取消);超期实时计算',
|
||||
MODIFY COLUMN `planned_start_at` bigint DEFAULT NULL COMMENT '预计开始时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
MODIFY COLUMN `planned_end_at` bigint DEFAULT NULL COMMENT '预计结束时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
MODIFY COLUMN `actual_start_at` bigint DEFAULT NULL COMMENT '实际开始时间(UTC时间戳,微秒;尚未开始为空)',
|
||||
MODIFY COLUMN `actual_end_at` bigint DEFAULT NULL COMMENT '实际结束时间(UTC时间戳,微秒;尚未结束为空)',
|
||||
MODIFY COLUMN `stage_id` bigint DEFAULT NULL COMMENT '所属流程阶段ID',
|
||||
MODIFY COLUMN `parent_task_id` bigint DEFAULT NULL COMMENT '父任务ID,空值为顶层任务;仅支持一层子任务',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,1已删除)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `stage_revision_id` bigint DEFAULT NULL COMMENT '工作项所属阶段执行版本ID,历史版本保持只读',
|
||||
MODIFY COLUMN `origin_work_item_id` bigint DEFAULT NULL COMMENT '回退复制时的来源工作项ID,保留历史追溯关系',
|
||||
MODIFY COLUMN `schedule_review_rework_id` bigint DEFAULT NULL COMMENT '导致排期待复核的回退事件ID,空值表示无需复核',
|
||||
MODIFY COLUMN `iteration_id` bigint NOT NULL COMMENT '所属迭代ID,复合外键隔离迭代数据',
|
||||
MODIFY COLUMN `reference_planned_start_at` bigint DEFAULT NULL COMMENT '失效排期的原开始时间(UTC微秒),仅供复核参考',
|
||||
MODIFY COLUMN `reference_planned_end_at` bigint DEFAULT NULL COMMENT '失效排期的原结束时间(UTC微秒),仅供复核参考',
|
||||
COMMENT='项目协作:工作项', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
SET SESSION lock_wait_timeout = @pm_comment_lock_wait_timeout;
|
||||
205
ruoyi-project/sql/upgrade/012_legacy_collaboration_comments.sql
Normal file
205
ruoyi-project/sql/upgrade/012_legacy_collaboration_comments.sql
Normal file
@ -0,0 +1,205 @@
|
||||
-- target-database: cmvr-project-dev
|
||||
|
||||
-- 可选:仅为保留全部 17 张旧 pm_* 表的库补齐历史用途注释;新安装不执行。
|
||||
-- 仅保留部分旧表时,核对定义后只执行对应表的语句;不要为补注释创建已停用表。
|
||||
-- 当前开发库已执行;此文件不恢复旧业务读写。失败后关闭部署会话以恢复会话参数。
|
||||
-- 适用于本文档对应的完整列定义;结构不一致时停止并核对,不能套用旧类型覆盖新列。
|
||||
-- 每列保留原类型、空值、默认值和额外属性;仅 COMMENT 发生变化。
|
||||
-- DDL 自动提交,可重复执行;禁止删索引或关闭外键来强行继续。
|
||||
SET NAMES utf8mb4;
|
||||
SET @pm_comment_lock_wait_timeout = @@SESSION.lock_wait_timeout;
|
||||
SET SESSION lock_wait_timeout = 10;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):工作项附件
|
||||
ALTER TABLE `pm_attachment`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `work_item_id` bigint NOT NULL COMMENT '关联工作项ID',
|
||||
MODIFY COLUMN `name` varchar(255) NOT NULL COMMENT '附件原文件名',
|
||||
MODIFY COLUMN `media_type` varchar(120) NOT NULL COMMENT '附件媒体类型',
|
||||
MODIFY COLUMN `content` longblob NOT NULL COMMENT '附件二进制内容,需经项目权限校验后访问',
|
||||
MODIFY COLUMN `size` bigint NOT NULL COMMENT '附件大小(字节)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):工作项附件', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):工作项评论
|
||||
ALTER TABLE `pm_comment`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `work_item_id` bigint NOT NULL COMMENT '关联工作项ID',
|
||||
MODIFY COLUMN `body` text NOT NULL COMMENT '评论正文',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):工作项评论', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):任务前置依赖条件
|
||||
ALTER TABLE `pm_dependency_condition`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `successor_task_id` bigint NOT NULL COMMENT '受约束的后续任务ID',
|
||||
MODIFY COLUMN `condition_type` varchar(32) NOT NULL COMMENT '旧条件类型(TASK_COMPLETED任务完成,NODE_STATUS_EQUALS节点状态相等)',
|
||||
MODIFY COLUMN `predecessor_task_id` bigint DEFAULT NULL COMMENT '前置任务ID',
|
||||
MODIFY COLUMN `predecessor_node_id` bigint DEFAULT NULL COMMENT '旧前置节点实例ID,节点依赖已停用',
|
||||
MODIFY COLUMN `expected_status` varchar(32) NOT NULL COMMENT '旧依赖条件配置的目标状态',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):任务前置依赖条件', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):流程模板
|
||||
ALTER TABLE `pm_flow`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `name` varchar(120) NOT NULL COMMENT '旧流程模板名称',
|
||||
MODIFY COLUMN `require_assignee` tinyint(1) NOT NULL DEFAULT '1' COMMENT '旧流程开始时是否必须设置负责人',
|
||||
MODIFY COLUMN `require_description` tinyint(1) NOT NULL DEFAULT '0' COMMENT '旧流程开始时是否必须填写描述',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):流程模板', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):流程模板节点
|
||||
ALTER TABLE `pm_flow_node`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `flow_id` bigint NOT NULL COMMENT '旧流程模板ID',
|
||||
MODIFY COLUMN `name` varchar(120) NOT NULL COMMENT '旧模板节点名称',
|
||||
MODIFY COLUMN `sort_order` int NOT NULL COMMENT '展示排序值,不代表阶段执行依赖',
|
||||
MODIFY COLUMN `allowed_states` json NOT NULL COMMENT '旧节点允许的状态集合(JSON)',
|
||||
MODIFY COLUMN `terminal_states` json NOT NULL COMMENT '允许的终态集合(JSON)',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):流程模板节点', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):流程画布布局(历史兼容,当前视图不使用)
|
||||
ALTER TABLE `pm_graph_layout`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `owner_id` bigint NOT NULL COMMENT '布局所属用户ID(0为旧共享布局),当前画布使用浏览器存储',
|
||||
MODIFY COLUMN `layout_json` json NOT NULL COMMENT '旧画布节点位置、折叠及视口数据(JSON)',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '1' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `updated_by` bigint NOT NULL COMMENT '最后更新人用户ID',
|
||||
MODIFY COLUMN `updated_at` bigint NOT NULL COMMENT '最后更新时间(UTC时间戳,微秒)',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):流程画布布局(历史兼容,当前视图不使用)', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):操作历史
|
||||
ALTER TABLE `pm_history`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `work_item_id` bigint DEFAULT NULL COMMENT '关联工作项ID,项目或阶段级操作可为空',
|
||||
MODIFY COLUMN `action` varchar(40) NOT NULL COMMENT '业务操作类型',
|
||||
MODIFY COLUMN `detail` json NOT NULL COMMENT '操作详情及变更记录(JSON)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):操作历史', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):工作项节点实例
|
||||
ALTER TABLE `pm_node_instance`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `work_item_id` bigint NOT NULL COMMENT '关联工作项ID',
|
||||
MODIFY COLUMN `name` varchar(120) NOT NULL COMMENT '旧工作项节点实例名称',
|
||||
MODIFY COLUMN `sort_order` int NOT NULL COMMENT '展示排序值,不代表阶段执行依赖',
|
||||
MODIFY COLUMN `status` varchar(32) NOT NULL DEFAULT 'READY' COMMENT '旧节点实例的当前状态',
|
||||
MODIFY COLUMN `terminal_states` json NOT NULL COMMENT '允许的终态集合(JSON)',
|
||||
MODIFY COLUMN `planned_start_at` bigint DEFAULT NULL COMMENT '预计开始时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
MODIFY COLUMN `planned_end_at` bigint DEFAULT NULL COMMENT '预计结束时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,1已删除)',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):工作项节点实例', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):节点允许状态
|
||||
ALTER TABLE `pm_node_state`
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `node_id` bigint NOT NULL COMMENT '旧节点实例ID',
|
||||
MODIFY COLUMN `status` varchar(32) NOT NULL COMMENT '旧节点实例允许的单个状态值',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):节点允许状态', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):节点推进前置任务
|
||||
ALTER TABLE `pm_node_task_prerequisite`
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `node_id` bigint NOT NULL COMMENT '旧节点实例ID',
|
||||
MODIFY COLUMN `task_id` bigint NOT NULL COMMENT '前置任务ID',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):节点推进前置任务', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):成员通知
|
||||
ALTER TABLE `pm_notification`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `event_id` bigint NOT NULL COMMENT '来源事务事件ID,与用户ID共同保证通知幂等',
|
||||
MODIFY COLUMN `user_id` bigint NOT NULL COMMENT '用户ID,关联系统账号',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `work_item_id` bigint DEFAULT NULL COMMENT '关联工作项ID,无关联工作项时为空',
|
||||
MODIFY COLUMN `message` varchar(255) NOT NULL COMMENT '通知内容摘要',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):成员通知', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):事务事件发件箱
|
||||
ALTER TABLE `pm_outbox`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `work_item_id` bigint DEFAULT NULL COMMENT '关联工作项ID,无关联工作项时为空',
|
||||
MODIFY COLUMN `event_type` varchar(40) NOT NULL COMMENT '事务事件类型',
|
||||
MODIFY COLUMN `payload` json NOT NULL COMMENT '已提交业务事件内容(JSON)',
|
||||
MODIFY COLUMN `attempts` int NOT NULL DEFAULT '0' COMMENT '通知投递失败后的重试次数',
|
||||
MODIFY COLUMN `next_attempt_at` bigint NOT NULL COMMENT '下次允许投递时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `delivered_at` bigint DEFAULT NULL COMMENT '成功投递时间(UTC时间戳,微秒;未投递为空)',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):事务事件发件箱', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):项目空间及创建人配置
|
||||
ALTER TABLE `pm_project_config`
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `space_id` bigint NOT NULL COMMENT '所属协作空间ID',
|
||||
MODIFY COLUMN `timezone` varchar(64) NOT NULL DEFAULT 'Asia/Shanghai' COMMENT '历史时区兼容字段,当前界面统一使用北京时间',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `creator_id` bigint DEFAULT NULL COMMENT '项目创建人用户ID,创建人专属维护权限依据',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):项目空间及创建人配置', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):项目事务互斥锁
|
||||
ALTER TABLE `pm_project_lock`
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):项目事务互斥锁', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):流程阶段
|
||||
ALTER TABLE `pm_project_stage`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `name` varchar(120) NOT NULL COMMENT '阶段名称',
|
||||
MODIFY COLUMN `sort_order` int NOT NULL DEFAULT '0' COMMENT '展示排序值,不代表阶段执行依赖',
|
||||
MODIFY COLUMN `owner_id` bigint DEFAULT NULL COMMENT '阶段负责人用户ID,未分配时为空',
|
||||
MODIFY COLUMN `description` text COMMENT '详细说明',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,1已删除)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):流程阶段', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):协作空间
|
||||
ALTER TABLE `pm_space`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `name` varchar(120) NOT NULL COMMENT '空间名称',
|
||||
MODIFY COLUMN `owner_id` bigint NOT NULL COMMENT '空间创建人用户ID,创建人专属维护权限依据',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,1已删除)',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):协作空间', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
-- 旧项目协作(已停用,保留历史数据):工作项
|
||||
ALTER TABLE `pm_work_item`
|
||||
MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
MODIFY COLUMN `project_id` bigint NOT NULL COMMENT '旧协作项目引用,停用后不再参与当前项目协作',
|
||||
MODIFY COLUMN `type` varchar(16) NOT NULL COMMENT '工作项类型(REQUIREMENT需求,TASK任务,BUG缺陷)',
|
||||
MODIFY COLUMN `title` varchar(200) NOT NULL COMMENT '工作项标题',
|
||||
MODIFY COLUMN `description` text COMMENT '详细说明',
|
||||
MODIFY COLUMN `assignee_id` bigint DEFAULT NULL COMMENT '负责人用户ID,未分配时为空',
|
||||
MODIFY COLUMN `priority` varchar(16) NOT NULL DEFAULT 'MEDIUM' COMMENT '优先级(LOW低,MEDIUM中,HIGH高,URGENT紧急)',
|
||||
MODIFY COLUMN `status` varchar(16) NOT NULL DEFAULT 'READY' COMMENT '生命周期(READY待开始,IN_PROGRESS进行中,COMPLETED已完成,CLOSED已关闭,CANCELLED已取消);超期实时计算',
|
||||
MODIFY COLUMN `flow_id` bigint DEFAULT NULL COMMENT '旧流程模板ID',
|
||||
MODIFY COLUMN `planned_start_at` bigint DEFAULT NULL COMMENT '预计开始时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
MODIFY COLUMN `planned_end_at` bigint DEFAULT NULL COMMENT '预计结束时间(UTC时间戳,微秒;空值表示未排期)',
|
||||
MODIFY COLUMN `actual_start_at` bigint DEFAULT NULL COMMENT '实际开始时间(UTC时间戳,微秒;尚未开始为空)',
|
||||
MODIFY COLUMN `actual_end_at` bigint DEFAULT NULL COMMENT '实际结束时间(UTC时间戳,微秒;尚未结束为空)',
|
||||
MODIFY COLUMN `version` int NOT NULL DEFAULT '0' COMMENT '乐观锁版本号,更新时校验并递增',
|
||||
MODIFY COLUMN `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '软删除标志(0正常,1已删除)',
|
||||
MODIFY COLUMN `created_by` bigint NOT NULL COMMENT '创建人用户ID',
|
||||
MODIFY COLUMN `created_at` bigint NOT NULL COMMENT '创建时间(UTC时间戳,微秒)',
|
||||
MODIFY COLUMN `stage_id` bigint DEFAULT NULL COMMENT '所属流程阶段ID',
|
||||
MODIFY COLUMN `parent_task_id` bigint DEFAULT NULL COMMENT '父任务ID,空值为顶层任务;仅支持一层子任务',
|
||||
COMMENT='旧项目协作(已停用,保留历史数据):工作项', ALGORITHM=INPLACE, LOCK=NONE;
|
||||
|
||||
SET SESSION lock_wait_timeout = @pm_comment_lock_wait_timeout;
|
||||
@ -0,0 +1,24 @@
|
||||
package com.ruoyi.project.manage.config;
|
||||
|
||||
import jakarta.servlet.http.*;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.*;
|
||||
import org.springframework.web.servlet.config.annotation.*;
|
||||
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
|
||||
|
||||
/** 限定本模块不存在路由的响应,不让旧全局异常处理将静态资源兜底错误包装成 HTTP 200。 */
|
||||
@Configuration(proxyBeanMethods=false)
|
||||
public class PmRoutes implements WebMvcConfigurer {
|
||||
/** 仅注册模块路径,真实业务方法继续使用服务鉴权和原有异常处理。 */
|
||||
@Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new MissingRoute()).addPathPatterns("/project/manage/**"); }
|
||||
|
||||
/** Spring 把未知 API 落入静态资源处理器时,终止兜底解析并返回不泄露路径细节的 404。 */
|
||||
public static class MissingRoute implements HandlerInterceptor {
|
||||
/** 仅处理资源兜底;真正的 Controller 不受影响,也不恢复已移除的流程/节点入口。 */
|
||||
@Override public boolean preHandle(HttpServletRequest request,HttpServletResponse response,Object handler) throws Exception {
|
||||
if(!(handler instanceof ResourceHttpRequestHandler)) return true;
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"code\":\"NOT_FOUND\",\"message\":\"接口不存在\"}"); return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.ruoyi.project.manage.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/** 仅启用 Spring outbox 注解调度,不更改原 Quartz 任务及启动策略。 */
|
||||
@Configuration(proxyBeanMethods=false)
|
||||
@EnableScheduling
|
||||
public class PmSchedulingConfig { }
|
||||
@ -0,0 +1,145 @@
|
||||
package com.ruoyi.project.manage.controller;
|
||||
|
||||
import com.ruoyi.project.manage.dto.BatchInput;
|
||||
import com.ruoyi.project.manage.dto.ChildInput;
|
||||
import com.ruoyi.project.manage.dto.CommentInput;
|
||||
import com.ruoyi.project.manage.dto.ConfigInput;
|
||||
import com.ruoyi.project.manage.dto.DependencyInput;
|
||||
import com.ruoyi.project.manage.dto.ItemInput;
|
||||
import com.ruoyi.project.manage.dto.MemberInput;
|
||||
import com.ruoyi.project.manage.dto.NameInput;
|
||||
import com.ruoyi.project.manage.dto.ProjectEditInput;
|
||||
import com.ruoyi.project.manage.dto.ProjectInput;
|
||||
import com.ruoyi.project.manage.dto.ScheduleInput;
|
||||
import com.ruoyi.project.manage.dto.SpaceInput;
|
||||
import com.ruoyi.project.manage.dto.TransitionInput;
|
||||
import com.ruoyi.project.manage.dto.VersionInput;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.service.IPmService;
|
||||
import com.ruoyi.project.manage.dto.ItemQuery;
|
||||
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/** REST 适配层不直接更新状态;动作鉴权、版本与事务规则统一在服务中执行。 */
|
||||
@RestController
|
||||
@RequestMapping("/project/manage")
|
||||
public class PmController {
|
||||
private final IPmService service;
|
||||
private final ObjectMapper strict;
|
||||
/** 独立严格解码器拒绝未知字段,避免普通编辑注入 status/actualStartAt 绕过开始规则。 */
|
||||
public PmController(IPmService service,ObjectMapper mapper) { this.service=service; this.strict=mapper.copy().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).disable(DeserializationFeature.ACCEPT_FLOAT_AS_INT); }
|
||||
|
||||
/** 返回当前用户参与的项目,避免前端调用原有全项目列表。 */
|
||||
@GetMapping("/projects") public Map<String,Object> projects() { return ok(service.projects()); }
|
||||
/** 创建项目,创建者成为经理;具体权限由服务验证。 */
|
||||
@PostMapping("/projects") public Map<String,Object> project(@RequestBody JsonNode body) { return ok(service.createProject(decode(body,ProjectInput.class))); }
|
||||
/** 返回可见空间,不向所有用户公开空间列表。 */
|
||||
@GetMapping("/spaces") public Map<String,Object> spaces() { return ok(service.spaces()); }
|
||||
/** 创建自己的空间,保留可管理的所有者身份。 */
|
||||
@PostMapping("/spaces") public Map<String,Object> space(@RequestBody JsonNode body) { return ok(service.createSpace(decode(body,SpaceInput.class))); }
|
||||
/** 仅创建人可改空间名称,版本防止覆盖他人的已保存内容。 */
|
||||
@PatchMapping("/spaces/{id}") public Map<String,Object> editSpace(@PathVariable long id,@RequestBody JsonNode body) { service.editSpace(id,decode(body,NameInput.class)); return ok(null); }
|
||||
/** 非空空间禁止软删除,保留原记录供历史关联使用。 */
|
||||
@DeleteMapping("/spaces/{id}") public Map<String,Object> deleteSpace(@PathVariable long id,@RequestBody JsonNode body) { service.deleteSpace(id,decode(body,VersionInput.class)); return ok(null); }
|
||||
/** 项目名称、空间归属统一由创建人维护,不接收时区或创建人字段。 */
|
||||
@PatchMapping("/projects/{id}") public Map<String,Object> editProject(@PathVariable long id,@RequestBody JsonNode body) { service.editProject(id,decode(body,ProjectEditInput.class)); return ok(null); }
|
||||
/** 项目软删除保留内容,但所有后续访问即时重新鉴权。 */
|
||||
@DeleteMapping("/projects/{id}") public Map<String,Object> deleteProject(@PathVariable long id,@RequestBody JsonNode body) { service.deleteProject(id,decode(body,VersionInput.class)); return ok(null); }
|
||||
/** 只修改现有独立协作项目的空间配置,不支持关联或导入项目列表中的项目。 */
|
||||
@PatchMapping("/projects/{id}/config") public Map<String,Object> config(@PathVariable long id,@RequestBody JsonNode body) { service.configure(id,decode(body,ConfigInput.class)); return ok(null); }
|
||||
/** 返回本项目有效成员与项目经理,供负责人选择。 */
|
||||
@GetMapping("/projects/{id}/members") public Map<String,Object> members(@PathVariable long id) { return ok(service.members(id)); }
|
||||
/** 经理按昵称搜索可加入的用户,只返回非敏感字段。 */
|
||||
@GetMapping("/projects/{id}/member-candidates") public Map<String,Object> candidates(@PathVariable long id,@RequestParam(defaultValue="") String keyword) { return ok(service.candidateUsers(id,keyword)); }
|
||||
/** 添加成员或修改角色,服务保护项目负责人资格。 */
|
||||
@PostMapping("/projects/{id}/members") public Map<String,Object> member(@PathVariable long id,@RequestBody JsonNode body) { service.member(id,decode(body,MemberInput.class),false); return ok(null); }
|
||||
/** 移除成员前重新校验经理权限及现有分配。 */
|
||||
@DeleteMapping("/projects/{id}/members/{userId}") public Map<String,Object> removeMember(@PathVariable long id,@PathVariable long userId) { service.member(id,new MemberInput(userId,null),true); return ok(null); }
|
||||
/** 统一工作项列表包含后端计算的依赖阻塞和排期状态。 */
|
||||
@GetMapping("/projects/{id}/items") public Map<String,Object> items(@PathVariable long id) { return ok(service.items(id)); }
|
||||
/** 创建需求、任务或缺陷,初始生命周期由后端固定。 */
|
||||
@PostMapping("/projects/{id}/items") public Map<String,Object> create(@PathVariable long id,@RequestBody JsonNode body) { return ok(service.create(id,decode(body,ItemInput.class))); }
|
||||
/** 返回指定迭代的视图页;父子上下文、状态总数和窗口条件均由服务端统一计算。 */
|
||||
@GetMapping("/projects/{id}/iterations/{iterationId}/items")
|
||||
public Map<String,Object> itemPage(@PathVariable long id,@PathVariable long iterationId,
|
||||
@RequestParam(defaultValue="1") int page,@RequestParam(defaultValue="50") int pageSize,
|
||||
@RequestParam(defaultValue="flat") String view,@RequestParam(required=false) String keyword,
|
||||
@RequestParam(required=false) String type,@RequestParam(required=false) String status,
|
||||
@RequestParam(required=false) Boolean blockedOnly,@RequestParam(required=false) Long stageId,
|
||||
@RequestParam(required=false) String from,@RequestParam(required=false) String to) {
|
||||
return ok(service.itemPage(id,iterationId,new ItemQuery(page,pageSize,view,keyword,type,status,blockedOnly,stageId,from,to)));
|
||||
}
|
||||
/** 工作项必须明确归属迭代,普通 DTO 不接收客户端指定状态或归属变更。 */
|
||||
@PostMapping("/projects/{id}/iterations/{iterationId}/items")
|
||||
public Map<String,Object> createIterationItem(@PathVariable long id,@PathVariable long iterationId,@RequestBody JsonNode body) { return ok(service.create(id,iterationId,decode(body,ItemInput.class))); }
|
||||
/** 工作项详情在鉴权后返回有效任务前置、评论、附件和历史,不加载停用的流程数据。 */
|
||||
@GetMapping("/items/{id}") public Map<String,Object> detail(@PathVariable long id) { return ok(service.detail(id)); }
|
||||
/** 子任务创建使用父版本且严格解码,拒绝通过普通字段变更父关系或绕过层级规则。 */
|
||||
@PostMapping("/items/{id}/children") public Map<String,Object> child(@PathVariable long id,@RequestBody JsonNode body) { return ok(service.createChild(id,decode(body,ChildInput.class))); }
|
||||
/** 子任务列表在服务层复验项目成员权限与实时状态。 */
|
||||
@GetMapping("/items/{id}/children") public Map<String,Object> children(@PathVariable long id) { return ok(service.children(id)); }
|
||||
/** 普通编辑拒绝状态;旧调用省略 stageId 时保留归属,显式 null 才移到未分配,版本仍保护读写间竞态。 */
|
||||
@PatchMapping("/items/{id}") public Map<String,Object> edit(@PathVariable long id,@RequestBody JsonNode body) {
|
||||
ItemInput input=decode(body,ItemInput.class);
|
||||
if(!body.has("stageId")) input=new ItemInput(input.type(),input.title(),input.description(),input.assigneeId(),input.priority(),input.plannedStartAt(),input.plannedEndAt(),input.version(),nullableStage(service.detail(id).get("stageId")));
|
||||
service.edit(id,input); return ok(null);
|
||||
}
|
||||
/** 带版本软删除,并保护已开始后续条件。 */
|
||||
@DeleteMapping("/items/{id}") public Map<String,Object> delete(@PathVariable long id,@RequestBody JsonNode body) { service.delete(id,decode(body,VersionInput.class)); return ok(null); }
|
||||
/** 返回实际可开始状态,不将前端禁用按钮作为安全边界。 */
|
||||
@GetMapping("/items/{id}/startability") public Map<String,Object> startability(@PathVariable long id) { return ok(service.startability(id)); }
|
||||
/** 详情、看板、批量客户端均应调用统一开始服务。 */
|
||||
@PostMapping("/items/{id}/start") public Map<String,Object> start(@PathVariable long id,@RequestBody JsonNode body) { service.start(id,decode(body,VersionInput.class)); return ok(null); }
|
||||
/** 状态入口进入进行中时同样委托 start,不能直接更新数据库状态。 */
|
||||
@PostMapping("/items/{id}/transition") public Map<String,Object> transition(@PathVariable long id,@RequestBody JsonNode body) { service.transition(id,decode(body,TransitionInput.class)); return ok(null); }
|
||||
/** 返回依赖的当前满足状态与排期参与信息。 */
|
||||
@GetMapping("/items/{id}/dependencies") public Map<String,Object> dependencies(@PathVariable long id) { return ok(service.dependencies(id)); }
|
||||
/** 新依赖必须通过最终图的循环和排期检查。 */
|
||||
@PostMapping("/items/{id}/dependencies") public Map<String,Object> addDependency(@PathVariable long id,@RequestBody JsonNode body) { return ok(service.dependency(id,null,decode(body,DependencyInput.class),false)); }
|
||||
/** 修改依赖带上依赖与任务两个版本,保护并发编辑。 */
|
||||
@PatchMapping("/items/{id}/dependencies/{dependencyId}") public Map<String,Object> editDependency(@PathVariable long id,@PathVariable long dependencyId,@RequestBody JsonNode body) { return ok(service.dependency(id,dependencyId,decode(body,DependencyInput.class),false)); }
|
||||
/** 仅待开始任务可删除依赖,拒绝撤销已开始任务的前置记录。 */
|
||||
@DeleteMapping("/items/{id}/dependencies/{dependencyId}") public Map<String,Object> deleteDependency(@PathVariable long id,@PathVariable long dependencyId,@RequestBody JsonNode body) { return ok(service.dependency(id,dependencyId,decode(body,DependencyInput.class),true)); }
|
||||
/** 查询最早预计开始与排期完整性,不能代替实际开始判断。 */
|
||||
@GetMapping("/items/{id}/schedule-constraints") public Map<String,Object> constraints(@PathVariable long id) { return ok(service.constraints(id)); }
|
||||
/** 单项排期委托相同的批量最终态校验逻辑,路径 ID 必须与请求一致。 */
|
||||
@PatchMapping("/items/{id}/schedule") public Map<String,Object> schedule(@PathVariable long id,@RequestBody JsonNode body) { ScheduleInput input=decode(body,ScheduleInput.class); if(input.id()!=id) throw PmException.bad("工作项 ID 不匹配"); service.schedule(service.projectOf(id),service.iterationOf(id),List.of(input)); return ok(null); }
|
||||
/** 批量排期在一个事务中校验最终图并提交,不能逐条调用单项接口。 */
|
||||
@PostMapping("/projects/{id}/schedules/batch") public Map<String,Object> batch(@PathVariable long id,@RequestBody JsonNode body) { service.schedule(id,decode(body,BatchInput.class).items()); return ok(null); }
|
||||
/** 整批只允许同一迭代,服务按完整最终图处理前置与父子排期约束。 */
|
||||
@PostMapping("/projects/{id}/iterations/{iterationId}/schedules/batch")
|
||||
public Map<String,Object> iterationBatch(@PathVariable long id,@PathVariable long iterationId,@RequestBody JsonNode body) { service.scheduleBatch(id,iterationId,decode(body,BatchInput.class)); return ok(null); }
|
||||
/** 前置任务影响分析只返回可见项目的直接后续。 */
|
||||
@GetMapping("/items/{id}/successors") public Map<String,Object> successors(@PathVariable long id) { return ok(service.successors(id)); }
|
||||
/** 工作项评论受同一数据权限保护,并原子记录历史。 */
|
||||
@PostMapping("/items/{id}/comments") public Map<String,Object> comment(@PathVariable long id,@RequestBody JsonNode body) { service.comment(id,decode(body,CommentInput.class)); return ok(null); }
|
||||
/** 文件作为受限数据库附件保存,不产生公开上传 URL。 */
|
||||
@PostMapping("/items/{id}/attachments") public Map<String,Object> attach(@PathVariable long id,@RequestParam("file") MultipartFile file) throws java.io.IOException { if(file.getSize()>10*1024*1024) throw PmException.bad("附件不能超过 10 MiB"); return ok(service.attach(id,file.getOriginalFilename(),file.getContentType(),file.getBytes())); }
|
||||
/** 下载每次重新鉴权,强制附件方式并禁止内容嗅探,避免 HTML 等主动内容执行。 */
|
||||
@GetMapping("/attachments/{id}") public ResponseEntity<byte[]> download(@PathVariable long id) {
|
||||
Map<String,Object> file=service.attachment(id);
|
||||
return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM).header("X-Content-Type-Options","nosniff")
|
||||
.header(HttpHeaders.CACHE_CONTROL,"no-store").header(HttpHeaders.CONTENT_DISPOSITION,ContentDisposition.attachment().filename((String)file.get("name"),StandardCharsets.UTF_8).build().toString()).body((byte[])file.get("content"));
|
||||
}
|
||||
/** 项目统计只包含当前用户有权查看的工作项。 */
|
||||
@GetMapping("/projects/{id}/statistics") public Map<String,Object> statistics(@PathVariable long id) { return ok(service.statistics(id)); }
|
||||
/** 返回迭代当前有效版本统计,历史返工项不重复累计,取消不冒充完成。 */
|
||||
@GetMapping("/projects/{id}/iterations/{iterationId}/statistics")
|
||||
public Map<String,Object> iterationStatistics(@PathVariable long id,@PathVariable long iterationId) { return ok(service.statistics(id,iterationId)); }
|
||||
/** 个人通知再次过滤当前项目成员资格。 */
|
||||
@GetMapping("/notifications") public Map<String,Object> notifications() { return ok(service.notifications()); }
|
||||
|
||||
/** 成功响应沿用若依的数值 code 与 data,不丢失模块业务结果。 */
|
||||
private static Map<String,Object> ok(Object data) { return map("code",200,"msg","操作成功","data",data); }
|
||||
/** 仅兼容旧普通编辑入口的省略字段语义,不允许通过该转换修改身份或任务状态。 */
|
||||
private static Long nullableStage(Object value) { return value==null?null:((Number)value).longValue(); }
|
||||
/** 对所有请求使用严格白名单字段,解码失败统一返回 400 而非透出内部异常。 */
|
||||
private <T> T decode(JsonNode body,Class<T> type) { try { if(body==null||!body.isObject()) throw PmException.bad("请求必须为 JSON 对象"); return strict.treeToValue(body,type); } catch(Exception e) { throw PmException.bad("请求字段或格式无效,请勿提交状态等未允许字段"); } }
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.ruoyi.project.manage.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.ruoyi.project.manage.dto.IterationInput;
|
||||
import com.ruoyi.project.manage.dto.IterationActionInput;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.service.IPmIterationService;
|
||||
import java.util.Map;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
/** 迭代 REST 白名单适配层;身份、状态、归档和执行事实仅由服务写入。 */
|
||||
@RestController
|
||||
@RequestMapping("/project/manage/projects/{projectId}/iterations")
|
||||
public class PmIterationController {
|
||||
private final IPmIterationService service;
|
||||
private final ObjectMapper strict;
|
||||
/** 独立严格解码器拒绝未知业务字段以及数值截断。 */
|
||||
public PmIterationController(IPmIterationService service,ObjectMapper json) { this.service=service; this.strict=json.copy().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).disable(DeserializationFeature.ACCEPT_FLOAT_AS_INT); }
|
||||
/** 列表默认隐藏归档,客户端可显式打开历史迭代。 */
|
||||
@GetMapping public Map<String,Object> list(@PathVariable long projectId,@RequestParam(defaultValue="false") boolean includeArchived) { return ok(service.list(projectId,includeArchived)); }
|
||||
/** 成员可读取终态及归档迭代,不隐式切换当前迭代。 */
|
||||
@GetMapping("/{iterationId}") public Map<String,Object> get(@PathVariable long projectId,@PathVariable long iterationId) { return ok(service.get(projectId,iterationId)); }
|
||||
/** 创建请求必须携带幂等键,可指定同项目来源结构。 */
|
||||
@PostMapping public Map<String,Object> create(@PathVariable long projectId,@RequestBody JsonNode body) { return ok(service.create(projectId,decode(body,IterationInput.class))); }
|
||||
/** 元数据更新只接受基础字段及对象版本。 */
|
||||
@PatchMapping("/{iterationId}") public Map<String,Object> update(@PathVariable long projectId,@PathVariable long iterationId,@RequestBody JsonNode body) { return ok(service.update(projectId,iterationId,decode(body,IterationInput.class))); }
|
||||
/** 软删除空迭代,请求可按原幂等键安全重试。 */
|
||||
@DeleteMapping("/{iterationId}") public Map<String,Object> delete(@PathVariable long projectId,@PathVariable long iterationId,@RequestBody JsonNode body) { return ok(service.delete(projectId,iterationId,decode(body,IterationActionInput.class))); }
|
||||
/** 预览通过 POST 返回完整清单,服务持锁读取而不产生成功记录。 */
|
||||
@PostMapping("/{iterationId}/{action:finish|cancel}/preview") public Map<String,Object> preview(@PathVariable long projectId,@PathVariable long iterationId,@PathVariable String action,@RequestBody(required=false) JsonNode body) { if(body!=null) decode(body,IterationActionInput.class); return ok(service.preview(projectId,iterationId,action)); }
|
||||
/** 统一生命周期提交入口,动作白名单由路由和服务双重限定。 */
|
||||
@PostMapping("/{iterationId}/{action:activate|finish|cancel|reopen|archive|unarchive}") public Map<String,Object> action(@PathVariable long projectId,@PathVariable long iterationId,@PathVariable String action,@RequestBody JsonNode body) { return ok(service.action(projectId,iterationId,action,decode(body,IterationActionInput.class))); }
|
||||
/** 沿用项目模块响应包,返回数据库实际提交结果。 */
|
||||
private static Map<String,Object> ok(Object value) { return map("code",200,"msg","操作成功","data",value); }
|
||||
/** 递归白名单解码不接受客户端注入创建人、删除标记或执行状态。 */
|
||||
private <T> T decode(JsonNode body,Class<T> type) { try { if(body==null||!body.isObject()) throw PmException.bad("请求必须为 JSON 对象"); return strict.treeToValue(body,type); } catch(Exception invalid) { throw PmException.bad("请求字段或格式无效"); } }
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.ruoyi.project.manage.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.ruoyi.project.manage.dto.ReworkInput;
|
||||
import com.ruoyi.project.manage.dto.VersionInput;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.service.IPmReworkService;
|
||||
import java.util.Map;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
/** 阶段回退和历史 REST 入口;严格解码避免客户端伪造新版本与操作人。 */
|
||||
@RestController
|
||||
@RequestMapping("/project/manage")
|
||||
public class PmReworkController {
|
||||
private final IPmReworkService service;
|
||||
private final ObjectMapper strict;
|
||||
/** 控制器只依赖业务接口,未知字段与非整数 ID 一律拒绝。 */
|
||||
public PmReworkController(IPmReworkService service,ObjectMapper json) { this.service=service; this.strict=json.copy().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).disable(DeserializationFeature.ACCEPT_FLOAT_AS_INT); }
|
||||
/** 项目管理者预览回退影响和需要手动处理的冲突。 */
|
||||
@PostMapping("/projects/{id}/reworks/preview") public Map<String,Object> preview(@PathVariable long id,@RequestBody JsonNode body) { return ok(service.preview(id,decode(body,ReworkInput.class))); }
|
||||
/** 同一幂等键只保存一次回退,过期图版本返回冲突。 */
|
||||
@PostMapping("/projects/{id}/reworks") public Map<String,Object> commit(@PathVariable long id,@RequestBody JsonNode body) { return ok(service.commit(id,decode(body,ReworkInput.class))); }
|
||||
/** 回退预览只计算当前迭代范围,不扩展至项目的其他研发轮次。 */
|
||||
@PostMapping("/projects/{id}/iterations/{iterationId}/reworks/preview")
|
||||
public Map<String,Object> iterationPreview(@PathVariable long id,@PathVariable long iterationId,@RequestBody JsonNode body) { return ok(service.preview(id,iterationId,decode(body,ReworkInput.class))); }
|
||||
/** 复验迭代图版本、幂等键及完整影响清单后原子复制新轮次。 */
|
||||
@PostMapping("/projects/{id}/iterations/{iterationId}/reworks")
|
||||
public Map<String,Object> iterationCommit(@PathVariable long id,@PathVariable long iterationId,@RequestBody JsonNode body) { return ok(service.commit(id,iterationId,decode(body,ReworkInput.class))); }
|
||||
/** 阶段历史列表分页且先检查项目、迭代和阶段的完整归属。 */
|
||||
@GetMapping("/projects/{id}/iterations/{iterationId}/stages/{stageId}/revisions")
|
||||
public Map<String,Object> 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<String,Object> 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}/stages/{stageId}/revisions") public Map<String,Object> revisions(@PathVariable long id,@PathVariable long stageId) { return ok(service.revisions(id,stageId)); }
|
||||
/** 轮次的只读工作项快照。 */
|
||||
@GetMapping("/projects/{id}/stages/{stageId}/revisions/{revisionId}") public Map<String,Object> revision(@PathVariable long id,@PathVariable long stageId,@PathVariable long revisionId) { return ok(service.revision(id,stageId,revisionId)); }
|
||||
/** 后续待开始项的排期复核需要当前工作项版本。 */
|
||||
@PostMapping("/items/{id}/schedule-review") public Map<String,Object> confirm(@PathVariable long id,@RequestBody JsonNode body) { service.confirmScheduleReview(id,decode(body,VersionInput.class)); return ok(null); }
|
||||
/** 复用若依项目协作响应包装。 */
|
||||
private static Map<String,Object> ok(Object value) { return map("code",200,"msg","操作成功","data",value); }
|
||||
/** 请求体必须是严格 JSON 对象,不允许额外写入内部版本字段。 */
|
||||
private <T> T decode(JsonNode body,Class<T> type) { try { if(body==null||!body.isObject()) throw PmException.bad("请求必须为 JSON 对象"); return strict.treeToValue(body,type); } catch(Exception e) { throw PmException.bad("请求字段或格式无效"); } }
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.ruoyi.project.manage.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.ruoyi.project.manage.dto.*;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.service.IPmScheduleService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.*;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
/** 阶段时间适配层只接收计划白名单字段,实际时间和复核标志由业务服务维护。 */
|
||||
@RestController
|
||||
@RequestMapping("/project/manage/projects/{projectId}/iterations/{iterationId}/stages/{stageId}")
|
||||
public class PmScheduleController {
|
||||
private final IPmScheduleService service;
|
||||
private final ObjectMapper decoder;
|
||||
/** 独立解码器防止客户端注入实际时间、历史状态或复核关联。 */
|
||||
public PmScheduleController(IPmScheduleService service,ObjectMapper mapper) { this.service=service; this.decoder=mapper.copy().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).disable(DeserializationFeature.ACCEPT_FLOAT_AS_INT); }
|
||||
/** 查询最新阶段版本及合法排期边界,全部来源经过项目与迭代权限校验。 */
|
||||
@GetMapping("/schedule-constraints")
|
||||
public Map<String,Object> constraints(@PathVariable long projectId,@PathVariable long iterationId,@PathVariable long stageId) { return ok(service.constraints(projectId,iterationId,stageId)); }
|
||||
/** 单阶段保存也委托批量最终图业务方法,避免甘特拖动绕过约束。 */
|
||||
@PatchMapping("/schedule")
|
||||
public Map<String,Object> schedule(@PathVariable long projectId,@PathVariable long iterationId,@PathVariable long stageId,@RequestBody JsonNode body) {
|
||||
StageScheduleInput input=decode(body,stageId); service.schedule(projectId,iterationId,new BatchInput(List.of(),List.of(input),null)); return ok(null);
|
||||
}
|
||||
/** 缺失计划的完成后补录明确使用独立入口,不能改写已有正常计划。 */
|
||||
@PostMapping("/schedule-backfill")
|
||||
public Map<String,Object> backfill(@PathVariable long projectId,@PathVariable long iterationId,@PathVariable long stageId,@RequestBody JsonNode body) { service.backfill(projectId,iterationId,decode(body,stageId)); return ok(null); }
|
||||
/** JSON 字段严格匹配 DTO,路径和实体 ID 必须一致。 */
|
||||
private StageScheduleInput decode(JsonNode body,long id) {
|
||||
StageScheduleInput input;
|
||||
try { if(body==null||!body.isObject()) throw PmException.bad("请求必须为对象"); input=decoder.treeToValue(body,StageScheduleInput.class); }
|
||||
catch(Exception e) { throw PmException.bad("请求字段或格式无效"); }
|
||||
if(input.id()!=id) throw PmException.bad("阶段 ID 不匹配"); return input;
|
||||
}
|
||||
/** 成功结构沿用模块约定。 */
|
||||
private static Map<String,Object> ok(Object data) { return map("code",200,"msg","操作成功","data",data); }
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
package com.ruoyi.project.manage.controller;
|
||||
|
||||
import com.ruoyi.project.manage.dto.LayoutInput;
|
||||
import com.ruoyi.project.manage.dto.StageAssignment;
|
||||
import com.ruoyi.project.manage.dto.StageInput;
|
||||
import com.ruoyi.project.manage.dto.StageEdgeInput;
|
||||
import com.ruoyi.project.manage.dto.VersionInput;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.service.IPmStageService;
|
||||
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/** 阶段执行图与布局 REST 适配层;严格解码拒绝业务字段注入和伪造身份。 */
|
||||
@RestController
|
||||
@RequestMapping("/project/manage")
|
||||
public class PmStageController {
|
||||
private final IPmStageService service;
|
||||
private final ObjectMapper strict;
|
||||
/** 复用项目动作鉴权服务,独立解码器同时校验所有嵌套展示字段白名单。 */
|
||||
public PmStageController(IPmStageService service,ObjectMapper json) { this.service=service; this.strict=json.copy().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).disable(DeserializationFeature.ACCEPT_FLOAT_AS_INT); }
|
||||
/** 返回成员可见项目的阶段、显式连线与工作项,不查询浏览器偏好。 */
|
||||
@GetMapping("/projects/{id}/flow-view") public Map<String,Object> view(@PathVariable long id) { return ok(service.flowView(id)); }
|
||||
/** 画布只读取阶段摘要和连线,工作项由阶段抽屉分页获取。 */
|
||||
@GetMapping("/projects/{id}/iterations/{iterationId}/flow-view")
|
||||
public Map<String,Object> iterationView(@PathVariable long id,@PathVariable long iterationId) { return ok(service.flowView(id,iterationId)); }
|
||||
/** 在选定迭代中新建首版阶段,不能引用其他迭代执行事实。 */
|
||||
@PostMapping("/projects/{id}/iterations/{iterationId}/stages")
|
||||
public Map<String,Object> iterationCreate(@PathVariable long id,@PathVariable long iterationId,@RequestBody JsonNode body) { return ok(service.createStage(id,iterationId,decode(body,StageInput.class))); }
|
||||
/** 阶段版本与所属迭代状态均在统一项目锁内检查。 */
|
||||
@PatchMapping("/projects/{id}/iterations/{iterationId}/stages/{stageId}")
|
||||
public Map<String,Object> iterationEdit(@PathVariable long id,@PathVariable long iterationId,@PathVariable long stageId,@RequestBody JsonNode body) { service.editStage(id,iterationId,stageId,decode(body,StageInput.class)); return ok(null); }
|
||||
/** 仅当前迭代的空阶段可软删除,保留原版本记录。 */
|
||||
@DeleteMapping("/projects/{id}/iterations/{iterationId}/stages/{stageId}")
|
||||
public Map<String,Object> iterationDelete(@PathVariable long id,@PathVariable long iterationId,@PathVariable long stageId,@RequestBody JsonNode body) { service.deleteStage(id,iterationId,stageId,decode(body,VersionInput.class)); return ok(null); }
|
||||
/** 连线两端限定在当前迭代,混合任务阶段图仍统一检查循环。 */
|
||||
@PostMapping("/projects/{id}/iterations/{iterationId}/stage-edges")
|
||||
public Map<String,Object> iterationCreateEdge(@PathVariable long id,@PathVariable long iterationId,@RequestBody JsonNode body) { return ok(service.createEdge(id,iterationId,decode(body,StageEdgeInput.class))); }
|
||||
/** 按边版本断开当前迭代执行关系,不改变其他迭代。 */
|
||||
@DeleteMapping("/projects/{id}/iterations/{iterationId}/stage-edges/{edgeId}")
|
||||
public Map<String,Object> iterationDeleteEdge(@PathVariable long id,@PathVariable long iterationId,@PathVariable long edgeId,@RequestBody JsonNode body) { service.deleteEdge(id,iterationId,edgeId,decode(body,VersionInput.class)); return ok(null); }
|
||||
/** 新建组织阶段,调用者不能指定创建人或删除标记。 */
|
||||
@PostMapping("/projects/{id}/stages") public Map<String,Object> create(@PathVariable long id,@RequestBody JsonNode body) { return ok(service.createStage(id,decode(body,StageInput.class))); }
|
||||
/** 阶段更新携带自身版本,不调整工作项开始或排期规则。 */
|
||||
@PatchMapping("/projects/{id}/stages/{stageId}") public Map<String,Object> edit(@PathVariable long id,@PathVariable long stageId,@RequestBody JsonNode body) { service.editStage(id,stageId,decode(body,StageInput.class)); return ok(null); }
|
||||
/** 非空阶段拒绝删除;空阶段采用软删除保留历史。 */
|
||||
@DeleteMapping("/projects/{id}/stages/{stageId}") public Map<String,Object> delete(@PathVariable long id,@PathVariable long stageId,@RequestBody JsonNode body) { service.deleteStage(id,stageId,decode(body,VersionInput.class)); return ok(null); }
|
||||
/** 连线仅由项目管理者维护;执行顺序和环检测在持锁服务中统一处理。 */
|
||||
@PostMapping("/projects/{id}/stage-edges") public Map<String,Object> createEdge(@PathVariable long id,@RequestBody JsonNode body) { return ok(service.createEdge(id,decode(body,StageEdgeInput.class))); }
|
||||
/** 使用边版本删除连线,防止过期画布覆盖其他管理者的修改。 */
|
||||
@DeleteMapping("/projects/{id}/stage-edges/{edgeId}") public Map<String,Object> deleteEdge(@PathVariable long id,@PathVariable long edgeId,@RequestBody JsonNode body) { service.deleteEdge(id,edgeId,decode(body,VersionInput.class)); return ok(null); }
|
||||
/** 明确移动到阶段的业务入口,与普通画布位置拖动分离。 */
|
||||
@PatchMapping("/items/{id}/stage") public Map<String,Object> assign(@PathVariable long id,@RequestBody JsonNode body) { service.assign(id,decode(body,StageAssignment.class)); return ok(null); }
|
||||
/** 仅为旧客户端保留独立版本布局写入,不接受 ownerId;当前流程页面不调用。 */
|
||||
@PutMapping("/projects/{id}/graph-layout/{scope}") public Map<String,Object> layout(@PathVariable long id,@PathVariable String scope,@RequestBody JsonNode body) { return ok(service.saveLayout(id,scope,decode(body,LayoutInput.class))); }
|
||||
/** 沿用若依响应包,返回真实事务结果。 */
|
||||
private static Map<String,Object> ok(Object value) { return map("code",200,"msg","操作成功","data",value); }
|
||||
/** 所有层级禁止未知字段及数值截断,避免展示配置夹带业务写入。 */
|
||||
private <T> T decode(JsonNode body,Class<T> type) { try { if(body==null||!body.isObject()) throw PmException.bad("请求必须为 JSON 对象"); return strict.treeToValue(body,type); } catch(Exception e) { throw PmException.bad("请求字段或格式无效"); } }
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.domain;
|
||||
|
||||
/** 同项目任务前置快照,始终依据前置任务当前状态判断。 */
|
||||
public record Dependency(long id,long projectId,long successorId,String type,Long taskId,String expected,int version) { }
|
||||
@ -0,0 +1,17 @@
|
||||
package com.ruoyi.project.manage.domain;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/** 事务内可替换的最终依赖图,用于统一排期、实际状态和循环校验。 */
|
||||
public record Graph(Map<Long,Item> items,List<Dependency> dependencies,Map<Long,String> stageNames,List<StageLink> stageLinks,Map<Long,StageRevision> stageRevisions,IterationScope iteration) {
|
||||
/** 纯规则和历史快照可省略迭代上下文;生产当前图始终显式携带数据库迭代。 */
|
||||
public Graph(Map<Long,Item> items,List<Dependency> dependencies,Map<Long,String> stageNames,List<StageLink> stageLinks,Map<Long,StageRevision> stageRevisions) { this(items,dependencies,stageNames,stageLinks,stageRevisions,null); }
|
||||
/** 旧的纯任务规则测试无需构造阶段;生产图始终由数据库加载有效阶段。 */
|
||||
public Graph(Map<Long,Item> items,List<Dependency> dependencies) { this(items,dependencies,new LinkedHashMap<>(),new ArrayList<>(),new LinkedHashMap<>()); }
|
||||
|
||||
/** 旧测试可只传阶段和边;无版本快照时按当前工作项事实派生状态。 */
|
||||
public Graph(Map<Long,Item> items,List<Dependency> dependencies,Map<Long,String> stageNames,List<StageLink> 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); }
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.ruoyi.project.manage.domain;
|
||||
|
||||
/** 事务内不可变工作项快照;时间、生命周期和父阶段变更通过重建快照校验。 */
|
||||
public record Item(long id, long projectId, String type, String title, String description, Long assigneeId,
|
||||
String priority, String status, Long start, Long end, Long actualStart, Long actualEnd,
|
||||
int version, boolean deleted, Long stageId, Long parentTaskId,
|
||||
Long stageRevisionId,Long originWorkItemId,Long scheduleReviewReworkId,Long referenceStart,Long referenceEnd) {
|
||||
/** 既有调用不带参考日期;正式加载由 Mapper 显式提供,参考日期永不充当正常预计时间。 */
|
||||
public Item(long id,long projectId,String type,String title,String description,Long assigneeId,String priority,String status,Long start,Long end,Long actualStart,Long actualEnd,int version,boolean deleted,Long stageId,Long parentTaskId,Long stageRevisionId,Long originWorkItemId,Long scheduleReviewReworkId) { this(id,projectId,type,title,description,assigneeId,priority,status,start,end,actualStart,actualEnd,version,deleted,stageId,parentTaskId,stageRevisionId,originWorkItemId,scheduleReviewReworkId,null,null); }
|
||||
/** 兼容既有候选图构造;正式入库时阶段版本由服务在项目锁内确定。 */
|
||||
public Item(long id,long projectId,String type,String title,String description,Long assigneeId,String priority,String status,Long start,Long end,Long actualStart,Long actualEnd,int version,boolean deleted,Long stageId,Long parentTaskId) { this(id,projectId,type,title,description,assigneeId,priority,status,start,end,actualStart,actualEnd,version,deleted,stageId,parentTaskId,null,null,null); }
|
||||
/** 阶段版本旧调用创建根工作项;父关系只由专用子任务创建入口确定。 */
|
||||
public Item(long id,long projectId,String type,String title,String description,Long assigneeId,String priority,String status,Long start,Long end,Long actualStart,Long actualEnd,int version,boolean deleted,Long stageId) { this(id,projectId,type,title,description,assigneeId,priority,status,start,end,actualStart,actualEnd,version,deleted,stageId,null); }
|
||||
/** 保持既有内部调用兼容,未指定阶段的旧工作项仍归入未分配组。 */
|
||||
public Item(long id,long projectId,String type,String title,String description,Long assigneeId,String priority,String status,Long start,Long end,Long actualStart,Long actualEnd,int version,boolean deleted) { this(id,projectId,type,title,description,assigneeId,priority,status,start,end,actualStart,actualEnd,version,deleted,null); }
|
||||
/** 用请求最终时间替换快照,供整批校验;不修改数据库或生命周期。 */
|
||||
public Item scheduled(Long start, Long end) { return new Item(id,projectId,type,title,description,assigneeId,priority,status,start,end,actualStart,actualEnd,version,deleted,stageId,parentTaskId,stageRevisionId,originWorkItemId,scheduleReviewReworkId,referenceStart,referenceEnd); }
|
||||
/** 用目标状态重建快照,供回退影响检查;实际时间在正式写入时决定。 */
|
||||
public Item transitioned(String status, boolean deleted) { return new Item(id,projectId,type,title,description,assigneeId,priority,status,start,end,actualStart,actualEnd,version,deleted,stageId,parentTaskId,stageRevisionId,originWorkItemId,scheduleReviewReworkId,referenceStart,referenceEnd); }
|
||||
/** 仅事务候选图中替换阶段归属;父子同步由服务在同一项目锁下完成。 */
|
||||
public Item inStage(Long stageId) { return new Item(id,projectId,type,title,description,assigneeId,priority,status,start,end,actualStart,actualEnd,version,deleted,stageId,parentTaskId,stageRevisionId,originWorkItemId,scheduleReviewReworkId,referenceStart,referenceEnd); }
|
||||
/** 专用排期入口的候选结果,全部校验通过后才可清除复核及参考日期。 */
|
||||
public Item confirmedSchedule(Long start,Long end) { return new Item(id,projectId,type,title,description,assigneeId,priority,status,start,end,actualStart,actualEnd,version,deleted,stageId,parentTaskId,stageRevisionId,originWorkItemId,null,null,null); }
|
||||
/** 转存原计划并保留执行事实,用于回退影响闭包的最终态预检。 */
|
||||
public Item pending(long reworkId) { return new Item(id,projectId,type,title,description,assigneeId,priority,status,null,null,actualStart,actualEnd,version,deleted,stageId,parentTaskId,stageRevisionId,originWorkItemId,reworkId,start!=null?start:referenceStart,end!=null?end:referenceEnd); }
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.ruoyi.project.manage.domain;
|
||||
|
||||
/** 数据库迭代快照,只描述当前业务边界;不替代服务中的成员鉴权和事务锁。 */
|
||||
public record IterationScope(long id,long projectId,String status,boolean archived) {
|
||||
/** 仅进行中且未归档迭代可执行工作项,筹备阶段只允许配置。 */
|
||||
public boolean active() { return !archived&&"ACTIVE".equals(status); }
|
||||
/** 待开始和进行中可维护业务内容,所有终态和归档轮次保持只读。 */
|
||||
public boolean mutable() { return !archived&&("PLANNED".equals(status)||"ACTIVE".equals(status)); }
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.domain;
|
||||
|
||||
/** 显式阶段执行边;项目及两端阶段由数据库外键限定,版本用于并发删除保护。 */
|
||||
public record StageLink(long id,long projectId,long predecessorStageId,long successorStageId,int version) { }
|
||||
@ -0,0 +1,20 @@
|
||||
package com.ruoyi.project.manage.domain;
|
||||
|
||||
/** 当前阶段执行轮次的最小快照;历史轮次只能通过独立只读查询获取。 */
|
||||
public record StageRevision(long id,long stageId,int revisionNo,Long startedAt,Long completedAt,Long legacyPassedAt,
|
||||
Long plannedStart,Long plannedEnd,Long referenceStart,Long referenceEnd,Long scheduleReviewReworkId,
|
||||
String planSource,Long planRecordedAt,int version) {
|
||||
/** 旧规则测试与初始轮次没有计划,空值不能被推断为实际时间或当前时间。 */
|
||||
public StageRevision(long id,long stageId,int revisionNo,Long startedAt,Long completedAt,Long legacyPassedAt) {
|
||||
this(id,stageId,revisionNo,startedAt,completedAt,legacyPassedAt,null,null,null,null,null,null,null,0);
|
||||
}
|
||||
/** 最终图中确认新计划;仅正式事务提交后才增加数据版本,不创建新执行轮次。 */
|
||||
public StageRevision scheduled(Long start,Long end,String source,Long recordedAt) {
|
||||
return new StageRevision(id,stageId,revisionNo,startedAt,completedAt,legacyPassedAt,start,end,null,null,null,source,recordedAt,version);
|
||||
}
|
||||
/** 回退使原计划失效时保留参考值;连续回退不能用空值覆盖尚未确认的参考。 */
|
||||
public StageRevision pending(long reworkId) {
|
||||
return new StageRevision(id,stageId,revisionNo,startedAt,completedAt,legacyPassedAt,null,null,
|
||||
plannedStart!=null?plannedStart:referenceStart,plannedEnd!=null?plannedEnd:referenceEnd,reworkId,planSource,planRecordedAt,version);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 整批最终排期请求,在同一事务验证并提交。 */
|
||||
public record BatchInput(List<ScheduleInput> items,List<StageScheduleInput> stages,Long graphVersion) {
|
||||
/** 兼容原有仅工作项批量请求,阶段列表缺省不改变阶段计划。 */
|
||||
public BatchInput(List<ScheduleInput> items) { this(items,null,null); }
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 专用子任务创建请求,父版本保护并发关联变化。 */
|
||||
public record ChildInput(ItemInput item,Integer parentVersion) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 受限工作项评论请求,作者与时间由服务填写。 */
|
||||
public record CommentInput(String body) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 独立项目配置维护请求,不支持从项目列表导入。 */
|
||||
public record ConfigInput(Long spaceId,String timezone,Integer version) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 任务条件与任务/依赖两个版本,不支持停用的节点依赖。 */
|
||||
public record DependencyInput(String conditionType,Long predecessorTaskId,String expectedStatus,Integer version,Integer taskVersion) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 个人展示筛选,查询可见范围仍由后端权限限定。 */
|
||||
public record FilterInput(String keyword,String type,Long assigneeId,String status,Boolean blockedOnly) { }
|
||||
@ -0,0 +1,7 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 工作项编辑白名单,不接受生命周期、实际时间或父关系字段。 */
|
||||
public record ItemInput(String type,String title,String description,Long assigneeId,String priority,String plannedStartAt,String plannedEndAt,Integer version,Long stageId) {
|
||||
/** 旧内部调用未指定阶段时继续使用未分配,不引入隐式阶段或门禁。 */
|
||||
public ItemInput(String type,String title,String description,Long assigneeId,String priority,String plannedStartAt,String plannedEndAt,Integer version) { this(type,title,description,assigneeId,priority,plannedStartAt,plannedEndAt,version,null); }
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 视图查询白名单;分页仅限制返回内容,不缩小服务端依赖或排期校验的图。 */
|
||||
public record ItemQuery(Integer page,Integer pageSize,String view,String keyword,String type,String status,Boolean blockedOnly,Long stageId,String from,String to) { }
|
||||
@ -0,0 +1,7 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 生命周期提交携带双版本和完整预览确认;取消清单不能用仅有布尔确认替代。 */
|
||||
public record IterationActionInput(Long version,Long graphVersion,String idempotencyKey,String reason,
|
||||
List<String> acceptedExceptionIds,List<Long> acceptedItemIds) { }
|
||||
@ -0,0 +1,5 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 迭代基础信息及一次性结构复制来源;身份、状态和执行事实均由服务端决定。 */
|
||||
public record IterationInput(String code,String name,String goal,String plannedStartAt,String plannedEndAt,
|
||||
Integer sortOrder,Long version,Long sourceIterationId,Long sourceGraphVersion,String idempotencyKey) { }
|
||||
@ -0,0 +1,7 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** 独立展示布局白名单,不能夹带工作项业务写入。 */
|
||||
public record LayoutInput(Integer version,Map<String,PositionInput> positions,List<Long> collapsedStages,ViewportInput viewport,FilterInput filters) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 独立项目成员角色请求,实际身份和经理权限由服务校验。 */
|
||||
public record MemberInput(Long userId,String role) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 空间名称维护请求,不能修改创建人。 */
|
||||
public record NameInput(String name,Integer version) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 有限画布坐标,仅影响展示位置。 */
|
||||
public record PositionInput(Double x,Double y) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 项目名称及空间维护白名单,不接受创建人或成员字段。 */
|
||||
public record ProjectEditInput(String name,Long spaceId,Integer version) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 独立协作项目创建请求,兼容字段只能使用固定北京时间。 */
|
||||
public record ProjectInput(String name,Long spaceId,String timezone) { }
|
||||
@ -0,0 +1,8 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** 预览与提交共用明确范围;提交时图版本和幂等键必填。 */
|
||||
public record ReworkInput(Long sourceStageId,Long targetStageId,String reason,Long graphVersion,String idempotencyKey,List<Long> expectedStageIds,
|
||||
Map<Long,List<ReworkItemInput>> additions) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 空轮次回退时补录的根工作项;排期与实际时间始终从空值重新制定。 */
|
||||
public record ReworkItemInput(String type,String title,String description,Long assigneeId,String priority) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 单项最终排期,时间必须为带偏移 ISO 8601。 */
|
||||
public record ScheduleInput(long id,Integer version,String plannedStartAt,String plannedEndAt) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 空间创建白名单,创建身份只取当前登录用户。 */
|
||||
public record SpaceInput(String name) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 显式阶段归属操作,使用工作项版本保护并发移动。 */
|
||||
public record StageAssignment(Long stageId,Integer version) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 管理者提交的阶段连线端点;项目、创建人和版本由服务端确定。 */
|
||||
public record StageEdgeInput(Long predecessorStageId,Long successorStageId) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 阶段组织元数据,不承载执行流程或节点状态。 */
|
||||
public record StageInput(String name,Integer sortOrder,Long ownerId,String description,Integer version) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 阶段排期同时绑定执行版本与数据版本;补录只能在专用入口处理。 */
|
||||
public record StageScheduleInput(long id,Long revisionId,Integer version,String plannedStartAt,String plannedEndAt,String reason,Boolean backfill) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 状态变更请求,进入进行中仍调用唯一开始业务方法。 */
|
||||
public record TransitionInput(String status,Integer version) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 动作请求必须携带当前数据版本,禁止默认覆盖最新值。 */
|
||||
public record VersionInput(Integer version) { }
|
||||
@ -0,0 +1,4 @@
|
||||
package com.ruoyi.project.manage.dto;
|
||||
|
||||
/** 个人视口偏好,不纳入共享业务规则。 */
|
||||
public record ViewportInput(Double x,Double y,Double zoom) { }
|
||||
@ -0,0 +1,53 @@
|
||||
package com.ruoyi.project.manage.event;
|
||||
|
||||
import com.ruoyi.project.manage.mapper.PmEventMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmWorkspaceMapper;
|
||||
import com.ruoyi.project.manage.util.PmTime;
|
||||
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.scheduling.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/** 事务 outbox 异步生成受限站内通知;数据库行锁与唯一键保证多实例重试幂等。 */
|
||||
@Service
|
||||
public class PmOutbox {
|
||||
private final PmWorkspaceMapper workspaceMapper;
|
||||
private final PmEventMapper eventMapper;
|
||||
private final TransactionTemplate tx;
|
||||
/** 调度事务独立于用户请求,失败不会撤销已提交业务,也不会漏掉待重试事件。 */
|
||||
public PmOutbox(PmWorkspaceMapper workspaceMapper,PmEventMapper eventMapper,PlatformTransactionManager manager) { this.workspaceMapper=workspaceMapper; this.eventMapper=eventMapper; this.tx=new TransactionTemplate(manager); this.tx.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED); }
|
||||
|
||||
/** 每次领取有限已提交事件;SKIP LOCKED 避免多实例重复处理,通知与 delivered 标记原子提交。 */
|
||||
@Scheduled(fixedDelayString="${project.manage.outbox-delay-ms:5000}")
|
||||
public void dispatch() {
|
||||
for(Map<String,Object> candidate:eventMapper.selectPendingEvents(PmTime.now())) {
|
||||
long id=number(candidate,"id");
|
||||
try { deliver(id); }
|
||||
catch(RuntimeException failure) {
|
||||
// 发送失败只推进重试时间,不写成功标记;退避最多一小时,并持续保留事件。
|
||||
tx.executeWithoutResult(s->eventMapper.scheduleRetry(PmTime.now(),id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 只处理独立协作事件和成员,同 ID 的项目列表成员不会收到通知;重试由唯一键保持幂等。 */
|
||||
public void deliver(long eventId) {
|
||||
tx.executeWithoutResult(s->{
|
||||
Map<String,Object> metadata=eventMapper.selectEventProject(eventId);
|
||||
if(metadata==null) return;
|
||||
// 通知接收者与成员变更也遵循项目→事件的锁顺序,避免撤权与分发使用不同的成员快照。
|
||||
workspaceMapper.lockProject(number(metadata,"project_id"));
|
||||
Map<String,Object> event=eventMapper.selectEventForUpdate(eventId);
|
||||
if(event==null) return;
|
||||
long project=number(event,"project_id");
|
||||
eventMapper.insertRecipientNotifications(eventId,project,nullable(event,"work_item_id"),"项目变更:"+text(event,"event_type"),PmTime.now());
|
||||
eventMapper.markDelivered(PmTime.now(),eventId);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.ruoyi.project.manage.exception;
|
||||
|
||||
import com.ruoyi.project.manage.controller.PmController;
|
||||
import com.ruoyi.project.manage.controller.PmStageController;
|
||||
import com.ruoyi.project.manage.controller.PmIterationController;
|
||||
import com.ruoyi.project.manage.controller.PmReworkController;
|
||||
import com.ruoyi.project.manage.controller.PmScheduleController;
|
||||
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
import java.util.Map;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.dao.*;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||
import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
||||
|
||||
/** 局部异常处理优先于旧全局处理,保留 HTTP 状态和结构化冲突,且不暴露 SQL。 */
|
||||
@RestControllerAdvice(assignableTypes={PmController.class,PmStageController.class,PmIterationController.class,PmReworkController.class,PmScheduleController.class})
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class PmErrorHandler {
|
||||
/** 返回已鉴权后的安全业务详情,包括阻塞原因、影响任务和依赖路径。 */
|
||||
@ExceptionHandler(PmException.class)
|
||||
public ResponseEntity<Map<String,Object>> business(PmException e) { Map<String,Object> body=map("code",e.getCode(),"message",e.getMessage()); body.putAll(e.getDetails()); return ResponseEntity.status(e.getHttpStatus()).body(body); }
|
||||
/** JSON、查询参数及上传限制统一使用结构化 400,避免旧全局处理将格式错误包装成 HTTP 200。 */
|
||||
@ExceptionHandler({HttpMessageNotReadableException.class,MaxUploadSizeExceededException.class,MethodArgumentTypeMismatchException.class,MissingServletRequestParameterException.class})
|
||||
public ResponseEntity<Map<String,Object>> invalid(Exception e) { return business(PmException.bad("请求格式无效或附件超出大小限制")); }
|
||||
/** 锁冲突允许用户刷新重试;事务已经回滚,不可记录成功历史。 */
|
||||
@ExceptionHandler(PessimisticLockingFailureException.class)
|
||||
public ResponseEntity<Map<String,Object>> lock(Exception e) { return business(PmException.conflict("CONCURRENT_MODIFICATION","项目正在修改,请刷新后重试")); }
|
||||
/** 数据库完整性兜底拒绝绕过应用层的无效组合,不泄露库表或其它对象信息。 */
|
||||
@ExceptionHandler(DataIntegrityViolationException.class)
|
||||
public ResponseEntity<Map<String,Object>> integrity(Exception e) { return business(PmException.conflict("DATA_INTEGRITY_CONFLICT","对象已变更或关联无效,请刷新后重试")); }
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package com.ruoyi.project.manage.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.Map;
|
||||
|
||||
/** 模块业务冲突保留结构化详情,由局部异常处理器转换为真实 HTTP 状态。 */
|
||||
public class PmException extends RuntimeException {
|
||||
// 沿用当前类原先自动计算的标识,固定序列化版本并保持已有序列化兼容性。
|
||||
@Serial
|
||||
private static final long serialVersionUID = -313267722320197619L;
|
||||
|
||||
private final int httpStatus;
|
||||
private final String code;
|
||||
private final Map<String, Object> details;
|
||||
|
||||
/** 保存错误码与安全详情;调用方必须先鉴权,避免返回不可见对象。 */
|
||||
public PmException(int httpStatus, String code, String message, Map<String, Object> details) {
|
||||
super(message); this.httpStatus = httpStatus; this.code = code; this.details = details;
|
||||
}
|
||||
|
||||
/** 返回实际 HTTP 错误状态,供 REST 适配及调用方识别失败类型。 */
|
||||
public int getHttpStatus() { return httpStatus; }
|
||||
|
||||
/** 返回稳定业务错误码,供界面处理冲突而不依赖中文消息文本。 */
|
||||
public String getCode() { return code; }
|
||||
|
||||
/** 返回服务完成鉴权后构造的结构化详情,不能加入未授权对象信息。 */
|
||||
public Map<String,Object> getDetails() { return details; }
|
||||
|
||||
/** 创建无敏感详情的字段错误,返回给调用方修正请求。 */
|
||||
public static PmException bad(String message) { return new PmException(400, "INVALID_REQUEST", message, Map.of()); }
|
||||
|
||||
/** 创建可刷新后重试的业务冲突,不代表任何修改已经提交。 */
|
||||
public static PmException conflict(String code, String message) { return new PmException(409, code, message, Map.of()); }
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.ruoyi.project.manage.mapper;
|
||||
|
||||
import com.ruoyi.project.manage.mapper.support.PmMapperWrite;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/** 项目协作对象访问接口;固定 SQL 位于同名 XML,服务层负责权限、事务与规则。 */
|
||||
@Mapper
|
||||
public interface PmActivityMapper {
|
||||
/** 只为已授权工作项加载评论,作者信息限制为显示名。 */
|
||||
List<Map<String,Object>> selectComments(@Param("itemId") long itemId);
|
||||
|
||||
/** 仅列出附件元数据,二进制内容通过单独鉴权接口获取。 */
|
||||
List<Map<String,Object>> selectAttachments(@Param("itemId") long itemId);
|
||||
|
||||
/** 按最近记录返回操作历史,限制数量避免详情读取无限增长。 */
|
||||
List<Map<String,Object>> selectHistory(@Param("itemId") long itemId);
|
||||
|
||||
/** 下载前读取单个附件,服务层须先鉴权其所属工作项。 */
|
||||
Map<String,Object> selectAttachment(@Param("attachmentId") long attachmentId);
|
||||
|
||||
/** 保存评论及创建人,服务层已校验成员身份。 */
|
||||
int insertCommentRow(@Param("values") Map<String,Object> values);
|
||||
/** 使用数据库生成键;插入与外层业务校验共享一个事务。 */
|
||||
default long insertComment(Map<String,Object> values) { insertCommentRow(values); return PmMapperWrite.generatedId(values); }
|
||||
|
||||
/** 保存附件和内容,调用方负责大小及访问权限检查。 */
|
||||
int insertAttachmentRow(@Param("values") Map<String,Object> values);
|
||||
/** 使用数据库生成键;插入与外层业务校验共享一个事务。 */
|
||||
default long insertAttachment(Map<String,Object> values) { insertAttachmentRow(values); return PmMapperWrite.generatedId(values); }
|
||||
|
||||
/** 与业务更新同事务记录成功历史,回滚时不得留下成功记录。 */
|
||||
int insertHistoryRow(@Param("values") Map<String,Object> values);
|
||||
/** 使用数据库生成键;插入与外层业务校验共享一个事务。 */
|
||||
default long insertHistory(Map<String,Object> values) { insertHistoryRow(values); return PmMapperWrite.generatedId(values); }
|
||||
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.ruoyi.project.manage.mapper;
|
||||
|
||||
import com.ruoyi.project.manage.mapper.support.PmMapperWrite;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/** 项目协作对象访问接口;固定 SQL 位于同名 XML,服务层负责权限、事务与规则。 */
|
||||
@Mapper
|
||||
public interface PmDependencyMapper {
|
||||
/** 在项目锁内移除依赖,后续任务和版本由服务检查。 */
|
||||
int deleteDependency(@Param("dependencyId") long dependencyId);
|
||||
|
||||
/** 保存同项目任务前置关系,循环与排期在项目锁内预先校验。 */
|
||||
int insertDependencyRow(@Param("values") Map<String,Object> values);
|
||||
/** 使用数据库生成键;插入与外层业务校验共享一个事务。 */
|
||||
default long insertDependency(Map<String,Object> values) { insertDependencyRow(values); return PmMapperWrite.generatedId(values); }
|
||||
|
||||
/** 按版本修改前置任务,避免并发编辑覆盖依赖。 */
|
||||
int updateDependencyRow(@Param("id") long id, @Param("version") int version, @Param("values") Map<String,Object> values);
|
||||
/** 版本不匹配必须拒绝覆盖;业务服务持有项目锁并在同一事务内记录历史。 */
|
||||
default void updateDependency(long id,int version,Map<String,Object> values) { PmMapperWrite.requireUpdated(updateDependencyRow(id,version,values)); }
|
||||
|
||||
/** 加载任务前置边,供开始条件、排期及无环检查共用。 */
|
||||
List<Map<String,Object>> selectGraphDependencies(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
|
||||
/** 历史工作项详情读取原始依赖行,不把旧边加载进当前执行图。 */
|
||||
List<Map<String,Object>> selectItemDependencies(@Param("projectId") long projectId,@Param("itemId") long itemId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.ruoyi.project.manage.mapper;
|
||||
|
||||
import com.ruoyi.project.manage.mapper.support.PmMapperWrite;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/** 项目协作对象访问接口;固定 SQL 位于同名 XML,服务层负责权限、事务与规则。 */
|
||||
@Mapper
|
||||
public interface PmEventMapper {
|
||||
/** 仅返回当前用户且仍可访问项目的通知,撤权后不泄露详情。 */
|
||||
List<Map<String,Object>> selectNotifications(@Param("userId") long userId, @Param("administrator") boolean administrator);
|
||||
|
||||
/** 按重试时间领取未投递事件,发送端仅处理已提交记录。 */
|
||||
List<Map<String,Object>> selectPendingEvents(@Param("now") long now);
|
||||
|
||||
/** 失败后指数退避并限制等待上限,事件保持待发送状态。 */
|
||||
int scheduleRetry(@Param("now") long now, @Param("eventId") long eventId);
|
||||
|
||||
/** 先读事件所属项目,投递事务按项目锁顺序加锁。 */
|
||||
Map<String,Object> selectEventProject(@Param("eventId") long eventId);
|
||||
|
||||
/** 跳过其他投递者已锁事件,防止重复并发投递。 */
|
||||
Map<String,Object> selectEventForUpdate(@Param("eventId") long eventId);
|
||||
|
||||
/** 按当前有效成员生成站内通知,唯一事件用户键确保重试幂等。 */
|
||||
int insertRecipientNotifications(@Param("eventId") long eventId, @Param("projectId") long projectId, @Param("itemId") Long itemId, @Param("message") String message, @Param("createdAt") long createdAt);
|
||||
|
||||
/** 接收者通知成功保存后标记事件已投递,操作处于同一事务。 */
|
||||
int markDelivered(@Param("deliveredAt") long deliveredAt, @Param("eventId") long eventId);
|
||||
|
||||
/** 在业务事务内写入 outbox,提交后才由异步投递器领取。 */
|
||||
int insertEventRow(@Param("values") Map<String,Object> values);
|
||||
/** 使用数据库生成键;插入与外层业务校验共享一个事务。 */
|
||||
default long insertEvent(Map<String,Object> values) { insertEventRow(values); return PmMapperWrite.generatedId(values); }
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package com.ruoyi.project.manage.mapper;
|
||||
|
||||
import com.ruoyi.project.manage.mapper.support.PmMapperWrite;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/** 迭代与请求结果持久层;所有写操作由项目行锁统一串行化。 */
|
||||
@Mapper
|
||||
public interface PmIterationMapper {
|
||||
/** 读取显式项目中的有效迭代,保留数据库列名供统一门禁使用。 */
|
||||
Map<String,Object> selectIteration(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
/** 列表按展示顺序返回,归档仅在调用者明确要求时显示。 */
|
||||
List<Map<String,Object>> selectIterations(@Param("projectId") long projectId,@Param("includeArchived") boolean includeArchived);
|
||||
/** 使用项目和操作者的请求键读取已提交结果,不向其他用户泄露请求内容。 */
|
||||
Map<String,Object> selectRequest(@Param("projectId") long projectId,@Param("actor") long actor,@Param("key") String key);
|
||||
/** 保存成功结果,与业务变更、审计和 outbox 同事务提交。 */
|
||||
int insertRequest(@Param("values") Map<String,Object> values);
|
||||
/** 插入仅由服务构造的迭代列,状态固定从筹备开始。 */
|
||||
int insertIterationRow(@Param("values") Map<String,Object> values);
|
||||
/** 返回数据库生成键,禁止客户端指定迭代 ID。 */
|
||||
default long insertIteration(Map<String,Object> values) { insertIterationRow(values); return PmMapperWrite.generatedId(values); }
|
||||
/** 元数据和生命周期均以旧版本写入,不修改其它迭代。 */
|
||||
int updateIteration(@Param("projectId") long projectId,@Param("iterationId") long iterationId,@Param("version") long version,@Param("values") Map<String,Object> values);
|
||||
/** 删除检查包含全部工作项和执行事实;初始未执行阶段与定义配置不阻止清理。 */
|
||||
long countContents(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
/** 复制只读取当前有效阶段元数据,不读取任务或旧轮次。 */
|
||||
List<Map<String,Object>> selectCopyStages(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
/** 复制当前有效阶段之间的边,旧 ID 由服务映射为新阶段 ID。 */
|
||||
List<Map<String,Object>> selectCopyEdges(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
/** 为复制结构创建新阶段;执行版本指针稍后在同事务初始化。 */
|
||||
int insertCopiedStageRow(@Param("values") Map<String,Object> values);
|
||||
/** 取得新阶段 ID 以建立单次复制的映射表。 */
|
||||
default long insertCopiedStage(Map<String,Object> values) { insertCopiedStageRow(values); return PmMapperWrite.generatedId(values); }
|
||||
/** 新阶段只创建 v1,所有开始、完成和兼容放行事实为空。 */
|
||||
int insertCopiedRevisionRow(@Param("values") Map<String,Object> values);
|
||||
/** 返回新的首版轮次 ID,不复用来源版本标识。 */
|
||||
default long insertCopiedRevision(Map<String,Object> values) { insertCopiedRevisionRow(values); return PmMapperWrite.generatedId(values); }
|
||||
/** 初始指针仅从空值设置,防止覆盖已经发生执行的轮次。 */
|
||||
int initializeCopiedRevision(@Param("stageId") long stageId,@Param("revisionId") long revisionId);
|
||||
/** 只写新迭代内部映射后的端点,数据库复合外键再次校验边界。 */
|
||||
int insertCopiedEdge(@Param("values") Map<String,Object> values);
|
||||
/** 保存复制完成的初始定义,未来首次开始可绑定该迭代自己的快照。 */
|
||||
int insertCopiedDefinition(@Param("values") Map<String,Object> values);
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.ruoyi.project.manage.mapper;
|
||||
|
||||
import com.ruoyi.project.manage.mapper.support.PmMapperWrite;
|
||||
import java.util.Map;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/** 项目协作对象访问接口;固定 SQL 位于同名 XML,服务层负责权限、事务与规则。 */
|
||||
@Mapper
|
||||
public interface PmLayoutMapper {
|
||||
/** 锁定个人或共享布局行,版本检查与保存必须处于同一事务。 */
|
||||
Map<String,Object> selectLayoutForUpdate(@Param("projectId") long projectId, @Param("ownerId") long ownerId);
|
||||
|
||||
/** 读取指定拥有者布局,个人草稿不会覆盖共享布局。 */
|
||||
Map<String,Object> selectLayout(@Param("projectId") long projectId, @Param("ownerId") long ownerId);
|
||||
|
||||
/** 写入新的布局行并返回生成 ID,坐标已由服务校验。 */
|
||||
int insertLayoutRow(@Param("values") Map<String,Object> values);
|
||||
/** 使用数据库生成键;插入与外层业务校验共享一个事务。 */
|
||||
default long insertLayout(Map<String,Object> values) { insertLayoutRow(values); return PmMapperWrite.generatedId(values); }
|
||||
|
||||
/** 按布局独立版本更新,避免并发拖动覆盖他人或旧草稿。 */
|
||||
int updateLayoutRow(@Param("id") long id, @Param("version") int version, @Param("values") Map<String,Object> values);
|
||||
/** 版本不匹配必须拒绝覆盖;业务服务持有项目锁并在同一事务内记录历史。 */
|
||||
default void updateLayout(long id,int version,Map<String,Object> values) { PmMapperWrite.requireUpdated(updateLayoutRow(id,version,values)); }
|
||||
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
package com.ruoyi.project.manage.mapper;
|
||||
|
||||
import com.ruoyi.project.manage.mapper.support.PmMapperWrite;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/** 阶段轮次、回退事件和流程定义快照的持久层;业务一致性由同一项目行锁保护。 */
|
||||
@Mapper
|
||||
public interface PmRevisionMapper {
|
||||
/** 读取当前阶段版本,供图加载和状态推导共用。 */
|
||||
List<Map<String,Object>> selectCurrentRevisions(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
/** 按项目与阶段读取历史轮次,避免跨项目版本 ID 泄露。 */
|
||||
List<Map<String,Object>> selectStageRevisions(@Param("projectId") long projectId,@Param("iterationId") long iterationId,@Param("stageId") long stageId);
|
||||
/** 查单个历史轮次元数据。 */
|
||||
Map<String,Object> selectRevision(@Param("projectId") long projectId,@Param("iterationId") long iterationId,@Param("stageId") long stageId,@Param("revisionId") long revisionId);
|
||||
/** 历史工作项只按选定版本返回,不参加当前图校验。 */
|
||||
List<Map<String,Object>> selectRevisionItems(@Param("revisionId") long revisionId);
|
||||
/** 新建执行版本,数据库唯一键防止同一阶段重复版本号。 */
|
||||
int insertRevisionRow(@Param("values") Map<String,Object> values);
|
||||
/** 在项目锁事务中取得新执行版本 ID。 */
|
||||
default long insertRevision(Map<String,Object> values) { insertRevisionRow(values); return PmMapperWrite.generatedId(values); }
|
||||
/** 初建阶段将空指针设为首版;回退须使用带旧指针的切换方法。 */
|
||||
int initializeCurrentRevision(@Param("projectId") long projectId,@Param("stageId") long stageId,@Param("revisionId") long revisionId);
|
||||
/** 切换阶段当前版本时检查原指针,防止过期替换。 */
|
||||
int switchCurrentRevision(@Param("projectId") long projectId,@Param("stageId") long stageId,@Param("previousId") long previousId,@Param("nextId") long nextId);
|
||||
/** 工作项状态变更时记录当前版本首次开始和完成时刻。 */
|
||||
int updateRevisionState(@Param("revisionId") long revisionId,@Param("startedAt") Long startedAt,@Param("completedAt") Long completedAt);
|
||||
/** 旧执行版本只读标记与当前版本指针在同一事务提交。 */
|
||||
int supersedeRevision(@Param("revisionId") long revisionId,@Param("at") long at);
|
||||
/** 单迭代图版本用于回退、结束和复制预览的并发检测。 */
|
||||
Map<String,Object> selectGraphVersion(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
/** 图相关写入在持锁事务中推进版本,失败时随业务回滚。 */
|
||||
int advanceGraphVersion(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
/**
|
||||
* 成员资格变化会改变复制时的负责人有效性,仅使引用该成员的迭代预览失效。
|
||||
* @param projectId 已持统一项目锁的独立项目
|
||||
* @param userId 本次真正加入或移除的有效账号
|
||||
* @return 推进版本的迭代数;包含可被用作复制来源的终态和归档迭代
|
||||
*/
|
||||
int advanceMemberAffectedGraphVersions(@Param("projectId") long projectId,@Param("userId") long userId);
|
||||
/** 幂等键查已提交回退;必须先校验项目管理权限。 */
|
||||
Map<String,Object> selectReworkByKey(@Param("projectId") long projectId,@Param("iterationId") long iterationId,@Param("key") String key);
|
||||
/** 保存一次回退事件及完整影响摘要。 */
|
||||
int insertReworkRow(@Param("values") Map<String,Object> values);
|
||||
/** 返回回退事件 ID,版本、复制与历史写入仍在调用事务内。 */
|
||||
default long insertRework(Map<String,Object> values) { insertReworkRow(values); return PmMapperWrite.generatedId(values); }
|
||||
/** 在同一回退事务保存最终 ID 映射,幂等重试无需重新执行复制。 */
|
||||
int saveReworkResult(@Param("reworkId") long reworkId,@Param("result") String result);
|
||||
/** 为项目拓扑和阶段元数据变更保存只读定义快照。 */
|
||||
int insertDefinitionRow(@Param("values") Map<String,Object> values);
|
||||
/** 读取定义快照的新 ID。 */
|
||||
default long insertDefinition(Map<String,Object> values) { insertDefinitionRow(values); return PmMapperWrite.generatedId(values); }
|
||||
/** 取得项目最后一版定义编号。 */
|
||||
Map<String,Object> selectLatestDefinition(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
/** 历史版本只通过本项目绑定的定义 ID 读取当时的连线,不用当前流程图冒充旧版。 */
|
||||
Map<String,Object> selectDefinition(@Param("projectId") long projectId,@Param("iterationId") long iterationId,@Param("definitionId") long definitionId);
|
||||
/** 将当前版本首次启动绑定当时的流程定义快照。 */
|
||||
int bindStartedDefinition(@Param("revisionId") long revisionId,@Param("definitionId") long definitionId);
|
||||
/** 第一次启动时固化当时阶段名称和负责人,避免开始前编辑污染历史展示。 */
|
||||
int refreshStartedIdentity(@Param("revisionId") long revisionId,@Param("name") String name,@Param("ownerId") Long ownerId);
|
||||
/** 当前未换版待开始项需要显式排期复核。 */
|
||||
int markScheduleReview(@Param("itemId") long itemId,@Param("reworkId") long reworkId);
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.ruoyi.project.manage.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.*;
|
||||
|
||||
/** 阶段时间和回退线只通过固定 SQL 访问;项目锁和业务约束由服务维护。 */
|
||||
@Mapper
|
||||
public interface PmScheduleMapper {
|
||||
/** 更新仍为当前的执行版本;双重版本条件避免旧页面覆盖回退后的新轮次。 */
|
||||
int updateStagePlan(@Param("revisionId") long revisionId,@Param("version") int version,@Param("values") Map<String,Object> values);
|
||||
/** 将失效计划转存参考区间,连续回退保留已有参考;调用方已锁项目并确定影响闭包。 */
|
||||
int markStageReview(@Param("revisionId") long revisionId,@Param("reworkId") long reworkId);
|
||||
/** 只聚合成功提交的回退事件;幂等记录唯一键保证重试不重复累计,不读执行边表。 */
|
||||
List<Map<String,Object>> selectReworkEdges(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package com.ruoyi.project.manage.mapper;
|
||||
|
||||
import com.ruoyi.project.manage.mapper.support.PmMapperWrite;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/** 项目协作对象访问接口;固定 SQL 位于同名 XML,服务层负责权限、事务与规则。 */
|
||||
@Mapper
|
||||
public interface PmStageMapper {
|
||||
/** 移除成员前检查其是否负责有效阶段。 */
|
||||
Map<String,Object> selectOwnedStage(@Param("projectId") long projectId, @Param("userId") Long userId);
|
||||
|
||||
/** 验证阶段归属当前项目且未软删除。 */
|
||||
Map<String,Object> selectActiveStageId(@Param("stageId") Long stageId, @Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
|
||||
/** 按展示顺序及 ID 返回有效阶段;执行边由独立查询决定。 */
|
||||
List<Map<String,Object>> selectVisibleStages(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
|
||||
/** 校验画布阶段引用时读取当前项目全部阶段 ID。 */
|
||||
List<Map<String,Object>> selectProjectStageIds(@Param("projectId") long projectId);
|
||||
|
||||
/** 编辑阶段前重读有效行与版本,避免并发删除。 */
|
||||
Map<String,Object> selectActiveStage(@Param("stageId") long stageId, @Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
|
||||
/** 插入项目阶段受控列,排序及负责人规则由服务校验。 */
|
||||
int insertStageRow(@Param("values") Map<String,Object> values);
|
||||
/** 使用数据库生成键;插入与外层业务校验共享一个事务。 */
|
||||
default long insertStage(Map<String,Object> values) { insertStageRow(values); return PmMapperWrite.generatedId(values); }
|
||||
|
||||
/** 按版本更新阶段,项目锁同时保护工作项归属。 */
|
||||
int updateStageRow(@Param("id") long id, @Param("version") int version, @Param("values") Map<String,Object> values);
|
||||
/** 版本不匹配必须拒绝覆盖;业务服务持有项目锁并在同一事务内记录历史。 */
|
||||
default void updateStage(long id,int version,Map<String,Object> values) { PmMapperWrite.requireUpdated(updateStageRow(id,version,values)); }
|
||||
|
||||
/** 项目图加载全部当前有效阶段边;两端软删除后不能继续阻塞开始。 */
|
||||
List<Map<String,Object>> selectStageEdges(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
|
||||
/** 项目锁内插入显式执行边,数据库唯一键和复合外键提供最后一道约束。 */
|
||||
int insertStageEdgeRow(@Param("values") Map<String,Object> values);
|
||||
|
||||
/** 返回数据库生成的边 ID,供画布断线操作使用。 */
|
||||
default long insertStageEdge(Map<String,Object> values) { insertStageEdgeRow(values); return PmMapperWrite.generatedId(values); }
|
||||
|
||||
/** 版本匹配才删除阶段边,调用方已验证项目、管理权限及最终图。 */
|
||||
int deleteStageEdge(@Param("id") long id,@Param("projectId") long projectId,@Param("version") int version);
|
||||
|
||||
/** 软删空阶段前清理仍有效的入边和出边。 */
|
||||
int deleteEdgesForStage(@Param("projectId") long projectId,@Param("stageId") long stageId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.ruoyi.project.manage.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/** 项目协作对象访问接口;固定 SQL 位于同名 XML,服务层负责权限、事务与规则。 */
|
||||
@Mapper
|
||||
public interface PmUserMapper {
|
||||
/** 只列出有效账号候选人,查询词仍通过参数绑定。 */
|
||||
List<Map<String,Object>> selectCandidates(@Param("nicknamePattern") String nicknamePattern);
|
||||
|
||||
/** 成员维护前确认目标系统账号仍有效。 */
|
||||
Map<String,Object> selectActiveUser(@Param("userId") long userId);
|
||||
|
||||
/** 负责人必须是有效项目成员或经理,拒绝跨项目指派。 */
|
||||
Map<String,Object> selectAssignableUser(@Param("projectId") long projectId, @Param("userId") Long userId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package com.ruoyi.project.manage.mapper;
|
||||
|
||||
import com.ruoyi.project.manage.mapper.support.PmMapperWrite;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/** 项目协作对象访问接口;固定 SQL 位于同名 XML,服务层负责权限、事务与规则。 */
|
||||
@Mapper
|
||||
public interface PmWorkItemMapper {
|
||||
/** 移除成员前查找其未删除工作项,避免留下不可访问的负责人。 */
|
||||
Map<String,Object> selectAssignedItem(@Param("projectId") long projectId, @Param("userId") Long userId);
|
||||
|
||||
/** 路由鉴权只取工作项所属项目 ID,不先暴露内容。 */
|
||||
Map<String,Object> selectProjectReference(@Param("itemId") long itemId);
|
||||
|
||||
/** 插入受控工作项列,状态和时间必须先由服务规则校验。 */
|
||||
int insertWorkItemRow(@Param("values") Map<String,Object> values);
|
||||
/** 使用数据库生成键;插入与外层业务校验共享一个事务。 */
|
||||
default long insertWorkItem(Map<String,Object> values) { insertWorkItemRow(values); return PmMapperWrite.generatedId(values); }
|
||||
|
||||
/** 按版本写入工作项,项目锁保护依赖、排期及生命周期约束。 */
|
||||
int updateWorkItemRow(@Param("id") long id, @Param("version") int version, @Param("values") Map<String,Object> values);
|
||||
/** 版本不匹配必须拒绝覆盖;业务服务持有项目锁并在同一事务内记录历史。 */
|
||||
default void updateWorkItem(long id,int version,Map<String,Object> values) { PmMapperWrite.requireUpdated(updateWorkItemRow(id,version,values)); }
|
||||
|
||||
/** 删除阶段前检查是否仍有有效工作项归属。 */
|
||||
Map<String,Object> selectItemInStage(@Param("projectId") long projectId, @Param("stageId") long stageId);
|
||||
|
||||
/** 加载项目全部工作项 ID,验证画布坐标不引用其他项目。 */
|
||||
List<Map<String,Object>> selectProjectItemIds(@Param("projectId") long projectId);
|
||||
|
||||
/** 按稳定 ID 加载项目完整工作项快照,含软删除记录供依赖校验。 */
|
||||
List<Map<String,Object>> selectGraphItems(@Param("projectId") long projectId,@Param("iterationId") long iterationId);
|
||||
|
||||
/** 历史详情查询仍限定项目归属,写操作必须拒绝此类旧 ID。 */
|
||||
Map<String,Object> selectHistoricalItem(@Param("projectId") long projectId,@Param("itemId") long itemId);
|
||||
|
||||
/** 判别同项目旧版本和软删除项,不能将任意缺失图节点直接当作可编辑。 */
|
||||
Map<String,Object> selectRevisionReference(@Param("projectId") long projectId,@Param("itemId") long itemId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
package com.ruoyi.project.manage.mapper;
|
||||
|
||||
import com.ruoyi.project.manage.mapper.support.PmMapperWrite;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/** 项目协作对象访问接口;固定 SQL 位于同名 XML,服务层负责权限、事务与规则。 */
|
||||
@Mapper
|
||||
public interface PmWorkspaceMapper {
|
||||
/** 按当前用户的成员资格筛选独立协作项目,避免暴露非成员项目及创建人。 */
|
||||
List<Map<String,Object>> selectVisibleProjects(@Param("userId") long userId, @Param("administrator") boolean administrator);
|
||||
|
||||
/** 只返回创建或参与项目所在的空间,防止空间选择器泄露无权项目。 */
|
||||
List<Map<String,Object>> selectVisibleSpaces(@Param("userId") long userId, @Param("administrator") boolean administrator);
|
||||
|
||||
/** 删除空间前检查有效项目,软删除项目不会阻止清理空空间。 */
|
||||
Map<String,Object> selectActiveProjectInSpace(@Param("spaceId") long spaceId);
|
||||
|
||||
/** 为新项目幂等创建锁行,同项目跨记录更新需要共用此锁。 */
|
||||
int ensureProjectLock(@Param("projectId") long projectId);
|
||||
|
||||
/** 在空间和项目锁内变更归属并推进配置版本,避免并发删除空间。 */
|
||||
int moveProjectSpace(@Param("spaceId") Long spaceId, @Param("projectId") long projectId);
|
||||
|
||||
/** 读取独立协作配置,缺失时不回退到项目列表数据。 */
|
||||
Map<String,Object> selectConfig(@Param("projectId") long projectId);
|
||||
|
||||
/** 项目内容变化后推进版本,让并发编辑能发现旧快照。 */
|
||||
int incrementProjectVersion(@Param("projectId") long projectId);
|
||||
|
||||
/** 只投影有效成员的最小身份信息,不返回系统账号敏感列。 */
|
||||
List<Map<String,Object>> selectMembers(@Param("projectId") long projectId);
|
||||
|
||||
/** 读取项目经理以保护管理角色和成员关系。 */
|
||||
Map<String,Object> selectProjectManager(@Param("projectId") long projectId);
|
||||
|
||||
/** 权限及受分配工作项检查通过后移除成员,服务事务仍持有项目锁。 */
|
||||
int deleteMember(@Param("projectId") long projectId, @Param("userId") Long userId);
|
||||
|
||||
/** 按项目和用户唯一键维护成员角色,避免重复邀请产生多条记录。 */
|
||||
int upsertMember(@Param("projectId") long projectId, @Param("userId") Long userId, @Param("role") String role, @Param("actorName") String actorName);
|
||||
|
||||
/** 确认项目使用独立协作存储,不接受项目列表中的同 ID 对象。 */
|
||||
Map<String,Object> selectConfiguredProject(@Param("projectId") long projectId);
|
||||
|
||||
/** 在空间维护事务中独占有效空间行,防止并发创建项目或删除空间。 */
|
||||
Map<String,Object> selectSpaceForUpdate(@Param("spaceId") Long spaceId);
|
||||
|
||||
/** 为新项目保存空间及固定创建人,时区沿用历史数据库列的北京时间默认值。 */
|
||||
int insertConfig(@Param("projectId") long projectId, @Param("spaceId") long spaceId, @Param("creatorId") Long creatorId);
|
||||
|
||||
/** 只插入 XML 白名单中的空间列,保留数据库默认版本及删除标记。 */
|
||||
int insertSpaceRow(@Param("values") Map<String,Object> values);
|
||||
/** 使用数据库生成键;插入与外层业务校验共享一个事务。 */
|
||||
default long insertSpace(Map<String,Object> values) { insertSpaceRow(values); return PmMapperWrite.generatedId(values); }
|
||||
|
||||
/** 只插入 XML 白名单中的独立项目列,不引用项目列表主表。 */
|
||||
int insertProjectRow(@Param("values") Map<String,Object> values);
|
||||
/** 使用数据库生成键;插入与外层业务校验共享一个事务。 */
|
||||
default long insertProject(Map<String,Object> values) { insertProjectRow(values); return PmMapperWrite.generatedId(values); }
|
||||
|
||||
/** 插入成员关系的受控列,身份和角色由服务层校验。 */
|
||||
int insertMemberRow(@Param("values") Map<String,Object> values);
|
||||
/** 使用数据库生成键;插入与外层业务校验共享一个事务。 */
|
||||
default long insertMember(Map<String,Object> values) { insertMemberRow(values); return PmMapperWrite.generatedId(values); }
|
||||
|
||||
/** 以旧版本为条件更新空间,删除仍采用软删除字段。 */
|
||||
int updateSpaceRow(@Param("id") long id, @Param("version") int version, @Param("values") Map<String,Object> values);
|
||||
/** 版本不匹配必须拒绝覆盖;业务服务持有项目锁并在同一事务内记录历史。 */
|
||||
default void updateSpace(long id,int version,Map<String,Object> values) { PmMapperWrite.requireUpdated(updateSpaceRow(id,version,values)); }
|
||||
|
||||
/** 以旧版本为条件更新独立项目,避免并发覆盖名称或删除状态。 */
|
||||
int updateProjectRow(@Param("id") long id, @Param("version") int version, @Param("values") Map<String,Object> values);
|
||||
/** 版本不匹配必须拒绝覆盖;业务服务持有项目锁并在同一事务内记录历史。 */
|
||||
default void updateProject(long id,int version,Map<String,Object> values) { PmMapperWrite.requireUpdated(updateProjectRow(id,version,values)); }
|
||||
|
||||
/** 读取稳定创建人而非当前经理,编辑和删除只由创建人授权。 */
|
||||
Map<String,Object> selectCreatorProject(@Param("projectId") long projectId);
|
||||
|
||||
/** 鉴权时只读取未软删除的独立项目经理。 */
|
||||
Map<String,Object> selectActiveProjectManager(@Param("projectId") long projectId);
|
||||
|
||||
/** 按当前项目重新读取成员角色,避免沿用已经撤销的权限。 */
|
||||
Map<String,Object> selectMemberRole(@Param("projectId") long projectId, @Param("userId") long userId);
|
||||
|
||||
/** 共享锁读取项目锁行,保护布局写入期间的成员与删除状态。 */
|
||||
Map<String,Object> selectProjectForShare(@Param("projectId") long projectId);
|
||||
|
||||
/** 独占项目锁行直到事务提交,防止依赖图和排期发生跨记录竞态。 */
|
||||
Map<String,Object> selectProjectLockForUpdate(@Param("projectId") long projectId);
|
||||
/** 未启用协作时拒绝写入;锁由外层事务持有到历史及 outbox 一同提交。 */
|
||||
default void lockProject(long projectId) {
|
||||
if (selectProjectLockForUpdate(projectId)==null) throw PmException.bad("项目尚未启用协作管理");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.ruoyi.project.manage.mapper.support;
|
||||
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import java.util.Map;
|
||||
|
||||
/** MyBatis 写入返回值检查;仅处理生成键和乐观版本,不定义 SQL 或事务边界。 */
|
||||
public final class PmMapperWrite {
|
||||
private PmMapperWrite() { }
|
||||
|
||||
/** 插入后读取 MyBatis 写回的数据库主键,避免调用方把未保存对象当成已保存。 */
|
||||
public static long generatedId(Map<String,Object> values) {
|
||||
Object id=values.get("id");
|
||||
if (!(id instanceof Number number)) throw new IllegalStateException("数据库未返回生成的对象 ID");
|
||||
return number.longValue();
|
||||
}
|
||||
|
||||
/** 更新零行意味着客户端版本过期或记录已不存在,不能静默覆盖或记录成功历史。 */
|
||||
public static void requireUpdated(int changed) {
|
||||
if(changed!=1) throw PmException.conflict("VERSION_CONFLICT","数据已被修改,请刷新后重试");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
package com.ruoyi.project.manage.rule;
|
||||
|
||||
import com.ruoyi.project.manage.domain.Graph;
|
||||
import com.ruoyi.project.manage.domain.Item;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import java.util.*;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
/** 迭代生命周期纯规则;读取当前图,不把历史完成或空集合当作正常完成。 */
|
||||
public final class PmIterationRules {
|
||||
/** 规则不保存状态,所有并发快照由服务在项目锁内提供。 */
|
||||
private PmIterationRules() { }
|
||||
|
||||
/** 根据当前状态校验动作;归档只开放读取和取消归档,执行开始仅允许 ACTIVE。 */
|
||||
public static void requireAction(String status,boolean archived,String action) {
|
||||
if("read".equals(action)) return;
|
||||
if("unarchive".equals(action)) {
|
||||
if(!archived) throw PmException.conflict("ITERATION_NOT_ARCHIVED","迭代尚未归档");
|
||||
return;
|
||||
}
|
||||
if(archived) throw PmException.conflict("ITERATION_READ_ONLY","归档迭代只读,请先取消归档");
|
||||
boolean terminal=Set.of("FINISHED","CANCELLED").contains(status);
|
||||
if("archive".equals(action)||"reopen".equals(action)) {
|
||||
if(!terminal) throw PmException.conflict("ITERATION_STATE_CONFLICT","仅结束或取消的迭代可执行该操作");
|
||||
return;
|
||||
}
|
||||
if("activate".equals(action)) {
|
||||
if(!"PLANNED".equals(status)) throw PmException.conflict("ITERATION_STATE_CONFLICT","仅筹备中的迭代可以开始");
|
||||
return;
|
||||
}
|
||||
if("delete".equals(action)) {
|
||||
if(!"PLANNED".equals(status)) throw PmException.conflict("ITERATION_STATE_CONFLICT","仅未执行的筹备迭代可以删除");
|
||||
return;
|
||||
}
|
||||
if("start".equals(action)||"finish".equals(action)) {
|
||||
if(!"ACTIVE".equals(status)) throw PmException.conflict("ITERATION_NOT_ACTIVE","迭代尚未开始或已经结束");
|
||||
return;
|
||||
}
|
||||
if(terminal) throw PmException.conflict("ITERATION_READ_ONLY","结束或取消的迭代只读");
|
||||
if(!Set.of("PLANNED","ACTIVE").contains(status)) throw PmException.conflict("ITERATION_STATE_CONFLICT","迭代状态不允许操作");
|
||||
}
|
||||
|
||||
/**
|
||||
* 从当前有效图构造结束或取消清单,键由对象 ID 派生,供提交时精确比对。
|
||||
* @param graph 持锁读取的当前轮次图,历史和软删除项不参加完成判断
|
||||
* @param iterationId 当前迭代标识
|
||||
* @param version 元数据版本
|
||||
* @param graphVersion 任务和结构版本
|
||||
* @param action finish 或 cancel
|
||||
* @return 含完整影响清单和可提交标识的安全预览
|
||||
*/
|
||||
public static Map<String,Object> preview(Graph graph,long iterationId,long version,long graphVersion,String action) {
|
||||
List<Item> current=graph.items().values().stream().filter(i->!i.deleted()).sorted(Comparator.comparingLong(Item::id)).toList();
|
||||
List<Map<String,Object>> unfinished=current.stream().filter(i->Set.of("READY","IN_PROGRESS").contains(i.status())).map(PmIterationRules::itemSummary).toList();
|
||||
List<Map<String,Object>> exceptions=new ArrayList<>();
|
||||
if(current.isEmpty()) exceptions.add(map("key","EMPTY_ITERATION","message","迭代没有有效工作项,不能按正常完成结束"));
|
||||
for(Item item:current) if("CANCELLED".equals(item.status())) exceptions.add(map("key","ITEM_CANCELLED:"+item.id(),"message","工作项已取消","itemId",item.id()));
|
||||
for(Long stageId:new TreeSet<>(graph.stageNames().keySet())) {
|
||||
if(!Set.of("COMPLETED","LEGACY_PASSED").contains(PmStageRules.executionStatus(graph,stageId)))
|
||||
exceptions.add(map("key","STAGE_INCOMPLETE:"+stageId,"message","阶段尚未完成:"+graph.stageNames().get(stageId),"stageId",stageId));
|
||||
}
|
||||
return map("iterationId",iterationId,"version",version,"graphVersion",graphVersion,"unfinishedItems",unfinished,
|
||||
"exceptions",exceptions,"finishResult",exceptions.isEmpty()?"COMPLETED":"WITH_EXCEPTIONS",
|
||||
"canCommit","cancel".equals(action)||unfinished.isEmpty(),"itemsToCancel","cancel".equals(action)?unfinished:List.of());
|
||||
}
|
||||
|
||||
/** 结束不得有未结束项;异常清单须完整确认并说明业务原因,拒绝额外或重复键。 */
|
||||
public static void confirmFinish(Map<String,Object> preview,List<String> accepted,String reason) {
|
||||
if(!Boolean.TRUE.equals(preview.get("canCommit"))) throw new PmException(409,"ITERATION_UNFINISHED","仍有未结束工作项",preview);
|
||||
List<String> expected=((List<?>)preview.get("exceptions")).stream().map(row->String.valueOf(((Map<?,?>)row).get("key"))).toList();
|
||||
if(!sameUnique(expected,accepted)) throw new PmException(409,"ITERATION_PREVIEW_CHANGED","必须确认当前完整异常清单",preview);
|
||||
if(!expected.isEmpty()&&(reason==null||reason.isBlank())) throw PmException.bad("异常结束必须填写说明");
|
||||
}
|
||||
|
||||
/** 取消必须确认全部当前未结束项;终态项不纳入清单也不会被覆盖。 */
|
||||
public static void confirmCancel(Map<String,Object> preview,List<Long> accepted) {
|
||||
List<Long> expected=((List<?>)preview.get("itemsToCancel")).stream().map(row->((Number)((Map<?,?>)row).get("id")).longValue()).toList();
|
||||
if(!sameUnique(expected,accepted)) throw new PmException(409,"ITERATION_PREVIEW_CHANGED","必须确认当前全部待取消工作项",preview);
|
||||
}
|
||||
|
||||
/** 按集合比对同时拒绝重复和空元素,避免“确认了部分清单”被宽松转换接受。 */
|
||||
private static <T> boolean sameUnique(List<T> expected,List<T> accepted) {
|
||||
List<T> actual=accepted==null?List.of():accepted;
|
||||
return actual.stream().noneMatch(Objects::isNull)&&new HashSet<>(actual).size()==actual.size()&&new HashSet<>(expected).equals(new HashSet<>(actual));
|
||||
}
|
||||
|
||||
/** 只返回确认所需的当前状态和版本,避免预览暴露完整任务描述。 */
|
||||
private static Map<String,Object> itemSummary(Item item) { return map("id",item.id(),"title",item.title(),"status",item.status(),"version",item.version()); }
|
||||
}
|
||||
@ -0,0 +1,179 @@
|
||||
package com.ruoyi.project.manage.rule;
|
||||
|
||||
import com.ruoyi.project.manage.domain.Dependency;
|
||||
import com.ruoyi.project.manage.domain.Graph;
|
||||
import com.ruoyi.project.manage.domain.Item;
|
||||
import com.ruoyi.project.manage.domain.StageLink;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.util.PmTime;
|
||||
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/** 纯业务规则仅处理已鉴权的项目快照;事务服务负责锁和持久化,便于独立验证边界。 */
|
||||
public final class PmRules {
|
||||
/** 工具类不持有数据库或用户上下文,所有判断基于传入的当前快照。 */
|
||||
private PmRules() { }
|
||||
|
||||
/** 关闭保留完成事实;取消和软删除不能满足任务已完成条件。 */
|
||||
public static boolean completed(Item item) { return !item.deleted() && Set.of("COMPLETED","CLOSED").contains(item.status()); }
|
||||
|
||||
/** 子任务终态包括取消,仅用于父任务完成门禁,不代替显式的已完成依赖。 */
|
||||
public static boolean terminal(Item item) { return Set.of("COMPLETED","CLOSED","CANCELLED").contains(item.status()); }
|
||||
|
||||
/** 按当前时间点派生超期展示,不写回生命周期;等于结束时间即超期,延期可自然解除。 */
|
||||
public static boolean overdue(Item item,long now) { return !item.deleted() && item.end()!=null && now>=item.end() && Set.of("READY","IN_PROGRESS").contains(item.status()); }
|
||||
|
||||
/** 取得有效直接子任务;父关系创建后不可变,首版只有一层。 */
|
||||
public static List<Item> children(Graph graph,long parentId) { return graph.items().values().stream().filter(i->!i.deleted()&&Objects.equals(i.parentTaskId(),parentId)).toList(); }
|
||||
|
||||
/** 返回阻止父任务完成的子任务,便于统一服务校验和前端说明门禁原因。 */
|
||||
public static List<Map<String,Object>> unfinishedChildren(Graph graph,long parentId) { return children(graph,parentId).stream().filter(i->!terminal(i)).map(i->map("taskId",i.id(),"taskName",i.title(),"currentStatus",i.status(),"message","子任务尚未结束")).toList(); }
|
||||
|
||||
/** 逐个计算直接条件的当前满足情况和排期来源;不以历史状态或缓存布尔值代替当前状态。 */
|
||||
public static List<Map<String,Object>> conditions(Graph graph,long successorId,String zone) {
|
||||
List<Map<String,Object>> result = new ArrayList<>();
|
||||
for (Dependency dep : graph.dependencies()) {
|
||||
if (dep.successorId()!=successorId) continue;
|
||||
Item task = dep.taskId()==null ? null : graph.items().get(dep.taskId());
|
||||
boolean available = task!=null && !task.deleted();
|
||||
String status = task!=null ? task.status() : "UNAVAILABLE";
|
||||
Long end = task!=null ? task.end() : null;
|
||||
result.add(map("id",dep.id(),"version",dep.version(),"conditionType",dep.type(),"sourceId",dep.taskId(),
|
||||
"sourceName",available ? task.title() : "前置对象不可用",
|
||||
"sourceWorkItemId",available ? task.id() : null,
|
||||
"currentStatus",status,"expectedStatus",dep.expected(),"satisfied",available && completed(task),
|
||||
"plannedEndAt",PmTime.format(end,zone),"participatesInSchedule",end!=null,
|
||||
"scheduleNote",null));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 只按前置任务当前状态判断;取消、回退和软删除均不能视为已完成。 */
|
||||
public static List<Map<String,Object>> blocked(Graph graph,long taskId,String zone) {
|
||||
return conditions(graph,taskId,zone).stream().filter(c -> !Boolean.TRUE.equals(c.get("satisfied"))).toList();
|
||||
}
|
||||
|
||||
/** 合并任务前置、父任务和阶段边界;缺失阶段计划只标记不完整,已知边界必须满足。 */
|
||||
public static Map<String,Object> schedule(Graph graph,Item item,String zone) {
|
||||
Long earliest = null;
|
||||
Long latest = null;
|
||||
var stage = item.stageId()==null?null:graph.stageRevisions().get(item.stageId());
|
||||
List<Map<String,Object>> reasons = new ArrayList<>();
|
||||
List<Map<String,Object>> sources = new ArrayList<>();
|
||||
boolean conflict = false;
|
||||
Item parent=item.parentTaskId()==null?null:graph.items().get(item.parentTaskId());
|
||||
if(parent!=null) {
|
||||
earliest=parent.start();
|
||||
sources.add(map("sourceId",parent.id(),"sourceName",parent.title(),"plannedStartAt",PmTime.format(parent.start(),zone),"plannedEndAt",PmTime.format(parent.end(),zone),"kind","PARENT_RANGE"));
|
||||
if(item.start()!=null&&(parent.start()==null||item.start()<parent.start()) || item.end()!=null&&(parent.end()==null||item.end()>parent.end())) {
|
||||
conflict=true; reasons.add(map("code","PARENT_SCHEDULE_CONFLICT","sourceId",parent.id(),"sourceName",parent.title(),"message","子任务时间必须在父任务范围内,且对应父时间不能为空","plannedStartAt",PmTime.format(parent.start(),zone),"plannedEndAt",PmTime.format(parent.end(),zone)));
|
||||
}
|
||||
}
|
||||
for (Dependency d : graph.dependencies()) {
|
||||
if (d.successorId()!=item.id()) continue;
|
||||
Item task = d.taskId()==null?null:graph.items().get(d.taskId());
|
||||
Long end = task!=null?task.end():null;
|
||||
String name = task!=null&&!task.deleted()?task.title():"前置对象不可用";
|
||||
if (d.taskId()!=null && end==null) reasons.add(map("code","PREDECESSOR_UNSCHEDULED","sourceId",d.taskId(),"sourceName",name,"message","前置任务未设置预计结束时间"));
|
||||
if (end!=null) {
|
||||
earliest = earliest==null?end:Math.max(earliest,end);
|
||||
Map<String,Object> source = map("predecessorTaskId",d.taskId(),"sourceName",name,"plannedEndAt",PmTime.format(end,zone));
|
||||
sources.add(source);
|
||||
if (item.start()!=null && item.start()<end) { conflict=true; reasons.add(source); }
|
||||
}
|
||||
}
|
||||
if (item.start()!=null && item.end()!=null && item.end()<item.start()) {
|
||||
conflict=true; reasons.add(map("code","OWN_SCHEDULE_CONFLICT","sourceId",item.id(),"sourceName",item.title()));
|
||||
}
|
||||
if(stage!=null&&stage.plannedStart()!=null&&stage.scheduleReviewReworkId()==null) {
|
||||
earliest=earliest==null?stage.plannedStart():Math.max(earliest,stage.plannedStart());
|
||||
latest=stage.plannedEnd();
|
||||
if(PmStageScheduleRules.outside(stage,item)) { conflict=true; reasons.add(map("code","ITEM_OUTSIDE_STAGE","sourceName",graph.stageNames().get(item.stageId()),"message","工作项时间超出阶段计划区间")); }
|
||||
sources.add(map("kind","STAGE_RANGE","stageId",item.stageId(),"revisionId",stage.id(),"sourceName",graph.stageNames().get(item.stageId()),"plannedStartAt",PmTime.format(stage.plannedStart(),zone),"plannedEndAt",PmTime.format(stage.plannedEnd(),zone)));
|
||||
}
|
||||
boolean stageIncomplete=item.stageId()!=null&&(stage==null||stage.plannedStart()==null||stage.scheduleReviewReworkId()!=null);
|
||||
if(stageIncomplete) reasons.add(map("code","STAGE_UNSCHEDULED","sourceName",graph.stageNames().get(item.stageId()),"message","阶段未排期或排期待复核,阶段约束尚不完整"));
|
||||
if(parent!=null&&parent.end()!=null) latest=latest==null?parent.end():Math.min(latest,parent.end());
|
||||
boolean missingPredecessor = reasons.stream().anyMatch(r -> "PREDECESSOR_UNSCHEDULED".equals(r.get("code")));
|
||||
String status = conflict?"CONFLICT":item.start()==null || item.end()==null || missingPredecessor || stageIncomplete || item.scheduleReviewReworkId()!=null?"INCOMPLETE":"VALID";
|
||||
return map("earliestPlannedStartAt",missingPredecessor?null:PmTime.format(earliest,zone),"latestPlannedEndAt",PmTime.format(latest,zone),"scheduleValidationStatus",status,
|
||||
"scheduleBlockedReasons",reasons,"sources",sources,"missingPredecessorEnd",missingPredecessor);
|
||||
}
|
||||
|
||||
/** 校验整张图的最终排期;只在后续已设置开始时拒绝缺失前置结束,允许暂未排期。 */
|
||||
public static void validateSchedules(Graph graph,String zone) {
|
||||
List<Map<String,Object>> conflicts = new ArrayList<>();
|
||||
String earliest = null;
|
||||
for (Item item : graph.items().values()) {
|
||||
if (item.deleted()) continue;
|
||||
Map<String,Object> summary = schedule(graph,item,zone);
|
||||
if ("CONFLICT".equals(summary.get("scheduleValidationStatus")) || item.start()!=null && Boolean.TRUE.equals(summary.get("missingPredecessorEnd"))) {
|
||||
conflicts.add(map("taskId",item.id(),"taskName",item.title(),"plannedStartAt",PmTime.format(item.start(),zone),
|
||||
"earliestPlannedStartAt",summary.get("earliestPlannedStartAt"),"reasons",summary.get("scheduleBlockedReasons")));
|
||||
if (earliest==null) earliest=(String)summary.get("earliestPlannedStartAt");
|
||||
}
|
||||
}
|
||||
PmStageScheduleRules.validate(graph);
|
||||
if (!conflicts.isEmpty()) throw new PmException(409,"SCHEDULE_DEPENDENCY_CONFLICT","排期不满足前置约束,请调整列出的工作项",map("earliestPlannedStartAt",earliest,"conflicts",conflicts));
|
||||
}
|
||||
|
||||
/** 保护进行中、完成、关闭的实际依赖及父完成门禁;回退不能留下已完成父和未结束子。 */
|
||||
public static void validateActual(Graph graph,String zone) {
|
||||
List<Map<String,Object>> affected = new ArrayList<>();
|
||||
for (Item item : graph.items().values()) {
|
||||
if (item.deleted() || !Set.of("IN_PROGRESS","COMPLETED","CLOSED").contains(item.status())) continue;
|
||||
List<Map<String,Object>> reasons = new ArrayList<>(blocked(graph,item.id(),zone));
|
||||
if(completed(item)) reasons.addAll(unfinishedChildren(graph,item.id()));
|
||||
if (!reasons.isEmpty()) affected.add(map("taskId",item.id(),"taskName",item.title(),"blockedReasons",reasons));
|
||||
}
|
||||
if (!affected.isEmpty()) throw new PmException(409,"DEPENDENT_ALREADY_STARTED","操作会使已开始或已完成对象的条件失效",map("affectedTasks",affected));
|
||||
}
|
||||
|
||||
/** 用 DFS 三色法检查任务、父子和阶段执行图;阶段进入/完成拆点,才能检测跨阶段任务死锁。 */
|
||||
public static void validateAcyclic(Graph graph) {
|
||||
Map<String,Set<String>> edges = new LinkedHashMap<>();
|
||||
for (Dependency d : graph.dependencies()) edge(edges,"T"+d.taskId(),"T"+d.successorId());
|
||||
// 父完成等待所有子任务结束,因此子完成→父完成也是执行图中的边。
|
||||
// 与显式依赖一起检查,防止子任务等待父完成或跨父形成间接死锁。
|
||||
for(Item item:graph.items().values()) if(!item.deleted()&&item.parentTaskId()!=null) edge(edges,"T"+item.id(),"T"+item.parentTaskId());
|
||||
// 进入阶段后才可启动工作项;阶段所有工作项完成后才可进入下游。
|
||||
// 空阶段仍有进入→完成边,使纯阶段环及混合任务环使用同一检测算法。
|
||||
for(Long stageId:graph.stageNames().keySet()) edge(edges,"I"+stageId,"O"+stageId);
|
||||
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());
|
||||
}
|
||||
for(StageLink link:graph.stageLinks()) edge(edges,"O"+link.predecessorStageId(),"I"+link.successorStageId());
|
||||
Map<String,Integer> colors = new HashMap<>();
|
||||
for (String vertex : new ArrayList<>(edges.keySet())) visit(vertex,edges,colors,new ArrayList<>(),graph);
|
||||
}
|
||||
|
||||
/** 增加前置→后续边,并注册后续顶点;去重避免重复遍历。 */
|
||||
private static void edge(Map<String,Set<String>> edges,String from,String to) { edges.computeIfAbsent(from,k->new LinkedHashSet<>()).add(to); edges.computeIfAbsent(to,k->new LinkedHashSet<>()); }
|
||||
|
||||
private record Frame(String vertex,Iterator<String> next) { }
|
||||
|
||||
/** 显式栈检测灰色顶点回边,避免长依赖链耗尽线程栈;响应仅包含已鉴权项目路径。 */
|
||||
private static void visit(String v,Map<String,Set<String>> edges,Map<String,Integer> colors,List<String> path,Graph graph) {
|
||||
if (colors.getOrDefault(v,0)==2) return;
|
||||
Deque<Frame> stack=new ArrayDeque<>();
|
||||
colors.put(v,1); path.add(v); stack.push(new Frame(v,edges.getOrDefault(v,Set.of()).iterator()));
|
||||
while(!stack.isEmpty()) {
|
||||
Frame current=stack.peek();
|
||||
if(!current.next().hasNext()) { colors.put(current.vertex(),2); path.remove(path.size()-1); stack.pop(); continue; }
|
||||
String next=current.next().next(); int color=colors.getOrDefault(next,0);
|
||||
if(color==2) continue;
|
||||
if(color==1) {
|
||||
List<String> cycle=new ArrayList<>(path.subList(path.indexOf(next),path.size())); cycle.add(next);
|
||||
List<String> names=cycle.stream().map(x -> {
|
||||
long id=Long.parseLong(x.substring(1));
|
||||
if(x.startsWith("T")) { Item item=graph.items().get(id); return (item==null?"不可用工作项":item.title())+" [工作项 "+id+"]"; }
|
||||
return graph.stageNames().getOrDefault(id,"不可用阶段")+" [阶段 "+id+(x.startsWith("I")?" 进入]":" 完成]");
|
||||
}).toList();
|
||||
throw new PmException(409,"DEPENDENCY_CYCLE","依赖形成循环:"+String.join(" → ",names),map("dependencyPath",names));
|
||||
}
|
||||
colors.put(next,1); path.add(next); stack.push(new Frame(next,edges.getOrDefault(next,Set.of()).iterator()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package com.ruoyi.project.manage.rule;
|
||||
|
||||
import com.ruoyi.project.manage.domain.*;
|
||||
import java.util.*;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
/** 回退排期影响闭包与执行换版分开;参考转换不得静默改写已开始或完成的对象。 */
|
||||
public final class PmScheduleReviewRules {
|
||||
/** 仅通过静态纯规则使用。 */
|
||||
private PmScheduleReviewRules() { }
|
||||
/** 阶段、任务和不能安全复核的对象清单,供预览与提交共用。 */
|
||||
public record Impact(List<Long> stageIds,List<Long> itemIds,List<Map<String,Object>> blockers) { }
|
||||
/**
|
||||
* 从换版阶段的后继传播阶段、任务前置和父子排期失效,直到集合不再增长。
|
||||
* 空阶段也纳入,避免有计划但无工作项的后继漏掉。遇已执行对象返回阻塞,而不擦除执行记录。
|
||||
* @param graph 当前完整图
|
||||
* @param replaced 已由现有执行影响规则确定的换版阶段集合
|
||||
* @return 稳定顺序的复核集合及可理解的阻塞原因;不修改原图
|
||||
*/
|
||||
public static Impact affected(Graph graph,Set<Long> replaced) {
|
||||
Set<Long> 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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 升级旧数据时从已有失效标记补齐同一闭包,而不是再次触发执行换版。
|
||||
* @param graph 仅包含当前版本的图;历史不能作为传播种子
|
||||
* @param stageIds 已待复核的当前阶段
|
||||
* @param itemIds 已待复核的当前工作项
|
||||
* @return 包含已执行对象的影响清单;迁移器必须显式保护它们,不能无条件清空计划
|
||||
*/
|
||||
public static Impact pending(Graph graph,Set<Long> stageIds,Set<Long> itemIds) {
|
||||
return closure(graph,Set.of(),stageIds,itemIds);
|
||||
}
|
||||
|
||||
/** 运行时回退与升级共用不动点传播,避免迁移遗漏取消子项或跨阶段任务后继。 */
|
||||
private static Impact closure(Graph graph,Set<Long> replaced,Set<Long> stageSeeds,Set<Long> itemSeeds) {
|
||||
Set<Long> stages=new TreeSet<>(stageSeeds),items=new TreeSet<>(itemSeeds); boolean changed;
|
||||
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(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());
|
||||
if(item.parentTaskId()!=null) items.add(item.parentTaskId());
|
||||
}
|
||||
}
|
||||
for(Dependency dep:graph.dependencies()) if(items.contains(dep.taskId())) {
|
||||
Item next=graph.items().get(dep.successorId());
|
||||
if(next!=null&&!next.deleted()&&(next.stageId()==null||!replaced.contains(next.stageId()))) { items.add(next.id()); if(next.stageId()!=null) stages.add(next.stageId()); }
|
||||
}
|
||||
changed=before!=stages.size()+items.size();
|
||||
} while(changed);
|
||||
List<Map<String,Object>> blockers=new ArrayList<>();
|
||||
for(Long id:stages) if(!"NOT_STARTED".equals(PmStageRules.executionStatus(graph,id))) blockers.add(map("code","EXECUTED_SCHEDULE_REVIEW","stageId",id,"sourceName",graph.stageNames().get(id),"message","排期影响到已执行阶段,请调整回退范围后重试"));
|
||||
for(Long id:items) { Item item=graph.items().get(id); if(item!=null&&!Set.of("READY","CANCELLED").contains(item.status())) blockers.add(map("code","EXECUTED_SCHEDULE_REVIEW","taskId",id,"taskName",item.title(),"message","不能将已执行工作项的计划静默转为参考")); }
|
||||
return new Impact(List.copyOf(stages),List.copyOf(items),blockers);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,120 @@
|
||||
package com.ruoyi.project.manage.rule;
|
||||
|
||||
import com.ruoyi.project.manage.domain.Graph;
|
||||
import com.ruoyi.project.manage.domain.Item;
|
||||
import com.ruoyi.project.manage.domain.StageLink;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
import java.util.*;
|
||||
|
||||
/** 阶段执行规则只处理已鉴权的项目快照,具体读写和互斥由服务层负责。 */
|
||||
public final class PmStageRules {
|
||||
/** 纯规则类不保存状态,避免缓存的阶段完成结果在成员编辑后过期。 */
|
||||
private PmStageRules() { }
|
||||
|
||||
/**
|
||||
* 从目标阶段逆向遍历所有祖先,检查当前版本是否完成或有迁移兼容事实。
|
||||
* 新空阶段保持未执行并阻塞后继,避免空版本被误认为已完成。
|
||||
* @param graph 项目锁内读取的当前图
|
||||
* @param itemId 要开始或展示的工作项 ID
|
||||
* @return 未完成上游阶段的可读原因;未分配阶段的工作项返回空列表
|
||||
*/
|
||||
public static List<Map<String,Object>> blocked(Graph graph,long itemId) {
|
||||
Item item=graph.items().get(itemId);
|
||||
if(item==null||item.stageId()==null) return List.of();
|
||||
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";
|
||||
List<Item> 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";
|
||||
return "NOT_STARTED";
|
||||
}
|
||||
|
||||
/**
|
||||
* 从当前版本事实判断流程推进到的阶段,不用持久化指针限制并行分支。
|
||||
* 未执行和执行中的阶段,只要所有上游已经完成便是当前阶段;空阶段仍未完成。
|
||||
* @param graph 已鉴权、在项目锁内读取的当前迭代图
|
||||
* @param stageId 待判断的有效阶段 ID
|
||||
* @return 是否为当前阶段;全部完成时所有阶段均返回 false
|
||||
*/
|
||||
public static boolean isCurrent(Graph graph,long stageId) {
|
||||
return graph.stageNames().containsKey(stageId)
|
||||
&& !Set.of("COMPLETED","LEGACY_PASSED").contains(executionStatus(graph,stageId))
|
||||
&& blockedStage(graph,stageId).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 画布能力与回退预览、提交共用来源规则,防止仅隐藏按钮而保留旧的已完成阶段入口。
|
||||
* @param graph 当前版本图;回退换版后重新调用即可得到新的当前阶段
|
||||
* @param stageId 发起回退的来源阶段,调用方须先校验归属与访问权限
|
||||
* @return 来源不合法的原因;空列表只代表业务条件满足,权限及迭代门禁仍由服务检查
|
||||
*/
|
||||
public static List<Map<String,Object>> reworkBlocked(Graph graph,long stageId) {
|
||||
if(graph.stageNames().containsKey(stageId)&&graph.stageLinks().stream().noneMatch(edge->edge.successorStageId()==stageId))
|
||||
return List.of(map("code","REWORK_FIRST_STAGE","stageId",stageId,"message","首阶段没有上游,不能发起回退"));
|
||||
if(!isCurrent(graph,stageId))
|
||||
return List.of(map("code","REWORK_SOURCE_NOT_CURRENT","stageId",stageId,"message","只有前置阶段全部完成且自身尚未完成的当前阶段可以回退","blockedReasons",blockedStage(graph,stageId)));
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/** 阶段的全部直接和间接前置都要完成;空新阶段不能放行后继。 */
|
||||
public static List<Map<String,Object>> blockedStage(Graph graph,long stageId) {
|
||||
Map<Long,List<Long>> incoming=new HashMap<>();
|
||||
for(StageLink link:graph.stageLinks()) incoming.computeIfAbsent(link.successorStageId(),unused->new ArrayList<>()).add(link.predecessorStageId());
|
||||
List<Map<String,Object>> reasons=new ArrayList<>();
|
||||
Set<Long> visited=new HashSet<>(); Deque<Long> queue=new ArrayDeque<>(incoming.getOrDefault(stageId,List.of()));
|
||||
while(!queue.isEmpty()) {
|
||||
long predecessorId=queue.removeFirst(); if(!visited.add(predecessorId)) continue;
|
||||
List<Item> unfinished=graph.items().values().stream().filter(candidate->!candidate.deleted()&&Objects.equals(candidate.stageId(),predecessorId)&&!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()));
|
||||
queue.addAll(incoming.getOrDefault(predecessorId,List.of()));
|
||||
}
|
||||
return reasons;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只拒绝新产生的已开始工作项阶段阻塞,兼容迁移前已经开始的旧项目状态。
|
||||
* 比较阶段与未完成工作项 ID,而非单个布尔值;已有旧阻塞不能掩盖新回退或新建工作项。
|
||||
* @param before 写入前的项目图
|
||||
* @param after 模拟全部修改后的最终图
|
||||
*/
|
||||
public static void validateRegression(Graph before,Graph after) {
|
||||
List<Map<String,Object>> affected=new ArrayList<>();
|
||||
for(Item item:after.items().values()) {
|
||||
if(item.deleted()||!Set.of("IN_PROGRESS","COMPLETED","CLOSED").contains(item.status())) continue;
|
||||
Set<String> previous=new HashSet<>();
|
||||
if(before.items().containsKey(item.id())) for(Map<String,Object> reason:blocked(before,item.id())) {
|
||||
previous.add(reason.get("stageId")+":stage");
|
||||
for(Object source:(List<?>)reason.get("unfinishedItemIds")) previous.add(reason.get("stageId")+":"+source);
|
||||
}
|
||||
List<Map<String,Object>> added=blocked(after,item.id()).stream().filter(reason->!previous.contains(reason.get("stageId")+":stage")||((List<?>)reason.get("unfinishedItemIds")).stream().anyMatch(source->!previous.contains(reason.get("stageId")+":"+source))).toList();
|
||||
if(!added.isEmpty()) affected.add(map("taskId",item.id(),"taskName",item.title(),"blockedReasons",added));
|
||||
}
|
||||
if(!affected.isEmpty()) throw new PmException(409,"STAGE_DEPENDENCY_INVALIDATED","操作会使已开始工作项新增阶段阻塞",map("affectedTasks",affected));
|
||||
}
|
||||
|
||||
/** 已执行阶段的祖先集合属于启动时的准入依据;拓扑编辑只能发生在未来子图。 */
|
||||
public static void validateExecutedAncestors(Graph before,Graph after) {
|
||||
List<Long> 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(!changed.isEmpty()) throw new PmException(409,"STAGE_TOPOLOGY_LOCKED","已执行阶段的前置关系不能改写;请先回退或只编辑未开始的后续流程",map("stageIds",changed));
|
||||
}
|
||||
|
||||
/** 从显式入边取得祖先集合,画布坐标与展示顺序不参与执行定义。 */
|
||||
public static Set<Long> ancestors(Graph graph,long stageId) {
|
||||
Map<Long,List<Long>> incoming=new HashMap<>();
|
||||
for(StageLink edge:graph.stageLinks()) incoming.computeIfAbsent(edge.successorStageId(),unused->new ArrayList<>()).add(edge.predecessorStageId());
|
||||
Set<Long> result=new LinkedHashSet<>(); Deque<Long> queue=new ArrayDeque<>(incoming.getOrDefault(stageId,List.of()));
|
||||
while(!queue.isEmpty()) { Long next=queue.removeFirst(); if(result.add(next)) queue.addAll(incoming.getOrDefault(next,List.of())); }
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
package com.ruoyi.project.manage.rule;
|
||||
|
||||
import com.ruoyi.project.manage.domain.*;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.util.PmTime;
|
||||
import java.util.*;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
/** 阶段计划只使用当前执行版本的正常时间,历史和失效参考值不能成为准入依据。 */
|
||||
public final class PmStageScheduleRules {
|
||||
/** 纯规则不依赖数据库;服务在项目锁内传入完整迭代图。 */
|
||||
private PmStageScheduleRules() { }
|
||||
|
||||
/**
|
||||
* 计算阶段串行边界、工作项包含关系和复核状态。
|
||||
* @param graph 当前事务的完整最终图
|
||||
* @param stageId 所属阶段;缺失版本只能返回未排期,不能补造时间
|
||||
* @return 带时间、未决来源和冲突明细的摘要;不会修改快照
|
||||
*/
|
||||
public static Map<String,Object> summary(Graph graph,long stageId) {
|
||||
StageRevision r=graph.stageRevisions().get(stageId);
|
||||
List<Map<String,Object>> sources=new ArrayList<>(),missing=new ArrayList<>(),conflicts=new ArrayList<>();
|
||||
Long earliest=null;
|
||||
for(StageLink edge:graph.stageLinks()) if(edge.successorStageId()==stageId) {
|
||||
StageRevision p=graph.stageRevisions().get(edge.predecessorStageId());
|
||||
Map<String,Object> source=map("stageId",edge.predecessorStageId(),"sourceName",graph.stageNames().get(edge.predecessorStageId()),
|
||||
"revisionId",p==null?null:p.id(),"plannedEndAt",time(p==null?null:p.plannedEnd()));
|
||||
sources.add(source);
|
||||
if(p==null||p.plannedEnd()==null||p.scheduleReviewReworkId()!=null) {
|
||||
missing.add(map("code","PREDECESSOR_STAGE_UNSCHEDULED","stageId",edge.predecessorStageId(),"sourceName",graph.stageNames().get(edge.predecessorStageId()),"message","前置阶段未排期或排期待复核"));
|
||||
} else {
|
||||
earliest=earliest==null?p.plannedEnd():Math.max(earliest,p.plannedEnd());
|
||||
if(r!=null&&r.plannedStart()!=null&&r.plannedStart()<p.plannedEnd()) conflicts.add(source);
|
||||
}
|
||||
}
|
||||
if(r!=null) {
|
||||
if((r.plannedStart()==null)!=(r.plannedEnd()==null)||r.plannedStart()!=null&&r.plannedEnd()<r.plannedStart())
|
||||
conflicts.add(map("code","STAGE_OWN_SCHEDULE_CONFLICT","sourceName",graph.stageNames().get(stageId),"message","阶段预计时间须成对填写且结束不得早于开始"));
|
||||
for(Item item:graph.items().values()) if(!item.deleted()&&Objects.equals(item.stageId(),stageId)&&outside(r,item))
|
||||
conflicts.add(map("code","ITEM_OUTSIDE_STAGE","taskId",item.id(),"taskName",item.title(),"message","工作项时间超出阶段计划区间","plannedStartAt",time(item.start()),"plannedEndAt",time(item.end())));
|
||||
}
|
||||
boolean review=r!=null&&r.scheduleReviewReworkId()!=null;
|
||||
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<String,Object> result=times(r);
|
||||
result.putAll(map("earliestPlannedStartAt",missing.isEmpty()?time(earliest):null,"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()));
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 所选历史版本的时间只读自身快照,不使用当前上游版本重新解释过去。 */
|
||||
public static Map<String,Object> times(StageRevision r) {
|
||||
return map("revisionId",r==null?null:r.id(),"revisionVersion",r==null?null:r.version(),
|
||||
"plannedStartAt",time(r==null?null:r.plannedStart()),"plannedEndAt",time(r==null?null:r.plannedEnd()),
|
||||
"referencePlannedStartAt",time(r==null?null:r.referenceStart()),"referencePlannedEndAt",time(r==null?null:r.referenceEnd()),
|
||||
"actualStartAt",time(r==null?null:r.startedAt()),"actualEndAt",time(r==null?null:r.completedAt()),
|
||||
"scheduleReviewRequired",r!=null&&r.scheduleReviewReworkId()!=null,"scheduleReviewClosed",r!=null&&r.scheduleReviewReworkId()!=null&&r.completedAt()!=null,
|
||||
"planSource",r==null?null:r.planSource(),"planRecordedAt",time(r==null?null:r.planRecordedAt()));
|
||||
}
|
||||
|
||||
/** 已知边界必须覆盖工作项任一已填写端点,不能用倒置或半填区间逃过包含检查。 */
|
||||
public static boolean outside(StageRevision r,Item item) {
|
||||
return r.plannedStart()!=null&&(item.start()!=null&&item.start()<r.plannedStart()||item.end()!=null&&item.end()<r.plannedStart())
|
||||
||r.plannedEnd()!=null&&(item.start()!=null&&item.start()>r.plannedEnd()||item.end()!=null&&item.end()>r.plannedEnd());
|
||||
}
|
||||
|
||||
/** 整张图只拒绝实际冲突及已有阶段计划的缺失前置;空计划仍允许按实际条件执行。 */
|
||||
public static void validate(Graph graph) {
|
||||
List<Map<String,Object>> conflicts=new ArrayList<>();
|
||||
for(Long id:graph.stageNames().keySet()) {
|
||||
StageRevision r=graph.stageRevisions().get(id); Map<String,Object> view=summary(graph,id);
|
||||
if("CONFLICT".equals(view.get("scheduleValidationStatus"))||r!=null&&r.plannedStart()!=null&&!((List<?>)view.get("unresolvedSources")).isEmpty())
|
||||
conflicts.add(map("stageId",id,"sourceName",graph.stageNames().get(id),"reasons",view.get("scheduleBlockedReasons"),"earliestPlannedStartAt",view.get("earliestPlannedStartAt")));
|
||||
}
|
||||
if(!conflicts.isEmpty()) throw new PmException(409,"STAGE_SCHEDULE_CONFLICT","阶段排期不满足前置或工作项边界,请调整列出的对象",map("conflicts",conflicts));
|
||||
}
|
||||
|
||||
/** 摘要使用唯一北京时间格式,比较始终发生在 UTC 微秒值上。 */
|
||||
private static String time(Long value) { return PmTime.format(value,"Asia/Shanghai"); }
|
||||
/** 合并原因时创建新容器,避免调用方修改来源列表。 */
|
||||
private static List<Map<String,Object>> concat(List<Map<String,Object>> a,List<Map<String,Object>> b) { List<Map<String,Object>> result=new ArrayList<>(a); result.addAll(b); return result; }
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package com.ruoyi.project.manage.security;
|
||||
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.mapper.PmUserMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmWorkspaceMapper;
|
||||
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
import java.util.Map;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
|
||||
/** 项目成员与若依操作权限双重校验;服务入口也检查,内部调用不能依赖 Controller 注解。 */
|
||||
@Component
|
||||
public class PmAccess {
|
||||
private final PmWorkspaceMapper workspaceMapper;
|
||||
private final PmUserMapper userMapper;
|
||||
/** 使用同事务存储读取当前成员,防止项目权限变更后继续沿用旧缓存。 */
|
||||
public PmAccess(PmWorkspaceMapper workspaceMapper,PmUserMapper userMapper) { this.workspaceMapper=workspaceMapper; this.userMapper=userMapper; }
|
||||
|
||||
/** 获取当前已认证用户并确认仍是有效系统用户,不接受请求伪造操作人。 */
|
||||
public long actor() {
|
||||
long id=SecurityUtils.getUserId();
|
||||
if(userMapper.selectActiveUser(id)==null) throw denied();
|
||||
return id;
|
||||
}
|
||||
|
||||
/** 检查菜单动作权限;系统管理员沿用若依全权限语义。 */
|
||||
public boolean permitted(String action) { return SecurityUtils.isAdmin() || SecurityUtils.hasPermi("project:manage:"+action); }
|
||||
|
||||
/** 强制检查当前动作权限,默认拒绝未分配新增权限的普通角色。 */
|
||||
public void permission(String action) { actor(); if(!permitted(action)) throw denied(); }
|
||||
|
||||
/** 稳定创建人只来自独立协作配置;不使用项目列表账号或经理/管理员身份替代。 */
|
||||
public Map<String,Object> creatorProject(long projectId) {
|
||||
Map<String,Object> project=workspaceMapper.selectCreatorProject(projectId);
|
||||
if(project==null||!Long.valueOf(actor()).equals(nullable(project,"actualCreatorId"))) throw denied(); return project;
|
||||
}
|
||||
|
||||
/** 仅独立协作项目成员可访问;创建工作项沿用菜单读取权限和成员身份,编辑仍需写权限。 */
|
||||
public void project(long projectId,String action) {
|
||||
permission("create".equals(action)?"read":action); long user=actor();
|
||||
Map<String,Object> project=workspaceMapper.selectActiveProjectManager(projectId);
|
||||
if(project==null) throw denied();
|
||||
if(SecurityUtils.isAdmin()) return;
|
||||
Map<String,Object> member=workspaceMapper.selectMemberRole(projectId,user);
|
||||
boolean manager=Long.valueOf(user).equals(nullable(project,"manager_id")) || member!=null&&"MANAGER".equals(text(member,"member_role"));
|
||||
if(member==null&&!manager || "admin".equals(action)&&!manager) throw denied();
|
||||
}
|
||||
|
||||
/** 负责人必须是独立协作项目成员或经理,项目列表成员不能获得任务分配资格。 */
|
||||
public void assignee(long projectId,Long userId) {
|
||||
if(userId==null) return;
|
||||
if(userMapper.selectAssignableUser(projectId,userId)==null) throw PmException.bad("负责人不是当前项目的有效成员");
|
||||
}
|
||||
|
||||
/** 返回不包含项目名称或成员信息的统一拒绝错误。 */
|
||||
public static PmException denied() { return new PmException(403,"FORBIDDEN","对象不存在或无权访问",Map.of()); }
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.ruoyi.project.manage.security;
|
||||
|
||||
import com.ruoyi.project.manage.mapper.PmIterationMapper;
|
||||
import com.ruoyi.project.manage.rule.PmIterationRules;
|
||||
import java.util.Map;
|
||||
import org.springframework.stereotype.Component;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
/** 所有业务写入口共享迭代状态门禁,成员和动作权限继续继承项目。 */
|
||||
@Component
|
||||
public class PmIterationAccess {
|
||||
private final PmAccess access;
|
||||
private final PmIterationMapper mapper;
|
||||
/** 不依赖图服务,避免图加载与鉴权之间出现循环依赖。 */
|
||||
public PmIterationAccess(PmAccess access,PmIterationMapper mapper) { this.access=access; this.mapper=mapper; }
|
||||
/**
|
||||
* 在调用方已持有项目锁的事务内重新鉴权,并校验迭代当前状态。
|
||||
* @param projectId 项目边界
|
||||
* @param iterationId 显式迭代边界,不能自动选择默认迭代
|
||||
* @param action 项目权限动作或生命周期动作;开始工作项使用 start
|
||||
* @return 未软删除迭代的数据库行,供服务进行版本和归属校验
|
||||
*/
|
||||
public Map<String,Object> require(long projectId,long iterationId,String action) {
|
||||
String permission=switch(action) { case "read"->"read"; case "create"->"create"; case "write","start"->"write"; default->"admin"; };
|
||||
access.project(projectId,permission);
|
||||
Map<String,Object> row=mapper.selectIteration(projectId,iterationId);
|
||||
if(row==null) throw PmAccess.denied();
|
||||
PmIterationRules.requireAction(text(row,"status"),nullable(row,"archived_at")!=null,action);
|
||||
return row;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.ruoyi.project.manage.service;
|
||||
|
||||
import com.ruoyi.project.manage.dto.IterationInput;
|
||||
import com.ruoyi.project.manage.dto.IterationActionInput;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** 迭代边界内的生命周期;权限继承项目,执行图由现有业务服务保持一致。 */
|
||||
public interface IPmIterationService {
|
||||
/** 查询成员可读迭代,可显式包含已归档项。 */
|
||||
List<Map<String,Object>> list(long projectId,boolean includeArchived);
|
||||
/** 读取当前迭代元数据;终态和归档仍可查看。 */
|
||||
Map<String,Object> get(long projectId,long iterationId);
|
||||
/** 创建筹备迭代,可一次性复制同项目的当前阶段结构。 */
|
||||
Map<String,Object> create(long projectId,IterationInput input);
|
||||
/** 版本更新基础信息,不允许夹带执行状态。 */
|
||||
Map<String,Object> update(long projectId,long iterationId,IterationInput input);
|
||||
/** 锁内生成结束或取消的完整影响清单。 */
|
||||
Map<String,Object> preview(long projectId,long iterationId,String action);
|
||||
/** 检查双版本和确认清单后原子提交生命周期动作。 */
|
||||
Map<String,Object> action(long projectId,long iterationId,String action,IterationActionInput input);
|
||||
/** 空迭代软删除保留 ID 与成功请求结果。 */
|
||||
Map<String,Object> delete(long projectId,long iterationId,IterationActionInput input);
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package com.ruoyi.project.manage.service;
|
||||
|
||||
import com.ruoyi.project.manage.dto.ReworkInput;
|
||||
import com.ruoyi.project.manage.dto.VersionInput;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
|
||||
/** 项目协作阶段回退及历史读取契约;所有修改仍使用同一项目图锁。 */
|
||||
public interface IPmReworkService {
|
||||
/** 在项目锁内读取回退影响与冲突,不创建新轮次或成功事件。 */
|
||||
Map<String,Object> preview(long projectId,long iterationId,ReworkInput input);
|
||||
/** 旧回退预览入口缺少迭代时拒绝,避免使用项目内其他执行图。 */
|
||||
default Map<String,Object> preview(long projectId,ReworkInput input) { throw new PmException(400,"ITERATION_REQUIRED","请明确选择迭代",Map.of()); }
|
||||
/** 重新计算并按预览图版本原子复制受影响轮次,幂等键可安全重试。 */
|
||||
Map<String,Object> commit(long projectId,long iterationId,ReworkInput input);
|
||||
/** 旧回退提交入口缺少迭代时拒绝,不产生新轮次或成功记录。 */
|
||||
default Map<String,Object> commit(long projectId,ReworkInput input) { throw new PmException(400,"ITERATION_REQUIRED","请明确选择迭代",Map.of()); }
|
||||
/** 仅项目成员可查看指定阶段的历史轮次元数据。 */
|
||||
List<Map<String,Object>> revisions(long projectId,long iterationId,long stageId);
|
||||
/** 旧历史列表入口要求明确迭代,不能只凭阶段 ID 绕过范围校验。 */
|
||||
default List<Map<String,Object>> revisions(long projectId,long stageId) { throw new PmException(400,"ITERATION_REQUIRED","请明确选择迭代",Map.of()); }
|
||||
/** 历史轮次与工作项只读返回,评论和操作记录由旧工作项详情提供。 */
|
||||
Map<String,Object> revision(long projectId,long iterationId,long stageId,long revisionId);
|
||||
/** 旧历史详情入口缺少迭代边界时拒绝。 */
|
||||
default Map<String,Object> revision(long projectId,long stageId,long revisionId) { throw new PmException(400,"ITERATION_REQUIRED","请明确选择迭代",Map.of()); }
|
||||
/** 明确复核未换版后续工作项的原排期,不自动移动时间。 */
|
||||
void confirmScheduleReview(long itemId,VersionInput input);
|
||||
/** 经过阶段归属鉴权后分页读取版本列表,每页最多 200 条。 */
|
||||
Map<String,Object> revisionPage(long projectId,long iterationId,long stageId,int page,int pageSize);
|
||||
/** 分页读取指定历史轮次的工作项,返回总数与只读版本元数据。 */
|
||||
Map<String,Object> revisionItemsPage(long projectId,long iterationId,long stageId,long revisionId,int page,int pageSize);
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.ruoyi.project.manage.service;
|
||||
|
||||
import com.ruoyi.project.manage.dto.*;
|
||||
import java.util.Map;
|
||||
|
||||
/** 阶段和工作项排期共用的事务业务入口。 */
|
||||
public interface IPmScheduleService {
|
||||
/** 在项目成员范围读取阶段当前版本约束与来源,不以缓存布尔值决定可保存。 */
|
||||
Map<String,Object> constraints(long projectId,long iterationId,long stageId);
|
||||
/** 在项目锁内模拟整批最终状态,任一冲突回滚业务、历史和事件。 */
|
||||
void schedule(long projectId,long iterationId,BatchInput input);
|
||||
/** 仅为当前已完成且缺失计划的版本补录,原因和来源写入历史。 */
|
||||
void backfill(long projectId,long iterationId,StageScheduleInput input);
|
||||
/** 恢复原参考时间前重新校验,不能通过普通字段编辑清除复核。 */
|
||||
void confirmItem(long itemId,VersionInput input);
|
||||
}
|
||||
@ -0,0 +1,333 @@
|
||||
package com.ruoyi.project.manage.service;
|
||||
|
||||
import com.ruoyi.project.manage.dto.ChildInput;
|
||||
import com.ruoyi.project.manage.dto.CommentInput;
|
||||
import com.ruoyi.project.manage.dto.ConfigInput;
|
||||
import com.ruoyi.project.manage.dto.DependencyInput;
|
||||
import com.ruoyi.project.manage.dto.ItemInput;
|
||||
import com.ruoyi.project.manage.dto.MemberInput;
|
||||
import com.ruoyi.project.manage.dto.NameInput;
|
||||
import com.ruoyi.project.manage.dto.ProjectEditInput;
|
||||
import com.ruoyi.project.manage.dto.ProjectInput;
|
||||
import com.ruoyi.project.manage.dto.ScheduleInput;
|
||||
import com.ruoyi.project.manage.dto.SpaceInput;
|
||||
import com.ruoyi.project.manage.dto.StageAssignment;
|
||||
import com.ruoyi.project.manage.dto.TransitionInput;
|
||||
import com.ruoyi.project.manage.dto.VersionInput;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/** 项目协作统一业务契约,所有入口必须复用权限、依赖和排期规则。 */
|
||||
public interface IPmService {
|
||||
/**
|
||||
* 只列出独立协作项目和创建人;项目列表和旧协作记录不参与可见性或维护资格计算。
|
||||
*
|
||||
* @return 当前用户可见的独立项目与创建人摘要
|
||||
*/
|
||||
List<Map<String,Object>> projects();
|
||||
|
||||
/**
|
||||
* 空间仅向所有者和可见项目成员展示,创建人昵称及维护资格由服务计算。
|
||||
*
|
||||
* @return 当前用户可见的独立空间与创建人摘要
|
||||
*/
|
||||
List<Map<String,Object>> spaces();
|
||||
|
||||
/**
|
||||
* 有管理动作权限的用户创建自己管理的空间,不修改其它空间所有者。
|
||||
*
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* @return 新空间 ID
|
||||
*/
|
||||
long createSpace(SpaceInput input);
|
||||
|
||||
/**
|
||||
* 锁定协作空间后只创建独立项目和成员;不生成项目列表、财务或生产项目记录。
|
||||
*
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* @return 新独立项目 ID
|
||||
*/
|
||||
long createProject(ProjectInput input);
|
||||
|
||||
/**
|
||||
* 创建人编辑空间名称;行锁与版本覆盖整个鉴权、更新事务,不能转移创建身份。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* <p>副作用:按版本修改空间名称,不更改创建人。</p>
|
||||
*/
|
||||
void editSpace(long id,NameInput input);
|
||||
|
||||
/**
|
||||
* 仅创建人可软删除空空间;与项目创建/移动共用空间锁,保留所有历史关联行。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* <p>副作用:仅在空间无有效项目时软删除,保留关联历史。</p>
|
||||
*/
|
||||
void deleteSpace(long id,VersionInput input);
|
||||
|
||||
/**
|
||||
* 创建人更新名称或空间,空间 ID 升序→项目锁的固定顺序保护移动与空间删除。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* <p>副作用:按空间→项目锁序修改名称或归属并原子保存历史/outbox。</p>
|
||||
*/
|
||||
void editProject(long id,ProjectEditInput input);
|
||||
|
||||
/**
|
||||
* 创建人软删除项目;持有统一项目锁直到历史和事件提交,关联内容不物理删除。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* <p>副作用:软删除项目并原子保存历史/outbox,成员权限即时失效。</p>
|
||||
*/
|
||||
void deleteProject(long id,VersionInput input);
|
||||
|
||||
/**
|
||||
* 兼容空间配置更新,只接受已有独立协作项目;没有从项目列表导入或启用的路径。
|
||||
*
|
||||
* @param projectId 当前独立协作项目 ID;服务内重新检查成员权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* <p>副作用:修改现有协作配置并推进项目版本,不导入项目列表数据。</p>
|
||||
*/
|
||||
void configure(long projectId,ConfigInput input);
|
||||
|
||||
/**
|
||||
* 项目成员和经理列表只暴露分配工作所需的用户标识与昵称。
|
||||
*
|
||||
* @param projectId 当前独立协作项目 ID;服务内重新检查成员权限
|
||||
* @return 当前项目有效成员的 ID、昵称和角色
|
||||
*/
|
||||
List<Map<String,Object>> members(long projectId);
|
||||
|
||||
/**
|
||||
* 只有项目经理具备管理动作权限时可搜索有效用户,以便邀请成员;不返回账号敏感字段。
|
||||
*
|
||||
* @param projectId 当前独立协作项目 ID;服务内重新检查成员权限
|
||||
* @param keyword 昵称筛选文本,由数据库绑定为模糊查询参数
|
||||
* @return 最多 30 个有效候选用户的 ID 和昵称
|
||||
*/
|
||||
List<Map<String,Object>> candidateUsers(long projectId,String keyword);
|
||||
|
||||
/**
|
||||
* 修改成员角色或移除成员;所有者保留经理资格,移除前先解除工作项及阶段负责关系。
|
||||
*
|
||||
* @param projectId 当前独立协作项目 ID;服务内重新检查成员权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* @param remove 为 true 时移除已存在成员或依赖,否则创建或修改
|
||||
* <p>副作用:在项目锁内维护成员关系并原子记录历史/outbox。</p>
|
||||
*/
|
||||
void member(long projectId,MemberInput input,boolean remove);
|
||||
|
||||
/**
|
||||
* 列表使用单次项目图快照计算状态,生命周期和依赖阻塞分别返回。
|
||||
*
|
||||
* @param projectId 当前独立协作项目 ID;服务内重新检查成员权限
|
||||
* @return 当前项目有效工作项及实时依赖与排期摘要
|
||||
*/
|
||||
List<Map<String,Object>> items(long projectId,long iterationId);
|
||||
/** 旧调用不能隐式加载项目全部迭代,要求客户端明确选择。 */
|
||||
default List<Map<String,Object>> items(long projectId) { throw iterationRequired(); }
|
||||
|
||||
/**
|
||||
* 工作项详情只加载有效任务前置,评论、附件和历史均在项目鉴权后返回。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @return 有权查看的工作项详情、评论、附件元数据和历史
|
||||
*/
|
||||
Map<String,Object> detail(long id);
|
||||
|
||||
/**
|
||||
* 创建待开始工作项,校验同项目有效阶段与最终排期;阶段仅表达归属,不生成流程节点。
|
||||
*
|
||||
* @param projectId 当前独立协作项目 ID;服务内重新检查成员权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* @return 新工作项 ID
|
||||
*/
|
||||
long create(long projectId,long iterationId,ItemInput input);
|
||||
/** 创建必须明确归属,不能根据项目当前页面选择推断迭代。 */
|
||||
default long create(long projectId,ItemInput input) { throw iterationRequired(); }
|
||||
|
||||
/**
|
||||
* 创建一层子任务,项目锁覆盖父版本、终态、时间、隐式循环与历史;阶段始终继承父任务。
|
||||
* @param parentId 当前项目有效根任务 ID,完成、关闭、取消或子任务不能作为新父项
|
||||
* @param request 当前父版本和白名单子任务字段;未指定阶段时继承父阶段
|
||||
* @return 新子任务 ID;同时推进父版本,子创建和父关联历史/outbox 在同一事务保存
|
||||
* @throws PmException 权限、版本、父范围或业务规则不满足时拒绝,整笔事务回滚
|
||||
*/
|
||||
long createChild(long parentId,ChildInput request);
|
||||
|
||||
/**
|
||||
* 在父项目鉴权后返回有效子任务,详情和外部客户端复用实时业务摘要。
|
||||
* @param id 有权限访问的父工作项 ID,不接受跨项目来源
|
||||
* @return 未软删除子任务的当前状态、门禁及排期;无子任务返回空列表,不产生业务历史
|
||||
*/
|
||||
List<Map<String,Object>> children(long id);
|
||||
|
||||
/**
|
||||
* 普通编辑校验父子时间及阶段继承,父阶段变化原子同步子阶段;父关系不能经普通字段修改。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* <p>副作用:更新普通工作项字段、时间与阶段,父子阶段同步及历史原子提交。</p>
|
||||
*/
|
||||
void edit(long id,ItemInput input);
|
||||
|
||||
/**
|
||||
* 所有阶段调整共用父子继承校验,版本、归属和历史在同一项目锁事务中提交。
|
||||
* @param id 当前有效工作项 ID;子任务不能脱离父阶段
|
||||
* @param input 目标同项目阶段及工作项版本,null 阶段代表未分配
|
||||
* 注意:父移动同步有效子任务,并推进各子版本和审计;相同阶段不产生重复更新。
|
||||
* <p>副作用:更新业务归属及子阶段,保存成功历史和待发送事件。</p>
|
||||
*/
|
||||
void assignStage(long id,StageAssignment input);
|
||||
|
||||
/**
|
||||
* 返回后端实时可开始判断;与提交校验使用同一实际条件函数。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @return 实时可开始结论和阻塞原因
|
||||
*/
|
||||
Map<String,Object> startability(long id);
|
||||
|
||||
/**
|
||||
* 所有进入进行中的公共入口:先校验身份权限、状态、版本和任务依赖,再原子保存状态/时间/历史/outbox。
|
||||
* @param id 要开始的工作项 ID
|
||||
* @param input 用户当前看到的数据版本;缺失或过期时拒绝开始
|
||||
* <p>副作用:唯一开始入口更新状态、实际开始时间、历史及 outbox;失败全部回滚。</p>
|
||||
*/
|
||||
void start(long id,VersionInput input);
|
||||
|
||||
/**
|
||||
* 状态修改委托统一开始;完成检查子终态,关闭/重开保留完成时间,回退保护全部已开始后续和父任务。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* <p>副作用:经状态机更新生命周期及实际时间,统一开始门禁不能绕过。</p>
|
||||
*/
|
||||
void transition(long id,TransitionInput input);
|
||||
|
||||
/**
|
||||
* 软删除工作项前检查已开始后续的任务条件;历史记录及已停用的流程数据均保留。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* <p>副作用:软删除工作项并检查已开始后续与父子约束,历史/outbox 同事务保存。</p>
|
||||
*/
|
||||
void delete(long id,VersionInput input);
|
||||
|
||||
/**
|
||||
* 查询当前有效任务依赖及条件状态;停用节点条件只保留历史,不参与响应或判断。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @return 全部有效任务前置及满足状态
|
||||
*/
|
||||
List<Map<String,Object>> dependencies(long id);
|
||||
|
||||
/**
|
||||
* 在项目锁下模拟依赖最终图,先检查循环与排期再保存;只有待开始任务可以编辑。
|
||||
* @param id 后续任务实例 ID
|
||||
* @param dependencyId 编辑或删除的依赖 ID;新增时为空
|
||||
* @param input 前置任务引用及任务/依赖版本;删除时仍必须提供两个版本
|
||||
* @param remove 是否删除此依赖
|
||||
* @return 已保存或删除的依赖 ID;失败时整个事务回滚且不产生成功事件
|
||||
*/
|
||||
long dependency(long id,Long dependencyId,DependencyInput input,boolean remove);
|
||||
|
||||
/**
|
||||
* 任务排期摘要返回完整性、最早时间和缺失的前置结束时间,与实际开始条件独立。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @return 最早合法预计开始与排期完整性摘要
|
||||
*/
|
||||
Map<String,Object> constraints(long id);
|
||||
|
||||
/**
|
||||
* 单项与批量排期共用最终图校验,合法的整批延后不会因中间顺序被拒绝。
|
||||
* @param projectId 已鉴权的项目 ID;不允许跨项目混合排期
|
||||
* @param changes 整批工作项版本与最终预计时间;任一冲突导致整批回滚
|
||||
* <p>副作用:先校验整批最终图,再在同一事务更新全部排期及历史/outbox。</p>
|
||||
*/
|
||||
void schedule(long projectId,long iterationId,List<ScheduleInput> changes);
|
||||
/** 项目级批量入口拒绝混合或隐式选择多个迭代。 */
|
||||
default void schedule(long projectId,List<ScheduleInput> changes) { throw iterationRequired(); }
|
||||
|
||||
/**
|
||||
* 查询前置任务直接影响的后续,仅包含当前有效任务依赖及排期约束。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @return 此任务直接影响的后续任务列表
|
||||
*/
|
||||
List<Map<String,Object>> successors(long id);
|
||||
|
||||
/**
|
||||
* 评论在受限工作项事务内保存,不把客户端内容当作 HTML 执行。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* <p>副作用:保存受限评论及成功历史/outbox,作者从登录用户获取。</p>
|
||||
*/
|
||||
void comment(long id,CommentInput input);
|
||||
|
||||
/**
|
||||
* 附件保存在受鉴权的模块数据库中,避免沿用可公开访问上传目录泄露文件;限制为 10 MiB。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @param name 附件原始文件名,服务会校验和净化
|
||||
* @param mediaType 上传内容类型,仅保存受限附件元数据
|
||||
* @param content 受大小限制的文件字节,不创建公开下载地址
|
||||
* @return 新受限附件 ID
|
||||
*/
|
||||
long attach(long id,String name,String mediaType,byte[] content);
|
||||
|
||||
/**
|
||||
* 每次下载重新校验工作项可见性,成员移除后旧附件 ID 不可继续下载。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @return 每次重新鉴权后的附件元数据和字节
|
||||
*/
|
||||
Map<String,Object> attachment(long id);
|
||||
|
||||
/**
|
||||
* 统计由当前用户可见的单项目快照计算,不通过全局统计泄露其它项目。
|
||||
*
|
||||
* @param projectId 当前独立协作项目 ID;服务内重新检查成员权限
|
||||
* @return 当前项目的可见工作项统计
|
||||
*/
|
||||
Map<String,Object> statistics(long projectId,long iterationId);
|
||||
/** 旧统计入口不再把多个迭代的任务混成一个研发视图。 */
|
||||
default Map<String,Object> statistics(long projectId) { throw iterationRequired(); }
|
||||
|
||||
/** 按视图分页当前迭代工作项;业务规则计算仍使用完整迭代图。 */
|
||||
Map<String,Object> itemPage(long projectId,long iterationId,com.ruoyi.project.manage.dto.ItemQuery query);
|
||||
|
||||
/** 取消迭代专用最终态入口,精确确认剩余项后原子取消,不能逐条留下中间状态。 */
|
||||
void cancelRemaining(long projectId,long iterationId,List<Long> expectedIds);
|
||||
|
||||
/**
|
||||
* 通知展示再次过滤当前成员资格;异步发送后被撤权的用户不能查看原项目通知。
|
||||
*
|
||||
* @return 当前成员资格过滤的个人通知
|
||||
*/
|
||||
List<Map<String,Object>> notifications();
|
||||
|
||||
/**
|
||||
* 仅取路由所需项目 ID,所有标题和业务内容在项目鉴权之后加载。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @return 目标工作项所属的独立协作项目 ID
|
||||
*/
|
||||
long projectOf(long id);
|
||||
|
||||
/** 仅推导不可变迭代归属;调用方随后必须鉴权并检查所属迭代状态。 */
|
||||
long iterationOf(long id);
|
||||
|
||||
/** 统一返回缺少业务范围的格式错误,不返回对象名称。 */
|
||||
private static PmException iterationRequired() { return new PmException(400,"ITERATION_REQUIRED","请明确选择迭代",Map.of()); }
|
||||
|
||||
/** 阶段与工作项混合批量委托统一排期服务,旧的 items-only 请求保持兼容。 */
|
||||
void scheduleBatch(long projectId,long iterationId,com.ruoyi.project.manage.dto.BatchInput input);
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
package com.ruoyi.project.manage.service;
|
||||
|
||||
import com.ruoyi.project.manage.dto.LayoutInput;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.dto.StageAssignment;
|
||||
import com.ruoyi.project.manage.dto.StageInput;
|
||||
import com.ruoyi.project.manage.dto.StageEdgeInput;
|
||||
import com.ruoyi.project.manage.dto.VersionInput;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/** 显式阶段执行图与展示布局契约;不恢复已停用的流程节点依赖。 */
|
||||
public interface IPmStageService {
|
||||
/**
|
||||
* 在项目锁内读取单迭代阶段、显式阶段边和工作项计数;画布不返回完整工作项。
|
||||
*
|
||||
* @param projectId 当前独立协作项目 ID;服务内重新检查成员权限
|
||||
* @param iterationId 明确的迭代边界,不能混合项目内多个执行图
|
||||
* @return 阶段和执行连线摘要;浏览器展示偏好不进入响应
|
||||
*/
|
||||
Map<String,Object> flowView(long projectId,long iterationId);
|
||||
/** 旧项目级画布入口拒绝隐式选择迭代,避免混合多个执行图。 */
|
||||
default Map<String,Object> flowView(long projectId) { throw requiredIteration(); }
|
||||
|
||||
/**
|
||||
* 阶段经理维护入口;负责人仅代表业务责任,名称和顺序不隐式产生执行依赖。
|
||||
*
|
||||
* @param projectId 当前独立协作项目 ID;服务内重新检查成员权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* @return 新阶段 ID
|
||||
*/
|
||||
long createStage(long projectId,long iterationId,StageInput input);
|
||||
/** 旧新增入口要求明确迭代,不根据最近打开页面推断阶段归属。 */
|
||||
default long createStage(long projectId,StageInput input) { throw requiredIteration(); }
|
||||
|
||||
/**
|
||||
* 在统一项目锁下版本更新阶段元数据,不改变工作项状态、预计时间或有效依赖。
|
||||
*
|
||||
* @param projectId 当前独立协作项目 ID;服务内重新检查成员权限
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* <p>副作用:按阶段版本修改组织元数据并原子保存历史/outbox。</p>
|
||||
*/
|
||||
void editStage(long projectId,long iterationId,long id,StageInput input);
|
||||
/** 旧编辑入口缺少迭代边界时拒绝执行。 */
|
||||
default void editStage(long projectId,long id,StageInput input) { throw requiredIteration(); }
|
||||
|
||||
/**
|
||||
* 非空阶段拒绝删除;共享项目锁与归属更新串行化,历史关联和成功事件原子保留。
|
||||
*
|
||||
* @param projectId 当前独立协作项目 ID;服务内重新检查成员权限
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* <p>副作用:仅空阶段可软删除,同时保存成功历史/outbox。</p>
|
||||
*/
|
||||
void deleteStage(long projectId,long iterationId,long id,VersionInput input);
|
||||
/** 旧删除入口缺少迭代边界时拒绝执行。 */
|
||||
default void deleteStage(long projectId,long id,VersionInput input) { throw requiredIteration(); }
|
||||
|
||||
/** 在项目锁内新增显式阶段边,验证权限、最终图无环及已开始工作项不产生新阻塞。 */
|
||||
long createEdge(long projectId,long iterationId,StageEdgeInput input);
|
||||
/** 旧加边入口不能跨越迭代或自动选取默认执行图。 */
|
||||
default long createEdge(long projectId,StageEdgeInput input) { throw requiredIteration(); }
|
||||
|
||||
/** 版本校验后删除共享阶段边;删除只能解除门禁,历史保存在审计表。 */
|
||||
void deleteEdge(long projectId,long iterationId,long edgeId,VersionInput input);
|
||||
/** 旧删边入口缺少迭代边界时拒绝执行。 */
|
||||
default void deleteEdge(long projectId,long edgeId,VersionInput input) { throw requiredIteration(); }
|
||||
|
||||
/**
|
||||
* 阶段调整委托统一父子继承服务,父移动会原子同步全部有效子任务。
|
||||
*
|
||||
* @param id 路径中的目标对象 ID;服务按当前身份校验维护或查看权限
|
||||
* @param input 仅包含接口允许字段的请求对象;身份、版本及关联由对应业务入口复验
|
||||
* <p>副作用:调用统一工作项阶段服务,父子继承规则在该服务中校验。</p>
|
||||
*/
|
||||
void assign(long id,StageAssignment input);
|
||||
|
||||
/**
|
||||
* 拒绝旧数据库布局保存入口;当前迭代画布布局只存浏览器。
|
||||
* @param scope 旧接口布局范围,不再保存到数据库
|
||||
* @param projectId 旧接口项目 ID,不用于隐式选择迭代
|
||||
* @param input 旧布局请求,始终拒绝而不写入
|
||||
* @return 不返回结果,抛出 ITERATION_REQUIRED 业务错误
|
||||
*/
|
||||
Map<String,Object> saveLayout(long projectId,String scope,LayoutInput input);
|
||||
|
||||
/** 为旧入口统一生成不包含对象信息的范围缺失错误。 */
|
||||
private static PmException requiredIteration() { return new PmException(400,"ITERATION_REQUIRED","请明确选择迭代",Map.of()); }
|
||||
}
|
||||
@ -0,0 +1,280 @@
|
||||
package com.ruoyi.project.manage.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.ruoyi.project.manage.dto.IterationInput;
|
||||
import com.ruoyi.project.manage.dto.IterationActionInput;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.mapper.PmIterationMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmWorkspaceMapper;
|
||||
import com.ruoyi.project.manage.mapper.support.PmMapperWrite;
|
||||
import com.ruoyi.project.manage.rule.PmIterationRules;
|
||||
import com.ruoyi.project.manage.security.PmAccess;
|
||||
import com.ruoyi.project.manage.security.PmIterationAccess;
|
||||
import com.ruoyi.project.manage.service.IPmIterationService;
|
||||
import com.ruoyi.project.manage.service.IPmService;
|
||||
import com.ruoyi.project.manage.service.support.PmAuditService;
|
||||
import com.ruoyi.project.manage.service.support.PmGraphService;
|
||||
import com.ruoyi.project.manage.util.PmJson;
|
||||
import com.ruoyi.project.manage.util.PmTime;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.*;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
/** 生命周期使用项目→迭代的统一锁序,业务、幂等结果与审计始终共同提交。 */
|
||||
@Service
|
||||
@Transactional(isolation=Isolation.READ_COMMITTED,rollbackFor=Exception.class)
|
||||
public class PmIterationServiceImpl implements IPmIterationService {
|
||||
private final PmIterationMapper mapper;
|
||||
private final PmWorkspaceMapper workspace;
|
||||
private final PmAccess access;
|
||||
private final PmIterationAccess iterations;
|
||||
private final PmGraphService graphs;
|
||||
private final PmAuditService audit;
|
||||
private final IPmService business;
|
||||
private final PmJson codec;
|
||||
private final ObjectMapper json;
|
||||
|
||||
/** 所有依赖共享上层事务连接;取消复用现有最终图校验,避免直接批量改状态。 */
|
||||
public PmIterationServiceImpl(PmIterationMapper mapper,PmWorkspaceMapper workspace,PmAccess access,PmIterationAccess iterations,
|
||||
PmGraphService graphs,PmAuditService audit,IPmService business,PmJson codec,ObjectMapper json) {
|
||||
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;
|
||||
}
|
||||
|
||||
/** 读取同项目迭代,不通过项目默认值推断执行范围。 */
|
||||
public List<Map<String,Object>> list(long projectId,boolean includeArchived) {
|
||||
locked(projectId,"read");
|
||||
boolean manage=canManage(projectId);
|
||||
return mapper.selectIterations(projectId,includeArchived).stream().map(row->response(row,manage)).toList();
|
||||
}
|
||||
|
||||
/** 归档和终态仍保留可读历史,动作资格由响应明确展示。 */
|
||||
public Map<String,Object> get(long projectId,long iterationId) {
|
||||
locked(projectId,"read");
|
||||
return response(iterations.require(projectId,iterationId,"read"),canManage(projectId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建按整日排期的筹备迭代并可复制当前阶段拓扑;同请求重试直接返回原提交结果。
|
||||
* 来源与目标在同一项目锁下读取和写入,复制不会继承任务、实际时间或旧轮次事实。
|
||||
* @param projectId 当前项目
|
||||
* @param input 基础信息、幂等键以及可选来源双版本
|
||||
* @return 新迭代的安全元数据
|
||||
*/
|
||||
public Map<String,Object> create(long projectId,IterationInput input) {
|
||||
locked(projectId,"admin");
|
||||
if(input==null) throw PmException.bad("缺少迭代信息");
|
||||
String request=key(input.idempotencyKey()),hash=fingerprint("create",null,input);
|
||||
Map<String,Object> replay=replay(projectId,request,"create",hash);
|
||||
if(replay!=null) return replay;
|
||||
Map<String,Object> values=metadata(input,null);
|
||||
if(input.sourceIterationId()!=null) {
|
||||
Map<String,Object> source=iterations.require(projectId,input.sourceIterationId(),"read");
|
||||
expected(input.sourceGraphVersion(),number(source,"graph_version"),"GRAPH_VERSION_CONFLICT");
|
||||
} else if(input.sourceGraphVersion()!=null) throw PmException.bad("来源图版本必须与来源迭代一起提交");
|
||||
long actor=access.actor(),now=PmTime.now();
|
||||
values.putAll(map("project_id",projectId,"created_by",actor,"created_at",now));
|
||||
long id;
|
||||
try { id=mapper.insertIteration(values); }
|
||||
catch(DuplicateKeyException duplicate) { throw PmException.conflict("ITERATION_CODE_EXISTS","迭代编号已存在"); }
|
||||
List<Map<String,Object>> copyWarnings=input.sourceIterationId()==null?List.of():copyStructure(projectId,input.sourceIterationId(),id,actor,now);
|
||||
Map<String,Object> result=response(mapper.selectIteration(projectId,id),true);
|
||||
if(!copyWarnings.isEmpty()) result.put("copyWarnings",copyWarnings);
|
||||
audit.record(projectId,id,null,"ITERATION_CREATED",map("iterationId",id,"sourceIterationId",input.sourceIterationId(),"name",input.name().trim(),"copyWarnings",copyWarnings),actor);
|
||||
remember(projectId,id,request,"create",hash,result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 更新只接受基础信息,日期未变时保留原排期精度;版本检查与归档门禁都位于项目锁内。 */
|
||||
public Map<String,Object> update(long projectId,long iterationId,IterationInput input) {
|
||||
locked(projectId,"admin");
|
||||
Map<String,Object> row=iterations.require(projectId,iterationId,"admin");
|
||||
if(input==null) throw PmException.bad("缺少迭代信息");
|
||||
expected(input.version(),number(row,"version"),"VERSION_CONFLICT");
|
||||
if(input.sourceIterationId()!=null||input.sourceGraphVersion()!=null) throw PmException.bad("结构复制仅允许在创建时执行");
|
||||
Map<String,Object> values=metadata(input,row);
|
||||
try { change(projectId,iterationId,row,values); }
|
||||
catch(DuplicateKeyException duplicate) { throw PmException.conflict("ITERATION_CODE_EXISTS","迭代编号已存在"); }
|
||||
audit.record(projectId,iterationId,null,"ITERATION_EDITED",map("iterationId",iterationId,"name",input.name().trim()),access.actor());
|
||||
return response(mapper.selectIteration(projectId,iterationId),true);
|
||||
}
|
||||
|
||||
/** 锁内预览与提交使用完全相同的图和异常规则,避免展示规则与业务规则分叉。 */
|
||||
public Map<String,Object> preview(long projectId,long iterationId,String action) {
|
||||
if(!Set.of("finish","cancel").contains(action)) throw PmException.bad("不支持的预览动作");
|
||||
locked(projectId,"admin");
|
||||
Map<String,Object> row=iterations.require(projectId,iterationId,action);
|
||||
return previewOf(projectId,iterationId,row,action);
|
||||
}
|
||||
|
||||
/**
|
||||
* 串行提交生命周期状态;重复键先检查权限再重放,过期双版本不产生成功历史。
|
||||
* 取消复用统一业务服务构造最终图,任一步失败都会连同任务、审计、outbox 与请求结果回滚。
|
||||
* @param projectId 当前项目
|
||||
* @param iterationId 目标迭代
|
||||
* @param action activate、finish、cancel、reopen、archive 或 unarchive
|
||||
* @param input 版本、幂等键与当前完整预览确认
|
||||
* @return 已提交的迭代元数据
|
||||
*/
|
||||
public Map<String,Object> action(long projectId,long iterationId,String action,IterationActionInput input) {
|
||||
if(!Set.of("activate","finish","cancel","reopen","archive","unarchive").contains(action)) throw PmException.bad("不支持的迭代动作");
|
||||
locked(projectId,"admin");
|
||||
if(input==null) throw PmException.bad("缺少操作版本");
|
||||
String request=key(input.idempotencyKey()),hash=fingerprint(action,iterationId,input);
|
||||
Map<String,Object> replay=replay(projectId,request,action,hash);
|
||||
if(replay!=null) return replay;
|
||||
Map<String,Object> row=iterations.require(projectId,iterationId,action);
|
||||
expected(input.version(),number(row,"version"),"VERSION_CONFLICT");
|
||||
if(Set.of("finish","cancel").contains(action)||input.graphVersion()!=null)
|
||||
expected(input.graphVersion(),number(row,"graph_version"),"GRAPH_VERSION_CONFLICT");
|
||||
if(input.reason()!=null&&input.reason().length()>2000) throw PmException.bad("说明不能超过 2000 字");
|
||||
long now=PmTime.now(); Map<String,Object> values=new LinkedHashMap<>();
|
||||
switch(action) {
|
||||
case "activate" -> values.putAll(map("status","ACTIVE","actual_start_at",now));
|
||||
case "finish" -> {
|
||||
Map<String,Object> preview=previewOf(projectId,iterationId,row,action);
|
||||
PmIterationRules.confirmFinish(preview,input.acceptedExceptionIds(),input.reason());
|
||||
values.putAll(map("status","FINISHED","finish_result",preview.get("finishResult"),"finish_note",input.reason(),"actual_end_at",now));
|
||||
}
|
||||
case "cancel" -> {
|
||||
Map<String,Object> preview=previewOf(projectId,iterationId,row,action);
|
||||
PmIterationRules.confirmCancel(preview,input.acceptedItemIds());
|
||||
business.cancelRemaining(projectId,iterationId,input.acceptedItemIds()==null?List.of():input.acceptedItemIds());
|
||||
values.putAll(map("status","CANCELLED","finish_result",null,"finish_note",input.reason(),"actual_end_at",now));
|
||||
}
|
||||
case "reopen" -> values.putAll(map("status","ACTIVE","finish_result",null,"finish_note",null,"actual_end_at",null,
|
||||
"actual_start_at",nullable(row,"actual_start_at")==null?now:nullable(row,"actual_start_at")));
|
||||
case "archive" -> values.putAll(map("archived_at",now,"archived_by",access.actor()));
|
||||
case "unarchive" -> values.putAll(map("archived_at",null,"archived_by",null));
|
||||
default -> throw new IllegalStateException("未处理的迭代动作");
|
||||
}
|
||||
change(projectId,iterationId,row,values);
|
||||
Map<String,Object> result=response(mapper.selectIteration(projectId,iterationId),true);
|
||||
audit.record(projectId,iterationId,null,"ITERATION_"+action.toUpperCase(Locale.ROOT),map("iterationId",iterationId,"reason",input.reason(),"acceptedExceptionIds",input.acceptedExceptionIds(),"acceptedItemIds",input.acceptedItemIds()),access.actor());
|
||||
remember(projectId,iterationId,request,action,hash,result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 仅从未执行且无任何工作项的筹备迭代允许软删除;初始阶段结构属于可清理配置。 */
|
||||
public Map<String,Object> delete(long projectId,long iterationId,IterationActionInput input) {
|
||||
locked(projectId,"admin");
|
||||
if(input==null) throw PmException.bad("缺少操作版本");
|
||||
String request=key(input.idempotencyKey()),hash=fingerprint("delete",iterationId,input);
|
||||
Map<String,Object> replay=replay(projectId,request,"delete",hash);
|
||||
if(replay!=null) return replay;
|
||||
Map<String,Object> row=iterations.require(projectId,iterationId,"delete");
|
||||
expected(input.version(),number(row,"version"),"VERSION_CONFLICT");
|
||||
if(nullable(row,"actual_start_at")!=null||mapper.countContents(projectId,iterationId)!=0) throw PmException.conflict("ITERATION_NOT_EMPTY","迭代已有工作项或执行历史,不能删除");
|
||||
change(projectId,iterationId,row,map("deleted",true));
|
||||
Map<String,Object> result=map("id",iterationId,"deleted",true);
|
||||
audit.record(projectId,iterationId,null,"ITERATION_DELETED",result,access.actor());
|
||||
remember(projectId,iterationId,request,"delete",hash,result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 先鉴权再取项目锁,锁后重新校验成员,防止等待期间撤权或删除后继续写入。 */
|
||||
private void locked(long projectId,String action) { access.project(projectId,action); workspace.lockProject(projectId); access.project(projectId,action); }
|
||||
|
||||
/** 管理资格仍由项目管理角色及菜单权限共同决定,终态只影响动作可用性。 */
|
||||
private boolean canManage(long projectId) { try { access.project(projectId,"admin"); return true; } catch(PmException denied) { if(denied.getHttpStatus()!=403) throw denied; return false; } }
|
||||
|
||||
/** 元数据新建或改期按整日处理;普通信息编辑保留原时间点,状态和操作人不进入可写白名单。 */
|
||||
private Map<String,Object> metadata(IterationInput input,Map<String,Object> previous) {
|
||||
if(input.code()==null||input.code().isBlank()||input.code().trim().length()>64) throw PmException.bad("迭代编号必填且不能超过 64 字");
|
||||
if(input.name()==null||input.name().isBlank()||input.name().trim().length()>200) throw PmException.bad("迭代名称必填且不能超过 200 字");
|
||||
if(input.goal()!=null&&input.goal().length()>10000) throw PmException.bad("迭代目标不能超过 10000 字");
|
||||
if(input.sortOrder()!=null&&(input.sortOrder()<0||input.sortOrder()>1000000)) throw PmException.bad("迭代顺序必须在 0 到 1000000 之间");
|
||||
PmTime.Plan plan=previous==null?PmTime.planned(input.plannedStartAt(),input.plannedEndAt()):PmTime.editedPlan(input.plannedStartAt(),input.plannedEndAt(),nullable(previous,"planned_start_at"),nullable(previous,"planned_end_at"));
|
||||
Long start=plan.start(),end=plan.end();
|
||||
if(start!=null&&end!=null&&end<start) throw PmException.bad("预计结束时间不能早于开始时间");
|
||||
return map("iteration_code",input.code().trim(),"name",input.name().trim(),"goal",input.goal(),"planned_start_at",start,"planned_end_at",end,"sort_order",input.sortOrder()==null?0:input.sortOrder());
|
||||
}
|
||||
|
||||
/** 双版本均显式提交;缺失不能按当前版本补齐,否则预览会失去并发保护。 */
|
||||
private void expected(Long supplied,long current,String code) { if(supplied==null||supplied!=current) throw PmException.conflict(code,"数据已变化,请刷新后重试"); }
|
||||
|
||||
/** 更新元数据版本和操作人,外层项目锁覆盖校验、任务变更及全部成功记录。 */
|
||||
private void change(long projectId,long iterationId,Map<String,Object> row,Map<String,Object> values) {
|
||||
values.putAll(map("updated_by",access.actor(),"updated_at",PmTime.now()));
|
||||
PmMapperWrite.requireUpdated(mapper.updateIteration(projectId,iterationId,number(row,"version"),values));
|
||||
}
|
||||
|
||||
/** 预览只使用当前迭代图,未分页的完整服务图确保窗口外任务也参与校验。 */
|
||||
private Map<String,Object> previewOf(long projectId,long iterationId,Map<String,Object> row,String action) {
|
||||
return PmIterationRules.preview(graphs.load(projectId,iterationId),iterationId,number(row,"version"),number(row,"graph_version"),action);
|
||||
}
|
||||
|
||||
/**
|
||||
* 一次复制先建立阶段 ID 映射,再写边和新 v1,不携带来源执行事实。
|
||||
* @param source 同项目来源迭代,允许终态和归档,但历史负责人可能已经离开项目
|
||||
* @param target 本事务创建的筹备迭代,所有新对象使用独立 ID
|
||||
* @return 无法继续分配的负责人清空说明,随创建结果保存供幂等重放
|
||||
* 注意:只调整新阶段及新快照,不改写来源阶段;项目锁覆盖当前成员资格读取及全部复制。
|
||||
*/
|
||||
private List<Map<String,Object>> copyStructure(long projectId,long source,long target,long actor,long now) {
|
||||
Map<Long,Long> ids=new LinkedHashMap<>();
|
||||
Set<Long> members=new HashSet<>();
|
||||
for(Map<String,Object> member:workspace.selectMembers(projectId)) members.add(number(member,"userId"));
|
||||
List<Map<String,Object>> warnings=new ArrayList<>();
|
||||
for(Map<String,Object> stage:mapper.selectCopyStages(projectId,source)) {
|
||||
Long owner=nullable(stage,"owner_id");
|
||||
// 终态来源保留原负责人用于历史追溯,新版不能继承非成员或已停用账号的分配。
|
||||
if(owner!=null&&!members.contains(owner)) {
|
||||
warnings.add(map("sourceStageId",number(stage,"id"),"sourceStageName",text(stage,"name"),"ownerId",owner,"message","阶段“"+text(stage,"name")+"”的原负责人已不可分配,新阶段负责人已清空"));
|
||||
owner=null;
|
||||
}
|
||||
Map<String,Object> 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 id=mapper.insertCopiedStage(values); ids.put(number(stage,"id"),id);
|
||||
values.put("stage_id",id); values.remove("id");
|
||||
long revision=mapper.insertCopiedRevision(values);
|
||||
PmMapperWrite.requireUpdated(mapper.initializeCopiedRevision(id,revision));
|
||||
}
|
||||
for(Map<String,Object> edge:mapper.selectCopyEdges(projectId,source)) {
|
||||
Long predecessor=ids.get(number(edge,"predecessor_stage_id")),successor=ids.get(number(edge,"successor_stage_id"));
|
||||
if(predecessor==null||successor==null) throw new IllegalStateException("复制来源阶段端点不完整");
|
||||
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));
|
||||
return warnings;
|
||||
}
|
||||
|
||||
/** 幂等键限定长度且不可省略,避免网络重试重复创建迭代或重复取消。 */
|
||||
private String key(String value) { if(value==null||value.isBlank()||value.length()>100) throw PmException.bad("幂等键必填且不能超过 100 字"); return value; }
|
||||
|
||||
/** 请求摘要绑定动作、对象和输入,防止相同幂等键用于不同业务请求。 */
|
||||
private String fingerprint(String action,Long iterationId,Object input) {
|
||||
try { return HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(codec.encode(map("action",action,"iterationId",iterationId,"input",input)).getBytes(StandardCharsets.UTF_8))); }
|
||||
catch(java.security.NoSuchAlgorithmException impossible) { throw new IllegalStateException(impossible); }
|
||||
}
|
||||
|
||||
/** 鉴权之后才读取成功结果;相同键和不同请求必须报冲突而不是重放错误对象。 */
|
||||
private Map<String,Object> replay(long projectId,String key,String action,String hash) {
|
||||
Map<String,Object> request=mapper.selectRequest(projectId,access.actor(),key);
|
||||
if(request==null) return null;
|
||||
if(!action.equals(text(request,"action"))||!hash.equals(text(request,"request_hash"))) throw PmException.conflict("IDEMPOTENCY_CONFLICT","幂等键已用于其它请求");
|
||||
try { return json.readerFor(new TypeReference<Map<String,Object>>(){}).with(DeserializationFeature.USE_LONG_FOR_INTS).readValue(text(request,"result_json")); }
|
||||
catch(Exception invalid) { throw new IllegalStateException("已保存的迭代请求结果无效",invalid); }
|
||||
}
|
||||
|
||||
/** 请求结果仅在全部业务和审计完成后写入,事务回滚后不会出现虚假的成功重放。 */
|
||||
private void remember(long projectId,long iterationId,String key,String action,String hash,Map<String,Object> result) {
|
||||
mapper.insertRequest(map("project_id",projectId,"iteration_id",iterationId,"idempotency_key",key,"action",action,"request_hash",hash,"result_json",codec.encode(result),"created_by",access.actor(),"created_at",PmTime.now()));
|
||||
}
|
||||
|
||||
/** 显式投影接口字段并保留微秒精度,不将数据库内部字段整体交给客户端。 */
|
||||
private Map<String,Object> response(Map<String,Object> row,boolean manage) {
|
||||
return map("id",number(row,"id"),"projectId",number(row,"project_id"),"code",text(row,"iteration_code"),"name",text(row,"name"),"goal",text(row,"goal"),
|
||||
"status",text(row,"status"),"finishResult",text(row,"finish_result"),"finishNote",text(row,"finish_note"),
|
||||
"plannedStartAt",PmTime.format(nullable(row,"planned_start_at"),"Asia/Shanghai"),"plannedEndAt",PmTime.format(nullable(row,"planned_end_at"),"Asia/Shanghai"),
|
||||
"actualStartAt",PmTime.format(nullable(row,"actual_start_at"),"Asia/Shanghai"),"actualEndAt",PmTime.format(nullable(row,"actual_end_at"),"Asia/Shanghai"),
|
||||
"sortOrder",number(row,"sort_order"),"version",number(row,"version"),"graphVersion",number(row,"graph_version"),
|
||||
"archivedAt",PmTime.format(nullable(row,"archived_at"),"Asia/Shanghai"),"archived",nullable(row,"archived_at")!=null,"createdBy",number(row,"created_by"),
|
||||
"creatorName",text(row,"creator_name"),"createdAt",PmTime.format(nullable(row,"created_at"),"Asia/Shanghai"),"canManage",manage);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,306 @@
|
||||
package com.ruoyi.project.manage.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.ruoyi.project.manage.domain.Dependency;
|
||||
import com.ruoyi.project.manage.domain.Graph;
|
||||
import com.ruoyi.project.manage.domain.Item;
|
||||
import com.ruoyi.project.manage.dto.ReworkInput;
|
||||
import com.ruoyi.project.manage.dto.ReworkItemInput;
|
||||
import com.ruoyi.project.manage.dto.VersionInput;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.mapper.PmDependencyMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmRevisionMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmStageMapper;
|
||||
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.security.PmAccess;
|
||||
import com.ruoyi.project.manage.security.PmIterationAccess;
|
||||
import com.ruoyi.project.manage.service.IPmReworkService;
|
||||
import com.ruoyi.project.manage.service.support.PmAuditService;
|
||||
import com.ruoyi.project.manage.service.support.PmGraphService;
|
||||
import com.ruoyi.project.manage.util.PmJson;
|
||||
import com.ruoyi.project.manage.util.PmTime;
|
||||
import java.util.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
/** 回退只操作独立协作当前图;项目行锁串行化开始、改线、排期和版本替换。 */
|
||||
@Service
|
||||
@Transactional(isolation=Isolation.READ_COMMITTED,rollbackFor=Exception.class)
|
||||
public class PmReworkServiceImpl implements IPmReworkService {
|
||||
private final PmWorkspaceMapper workspace;
|
||||
private final PmStageMapper stages;
|
||||
private final PmWorkItemMapper workItems;
|
||||
private final PmDependencyMapper dependencies;
|
||||
private final PmRevisionMapper revisions;
|
||||
private final com.ruoyi.project.manage.mapper.PmScheduleMapper schedules;
|
||||
private final com.ruoyi.project.manage.service.IPmScheduleService scheduleService;
|
||||
private final PmGraphService graphs;
|
||||
private final PmAuditService audit;
|
||||
private final PmAccess access;
|
||||
private final PmIterationAccess iterationAccess;
|
||||
private final PmJson json;
|
||||
private final ObjectMapper decoder;
|
||||
|
||||
/** 只注入本模块 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) {
|
||||
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<Long> affected,List<Item> copies,List<Map<String,Object>> excluded,
|
||||
List<Map<String,Object>> missingAssignees,List<Map<String,Object>> blockers,List<Long> reviewStages,List<Long> reviewItems,
|
||||
Set<Long> members) { }
|
||||
|
||||
/** 预览持有项目锁读取一致快照;只返回本项目成员可见的名称和冲突。 */
|
||||
public Map<String,Object> preview(long projectId,long iterationId,ReworkInput input) {
|
||||
locked(projectId,iterationId,"admin"); Graph graph=graphs.load(projectId,iterationId); Plan plan=plan(projectId,iterationId,input,graph);
|
||||
return previewValue(projectId,iterationId,input,plan,graphVersion(projectId,iterationId));
|
||||
}
|
||||
|
||||
/** 幂等查重先于版本检查;新提交重新计算影响范围,再原子复制并切换所有当前指针。 */
|
||||
public Map<String,Object> commit(long projectId,long iterationId,ReworkInput input) {
|
||||
locked(projectId,iterationId,"admin");
|
||||
if(input==null||input.idempotencyKey()==null||input.idempotencyKey().isBlank()||input.idempotencyKey().length()>100) throw PmException.bad("回退请求幂等键不能为空且不能超过 100 个字符");
|
||||
Map<String,Object> earlier=revisions.selectReworkByKey(projectId,iterationId,input.idempotencyKey());
|
||||
if(earlier!=null) {
|
||||
Map<String,Object> previous=decoded(text(earlier,"impact_json"));
|
||||
if(!Objects.equals(nullable(earlier,"source_stage_id"),input.sourceStageId())||!Objects.equals(nullable(earlier,"target_stage_id"),input.targetStageId())
|
||||
||!Objects.equals(text(earlier,"reason"),input.reason()==null?null:input.reason().trim())
|
||||
||!Objects.equals(nullable(earlier,"preview_graph_version"),input.graphVersion())
|
||||
||!Objects.equals(previous.get("requestAdditionsJson"),additionsJson(input))
|
||||
||!Objects.equals(((List<?>)previous.get("affectedStageIds")).stream().map(id->((Number)id).longValue()).toList(),input.expectedStageIds()))
|
||||
throw PmException.conflict("IDEMPOTENCY_KEY_REUSED","该回退请求标识已用于另一操作");
|
||||
return previous;
|
||||
}
|
||||
if(input.reason()==null||input.reason().isBlank()||input.reason().trim().length()>2000) throw PmException.bad("请填写不超过 2000 字的回退原因");
|
||||
long version=graphVersion(projectId,iterationId);
|
||||
if(input.graphVersion()==null||input.graphVersion()!=version) throw PmException.conflict("GRAPH_VERSION_CONFLICT","流程已变化,请重新预览回退影响");
|
||||
Graph before=graphs.load(projectId,iterationId); Plan plan=plan(projectId,iterationId,input,before);
|
||||
if(input.expectedStageIds()==null||!plan.affected().equals(input.expectedStageIds())) throw PmException.conflict("REWORK_SCOPE_CHANGED","回退范围已变化,请重新预览");
|
||||
if(!plan.blockers().isEmpty()) throw new PmException(409,"REWORK_CONFLICT","回退仍有待处理的工作项或依赖冲突",map("blockedReasons",plan.blockers()));
|
||||
|
||||
long at=PmTime.now(),actor=access.actor();
|
||||
Map<String,Object> saved=map("projectId",projectId,"iterationId",iterationId,"sourceStageId",input.sourceStageId(),"targetStageId",input.targetStageId(),
|
||||
"graphVersion",version+1,"affectedStageIds",plan.affected(),"itemMapping",new LinkedHashMap<Long,Long>(),
|
||||
"requestAdditionsJson",additionsJson(input));
|
||||
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<Long,Long> nextRevisions=new LinkedHashMap<>();
|
||||
for(Long stageId:plan.affected()) {
|
||||
var old=before.stageRevisions().get(stageId);
|
||||
Map<String,Object> stage=stages.selectActiveStage(stageId,projectId,iterationId);
|
||||
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));
|
||||
nextRevisions.put(stageId,next);
|
||||
}
|
||||
Map<Long,Long> mapped=new LinkedHashMap<>();
|
||||
// 父项先于子项插入;复制只继承业务文本和仍有效的成员,不继承执行与排期事实。
|
||||
for(Item old:plan.copies()) {
|
||||
Long parent=old.parentTaskId()==null?null:mapped.get(old.parentTaskId());
|
||||
if(old.parentTaskId()!=null&&parent==null) throw PmException.conflict("REWORK_PARENT_CONFLICT","子任务的父项未能复制");
|
||||
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,
|
||||
"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);
|
||||
}
|
||||
for(var entry:additions(input).entrySet()) for(ReworkItemInput addition:entry.getValue()) {
|
||||
validateAddition(projectId,addition);
|
||||
workItems.insertWorkItem(map("project_id",projectId,"iteration_id",iterationId,"type",addition.type(),"title",addition.title().trim(),"description",addition.description(),
|
||||
"assignee_id",addition.assigneeId(),"priority",addition.priority()==null?"MEDIUM":addition.priority(),"status","READY",
|
||||
"stage_id",entry.getKey(),"stage_revision_id",nextRevisions.get(entry.getKey()),"created_by",actor,"created_at",at));
|
||||
}
|
||||
for(Dependency dependency:before.dependencies()) if(mapped.containsKey(dependency.successorId())) {
|
||||
Long predecessor=mapped.getOrDefault(dependency.taskId(),dependency.taskId());
|
||||
if(predecessor==null||!before.items().containsKey(dependency.taskId())&& !mapped.containsKey(dependency.taskId())) throw PmException.conflict("REWORK_DEPENDENCY_CONFLICT","前置任务已不属于当前版本");
|
||||
dependencies.insertDependency(map("project_id",projectId,"iteration_id",iterationId,"successor_task_id",mapped.get(dependency.successorId()),
|
||||
"condition_type","TASK_COMPLETED","predecessor_task_id",predecessor,"expected_status","COMPLETED","created_by",actor,"created_at",at));
|
||||
}
|
||||
for(Long stageId:plan.affected()) {
|
||||
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","工作项计划已变化");
|
||||
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");
|
||||
revisions.advanceGraphVersion(projectId,iterationId);
|
||||
saved.put("reworkId",reworkId); saved.put("itemMapping",mapped); saved.put("newStageRevisionIds",nextRevisions);
|
||||
String result=json.encode(saved); revisions.saveReworkResult(reworkId,result);
|
||||
audit.record(projectId,iterationId,null,"STAGE_REWORKED",map("reworkId",reworkId,"reason",input.reason().trim(),"affectedStageIds",plan.affected(),"itemMapping",mapped),actor);
|
||||
return decoded(result);
|
||||
}
|
||||
|
||||
/** 历史轮次仅展示本项目阶段的只读快照,不把旧 ID 加回当前业务图。 */
|
||||
public List<Map<String,Object>> revisions(long projectId,long iterationId,long stageId) {
|
||||
locked(projectId,iterationId,"read"); stage(projectId,iterationId,stageId);
|
||||
List<Map<String,Object>> rows=revisions.selectStageRevisions(projectId,iterationId,stageId);
|
||||
for(Map<String,Object> row:rows) revisionTimes(row);
|
||||
return rows;
|
||||
}
|
||||
|
||||
/** 只读历史轮次及其中工作项;详情 ID 仍可打开评论、附件和原审计。 */
|
||||
public Map<String,Object> revision(long projectId,long iterationId,long stageId,long revisionId) {
|
||||
locked(projectId,iterationId,"read"); stage(projectId,iterationId,stageId);
|
||||
Map<String,Object> row=revisions.selectRevision(projectId,iterationId,stageId,revisionId); if(row==null) throw PmAccess.denied();
|
||||
revisionTimes(row);
|
||||
List<Map<String,Object>> items=revisions.selectRevisionItems(revisionId);
|
||||
for(Map<String,Object> item:items) {
|
||||
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);
|
||||
}
|
||||
|
||||
/** 列表与详情统一输出版本自身的 ISO 时间,避免历史抽屉误用数据库微秒列或当前阶段计划。 */
|
||||
private static void revisionTimes(Map<String,Object> row) {
|
||||
row.putAll(com.ruoyi.project.manage.rule.PmStageScheduleRules.times(PmGraphService.revision(row)));
|
||||
row.put("startedAt",PmTime.format(nullable(row,"started_at"),"Asia/Shanghai"));
|
||||
row.put("completedAt",PmTime.format(nullable(row,"completed_at"),"Asia/Shanghai"));
|
||||
row.put("supersededAt",PmTime.format(nullable(row,"superseded_at"),"Asia/Shanghai"));
|
||||
}
|
||||
|
||||
/** 版本列表按需返回,阶段归属先于分页校验,防止通过其他迭代阶段 ID 查询历史。 */
|
||||
public Map<String,Object> revisionPage(long projectId,long iterationId,long stageId,int page,int pageSize) {
|
||||
validatePage(page,pageSize); List<Map<String,Object>> rows=revisions(projectId,iterationId,stageId);
|
||||
return map("rows",rows.stream().skip((long)(page-1)*pageSize).limit(pageSize).toList(),"total",rows.size());
|
||||
}
|
||||
|
||||
/** 仅限制历史表格返回行数,轮次元数据和定义快照仍对应同一经过鉴权的历史版本。 */
|
||||
public Map<String,Object> revisionItemsPage(long projectId,long iterationId,long stageId,long revisionId,int page,int pageSize) {
|
||||
validatePage(page,pageSize); Map<String,Object> result=revision(projectId,iterationId,stageId,revisionId);
|
||||
List<?> rows=(List<?>)result.get("items"); result.put("total",rows.size());
|
||||
result.put("items",rows.stream().skip((long)(page-1)*pageSize).limit(pageSize).toList()); return result;
|
||||
}
|
||||
|
||||
/** 历史接口与当前项使用相同分页上限,拒绝负数和异常大页避免读取无界响应。 */
|
||||
private static void validatePage(int page,int size) { if(page<1||size<1||size>200) throw PmException.bad("分页范围无效,每页最多 200 项"); }
|
||||
|
||||
/** 成员显式确认保留的旧排期后清除警示;仍不绕过任务依赖排期校验。 */
|
||||
public void confirmScheduleReview(long itemId,VersionInput input) {
|
||||
scheduleService.confirmItem(itemId,input);
|
||||
}
|
||||
|
||||
/** 项目锁顺序与其它协作入口一致:先鉴权、锁项目行、再鉴权。 */
|
||||
private void locked(long projectId,long iterationId,String action) { access.project(projectId,action); workspace.lockProject(projectId); access.project(projectId,action); iterationAccess.require(projectId,iterationId,action); }
|
||||
/** 所有阶段 ID 先限定当前可访问项目,不对跨项目调用返回名称。 */
|
||||
private void stage(long projectId,long iterationId,long stageId) { if(stages.selectActiveStage(stageId,projectId,iterationId)==null) throw PmAccess.denied(); }
|
||||
/** 预览和提交使用同一项目图版本,不依赖单个工作项乐观锁。 */
|
||||
private long graphVersion(long projectId,long iterationId) { return number(revisions.selectGraphVersion(projectId,iterationId),"graph_version"); }
|
||||
/** JSON 仅来自本服务曾保存的结果,用于幂等重试返回完全相同的映射。 */
|
||||
private Map<String,Object> decoded(String value) { try { return decoder.readValue(value,new TypeReference<LinkedHashMap<String,Object>>(){}); } catch(Exception e) { throw new IllegalStateException("回退结果无法读取",e); } }
|
||||
/** 历史连线只读解析启动时的定义快照,无需假设 JSON 容器的泛型类型;缺少快照仍返回空值。 */
|
||||
private Map<String,Object> definitionSnapshot(long projectId,long iterationId,Map<String,Object> revision) {
|
||||
Long definitionId=nullable(revision,"flow_definition_revision_id"); if(definitionId==null) return null;
|
||||
Map<String,Object> saved=revisions.selectDefinition(projectId,iterationId,definitionId); if(saved==null) throw new IllegalStateException("阶段绑定的流程定义快照不存在");
|
||||
Map<String,Object> graph=decoded(text(saved,"graph_json"));
|
||||
Map<Long,String> names=new HashMap<>();
|
||||
for(Object value:(List<?>)graph.getOrDefault("stages",List.of())) { Map<?,?> stage=(Map<?,?>)value; names.put(number(stage,"id"),text(stage,"name")); }
|
||||
List<Map<String,Object>> edges=new ArrayList<>();
|
||||
for(Object value:(List<?>)graph.getOrDefault("stageEdges",List.of())) {
|
||||
Map<?,?> edge=(Map<?,?>)value;
|
||||
long from=number(edge,"predecessor_stage_id"),to=number(edge,"successor_stage_id");
|
||||
edges.add(map("predecessorStageId",from,"successorStageId",to,"predecessorName",names.get(from),"successorName",names.get(to)));
|
||||
}
|
||||
return map("revisionNo",number(saved,"revision_no"),"edges",edges);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在项目锁内复验当前阶段与严格上游目标,再计算路径、已执行后继和任务依赖的影响闭包。
|
||||
* 预览和提交都调用此方法;完成、开始或另一回退提交后,旧页面不能继续沿用来源资格。
|
||||
* @param projectId 已完成管理鉴权并锁定的项目
|
||||
* @param iterationId 回退操作唯一的迭代范围
|
||||
* @param input 来源、目标与补录草稿,不能通过参数指定当前阶段
|
||||
* @param graph 持锁读取的当前迭代图,历史轮次不参与判定
|
||||
* @return 新版本复制计划;无效来源或目标立即拒绝,需补录等问题保留在计划阻塞原因中
|
||||
*/
|
||||
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);
|
||||
List<Map<String,Object>> 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","只能回退到当前阶段的上游阶段,不能选择自身");
|
||||
LinkedHashSet<Long> affected=new LinkedHashSet<>();
|
||||
for(Long id:graph.stageNames().keySet()) if(sourceEqualsOrDescends(graph,target,id)&&sourceEqualsOrDescends(graph,id,source)) affected.add(id);
|
||||
List<Map<String,Object>> blockers=new ArrayList<>();
|
||||
boolean changed;
|
||||
do {
|
||||
changed=false;
|
||||
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);
|
||||
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; }
|
||||
if(predecessor.stageId()!=null&&affected.contains(predecessor.stageId())&&!affected.contains(successor.stageId())) {
|
||||
if(successor.stageId()==null) blockers.add(map("code","UNASSIGNED_DEPENDENT","taskId",successor.id(),"taskName",successor.title(),"message","依赖旧版任务的未分配工作项需先归入阶段"));
|
||||
else changed|=affected.add(successor.stageId());
|
||||
}
|
||||
}
|
||||
} while(changed);
|
||||
List<Item> copies=graph.items().values().stream().filter(i->!i.deleted()&&i.stageId()!=null&&affected.contains(i.stageId())&&!"CANCELLED".equals(i.status()))
|
||||
.sorted(Comparator.comparing((Item i)->i.parentTaskId()!=null).thenComparingLong(Item::id)).toList();
|
||||
List<Map<String,Object>> excluded=graph.items().values().stream().filter(i->!i.deleted()&&i.stageId()!=null&&affected.contains(i.stageId())&&"CANCELLED".equals(i.status()))
|
||||
.map(i->map("taskId",i.id(),"taskName",i.title(),"stageId",i.stageId(),"reason","已取消项不自动复活")).toList();
|
||||
Set<Long> copiedIds=new HashSet<>(); for(Item item:copies) copiedIds.add(item.id());
|
||||
for(Item item:copies) if(item.parentTaskId()!=null&&!copiedIds.contains(item.parentTaskId()))
|
||||
blockers.add(map("code","REWORK_PARENT_CONFLICT","taskId",item.id(),"message","子任务的父项已取消或不可复制"));
|
||||
for(Dependency dependency:graph.dependencies()) if(copiedIds.contains(dependency.successorId())) {
|
||||
Item predecessor=graph.items().get(dependency.taskId());
|
||||
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(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<Long> members=new HashSet<>(); for(Map<String,Object> row:workspace.selectMembers(projectId)) members.add(number(row,"userId"));
|
||||
List<Map<String,Object>> 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();
|
||||
var review=com.ruoyi.project.manage.rule.PmScheduleReviewRules.affected(graph,affected);
|
||||
blockers.addAll(review.blockers());
|
||||
return new Plan(graph,List.copyOf(affected),copies,excluded,missingAssignees,blockers,review.stageIds(),review.itemIds(),members);
|
||||
}
|
||||
|
||||
/** 预览完整解释版本替换、排期失效和不能提交的原因,不把警告当作成功。 */
|
||||
private Map<String,Object> previewValue(long projectId,long iterationId,ReworkInput input,Plan plan,long graphVersion) {
|
||||
List<Map<String,Object>> stages=plan.affected().stream().map(id->map("stageId",id,"name",plan.graph().stageNames().get(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(),
|
||||
"scheduleReviewStageIds",plan.reviewStages(),"scheduleReviewItemIds",plan.reviewItems(),"blockedReasons",plan.blockers(),"canCommit",plan.blockers().isEmpty(),
|
||||
"message","旧版工作项和历史保持只读,新版工作项重新开始且需要重新排期");
|
||||
}
|
||||
|
||||
/** 画布拓扑的祖先集合决定可回退路径,同顺序数字不会产生隐式关系。 */
|
||||
private static boolean sourceEqualsOrDescends(Graph graph,long ancestor,long descendant) { return ancestor==descendant||PmStageRules.ancestors(graph,descendant).contains(ancestor); }
|
||||
/** 补录列表缺失时视为空;数据有效性在正式插入前逐项校验。 */
|
||||
private static Map<Long,List<ReworkItemInput>> additions(ReworkInput input) { return input.additions()==null?Map.of():input.additions(); }
|
||||
/** 幂等键绑定补录内容,按阶段 ID 固定顺序编码,避免同一键重试时悄悄丢弃新工作项。 */
|
||||
private String additionsJson(ReworkInput input) { return json.encode(new TreeMap<>(additions(input))); }
|
||||
/** 补录只允许工作项白名单字段和有效项目成员,避免回退时注入状态或排期。 */
|
||||
private void validateAddition(long projectId,ReworkItemInput item) {
|
||||
if(item==null||item.title()==null||item.title().isBlank()||item.title().trim().length()>200) throw PmException.bad("补录工作项标题需为 1—200 个字符");
|
||||
if(!Set.of("TASK","REQUIREMENT","BUG").contains(item.type())) throw PmException.bad("补录工作项类型无效");
|
||||
if(item.priority()!=null&&!Set.of("LOW","MEDIUM","HIGH","URGENT").contains(item.priority())) throw PmException.bad("补录优先级无效");
|
||||
if(item.description()!=null&&item.description().length()>50000) throw PmException.bad("补录描述过长");
|
||||
access.assignee(projectId,item.assigneeId());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,141 @@
|
||||
package com.ruoyi.project.manage.service.impl;
|
||||
|
||||
import com.ruoyi.project.manage.domain.*;
|
||||
import com.ruoyi.project.manage.dto.*;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.mapper.*;
|
||||
import com.ruoyi.project.manage.rule.*;
|
||||
import com.ruoyi.project.manage.security.*;
|
||||
import com.ruoyi.project.manage.service.IPmScheduleService;
|
||||
import com.ruoyi.project.manage.service.support.*;
|
||||
import com.ruoyi.project.manage.util.PmTime;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.*;
|
||||
import java.util.*;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
/** 跨阶段和任务的时间约束共用项目锁,按整批最终图提交,避免逐条更新造成暂态冲突。 */
|
||||
@Service
|
||||
@Transactional(isolation=Isolation.READ_COMMITTED,rollbackFor=Exception.class)
|
||||
public class PmScheduleServiceImpl implements IPmScheduleService {
|
||||
private final PmWorkspaceMapper workspace;
|
||||
private final PmRevisionMapper revisions;
|
||||
private final PmScheduleMapper schedules;
|
||||
private final PmWorkItemMapper items;
|
||||
private final PmGraphService graphs;
|
||||
private final PmAuditService audit;
|
||||
private final PmAccess access;
|
||||
private final PmIterationAccess iterations;
|
||||
|
||||
/** 注入共享锁、完整图和审计边界;不调用控制器或自行创建数据库连接。 */
|
||||
public PmScheduleServiceImpl(PmWorkspaceMapper workspace,PmRevisionMapper revisions,PmScheduleMapper schedules,PmWorkItemMapper items,
|
||||
PmGraphService graphs,PmAuditService audit,PmAccess access,PmIterationAccess iterations) {
|
||||
this.workspace=workspace; this.revisions=revisions; this.schedules=schedules; this.items=items;
|
||||
this.graphs=graphs; this.audit=audit; this.access=access; this.iterations=iterations;
|
||||
}
|
||||
|
||||
/** 读当前版本及约束;未知阶段不返回其他项目的名称或时间。 */
|
||||
public Map<String,Object> constraints(long projectId,long iterationId,long stageId) {
|
||||
locked(projectId,iterationId,"read"); Graph graph=graphs.load(projectId,iterationId);
|
||||
if(!graph.stageRevisions().containsKey(stageId)) throw PmAccess.denied();
|
||||
return PmStageScheduleRules.summary(graph,stageId);
|
||||
}
|
||||
|
||||
/** 普通批量入口不能携带补录标志来解冻已完成版本。 */
|
||||
public void schedule(long projectId,long iterationId,BatchInput input) { apply(projectId,iterationId,input,false); }
|
||||
|
||||
/** 完成后补录单独鉴权且必填原因;不能改变实际时间或已存在的正常计划。 */
|
||||
public void backfill(long projectId,long iterationId,StageScheduleInput input) {
|
||||
if(input==null) throw PmException.bad("补录内容不能为空");
|
||||
apply(projectId,iterationId,new BatchInput(List.of(),List.of(input),null),true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在同一锁事务中将请求转换为整日计划、验证最终图并写入审计,旧参考只在成功确认时移除。
|
||||
* @param backfill 是否由受控补录入口调用,普通请求不能自行开启
|
||||
*/
|
||||
private void apply(long projectId,long iterationId,BatchInput input,boolean backfill) {
|
||||
if(input==null) throw PmException.bad("排期内容不能为空");
|
||||
List<StageScheduleInput> stageChanges=input.stages()==null?List.of():input.stages();
|
||||
List<ScheduleInput> itemChanges=input.items()==null?List.of():input.items();
|
||||
locked(projectId,iterationId,stageChanges.isEmpty()?"write":"admin");
|
||||
if(stageChanges.size()+itemChanges.size()<1||stageChanges.size()+itemChanges.size()>500) throw PmException.bad("每批排期需包含 1—500 个对象");
|
||||
if(!stageChanges.isEmpty()&&!itemChanges.isEmpty()) access.project(projectId,"write");
|
||||
if(input.graphVersion()!=null&&input.graphVersion()!=number(revisions.selectGraphVersion(projectId,iterationId),"graph_version"))
|
||||
throw PmException.conflict("GRAPH_VERSION_CONFLICT","流程已变化,请刷新排期后重试");
|
||||
Graph before=graphs.load(projectId,iterationId),after=before.copy(); long now=PmTime.now();
|
||||
Set<Long> seen=new HashSet<>();
|
||||
for(StageScheduleInput change:stageChanges) {
|
||||
if(change==null||!seen.add(change.id())) throw PmException.bad("阶段排期为空或重复");
|
||||
StageRevision old=before.stageRevisions().get(change.id()); if(old==null) throw PmAccess.denied();
|
||||
if(change.revisionId()==null||change.revisionId()!=old.id()) throw PmException.conflict("STAGE_REVISION_CHANGED","阶段已换版,请刷新后重试");
|
||||
version(change.version(),old.version()); boolean finished=finished(before,change.id());
|
||||
if(backfill) {
|
||||
if(!finished||old.plannedStart()!=null||old.plannedEnd()!=null||"BACKFILLED".equals(old.planSource())) throw PmException.conflict("PLAN_BACKFILL_NOT_ALLOWED","仅当前已完成且缺失计划的版本允许一次补录");
|
||||
reason(change.reason());
|
||||
} else if(finished||Boolean.TRUE.equals(change.backfill())) throw PmException.conflict("STAGE_REVISION_FROZEN","已完成版本只读,缺失计划请使用补录入口");
|
||||
PmTime.Plan plan=PmTime.planned(change.plannedStartAt(),change.plannedEndAt()); Long start=plan.start(),end=plan.end();
|
||||
if((start==null)!=(end==null)||start!=null&&end<start) throw PmException.bad("阶段预计时间须成对填写且结束不得早于开始");
|
||||
if(backfill&&start==null||old.scheduleReviewReworkId()!=null&&start==null) throw PmException.bad("确认或补录计划必须填写预计开始和结束");
|
||||
if(old.startedAt()!=null&&!Objects.equals(start,old.plannedStart())||old.startedAt()!=null&&!Objects.equals(end,old.plannedEnd())) reason(change.reason());
|
||||
after.stageRevisions().put(change.id(),old.scheduled(start,end,backfill?"BACKFILLED":"NORMAL",now));
|
||||
}
|
||||
seen.clear();
|
||||
for(ScheduleInput change:itemChanges) {
|
||||
if(change==null||!seen.add(change.id())) throw PmException.bad("工作项排期为空或重复");
|
||||
Item old=before.items().get(change.id());
|
||||
if(old==null) {
|
||||
Map<String,Object> ref=items.selectRevisionReference(projectId,change.id());
|
||||
if(ref!=null&&!Objects.equals(ref.get("stage_revision_id"),ref.get("current_revision_id"))) throw PmException.conflict("HISTORICAL_WORK_ITEM","历史版本工作项只读");
|
||||
throw PmAccess.denied();
|
||||
}
|
||||
if(old.deleted()) throw PmAccess.denied(); version(change.version(),old.version());
|
||||
if(old.stageId()!=null&&finished(before,old.stageId())) throw PmException.conflict("STAGE_REVISION_FROZEN","已完成阶段不能修改工作项排期");
|
||||
PmTime.Plan plan=PmTime.planned(change.plannedStartAt(),change.plannedEndAt()); Long start=plan.start(),end=plan.end();
|
||||
if(old.scheduleReviewReworkId()!=null) {
|
||||
if(PmRules.completed(old)) throw PmException.conflict("SCHEDULE_REVIEW_CLOSED","本轮已完成且未确认排期,参考时间仅供历史查看");
|
||||
StageRevision stage=old.stageId()==null?null:after.stageRevisions().get(old.stageId());
|
||||
if(start==null||end==null||old.stageId()!=null&&(stage==null||stage.plannedStart()==null||stage.scheduleReviewReworkId()!=null))
|
||||
throw PmException.conflict("SCHEDULE_REVIEW_REQUIRED","请先确认阶段计划,并完整填写工作项预计时间");
|
||||
}
|
||||
after.items().put(old.id(),old.confirmedSchedule(start,end));
|
||||
}
|
||||
// 已经生效的阶段边界不能直接清空来逃过包含关系;同批先取消全部受影响排期才允许清空。
|
||||
for(StageScheduleInput change:stageChanges) if(before.stageRevisions().get(change.id()).plannedStart()!=null&&after.stageRevisions().get(change.id()).plannedStart()==null
|
||||
&&after.items().values().stream().anyMatch(i->!i.deleted()&&Objects.equals(i.stageId(),change.id())&&(i.start()!=null||i.end()!=null)))
|
||||
throw PmException.conflict("STAGE_SCHEDULE_IN_USE","阶段仍有已排期工作项,不能单独清空阶段计划");
|
||||
PmRules.validateSchedules(after,"Asia/Shanghai");
|
||||
for(StageScheduleInput change:stageChanges) {
|
||||
StageRevision old=before.stageRevisions().get(change.id()),next=after.stageRevisions().get(change.id());
|
||||
if(schedules.updateStagePlan(old.id(),old.version(),map("start",next.plannedStart(),"end",next.plannedEnd(),"source",next.planSource(),"at",now))!=1)
|
||||
throw PmException.conflict("VERSION_CONFLICT","阶段计划已变化,请刷新后重试");
|
||||
audit.record(projectId,iterationId,null,backfill?"STAGE_PLAN_BACKFILLED":"STAGE_SCHEDULE_CHANGED",
|
||||
map("stageId",change.id(),"revisionId",old.id(),"before",PmStageScheduleRules.times(old),"after",PmStageScheduleRules.times(next),"reason",change.reason(),"sources",PmStageScheduleRules.summary(after,change.id()).get("sources")),access.actor());
|
||||
}
|
||||
for(ScheduleInput change:itemChanges) {
|
||||
Item old=before.items().get(change.id()),next=after.items().get(change.id());
|
||||
items.updateWorkItem(old.id(),old.version(),map("planned_start_at",next.start(),"planned_end_at",next.end(),"schedule_review_rework_id",null,"reference_planned_start_at",null,"reference_planned_end_at",null));
|
||||
audit.record(projectId,iterationId,old.id(),old.scheduleReviewReworkId()!=null?"SCHEDULE_REVIEWED":"SCHEDULE_CHANGED",
|
||||
map("beforeStart",PmTime.format(old.start(),"Asia/Shanghai"),"beforeEnd",PmTime.format(old.end(),"Asia/Shanghai"),"plannedStartAt",PmTime.format(next.start(),"Asia/Shanghai"),"plannedEndAt",PmTime.format(next.end(),"Asia/Shanghai"),"reworkId",old.scheduleReviewReworkId()),access.actor());
|
||||
}
|
||||
revisions.advanceGraphVersion(projectId,iterationId);
|
||||
}
|
||||
|
||||
/** 同一项目锁内将参考计划按整日重新确认;不能因普通编辑或缺省时间将待复核自动视为完成。 */
|
||||
public void confirmItem(long itemId,VersionInput input) {
|
||||
Map<String,Object> ref=items.selectProjectReference(itemId); if(ref==null) throw PmAccess.denied();
|
||||
long projectId=number(ref,"project_id"),iterationId=number(ref,"iteration_id"); locked(projectId,iterationId,"write");
|
||||
Item item=graphs.load(projectId,iterationId).items().get(itemId); if(item==null||item.deleted()) throw PmAccess.denied();
|
||||
version(input==null?null:input.version(),item.version()); if(item.scheduleReviewReworkId()==null) return;
|
||||
apply(projectId,iterationId,new BatchInput(List.of(new ScheduleInput(itemId,item.version(),PmTime.format(item.referenceStart(),"Asia/Shanghai"),PmTime.format(item.referenceEnd(),"Asia/Shanghai")))),false);
|
||||
}
|
||||
|
||||
/** 先鉴权再锁,锁后再鉴权;所有排期和回退服务遵循相同顺序,直至事务提交才释放。 */
|
||||
private void locked(long projectId,long iterationId,String action) { access.project(projectId,action); workspace.lockProject(projectId); access.project(projectId,action); iterations.require(projectId,iterationId,action); }
|
||||
/** 完成后的正常计划冻结,只有专用补录规则可以处理缺失值。 */
|
||||
private static boolean finished(Graph graph,long id) { return Set.of("COMPLETED","LEGACY_PASSED").contains(PmStageRules.executionStatus(graph,id)); }
|
||||
/** 请求必须提供数据版本,不能省略后覆盖他人的计划。 */
|
||||
private static void version(Integer expected,int actual) { if(expected==null) throw PmException.bad("数据版本不能为空"); if(expected!=actual) throw PmException.conflict("VERSION_CONFLICT","数据已更新,请刷新后重试"); }
|
||||
/** 已执行后的改期及补录必须留下可解释原因,避免将历史偏差静默抹去。 */
|
||||
private static void reason(String value) { if(value==null||value.isBlank()||value.length()>2000) throw PmException.bad("请填写 1—2000 字的调整或补录原因"); }
|
||||
}
|
||||
@ -0,0 +1,709 @@
|
||||
package com.ruoyi.project.manage.service.impl;
|
||||
|
||||
import com.ruoyi.project.manage.domain.Dependency;
|
||||
import com.ruoyi.project.manage.domain.Graph;
|
||||
import com.ruoyi.project.manage.domain.Item;
|
||||
import com.ruoyi.project.manage.dto.ChildInput;
|
||||
import com.ruoyi.project.manage.dto.CommentInput;
|
||||
import com.ruoyi.project.manage.dto.ConfigInput;
|
||||
import com.ruoyi.project.manage.dto.DependencyInput;
|
||||
import com.ruoyi.project.manage.dto.ItemInput;
|
||||
import com.ruoyi.project.manage.dto.MemberInput;
|
||||
import com.ruoyi.project.manage.dto.NameInput;
|
||||
import com.ruoyi.project.manage.dto.ProjectEditInput;
|
||||
import com.ruoyi.project.manage.dto.ProjectInput;
|
||||
import com.ruoyi.project.manage.dto.ScheduleInput;
|
||||
import com.ruoyi.project.manage.dto.SpaceInput;
|
||||
import com.ruoyi.project.manage.dto.StageAssignment;
|
||||
import com.ruoyi.project.manage.dto.TransitionInput;
|
||||
import com.ruoyi.project.manage.dto.VersionInput;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.mapper.PmActivityMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmDependencyMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmEventMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmRevisionMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmStageMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmUserMapper;
|
||||
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.security.PmAccess;
|
||||
import com.ruoyi.project.manage.security.PmIterationAccess;
|
||||
import com.ruoyi.project.manage.service.IPmService;
|
||||
import com.ruoyi.project.manage.service.support.PmAuditService;
|
||||
import com.ruoyi.project.manage.service.support.PmGraphService;
|
||||
import com.ruoyi.project.manage.util.PmTime;
|
||||
import com.ruoyi.project.manage.util.PmJson;
|
||||
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
import java.util.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.*;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
|
||||
/** 独立协作只使用 pm_collab_* 存储;所有业务写入口共享项目锁,最终态、历史和 outbox 原子提交。 */
|
||||
@Service
|
||||
@Transactional(isolation=Isolation.READ_COMMITTED,rollbackFor=Exception.class)
|
||||
public class PmServiceImpl implements IPmService {
|
||||
private final PmWorkspaceMapper workspaceMapper;
|
||||
private final PmWorkItemMapper workItemMapper;
|
||||
private final PmDependencyMapper dependencyMapper;
|
||||
private final PmStageMapper stageMapper;
|
||||
private final PmActivityMapper activityMapper;
|
||||
private final PmEventMapper eventMapper;
|
||||
private final PmRevisionMapper revisionMapper;
|
||||
private final PmUserMapper userMapper;
|
||||
private final PmGraphService graphService;
|
||||
private final PmAuditService auditService;
|
||||
private final PmAccess access;
|
||||
private final PmIterationAccess iterationAccess;
|
||||
private final PmJson jsonCodec;
|
||||
private final com.ruoyi.project.manage.service.IPmScheduleService schedules;
|
||||
|
||||
/** 注入对象 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) {
|
||||
this.schedules=schedules;
|
||||
this.iterationAccess=iterationAccess;
|
||||
this.workspaceMapper=workspaceMapper;
|
||||
this.workItemMapper=workItemMapper;
|
||||
this.dependencyMapper=dependencyMapper;
|
||||
this.stageMapper=stageMapper;
|
||||
this.activityMapper=activityMapper;
|
||||
this.eventMapper=eventMapper;
|
||||
this.revisionMapper=revisionMapper;
|
||||
this.userMapper=userMapper;
|
||||
this.graphService=graphService;
|
||||
this.auditService=auditService;
|
||||
this.access=access;
|
||||
this.jsonCodec=jsonCodec;
|
||||
}
|
||||
|
||||
/** 只列出独立协作项目和创建人;项目列表和旧协作记录不参与可见性或维护资格计算。 */
|
||||
public List<Map<String,Object>> projects() {
|
||||
access.permission("read"); long user=access.actor(); boolean admin=SecurityUtils.isAdmin();
|
||||
List<Map<String,Object>> result=workspaceMapper.selectVisibleProjects(user,admin);
|
||||
for(Map<String,Object> p:result) { boolean own=access.permitted("admin")&&Long.valueOf(user).equals(nullable(p,"creatorId")); p.put("enabled",flag(p,"enabled")); p.put("canEdit",own); p.put("canDelete",own); p.put("canManage",access.permitted("admin")&&(admin||flag(p,"manager"))); p.put("canCreate",true); p.put("canWrite",access.permitted("write")); p.remove("manager"); }
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 空间仅向所有者和可见项目成员展示,创建人昵称及维护资格由服务计算。 */
|
||||
public List<Map<String,Object>> spaces() {
|
||||
access.permission("read"); long user=access.actor();
|
||||
List<Map<String,Object>> result=workspaceMapper.selectVisibleSpaces(user,SecurityUtils.isAdmin());
|
||||
for(Map<String,Object> s:result) { boolean own=access.permitted("admin")&&number(s,"creatorId")==user; s.put("canEdit",own); s.put("canDelete",own); s.put("canCreateProject",access.permitted("admin")&&(SecurityUtils.isAdmin()||number(s,"creatorId")==user)); }
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 有管理动作权限的用户创建自己管理的空间,不修改其它空间所有者。 */
|
||||
public long createSpace(SpaceInput input) { access.permission("admin"); return workspaceMapper.insertSpace(map("name",required(input.name(),120,"空间名称"),"owner_id",access.actor(),"created_at",PmTime.now())); }
|
||||
|
||||
/** 锁定协作空间后只创建独立项目和成员;不生成项目列表、财务或生产项目记录。 */
|
||||
public long createProject(ProjectInput input) {
|
||||
access.permission("admin"); associationSpace(input.spaceId()); fixedZone(input.timezone()); long user=access.actor();
|
||||
long id=workspaceMapper.insertProject(map("project_code","PM-"+UUID.randomUUID().toString().substring(0,12),"project_name",required(input.name(),200,"项目名称"),"manager_id",user,"create_by",SecurityUtils.getUsername(),"create_time",new java.sql.Timestamp(System.currentTimeMillis())));
|
||||
workspaceMapper.insertMember(map("project_id",id,"user_id",user,"member_role","MANAGER","create_by",SecurityUtils.getUsername(),"create_time",new java.sql.Timestamp(System.currentTimeMillis())));
|
||||
configureNew(id,input.spaceId(),user); auditService.record(id,null,"PROJECT_CREATED",map("name",input.name()),user); return id;
|
||||
}
|
||||
|
||||
/** 创建人编辑空间名称;行锁与版本覆盖整个鉴权、更新事务,不能转移创建身份。 */
|
||||
public void editSpace(long id,NameInput input) {
|
||||
access.permission("admin"); Map<String,Object> space=lockSpace(id,true); version(input.version(),(int)number(space,"version"));
|
||||
workspaceMapper.updateSpace(id,(int)number(space,"version"),map("name",required(input.name(),120,"空间名称")));
|
||||
}
|
||||
|
||||
/** 仅创建人可软删除空空间;与项目创建/移动共用空间锁,保留所有历史关联行。 */
|
||||
public void deleteSpace(long id,VersionInput input) {
|
||||
access.permission("admin"); Map<String,Object> space=lockSpace(id,true); version(input.version(),(int)number(space,"version"));
|
||||
if(workspaceMapper.selectActiveProjectInSpace(id)!=null) throw PmException.conflict("SPACE_NOT_EMPTY","空间仍有未删除项目,请先删除或移动这些项目");
|
||||
workspaceMapper.updateSpace(id,(int)number(space,"version"),map("deleted",true));
|
||||
}
|
||||
|
||||
/** 创建人更新名称或空间,空间 ID 升序→项目锁的固定顺序保护移动与空间删除。 */
|
||||
public void editProject(long id,ProjectEditInput input) {
|
||||
Map<String,Object> original=creatorProject(id); lockProjectSpaces(original,input.spaceId());
|
||||
workspaceMapper.ensureProjectLock(id); workspaceMapper.lockProject(id);
|
||||
Map<String,Object> latest=creatorProject(id); ensureSameSpace(original,latest); version(input.version(),(int)number(latest,"version"));
|
||||
String name=required(input.name(),200,"项目名称");
|
||||
workspaceMapper.updateProject(id,(int)number(latest,"version"),map("project_name",name,"update_by",SecurityUtils.getUsername(),"update_time",new java.sql.Timestamp(System.currentTimeMillis())));
|
||||
if(latest.get("space_id")==null) configureNew(id,input.spaceId(),nullable(latest,"actualCreatorId"));
|
||||
else workspaceMapper.moveProjectSpace(input.spaceId(),id);
|
||||
auditService.record(id,null,"PROJECT_EDITED",map("name",name,"spaceId",input.spaceId()),access.actor());
|
||||
}
|
||||
|
||||
/** 创建人软删除项目;持有统一项目锁直到历史和事件提交,关联内容不物理删除。 */
|
||||
public void deleteProject(long id,VersionInput input) {
|
||||
Map<String,Object> original=creatorProject(id); Long spaceId=nullable(original,"space_id"); if(spaceId!=null) lockSpace(spaceId,false);
|
||||
workspaceMapper.ensureProjectLock(id); workspaceMapper.lockProject(id);
|
||||
Map<String,Object> latest=creatorProject(id); ensureSameSpace(original,latest); version(input.version(),(int)number(latest,"version"));
|
||||
workspaceMapper.updateProject(id,(int)number(latest,"version"),map("del_flag","2","update_by",SecurityUtils.getUsername(),"update_time",new java.sql.Timestamp(System.currentTimeMillis())));
|
||||
auditService.record(id,null,"PROJECT_DELETED",map("name",text(latest,"project_name")),access.actor());
|
||||
}
|
||||
|
||||
/** 兼容空间配置更新,只接受已有独立协作项目;没有从项目列表导入或启用的路径。 */
|
||||
public void configure(long projectId,ConfigInput input) {
|
||||
Map<String,Object> original=creatorProject(projectId); fixedZone(input.timezone()); lockProjectSpaces(original,input.spaceId());
|
||||
workspaceMapper.ensureProjectLock(projectId);
|
||||
workspaceMapper.lockProject(projectId); Map<String,Object> latest=creatorProject(projectId); ensureSameSpace(original,latest);
|
||||
Map<String,Object> config=workspaceMapper.selectConfig(projectId);
|
||||
if(config==null) throw PmAccess.denied();
|
||||
version(input.version(),(int)number(config,"version"));
|
||||
workspaceMapper.moveProjectSpace(input.spaceId(),projectId);
|
||||
workspaceMapper.incrementProjectVersion(projectId);
|
||||
auditService.record(projectId,null,"PROJECT_CONFIGURED",map("spaceId",input.spaceId()),access.actor());
|
||||
}
|
||||
|
||||
/** 项目成员和经理列表只暴露分配工作所需的用户标识与昵称。 */
|
||||
public List<Map<String,Object>> members(long projectId) {
|
||||
locked(projectId,"read");
|
||||
return workspaceMapper.selectMembers(projectId);
|
||||
}
|
||||
|
||||
/** 只有项目经理具备管理动作权限时可搜索有效用户,以便邀请成员;不返回账号敏感字段。 */
|
||||
public List<Map<String,Object>> candidateUsers(long projectId,String keyword) {
|
||||
locked(projectId,"admin"); String search=keyword==null?"":keyword.trim();
|
||||
return userMapper.selectCandidates("%"+search+"%");
|
||||
}
|
||||
|
||||
/** 修改项目成员;资格增减只使引用该成员的迭代复制/回退预览失效,角色调整不改任务数据。 */
|
||||
public void member(long projectId,MemberInput input,boolean remove) {
|
||||
locked(projectId,"admin"); if(input.userId()==null) throw PmException.bad("成员不能为空");
|
||||
if(userMapper.selectActiveUser(input.userId())==null) throw PmException.bad("用户不可用");
|
||||
boolean wasMember=workspaceMapper.selectMembers(projectId).stream().anyMatch(row->number(row,"userId")==input.userId());
|
||||
Map<String,Object> project=workspaceMapper.selectProjectManager(projectId);
|
||||
if(input.userId().equals(nullable(project,"manager_id")) && (remove||!"MANAGER".equals(input.role()))) throw PmException.bad("项目负责人必须保留经理身份");
|
||||
if(remove) {
|
||||
if(workItemMapper.selectAssignedItem(projectId,input.userId())!=null) throw PmException.conflict("MEMBER_ASSIGNED","请先重新分配该成员负责的工作项");
|
||||
if(stageMapper.selectOwnedStage(projectId,input.userId())!=null) throw PmException.conflict("MEMBER_ASSIGNED","请先重新分配该成员负责的阶段");
|
||||
workspaceMapper.deleteMember(projectId,input.userId());
|
||||
} else {
|
||||
if(input.role()==null||!Set.of("MANAGER","MEMBER").contains(input.role())) throw PmException.bad("成员角色无效");
|
||||
workspaceMapper.upsertMember(projectId,input.userId(),input.role(),SecurityUtils.getUsername());
|
||||
}
|
||||
// 负责人保留在历史中,但复制必须使用当前成员资格。项目锁覆盖资格和版本更新,
|
||||
// 防止回退预览通过后静默清空或恢复新版负责人,也不让无关迭代的预览过期。
|
||||
if(wasMember!=!remove) revisionMapper.advanceMemberAffectedGraphVersions(projectId,input.userId());
|
||||
auditService.record(projectId,null,remove?"MEMBER_REMOVED":"MEMBER_CHANGED",map("userId",input.userId(),"role",input.role()),access.actor());
|
||||
}
|
||||
|
||||
/** 列表使用单次项目图快照计算状态,生命周期、任务和阶段阻塞分别返回。 */
|
||||
public List<Map<String,Object>> items(long projectId,long iterationId) {
|
||||
locked(projectId,iterationId,"read"); Graph graph=graphService.load(projectId,iterationId); String zone=zone(projectId);
|
||||
return graph.items().values().stream().filter(i->!i.deleted()).map(i->view(graph,i,zone)).toList();
|
||||
}
|
||||
|
||||
/** 工作项详情加载当前任务及阶段前置,评论、附件和历史均在项目鉴权后返回。 */
|
||||
public Map<String,Object> detail(long id) {
|
||||
long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"read"); Graph graph=graphService.load(projectId,iterationId);
|
||||
Item current=graph.items().get(id);
|
||||
Map<String,Object> result;
|
||||
if(current==null) {
|
||||
Map<String,Object> row=workItemMapper.selectHistoricalItem(projectId,id); if(row==null) throw PmAccess.denied();
|
||||
Map<Long,Item> oldItems=new LinkedHashMap<>();
|
||||
for(Map<String,Object> saved:revisionMapper.selectRevisionItems(number(row,"stage_revision_id"))) {
|
||||
Item old=historicalItem(projectId,saved); oldItems.put(old.id(),old);
|
||||
}
|
||||
Graph oldGraph=new Graph(oldItems,new ArrayList<>(),new LinkedHashMap<>(),new ArrayList<>(),new LinkedHashMap<>(),graph.iteration()); Item historical=item(oldGraph,id);
|
||||
result=view(oldGraph,historical,zone(projectId));
|
||||
result.put("stageRevisionNo",(int)number(row,"stage_revision_no"));
|
||||
result.put("stageNameSnapshot",text(row,"stage_name_snapshot"));
|
||||
result.put("historicalChildren",PmRules.children(oldGraph,id).stream().map(child->{ Map<String,Object> childView=view(oldGraph,child,zone(projectId)); childView.put("historical",true); childView.put("canStart",false); return childView; }).toList());
|
||||
List<Map<String,Object>> originalConditions=new ArrayList<>();
|
||||
for(Map<String,Object> dependency:dependencyMapper.selectItemDependencies(projectId,id)) {
|
||||
boolean available=!flag(dependency,"source_deleted"); String status=text(dependency,"source_status");
|
||||
originalConditions.add(map("id",number(dependency,"id"),"version",number(dependency,"version"),"conditionType","TASK_COMPLETED",
|
||||
"sourceId",number(dependency,"predecessor_task_id"),"sourceWorkItemId",available?number(dependency,"predecessor_task_id"):null,
|
||||
"sourceName",available?text(dependency,"source_name"):"前置对象不可用","currentStatus",status,"expectedStatus","COMPLETED",
|
||||
"satisfied",available&&Set.of("COMPLETED","CLOSED").contains(status),"plannedEndAt",PmTime.format(nullable(dependency,"planned_end_at"),zone(projectId)),
|
||||
"participatesInSchedule",nullable(dependency,"planned_end_at")!=null));
|
||||
}
|
||||
result.put("dependencyConditions",originalConditions);
|
||||
result.putAll(map("historical",true,"canStart",false,"canComplete",false,"canCreateChild",false,"blockedReasons",List.of(map("code","HISTORICAL_WORK_ITEM","message","历史版本只读"))));
|
||||
} else result=view(graph,item(graph,id),zone(projectId));
|
||||
result.put("comments",auditTimes(activityMapper.selectComments(id),zone(projectId)));
|
||||
result.put("attachments",activityMapper.selectAttachments(id));
|
||||
result.put("history",auditTimes(activityMapper.selectHistory(id),zone(projectId)));
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 项目成员创建待开始工作项时按北京时间整日排期;阶段、最终排期和成员归属仍在项目锁内校验。 */
|
||||
public long create(long projectId,long iterationId,ItemInput input) {
|
||||
locked(projectId,iterationId,"create"); validateFields(projectId,iterationId,input);
|
||||
PmTime.Plan plan=PmTime.planned(input.plannedStartAt(),input.plannedEndAt()); Long start=plan.start(),end=plan.end();
|
||||
Graph before=graphService.load(projectId,iterationId),proposed=before.copy(); requireStageMutable(before,input.stageId());
|
||||
// 先校验候选最终态,再写入,避免数据库 CHECK 抢先把业务排期冲突变成通用完整性错误。
|
||||
proposed.items().put(-1L,new Item(-1,projectId,input.type(),input.title(),input.description(),input.assigneeId(),input.priority(),"READY",start,end,null,null,0,false,input.stageId()));
|
||||
PmRules.validateSchedules(proposed,zone(projectId)); PmRules.validateAcyclic(proposed); PmStageRules.validateRegression(before,proposed);
|
||||
long id=workItemMapper.insertWorkItem(map("project_id",projectId,"iteration_id",iterationId,"type",input.type(),"title",input.title().trim(),"description",input.description(),"assignee_id",input.assigneeId(),"priority",input.priority()==null?"MEDIUM":input.priority(),"planned_start_at",start,"planned_end_at",end,"stage_id",input.stageId(),"stage_revision_id",currentRevision(before,input.stageId()),"created_by",access.actor(),"created_at",PmTime.now()));
|
||||
Graph graph=graphService.load(projectId,iterationId); PmRules.validateSchedules(graph,zone(projectId)); PmRules.validateAcyclic(graph);
|
||||
auditService.record(projectId,iterationId,id,"ITEM_CREATED",map("title",input.title(),"type",input.type()),access.actor()); return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一层子任务并按整日排期,项目锁覆盖父版本、终态、时间、隐式循环与历史;阶段始终继承父任务。
|
||||
* @param parentId 当前项目有效根任务 ID,完成、关闭、取消或子任务不能作为新父项
|
||||
* @param request 当前父版本和白名单子任务字段;未指定阶段时继承父阶段
|
||||
* @return 新子任务 ID;同时推进父版本,子创建和父关联历史/outbox 在同一事务保存
|
||||
* @throws PmException 权限、版本、父范围或业务规则不满足时拒绝,整笔事务回滚
|
||||
*/
|
||||
public long createChild(long parentId,ChildInput request) {
|
||||
long projectId=projectOf(parentId),iterationId=iterationOf(parentId); locked(projectId,iterationId,"write"); Graph graph=graphService.load(projectId,iterationId); Item parent=writableItem(graph,parentId);
|
||||
version(request.parentVersion(),parent.version());
|
||||
if(!"TASK".equals(parent.type())||parent.parentTaskId()!=null||PmRules.terminal(parent)) throw PmException.conflict("CHILD_CREATE_FORBIDDEN","仅未结束的根任务可以创建一层子任务");
|
||||
ItemInput input=request.item(); if(input==null) throw PmException.bad("子任务内容不能为空");
|
||||
if(!"TASK".equals(input.type())||input.stageId()!=null&&!Objects.equals(input.stageId(),parent.stageId())) throw PmException.bad("子任务必须为任务且继承父阶段");
|
||||
input=new ItemInput(input.type(),input.title(),input.description(),input.assigneeId(),input.priority(),input.plannedStartAt(),input.plannedEndAt(),input.version(),parent.stageId());
|
||||
validateFields(projectId,iterationId,input); PmTime.Plan plan=PmTime.planned(input.plannedStartAt(),input.plannedEndAt()); Long start=plan.start(),end=plan.end();
|
||||
Graph before=graph.copy();
|
||||
graph.items().put(-1L,new Item(-1,projectId,"TASK",input.title(),input.description(),input.assigneeId(),input.priority(),"READY",start,end,null,null,0,false,parent.stageId(),parentId));
|
||||
PmRules.validateSchedules(graph,zone(projectId)); PmRules.validateAcyclic(graph); PmStageRules.validateRegression(before,graph);
|
||||
long id=workItemMapper.insertWorkItem(map("project_id",projectId,"iteration_id",iterationId,"parent_task_id",parentId,"stage_id",parent.stageId(),"stage_revision_id",parent.stageRevisionId(),"type","TASK","title",input.title().trim(),"description",input.description(),"assignee_id",input.assigneeId(),"priority",input.priority()==null?"MEDIUM":input.priority(),"planned_start_at",start,"planned_end_at",end,"created_by",access.actor(),"created_at",PmTime.now()));
|
||||
workItemMapper.updateWorkItem(parentId,parent.version(),map("title",parent.title()));
|
||||
auditService.record(projectId,iterationId,id,"CHILD_CREATED",map("title",input.title(),"parentTaskId",parentId),access.actor());
|
||||
auditService.record(projectId,iterationId,parentId,"CHILD_ADDED",map("childTaskId",id,"title",input.title()),access.actor()); return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在父项目鉴权后返回有效子任务,详情和外部客户端复用实时业务摘要。
|
||||
* @param id 有权限访问的父工作项 ID,不接受跨项目来源
|
||||
* @return 未软删除子任务的当前状态、门禁及排期;无子任务返回空列表,不产生业务历史
|
||||
*/
|
||||
public List<Map<String,Object>> children(long id) {
|
||||
long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"read"); Graph graph=graphService.load(projectId,iterationId); item(graph,id);
|
||||
return PmRules.children(graph,id).stream().map(i->view(graph,i,zone(projectId))).toList();
|
||||
}
|
||||
|
||||
/** 普通编辑保留未改变的旧排期,改期才转换为整日;校验父子时间及阶段继承,父阶段变化原子同步子阶段。 */
|
||||
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(!existing.type().equals(input.type())) throw PmException.bad("工作项类型创建后不可直接变更");
|
||||
validateInheritedStage(graph,existing,input.stageId());
|
||||
if(existing.scheduleReviewReworkId()!=null&&(!Objects.equals(existing.start(),PmTime.parse(input.plannedStartAt()))||!Objects.equals(existing.end(),PmTime.parse(input.plannedEndAt()))))
|
||||
throw PmException.conflict("SCHEDULE_REVIEW_REQUIRED","排期待复核,请通过排期编辑或批量排期确认时间");
|
||||
Graph before=graph.copy();
|
||||
PmTime.Plan plan=PmTime.editedPlan(input.plannedStartAt(),input.plannedEndAt(),existing.start(),existing.end());
|
||||
graph.items().put(id,existing.scheduled(plan.start(),plan.end()).inStage(input.stageId()));
|
||||
simulateStage(graph,existing,input.stageId());
|
||||
PmRules.validateSchedules(graph,zone(projectId)); PmRules.validateAcyclic(graph); PmStageRules.validateRegression(before,graph);
|
||||
workItemMapper.updateWorkItem(id,existing.version(),map("title",input.title().trim(),"description",input.description(),"assignee_id",input.assigneeId(),"priority",input.priority()==null?"MEDIUM":input.priority(),"planned_start_at",plan.start(),"planned_end_at",plan.end(),"stage_id",input.stageId(),"stage_revision_id",currentRevision(graph,input.stageId())));
|
||||
auditService.record(projectId,iterationId,id,"ITEM_EDITED",map("title",input.title()),access.actor());
|
||||
cascadeStage(before,existing,input.stageId()); syncStage(projectId,iterationId,existing.stageId(),PmStageRules.executionStatus(before,existing.stageId()==null?-1:existing.stageId())); syncStage(projectId,iterationId,input.stageId(),PmStageRules.executionStatus(before,input.stageId()==null?-1:input.stageId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有阶段调整共用父子继承校验,版本、归属和历史在同一项目锁事务中提交。
|
||||
* @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());
|
||||
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());
|
||||
PmRules.validateSchedules(graph,zone(projectId)); PmRules.validateAcyclic(graph); PmStageRules.validateRegression(before,graph);
|
||||
workItemMapper.updateWorkItem(id,existing.version(),map("stage_id",input.stageId(),"stage_revision_id",currentRevision(graph,input.stageId())));
|
||||
auditService.record(projectId,iterationId,id,"ITEM_STAGE_CHANGED",map("fromStageId",existing.stageId(),"stageId",input.stageId()),access.actor()); cascadeStage(before,existing,input.stageId());
|
||||
syncStage(projectId,iterationId,existing.stageId(),PmStageRules.executionStatus(before,existing.stageId()==null?-1:existing.stageId())); syncStage(projectId,iterationId,input.stageId(),PmStageRules.executionStatus(before,input.stageId()==null?-1:input.stageId()));
|
||||
}
|
||||
|
||||
/** 子任务不能单独移动阶段;保持同父归属避免画布组织和层级关系相互矛盾。 */
|
||||
private void validateInheritedStage(Graph graph,Item item,Long stageId) {
|
||||
if(item.parentTaskId()!=null&&!Objects.equals(item(graph,item.parentTaskId()).stageId(),stageId)) throw PmException.conflict("CHILD_STAGE_INHERITED","子任务阶段由父任务决定");
|
||||
}
|
||||
|
||||
/** 父阶段移动时同步有效子任务并推进各自版本;项目锁防止子编辑覆盖同步结果。 */
|
||||
private void cascadeStage(Graph graph,Item parent,Long stageId) {
|
||||
if(Objects.equals(parent.stageId(),stageId)) return;
|
||||
for(Item child:PmRules.children(graph,parent.id())) {
|
||||
workItemMapper.updateWorkItem(child.id(),child.version(),map("stage_id",stageId,"stage_revision_id",currentRevision(graph,stageId)));
|
||||
auditService.record(parent.projectId(),graph.iteration().id(),child.id(),"ITEM_STAGE_CHANGED",map("fromStageId",child.stageId(),"stageId",stageId,"parentTaskId",parent.id()),access.actor());
|
||||
}
|
||||
}
|
||||
|
||||
/** 在数据库写入前模拟父子最终阶段,确保跨阶段循环与已开始任务门禁不会被归属修改绕过。 */
|
||||
private void simulateStage(Graph graph,Item parent,Long stageId) {
|
||||
graph.items().put(parent.id(),item(graph,parent.id()).inStage(stageId));
|
||||
for(Item child:PmRules.children(graph,parent.id())) graph.items().put(child.id(),child.inStage(stageId));
|
||||
}
|
||||
|
||||
/** 返回后端实时可开始判断;与提交校验使用同一实际条件函数。 */
|
||||
public Map<String,Object> startability(long id) {
|
||||
long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"read"); Graph graph=graphService.load(projectId,iterationId);
|
||||
return startability(graph,item(graph,id),zone(projectId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有进入进行中的公共入口:先校验身份权限、状态、版本和任务/阶段前置,再原子保存状态/时间/历史/outbox。
|
||||
* @param id 要开始的工作项 ID
|
||||
* @param input 用户当前看到的数据版本;缺失或过期时拒绝开始
|
||||
*/
|
||||
public void start(long id,VersionInput input) {
|
||||
long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"write"); Graph graph=graphService.load(projectId,iterationId);
|
||||
performStart(graph,writableItem(graph,id),input.version(),zone(projectId));
|
||||
}
|
||||
|
||||
/** 状态修改委托统一开始;完成检查子终态,关闭/重开保留完成时间,回退保护全部已开始后续和父任务。 */
|
||||
public void transition(long id,TransitionInput input) {
|
||||
long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"write"); Graph graph=graphService.load(projectId,iterationId); Item existing=writableItem(graph,id);
|
||||
if("IN_PROGRESS".equals(input.status())) { performStart(graph,existing,input.version(),zone(projectId)); return; }
|
||||
version(input.version(),existing.version());
|
||||
if(input.status()==null || existing.status().equals(input.status())) throw PmException.bad("目标状态无效");
|
||||
boolean allowed="READY".equals(input.status())&&!"CLOSED".equals(existing.status()) || "COMPLETED".equals(input.status())&&Set.of("IN_PROGRESS","CLOSED").contains(existing.status()) || "CLOSED".equals(input.status())&&"COMPLETED".equals(existing.status()) || "CANCELLED".equals(input.status())&&Set.of("READY","IN_PROGRESS").contains(existing.status());
|
||||
if(!allowed) throw PmException.conflict("INVALID_TRANSITION","当前状态不允许此转换");
|
||||
Graph before=graph.copy(); graph.items().put(id,existing.transitioned(input.status(),false));
|
||||
PmRules.validateActual(graph,zone(projectId)); PmStageRules.validateRegression(before,graph);
|
||||
Long actualEnd=Set.of("COMPLETED","CLOSED").contains(input.status())?("IN_PROGRESS".equals(existing.status())?PmTime.now():existing.actualEnd()):null;
|
||||
workItemMapper.updateWorkItem(id,existing.version(),map("status",input.status(),"actual_start_at","READY".equals(input.status())?null:existing.actualStart(),"actual_end_at",actualEnd));
|
||||
auditService.record(projectId,iterationId,id,"STATUS_CHANGED",map("from",existing.status(),"to",input.status()),access.actor());
|
||||
syncStage(projectId,iterationId,existing.stageId(),PmStageRules.executionStatus(before,existing.stageId()==null?-1:existing.stageId()));
|
||||
}
|
||||
|
||||
/** 软删除工作项前检查已开始后续的任务条件;历史记录及已停用的流程数据均保留。 */
|
||||
public void delete(long id,VersionInput 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());
|
||||
if(!PmRules.children(graph,id).isEmpty()) throw PmException.conflict("PARENT_HAS_CHILDREN","请先处理并删除子任务,再删除父任务");
|
||||
Graph before=graph.copy(); graph.items().put(id,existing.transitioned(existing.status(),true));
|
||||
PmRules.validateActual(graph,zone(projectId)); PmStageRules.validateRegression(before,graph);
|
||||
workItemMapper.updateWorkItem(id,existing.version(),map("deleted",true)); auditService.record(projectId,iterationId,id,"ITEM_DELETED",map("title",existing.title()),access.actor());
|
||||
syncStage(projectId,iterationId,existing.stageId(),PmStageRules.executionStatus(before,existing.stageId()==null?-1:existing.stageId()));
|
||||
if(existing.parentTaskId()!=null) {
|
||||
Item parent=item(graph,existing.parentTaskId()); workItemMapper.updateWorkItem(parent.id(),parent.version(),map("title",parent.title()));
|
||||
auditService.record(projectId,iterationId,parent.id(),"CHILD_REMOVED",map("childTaskId",id,"title",existing.title()),access.actor());
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询当前有效任务依赖及条件状态;停用节点条件只保留历史,不参与响应或判断。 */
|
||||
public List<Map<String,Object>> dependencies(long id) {
|
||||
long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"read"); Graph graph=graphService.load(projectId,iterationId); item(graph,id); return PmRules.conditions(graph,id,zone(projectId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 在项目锁下模拟依赖最终图,先检查循环与排期再保存;只有待开始任务可以编辑。
|
||||
* @param id 后续任务实例 ID
|
||||
* @param dependencyId 编辑或删除的依赖 ID;新增时为空
|
||||
* @param input 前置任务引用及任务/依赖版本;删除时仍必须提供两个版本
|
||||
* @param remove 是否删除此依赖
|
||||
* @return 已保存或删除的依赖 ID;失败时整个事务回滚且不产生成功事件
|
||||
*/
|
||||
public long dependency(long id,Long dependencyId,DependencyInput input,boolean remove) {
|
||||
long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"write"); Graph graph=graphService.load(projectId,iterationId); Item successor=writableItem(graph,id);
|
||||
if(!"TASK".equals(successor.type()) || !"READY".equals(successor.status())) throw PmException.conflict("DEPENDENCY_EDIT_FORBIDDEN","只有待开始任务可以编辑前置依赖");
|
||||
version(input.taskVersion(),successor.version());
|
||||
Dependency existing=dependencyId==null?null:graph.dependencies().stream().filter(d->d.id()==dependencyId&&d.successorId()==id).findFirst().orElseThrow(PmAccess::denied);
|
||||
if(existing!=null) { version(input.version(),existing.version()); graph.dependencies().remove(existing); }
|
||||
Dependency added=null;
|
||||
if(!remove) {
|
||||
if(!"TASK_COMPLETED".equals(input.conditionType()) || input.predecessorTaskId()==null || input.expectedStatus()!=null&&!"COMPLETED".equals(input.expectedStatus())) throw PmException.bad("仅支持前置任务已完成条件");
|
||||
Item predecessor=item(graph,input.predecessorTaskId());
|
||||
if(!"TASK".equals(predecessor.type())) throw PmException.bad("前置对象必须是任务");
|
||||
if(predecessor.id()==id) throw PmException.conflict("SELF_DEPENDENCY","任务不能依赖自身");
|
||||
added=new Dependency(existing==null?-1:existing.id(),projectId,id,"TASK_COMPLETED",predecessor.id(),"COMPLETED",existing==null?0:existing.version());
|
||||
for(Dependency other:graph.dependencies()) if(other.successorId()==id && Objects.equals(other.taskId(),added.taskId())) throw PmException.conflict("DUPLICATE_DEPENDENCY","不能重复添加同一个前置条件");
|
||||
graph.dependencies().add(added);
|
||||
}
|
||||
PmRules.validateAcyclic(graph); PmRules.validateSchedules(graph,zone(projectId));
|
||||
long saved=dependencyId==null?0:dependencyId;
|
||||
if(remove) { if(existing==null) throw PmException.bad("依赖不能为空"); dependencyMapper.deleteDependency(dependencyId); }
|
||||
else {
|
||||
Map<String,Object> values=map("condition_type",added.type(),"predecessor_task_id",added.taskId(),"expected_status",added.expected());
|
||||
if(existing==null) { values.putAll(map("project_id",projectId,"iteration_id",iterationId,"successor_task_id",id,"created_by",access.actor(),"created_at",PmTime.now())); saved=dependencyMapper.insertDependency(values); }
|
||||
else dependencyMapper.updateDependency(dependencyId,existing.version(),values);
|
||||
}
|
||||
workItemMapper.updateWorkItem(id,successor.version(),map("title",successor.title()));
|
||||
auditService.record(projectId,iterationId,id,remove?"DEPENDENCY_REMOVED":"DEPENDENCY_SAVED",map("dependencyId",saved,"conditionType",input.conditionType()),access.actor()); return saved;
|
||||
}
|
||||
|
||||
/** 任务排期摘要返回完整性、最早时间和缺失的前置结束时间,与实际开始条件独立。 */
|
||||
public Map<String,Object> constraints(long id) {
|
||||
long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"read"); Graph graph=graphService.load(projectId,iterationId); return PmRules.schedule(graph,item(graph,id),zone(projectId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单项与批量排期共用最终图校验,合法的整批延后不会因中间顺序被拒绝。
|
||||
* @param projectId 已鉴权的项目 ID;不允许跨项目混合排期
|
||||
* @param changes 整批工作项版本与最终预计时间;任一冲突导致整批回滚
|
||||
*/
|
||||
public void schedule(long projectId,long iterationId,List<ScheduleInput> changes) {
|
||||
schedules.schedule(projectId,iterationId,new com.ruoyi.project.manage.dto.BatchInput(changes));
|
||||
}
|
||||
|
||||
/** 混合批量与单项时间修改共用一个事务入口,不按对象逐次提交。 */
|
||||
public void scheduleBatch(long projectId,long iterationId,com.ruoyi.project.manage.dto.BatchInput input) { schedules.schedule(projectId,iterationId,input); }
|
||||
|
||||
/** 查询前置任务直接影响的后续,仅包含当前有效任务依赖及排期约束。 */
|
||||
public List<Map<String,Object>> successors(long id) {
|
||||
long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"read"); Graph graph=graphService.load(projectId,iterationId); item(graph,id);
|
||||
Set<Long> targets=new LinkedHashSet<>();
|
||||
for(Dependency d:graph.dependencies()) if(Objects.equals(d.taskId(),id)) targets.add(d.successorId());
|
||||
String zone=zone(projectId);
|
||||
return targets.stream().map(graph.items()::get).filter(i->!i.deleted()).map(i->view(graph,i,zone)).toList();
|
||||
}
|
||||
|
||||
/** 评论在受限工作项事务内保存,不把客户端内容当作 HTML 执行。 */
|
||||
public void comment(long id,CommentInput input) {
|
||||
long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"write"); writableItem(graphService.load(projectId,iterationId),id);
|
||||
activityMapper.insertComment(map("work_item_id",id,"body",required(input.body(),10000,"评论"),"created_by",access.actor(),"created_at",PmTime.now())); auditService.record(projectId,iterationId,id,"COMMENT_ADDED",map("message","新增评论"),access.actor());
|
||||
}
|
||||
|
||||
/** 附件保存在受鉴权的模块数据库中,避免沿用可公开访问上传目录泄露文件;限制为 10 MiB。 */
|
||||
public long attach(long id,String name,String mediaType,byte[] content) {
|
||||
long projectId=projectOf(id),iterationId=iterationOf(id); locked(projectId,iterationId,"write"); writableItem(graphService.load(projectId,iterationId),id);
|
||||
if(content.length==0||content.length>10*1024*1024) throw PmException.bad("附件需为 1 字节至 10 MiB");
|
||||
String safeName=required(name==null?"附件":name.replace('\\','/').substring(name.replace('\\','/').lastIndexOf('/')+1),255,"附件名称");
|
||||
long saved=activityMapper.insertAttachment(map("work_item_id",id,"name",safeName,"media_type",mediaType==null?"application/octet-stream":required(mediaType,120,"文件类型"),"content",content,"size",content.length,"created_by",access.actor(),"created_at",PmTime.now()));
|
||||
auditService.record(projectId,iterationId,id,"ATTACHMENT_ADDED",map("name",safeName,"size",content.length),access.actor()); return saved;
|
||||
}
|
||||
|
||||
/** 每次下载重新校验工作项可见性,成员移除后旧附件 ID 不可继续下载。 */
|
||||
public Map<String,Object> attachment(long id) {
|
||||
Map<String,Object> file=activityMapper.selectAttachment(id); if(file==null) throw PmAccess.denied();
|
||||
long itemId=number(file,"work_item_id"),projectId=projectOf(itemId),iterationId=iterationOf(itemId); locked(projectId,iterationId,"read");
|
||||
Item current=graphService.load(projectId,iterationId).items().get(itemId);
|
||||
if((current==null||current.deleted())&&workItemMapper.selectHistoricalItem(projectId,itemId)==null) throw PmAccess.denied(); return file;
|
||||
}
|
||||
|
||||
/** 统计由当前用户可见的单项目快照计算,不通过全局统计泄露其它项目。 */
|
||||
public Map<String,Object> statistics(long projectId,long iterationId) {
|
||||
List<Map<String,Object>> items=items(projectId,iterationId);
|
||||
return map("total",items.size(),"completed",items.stream().filter(i->"COMPLETED".equals(i.get("status"))).count(),"closed",items.stream().filter(i->"CLOSED".equals(i.get("status"))).count(),"cancelled",items.stream().filter(i->"CANCELLED".equals(i.get("status"))).count(),"overdue",items.stream().filter(i->Boolean.TRUE.equals(i.get("overdue"))).count(),"inProgress",items.stream().filter(i->"IN_PROGRESS".equals(i.get("status"))).count(),"blocked",items.stream().filter(i->Boolean.TRUE.equals(i.get("dependencyBlocked"))).count(),"scheduleIncomplete",items.stream().filter(i->"INCOMPLETE".equals(((Map<?,?>)i.get("scheduleConstraints")).get("scheduleValidationStatus"))).count());
|
||||
}
|
||||
|
||||
/**
|
||||
* 按视图限定返回行;列表以父项为分页单位并补齐命中子项的父上下文,看板总数不受加载页影响。
|
||||
* @param query 白名单查询;甘特窗口只影响返回内容,所有约束仍以完整迭代图计算
|
||||
* @return 当前页、真实总数、各状态计数和当前图版本,不向其他迭代扩展候选
|
||||
*/
|
||||
public Map<String,Object> itemPage(long projectId,long iterationId,com.ruoyi.project.manage.dto.ItemQuery query) {
|
||||
int page=query.page()==null?1:query.page(),size=query.pageSize()==null?50:query.pageSize();
|
||||
if(page<1||size<1||size>200) throw PmException.bad("分页范围无效,每页最多 200 项");
|
||||
String mode=query.view()==null?"flat":query.view();
|
||||
if(!Set.of("list","flat","board","gantt").contains(mode)) throw PmException.bad("查询视图无效");
|
||||
if(query.type()!=null&&!query.type().isBlank()&&!Set.of("TASK","REQUIREMENT","BUG").contains(query.type())) throw PmException.bad("工作项类型无效");
|
||||
if(query.status()!=null&&!query.status().isBlank()&&!Set.of("READY","IN_PROGRESS","COMPLETED","CANCELLED","CLOSED").contains(query.status())) throw PmException.bad("工作项状态无效");
|
||||
Long from=PmTime.parse(query.from()),to=PmTime.parse(query.to());
|
||||
if(from!=null&&to!=null&&from>to) throw PmException.bad("时间窗口结束不能早于开始");
|
||||
List<Map<String,Object>> all=items(projectId,iterationId);
|
||||
String keyword=query.keyword()==null?"":query.keyword().trim().toLowerCase(Locale.ROOT);
|
||||
List<Map<String,Object>> filtered=all.stream().filter(row->
|
||||
(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"))))
|
||||
&&(!"gantt".equals(mode)||overlaps(row,from,to))).toList();
|
||||
Map<String,Object> counts=new LinkedHashMap<>();
|
||||
for(String state:List.of("READY","IN_PROGRESS","COMPLETED","CANCELLED","CLOSED")) counts.put(state,filtered.stream().filter(row->state.equals(row.get("status"))).count());
|
||||
List<Map<String,Object>> matched=filtered.stream().filter(row->query.status()==null||query.status().isBlank()||query.status().equals(row.get("status"))).toList();
|
||||
long offset=(long)(page-1)*size;
|
||||
List<Map<String,Object>> rows; long total;
|
||||
if("list".equals(mode)) {
|
||||
Set<Long> matchedIds=new HashSet<>(); LinkedHashSet<Long> roots=new LinkedHashSet<>();
|
||||
for(Map<String,Object> row:matched) { long id=number(row,"id"); matchedIds.add(id); Long parent=nullable(row,"parentTaskId"); roots.add(parent==null?id:parent); }
|
||||
List<Long> selected=roots.stream().skip(offset).limit(size).toList(); Set<Long> selectedSet=new HashSet<>(selected);
|
||||
rows=all.stream().filter(row->{ long id=number(row,"id"); Long parent=nullable(row,"parentTaskId"); return selectedSet.contains(id)||parent!=null&&selectedSet.contains(parent)&&(matchedIds.contains(id)||matchedIds.contains(parent)); }).toList();
|
||||
total=roots.size();
|
||||
} else { total=matched.size(); rows=matched.stream().skip(offset).limit(size).toList(); }
|
||||
return map("rows",rows,"total",total,"counts",counts,"graphVersion",number(revisionMapper.selectGraphVersion(projectId,iterationId),"graph_version"));
|
||||
}
|
||||
|
||||
/** 未排期项保留可见,已排期项按完整时间点与窗口交集判断,不截断时区或微秒。 */
|
||||
private static boolean overlaps(Map<String,Object> row,Long from,Long to) {
|
||||
Long start=PmTime.parse(text(row,"plannedStartAt")),end=PmTime.parse(text(row,"plannedEndAt"));
|
||||
return start==null||end==null||(from==null||end>=from)&&(to==null||start<=to);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消迭代时先构造整批最终图,再保存每项合法的取消转换。
|
||||
* @param expectedIds 预览明确确认的全部未结束项,不能遗漏、重复或附加其他迭代项
|
||||
* 注意:调用方还须在同一事务改变迭代状态;任一校验或审计失败会全部回滚。
|
||||
*/
|
||||
public void cancelRemaining(long projectId,long iterationId,List<Long> expectedIds) {
|
||||
locked(projectId,iterationId,"write");
|
||||
Graph before=graphService.load(projectId,iterationId),after=before.copy();
|
||||
List<Item> remaining=before.items().values().stream().filter(i->!i.deleted()&&!PmRules.terminal(i)).toList();
|
||||
Set<Long> actual=new HashSet<>(); for(Item item:remaining) actual.add(item.id());
|
||||
if(expectedIds==null||expectedIds.size()!=actual.size()||!actual.equals(new HashSet<>(expectedIds))) throw PmException.conflict("ITERATION_SCOPE_CHANGED","未结束工作项已变化,请重新预览");
|
||||
for(Item item:remaining) after.items().put(item.id(),item.transitioned("CANCELLED",false));
|
||||
PmRules.validateActual(after,zone(projectId)); PmStageRules.validateRegression(before,after);
|
||||
for(Item item:remaining) {
|
||||
workItemMapper.updateWorkItem(item.id(),item.version(),map("status","CANCELLED","actual_end_at",null));
|
||||
auditService.record(projectId,iterationId,item.id(),"STATUS_CHANGED",map("from",item.status(),"to","CANCELLED","reason","取消所属迭代"),access.actor());
|
||||
}
|
||||
for(Long stageId:before.stageNames().keySet()) syncStage(projectId,iterationId,stageId,PmStageRules.executionStatus(before,stageId));
|
||||
}
|
||||
|
||||
/** 通知展示再次过滤当前成员资格;异步发送后被撤权的用户不能查看原项目通知。 */
|
||||
public List<Map<String,Object>> notifications() {
|
||||
access.permission("read"); long user=access.actor();
|
||||
List<Map<String,Object>> result=eventMapper.selectNotifications(user,SecurityUtils.isAdmin());
|
||||
for(Map<String,Object> row:result) { row.put("createdAt",PmTime.format(nullable(row,"createdAt"),"Asia/Shanghai")); row.remove("timezone"); }
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 在已锁定快照上执行唯一开始实现;任务与阶段条件取当前状态,不等待预计开始时间。 */
|
||||
private void performStart(Graph graph,Item item,Integer requestedVersion,String zone) {
|
||||
if(graph.iteration()==null||!graph.iteration().active()) throw PmException.conflict("ITERATION_NOT_ACTIVE","迭代尚未开始或已结束,不能执行工作项");
|
||||
if(!"READY".equals(item.status())) throw PmException.conflict("INVALID_TASK_STATUS","只有待开始工作项可以开始");
|
||||
version(requestedVersion,item.version());
|
||||
List<Map<String,Object>> reasons=new ArrayList<>(PmRules.blocked(graph,item.id(),zone));
|
||||
reasons.addAll(PmStageRules.blocked(graph,item.id()));
|
||||
if(!reasons.isEmpty()) throw new PmException(409,"DEPENDENCY_NOT_SATISFIED","任务暂时无法开始",map("blockedReasons",reasons));
|
||||
workItemMapper.updateWorkItem(item.id(),item.version(),map("status","IN_PROGRESS","actual_start_at",PmTime.now(),"actual_end_at",null));
|
||||
auditService.record(item.projectId(),graph.iteration().id(),item.id(),"TASK_STARTED",map("from","READY","to","IN_PROGRESS"),access.actor());
|
||||
syncStage(item.projectId(),graph.iteration().id(),item.stageId(),PmStageRules.executionStatus(graph,item.stageId()==null?-1:item.stageId()));
|
||||
}
|
||||
|
||||
/** 可开始摘要同时考虑动作权限、生命周期与任务及阶段前置,前端不得替代此判断。 */
|
||||
private Map<String,Object> startability(Graph graph,Item item,String zone) {
|
||||
List<Map<String,Object>> reasons=new ArrayList<>();
|
||||
if(graph.iteration()==null||!graph.iteration().active()) reasons.add(map("code","ITERATION_NOT_ACTIVE","message","迭代尚未开始或已结束"));
|
||||
if(!access.permitted("write")) reasons.add(map("code","FORBIDDEN","message","没有工作项维护权限"));
|
||||
if(!"READY".equals(item.status())) reasons.add(map("code","INVALID_TASK_STATUS","message","当前不是待开始状态"));
|
||||
reasons.addAll(PmRules.blocked(graph,item.id(),zone));
|
||||
List<Map<String,Object>> stageReasons=PmStageRules.blocked(graph,item.id()); reasons.addAll(stageReasons);
|
||||
return map("canStart",reasons.isEmpty(),"blockedReasons",reasons,"stageBlockedReasons",stageReasons,"dependencyConditions",PmRules.conditions(graph,item.id(),zone));
|
||||
}
|
||||
|
||||
/** 返回组织阶段和北京时间 ISO 时间;阶段归属、生命周期、实际阻塞与排期校验分别表达。 */
|
||||
private Map<String,Object> view(Graph graph,Item item,String zone) {
|
||||
Map<String,Object> 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));
|
||||
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));
|
||||
Item parent=item.parentTaskId()==null?null:graph.items().get(item.parentTaskId());
|
||||
List<Item> children=PmRules.children(graph,item.id()); List<Map<String,Object>> unfinished=PmRules.unfinishedChildren(graph,item.id());
|
||||
boolean overdue=PmRules.overdue(item,PmTime.now());
|
||||
response.putAll(map("parentTaskId",item.parentTaskId(),"parentTaskTitle",parent==null?null:parent.title(),"parentPlannedStartAt",parent==null?null:PmTime.format(parent.start(),zone),"parentPlannedEndAt",parent==null?null:PmTime.format(parent.end(),zone),"childCount",children.size(),"childTerminalCount",children.stream().filter(PmRules::terminal).count(),"canCreateChild",access.permitted("write")&&"TASK".equals(item.type())&&item.parentTaskId()==null&&!PmRules.terminal(item),"canComplete",access.permitted("write")&&"IN_PROGRESS".equals(item.status())&&unfinished.isEmpty(),"completionBlockedReasons",unfinished,"overdue",overdue,"displayStatus",overdue?"OVERDUE":item.status()));
|
||||
response.put("stageId",item.stageId()); response.put("stageRevisionId",item.stageRevisionId()); response.put("stageRevisionNo",item.stageId()==null?null:graph.stageRevisions().get(item.stageId())==null?null:graph.stageRevisions().get(item.stageId()).revisionNo()); response.put("originWorkItemId",item.originWorkItemId()); response.put("scheduleReviewRequired",item.scheduleReviewReworkId()!=null); response.put("scheduleReviewClosed",item.scheduleReviewReworkId()!=null&&(!mutable||PmRules.completed(item)||item.stageId()!=null&&Set.of("COMPLETED","LEGACY_PASSED").contains(PmStageRules.executionStatus(graph,item.stageId())))); response.put("referencePlannedStartAt",PmTime.format(item.referenceStart(),zone)); response.put("referencePlannedEndAt",PmTime.format(item.referenceEnd(),zone));
|
||||
if(!mutable) { response.put("canCreateChild",false); response.put("canComplete",false); }
|
||||
response.putAll(startability(graph,item,zone)); response.put("dependencyBlocked",!PmRules.blocked(graph,item.id(),zone).isEmpty()||!PmStageRules.blocked(graph,item.id()).isEmpty()); response.put("scheduleConstraints",PmRules.schedule(graph,item,zone)); return response;
|
||||
}
|
||||
|
||||
/** 先鉴权再锁图,取得锁后重新验证成员资格,防止与撤权同时操作。 */
|
||||
private void locked(long projectId,String action) { access.project(projectId,action); workspaceMapper.lockProject(projectId); access.project(projectId,action); }
|
||||
|
||||
/**
|
||||
* 所有迭代写入口使用同一锁序;获取项目锁后重新校验迭代状态,防止结束或撤权与写入穿插。
|
||||
* 图版本在事务内推进,后续校验失败时随业务回滚;项目级成员事件不会推进任意迭代图。
|
||||
*/
|
||||
private void locked(long projectId,long iterationId,String action) {
|
||||
locked(projectId,action);
|
||||
iterationAccess.require(projectId,iterationId,action);
|
||||
if(!"read".equals(action)) revisionMapper.advanceGraphVersion(projectId,iterationId);
|
||||
}
|
||||
|
||||
/** 从当前图取有效阶段版本,未分配工作项保持空版本;项目锁防止切换与创建交错。 */
|
||||
private static Long currentRevision(Graph graph,Long stageId) {
|
||||
if(stageId==null) return null;
|
||||
var revision=graph.stageRevisions().get(stageId);
|
||||
if(revision==null) throw PmException.conflict("STAGE_REVISION_MISSING","阶段尚未建立当前执行版本");
|
||||
return revision.id();
|
||||
}
|
||||
|
||||
/** 已完成或迁移放行阶段不可增减和改写工作项,重做必须走经理回退入口。 */
|
||||
private static void requireStageMutable(Graph graph,Long stageId) {
|
||||
if(stageId==null) return;
|
||||
String status=PmStageRules.executionStatus(graph,stageId);
|
||||
if(Set.of("COMPLETED","LEGACY_PASSED").contains(status)) throw PmException.conflict("STAGE_REVISION_FROZEN","阶段已完成,需由项目经理创建回退版本后重做");
|
||||
}
|
||||
|
||||
/** 所有写入口识别旧版 ID 并拒绝,避免当前图过滤后把历史项误当作可写。 */
|
||||
private Item writableItem(Graph graph,long id) {
|
||||
Item current=graph.items().get(id);
|
||||
if(current==null) {
|
||||
Map<String,Object> reference=workItemMapper.selectRevisionReference(projectOf(id),id);
|
||||
if(reference!=null&&nullable(reference,"stage_revision_id")!=null&&!Objects.equals(nullable(reference,"stage_revision_id"),nullable(reference,"current_revision_id"))) throw PmException.conflict("HISTORICAL_WORK_ITEM","历史版本工作项只读");
|
||||
throw PmAccess.denied();
|
||||
}
|
||||
if(current.deleted()) throw PmAccess.denied();
|
||||
requireStageMutable(graph,current.stageId());
|
||||
return current;
|
||||
}
|
||||
|
||||
/** 工作项写入后从事务内新图推导阶段状态,并将转换时间、审计和 outbox 一并提交。 */
|
||||
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;
|
||||
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);
|
||||
if("IN_PROGRESS".equals(status)) {
|
||||
Map<String,Object> stage=stageMapper.selectActiveStage(stageId,projectId,iterationId);
|
||||
revisionMapper.refreshStartedIdentity(revision.id(),text(stage,"name"),nullable(stage,"owner_id"));
|
||||
Map<String,Object> latest=revisionMapper.selectLatestDefinition(projectId,iterationId);
|
||||
if(latest==null) {
|
||||
long definition=revisionMapper.insertDefinition(map("project_id",projectId,"iteration_id",iterationId,"revision_no",1,"graph_json",jsonCodec.encode(map("stages",stageMapper.selectVisibleStages(projectId,iterationId),"stageEdges",stageMapper.selectStageEdges(projectId,iterationId))),"created_by",access.actor(),"created_at",now));
|
||||
revisionMapper.bindStartedDefinition(revision.id(),definition);
|
||||
} 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());
|
||||
}
|
||||
|
||||
/** 仅取路由所需项目 ID,所有标题和业务内容在项目鉴权之后加载。 */
|
||||
public long projectOf(long id) { Map<String,Object> row=workItemMapper.selectProjectReference(id); if(row==null) throw PmAccess.denied(); return number(row,"project_id"); }
|
||||
|
||||
/** 数据库归属创建后不可变;这里只取路由 ID,实际内容仍须在项目锁内检查成员和迭代状态。 */
|
||||
public long iterationOf(long id) { Map<String,Object> row=workItemMapper.selectProjectReference(id); if(row==null||nullable(row,"iteration_id")==null) throw PmAccess.denied(); return number(row,"iteration_id"); }
|
||||
|
||||
/** 验证协作已启用并返回统一北京时间,不再从历史配置读取可变时区。 */
|
||||
private String zone(long projectId) { if(workspaceMapper.selectConfiguredProject(projectId)==null) throw PmException.bad("项目尚未启用协作管理"); return "Asia/Shanghai"; }
|
||||
|
||||
/** 模型对象限定在已鉴权项目快照,跨项目或软删除目标统一拒绝。 */
|
||||
private static Item item(Graph graph,long id) { Item item=graph.items().get(id); if(item==null||item.deleted()) throw PmAccess.denied(); return item; }
|
||||
|
||||
/** 历史轮次只读重建原工作项快照,不加入当前排期与实际开始图。 */
|
||||
private static Item historicalItem(long projectId,Map<String,Object> row) {
|
||||
return new Item(number(row,"id"),projectId,text(row,"type"),text(row,"title"),text(row,"description"),nullable(row,"assignee_id"),text(row,"priority"),text(row,"status"),nullable(row,"planned_start_at"),nullable(row,"planned_end_at"),nullable(row,"actual_start_at"),nullable(row,"actual_end_at"),(int)number(row,"version"),flag(row,"deleted"),nullable(row,"stage_id"),nullable(row,"parent_task_id"),nullable(row,"stage_revision_id"),nullable(row,"origin_work_item_id"),nullable(row,"schedule_review_rework_id"),nullable(row,"reference_planned_start_at"),nullable(row,"reference_planned_end_at"));
|
||||
}
|
||||
|
||||
/** 校验用户看到的版本,不把缺失版本当作覆盖最新数据的授权。 */
|
||||
private static void version(Integer requested,int actual) { if(requested==null) throw PmException.bad("数据版本不能为空"); if(requested!=actual) throw PmException.conflict("VERSION_CONFLICT","数据已被修改,请刷新后重试"); }
|
||||
|
||||
/** 校验普通字段、负责人及同项目有效阶段,软删除有效性由项目锁保护,时间由统一转换检查。 */
|
||||
private void validateFields(long projectId,long iterationId,ItemInput input) {
|
||||
required(input.title(),200,"标题"); if(input.type()==null||!Set.of("REQUIREMENT","TASK","BUG").contains(input.type())) throw PmException.bad("工作项类型无效");
|
||||
if(input.priority()!=null&&!Set.of("LOW","MEDIUM","HIGH","URGENT").contains(input.priority())) throw PmException.bad("优先级无效");
|
||||
if(input.description()!=null&&input.description().length()>50000) throw PmException.bad("描述过长"); access.assignee(projectId,input.assigneeId());
|
||||
if(input.stageId()!=null&&stageMapper.selectActiveStageId(input.stageId(),projectId,iterationId)==null) throw PmAccess.denied();
|
||||
}
|
||||
|
||||
/** 标题等文本拒绝空白和过长值,调用方使用返回的修剪值保存。 */
|
||||
private static String required(String value,int limit,String name) { if(value==null||value.isBlank()||value.trim().length()>limit) throw PmException.bad(name+"不能为空且不能超过 "+limit+" 个字符"); return value.trim(); }
|
||||
|
||||
/** 锁定有效空间;创建、移动、删除统一使用此锁,创建身份不存在管理员绕过。 */
|
||||
private Map<String,Object> lockSpace(Long spaceId,boolean ownerRequired) {
|
||||
if(spaceId==null) throw PmException.bad("空间不能为空");
|
||||
Map<String,Object> space=workspaceMapper.selectSpaceForUpdate(spaceId);
|
||||
if(space==null||ownerRequired&&number(space,"owner_id")!=access.actor()) throw PmAccess.denied(); return space;
|
||||
}
|
||||
|
||||
/** 项目关联沿用原空间所有者/系统管理员规则;此资格不能用于编辑或删除他人空间。 */
|
||||
private void associationSpace(Long id) { Map<String,Object> space=lockSpace(id,false); if(!SecurityUtils.isAdmin()&&number(space,"owner_id")!=access.actor()) throw PmAccess.denied(); }
|
||||
|
||||
/** 从独立协作配置读取不可转移的创建身份;不查询项目列表或按旧账号猜测创建人。 */
|
||||
private Map<String,Object> creatorProject(long id) {
|
||||
access.permission("admin"); return access.creatorProject(id);
|
||||
}
|
||||
|
||||
/** 移动前按空间 ID 排序加锁再获取项目锁,避免双向移动和空间删除形成反向锁序。 */
|
||||
private void lockProjectSpaces(Map<String,Object> project,Long target) {
|
||||
if(target==null) throw PmException.bad("空间不能为空"); Long original=nullable(project,"space_id");
|
||||
TreeSet<Long> ids=new TreeSet<>(); if(original!=null) ids.add(original); ids.add(target);
|
||||
for(Long id:ids) { if(id.equals(target)&&!id.equals(original)) associationSpace(id); else lockSpace(id,false); }
|
||||
}
|
||||
|
||||
/** 等待锁期间项目若已移动,拒绝过期操作,不能临时扩展锁集合破坏锁顺序。 */
|
||||
private void ensureSameSpace(Map<String,Object> before,Map<String,Object> after) {
|
||||
if(!Objects.equals(nullable(before,"space_id"),nullable(after,"space_id"))) throw PmException.conflict("VERSION_CONFLICT","项目所属空间已改变,请刷新后重试");
|
||||
}
|
||||
|
||||
/** 旧客户端可携带默认值,但不能配置其它时区;统一展示不更改数据库时间点。 */
|
||||
private void fixedZone(String requested) { if(requested!=null&&!"Asia/Shanghai".equals(requested)) throw PmException.bad("时间统一使用北京时间,不支持项目时区配置"); }
|
||||
|
||||
/** 配置和锁行原子建立,并保存稳定创建人外键;调用方须先锁定所属空间。 */
|
||||
private void configureNew(long projectId,long spaceId,Long creator) { workspaceMapper.insertConfig(projectId,spaceId,creator); workspaceMapper.ensureProjectLock(projectId); }
|
||||
|
||||
/** 将审计/评论的创建时间也转换为 ISO,避免接口混用 UTC 微秒数和带时区字符串。 */
|
||||
private static List<Map<String,Object>> auditTimes(List<Map<String,Object>> rows,String zone) { for(Map<String,Object> row:rows) row.put("createdAt",PmTime.format(nullable(row,"createdAt"),zone)); return rows; }
|
||||
}
|
||||
@ -0,0 +1,271 @@
|
||||
package com.ruoyi.project.manage.service.impl;
|
||||
|
||||
import com.ruoyi.project.manage.dto.FilterInput;
|
||||
import com.ruoyi.project.manage.dto.LayoutInput;
|
||||
import com.ruoyi.project.manage.dto.PositionInput;
|
||||
import com.ruoyi.project.manage.dto.StageAssignment;
|
||||
import com.ruoyi.project.manage.dto.StageEdgeInput;
|
||||
import com.ruoyi.project.manage.dto.StageInput;
|
||||
import com.ruoyi.project.manage.dto.VersionInput;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
import com.ruoyi.project.manage.domain.Graph;
|
||||
import com.ruoyi.project.manage.domain.StageLink;
|
||||
import com.ruoyi.project.manage.mapper.PmLayoutMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmRevisionMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmStageMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmWorkItemMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmWorkspaceMapper;
|
||||
import com.ruoyi.project.manage.security.PmAccess;
|
||||
import com.ruoyi.project.manage.security.PmIterationAccess;
|
||||
import com.ruoyi.project.manage.rule.PmRules;
|
||||
import com.ruoyi.project.manage.rule.PmStageRules;
|
||||
import com.ruoyi.project.manage.service.IPmService;
|
||||
import com.ruoyi.project.manage.service.IPmStageService;
|
||||
import com.ruoyi.project.manage.service.support.PmAuditService;
|
||||
import com.ruoyi.project.manage.service.support.PmGraphService;
|
||||
import com.ruoyi.project.manage.util.PmJson;
|
||||
import com.ruoyi.project.manage.util.PmTime;
|
||||
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
import java.util.*;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.*;
|
||||
|
||||
/** 阶段和显式执行边共享项目图锁;画布位置仍只是浏览器偏好。 */
|
||||
@Service
|
||||
@Transactional(isolation=Isolation.READ_COMMITTED,rollbackFor=Exception.class)
|
||||
public class PmStageServiceImpl implements IPmStageService {
|
||||
private final PmWorkspaceMapper workspaceMapper;
|
||||
private final PmWorkItemMapper workItemMapper;
|
||||
private final PmStageMapper stageMapper;
|
||||
private final PmLayoutMapper layoutMapper;
|
||||
private final PmRevisionMapper revisionMapper;
|
||||
private final com.ruoyi.project.manage.mapper.PmScheduleMapper schedules;
|
||||
private final PmGraphService graphService;
|
||||
private final PmAuditService auditService;
|
||||
private final PmJson jsonCodec;
|
||||
private final PmAccess access;
|
||||
private final PmIterationAccess iterationAccess;
|
||||
private final IPmService business;
|
||||
private final ObjectMapper json;
|
||||
|
||||
/** 注入对象 Mapper、统一权限和事务支持,不允许 Controller 直接持有存储或实现。 */
|
||||
public PmStageServiceImpl(PmWorkspaceMapper workspaceMapper,PmWorkItemMapper workItemMapper,PmStageMapper stageMapper,PmLayoutMapper layoutMapper,PmRevisionMapper revisionMapper,PmGraphService graphService,PmAuditService auditService,PmJson jsonCodec,PmAccess access,IPmService business,ObjectMapper json,PmIterationAccess iterationAccess,com.ruoyi.project.manage.mapper.PmScheduleMapper schedules) {
|
||||
this.schedules=schedules;
|
||||
this.iterationAccess=iterationAccess;
|
||||
this.workspaceMapper=workspaceMapper;
|
||||
this.workItemMapper=workItemMapper;
|
||||
this.stageMapper=stageMapper;
|
||||
this.layoutMapper=layoutMapper;
|
||||
this.revisionMapper=revisionMapper;
|
||||
this.graphService=graphService;
|
||||
this.auditService=auditService;
|
||||
this.jsonCodec=jsonCodec;
|
||||
this.access=access;
|
||||
this.business=business;
|
||||
this.json=json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在项目锁内计算阶段状态、当前阶段及回退能力,避免多个独立查询拼出过期门禁。
|
||||
* 回退能力同时考虑既有经理权限和迭代可写性;只读成员仍可看到当前阶段事实。
|
||||
* @param projectId 独立协作项目 ID,先完成成员鉴权再读取摘要
|
||||
* @param iterationId 阶段和版本所属迭代,不能跨迭代混合判断
|
||||
* @return 当前迭代的阶段与边摘要,工作项明细继续由抽屉分页读取
|
||||
*/
|
||||
public Map<String,Object> flowView(long projectId,long iterationId) {
|
||||
locked(projectId,iterationId,"read");
|
||||
List<Map<String,Object>> items=business.items(projectId,iterationId);
|
||||
List<Map<String,Object>> stages=stageRows(projectId,iterationId);
|
||||
Graph graph=graphService.load(projectId,iterationId);
|
||||
boolean canManage=graph.iteration()!=null&&graph.iteration().mutable();
|
||||
if(canManage) {
|
||||
// 复用完整项目管理鉴权;拥有菜单权限但不是本项目经理的成员也不能获得回退能力。
|
||||
try { access.project(projectId,"admin"); }
|
||||
catch(PmException error) { if(error.getHttpStatus()!=403) throw error; canManage=false; }
|
||||
}
|
||||
for(Map<String,Object> stage:stages) {
|
||||
long stageId=number(stage,"id"); stage.putAll(summary(items,stageId));
|
||||
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));
|
||||
stage.put("blockedReasons",PmStageRules.blockedStage(graph,stageId));
|
||||
List<Map<String,Object>> reworkBlocked=PmStageRules.reworkBlocked(graph,stageId);
|
||||
stage.put("isCurrent",PmStageRules.isCurrent(graph,stageId));
|
||||
stage.put("canRework",canManage&&reworkBlocked.isEmpty());
|
||||
stage.put("reworkBlockedReasons",reworkBlocked);
|
||||
}
|
||||
List<Map<String,Object>> stageEdges=graph.stageLinks().stream().map(link->{
|
||||
String status=PmStageRules.executionStatus(graph,link.predecessorStageId());
|
||||
return map("id",link.id(),"predecessorStageId",link.predecessorStageId(),"successorStageId",link.successorStageId(),"version",link.version(),"satisfied",Set.of("COMPLETED","LEGACY_PASSED").contains(status),"legacyPassed","LEGACY_PASSED".equals(status));
|
||||
}).toList();
|
||||
List<Map<String,Object>> reworkEdges=schedules.selectReworkEdges(projectId,iterationId);
|
||||
for(Map<String,Object> 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());
|
||||
}
|
||||
|
||||
/** 阶段经理维护入口;名称和展示顺序不隐式产生连线,执行顺序只由显式边决定。 */
|
||||
public long createStage(long projectId,long iterationId,StageInput input) {
|
||||
locked(projectId,iterationId,"admin"); validateStage(projectId,input);
|
||||
long id=stageMapper.insertStage(map("project_id",projectId,"iteration_id",iterationId,"name",input.name().trim(),"sort_order",input.sortOrder()==null?0:input.sortOrder(),
|
||||
"owner_id",input.ownerId(),"description",input.description(),"created_by",access.actor(),"created_at",PmTime.now()));
|
||||
long revision=revisionMapper.insertRevision(map("project_id",projectId,"iteration_id",iterationId,"stage_id",id,"revision_no",1,"rework_id",null,"previous_revision_id",null,"flow_definition_revision_id",null,"stage_name_snapshot",input.name().trim(),"stage_owner_snapshot",input.ownerId(),"created_by",access.actor(),"created_at",PmTime.now()));
|
||||
if(revisionMapper.initializeCurrentRevision(projectId,id,revision)!=1) throw PmException.conflict("VERSION_CONFLICT","阶段初始版本建立失败");
|
||||
snapshotDefinition(projectId,iterationId);
|
||||
auditService.record(projectId,iterationId,null,"STAGE_CREATED",map("stageId",id,"name",input.name().trim()),access.actor()); return id;
|
||||
}
|
||||
|
||||
/** 在统一项目锁下版本更新阶段元数据,不改变工作项状态、预计时间或有效依赖。 */
|
||||
public void editStage(long projectId,long iterationId,long id,StageInput input) {
|
||||
locked(projectId,iterationId,"admin"); Map<String,Object> 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);
|
||||
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<String,Object> existing=stage(projectId,iterationId,id); version(input.version(),(int)number(existing,"version"));
|
||||
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);
|
||||
PmStageRules.validateExecutedAncestors(before,after);
|
||||
stageMapper.deleteEdgesForStage(projectId,id);
|
||||
stageMapper.updateStage(id,(int)number(existing,"version"),map("deleted",true));
|
||||
snapshotDefinition(projectId,iterationId);
|
||||
auditService.record(projectId,iterationId,null,"STAGE_DELETED",map("stageId",id,"name",text(existing,"name")),access.actor());
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目管理者在共享图中建立阶段执行边;项目锁串行化两个并发加边请求,
|
||||
* 最终图同时检查阶段环、任务跨阶段死锁和已开始工作项的新阻塞。
|
||||
* @param projectId 独立协作项目 ID
|
||||
* @param input 当前项目内两个有效阶段 ID
|
||||
* @return 新阶段边 ID;失败时不写入历史或 outbox
|
||||
*/
|
||||
public long createEdge(long projectId,long iterationId,StageEdgeInput input) {
|
||||
locked(projectId,iterationId,"admin");
|
||||
if(input==null||input.predecessorStageId()==null||input.successorStageId()==null) throw PmException.bad("阶段连线两端不能为空");
|
||||
long source=input.predecessorStageId(),target=input.successorStageId();
|
||||
if(source==target) throw PmException.conflict("SELF_STAGE_EDGE","阶段不能连接自己");
|
||||
stage(projectId,iterationId,source); stage(projectId,iterationId,target);
|
||||
Graph before=graphService.load(projectId,iterationId),after=before.copy();
|
||||
if(before.stageLinks().stream().anyMatch(edge->edge.predecessorStageId()==source&&edge.successorStageId()==target)) throw PmException.conflict("DUPLICATE_STAGE_EDGE","阶段连线已存在");
|
||||
after.stageLinks().add(new StageLink(-1,projectId,source,target,0));
|
||||
PmRules.validateAcyclic(after); PmRules.validateSchedules(after,"Asia/Shanghai"); PmStageRules.validateRegression(before,after); PmStageRules.validateExecutedAncestors(before,after);
|
||||
long id=stageMapper.insertStageEdge(map("project_id",projectId,"iteration_id",iterationId,"predecessor_stage_id",source,"successor_stage_id",target,"created_by",access.actor(),"created_at",PmTime.now()));
|
||||
snapshotDefinition(projectId,iterationId);
|
||||
auditService.record(projectId,iterationId,null,"STAGE_EDGE_CREATED",map("edgeId",id,"predecessorStageId",source,"successorStageId",target),access.actor()); return id;
|
||||
}
|
||||
|
||||
/** 管理者按当前边版本断开阶段;移除约束不会令已开始任务新增阻塞。 */
|
||||
public void deleteEdge(long projectId,long iterationId,long edgeId,VersionInput input) {
|
||||
locked(projectId,iterationId,"admin");
|
||||
Graph before=graphService.load(projectId,iterationId),after=before.copy();
|
||||
StageLink edge=before.stageLinks().stream().filter(link->link.id()==edgeId).findFirst().orElseThrow(PmAccess::denied);
|
||||
version(input.version(),edge.version());
|
||||
after.stageLinks().remove(edge); PmStageRules.validateExecutedAncestors(before,after);
|
||||
if(stageMapper.deleteStageEdge(edgeId,projectId,edge.version())!=1) throw PmException.conflict("VERSION_CONFLICT","阶段连线已被修改,请刷新后重试");
|
||||
snapshotDefinition(projectId,iterationId);
|
||||
auditService.record(projectId,iterationId,null,"STAGE_EDGE_DELETED",map("edgeId",edgeId,"predecessorStageId",edge.predecessorStageId(),"successorStageId",edge.successorStageId()),access.actor());
|
||||
}
|
||||
|
||||
/** 阶段调整委托统一父子继承服务,父移动会原子同步全部有效子任务。 */
|
||||
public void assign(long id,StageAssignment input) {
|
||||
business.assignStage(id,input);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拒绝旧的数据库布局保存,迭代画布位置和折叠状态统一保存在当前浏览器。
|
||||
* @param scope 旧布局范围,不再参与业务
|
||||
* @return 不返回结果,始终提示选择迭代并使用浏览器布局
|
||||
*/
|
||||
public Map<String,Object> saveLayout(long projectId,String scope,LayoutInput input) { throw new PmException(400,"ITERATION_REQUIRED","请明确选择迭代,流程布局保存在当前浏览器",Map.of()); }
|
||||
|
||||
/** 读取阶段元数据和负责人昵称,时间统一为带偏移 ISO;调用方已取得项目锁并校验数据权限。 */
|
||||
private List<Map<String,Object>> stageRows(long projectId,long iterationId) {
|
||||
List<Map<String,Object>> rows=stageMapper.selectVisibleStages(projectId,iterationId);
|
||||
for(Map<String,Object> row:rows) row.put("createdAt",PmTime.format(nullable(row,"createdAt"),"Asia/Shanghai"));
|
||||
return rows;
|
||||
}
|
||||
|
||||
/** 按全部有效工作项汇总,不受画布筛选影响;取消不计入完成,时间覆盖单独返回。 */
|
||||
private Map<String,Object> summary(List<Map<String,Object>> items,Long stageId) {
|
||||
List<Map<String,Object>> group=items.stream().filter(i->Objects.equals(nullable(i,"stageId"),stageId)).toList();
|
||||
Map<String,Object> 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());
|
||||
counts.put("blocked",group.stream().filter(i->Boolean.TRUE.equals(i.get("dependencyBlocked"))).count());
|
||||
counts.put("scheduleIncomplete",group.stream().filter(i->!"VALID".equals(((Map<?,?>)i.get("scheduleConstraints")).get("scheduleValidationStatus"))).count());
|
||||
Long first=null,last=null; int fullyScheduled=0;
|
||||
for(Map<String,Object> item:group) {
|
||||
Long start=PmTime.parse(text(item,"plannedStartAt")),end=PmTime.parse(text(item,"plannedEndAt"));
|
||||
if(start!=null&&(first==null||start<first)) first=start;
|
||||
if(end!=null&&(last==null||end>last)) last=end;
|
||||
if(start!=null&&end!=null) fullyScheduled++;
|
||||
}
|
||||
return map("counts",counts,"plannedStartAt",PmTime.format(first,"Asia/Shanghai"),"plannedEndAt",PmTime.format(last,"Asia/Shanghai"),"fullyScheduled",fullyScheduled);
|
||||
}
|
||||
|
||||
/** 布局无记录时版本为零;JSON 仅来自经验证的展示 DTO,不能作为业务快照使用。 */
|
||||
private Map<String,Object> layout(long projectId,long owner) {
|
||||
Map<String,Object> row=layoutMapper.selectLayout(projectId,owner);
|
||||
if(row==null) return map("version",0,"positions",Map.of(),"collapsedStages",List.of(),"viewport",null,"filters",null,"updatedAt",null);
|
||||
try {
|
||||
Map<String,Object> value=json.readValue(text(row,"layout_json"),new TypeReference<LinkedHashMap<String,Object>>(){});
|
||||
value.put("version",(int)number(row,"version")); value.put("updatedAt",PmTime.format(nullable(row,"updated_at"),"Asia/Shanghai")); return value;
|
||||
} catch(Exception e) { throw new IllegalStateException("布局数据无法读取",e); }
|
||||
}
|
||||
|
||||
/** 校验阶段引用、负责人及大小限制;同项目软删除检查不能仅依赖物理外键。 */
|
||||
private void validateStage(long projectId,StageInput input) {
|
||||
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 之间");
|
||||
access.assignee(projectId,input.ownerId());
|
||||
}
|
||||
|
||||
/** 严格校验展示配置和同项目稳定 ID;允许历史已删除对象坐标由前端忽略,不允许跨项目引用。 */
|
||||
private void validateLayout(long projectId,LayoutInput input,boolean shared) {
|
||||
if(input.positions()==null||input.positions().size()>20000||input.collapsedStages()==null||input.collapsedStages().size()>2000) throw PmException.bad("布局结构或数量无效");
|
||||
Set<String> allowed=new HashSet<>(); allowed.add("s:0");
|
||||
for(Map<String,Object> r:workItemMapper.selectProjectItemIds(projectId)) allowed.add("w:"+number(r,"id"));
|
||||
Set<Long> stages=new HashSet<>(); stages.add(0L);
|
||||
for(Map<String,Object> r:stageMapper.selectProjectStageIds(projectId)) { stages.add(number(r,"id")); allowed.add("s:"+number(r,"id")); }
|
||||
for(Map.Entry<String,PositionInput> entry:input.positions().entrySet()) {
|
||||
if(!allowed.contains(entry.getKey())||entry.getValue()==null) throw PmException.bad("布局包含无效或跨项目节点");
|
||||
coordinate(entry.getValue().x()); coordinate(entry.getValue().y());
|
||||
}
|
||||
if(input.collapsedStages().stream().anyMatch(id->id==null||!stages.contains(id))||new HashSet<>(input.collapsedStages()).size()!=input.collapsedStages().size()) throw PmException.bad("折叠阶段无效或重复");
|
||||
if(shared&&(input.viewport()!=null||input.filters()!=null)) throw PmException.bad("共享布局仅包含位置和折叠,视口和筛选属于个人偏好");
|
||||
if(input.viewport()!=null) {
|
||||
coordinate(input.viewport().x()); coordinate(input.viewport().y()); Double zoom=input.viewport().zoom();
|
||||
if(zoom==null||!Double.isFinite(zoom)||zoom<0.1||zoom>4) throw PmException.bad("缩放比例无效");
|
||||
}
|
||||
FilterInput filter=input.filters(); if(filter!=null) {
|
||||
if(filter.keyword()!=null&&filter.keyword().length()>200) throw PmException.bad("筛选标题过长");
|
||||
if(filter.type()!=null&&!Set.of("TASK","REQUIREMENT","BUG").contains(filter.type())) throw PmException.bad("筛选类型无效");
|
||||
if(filter.status()!=null&&!Set.of("READY","IN_PROGRESS","COMPLETED","CANCELLED","CLOSED").contains(filter.status())) throw PmException.bad("筛选状态无效");
|
||||
access.assignee(projectId,filter.assigneeId());
|
||||
}
|
||||
}
|
||||
|
||||
/** 防止无穷值和异常巨大坐标导致浏览器画布不可用,允许正常负坐标平移。 */
|
||||
private static void coordinate(Double value) { if(value==null||!Double.isFinite(value)||Math.abs(value)>1_000_000) throw PmException.bad("画布坐标无效"); }
|
||||
/** 在已锁定项目中限定有效阶段,不向跨项目调用泄露名称。 */
|
||||
private Map<String,Object> stage(long projectId,long iterationId,long id) { Map<String,Object> row=stageMapper.selectActiveStage(id,projectId,iterationId); if(row==null) throw PmAccess.denied(); return row; }
|
||||
/** 项目锁覆盖权限重查、归属校验和历史/outbox;所有相关写入具有相同锁序。 */
|
||||
private void locked(long projectId,long iterationId,String action) { access.project(projectId,action); workspaceMapper.lockProject(projectId); access.project(projectId,action); iterationAccess.require(projectId,iterationId,action); if("admin".equals(action)) revisionMapper.advanceGraphVersion(projectId,iterationId); }
|
||||
/** 每次图定义变动记录阶段与边的只读快照,已启动轮次仍指向启动时的定义版本。 */
|
||||
private long snapshotDefinition(long projectId,long iterationId) {
|
||||
Map<String,Object> latest=revisionMapper.selectLatestDefinition(projectId,iterationId);
|
||||
return revisionMapper.insertDefinition(map("project_id",projectId,"iteration_id",iterationId,"revision_no",latest==null?1:number(latest,"revision_no")+1,
|
||||
"graph_json",jsonCodec.encode(map("stages",stageMapper.selectVisibleStages(projectId,iterationId),"stageEdges",stageMapper.selectStageEdges(projectId,iterationId))),"created_by",access.actor(),"created_at",PmTime.now()));
|
||||
}
|
||||
/** 请求缺失版本返回格式错误,过期版本返回冲突,不以最后写入覆盖。 */
|
||||
private static void version(Integer requested,int actual) { if(requested==null) throw PmException.bad("数据版本不能为空"); if(requested!=actual) throw PmException.conflict("VERSION_CONFLICT","数据已被修改,请刷新后重试"); }
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package com.ruoyi.project.manage.service.support;
|
||||
|
||||
import com.ruoyi.project.manage.mapper.PmActivityMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmEventMapper;
|
||||
import com.ruoyi.project.manage.util.PmJson;
|
||||
import com.ruoyi.project.manage.util.PmTime;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.*;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
/** 成功历史与 outbox 作为业务事务的一部分保存,异步发送仅由提交后的调度承担。 */
|
||||
@Service
|
||||
public class PmAuditService {
|
||||
private final PmActivityMapper activityMapper;
|
||||
private final PmEventMapper eventMapper;
|
||||
private final PmJson json;
|
||||
/** 注入两个独立数据访问对象,共享上层事务连接。 */
|
||||
public PmAuditService(PmActivityMapper activityMapper,PmEventMapper eventMapper,PmJson json) { this.activityMapper=activityMapper; this.eventMapper=eventMapper; this.json=json; }
|
||||
/**
|
||||
* 在已有业务事务中原子保存成功历史和待发送事件;不创建独立事务。
|
||||
* @param projectId 已锁定的独立协作项目
|
||||
* @param itemId 工作项 ID,项目级操作可以为空
|
||||
* @param action 已执行成功的动作类型
|
||||
* @param detail 服务构造的安全审计内容
|
||||
* @param actor 当前认证操作人,不接受客户端身份
|
||||
* <p>无事务时立即拒绝;任一写入失败使整个业务回滚,不能产生半条成功记录。</p>
|
||||
*/
|
||||
@Transactional(propagation=Propagation.MANDATORY,rollbackFor=Exception.class)
|
||||
public void record(long projectId,Long itemId,String action,Object detail,long actor) {
|
||||
record(projectId,null,itemId,action,detail,actor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在调用者持有的项目锁事务中保存迭代归属,项目级事件明确传空迭代。
|
||||
* @param iterationId 工作项或阶段所属迭代,不接受客户端伪造归属
|
||||
* @param itemId 工作项 ID;阶段和迭代动作可以为空
|
||||
* 注意:历史和待发送事件必须同事务,任何失败都会回滚业务写入。
|
||||
*/
|
||||
@Transactional(propagation=Propagation.MANDATORY,rollbackFor=Exception.class)
|
||||
public void record(long projectId,Long iterationId,Long itemId,String action,Object detail,long actor) {
|
||||
long now=PmTime.now(); String payload=json.encode(detail);
|
||||
activityMapper.insertHistory(map("project_id",projectId,"iteration_id",iterationId,"work_item_id",itemId,"action",action,"detail",payload,"created_by",actor,"created_at",now));
|
||||
eventMapper.insertEvent(map("project_id",projectId,"iteration_id",iterationId,"work_item_id",itemId,"event_type",action,"payload",payload,"next_attempt_at",now,"created_at",now));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package com.ruoyi.project.manage.service.support;
|
||||
|
||||
import com.ruoyi.project.manage.domain.Dependency;
|
||||
import com.ruoyi.project.manage.domain.Graph;
|
||||
import com.ruoyi.project.manage.domain.Item;
|
||||
import com.ruoyi.project.manage.domain.StageLink;
|
||||
import com.ruoyi.project.manage.domain.StageRevision;
|
||||
import com.ruoyi.project.manage.domain.IterationScope;
|
||||
import com.ruoyi.project.manage.mapper.PmDependencyMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmStageMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmWorkItemMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmRevisionMapper;
|
||||
import com.ruoyi.project.manage.mapper.PmIterationMapper;
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
|
||||
import java.util.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import static com.ruoyi.project.manage.util.PmValues.*;
|
||||
|
||||
/** 通过对象 Mapper 组装事务内任务与阶段图,执行和排期校验共享同一快照模型。 */
|
||||
@Component
|
||||
public class PmGraphService {
|
||||
private final PmWorkItemMapper workItemMapper;
|
||||
private final PmDependencyMapper dependencyMapper;
|
||||
private final PmStageMapper stageMapper;
|
||||
private final PmRevisionMapper revisionMapper;
|
||||
private final PmIterationMapper iterationMapper;
|
||||
/** 注入只负责数据库访问的 Mapper,不在加载过程中触发业务写入。 */
|
||||
public PmGraphService(PmWorkItemMapper workItemMapper,PmDependencyMapper dependencyMapper,PmStageMapper stageMapper,PmRevisionMapper revisionMapper,PmIterationMapper iterationMapper) { this.workItemMapper=workItemMapper; this.dependencyMapper=dependencyMapper; this.stageMapper=stageMapper; this.revisionMapper=revisionMapper; this.iterationMapper=iterationMapper; }
|
||||
/** 旧项目图入口拒绝隐式选取迭代,内部调用也不能意外加载多个迭代的任务。 */
|
||||
public Graph load(long projectId) { throw new PmException(400,"ITERATION_REQUIRED","请明确选择迭代",Map.of()); }
|
||||
/**
|
||||
* 在已鉴权、持项目锁事务中加载单个迭代的完整最终态校验图。
|
||||
* 所有查询都绑定迭代,分页或甘特可见窗口不能削减业务校验范围。
|
||||
* @param projectId 所属协作项目
|
||||
* @param iterationId 明确的迭代 ID;不接受其他项目迭代
|
||||
* @return 带数据库迭代状态的任务、父子、依赖和阶段快照,不缓存门禁结果
|
||||
*/
|
||||
public Graph load(long projectId,long iterationId) {
|
||||
Map<String,Object> iteration=iterationMapper.selectIteration(projectId,iterationId);
|
||||
if(iteration==null) throw com.ruoyi.project.manage.security.PmAccess.denied();
|
||||
Map<Long,Item> items=new LinkedHashMap<>();
|
||||
for(Map<String,Object> r:workItemMapper.selectGraphItems(projectId,iterationId)) {
|
||||
Item item=new Item(number(r,"id"),projectId,text(r,"type"),text(r,"title"),text(r,"description"),nullable(r,"assignee_id"),text(r,"priority"),text(r,"status"),nullable(r,"planned_start_at"),nullable(r,"planned_end_at"),nullable(r,"actual_start_at"),nullable(r,"actual_end_at"),(int)number(r,"version"),flag(r,"deleted"),nullable(r,"stage_id"),nullable(r,"parent_task_id"),nullable(r,"stage_revision_id"),nullable(r,"origin_work_item_id"),nullable(r,"schedule_review_rework_id"),nullable(r,"reference_planned_start_at"),nullable(r,"reference_planned_end_at")); items.put(item.id(),item);
|
||||
}
|
||||
// 独立存储只允许任务条件;唯一图入口仍显式限定类型,保证所有校验使用同一条件集合。
|
||||
List<Dependency> dependencies=new ArrayList<>();
|
||||
for(Map<String,Object> 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<Long,String> names=new LinkedHashMap<>();
|
||||
for(Map<String,Object> row:stageMapper.selectVisibleStages(projectId,iterationId)) names.put(number(row,"id"),text(row,"name"));
|
||||
List<StageLink> links=new ArrayList<>();
|
||||
for(Map<String,Object> 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<Long,StageRevision> revisions=new LinkedHashMap<>();
|
||||
for(Map<String,Object> row:revisionMapper.selectCurrentRevisions(projectId,iterationId)) {
|
||||
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));
|
||||
}
|
||||
/** 当前与历史版本使用相同字段解码,但历史不会被加入当前依赖图。 */
|
||||
public static StageRevision revision(Map<String,Object> 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")); }
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.ruoyi.project.manage.util;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/** 序列化内部白名单审计或展示对象,不接收数据库表名或 SQL。 */
|
||||
@Component
|
||||
public class PmJson {
|
||||
private final ObjectMapper json;
|
||||
/** 复用应用 JSON 配置,确保审计与 API 对象编码一致。 */
|
||||
public PmJson(ObjectMapper json) { this.json=json; }
|
||||
/** 编码失败须使业务事务失败,避免业务成功但审计内容无法保存。 */
|
||||
public String encode(Object value) { try { return json.writeValueAsString(value); } catch(Exception e) { throw new IllegalStateException("无法记录项目审计信息",e); } }
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
package com.ruoyi.project.manage.util;
|
||||
|
||||
import com.ruoyi.project.manage.exception.PmException;
|
||||
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Objects;
|
||||
|
||||
/** 所有新模块时间按 UTC 微秒保存,接口显式使用 offset,避免旧全局日期格式影响比较。 */
|
||||
public final class PmTime {
|
||||
private static final ZoneId PLANNING_ZONE = ZoneId.of("Asia/Shanghai");
|
||||
|
||||
/** 已解析的预计起止时间;仍以 UTC 微秒交给现有排期图校验,空端点表示未排期。 */
|
||||
public record Plan(Long start, Long end) { }
|
||||
|
||||
/** 工具类不能实例化,时间转换不持有可变时区状态。 */
|
||||
private PmTime() { }
|
||||
|
||||
/** 将带时区 ISO 时间转换为微秒;空值表示未排期,超出精度明确拒绝而不是截断。 */
|
||||
public static Long parse(String value) {
|
||||
if (value == null || value.isBlank()) return null;
|
||||
try {
|
||||
Instant instant = OffsetDateTime.parse(value).toInstant();
|
||||
if (instant.getNano() % 1000 != 0) throw PmException.bad("时间最多支持六位小数,不允许隐式截断");
|
||||
return Math.addExact(Math.multiplyExact(instant.getEpochSecond(), 1_000_000L), instant.getNano() / 1000);
|
||||
} catch (DateTimeParseException | ArithmeticException e) { throw PmException.bad("时间必须为带时区的 ISO 8601 时间"); }
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建或显式改期统一覆盖北京时间整日,避免接口绕过日期控件保存半日排期。
|
||||
* @param start 带时区的开始时间,取其北京时间日期的 00:00:00
|
||||
* @param end 带时区的结束时间,取其北京时间日期的 23:59:59
|
||||
* @return 保留空端点的整日计划;调用方继续校验依赖、阶段及父子范围
|
||||
*/
|
||||
public static Plan planned(String start, String end) {
|
||||
return new Plan(dayBoundary(parse(start), false), dayBoundary(parse(end), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通信息编辑仅在任一预计时间点变化时转换整对日期,保护既有小时和微秒排期。
|
||||
* @param start 请求开始时间;等价的 ISO 时区表达不会触发改期
|
||||
* @param end 请求结束时间
|
||||
* @param previousStart 数据库原开始时间
|
||||
* @param previousEnd 数据库原结束时间
|
||||
* @return 未变更时原样返回旧时间,否则返回整日计划;不修改历史记录
|
||||
*/
|
||||
public static Plan editedPlan(String start, String end, Long previousStart, Long previousEnd) {
|
||||
Long parsedStart = parse(start), parsedEnd = parse(end);
|
||||
if (Objects.equals(parsedStart, previousStart) && Objects.equals(parsedEnd, previousEnd))
|
||||
return new Plan(previousStart, previousEnd);
|
||||
return new Plan(dayBoundary(parsedStart, false), dayBoundary(parsedEnd, true));
|
||||
}
|
||||
|
||||
/** 根据时间点在北京时间所属的日期取边界;实际时间及查询结果不得调用此方法做截断。 */
|
||||
private static Long dayBoundary(Long micros, boolean end) {
|
||||
if (micros == null) return null;
|
||||
LocalDate date = Instant.ofEpochSecond(Math.floorDiv(micros, 1_000_000), Math.floorMod(micros, 1_000_000) * 1000)
|
||||
.atZone(PLANNING_ZONE).toLocalDate();
|
||||
return Math.multiplyExact(date.atTime(end ? LocalTime.of(23, 59, 59) : LocalTime.MIDNIGHT)
|
||||
.atZone(PLANNING_ZONE).toEpochSecond(), 1_000_000L);
|
||||
}
|
||||
|
||||
/** 将数据库微秒原样表达为项目时区的 ISO 时间,不损失精度;空值仍为空。 */
|
||||
public static String format(Long micros, String zone) {
|
||||
if (micros == null) return null;
|
||||
return Instant.ofEpochSecond(Math.floorDiv(micros, 1_000_000), Math.floorMod(micros, 1_000_000) * 1000)
|
||||
.atZone(ZoneId.of(zone)).toOffsetDateTime().toString();
|
||||
}
|
||||
|
||||
/** 取得事件记录时间,使用统一的微秒单位。 */
|
||||
public static long now() { Instant i = Instant.now(); return i.getEpochSecond() * 1_000_000 + i.getNano() / 1000; }
|
||||
|
||||
/** 校验可展示的 IANA 时区;默认值由项目配置承担,不替换非法输入。 */
|
||||
public static String zone(String value) {
|
||||
try { return ZoneId.of(value).getId(); }
|
||||
catch (RuntimeException e) { throw PmException.bad("项目时区无效"); }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.ruoyi.project.manage.util;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/** 保留空值的响应构造和 JDBC 行值转换,避免把缺失排期误当零或文本 null。 */
|
||||
public final class PmValues {
|
||||
/** 仅提供无状态转换方法,禁止实例化。 */
|
||||
private PmValues() { }
|
||||
/** 构造可包含 null 的有序响应,避免 Map.of 在未排期对象上抛出异常。 */
|
||||
public static Map<String,Object> map(Object... pairs) {
|
||||
Map<String,Object> result = new LinkedHashMap<>();
|
||||
for (int i=0;i<pairs.length;i+=2) result.put((String)pairs[i],pairs[i+1]);
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 只读数值字段,允许 JDBC 行和泛型 JSON 快照;缺失值仍视为结构错误而不是零。 */
|
||||
public static long number(Map<?,?> row,String key) { return ((Number)row.get(key)).longValue(); }
|
||||
/** 只读可空时间或引用,保留原数值转换规则,不将缺失值替换成零。 */
|
||||
public static Long nullable(Map<?,?> row,String key) { return row.get(key)==null?null:((Number)row.get(key)).longValue(); }
|
||||
/** 只读文本并保留空值,泛型参数不要求调用方对 JSON 快照进行未检查转换。 */
|
||||
public static String text(Map<?,?> row,String key) { return row.get(key)==null?null:String.valueOf(row.get(key)); }
|
||||
/** 只读布尔字段,兼容 JDBC 的 Boolean 或整数表示,不改变原真假值规则。 */
|
||||
public static boolean flag(Map<?,?> row,String key) { Object v=row.get(key); return Boolean.TRUE.equals(v)||v instanceof Number n&&n.intValue()!=0; }
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!-- SQL 由应用数据源执行;未在 IDEA 关联数据源时,仅豁免这一环境提示,保留 SQL 语法检查。 -->
|
||||
<!--suppress SqlNoDataSourceInspection -->
|
||||
<mapper namespace="com.ruoyi.project.manage.mapper.PmActivityMapper">
|
||||
<select id="selectComments" resultType="java.util.LinkedHashMap">
|
||||
SELECT c.id,c.body,c.created_by AS createdBy,u.nick_name AS author,c.created_at AS createdAt FROM pm_collab_comment c LEFT JOIN sys_user u ON u.user_id=c.created_by WHERE c.work_item_id=#{itemId} ORDER BY c.id
|
||||
</select>
|
||||
|
||||
<select id="selectAttachments" resultType="java.util.LinkedHashMap">
|
||||
SELECT id,name,size,created_by AS createdBy FROM pm_collab_attachment WHERE work_item_id=#{itemId} ORDER BY id
|
||||
</select>
|
||||
|
||||
<select id="selectHistory" resultType="java.util.LinkedHashMap">
|
||||
SELECT id,action,detail,created_by AS createdBy,created_at AS createdAt FROM pm_collab_history WHERE work_item_id=#{itemId} ORDER BY id DESC LIMIT 200
|
||||
</select>
|
||||
|
||||
<select id="selectAttachment" resultType="java.util.LinkedHashMap">
|
||||
SELECT * FROM pm_collab_attachment WHERE id=#{attachmentId}
|
||||
</select>
|
||||
|
||||
<insert id="insertCommentRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_comment
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('work_item_id')">work_item_id,</if>
|
||||
<if test="values.containsKey('body')">body,</if>
|
||||
<if test="values.containsKey('created_by')">created_by,</if>
|
||||
<if test="values.containsKey('created_at')">created_at,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('work_item_id')">#{values.work_item_id},</if>
|
||||
<if test="values.containsKey('body')">#{values.body},</if>
|
||||
<if test="values.containsKey('created_by')">#{values.created_by},</if>
|
||||
<if test="values.containsKey('created_at')">#{values.created_at},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<insert id="insertAttachmentRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_attachment
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('work_item_id')">work_item_id,</if>
|
||||
<if test="values.containsKey('name')">name,</if>
|
||||
<if test="values.containsKey('media_type')">media_type,</if>
|
||||
<if test="values.containsKey('content')">content,</if>
|
||||
<if test="values.containsKey('size')">size,</if>
|
||||
<if test="values.containsKey('created_by')">created_by,</if>
|
||||
<if test="values.containsKey('created_at')">created_at,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('work_item_id')">#{values.work_item_id},</if>
|
||||
<if test="values.containsKey('name')">#{values.name},</if>
|
||||
<if test="values.containsKey('media_type')">#{values.media_type},</if>
|
||||
<if test="values.containsKey('content')">#{values.content},</if>
|
||||
<if test="values.containsKey('size')">#{values.size},</if>
|
||||
<if test="values.containsKey('created_by')">#{values.created_by},</if>
|
||||
<if test="values.containsKey('created_at')">#{values.created_at},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<insert id="insertHistoryRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_history
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">project_id,</if>
|
||||
<if test="values.containsKey('iteration_id')">iteration_id,</if>
|
||||
<if test="values.containsKey('work_item_id')">work_item_id,</if>
|
||||
<if test="values.containsKey('action')">action,</if>
|
||||
<if test="values.containsKey('detail')">detail,</if>
|
||||
<if test="values.containsKey('created_by')">created_by,</if>
|
||||
<if test="values.containsKey('created_at')">created_at,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">#{values.project_id},</if>
|
||||
<if test="values.containsKey('iteration_id')">#{values.iteration_id},</if>
|
||||
<if test="values.containsKey('work_item_id')">#{values.work_item_id},</if>
|
||||
<if test="values.containsKey('action')">#{values.action},</if>
|
||||
<if test="values.containsKey('detail')">#{values.detail},</if>
|
||||
<if test="values.containsKey('created_by')">#{values.created_by},</if>
|
||||
<if test="values.containsKey('created_at')">#{values.created_at},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!-- SQL 由应用数据源执行;未在 IDEA 关联数据源时,仅豁免这一环境提示,保留 SQL 语法检查。 -->
|
||||
<!--suppress SqlNoDataSourceInspection -->
|
||||
<mapper namespace="com.ruoyi.project.manage.mapper.PmDependencyMapper">
|
||||
<update id="deleteDependency">
|
||||
DELETE FROM pm_collab_dependency_condition WHERE id=#{dependencyId}
|
||||
</update>
|
||||
|
||||
<insert id="insertDependencyRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_dependency_condition
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">project_id,</if>
|
||||
<if test="values.containsKey('iteration_id')">iteration_id,</if>
|
||||
<if test="values.containsKey('successor_task_id')">successor_task_id,</if>
|
||||
<if test="values.containsKey('condition_type')">condition_type,</if>
|
||||
<if test="values.containsKey('predecessor_task_id')">predecessor_task_id,</if>
|
||||
<if test="values.containsKey('expected_status')">expected_status,</if>
|
||||
<if test="values.containsKey('created_by')">created_by,</if>
|
||||
<if test="values.containsKey('created_at')">created_at,</if>
|
||||
<if test="values.containsKey('version')">version,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">#{values.project_id},</if>
|
||||
<if test="values.containsKey('iteration_id')">#{values.iteration_id},</if>
|
||||
<if test="values.containsKey('successor_task_id')">#{values.successor_task_id},</if>
|
||||
<if test="values.containsKey('condition_type')">#{values.condition_type},</if>
|
||||
<if test="values.containsKey('predecessor_task_id')">#{values.predecessor_task_id},</if>
|
||||
<if test="values.containsKey('expected_status')">#{values.expected_status},</if>
|
||||
<if test="values.containsKey('created_by')">#{values.created_by},</if>
|
||||
<if test="values.containsKey('created_at')">#{values.created_at},</if>
|
||||
<if test="values.containsKey('version')">#{values.version},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateDependencyRow">
|
||||
UPDATE pm_collab_dependency_condition
|
||||
<set>
|
||||
<if test="values.containsKey('project_id')">project_id=#{values.project_id},</if>
|
||||
<if test="values.containsKey('successor_task_id')">successor_task_id=#{values.successor_task_id},</if>
|
||||
<if test="values.containsKey('condition_type')">condition_type=#{values.condition_type},</if>
|
||||
<if test="values.containsKey('predecessor_task_id')">predecessor_task_id=#{values.predecessor_task_id},</if>
|
||||
<if test="values.containsKey('expected_status')">expected_status=#{values.expected_status},</if>
|
||||
<if test="values.containsKey('created_by')">created_by=#{values.created_by},</if>
|
||||
<if test="values.containsKey('created_at')">created_at=#{values.created_at},</if>
|
||||
version=version+1
|
||||
</set>
|
||||
WHERE id=#{id} AND version=#{version}
|
||||
</update>
|
||||
|
||||
<select id="selectGraphDependencies" resultType="java.util.LinkedHashMap">
|
||||
SELECT d.* FROM pm_collab_dependency_condition d
|
||||
JOIN pm_collab_work_item successor ON successor.id=d.successor_task_id
|
||||
LEFT JOIN pm_collab_project_stage ss ON ss.project_id=successor.project_id AND ss.id=successor.stage_id
|
||||
WHERE d.project_id=#{projectId} AND d.iteration_id=#{iterationId} AND d.condition_type='TASK_COMPLETED'
|
||||
AND (successor.stage_id IS NULL OR successor.stage_revision_id=ss.current_revision_id)
|
||||
ORDER BY d.id
|
||||
</select>
|
||||
|
||||
<select id="selectItemDependencies" resultType="java.util.LinkedHashMap">
|
||||
SELECT d.id,d.version,d.predecessor_task_id,d.expected_status,p.title AS source_name,p.status AS source_status,p.planned_end_at,p.deleted AS source_deleted
|
||||
FROM pm_collab_dependency_condition d JOIN pm_collab_work_item p ON p.id=d.predecessor_task_id AND p.project_id=d.project_id
|
||||
WHERE d.project_id=#{projectId} AND d.successor_task_id=#{itemId} ORDER BY d.id
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!-- SQL 由应用数据源执行;未在 IDEA 关联数据源时,仅豁免这一环境提示,保留 SQL 语法检查。 -->
|
||||
<!--suppress SqlNoDataSourceInspection -->
|
||||
<mapper namespace="com.ruoyi.project.manage.mapper.PmEventMapper">
|
||||
<select id="selectNotifications" resultType="java.util.LinkedHashMap">
|
||||
SELECT n.id,n.project_id AS projectId,n.iteration_id AS iterationId,n.work_item_id AS workItemId,n.message,n.created_at AS createdAt,c.timezone FROM pm_collab_notification n JOIN pm_collab_project p ON p.id=n.project_id JOIN pm_collab_project_config c ON c.project_id=p.id WHERE n.user_id=#{userId} AND p.del_flag='0' AND (n.iteration_id IS NULL OR EXISTS(SELECT 1 FROM pm_collab_iteration i WHERE i.id=n.iteration_id AND i.project_id=n.project_id AND i.deleted=false)) AND (#{administrator} OR p.manager_id=#{userId} OR EXISTS(SELECT 1 FROM pm_collab_project_member m WHERE m.project_id=p.id AND m.user_id=#{userId})) ORDER BY n.id DESC LIMIT 100
|
||||
</select>
|
||||
|
||||
<select id="selectPendingEvents" resultType="java.util.LinkedHashMap">
|
||||
SELECT id FROM pm_collab_outbox WHERE delivered_at IS NULL AND next_attempt_at<=#{now} ORDER BY id LIMIT 50
|
||||
</select>
|
||||
|
||||
<update id="scheduleRetry">
|
||||
UPDATE pm_collab_outbox SET attempts=attempts+1,next_attempt_at=#{now} + LEAST(3600,POW(2,LEAST(attempts+1,12))) * 1000000 WHERE id=#{eventId} AND delivered_at IS NULL
|
||||
</update>
|
||||
|
||||
<select id="selectEventProject" resultType="java.util.LinkedHashMap">
|
||||
SELECT project_id FROM pm_collab_outbox WHERE id=#{eventId} AND delivered_at IS NULL
|
||||
</select>
|
||||
|
||||
<select id="selectEventForUpdate" resultType="java.util.LinkedHashMap">
|
||||
SELECT * FROM pm_collab_outbox WHERE id=#{eventId} AND delivered_at IS NULL FOR UPDATE SKIP LOCKED
|
||||
</select>
|
||||
|
||||
<update id="insertRecipientNotifications">
|
||||
INSERT IGNORE INTO pm_collab_notification(event_id,user_id,project_id,iteration_id,work_item_id,message,created_at) SELECT #{eventId},u.user_id,#{projectId},(SELECT iteration_id FROM pm_collab_outbox WHERE id=#{eventId}),#{itemId},#{message},#{createdAt} FROM sys_user u JOIN pm_collab_project p ON p.id=#{projectId} WHERE u.status='0' AND u.del_flag='0' AND p.del_flag='0' AND (u.user_id=1 OR u.user_id=p.manager_id OR EXISTS(SELECT 1 FROM pm_collab_project_member m WHERE m.project_id=p.id AND m.user_id=u.user_id))
|
||||
</update>
|
||||
|
||||
<update id="markDelivered">
|
||||
UPDATE pm_collab_outbox SET delivered_at=#{deliveredAt} WHERE id=#{eventId}
|
||||
</update>
|
||||
|
||||
<insert id="insertEventRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_outbox
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">project_id,</if>
|
||||
<if test="values.containsKey('iteration_id')">iteration_id,</if>
|
||||
<if test="values.containsKey('work_item_id')">work_item_id,</if>
|
||||
<if test="values.containsKey('event_type')">event_type,</if>
|
||||
<if test="values.containsKey('payload')">payload,</if>
|
||||
<if test="values.containsKey('attempts')">attempts,</if>
|
||||
<if test="values.containsKey('next_attempt_at')">next_attempt_at,</if>
|
||||
<if test="values.containsKey('delivered_at')">delivered_at,</if>
|
||||
<if test="values.containsKey('created_at')">created_at,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">#{values.project_id},</if>
|
||||
<if test="values.containsKey('iteration_id')">#{values.iteration_id},</if>
|
||||
<if test="values.containsKey('work_item_id')">#{values.work_item_id},</if>
|
||||
<if test="values.containsKey('event_type')">#{values.event_type},</if>
|
||||
<if test="values.containsKey('payload')">#{values.payload},</if>
|
||||
<if test="values.containsKey('attempts')">#{values.attempts},</if>
|
||||
<if test="values.containsKey('next_attempt_at')">#{values.next_attempt_at},</if>
|
||||
<if test="values.containsKey('delivered_at')">#{values.delivered_at},</if>
|
||||
<if test="values.containsKey('created_at')">#{values.created_at},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!-- SQL 由应用数据源执行;未在 IDEA 关联数据源时,仅豁免这一环境提示,保留 SQL 语法检查。 -->
|
||||
<!--suppress SqlNoDataSourceInspection -->
|
||||
<mapper namespace="com.ruoyi.project.manage.mapper.PmIterationMapper">
|
||||
<select id="selectIteration" resultType="java.util.LinkedHashMap">
|
||||
SELECT i.*,u.nick_name AS creator_name FROM pm_collab_iteration i LEFT JOIN sys_user u ON u.user_id=i.created_by
|
||||
WHERE i.project_id=#{projectId} AND i.id=#{iterationId} AND i.deleted=false
|
||||
</select>
|
||||
<select id="selectIterations" resultType="java.util.LinkedHashMap">
|
||||
SELECT i.*,u.nick_name AS creator_name FROM pm_collab_iteration i LEFT JOIN sys_user u ON u.user_id=i.created_by
|
||||
WHERE i.project_id=#{projectId} AND i.deleted=false
|
||||
<if test="!includeArchived">AND i.archived_at IS NULL</if>
|
||||
ORDER BY i.sort_order,i.id
|
||||
</select>
|
||||
<select id="selectRequest" resultType="java.util.LinkedHashMap">
|
||||
SELECT * FROM pm_collab_iteration_request WHERE project_id=#{projectId} AND created_by=#{actor} AND idempotency_key=#{key}
|
||||
</select>
|
||||
<insert id="insertRequest">
|
||||
INSERT INTO pm_collab_iteration_request(project_id,iteration_id,idempotency_key,action,request_hash,result_json,created_by,created_at)
|
||||
VALUES(#{values.project_id},#{values.iteration_id},#{values.idempotency_key},#{values.action},#{values.request_hash},#{values.result_json},#{values.created_by},#{values.created_at})
|
||||
</insert>
|
||||
<insert id="insertIterationRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_iteration(project_id,iteration_code,name,goal,planned_start_at,planned_end_at,sort_order,created_by,created_at,updated_by,updated_at)
|
||||
VALUES(#{values.project_id},#{values.iteration_code},#{values.name},#{values.goal},#{values.planned_start_at},#{values.planned_end_at},#{values.sort_order},#{values.created_by},#{values.created_at},#{values.created_by},#{values.created_at})
|
||||
</insert>
|
||||
<update id="updateIteration">
|
||||
UPDATE pm_collab_iteration
|
||||
<set>
|
||||
<if test="values.containsKey('iteration_code')">iteration_code=#{values.iteration_code},</if>
|
||||
<if test="values.containsKey('name')">name=#{values.name},</if>
|
||||
<if test="values.containsKey('goal')">goal=#{values.goal},</if>
|
||||
<if test="values.containsKey('planned_start_at')">planned_start_at=#{values.planned_start_at},</if>
|
||||
<if test="values.containsKey('planned_end_at')">planned_end_at=#{values.planned_end_at},</if>
|
||||
<if test="values.containsKey('sort_order')">sort_order=#{values.sort_order},</if>
|
||||
<if test="values.containsKey('status')">status=#{values.status},</if>
|
||||
<if test="values.containsKey('finish_result')">finish_result=#{values.finish_result},</if>
|
||||
<if test="values.containsKey('finish_note')">finish_note=#{values.finish_note},</if>
|
||||
<if test="values.containsKey('actual_start_at')">actual_start_at=#{values.actual_start_at},</if>
|
||||
<if test="values.containsKey('actual_end_at')">actual_end_at=#{values.actual_end_at},</if>
|
||||
<if test="values.containsKey('archived_at')">archived_at=#{values.archived_at},</if>
|
||||
<if test="values.containsKey('archived_by')">archived_by=#{values.archived_by},</if>
|
||||
<if test="values.containsKey('deleted')">deleted=#{values.deleted},</if>
|
||||
updated_by=#{values.updated_by},updated_at=#{values.updated_at},version=version+1
|
||||
</set>
|
||||
WHERE project_id=#{projectId} AND id=#{iterationId} AND version=#{version} AND deleted=false
|
||||
</update>
|
||||
<select id="countContents" resultType="long">
|
||||
SELECT (SELECT COUNT(*) FROM pm_collab_work_item WHERE project_id=#{projectId} AND iteration_id=#{iterationId})+
|
||||
(SELECT COUNT(*) FROM pm_collab_stage_rework WHERE project_id=#{projectId} AND iteration_id=#{iterationId})+
|
||||
(SELECT COUNT(*) FROM pm_collab_stage_revision WHERE project_id=#{projectId} AND iteration_id=#{iterationId}
|
||||
AND (revision_no != 1 OR rework_id IS NOT NULL OR previous_revision_id IS NOT NULL OR started_at IS NOT NULL
|
||||
OR completed_at IS NOT NULL OR superseded_at IS NOT NULL OR legacy_passed_at IS NOT NULL))
|
||||
</select>
|
||||
<select id="selectCopyStages" resultType="java.util.LinkedHashMap">
|
||||
SELECT id,name,sort_order,owner_id,description FROM pm_collab_project_stage
|
||||
WHERE project_id=#{projectId} AND iteration_id=#{iterationId} AND deleted=false ORDER BY sort_order,id
|
||||
</select>
|
||||
<select id="selectCopyEdges" resultType="java.util.LinkedHashMap">
|
||||
SELECT e.predecessor_stage_id,e.successor_stage_id FROM pm_collab_stage_edge e
|
||||
JOIN pm_collab_project_stage a ON a.id=e.predecessor_stage_id AND a.deleted=false
|
||||
JOIN pm_collab_project_stage b ON b.id=e.successor_stage_id AND b.deleted=false
|
||||
WHERE e.project_id=#{projectId} AND e.iteration_id=#{iterationId} ORDER BY e.id
|
||||
</select>
|
||||
<insert id="insertCopiedStageRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
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>
|
||||
<insert id="insertCopiedRevisionRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
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>
|
||||
<update id="initializeCopiedRevision">
|
||||
UPDATE pm_collab_project_stage SET current_revision_id=#{revisionId} WHERE id=#{stageId} AND current_revision_id IS NULL
|
||||
</update>
|
||||
<insert id="insertCopiedEdge">
|
||||
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>
|
||||
<insert id="insertCopiedDefinition">
|
||||
INSERT INTO pm_collab_flow_definition_revision(project_id,iteration_id,revision_no,graph_json,created_by,created_at)
|
||||
VALUES(#{values.project_id},#{values.iteration_id},1,#{values.graph_json},#{values.created_by},#{values.created_at})
|
||||
</insert>
|
||||
</mapper>
|
||||
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!-- SQL 由应用数据源执行;未在 IDEA 关联数据源时,仅豁免这一环境提示,保留 SQL 语法检查。 -->
|
||||
<!--suppress SqlNoDataSourceInspection -->
|
||||
<mapper namespace="com.ruoyi.project.manage.mapper.PmLayoutMapper">
|
||||
<select id="selectLayoutForUpdate" resultType="java.util.LinkedHashMap">
|
||||
SELECT id,version FROM pm_collab_graph_layout WHERE project_id=#{projectId} AND owner_id=#{ownerId} FOR UPDATE
|
||||
</select>
|
||||
|
||||
<select id="selectLayout" resultType="java.util.LinkedHashMap">
|
||||
SELECT layout_json,version,updated_at FROM pm_collab_graph_layout WHERE project_id=#{projectId} AND owner_id=#{ownerId}
|
||||
</select>
|
||||
|
||||
<insert id="insertLayoutRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_graph_layout
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">project_id,</if>
|
||||
<if test="values.containsKey('owner_id')">owner_id,</if>
|
||||
<if test="values.containsKey('layout_json')">layout_json,</if>
|
||||
<if test="values.containsKey('version')">version,</if>
|
||||
<if test="values.containsKey('updated_by')">updated_by,</if>
|
||||
<if test="values.containsKey('updated_at')">updated_at,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">#{values.project_id},</if>
|
||||
<if test="values.containsKey('owner_id')">#{values.owner_id},</if>
|
||||
<if test="values.containsKey('layout_json')">#{values.layout_json},</if>
|
||||
<if test="values.containsKey('version')">#{values.version},</if>
|
||||
<if test="values.containsKey('updated_by')">#{values.updated_by},</if>
|
||||
<if test="values.containsKey('updated_at')">#{values.updated_at},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateLayoutRow">
|
||||
UPDATE pm_collab_graph_layout
|
||||
<set>
|
||||
<if test="values.containsKey('project_id')">project_id=#{values.project_id},</if>
|
||||
<if test="values.containsKey('owner_id')">owner_id=#{values.owner_id},</if>
|
||||
<if test="values.containsKey('layout_json')">layout_json=#{values.layout_json},</if>
|
||||
<if test="values.containsKey('updated_by')">updated_by=#{values.updated_by},</if>
|
||||
<if test="values.containsKey('updated_at')">updated_at=#{values.updated_at},</if>
|
||||
version=version+1
|
||||
</set>
|
||||
WHERE id=#{id} AND version=#{version}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,82 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!-- SQL 由应用数据源执行;未在 IDEA 关联数据源时,仅豁免这一环境提示,保留 SQL 语法检查。 -->
|
||||
<!--suppress SqlNoDataSourceInspection -->
|
||||
<mapper namespace="com.ruoyi.project.manage.mapper.PmRevisionMapper">
|
||||
<select id="selectCurrentRevisions" resultType="java.util.LinkedHashMap">
|
||||
SELECT r.* FROM pm_collab_stage_revision r JOIN pm_collab_project_stage s ON s.id=r.stage_id AND s.project_id=r.project_id AND s.current_revision_id=r.id
|
||||
WHERE r.project_id=#{projectId} AND r.iteration_id=#{iterationId} AND s.deleted=false ORDER BY s.sort_order,s.id
|
||||
</select>
|
||||
<select id="selectStageRevisions" resultType="java.util.LinkedHashMap">
|
||||
SELECT r.* FROM pm_collab_stage_revision r WHERE r.project_id=#{projectId} AND r.iteration_id=#{iterationId} AND r.stage_id=#{stageId} ORDER BY r.revision_no DESC
|
||||
</select>
|
||||
<select id="selectRevision" resultType="java.util.LinkedHashMap">
|
||||
SELECT r.* FROM pm_collab_stage_revision r WHERE r.project_id=#{projectId} AND r.iteration_id=#{iterationId} AND r.stage_id=#{stageId} AND r.id=#{revisionId}
|
||||
</select>
|
||||
<select id="selectRevisionItems" resultType="java.util.LinkedHashMap">
|
||||
SELECT * FROM pm_collab_work_item WHERE stage_revision_id=#{revisionId} ORDER BY id
|
||||
</select>
|
||||
<insert id="insertRevisionRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="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>
|
||||
<update id="switchCurrentRevision">
|
||||
UPDATE pm_collab_project_stage SET current_revision_id=#{nextId},version=version+1
|
||||
WHERE project_id=#{projectId} AND id=#{stageId} AND current_revision_id=#{previousId} AND deleted=false
|
||||
</update>
|
||||
<update id="initializeCurrentRevision">
|
||||
UPDATE pm_collab_project_stage SET current_revision_id=#{revisionId} WHERE project_id=#{projectId} AND id=#{stageId} AND current_revision_id IS NULL
|
||||
</update>
|
||||
<update id="updateRevisionState">
|
||||
UPDATE pm_collab_stage_revision SET started_at=COALESCE(started_at,#{startedAt}),completed_at=#{completedAt},version=version+1 WHERE id=#{revisionId} AND superseded_at IS NULL
|
||||
</update>
|
||||
<update id="supersedeRevision">
|
||||
UPDATE pm_collab_stage_revision SET superseded_at=#{at},version=version+1 WHERE id=#{revisionId} AND superseded_at IS NULL
|
||||
</update>
|
||||
<select id="selectGraphVersion" resultType="java.util.LinkedHashMap">
|
||||
SELECT graph_version FROM pm_collab_iteration WHERE project_id=#{projectId} AND id=#{iterationId} AND deleted=false
|
||||
</select>
|
||||
<update id="advanceGraphVersion">
|
||||
UPDATE pm_collab_iteration SET graph_version=graph_version+1 WHERE project_id=#{projectId} AND id=#{iterationId} AND deleted=false
|
||||
</update>
|
||||
<!-- 成员属于项目,但只有引用该成员的当前图需要失效。终态/归档仍可作为结构复制来源,不能排除。 -->
|
||||
<update id="advanceMemberAffectedGraphVersions">
|
||||
UPDATE pm_collab_iteration i SET i.graph_version=i.graph_version+1
|
||||
WHERE i.project_id=#{projectId} AND i.deleted=false AND (
|
||||
EXISTS(SELECT 1 FROM pm_collab_project_stage s WHERE s.project_id=i.project_id AND s.iteration_id=i.id AND s.deleted=false AND s.owner_id=#{userId})
|
||||
OR EXISTS(SELECT 1 FROM pm_collab_work_item w LEFT JOIN pm_collab_project_stage s ON s.project_id=w.project_id AND s.iteration_id=w.iteration_id AND s.id=w.stage_id
|
||||
WHERE w.project_id=i.project_id AND w.iteration_id=i.id AND w.assignee_id=#{userId} AND w.deleted=false AND w.status<>'CANCELLED'
|
||||
AND (w.stage_id IS NULL OR (s.deleted=false AND w.stage_revision_id=s.current_revision_id)))
|
||||
)
|
||||
</update>
|
||||
<select id="selectReworkByKey" resultType="java.util.LinkedHashMap">
|
||||
SELECT * FROM pm_collab_stage_rework WHERE project_id=#{projectId} AND iteration_id=#{iterationId} AND idempotency_key=#{key}
|
||||
</select>
|
||||
<insert id="insertReworkRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_stage_rework(project_id,iteration_id,source_stage_id,target_stage_id,reason,idempotency_key,preview_graph_version,impact_json,created_by,created_at)
|
||||
VALUES(#{values.project_id},#{values.iteration_id},#{values.source_stage_id},#{values.target_stage_id},#{values.reason},#{values.idempotency_key},#{values.preview_graph_version},#{values.impact_json},#{values.created_by},#{values.created_at})
|
||||
</insert>
|
||||
<update id="saveReworkResult">
|
||||
UPDATE pm_collab_stage_rework SET impact_json=#{result} WHERE id=#{reworkId}
|
||||
</update>
|
||||
<insert id="insertDefinitionRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_flow_definition_revision(project_id,iteration_id,revision_no,graph_json,created_by,created_at)
|
||||
VALUES(#{values.project_id},#{values.iteration_id},#{values.revision_no},#{values.graph_json},#{values.created_by},#{values.created_at})
|
||||
</insert>
|
||||
<select id="selectLatestDefinition" resultType="java.util.LinkedHashMap">
|
||||
SELECT id,revision_no FROM pm_collab_flow_definition_revision WHERE project_id=#{projectId} AND iteration_id=#{iterationId} ORDER BY revision_no DESC LIMIT 1
|
||||
</select>
|
||||
<select id="selectDefinition" resultType="java.util.LinkedHashMap">
|
||||
SELECT revision_no,graph_json FROM pm_collab_flow_definition_revision WHERE project_id=#{projectId} AND iteration_id=#{iterationId} AND id=#{definitionId}
|
||||
</select>
|
||||
<update id="bindStartedDefinition">
|
||||
UPDATE pm_collab_stage_revision SET flow_definition_revision_id=#{definitionId} WHERE id=#{revisionId} AND flow_definition_revision_id IS NULL
|
||||
</update>
|
||||
<update id="refreshStartedIdentity">
|
||||
UPDATE pm_collab_stage_revision SET stage_name_snapshot=#{name},stage_owner_snapshot=#{ownerId}
|
||||
WHERE id=#{revisionId} AND flow_definition_revision_id IS NULL AND superseded_at IS NULL
|
||||
</update>
|
||||
<update id="markScheduleReview">
|
||||
UPDATE pm_collab_work_item SET reference_planned_start_at=COALESCE(planned_start_at,reference_planned_start_at),reference_planned_end_at=COALESCE(planned_end_at,reference_planned_end_at),planned_start_at=NULL,planned_end_at=NULL,schedule_review_rework_id=#{reworkId},version=version+1 WHERE id=#{itemId} AND status IN ('READY','CANCELLED') AND deleted=false
|
||||
</update>
|
||||
</mapper>
|
||||
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!--suppress SqlNoDataSourceInspection -->
|
||||
<mapper namespace="com.ruoyi.project.manage.mapper.PmScheduleMapper">
|
||||
<update id="updateStagePlan">
|
||||
UPDATE pm_collab_stage_revision r JOIN pm_collab_project_stage s ON s.current_revision_id=r.id AND s.id=r.stage_id
|
||||
SET r.planned_start_at=#{values.start},r.planned_end_at=#{values.end},r.reference_planned_start_at=NULL,r.reference_planned_end_at=NULL,
|
||||
r.schedule_review_rework_id=NULL,r.plan_source=#{values.source},r.plan_recorded_at=#{values.at},r.version=r.version+1
|
||||
WHERE r.id=#{revisionId} AND r.version=#{version} AND r.superseded_at IS NULL AND s.deleted=false
|
||||
</update>
|
||||
<update id="markStageReview">
|
||||
UPDATE pm_collab_stage_revision SET reference_planned_start_at=COALESCE(planned_start_at,reference_planned_start_at),
|
||||
reference_planned_end_at=COALESCE(planned_end_at,reference_planned_end_at),planned_start_at=NULL,planned_end_at=NULL,
|
||||
schedule_review_rework_id=#{reworkId},version=version+1 WHERE id=#{revisionId} AND superseded_at IS NULL
|
||||
</update>
|
||||
<select id="selectReworkEdges" resultType="java.util.LinkedHashMap">
|
||||
SELECT r.source_stage_id AS sourceStageId,r.target_stage_id AS targetStageId,COUNT(*) AS reworkCount,MAX(r.created_at) AS latestReworkAt
|
||||
FROM pm_collab_stage_rework r
|
||||
JOIN pm_collab_project_stage s ON s.id=r.source_stage_id AND s.project_id=r.project_id AND s.iteration_id=r.iteration_id AND s.deleted=false
|
||||
JOIN pm_collab_project_stage t ON t.id=r.target_stage_id AND t.project_id=r.project_id AND t.iteration_id=r.iteration_id AND t.deleted=false
|
||||
WHERE r.project_id=#{projectId} AND r.iteration_id=#{iterationId}
|
||||
GROUP BY r.source_stage_id,r.target_stage_id ORDER BY r.source_stage_id,r.target_stage_id
|
||||
</select>
|
||||
</mapper>
|
||||
@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!-- SQL 由应用数据源执行;未在 IDEA 关联数据源时,仅豁免这一环境提示,保留 SQL 语法检查。 -->
|
||||
<!--suppress SqlNoDataSourceInspection -->
|
||||
<mapper namespace="com.ruoyi.project.manage.mapper.PmStageMapper">
|
||||
<select id="selectOwnedStage" resultType="java.util.LinkedHashMap">
|
||||
SELECT s.id FROM pm_collab_project_stage s JOIN pm_collab_iteration i ON i.project_id=s.project_id AND i.id=s.iteration_id WHERE s.project_id=#{projectId} AND s.owner_id=#{userId} AND s.deleted=false AND i.deleted=false AND i.archived_at IS NULL AND i.status IN ('PLANNED','ACTIVE') LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectActiveStageId" resultType="java.util.LinkedHashMap">
|
||||
SELECT id FROM pm_collab_project_stage WHERE id=#{stageId} AND project_id=#{projectId} AND iteration_id=#{iterationId} AND deleted=false
|
||||
</select>
|
||||
|
||||
<select id="selectVisibleStages" resultType="java.util.LinkedHashMap">
|
||||
SELECT s.id,s.name,s.sort_order AS sortOrder,s.owner_id AS ownerId,u.nick_name AS ownerName,s.description,s.version,s.current_revision_id AS currentRevisionId,r.revision_no AS revisionNo,s.created_by AS creatorId,s.created_at AS createdAt
|
||||
FROM pm_collab_project_stage s LEFT JOIN sys_user u ON u.user_id=s.owner_id
|
||||
LEFT JOIN pm_collab_stage_revision r ON r.id=s.current_revision_id
|
||||
WHERE s.project_id=#{projectId} AND s.iteration_id=#{iterationId} AND s.deleted=false ORDER BY s.sort_order,s.id
|
||||
</select>
|
||||
|
||||
<select id="selectProjectStageIds" resultType="java.util.LinkedHashMap">
|
||||
SELECT id FROM pm_collab_project_stage WHERE project_id=#{projectId}
|
||||
</select>
|
||||
|
||||
<select id="selectActiveStage" resultType="java.util.LinkedHashMap">
|
||||
SELECT * FROM pm_collab_project_stage WHERE id=#{stageId} AND project_id=#{projectId} AND iteration_id=#{iterationId} AND deleted=false
|
||||
</select>
|
||||
|
||||
<insert id="insertStageRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_project_stage
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">project_id,</if>
|
||||
<if test="values.containsKey('iteration_id')">iteration_id,</if>
|
||||
<if test="values.containsKey('name')">name,</if>
|
||||
<if test="values.containsKey('sort_order')">sort_order,</if>
|
||||
<if test="values.containsKey('owner_id')">owner_id,</if>
|
||||
<if test="values.containsKey('description')">description,</if>
|
||||
<if test="values.containsKey('version')">version,</if>
|
||||
<if test="values.containsKey('deleted')">deleted,</if>
|
||||
<if test="values.containsKey('created_by')">created_by,</if>
|
||||
<if test="values.containsKey('created_at')">created_at,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">#{values.project_id},</if>
|
||||
<if test="values.containsKey('iteration_id')">#{values.iteration_id},</if>
|
||||
<if test="values.containsKey('name')">#{values.name},</if>
|
||||
<if test="values.containsKey('sort_order')">#{values.sort_order},</if>
|
||||
<if test="values.containsKey('owner_id')">#{values.owner_id},</if>
|
||||
<if test="values.containsKey('description')">#{values.description},</if>
|
||||
<if test="values.containsKey('version')">#{values.version},</if>
|
||||
<if test="values.containsKey('deleted')">#{values.deleted},</if>
|
||||
<if test="values.containsKey('created_by')">#{values.created_by},</if>
|
||||
<if test="values.containsKey('created_at')">#{values.created_at},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateStageRow">
|
||||
UPDATE pm_collab_project_stage
|
||||
<set>
|
||||
<if test="values.containsKey('project_id')">project_id=#{values.project_id},</if>
|
||||
<if test="values.containsKey('name')">name=#{values.name},</if>
|
||||
<if test="values.containsKey('sort_order')">sort_order=#{values.sort_order},</if>
|
||||
<if test="values.containsKey('owner_id')">owner_id=#{values.owner_id},</if>
|
||||
<if test="values.containsKey('description')">description=#{values.description},</if>
|
||||
<if test="values.containsKey('deleted')">deleted=#{values.deleted},</if>
|
||||
<if test="values.containsKey('created_by')">created_by=#{values.created_by},</if>
|
||||
<if test="values.containsKey('created_at')">created_at=#{values.created_at},</if>
|
||||
version=version+1
|
||||
</set>
|
||||
WHERE id=#{id} AND version=#{version}
|
||||
</update>
|
||||
|
||||
<select id="selectStageEdges" resultType="java.util.LinkedHashMap">
|
||||
SELECT e.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
|
||||
WHERE e.project_id=#{projectId} AND e.iteration_id=#{iterationId} ORDER BY e.id
|
||||
</select>
|
||||
|
||||
<insert id="insertStageEdgeRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
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>
|
||||
|
||||
<delete id="deleteStageEdge">
|
||||
DELETE FROM pm_collab_stage_edge WHERE id=#{id} AND project_id=#{projectId} AND version=#{version}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteEdgesForStage">
|
||||
DELETE FROM pm_collab_stage_edge WHERE project_id=#{projectId} AND (predecessor_stage_id=#{stageId} OR successor_stage_id=#{stageId})
|
||||
</delete>
|
||||
</mapper>
|
||||
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!-- SQL 由应用数据源执行;未在 IDEA 关联数据源时,仅豁免这一环境提示,保留 SQL 语法检查。 -->
|
||||
<!--suppress SqlNoDataSourceInspection -->
|
||||
<mapper namespace="com.ruoyi.project.manage.mapper.PmUserMapper">
|
||||
<select id="selectCandidates" resultType="java.util.LinkedHashMap">
|
||||
SELECT user_id AS userId,nick_name AS name FROM sys_user WHERE status='0' AND del_flag='0' AND nick_name LIKE #{nicknamePattern} ORDER BY user_id LIMIT 30
|
||||
</select>
|
||||
|
||||
<select id="selectActiveUser" resultType="java.util.LinkedHashMap">
|
||||
SELECT user_id FROM sys_user WHERE user_id=#{userId} AND status='0' AND del_flag='0'
|
||||
</select>
|
||||
|
||||
<select id="selectAssignableUser" resultType="java.util.LinkedHashMap">
|
||||
SELECT u.user_id FROM sys_user u JOIN pm_collab_project p ON p.id=#{projectId} WHERE u.user_id=#{userId} AND u.status='0' AND u.del_flag='0' AND (p.manager_id=u.user_id OR EXISTS(SELECT 1 FROM pm_collab_project_member m WHERE m.project_id=p.id AND m.user_id=u.user_id))
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!-- SQL 由应用数据源执行;未在 IDEA 关联数据源时,仅豁免这一环境提示,保留 SQL 语法检查。 -->
|
||||
<!--suppress SqlNoDataSourceInspection -->
|
||||
<mapper namespace="com.ruoyi.project.manage.mapper.PmWorkItemMapper">
|
||||
<select id="selectAssignedItem" resultType="java.util.LinkedHashMap">
|
||||
SELECT w.id FROM pm_collab_work_item w JOIN pm_collab_iteration i ON i.project_id=w.project_id AND i.id=w.iteration_id LEFT JOIN pm_collab_project_stage s ON s.project_id=w.project_id AND s.id=w.stage_id WHERE w.project_id=#{projectId} AND w.assignee_id=#{userId} AND w.deleted=false AND w.status IN ('READY','IN_PROGRESS') AND i.deleted=false AND i.archived_at IS NULL AND i.status IN ('PLANNED','ACTIVE') AND (w.stage_id IS NULL OR w.stage_revision_id=s.current_revision_id) LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectProjectReference" resultType="java.util.LinkedHashMap">
|
||||
SELECT project_id,iteration_id FROM pm_collab_work_item WHERE id=#{itemId}
|
||||
</select>
|
||||
|
||||
<insert id="insertWorkItemRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_work_item
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">project_id,</if>
|
||||
<if test="values.containsKey('iteration_id')">iteration_id,</if>
|
||||
<if test="values.containsKey('type')">type,</if>
|
||||
<if test="values.containsKey('title')">title,</if>
|
||||
<if test="values.containsKey('description')">description,</if>
|
||||
<if test="values.containsKey('assignee_id')">assignee_id,</if>
|
||||
<if test="values.containsKey('priority')">priority,</if>
|
||||
<if test="values.containsKey('status')">status,</if>
|
||||
<if test="values.containsKey('planned_start_at')">planned_start_at,</if>
|
||||
<if test="values.containsKey('planned_end_at')">planned_end_at,</if>
|
||||
<if test="values.containsKey('actual_start_at')">actual_start_at,</if>
|
||||
<if test="values.containsKey('actual_end_at')">actual_end_at,</if>
|
||||
<if test="values.containsKey('stage_id')">stage_id,</if>
|
||||
<if test="values.containsKey('stage_revision_id')">stage_revision_id,</if>
|
||||
<if test="values.containsKey('origin_work_item_id')">origin_work_item_id,</if>
|
||||
<if test="values.containsKey('schedule_review_rework_id')">schedule_review_rework_id,</if>
|
||||
<if test="values.containsKey('parent_task_id')">parent_task_id,</if>
|
||||
<if test="values.containsKey('version')">version,</if>
|
||||
<if test="values.containsKey('deleted')">deleted,</if>
|
||||
<if test="values.containsKey('created_by')">created_by,</if>
|
||||
<if test="values.containsKey('created_at')">created_at,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">#{values.project_id},</if>
|
||||
<if test="values.containsKey('iteration_id')">#{values.iteration_id},</if>
|
||||
<if test="values.containsKey('type')">#{values.type},</if>
|
||||
<if test="values.containsKey('title')">#{values.title},</if>
|
||||
<if test="values.containsKey('description')">#{values.description},</if>
|
||||
<if test="values.containsKey('assignee_id')">#{values.assignee_id},</if>
|
||||
<if test="values.containsKey('priority')">#{values.priority},</if>
|
||||
<if test="values.containsKey('status')">#{values.status},</if>
|
||||
<if test="values.containsKey('planned_start_at')">#{values.planned_start_at},</if>
|
||||
<if test="values.containsKey('planned_end_at')">#{values.planned_end_at},</if>
|
||||
<if test="values.containsKey('actual_start_at')">#{values.actual_start_at},</if>
|
||||
<if test="values.containsKey('actual_end_at')">#{values.actual_end_at},</if>
|
||||
<if test="values.containsKey('stage_id')">#{values.stage_id},</if>
|
||||
<if test="values.containsKey('stage_revision_id')">#{values.stage_revision_id},</if>
|
||||
<if test="values.containsKey('origin_work_item_id')">#{values.origin_work_item_id},</if>
|
||||
<if test="values.containsKey('schedule_review_rework_id')">#{values.schedule_review_rework_id},</if>
|
||||
<if test="values.containsKey('parent_task_id')">#{values.parent_task_id},</if>
|
||||
<if test="values.containsKey('version')">#{values.version},</if>
|
||||
<if test="values.containsKey('deleted')">#{values.deleted},</if>
|
||||
<if test="values.containsKey('created_by')">#{values.created_by},</if>
|
||||
<if test="values.containsKey('created_at')">#{values.created_at},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateWorkItemRow">
|
||||
UPDATE pm_collab_work_item
|
||||
<set>
|
||||
<if test="values.containsKey('project_id')">project_id=#{values.project_id},</if>
|
||||
<if test="values.containsKey('type')">type=#{values.type},</if>
|
||||
<if test="values.containsKey('title')">title=#{values.title},</if>
|
||||
<if test="values.containsKey('description')">description=#{values.description},</if>
|
||||
<if test="values.containsKey('assignee_id')">assignee_id=#{values.assignee_id},</if>
|
||||
<if test="values.containsKey('priority')">priority=#{values.priority},</if>
|
||||
<if test="values.containsKey('status')">status=#{values.status},</if>
|
||||
<if test="values.containsKey('planned_start_at')">planned_start_at=#{values.planned_start_at},</if>
|
||||
<if test="values.containsKey('planned_end_at')">planned_end_at=#{values.planned_end_at},</if>
|
||||
<if test="values.containsKey('reference_planned_start_at')">reference_planned_start_at=#{values.reference_planned_start_at},</if>
|
||||
<if test="values.containsKey('reference_planned_end_at')">reference_planned_end_at=#{values.reference_planned_end_at},</if>
|
||||
<if test="values.containsKey('actual_start_at')">actual_start_at=#{values.actual_start_at},</if>
|
||||
<if test="values.containsKey('actual_end_at')">actual_end_at=#{values.actual_end_at},</if>
|
||||
<if test="values.containsKey('stage_id')">stage_id=#{values.stage_id},</if>
|
||||
<if test="values.containsKey('stage_revision_id')">stage_revision_id=#{values.stage_revision_id},</if>
|
||||
<if test="values.containsKey('schedule_review_rework_id')">schedule_review_rework_id=#{values.schedule_review_rework_id},</if>
|
||||
<if test="values.containsKey('parent_task_id')">parent_task_id=#{values.parent_task_id},</if>
|
||||
<if test="values.containsKey('deleted')">deleted=#{values.deleted},</if>
|
||||
<if test="values.containsKey('created_by')">created_by=#{values.created_by},</if>
|
||||
<if test="values.containsKey('created_at')">created_at=#{values.created_at},</if>
|
||||
version=version+1
|
||||
</set>
|
||||
WHERE id=#{id} AND version=#{version}
|
||||
</update>
|
||||
|
||||
<select id="selectItemInStage" resultType="java.util.LinkedHashMap">
|
||||
SELECT id FROM pm_collab_work_item WHERE project_id=#{projectId} AND stage_id=#{stageId} AND deleted=false LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectProjectItemIds" resultType="java.util.LinkedHashMap">
|
||||
SELECT id FROM pm_collab_work_item WHERE project_id=#{projectId}
|
||||
</select>
|
||||
|
||||
<select id="selectGraphItems" resultType="java.util.LinkedHashMap">
|
||||
SELECT i.* FROM pm_collab_work_item i LEFT JOIN pm_collab_project_stage s ON s.project_id=i.project_id AND s.id=i.stage_id
|
||||
WHERE i.project_id=#{projectId} AND i.iteration_id=#{iterationId} AND (i.stage_id IS NULL OR (s.deleted=false AND i.stage_revision_id=s.current_revision_id)) ORDER BY i.id
|
||||
</select>
|
||||
|
||||
<select id="selectHistoricalItem" resultType="java.util.LinkedHashMap">
|
||||
SELECT i.*,r.revision_no AS stage_revision_no,r.stage_name_snapshot FROM pm_collab_work_item i JOIN pm_collab_project_stage s ON s.id=i.stage_id AND s.project_id=i.project_id
|
||||
JOIN pm_collab_stage_revision r ON r.id=i.stage_revision_id
|
||||
WHERE i.project_id=#{projectId} AND i.id=#{itemId} AND i.deleted=false AND i.stage_revision_id IS NOT NULL AND i.stage_revision_id<>s.current_revision_id
|
||||
</select>
|
||||
|
||||
<select id="selectRevisionReference" resultType="java.util.LinkedHashMap">
|
||||
SELECT i.id,i.deleted,i.stage_id,i.stage_revision_id,s.current_revision_id FROM pm_collab_work_item i
|
||||
LEFT JOIN pm_collab_project_stage s ON s.id=i.stage_id AND s.project_id=i.project_id
|
||||
WHERE i.project_id=#{projectId} AND i.id=#{itemId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,175 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!-- SQL 由应用数据源执行;未在 IDEA 关联数据源时,仅豁免这一环境提示,保留 SQL 语法检查。 -->
|
||||
<!--suppress SqlNoDataSourceInspection -->
|
||||
<mapper namespace="com.ruoyi.project.manage.mapper.PmWorkspaceMapper">
|
||||
<select id="selectVisibleProjects" resultType="java.util.LinkedHashMap">
|
||||
SELECT p.id,p.project_name AS name,p.project_code AS code,p.manager_id AS managerId,c.space_id AS spaceId,p.version,s.name AS spaceName,true AS enabled,c.creator_id AS creatorId,COALESCE(u.nick_name,'未知创建人') AS creatorName,(p.manager_id=#{userId} OR EXISTS(SELECT 1 FROM pm_collab_project_member m WHERE m.project_id=p.id AND m.user_id=#{userId} AND m.member_role='MANAGER')) AS manager FROM pm_collab_project p JOIN pm_collab_project_config c ON c.project_id=p.id JOIN pm_collab_space s ON s.id=c.space_id LEFT JOIN sys_user u ON u.user_id=c.creator_id WHERE p.del_flag='0' AND s.deleted=false AND (#{administrator} OR p.manager_id=#{userId} OR EXISTS(SELECT 1 FROM pm_collab_project_member m WHERE m.project_id=p.id AND m.user_id=#{userId})) ORDER BY p.id DESC
|
||||
</select>
|
||||
|
||||
<select id="selectVisibleSpaces" resultType="java.util.LinkedHashMap">
|
||||
SELECT s.id,s.name,s.owner_id AS ownerId,s.owner_id AS creatorId,COALESCE(u.nick_name,'未知创建人') AS creatorName,s.version FROM pm_collab_space s LEFT JOIN sys_user u ON u.user_id=s.owner_id WHERE s.deleted=false AND (#{administrator} OR s.owner_id=#{userId} OR EXISTS(SELECT 1 FROM pm_collab_project_config c JOIN pm_collab_project p ON p.id=c.project_id WHERE c.space_id=s.id AND p.del_flag='0' AND (p.manager_id=#{userId} OR EXISTS(SELECT 1 FROM pm_collab_project_member m WHERE m.project_id=p.id AND m.user_id=#{userId})))) ORDER BY s.id
|
||||
</select>
|
||||
|
||||
<select id="selectActiveProjectInSpace" resultType="java.util.LinkedHashMap">
|
||||
SELECT p.id FROM pm_collab_project_config c JOIN pm_collab_project p ON p.id=c.project_id WHERE c.space_id=#{spaceId} AND p.del_flag='0' LIMIT 1
|
||||
</select>
|
||||
|
||||
<update id="ensureProjectLock">
|
||||
INSERT IGNORE INTO pm_collab_project_lock(project_id) VALUES(#{projectId})
|
||||
</update>
|
||||
|
||||
<update id="moveProjectSpace">
|
||||
UPDATE pm_collab_project_config SET space_id=#{spaceId},version=version+1 WHERE project_id=#{projectId}
|
||||
</update>
|
||||
|
||||
<select id="selectConfig" resultType="java.util.LinkedHashMap">
|
||||
SELECT * FROM pm_collab_project_config WHERE project_id=#{projectId}
|
||||
</select>
|
||||
|
||||
<update id="incrementProjectVersion">
|
||||
UPDATE pm_collab_project SET version=version+1 WHERE id=#{projectId}
|
||||
</update>
|
||||
|
||||
<select id="selectMembers" resultType="java.util.LinkedHashMap">
|
||||
SELECT u.user_id AS userId,u.nick_name AS name,CASE WHEN p.manager_id=u.user_id THEN 'MANAGER' ELSE m.member_role END AS role FROM pm_collab_project p JOIN sys_user u ON u.user_id=p.manager_id OR EXISTS(SELECT 1 FROM pm_collab_project_member x WHERE x.project_id=p.id AND x.user_id=u.user_id) LEFT JOIN pm_collab_project_member m ON m.project_id=p.id AND m.user_id=u.user_id WHERE p.id=#{projectId} AND u.status='0' AND u.del_flag='0' ORDER BY u.user_id
|
||||
</select>
|
||||
|
||||
<select id="selectProjectManager" resultType="java.util.LinkedHashMap">
|
||||
SELECT manager_id FROM pm_collab_project WHERE id=#{projectId}
|
||||
</select>
|
||||
|
||||
<update id="deleteMember">
|
||||
DELETE FROM pm_collab_project_member WHERE project_id=#{projectId} AND user_id=#{userId}
|
||||
</update>
|
||||
|
||||
<update id="upsertMember">
|
||||
INSERT INTO pm_collab_project_member(project_id,user_id,member_role,create_by,create_time) VALUES(#{projectId},#{userId},#{role},#{actorName},CURRENT_TIMESTAMP) ON DUPLICATE KEY UPDATE member_role=VALUES(member_role)
|
||||
</update>
|
||||
|
||||
<select id="selectConfiguredProject" resultType="java.util.LinkedHashMap">
|
||||
SELECT project_id FROM pm_collab_project_config WHERE project_id=#{projectId}
|
||||
</select>
|
||||
|
||||
<select id="selectSpaceForUpdate" resultType="java.util.LinkedHashMap">
|
||||
SELECT * FROM pm_collab_space WHERE id=#{spaceId} AND deleted=false FOR UPDATE
|
||||
</select>
|
||||
|
||||
<update id="insertConfig">
|
||||
INSERT INTO pm_collab_project_config(project_id,space_id,timezone,creator_id) VALUES(#{projectId},#{spaceId},'Asia/Shanghai',#{creatorId})
|
||||
</update>
|
||||
|
||||
<insert id="insertSpaceRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_space
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('name')">name,</if>
|
||||
<if test="values.containsKey('owner_id')">owner_id,</if>
|
||||
<if test="values.containsKey('version')">version,</if>
|
||||
<if test="values.containsKey('created_at')">created_at,</if>
|
||||
<if test="values.containsKey('deleted')">deleted,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('name')">#{values.name},</if>
|
||||
<if test="values.containsKey('owner_id')">#{values.owner_id},</if>
|
||||
<if test="values.containsKey('version')">#{values.version},</if>
|
||||
<if test="values.containsKey('created_at')">#{values.created_at},</if>
|
||||
<if test="values.containsKey('deleted')">#{values.deleted},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<insert id="insertProjectRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_project
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_code')">project_code,</if>
|
||||
<if test="values.containsKey('project_name')">project_name,</if>
|
||||
<if test="values.containsKey('manager_id')">manager_id,</if>
|
||||
<if test="values.containsKey('version')">version,</if>
|
||||
<if test="values.containsKey('del_flag')">del_flag,</if>
|
||||
<if test="values.containsKey('create_by')">create_by,</if>
|
||||
<if test="values.containsKey('create_time')">create_time,</if>
|
||||
<if test="values.containsKey('update_by')">update_by,</if>
|
||||
<if test="values.containsKey('update_time')">update_time,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_code')">#{values.project_code},</if>
|
||||
<if test="values.containsKey('project_name')">#{values.project_name},</if>
|
||||
<if test="values.containsKey('manager_id')">#{values.manager_id},</if>
|
||||
<if test="values.containsKey('version')">#{values.version},</if>
|
||||
<if test="values.containsKey('del_flag')">#{values.del_flag},</if>
|
||||
<if test="values.containsKey('create_by')">#{values.create_by},</if>
|
||||
<if test="values.containsKey('create_time')">#{values.create_time},</if>
|
||||
<if test="values.containsKey('update_by')">#{values.update_by},</if>
|
||||
<if test="values.containsKey('update_time')">#{values.update_time},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<insert id="insertMemberRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
|
||||
INSERT INTO pm_collab_project_member
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">project_id,</if>
|
||||
<if test="values.containsKey('user_id')">user_id,</if>
|
||||
<if test="values.containsKey('member_role')">member_role,</if>
|
||||
<if test="values.containsKey('create_by')">create_by,</if>
|
||||
<if test="values.containsKey('create_time')">create_time,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="values.containsKey('project_id')">#{values.project_id},</if>
|
||||
<if test="values.containsKey('user_id')">#{values.user_id},</if>
|
||||
<if test="values.containsKey('member_role')">#{values.member_role},</if>
|
||||
<if test="values.containsKey('create_by')">#{values.create_by},</if>
|
||||
<if test="values.containsKey('create_time')">#{values.create_time},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateSpaceRow">
|
||||
UPDATE pm_collab_space
|
||||
<set>
|
||||
<if test="values.containsKey('name')">name=#{values.name},</if>
|
||||
<if test="values.containsKey('owner_id')">owner_id=#{values.owner_id},</if>
|
||||
<if test="values.containsKey('created_at')">created_at=#{values.created_at},</if>
|
||||
<if test="values.containsKey('deleted')">deleted=#{values.deleted},</if>
|
||||
version=version+1
|
||||
</set>
|
||||
WHERE id=#{id} AND version=#{version}
|
||||
</update>
|
||||
|
||||
<update id="updateProjectRow">
|
||||
UPDATE pm_collab_project
|
||||
<set>
|
||||
<if test="values.containsKey('project_code')">project_code=#{values.project_code},</if>
|
||||
<if test="values.containsKey('project_name')">project_name=#{values.project_name},</if>
|
||||
<if test="values.containsKey('manager_id')">manager_id=#{values.manager_id},</if>
|
||||
<if test="values.containsKey('del_flag')">del_flag=#{values.del_flag},</if>
|
||||
<if test="values.containsKey('create_by')">create_by=#{values.create_by},</if>
|
||||
<if test="values.containsKey('create_time')">create_time=#{values.create_time},</if>
|
||||
<if test="values.containsKey('update_by')">update_by=#{values.update_by},</if>
|
||||
<if test="values.containsKey('update_time')">update_time=#{values.update_time},</if>
|
||||
version=version+1
|
||||
</set>
|
||||
WHERE id=#{id} AND version=#{version}
|
||||
</update>
|
||||
|
||||
<select id="selectCreatorProject" resultType="java.util.LinkedHashMap">
|
||||
SELECT p.*,c.space_id,c.creator_id AS actualCreatorId FROM pm_collab_project p JOIN pm_collab_project_config c ON c.project_id=p.id WHERE p.id=#{projectId} AND p.del_flag='0'
|
||||
</select>
|
||||
|
||||
<select id="selectActiveProjectManager" resultType="java.util.LinkedHashMap">
|
||||
SELECT manager_id FROM pm_collab_project WHERE id=#{projectId} AND del_flag='0'
|
||||
</select>
|
||||
|
||||
<select id="selectMemberRole" resultType="java.util.LinkedHashMap">
|
||||
SELECT member_role FROM pm_collab_project_member WHERE project_id=#{projectId} AND user_id=#{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectProjectForShare" resultType="java.util.LinkedHashMap">
|
||||
SELECT project_id FROM pm_collab_project_lock WHERE project_id=#{projectId} LOCK IN SHARE MODE
|
||||
</select>
|
||||
|
||||
<select id="selectProjectLockForUpdate" resultType="java.util.LinkedHashMap">
|
||||
SELECT project_id FROM pm_collab_project_lock WHERE project_id=#{projectId} FOR UPDATE
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@ -22,6 +22,11 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "2.3.2",
|
||||
"@js-temporal/polyfill": "^0.5.1",
|
||||
"@vue-flow/background": "^1.3.2",
|
||||
"@vue-flow/controls": "^1.1.3",
|
||||
"@vue-flow/core": "^1.48.2",
|
||||
"@vue-flow/minimap": "^1.5.4",
|
||||
"@vueup/vue-quill": "1.2.0",
|
||||
"@vueuse/core": "14.1.0",
|
||||
"axios": "1.13.2",
|
||||
@ -36,6 +41,7 @@
|
||||
"nprogress": "0.2.0",
|
||||
"pdfjs-dist": "6.4.299",
|
||||
"pinia": "3.0.4",
|
||||
"sortablejs": "1.14.0",
|
||||
"vue": "3.5.26",
|
||||
"vue-cropper": "1.1.1",
|
||||
"vue-router": "4.6.4",
|
||||
@ -43,13 +49,18 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "5.2.4",
|
||||
"@vue/test-utils": "^2.5.1",
|
||||
"jsdom": "^30.1.2",
|
||||
"playwright": "1.62.1",
|
||||
"sass-embedded": "1.97.2",
|
||||
"typescript": "^5.9.3",
|
||||
"unplugin-auto-import": "0.18.6",
|
||||
"unplugin-vue-setup-extend-plus": "1.0.1",
|
||||
"vite": "6.4.1",
|
||||
"vite-plugin-compression": "0.5.1",
|
||||
"vite-plugin-svg-icons": "2.0.1"
|
||||
"vite-plugin-svg-icons": "2.0.1",
|
||||
"vitest": "^5.0.4",
|
||||
"vue-tsc": "^3.3.13"
|
||||
},
|
||||
"overrides": {
|
||||
"quill": "2.0.2"
|
||||
|
||||
5780
ruoyi-ui-vue3/pnpm-lock.yaml
generated
Normal file
5780
ruoyi-ui-vue3/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
5
ruoyi-ui-vue3/pnpm-workspace.yaml
Normal file
5
ruoyi-ui-vue3/pnpm-workspace.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
# 仅允许当前工具链依赖的安装脚本,完成原生模块、esbuild 和 Vue 适配初始化。
|
||||
allowBuilds:
|
||||
'@parcel/watcher': true
|
||||
esbuild: true
|
||||
vue-demi: true
|
||||
17
ruoyi-ui-vue3/src/views/project/manage/AGENTS.md
Normal file
17
ruoyi-ui-vue3/src/views/project/manage/AGENTS.md
Normal file
@ -0,0 +1,17 @@
|
||||
# 项目协作测试文件管理
|
||||
|
||||
遵循仓库根目录规范,并执行用户确认的补充要求:
|
||||
|
||||
- 验证工作仍需完成,不因清理文件而跳过必要检查。
|
||||
- 后续新增的测试代码、测试辅助文件、测试夹具和浏览器验收脚本,在测试完成后删除,不作为业务代码交付。
|
||||
- 同时清理本次测试产生的专用配置、截图和临时报告;移除因此失效的执行命令与引用。
|
||||
- 可以在交付说明中保留测试命令和实际结果,但须标明测试文件已清理,不能作为当前可执行入口。
|
||||
- 业务组件、类型检查配置、构建配置和本地启动脚本不属于测试文件。
|
||||
|
||||
## 目录分层规范
|
||||
|
||||
- `index.vue` 仅负责页面装配;页面级范围、请求及轮询协调放到 `composables`。
|
||||
- 展示视图放入 `views/<视图>`,业务操作组件放入 `features/<功能>/components`;相关工具就近归档。
|
||||
- HTTP 请求按业务放入 `api`,数据契约按领域放入 `types`,跨功能组件、展示文案和工具放入 `shared`。
|
||||
- `api` 和 `types` 不依赖视图组件,`shared` 不反向依赖业务功能;不在根目录新增散落的业务工具或集中堆放组件。
|
||||
- 新文件的具体归属及依赖边界以同目录 `README.md` 为准。
|
||||
64
ruoyi-ui-vue3/src/views/project/manage/README.md
Normal file
64
ruoyi-ui-vue3/src/views/project/manage/README.md
Normal file
@ -0,0 +1,64 @@
|
||||
# 项目协作前端
|
||||
|
||||
`index.vue` 是菜单使用的固定路由入口,只装配页面及连接状态和事件。所有项目协作前端代码留在本目录,后端接口仍为 `/project/manage`。
|
||||
|
||||
## 目录职责
|
||||
|
||||
```text
|
||||
manage/
|
||||
├── index.vue # 页面装配、顶部统计、筛选及视图切换
|
||||
├── composables/
|
||||
│ └── useProjectCollaboration.ts # 项目/迭代范围、加载、轮询、路由和动作协调
|
||||
├── views/ # 各展示视图及只服务该视图的代码
|
||||
│ ├── list/ # 工作项树形列表
|
||||
│ ├── board/ # 状态看板
|
||||
│ ├── flow/ # 流程画布
|
||||
│ │ ├── components/ # 阶段节点、回退边等画布元素
|
||||
│ │ ├── utils/ # 图布局、当前浏览器偏好
|
||||
│ │ └── constants/ # 流程线条主题
|
||||
│ ├── gantt/ # 甘特排期
|
||||
│ └── notifications/ # 变更通知展示
|
||||
├── features/ # 可由多个视图使用的业务操作
|
||||
│ ├── workspace/ # 空间和项目管理
|
||||
│ ├── iterations/ # 迭代操作、生命周期展示规则
|
||||
│ ├── members/ # 项目成员弹窗
|
||||
│ ├── work-items/ # 工作项详情、编辑、父子树工具
|
||||
│ ├── stages/ # 阶段维护、回退、当前和历史工作项抽屉
|
||||
│ └── schedules/ # 工作项和阶段排期、批量排期
|
||||
├── api/ # 按业务分类的请求;index.ts 汇总调用入口
|
||||
│ ├── client.ts # 单一客户端、会话鉴权、响应处理
|
||||
│ ├── errors.ts # 保留后端冲突详情及提示文本
|
||||
│ ├── paths.ts # 显式项目/迭代请求路径
|
||||
│ ├── attachments.ts # 受鉴权附件下载
|
||||
│ └── *.ts # 空间项目、迭代、成员、工作项、阶段、排期、通知
|
||||
├── types/ # 按领域分类的数据契约,不依赖组件或请求实现
|
||||
├── shared/
|
||||
│ ├── components/ # 跨功能基础控件,如日期选择
|
||||
│ ├── constants/ # 状态、类型、操作名称等展示映射
|
||||
│ └── utils/ # 时间换算、失败恢复等公共工具
|
||||
├── docs/ # 模块实施说明
|
||||
├── tsconfig.json # 本模块严格类型检查入口
|
||||
└── local.mjs # 本地开发/预览启动入口
|
||||
```
|
||||
|
||||
## 依赖与维护约定
|
||||
|
||||
- 新组件优先放在对应 `features/<功能>/components` 或 `views/<视图>`;画布专用元素不放到公共组件目录。
|
||||
- `shared` 只存放多个功能实际共用的能力;禁止反向依赖业务视图。`types` 只声明数据契约,展示文案在 `shared/constants/labels.ts`。
|
||||
- `api` 不依赖 Vue 组件;请求客户端、认证头、错误详情处理只有一份。业务接口按文件归属维护,上层从 `api/index.ts` 调用。
|
||||
- 页面级项目/迭代切换、请求代次和轮询集中在 composable;展示组件通过 props/v-model 接收状态并通过事件请求动作,不各自发起重复的页面轮询。
|
||||
- composable 使用 `useTemplateRef` 绑定页面的控件引用,读取编辑状态以暂停轮询;模板中的引用名必须同步维护。
|
||||
- 同一类型的字段集中声明;不要用散落在不同位置的重复接口声明累积工作项或阶段字段。
|
||||
- 保留 `index.vue`、`tsconfig.json` 和 `local.mjs` 路径,避免改变菜单及现有启动/类型检查命令。
|
||||
- 临时测试在执行完成后删除,规则见 [AGENTS.md](AGENTS.md)。
|
||||
|
||||
## 检查命令
|
||||
|
||||
在 `ruoyi-ui-vue3` 执行:
|
||||
|
||||
```powershell
|
||||
npx --no-install vue-tsc --noEmit -p src/views/project/manage/tsconfig.json --noUnusedLocals --noUnusedParameters
|
||||
npm run build:prod
|
||||
```
|
||||
|
||||
实施范围、验收标准和实际结果见 [前端分层实施记录](docs/frontend-structure-plan.md)。
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user