From 2f3ad0881306ba124a47733405c82b2ce34dcaf4 Mon Sep 17 00:00:00 2001 From: wkc <978997012@qq.com> Date: Sun, 8 Feb 2026 16:03:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E4=B8=AD=E4=BB=8B=E6=89=B9=E9=87=8F=E5=AF=BC=E5=85=A5ON=20DUPL?= =?UTF-8?q?ICATE=20KEY=20UPDATE=20SQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用INSERT ... ON DUPLICATE KEY UPDATE实现单次SQL完成插入或更新操作。 - 仅更新Excel中非空的字段 - 自动更新update_time和update_by - 保留created_by和create_time等审计字段 Co-Authored-By: Claude Sonnet 4.5 --- .../mapper/ccdi/CcdiBizIntermediaryMapper.xml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/ruoyi-ccdi/src/main/resources/mapper/ccdi/CcdiBizIntermediaryMapper.xml b/ruoyi-ccdi/src/main/resources/mapper/ccdi/CcdiBizIntermediaryMapper.xml index 0225943..ed52af3 100644 --- a/ruoyi-ccdi/src/main/resources/mapper/ccdi/CcdiBizIntermediaryMapper.xml +++ b/ruoyi-ccdi/src/main/resources/mapper/ccdi/CcdiBizIntermediaryMapper.xml @@ -52,4 +52,42 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + INSERT INTO ccdi_biz_intermediary ( + biz_id, person_type, person_sub_type, relation_type, + name, gender, id_type, person_id, mobile, wechat_no, + contact_address, company, social_credit_code, position, + related_num_id, data_source, remark, + created_by, updated_by, create_time, update_time + ) VALUES + + ( + #{item.bizId}, #{item.personType}, #{item.personSubType}, #{item.relationType}, + #{item.name}, #{item.gender}, #{item.idType}, #{item.personId}, #{item.mobile}, #{item.wechatNo}, + #{item.contactAddress}, #{item.company}, #{item.socialCreditCode}, #{item.position}, + #{item.relatedNumId}, #{item.dataSource}, #{item.remark}, + #{item.createdBy}, #{item.updatedBy}, #{item.createTime}, #{item.updateTime} + ) + + ON DUPLICATE KEY UPDATE + name = IF(VALUES(name) IS NOT NULL AND VALUES(name) != '', VALUES(name), name), + gender = IF(VALUES(gender) IS NOT NULL AND VALUES(gender) != '', VALUES(gender), gender), + id_type = IF(VALUES(id_type) IS NOT NULL AND VALUES(id_type) != '', VALUES(id_type), id_type), + mobile = IF(VALUES(mobile) IS NOT NULL AND VALUES(mobile) != '', VALUES(mobile), mobile), + wechat_no = IF(VALUES(wechat_no) IS NOT NULL AND VALUES(wechat_no) != '', VALUES(wechat_no), wechat_no), + contact_address = IF(VALUES(contact_address) IS NOT NULL AND VALUES(contact_address) != '', VALUES(contact_address), contact_address), + company = IF(VALUES(company) IS NOT NULL AND VALUES(company) != '', VALUES(company), company), + social_credit_code = IF(VALUES(social_credit_code) IS NOT NULL AND VALUES(social_credit_code) != '', VALUES(social_credit_code), social_credit_code), + position = IF(VALUES(position) IS NOT NULL AND VALUES(position) != '', VALUES(position), position), + related_num_id = IF(VALUES(related_num_id) IS NOT NULL AND VALUES(related_num_id) != '', VALUES(related_num_id), related_num_id), + relation_type = IF(VALUES(relation_type) IS NOT NULL AND VALUES(relation_type) != '', VALUES(relation_type), relation_type), + person_type = IF(VALUES(person_type) IS NOT NULL AND VALUES(person_type) != '', VALUES(person_type), person_type), + person_sub_type = IF(VALUES(person_sub_type) IS NOT NULL AND VALUES(person_sub_type) != '', VALUES(person_sub_type), person_sub_type), + data_source = IF(VALUES(data_source) IS NOT NULL AND VALUES(data_source) != '', VALUES(data_source), data_source), + remark = IF(VALUES(remark) IS NOT NULL, VALUES(remark), remark), + update_time = NOW(), + update_by = VALUES(updated_by) + +