mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 19:49:19 +08:00
feat: 新增意见反馈功能
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
-- 系统-意见反馈域设计(已落地 migration: V20260915__sys_feedback.sql)
|
||||
-- sys_feedback / sys_feedback_images
|
||||
-- sys_feedback_message / sys_feedback_message_images
|
||||
--
|
||||
-- 产品约定(已拍板):
|
||||
-- 1) 处理侧:超管 + 公司有 handle 权限者(本公司);超管可看全部公司
|
||||
-- 2) 用户侧列表:本公司全员互看
|
||||
-- 3) 用户侧可互相留言回复;处理侧回复仅 assignee
|
||||
-- 4) 留言允许多层树
|
||||
-- 5) 用户仅可关闭 OPEN 单;RESOLVED 后再留言不重开
|
||||
-- 6) 删除需 sys:feedback:delete
|
||||
-- 7) 处理侧菜单挂系统设置;用户侧独立菜单 + 工作台/个人中心入口
|
||||
-- 8) 关联菜单由用户手选(menu_id 选填)
|
||||
--
|
||||
-- 边界:
|
||||
-- - 按公司隔离(company_id);提交人为公司成员(create_by)
|
||||
-- - 正文可选关联 sys_menu(menu_id 选填)
|
||||
-- - 多图不落 URL:一律 sys_file.id,经关联表挂接
|
||||
-- - 反馈正文图 → sys_feedback_images
|
||||
-- - 留言/回复图 → sys_feedback_message_images
|
||||
-- - 留言支持树形回复(parent_id);root_id 便于按楼聚合
|
||||
-- ========================================
|
||||
|
||||
-- ========================================
|
||||
-- 意见反馈主表
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `sys_feedback_message_images`;
|
||||
DROP TABLE IF EXISTS `sys_feedback_message`;
|
||||
DROP TABLE IF EXISTS `sys_feedback_images`;
|
||||
DROP TABLE IF EXISTS `sys_feedback`;
|
||||
|
||||
CREATE TABLE `sys_feedback` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '反馈ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '所属公司ID',
|
||||
`title` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '标题',
|
||||
`content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '正文',
|
||||
`type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'OTHER' COMMENT '类型:BUG/FEATURE/QUESTION/COMPLAINT/OTHER',
|
||||
`status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'OPEN' COMMENT '状态:OPEN/PROCESSING/RESOLVED/CLOSED/REJECTED',
|
||||
`priority` tinyint UNSIGNED NOT NULL DEFAULT 2 COMMENT '优先级:1高 2中 3低',
|
||||
`contact` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '联系方式(选填:手机/微信/邮箱)',
|
||||
`menu_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '关联菜单ID(选填,对应 sys_menu.id)',
|
||||
`page_url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '提交时页面路径/URL(便于复现;可与 menu_id 并存)',
|
||||
`client_info` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '客户端摘要(UA/端类型等,可选)',
|
||||
`assignee_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '处理人用户ID(可空)',
|
||||
`image_count` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '正文附图数量(冗余)',
|
||||
`message_count` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '留言+回复总数(冗余,不含正文)',
|
||||
`last_message_at` timestamp NULL DEFAULT NULL COMMENT '最近一条留言时间(列表排序用)',
|
||||
`submitter_unread` tinyint UNSIGNED NOT NULL DEFAULT 0 COMMENT '提交人未读:0否 1是(处理方新留言后置1)',
|
||||
`handler_unread` tinyint UNSIGNED NOT NULL DEFAULT 1 COMMENT '处理方未读:0否 1是(新建/用户新留言置1)',
|
||||
`resolved_at` timestamp NULL DEFAULT NULL COMMENT '首次标记已解决时间',
|
||||
`closed_at` timestamp NULL DEFAULT NULL COMMENT '关闭时间',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint UNSIGNED NOT NULL COMMENT '提交人用户ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人用户ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_sys_feedback_company_status` (`company_id` ASC, `status` ASC, `update_time` DESC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_company_create_by` (`company_id` ASC, `create_by` ASC, `id` DESC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_menu` (`menu_id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_assignee` (`assignee_id` ASC, `status` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_last_message` (`company_id` ASC, `last_message_at` DESC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_handler_unread` (`company_id` ASC, `handler_unread` ASC, `id` DESC) USING BTREE,
|
||||
CONSTRAINT `fk_sys_feedback_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_menu` FOREIGN KEY (`menu_id`) REFERENCES `sys_menu` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_assignee` FOREIGN KEY (`assignee_id`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统-意见反馈主表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ========================================
|
||||
-- 反馈正文多图(关联 sys_file)
|
||||
-- ========================================
|
||||
CREATE TABLE `sys_feedback_images` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`feedback_id` bigint UNSIGNED NOT NULL COMMENT '反馈ID',
|
||||
`file_id` bigint UNSIGNED NOT NULL COMMENT '系统文件ID',
|
||||
`sort_order` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '展示顺序(小在前)',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '上传人(通常=反馈提交人)',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_sys_feedback_images_fb_file` (`feedback_id` ASC, `file_id` ASC) USING BTREE COMMENT '同一反馈内文件不重复',
|
||||
INDEX `idx_sys_feedback_images_feedback` (`feedback_id` ASC, `sort_order` ASC, `id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_images_file` (`file_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_sys_feedback_images_feedback` FOREIGN KEY (`feedback_id`) REFERENCES `sys_feedback` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_images_file` FOREIGN KEY (`file_id`) REFERENCES `sys_file` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_images_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统-意见反馈正文图片关联表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ========================================
|
||||
-- 反馈留言 / 回复
|
||||
-- parent_id IS NULL = 顶层留言
|
||||
-- parent_id 非空 = 回复某条留言(可多层;产品可限深)
|
||||
-- root_id = 所属顶层留言ID(顶层时 root_id = 自身 id,插入后回写或应用层写入)
|
||||
-- ========================================
|
||||
CREATE TABLE `sys_feedback_message` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '留言ID',
|
||||
`feedback_id` bigint UNSIGNED NOT NULL COMMENT '所属反馈ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID(冗余,便于权限过滤)',
|
||||
`parent_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '父留言ID;NULL=顶层留言',
|
||||
`root_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '顶层留言ID;顶层留言可等于自身id',
|
||||
`content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '留言正文',
|
||||
`author_role` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'USER' COMMENT '发言角色:USER提交侧 / HANDLER处理侧 / SYSTEM系统',
|
||||
`image_count` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '本条附图数量(冗余)',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint UNSIGNED NOT NULL COMMENT '发言人用户ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_feedback` (`feedback_id` ASC, `id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_root` (`feedback_id` ASC, `root_id` ASC, `id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_parent` (`parent_id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_company_author` (`company_id` ASC, `create_by` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_sys_feedback_message_feedback` FOREIGN KEY (`feedback_id`) REFERENCES `sys_feedback` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_parent` FOREIGN KEY (`parent_id`) REFERENCES `sys_feedback_message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_root` FOREIGN KEY (`root_id`) REFERENCES `sys_feedback_message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统-意见反馈留言/回复表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ========================================
|
||||
-- 留言多图(关联 sys_file)
|
||||
-- ========================================
|
||||
CREATE TABLE `sys_feedback_message_images` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`message_id` bigint UNSIGNED NOT NULL COMMENT '留言ID',
|
||||
`feedback_id` bigint UNSIGNED NOT NULL COMMENT '反馈ID(冗余,便于按单清理/查询)',
|
||||
`file_id` bigint UNSIGNED NOT NULL COMMENT '系统文件ID',
|
||||
`sort_order` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '展示顺序(小在前)',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '上传人',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_sys_feedback_message_images_msg_file` (`message_id` ASC, `file_id` ASC) USING BTREE COMMENT '同一留言内文件不重复',
|
||||
INDEX `idx_sys_feedback_message_images_msg` (`message_id` ASC, `sort_order` ASC, `id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_images_feedback` (`feedback_id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_images_file` (`file_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_sys_feedback_message_images_msg` FOREIGN KEY (`message_id`) REFERENCES `sys_feedback_message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_images_feedback` FOREIGN KEY (`feedback_id`) REFERENCES `sys_feedback` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_images_file` FOREIGN KEY (`file_id`) REFERENCES `sys_file` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_images_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统-意见反馈留言图片关联表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ========================================
|
||||
-- 权限码建议(落地时写入 sys_permission / 菜单,非本文件建表)
|
||||
-- sys:feedback:create 提交反馈
|
||||
-- sys:feedback:read 查看本公司反馈(普通用户仅自己的;管理员看全部——应用层区分)
|
||||
-- sys:feedback:handle 处理/回复/改状态(公司管理员或平台超管)
|
||||
-- sys:feedback:delete 删除反馈(建议仅管理员;已有留言时需确认策略)
|
||||
-- ========================================
|
||||
@@ -0,0 +1,172 @@
|
||||
-- 意见反馈:主表 / 正文图 / 留言 / 留言图 + 权限与菜单
|
||||
-- 用户侧菜单 SysFeedbackUser;处理侧菜单 SysFeedbackHandle(系统设置下)
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sys_feedback` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '反馈ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '所属公司ID',
|
||||
`title` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '标题',
|
||||
`content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '正文',
|
||||
`type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'OTHER' COMMENT '类型:BUG/FEATURE/QUESTION/COMPLAINT/OTHER',
|
||||
`status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'OPEN' COMMENT '状态:OPEN/PROCESSING/RESOLVED/CLOSED/REJECTED',
|
||||
`priority` tinyint UNSIGNED NOT NULL DEFAULT 2 COMMENT '优先级:1高 2中 3低',
|
||||
`contact` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '联系方式(选填)',
|
||||
`menu_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '关联菜单ID(选填)',
|
||||
`page_url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '提交时页面路径/URL',
|
||||
`client_info` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '客户端摘要',
|
||||
`assignee_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '处理人用户ID',
|
||||
`image_count` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '正文附图数量',
|
||||
`message_count` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '留言+回复总数',
|
||||
`last_message_at` timestamp NULL DEFAULT NULL COMMENT '最近留言时间',
|
||||
`submitter_unread` tinyint UNSIGNED NOT NULL DEFAULT 0 COMMENT '提交人未读',
|
||||
`handler_unread` tinyint UNSIGNED NOT NULL DEFAULT 1 COMMENT '处理方未读',
|
||||
`resolved_at` timestamp NULL DEFAULT NULL COMMENT '首次已解决时间',
|
||||
`closed_at` timestamp NULL DEFAULT NULL COMMENT '关闭时间',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint UNSIGNED NOT NULL COMMENT '提交人',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_sys_feedback_company_status` (`company_id` ASC, `status` ASC, `update_time` DESC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_company_create_by` (`company_id` ASC, `create_by` ASC, `id` DESC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_menu` (`menu_id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_assignee` (`assignee_id` ASC, `status` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_last_message` (`company_id` ASC, `last_message_at` DESC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_handler_unread` (`company_id` ASC, `handler_unread` ASC, `id` DESC) USING BTREE,
|
||||
CONSTRAINT `fk_sys_feedback_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_menu` FOREIGN KEY (`menu_id`) REFERENCES `sys_menu` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_assignee` FOREIGN KEY (`assignee_id`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统-意见反馈主表' ROW_FORMAT = Dynamic;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sys_feedback_images` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`feedback_id` bigint UNSIGNED NOT NULL COMMENT '反馈ID',
|
||||
`file_id` bigint UNSIGNED NOT NULL COMMENT '系统文件ID',
|
||||
`sort_order` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '展示顺序',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '上传人',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_sys_feedback_images_fb_file` (`feedback_id` ASC, `file_id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_images_feedback` (`feedback_id` ASC, `sort_order` ASC, `id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_images_file` (`file_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_sys_feedback_images_feedback` FOREIGN KEY (`feedback_id`) REFERENCES `sys_feedback` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_images_file` FOREIGN KEY (`file_id`) REFERENCES `sys_file` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_images_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统-意见反馈正文图片' ROW_FORMAT = Dynamic;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sys_feedback_message` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '留言ID',
|
||||
`feedback_id` bigint UNSIGNED NOT NULL COMMENT '所属反馈ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`parent_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '父留言ID',
|
||||
`root_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '顶层留言ID',
|
||||
`content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '留言正文',
|
||||
`author_role` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'USER' COMMENT 'USER/HANDLER/SYSTEM',
|
||||
`image_count` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '附图数量',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint UNSIGNED NOT NULL COMMENT '发言人',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_feedback` (`feedback_id` ASC, `id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_root` (`feedback_id` ASC, `root_id` ASC, `id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_parent` (`parent_id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_company_author` (`company_id` ASC, `create_by` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_sys_feedback_message_feedback` FOREIGN KEY (`feedback_id`) REFERENCES `sys_feedback` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_parent` FOREIGN KEY (`parent_id`) REFERENCES `sys_feedback_message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_root` FOREIGN KEY (`root_id`) REFERENCES `sys_feedback_message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统-意见反馈留言' ROW_FORMAT = Dynamic;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sys_feedback_message_images` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`message_id` bigint UNSIGNED NOT NULL COMMENT '留言ID',
|
||||
`feedback_id` bigint UNSIGNED NOT NULL COMMENT '反馈ID',
|
||||
`file_id` bigint UNSIGNED NOT NULL COMMENT '系统文件ID',
|
||||
`sort_order` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '展示顺序',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '上传人',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_sys_feedback_message_images_msg_file` (`message_id` ASC, `file_id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_images_msg` (`message_id` ASC, `sort_order` ASC, `id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_images_feedback` (`feedback_id` ASC) USING BTREE,
|
||||
INDEX `idx_sys_feedback_message_images_file` (`file_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_sys_feedback_message_images_msg` FOREIGN KEY (`message_id`) REFERENCES `sys_feedback_message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_images_feedback` FOREIGN KEY (`feedback_id`) REFERENCES `sys_feedback` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_images_file` FOREIGN KEY (`file_id`) REFERENCES `sys_file` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_feedback_message_images_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '系统-意见反馈留言图片' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- 权限:sys:feedback*
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 1600, (SELECT id FROM `sys_permission` WHERE `code` = 'sys' LIMIT 1), 'sys:feedback', '意见反馈', 'module', 1, '', 60
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 1600 OR `code` = 'sys:feedback');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 1601, (SELECT id FROM `sys_permission` WHERE `code` = 'sys:feedback' LIMIT 1), 'sys:feedback:read', '查看', 'api', 1, '用户侧本公司全员;处理侧超管/有权用户', 1
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 1601 OR `code` = 'sys:feedback:read');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 1602, (SELECT id FROM `sys_permission` WHERE `code` = 'sys:feedback' LIMIT 1), 'sys:feedback:create', '提交', 'api', 1, '', 2
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 1602 OR `code` = 'sys:feedback:create');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 1603, (SELECT id FROM `sys_permission` WHERE `code` = 'sys:feedback' LIMIT 1), 'sys:feedback:handle', '处理', 'api', 1, '改状态/指派;回复仅 assignee', 3
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 1603 OR `code` = 'sys:feedback:handle');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 1604, (SELECT id FROM `sys_permission` WHERE `code` = 'sys:feedback' LIMIT 1), 'sys:feedback:delete', '删除', 'api', 1, '仅管理员(公司已分配权限的角色)', 4
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 1604 OR `code` = 'sys:feedback:delete');
|
||||
|
||||
-- 用户侧菜单(顶级独立入口)
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 12100,
|
||||
NULL,
|
||||
0,
|
||||
'SysFeedbackUser',
|
||||
'意见反馈',
|
||||
'/feedback',
|
||||
'/sys/feedback/user/index',
|
||||
'',
|
||||
'lucide:message-square-plus',
|
||||
'menu',
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
12
|
||||
FROM DUAL
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 12100 OR `route_name` = 'SysFeedbackUser');
|
||||
|
||||
-- 处理侧菜单(系统设置下)
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 12101,
|
||||
(SELECT id FROM `sys_menu` WHERE `id` = 1 OR `title` = '系统设置' OR `route_name` = 'SysSettings' LIMIT 1),
|
||||
1,
|
||||
'SysFeedbackHandle',
|
||||
'反馈处理',
|
||||
'/sys/feedback/handle',
|
||||
'/sys/feedback/handle/index',
|
||||
'',
|
||||
'lucide:messages-square',
|
||||
'menu',
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
6
|
||||
FROM DUAL
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 12101 OR `route_name` = 'SysFeedbackHandle');
|
||||
|
||||
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||
SELECT m.id, p.id
|
||||
FROM `sys_menu` m
|
||||
JOIN `sys_permission` p ON p.code IN ('sys:feedback:read', 'sys:feedback:create')
|
||||
WHERE m.route_name = 'SysFeedbackUser';
|
||||
|
||||
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||
SELECT m.id, p.id
|
||||
FROM `sys_menu` m
|
||||
JOIN `sys_permission` p ON p.code IN ('sys:feedback:read', 'sys:feedback:handle', 'sys:feedback:delete')
|
||||
WHERE m.route_name = 'SysFeedbackHandle';
|
||||
@@ -0,0 +1,29 @@
|
||||
-- 反馈附图:文件可被多条反馈引用(sys_file 按哈希去重时同图同 id)
|
||||
-- 唯一约束改为「同一反馈/留言内不重复」
|
||||
-- MySQL:uk 被 FK 占用时,需先删 FK → 改索引 → 重建 FK
|
||||
|
||||
ALTER TABLE `sys_feedback_images`
|
||||
DROP FOREIGN KEY `fk_sys_feedback_images_file`;
|
||||
|
||||
ALTER TABLE `sys_feedback_images`
|
||||
DROP INDEX `uk_sys_feedback_images_file`,
|
||||
ADD UNIQUE INDEX `uk_sys_feedback_images_fb_file` (`feedback_id` ASC, `file_id` ASC) USING BTREE,
|
||||
ADD INDEX `idx_sys_feedback_images_file` (`file_id` ASC) USING BTREE;
|
||||
|
||||
ALTER TABLE `sys_feedback_images`
|
||||
ADD CONSTRAINT `fk_sys_feedback_images_file`
|
||||
FOREIGN KEY (`file_id`) REFERENCES `sys_file` (`id`)
|
||||
ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE `sys_feedback_message_images`
|
||||
DROP FOREIGN KEY `fk_sys_feedback_message_images_file`;
|
||||
|
||||
ALTER TABLE `sys_feedback_message_images`
|
||||
DROP INDEX `uk_sys_feedback_message_images_file`,
|
||||
ADD UNIQUE INDEX `uk_sys_feedback_message_images_msg_file` (`message_id` ASC, `file_id` ASC) USING BTREE,
|
||||
ADD INDEX `idx_sys_feedback_message_images_file` (`file_id` ASC) USING BTREE;
|
||||
|
||||
ALTER TABLE `sys_feedback_message_images`
|
||||
ADD CONSTRAINT `fk_sys_feedback_message_images_file`
|
||||
FOREIGN KEY (`file_id`) REFERENCES `sys_file` (`id`)
|
||||
ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto.CreateFeedbackMessageDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto.FeedbackFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto.UpdateFeedbackAssigneeDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto.UpdateFeedbackStatusDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackDetailVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackMessageVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.service.FeedbackService;
|
||||
|
||||
/**
|
||||
* 意见反馈-处理侧接口(超管全量 / 公司用户本公司)。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/sys/feedback/handle")
|
||||
public class FeedbackHandleController {
|
||||
|
||||
private final FeedbackService feedbackService;
|
||||
|
||||
public FeedbackHandleController(FeedbackService feedbackService) {
|
||||
this.feedbackService = feedbackService;
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "sys:feedback:handle", description = "处理侧反馈列表", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<FeedbackVO>> list(
|
||||
@Valid @RequestBody PageQueryDTO<FeedbackFilterDTO> query) {
|
||||
return ApiResponse.success("获取反馈列表成功", feedbackService.listForHandle(query));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@RequirePermission(value = "sys:feedback:handle", description = "处理侧反馈详情", allowSuper = true)
|
||||
public ApiResponse<FeedbackDetailVO> detail(@PathVariable Long id) {
|
||||
return ApiResponse.success("获取反馈详情成功", feedbackService.getDetailForHandle(id));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/status")
|
||||
@RequirePermission(value = "sys:feedback:handle", description = "更新反馈状态", allowSuper = true)
|
||||
public ApiResponse<Void> updateStatus(
|
||||
@PathVariable Long id, @Valid @RequestBody UpdateFeedbackStatusDTO dto) {
|
||||
feedbackService.updateStatus(id, dto);
|
||||
return ApiResponse.success("状态更新成功");
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/assignee")
|
||||
@RequirePermission(value = "sys:feedback:handle", description = "指派处理人", allowSuper = true)
|
||||
public ApiResponse<Void> updateAssignee(
|
||||
@PathVariable Long id, @Valid @RequestBody UpdateFeedbackAssigneeDTO dto) {
|
||||
feedbackService.updateAssignee(id, dto);
|
||||
return ApiResponse.success("指派成功");
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/messages")
|
||||
@RequirePermission(value = "sys:feedback:handle", description = "处理人回复", allowSuper = true)
|
||||
public ApiResponse<FeedbackMessageVO> addMessage(
|
||||
@PathVariable Long id, @Valid @RequestBody CreateFeedbackMessageDTO dto) {
|
||||
return ApiResponse.success("回复成功", feedbackService.addHandlerMessage(id, dto));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@RequirePermission(value = "sys:feedback:delete", description = "删除反馈", allowSuper = true)
|
||||
public ApiResponse<Void> delete(@PathVariable Long id) {
|
||||
feedbackService.delete(id);
|
||||
return ApiResponse.success("删除成功");
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/read")
|
||||
@RequirePermission(value = "sys:feedback:handle", description = "标记处理方已读", allowSuper = true)
|
||||
public ApiResponse<Void> markRead(@PathVariable Long id) {
|
||||
feedbackService.markHandlerRead(id);
|
||||
return ApiResponse.success("已读成功");
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto.CreateFeedbackDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto.CreateFeedbackMessageDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto.FeedbackFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackDetailVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackMessageVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.service.FeedbackService;
|
||||
|
||||
/**
|
||||
* 意见反馈-用户侧接口(本公司可见)。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/sys/feedback")
|
||||
public class FeedbackUserController {
|
||||
|
||||
private final FeedbackService feedbackService;
|
||||
|
||||
public FeedbackUserController(FeedbackService feedbackService) {
|
||||
this.feedbackService = feedbackService;
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "sys:feedback:read", description = "查看意见反馈", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<FeedbackVO>> list(
|
||||
@Valid @RequestBody PageQueryDTO<FeedbackFilterDTO> query) {
|
||||
return ApiResponse.success("获取反馈列表成功", feedbackService.listForUser(query));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@RequirePermission(value = "sys:feedback:read", description = "查看意见反馈详情", allowSuper = true)
|
||||
public ApiResponse<FeedbackDetailVO> detail(@PathVariable Long id) {
|
||||
return ApiResponse.success("获取反馈详情成功", feedbackService.getDetailForUser(id));
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@RequirePermission(value = "sys:feedback:create", description = "提交意见反馈", allowSuper = true)
|
||||
public ApiResponse<FeedbackDetailVO> create(@Valid @RequestBody CreateFeedbackDTO dto) {
|
||||
return ApiResponse.success("提交反馈成功", feedbackService.create(dto));
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/messages")
|
||||
@RequirePermission(value = "sys:feedback:read", description = "反馈留言/回复", allowSuper = true)
|
||||
public ApiResponse<FeedbackMessageVO> addMessage(
|
||||
@PathVariable Long id, @Valid @RequestBody CreateFeedbackMessageDTO dto) {
|
||||
return ApiResponse.success("留言成功", feedbackService.addUserMessage(id, dto));
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/close")
|
||||
@RequirePermission(value = "sys:feedback:create", description = "关闭自己的反馈", allowSuper = true)
|
||||
public ApiResponse<Void> close(@PathVariable Long id) {
|
||||
feedbackService.closeByUser(id);
|
||||
return ApiResponse.success("关闭成功");
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/read")
|
||||
@RequirePermission(value = "sys:feedback:read", description = "标记提交人已读", allowSuper = true)
|
||||
public ApiResponse<Void> markRead(@PathVariable Long id) {
|
||||
feedbackService.markSubmitterRead(id);
|
||||
return ApiResponse.success("已读成功");
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.po.FeedbackImagePO;
|
||||
|
||||
/**
|
||||
* 反馈正文图片 Mapper。
|
||||
*/
|
||||
@Mapper
|
||||
public interface FeedbackImageMapper extends BaseMapper<FeedbackImagePO> {
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.po.FeedbackPO;
|
||||
|
||||
/**
|
||||
* 意见反馈主表 Mapper。
|
||||
*/
|
||||
@Mapper
|
||||
public interface FeedbackMapper extends BaseMapper<FeedbackPO> {
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.po.FeedbackMessageImagePO;
|
||||
|
||||
/**
|
||||
* 留言图片 Mapper。
|
||||
*/
|
||||
@Mapper
|
||||
public interface FeedbackMessageImageMapper extends BaseMapper<FeedbackMessageImagePO> {
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.po.FeedbackMessagePO;
|
||||
|
||||
/**
|
||||
* 反馈留言 Mapper。
|
||||
*/
|
||||
@Mapper
|
||||
public interface FeedbackMessageMapper extends BaseMapper<FeedbackMessagePO> {
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 提交意见反馈。
|
||||
*/
|
||||
@Data
|
||||
public class CreateFeedbackDTO {
|
||||
|
||||
@NotBlank(message = "标题不能为空")
|
||||
@Size(max = 200, message = "标题最长200字")
|
||||
private String title;
|
||||
|
||||
@NotBlank(message = "正文不能为空")
|
||||
private String content;
|
||||
|
||||
/** BUG/FEATURE/QUESTION/COMPLAINT/OTHER,默认 OTHER */
|
||||
private String type;
|
||||
|
||||
/** 1高 2中 3低,默认 2 */
|
||||
private Integer priority;
|
||||
|
||||
@Size(max = 100, message = "联系方式最长100字")
|
||||
private String contact;
|
||||
|
||||
private Long menuId;
|
||||
|
||||
@Size(max = 500, message = "页面路径最长500字")
|
||||
private String pageUrl;
|
||||
|
||||
@Size(max = 500, message = "客户端信息最长500字")
|
||||
private String clientInfo;
|
||||
|
||||
/** 正文附图 fileId 列表 */
|
||||
private List<Long> fileIds;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 新增反馈留言/回复。
|
||||
*/
|
||||
@Data
|
||||
public class CreateFeedbackMessageDTO {
|
||||
|
||||
@NotBlank(message = "留言内容不能为空")
|
||||
private String content;
|
||||
|
||||
/** 父留言ID;空则为顶层留言 */
|
||||
private Long parentId;
|
||||
|
||||
/** 附图 fileId 列表 */
|
||||
private List<Long> fileIds;
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 反馈列表筛选条件。
|
||||
*/
|
||||
@Data
|
||||
public class FeedbackFilterDTO {
|
||||
|
||||
/** 超管处理侧可按公司过滤 */
|
||||
private Long companyId;
|
||||
|
||||
private String status;
|
||||
|
||||
private String type;
|
||||
|
||||
private Integer priority;
|
||||
|
||||
private Long createBy;
|
||||
|
||||
private Long assigneeId;
|
||||
|
||||
private Long menuId;
|
||||
|
||||
/** 标题模糊 */
|
||||
private String title;
|
||||
|
||||
/** 处理方未读:0/1 */
|
||||
private Integer handlerUnread;
|
||||
|
||||
/** 提交人未读:0/1 */
|
||||
private Integer submitterUnread;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 处理侧指派处理人。
|
||||
*/
|
||||
@Data
|
||||
public class UpdateFeedbackAssigneeDTO {
|
||||
|
||||
@NotNull(message = "处理人不能为空")
|
||||
private Long assigneeId;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 处理侧更新反馈状态。
|
||||
*/
|
||||
@Data
|
||||
public class UpdateFeedbackStatusDTO {
|
||||
|
||||
/** PROCESSING / RESOLVED / CLOSED / REJECTED(及 OPEN) */
|
||||
@NotBlank(message = "状态不能为空")
|
||||
private String status;
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 反馈正文图片关联(sys_file.id)。
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_feedback_images")
|
||||
public class FeedbackImagePO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("feedback_id")
|
||||
private Long feedbackId;
|
||||
|
||||
@TableField("file_id")
|
||||
private Long fileId;
|
||||
|
||||
@TableField("sort_order")
|
||||
private Integer sortOrder;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 留言图片关联(sys_file.id)。
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_feedback_message_images")
|
||||
public class FeedbackMessageImagePO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("message_id")
|
||||
private Long messageId;
|
||||
|
||||
@TableField("feedback_id")
|
||||
private Long feedbackId;
|
||||
|
||||
@TableField("file_id")
|
||||
private Long fileId;
|
||||
|
||||
@TableField("sort_order")
|
||||
private Integer sortOrder;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 反馈留言/回复;parent_id + root_id 组成树。
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_feedback_message")
|
||||
public class FeedbackMessagePO {
|
||||
|
||||
public static final String AUTHOR_ROLE_USER = "USER";
|
||||
public static final String AUTHOR_ROLE_HANDLER = "HANDLER";
|
||||
public static final String AUTHOR_ROLE_SYSTEM = "SYSTEM";
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("feedback_id")
|
||||
private Long feedbackId;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
/** NULL=顶层留言 */
|
||||
@TableField("parent_id")
|
||||
private Long parentId;
|
||||
|
||||
/** 顶层留言ID;顶层时等于自身 id */
|
||||
@TableField("root_id")
|
||||
private Long rootId;
|
||||
|
||||
@TableField("content")
|
||||
private String content;
|
||||
|
||||
/** USER / HANDLER / SYSTEM */
|
||||
@TableField("author_role")
|
||||
private String authorRole;
|
||||
|
||||
@TableField("image_count")
|
||||
private Integer imageCount;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 意见反馈主表实体。
|
||||
* 公司隔离;未读与计数字段由业务维护。
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_feedback")
|
||||
public class FeedbackPO {
|
||||
|
||||
public static final String STATUS_OPEN = "OPEN";
|
||||
public static final String STATUS_PROCESSING = "PROCESSING";
|
||||
public static final String STATUS_RESOLVED = "RESOLVED";
|
||||
public static final String STATUS_CLOSED = "CLOSED";
|
||||
public static final String STATUS_REJECTED = "REJECTED";
|
||||
|
||||
public static final String TYPE_BUG = "BUG";
|
||||
public static final String TYPE_FEATURE = "FEATURE";
|
||||
public static final String TYPE_QUESTION = "QUESTION";
|
||||
public static final String TYPE_COMPLAINT = "COMPLAINT";
|
||||
public static final String TYPE_OTHER = "OTHER";
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("title")
|
||||
private String title;
|
||||
|
||||
@TableField("content")
|
||||
private String content;
|
||||
|
||||
/** BUG/FEATURE/QUESTION/COMPLAINT/OTHER */
|
||||
@TableField("type")
|
||||
private String type;
|
||||
|
||||
/** OPEN/PROCESSING/RESOLVED/CLOSED/REJECTED */
|
||||
@TableField("status")
|
||||
private String status;
|
||||
|
||||
/** 1高 2中 3低 */
|
||||
@TableField("priority")
|
||||
private Integer priority;
|
||||
|
||||
@TableField("contact")
|
||||
private String contact;
|
||||
|
||||
@TableField("menu_id")
|
||||
private Long menuId;
|
||||
|
||||
@TableField("page_url")
|
||||
private String pageUrl;
|
||||
|
||||
@TableField("client_info")
|
||||
private String clientInfo;
|
||||
|
||||
@TableField("assignee_id")
|
||||
private Long assigneeId;
|
||||
|
||||
@TableField("image_count")
|
||||
private Integer imageCount;
|
||||
|
||||
@TableField("message_count")
|
||||
private Integer messageCount;
|
||||
|
||||
@TableField("last_message_at")
|
||||
private LocalDateTime lastMessageAt;
|
||||
|
||||
@TableField("submitter_unread")
|
||||
private Integer submitterUnread;
|
||||
|
||||
@TableField("handler_unread")
|
||||
private Integer handlerUnread;
|
||||
|
||||
@TableField("resolved_at")
|
||||
private LocalDateTime resolvedAt;
|
||||
|
||||
@TableField("closed_at")
|
||||
private LocalDateTime closedAt;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 意见反馈详情(含留言树)。
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class FeedbackDetailVO extends FeedbackVO {
|
||||
|
||||
/** 留言树(顶层节点含 children) */
|
||||
private List<FeedbackMessageVO> messages;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 反馈附图(含访问地址,详情接口直接下发)。
|
||||
*/
|
||||
@Data
|
||||
public class FeedbackFileVO {
|
||||
private Long fileId;
|
||||
private String accessUrl;
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 反馈留言/回复节点。
|
||||
*/
|
||||
@Data
|
||||
public class FeedbackMessageVO {
|
||||
|
||||
private Long id;
|
||||
private Long feedbackId;
|
||||
private Long companyId;
|
||||
private Long parentId;
|
||||
private Long rootId;
|
||||
private String content;
|
||||
private String authorRole;
|
||||
private Integer imageCount;
|
||||
private LocalDateTime createTime;
|
||||
private Long createBy;
|
||||
private String creatorName;
|
||||
private List<Long> fileIds;
|
||||
/** 附图含访问地址 */
|
||||
private List<FeedbackFileVO> images;
|
||||
private List<FeedbackMessageVO> children;
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 意见反馈列表项。
|
||||
*/
|
||||
@Data
|
||||
public class FeedbackVO {
|
||||
|
||||
private Long id;
|
||||
private Long companyId;
|
||||
private String title;
|
||||
private String content;
|
||||
private String type;
|
||||
private String status;
|
||||
private Integer priority;
|
||||
private String contact;
|
||||
private Long menuId;
|
||||
private String menuTitle;
|
||||
private String pageUrl;
|
||||
private String clientInfo;
|
||||
private Long assigneeId;
|
||||
private String assigneeName;
|
||||
private Integer imageCount;
|
||||
private Integer messageCount;
|
||||
private LocalDateTime lastMessageAt;
|
||||
private Integer submitterUnread;
|
||||
private Integer handlerUnread;
|
||||
private LocalDateTime resolvedAt;
|
||||
private LocalDateTime closedAt;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Long createBy;
|
||||
private String creatorName;
|
||||
/** 附图 fileId(兼容) */
|
||||
private List<Long> fileIds;
|
||||
/** 附图含访问地址(详情优先用) */
|
||||
private List<FeedbackFileVO> images;
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto.*;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackDetailVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackMessageVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackVO;
|
||||
|
||||
/**
|
||||
* 意见反馈用例:用户侧提交/留言与处理侧指派/状态/回复。
|
||||
*/
|
||||
public interface FeedbackService {
|
||||
|
||||
PageResultVO<FeedbackVO> listForUser(PageQueryDTO<FeedbackFilterDTO> query);
|
||||
|
||||
FeedbackDetailVO getDetailForUser(Long id);
|
||||
|
||||
FeedbackDetailVO create(CreateFeedbackDTO dto);
|
||||
|
||||
FeedbackMessageVO addUserMessage(Long feedbackId, CreateFeedbackMessageDTO dto);
|
||||
|
||||
void closeByUser(Long id);
|
||||
|
||||
void markSubmitterRead(Long id);
|
||||
|
||||
PageResultVO<FeedbackVO> listForHandle(PageQueryDTO<FeedbackFilterDTO> query);
|
||||
|
||||
FeedbackDetailVO getDetailForHandle(Long id);
|
||||
|
||||
void updateStatus(Long id, UpdateFeedbackStatusDTO dto);
|
||||
|
||||
void updateAssignee(Long id, UpdateFeedbackAssigneeDTO dto);
|
||||
|
||||
FeedbackMessageVO addHandlerMessage(Long feedbackId, CreateFeedbackMessageDTO dto);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void markHandlerRead(Long id);
|
||||
}
|
||||
+672
@@ -0,0 +1,672 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.feedback.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.mapper.FeedbackImageMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.mapper.FeedbackMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.mapper.FeedbackMessageImageMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.mapper.FeedbackMessageMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.dto.*;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.po.FeedbackImagePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.po.FeedbackMessageImagePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.po.FeedbackMessagePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.po.FeedbackPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackDetailVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackFileVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackMessageVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.model.vo.FeedbackVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.feedback.service.FeedbackService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.mapper.SysFileMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.po.SysFilePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.menu.mapper.MenuMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.menu.model.po.MenuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.mapper.UserMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
import top.xyquan.ecomdmbbackend.utils.SysFileUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 意见反馈业务实现:公司隔离、未读与留言树维护。
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class FeedbackServiceImpl implements FeedbackService {
|
||||
|
||||
private static final Set<String> ALLOWED_TYPES = Set.of(
|
||||
FeedbackPO.TYPE_BUG, FeedbackPO.TYPE_FEATURE, FeedbackPO.TYPE_QUESTION,
|
||||
FeedbackPO.TYPE_COMPLAINT, FeedbackPO.TYPE_OTHER);
|
||||
|
||||
private static final Set<String> HANDLE_STATUSES = Set.of(
|
||||
FeedbackPO.STATUS_OPEN, FeedbackPO.STATUS_PROCESSING, FeedbackPO.STATUS_RESOLVED,
|
||||
FeedbackPO.STATUS_CLOSED, FeedbackPO.STATUS_REJECTED);
|
||||
|
||||
private final FeedbackMapper feedbackMapper;
|
||||
private final FeedbackImageMapper feedbackImageMapper;
|
||||
private final FeedbackMessageMapper feedbackMessageMapper;
|
||||
private final FeedbackMessageImageMapper feedbackMessageImageMapper;
|
||||
private final MenuMapper menuMapper;
|
||||
private final UserMapper userMapper;
|
||||
private final SysFileMapper sysFileMapper;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
@Override
|
||||
public PageResultVO<FeedbackVO> listForUser(PageQueryDTO<FeedbackFilterDTO> query) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
return pageFeedback(query, companyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeedbackDetailVO getDetailForUser(Long id) {
|
||||
FeedbackPO po = requireVisibleForUser(id);
|
||||
return toDetailVO(po);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public FeedbackDetailVO create(CreateFeedbackDTO dto) {
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
validateMenuId(dto.getMenuId());
|
||||
|
||||
FeedbackPO po = new FeedbackPO();
|
||||
po.setCompanyId(companyId);
|
||||
po.setTitle(dto.getTitle().trim());
|
||||
po.setContent(dto.getContent());
|
||||
po.setType(normalizeType(dto.getType()));
|
||||
po.setStatus(FeedbackPO.STATUS_OPEN);
|
||||
po.setPriority(dto.getPriority() != null ? dto.getPriority() : 2);
|
||||
po.setContact(dto.getContact());
|
||||
po.setMenuId(dto.getMenuId());
|
||||
po.setPageUrl(dto.getPageUrl());
|
||||
po.setClientInfo(dto.getClientInfo());
|
||||
po.setImageCount(0);
|
||||
po.setMessageCount(0);
|
||||
po.setSubmitterUnread(0);
|
||||
po.setHandlerUnread(1);
|
||||
po.setCreateBy(userId);
|
||||
po.setUpdateBy(userId);
|
||||
feedbackMapper.insert(po);
|
||||
|
||||
int imageCount = saveFeedbackImages(po.getId(), dto.getFileIds(), userId);
|
||||
if (imageCount > 0) {
|
||||
po.setImageCount(imageCount);
|
||||
feedbackMapper.updateById(po);
|
||||
}
|
||||
return toDetailVO(feedbackMapper.selectById(po.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public FeedbackMessageVO addUserMessage(Long feedbackId, CreateFeedbackMessageDTO dto) {
|
||||
FeedbackPO feedback = requireVisibleForUser(feedbackId);
|
||||
FeedbackMessagePO message = insertMessage(
|
||||
feedback, dto, FeedbackMessagePO.AUTHOR_ROLE_USER, currentUserContext.getCurrentUserId());
|
||||
|
||||
// 用户留言:处理方未读;已解决后不重开状态
|
||||
int nextCount = (feedback.getMessageCount() != null ? feedback.getMessageCount() : 0) + 1;
|
||||
LambdaUpdateWrapper<FeedbackPO> uw = new LambdaUpdateWrapper<>();
|
||||
uw.eq(FeedbackPO::getId, feedbackId)
|
||||
.set(FeedbackPO::getHandlerUnread, 1)
|
||||
.set(FeedbackPO::getMessageCount, nextCount)
|
||||
.set(FeedbackPO::getLastMessageAt, message.getCreateTime() != null
|
||||
? message.getCreateTime() : LocalDateTime.now())
|
||||
.set(FeedbackPO::getUpdateBy, currentUserContext.getCurrentUserId());
|
||||
feedbackMapper.update(null, uw);
|
||||
return toMessageVO(message, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void closeByUser(Long id) {
|
||||
FeedbackPO po = requireVisibleForUser(id);
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
if (!Objects.equals(po.getCreateBy(), userId)) {
|
||||
throw new BusinessException("仅提交人可关闭自己的反馈");
|
||||
}
|
||||
if (!FeedbackPO.STATUS_OPEN.equals(po.getStatus())) {
|
||||
throw new BusinessException("仅未开始处理的反馈可关闭");
|
||||
}
|
||||
LambdaUpdateWrapper<FeedbackPO> uw = new LambdaUpdateWrapper<>();
|
||||
uw.eq(FeedbackPO::getId, id)
|
||||
.set(FeedbackPO::getStatus, FeedbackPO.STATUS_CLOSED)
|
||||
.set(FeedbackPO::getClosedAt, LocalDateTime.now())
|
||||
.set(FeedbackPO::getUpdateBy, userId);
|
||||
feedbackMapper.update(null, uw);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void markSubmitterRead(Long id) {
|
||||
FeedbackPO po = requireVisibleForUser(id);
|
||||
if (!Objects.equals(po.getCreateBy(), currentUserContext.getCurrentUserId())) {
|
||||
return;
|
||||
}
|
||||
LambdaUpdateWrapper<FeedbackPO> uw = new LambdaUpdateWrapper<>();
|
||||
uw.eq(FeedbackPO::getId, id).set(FeedbackPO::getSubmitterUnread, 0);
|
||||
feedbackMapper.update(null, uw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<FeedbackVO> listForHandle(PageQueryDTO<FeedbackFilterDTO> query) {
|
||||
Long companyScope = resolveHandleCompanyScope(query != null ? query.getFilters() : null);
|
||||
return pageFeedback(query, companyScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeedbackDetailVO getDetailForHandle(Long id) {
|
||||
FeedbackPO po = requireVisibleForHandle(id);
|
||||
return toDetailVO(po);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateStatus(Long id, UpdateFeedbackStatusDTO dto) {
|
||||
FeedbackPO po = requireVisibleForHandle(id);
|
||||
String status = dto.getStatus().trim().toUpperCase(Locale.ROOT);
|
||||
if (!HANDLE_STATUSES.contains(status)) {
|
||||
throw new BusinessException("无效的反馈状态");
|
||||
}
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LambdaUpdateWrapper<FeedbackPO> uw = new LambdaUpdateWrapper<>();
|
||||
uw.eq(FeedbackPO::getId, id)
|
||||
.set(FeedbackPO::getStatus, status)
|
||||
.set(FeedbackPO::getUpdateBy, userId);
|
||||
if (FeedbackPO.STATUS_RESOLVED.equals(status) && po.getResolvedAt() == null) {
|
||||
uw.set(FeedbackPO::getResolvedAt, now);
|
||||
}
|
||||
if (FeedbackPO.STATUS_CLOSED.equals(status) || FeedbackPO.STATUS_REJECTED.equals(status)) {
|
||||
uw.set(FeedbackPO::getClosedAt, now);
|
||||
}
|
||||
feedbackMapper.update(null, uw);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateAssignee(Long id, UpdateFeedbackAssigneeDTO dto) {
|
||||
requireVisibleForHandle(id);
|
||||
UserPO assignee = userMapper.selectById(dto.getAssigneeId());
|
||||
if (assignee == null) {
|
||||
throw new BusinessException("处理人不存在");
|
||||
}
|
||||
LambdaUpdateWrapper<FeedbackPO> uw = new LambdaUpdateWrapper<>();
|
||||
uw.eq(FeedbackPO::getId, id)
|
||||
.set(FeedbackPO::getAssigneeId, dto.getAssigneeId())
|
||||
.set(FeedbackPO::getUpdateBy, currentUserContext.getCurrentUserId());
|
||||
feedbackMapper.update(null, uw);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public FeedbackMessageVO addHandlerMessage(Long feedbackId, CreateFeedbackMessageDTO dto) {
|
||||
FeedbackPO feedback = requireVisibleForHandle(feedbackId);
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
if (feedback.getAssigneeId() == null || !Objects.equals(feedback.getAssigneeId(), userId)) {
|
||||
throw new BusinessException("仅当前处理人可回复");
|
||||
}
|
||||
FeedbackMessagePO message = insertMessage(
|
||||
feedback, dto, FeedbackMessagePO.AUTHOR_ROLE_HANDLER, userId);
|
||||
|
||||
int nextCount = (feedback.getMessageCount() != null ? feedback.getMessageCount() : 0) + 1;
|
||||
LambdaUpdateWrapper<FeedbackPO> uw = new LambdaUpdateWrapper<>();
|
||||
uw.eq(FeedbackPO::getId, feedbackId)
|
||||
.set(FeedbackPO::getSubmitterUnread, 1)
|
||||
.set(FeedbackPO::getMessageCount, nextCount)
|
||||
.set(FeedbackPO::getLastMessageAt, message.getCreateTime() != null
|
||||
? message.getCreateTime() : LocalDateTime.now())
|
||||
.set(FeedbackPO::getUpdateBy, userId);
|
||||
feedbackMapper.update(null, uw);
|
||||
return toMessageVO(message, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
requireVisibleForHandle(id);
|
||||
// 关联图与留言由 FK CASCADE 清理
|
||||
feedbackMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void markHandlerRead(Long id) {
|
||||
requireVisibleForHandle(id);
|
||||
LambdaUpdateWrapper<FeedbackPO> uw = new LambdaUpdateWrapper<>();
|
||||
uw.eq(FeedbackPO::getId, id).set(FeedbackPO::getHandlerUnread, 0);
|
||||
feedbackMapper.update(null, uw);
|
||||
}
|
||||
|
||||
// ---------- 可见性 ----------
|
||||
|
||||
private FeedbackPO requireVisibleForUser(Long id) {
|
||||
FeedbackPO po = feedbackMapper.selectById(id);
|
||||
if (po == null) {
|
||||
throw new BusinessException("反馈不存在");
|
||||
}
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
if (!Objects.equals(po.getCompanyId(), companyId)) {
|
||||
throw new BusinessException("无权查看该反馈");
|
||||
}
|
||||
return po;
|
||||
}
|
||||
|
||||
private FeedbackPO requireVisibleForHandle(Long id) {
|
||||
FeedbackPO po = feedbackMapper.selectById(id);
|
||||
if (po == null) {
|
||||
throw new BusinessException("反馈不存在");
|
||||
}
|
||||
if (currentUserContext.isCurrentUserSuper()) {
|
||||
return po;
|
||||
}
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
if (!Objects.equals(po.getCompanyId(), companyId)) {
|
||||
throw new BusinessException("无权查看该反馈");
|
||||
}
|
||||
return po;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理侧公司范围:超管可看全部(filters.companyId 可选);公司用户仅本公司。
|
||||
*/
|
||||
private Long resolveHandleCompanyScope(FeedbackFilterDTO filters) {
|
||||
if (currentUserContext.isCurrentUserSuper()) {
|
||||
return filters != null ? filters.getCompanyId() : null;
|
||||
}
|
||||
return currentUserContext.getCurrentCompanyId();
|
||||
}
|
||||
|
||||
// ---------- 查询 ----------
|
||||
|
||||
private PageResultVO<FeedbackVO> pageFeedback(
|
||||
PageQueryDTO<FeedbackFilterDTO> query, Long companyScope) {
|
||||
int pageNum = query.getPage() != null ? query.getPage() : 1;
|
||||
int pageSize = query.getPageSize() != null ? query.getPageSize() : 10;
|
||||
Page<FeedbackPO> page = new Page<>(pageNum, pageSize);
|
||||
LambdaQueryWrapper<FeedbackPO> wrapper = new LambdaQueryWrapper<>();
|
||||
if (companyScope != null) {
|
||||
wrapper.eq(FeedbackPO::getCompanyId, companyScope);
|
||||
}
|
||||
FeedbackFilterDTO filter = query.getFilters();
|
||||
if (filter != null) {
|
||||
if (StringUtils.hasText(filter.getStatus())) {
|
||||
wrapper.eq(FeedbackPO::getStatus, filter.getStatus().trim());
|
||||
}
|
||||
if (StringUtils.hasText(filter.getType())) {
|
||||
wrapper.eq(FeedbackPO::getType, filter.getType().trim());
|
||||
}
|
||||
if (filter.getPriority() != null) {
|
||||
wrapper.eq(FeedbackPO::getPriority, filter.getPriority());
|
||||
}
|
||||
if (filter.getCreateBy() != null) {
|
||||
wrapper.eq(FeedbackPO::getCreateBy, filter.getCreateBy());
|
||||
}
|
||||
if (filter.getAssigneeId() != null) {
|
||||
wrapper.eq(FeedbackPO::getAssigneeId, filter.getAssigneeId());
|
||||
}
|
||||
if (filter.getMenuId() != null) {
|
||||
wrapper.eq(FeedbackPO::getMenuId, filter.getMenuId());
|
||||
}
|
||||
if (StringUtils.hasText(filter.getTitle())) {
|
||||
wrapper.like(FeedbackPO::getTitle, filter.getTitle().trim());
|
||||
}
|
||||
if (filter.getHandlerUnread() != null) {
|
||||
wrapper.eq(FeedbackPO::getHandlerUnread, filter.getHandlerUnread());
|
||||
}
|
||||
if (filter.getSubmitterUnread() != null) {
|
||||
wrapper.eq(FeedbackPO::getSubmitterUnread, filter.getSubmitterUnread());
|
||||
}
|
||||
}
|
||||
wrapper.orderByDesc(FeedbackPO::getUpdateTime).orderByDesc(FeedbackPO::getId);
|
||||
IPage<FeedbackPO> result = feedbackMapper.selectPage(page, wrapper);
|
||||
List<FeedbackVO> vos = result.getRecords().stream()
|
||||
.map(po -> toListVO(po, false))
|
||||
.collect(Collectors.toList());
|
||||
fillNames(vos);
|
||||
return PageResultVO.create(vos, result.getTotal(), (int) result.getCurrent(), (int) result.getSize());
|
||||
}
|
||||
|
||||
// ---------- 留言 ----------
|
||||
|
||||
private FeedbackMessagePO insertMessage(
|
||||
FeedbackPO feedback, CreateFeedbackMessageDTO dto, String authorRole, Long userId) {
|
||||
Long parentId = dto.getParentId();
|
||||
Long rootId = null;
|
||||
if (parentId != null) {
|
||||
FeedbackMessagePO parent = feedbackMessageMapper.selectById(parentId);
|
||||
if (parent == null || !Objects.equals(parent.getFeedbackId(), feedback.getId())) {
|
||||
throw new BusinessException("父留言不存在或不属于该反馈");
|
||||
}
|
||||
rootId = parent.getRootId() != null ? parent.getRootId() : parent.getId();
|
||||
}
|
||||
|
||||
FeedbackMessagePO message = new FeedbackMessagePO();
|
||||
message.setFeedbackId(feedback.getId());
|
||||
message.setCompanyId(feedback.getCompanyId());
|
||||
message.setParentId(parentId);
|
||||
message.setRootId(rootId);
|
||||
message.setContent(dto.getContent());
|
||||
message.setAuthorRole(authorRole);
|
||||
message.setImageCount(0);
|
||||
message.setCreateBy(userId);
|
||||
message.setUpdateBy(userId);
|
||||
feedbackMessageMapper.insert(message);
|
||||
|
||||
// 顶层留言:插入后回写 root_id = id
|
||||
if (parentId == null) {
|
||||
message.setRootId(message.getId());
|
||||
feedbackMessageMapper.updateById(message);
|
||||
}
|
||||
|
||||
int imageCount = saveMessageImages(message.getId(), feedback.getId(), dto.getFileIds(), userId);
|
||||
if (imageCount > 0) {
|
||||
message.setImageCount(imageCount);
|
||||
feedbackMessageMapper.updateById(message);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
// ---------- 图片 ----------
|
||||
|
||||
private int saveFeedbackImages(Long feedbackId, List<Long> fileIds, Long userId) {
|
||||
List<Long> distinct = distinctFileIds(fileIds);
|
||||
if (distinct.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int order = 0;
|
||||
for (Long fileId : distinct) {
|
||||
FeedbackImagePO image = new FeedbackImagePO();
|
||||
image.setFeedbackId(feedbackId);
|
||||
image.setFileId(fileId);
|
||||
image.setSortOrder(order++);
|
||||
image.setCreateBy(userId);
|
||||
feedbackImageMapper.insert(image);
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
private int saveMessageImages(Long messageId, Long feedbackId, List<Long> fileIds, Long userId) {
|
||||
List<Long> distinct = distinctFileIds(fileIds);
|
||||
if (distinct.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int order = 0;
|
||||
for (Long fileId : distinct) {
|
||||
FeedbackMessageImagePO image = new FeedbackMessageImagePO();
|
||||
image.setMessageId(messageId);
|
||||
image.setFeedbackId(feedbackId);
|
||||
image.setFileId(fileId);
|
||||
image.setSortOrder(order++);
|
||||
image.setCreateBy(userId);
|
||||
feedbackMessageImageMapper.insert(image);
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
/** 去重并去掉空 id,保持首次出现顺序 */
|
||||
private static List<Long> distinctFileIds(List<Long> fileIds) {
|
||||
if (CollectionUtils.isEmpty(fileIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
LinkedHashSet<Long> set = new LinkedHashSet<>();
|
||||
for (Long fileId : fileIds) {
|
||||
if (fileId != null) {
|
||||
set.add(fileId);
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(set);
|
||||
}
|
||||
|
||||
private void validateMenuId(Long menuId) {
|
||||
if (menuId == null) {
|
||||
return;
|
||||
}
|
||||
MenuPO menu = menuMapper.selectById(menuId);
|
||||
if (menu == null) {
|
||||
throw new BusinessException("关联菜单不存在");
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizeType(String type) {
|
||||
if (!StringUtils.hasText(type)) {
|
||||
return FeedbackPO.TYPE_OTHER;
|
||||
}
|
||||
String normalized = type.trim().toUpperCase(Locale.ROOT);
|
||||
if (!ALLOWED_TYPES.contains(normalized)) {
|
||||
throw new BusinessException("无效的反馈类型");
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
// ---------- VO 组装 ----------
|
||||
|
||||
private FeedbackDetailVO toDetailVO(FeedbackPO po) {
|
||||
FeedbackDetailVO vo = new FeedbackDetailVO();
|
||||
BeanCopyUtils.copyProperties(toListVO(po, true), vo);
|
||||
List<FeedbackMessageVO> messages = loadMessageTree(po.getId());
|
||||
vo.setMessages(messages);
|
||||
fillNames(List.of(vo));
|
||||
// 正文 + 留言附图统一补访问地址
|
||||
Set<Long> allFileIds = new LinkedHashSet<>();
|
||||
if (vo.getFileIds() != null) {
|
||||
allFileIds.addAll(vo.getFileIds());
|
||||
}
|
||||
collectMessageFileIds(messages, allFileIds);
|
||||
Map<Long, String> urlMap = loadFileAccessUrls(allFileIds);
|
||||
vo.setImages(toFileVos(vo.getFileIds(), urlMap));
|
||||
fillMessageImages(messages, urlMap);
|
||||
return vo;
|
||||
}
|
||||
|
||||
private FeedbackVO toListVO(FeedbackPO po, boolean withFileIds) {
|
||||
FeedbackVO vo = new FeedbackVO();
|
||||
BeanCopyUtils.copyProperties(po, vo);
|
||||
if (withFileIds) {
|
||||
vo.setFileIds(listFeedbackFileIds(po.getId()));
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
private List<Long> listFeedbackFileIds(Long feedbackId) {
|
||||
return feedbackImageMapper.selectList(new LambdaQueryWrapper<FeedbackImagePO>()
|
||||
.eq(FeedbackImagePO::getFeedbackId, feedbackId)
|
||||
.orderByAsc(FeedbackImagePO::getSortOrder, FeedbackImagePO::getId))
|
||||
.stream()
|
||||
.map(FeedbackImagePO::getFileId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<FeedbackMessageVO> loadMessageTree(Long feedbackId) {
|
||||
List<FeedbackMessagePO> all = feedbackMessageMapper.selectList(
|
||||
new LambdaQueryWrapper<FeedbackMessagePO>()
|
||||
.eq(FeedbackMessagePO::getFeedbackId, feedbackId)
|
||||
.orderByAsc(FeedbackMessagePO::getId));
|
||||
if (all.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
Map<Long, List<Long>> messageFileIds = loadMessageFileIds(
|
||||
all.stream().map(FeedbackMessagePO::getId).collect(Collectors.toList()));
|
||||
Set<Long> authorIds = all.stream().map(FeedbackMessagePO::getCreateBy).collect(Collectors.toSet());
|
||||
Map<Long, String> nameMap = loadUserNames(authorIds);
|
||||
|
||||
Map<Long, FeedbackMessageVO> byId = new LinkedHashMap<>();
|
||||
for (FeedbackMessagePO msg : all) {
|
||||
FeedbackMessageVO mvo = toMessageVO(msg, false);
|
||||
mvo.setFileIds(messageFileIds.getOrDefault(msg.getId(), Collections.emptyList()));
|
||||
mvo.setCreatorName(nameMap.get(msg.getCreateBy()));
|
||||
mvo.setChildren(new ArrayList<>());
|
||||
byId.put(msg.getId(), mvo);
|
||||
}
|
||||
List<FeedbackMessageVO> roots = new ArrayList<>();
|
||||
for (FeedbackMessageVO mvo : byId.values()) {
|
||||
if (mvo.getParentId() == null) {
|
||||
roots.add(mvo);
|
||||
continue;
|
||||
}
|
||||
FeedbackMessageVO parent = byId.get(mvo.getParentId());
|
||||
if (parent != null) {
|
||||
parent.getChildren().add(mvo);
|
||||
} else {
|
||||
roots.add(mvo);
|
||||
}
|
||||
}
|
||||
clearEmptyChildren(roots);
|
||||
return roots;
|
||||
}
|
||||
|
||||
private void collectMessageFileIds(List<FeedbackMessageVO> messages, Set<Long> out) {
|
||||
if (CollectionUtils.isEmpty(messages)) {
|
||||
return;
|
||||
}
|
||||
for (FeedbackMessageVO msg : messages) {
|
||||
if (msg.getFileIds() != null) {
|
||||
out.addAll(msg.getFileIds());
|
||||
}
|
||||
collectMessageFileIds(msg.getChildren(), out);
|
||||
}
|
||||
}
|
||||
|
||||
private void fillMessageImages(List<FeedbackMessageVO> messages, Map<Long, String> urlMap) {
|
||||
if (CollectionUtils.isEmpty(messages)) {
|
||||
return;
|
||||
}
|
||||
for (FeedbackMessageVO msg : messages) {
|
||||
msg.setImages(toFileVos(msg.getFileIds(), urlMap));
|
||||
fillMessageImages(msg.getChildren(), urlMap);
|
||||
}
|
||||
}
|
||||
|
||||
private List<FeedbackFileVO> toFileVos(List<Long> fileIds, Map<Long, String> urlMap) {
|
||||
if (CollectionUtils.isEmpty(fileIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<FeedbackFileVO> list = new ArrayList<>(fileIds.size());
|
||||
for (Long fileId : fileIds) {
|
||||
FeedbackFileVO f = new FeedbackFileVO();
|
||||
f.setFileId(fileId);
|
||||
f.setAccessUrl(urlMap.get(fileId));
|
||||
list.add(f);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private Map<Long, String> loadFileAccessUrls(Collection<Long> fileIds) {
|
||||
if (CollectionUtils.isEmpty(fileIds)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<SysFilePO> files = sysFileMapper.selectBatchIds(fileIds);
|
||||
Map<Long, String> map = new HashMap<>();
|
||||
for (SysFilePO file : files) {
|
||||
if (file == null || file.getId() == null || file.getDeleteTime() != null) {
|
||||
continue;
|
||||
}
|
||||
String url = SysFileUtils.getFileAccessUrl(file.getStoragePath(), file.getStorageType());
|
||||
if (StringUtils.hasText(url)) {
|
||||
map.put(file.getId(), url);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private void clearEmptyChildren(List<FeedbackMessageVO> nodes) {
|
||||
if (nodes == null) {
|
||||
return;
|
||||
}
|
||||
for (FeedbackMessageVO node : nodes) {
|
||||
if (node.getChildren() == null || node.getChildren().isEmpty()) {
|
||||
node.setChildren(null);
|
||||
} else {
|
||||
clearEmptyChildren(node.getChildren());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private FeedbackMessageVO toMessageVO(FeedbackMessagePO po, boolean withFilesAndName) {
|
||||
FeedbackMessageVO vo = new FeedbackMessageVO();
|
||||
BeanCopyUtils.copyProperties(po, vo);
|
||||
if (withFilesAndName) {
|
||||
List<Long> ids = loadMessageFileIds(List.of(po.getId())).getOrDefault(po.getId(), Collections.emptyList());
|
||||
vo.setFileIds(ids);
|
||||
vo.setImages(toFileVos(ids, loadFileAccessUrls(ids)));
|
||||
Map<Long, String> names = loadUserNames(Set.of(po.getCreateBy()));
|
||||
vo.setCreatorName(names.get(po.getCreateBy()));
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
private Map<Long, List<Long>> loadMessageFileIds(List<Long> messageIds) {
|
||||
if (CollectionUtils.isEmpty(messageIds)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<FeedbackMessageImagePO> images = feedbackMessageImageMapper.selectList(
|
||||
new LambdaQueryWrapper<FeedbackMessageImagePO>()
|
||||
.in(FeedbackMessageImagePO::getMessageId, messageIds)
|
||||
.orderByAsc(FeedbackMessageImagePO::getSortOrder, FeedbackMessageImagePO::getId));
|
||||
Map<Long, List<Long>> map = new HashMap<>();
|
||||
for (FeedbackMessageImagePO image : images) {
|
||||
map.computeIfAbsent(image.getMessageId(), k -> new ArrayList<>()).add(image.getFileId());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private void fillNames(List<? extends FeedbackVO> vos) {
|
||||
if (CollectionUtils.isEmpty(vos)) {
|
||||
return;
|
||||
}
|
||||
Set<Long> userIds = new HashSet<>();
|
||||
Set<Long> menuIds = new HashSet<>();
|
||||
for (FeedbackVO vo : vos) {
|
||||
if (vo.getCreateBy() != null) {
|
||||
userIds.add(vo.getCreateBy());
|
||||
}
|
||||
if (vo.getAssigneeId() != null) {
|
||||
userIds.add(vo.getAssigneeId());
|
||||
}
|
||||
if (vo.getMenuId() != null) {
|
||||
menuIds.add(vo.getMenuId());
|
||||
}
|
||||
}
|
||||
Map<Long, String> userNames = loadUserNames(userIds);
|
||||
Map<Long, String> menuTitles = loadMenuTitles(menuIds);
|
||||
for (FeedbackVO vo : vos) {
|
||||
vo.setCreatorName(userNames.get(vo.getCreateBy()));
|
||||
vo.setAssigneeName(userNames.get(vo.getAssigneeId()));
|
||||
vo.setMenuTitle(menuTitles.get(vo.getMenuId()));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Long, String> loadUserNames(Set<Long> userIds) {
|
||||
if (CollectionUtils.isEmpty(userIds)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return userMapper.selectByIds(userIds).stream()
|
||||
.collect(Collectors.toMap(UserPO::getId, u -> {
|
||||
if (StringUtils.hasText(u.getRealName())) {
|
||||
return u.getRealName();
|
||||
}
|
||||
return u.getLoginCode() != null ? u.getLoginCode() : String.valueOf(u.getId());
|
||||
}, (a, b) -> a));
|
||||
}
|
||||
|
||||
private Map<Long, String> loadMenuTitles(Set<Long> menuIds) {
|
||||
if (CollectionUtils.isEmpty(menuIds)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return menuMapper.selectByIds(menuIds).stream()
|
||||
.collect(Collectors.toMap(MenuPO::getId, MenuPO::getTitle, (a, b) -> a));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user