RenheCodeTask.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.metro.job;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.metro.utils.HttpClientUtil;
  5. import lombok.extern.log4j.Log4j2;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.springframework.scheduling.annotation.EnableScheduling;
  9. import org.springframework.scheduling.annotation.Scheduled;
  10. import org.springframework.stereotype.Component;
  11. /**
  12. * @ClassName: RenheCodeTask
  13. * @Description: TODO
  14. * @Author: ZS
  15. * @CreateName: lws
  16. * @Date 2022/3/23 16:18
  17. * ...
  18. */
  19. @Component
  20. @EnableScheduling
  21. @Log4j2
  22. @Slf4j
  23. public class RenheCodeTask {
  24. @Scheduled(cron = "0/5 * * * * ?")
  25. public void boot(){
  26. long begin = System.currentTimeMillis();
  27. String params = "{\"idNumber\": \"410322199907309877\",\"token\":\"hh_token_51063b27-9fd8-420d-b7eb-e5600fe0dec9\"}";
  28. String result = HttpClientUtil.httpPostSetConfig("https://renhe.hz-hanghui.com/health-code/hh/getHealthCode", params);
  29. if (StringUtils.isEmpty(result)) {
  30. long timeValue = System.currentTimeMillis() - begin;
  31. log.error("调用仁和接口调用失败,总耗时: {} 毫秒",timeValue);
  32. return;
  33. }
  34. JSONObject jsonObject = JSON.parseObject(result);
  35. if (200==jsonObject.getInteger("code")) {
  36. long timeValue = System.currentTimeMillis() - begin;
  37. } else {
  38. long timeValue = System.currentTimeMillis() - begin;
  39. log.error("调用仁和失败!:返回结果为:{},总耗时:{} 毫秒", result,timeValue);
  40. }
  41. }
  42. }