PtlCrawlerApiServiceImpl.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.ydtech.modules.protocol.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.ydtech.exception.SystemException;
  5. import com.ydtech.modules.protocol.dao.PtlCrawlerApiMapper;
  6. import com.ydtech.modules.protocol.entity.constants.PtlCrawlerApiType;
  7. import com.ydtech.modules.protocol.entity.po.PtlCrawlerApi;
  8. import com.ydtech.modules.protocol.service.PtlCrawlerApiService;
  9. import com.ydtech.modules.protocol.utils.AssertionUtils;
  10. import org.springframework.stereotype.Service;
  11. import java.util.List;
  12. /**
  13. * @author wenks
  14. * @description 针对表【ptl_crawler_api(python对接接口)】的数据库操作Service实现
  15. * @createDate 2023-07-03 18:10:03
  16. */
  17. @Service
  18. public class PtlCrawlerApiServiceImpl extends ServiceImpl<PtlCrawlerApiMapper, PtlCrawlerApi>
  19. implements PtlCrawlerApiService {
  20. @Override
  21. public String getApiUrl(String agreementId, PtlCrawlerApiType ptlCrawlerApiType) {
  22. String apiUrl = baseMapper.getApiUrl(agreementId, String.valueOf(ptlCrawlerApiType.getCode()));
  23. AssertionUtils.isStringEmpty(apiUrl, "请求地址未配置");
  24. return apiUrl;
  25. }
  26. @Override
  27. public String getByTemplateId(String templateId, PtlCrawlerApiType ptlCrawlerApiType) {
  28. LambdaQueryWrapper<PtlCrawlerApi> w = new LambdaQueryWrapper<>();
  29. w.select(PtlCrawlerApi::getUrl)
  30. .eq(PtlCrawlerApi::getTemplateId, templateId)
  31. .eq(PtlCrawlerApi::getApiType, ptlCrawlerApiType.getCode());
  32. PtlCrawlerApi one = getOne(w);
  33. if(one == null){
  34. throw new SystemException("没有找到python Api 模版");
  35. }
  36. return one.getUrl();
  37. }
  38. public List<PtlCrawlerApi> getByTemplateIdList(String templateId) {
  39. LambdaQueryWrapper<PtlCrawlerApi> w = new LambdaQueryWrapper<>();
  40. w.eq(PtlCrawlerApi::getTemplateId, templateId).orderByAsc(PtlCrawlerApi::getApiType);
  41. return list(w);
  42. }
  43. }