定时任务修改状态

master
bynt 3 years ago
parent 6930519f8a
commit b616034e0d

@ -3,7 +3,7 @@ server:
spring: spring:
profiles: profiles:
active: prod active: dev
servlet: servlet:
multipart: multipart:
max-file-size: 200MB #单个文件上传大小 max-file-size: 200MB #单个文件上传大小

@ -4,8 +4,10 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.hchbox.config.MiProperties; import com.hchbox.config.MiProperties;
import com.hchbox.constant.DefaultNumberConstants;
import com.hchbox.constant.TaoBaoDataMethodConstants; import com.hchbox.constant.TaoBaoDataMethodConstants;
import com.hchbox.entity.master.Blacklist; import com.hchbox.entity.master.Blacklist;
import com.hchbox.entity.master.SellerAccount;
import com.hchbox.entity.master.User; import com.hchbox.entity.master.User;
import com.hchbox.entity.slaver.JdpTrade; import com.hchbox.entity.slaver.JdpTrade;
import com.hchbox.repository.master.BlacklistRepository; import com.hchbox.repository.master.BlacklistRepository;
@ -79,11 +81,8 @@ public class SlaverTest {
private TaoBaoMessageService taoBaoMessageService; private TaoBaoMessageService taoBaoMessageService;
@Resource
private BlacklistRepository blacklistRepository;
@Resource
private TaoBaoSaleService taoBaoSaleService;
@Resource @Resource
private MiProperties miProperties; private MiProperties miProperties;
@ -121,9 +120,10 @@ public class SlaverTest {
@Test @Test
public void getAccount() { public void getAccount() {
sellerAccountService.getAccountByNick("usw电器旗舰店"); List<SellerAccount> allByParentId = sellerAccountRepository.findAllByParentId(2L);
cacheManagerUtil.evictCache("sellerAccountCache","usw电器旗舰店"); for (SellerAccount sellerAccount : allByParentId) {
sellerAccountService.getAccountByNick("usw电器旗舰店");
}
} }
@ -150,7 +150,7 @@ public class SlaverTest {
@Test @Test
public void findUserList() { public void findUserList() {
taoBaoRdsPushService.deletePushUser("usw电器旗舰店"); taoBaoRdsPushService.turnOnPushService("50008400241xjDTcDePNGtjMCsvtS9byhUEIpESqjccFrgkxXi6Fe16809637nng5v",30L);
} }
@Test @Test

@ -100,4 +100,23 @@ public interface SellerAccountRepository extends JpaRepository<SellerAccount, Lo
*/ */
@Query(value = "select * from seller_account as s where s.parent_id != ?1 ", nativeQuery = true) @Query(value = "select * from seller_account as s where s.parent_id != ?1 ", nativeQuery = true)
List<SellerAccount> queryChildrenSellerAccounts(Long parentId); List<SellerAccount> queryChildrenSellerAccounts(Long parentId);
/**
*
* @param date
* @param zeroNumber
* @return
*/
@Query("from SellerAccount s where s.freeSyncEndTime < ?1 and s.parentId = ?2")
List<SellerAccount> 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);
} }

@ -7,11 +7,14 @@ import com.hchbox.entity.master.SellerAccount;
import com.hchbox.repository.master.SellerAccountRepository; import com.hchbox.repository.master.SellerAccountRepository;
import com.hchbox.service.SellerAccountService; import com.hchbox.service.SellerAccountService;
import com.hchbox.service.TaoBaoOrderingService; import com.hchbox.service.TaoBaoOrderingService;
import com.hchbox.service.TaoBaoRdsPushService;
import com.taobao.api.domain.ArticleSub; import com.taobao.api.domain.ArticleSub;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.After;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -26,40 +29,45 @@ import java.util.Optional;
@RequiredArgsConstructor @RequiredArgsConstructor
public class AccountTask { public class AccountTask {
private final SellerAccountService sellerAccountService;
private final TaoBaoOrderingService taoBaoOrderingService;
private final SellerAccountRepository sellerAccountRepository; private final SellerAccountRepository sellerAccountRepository;
// @Scheduled(cron = "0 0 1 * * ?") private final SellerAccountService sellerAccountService;
// public void syncAccount() {
// List<SellerAccount> sellerAccounts = sellerAccountService.queryAccountByParentId(); private final TaoBaoRdsPushService taoBaoRdsPushService;
// sellerAccounts.forEach(account -> {
// List<ArticleSub> orderTimeByUserName = taoBaoOrderingService.getOrderTimeByUserName(account.getNickname());
// Optional<Date> 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);
// });
// }
/** /**
* *
*/ */
@Scheduled(cron = "0 0 1 * * ?") @Scheduled(cron = " 0 1 0 * * ?")
public void expiredChildrenAccount() { // @Scheduled(cron = "0 0/1 * * * *")
List<SellerAccount> sellerAccounts = sellerAccountRepository.queryChildrenSellerAccounts((long) DefaultNumberConstants.ZERO_NUMBER); @Transactional(rollbackFor = Exception.class)
if (CollUtil.isNotEmpty(sellerAccounts)) { public void deleteAccountAfterExpirationTime() {
for (SellerAccount info : sellerAccounts) { List<SellerAccount> sellerAccounts =
Date time = info.getAuthorizeEndTime(); sellerAccountRepository.findAllByParentId((long) DefaultNumberConstants.ZERO_NUMBER);
int num = DateUtil.compare(DateUtil.date(), time); for (SellerAccount account : sellerAccounts) {
if (num > 0) { List<SellerAccount> allByParentId = sellerAccountRepository.findAllByParentId(account.getId());
info.setStatus(DefaultNumberConstants.TWO_NUMBER); boolean flag = Boolean.TRUE;
long id = sellerAccountRepository.save(info).getId(); for (SellerAccount sellerAccount : allByParentId) {
log.info("=========update childrenAccount id as {}", id); 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());
}
} }
} }
} }

@ -151,7 +151,9 @@ public class SyncTask {
int totalAmount = messageCount + trades.size(); int totalAmount = messageCount + trades.size();
sellerAccountService.updateMessageCount(sellerAccount.getId(), totalAmount); sellerAccountService.updateMessageCount(sellerAccount.getId(), totalAmount);
// TODO 同步数据发送 // 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 {} ==================", log.info("======================== the massNum as {} trades size as {} ==================",
sellerAccount.getMassNum(), trades.size()); sellerAccount.getMassNum(), trades.size());
// 删除数据推送 // 删除数据推送

@ -40,7 +40,6 @@ public class BaseSellerAccount implements Serializable {
@ApiModelProperty(value = "头像") @ApiModelProperty(value = "头像")
private String avatar; private String avatar;
@Column(name = "level") @Column(name = "level")
@ApiModelProperty(value = "账号等级") @ApiModelProperty(value = "账号等级")
private Integer level; private Integer level;
@ -126,6 +125,7 @@ public class BaseSellerAccount implements Serializable {
@Column(name = "mass_num") @Column(name = "mass_num")
@ApiModelProperty(value = "消息总条数") @ApiModelProperty(value = "消息总条数")
private Integer massNum; private Integer massNum;
@Column(name = "free_sync_end_time") @Column(name = "free_sync_end_time")
@ApiModelProperty(value = "免费同步到期时间") @ApiModelProperty(value = "免费同步到期时间")
private Date freeSyncEndTime; private Date freeSyncEndTime;

Loading…
Cancel
Save