File was renamed from pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/config/VirtualCardInUseInterceptor.java |
| | |
| | | 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.plugin.Intercepts; |
| | | import org.apache.ibatis.plugin.Invocation; |
| | | import org.apache.ibatis.plugin.Signature; |
| | | |
| | | import java.lang.reflect.Method; |
| | | |
| | | /** |
| | | * 拦截虚拟卡表的更新操作,使不能设置占用状态操作。 |
| | | * @Author: liurunyu |
| | | * @Date: 2025/5/15 11:10 |
| | | * @Description |
| | | */ |
| | | /** |
| | | * 拦截虚拟卡表的更新操作,使: |
| | | * 字段in_use意为占用状态,当为true时统一设置值为0 |
| | | * 字段money意为剩余金额,当为true时统一设置值为10000 |
| | | */ |
| | | @Intercepts({ |
| | | @Signature( |
| | |
| | | ) |
| | | }) |
| | | @Slf4j |
| | | public class VirtualCardInUseInterceptor implements Interceptor { |
| | | public class VirtualCardSetDefaultInterceptor implements Interceptor { |
| | | |
| | | static int MAPPED_STATEMENT_INDEX = 0; |
| | | static int PARAMETER_INDEX = 1; |
| | | static String BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETINUSE = "setInUse"; |
| | | static String BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETMONEY = "setMoney"; |
| | | |
| | | @Override |
| | | public Object intercept(Invocation invocation) throws Throwable { |
| | |
| | | if (setInUse != null) { |
| | | setInUse.invoke(entity, (byte)0); |
| | | } |
| | | |
| | | Method setMoney = null; |
| | | try { |
| | | setMoney = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_SETMONEY, Double.class); |
| | | } catch (Exception e) { |
| | | //当entityClass没有setMoney方法时,会抛出异常 |
| | | } |
| | | if (setMoney != null) { |
| | | setMoney.invoke(entity, 10000.00D); |
| | | } |
| | | invocation.getArgs()[PARAMETER_INDEX] = entity; |
| | | } |
| | | } |