[新增功能](master): 初始化项目

提交巨量回调代码
master
土豆兄弟 3 years ago
commit 1adf59bd4d

33
.gitignore vendored

@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JpaPluginProjectSettings">
<option name="entityNameTemplate" value="${className}" />
<option name="generateJpaOnGetter" value="true" />
<option name="generateSerialVersionUID" value="true" />
<option name="isLombokGetterAndSetter" value="true" />
<option name="isLombokToString" value="true" />
<option name="isLombokOnlyExplicitlyIncluded" value="true" />
<option name="isLombokRequiredArgsConstructor" value="true" />
<option name="scaffoldingLanguage" />
<option name="lastSelectedLanguage" value="Java" />
</component>
</project>

@ -0,0 +1,4 @@
## 百度广告投放平台检测 - 百度营销
https://dev2.baidu.com/content?sceneType=0&pageId=101214&nodeId=662&subhead=
## 广电通 - 腾讯广告
https://developers.e.qq.com/docs/guide/conversion/new_version/dianjijiance

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.baiyee</groupId>
<artifactId>ad-callback</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ad-callback</name>
<description>ad-callback</description>
<properties>
<java.version>1.8</java.version>
<maven.test.skip>true</maven.test.skip>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.16</version>
</dependency>
<!-- druid数据源驱动 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.22</version>
</dependency>
<!--Mysql依赖包-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- 配置跳过测试 -->
<configuration>
<skip>${maven.test.skip}</skip>
<testFailureIgnore>${maven.test.failure.ignore}</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,23 @@
package com.baiyee.adcallback;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* 广
*
* @author q
* @date 2022/01/05
*/
@SpringBootApplication
// 开启定时任务功能
@EnableScheduling
public class AdCallbackApplication {
public static void main(String[] args) {
SpringApplication.run(AdCallbackApplication.class, args);
}
}

@ -0,0 +1,43 @@
package com.baiyee.adcallback.api.callback;
import com.baiyee.adcallback.service.TokenManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/**
* juliangapi
*
* @author q
* @date 2022/01/05
*/
@RestController
@RequestMapping(value = ("/jl"))
public class JuliangAuthCallbackAPI {
@Autowired
private TokenManageService tokenManageService;
@RequestMapping(value = "/callback")
public void julaingAuthCallbackReqUrl(HttpServletRequest request){
// 授权链接的回调地址
// 需要与callback address相同**,否则会报错
System.out.println(request.getParameter("redirect"));
// 授权成功后开发者通回调地址获取的授权码auth code可用于获取 Access Token。
// 注意auth_code有效时间为10分钟且只可使用一次
System.out.println(request.getParameter("auth_code"));
// 这里是一个自定义的字段
// state=your_custom_params&
// 用于拼装授权URL时传递自定义信息授权成功回调时会原样带回。
// 常见应用:比如将广告主账号作为自定义参数,回调时以区分授权码对应的广告主。
System.out.println(request.getParameter("state"));
}
// https://xx.tuoz.net/login?redirect=%2Fdashboard%3Fstate%3Dyour_custom_params&auth_code=3819efd33fcaba807c0f65ac252b5b58495e5223
}

@ -0,0 +1,125 @@
package com.baiyee.adcallback.api.callback;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baiyee.adcallback.api.common.CommonResponse;
import com.baiyee.adcallback.api.common.ResponseCode;
import com.baiyee.adcallback.api.vo.JuliangMobileMonitorCallbackRequestVO;
import com.baiyee.adcallback.common.pojo.JlBackdataDTO;
import com.baiyee.adcallback.common.pojo.convert.JlBackdataConvert;
import com.baiyee.adcallback.service.AdOriginalityManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static com.baiyee.adcallback.common.constant.JuliangConstant.IMEI_TAG;
/**
* juliangapi
*
* @author q
* @date 2022/01/06
* @see <a href="https://open.oceanengine.com/doc/index.html?key=ad&type=api&id=1696710655781900#item-link-%E6%8E%A5%E5%8F%A3%E7%AE%80%E4%BB%8B"></a>
*/
@RestController
@RequestMapping(value = ("/jl"))
@Slf4j
public class JuliangMobileMonitorCallbackAPI {
private final AdOriginalityManageService adOriginalityManageService;
public JuliangMobileMonitorCallbackAPI(AdOriginalityManageService adOriginalityManageService) {
this.adOriginalityManageService = adOriginalityManageService;
}
/**
* julaingurl
* <p>
* 1. 广
* exp: https://mybest.custom.com/click/?aid=__AID__&cid=__CID__&callback_url=__CALLBACK_URL__
* <p>
* ps. 线广 ASC url encode
* ps. 广广广
* ps. 使HTTPS
* ps. HTTP GETURL
* <p>
* 2.
* exp: &__AID__&__AIDNAME__&__ADVERTISERID__&__CID__&__CTYPE__&__CSITE__&__IMEI__&__IDFA__&__OAID__&__OS__&__MAC__&__MAC1__&__IP__&__GEO__&__TS__&__CALLBACKURL__&__MODEL__&__CAID12__
* exp: aid=1645988237525045&aidname=testaidname1&advertiserid=1631857582073864&cid=1650703686054530&ctype=2&csite=33013&imei=0c2bd03c39f19845bf54ea0abafae70e&idfa=4FCFEFA1-096D-4176-B352-1870ED6DB777&oaid=97e7ef3f-e5f2-d0b8-ccfc-f79bbeaf4841&os=0&mac=df97bc5021e14256e141b2f036df5a3c&mac1=4d0433eb614f5d5ad409a65395426cbe&ip=61.158.146.195&geo=35.7x122.4x100.0&ts=1575194434000&callbackurl=https://ad.toutiao.com/track/activate/?callback=EJiw267wvfQCGKf2g74ZIPD89-vIATAMOAFCIjIwMTkxMTI3MTQxMTEzMDEwMDI2MDc3MjE1MTUwNTczNTBIAQ==&os=0&muid=db94e6a60a9c6661e3e03a7d301c25b6&model=iPhone12%2c2&caid12=f949f306494646edfee1f939698e1fb1
*
*/
@RequestMapping(value = "/monitor")
public CommonResponse julaingMonitorUrlCallbackReqUrl(
@RequestParam(value = "aid", defaultValue = "") String aid,
@RequestParam(value = "aidname", defaultValue = "") String aidName,
@RequestParam(value = "advertiserid", defaultValue = "") String advertiserId,
@RequestParam(value = "cid", defaultValue = "") Long cid,
@RequestParam(value = "ctype", defaultValue = "") Integer ctype,
@RequestParam(value = "csite", defaultValue = "") Integer csite,
@RequestParam(value = "imei", defaultValue = "") String imei,
@RequestParam(value = "idfa", defaultValue = "") String idfa,
@RequestParam(value = "oaid", defaultValue = "") String oaid,
@RequestParam(value = "os", defaultValue = "") Integer os,
@RequestParam(value = "mac", defaultValue = "") String mac,
@RequestParam(value = "mac1", defaultValue = "") String mac1,
@RequestParam(value = "ip", defaultValue = "") String ip,
@RequestParam(value = "geo", defaultValue = "") String geo,
@RequestParam(value = "TIMESTAMP", defaultValue = "") Long ts,
@RequestParam(value = "callback_url", defaultValue = "") String callbackUrl,
@RequestParam(value = "model", defaultValue = "") String model,
@RequestParam(value = "caid1", defaultValue = "") String caid12
) {
JuliangMobileMonitorCallbackRequestVO vo = new JuliangMobileMonitorCallbackRequestVO(
aid,aidName,advertiserId,cid,ctype,csite,imei,idfa,oaid,os,mac,mac1,ip,geo,ts,callbackUrl,model,caid12
);
if (ObjectUtil.isNull(vo)) {
return CommonResponse.createByErrorMessage(ResponseCode.EMPTY_ARGUMENT.getDesc());
}
// 请求过滤规则,过滤掉不用的数据
if (preRuleForReq(vo)){
log.error("================================= [not right imei data ,{} ] =================================",vo);
return CommonResponse.createBySuccess();
}
log.info("================================= [one request comming, JuliangMobileMonitorCallbackAPI|julaingMonitorUrlCallbackReqUrl, vo is {} ] =================================", vo);
JlBackdataDTO jlBackdataDTO = new JlBackdataDTO();
JlBackdataConvert.voCovertToDTO(vo, jlBackdataDTO);
adOriginalityManageService.handleMonitorUrlCallbackDataThenSave();
return CommonResponse.createBySuccess();
}
/**
*
*
* @return boolean
*/
private boolean preRuleForReq(JuliangMobileMonitorCallbackRequestVO vo) {
String imei = vo.getImei();
if (StrUtil.isBlank(imei)){
return Boolean.TRUE;
}
if (StrUtil.isNotBlank(imei) && StrUtil.equalsIgnoreCase(IMEI_TAG,imei)){
return Boolean.TRUE;
}
return Boolean.FALSE;
}
// https://xx.tuoz.net/login?redirect=%2Fdashboard%3Fstate%3Dyour_custom_params&auth_code=3819efd33fcaba807c0f65ac252b5b58495e5223
}

@ -0,0 +1,134 @@
package com.baiyee.adcallback.api.common;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
*
* JsonInclude.Include.NON_EMPTY "" NULL json
*
* @param <T>
* @author q
*/
@JsonSerialize
@Getter
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@NoArgsConstructor
public class CommonResponse<T> implements Serializable {
/**
* 0, 1,
*/
private int status;
/**
*
*/
private String msg;
/**
*
*/
private T data;
/*
*
*/
private CommonResponse(int status) {
this.status = status;
}
private CommonResponse(int status, T data) { // ps: 当调用T为String类型时候,会默认调用下面的ServerResponse(int status, String msg)类型的构造器
this.status = status;
this.data = data;
}
private CommonResponse(int status, String msg, T data) {
this.status = status;
this.msg = msg;
this.data = data;
}
private CommonResponse(int status, String msg) {
this.status = status;
this.msg = msg;
}
/*
* ,,
*/
/**
* @return
*/
public static <T> CommonResponse<T> createBySuccess() {
return new CommonResponse<T>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getDesc());
}
/**
*
* @param msg
* @return
*/
public static <T> CommonResponse<T> createBySuccessMessage(String msg) {
return new CommonResponse<T>(ResponseCode.SUCCESS.getCode(), msg);
}
/**
*
* @param data
* @return
*/
public static <T> CommonResponse<T> createBySuccess(T data) {
return new CommonResponse<T>(ResponseCode.SUCCESS.getCode(), data);
}
/**
*
* @param msg
* @param data
* @return
*/
public static <T> CommonResponse<T> createBySuccess(String msg, T data) {
return new CommonResponse<T>(ResponseCode.SUCCESS.getCode(), msg, data);
}
/*
,,
*/
/**
*
* @return
*/
public static <T> CommonResponse<T> createByError(){
return new CommonResponse<T>(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getDesc());
}
/**
*
* @param errorMessage
* @return ()
*/
public static <T> CommonResponse<T> createByErrorMessage(String errorMessage){
return new CommonResponse<T>(ResponseCode.ERROR.getCode(),errorMessage);
}
/**
*
* @param errorCode
* @param errorMessage
* @return ()()
*/
public static <T> CommonResponse<T> createByErrorCodeMessage(int errorCode,String errorMessage){
return new CommonResponse<T>(errorCode,errorMessage);
}
}

@ -0,0 +1,48 @@
package com.baiyee.adcallback.api.common;
/**
* Description: Response ->
* @author q
*/
public enum ResponseCode {
/**
*
*/
SUCCESS(0,"SUCCESS"),
/**
*
*/
ERROR(1,"ERROR"),
/*
*
*/
ILLEGAL_ARGUMENT(1,"请求参数格式错误"),
EMPTY_ARGUMENT(1,"请求参数为空"),
/*
*
*/
NO_REASON_ERROR(1,"未知异常错误发生"),
SYSTEM_ERROR(1,"系统异常"),
DECRYPT_ERROR(1,"解密错误,请联系相关人员");
private final int code;
private final String desc;
ResponseCode(int code, String desc){
this.code = code;
this.desc = desc;
}
public int getCode() {
return code;
}
public String getDesc() {
return desc;
}
}

@ -0,0 +1,11 @@
package com.baiyee.adcallback.api.constants;
/**
* -
*/
public class RequestDetailConstant {
public static final String REQUEST_ADDR_EMPTY = "请求的地址为空";
public static final String REQUEST_PARAMS_EMPTY = "请求参数为空";
}

@ -0,0 +1,32 @@
package com.baiyee.adcallback.api.constants;
/**
*
*/
public class RequestInfoConstant {
/**
*
*/
public static final String CUSTOMER_IP_ADDR_KEY = "customer_ip_addr_key";
/**
*
*/
public static final String PROD_SERVER_HOST = "http://bc.tuoz.net/";
/**
* -
*/
public static final String DEV_SERVER_HOST = "http://localhost:6666/";
/**
* Http
*/
public static final int RETRY_COUNT = 3;
/**
* 2000ms
*/
public static final int DEFAULT_TIMEOUT_NUMBER = 20000;
}

@ -0,0 +1,74 @@
package com.baiyee.adcallback.api.controller;
import com.baiyee.adcallback.api.common.CommonResponse;
/**
* 广
*
* API doc
* @see <a href="https://open.oceanengine.com/doc/index.html?key=ad&type=solution&id=1697474988931072#item-link-%E7%9B%91%E6%B5%8B%E9%93%BE%E6%8E%A5">Api</a>
*
* @author q
* @date 2022/01/05
*/
public class AdOriginalityManageController {
/**
*
*
* @see <a href="https://open.oceanengine.com/doc/index.html?key=ad&type=api&id=1696710540735500#item-link-%E8%AF%B7%E6%B1%82%E5%9C%B0%E5%9D%80"></a>
*
* @return {@link CommonResponse}
*/
public CommonResponse getListOfOriginality(){
return CommonResponse.createBySuccess();
}
/**
* 广
*
* @see <a href="https://open.oceanengine.com/doc/index.html?key=ad&type=api&id=1696710541275148#item-link-%E8%AF%B7%E6%B1%82%E5%9C%B0%E5%9D%80"></a>
*
* @return {@link CommonResponse}
*/
public CommonResponse createOriginality(){
return CommonResponse.createBySuccess();
}
/**
*
*
* @see <a href="https://open.oceanengine.com/doc/index.html?key=ad&type=api&id=1696710541985792#item-link-%E8%AF%B7%E6%B1%82%E5%9C%B0%E5%9D%80"></a>
*
* @return {@link CommonResponse}
*/
public CommonResponse detailsOfOriginality(){
return CommonResponse.createBySuccess();
}
/**
*
*
* @see <a href="https://open.oceanengine.com/doc/index.html?key=ad&type=api&id=1696710542519311#item-link-%E8%AF%B7%E6%B1%82%E5%9C%B0%E5%9D%80"></a>
*
* @return {@link CommonResponse}
*/
public CommonResponse editOriginality(){
return CommonResponse.createBySuccess();
}
/**
*
*
* @return {@link CommonResponse}
*/
public CommonResponse updateOriginalityState(){
return CommonResponse.createBySuccess();
}
}

@ -0,0 +1,11 @@
package com.baiyee.adcallback.api.controller;
/**
*
*
* @author q
* @date 2022/01/05
*/
public class BaseController {
}

@ -0,0 +1,23 @@
package com.baiyee.adcallback.api.controller;
import com.baiyee.adcallback.api.common.CommonResponse;
/**
*
*
* @author q
* @date 2022/01/05
*/
public class FeiyuSourceManageController {
/**
* 线
*
* @return {@link CommonResponse}
*/
public CommonResponse getListOfFeiyuSource(){
return CommonResponse.createBySuccess();
}
}

@ -0,0 +1,61 @@
package com.baiyee.adcallback.api.controller;
import com.baiyee.adcallback.api.common.CommonResponse;
import com.baiyee.adcallback.service.JuliangMobileMonitorService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
/**
* juliang
*
* @author q
* @date 2022/01/10
*/
@RestController
@RequestMapping("/jl")
public class JuliangMobileMonitorController {
private final JuliangMobileMonitorService juliangMobileMonitorService;
public JuliangMobileMonitorController(JuliangMobileMonitorService juliangMobileMonitorService) {
this.juliangMobileMonitorService = juliangMobileMonitorService;
}
/**
* db imei
*
* @return {@link CommonResponse}
*/
@GetMapping("/getimei")
public CommonResponse getImeiListFormDB() {
List<String> result = juliangMobileMonitorService.queryByImeiAdvancedMode();
return CommonResponse.createBySuccess(result);
}
/**
* imei
*
* @param date yyyy-MM-dd
* @param response
*/
@GetMapping("/download")
public void downloadImeiToFile(@RequestParam(value = "startDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date startDate,
@RequestParam(value = "endDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date endDate,
HttpServletResponse response){
juliangMobileMonitorService.downloadImeiFile(response, startDate, endDate);
}
}

@ -0,0 +1,49 @@
package com.baiyee.adcallback.api.controller;
import com.baiyee.adcallback.api.common.CommonResponse;
import com.baiyee.adcallback.service.TokenManageService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
*
* @author q
* @date 2022/01/05
*/
@RestController(value = "/token")
public class TokenManageController {
private final TokenManageService tokenManageService;
public TokenManageController(TokenManageService tokenManageService) {
this.tokenManageService = tokenManageService;
}
/**
* 访 -
*
* @see <a href="https://open.oceanengine.com/doc/index.html?key=ad&type=api&id=1696710505596940"></a>
*
* @return {@link CommonResponse}
*/
@PostMapping(value = "/get")
public CommonResponse getAccessToken(){
tokenManageService.getAccessToken();
return CommonResponse.createBySuccess();
}
/**
* - -
*
* @return {@link CommonResponse}
*/
@PostMapping(value = "/refresh")
public CommonResponse refreshToken(){
tokenManageService.refreshToken();
return CommonResponse.createBySuccess();
}
}

@ -0,0 +1,40 @@
package com.baiyee.adcallback.api.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* juliang vo
*
* @author q
* @date 2022/01/07
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JuliangMobileMonitorCallbackRequestVO implements Serializable {
private String aid;
private String aidName;
private String advertiserId;
private Long cid;
private Integer ctype;
private Integer csite;
private String imei;
private String idfa;
private String oaid;
private Integer os;
private String mac;
private String mac1;
private String ip;
private String geo;
private Long ts;
private String callbackUrl;
private String model;
private String caid12;
}

@ -0,0 +1,35 @@
package com.baiyee.adcallback.common.constant;
/**
* juliang
*
* @author q
* @date 2022/01/05
*/
public class JuliangConstant {
/**
*
*/
public static final String BACK_URL = "http://cb.tuoz.net";
/**
* Access Token url
*/
public static final String GET_ACCESS_TOKEN_URL = "https://ad.oceanengine.com/open_api/oauth2/access_token/";
/**
* Access Token url
*/
public static final String REFRESH_ACCESS_TOKEN_URL = "https://ad.oceanengine.com/open_api/oauth2/refresh_token/";
/**
* - Token advertiser_ids
*/
public static final String ADVERTISER_LIST_URL = "https://ad.oceanengine.com/open_api/oauth2/advertiser/get/";
public static final String IMEI_TAG = "__IMEI__";
}

@ -0,0 +1,36 @@
package com.baiyee.adcallback.common.pojo;
import cn.hutool.core.bean.BeanUtil;
import com.baiyee.adcallback.api.vo.JuliangMobileMonitorCallbackRequestVO;
import com.baiyee.adcallback.repository.entity.TbJlBackdataEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JlBackdataDTO implements Serializable {
private String aid;
private String aidName;
private String advertiserId;
private Long cid;
private Integer ctype;
private Integer csite;
private String imei;
private String idfa;
private String oaid;
private Integer os;
private String mac;
private String mac1;
private String ip;
private String geo;
private Long ts;
private String callbackUrl;
private String model;
private String caid12;
}

@ -0,0 +1,41 @@
package com.baiyee.adcallback.common.pojo.convert;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baiyee.adcallback.api.vo.JuliangMobileMonitorCallbackRequestVO;
import com.baiyee.adcallback.common.pojo.JlBackdataDTO;
import com.baiyee.adcallback.repository.entity.TbJlBackdataEntity;
public class JlBackdataConvert {
/**
*
*/
private JlBackdataConvert(){}
private static final ThreadLocal<JlBackdataDTO> context = new ThreadLocal<>();
/**
* vo dto -> 线
*
* @param vo
*/
public static void voCovertToDTO(JuliangMobileMonitorCallbackRequestVO vo, JlBackdataDTO dto) {
BeanUtil.copyProperties(vo, dto, true);
context.set(dto);
}
/**
*
*
* @return {@link TbJlBackdataEntity}
*/
public static TbJlBackdataEntity covertToEntity(TbJlBackdataEntity entity) {
JlBackdataDTO jlBackdataDTO = context.get();
if (ObjectUtil.isNotNull(jlBackdataDTO)){
BeanUtil.copyProperties(jlBackdataDTO, entity, true);
}
context.remove();
return entity;
}
}

@ -0,0 +1,48 @@
package com.baiyee.adcallback.common.request;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
/**
*
*
* @author q
* @date 2022/01/05
*/
public class JuliangRequestHeader {
/**
* content-type
*/
public static final String CONTEN_TTYPE = "application/json";
public static final String X_Debug_Mode_NAME = "X-Debug-Mode";
/**
* 1Debugger使线
* 20/
* headerhelp message
*/
public static String X_DEBUGMODE_VALUE;
public static String getXDebugModeValue(){
return X_DEBUGMODE_VALUE;
}
@Value("${x-debug.mode}")
public void setXDebugmodeValue(String xDebugmodeValue) {
JuliangRequestHeader.X_DEBUGMODE_VALUE = xDebugmodeValue;
}
/**
* access-tokenAccess-Token
* @see <a href="https://ad.oceanengine.com/openapi/doc/index.html?id=1696710505596940"></a>
*/
@Setter
@Getter
public String accessToken;
}

@ -0,0 +1,26 @@
package com.baiyee.adcallback.common.request;
/**
* juliang
*
* @author q
* @date 2022/01/05
*/
public class JuliangRequestParam {
/**
* APP_ID
*/
public static final String APPID = "1720560676257815";
/**
* Secretsecretapp_id
*
*/
public static final String SECRET = "343e2d0e55713607bdd34da957603f66f578ebe5";
/**
* - 1
*/
public static final String GRANT_TYPE_AUTH_CODE = "auth_code";
}

@ -0,0 +1,382 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.baiyee.adcallback.common.util;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.poi.excel.BigExcelWriter;
import cn.hutool.poi.excel.ExcelUtil;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* File hutool
*
* @author Zheng Jie
* @date 2018-12-27
*/
public class FileUtil extends cn.hutool.core.io.FileUtil {
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
/**
*
* <br>
* windows Linux ,
* windows \\==\
*
* <pre>
* java.io.tmpdir
* windows : C:\Users/xxx\AppData\Local\Temp\
* linux: /temp
* </pre>
*/
public static final String SYS_TEM_DIR = System.getProperty("java.io.tmpdir") + File.separator;
/**
* GB
*/
private static final int GB = 1024 * 1024 * 1024;
/**
* MB
*/
private static final int MB = 1024 * 1024;
/**
* KB
*/
private static final int KB = 1024;
/**
*
*/
private static final String PRE_FILE = "out_task_";
/**
* (,...) [使]
*/
private static final String SEPARATOR = "_";
/**
* (,...) [使]
*/
private static final int RANDOM_STRING_LENGTH = 6;
/**
*
*/
private static final DecimalFormat DF = new DecimalFormat("0.00");
/**
* MultipartFileFile
*/
public static File toFile(MultipartFile multipartFile) {
// 获取文件名
String fileName = multipartFile.getOriginalFilename();
// 获取文件后缀
String prefix = "." + getExtensionName(fileName);
File file = null;
try {
// 用uuid作为文件名防止生成的临时文件重复
file = File.createTempFile(IdUtil.simpleUUID(), prefix);
// MultipartFile to File
multipartFile.transferTo(file);
} catch (IOException e) {
log.error(e.getMessage(), e);
}
return file;
}
/**
* .
*/
public static String getExtensionName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot > -1) && (dot < (filename.length() - 1))) {
return filename.substring(dot + 1);
}
}
return filename;
}
/**
* Java
*/
public static String getFileNameNoEx(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot > -1) && (dot < (filename.length()))) {
return filename.substring(0, dot);
}
}
return filename;
}
/**
*
*/
public static String getSize(long size) {
String resultSize;
if (size / GB >= 1) {
//如果当前Byte的值大于等于1GB
resultSize = DF.format(size / (float) GB) + "GB ";
} else if (size / MB >= 1) {
//如果当前Byte的值大于等于1MB
resultSize = DF.format(size / (float) MB) + "MB ";
} else if (size / KB >= 1) {
//如果当前Byte的值大于等于1KB
resultSize = DF.format(size / (float) KB) + "KB ";
} else {
resultSize = size + "B ";
}
return resultSize;
}
/**
* inputStream File
*/
static File inputStreamToFile(InputStream ins, String name) throws Exception {
File file = new File(SYS_TEM_DIR + name);
if (file.exists()) {
return file;
}
OutputStream os = new FileOutputStream(file);
int bytesRead;
int len = 8192;
byte[] buffer = new byte[len];
while ((bytesRead = ins.read(buffer, 0, len)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
ins.close();
return file;
}
/**
*
*/
public static File upload(MultipartFile file, String filePath) {
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
String name = getFileNameNoEx(file.getOriginalFilename());
String suffix = getExtensionName(file.getOriginalFilename());
String nowStr = "-" + format.format(date);
try {
String fileName = name + nowStr + "." + suffix;
String path = filePath + fileName;
// getCanonicalFile 可解析正确各种路径
File dest = new File(path).getCanonicalFile();
// 检测是否存在目录
if (!dest.getParentFile().exists()) {
if (!dest.getParentFile().mkdirs()) {
System.out.println("was not successful.");
}
}
// 文件写入
file.transferTo(dest);
return dest;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
/**
* excel
*/
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws IOException {
String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx";
File file = new File(tempPath);
BigExcelWriter writer = ExcelUtil.getBigWriter(file);
// 一次性写出内容,使用默认样式,强制输出标题
writer.write(list, true);
//response为HttpServletResponse对象
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
//test.xls是弹出下载对话框的文件名不能为中文中文请自行编码
response.setHeader("Content-Disposition", "attachment;filename=学习资料.xlsx");
ServletOutputStream out = response.getOutputStream();
// 终止后删除临时文件
file.deleteOnExit();
writer.flush(out, true);
//此处记得关闭输出Servlet流
IoUtil.close(out);
}
/**
* excel
*
* @param file
* @param response
* @throws IOException
*/
public static void downloadExcel(File file, HttpServletResponse response) throws IOException {
BigExcelWriter writer = ExcelUtil.getBigWriter(file);
//response为HttpServletResponse对象
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
//test.xls是弹出下载对话框的文件名不能为中文中文请自行编码
response.setHeader("Content-Disposition", "attachment;filename=file.xlsx");
ServletOutputStream out = response.getOutputStream();
// 终止后删除临时文件
file.deleteOnExit();
writer.flush(out, true);
//此处记得关闭输出Servlet流
IoUtil.close(out);
}
public static String getFileType(String type) {
String documents = "txt doc pdf ppt pps xlsx xls docx";
String music = "mp3 wav wma mpa ram ra aac aif m4a";
String video = "avi mpg mpe mpeg asf wmv mov qt rm mp4 flv m4v webm ogv ogg";
String image = "bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg";
if (image.contains(type)) {
return "图片";
} else if (documents.contains(type)) {
return "文档";
} else if (music.contains(type)) {
return "音乐";
} else if (video.contains(type)) {
return "视频";
} else {
return "其他";
}
}
public static void checkSize(long maxSize, long size) {
// 1M
int len = 1024 * 1024;
if (size > (maxSize * len)) {
throw new RuntimeException("文件超出规定大小");
}
}
/**
*
*/
public static boolean check(File file1, File file2) {
String img1Md5 = getMd5(file1);
String img2Md5 = getMd5(file2);
return img1Md5.equals(img2Md5);
}
/**
*
*/
public static boolean check(String file1Md5, String file2Md5) {
return file1Md5.equals(file2Md5);
}
private static byte[] getByte(File file) {
// 得到文件长度
byte[] b = new byte[(int) file.length()];
try {
InputStream in = new FileInputStream(file);
try {
System.out.println(in.read(b));
} catch (IOException e) {
log.error(e.getMessage(), e);
}
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e);
return null;
}
return b;
}
private static String getMd5(byte[] bytes) {
// 16进制字符
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
try {
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(bytes);
byte[] md = mdTemp.digest();
int j = md.length;
char[] str = new char[j * 2];
int k = 0;
// 移位 输出字符串
for (byte byte0 : md) {
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
/**
*
*
* @param request /
* @param response /
* @param file /
*/
public static void downloadFile(HttpServletRequest request, HttpServletResponse response, File file, boolean deleteOnExit) {
response.setCharacterEncoding(request.getCharacterEncoding());
response.setContentType("application/octet-stream");
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
response.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
IOUtils.copy(fis, response.getOutputStream());
response.flushBuffer();
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
if (fis != null) {
try {
fis.close();
if (deleteOnExit) {
file.deleteOnExit();
}
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
}
}
public static String getMd5(File file) {
return getMd5(getByte(file));
}
/**
*
*
* @return
*/
public static String buildOnlyFileNameRule(){
String fileName = PRE_FILE +
RandomUtil.randomString(RANDOM_STRING_LENGTH) +
SEPARATOR +
Instant.now().getEpochSecond();
return fileName;
}
}

@ -0,0 +1,15 @@
package com.baiyee.adcallback.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
@Configuration
@EnableJpaAuditing
public class AuditingConfig {
@Bean
public AuditorAware<String> auditorProvider() {
return new DefaultAuditorAwareImpl();
}
}

@ -0,0 +1,15 @@
package com.baiyee.adcallback.config;
import org.springframework.data.domain.AuditorAware;
import java.util.Optional;
public class DefaultAuditorAwareImpl implements AuditorAware<String> {
@Override
public Optional<String> getCurrentAuditor() {
String testName = "test123";
return Optional.of(testName);
}
}

@ -0,0 +1,25 @@
package com.baiyee.adcallback.config;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
import org.springframework.stereotype.Component;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
@Component
public class SpringMVCConfiguration {
@Bean
public ConversionService conversionService() {
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setDateFormatter(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
factory.setFormatterRegistrars(Collections.singleton(registrar));
factory.afterPropertiesSet();
return factory.getObject();
}
}

@ -0,0 +1,18 @@
package com.baiyee.adcallback.repository;
import com.baiyee.adcallback.repository.entity.TbJlBackdataEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.Date;
import java.util.List;
public interface TbJlBackdataEntityRepository extends JpaRepository<TbJlBackdataEntity, Long> {
@Query(value = "SELECT imei FROM tb_jl_backdata WHERE imei != '' AND imei != '__IMEI__'", nativeQuery = true)
List<String> queryAllImei();
@Query(value = "SELECT imei FROM tb_jl_backdata WHERE imei != '' AND imei != '__IMEI__' AND gmt_create > :startDate AND gmt_create < :endDate", nativeQuery = true)
List<String> queryAllImeiByDate(Date startDate, Date endDate);
}

@ -0,0 +1,7 @@
package com.baiyee.adcallback.repository;
import com.baiyee.adcallback.repository.entity.TbJlTokenEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface TbJlTokenEntityRepository extends JpaRepository<TbJlTokenEntity, Long> {
}

@ -0,0 +1,104 @@
package com.baiyee.adcallback.repository.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Objects;
/**
* jl backdata
*
* @author q
* @date 2022/01/07
*/
@Entity
@Table(name = "tb_jl_backdata", schema = "db_ad", catalog = "")
@Data
@EntityListeners(AuditingEntityListener.class)
public class TbJlBackdataEntity {
@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@CreatedDate
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Column(name = "gmt_create", nullable = false)
private Date gmtCreate;
@LastModifiedDate
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Column(name = "gmt_modify", nullable = false)
private Date gmtModify;
@LastModifiedBy
@Column(name = "operator", nullable = false, length = 255)
private String operator;
@Basic
@Column(name = "aid", nullable = false, length = 255)
private String aid;
@Basic
@Column(name = "aid_name", nullable = false, length = 255)
private String aidName;
@Basic
@Column(name = "advertiser_id", nullable = false, length = 255)
private String advertiserId;
@Basic
@Column(name = "cid", nullable = false)
private long cid;
@Basic
@Column(name = "ctype", nullable = false)
private byte ctype;
@Basic
@Column(name = "csite", nullable = false)
private int csite;
@Basic
@Column(name = "imei", nullable = false, length = 255)
private String imei;
@Basic
@Column(name = "idfa", nullable = false, length = 255)
private String idfa;
@Basic
@Column(name = "oaid", nullable = false, length = 255)
private String oaid;
@Basic
@Column(name = "os", nullable = false)
private byte os;
@Basic
@Column(name = "mac", nullable = false, length = 255)
private String mac;
@Basic
@Column(name = "mac1", nullable = false, length = 255)
private String mac1;
@Basic
@Column(name = "ip", nullable = false, length = 255)
private String ip;
@Basic
@Column(name = "geo", nullable = false, length = 255)
private String geo;
@Basic
@Column(name = "ts", nullable = false)
private long ts;
@Basic
@Column(name = "callback_url", nullable = false, length = 255)
private String callbackUrl;
@Basic
@Column(name = "model", nullable = false, length = 255)
private String model;
@Basic
@Column(name = "caid12", nullable = false, length = 255)
private String caid12;
}

@ -0,0 +1,62 @@
package com.baiyee.adcallback.repository.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Objects;
@Entity
@Table(name = "tb_jl_token", schema = "db_ad", catalog = "")
@Data
@EntityListeners(AuditingEntityListener.class)
public class TbJlTokenEntity {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "gmt_create")
@CreatedDate
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date gmtCreate;
@LastModifiedDate
@Column(name = "gmt_modify")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date gmtModify;
@Basic
@LastModifiedBy
@Column(name = "operator")
private String operator;
@Basic
@Column(name = "access_token")
private String accessToken;
@Basic
@Column(name = "expires_in")
private int expiresIn;
@Basic
@Column(name = "refresh_token")
private String refreshToken;
@Basic
@Column(name = "refresh_token_expires_in")
private int refreshTokenExpiresIn;
@Basic
@Column(name = "advertiser_ids")
private String advertiserIds;
@Basic
@Column(name = "auth_code")
private String authCode;
@Basic
@Column(name = "state")
private String state;
}

@ -0,0 +1,14 @@
package com.baiyee.adcallback.service;
/**
* 广
*
* @author q
* @date 2022/01/07
*/
public interface AdOriginalityManageService {
/**
*
*/
void handleMonitorUrlCallbackDataThenSave();
}

@ -0,0 +1,4 @@
package com.baiyee.adcallback.service;
public interface FeiyuSourceManageService {
}

@ -0,0 +1,13 @@
package com.baiyee.adcallback.service;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
public interface JuliangMobileMonitorService {
List<String> queryByImeiAdvancedMode();
void downloadImeiFile(HttpServletResponse response, Date startDate, Date endDate);
}

@ -0,0 +1,36 @@
package com.baiyee.adcallback.service;
import com.baiyee.adcallback.repository.entity.TbJlTokenEntity;
/**
*
*
* @author q
* @date 2022/01/05
*/
public interface TokenManageService {
/**
*
*
*/
void saveCallbackParam();
/**
*
*
* @return {@link TbJlTokenEntity}
*/
TbJlTokenEntity queryCallbackParam();
/**
* 访
*/
void getAccessToken();
/**
*
*/
void refreshToken();
}

@ -0,0 +1,38 @@
package com.baiyee.adcallback.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baiyee.adcallback.common.pojo.convert.JlBackdataConvert;
import com.baiyee.adcallback.repository.TbJlBackdataEntityRepository;
import com.baiyee.adcallback.repository.entity.TbJlBackdataEntity;
import com.baiyee.adcallback.service.AdOriginalityManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* 广impl
*
* @author q
* @date 2022/01/07
*/
@Service
@Slf4j
public class AdOriginalityManageServiceImpl implements AdOriginalityManageService {
private final TbJlBackdataEntityRepository repository;
public AdOriginalityManageServiceImpl(TbJlBackdataEntityRepository repository) {
this.repository = repository;
}
@Override
public void handleMonitorUrlCallbackDataThenSave() {
TbJlBackdataEntity entity = new TbJlBackdataEntity();
TbJlBackdataEntity backEntity = JlBackdataConvert.covertToEntity(entity);
TbJlBackdataEntity save = repository.save(backEntity);
if (ObjectUtil.isNull(save)){
log.error("============================= [save a data fail save is {} ] =============================", save);
}
}
}

@ -0,0 +1,8 @@
package com.baiyee.adcallback.service.impl;
import com.baiyee.adcallback.service.FeiyuSourceManageService;
import org.springframework.stereotype.Service;
@Service
public class FeiyuSourceManageServiceImpl implements FeiyuSourceManageService {
}

@ -0,0 +1,88 @@
package com.baiyee.adcallback.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baiyee.adcallback.common.util.FileUtil;
import com.baiyee.adcallback.repository.TbJlBackdataEntityRepository;
import com.baiyee.adcallback.service.JuliangMobileMonitorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;
import java.util.*;
/**
* impl juliang
*
* @author q
* @date 2022/01/10
*/
@Service
@Slf4j
public class JuliangMobileMonitorServiceImpl implements JuliangMobileMonitorService {
private final TbJlBackdataEntityRepository tbJlBackdataEntityRepository;
public JuliangMobileMonitorServiceImpl(TbJlBackdataEntityRepository tbJlBackdataEntityRepository) {
this.tbJlBackdataEntityRepository = tbJlBackdataEntityRepository;
}
/**
* imei
*
* @return {@link List}<{@link String}>
*/
@Override
public List<String> queryByImeiAdvancedMode() {
List<String> entities = tbJlBackdataEntityRepository.queryAllImei();
List<String> results = new ArrayList<>(1000);
Map<String, Integer> resultByCountMap = CollectionUtil.countMap(entities);
resultByCountMap.forEach((k, v) -> {
results.add(k + "," + v);
});
return results;
}
@Override
public void downloadImeiFile(HttpServletResponse response,
@RequestParam(value = "startDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date startDate,
@RequestParam(value = "endDate")@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endDate) {
List<String> entities = tbJlBackdataEntityRepository.queryAllImeiByDate(startDate, endDate);
Map<String, Integer> resultByCountMap = CollectionUtil.countMap(entities);
List<Map<String, Object>> list = new ArrayList<>();
resultByCountMap.forEach(
(k, v) -> {
Map<String,Object> map = new LinkedHashMap<>();
map.put("imei", k);
map.put("weight", v);
list.add(map);
}
);
try {
FileUtil.downloadExcel(list, response);
} catch (IOException e) {
log.error("============================================== [downloadExcel error!] ==============================================");
}
}
}

@ -0,0 +1,122 @@
package com.baiyee.adcallback.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import com.baiyee.adcallback.api.constants.RequestInfoConstant;
import com.baiyee.adcallback.common.constant.JuliangConstant;
import com.baiyee.adcallback.common.request.JuliangRequestParam;
import com.baiyee.adcallback.repository.entity.TbJlTokenEntity;
import com.baiyee.adcallback.service.TokenManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* impl
*
* @author q
* @date 2022/01/05
*/
@Service
@Slf4j
public class TokenManageServiceImpl implements TokenManageService {
/**
*
*/
@Override
public void saveCallbackParam() {
}
/**
*
*
* @return {@link TbJlTokenEntity}
*/
@Override
public TbJlTokenEntity queryCallbackParam() {
return null;
}
/**
* 访
*
*
* <p>
* Access-Token广24
* Refresh-Tokenaccess_tokenrefresh_token
* <p>
* Access_Token1,Access_Token使refresh_tokenaccess_tokenRefresh_Token
* <p>
* Tokentoken使Token10
* <p>
* Token
* TokenAccess_TokenRefresh_TokenAccess_TokenRefresh_Token101010TokenTokenToken10
* <p>
* auth_code
* auth_codeToken
* <p>
* 广
* APPID广auth_codeToken
*
* -
*/
@Override
public void getAccessToken() {
// 初始化参数
String reqParam = buildGetTokenReqParam();
if (StrUtil.isBlank(reqParam)){
return;
}
// 发送获取 Access_Token 请求
String result = HttpRequest
.post(JuliangConstant.GET_ACCESS_TOKEN_URL)
.timeout(RequestInfoConstant.DEFAULT_TIMEOUT_NUMBER)
// 允许值1开启Debugger模式仅适用于接口测试使用不适合线上生产环境目前频控限制为20次/分钟建议在遇到调用接口报错后在header中传入此段以获取错误help message。
// .header(JuliangRequestHeader.X_Debug_Mode_NAME,JuliangRequestHeader.X_DEBUGMODE_VALUE,true)
.body(reqParam)
.execute().body();
// todo 返回的 Access_Token 存入到数据库中
}
/**
*
*
* @return
*/
private String buildGetTokenReqParam(){
// 准备 auth_code
TbJlTokenEntity tbJlTokenEntity = queryCallbackParam();
String authCode = "";
if (ObjectUtil.isNotNull(tbJlTokenEntity)){
authCode = tbJlTokenEntity.getAuthCode();
if (StrUtil.isBlank(authCode)){
log.error("========[authCode is empty ]========");
return null;
}
}
// 拼接 查询参数为 json
return String.format(
"{\"app_id\": \"%s\", \"secret\": \"%s\", \"grant_type\": \"%s\", \"auth_code\": \"%s\"}",
JuliangRequestParam.APPID,
JuliangRequestParam.SECRET,
JuliangRequestParam.GRANT_TYPE_AUTH_CODE,
authCode
);
}
/**
*
*/
@Override
public void refreshToken() {
}
}

@ -0,0 +1,50 @@
package com.baiyee.adcallback.task;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import com.baiyee.adcallback.api.constants.RequestInfoConstant;
import com.baiyee.adcallback.common.constant.JuliangConstant;
import com.baiyee.adcallback.common.request.JuliangRequestParam;
import com.baiyee.adcallback.repository.entity.TbJlTokenEntity;
import com.baiyee.adcallback.service.TokenManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* -
*
* @author q
* @date 2022/01/06
*/
@Component
@Slf4j
public class FixedTimeAutoRefreshJuliangTokenTask {
private final TokenManageService tokenManageService;
public FixedTimeAutoRefreshJuliangTokenTask(TokenManageService tokenManageService) {
this.tokenManageService = tokenManageService;
}
/**
*
*/
@Scheduled(cron = "0 0 23 1/1 * ?")
public void scheduledRule() {
log.info(" =============================== [定时刷新Token任务已经执行, 执行时间为 {} ] ===============================", DateUtil.date());
execute();
log.info(" =============================== [定时刷新Token任务执行完成, 执行时间为 {} ] ===============================", DateUtil.date());
}
/**
*
*/
public void execute() {
tokenManageService.refreshToken();
}
}

@ -0,0 +1,47 @@
x-debug:
mode: '1'
#配置数据源
spring:
datasource:
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
driverClassName: 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: root
# 初始连接数
initial-size: 5
# 最小连接数
min-idle: 10
# 最大连接数
max-active: 20
# 获取连接超时时间
max-wait: 5000
# 连接有效性检测时间
time-between-eviction-runs-millis: 60000
# 连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
# 连接在池中最大生存的时间
max-evictable-idle-time-millis: 900000
test-while-idle: true
test-on-borrow: false
test-on-return: false
# # 检测连接是否有效
validation-query: select 1
# 配置监控统计
webStatFilter:
enabled: true
stat-view-servlet:
enabled: true
url-pattern: /druid/*
reset-enable: false
filter:
stat:
enabled: true
# 记录慢SQL
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: true
wall:
config:
multi-statement-allow: true

@ -0,0 +1,45 @@
#配置数据源
spring:
datasource:
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://rm-bp1693kl5d490o5cn.mysql.rds.aliyuncs.com:3306/db_ad?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true
username: prod
password: yuyou@RDS9495
# 初始连接数
initial-size: 5
# 最小连接数
min-idle: 10
# 最大连接数
max-active: 20
# 获取连接超时时间
max-wait: 5000
# 连接有效性检测时间
time-between-eviction-runs-millis: 60000
# 连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
# 连接在池中最大生存的时间
max-evictable-idle-time-millis: 900000
test-while-idle: true
test-on-borrow: false
test-on-return: false
# 检测连接是否有效
validation-query: select 1
# 配置监控统计
webStatFilter:
enabled: true
stat-view-servlet:
enabled: true
url-pattern: /druid/*
reset-enable: false
filter:
stat:
enabled: true
# 记录慢SQL
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: true
wall:
config:
multi-statement-allow: true

@ -0,0 +1,45 @@
#配置数据源
spring:
datasource:
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
driverClassName: 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
# 最小连接数
min-idle: 10
# 最大连接数
max-active: 20
# 获取连接超时时间
max-wait: 5000
# 连接有效性检测时间
time-between-eviction-runs-millis: 60000
# 连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
# 连接在池中最大生存的时间
max-evictable-idle-time-millis: 900000
test-while-idle: true
test-on-borrow: false
test-on-return: false
# 检测连接是否有效
validation-query: select 1
# 配置监控统计
webStatFilter:
enabled: true
stat-view-servlet:
enabled: true
url-pattern: /druid/*
reset-enable: false
filter:
stat:
enabled: true
# 记录慢SQL
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: true
wall:
config:
multi-statement-allow: true

@ -0,0 +1,55 @@
server:
port: 9191
spring:
application:
name: ad-callback
profiles:
active: prod
jackson:
time-zone: GMT+8
date-format: yyyy-MM-dd HH:mm:ss
serialization:
#格式化输出
indent_output: true
#忽略无法转换的对象
fail_on_empty_beans: false
#设置空如何序列化
defaultPropertyInclusion: NON_EMPTY
deserialization:
#允许对象忽略json中不存在的属性
fail_on_unknown_properties: false
parser:
#允许出现特殊字符和转义符
allow_unquoted_control_chars: true
#允许出现单引号
allow_single_quotes: true
# 配置 Jpa
jpa:
properties:
hibernate:
ddl-auto: none
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
open-in-view: true
redis:
#数据库索引
database: 0
host: 127.0.0.1
port: 6379
password:
# 连接超时时间
timeout: 5000
# 配置日志
logging:
config: classpath:logback.xml
# 线程池配置
short:
chain:
task:
corePoolSize: 4
maxPoolSize: 32
queueCapacity: 100
ThreadNamePrefix: 'XXX-'

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds" debug="false">
<contextName>ad-callback</contextName>
<!-- 定义日志格式基础信息 -->
<property name="LOG_DIR" value="./log/" />
<property name="LOG_PATTERN" value="%white(%contextName-) %d{yyyy-MM-dd HH:mm:ss:SS} %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{50}) - %cyan(%msg%n)" />
<property name="LOG_CHARSET" value="utf-8" />
<!--输出到控制台-->
<appender name="stdAppender" class="ch.qos.logback.core.ConsoleAppender">
<!--<withJansi>true</withJansi> &lt;!&ndash; 如果是UTF-8的环境这句要注释掉 &ndash;&gt;-->
<encoder>
<pattern>%highlight([%-5level]) %cyan(%d{yyyy-MM-dd#HH:mm:ss.SSS}) %yellow([Thread:%thread]) %magenta([Logger:%logger]) -> %msg%n</pattern>
<charset>utf-8</charset>
</encoder>
</appender>
<!-- 输出到文件,并按天进行归档 -->
<appender name="fileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/ad-callback-log.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 按天归档,如果按小时后面加-hh -->
<fileNamePattern>${LOG_DIR}/history/%d{yyyy-MM-dd}.gz</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<append>true</append>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
<charset>utf-8</charset>
</encoder>
<!-- 不写TRACE DEBUG -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
</appender>
<!--普通日志输出到控制台-->
<root level="info">
<appender-ref ref="stdAppender" />
</root>
<!--监控sql日志输出 -->
<logger name="jdbc.sqlonly" level="INFO" additivity="false">
<appender-ref ref="stdAppender" />
<appender-ref ref="fileAppender"/>
</logger>
<logger name="jdbc.resultset" level="ERROR" additivity="false">
<appender-ref ref="stdAppender" />
<appender-ref ref="fileAppender"/>
</logger>
<!-- 如想看到表格数据将OFF改为INFO -->
<logger name="jdbc.resultsettable" level="OFF" additivity="false">
<appender-ref ref="stdAppender" />
<appender-ref ref="fileAppender"/>
</logger>
<logger name="jdbc.connection" level="OFF" additivity="false">
<appender-ref ref="stdAppender" />
<appender-ref ref="fileAppender"/>
</logger>
<logger name="jdbc.sqltiming" level="OFF" additivity="false">
<appender-ref ref="stdAppender" />
<appender-ref ref="fileAppender"/>
</logger>
<logger name="jdbc.audit" level="OFF" additivity="false">
<appender-ref ref="stdAppender" />
<appender-ref ref="fileAppender"/>
</logger>
<root level="INFO">
<!-- TODO prod 环境去掉std -->
<!-- <appender-ref ref="stdAppender"/>-->
<appender-ref ref="fileAppender"/>
</root>
</configuration>

@ -0,0 +1,13 @@
package com.baiyee.adcallback;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class AdCallbackApplicationTests {
@Test
void contextLoads() {
}
}
Loading…
Cancel
Save