|
|
@ -1,29 +1,38 @@ |
|
|
|
/** |
|
|
|
* Copyright (c) 2018 人人开源 All rights reserved. |
|
|
|
* |
|
|
|
* <p> |
|
|
|
* https://www.renren.io
|
|
|
|
* |
|
|
|
* <p> |
|
|
|
* 版权所有,侵权必究! |
|
|
|
*/ |
|
|
|
|
|
|
|
package com.epmet.commons.mybatis.config; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.annotation.DbType; |
|
|
|
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
|
|
|
import com.epmet.commons.mybatis.interceptor.DataFilterInterceptor; |
|
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.core.annotation.Order; |
|
|
|
|
|
|
|
import java.util.Random; |
|
|
|
|
|
|
|
/** |
|
|
|
* mybatis-plus配置 |
|
|
|
* |
|
|
|
* @author Mark sunlightcs@gmail.com |
|
|
|
* @since 1.0.0 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Configuration |
|
|
|
public class MybatisPlusConfig { |
|
|
|
@Autowired |
|
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
|
|
/** |
|
|
|
* 配置数据权限 |
|
|
@ -45,4 +54,18 @@ public class MybatisPlusConfig { |
|
|
|
return interceptor; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* id生成器指定2个参数 防止id重复 |
|
|
|
*/ |
|
|
|
@Bean |
|
|
|
@Order(0) |
|
|
|
public DefaultIdentifierGenerator myIdentifierGenerator() { |
|
|
|
Random random = new Random(); |
|
|
|
int workerId = random.nextInt(30) + 1; |
|
|
|
int dataCenterId = random.nextInt(30) + 1; |
|
|
|
DefaultIdentifierGenerator interceptor = new DefaultIdentifierGenerator(workerId, dataCenterId); |
|
|
|
log.info("workerId:{},dataCenterId:{}", workerId, dataCenterId); |
|
|
|
return interceptor; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|