批量更新功能

This commit is contained in:
2026-09-14 16:15:44 +08:00
parent 6f106e43af
commit a26c98b92b
79 changed files with 4529 additions and 724 deletions
@@ -0,0 +1,20 @@
-- =============================================================
-- Product dev_mode: distinguish self-developed vs outsourced
-- (software development has two kinds: developed by ourselves,
-- or developed by others for us)
-- Table: yz_backend_crm_product
-- dev_mode varchar(20) NOT NULL DEFAULT 'self'
-- 'self' -> developed in-house (default)
-- 'outsource' -> outsourced / developed by others for us
-- Note: the server also auto-adds this column on startup
-- (models.EnsureCrmProductDevColumns); this file is only
-- for manual repair. Re-running reports
-- "Duplicate column name", which is safe.
-- Run: mysql -h<host> -P<port> -u<user> -p <db> < alter_backend_crm_product_dev_mode.sql
-- NOTE: keep this file ASCII-only; piping through some shells mangles non-ASCII.
-- =============================================================
ALTER TABLE `yz_backend_crm_product`
ADD COLUMN `dev_mode` VARCHAR(20) NOT NULL DEFAULT 'self'
COMMENT 'software dev mode: self in-house / outsource developed by others'
AFTER `dev_unit_price`;
+48
View File
@@ -0,0 +1,48 @@
-- =============================================================
-- Contacts: support multiple mobile numbers (a person may have several)
-- Tables:
-- 1) yz_backend_crm_entity_contact : contacts of clue / business / project
-- 2) yz_backend_erp_contact : global address book contacts
-- 3) yz_backend_contact_company : company contacts (customers/suppliers),
-- shared by project contact picker / address book / customer-supplier
-- conversion. This one was missed before: without the column any SELECT
-- fails and contact lists show as empty (fixed by the server-side
-- migration EnsureErpCompanyContactMobilesColumn on startup).
-- All tables get a new column `mobiles` (TEXT, JSON array, max 5).
-- The old `mobile` / `phone` column keeps the FIRST number for backward
-- compatibility (list display, phone-based dedupe on sync), and existing
-- single numbers are backfilled into `mobiles`.
-- Run: mysql -h<host> -P<port> -u<user> -p <db> < alter_contact_mobiles.sql
-- (re-running only reports "Duplicate column name", which is safe)
-- NOTE: keep this file ASCII-only; piping through some shells mangles non-ASCII.
-- =============================================================
-- 1) clue / business / project contacts
ALTER TABLE `yz_backend_crm_entity_contact`
ADD COLUMN `mobiles` TEXT NULL COMMENT 'phones in JSON array, max 5' AFTER `mobile`;
-- backfill existing single number as a one-element JSON array
UPDATE `yz_backend_crm_entity_contact`
SET `mobiles` = JSON_ARRAY(`mobile`)
WHERE (`mobiles` IS NULL OR `mobiles` = '')
AND `mobile` IS NOT NULL AND `mobile` <> '';
-- 2) global address book contacts
ALTER TABLE `yz_backend_erp_contact`
ADD COLUMN `mobiles` TEXT NULL COMMENT 'phones in JSON array, max 5' AFTER `phone`;
UPDATE `yz_backend_erp_contact`
SET `mobiles` = JSON_ARRAY(`phone`)
WHERE (`mobiles` IS NULL OR `mobiles` = '')
AND `phone` IS NOT NULL AND `phone` <> '';
-- 3) company contacts (customers / suppliers) - shared by project contact
-- picker / address book / customer-supplier conversion.
-- NOTE: also auto-added on server startup (EnsureErpCompanyContactMobilesColumn).
ALTER TABLE `yz_backend_contact_company`
ADD COLUMN `mobiles` TEXT NULL COMMENT 'phones in JSON array, max 5' AFTER `phone`;
UPDATE `yz_backend_contact_company`
SET `mobiles` = JSON_ARRAY(`phone`)
WHERE (`mobiles` IS NULL OR `mobiles` = '')
AND `phone` IS NOT NULL AND `phone` <> '';
@@ -0,0 +1,21 @@
-- =============================================================
-- CRM product categories: system default category "未分类"
-- Table: yz_backend_crm_product_category
-- is_default = 1 -> system default category ("未分类"): kept by
-- the system, cannot be edited or deleted,
-- sort pinned to the top (-1)
-- is_default = 0 -> tenant custom category (full CRUD)
-- Existing "未分类" rows (if any) are marked as default below;
-- the backend also self-heals the flag and creates the record
-- on first use after upgrade.
-- Run: mysql --default-character-set=utf8mb4 -h<host> -P<port> -u<user> -p <db> < alter_crm_product_category_default.sql
-- (re-running only reports "Duplicate column name", which is safe)
-- =============================================================
ALTER TABLE `yz_backend_crm_product_category`
ADD COLUMN `is_default` TINYINT NOT NULL DEFAULT 0 COMMENT '1=system default category (read-only), 0=tenant custom' AFTER `status`;
-- Mark existing default category (same name as backend default) and pin it to the top
UPDATE `yz_backend_crm_product_category`
SET `is_default` = 1, `sort` = -1
WHERE `name` = '未分类';
+19
View File
@@ -0,0 +1,19 @@
-- =============================================================
-- CRM units: mark system default units as not editable/deletable
-- Table: yz_backend_crm_unit
-- is_default = 1 -> system default unit (seeded by the system,
-- cannot be edited or deleted by tenants)
-- is_default = 0 -> tenant custom unit (full CRUD)
-- Existing seeded default units (matched by name) are marked below;
-- the backend also self-heals the flag on first use after upgrade.
-- Run: mysql --default-character-set=utf8mb4 -h<host> -P<port> -u<user> -p <db> < alter_crm_unit_default.sql
-- (re-running only reports "Duplicate column name", which is safe)
-- =============================================================
ALTER TABLE `yz_backend_crm_unit`
ADD COLUMN `is_default` TINYINT NOT NULL DEFAULT 0 COMMENT '1=system default unit (read-only), 0=tenant custom' AFTER `status`;
-- Mark seeded default units (same list as backend crmDefaultUnits)
UPDATE `yz_backend_crm_unit`
SET `is_default` = 1
WHERE `name` IN ('套', '台', '个', '件', '批', '次', '项', '人月', '人天', '年', '月', '米', '平方米', '吨', '千克', '箱');
+16
View File
@@ -0,0 +1,16 @@
-- =============================================================
-- Payback records: mark which plan item (progress node / period)
-- a received payment belongs to, so payments can be registered
-- per progress node and shown as tree children under the plan.
-- Table: yz_backend_crm_payback_record
-- item_seq : seq of the plan items entry (1-based), 0 = not specified
-- item_name : node name snapshot (e.g. "预付款")
-- Run: mysql -h<host> -P<port> -u<user> -p <db> < alter_payback_record_item.sql
-- (re-running only reports "Duplicate column name", which is safe)
-- =============================================================
ALTER TABLE `yz_backend_crm_payback_record`
ADD COLUMN `item_seq` INT NOT NULL DEFAULT 0 COMMENT 'plan item seq (1-based), 0 = not specified' AFTER `payback_id`;
ALTER TABLE `yz_backend_crm_payback_record`
ADD COLUMN `item_name` VARCHAR(50) NULL COMMENT 'plan item name snapshot' AFTER `item_seq`;
+21
View File
@@ -0,0 +1,21 @@
-- =============================================================
-- Project contacts: pick contacts from the linked companies
-- (a project no longer shows ALL contacts of the customer)
-- Table: yz_backend_crm_project
-- 1) upstream_contact_ids : JSON array of contact IDs picked from
-- the customer's address book (upstream).
-- 2) downstream_contact_ids : JSON array of contact IDs picked from
-- the counterpart's address book
-- (downstream for type=2 / midstream for type=3).
-- Contact details always come from yz_backend_erp_contact in real time;
-- only the picked ID references are stored here. Empty array -> ''.
-- Run: mysql -h<host> -P<port> -u<user> -p <db> < alter_project_contacts.sql
-- (re-running only reports "Duplicate column name", which is safe)
-- NOTE: keep this file ASCII-only; piping through some shells mangles non-ASCII.
-- =============================================================
ALTER TABLE `yz_backend_crm_project`
ADD COLUMN `upstream_contact_ids` TEXT NULL COMMENT 'picked contact IDs (JSON array) from customer address book' AFTER `downstream_phone`;
ALTER TABLE `yz_backend_crm_project`
ADD COLUMN `downstream_contact_ids` TEXT NULL COMMENT 'picked contact IDs (JSON array) from counterpart address book (downstream/midstream)' AFTER `upstream_contact_ids`;