From 12e9ce64c364deb7ea08ba82f8d72abf6e561fc2 Mon Sep 17 00:00:00 2001
From: wuzeyu <1223318623@qq.com>
Date: 星期一, 27 五月 2024 16:53:50 +0800
Subject: [PATCH] 田间灌溉项目管理 灌溉制度模块 修改查询流浪灌溉单元和已绑定灌溉单元接口返回id类型 作物分页查询增加返回备注字段
---
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java | 40 +++++++++++++++++++++++++++++-----------
1 files changed, 29 insertions(+), 11 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..f518814 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;
@@ -27,7 +25,9 @@
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_SETID = "setId";
+ static String BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETUSERID = "setUserId";
+ static String BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETROLEID = "setRoleId";
/**
* 鎷︽埅閫昏緫瀹炵幇
@@ -43,17 +43,35 @@
if (entity instanceof BaseEntity) {
//Class<? extends Object> entityClass = entity.getClass();
Class<?> entityClass = entity.getClass();
- Method setMt = null ;
+ Method setId = null ;
+ Method setUserId = null ;
+ Method setRoleId = null ;
try{
+ /*
+ // 娣诲姞鐢ㄦ埛鏃秛serId涓鸿嚜鍔ㄧ敓鎴愪富閿�俽oleId瀛樺湪鏃舵槸涓虹敤鎴风粦瑙掕壊
+ String jsonString = JSONObject.toJSONString(entity, JSONWriter.Feature.WriteMapNullValue);
+ JSONObject jsonObject = JSONObject.parseObject(jsonString);
+ if(jsonObject.containsKey("userId") && !jsonObject.containsKey("roleId")) {
+ setUserId = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETUSERID, Long.class) ;
+ setRoleId = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETROLEID, Long.class) ;
+ }else {
+ //鏈変竴浜涘疄浣撴病鏈塱d锛屼緥濡備腑闂磋〃
+ setId = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETID, Long.class) ;
+ }
+ */
//鏈変竴浜涘疄浣撴病鏈塱d锛屼緥濡備腑闂磋〃
- setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ;
+ setId = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETID, Long.class) ;
+ // BaUser瀹炰綋涓槸setUserId, BaUserRole瀹炰綋涓寘鍚玸etUserId,鍜宻etRoleId
+ setUserId = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETUSERID, Long.class) ;
+ setRoleId = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETROLEID, Long.class) ;
}catch (Exception e){
//褰揺ntityClass娌℃湁setId鏂规硶鏃讹紝浼氭姏鍑哄紓甯�
}
- if(setMt != null){
- setMt.invoke(entity, new IDLongGenerator().generate());
+ if(setUserId != null && setRoleId == null){
+ setUserId.invoke(entity, new IDLongGenerator().generate());
+ }else if(setId != null){
+ setId.invoke(entity, new IDLongGenerator().generate());
}
-
invocation.getArgs()[PARAMETER_INDEX] = entity;
}
}
--
Gitblit v1.8.0