定时任务修改状态

master
bynt 3 years ago
parent 6930519f8a
commit b616034e0d

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

@ -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<SellerAccount> 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

@ -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)
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.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<SellerAccount> sellerAccounts = sellerAccountService.queryAccountByParentId();
// 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);
// });
// }
private final SellerAccountService sellerAccountService;
private final TaoBaoRdsPushService taoBaoRdsPushService;
/**
*
*/
@Scheduled(cron = "0 0 1 * * ?")
public void expiredChildrenAccount() {
List<SellerAccount> 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<SellerAccount> sellerAccounts =
sellerAccountRepository.findAllByParentId((long) DefaultNumberConstants.ZERO_NUMBER);
for (SellerAccount account : sellerAccounts) {
List<SellerAccount> 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());
}
}
}
}

@ -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());
// 删除数据推送

@ -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;

Loading…
Cancel
Save