提交
This commit is contained in:
1 parent
012a2ad68e
commit
5fe53c5481
4775 files changed
+2190111
-40277
No files matched your search
+14
-8
@@ -11,7 +11,7 @@
|
||||
Target Server Version : 50736 (5.7.36)
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 02/08/2026 22:40:54
|
||||
Date: 03/08/2026 21:29:44
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
@@ -273,7 +273,7 @@ CREATE TABLE `inbound_outbound` (
|
||||
KEY `idx_is_deleted` (`is_deleted`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_vehicle_no` (`vehicle_no`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2420 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='出入库单表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2423 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='出入库单表';
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of inbound_outbound
|
||||
@@ -2649,10 +2649,10 @@ INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2395, '2026-08-02', '中盐安徽红四方股份有限公司', '出库', '32% 烧碱', 32, NULL, 'CRKDH0002045', '皖H38397', '已完成', NULL, NULL, 0, '2026-07-31 14:58:35');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2396, '2026-08-02', '中盐安徽红四方股份有限公司', '出库', '32% 烧碱', 32, NULL, 'CRKDH0002046', '皖H38397', '已完成', NULL, NULL, 0, '2026-07-31 14:58:48');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2397, '2026-08-02', '中盐安徽红四方股份有限公司', '出库', '32% 烧碱', 32, NULL, 'CRKDH0002047', '皖H38397', '已完成', NULL, NULL, 0, '2026-07-31 14:59:02');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2398, '2026-08-03', '中盐安徽红四方股份有限公司', '出库', '32% 烧碱', 32, NULL, 'CRKDH0002048', '皖H38397', '待出库', NULL, NULL, 0, '2026-07-31 14:59:20');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2399, '2026-08-03', '中盐安徽红四方股份有限公司', '出库', '32% 烧碱', 32, NULL, 'CRKDH0002049', '皖H38397', '待出库', NULL, NULL, 0, '2026-07-31 14:59:33');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2400, '2026-08-03', '中盐安徽红四方股份有限公司', '出库', '32% 烧碱', 32, NULL, 'CRKDH0002050', '皖H38397', '待出库', NULL, NULL, 0, '2026-07-31 14:59:47');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2401, '2026-08-03', '中盐安徽红四方股份有限公司', '出库', '32% 烧碱', 32, NULL, 'CRKDH0002051', '皖H38397', '待出库', NULL, NULL, 0, '2026-07-31 15:00:01');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2398, '2026-08-03', '中盐安徽红四方股份有限公司', '出库', '32% 烧碱', 32, NULL, 'CRKDH0002048', '皖H38397', '已完成', NULL, NULL, 0, '2026-07-31 14:59:20');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2399, '2026-08-03', '中石化安庆分公司', '出库', '32% 烧碱', 32, '', 'CRKDH0002049', '皖H38397', '待出库', '', NULL, 0, '2026-07-31 14:59:33');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2400, '2026-08-03', '中石化安庆分公司', '出库', '32% 烧碱', 32, '', 'CRKDH0002050', '皖H38397', '待出库', '', NULL, 0, '2026-07-31 14:59:47');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2401, '2026-08-03', '中石化安庆分公司', '出库', '32% 烧碱', 32, '', 'CRKDH0002051', '皖H38397', '待出库', '', NULL, 0, '2026-07-31 15:00:01');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2402, '2026-07-31', '安徽辉隆中成科技有限 公司', '入库', '工业硫酸 98%', 32, NULL, 'CRKDH0002052', '皖HA3690', '已完成', '', NULL, 0, '2026-07-31 15:11:36');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2403, '2026-07-31', '安徽嘉珑凯贸易有限责任公司', '入库', '32% 烧碱', 32, NULL, 'CRKDH0002053', '皖H13487', '已完成', NULL, NULL, 0, '2026-07-31 16:32:21');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2404, '2026-08-01', '合肥德泽化工科技有限公司', '出库', '30%工业硫酸', 10, NULL, 'CRKDH0002054', '皖AM8516', '已完成', NULL, NULL, 0, '2026-07-31 16:35:32');
|
||||
@@ -2671,6 +2671,9 @@ INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2417, '2026-08-02', '安徽川沃化学科技有限公司', '出库', '精制硫酸', 32, NULL, 'CRKDH0002067', '皖LB1283', '已完成', '', NULL, 0, '2026-08-02 11:55:25');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2418, '2026-08-02', '昆山市富乐化工有限公司', '出库', '工业硫酸 50%', 25, NULL, 'CRKDH0002068', '皖H10291', '已完成', NULL, NULL, 0, '2026-08-02 14:23:05');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2419, '2026-08-02', '安庆市曙光供销运输有限责任公司', '入库', '32% 烧碱', 32, NULL, 'CRKDH0002069', '皖H13487', '已完成', '', NULL, 0, '2026-08-02 15:57:53');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2420, '2026-08-03', '安徽嘉珑凯贸易有限责任公司', '入库', '32% 烧碱', 32, '', 'CRKDH0002070', '皖H31656', '已完成', '', NULL, 0, '2026-08-03 08:15:36');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2421, '2026-08-03', '合肥金顺化工有限公司', '出库', '工业硫酸 50%', 32, NULL, 'CRKDH0002071', '皖M8B070', '待出库', NULL, NULL, 0, '2026-08-03 09:41:17');
|
||||
INSERT INTO `inbound_outbound` (`id`, `date`, `partner_company`, `business_type`, `product`, `quantity`, `plan_no`, `batch_no`, `vehicle_no`, `status`, `remarks`, `purchase_plan_id`, `is_deleted`, `created_at`) VALUES (2422, '2026-08-03', '厦门圣益石化有限公司', '出库', '工业硫酸 50%', 32, 'SX-20260803104330001', 'CRKDH0002072', '皖H57837', '待出库', '', 130, 0, '2026-08-03 10:44:17');
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
@@ -3641,7 +3644,7 @@ CREATE TABLE `purchase_plans` (
|
||||
KEY `idx_execution_status` (`execution_status`),
|
||||
KEY `idx_auto_generate_enabled` (`auto_generate_enabled`),
|
||||
KEY `idx_auto_generate_end_month` (`auto_generate_end_month`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=130 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='计划表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=131 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='计划表';
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of purchase_plans
|
||||
@@ -3765,6 +3768,7 @@ INSERT INTO `purchase_plans` (`id`, `plan_no`, `plan_date`, `start_date`, `end_d
|
||||
INSERT INTO `purchase_plans` (`id`, `plan_no`, `plan_date`, `start_date`, `end_date`, `business_type`, `product`, `specification`, `planned_quantity`, `vehicle_no`, `customer_name`, `remarks`, `is_deleted`, `execution_status`, `executed_at`, `last_weighing_slip_id`, `executed_quantity`, `created_at`, `auto_generate_enabled`, `auto_generate_end_month`, `auto_generate_last_month`) VALUES (127, 'SX-20260801012342001', '2026-08-01', '2026-08-01', '2026-08-31', '出库', '32% 烧碱', '', 1000, '', '中石化安庆分公司', '', 0, '待出库', NULL, NULL, 0, '2026-08-01 01:23:42', 1, NULL, NULL);
|
||||
INSERT INTO `purchase_plans` (`id`, `plan_no`, `plan_date`, `start_date`, `end_date`, `business_type`, `product`, `specification`, `planned_quantity`, `vehicle_no`, `customer_name`, `remarks`, `is_deleted`, `execution_status`, `executed_at`, `last_weighing_slip_id`, `executed_quantity`, `created_at`, `auto_generate_enabled`, `auto_generate_end_month`, `auto_generate_last_month`) VALUES (128, 'SX-20260801012342001', '2026-08-01', '2026-08-01', '2026-08-31', '出库', '精致硫酸', '', 200, '', '安徽永恒动力科技有限公司', '', 0, '待出库', NULL, NULL, 0, '2026-08-01 01:23:42', 1, NULL, NULL);
|
||||
INSERT INTO `purchase_plans` (`id`, `plan_no`, `plan_date`, `start_date`, `end_date`, `business_type`, `product`, `specification`, `planned_quantity`, `vehicle_no`, `customer_name`, `remarks`, `is_deleted`, `execution_status`, `executed_at`, `last_weighing_slip_id`, `executed_quantity`, `created_at`, `auto_generate_enabled`, `auto_generate_end_month`, `auto_generate_last_month`) VALUES (129, 'SX-20260801012342001', '2026-08-01', '2026-08-01', '2026-08-31', '入库', '32% 烧碱', '', 1000, '', '中盐安徽红四方股份有限公司', '', 0, '待入库', NULL, NULL, 0, '2026-08-01 01:23:42', 1, NULL, NULL);
|
||||
INSERT INTO `purchase_plans` (`id`, `plan_no`, `plan_date`, `start_date`, `end_date`, `business_type`, `product`, `specification`, `planned_quantity`, `vehicle_no`, `customer_name`, `remarks`, `is_deleted`, `execution_status`, `executed_at`, `last_weighing_slip_id`, `executed_quantity`, `created_at`, `auto_generate_enabled`, `auto_generate_end_month`, `auto_generate_last_month`) VALUES (130, 'SX-20260803104330001', '2026-08-03', '2026-08-03', '', '出库', '工业硫酸 50%', NULL, 31, '', '厦门圣益石化有限公司', '', 0, '待出库', NULL, NULL, 0, '2026-08-03 10:43:30', 0, NULL, NULL);
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
@@ -4105,7 +4109,7 @@ CREATE TABLE `weighing_slips` (
|
||||
KEY `idx_is_voided` (`is_voided`),
|
||||
KEY `idx_purchase_plan_id` (`purchase_plan_id`),
|
||||
KEY `idx_inbound_outbound_id` (`inbound_outbound_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1895 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='地磅单表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1897 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='地磅单表';
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of weighing_slips
|
||||
@@ -5963,6 +5967,8 @@ INSERT INTO `weighing_slips` (`id`, `vehicle_no`, `plan_no`, `cargo_name`, `busi
|
||||
INSERT INTO `weighing_slips` (`id`, `vehicle_no`, `plan_no`, `cargo_name`, `business_type`, `batch_no`, `supplier`, `consignee`, `gross_weight`, `gross_weight_time`, `tare_weight`, `tare_weight_time`, `deduction`, `net_weight`, `planned_quantity`, `executed_quantity`, `purchase_plan_id`, `inbound_outbound_id`, `weighing_point`, `remarks`, `current_quantity`, `is_voided`, `created_at`) VALUES (1892, '皖H38397', NULL, '32% 烧碱', '出库', 'CRKDH0002047', '安庆市山峡化工有限公司', '中盐安徽红四方股份有限公司', 50250, '2026-08-02 14:26:47', 15880, '2026-08-02 13:43:37', 0, 34370, NULL, NULL, NULL, 2397, '山峡地磅', '', 32000, 0, '2026-08-02 13:43:38');
|
||||
INSERT INTO `weighing_slips` (`id`, `vehicle_no`, `plan_no`, `cargo_name`, `business_type`, `batch_no`, `supplier`, `consignee`, `gross_weight`, `gross_weight_time`, `tare_weight`, `tare_weight_time`, `deduction`, `net_weight`, `planned_quantity`, `executed_quantity`, `purchase_plan_id`, `inbound_outbound_id`, `weighing_point`, `remarks`, `current_quantity`, `is_voided`, `created_at`) VALUES (1893, '皖H10291', NULL, '工业硫酸 50%', '出库', 'CRKDH0002068', '安庆市山峡化工有限公司', '昆山市富乐化工有限公司', 41860, '2026-08-02 15:48:32', 17030, '2026-08-02 14:58:04', 0, 24830, NULL, NULL, NULL, 2418, '山峡地磅', '', 25000, 0, '2026-08-02 14:58:06');
|
||||
INSERT INTO `weighing_slips` (`id`, `vehicle_no`, `plan_no`, `cargo_name`, `business_type`, `batch_no`, `supplier`, `consignee`, `gross_weight`, `gross_weight_time`, `tare_weight`, `tare_weight_time`, `deduction`, `net_weight`, `planned_quantity`, `executed_quantity`, `purchase_plan_id`, `inbound_outbound_id`, `weighing_point`, `remarks`, `current_quantity`, `is_voided`, `created_at`) VALUES (1894, '皖H13487', NULL, '32% 烧碱', '入库', 'CRKDH0002069', '安庆市曙光供销运输有限责任公司', '安庆市山峡化工有限公司', 48920, '2026-08-02 16:46:47', 15510, '2026-08-02 17:34:44', 0, 33410, NULL, NULL, NULL, 2419, '山峡地磅', '', 32000, 0, '2026-08-02 16:46:49');
|
||||
INSERT INTO `weighing_slips` (`id`, `vehicle_no`, `plan_no`, `cargo_name`, `business_type`, `batch_no`, `supplier`, `consignee`, `gross_weight`, `gross_weight_time`, `tare_weight`, `tare_weight_time`, `deduction`, `net_weight`, `planned_quantity`, `executed_quantity`, `purchase_plan_id`, `inbound_outbound_id`, `weighing_point`, `remarks`, `current_quantity`, `is_voided`, `created_at`) VALUES (1895, '皖H38397', NULL, '32% 烧碱', '出库', 'CRKDH0002048', '安庆市山峡化工有限公司', '中盐安徽红四方股份有限公司', 50200, '2026-08-03 08:44:08', 15870, '2026-08-03 07:48:21', 0, 34330, NULL, NULL, NULL, 2398, '山峡地磅', '', 32000, 0, '2026-08-03 07:48:23');
|
||||
INSERT INTO `weighing_slips` (`id`, `vehicle_no`, `plan_no`, `cargo_name`, `business_type`, `batch_no`, `supplier`, `consignee`, `gross_weight`, `gross_weight_time`, `tare_weight`, `tare_weight_time`, `deduction`, `net_weight`, `planned_quantity`, `executed_quantity`, `purchase_plan_id`, `inbound_outbound_id`, `weighing_point`, `remarks`, `current_quantity`, `is_voided`, `created_at`) VALUES (1896, '皖H31656', '', '32% 烧碱', '入库', 'CRKDH0002070', '安徽嘉珑凯贸易有限责任公司', '安庆市山峡化工有限公司', 48500, '2026-08-03 08:42:10', 14730, '2026-08-03 09:40:33', 0, 33770, NULL, NULL, NULL, 2420, '山峡地磅', '', 32000, 0, '2026-08-03 08:42:11');
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
-- 合同编号重复排查(只读,不改数据)
|
||||
-- 库:shanxia2.0 / crm_contract
|
||||
-- 用途:检查租户内 contract_no 是否仍有重复(含软删)
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
-- 1) 按 (contract_no, tenant_no) 分组:任何重复(含软删)
|
||||
SELECT
|
||||
contract_no,
|
||||
tenant_no,
|
||||
COUNT(*) AS cnt,
|
||||
SUM(CASE WHEN del_flag = 0 THEN 1 ELSE 0 END) AS alive_cnt,
|
||||
SUM(CASE WHEN del_flag = 1 THEN 1 ELSE 0 END) AS deleted_cnt,
|
||||
GROUP_CONCAT(
|
||||
CONCAT(id, '/del', del_flag, '/', IFNULL(customer_name, ''))
|
||||
ORDER BY del_flag, create_time
|
||||
SEPARATOR ' | '
|
||||
) AS detail
|
||||
FROM crm_contract
|
||||
GROUP BY contract_no, tenant_no
|
||||
HAVING COUNT(*) > 1
|
||||
ORDER BY cnt DESC, contract_no;
|
||||
|
||||
-- 2) 仅有效单据 (del_flag=0) 是否撞号
|
||||
SELECT
|
||||
contract_no,
|
||||
tenant_no,
|
||||
COUNT(*) AS alive_cnt,
|
||||
GROUP_CONCAT(id ORDER BY create_time SEPARATOR ' | ') AS ids,
|
||||
GROUP_CONCAT(IFNULL(customer_name, '') ORDER BY create_time SEPARATOR ' | ') AS customers
|
||||
FROM crm_contract
|
||||
WHERE del_flag = 0
|
||||
GROUP BY contract_no, tenant_no
|
||||
HAVING COUNT(*) > 1
|
||||
ORDER BY alive_cnt DESC, contract_no;
|
||||
|
||||
-- 3) 指定编号示例:SX/X-JT20260803001(含改号后的 ~DEL~ 变体)
|
||||
SELECT
|
||||
id,
|
||||
contract_no,
|
||||
contract_name,
|
||||
customer_name,
|
||||
status,
|
||||
del_flag,
|
||||
create_time,
|
||||
update_time
|
||||
FROM crm_contract
|
||||
WHERE tenant_no = 'shanxia2.0'
|
||||
AND (
|
||||
contract_no = 'SX/X-JT20260803001'
|
||||
OR contract_no LIKE 'SX/X-JT20260803001~%'
|
||||
)
|
||||
ORDER BY del_flag, create_time;
|
||||
|
||||
-- 4) 当前唯一索引是否已是全局唯一版
|
||||
SHOW INDEX FROM crm_contract WHERE Key_name LIKE 'uk_contract%';
|
||||
@@ -1,77 +0,0 @@
|
||||
-- 合同编号租户内全局唯一(含软删不复用)— 可重复执行
|
||||
-- 1) 消解已有 (contract_no, tenant_no) 撞号:保留 del_flag=0,软删行改号
|
||||
-- 2) 唯一索引改为 (contract_no, tenant_no)
|
||||
--
|
||||
-- 说明:若生产已执行过,旧索引 uk_contract_tenant_no_del 可能已不存在,
|
||||
-- 本脚本会先检查再 DROP/ADD,避免 1091。
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
-- 软删撞号改号:{原编号}~DEL~{id前8位}
|
||||
UPDATE crm_contract c
|
||||
INNER JOIN (
|
||||
SELECT contract_no, tenant_no
|
||||
FROM crm_contract
|
||||
GROUP BY contract_no, tenant_no
|
||||
HAVING COUNT(*) > 1
|
||||
) d ON c.contract_no = d.contract_no AND c.tenant_no = d.tenant_no
|
||||
SET c.contract_no = CONCAT(c.contract_no, '~DEL~', LEFT(c.id, 8)),
|
||||
c.update_time = NOW()
|
||||
WHERE c.del_flag = 1
|
||||
AND c.contract_no NOT LIKE '%~DEL~%'
|
||||
AND c.contract_no NOT LIKE '%~DUP~%';
|
||||
|
||||
-- 若仍有撞号(极端:两条都 del_flag=0),再改非 keep 的一条
|
||||
UPDATE crm_contract c
|
||||
INNER JOIN (
|
||||
SELECT contract_no, tenant_no, MIN(id) AS keep_id
|
||||
FROM crm_contract
|
||||
GROUP BY contract_no, tenant_no
|
||||
HAVING COUNT(*) > 1
|
||||
) d ON c.contract_no = d.contract_no AND c.tenant_no = d.tenant_no AND c.id <> d.keep_id
|
||||
SET c.contract_no = CONCAT(c.contract_no, '~DUP~', LEFT(c.id, 8)),
|
||||
c.update_time = NOW()
|
||||
WHERE c.contract_no NOT LIKE '%~DUP~%';
|
||||
|
||||
-- 有旧索引则删除
|
||||
SET @db := DATABASE();
|
||||
SET @sql := (
|
||||
SELECT IF(
|
||||
EXISTS(
|
||||
SELECT 1 FROM information_schema.statistics
|
||||
WHERE table_schema = @db
|
||||
AND table_name = 'crm_contract'
|
||||
AND index_name = 'uk_contract_tenant_no_del'
|
||||
),
|
||||
'ALTER TABLE crm_contract DROP INDEX `uk_contract_tenant_no_del`',
|
||||
'SELECT ''skip DROP uk_contract_tenant_no_del'' AS info'
|
||||
)
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 无新索引则添加
|
||||
SET @sql := (
|
||||
SELECT IF(
|
||||
EXISTS(
|
||||
SELECT 1 FROM information_schema.statistics
|
||||
WHERE table_schema = @db
|
||||
AND table_name = 'crm_contract'
|
||||
AND index_name = 'uk_contract_tenant_no'
|
||||
),
|
||||
'SELECT ''skip ADD uk_contract_tenant_no (already exists)'' AS info',
|
||||
'ALTER TABLE crm_contract ADD UNIQUE KEY `uk_contract_tenant_no` (`contract_no`, `tenant_no`)'
|
||||
)
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 验收:应为空
|
||||
SELECT contract_no, tenant_no, COUNT(*) AS cnt
|
||||
FROM crm_contract
|
||||
GROUP BY contract_no, tenant_no
|
||||
HAVING COUNT(*) > 1;
|
||||
|
||||
SHOW INDEX FROM crm_contract WHERE Key_name LIKE 'uk_contract%';
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
+14421
-1477
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -11,7 +11,7 @@
|
||||
Target Server Version : 50736 (5.7.36)
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 02/08/2026 22:41:14
|
||||
Date: 03/08/2026 21:30:04
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
Reference in new issue
Block a user