Files
34047007@qq.com b95053c52c init: 初始化 dpb 桃育种系统代码库
前后端 + 后端 FastAPI 全量源码、部署脚本与文档。
2026-08-06 00:17:49 +08:00

182 lines
11 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.
-- ============================================================
-- 桃育种系统 - 业务枚举字典初始化 SQL(权威单一来源,方案 B:dict_value 存英码,dict_label 显中文)
-- ------------------------------------------------------------
-- 说明(2026-08-03 命名校准):
-- * 线上库已存在一批「规划附录 7 标签页性状字典」(growth_vigor/fruit_shape/firmness/
-- identify_status/peach_variety_type/seed_treatment 等,英码设计,共 51 类型),
-- 本文件与线上库对齐,只负责【as-built 字段】所需字典,不再重复种入已存在类型。
-- * 已确认的命名对齐(旧 bre_dict 名 → 线上权威名):
-- variety_type -> peach_variety_type (线上已存在,值同)
-- seed_treatment_method-> seed_treatment (线上已存在;本文件补充 层积=stratify)
-- selection_result -> identify_status (选育结论用线上 6 态:未知/入选/初选/重点/保存/淘汰)
-- is_preset -> 复用 sys_yes_no (是=1/否=0,与现有存储一致,不再建独立类型)
-- firmness -> 线上权威值 (很软/软/中/硬/很硬,非旧「溶质」族)
-- * 本文件补充的 as-built 类型(10 个):maturity_period / flowering_period / eco_type /
-- row_orientation / gender / personnel_role / cross_method / tree_status / photo_type / series。
-- * dict_value = 英码(稳定键,落库用);dict_label = 中文(下拉/回显展示用)。
-- * 页面下拉经 sys_dict 取 {value:dict_value, label:dict_label},用户选中文、库存英码。
-- * Excel 导入:单元格填中文 dict_label,导入服务经 sys_dict 解析 label→value 后写库
-- (实现见 backend/app/utils/dict_util.py: DictLabelResolver,接入各 breeding 域
-- service.batch_import;存量中文值经 scripts/migrate_dict_english.py 迁移)。
-- 运行:psql -h localhost -U dpb -d dpb -f backend/sql/bre_dict.sql
-- 特性:幂等可重复执行(dict_type / (dict_type,dict_value) 已存在则跳过)
-- 注 gen_random_uuid() 为 PostgreSQL 13+ 内置(本项目 PG16
-- ============================================================
-- ------------------------------------------------------------
-- 1) 字典类型(as-built 字段需要的 11 个;已存在则跳过)
-- 注:peach_variety_type/firmness/seed_treatment/identify_status 线上已存在,不重复建。
-- ------------------------------------------------------------
INSERT INTO sys_dict_type (dict_name, dict_type, status, description, uuid, is_deleted, created_time, updated_time)
SELECT v.dict_name, v.dict_type, 0, v.description, gen_random_uuid(), FALSE, now(), now()
FROM (VALUES
('成熟期', 'maturity_period', '亲本资源-成熟期'),
('花期', 'flowering_period', '亲本资源-花期'),
('生态区类型', 'eco_type', '基地管理-生态区'),
('地块行向', 'row_orientation', '试验地块-行向'),
('人员性别', 'gender', '人员花名册-性别'),
('人员角色', 'personnel_role', '人员花名册-角色'),
('杂交方式', 'cross_method', '杂交组合-杂交方式'),
('单株状态', 'tree_status', '育种单株-状态'),
('照片类型', 'photo_type', '单株照片-类型'),
('育种系列', 'series', '育种目标-系列'),
('桃变种类型', 'peach_variety_type', '亲本资源-变种类型'),
('育种阶段', 'breeding_stage', '全流程-育种阶段(germplasm种质/parent亲本/seedling实生苗/sp初选株/ap复选株/line品系/regional_trial区试品系/released新品种)'),
('世代', 'breeding_generation', '育种-世代(F1/F2/BC1/BC2/BC3'),
('分组类型', 'breeding_group_type', '分组管理-类型(project/family/category/temporary_set/custom'),
('试验设计', 'breeding_design_type', '试验设计-类型(rcbd/augmented/contrast/split_plot/unreplicated'),
('生物学状态', 'biological_status', '亲本资源-生物学状态(wild/landrace/breeding_line'),
('保存方式', 'storage_type', '种质/种质库-保存方式(田间/离体/种子/DNA)'),
('杂交类型', 'cross_type', '杂交组合-杂交类型(杂交/自交/开放)'),
('农事操作', 'field_operation', '农事操作-操作类型(施肥/喷药/修剪/灌溉/疏果/套袋/采收)')
) AS v(dict_name, dict_type, description)
WHERE NOT EXISTS (SELECT 1 FROM sys_dict_type t WHERE t.dict_type = v.dict_type);
-- ------------------------------------------------------------
-- 2) 字典数据(dict_type_id 由子查询解析;dict_value=英码, dict_label=中文)
-- dict_sort 同字典内升序;首个值默认(is_default=true)
-- peach_variety_type/firmness/identify_status 线上已存在,未列入 VALUES 的不重复种)
-- ------------------------------------------------------------
INSERT INTO sys_dict_data (
dict_sort, dict_label, dict_value, dict_type, dict_type_id,
is_default, status, css_class, list_class, description,
uuid, is_deleted, created_time, updated_time
)
SELECT
v.dict_sort, v.dict_label, v.dict_value, v.dict_type, t.id,
v.is_default, 0, '', NULL, v.dict_label,
gen_random_uuid(), FALSE, now(), now()
FROM (VALUES
-- 成熟期 maturity_period
(1,'早','early','maturity_period',TRUE),
(2,'中','mid','maturity_period',FALSE),
(3,'晚','late','maturity_period',FALSE),
-- 花期 flowering_period
(1,'极早花','very_early','flowering_period',TRUE),
(2,'早花','early','flowering_period',FALSE),
(3,'中花','mid','flowering_period',FALSE),
(4,'晚花','late','flowering_period',FALSE),
(5,'极晚花','very_late','flowering_period',FALSE),
-- 生态区类型 eco_type
(1,'华北','north_china','eco_type',TRUE),
(2,'西北','northwest','eco_type',FALSE),
(3,'华东','east_china','eco_type',FALSE),
(4,'西南','southwest','eco_type',FALSE),
(5,'东北','northeast','eco_type',FALSE),
(6,'华南','south_china','eco_type',FALSE),
-- 地块行向 row_orientation
(1,'南北行','ns','row_orientation',TRUE),
(2,'东西行','ew','row_orientation',FALSE),
-- 人员性别 gender
(1,'男','male','gender',TRUE),
(2,'女','female','gender',FALSE),
-- 人员角色 personnel_role
(1,'育种专家','expert','personnel_role',TRUE),
(2,'技术员','technician','personnel_role',FALSE),
(3,'管理员','admin','personnel_role',FALSE),
-- 杂交方式 cross_method
(1,'人工杂交','artificial','cross_method',TRUE),
(2,'自然授粉','natural','cross_method',FALSE),
(3,'回交','backcross','cross_method',FALSE),
-- 单株状态 tree_status(与 selection_result 写回映射一致:
-- _TREE_STATUS_BY_SELECT 写入 selected/primary/key/preserved/eliminated
(1,'存活','alive','tree_status',TRUE),
(2,'淘汰','eliminated','tree_status',FALSE),
(3,'入选','selected','tree_status',FALSE),
(4,'初选','primary','tree_status',FALSE),
(5,'核心','key','tree_status',FALSE),
(6,'保留','preserved','tree_status',FALSE),
-- 照片类型 photo_type
(1,'全株','whole','photo_type',TRUE),
(2,'果实','fruit','photo_type',FALSE),
(3,'枝干','branch','photo_type',FALSE),
-- 育种系列 series
(1,'普通桃','common','series',TRUE),
(2,'油桃','nectarine','series',FALSE),
(3,'蟠桃','flat_peach','series',FALSE),
(4,'油蟠桃','nectarine_flat','series',FALSE),
(5,'黄肉加工桃','yellow_processing','series',FALSE),
(6,'观赏桃','ornamental','series',FALSE),
-- 桃变种类型 peach_variety_type(线上已存在时 NOT EXISTS 自动跳过)
(1,'普通桃','common','peach_variety_type',TRUE),
(2,'油桃','nectarine','peach_variety_type',FALSE),
(3,'蟠桃','flat_peach','peach_variety_type',FALSE),
(4,'油蟠桃','nectarine_flat','peach_variety_type',FALSE),
(5,'黄肉','yellow_flesh','peach_variety_type',FALSE),
-- 种子处理方法 seed_treatment(补充 层积=stratify;线上 胚培养/冷床沙藏/露地沙藏 已存在,自动跳过)
(4,'层积','stratify','seed_treatment',FALSE),
-- 育种阶段 breeding_stage
(1,'种质','germplasm','breeding_stage',TRUE),
(2,'亲本','parent','breeding_stage',FALSE),
(3,'实生苗','seedling','breeding_stage',FALSE),
(4,'初选株','sp','breeding_stage',FALSE),
(5,'复选株','ap','breeding_stage',FALSE),
(6,'品系','line','breeding_stage',FALSE),
(7,'区试品系','regional_trial','breeding_stage',FALSE),
(8,'新品种','released','breeding_stage',FALSE),
-- 世代 breeding_generation
(1,'F1','F1','breeding_generation',TRUE),
(2,'F2','F2','breeding_generation',FALSE),
(3,'BC1','BC1','breeding_generation',FALSE),
(4,'BC2','BC2','breeding_generation',FALSE),
(5,'BC3','BC3','breeding_generation',FALSE),
-- 分组类型 breeding_group_type
(1,'育种项目','project','breeding_group_type',TRUE),
(2,'家系','family','breeding_group_type',FALSE),
(3,'类目','category','breeding_group_type',FALSE),
(4,'临时集','temporary_set','breeding_group_type',FALSE),
(5,'自定义','custom','breeding_group_type',FALSE),
-- 试验设计 breeding_design_type
(1,'随机区组','rcbd','breeding_design_type',TRUE),
(2,'增广设计','augmented','breeding_design_type',FALSE),
(3,'对照设计','contrast','breeding_design_type',FALSE),
(4,'裂区设计','split_plot','breeding_design_type',FALSE),
(5,'不设重复','unreplicated','breeding_design_type',FALSE),
-- 生物学状态 biological_status
(1,'野生','wild','biological_status',TRUE),
(2,'地方品种','landrace','biological_status',FALSE),
(3,'育成品种','breeding_line','biological_status',FALSE),
-- 保存方式 storage_type
(1,'田间','field','storage_type',TRUE),
(2,'离体','in_vitro','storage_type',FALSE),
(3,'种子','seed','storage_type',FALSE),
(4,'DNA','dna','storage_type',FALSE),
-- 杂交类型 cross_type
(1,'杂交','hybrid','cross_type',TRUE),
(2,'自交','selfing','cross_type',FALSE),
(3,'开放','open','cross_type',FALSE),
-- 农事操作 field_operation
(1,'施肥','fertilize','field_operation',TRUE),
(2,'喷药','spray','field_operation',FALSE),
(3,'修剪','prune','field_operation',FALSE),
(4,'灌溉','irrigate','field_operation',FALSE),
(5,'疏果','thinning','field_operation',FALSE),
(6,'套袋','bagging','field_operation',FALSE),
(7,'采收','harvest','field_operation',FALSE)
) AS v(dict_sort, dict_label, dict_value, dict_type, is_default)
JOIN sys_dict_type t ON t.dict_type = v.dict_type
WHERE NOT EXISTS (
SELECT 1 FROM sys_dict_data d
WHERE d.dict_type = v.dict_type AND d.dict_value = v.dict_value
);