package com.nuvole.four.config.mybatisInt;//package com.nuvole.shop.config.mybatisInt;
|
//
|
//import com.nuvole.util.AESUtil;
|
//import lombok.extern.slf4j.Slf4j;
|
//import org.apache.ibatis.binding.MapperMethod;
|
//import org.apache.ibatis.executor.Executor;
|
//import org.apache.ibatis.mapping.MappedStatement;
|
//import org.apache.ibatis.plugin.*;
|
//import org.apache.ibatis.session.ResultHandler;
|
//import org.apache.ibatis.session.RowBounds;
|
//import org.springframework.stereotype.Component;
|
//
|
//import java.util.Properties;
|
//
|
///**
|
// * @ClassName MySqlInterceptor
|
// * @Author cy
|
// * @Date 2022/12/13
|
// * @Description
|
// * @Version 1.0
|
// **/
|
//@Slf4j
|
//@Intercepts({@Signature(type = Executor.class, method = "query",
|
// args = {MappedStatement.class,
|
// Object.class,
|
// RowBounds.class,
|
// ResultHandler.class})})
|
//@Component
|
//public class MySqlInterceptor implements Interceptor {
|
//// @Autowired
|
//// private ActivityDetailHeadBandCoupDetailService activityDetailHeadBandCoupDetailService;
|
//
|
// @Override
|
// /**
|
// * intercept 方法用来对拦截的 sql 进行具体的操作
|
// * 本拦截方法只对 mapper 接口中的 searchByQuery 方法进行拦截,实际每个方法都拦截了,
|
// * 只是只有 searchByQuery 方法时,才真正执行 拦截的相关操作
|
// * @param invocation 拦截器执行器
|
// * @return
|
// * @throws Throwable 异常信息
|
// */
|
// public Object intercept(Invocation invocation) throws Throwable {
|
// // logger.info("执行intercept方法:{}", invocation.toString());
|
// // 获取 invocation 传递的参数
|
// Object[] args = invocation.getArgs();
|
//
|
// MappedStatement ms = (MappedStatement) args[0];
|
// // 获取执行的该拦截器的全路径方法 比如你的 UserInfoMapper 接口的 getById 方法, com.xx.UserInfoMapper.getById
|
// String id = ms.getId();
|
// // 如果不是 searchByQuery 方法,就不进行相关的拦截操作
|
// Object proceed = invocation.proceed();
|
// if (!filterMethodById(id)) {
|
// return proceed;
|
// }
|
//
|
// // 该参数类型 org.apache.ibatis.binding.MapperMethod$ParamMap
|
// Object parameterObject = args[1];
|
// // 获取传递的参数, 主要包含三个参数 1. 查询语句 searchQuery, 2. 查询偏移 pageOffset, 3. 查询每页的数据条数
|
// MapperMethod.ParamMap paramMap = (MapperMethod.ParamMap) parameterObject;
|
//
|
// Long memberId = null;
|
// String cardNo = null;
|
// if (paramMap.containsKey("memberId")) {
|
// memberId = (Long) paramMap.get("memberId");
|
// }
|
// if (paramMap.containsKey("cardNo")) {
|
// cardNo = AESUtil.decode((String) paramMap.get("cardNo"));
|
// }
|
//// activityDetailHeadBandCoupDetailService.doGetGiveCoupon(memberId, cardNo);
|
// log.info("拦截了 " + id + " 相关执行。");
|
// return proceed;
|
// }
|
//
|
// @Override
|
// /***
|
// * 定义拦截的类 Executor、ParameterHandler、StatementHandler、ResultSetHandler当中的一个
|
// * @param target 需要拦截的类
|
// * @return
|
// */
|
// public Object plugin(Object target) {
|
// if (target instanceof Executor) {
|
// return Plugin.wrap(target, this);
|
// }
|
// return target;
|
// }
|
//
|
// @Override
|
// /**
|
// * 属性相关操作
|
// * 设置和自定义属性值
|
// * @param properties 属性值
|
// */
|
// public void setProperties(Properties properties) {
|
// // 获取属性
|
// // String value1 = properties.getProperty("prop1");
|
// }
|
//
|
//
|
// /**
|
// * 根据获取到执行 id 找到对应的方法,只在 insertSelective 方法上执行拦截
|
// *
|
// * @param id 根据 MappedStatement 获取到的 id 属性
|
// * @return 是否是 insertSelective 方法
|
// */
|
// private boolean filterMethodById(String id) {
|
// System.out.println("id: " + id);
|
// return id.contains("com.nuvole.shop.mapper.extend.StoreMemberBankcardMapper.insertSelective");
|
// }
|
//
|
// private void headBandGiveCoup(Long memberId) {
|
//
|
// }
|
//
|
//}
|