From b616034e0daaa86d971161369ec3b7d8379932dc Mon Sep 17 00:00:00 2001 From: bynt Date: Fri, 19 Nov 2021 16:17:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 2 +- .../src/test/java/com/hchbox/SlaverTest.java | 16 ++--- .../master/SellerAccountRepository.java | 19 ++++++ .../java/com/hchbox/task/AccountTask.java | 58 +++++++++++-------- .../main/java/com/hchbox/task/SyncTask.java | 4 +- .../model/entity/BaseSellerAccount.java | 2 +- 6 files changed, 65 insertions(+), 36 deletions(-) diff --git a/service/trade-service-source/trade-service-source-core/src/main/resources/application.yml b/service/trade-service-source/trade-service-source-core/src/main/resources/application.yml index 05b888b..768eba6 100644 --- a/service/trade-service-source/trade-service-source-core/src/main/resources/application.yml +++ b/service/trade-service-source/trade-service-source-core/src/main/resources/application.yml @@ -3,7 +3,7 @@ server: spring: profiles: - active: prod + active: dev servlet: multipart: max-file-size: 200MB #单个文件上传大小 diff --git a/service/trade-service-source/trade-service-source-core/src/test/java/com/hchbox/SlaverTest.java b/service/trade-service-source/trade-service-source-core/src/test/java/com/hchbox/SlaverTest.java index 729404d..26b8037 100644 --- a/service/trade-service-source/trade-service-source-core/src/test/java/com/hchbox/SlaverTest.java +++ b/service/trade-service-source/trade-service-source-core/src/test/java/com/hchbox/SlaverTest.java @@ -4,8 +4,10 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.json.JSONUtil; import com.google.common.collect.Lists; import com.hchbox.config.MiProperties; +import com.hchbox.constant.DefaultNumberConstants; import com.hchbox.constant.TaoBaoDataMethodConstants; import com.hchbox.entity.master.Blacklist; +import com.hchbox.entity.master.SellerAccount; import com.hchbox.entity.master.User; import com.hchbox.entity.slaver.JdpTrade; import com.hchbox.repository.master.BlacklistRepository; @@ -79,11 +81,8 @@ public class SlaverTest { private TaoBaoMessageService taoBaoMessageService; - @Resource - private BlacklistRepository blacklistRepository; - @Resource - private TaoBaoSaleService taoBaoSaleService; + @Resource private MiProperties miProperties; @@ -121,9 +120,10 @@ public class SlaverTest { @Test public void getAccount() { - sellerAccountService.getAccountByNick("usw电器旗舰店"); - cacheManagerUtil.evictCache("sellerAccountCache","usw电器旗舰店"); - sellerAccountService.getAccountByNick("usw电器旗舰店"); + List allByParentId = sellerAccountRepository.findAllByParentId(2L); + for (SellerAccount sellerAccount : allByParentId) { + + } } @@ -150,7 +150,7 @@ public class SlaverTest { @Test public void findUserList() { - taoBaoRdsPushService.deletePushUser("usw电器旗舰店"); + taoBaoRdsPushService.turnOnPushService("50008400241xjDTcDePNGtjMCsvtS9byhUEIpESqjccFrgkxXi6Fe16809637nng5v",30L); } @Test diff --git a/service/trade-service-source/trade-service-source-dao/src/main/java/com/hchbox/repository/master/SellerAccountRepository.java b/service/trade-service-source/trade-service-source-dao/src/main/java/com/hchbox/repository/master/SellerAccountRepository.java index 677c61f..50b557a 100644 --- a/service/trade-service-source/trade-service-source-dao/src/main/java/com/hchbox/repository/master/SellerAccountRepository.java +++ b/service/trade-service-source/trade-service-source-dao/src/main/java/com/hchbox/repository/master/SellerAccountRepository.java @@ -100,4 +100,23 @@ public interface SellerAccountRepository extends JpaRepository queryChildrenSellerAccounts(Long parentId); + + + /** + * 时间查询 + * @param date + * @param zeroNumber + * @return + */ + @Query("from SellerAccount s where s.freeSyncEndTime < ?1 and s.parentId = ?2") + List queryUnexpiredAccounts(Date date, Long zeroNumber); + + /** + * 修改账号状态 + * @param twoNumber + * @param id + */ + @Modifying + @Query(value = "update SellerAccount set status = ?1 where id = ?2") + void updateSellerStatusById(int twoNumber, Long id); } diff --git a/service/trade-service-source/trade-service-source-taobao/src/main/java/com/hchbox/task/AccountTask.java b/service/trade-service-source/trade-service-source-taobao/src/main/java/com/hchbox/task/AccountTask.java index 1da61bb..8a33ee5 100644 --- a/service/trade-service-source/trade-service-source-taobao/src/main/java/com/hchbox/task/AccountTask.java +++ b/service/trade-service-source/trade-service-source-taobao/src/main/java/com/hchbox/task/AccountTask.java @@ -7,11 +7,14 @@ import com.hchbox.entity.master.SellerAccount; import com.hchbox.repository.master.SellerAccountRepository; import com.hchbox.service.SellerAccountService; import com.hchbox.service.TaoBaoOrderingService; +import com.hchbox.service.TaoBaoRdsPushService; import com.taobao.api.domain.ArticleSub; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.annotation.After; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; @@ -26,40 +29,45 @@ import java.util.Optional; @RequiredArgsConstructor public class AccountTask { - private final SellerAccountService sellerAccountService; - private final TaoBaoOrderingService taoBaoOrderingService; private final SellerAccountRepository sellerAccountRepository; -// @Scheduled(cron = "0 0 1 * * ?") -// public void syncAccount() { -// List sellerAccounts = sellerAccountService.queryAccountByParentId(); -// sellerAccounts.forEach(account -> { -// List orderTimeByUserName = taoBaoOrderingService.getOrderTimeByUserName(account.getNickname()); -// Optional max = orderTimeByUserName.stream().map(ArticleSub::getDeadline).max(Date::compareTo); -// // TODO 可做判断 -// max.ifPresent(account::setExpirationTime); -// Boolean result = sellerAccountService.updateAccountByExpirationTime(account); -// log.info("==================== update account id as {}, result as {} ====================", account.getId(), result); -// }); -// } + private final SellerAccountService sellerAccountService; + + private final TaoBaoRdsPushService taoBaoRdsPushService; + /** * 定时检测授权时间 */ - @Scheduled(cron = "0 0 1 * * ?") - public void expiredChildrenAccount() { - List sellerAccounts = sellerAccountRepository.queryChildrenSellerAccounts((long) DefaultNumberConstants.ZERO_NUMBER); - if (CollUtil.isNotEmpty(sellerAccounts)) { - for (SellerAccount info : sellerAccounts) { - Date time = info.getAuthorizeEndTime(); - int num = DateUtil.compare(DateUtil.date(), time); - if (num > 0) { - info.setStatus(DefaultNumberConstants.TWO_NUMBER); - long id = sellerAccountRepository.save(info).getId(); - log.info("=========update childrenAccount id as {}", id); + @Scheduled(cron = " 0 1 0 * * ?") + // @Scheduled(cron = "0 0/1 * * * *") + @Transactional(rollbackFor = Exception.class) + public void deleteAccountAfterExpirationTime() { + List sellerAccounts = + sellerAccountRepository.findAllByParentId((long) DefaultNumberConstants.ZERO_NUMBER); + for (SellerAccount account : sellerAccounts) { + List allByParentId = sellerAccountRepository.findAllByParentId(account.getId()); + boolean flag = Boolean.TRUE; + for (SellerAccount sellerAccount : allByParentId) { + Date endTime = sellerAccount.getAuthorizeEndTime(); + if (endTime != null) { + if (endTime.before(DateUtil.date())) { + sellerAccountRepository.updateSellerStatusById + (DefaultNumberConstants.TWO_NUMBER, sellerAccount.getId()); + continue; + } + flag = Boolean.FALSE; } } + if (flag) { + // 删除数据推送 + taoBaoRdsPushService.deletePushUser(account.getNickname()); + // 修改账号状态 + sellerAccountService.updateAccountStatusAndExpiration + (account.getId(), DefaultNumberConstants.MINUS_ONE_NUMBER, DateUtil.date()); + } } } + } diff --git a/service/trade-service-source/trade-service-source-taobao/src/main/java/com/hchbox/task/SyncTask.java b/service/trade-service-source/trade-service-source-taobao/src/main/java/com/hchbox/task/SyncTask.java index 0f115d7..a383b22 100644 --- a/service/trade-service-source/trade-service-source-taobao/src/main/java/com/hchbox/task/SyncTask.java +++ b/service/trade-service-source/trade-service-source-taobao/src/main/java/com/hchbox/task/SyncTask.java @@ -151,7 +151,9 @@ public class SyncTask { int totalAmount = messageCount + trades.size(); sellerAccountService.updateMessageCount(sellerAccount.getId(), totalAmount); // TODO 同步数据发送 - if (sellerAccount.getMassNum() != null && totalAmount > sellerAccount.getMassNum()) { + if (sellerAccount.getMassNum() != null + && sellerAccount.getMassNum() > DefaultNumberConstants.ZERO_NUMBER + && totalAmount > sellerAccount.getMassNum()) { log.info("======================== the massNum as {} trades size as {} ==================", sellerAccount.getMassNum(), trades.size()); // 删除数据推送 diff --git a/trade-common/src/main/java/com/hchbox/model/entity/BaseSellerAccount.java b/trade-common/src/main/java/com/hchbox/model/entity/BaseSellerAccount.java index c109ef7..c1f929d 100644 --- a/trade-common/src/main/java/com/hchbox/model/entity/BaseSellerAccount.java +++ b/trade-common/src/main/java/com/hchbox/model/entity/BaseSellerAccount.java @@ -40,7 +40,6 @@ public class BaseSellerAccount implements Serializable { @ApiModelProperty(value = "头像") private String avatar; - @Column(name = "level") @ApiModelProperty(value = "账号等级") private Integer level; @@ -126,6 +125,7 @@ public class BaseSellerAccount implements Serializable { @Column(name = "mass_num") @ApiModelProperty(value = "消息总条数") private Integer massNum; + @Column(name = "free_sync_end_time") @ApiModelProperty(value = "免费同步到期时间") private Date freeSyncEndTime;