From a3c305251c99635c95ea2057a4dc76d9d2698a58 Mon Sep 17 00:00:00 2001 From: bynt Date: Wed, 1 Mar 2023 15:38:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=BA=E5=9E=8B=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=20=E4=BF=AE=E6=94=B9=E8=AF=B7=E6=B1=82=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JuliangMobileMonitorCallbackAPI.java | 2 +- .../callback/MobileMonitorCallbackAPI.java | 133 ++++++++++++++---- .../adcallback/api/constants/SqlConstant.java | 5 + ...uaiShouMobileMonitorCallbackRequestVO.java | 2 + .../vo/UcMobileMonitorCallbackRequestVO.java | 2 + ...JuliangConstant.java => DataConstant.java} | 14 +- .../TbEquipmentEntityRepository.java | 30 ++++ .../repository/TbIDFAEntityRepository.java | 14 ++ .../repository/entity/TbBdBackdataEntity.java | 1 - .../repository/entity/TbEquipmentEntity.java | 48 +++++++ .../repository/entity/TbIDFAEntity.java | 56 ++++++++ .../adcallback/service/EquipmentService.java | 26 ++++ .../adcallback/service/IdfaService.java | 15 ++ .../service/impl/EquipmentServiceImpl.java | 40 ++++++ .../service/impl/GenerateServiceImpl.java | 6 +- .../service/impl/IdfaServiceImpl.java | 30 ++++ .../service/impl/TokenManageServiceImpl.java | 4 +- .../task/DeleteDeliveryDataTask.java | 72 ++++++++++ .../FixedTimeAutoRefreshJuliangTokenTask.java | 7 - .../baiyee/adcallback/TbEquipmentTest.java | 63 +++++++++ 20 files changed, 526 insertions(+), 44 deletions(-) rename src/main/java/com/baiyee/adcallback/common/constant/{JuliangConstant.java => DataConstant.java} (77%) create mode 100644 src/main/java/com/baiyee/adcallback/repository/TbEquipmentEntityRepository.java create mode 100644 src/main/java/com/baiyee/adcallback/repository/TbIDFAEntityRepository.java create mode 100644 src/main/java/com/baiyee/adcallback/repository/entity/TbEquipmentEntity.java create mode 100644 src/main/java/com/baiyee/adcallback/repository/entity/TbIDFAEntity.java create mode 100644 src/main/java/com/baiyee/adcallback/service/EquipmentService.java create mode 100644 src/main/java/com/baiyee/adcallback/service/IdfaService.java create mode 100644 src/main/java/com/baiyee/adcallback/service/impl/EquipmentServiceImpl.java create mode 100644 src/main/java/com/baiyee/adcallback/service/impl/IdfaServiceImpl.java create mode 100644 src/main/java/com/baiyee/adcallback/task/DeleteDeliveryDataTask.java create mode 100644 src/test/java/com/baiyee/adcallback/TbEquipmentTest.java diff --git a/src/main/java/com/baiyee/adcallback/api/callback/JuliangMobileMonitorCallbackAPI.java b/src/main/java/com/baiyee/adcallback/api/callback/JuliangMobileMonitorCallbackAPI.java index a30f59c..ca08ab6 100644 --- a/src/main/java/com/baiyee/adcallback/api/callback/JuliangMobileMonitorCallbackAPI.java +++ b/src/main/java/com/baiyee/adcallback/api/callback/JuliangMobileMonitorCallbackAPI.java @@ -14,7 +14,7 @@ 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; +import static com.baiyee.adcallback.common.constant.DataConstant.IMEI_TAG; /** * juliang移动监控回调的api diff --git a/src/main/java/com/baiyee/adcallback/api/callback/MobileMonitorCallbackAPI.java b/src/main/java/com/baiyee/adcallback/api/callback/MobileMonitorCallbackAPI.java index b5c8121..f26582c 100644 --- a/src/main/java/com/baiyee/adcallback/api/callback/MobileMonitorCallbackAPI.java +++ b/src/main/java/com/baiyee/adcallback/api/callback/MobileMonitorCallbackAPI.java @@ -1,20 +1,27 @@ package com.baiyee.adcallback.api.callback; +import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.baiyee.adcallback.api.common.CommonResponse; import com.baiyee.adcallback.api.common.ResponseCode; import com.baiyee.adcallback.api.vo.*; +import com.baiyee.adcallback.common.enums.DeliveryPlatformEnum; import com.baiyee.adcallback.config.pojo.*; import com.baiyee.adcallback.config.pojo.convert.*; import com.baiyee.adcallback.service.AdOriginalityManageService; +import com.baiyee.adcallback.service.EquipmentService; +import com.baiyee.adcallback.service.IdfaService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import static com.baiyee.adcallback.common.constant.JuliangConstant.IMEI_NULL_TAG; -import static com.baiyee.adcallback.common.constant.JuliangConstant.IMEI_TAG; +import javax.annotation.Resource; +import java.util.Set; + +import static com.baiyee.adcallback.common.constant.DataConstant.*; /** * 移动监控 api @@ -27,6 +34,13 @@ import static com.baiyee.adcallback.common.constant.JuliangConstant.IMEI_TAG; @Slf4j public class MobileMonitorCallbackAPI { + + @Resource + private IdfaService idfaService; + + @Resource + private EquipmentService equipmentService; + @Autowired private AdOriginalityManageService adOriginalityManageService; @@ -54,7 +68,7 @@ public class MobileMonitorCallbackAPI { *

*/ @RequestMapping(value = "/jl/monitor") - public CommonResponse julaingMonitorUrlCallbackReqUrl( + public CommonResponse julaingMonitorUrlCallbackReqUrl( @RequestParam(value = "aid", defaultValue = "") String aid, @RequestParam(value = "aidname", defaultValue = "") String aidName, @RequestParam(value = "advertiserid", defaultValue = "") String advertiserId, @@ -82,9 +96,18 @@ public class MobileMonitorCallbackAPI { if (ObjectUtil.isNull(vo)) { return CommonResponse.createByErrorMessage(ResponseCode.EMPTY_ARGUMENT.getDesc()); } + + Set modeByResource = + equipmentService.queryModeByResource(DeliveryPlatformEnum.JL.getType()); + // 保存机型 + if (StringUtils.isNotBlank(model) && !modeByResource.contains(model)) { + equipmentService.saveEquipmentBySource(model, DeliveryPlatformEnum.JL.getType()); + } + // 保存数据 + filterIdfa(idfa, tag, DeliveryPlatformEnum.JL.getType()); // 请求过滤规则,过滤掉不用的数据 if (preRuleForReq(vo)) { - log.error("================================= [not right imei data ,vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); + log.error("================================= [not right imei data ,vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); return CommonResponse.createBySuccess(); } setTag(tag, vo); @@ -95,6 +118,7 @@ public class MobileMonitorCallbackAPI { return CommonResponse.createBySuccess(); } + /** * 之前的规则要求 * @@ -103,14 +127,13 @@ public class MobileMonitorCallbackAPI { private boolean preRuleForReq(JuliangMobileMonitorCallbackRequestVO vo) { String imei = vo.getImei(); + if (StrUtil.isBlank(imei)) { return Boolean.TRUE; } - if (StrUtil.equalsIgnoreCase(IMEI_TAG, imei)) { return Boolean.TRUE; } - return Boolean.FALSE; } @@ -124,7 +147,7 @@ public class MobileMonitorCallbackAPI { * http://www.test.com/notice?tag=test123&imei_md5={{IMEI_MD5}}&os={{OS}}&ip={{IP}}&ua={{UA}}&ts={{TS}}&userid={{USER_ID}}&pid={{PLAN_ID}}&uid={{UNIT_ID}}&aid={{IDEA_ID}}&click_id={{CLICK_ID}}&callback_url={{CALLBACK_URL}} */ @RequestMapping(value = "/bd/monitor") - public CommonResponse baiduMonitorUrlCallbackReqUrl( + public CommonResponse baiduMonitorUrlCallbackReqUrl( @RequestParam(value = "userid", defaultValue = "") String userId, @RequestParam(value = "aid", defaultValue = "") String aid, @RequestParam(value = "pid", defaultValue = "") String pid, @@ -151,13 +174,22 @@ public class MobileMonitorCallbackAPI { if (ObjectUtil.isNull(vo)) { return CommonResponse.createByErrorMessage(ResponseCode.EMPTY_ARGUMENT.getDesc()); } + Set modeByResource = + equipmentService.queryModeByResource(DeliveryPlatformEnum.BD.getType()); + // 保存机型 + if (StringUtils.isNotBlank(deviceInfo) && !modeByResource.contains(deviceInfo)) { + equipmentService.saveEquipmentBySource(deviceInfo, DeliveryPlatformEnum.BD.getType()); + } + // 保存数据 + filterIdfa(idfa, tag, DeliveryPlatformEnum.BD.getType()); // 请求过滤规则,过滤掉不用的数据 if (preRuleForReq(vo)) { - log.error("================================= [not right imei data ,vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); + log.error("================================= [not right imei data ,vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); return CommonResponse.createBySuccess(); } setTag(tag, vo); - log.info("================================= [one request comming, baiduMonitorUrlCallbackReqUrl|MobileMonitorCallbackAPI, vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); + + log.info("================================= [one request comming, baiduMonitorUrlCallbackReqUrl|MobileMonitorCallbackAPI, vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); BdBackdataDTO bdBackdataDTO = new BdBackdataDTO(); BdBackdataConvert.voCovertToDTO(vo, bdBackdataDTO); @@ -175,8 +207,7 @@ public class MobileMonitorCallbackAPI { private boolean preRuleForReq(BaiduMobileMonitorCallbackRequestVO vo) { String imei = vo.getImei(); - - if (StrUtil.isBlank(imei) || StrUtil.equalsIgnoreCase(IMEI_TAG, imei) || StrUtil.equalsIgnoreCase(IMEI_NULL_TAG,imei)) { + if (StrUtil.isBlank(imei) || StrUtil.equalsIgnoreCase(IMEI_TAG, imei) || StrUtil.equalsIgnoreCase(IMEI_NULL_TAG, imei)) { return Boolean.TRUE; } return Boolean.FALSE; @@ -192,7 +223,7 @@ public class MobileMonitorCallbackAPI { * A}&acid={ACID}&gid={GID}&aid={AID}&cid={CID}&tag=uc-jq-1 */ @RequestMapping(value = "/uc/monitor") - public CommonResponse ucMonitorUrlCallbackReqUrl( + public CommonResponse ucMonitorUrlCallbackReqUrl( @RequestParam(value = "imei", defaultValue = "") String imei, @RequestParam(value = "oaid", defaultValue = "") String oaid, @RequestParam(value = "time", defaultValue = "") Long ts, @@ -205,22 +236,33 @@ public class MobileMonitorCallbackAPI { @RequestParam(value = "gid", defaultValue = "") String gid, @RequestParam(value = "aid", defaultValue = "") String aid, @RequestParam(value = "cid", defaultValue = "") String cid, + @RequestParam(value = "idfa", defaultValue = "") String idfa, + @RequestParam(value = "model", defaultValue = "") String model, @RequestParam(value = "tag", defaultValue = "") String tag ) { UcMobileMonitorCallbackRequestVO vo = new UcMobileMonitorCallbackRequestVO( - imei, oaid, ts, callbackUrl, androidId, mac, ip, ua, acid, gid, aid, cid + imei, oaid, ts, callbackUrl, androidId, mac, ip, ua, acid, gid, aid, cid, model, idfa ); if (ObjectUtil.isNull(vo)) { return CommonResponse.createByErrorMessage(ResponseCode.EMPTY_ARGUMENT.getDesc()); } + + Set modeByResource = + equipmentService.queryModeByResource(DeliveryPlatformEnum.UC.getType()); + // 保存机型 + if (StringUtils.isNotBlank(model) && !modeByResource.contains(model)) { + equipmentService.saveEquipmentBySource(model, DeliveryPlatformEnum.UC.getType()); + } + // 保存数据 + filterIdfa(idfa, tag, DeliveryPlatformEnum.UC.getType()); // 请求过滤规则,过滤掉不用的数据 if (preRuleForReq(vo)) { - log.error("================================= [not right imei data ,vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); + log.error("================================= [not right imei data ,vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); return CommonResponse.createBySuccess(); } setTag(tag, vo); - log.info("================================= [one request comming, ucMonitorUrlCallbackReqUrl|MobileMonitorCallbackAPI, vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); + log.info("================================= [one request comming, ucMonitorUrlCallbackReqUrl|MobileMonitorCallbackAPI, vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); UcBackdataDTO ucBackdataDTO = new UcBackdataDTO(); UcBackdataConvert.voCovertToDTO(vo, ucBackdataDTO); adOriginalityManageService.handleMonitorUrlCallbackDataThenSave2(); @@ -252,7 +294,7 @@ public class MobileMonitorCallbackAPI { * https://docs.qingque.cn/d/home/eZQBTWKAahwgCU4YeU_bRW5B_# */ @RequestMapping(value = "/ks/monitor") - public CommonResponse kuaishouMonitorUrlCallbackReqUrl( + public CommonResponse kuaishouMonitorUrlCallbackReqUrl( @RequestParam(value = "accountid", defaultValue = "") String accountid, @RequestParam(value = "aid", defaultValue = "") String aid, @RequestParam(value = "cid", defaultValue = "") String cid, @@ -268,24 +310,33 @@ public class MobileMonitorCallbackAPI { @RequestParam(value = "ua", defaultValue = "") String ua, @RequestParam(value = "csite", defaultValue = "") String cSite, @RequestParam(value = "model", defaultValue = "") String model, + @RequestParam(value = "idfa", defaultValue = "") String idfa, @RequestParam(value = "ac_creative", defaultValue = "") String acCreative, @RequestParam(value = "tag", defaultValue = "") String tag ) { KuaiShouMobileMonitorCallbackRequestVO vo = new KuaiShouMobileMonitorCallbackRequestVO( - accountid, aid, cid, did, dName, imei, oaid, mac, androidid, os, ts, ip, ua, cSite, model, acCreative + accountid, aid, cid, did, dName, imei, oaid, mac, androidid, os, ts, ip, ua, cSite, model, acCreative, idfa ); if (ObjectUtil.isNull(vo)) { return CommonResponse.createByErrorMessage(ResponseCode.EMPTY_ARGUMENT.getDesc()); } + Set modeByResource = + equipmentService.queryModeByResource(DeliveryPlatformEnum.KS.getType()); + // 保存机型 + if (StringUtils.isNotBlank(model) && !modeByResource.contains(model)) { + equipmentService.saveEquipmentBySource(model, DeliveryPlatformEnum.KS.getType()); + } + // 保存数据 + filterIdfa(idfa, tag, DeliveryPlatformEnum.KS.getType()); // 请求过滤规则,过滤掉不用的数据 if (preRuleForReq(vo)) { - log.error("================================= [not right imei data ,vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); + log.error("================================= [not right imei data ,vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); return CommonResponse.createBySuccess(); } setTag(tag, vo); - log.info("================================= [one request comming, vivoMonitorUrlCallbackReqUrl|MobileMonitorCallbackAPI, vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); + log.info("================================= [one request comming, vivoMonitorUrlCallbackReqUrl|MobileMonitorCallbackAPI, vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); KuaiShouBackdataDTO kuaiShouBackdataDTO = new KuaiShouBackdataDTO(); KuaiShouBackdataConvert.voCovertToDTO(vo, kuaiShouBackdataDTO); adOriginalityManageService.handleMonitorUrlCallbackDataThenSave3(); @@ -317,7 +368,7 @@ public class MobileMonitorCallbackAPI { * API文档地址 : https://ad.vivo.com.cn/help?id=353 */ @RequestMapping(value = "/vivo/monitor") - public CommonResponse vivoMonitorUrlCallbackReqUrl( + public CommonResponse vivoMonitorUrlCallbackReqUrl( @RequestParam(value = "os", defaultValue = "") String os, @RequestParam(value = "imei", defaultValue = "") String imei, @RequestParam(value = "ip", defaultValue = "") String ip, @@ -347,13 +398,19 @@ public class MobileMonitorCallbackAPI { if (ObjectUtil.isNull(vo)) { return CommonResponse.createByErrorMessage(ResponseCode.EMPTY_ARGUMENT.getDesc()); } + Set modeByResource = + equipmentService.queryModeByResource(DeliveryPlatformEnum.VI.getType()); + // 保存机型 + if (StringUtils.isNotBlank(model) && !modeByResource.contains(model)) { + equipmentService.saveEquipmentBySource(model, DeliveryPlatformEnum.VI.getType()); + } // 请求过滤规则,过滤掉不用的数据 if (preRuleForReq(vo)) { - log.error("================================= [not right imei data , vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); + log.error("================================= [not right imei data , vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); return CommonResponse.createBySuccess(); } setTag(tag, vo); - log.info("================================= [one request comming, vivoMonitorUrlCallbackReqUrl|MobileMonitorCallbackAPI, vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); + log.info("================================= [one request comming, vivoMonitorUrlCallbackReqUrl|MobileMonitorCallbackAPI, vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); VivoBackdataDTO vivoBackdataDTO = new VivoBackdataDTO(); VivoBackdataConvert.voCovertToDTO(vo, vivoBackdataDTO); adOriginalityManageService.handleMonitorUrlCallbackDataThenSave4(); @@ -388,21 +445,19 @@ public class MobileMonitorCallbackAPI { * 直接配置链接即可 https://cb.tuoz.net/vivo/monitor */ @PostMapping(value = "/vivo/p/monitor") - public CommonResponse vivoMonitorUrlCallbackReqUrl(@RequestBody VivoMobileMonitorPointCallbackRequestVO vo) { + public CommonResponse vivoMonitorUrlCallbackReqUrl(@RequestBody VivoMobileMonitorPointCallbackRequestVO vo) { // fixme 返回值是 code msg 0 操作成功 return CommonResponse.createBySuccess(); } - - /** * 广点通 互联网检测 *

* API文档地址 : https://developers.e.qq.com/docs/guide/conversion/new_version/dianjijiance */ @RequestMapping(value = "/gdt/monitor") - public CommonResponse gdtMonitorUrlCallbackReqUrl( + public CommonResponse gdtMonitorUrlCallbackReqUrl( @RequestParam(value = "click_id", defaultValue = "") String clickId, @RequestParam(value = "click_time", defaultValue = "") String clickTime, @RequestParam(value = "impression_time", defaultValue = "") String impressionTime, @@ -451,13 +506,24 @@ public class MobileMonitorCallbackAPI { if (ObjectUtil.isNull(vo)) { return CommonResponse.createByErrorMessage(ResponseCode.EMPTY_ARGUMENT.getDesc()); } + if (IOS.equalsIgnoreCase(deviceOsType) + && !CharSequenceUtil.equalsIgnoreCase(MUID, muid)) { + // 保存数据 + filterIdfa(muid, tag, DeliveryPlatformEnum.GD.getType()); + } + Set modeByResource = + equipmentService.queryModeByResource(DeliveryPlatformEnum.GD.getType()); + // 保存机型 + if (StringUtils.isNotBlank(model) && !modeByResource.contains(model)) { + equipmentService.saveEquipmentBySource(model, DeliveryPlatformEnum.GD.getType()); + } // 请求过滤规则,过滤掉不用的数据 if (preRuleForReq(vo)) { - log.error("================================= [gdtMonitorUrlCallbackReqUrl|MobileMonitorCallbackAPI, not right imei data ,{} ] =================================", JSONUtil.toJsonStr(vo)); + log.error("================================= [gdtMonitorUrlCallbackReqUrl|MobileMonitorCallbackAPI, not right imei data ,{} ] =================================", JSONUtil.toJsonStr(vo)); return CommonResponse.createBySuccess(); } setTag(tag, vo); - log.info("================================= [one request comming, gdtMonitorUrlCallbackReqUrl|MobileMonitorCallbackAPI, vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); + log.info("================================= [one request comming, gdtMonitorUrlCallbackReqUrl|MobileMonitorCallbackAPI, vo json is {} ] =================================", JSONUtil.toJsonStr(vo)); GdtBackdataDTO dto = new GdtBackdataDTO(); GdtBackdataConvert.voCovertToDTO(vo, dto); adOriginalityManageService.handleMonitorUrlCallbackDataThenSave5(); @@ -484,7 +550,6 @@ public class MobileMonitorCallbackAPI { } - /** * 进行特殊标识处理 * @@ -499,4 +564,14 @@ public class MobileMonitorCallbackAPI { } } + + private void filterIdfa(String idfa, String tag, String type) { + // 保存数据 + if (StringUtils.isNotBlank(idfa) + && !CharSequenceUtil.equalsIgnoreCase(IMEI_NULL_TAG, idfa) + && !CharSequenceUtil.equalsIgnoreCase(IDFA_NUM, idfa) + && !CharSequenceUtil.equalsIgnoreCase(IDFA_STR, idfa)) { + idfaService.saveData(idfa, tag, type); + } + } } diff --git a/src/main/java/com/baiyee/adcallback/api/constants/SqlConstant.java b/src/main/java/com/baiyee/adcallback/api/constants/SqlConstant.java index e5dab43..e476217 100644 --- a/src/main/java/com/baiyee/adcallback/api/constants/SqlConstant.java +++ b/src/main/java/com/baiyee/adcallback/api/constants/SqlConstant.java @@ -12,6 +12,11 @@ public class SqlConstant { public static final String MUID_STR = "muid"; + public static final String DELETE_STR = "DELETE FROM "; + + + public static final String WHERE_STR = " WHERE GMT_CREATE < :DATE "; + public static final String TABLE_STR = "tabIndex"; diff --git a/src/main/java/com/baiyee/adcallback/api/vo/KuaiShouMobileMonitorCallbackRequestVO.java b/src/main/java/com/baiyee/adcallback/api/vo/KuaiShouMobileMonitorCallbackRequestVO.java index f943a05..f54684e 100644 --- a/src/main/java/com/baiyee/adcallback/api/vo/KuaiShouMobileMonitorCallbackRequestVO.java +++ b/src/main/java/com/baiyee/adcallback/api/vo/KuaiShouMobileMonitorCallbackRequestVO.java @@ -33,5 +33,7 @@ public class KuaiShouMobileMonitorCallbackRequestVO extends MobileMonitorCallbac private String cSite; private String model; private String acCreative; + private String idfa; + } diff --git a/src/main/java/com/baiyee/adcallback/api/vo/UcMobileMonitorCallbackRequestVO.java b/src/main/java/com/baiyee/adcallback/api/vo/UcMobileMonitorCallbackRequestVO.java index 68e66c6..b0a8ca9 100644 --- a/src/main/java/com/baiyee/adcallback/api/vo/UcMobileMonitorCallbackRequestVO.java +++ b/src/main/java/com/baiyee/adcallback/api/vo/UcMobileMonitorCallbackRequestVO.java @@ -24,4 +24,6 @@ public class UcMobileMonitorCallbackRequestVO extends MobileMonitorCallbackRequ private String gid; private String aid; private String cid; + private String model; + private String idfa; } diff --git a/src/main/java/com/baiyee/adcallback/common/constant/JuliangConstant.java b/src/main/java/com/baiyee/adcallback/common/constant/DataConstant.java similarity index 77% rename from src/main/java/com/baiyee/adcallback/common/constant/JuliangConstant.java rename to src/main/java/com/baiyee/adcallback/common/constant/DataConstant.java index 9b67ca8..0b5a195 100644 --- a/src/main/java/com/baiyee/adcallback/common/constant/JuliangConstant.java +++ b/src/main/java/com/baiyee/adcallback/common/constant/DataConstant.java @@ -6,7 +6,7 @@ package com.baiyee.adcallback.common.constant; * @author q * @date 2022/01/05 */ -public class JuliangConstant { +public class DataConstant { /** * 回调地址 @@ -33,5 +33,17 @@ public class JuliangConstant { public static final String IMEI_NULL_TAG = "NULL"; + public static final String IDFA_STR = "__IDFA__"; + + + public static final String IOS = "IOS"; + + public static final String MUID = "__MUID__"; + + + + + public static final String IDFA_NUM = "00000000-0000-0000-0000-000000000000"; + } diff --git a/src/main/java/com/baiyee/adcallback/repository/TbEquipmentEntityRepository.java b/src/main/java/com/baiyee/adcallback/repository/TbEquipmentEntityRepository.java new file mode 100644 index 0000000..6715aef --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/repository/TbEquipmentEntityRepository.java @@ -0,0 +1,30 @@ +package com.baiyee.adcallback.repository; + +import com.baiyee.adcallback.repository.entity.TbEquipmentEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.Map; +import java.util.Set; + +/** + * @author Enzo + * @date 2023-2-28 + */ +public interface TbEquipmentEntityRepository extends JpaRepository { + + + /** + * 类型查查找 + * + * @param sourceType + * @return + */ + @Query(value = "SELECT " + + " t.models "+ + " FROM " + + " tb_equipment t" + + " WHERE " + + " t.data_source = ?1", nativeQuery = true) + Set queryModelBySourceType(String sourceType); +} diff --git a/src/main/java/com/baiyee/adcallback/repository/TbIDFAEntityRepository.java b/src/main/java/com/baiyee/adcallback/repository/TbIDFAEntityRepository.java new file mode 100644 index 0000000..9ac549f --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/repository/TbIDFAEntityRepository.java @@ -0,0 +1,14 @@ +package com.baiyee.adcallback.repository; + +import com.baiyee.adcallback.repository.entity.TbIDFAEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @author Enzo + * @date 2023-2-28 + * + */ +public interface TbIDFAEntityRepository extends JpaRepository { + + +} diff --git a/src/main/java/com/baiyee/adcallback/repository/entity/TbBdBackdataEntity.java b/src/main/java/com/baiyee/adcallback/repository/entity/TbBdBackdataEntity.java index c84555c..7259553 100644 --- a/src/main/java/com/baiyee/adcallback/repository/entity/TbBdBackdataEntity.java +++ b/src/main/java/com/baiyee/adcallback/repository/entity/TbBdBackdataEntity.java @@ -10,7 +10,6 @@ import org.springframework.format.annotation.DateTimeFormat; import javax.persistence.*; import java.sql.Timestamp; -import java.util.Objects; @Data @Entity diff --git a/src/main/java/com/baiyee/adcallback/repository/entity/TbEquipmentEntity.java b/src/main/java/com/baiyee/adcallback/repository/entity/TbEquipmentEntity.java new file mode 100644 index 0000000..2c66f85 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/repository/entity/TbEquipmentEntity.java @@ -0,0 +1,48 @@ +package com.baiyee.adcallback.repository.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Getter; +import lombok.Setter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.*; +import java.io.Serializable; +import java.sql.Timestamp; + +/** + * @author Enzo + * @date : 2023/2/28 + */ +@Getter +@Setter +@Entity +@Table(name = "tb_equipment", schema = "db_ad") +@EntityListeners(AuditingEntityListener.class) +public class TbEquipmentEntity implements Serializable { + + private static final long serialVersionUID = 6137554839655790811L; + + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + @Column(name = "id", nullable = false) + 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 Timestamp gmtCreate; + + + @Basic + @Column(name = "models", nullable = false) + private String models; + + + + @Basic + @Column(name = "data_source", nullable = false) + private String dataSource; +} diff --git a/src/main/java/com/baiyee/adcallback/repository/entity/TbIDFAEntity.java b/src/main/java/com/baiyee/adcallback/repository/entity/TbIDFAEntity.java new file mode 100644 index 0000000..f09d4c1 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/repository/entity/TbIDFAEntity.java @@ -0,0 +1,56 @@ +package com.baiyee.adcallback.repository.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.*; +import java.io.Serializable; +import java.sql.Timestamp; + +/** + * @author Enzo + * @date : 2023/2/28 + */ +@Getter +@Setter +@Entity +@Table(name = "tb_idfa", schema = "db_ad") +@EntityListeners(AuditingEntityListener.class) +public class TbIDFAEntity implements Serializable { + + private static final long serialVersionUID = 4232805678739238024L; + + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + @Column(name = "id", nullable = false) + 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 Timestamp gmtCreate; + + @Basic + @Column(name = "idfa", nullable = false) + private String idfa; + + @Basic + @Column(name = "tag", nullable = false) + private String tag; + + @Basic + @Column(name = "use_type", nullable = false) + private Integer useType = 0; + + @Basic + @Column(name = "data_source", nullable = false) + private String dataSource; + + +} diff --git a/src/main/java/com/baiyee/adcallback/service/EquipmentService.java b/src/main/java/com/baiyee/adcallback/service/EquipmentService.java new file mode 100644 index 0000000..c034998 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/service/EquipmentService.java @@ -0,0 +1,26 @@ +package com.baiyee.adcallback.service; + +import java.util.Set; + +/** + * @author Enzo + * @date : 2023/2/28 + */ +public interface EquipmentService { + + /** + * 类型查找为机型 + * @param sourceType + * @return + */ + Set queryModeByResource(String sourceType); + + /** + * 保存机型 + * + * @param model + * @param sourceType + * @return + */ + Boolean saveEquipmentBySource(String model, String sourceType); +} diff --git a/src/main/java/com/baiyee/adcallback/service/IdfaService.java b/src/main/java/com/baiyee/adcallback/service/IdfaService.java new file mode 100644 index 0000000..72e34c0 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/service/IdfaService.java @@ -0,0 +1,15 @@ +package com.baiyee.adcallback.service; + +/** + * @author Enzo + * @date : 2023/2/28 + */ +public interface IdfaService { + /** + * 保存数据 + * @param idfa + * @param tag + * @param type + */ + void saveData(String idfa, String tag, String type); +} diff --git a/src/main/java/com/baiyee/adcallback/service/impl/EquipmentServiceImpl.java b/src/main/java/com/baiyee/adcallback/service/impl/EquipmentServiceImpl.java new file mode 100644 index 0000000..080e776 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/service/impl/EquipmentServiceImpl.java @@ -0,0 +1,40 @@ +package com.baiyee.adcallback.service.impl; + +import com.baiyee.adcallback.repository.TbEquipmentEntityRepository; +import com.baiyee.adcallback.repository.entity.TbEquipmentEntity; +import com.baiyee.adcallback.service.EquipmentService; +import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.Set; + +/** + * @author Enzo + * @date : 2023/2/28 + */ +@Service +@RequiredArgsConstructor +public class EquipmentServiceImpl implements EquipmentService { + + + private final TbEquipmentEntityRepository equipmentEntityRepository; + + + @Override + @Cacheable(cacheNames = "ModelCacheByResource", key = "#sourceType") + public Set queryModeByResource(String sourceType) { + return equipmentEntityRepository.queryModelBySourceType(sourceType); + } + + @Override + @CacheEvict(cacheNames = "ModelCacheByResource", key = "#sourceType") + public Boolean saveEquipmentBySource(String model, String sourceType) { + TbEquipmentEntity tbEquipment = new TbEquipmentEntity(); + tbEquipment.setModels(model); + tbEquipment.setDataSource(sourceType); + return equipmentEntityRepository.save(tbEquipment).getId() > 0; + } + +} diff --git a/src/main/java/com/baiyee/adcallback/service/impl/GenerateServiceImpl.java b/src/main/java/com/baiyee/adcallback/service/impl/GenerateServiceImpl.java index a91ba92..ec3a2ca 100644 --- a/src/main/java/com/baiyee/adcallback/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/baiyee/adcallback/service/impl/GenerateServiceImpl.java @@ -24,9 +24,9 @@ public class GenerateServiceImpl implements GenerateService { String replaceTag = tag.replace(" ", ""); String JL = "/api/jl/monitor?aid=__AID__&cid=__CID__&ctype=__CTYPE__&csite=__CSITE__&imei=__IMEI__&idfa=__IDFA__&oaid=__OAID__&os=__OS__&mac=__MAC__&mac1=__MAC1__&ip=__IP__&geo=__GEO__&TIMESTAMP=__TS__&callback_url=__CALLBACK_URL__&model=__MODEL__&caid1=__CAID1__&tag="; String BD = "/api/bd/monitor?userid=__USER_ID__&aid=__IDEA_ID__&pid=__PLAN_ID__&uid=__UNIT_ID__&callback_url=__CALLBACK_URL__&click_id=__CLICK_ID__&idfa=__IDFA__&imei_md5=__IMEI__&oaid=__OAID__&mac=__MAC__&ip=__IP__&os=__OS__&ts=__TS__&device_info=__DEVICE_INFO__&tag="; - String UC = "/api/uc/monitor?imei={IMEI_SUM1}&oaid={OAID}&time={TS}&callback={CALLBACK_URL}&androidid={ANDROIDID_SUM1}&mac={MAC_SUM2}&ip={IP}&ua={UA}&acid={ACID}&gid={GID}&aid={AID}&cid={CID}&tag="; - String GDT = "/api/gdt/monitor?click_id=__CLICK_ID__&click_time=__CLICK_TIME__&campaign_id=_CAMPAIGN_ID__&adgroup_id=__ADGROUP_ID__&ad_id=__AD_ID__&muid=__MUID__&hash_android_id=__HASH_ANDROID_ID__&oaid=__OAID__&hash_oaid=__HASH_OAID__&ip=__IP__&user_agent=__USER_AGENT__&account_id=__ACCOUNT_ID__&promoted_object_type=__PROMOTED_OBJECT_TYPE__&device_os_type=__DEVICE_OS_TYPE__&callback=__CALLBACK__&qz_gdt=__QZ_GDT__&tag="; - String KS = "/api/ks/monitor?&accountid=__ACCOUNTID__&aid=__AID__&cid=__CID__&did=__DID__&dname=__DNAME__&imeiMD5=__IMEI2__&oaid=__OAID__&mac=__MAC2__&androidid=__ANDROIDID2__&os=__OS__&ts=__TS__&ip=__IP__&ua=__UA__&csite=__CSITE__&model=__MODEL__&ac_creative=__AC_CREATIVE__&tag="; + String UC = "/api/uc/monitor?imei={IMEI_SUM1}&oaid={OAID}&time={TS}&callback={CALLBACK_URL}&androidid={ANDROIDID_SUM1}&mac={MAC_SUM2}&ip={IP}&ua={UA}&acid={ACID}&gid={GID}&aid={AID}&cid={CID}&model={MODEL1}&idfa={IDFA1}&tag="; + String GDT = "/api/gdt/monitor?click_id=__CLICK_ID__&click_time=__CLICK_TIME__&campaign_id=_CAMPAIGN_ID__&adgroup_id=__ADGROUP_ID__&ad_id=__AD_ID__&muid=__MUID__&hash_android_id=__HASH_ANDROID_ID__&oaid=__OAID__&hash_oaid=__HASH_OAID__&ip=__IP__&user_agent=__USER_AGENT__&account_id=__ACCOUNT_ID__&promoted_object_type=__PROMOTED_OBJECT_TYPE__&device_os_type=__DEVICE_OS_TYPE__&callback=__CALLBACK__&qz_gdt=__QZ_GDT__&model=__MODEL__&tag="; + String KS = "/api/ks/monitor?&accountid=__ACCOUNTID__&aid=__AID__&cid=__CID__&did=__DID__&dname=__DNAME__&imeiMD5=__IMEI2__&oaid=__OAID__&mac=__MAC2__&androidid=__ANDROIDID2__&os=__OS__&ts=__TS__&ip=__IP__&ua=__UA__&csite=__CSITE__&model=__MODEL__&ac_creative=__AC_CREATIVE__&idfa=__IDFA2__&tag="; String VIVO = "/api/vivo/monitor?os=__OS__&imei=__IMEI__&ip=__IP__&oaid=__OAID__&oaidPlain=__OAIDPLAIN__&ua=__UA__&androidId=__ANDROIDID__&location=__LOCATION__&requestId=__REQUESTID__&requestTime=__REQUESTTIME__&advertiserId=__ADVERTISERID__&adName=__ADNAME__&creativeId=__CREATIVEID__&osVersion=__OSVERSION__&model=__MODEL__&lang=__LANG__&resolution=__RESOLUTION__&netType=__NETTYPE__&ts=__TS__&tag="; String generateDmp; switch (type){ diff --git a/src/main/java/com/baiyee/adcallback/service/impl/IdfaServiceImpl.java b/src/main/java/com/baiyee/adcallback/service/impl/IdfaServiceImpl.java new file mode 100644 index 0000000..8c26970 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/service/impl/IdfaServiceImpl.java @@ -0,0 +1,30 @@ +package com.baiyee.adcallback.service.impl; + +import cn.hutool.core.text.CharSequenceUtil; +import com.baiyee.adcallback.repository.TbIDFAEntityRepository; +import com.baiyee.adcallback.repository.entity.TbIDFAEntity; +import com.baiyee.adcallback.service.IdfaService; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +/** + * @author Enzo + * @date : 2023/2/28 + */ +@Service +@RequiredArgsConstructor +public class IdfaServiceImpl implements IdfaService { + + + private final TbIDFAEntityRepository tbIDFAEntityRepository; + + @Override + public void saveData(String idfa, String tag, String type) { + TbIDFAEntity entity = new TbIDFAEntity(); + entity.setIdfa(idfa); + entity.setTag(StringUtils.isNotBlank(tag) ? tag : CharSequenceUtil.EMPTY); + entity.setDataSource(type); + tbIDFAEntityRepository.save(entity); + } +} diff --git a/src/main/java/com/baiyee/adcallback/service/impl/TokenManageServiceImpl.java b/src/main/java/com/baiyee/adcallback/service/impl/TokenManageServiceImpl.java index f0fe9cc..8d7846a 100644 --- a/src/main/java/com/baiyee/adcallback/service/impl/TokenManageServiceImpl.java +++ b/src/main/java/com/baiyee/adcallback/service/impl/TokenManageServiceImpl.java @@ -4,7 +4,7 @@ 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.constant.DataConstant; import com.baiyee.adcallback.common.request.JuliangRequestParam; import com.baiyee.adcallback.repository.entity.TbJlTokenEntity; import com.baiyee.adcallback.service.TokenManageService; @@ -73,7 +73,7 @@ public class TokenManageServiceImpl implements TokenManageService { // 发送获取 Access_Token 请求 String result = HttpRequest - .post(JuliangConstant.GET_ACCESS_TOKEN_URL) + .post(DataConstant.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) diff --git a/src/main/java/com/baiyee/adcallback/task/DeleteDeliveryDataTask.java b/src/main/java/com/baiyee/adcallback/task/DeleteDeliveryDataTask.java new file mode 100644 index 0000000..db03616 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/task/DeleteDeliveryDataTask.java @@ -0,0 +1,72 @@ +package com.baiyee.adcallback.task; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import com.baiyee.adcallback.api.constants.SqlConstant; +import com.baiyee.adcallback.common.enums.TableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.math.BigInteger; + +/** + * @author Enzo + * @date : 2023/2/28 + */ +@Slf4j +// @Component +public class DeleteDeliveryDataTask { + + + @PersistenceContext + private EntityManager entityManager; + + /** + * 凌晨五点 查询定时任务 删除记录 + */ + @Scheduled(cron = "0 0 5 * * ?") + @Transactional(rollbackFor = Exception.class) + public void deleteDataTask() { + for (TableEnum value : TableEnum.values()) { + //数据中需要删除的数据量 + long expiredCount; + // 已经删除数据量 + long totalDeleted = 0L; + // 删除表 + String tableName = value.getTableName(); + // 时间偏移一个月 + DateTime date = DateUtil.offsetMonth(DateUtil.date(), -1); + do { + Query deleteTagByQuery = entityManager.createNativeQuery + (SqlConstant.DELETE_STR + .concat(tableName) + .concat(SqlConstant.WHERE_STR) + .concat(" limit 50000")); + deleteTagByQuery.setParameter("DATE", date.toDateStr()); + int executeUpdate = deleteTagByQuery.executeUpdate(); + totalDeleted += executeUpdate; + expiredCount = queryCount(tableName, date); + } while (expiredCount > 0); + log.info("======== delete tag{} table size as [{}] ========", tableName, totalDeleted); + } + } + + /** + * 查询数据 + * + * @param tableName + * @param date + * @return + */ + private Long queryCount(String tableName, DateTime date) { + String sql = "select count(1) FROM " + tableName + " where gmt_create < :date "; + Query selectQueryCount = entityManager.createNativeQuery(sql); + selectQueryCount.setParameter("date", date.toDateStr()); + BigInteger bigInteger = (BigInteger) selectQueryCount.getSingleResult(); + return bigInteger.longValue(); + } +} diff --git a/src/main/java/com/baiyee/adcallback/task/FixedTimeAutoRefreshJuliangTokenTask.java b/src/main/java/com/baiyee/adcallback/task/FixedTimeAutoRefreshJuliangTokenTask.java index eb6ff6c..07548c7 100644 --- a/src/main/java/com/baiyee/adcallback/task/FixedTimeAutoRefreshJuliangTokenTask.java +++ b/src/main/java/com/baiyee/adcallback/task/FixedTimeAutoRefreshJuliangTokenTask.java @@ -1,13 +1,6 @@ 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; diff --git a/src/test/java/com/baiyee/adcallback/TbEquipmentTest.java b/src/test/java/com/baiyee/adcallback/TbEquipmentTest.java new file mode 100644 index 0000000..52376ee --- /dev/null +++ b/src/test/java/com/baiyee/adcallback/TbEquipmentTest.java @@ -0,0 +1,63 @@ +package com.baiyee.adcallback; + +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.common.enums.DeliveryPlatformEnum; +import com.baiyee.adcallback.repository.TbEquipmentEntityRepository; +import com.baiyee.adcallback.repository.entity.TbEquipmentEntity; +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.util.List; + +/** + * @author Enzo + * @date : 2023/3/1 + */ + +@Slf4j +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AdCallbackApplication.class, + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class TbEquipmentTest { + + @Resource + private TbEquipmentEntityRepository tbEquipmentEntityRepository; + + @Test + public void getSetting() { + + File file = new File("C:\\Users\\a\\Desktop\\1.csv"); + List stringList = Lists.newArrayList(); + List list = Lists.newArrayList(); + CsvReader reader = CsvUtil.getReader(); + + // 解析文件 + CsvData data = reader.read(file); + + data.getRows().forEach(clue -> stringList.add + (clue.get(0))); + + for (String s : stringList) { + + + TbEquipmentEntity equipment = new TbEquipmentEntity(); + if (StringUtils.isNotBlank(s)){ + equipment.setModels(s); + equipment.setDataSource(DeliveryPlatformEnum.VI.getType()); + list.add(equipment); + + } + } + + tbEquipmentEntityRepository.saveAll(list); + } +}