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.SysUserMapper.*(..)) || execution(* com.winsun.mapper.SchoolPackageMapper.*())")
    private void db1Aspect() {
    }

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

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

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

    @Before("db2Aspect()")
    public void db2() {
        System.out.println("切换到合伙人");
        DataSourceContextHolder.setDbType("dzqd");
    }

    @Before("db3Aspect()")
    public void db3() {
        System.out.println("切换到一人一码");
        DataSourceContextHolder.setDbType("yrym");
    }
}
