SuccessfulTask.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.picc.grab.task;
  2. import cn.hutool.core.date.DateUtil;
  3. import cn.hutool.http.HttpRequest;
  4. import cn.hutool.json.JSONUtil;
  5. import com.picc.grab.crawl.*;
  6. import com.picc.grab.entity.common.vo.ResultVO;
  7. import com.picc.grab.mapper.ZbwtMapper;
  8. import com.picc.grab.service.ICarinfoService;
  9. import com.picc.grab.service.IPiccgrabaccountService;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.apache.commons.collections.CollectionUtils;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.scheduling.annotation.EnableScheduling;
  15. import org.springframework.scheduling.annotation.Scheduled;
  16. import org.springframework.stereotype.Component;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RequestMethod;
  20. import org.springframework.web.bind.annotation.RestController;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.Objects;
  25. import java.util.function.Function;
  26. import java.util.stream.Collectors;
  27. /**
  28. * 爬取中标价
  29. * @author adu
  30. * @date 2022/8/1.
  31. */
  32. @Slf4j
  33. @Component
  34. @EnableScheduling
  35. public class SuccessfulTask {
  36. @Autowired
  37. private IPiccgrabaccountService piccgrabaccountService;
  38. @Autowired
  39. private ZbwtMapper zbwtMapper;
  40. private static final String OFFER_PLATFORM_LIST_URL = "https://baojia.epicc.com.cn/api/app/bbp/info/offerPlatformList";
  41. private static final String BBP_DETAIL_LIST_URL = "https://baojia.epicc.com.cn/api/app/bbp/info/BbpDetailList";
  42. /**
  43. * 同步信息
  44. * 每十分钟同步一次
  45. */
  46. @Transactional
  47. @Scheduled(cron = "0 */10 * * * ?")
  48. public void syncInfo() throws Exception {
  49. //入参
  50. OfferPlatFromBody body = new OfferPlatFromBody();
  51. body.setAuctionStatus("02");
  52. body.setSelectContionsType("02");
  53. body.setStartTime(DateUtil.format(cn.hutool.core.date.DateUtil.lastMonth(), "yyyy-MM-dd"));
  54. body.setEndTime(DateUtil.format(cn.hutool.core.date.DateUtil.tomorrow(), "yyyy-MM-dd"));
  55. List<String> tokens = piccgrabaccountService.findTokenByLogIn();
  56. if (CollectionUtils.isNotEmpty(tokens)) {
  57. for (String token : tokens) {
  58. // 获取报价完成列表的车辆
  59. OfferPlatformBean platFromBean = getPlatFromBean(token, body);
  60. for (OfferPlatformBean.BbpAuctionSelectVo car : platFromBean.getData().getBbpAuctionSelectVoList()) {
  61. //查询车辆详情
  62. try {
  63. BbpDetailBean detailBean = getBbpDetail(token, new BbpDetailBody(car.getId()));
  64. if (!Objects.isNull(detailBean)) {
  65. String zbgzstatus = "3";
  66. if (StringUtils.isNotBlank(detailBean.getData().getBbpWonBidVo().getBidCompanyName())
  67. && detailBean.getData().getBbpWonBidVo().getBidCompanyName().contains("湖北同凯拍卖有限公司")){
  68. zbgzstatus = "4";
  69. }
  70. List<String> carids = piccgrabaccountService.getCarIds(car.getCarNo());
  71. //修改车辆中标信息
  72. for (String carid : carids) {
  73. zbwtMapper.updateZbwt(zbgzstatus,carid
  74. ,detailBean.getData().getBbpWonBidVo().getBidCompanyName()
  75. ,detailBean.getData().getBbpWonBidVo().getCreateTime()
  76. ,detailBean.getData().getBbpWonBidVo().getBidPrice());
  77. log.info("定时任务--同步车辆中标信息,车辆id:"+carid);
  78. }
  79. }
  80. }catch (Exception e){
  81. continue;
  82. }
  83. }
  84. }
  85. }
  86. }
  87. /**
  88. * 调用人保 获取报价完成列表的车辆
  89. * @param token
  90. * @param body
  91. * @return
  92. * @throws Exception
  93. */
  94. private OfferPlatformBean getPlatFromBean(String token, OfferPlatFromBody body) throws Exception {
  95. String result = HttpRequest.post(OFFER_PLATFORM_LIST_URL)
  96. .header("token", token).body(JSONUtil.parseObj(body, false, true).toString()).timeout(20000).execute().body();
  97. OfferPlatformBean bean = JSONUtil.toBean(result, OfferPlatformBean.class);
  98. if (!"200".equals(bean.getCode())) {
  99. log.error("{},token:{}", bean.getMsg(), token);
  100. throw new Exception(bean.getMsg());
  101. }
  102. return bean;
  103. }
  104. /**
  105. * 调用人保 获取车辆详情
  106. * @param token
  107. * @param bbpDetailBody
  108. * @return
  109. * @throws Exception
  110. */
  111. private BbpDetailBean getBbpDetail(String token, BbpDetailBody bbpDetailBody) throws Exception {
  112. String result = HttpRequest.post(BBP_DETAIL_LIST_URL)
  113. .header("token", token).body(JSONUtil.parseObj(bbpDetailBody, false, true).toString()).timeout(20000).execute().body();
  114. BbpDetailBean detailBean = JSONUtil.toBean(result, BbpDetailBean.class);
  115. if (!"200".equals(detailBean.getCode())) {
  116. log.error(bbpDetailBody.getId() + "获取详情失败:" + detailBean.getMsg());
  117. if ("101".equals(detailBean.getCode())) {
  118. throw new Exception(detailBean.getMsg());
  119. }
  120. }
  121. return detailBean;
  122. }
  123. }