qiangdanxitong/database/V13__add_primary_demand_dept.sql
Your Name c99a927cca feat: 添加一级需求部门功能
- 新增一级需求部门类型和品牌关联管理
- 新增一级需求部门任务创建、审核、明细完善流程
- 新增一级需求部门数据分析模块
- 任务卡片显示一级需求人信息
- 部门管理增加品牌关联配置
2026-01-19 20:58:09 +08:00

56 lines
2.8 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- V13__add_primary_demand_dept.sql
-- 一级需求部门功能数据库迁移脚本
-- 创建日期:2026-01-19
-- =====================================================
-- 1. 系统配置:一级需求部门是否允许填写任务明细
-- =====================================================
INSERT INTO sys_config (config_key, config_value, config_group, config_name, description, value_type, built_in, sort_order, create_time, update_time, deleted)
VALUES ('primary_dept_can_fill_detail', 'false', 'task', '一级需求部门可填写明细', '开启后一级需求部门发布任务时可以填写任务明细,关闭后不允许填写', 'boolean', 0, 100, NOW(), NOW(), 0);
-- =====================================================
-- 2. 任务表新增字段
-- =====================================================
-- 一级部门发起人ID
ALTER TABLE task ADD COLUMN IF NOT EXISTS primary_publisher_id BIGINT COMMENT '一级部门发起人ID';
-- 一级部门ID
ALTER TABLE task ADD COLUMN IF NOT EXISTS primary_publisher_dept_id BIGINT COMMENT '一级部门ID';
-- 明细完善人ID
ALTER TABLE task ADD COLUMN IF NOT EXISTS detail_completer_id BIGINT COMMENT '明细完善人ID';
-- 是否一级部门任务
ALTER TABLE task ADD COLUMN IF NOT EXISTS is_primary_task TINYINT DEFAULT 0 COMMENT '是否一级部门任务:0-否,1-是';
-- 明细是否已完善
ALTER TABLE task ADD COLUMN IF NOT EXISTS detail_completed TINYINT DEFAULT 0 COMMENT '明细是否已完善:0-否,1-是';
-- =====================================================
-- 3. 创建品牌-部门关联表
-- =====================================================
CREATE TABLE IF NOT EXISTS dept_brand_relation (
id BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID',
dept_id BIGINT NOT NULL COMMENT '部门ID(需求部门)',
brand_id BIGINT NOT NULL COMMENT '品牌ID',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
UNIQUE KEY uk_brand_id (brand_id),
INDEX idx_dept_id (dept_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='部门品牌负责关系表';
-- =====================================================
-- 4. 为现有任务设置默认值
-- =====================================================
UPDATE task SET is_primary_task = 0 WHERE is_primary_task IS NULL;
UPDATE task SET detail_completed = 1 WHERE detail_completed IS NULL;
-- =====================================================
-- 5. 添加索引优化查询性能
-- =====================================================
-- 一级任务查询索引
CREATE INDEX IF NOT EXISTS idx_task_is_primary ON task(is_primary_task);
-- 一级发起人查询索引
CREATE INDEX IF NOT EXISTS idx_task_primary_publisher ON task(primary_publisher_id);
-- 一级部门查询索引
CREATE INDEX IF NOT EXISTS idx_task_primary_dept ON task(primary_publisher_dept_id);