From 4513ef24bf9b188c2a77d6ce94f1a6b7e9ebf0e6 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期日, 27 四月 2025 20:40:19 +0800
Subject: [PATCH] fix(irrigatePlan): 修正灌溉计划开始时间逻辑

---
 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/config/VirtualCardInUseInterceptor.java |   61 ++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/config/VirtualCardInUseInterceptor.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/config/VirtualCardInUseInterceptor.java
new file mode 100644
index 0000000..5f0a2e4
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/config/VirtualCardInUseInterceptor.java
@@ -0,0 +1,61 @@
+package com.dy.pipIrrGlobal.config;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2025/4/27 9:19
+ * @Description
+ */
+import com.dy.pipIrrGlobal.pojoSe.SeVirtualCard;
+import lombok.extern.slf4j.Slf4j;
+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.Signature;
+import java.lang.reflect.Method;
+
+/**
+ * 鎷︽埅铏氭嫙鍗¤〃鐨勬洿鏂版搷浣滐紝浣夸笉鑳借缃崰鐢ㄧ姸鎬佹搷浣溿��
+ */
+@Intercepts({
+        @Signature(
+                type = Executor.class,
+                method = "update",
+                args = {
+                        MappedStatement.class,
+                        Object.class
+                }
+        )
+})
+@Slf4j
+public class VirtualCardInUseInterceptor  implements Interceptor {
+
+    static int MAPPED_STATEMENT_INDEX = 0;
+    static int PARAMETER_INDEX = 1;
+    static String BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETINUSE = "setInUse";
+
+    @Override
+    public Object intercept(Invocation invocation) throws Throwable {
+        Object entity = invocation.getArgs()[PARAMETER_INDEX];
+        if (entity instanceof SeVirtualCard) {
+            MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[MAPPED_STATEMENT_INDEX];
+            SqlCommandType commandType = mappedStatement.getSqlCommandType();
+            if (commandType.equals(SqlCommandType.UPDATE)) {
+                Class<?> entityClass = entity.getClass();
+                Method setInUse = null;
+                try {
+                    setInUse = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETINUSE, Byte.class);
+                } catch (Exception e) {
+                    //褰揺ntityClass娌℃湁setInUse鏂规硶鏃讹紝浼氭姏鍑哄紓甯�
+                }
+                if (setInUse != null) {
+                    setInUse.invoke(entity, (byte)0);
+                }
+                invocation.getArgs()[PARAMETER_INDEX] = entity;
+            }
+        }
+        return invocation.proceed();
+    }
+}

--
Gitblit v1.8.0