添加多数据源 修改逻辑代码
parent
6cae668dfc
commit
313b87eca3
@ -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 {
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
@ -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…
Reference in New Issue