diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/AdPlatFormConstants.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/AdPlatFormConstants.java index 538666e4..39d6940b 100644 --- a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/AdPlatFormConstants.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/AdPlatFormConstants.java @@ -18,4 +18,8 @@ public class AdPlatFormConstants { public static final String AES_PASSWORD = "park_%33229*711&"; + + + public static final String DEFAULT_TAG = "jl-tripartite-1024"; + } diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/enums/MailRequestEnum.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/enums/MailRequestEnum.java index ad2b61b9..2a12fd56 100644 --- a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/enums/MailRequestEnum.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/enums/MailRequestEnum.java @@ -22,6 +22,12 @@ public enum MailRequestEnum { GG("GG", "mail::gender::"), + /** + * 三方请求 + */ + BT("BT", "dmp::Tripartite::"), + + /** * 定时 */ diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/CacheKey.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/CacheKey.java index 0c12b0ec..cfdeb2ba 100644 --- a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/CacheKey.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/CacheKey.java @@ -67,6 +67,12 @@ public interface CacheKey { String DMP_DOWN_URL = "dmp::down::url::"; + /** + * 三方下载地址 + */ + String DMP_TRIPARTITE_URL = "dmp::tripartite::url::"; + + /** * dmp请求类型 diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/TripartiteDownRecord.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/TripartiteDownRecord.java new file mode 100644 index 00000000..42828b66 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/TripartiteDownRecord.java @@ -0,0 +1,70 @@ +package com.baiye.modules.platform.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.sql.Timestamp; + +/** + * @author Enzo + * 下载链接 + */ +@Entity +@Getter +@Setter +@Table(name = "tb_tripartite_down_record") +@EntityListeners(AuditingEntityListener.class) +public class TripartiteDownRecord implements Serializable { + + @Id + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + @ApiModelProperty(value = "ID", hidden = true) + private Long id; + + + @Column(name = "status") + @ApiModelProperty(value = "下载状态") + private Integer status; + + + @Column(name = "date_str") + @ApiModelProperty(value = "日期转换") + private String dateStr; + + @Column(name = "down_url") + @ApiModelProperty(value = "下载链接") + private String downUrl; + + @Column(name = "file_path") + @ApiModelProperty(value = "文件地址") + private String filePath; + + @Column(name = "clue_num") + @ApiModelProperty(value = "线索数量") + private Integer clueNum; + + @Column(name = "source_data") + @ApiModelProperty(value = "资源来源") + private Long sourceData; + + @Column(name = "source_memo") + @ApiModelProperty(value = "资源来源") + private String sourceMemo; + + @CreationTimestamp + @Column(name = "create_time", updatable = false) + private Timestamp createTime; + + @UpdateTimestamp + @Column(name = "update_time") + private Timestamp updateTime; + + +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/TripartiteSource.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/TripartiteSource.java new file mode 100644 index 00000000..7796f547 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/TripartiteSource.java @@ -0,0 +1,49 @@ +package com.baiye.modules.platform.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * @author Enzo + * 三方资源 + */ +@Entity +@Getter +@Setter +@Table(name = "tb_tripartite_source") +@EntityListeners(AuditingEntityListener.class) +public class TripartiteSource implements Serializable { + @Id + @Column(name = "id") + @ApiModelProperty(value = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "equipment") + @ApiModelProperty(value = "equipment") + private String equipment; + + @Column(name = "status") + @ApiModelProperty(value = "状态 0-未兑换 1-已兑换") + private Integer status; + + @Column(name = "type") + @ApiModelProperty(value = "状态 0-imei 1-oaid") + private Integer type; + + + @Column(name = "create_time") + @ApiModelProperty(value = "createTime") + private Date createTime; + + @Column(name = "update_time") + @ApiModelProperty(value = "updateTime") + private Date updateTime; + +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TripartiteDownRecordRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TripartiteDownRecordRepository.java new file mode 100644 index 00000000..694f8240 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TripartiteDownRecordRepository.java @@ -0,0 +1,35 @@ +package com.baiye.modules.platform.repository; + +import com.baiye.modules.platform.domain.TripartiteDownRecord; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; + +/** + * @author Enzo + * @date : 2023/10/13 + */ +public interface TripartiteDownRecordRepository extends JpaRepository, JpaSpecificationExecutor { + + + /** + * 查询下载链接 + * @param dateStr + * @param sourceData + * @return + */ + @Query("select t.filePath from TripartiteDownRecord t where t.dateStr = ?1 and t.sourceData = ?2 order by t.id") + String findByDownPathByDateStr(String dateStr,Long sourceData); + + /** + * 修改数量 + * @param totalNumber + * @param sourceData + * @param dateStr + * @return + */ + @Modifying + @Query("UPDATE TripartiteDownRecord set clueNum = ?1 where sourceData = ?2 and dateStr = ?3") + int updateNumByDateStr(Integer totalNumber, Long sourceData, String dateStr); +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TripartiteSourceRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TripartiteSourceRepository.java new file mode 100644 index 00000000..f7a2e033 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TripartiteSourceRepository.java @@ -0,0 +1,47 @@ +package com.baiye.modules.platform.repository; + +import cn.hutool.core.date.DateTime; +import com.baiye.modules.platform.domain.TripartiteSource; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author Enzo + * @date + */ +@Repository +public interface TripartiteSourceRepository extends JpaRepository, JpaSpecificationExecutor { + + + /** + * 状态时间查找查找 + * + * @param num + * @param beginOfDay + * @param endOfDay + * @return + */ + @Query("from TripartiteSource t where t.status = ?1 and t.createTime > ?2 and t.createTime < ?3 order by t.id") + List findByStatusAndCreateTimeBetweenTime(Integer num, DateTime beginOfDay, DateTime endOfDay); + + + /** + * 修改数量 + * @param num + * @param date + * @param type + * @param minId + * @param maxId + * @return + */ + @Modifying + @Query("UPDATE TripartiteSource i set i.status = ?1,i.updateTime = ?2 where i.type = ?3 and i.id >= ?4 and i.id <= ?5") + int updateSourceByTypeAndId(Integer num, DateTime date, Integer type, Long minId, Long maxId); + + +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/TaskImeiController.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/TaskImeiController.java index a71385ac..60ad9b80 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/TaskImeiController.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/TaskImeiController.java @@ -2,8 +2,10 @@ package com.baiye.modules.platform.rest; import com.baiye.http.CommonResponse; import com.baiye.modules.platform.service.TaskImeiService; +import com.baiye.modules.platform.service.TripartiteSourceService; import com.baiye.modules.platform.service.dto.PlatformTransmitDTO; import com.baiye.modules.platform.service.dto.TaskImeiDTO; +import com.baiye.modules.platform.service.dto.TripartiteTransmitDTO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -24,6 +26,8 @@ public class TaskImeiController { private final TaskImeiService taskImeiService; + private final TripartiteSourceService tripartiteSourceService; + @ApiOperation("修改用户") @GetMapping("/updateImei") public ResponseEntity update(@RequestParam("taskName") String taskName) { @@ -38,6 +42,13 @@ public class TaskImeiController { CommonResponse.createBySuccess() : CommonResponse.createByError(); } + @ApiOperation("接受ad-back任务资源") + @PostMapping("/tripartite/add") + public CommonResponse tripartiteAddSource(@RequestBody TripartiteTransmitDTO dto) { + return Boolean.TRUE.equals(tripartiteSourceService.tripartiteAddSource(dto)) ? + CommonResponse.createBySuccess() : CommonResponse.createByError(); + } + @ApiOperation("兑换条数") @PostMapping("/exchange") public CommonResponse acceptAdBackSource(@Validated @RequestBody TaskImeiDTO taskImeiDTO) { diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/TripartiteDownRecordController.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/TripartiteDownRecordController.java new file mode 100644 index 00000000..76889cc0 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/TripartiteDownRecordController.java @@ -0,0 +1,66 @@ +package com.baiye.modules.platform.rest; + + +import com.baiye.annotation.Inner; +import com.baiye.modules.platform.service.TripartiteDownRecordService; +import com.baiye.modules.platform.service.dto.DownRecordQueryCriteria; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +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; + +/** + * @author Enzo + * @date : 2022/11/17 + */ +@RestController +@RequiredArgsConstructor +@Api(tags = "系统下载dmp文件") +@RequestMapping("/api/tripartite/record") +public class TripartiteDownRecordController { + + + private final TripartiteDownRecordService tripartiteDownRecordService; + + + @ApiOperation("查询记录") + @GetMapping + public ResponseEntity query(DownRecordQueryCriteria criteria, Pageable pageable) { + return new ResponseEntity<>(tripartiteDownRecordService.queryAll(criteria, pageable), HttpStatus.OK); + } + + + @Inner + @ApiOperation("保存下载链接") + @GetMapping("/save/path") + public ResponseEntity savePath(Long sourceData, Integer size, String zipPath, String downUrl, String dateStr) { + tripartiteDownRecordService.savePathByRecordId(sourceData, size, zipPath, downUrl, dateStr); + return new ResponseEntity<>(HttpStatus.OK); + } + + + @Inner + @ApiOperation("保存下载链接") + @GetMapping("/update/num") + public ResponseEntity updateNum(Long sourceData, String dateStr,Integer totalNumber) { + tripartiteDownRecordService.updateNum(sourceData, dateStr, totalNumber); + return new ResponseEntity<>(HttpStatus.OK); + } + + + @Inner + @ApiOperation("下载id查询下载地址") + @GetMapping("/find/path") + public ResponseEntity queryPathByDateStr(@RequestParam String dateStr,@RequestParam Long sourceData) { + String path = tripartiteDownRecordService.findDownPath(dateStr, sourceData); + return new ResponseEntity<>(path, HttpStatus.OK); + } + + +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TaskImeiService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TaskImeiService.java index 1ee6cf65..3dfaea29 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TaskImeiService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TaskImeiService.java @@ -91,4 +91,6 @@ public interface TaskImeiService { * @return */ Boolean updateImeiByDate(Integer status, Integer number, DateTime dateTime); + + } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TripartiteDownRecordService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TripartiteDownRecordService.java new file mode 100644 index 00000000..a71051f9 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TripartiteDownRecordService.java @@ -0,0 +1,49 @@ +package com.baiye.modules.platform.service; + +import com.baiye.modules.platform.service.dto.DownRecordQueryCriteria; +import org.springframework.data.domain.Pageable; + +import java.util.Map; + +/** + * @author Enzo + * @date : 2023/10/13 + */ +public interface TripartiteDownRecordService { + + /** + * 日期查询下载记录 + * + * @param dateStr + * @param sourceData + * @return + */ + String findDownPath(String dateStr, Long sourceData); + + /** + * 查询记录 + * @param criteria + * @param pageable + * @return + */ + Map queryAll(DownRecordQueryCriteria criteria, Pageable pageable); + + /** + * 保存下载链接 + * + * @param sourceData + * @param size + * @param zipPath + * @param downUrl + * @param dateStr + */ + void savePathByRecordId(Long sourceData, Integer size, String zipPath, String downUrl, String dateStr); + + /** + * 修改数量 + * @param sourceData + * @param dateStr + * @param totalNumber + */ + void updateNum(Long sourceData, String dateStr, Integer totalNumber); +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TripartiteSourceService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TripartiteSourceService.java new file mode 100644 index 00000000..d73de38a --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TripartiteSourceService.java @@ -0,0 +1,41 @@ +package com.baiye.modules.platform.service; + +import cn.hutool.core.date.DateTime; +import com.baiye.modules.platform.domain.TripartiteSource; +import com.baiye.modules.platform.service.dto.TripartiteTransmitDTO; + +import java.util.List; + +/** + * @author Enzo + * @date : 2023/10/13 + */ +public interface TripartiteSourceService { + + /** + * 保存三方资源 + * @param dto + * @return + */ + Boolean tripartiteAddSource(TripartiteTransmitDTO dto); + + /** + * 时间 + * + * @param num + * @param beginTime + * @param endTime + * @return + */ + List queryDateByTime(Integer num, DateTime beginTime, DateTime endTime); + + /** + * 修改批次 + * @param type + * @param num + * @param minId + * @param maxId + * @return 失败或者成功 + */ + Boolean updateBath(Integer type, Integer num, Long minId, Long maxId); +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/ImeiDTO.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/ImeiDTO.java index 5840f909..37affbb5 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/ImeiDTO.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/ImeiDTO.java @@ -15,6 +15,10 @@ public class ImeiDTO implements Serializable { private static final long serialVersionUID = -3271582444610218303L; + /** + * This field is used for IMEI exchange in the early stage, and OAID can also be exchanged later + * Enzo + */ @ApiModelProperty(value = "imei") private String imei; diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/TripartitePlatformDTO.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/TripartitePlatformDTO.java new file mode 100644 index 00000000..29d15054 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/TripartitePlatformDTO.java @@ -0,0 +1,16 @@ +package com.baiye.modules.platform.service.dto; + +import lombok.Data; + +/** + * @author Enzo + * @date : 2023/10/13 + */ +@Data +public class TripartitePlatformDTO { + + private String nid; + + private Integer type; + +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/TripartiteTransmitDTO.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/TripartiteTransmitDTO.java new file mode 100644 index 00000000..8ae1ab41 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/TripartiteTransmitDTO.java @@ -0,0 +1,18 @@ +package com.baiye.modules.platform.service.dto; + +import lombok.Data; + +import java.util.List; + +/** + * @author Enzo + * @date : 2022/10/14 + */ +@Data +public class TripartiteTransmitDTO { + + + private String authToken; + + private List list; +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TaskImeiServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TaskImeiServiceImpl.java index f7a756f0..eeaa03a7 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TaskImeiServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TaskImeiServiceImpl.java @@ -16,10 +16,7 @@ import com.baiye.modules.platform.domain.TaskImei; import com.baiye.modules.platform.repository.TaskImeiRepository; import com.baiye.modules.platform.service.DeliveryRecordService; import com.baiye.modules.platform.service.TaskImeiService; -import com.baiye.modules.platform.service.dto.ImeiDTO; -import com.baiye.modules.platform.service.dto.PlatformTransmitDTO; -import com.baiye.modules.platform.service.dto.RepeatFormDTO; -import com.baiye.modules.platform.service.dto.TaskImeiDTO; +import com.baiye.modules.platform.service.dto.*; import com.baiye.util.*; import com.google.common.collect.Lists; import com.google.common.collect.Sets; diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TripartiteDownRecordServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TripartiteDownRecordServiceImpl.java new file mode 100644 index 00000000..916ee5a7 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TripartiteDownRecordServiceImpl.java @@ -0,0 +1,59 @@ +package com.baiye.modules.platform.service.impl; + +import com.baiye.constant.DefaultNumberConstants; +import com.baiye.model.enums.SourceEnums; +import com.baiye.modules.platform.domain.TripartiteDownRecord; +import com.baiye.modules.platform.repository.TripartiteDownRecordRepository; +import com.baiye.modules.platform.service.TripartiteDownRecordService; +import com.baiye.modules.platform.service.dto.DownRecordQueryCriteria; +import com.baiye.util.PageUtil; +import com.baiye.util.QueryHelp; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Map; + +/** + * @author Enzo + * @date : 2023/10/13 + */ +@Service +@RequiredArgsConstructor +public class TripartiteDownRecordServiceImpl implements TripartiteDownRecordService { + + private final TripartiteDownRecordRepository tripartiteDownRecordRepository; + + @Override + public String findDownPath(String dateStr, Long sourceData) { + return tripartiteDownRecordRepository.findByDownPathByDateStr(dateStr, sourceData); + } + + @Override + public Map queryAll(DownRecordQueryCriteria criteria, Pageable pageable) { + Page page = tripartiteDownRecordRepository.findAll((root, query, cb) -> + QueryHelp.getPredicate(root, criteria, cb), pageable); + return PageUtil.toPage(page); + } + + @Override + public void savePathByRecordId(Long sourceData, Integer size, String zipPath, String downUrl, String dateStr) { + TripartiteDownRecord downRecord = new TripartiteDownRecord(); + downRecord.setClueNum(size); + downRecord.setDownUrl(downUrl); + downRecord.setDateStr(dateStr); + downRecord.setFilePath(zipPath); + downRecord.setSourceData(sourceData); + downRecord.setSourceMemo(SourceEnums.TO8TO.getMemo()); + downRecord.setStatus(DefaultNumberConstants.ONE_NUMBER); + tripartiteDownRecordRepository.save(downRecord); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateNum(Long sourceData, String dateStr, Integer totalNumber) { + tripartiteDownRecordRepository.updateNumByDateStr(totalNumber, sourceData, dateStr); + } +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TripartiteSourceServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TripartiteSourceServiceImpl.java new file mode 100644 index 00000000..5bf9e510 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TripartiteSourceServiceImpl.java @@ -0,0 +1,68 @@ +package com.baiye.modules.platform.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import com.baiye.constant.DefaultNumberConstants; +import com.baiye.modules.platform.domain.TripartiteSource; +import com.baiye.modules.platform.repository.TripartiteSourceRepository; +import com.baiye.modules.platform.service.TripartiteSourceService; +import com.baiye.modules.platform.service.dto.TripartitePlatformDTO; +import com.baiye.modules.platform.service.dto.TripartiteTransmitDTO; +import com.google.common.collect.Lists; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * @author Enzo + * @date : 2023/10/13 + */ +@Service +@RequiredArgsConstructor +public class TripartiteSourceServiceImpl implements TripartiteSourceService { + + + @Value("${platform.authToken}") + private String authToken; + + + private final TripartiteSourceRepository tripartiteSourceRepository; + + + @Override + public Boolean tripartiteAddSource(TripartiteTransmitDTO dto) { + if (StringUtils.isNotBlank(dto.getAuthToken()) + && dto.getAuthToken().equalsIgnoreCase(authToken)) { + List sourceList = Lists.newArrayList(); + if (CollUtil.isNotEmpty(dto.getList())) { + for (TripartitePlatformDTO platformDTO : dto.getList()) { + TripartiteSource source = new TripartiteSource(); + source.setType(platformDTO.getType()); + source.setCreateTime(DateUtil.date()); + source.setEquipment(platformDTO.getNid().trim()); + source.setStatus(DefaultNumberConstants.ZERO_NUMBER); + sourceList.add(source); + } + tripartiteSourceRepository.saveAll(sourceList); + return Boolean.TRUE; + } + } + return Boolean.FALSE; + } + + @Override + public List queryDateByTime(Integer num, DateTime beginTime, DateTime endTime) { + return tripartiteSourceRepository.findByStatusAndCreateTimeBetweenTime(num, beginTime, endTime); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean updateBath(Integer type, Integer num, Long minId, Long maxId) { + return tripartiteSourceRepository.updateSourceByTypeAndId(num, DateUtil.date(), type, minId, maxId) > DefaultNumberConstants.ZERO_NUMBER; + } +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/TripartiteDeliveryTask.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/TripartiteDeliveryTask.java new file mode 100644 index 00000000..850277f1 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/TripartiteDeliveryTask.java @@ -0,0 +1,130 @@ +package com.baiye.timed; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import com.baiye.common.CommonLog; +import com.baiye.config.properties.DeliveryProperties; +import com.baiye.constant.AdPlatFormConstants; +import com.baiye.constant.DefaultNumberConstants; +import com.baiye.enums.MailRequestEnum; +import com.baiye.modules.platform.domain.TripartiteSource; +import com.baiye.modules.platform.service.DeliveryRecordService; +import com.baiye.modules.platform.service.TripartiteSourceService; +import com.baiye.modules.platform.service.dto.ImeiDTO; +import com.baiye.util.RedisUtils; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import com.sun.corba.se.impl.orbutil.ORBConstants; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + + +/** + * @author Enzo + */ +@Component +@Slf4j +@RequiredArgsConstructor +public class TripartiteDeliveryTask { + + + private final RedisUtils redisUtils; + + private final DeliveryProperties deliveryProperties; + + private final DeliveryRecordService deliveryRecordService; + + private final TripartiteSourceService tripartiteSourceService; + + + + /** + * 凌晨一点兑换第三方数据 + * + */ + @Scheduled(cron = "0 0 1 * * ? ") + public void dealTurnover() { + DateTime date = DateUtil.offsetDay(DateUtil.date(),DefaultNumberConstants.MINUS_ONE_NUMBER); + List sourceList = tripartiteSourceService.queryDateByTime + (DefaultNumberConstants.ZERO_NUMBER, DateUtil.beginOfDay(date), DateUtil.endOfDay(date)); + if (CollUtil.isNotEmpty(sourceList)) { + // type 分组 + Map> listMap = + sourceList.stream().collect(Collectors.groupingBy(TripartiteSource::getType)); + + for (Map.Entry> map : listMap.entrySet()) { + // 去除重复数据 + List list = + Lists.newArrayList(Sets.newHashSet(map.getValue())); + // 接口每次100000 + List> lists = Lists.partition + (list, DefaultNumberConstants.ONE_HUNDRED_THOUSAND); + for (List taskImeiList : lists) { + // 发送并修改状态 + sendSourceAndUpdateImeiStatus(map.getKey(), taskImeiList); + } + } + } + } + + /** + * 接口发送数据 + * + * @param type + * @param list + */ + private void sendSourceAndUpdateImeiStatus(Integer type, List list) { + Long minId = (long) DefaultNumberConstants.ZERO_NUMBER; + Long maxId = (long) DefaultNumberConstants.ZERO_NUMBER; + // 接口最小20 邮件最小50 + if (list.size() > DefaultNumberConstants.TWENTY_NUMBER) { + Comparator comparing = Comparator.comparing(TripartiteSource::getId); + // 最小id + minId = getaLong(list.stream().min(comparing), minId); + // 最大id + maxId = getaLong(list.stream().max(comparing), maxId); + if (minId > DefaultNumberConstants.ZERO_NUMBER && + maxId > DefaultNumberConstants.ZERO_NUMBER) { + String taskImeiName = redisUtils.acquisitionBatch(MailRequestEnum.BT.getCacheName()); + List toList = Lists.newArrayList(); + list.forEach(source -> { + ImeiDTO imeiDTO = new ImeiDTO(); + imeiDTO.setImei(source.getEquipment()); + imeiDTO.setTag(AdPlatFormConstants.DEFAULT_TAG); + toList.add(imeiDTO); + }); + // 接口兑换 + Boolean result = deliveryRecordService.exchangeByInterFace + (toList, taskImeiName, type, deliveryProperties.getPublicKey(), deliveryProperties.getPrivateKey()); + if (Boolean.TRUE.equals(result)) { + CommonLog.info("兑换,当前tag值为".concat(toList.get(DefaultNumberConstants.ZERO_NUMBER).getTag())); + // 保存发送记录 + deliveryRecordService.saveDeliveryRecord(null, taskImeiName, + AdPlatFormConstants.DEFAULT_TAG, toList.size(), null, + (long) ORBConstants.GIOP_DEFAULT_BUFFER_SIZE, DefaultNumberConstants.FOUR_NUMBER, type, null); + // 批次修改状态 + tripartiteSourceService.updateBath(type, DefaultNumberConstants.ONE_NUMBER, minId, maxId); + } + log.info("=============== the interface sending a request result as {} batchNo as {} minId {} maxId {} ===============", result, taskImeiName, minId, maxId); + } + } + } + + private static Long getaLong(Optional downList, Long updateId) { + // 最小id + if (downList.isPresent()) { + updateId = downList.get().getId(); + } + return updateId; + } + +} diff --git a/ad-platform-manage/ad-platform-task/src/main/resources/application-dev.yml b/ad-platform-manage/ad-platform-task/src/main/resources/application-dev.yml index 3b4f12e6..84203f8a 100644 --- a/ad-platform-manage/ad-platform-task/src/main/resources/application-dev.yml +++ b/ad-platform-manage/ad-platform-task/src/main/resources/application-dev.yml @@ -9,13 +9,14 @@ spring: server-addr: ${NACOS_HOST:8.130.96.163}:${NACOS_PORT:8848} redis: database: 2 - host: 8.130.96.163 + host: 39.100.77.21 timeout: 5000 + password: sC33HXphkHBRj4Jb datasource: druid: db-type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver - url: jdbc:mysql://8.130.96.163:3306/ad-platform?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull + url: jdbc:mysql://39.100.77.21:3306/ad-platform?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull username: root password: y7z7noq2 # url: jdbc:mysql://localhost:3306/ad-platform?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/enums/SourceEnums.java b/ad-platform-pojo/src/main/java/com/baiye/model/enums/SourceEnums.java new file mode 100644 index 00000000..bf3e4cac --- /dev/null +++ b/ad-platform-pojo/src/main/java/com/baiye/model/enums/SourceEnums.java @@ -0,0 +1,25 @@ +package com.baiye.model.enums; + +import com.baiye.constant.DefaultNumberConstants; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author Enzo + * @date : 2023/10/16 + */ +@Getter +@AllArgsConstructor +public enum SourceEnums { + + + /** + * 置顶 + */ + TO8TO(1024, "土巴兔"); + + private final Integer value; + + private final String memo; + +} diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/feign/DeliveryRecordClient.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/feign/DeliveryRecordClient.java index bb5c8a4f..9db497b7 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/feign/DeliveryRecordClient.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/feign/DeliveryRecordClient.java @@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestParam; @FeignClient(value = "ad-platform-management", fallback = OrganizeClientFallback.class) public interface DeliveryRecordClient { + String TRIPARTITE_DOWN_PREFIX = "/api/tripartite/record"; + String PAY_PREFIX = "/api/down/record"; String AGENT_PREFIX = "/api/custom"; @@ -62,5 +64,42 @@ public interface DeliveryRecordClient { ResponseEntity queryPath(@RequestParam("downId") Long downId, @RequestHeader(SecurityConstants.FROM) String from); + /** + * id获取配置路径 + * + * @param dateStr + * @param sourceData + * @param from + * @return + */ + @ApiOperation("下载地址获取链接") + @GetMapping(TRIPARTITE_DOWN_PREFIX + "/find/path") + ResponseEntity queryTripartitePath(@RequestParam("dateStr") String dateStr, @RequestParam("sourceData") Long sourceData, @RequestHeader(SecurityConstants.FROM) String from); + + /** + * 保存数据 + * + * @param userId + * @param size + * @param zipPath + * @param downUrl + * @param format + * @param fromIn + * @return + */ + @ApiOperation("保存链接地址") + @GetMapping(TRIPARTITE_DOWN_PREFIX + "/save/path") + ResponseEntity savePathAndSetDateStr(@RequestParam("sourceData") Long userId, @RequestParam("size") Integer size, @RequestParam("zipPath") String zipPath, @RequestParam("downUrl") String downUrl, @RequestParam("dateStr") String format, @RequestHeader(SecurityConstants.FROM) String fromIn); + /** + * 修改下载数量 + * + * @param userId + * @param format + * @param size + * @param fromIn + */ + @ApiOperation("保存链接地址") + @GetMapping(TRIPARTITE_DOWN_PREFIX + "/update/num") + void updateOriginAndSize(@RequestParam("sourceData") Long userId, @RequestParam("dateStr") String format,@RequestParam("totalNumber") Integer size, @RequestHeader(SecurityConstants.FROM) String fromIn); } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/DmpCallbackServiceImpl.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/DmpCallbackServiceImpl.java index 6c1b0e51..a38327cc 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/DmpCallbackServiceImpl.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/DmpCallbackServiceImpl.java @@ -2,8 +2,12 @@ package com.baiye.module.service.impl; import cn.hutool.core.codec.Base64; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.text.StrPool; +import cn.hutool.core.text.csv.CsvData; +import cn.hutool.core.text.csv.CsvReader; import cn.hutool.core.text.csv.CsvUtil; import cn.hutool.core.text.csv.CsvWriter; import cn.hutool.core.util.CharsetUtil; @@ -41,6 +45,7 @@ import org.springframework.transaction.annotation.Transactional; import java.io.File; import java.util.List; import java.util.Objects; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -114,6 +119,9 @@ public class DmpCallbackServiceImpl implements DmpCallbackService { if (byTaskName.getType() == DefaultNumberConstants.TWO_NUMBER) { downResource(bathNo, byTaskName, originalList, responseList); } + if (byTaskName.getType() == DefaultNumberConstants.FOUR_NUMBER) { + downReceptionResource(bathNo, byTaskName, responseList); + } } // 兑换结果失败也将结果返回 if (byTaskName.getType() == DefaultNumberConstants.THREE_NUMBER) { @@ -166,7 +174,7 @@ public class DmpCallbackServiceImpl implements DmpCallbackService { Object objPath = redisUtils.get(CacheKey.DMP_DOWN_URL.concat(String.valueOf(byTaskName.getDownId()))); String path = ObjectUtil.isNotNull(objPath) ? String.valueOf(objPath) : deliveryRecordClient.queryPath - (byTaskName.getDownId(), SecurityConstants.FROM_IN).getBody(); + (byTaskName.getDownId(), SecurityConstants.FROM_IN).getBody(); if (ObjectUtil.isNotNull(path)) { // 解压文件 @@ -210,6 +218,57 @@ public class DmpCallbackServiceImpl implements DmpCallbackService { redisUtils.set(CacheKey.DMP_DOWN_URL.concat(String.valueOf(byTaskName.getDownId())), zipPath, DefaultNumberConstants.ONE_NUMBER, TimeUnit.DAYS); } + @SneakyThrows + private void downReceptionResource(String bathNo, DeliveryRecord byTaskName, List responseList) { + + String uuid = IdUtil.fastSimpleUUID(); + String format = DateUtil.format(DateUtil.date(), DatePattern.NORM_DATE_PATTERN); + String file = deliveryProperties.getFileUrl().concat(StrPool.SLASH).concat(uuid); + Object objPath = redisUtils.get(CacheKey.DMP_TRIPARTITE_URL.concat(format)); + String path = ObjectUtil.isNotNull(objPath) ? + String.valueOf(objPath) : deliveryRecordClient.queryTripartitePath(format, byTaskName.getUserId(), SecurityConstants.FROM_IN).getBody(); + if (ObjectUtil.isNotNull(path)) { + // 解压文件 + String unzipPath = CompressUtil.unzipFiles + (deliveryProperties.getFileUrl(), path, deliveryProperties.getZipPassword()); + File unzipFile = new File(unzipPath); + File parseFile = Objects.requireNonNull + (unzipFile.listFiles())[DefaultNumberConstants.ZERO_NUMBER]; + CsvReader reader = CsvUtil.getReader(); + CsvData read = reader.read(parseFile); + // 将原始内容解析 + Set originSet = read.getRows().stream().map + (origin -> origin.get(DefaultNumberConstants.ZERO_NUMBER)).collect(Collectors.toSet()); + // 追加新内容 + originSet.addAll(responseList.stream().map + (str -> EncryptUtil.aesEncrypt(str, AdPlatFormConstants.PLAT_DECRYPTION)).collect(Collectors.toSet())); + FileZipUtil.writeToCsv(Lists.newArrayList(originSet), parseFile.getPath(), Boolean.TRUE); + // 设置压缩文件 + CompressUtil.decryptionCompression(path, parseFile.getPath(), null); + deliveryRecordService.updateStatusByTaskName(DefaultNumberConstants.ONE_NUMBER, responseList.size(), bathNo); + deliveryRecordClient.updateOriginAndSize(byTaskName.getUserId(), format, originSet.size(), SecurityConstants.FROM_IN); + FileUtil.del(unzipPath); + return; + } + // 首次加载 + String csvPath = file.concat(StrPool.DOT).concat(FileConstant.CSV_FILE_SUB_NAME); + CsvWriter writer = CsvUtil.getWriter(csvPath, CharsetUtil.CHARSET_UTF_8); + String zipPath = file.concat(FileConstant.ZIP_FILE_SUB_NAME); + Set stringSet = responseList.stream().map + (str -> EncryptUtil.aesEncrypt(str, AdPlatFormConstants.PLAT_DECRYPTION)).collect(Collectors.toSet()); + writer.write(stringSet); + writer.close(); + // 设置压缩文件 + CompressUtil.decryptionCompression(zipPath, csvPath, null); + String filePath = zipPath.substring + (zipPath.lastIndexOf(StrPool.SLASH) + DefaultNumberConstants.ONE_NUMBER); + FileUtil.del(csvPath); + String downUrl = deliveryProperties.getDmpDownPath().concat(filePath); + deliveryRecordService.updateStatusByTaskName(DefaultNumberConstants.ONE_NUMBER, responseList.size(), bathNo); + deliveryRecordClient.savePathAndSetDateStr(byTaskName.getUserId(), stringSet.size(), zipPath, downUrl, format, SecurityConstants.FROM_IN); + redisUtils.set(CacheKey.DMP_TRIPARTITE_URL.concat(format), zipPath, DefaultNumberConstants.ONE_NUMBER, TimeUnit.DAYS); + } + private static void aggregateData(InterfaceResponseDTO responseDTO, DeliveryRecord byTaskName, List tagList, List phoneList, List> originalList) { for (InterfaceResponseDTO.Data data : responseDTO.getDatas()) { diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/MailSourceTask.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/MailSourceTask.java index 31389e33..4eb2c532 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/MailSourceTask.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/MailSourceTask.java @@ -47,6 +47,7 @@ import java.util.stream.Collectors; */ @Slf4j @Component +@Deprecated @RequiredArgsConstructor public class MailSourceTask { @@ -68,9 +69,10 @@ public class MailSourceTask { /** * 十分钟获取邮件内容 + * change to Deprecated by Enzo */ + @SneakyThrows - @Scheduled(cron = "0 0/10 * * * ? ") @Transactional(rollbackFor = Exception.class) public void receiveMail() { // 获取邮件内容 diff --git a/ad-platform-services/ad-platform-source/src/main/resources/application-test.yml b/ad-platform-services/ad-platform-source/src/main/resources/application-test.yml index 5c24bc3c..b0eb5b46 100644 --- a/ad-platform-services/ad-platform-source/src/main/resources/application-test.yml +++ b/ad-platform-services/ad-platform-source/src/main/resources/application-test.yml @@ -10,8 +10,6 @@ spring: host: 39.100.77.21 timeout: 5000 password: sC33HXphkHBRj4Jb - port: 6379 - datasource: druid: db-type: com.alibaba.druid.pool.DruidDataSource