WlnSyncTask.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package com.sd.wln.scheduled;
  2. import com.sd.wln.service.WlnOrderService;
  3. import com.sd.wln.service.WlnSkuService;
  4. import com.sd.wln.service.WlnStatementOfAccount;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.context.annotation.Profile;
  7. import org.springframework.scheduling.annotation.Scheduled;
  8. import org.springframework.stereotype.Component;
  9. /**
  10. * 同步万里牛数据(本地环境不执行同步逻辑)
  11. */
  12. @Profile({"test", "prod"})
  13. @Component
  14. public class WlnSyncTask {
  15. @Autowired
  16. private WlnSkuService wlnSkuService;
  17. @Autowired
  18. private WlnOrderService wlnOrderService;
  19. @Autowired
  20. private WlnStatementOfAccount wlnStatementOfAccount;
  21. /**
  22. * 每天凌晨1点同步一次sku信息
  23. */
  24. @Scheduled(cron = "0 0 1 * * ?")
  25. public void syncSku() {
  26. if (WlnSkuService.syncSkuLock.tryLock()) {
  27. try {
  28. wlnSkuService.syncSkuClassify();
  29. wlnSkuService.syncSku();
  30. } finally {
  31. WlnSkuService.syncSkuLock.unlock();
  32. }
  33. }
  34. }
  35. /**
  36. * 每分钟同步一次订单数据
  37. */
  38. @Scheduled(fixedDelay = 2 * 60 * 1000)
  39. private void syncOrder() {
  40. wlnOrderService.syncOrder();
  41. }
  42. /**
  43. * 生成对账单
  44. */
  45. @Scheduled(cron = "0 0 19-23 * * ?")
  46. private void createStatementOfAccount() {
  47. wlnStatementOfAccount.createStatementOfAccount();
  48. }
  49. }