From b5b296cc01699f96029b07073fe9d0078bedd445 Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期一, 26 二月 2024 16:32:35 +0800
Subject: [PATCH] 2024-02-26 朱宝民 解决添加用户主键不自动创建的问题,部分微信支付代码

---
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java
index eca91c8..960f6d0 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java
@@ -1,16 +1,14 @@
 package com.dy.common.mybatis;
 
 
+import com.alibaba.fastjson2.JSONObject;
+import com.alibaba.fastjson2.JSONWriter;
 import com.dy.common.po.BaseEntity;
 import com.dy.common.util.IDLongGenerator;
 import org.apache.ibatis.executor.Executor;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.mapping.SqlCommandType;
-import org.apache.ibatis.plugin.Interceptor;
-import org.apache.ibatis.plugin.Intercepts;
-import org.apache.ibatis.plugin.Invocation;
-import org.apache.ibatis.plugin.Plugin;
-import org.apache.ibatis.plugin.Signature;
+import org.apache.ibatis.plugin.*;
 
 import java.lang.reflect.Method;
 
@@ -28,6 +26,7 @@
     static int MAPPED_STATEMENT_INDEX = 0;
     static int PARAMETER_INDEX = 1;
     static String BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME = "setId";
+    static String BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME2 = "setUserId";
 
     /**
      * 鎷︽埅閫昏緫瀹炵幇
@@ -45,8 +44,15 @@
                 Class<?> entityClass = entity.getClass();
                 Method setMt = null ;
                 try{
-                    //鏈変竴浜涘疄浣撴病鏈塱d锛屼緥濡備腑闂磋〃
-                    setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ;
+                    // 鍒ゆ柇涓婚敭鏄痠d杩樻槸userId
+                    String jsonString = JSONObject.toJSONString(entity, JSONWriter.Feature.WriteMapNullValue);
+                    JSONObject jsonObject = JSONObject.parseObject(jsonString);
+                    if(jsonObject.containsKey("userId")) {
+                        setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME2, Long.class) ;
+                    }else {
+                        //鏈変竴浜涘疄浣撴病鏈塱d锛屼緥濡備腑闂磋〃
+                        setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ;
+                    }
                 }catch (Exception e){
                     //褰揺ntityClass娌℃湁setId鏂规硶鏃讹紝浼氭姏鍑哄紓甯�
                 }

--
Gitblit v1.8.0