添加多数据源 修改逻辑代码

master
bynt 1 year ago
parent 6cae668dfc
commit 313b87eca3

@ -18,6 +18,7 @@
<druid.version>1.1.22</druid.version> <druid.version>1.1.22</druid.version>
<hutool.version>5.7.16</hutool.version> <hutool.version>5.7.16</hutool.version>
<maven.test.skip>true</maven.test.skip> <maven.test.skip>true</maven.test.skip>
<shardingsphere.version>5.1.1</shardingsphere.version>
<mysql-connector.version>8.0.13</mysql-connector.version> <mysql-connector.version>8.0.13</mysql-connector.version>
<maven.test.failure.ignore>true</maven.test.failure.ignore> <maven.test.failure.ignore>true</maven.test.failure.ignore>
</properties> </properties>
@ -77,6 +78,20 @@
<artifactId>zip4j</artifactId> <artifactId>zip4j</artifactId>
<version>1.3.2</version> <version>1.3.2</version>
</dependency> </dependency>
<!--shardingsphere-->
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -0,0 +1,65 @@
package com.baiyee.adcallback.config;
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
import com.alibaba.druid.util.Utils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.*;
import java.io.IOException;
/**
* @author Enzo
* @date : 2023/6/7
*/
@Configuration
public class DruidConfig {
/**
* 广
*/
@SuppressWarnings({"rawtypes", "unchecked"})
@Bean
@ConditionalOnProperty(name = "spring.datasource.druid.stat-view-servlet.enabled", havingValue = "true")
public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties) {
// 获取web监控页面的参数
DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
// 提取common.js的配置路径
String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*";
String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
final String filePath = "support/http/resources/js/common.js";
// 创建filter进行过滤
Filter filter = new Filter() {
@Override
public void init(javax.servlet.FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
chain.doFilter(request, response);
// 重置缓冲区,响应头不会被重置
response.resetBuffer();
// 获取common.js
String text = Utils.readFromResource(filePath);
// 正则替换banner, 除去底部的广告信息
text = text.replaceAll("<a.*?banner\"></a><br/>", "");
text = text.replaceAll("powered.*?shrek.wang</a>", "");
response.getWriter().write(text);
}
@Override
public void destroy() {
}
};
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(filter);
registrationBean.addUrlPatterns(commonJsPattern);
return registrationBean;
}
}

@ -0,0 +1,27 @@
package com.baiyee.adcallback.config;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
import com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration;
import com.alibaba.druid.spring.boot.autoconfigure.stat.DruidSpringAopConfiguration;
import com.alibaba.druid.spring.boot.autoconfigure.stat.DruidStatViewServletConfiguration;
import com.alibaba.druid.spring.boot.autoconfigure.stat.DruidWebStatFilterConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* @author Enzo
* @date : 2023/6/7
*/
@Configuration
@ConditionalOnClass(DruidDataSourceAutoConfigure.class)
@EnableConfigurationProperties({DruidStatProperties.class})
@Import({
DruidSpringAopConfiguration.class,
DruidStatViewServletConfiguration.class,
DruidWebStatFilterConfiguration.class,
DruidFilterConfiguration.class})
public class DruidShardingJdbcDataSourceConfiguration {
}

@ -25,7 +25,7 @@ public interface TbBDNewBackdataEntityRepository extends JpaRepository<TbBdNewBa
* @return * @return
*/ */
@Query("select new com.baiyee.adcallback.api.dto.PlateFormDTO(imei as imei,tag as tag) from " + @Query("select new com.baiyee.adcallback.api.dto.PlateFormDTO(imei as imei,tag as tag) from " +
" TbBdBackdataEntity where imei != :imeiStrFirst and imei != :imeiSecond " + " TbBdNewBackdataEntity where imei != :imeiStrFirst and imei != :imeiSecond " +
"and gmtCreate >= :startDate and gmtCreate < :endDate and tag in :tag group by imei,tag") "and gmtCreate >= :startDate and gmtCreate < :endDate and tag in :tag group by imei,tag")
List<PlateFormDTO> queryPlateFormDTO(@Param("imeiStrFirst") String imeiStrFirst, @Param("imeiSecond") String imeiSecond, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, @Param("tag") List<String> tag); List<PlateFormDTO> queryPlateFormDTO(@Param("imeiStrFirst") String imeiStrFirst, @Param("imeiSecond") String imeiSecond, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, @Param("tag") List<String> tag);

@ -25,9 +25,9 @@ public interface TbGdtNewBackdataEntityRepository extends JpaRepository<TbGdtNew
* @param tag * @param tag
* @return * @return
*/ */
@Query("select new com.baiyee.adcallback.api.dto.PlateFormDTO(muid as imei,tag as tag) from " + @Query("select new com.baiyee.adcallback.api.dto.PlateFormDTO(imei as imei,tag as tag) from " +
" TbGdtBackdataEntity where muid != :imeiStrFirst and muid != :imeiSecond " + " TbGdtNewBackdataEntity where imei != :imeiStrFirst and imei != :imeiSecond " +
"and gmtCreate >= :startDate and gmtCreate < :endDate and tag in :tag and deviceOsType = :models group by muid,tag") "and gmtCreate >= :startDate and gmtCreate < :endDate and tag in :tag and deviceOsType = :models group by imei,tag")
List<PlateFormDTO> queryPlateFormDTO(@Param("imeiStrFirst") String imeiStrFirst, @Param("imeiSecond") String imeiSecond, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, @Param("tag") List<String> tag, @Param("models") String models); List<PlateFormDTO> queryPlateFormDTO(@Param("imeiStrFirst") String imeiStrFirst, @Param("imeiSecond") String imeiSecond, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, @Param("tag") List<String> tag, @Param("models") String models);
@Query(value = "SELECT * FROM tb_gdt_new_backdata WHERE imei != '' AND imei != '__imei__' AND gmt_create > ?1 AND gmt_create < ?2", nativeQuery = true) @Query(value = "SELECT * FROM tb_gdt_new_backdata WHERE imei != '' AND imei != '__imei__' AND gmt_create > ?1 AND gmt_create < ?2", nativeQuery = true)

@ -24,6 +24,7 @@ public interface TbJLV1BackdataEntityRepository extends JpaRepository<TbJLBackDa
/** /**
* *
*
* @param imeiStrFirst * @param imeiStrFirst
* @param imeiSecond * @param imeiSecond
* @param startDate * @param startDate
@ -32,10 +33,12 @@ public interface TbJLV1BackdataEntityRepository extends JpaRepository<TbJLBackDa
* @return * @return
*/ */
@Query("select new com.baiyee.adcallback.api.dto.PlateFormDTO(imei as imei,tag as tag) from " + @Query("select new com.baiyee.adcallback.api.dto.PlateFormDTO(imei as imei,tag as tag) from " +
" TbJlBackdataEntity where imei != :imeiStrFirst and imei != :imeiSecond " + " TbJLBackDataV1Entity where imei != :imeiStrFirst and imei != :imeiSecond " +
"and gmtCreate >= :startDate and gmtCreate < :endDate and tag in :tag group by imei,tag") "and gmtCreate >= :startDate and gmtCreate < :endDate and tag in :tag group by imei,tag")
List<PlateFormDTO> queryPlateFormDTO(@Param("imeiStrFirst") String imeiStrFirst, @Param("imeiSecond") String imeiSecond, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, @Param("tag") List<String> tag); List<PlateFormDTO> queryPlateFormDTO(@Param("imeiStrFirst") String imeiStrFirst, @Param("imeiSecond") String imeiSecond, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, @Param("tag") List<String> tag);
@Query(value = "SELECT * FROM tb_jl_v1_backdata WHERE imei != '' AND imei != '__IMEI__' AND gmt_create > ?1 AND gmt_create < ?2", nativeQuery = true) @Query(value = "SELECT * FROM tb_jl_v1_backdata WHERE imei != '' AND imei != '__IMEI__' AND gmt_create > ?1 AND gmt_create < ?2", nativeQuery = true)
List<TbJLBackDataV1Entity> queryByDate(String startDate, String endDate); List<TbJLBackDataV1Entity> queryByDate(String startDate, String endDate);
List<TbJLBackDataV1Entity> queryBytag(String s);
} }

@ -28,7 +28,7 @@ public interface TbJLV2BackdataEntityRepository extends JpaRepository<TbJLBackDa
* *
*/ */
@Query("select new com.baiyee.adcallback.api.dto.PlateFormDTO(imei as imei,tag as tag) from " + @Query("select new com.baiyee.adcallback.api.dto.PlateFormDTO(imei as imei,tag as tag) from " +
" TbJlBackdataEntity where imei != :imeiStrFirst and imei != :imeiSecond " + " TbJLBackDataV2Entity where imei != :imeiStrFirst and imei != :imeiSecond " +
"and gmtCreate >= :startDate and gmtCreate < :endDate and tag in :tag group by imei,tag") "and gmtCreate >= :startDate and gmtCreate < :endDate and tag in :tag group by imei,tag")
List<PlateFormDTO> queryPlateFormDTO(@Param("imeiStrFirst") String imeiStrFirst, @Param("imeiSecond") String imeiSecond, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, @Param("tag") List<String> tag); List<PlateFormDTO> queryPlateFormDTO(@Param("imeiStrFirst") String imeiStrFirst, @Param("imeiSecond") String imeiSecond, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, @Param("tag") List<String> tag);

@ -25,7 +25,7 @@ public interface TbKSNewBackdataEntityRepository extends JpaRepository<TbKSNewBa
* @return * @return
*/ */
@Query("select new com.baiyee.adcallback.api.dto.PlateFormDTO(imei as imei,tag as tag) from " + @Query("select new com.baiyee.adcallback.api.dto.PlateFormDTO(imei as imei,tag as tag) from " +
" TbKsBackdataEntity where imei != :imeiStrFirst and imei != :imeiSecond " + " TbKSNewBackdataEntity where imei != :imeiStrFirst and imei != :imeiSecond " +
"and gmtCreate >= :startDate and gmtCreate < :endDate and tag in :tag group by imei,tag") "and gmtCreate >= :startDate and gmtCreate < :endDate and tag in :tag group by imei,tag")
List<PlateFormDTO> queryPlateFormDTO(@Param("imeiStrFirst") String imeiStrFirst, @Param("imeiSecond") String imeiSecond, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, @Param("tag") List<String> tag); List<PlateFormDTO> queryPlateFormDTO(@Param("imeiStrFirst") String imeiStrFirst, @Param("imeiSecond") String imeiSecond, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, @Param("tag") List<String> tag);

@ -28,7 +28,6 @@ public interface TbPlatformDeliveryEntityRepository extends JpaRepository<TbPlat
List<RepeatFormDTO> findByTag(Long userId, String tagStr, int num); List<RepeatFormDTO> findByTag(Long userId, String tagStr, int num);
/** /**
* 0 * 0
* *

@ -22,5 +22,19 @@ public interface BackDataEntityService {
* @param value * @param value
* @return * @return
*/ */
@Deprecated
List<PlateFormDTO> queryPlateFormDTO(String imeiFirst, String imeiSecond, DateTime date, DateTime offsetMinute, List<String> tagStr, Integer value); List<PlateFormDTO> queryPlateFormDTO(String imeiFirst, String imeiSecond, DateTime date, DateTime offsetMinute, List<String> tagStr, Integer value);
/**
* imei
*
* @param imeiFirst
* @param imeiSecond
* @param date
* @param offsetMinute
* @param tagStr
* @param value
* @return
*/
List<PlateFormDTO> queryNewPlateFormDTO(String imeiFirst, String imeiSecond, DateTime offsetMinute, DateTime date, List<String> tagStr, Integer value);
} }

@ -8,6 +8,7 @@ import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List; import java.util.List;
@ -33,9 +34,20 @@ public class BackDataEntityServiceImpl implements BackDataEntityService {
private final TbVivoBackdataEntityRepository tbVivoBackdataEntityRepository; private final TbVivoBackdataEntityRepository tbVivoBackdataEntityRepository;
private final TbJLV1BackdataEntityRepository jlv1BackdataEntityRepository;
private final TbJLV2BackdataEntityRepository jlv2BackdataEntityRepository;
private final TbGdtNewBackdataEntityRepository tbGdtNewBackdataEntityRepository;
private final TbKSNewBackdataEntityRepository tbKSNewBackdataEntityRepository;
private final TbBDNewBackdataEntityRepository tbBDNewBackdataEntityRepository;
@Override @Override
public List<PlateFormDTO> queryPlateFormDTO @Deprecated
(String imeiFirst, String imeiSecond, DateTime date, DateTime offsetMinute, List<String> tagStr, Integer value) { public List<PlateFormDTO> queryPlateFormDTO(String imeiFirst, String imeiSecond, DateTime date, DateTime offsetMinute, List<String> tagStr, Integer value) {
List<PlateFormDTO> formDTOList = Lists.newArrayList(); List<PlateFormDTO> formDTOList = Lists.newArrayList();
switch (value) { switch (value) {
@ -68,4 +80,50 @@ public class BackDataEntityServiceImpl implements BackDataEntityService {
return formDTOList; return formDTOList;
} }
@Override
public List<PlateFormDTO> queryNewPlateFormDTO(String imeiFirst, String imeiSecond, DateTime offsetMinute, DateTime date, List<String> tagStr, Integer value) {
List<PlateFormDTO> newFormDTOList = Lists.newArrayList();
switch (value) {
case 1:
List<String> v1TagList = Lists.newArrayList();
List<String> v2TagList = Lists.newArrayList();
for (String tag : tagStr) {
((tag.lastIndexOf("v2") > 0) ? v1TagList : v2TagList).add(tag);
}
// 巨量
if (!CollectionUtils.isEmpty(v1TagList)) {
newFormDTOList.addAll(jlv1BackdataEntityRepository.queryPlateFormDTO(imeiFirst, imeiSecond, date, offsetMinute, v1TagList));
}
if (!CollectionUtils.isEmpty(v2TagList)) {
newFormDTOList.addAll(jlv2BackdataEntityRepository.queryPlateFormDTO(imeiFirst, imeiSecond, date, offsetMinute, v2TagList));
}
break;
case 2:
// 快手
newFormDTOList = tbKSNewBackdataEntityRepository.queryPlateFormDTO(imeiFirst, imeiSecond, date, offsetMinute, tagStr);
break;
case 3:
// UC
newFormDTOList = tbUcBackdataEntityRepository.queryPlateFormDTO(imeiFirst, imeiSecond, date, offsetMinute, tagStr);
break;
case 4:
// VIVO
newFormDTOList = tbVivoBackdataEntityRepository.queryPlateFormDTO(imeiFirst, imeiSecond, date, offsetMinute, tagStr);
break;
case 5:
// 百度
newFormDTOList = tbBDNewBackdataEntityRepository.queryPlateFormDTO(imeiFirst, imeiSecond, date, offsetMinute, tagStr);
break;
case 6:
// 广点通
newFormDTOList = tbGdtNewBackdataEntityRepository.queryPlateFormDTO(imeiFirst, imeiSecond, date, offsetMinute, tagStr, "android");
break;
default:
}
return newFormDTOList;
}
} }

@ -0,0 +1,165 @@
package com.baiyee.adcallback.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baiyee.adcallback.api.dto.PlateFormDTO;
import com.baiyee.adcallback.api.dto.RepeatFormDTO;
import com.baiyee.adcallback.common.enums.DeliveryPlatformEnum;
import com.baiyee.adcallback.config.pojo.PlatformTransmitDTO;
import com.baiyee.adcallback.repository.entity.TbPlatformCompanyEntity;
import com.baiyee.adcallback.repository.entity.TbPlatformDeliveryEntity;
import com.baiyee.adcallback.service.AdPlatformDeliveryService;
import com.baiyee.adcallback.service.AdPlatformService;
import com.baiyee.adcallback.service.BackDataEntityService;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
* @author Enzo
* @date : 2022/10/13
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class NewPlatFormRecordTask {
@Value("${platform.authToken}")
private String authToken;
@Value("${platform.url}")
private String url;
private DateTime beginTime;
private final AdPlatformService adPlatformService;
private final BackDataEntityService backDataEntityService;
private final AdPlatformDeliveryService adPlatformDeliveryService;
/**
*
*/
@Scheduled(cron = "0 0/9 * * * ? ")
@Transactional(rollbackFor = Exception.class)
public void deliveryPlatform() {
List<TbPlatformCompanyEntity> platforms
= adPlatformService.findByPlatTag(1);
if (CollUtil.isNotEmpty(platforms)) {
for (TbPlatformCompanyEntity platform : platforms) {
DateTime date = DateUtil.date();
if (CollUtil.isNotEmpty(platform.getTagStr())) {
String tagStr = platform.getTagStr().get(0);
if (tagStr.contains(StrPool.DASHED)) {
Integer value = DeliveryPlatformEnum.getValue
(tagStr.substring(0, tagStr.indexOf(StrPool.DASHED)));
// 偏移十分钟
DateTime offsetMinute = ObjectUtil.isNull(beginTime) ?
DateUtil.offsetMinute(date, -9) :
DateUtil.offsetMinute(beginTime, -9);
beginTime = offsetMinute;
log.info("================ the begin time as {} end time as {} ================", offsetMinute, date);
List<PlateFormDTO> dtoList = backDataEntityService.queryNewPlateFormDTO
(CharSequenceUtil.EMPTY, "__IMEI__", offsetMinute, date, platform.getTagStr(), value);
log.info("================ the dto list as {} ================", dtoList.size());
if (CollUtil.isNotEmpty(dtoList)) {
// tag进行分组
Map<String, List<PlateFormDTO>> listMap = dtoList.stream()
.collect(Collectors.groupingBy(PlateFormDTO::getTag));
List<RepeatFormDTO> saveDataList = Lists.newArrayList();
for (Map.Entry<String, List<PlateFormDTO>> stringListEntry : listMap.entrySet()) {
List<PlateFormDTO> list = listMap.get(stringListEntry.getKey());
List<RepeatFormDTO> repeatFormDTOList = Convert.toList(RepeatFormDTO.class, list);
repeatFormDTOList.forEach(dto -> dto.setUserId(platform.getUserId()));
// 去除重复数据
Set<RepeatFormDTO> originSet =
Sets.newHashSet(repeatFormDTOList);
// 查询数据
List<RepeatFormDTO> tagLists =
adPlatformDeliveryService.findByTag(platform.getUserId(), stringListEntry.getKey(), 0);
Set<RepeatFormDTO> querySet = Sets.newHashSet(tagLists);
// 差集去除数据
List<RepeatFormDTO> differentData
= Lists.newArrayList(Sets.difference(originSet, querySet));
// 保存将要插入数据
saveDataList.addAll(differentData);
}
// 分批发送
List<List<RepeatFormDTO>> partition = Lists.partition(saveDataList, 500);
int num = 0;
for (List<RepeatFormDTO> formDTOList : partition) {
PlatformTransmitDTO dto = new PlatformTransmitDTO();
dto.setList(formDTOList);
dto.setAuthToken(authToken);
dto.setUserId(platform.getUserId());
dto.setTaskId(platform.getTaskId());
String post = HttpUtil.post(url, JSONUtil.toJsonStr(dto));
Object status = new JSONObject(post).get("status");
if (ObjectUtil.isNotNull(status) &&
Integer.parseInt(status.toString()) != 0) {
num++;
}
}
if (num == 0 && CollUtil.isNotEmpty(saveDataList)) {
// 异步插入数据
CompletableFuture.runAsync(() -> {
List<TbPlatformDeliveryEntity> deliveryStatisticEntityList =
Convert.toList(TbPlatformDeliveryEntity.class, saveDataList);
// 批量保存
adPlatformDeliveryService.saveAll(deliveryStatisticEntityList);
});
beginTime = date;
}
log.error("================ the new datalist size as {} ================", saveDataList.size());
}
if (CollUtil.isEmpty(dtoList)) {
beginTime = date;
}
}
}
}
}
}
/**
*
*/
@Scheduled(cron = "0 30 23 * * ? ")
@Transactional(rollbackFor = Exception.class)
public void autoDeal() {
log.info("++++++++++++++++++++++ change plate form sync start time {} ++++++++++++++++", DateUtil.now());
//删除剩余天数为0的数据
adPlatformDeliveryService.deleteAllByDayNum(0);
//所有的数据剩余天数-1
adPlatformDeliveryService.updateAllByDayNum();
log.info("++++++++++++++++++++++ change plate form Sync end time {} ++++++++++++++++", DateUtil.now());
}
}

@ -60,7 +60,9 @@ public class PlatFormRecordTask {
/** /**
* *
*
*/ */
@Deprecated
@Scheduled(cron = "0 0/10 * * * ? ") @Scheduled(cron = "0 0/10 * * * ? ")
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deliveryPlatform() { public void deliveryPlatform() {
@ -145,21 +147,4 @@ public class PlatFormRecordTask {
} }
/**
*
*/
@Scheduled(cron = "0 30 23 * * ? ")
@Transactional(rollbackFor = Exception.class)
public void autoDeal() {
log.info("++++++++++++++++++++++ change plate form sync start time {} ++++++++++++++++", DateUtil.now());
//删除剩余天数为0的数据
adPlatformDeliveryService.deleteAllByDayNum(0);
//所有的数据剩余天数-1
adPlatformDeliveryService.updateAllByDayNum();
log.info("++++++++++++++++++++++ change plate form Sync end time {} ++++++++++++++++", DateUtil.now());
}
} }

@ -2,52 +2,229 @@ x-debug:
mode: '1' mode: '1'
#配置数据源 #配置数据源
spring: spring:
autoconfigure:
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
shardingsphere:
# 数据源配置
datasource: datasource:
druid: common:
db-type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost/db_ad?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true
username: root
password: root
# 初始连接数 # 初始连接数
initial-size: 5 initial-size: 6
# 最小连接数 # 最小连接池数量
min-idle: 10 min-idle: 3
# 最大连接数 # 最大连接池数量
max-active: 20 maxActive: 20
# 获取连接超时时间 # 配置获取连接等待超时的时间
max-wait: 5000 maxWait: 60000
# 连接有效性检测时间 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
time-between-eviction-runs-millis: 60000 timeBetweenEvictionRunsMillis: 60000
# 连接在池中最小生存的时间 # 配置一个连接在池中最小生存的时间,单位是毫秒
min-evictable-idle-time-millis: 300000 minEvictableIdleTimeMillis: 300000
# 连接在池中最大生存的时间 # 配置一个连接在池中最大生存的时间,单位是毫秒
max-evictable-idle-time-millis: 900000 maxEvictableIdleTimeMillis: 900000
test-while-idle: true #Oracle需要打开注释
test-on-borrow: false validationQuery: SELECT 1 FROM DUAL
test-on-return: false testWhileIdle: true
# # 检测连接是否有效 testOnBorrow: false
validation-query: select 1 testOnReturn: false
# 配置监控统计 # 打开PSCache并且指定每个连接上PSCache的大小
webStatFilter: poolPreparedStatements: true
enabled: true maxPoolPreparedStatementPerConnectionSize: 20
stat-view-servlet: # 配置监控统计拦截的filters去掉后监控界面sql无法统计'wall'用于防火墙
enabled: true filters: stat,wall,slf4j
url-pattern: /druid/* # 通过connectProperties属性来打开mergeSql功能慢SQL记录
reset-enable: false connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
wall:
multi-statement-allow: true
filter: filter:
stat: stat:
enabled: true enabled: true
# 记录慢SQL # 记录慢SQL
log-slow-sql: true logSlowSql: true
slow-sql-millis: 1000 slowSqlMillis: 1000
merge-sql: true mergeSql: true
wall: # 数据源名称,多数据源以逗号分隔
config: names: db0,db1
multi-statement-allow: true db0:
connect-properties: druid.stat.mergeSql=false # 数据库连接池类名称
type: com.alibaba.druid.pool.DruidDataSource
# 数据库驱动类名
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://8.130.96.163:3306/db_ad?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: y7z7noq2
db1:
# 数据库连接池类名称
type: com.alibaba.druid.pool.DruidDataSource
# 数据库驱动类名
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://8.130.96.163:3306/db_ad1?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: y7z7noq2
# 规则配置
rules:
sharding:
# 分片算法配置
sharding-algorithms:
database-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式(算法自行定义,此处为方便演示效果)
algorithm-expression: db$->{id % 2}
jl-v1-table-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式
algorithm-expression: tb_jl_v1_backdata_$->{(tag.hashCode() & Integer.MAX_VALUE) % 16}
jl-v2-table-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式
algorithm-expression: tb_jl_v2_backdata_$->{(tag.hashCode() & Integer.MAX_VALUE) % 16}
bd-table-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式
algorithm-expression: tb_bd_new_backdata_$->{(tag.hashCode() & Integer.MAX_VALUE) % 16}
gdt-table-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式
algorithm-expression: tb_gdt_new_backdata_$->{(tag.hashCode() & Integer.MAX_VALUE) % 16}
ks-table-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式
algorithm-expression: tb_ks_new_backdata_$->{(tag.hashCode() & Integer.MAX_VALUE) % 16}
# 分布式序列算法配置
key-generators:
snowflake:
# 分布式序列算法雪花算法SNOWFLAKE UUIDUUIDUUID没有props配置 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/keygen/
type: SNOWFLAKE
# 分布式序列算法属性配置
props:
# 工作机器唯一标识
worker-id: 32
tables:
# 逻辑表名称
tb_jl_v1_backdata:
# 行表达式标识符可以使用 ${...} 或 $->{...},但前者与 Spring 本身的属性文件占位符冲突,因此在 Spring 环境中使用行表达式标识符建议使用 $->{...}
actual-data-nodes: db$->{0..1}.tb_jl_v1_backdata_${0..15}
key-generate-strategy:
column: id
key-generator-name: snowflake
# 分库策略
database-strategy:
standard:
# 分片列名称
sharding-column: id
# 分片算法名称
sharding-algorithm-name: database-inline
# 分表策略
table-strategy:
standard:
# 分片列名称
sharding-column: tag
# 分片算法名称
sharding-algorithm-name: jl-v1-table-inline
# 逻辑表名称
tb_jl_v2_backdata:
actual-data-nodes: db$->{0..1}.tb_jl_v2_backdata_${0..15}
key-generate-strategy:
column: id
key-generator-name: snowflake
# 分库策略
database-strategy:
standard:
# 分片列名称
sharding-column: id
# 分片算法名称
sharding-algorithm-name: database-inline
# 分表策略
table-strategy:
standard:
# 分片列名称
sharding-column: tag
# 分片算法名称
sharding-algorithm-name: jl-v2-table-inline
# 逻辑表名称
tb_bd_new_backdata:
actual-data-nodes: db$->{0..1}.tb_bd_new_backdata_${0..15}
key-generate-strategy:
column: id
key-generator-name: snowflake
# 分库策略
database-strategy:
standard:
# 分片列名称
sharding-column: id
# 分片算法名称
sharding-algorithm-name: database-inline
# 分表策略
table-strategy:
standard:
# 分片列名称
sharding-column: tag
# 分片算法名称
sharding-algorithm-name: bd-table-inline
# 逻辑表名称
tb_gdt_new_backdata:
actual-data-nodes: db$->{0..1}.tb_gdt_new_backdata_${0..15}
key-generate-strategy:
column: id
key-generator-name: snowflake
# 分库策略
database-strategy:
standard:
# 分片列名称
sharding-column: id
# 分片算法名称
sharding-algorithm-name: database-inline
# 分表策略
table-strategy:
standard:
# 分片列名称
sharding-column: tag
# 分片算法名称
sharding-algorithm-name: gdt-table-inline
# 逻辑表名称
tb_ks_new_backdata:
actual-data-nodes: db$->{0..1}.tb_ks_new_backdata_${0..15}
key-generate-strategy:
column: id
key-generator-name: snowflake
# 分库策略
database-strategy:
standard:
# 分片列名称
sharding-column: id
# 分片算法名称
sharding-algorithm-name: database-inline
# 分表策略
table-strategy:
standard:
# 分片列名称
sharding-column: tag
# 分片算法名称
sharding-algorithm-name: ks-table-inline
# 属性配置
props:
# 展示修改以后的sql语句
sql-show: true
platform: platform:
authToken: JI8AeA7POKsdGcBC authToken: JI8AeA7POKsdGcBC
url: http://8.130.96.163:8866/api/taskImei/callback/add url: http://8.130.96.163:8866/api/taskImei/callback/add
tf:
source:
path: /home/www/ad-bak/source/

@ -1,49 +1,223 @@
#配置数据源 #配置数据源
spring: spring:
autoconfigure:
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
shardingsphere:
# 数据源配置
datasource: datasource:
druid: common:
db-type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/db_ad?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true
username: root
password: Yuyou@2020
# 初始连接数 # 初始连接数
initial-size: 5 initial-size: 6
# 最小连接数 # 最小连接池数量
min-idle: 10 min-idle: 3
# 最大连接数 # 最大连接池数量
max-active: 20 maxActive: 20
# 获取连接超时时间 # 配置获取连接等待超时的时间
max-wait: 5000 maxWait: 60000
# 连接有效性检测时间 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
time-between-eviction-runs-millis: 60000 timeBetweenEvictionRunsMillis: 60000
# 连接在池中最小生存的时间 # 配置一个连接在池中最小生存的时间,单位是毫秒
min-evictable-idle-time-millis: 300000 minEvictableIdleTimeMillis: 300000
# 连接在池中最大生存的时间 # 配置一个连接在池中最大生存的时间,单位是毫秒
max-evictable-idle-time-millis: 900000 maxEvictableIdleTimeMillis: 900000
test-while-idle: true #Oracle需要打开注释
test-on-borrow: false validationQuery: SELECT 1 FROM DUAL
test-on-return: false testWhileIdle: true
# 检测连接是否有效 testOnBorrow: false
validation-query: select 1 testOnReturn: false
# 配置监控统计 # 打开PSCache并且指定每个连接上PSCache的大小
webStatFilter: poolPreparedStatements: true
enabled: true maxPoolPreparedStatementPerConnectionSize: 20
stat-view-servlet: # 配置监控统计拦截的filters去掉后监控界面sql无法统计'wall'用于防火墙
enabled: true filters: stat,wall,slf4j
url-pattern: /druid/* # 通过connectProperties属性来打开mergeSql功能慢SQL记录
reset-enable: false connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
wall:
multi-statement-allow: true
filter: filter:
stat: stat:
enabled: true enabled: true
# 记录慢SQL # 记录慢SQL
log-slow-sql: true logSlowSql: true
slow-sql-millis: 1000 slowSqlMillis: 1000
merge-sql: true mergeSql: true
wall: # 数据源名称,多数据源以逗号分隔
config: names: db0,db1
multi-statement-allow: true db0:
connect-properties: druid.stat.mergeSql=false # 数据库连接池类名称
type: com.alibaba.druid.pool.DruidDataSource
# 数据库驱动类名
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/db_ad?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true
username: root
password: Yuyou@2020
db1:
# 数据库连接池类名称
type: com.alibaba.druid.pool.DruidDataSource
# 数据库驱动类名
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/db_ad?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true
username: root
password: Yuyou@2020
# 规则配置
rules:
sharding:
# 分片算法配置
sharding-algorithms:
database-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式(算法自行定义,此处为方便演示效果)
algorithm-expression: db$->{id % 2}
jl-v1-table-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式
algorithm-expression: tb_jl_v1_backdata_$->{(tag.hashCode() & Integer.MAX_VALUE) % 16}
jl-v2-table-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式
algorithm-expression: tb_jl_v2_backdata_$->{(tag.hashCode() & Integer.MAX_VALUE) % 16}
bd-table-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式
algorithm-expression: tb_bd_new_backdata_$->{(tag.hashCode() & Integer.MAX_VALUE) % 16}
gdt-table-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式
algorithm-expression: tb_gdt_new_backdata_$->{(tag.hashCode() & Integer.MAX_VALUE) % 16}
ks-table-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式
algorithm-expression: tb_ks_new_backdata_$->{(tag.hashCode() & Integer.MAX_VALUE) % 16}
# 分布式序列算法配置
key-generators:
snowflake:
# 分布式序列算法雪花算法SNOWFLAKE UUIDUUIDUUID没有props配置 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/keygen/
type: SNOWFLAKE
# 分布式序列算法属性配置
props:
# 工作机器唯一标识
worker-id: 32
tables:
# 逻辑表名称
tb_jl_v1_backdata:
# 行表达式标识符可以使用 ${...} 或 $->{...},但前者与 Spring 本身的属性文件占位符冲突,因此在 Spring 环境中使用行表达式标识符建议使用 $->{...}
actual-data-nodes: db$->{0..1}.tb_jl_v1_backdata_${0..15}
key-generate-strategy:
column: id
key-generator-name: snowflake
# 分库策略
database-strategy:
standard:
# 分片列名称
sharding-column: id
# 分片算法名称
sharding-algorithm-name: database-inline
# 分表策略
table-strategy:
standard:
# 分片列名称
sharding-column: tag
# 分片算法名称
sharding-algorithm-name: jl-v1-table-inline
# 逻辑表名称
tb_jl_v2_backdata:
actual-data-nodes: db$->{0..1}.tb_jl_v2_backdata_${0..15}
key-generate-strategy:
column: id
key-generator-name: snowflake
# 分库策略
database-strategy:
standard:
# 分片列名称
sharding-column: id
# 分片算法名称
sharding-algorithm-name: database-inline
# 分表策略
table-strategy:
standard:
# 分片列名称
sharding-column: tag
# 分片算法名称
sharding-algorithm-name: jl-v2-table-inline
# 逻辑表名称
tb_bd_new_backdata:
actual-data-nodes: db$->{0..1}.tb_bd_new_backdata_${0..15}
key-generate-strategy:
column: id
key-generator-name: snowflake
# 分库策略
database-strategy:
standard:
# 分片列名称
sharding-column: id
# 分片算法名称
sharding-algorithm-name: database-inline
# 分表策略
table-strategy:
standard:
# 分片列名称
sharding-column: tag
# 分片算法名称
sharding-algorithm-name: bd-table-inline
# 逻辑表名称
tb_gdt_new_backdata:
actual-data-nodes: db$->{0..1}.tb_gdt_new_backdata_${0..15}
key-generate-strategy:
column: id
key-generator-name: snowflake
# 分库策略
database-strategy:
standard:
# 分片列名称
sharding-column: id
# 分片算法名称
sharding-algorithm-name: database-inline
# 分表策略
table-strategy:
standard:
# 分片列名称
sharding-column: tag
# 分片算法名称
sharding-algorithm-name: gdt-table-inline
# 逻辑表名称
tb_ks_new_backdata:
actual-data-nodes: db$->{0..1}.tb_ks_new_backdata_${0..15}
key-generate-strategy:
column: id
key-generator-name: snowflake
# 分库策略
database-strategy:
standard:
# 分片列名称
sharding-column: id
# 分片算法名称
sharding-algorithm-name: database-inline
# 分表策略
table-strategy:
standard:
# 分片列名称
sharding-column: tag
# 分片算法名称
sharding-algorithm-name: ks-table-inline
# 属性配置
props:
# 展示修改以后的sql语句
sql-show: true
platform: platform:
authToken: nqJpVSf3UcrEcVIH authToken: nqJpVSf3UcrEcVIH
url: https://baiyee.vip/api/taskImei/callback/add url: https://baiyee.vip/api/taskImei/callback/add
@ -51,3 +225,9 @@ platform:
tf: tf:
source: source:
path: /home/www/ad-bak/source/ path: /home/www/ad-bak/source/
#配置数据源

@ -0,0 +1,79 @@
package com.baiyee.adcallback;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.text.csv.CsvData;
import cn.hutool.core.text.csv.CsvReader;
import cn.hutool.core.text.csv.CsvUtil;
import com.baiyee.adcallback.api.dto.PlateFormDTO;
import com.baiyee.adcallback.api.vo.KSNewMobileMonitorCallbackRequestVO;
import com.baiyee.adcallback.common.enums.DeliveryPlatformEnum;
import com.baiyee.adcallback.repository.TbEquipmentEntityRepository;
import com.baiyee.adcallback.repository.TbJLV1BackdataEntityRepository;
import com.baiyee.adcallback.repository.entity.TbEquipmentEntity;
import com.baiyee.adcallback.repository.entity.TbJLBackDataV1Entity;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Enzo
* @date : 2023/3/1
*/
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AdCallbackApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TagTest {
@Resource
private TbJLV1BackdataEntityRepository jlv1BackdataEntityRepository;
@Test
public void getSetting() {
List<TbJLBackDataV1Entity> tbJLBackDataV1Entities = jlv1BackdataEntityRepository.queryBytag("2r310nar8x59");
ArrayList<String> strings = Lists.newArrayList("arc1iiemw9ti","r55t3fp2dio5");
List<PlateFormDTO> imei__ = jlv1BackdataEntityRepository.queryPlateFormDTO
(CharSequenceUtil.EMPTY, "__IMEI__", DateUtil.beginOfDay(DateTime.now()), DateUtil.endOfDay(DateTime.now()), strings);
System.out.println();
}
@Test
public void filter() {
ArrayList<String> objects = Lists.newArrayList();
ArrayList<String> a = Lists.newArrayList();
List<String> list = Lists.newArrayList("jl-aaa-das", "jl-aaa-das-v2", "jl-aaa-das");
for (String s1 : list) {
int v2 = s1.lastIndexOf("v2");
if (v2 > 0) {
objects.add(s1);
continue;
}
a.add(s1);
}
System.out.println();
}
}
Loading…
Cancel
Save