Commit 5d219abb by zwb

新增公司企业信息查询

parent 1e220855
...@@ -150,6 +150,14 @@ ...@@ -150,6 +150,14 @@
<artifactId>langchain4j-open-ai</artifactId> <artifactId>langchain4j-open-ai</artifactId>
<version>0.29.1</version> <version>0.29.1</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>
</dependencies> </dependencies>
......
package org.dromara.common.core.config;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.apache.hc.core5.util.Timeout;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.*;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
/**
* RestTemplate
* @author jiangxiaoge
*/
@Configuration
public class RestTemplateConfig {
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate(httpRequestFactory());
configureMessageConverters(restTemplate);
return restTemplate;
}
// 创建一个不带服务发现的 RestTemplate
@Bean
public RestTemplate nonLoadBalancedRestTemplate() {
RestTemplate restTemplate = new RestTemplate(httpRequestFactory());
configureMessageConverters(restTemplate);
return restTemplate;
}
private void configureMessageConverters(RestTemplate restTemplate) {
// 确保有完整的消息转换器列表
List<HttpMessageConverter<?>> converters = new ArrayList<>();
// 添加字符串转换器
StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
converters.add(stringConverter);
// 添加JSON转换器
converters.add(new MappingJackson2HttpMessageConverter());
restTemplate.setMessageConverters(converters);
}
@Bean
public HttpComponentsClientHttpRequestFactory httpRequestFactory() {
// 使用自定义 HttpClient
CloseableHttpClient httpClient = httpClient();
// 创建工厂并绑定 HttpClient
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
// 使用 Duration 设置超时参数(Spring 6.0+ 推荐方式)
factory.setConnectTimeout(15000); // 连接超时 15秒
//factory.setReadTimeout(Duration.ofSeconds(180)); // 读取超时 180秒
factory.setConnectionRequestTimeout(15000); // 连接请求超时 15秒
return factory;
}
@Bean
public CloseableHttpClient httpClient() {
// 配置连接池
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(500); // 最大连接数
connectionManager.setDefaultMaxPerRoute(50); // 每个路由的最大连接数
// 配置超时
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(Timeout.ofSeconds(15)) // 连接超时
.setResponseTimeout(Timeout.ofSeconds(180)) // 响应超时
.setConnectionRequestTimeout(Timeout.ofSeconds(15)) // 连接请求超时
.build();
// 创建 HttpClient,并绑定连接池和超时配置
return HttpClients.custom()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.build();
}
@Bean(name = "balancedRestTemplate")
public RestTemplate balancedRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
// 文本
converters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8));
// JSON
converters.add(new MappingJackson2HttpMessageConverter());
// multipart/form-data 必备
FormHttpMessageConverter formConverter = new FormHttpMessageConverter();
formConverter.setCharset(StandardCharsets.UTF_8);
converters.add(formConverter);
converters.add(new ResourceHttpMessageConverter()); // 处理文件资源
// 文件下载
converters.add(new ByteArrayHttpMessageConverter());
restTemplate.setMessageConverters(converters);
return restTemplate;
}
}
\ No newline at end of file
package org.dromara.common.core.constant;
/**
* @author jiangxiaoge
* @description 奥德塔常量
* @data 2025/2/24
**/
public class AdtConstants {
/**登录*/
public final static String GET_TOKEN_URL = "http://47.95.12.119/services/auth/app/enuser/login/companylogin";
/**精确查询*/
public final static String GET_COMPANY_INFO_URL = "http://47.95.12.119/openapi/company/company/V4/selectCompanyBaseInfoByName";
/**模糊查询*/
public final static String GET_COMPANY_LIST_URL = "http://47.95.12.119/openapi/company/company/V1/searchCompanyName";
/**信用报告*/
public final static String GET_COMPANY_RISK_URL = "http://47.95.12.119/openapi/bkty/getRiskReport";
/**对外投资*/
public final static String GET_COMPANY_INVEST_URL = "http://47.95.12.119/openapi/chinaEnergy/company/selectOutInvestments";
public final static String HEADERS_AUTHORIZATION = "Authorization";
}
\ No newline at end of file
package com.bkty.system.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author jiangxiaoge
* @description atd 配置信息
* @data 2025/2/24
**/
@Data
@ConfigurationProperties(prefix = "adt")
public class AtdProperties {
private String username;
private String password;
}
\ No newline at end of file
...@@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author Zhang Wenbiao * @author Zhang Wenbiao
...@@ -128,6 +129,18 @@ public class JobRecommendController { ...@@ -128,6 +129,18 @@ public class JobRecommendController {
} }
/** /**
* 查询企业信息
*
* @param companyName
* @return
*/
@GetMapping("/query-company-info")
public R<Map<String, Object>> queryCompanyInfo(@RequestParam(value = "companyName") String companyName) {
Map<String, Object> map = jobRecommendService.queryCompanyInfo(companyName);
return new R<>(map);
}
/**
* 查询历史分析数据 * 查询历史分析数据
* @param dateTime * @param dateTime
* @return * @return
......
...@@ -22,6 +22,8 @@ public class PositionQueryDto { ...@@ -22,6 +22,8 @@ public class PositionQueryDto {
private String cityCode; private String cityCode;
private String companyName;
private List<String> cityCodes; private List<String> cityCodes;
} }
...@@ -4,6 +4,7 @@ import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; ...@@ -4,6 +4,7 @@ import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup; import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
...@@ -17,6 +18,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; ...@@ -17,6 +18,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling @EnableScheduling
@EnableCaching @EnableCaching
@SpringBootApplication @SpringBootApplication
@ConfigurationPropertiesScan
public class employmentBusinessPCSystemApplication { public class employmentBusinessPCSystemApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication application = new SpringApplication(employmentBusinessPCSystemApplication.class); SpringApplication application = new SpringApplication(employmentBusinessPCSystemApplication.class);
......
...@@ -7,6 +7,7 @@ import com.bkty.system.domain.vo.PositionRecommendListVo; ...@@ -7,6 +7,7 @@ import com.bkty.system.domain.vo.PositionRecommendListVo;
import com.bkty.system.init.Level1Group; import com.bkty.system.init.Level1Group;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 岗位智推 * 岗位智推
...@@ -47,4 +48,12 @@ public interface JobRecommendService { ...@@ -47,4 +48,12 @@ public interface JobRecommendService {
* @return * @return
*/ */
List<AnalysisListVo> queryAnalysisList(String dateTime); List<AnalysisListVo> queryAnalysisList(String dateTime);
/**
* 查询企业信息
* @param companyName
* @return
*/
Map<String, Object> queryCompanyInfo(String companyName);
} }
package com.bkty.system.service.jobRecommend.impl; package com.bkty.system.service.jobRecommend.impl;
import com.bkty.system.config.AtdProperties;
import com.bkty.system.domain.vo.AnalysisListVo; import com.bkty.system.domain.vo.AnalysisListVo;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.Date; import java.util.*;
import com.bkty.system.domain.entity.FunctionPositionPortraitV2; import com.bkty.system.domain.entity.FunctionPositionPortraitV2;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
...@@ -33,13 +34,18 @@ import com.bkty.system.service.jobRecommend.RecommendPositionService; ...@@ -33,13 +34,18 @@ import com.bkty.system.service.jobRecommend.RecommendPositionService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.dromara.common.core.constant.AdtConstants;
import org.dromara.common.core.domain.R; import org.dromara.common.core.domain.R;
import org.dromara.common.core.enums.AnalysisCareerEnum;
import org.dromara.common.core.exception.JxgException;
import org.dromara.common.core.exception.WarnException; import org.dromara.common.core.exception.WarnException;
import org.dromara.common.core.utils.DateTimeWrapper; import org.dromara.common.core.utils.DateTimeWrapper;
import org.dromara.common.core.utils.EconomicTypeUtil;
import org.dromara.common.core.utils.SecurityUtils; import org.dromara.common.core.utils.SecurityUtils;
import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.satoken.utils.LoginHelper;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.client.elc.NativeQuery; import org.springframework.data.elasticsearch.client.elc.NativeQuery;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
...@@ -48,12 +54,10 @@ import org.springframework.data.elasticsearch.core.SearchHits; ...@@ -48,12 +54,10 @@ import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.SourceFilter; import org.springframework.data.elasticsearch.core.query.SourceFilter;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
...@@ -82,6 +86,10 @@ public class JobRecommendServiceImpl implements JobRecommendService { ...@@ -82,6 +86,10 @@ public class JobRecommendServiceImpl implements JobRecommendService {
private static final String RECOMMEND_ITEM_KEY = "recommend:item:%d"; private static final String RECOMMEND_ITEM_KEY = "recommend:item:%d";
@Autowired
@Qualifier("nonLoadBalancedRestTemplate")
private RestTemplate restTemplate;
@Override @Override
public List<Level1Group> getLevel1Groups(String level1) { public List<Level1Group> getLevel1Groups(String level1) {
...@@ -301,4 +309,77 @@ public class JobRecommendServiceImpl implements JobRecommendService { ...@@ -301,4 +309,77 @@ public class JobRecommendServiceImpl implements JobRecommendService {
} }
return listVos; return listVos;
} }
@Override
public Map<String, Object> queryCompanyInfo(String companyName) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set(HttpHeaders.AUTHORIZATION, getAtdToken());
// 发送 POST 请求并获取响应
ResponseEntity<String> response = restTemplate.exchange(AdtConstants.GET_COMPANY_INFO_URL,
HttpMethod.POST, new HttpEntity<>(Map.of("companyName", companyName), headers),
String.class);
if (response.getStatusCode().equals(HttpStatus.OK)) {
try {
com.alibaba.fastjson2.JSONObject jsonObject = JSON.parseObject(response.getBody());
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
com.alibaba.fastjson2.JSONObject data = jsonObject.getJSONObject("data");
if (data != null) {
Map<String, Object> resultMap = new HashMap<>();
com.alibaba.fastjson2.JSONObject companyAllVoModel = data.getJSONObject("companyAllVoModel");
resultMap.put("companyName", companyAllVoModel.getString("companyName"));
resultMap.put("enterpriseNature", companyAllVoModel.getString("enterpriseNature"));
if (StringUtils.isNotBlank(Objects.toString(companyAllVoModel.getString("enterpriseNature"), ""))) {
Integer enterpriseNature = EconomicTypeUtil.getEconomicType(companyAllVoModel.getString("enterpriseNature"));
if (enterpriseNature != null) {
resultMap.put("enterpriseNature", AnalysisCareerEnum.CompanyNature.getNameByCode(enterpriseNature));
}
}
resultMap.put("companyDetailInfo", companyAllVoModel.getString("companyDetailInfo"));
resultMap.put("regCapital", companyAllVoModel.getString("regCapital"));
resultMap.put("estiblishTime", companyAllVoModel.getString("estiblishTime"));
resultMap.put("categoryStrBig", companyAllVoModel.getString("categoryStrBig"));
resultMap.put("dividingName", companyAllVoModel.getString("dividingName"));
resultMap.put("insuredNum", companyAllVoModel.getString("insuredNum"));
resultMap.put("legalPersonName", companyAllVoModel.getString("legalPersonName"));
resultMap.put("companyOrgType", companyAllVoModel.getString("companyOrgType"));
resultMap.put("regStatus", companyAllVoModel.getString("regStatus"));
resultMap.put("peoplesType", companyAllVoModel.getString("peoplesType"));
resultMap.put("newCategoryStrClass", companyAllVoModel.getString("newCategoryStrClass"));
return resultMap;
}
return Map.of();
} else {
log.error("获取企业信息失败:{}", response.getBody());
}
} catch (Exception e) {
log.error("获取企业信息失败", e);
}
}
return Map.of();
}
private final AtdProperties adtProperties;
public String getAtdToken() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// 发送 POST 请求并获取响应
ResponseEntity<String> response = restTemplate.exchange(AdtConstants.GET_TOKEN_URL, HttpMethod.POST,
new HttpEntity<>(Map.of("userName", adtProperties.getUsername(), "password", adtProperties.getPassword()), headers),
String.class);
if (response.getStatusCode().equals(HttpStatus.OK)) {
try {
com.alibaba.fastjson2.JSONObject jsonObject = JSON.parseObject(response.getBody());
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
return jsonObject.getString("token");
} else {
log.error("获取ATD token失败:{}", response.getBody());
}
} catch (Exception e) {
log.error("获取ATD token失败", e);
}
}
throw new JxgException("获取ATD token失败");
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment