From 0a25f0e1e5d97ec9c69c38ff48011bce27303b8f Mon Sep 17 00:00:00 2001 From: ninftao <13586541001@163.com> Date: Fri, 13 Jan 2023 23:37:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B0=8F=E8=93=9D=E6=9C=AC?= =?UTF-8?q?=E5=85=91=E6=8D=A2=E4=BB=A3=E7=A0=81=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/config/application-prod.yml | 2 +- .../constant/DefaultNumberConstants.java | 7 -- .../java/com/baiye/http/CommonResponse.java | 9 +++ .../main/java/com/baiye/http/DmpDataDTO.java | 19 +++++ .../main/java/com/baiye/http/DmpResponse.java | 16 ++++ .../main/java/com/baiye/util/AESUtils.java | 30 +++++--- .../resources/config/application-prod.yml | 2 +- .../src/main/resources/config/application.yml | 2 +- .../config/properties/DeliveryProperties.java | 3 + .../repository/DeliveryRecordRepository.java | 8 ++ .../platform/rest/TaskImeiController.java | 9 +++ .../service/DeliveryRecordService.java | 9 +++ .../platform/service/TaskImeiService.java | 9 +++ .../platform/service/dto/TaskImeiDTO.java | 26 +++++++ .../impl/DeliveryRecordServiceImpl.java | 5 ++ .../service/impl/TaskImeiServiceImpl.java | 77 ++++++++++++++++++- .../main/resources/config/application-dev.yml | 1 + .../resources/config/application-prod.yml | 3 +- .../model/entity/BaseDeliveryRecord.java | 4 + .../com/baiye/model/enums/ResponseCode.java | 40 +++++----- .../src/main/resources/application-prod.yml | 2 +- .../config/properties/DeliveryProperties.java | 3 + .../module/dao/DeliveryRecordRepository.java | 6 +- .../module/service/DeliveryRecordService.java | 3 +- .../impl/DeliveryRecordServiceImpl.java | 5 +- .../java/com/baiye/task/MailSourceTask.java | 73 +++++++++++------- .../src/main/resources/application-prod.yml | 5 +- .../src/main/resources/application-test.yml | 1 + 28 files changed, 302 insertions(+), 77 deletions(-) create mode 100644 ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/DmpDataDTO.java create mode 100644 ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/DmpResponse.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/TaskImeiDTO.java diff --git a/ad-platform-auth/src/main/resources/config/application-prod.yml b/ad-platform-auth/src/main/resources/config/application-prod.yml index 9f988b23..2250afd4 100644 --- a/ad-platform-auth/src/main/resources/config/application-prod.yml +++ b/ad-platform-auth/src/main/resources/config/application-prod.yml @@ -7,7 +7,7 @@ spring: auto-commit: true #注意的是这个地方的定义需要用在DataSourceConfig.java里面使用,是因为在定义JobEventConfig.java的时候需要引入自定义dataSource password: baiye@RDS2022 - jdbc-url: jdbc:mysql://172.16.190.245:3306/ad_platform?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull + jdbc-url: jdbc:mysql://127.0.0.1:3306/ad_platform?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull username: root redis: #数据库索引 diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java index 32d7c611..f2cab06f 100644 --- a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java @@ -218,11 +218,4 @@ public class DefaultNumberConstants { * % */ public static final String DOLLAR_DELIM = "${"; - - /** - * 七彩之谜 - */ - public static final Long COLORFUL_PUZZLE_NUMBER = 12576L; - - } diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CommonResponse.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CommonResponse.java index b959e42f..92de6fc7 100644 --- a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CommonResponse.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CommonResponse.java @@ -118,4 +118,13 @@ public class CommonResponse implements Serializable { public static CommonResponse createByErrorCodeMessage(int errorCode,String errorMessage){ return new CommonResponse<>(errorCode,errorMessage); } + + /** + * 返回错误码(传入)和错误信息(传入) + */ + public static CommonResponse createBySuccess(int successCode){ + return new CommonResponse<>(successCode, ResponseCode.SUCCESS.getDesc()); + } + + } diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/DmpDataDTO.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/DmpDataDTO.java new file mode 100644 index 00000000..176f3d5c --- /dev/null +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/DmpDataDTO.java @@ -0,0 +1,19 @@ +package com.baiye.http; + +import lombok.Data; + +/** + * @author Enzo + * @date : 2023/1/3 + */ +@Data +public class DmpDataDTO { + + private String decryptInfo; + + private String tag; + + + + +} diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/DmpResponse.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/DmpResponse.java new file mode 100644 index 00000000..e0f0e045 --- /dev/null +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/DmpResponse.java @@ -0,0 +1,16 @@ +package com.baiye.http; + +import com.baiye.http.DmpDataDTO; +import lombok.Data; + +import java.util.List; + +/** + * @author Enzo + * @date : 2023/1/3 + */ +@Data +public class DmpResponse { + private String batchNo; + private List decryptList; +} diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/AESUtils.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/AESUtils.java index af71e2a8..27d72ee3 100644 --- a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/AESUtils.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/AESUtils.java @@ -1,5 +1,6 @@ package com.baiye.util; +import com.baiye.constant.AdPlatFormConstants; import lombok.extern.slf4j.Slf4j; import javax.crypto.Cipher; @@ -15,13 +16,19 @@ import java.util.Base64; @Slf4j public class AESUtils { - /** 密钥长度: 128, 192 or 256 */ + /** + * 密钥长度: 128, 192 or 256 + */ private static final int KEY_SIZE = 128; - /** 加密/解密算法名称 */ + /** + * 加密/解密算法名称 + */ private static final String ALGORITHM = "AES"; - /** 随机数生成器(RNG)算法名称 */ + /** + * 随机数生成器(RNG)算法名称 + */ private static final String RNG_ALGORITHM = "SHA1PRNG"; /** @@ -63,8 +70,8 @@ public class AESUtils { //base64加密 String str = Base64.getEncoder().encodeToString(cipherBytes); return str; - }catch (Exception e){ - log.info("加密失败"+e.fillInStackTrace()); + } catch (Exception e) { + log.error("加密失败" + e.fillInStackTrace()); return null; } @@ -73,7 +80,7 @@ public class AESUtils { /** * 数据解密: 密文 -> 明文 */ - public static String decrypt(String cipherBytes, String key){ + public static String decrypt(String cipherBytes, String key) { try { // 生成密钥对象 SecretKey secKey = generateKey(key.getBytes(StandardCharsets.UTF_8)); @@ -90,12 +97,15 @@ public class AESUtils { byte[] plainBytes = cipher.doFinal(bytes); //反转解密的结果返回 - String str = new StringBuilder(new String(plainBytes, "utf-8")).reverse().toString(); - return str; - }catch (Exception e){ - log.info("解密失败"+e.fillInStackTrace()); + return new StringBuilder(new String(plainBytes, StandardCharsets.UTF_8)).reverse().toString(); + } catch (Exception e) { + log.error("解密失败" + e.fillInStackTrace()); return null; } + } + public static void main(String[] args) { + System.out.println(AESUtils.encrypt("216f7a59d24498e204ef5efd6b383b39", "DA2023xlb213v1.")); + System.out.println(AESUtils.decrypt("Lw1oRu+9EoCb++Fj6OrnyoUbr7QPTkCpe+OwvA9ZdH6DLJMxem509vAHRBtb5Kp1", "DB2023xlb213v1.")); } } diff --git a/ad-platform-gateway/src/main/resources/config/application-prod.yml b/ad-platform-gateway/src/main/resources/config/application-prod.yml index d4009ce7..b1ab1d20 100644 --- a/ad-platform-gateway/src/main/resources/config/application-prod.yml +++ b/ad-platform-gateway/src/main/resources/config/application-prod.yml @@ -3,7 +3,7 @@ spring: redis: #数据库索引 database: 9 - host: 172.16.190.245 + host: 127.0.0.1 port: 6379 password: datasource: diff --git a/ad-platform-gateway/src/main/resources/config/application.yml b/ad-platform-gateway/src/main/resources/config/application.yml index 6e9daa82..a5685053 100644 --- a/ad-platform-gateway/src/main/resources/config/application.yml +++ b/ad-platform-gateway/src/main/resources/config/application.yml @@ -1,7 +1,7 @@ spring: profiles: - active: dev + active: prod cloud: gateway: discovery: diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/config/properties/DeliveryProperties.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/config/properties/DeliveryProperties.java index 76ed3493..d0d4d5da 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/config/properties/DeliveryProperties.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/config/properties/DeliveryProperties.java @@ -20,6 +20,9 @@ public class DeliveryProperties { @ApiModelProperty("压缩密码") private String zipPassword; + @ApiModelProperty("兑换密码") + private String exchangePassword; + @ApiModelProperty("customerId") private String customerId; diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/DeliveryRecordRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/DeliveryRecordRepository.java index b83696c3..bee15b5a 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/DeliveryRecordRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/DeliveryRecordRepository.java @@ -10,4 +10,12 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; */ public interface DeliveryRecordRepository extends JpaRepository, JpaSpecificationExecutor { + + /** + * 根据任务名称查询 + * @param taskName + * @return + */ + DeliveryRecord findByTaskName(String taskName); + } 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 d96e2f66..a71385ac 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 @@ -3,11 +3,13 @@ package com.baiye.modules.platform.rest; import com.baiye.http.CommonResponse; import com.baiye.modules.platform.service.TaskImeiService; import com.baiye.modules.platform.service.dto.PlatformTransmitDTO; +import com.baiye.modules.platform.service.dto.TaskImeiDTO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; /** @@ -35,4 +37,11 @@ public class TaskImeiController { return Boolean.TRUE.equals(taskImeiService.acceptAdBackSource(transmitDTO)) ? CommonResponse.createBySuccess() : CommonResponse.createByError(); } + + @ApiOperation("兑换条数") + @PostMapping("/exchange") + public CommonResponse acceptAdBackSource(@Validated @RequestBody TaskImeiDTO taskImeiDTO) { + return taskImeiService.processingData(taskImeiDTO); + } + } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/DeliveryRecordService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/DeliveryRecordService.java index a6d2c500..d937b018 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/DeliveryRecordService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/DeliveryRecordService.java @@ -1,5 +1,7 @@ package com.baiye.modules.platform.service; +import com.baiye.modules.platform.domain.DeliveryRecord; + /** * @author Enzo * @date : 2022/10/18 @@ -17,4 +19,11 @@ public interface DeliveryRecordService { * @return */ Long saveDeliveryRecord(String filePath, String taskName, Integer num, Long taskId, Long userId, Integer type); + + /** + * 根据批次号查询记录 + * @param taskName + * @return 记录 + */ + DeliveryRecord findByBatchNo(String taskName); } 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 3287b850..3b54cbcc 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 @@ -1,7 +1,9 @@ package com.baiye.modules.platform.service; +import com.baiye.http.CommonResponse; import com.baiye.modules.platform.domain.TaskImei; import com.baiye.modules.platform.service.dto.PlatformTransmitDTO; +import com.baiye.modules.platform.service.dto.TaskImeiDTO; import java.util.List; import java.util.Set; @@ -67,4 +69,11 @@ public interface TaskImeiService { * @param taskIds */ void deleteTaskImei(Set taskIds); + + /** + * 上传并发送兑换邮件 + * @param taskImeiDTO + * @return + */ + CommonResponse processingData(TaskImeiDTO taskImeiDTO); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/TaskImeiDTO.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/TaskImeiDTO.java new file mode 100644 index 00000000..0f6d6209 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/TaskImeiDTO.java @@ -0,0 +1,26 @@ +package com.baiye.modules.platform.service.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import java.util.List; + +/** + * @author Enzo + * @date : 2023/1/13 + */ +@Data +public class TaskImeiDTO { + + @NotBlank + @ApiModelProperty(value = "批次号") + private String batchNo; + + @NotEmpty + @ApiModelProperty(value = "兑换数量") + private List imeiList; + + +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/DeliveryRecordServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/DeliveryRecordServiceImpl.java index efd77709..41aaa020 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/DeliveryRecordServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/DeliveryRecordServiceImpl.java @@ -29,4 +29,9 @@ public class DeliveryRecordServiceImpl implements DeliveryRecordService { return deliveryRecordRepository.save(deliveryRecord).getId(); } + + @Override + public DeliveryRecord findByBatchNo(String taskName) { + return deliveryRecordRepository.findByTaskName(taskName); + } } 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 0c3e06c3..bd33cbee 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 @@ -1,13 +1,27 @@ package com.baiye.modules.platform.service.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.text.StrPool; +import cn.hutool.core.util.ObjectUtil; +import com.baiye.config.properties.DeliveryProperties; import com.baiye.constant.DefaultNumberConstants; +import com.baiye.constant.FileConstant; +import com.baiye.http.CommonResponse; +import com.baiye.model.enums.ResponseCode; + +import com.baiye.modules.platform.domain.DeliveryRecord; 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.RepeatFormDTO; +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.util.*; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -15,8 +29,11 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; import java.util.List; import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; /** * @author Enzo @@ -30,8 +47,14 @@ public class TaskImeiServiceImpl implements TaskImeiService { @Value("${platform.authToken}") private String authToken; + private final RedisUtils redisUtils; + + private final DeliveryProperties deliveryProperties; + private final TaskImeiRepository taskImeiRepository; + private final DeliveryRecordService deliveryRecordService; + @Override public List findByStatus(Integer num) { @@ -74,17 +97,17 @@ public class TaskImeiServiceImpl implements TaskImeiService { public Boolean updateImeiByTaskName(String taskName) { return taskImeiRepository.updateImeiByTaskName (DefaultNumberConstants.ONE_NUMBER, DateUtil.date(), taskName) - > DefaultNumberConstants.ZERO_NUMBER; + > DefaultNumberConstants.ZERO_NUMBER; } @Override - public Boolean updateBath(Long taskId, String taskImeiName, Integer num, Long minId, Long maxId) { + public Boolean updateBath(Long taskId, String taskImeiName, Integer num, Long minId, Long maxId) { return taskImeiRepository.updateImeiByTaskNameId (num, taskImeiName, DateUtil.date(), taskId, minId, maxId) > DefaultNumberConstants.ZERO_NUMBER; } @Override - public Integer countByUserIdAndDate( Long userId, Integer num) { + public Integer countByUserIdAndDate(Long userId, Integer num) { return taskImeiRepository.countByUserId(userId, num); } @@ -93,5 +116,51 @@ public class TaskImeiServiceImpl implements TaskImeiService { taskImeiRepository.deleteByTaskIds(taskIds); } + @Override + public CommonResponse processingData(TaskImeiDTO taskImeiDTO) { + List dtoList = Lists.newArrayList(Sets.newHashSet(taskImeiDTO.getImeiList())); + if (dtoList.size() < DefaultNumberConstants.ONE_HUNDRED) { + return CommonResponse.createByErrorCodeMessage + (DefaultNumberConstants.ZERO_NUMBER, ResponseCode.SEND_MAIL_NUM_FRIEND.getDesc()); + } + + if (dtoList.size() >= DefaultNumberConstants.ONE_HUNDRED_THOUSAND) { + return CommonResponse.createByErrorCodeMessage + (DefaultNumberConstants.ZERO_NUMBER, ResponseCode.SEND_MAIL_MAX_NUM_FRIEND.getDesc()); + } + + if (redisUtils.get(taskImeiDTO.getBatchNo()) != null) { + DeliveryRecord byBatchNo = deliveryRecordService.findByBatchNo(taskImeiDTO.getBatchNo()); + if (ObjectUtil.isNotNull(byBatchNo) && ObjectUtil.isNotNull(byBatchNo.getId())) { + return CommonResponse.createByErrorCodeMessage + (DefaultNumberConstants.ZERO_NUMBER, ResponseCode.BATCH_NUMBER_ALREADY_EXISTS.getDesc()); + } + } + + dtoList.forEach(o -> o.setImei(AESUtils.decrypt(o.getImei(), deliveryProperties.getExchangePassword()))); + // 过滤未解密完成的 + List filterList = dtoList.stream().filter + (o -> ObjectUtil.isNotNull(o.getImei())).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(filterList)) { + String file = deliveryProperties.getFileUrl().concat(StrPool.SLASH).concat(taskImeiDTO.getBatchNo()); + // 保存文件 + String csvPath = file.concat(StrPool.DOT).concat(FileConstant.CSV_FILE_SUB_NAME); + CSVFileUtil.createCsvFile(filterList, csvPath); + String zipPath = file.concat(FileConstant.ZIP_FILE_SUB_NAME); + // 设置压缩文件 + CompressUtil.decryptionCompression + (zipPath, csvPath, deliveryProperties.getZipPassword()); + // 发送邮件 + MailUtil.sendMail(deliveryProperties.getEmailAddress(), + deliveryProperties.getEmailPassword(), deliveryProperties.getToEmailAddress(), zipPath, taskImeiDTO.getBatchNo()); + Long recordId = deliveryRecordService.saveDeliveryRecord(zipPath, taskImeiDTO.getBatchNo(), dtoList.size(), + null, (long) DefaultNumberConstants.ONE_NUMBER, DefaultNumberConstants.THREE_NUMBER); + // 缓存三天 + redisUtils.set(taskImeiDTO.getBatchNo(), recordId, DefaultNumberConstants.ONE_NUMBER, TimeUnit.DAYS); + } + return CommonResponse.createBySuccess(DefaultNumberConstants.TWO_HUNDRED); + } + } + diff --git a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml index 51987f6b..c4b9fd82 100644 --- a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml +++ b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml @@ -178,6 +178,7 @@ debt: platform: authToken: JI8AeA7POKsdGcBC zipPassword: DB2022hjk213v1... + exchangePassword: DA2023xlb213v1. fileUrl: /home/eladmin/mail emailAddress: ensoze@outlook.com emailPassword: baiye2022 diff --git a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml index c0e9b341..f5f191fb 100644 --- a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml +++ b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml @@ -3,7 +3,7 @@ spring: cloud: nacos: discovery: - server-addr: ${NACOS_HOST:172.16.190.245}:${NACOS_PORT:8848} + server-addr: ${NACOS_HOST:127.0.0.1}:${NACOS_PORT:8848} redis: database: 2 host: 127.0.0.1 @@ -177,6 +177,7 @@ debt: platform: authToken: nqJpVSf3UcrEcVIH zipPassword: DB2022hjk213v1... + exchangePassword: DA2023xlb213v1. fileUrl: /home/eladmin/mail emailAddress: ensoze@outlook.com emailPassword: baiye2022 diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseDeliveryRecord.java b/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseDeliveryRecord.java index 45e51c20..ce1002f8 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseDeliveryRecord.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseDeliveryRecord.java @@ -45,6 +45,10 @@ public class BaseDeliveryRecord { @Column(name = "num") private Integer num; + @ApiModelProperty("任务数量") + @Column(name = "decrypt_num") + private Integer decryptNum; + @ApiModelProperty("任务类型 1:定时发送 2:手动上传") @Column(name = "type") private Integer type; diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/enums/ResponseCode.java b/ad-platform-pojo/src/main/java/com/baiye/model/enums/ResponseCode.java index ac2e24cb..d0547194 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/enums/ResponseCode.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/enums/ResponseCode.java @@ -21,27 +21,27 @@ public enum ResponseCode { /** * 充值成功 */ - RECHARGE_SUCCESS("1020","充值成功"), + RECHARGE_SUCCESS("1020", "充值成功"), /** * 手机号码不正确 */ - PHONE_NUMBER_IS_INCORRECT("1022","手机号码不正确"), + PHONE_NUMBER_IS_INCORRECT("1022", "手机号码不正确"), /** * 验证码错误 */ - VERIFICATION_CODE_PARAMETER_ERROR("1023","验证码错误"), + VERIFICATION_CODE_PARAMETER_ERROR("1023", "验证码错误"), /** * 验证码不存在或已过期 */ - VERIFICATION_NOT_EXIST_HAS_EXPIRED("1024","验证码不存在或已过期"), + VERIFICATION_NOT_EXIST_HAS_EXPIRED("1024", "验证码不存在或已过期"), /** * 读取文件失败 */ - READ_FILE_ERROR("1021","读取文件失败"), + READ_FILE_ERROR("1021", "读取文件失败"), /** * 参数错误 */ @@ -65,17 +65,17 @@ public enum ResponseCode { /** * 支付宝支付失败 */ - ALI_PAY_ERROR("1016","支付宝支付失败"), + ALI_PAY_ERROR("1016", "支付宝支付失败"), /** * 支付宝支付回调失败 */ - CALLBACK_FAILED("1017","支付宝支付回调失败"), + CALLBACK_FAILED("1017", "支付宝支付回调失败"), /** * 账号已过期 */ - ACCOUNT_EXPIRED("1020","账号已过期,无法激活"), + ACCOUNT_EXPIRED("1020", "账号已过期,无法激活"), /** * 呼叫失败 */ @@ -104,31 +104,26 @@ public enum ResponseCode { WRONG_USER_NAME_PASSWORD("1016", "用户名或密码不正确"), /** - * * 账户余额不足 */ INSUFFICIENT_ACCOUNT_BALANCE("1019", "账户余额不足"), /** - * * 连接成功 */ CONNECTION_SUCCEEDED("1027", "连接成功"), /** - * * 获取二维码失败 */ FAILED_GET_QR_CODE("1028", "获取二维码失败"), /** - * * 获取模板失败 */ FAILED_GET_TEMPLATE("1029", "获取模板失败,请先配置发送模板"), /** - * * 发送消息至少配置一条 */ TEMPLATE_CHANGE_ERROR("1031", "发送消息至少配置一条!"), @@ -136,7 +131,7 @@ public enum ResponseCode { /** * 添加好友失败 */ - FAILED_ADD_FRIEND("1032","添加好友失败!"), + FAILED_ADD_FRIEND("1032", "添加好友失败!"), /** * 当前账户未登录或不在线 @@ -146,17 +141,17 @@ public enum ResponseCode { /** * 修改套餐失败 */ - UPDATE_COMBO_FRIEND("1033","修改套餐失败!"), + UPDATE_COMBO_FRIEND("1033", "修改套餐失败!"), /** * 发送邮件失败 */ - SEND_MAIL_FRIEND("1034","发送邮件失败!"), + SEND_MAIL_FRIEND("1034", "发送邮件失败!"), /** * 发送邮件失败 */ - SEND_MAIL_NUM_FRIEND("1035","发送数量不足100!"), + SEND_MAIL_NUM_FRIEND("1035", "发送数量不足100!"), /** * 用户被禁11005用 @@ -197,7 +192,16 @@ public enum ResponseCode { UPDATE_USER_ERROR("11012", "修改用户信息失败"), /** - * + * 发送邮件失败 + */ + SEND_MAIL_MAX_NUM_FRIEND("1036", "发送数量超出最大范围!"), + + /** + * 该批次号已经存在 + */ + BATCH_NUMBER_ALREADY_EXISTS("1037", "该批次号已经存在!"), + + /** * 非超级管理员不能修改数据 */ NON_SUPER_ADMINISTRATORS_CANNOT_MODIFY_DATA("1018", "非管理员不能修改数据"); diff --git a/ad-platform-services/ad-platform-service/src/main/resources/application-prod.yml b/ad-platform-services/ad-platform-service/src/main/resources/application-prod.yml index d02388c1..cb692f40 100644 --- a/ad-platform-services/ad-platform-service/src/main/resources/application-prod.yml +++ b/ad-platform-services/ad-platform-service/src/main/resources/application-prod.yml @@ -3,5 +3,5 @@ spring: cloud: nacos: discovery: - server-addr: ${NACOS_HOST:172.16.190.245}:${NACOS_PORT:8848} + server-addr: ${NACOS_HOST:127.0.0.1}:${NACOS_PORT:8848} diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/config/properties/DeliveryProperties.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/config/properties/DeliveryProperties.java index d7ef2498..5d4a4302 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/config/properties/DeliveryProperties.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/config/properties/DeliveryProperties.java @@ -26,6 +26,9 @@ public class DeliveryProperties { @ApiModelProperty("emailAddress") private String emailAddress; + @ApiModelProperty("兑换密码") + private String exchangePassword; + @ApiModelProperty("emailPassword") private String emailPassword; diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/DeliveryRecordRepository.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/DeliveryRecordRepository.java index 4f9f354f..90492ddb 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/DeliveryRecordRepository.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/DeliveryRecordRepository.java @@ -24,11 +24,13 @@ public interface DeliveryRecordRepository extends JpaRepository DefaultNumberConstants.ZERO_NUMBER; + public Boolean updateStatusByTaskName(Integer num, Integer decryptSize, String taskName) { + return deliveryRecordRepository.updateStatusAndDecryptNum + (num, decryptSize, taskName) > DefaultNumberConstants.ZERO_NUMBER; } } 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 cbe410c9..7353bfea 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 @@ -11,24 +11,26 @@ 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.util.ObjectUtil; +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONUtil; import com.baiye.config.properties.DeliveryProperties; import com.baiye.constant.DefaultNumberConstants; -import com.baiye.constant.SecurityConstants; import com.baiye.exception.BadRequestException; import com.baiye.feign.DownRecordClient; import com.baiye.feign.TaskClient; +import com.baiye.http.DmpResponse; +import com.baiye.http.ResponseCode; +import com.baiye.http.DmpDataDTO; import com.baiye.module.dao.ClueTalkRepository; import com.baiye.module.entity.DeliveryRecord; import com.baiye.module.entity.Task; import com.baiye.module.service.ClueService; import com.baiye.module.service.DeliveryRecordService; import com.baiye.module.service.dto.SecretResponseBean; -import com.baiye.util.CompressUtil; -import com.baiye.util.DecryptPnoUtil; -import com.baiye.util.MailUtil; -import com.baiye.util.RedisUtils; +import com.baiye.util.*; import com.google.common.base.Joiner; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.google.common.collect.Sets; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; @@ -40,13 +42,9 @@ import org.springframework.transaction.annotation.Transactional; import javax.mail.Flags; import javax.mail.Message; -import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; import java.io.File; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.concurrent.TimeUnit; /** @@ -114,7 +112,8 @@ public class MailSourceTask { CompressUtil.unzipFiles(deliveryProperties.getFileUrl(), path, deliveryProperties.getZipPassword()); if (ObjectUtil.isNotNull(byTaskName.getType())) { - if (byTaskName.getType() == DefaultNumberConstants.ONE_NUMBER) { + if (byTaskName.getType() == DefaultNumberConstants.ONE_NUMBER + || byTaskName.getType() == DefaultNumberConstants.THREE_NUMBER) { File file = new File(unzipPath); File parseFile = Objects.requireNonNull (file.listFiles())[DefaultNumberConstants.ZERO_NUMBER]; @@ -143,31 +142,53 @@ public class MailSourceTask { } } } - // 修改为接收参数 if (CollUtil.isNotEmpty(decryptList)) { log.info("=================== the decryptList size as {} =====================", decryptList.size()); - // 将imei转为线索 - clueService.saveClue(tagList, decryptList, byTaskName.getTaskId(), - byTaskName.getUserId(), DefaultNumberConstants.FOUR_NUMBER); - // 修改任务总条数 - Integer taskNum = clueTalkRepository.findTaskNum(taskId); - task.setId(taskId); - task.setTotalNumber(taskNum); - task.setIsDistribution(DefaultNumberConstants.ONE_NUMBER); - // 删除邮件 删除文件 - FileUtil.del(path); - FileUtil.del(unzipPath); - taskClient.updateTask(task); - deliveryRecordService.updateStatusByTaskName(DefaultNumberConstants.ONE_NUMBER, taskName); + if (byTaskName.getType() == DefaultNumberConstants.ONE_NUMBER) { + // 将imei转为线索 + clueService.saveClue(tagList, decryptList, byTaskName.getTaskId(), + byTaskName.getUserId(), DefaultNumberConstants.FOUR_NUMBER); + // 修改任务总条数 + Integer taskNum = clueTalkRepository.findTaskNum(taskId); + task.setId(taskId); + task.setTotalNumber(taskNum); + task.setIsDistribution(DefaultNumberConstants.ONE_NUMBER); + // 删除邮件 删除文件 + FileUtil.del(path); + FileUtil.del(unzipPath); + taskClient.updateTask(task); + deliveryRecordService.updateStatusByTaskName(DefaultNumberConstants.ONE_NUMBER,decryptList.size(), taskName); + } log.info("============== message parsing succeeded file path as {} unzip path as {} ===============", path, unzipPath); + if (byTaskName.getType() == DefaultNumberConstants.THREE_NUMBER) { + Map map = Maps.newHashMap(); + List arrayList = Lists.newArrayList(); + DmpResponse dmpResponse = new DmpResponse(); + for (int i = 0; i < decryptList.size(); i++) { + DmpDataDTO dto = new DmpDataDTO(); + String encrypt = AESUtils.encrypt + (decryptList.get(i), deliveryProperties.getExchangePassword()); + dto.setTag(tagList.get(i)); + dto.setDecryptInfo(encrypt); + arrayList.add(dto); + } + dmpResponse.setBatchNo(taskName); + dmpResponse.setDecryptList(arrayList); + map.put("status",DefaultNumberConstants.TWO_HUNDRED); + map.put("msg", ResponseCode.SUCCESS.getDesc()); + map.put("data",dmpResponse); + HttpUtil.post("", JSONUtil.toJsonStr(map)); + deliveryRecordService.updateStatusByTaskName(DefaultNumberConstants.ONE_NUMBER, decryptList.size(), taskName); + } } } if (byTaskName.getType() == DefaultNumberConstants.TWO_NUMBER) { log.info("========================= the path as {} =========================", path); String filePath = path.substring(path.lastIndexOf(StrPool.SLASH) + DefaultNumberConstants.ONE_NUMBER); - deliveryRecordService.updateStatusByTaskName(DefaultNumberConstants.ONE_NUMBER, taskName); + deliveryRecordService.updateStatusByTaskName(DefaultNumberConstants.ONE_NUMBER, decryptList.size(), taskName); downRecordClient.updatePath(deliveryProperties.getDmpDownPath().concat(filePath), byTaskName.getId()); } + } } } diff --git a/ad-platform-services/ad-platform-source/src/main/resources/application-prod.yml b/ad-platform-services/ad-platform-source/src/main/resources/application-prod.yml index 6148659f..6aa13052 100644 --- a/ad-platform-services/ad-platform-source/src/main/resources/application-prod.yml +++ b/ad-platform-services/ad-platform-source/src/main/resources/application-prod.yml @@ -3,7 +3,7 @@ spring: cloud: nacos: discovery: - server-addr: ${NACOS_HOST:172.16.190.245}:${NACOS_PORT:8848} + server-addr: ${NACOS_HOST:127.0.0.1}:${NACOS_PORT:8848} redis: database: 2 @@ -14,7 +14,7 @@ spring: druid: db-type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver - url: jdbc:mysql://172.16.190.245:3306/ad_platform?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull + url: jdbc:mysql://127.0.0.1:3306/ad_platform?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull username: root password: baiye@RDS2022 # 初始连接数 @@ -81,6 +81,7 @@ save: platform: zipPassword: DB2022hjk213v1... + exchangePassword: DA2023xlb213v1. fileUrl: /home/eladmin/mail emailAddress: ensoze@outlook.com emailPassword: baiye2022 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 c2c23282..e36bf95e 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 @@ -81,6 +81,7 @@ save: platform: zipPassword: DB2022hjk213v1... + exchangePassword: DA2023xlb213v1. fileUrl: /home/eladmin/mail emailAddress: lambda0821@outlook.com emailPassword: baiye123456789