fujian_water_biz_doc/sql/rev004_account_adjust_dict_seed.sql
tangweijie d0ee1cbc17 Align REV004 dictionaries with current interface semantics
Document the minimal dictionary additions and field-binding rules needed to
let REV004 front-end queries and dropdowns use system-managed object and
status semantics while continuing to reuse the existing legacy reason/type
dictionaries.

Constraint: Existing dictionary taxonomy must remain stable for historical pages
Constraint: REV004 needs explicit object/status dictionaries plus a redink reason set for FE binding
Rejected: Rename legacy dictionaries into a new unified taxonomy | too broad for this delivery and risks breaking existing pages
Rejected: Keep object/status values as code-only enums | insufficient for frontend dictionary binding
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: `payment_reason` is only a transitional binding for `WRITTENOFF_ADJUST`; introduce a dedicated writtenoff reason dictionary only when that object stabilizes long-term
Tested: Applied `sql/rev004_account_adjust_dict_seed.sql` to sw_system test DB and verified inserted dict types/data
Not-tested: Frontend page consumption against the new dictionary bindings
2026-04-07 17:53:47 +08:00

74 lines
4.2 KiB
PL/PgSQL

-- REV004 account adjust dictionaries
-- Target DB: sw_system (PostgreSQL)
-- Purpose:
-- 1) Reuse existing legacy reason/type/proc/business dictionaries
-- 2) Add the minimal new dictionaries needed for REV004 object/status semantics
-- Note:
-- This script is idempotent by (type) and (dict_type, value) checks.
BEGIN;
-- ============================================================
-- 1. Dict types
-- ============================================================
INSERT INTO system_dict_type (name, type, status, remark, creator, updater, category)
SELECT v.name, v.type, 0, v.remark, 'omx', 'omx', 'REV004'
FROM (VALUES
('红冲原因', 'redink_reason', 'REV004 红冲/冲正原因'),
('账务调整对象类型', 'account_adjust_object_type', 'REV004 objectType 字典'),
('账务调整结果状态', 'account_adjust_result_status', 'REV004 resultStatus 字典'),
('账务调整审批状态', 'account_adjust_approval_status', 'REV004 approvalStatus 字典'),
('账务调整回写状态', 'account_adjust_writeback_status', 'REV004 writeBackStatus 字典')
) AS v(name, type, remark)
WHERE NOT EXISTS (
SELECT 1 FROM system_dict_type t WHERE t.type = v.type AND t.deleted = 0
);
-- ============================================================
-- 2. Dict data
-- ============================================================
INSERT INTO system_dict_data (sort, label, value, dict_type, status, color_type, css_class, remark, creator, updater)
SELECT v.sort, v.label, v.value, v.dict_type, 0, v.color_type, v.css_class, v.remark, 'omx', 'omx'
FROM (VALUES
-- redink_reason
(10, '收费错误', '1', 'redink_reason', 'danger', '', 'REV004 红冲原因'),
(20, '用户拒缴', '2', 'redink_reason', 'warning', '', 'REV004 红冲原因'),
(30, '银行撤销', '3', 'redink_reason', 'warning', '', 'REV004 红冲原因'),
(40, '网络异常', '4', 'redink_reason', 'info', '', 'REV004 红冲原因'),
(90, '其它', '9', 'redink_reason', 'default', '', 'REV004 红冲原因'),
-- account_adjust_object_type
(10, '预付费退款', 'PREPAID_REFUND', 'account_adjust_object_type', 'success', '', 'REV004 objectType'),
(20, '红冲记录', 'REDINK_RECORD', 'account_adjust_object_type', 'danger', '', 'REV004 objectType'),
(30, '坏账申请', 'BAD_DEBT_RECORD', 'account_adjust_object_type', 'warning', '', 'REV004 objectType'),
(40, '核销调整', 'WRITTENOFF_ADJUST', 'account_adjust_object_type', 'warning', '', 'REV004 objectType'),
(50, '价差调整', 'PRICE_DIFF_ADJUST', 'account_adjust_object_type', 'info', '', 'REV004 objectType'),
(60, '违约金减免', 'LATE_FEE_REDUCE', 'account_adjust_object_type', 'info', '', 'REV004 objectType'),
(70, '账单拆分', 'SPLIT_ADJUST', 'account_adjust_object_type', 'primary', '', 'REV004 objectType'),
-- account_adjust_result_status
(10, '成功', 'SUCCESS', 'account_adjust_result_status', 'success', '', 'REV004 resultStatus'),
(20, '待审批', 'PENDING_APPROVAL', 'account_adjust_result_status', 'warning', '', 'REV004 resultStatus'),
(30, '失败', 'FAIL', 'account_adjust_result_status', 'danger', '', 'REV004 resultStatus'),
-- account_adjust_approval_status
(10, '无需审批', 'NOT_REQUIRED', 'account_adjust_approval_status', 'default', '', 'REV004 approvalStatus'),
(20, '待审批', 'PENDING_APPROVAL', 'account_adjust_approval_status', 'warning', '', 'REV004 approvalStatus'),
(30, '审批通过', 'APPROVED', 'account_adjust_approval_status', 'success', '', 'REV004 approvalStatus'),
(40, '审批驳回', 'REJECTED', 'account_adjust_approval_status', 'danger', '', 'REV004 approvalStatus'),
-- account_adjust_writeback_status
(10, '已回写', 'UPDATED', 'account_adjust_writeback_status', 'success', '', 'REV004 writeBackStatus'),
(20, '待回写', 'PENDING', 'account_adjust_writeback_status', 'warning', '', 'REV004 writeBackStatus'),
(30, '已跳过', 'SKIPPED', 'account_adjust_writeback_status', 'default', '', 'REV004 writeBackStatus')
) AS v(sort, label, value, dict_type, color_type, css_class, remark)
WHERE NOT EXISTS (
SELECT 1
FROM system_dict_data d
WHERE d.dict_type = v.dict_type
AND d.value = v.value
AND d.deleted = 0
);
COMMIT;