package com.winsun.migration.datasource;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Order(value = -100)
@Slf4j
@Aspect
public class DataSourceAspect {
    @Pointcut("execution(* com.winsun.migration.mapper.db1..*.*(..))"
            + "|| execution(* com.winsun.mapper.*.*(..)) || execution(* com.winsun.mapper.activity.*.*(..))")
    private void db1Aspect() {
    }

    @Pointcut("execution(* com.winsun.migration.mapper.db2..*.*(..))"
            )
    private void db2Aspect() {
    }

    @Before("db1Aspect()")
    public void db1() {
        System.out.println("切换到新框架数据源");
        DataSourceContextHolder.setDbType("schoolCenter");
    }

    @Before("db2Aspect()")
    public void db2() {
        System.out.println("切换到旧框架数据源");
        DataSourceContextHolder.setDbType("dzqd");
    }
}
