dms验证接口
This commit is contained in:
@@ -1,40 +1,40 @@
|
||||
package com.volvo.ai.analytic.center.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
public class ClickHouseConfig {
|
||||
|
||||
@Primary
|
||||
@Bean(name = "dataSource")
|
||||
@ConfigurationProperties(prefix="spring.datasource")
|
||||
public DataSource dataSource() {
|
||||
DataSource dataSource = DataSourceBuilder.create().build();
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@Bean(name = "clickHouseDataSource")
|
||||
@ConfigurationProperties(prefix="spring.clickhouse-ads-ai")
|
||||
public DataSource clickHouseDataSource(){
|
||||
DataSource dataSource = DataSourceBuilder.create().build();
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@Bean(name = "jdbcTemplate")
|
||||
public JdbcTemplate jdbcTemplate(@Qualifier("dataSource") DataSource dataSource) {
|
||||
return new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Bean(name = "clickhouseJdbcTemplate")
|
||||
public JdbcTemplate clickhouseJdbcTemplate(@Qualifier("clickHouseDataSource") DataSource clickhouseJdbcTemplate) {
|
||||
return new JdbcTemplate(clickhouseJdbcTemplate);
|
||||
}
|
||||
}
|
||||
//package com.volvo.ai.analytic.center.config;
|
||||
//
|
||||
//import org.springframework.beans.factory.annotation.Qualifier;
|
||||
//import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
//import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.context.annotation.Primary;
|
||||
//import org.springframework.jdbc.core.JdbcTemplate;
|
||||
//
|
||||
//import javax.sql.DataSource;
|
||||
//
|
||||
//@Configuration
|
||||
//public class ClickHouseConfig {
|
||||
//
|
||||
// @Primary
|
||||
// @Bean(name = "dataSource")
|
||||
// @ConfigurationProperties(prefix="spring.datasource")
|
||||
// public DataSource dataSource() {
|
||||
// DataSource dataSource = DataSourceBuilder.create().build();
|
||||
// return dataSource;
|
||||
// }
|
||||
//
|
||||
// @Bean(name = "clickHouseDataSource")
|
||||
// @ConfigurationProperties(prefix="spring.clickhouse-ads-ai")
|
||||
// public DataSource clickHouseDataSource(){
|
||||
// DataSource dataSource = DataSourceBuilder.create().build();
|
||||
// return dataSource;
|
||||
// }
|
||||
//
|
||||
// @Bean(name = "jdbcTemplate")
|
||||
// public JdbcTemplate jdbcTemplate(@Qualifier("dataSource") DataSource dataSource) {
|
||||
// return new JdbcTemplate(dataSource);
|
||||
// }
|
||||
//
|
||||
// @Bean(name = "clickhouseJdbcTemplate")
|
||||
// public JdbcTemplate clickhouseJdbcTemplate(@Qualifier("clickHouseDataSource") DataSource clickhouseJdbcTemplate) {
|
||||
// return new JdbcTemplate(clickhouseJdbcTemplate);
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.volvo.ai.analytic.center.config;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@MapperScan("com.volvo.ai.analytic.center.mapper") // 指定 Mapper 接口的包路径
|
||||
public class MyBatisPlusConfig {
|
||||
|
||||
@Bean
|
||||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
|
||||
|
||||
log.info("DataSource: {}", dataSource);
|
||||
MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
|
||||
sessionFactory.setDataSource(dataSource); // 设置数据源
|
||||
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
|
||||
.getResources("classpath*:mapper/*.xml")); // 设置 Mapper XML 文件路径
|
||||
sessionFactory.setTypeAliasesPackage("com.volvo.ai.analytic.center.entity"); // 设置实体类包路径
|
||||
return sessionFactory.getObject();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.volvo.ai.analytic.center.config;
|
||||
|
||||
import com.obs.services.ObsClient;
|
||||
import com.obs.services.ObsConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author CYI5
|
||||
*/
|
||||
@Configuration
|
||||
public class ObsConfig {
|
||||
|
||||
@Value("${huawei.cloud.obs.ak}")
|
||||
private String accessKey;
|
||||
|
||||
@Value("${huawei.cloud.obs.sk}")
|
||||
private String secretKey;
|
||||
|
||||
@Value("${huawei.cloud.obs.endpoint}")
|
||||
private String endpoint;
|
||||
|
||||
@Value("${huawei.cloud.obs.socket-timeout}")
|
||||
private int socketTimeOut;
|
||||
|
||||
@Value("${huawei.cloud.obs.connect-timeout}")
|
||||
private int connectTimeOut;
|
||||
|
||||
@Bean
|
||||
public ObsClient obsClient() {
|
||||
ObsConfiguration obsConfiguration = new ObsConfiguration();
|
||||
obsConfiguration.setSocketTimeout(socketTimeOut);
|
||||
obsConfiguration.setConnectionTimeout(connectTimeOut);
|
||||
obsConfiguration.setEndPoint(endpoint);
|
||||
return new ObsClient(accessKey, secretKey, obsConfiguration);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.volvo.ai.analytic.center.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.obs.services.model.ObsObject;
|
||||
import com.volvo.ai.analytic.center.feign.DiFyFeign;
|
||||
import com.volvo.ai.analytic.center.utils.ObsUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/dms/run")
|
||||
public class AiImageCompareController {
|
||||
|
||||
@Autowired
|
||||
private DiFyFeign diFyFeign;
|
||||
|
||||
@PostMapping("/fileUpload")
|
||||
public String fileUpload(@RequestHeader(value = "Authorization") String authorization, @RequestBody String filePath) throws IOException {
|
||||
|
||||
JSONObject jsonObjectResult;
|
||||
try {
|
||||
ObsObject obsObject = ObsUtil.downloadFile(filePath);
|
||||
InputStream inputStream = obsObject.getObjectContent();
|
||||
MultipartFile file = ObsUtil.getMultipartFile(inputStream, ObsUtil.getFilenameByUrl(filePath));
|
||||
JSONObject jsonObjectResult1 = diFyFeign.fileUpload(authorization,file);
|
||||
ObsObject obsObjectDoc = ObsUtil.downloadFile("file_test/business.docx");
|
||||
InputStream inputStreamDoc = obsObjectDoc.getObjectContent();
|
||||
MultipartFile fileDoc = ObsUtil.getMultipartFile(inputStreamDoc, ObsUtil.getFilenameByUrl("file_test/business.docx"));
|
||||
JSONObject jsonObjectResult2 = diFyFeign.fileUpload(authorization,fileDoc);
|
||||
JSONObject tpJSon = new JSONObject();
|
||||
tpJSon.put("type","image");
|
||||
tpJSon.put("transfer_method","local_file");
|
||||
tpJSon.put("upload_file_id",jsonObjectResult1.get("id"));
|
||||
JSONObject mbJsonp = new JSONObject();
|
||||
mbJsonp.put("type","document");
|
||||
mbJsonp.put("transfer_method","local_file");
|
||||
mbJsonp.put("upload_file_id",jsonObjectResult2.get("id"));
|
||||
Map<String ,Object> tpMpMap = new HashMap<>();
|
||||
tpMpMap.put("tp",tpJSon);
|
||||
tpMpMap.put("mb",mbJsonp);
|
||||
Map<String ,Object> reqMap = new HashMap<>();
|
||||
reqMap.put("inputs",tpMpMap);
|
||||
reqMap.put("response_mode","blocking");
|
||||
reqMap.put("user","streaming232");
|
||||
JSONObject runResultJson = diFyFeign.runWorkflows(authorization,reqMap);
|
||||
System.out.println("runResultJson:"+runResultJson);
|
||||
return runResultJson.toJSONString();
|
||||
} catch (Exception e) {
|
||||
log.error("error:{}",e);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -41,10 +41,10 @@ public class TestController {
|
||||
@Autowired
|
||||
private MqMessageRecordService mqMessageRecordService;
|
||||
|
||||
@Value("${service.dify.user}")
|
||||
@Value("${dify.user}")
|
||||
private String user;
|
||||
|
||||
@Value("${service.dify.flowId}")
|
||||
@Value("${dify.flowId}")
|
||||
private String flowId;
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.volvo.ai.analytic.center.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.volvo.ai.analytic.center.entity.TmTelephoneCorpus;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @description 电话语料表-同步表
|
||||
* @author BEJSON
|
||||
* @date 2025-03-04
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface TmTelephoneCorpusMapper extends BaseMapper<TmTelephoneCorpus> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.volvo.ai.analytic.center.mq;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.volvo.ai.analytic.center.dto.corpus.AicorpusTelephoneDTO;
|
||||
import com.volvo.ai.analytic.center.dto.corpus.DisplayDTO;
|
||||
import com.volvo.ai.analytic.center.entity.TmTelephoneCorpus;
|
||||
import com.volvo.ai.analytic.center.service.TmTelephoneCorpusService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @ClassName CorpusProcessKafkaConsumer
|
||||
* @Description
|
||||
* @Author renzhen
|
||||
* @Date 2025-03-04 10:18
|
||||
* @Version 1.0
|
||||
**/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RestController
|
||||
public class CorpusProcessKafkaConsumer {
|
||||
|
||||
@Autowired
|
||||
private TmTelephoneCorpusService tmTelephoneCorpusService;
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@GetMapping("corpusProcessKafkaConsumer")
|
||||
// @KafkaListener(topics = "aicorpus-telephone", groupId = "test-group")
|
||||
public void listen(@RequestBody String message) {
|
||||
try {
|
||||
log.info("Received message: {}" , message);
|
||||
|
||||
AicorpusTelephoneDTO aicorpusTelephone = objectMapper.readValue(message, AicorpusTelephoneDTO.class);
|
||||
log.info("aicorpusTelephone categoryCode:{}, display: {}" ,aicorpusTelephone.getCategoryCode(), aicorpusTelephone.getDisplay());
|
||||
DisplayDTO display = objectMapper.readValue(aicorpusTelephone.getDisplay(), DisplayDTO.class);
|
||||
log.info("aicorpusTelephone display getSegments: {}" , display.getSegments());
|
||||
TmTelephoneCorpus tmTelephoneCorpus = new TmTelephoneCorpus();
|
||||
BeanUtils.copyProperties(aicorpusTelephone, tmTelephoneCorpus);
|
||||
tmTelephoneCorpus.setCreateBy("kafka");
|
||||
tmTelephoneCorpus.setCreateTime(LocalDateTime.now());
|
||||
tmTelephoneCorpusService.saveTelephoneCorpus(tmTelephoneCorpus);
|
||||
|
||||
// 在这里可以添加对解析后的对象的进一步处理逻辑
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.volvo.ai.analytic.center.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.volvo.ai.analytic.center.entity.TmTelephoneCorpus;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description 电话语料表-同步表
|
||||
* @author BEJSON
|
||||
* @date 2025-03-04
|
||||
*/
|
||||
public interface TmTelephoneCorpusService extends IService<TmTelephoneCorpus> {
|
||||
|
||||
|
||||
void saveTelephoneCorpus(TmTelephoneCorpus tmTelephoneCorpus);
|
||||
}
|
||||
@@ -59,10 +59,10 @@ public class MqMessageRecordServiceImpl extends ServiceImpl<MqMessageRecordMappe
|
||||
@Autowired
|
||||
private AiAnalysisErrorsMapper aiAnalysisErrorsMapper;
|
||||
|
||||
@Value("${service.dify.user}")
|
||||
@Value("${dify.user}")
|
||||
private String user;
|
||||
|
||||
@Value("${service.dify.flowId}")
|
||||
@Value("${dify.flowId}")
|
||||
private String flowId;
|
||||
|
||||
@Value("${rocketmq.producer.topic}")
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.volvo.ai.analytic.center.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.volvo.ai.analytic.center.entity.TmTelephoneCorpus;
|
||||
import com.volvo.ai.analytic.center.exception.BizException;
|
||||
import com.volvo.ai.analytic.center.mapper.TmTelephoneCorpusMapper;
|
||||
import com.volvo.ai.analytic.center.service.TmTelephoneCorpusService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
/**
|
||||
* @description 电话语料表-同步表
|
||||
* @author rz
|
||||
* @date 2025-03-04
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TmTelephoneCorpusServiceImpl extends ServiceImpl<TmTelephoneCorpusMapper, TmTelephoneCorpus> implements TmTelephoneCorpusService {
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveTelephoneCorpus(TmTelephoneCorpus tmTelephoneCorpus) {
|
||||
this.save(tmTelephoneCorpus);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
package com.volvo.ai.analytic.center.utils;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.obs.services.ObsClient;
|
||||
import com.obs.services.model.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileItemFactory;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ObsUtil {
|
||||
|
||||
private static ObsClient obsClient;
|
||||
|
||||
private static String bucketName;
|
||||
|
||||
private static Long expireSeconds;
|
||||
|
||||
private static ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
private static String userDomainName;
|
||||
private static String userName;
|
||||
private static String userPassWord;
|
||||
private static String iamTokenUrl;
|
||||
|
||||
private static String securityTokenUrl;
|
||||
|
||||
private static String huaWeiCdn;
|
||||
|
||||
private static long durationSeconds;
|
||||
|
||||
@Autowired
|
||||
public void setObsClient(ObsClient obsClient) {
|
||||
ObsUtil.obsClient = obsClient;
|
||||
}
|
||||
|
||||
@Value("${huawei.cloud.obs.bucketName}")
|
||||
public void setBucketName(String bucketName) {
|
||||
ObsUtil.bucketName = bucketName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件下载
|
||||
*
|
||||
* @param objectKey 文件相对路径
|
||||
* @return ObsObject
|
||||
*/
|
||||
public static ObsObject downloadFile(String objectKey) {
|
||||
return obsClient.getObject(bucketName, objectKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件下载
|
||||
*
|
||||
* @param bucketName 桶
|
||||
* @param objectKey 文件名
|
||||
* @return ObsObject
|
||||
*/
|
||||
public static ObsObject downloadFile(String bucketName, String objectKey) {
|
||||
return obsClient.getObject(bucketName, objectKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据下载地址url获取文件名称
|
||||
*
|
||||
* @param url 文件url
|
||||
*/
|
||||
public static String getFilenameByUrl(String url) {
|
||||
String fileName = null;
|
||||
try {
|
||||
// url编码处理,中文名称会变成百分号编码
|
||||
String decode = URLDecoder.decode(url, "utf-8");
|
||||
fileName = decode.substring(decode.lastIndexOf("/") + 1);
|
||||
log.info("fileName :" + fileName);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("getFilenameByUrl() called with exception => 【url = {}】", url, e);
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取临时访问url并重命名
|
||||
*
|
||||
* @param objectKey 文件相对路径
|
||||
* @param fileName 需要返回下载的文件名称
|
||||
* @return 临时文件url
|
||||
*/
|
||||
public static String getSingedUrlAndRename(String objectKey, String fileName) {
|
||||
// 过期时间
|
||||
TemporarySignatureRequest temporarySignatureRequest = new TemporarySignatureRequest(HttpMethodEnum.GET, expireSeconds);
|
||||
// 桶名称
|
||||
temporarySignatureRequest.setBucketName(bucketName);
|
||||
// 对象名
|
||||
temporarySignatureRequest.setObjectKey(objectKey);
|
||||
Map<String, Object> queryParams = new HashMap<>(8);
|
||||
if (StringUtils.isNotBlank(fileName)) {
|
||||
String prefix = objectKey.substring(objectKey.lastIndexOf('.'));
|
||||
queryParams.put("response-content-disposition", String.format("attachment;filename=%s", fileName + prefix));
|
||||
}
|
||||
temporarySignatureRequest.setQueryParams(queryParams);
|
||||
TemporarySignatureResponse temporarySignature = obsClient.createTemporarySignature(temporarySignatureRequest);
|
||||
return temporarySignature.getSignedUrl();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取临时访问url
|
||||
*
|
||||
* @param objectKey 文件相对路径
|
||||
* @return 临时文件url
|
||||
*/
|
||||
public static String getSingedPictureUrl(String objectKey) {
|
||||
return getSingedUrlAndRename(objectKey, Strings.EMPTY);
|
||||
}
|
||||
|
||||
public static String getSingedUrl(String objectKey) {
|
||||
String previewUrl = "";
|
||||
if (!StringUtils.isEmpty(objectKey) && (objectKey.toLowerCase().endsWith(".tif") || objectKey.toLowerCase().endsWith(".tiff") || objectKey.toLowerCase().endsWith(".jpg") || objectKey.toLowerCase().endsWith(".jpeg") || objectKey.toLowerCase().endsWith(".png") || objectKey.toLowerCase().endsWith(".bmp"))) {
|
||||
return getSingedPictureUrl(objectKey);
|
||||
} else {
|
||||
previewUrl = huaWeiCdn + objectKey;
|
||||
}
|
||||
return previewUrl;
|
||||
}
|
||||
|
||||
|
||||
public static String getToken() {
|
||||
// String userDomainName,String userName, String userPassWord, String iamTokenUrl
|
||||
//组装获取token的参数
|
||||
HashMap<String, String> domainName = new HashMap<>();
|
||||
domainName.put("name", userDomainName);
|
||||
HashMap<String, Object> user = new HashMap<>();
|
||||
user.put("domain", domainName);
|
||||
user.put("name", userName);
|
||||
user.put("password", userPassWord);
|
||||
HashMap<String, Object> password = new HashMap<>();
|
||||
password.put("user", user);
|
||||
ArrayList<String> methodsList = new ArrayList<>();
|
||||
methodsList.add("password");
|
||||
HashMap<String, Object> identity = new HashMap<>();
|
||||
identity.put("methods", methodsList);
|
||||
identity.put("password", password);
|
||||
HashMap<String, Object> auth = new HashMap<>();
|
||||
HashMap<String, Object> projectName = new HashMap<>();
|
||||
projectName.put("name", "cn-east-3");
|
||||
HashMap<String, Object> project = new HashMap<>();
|
||||
project.put("scope", projectName);
|
||||
HashMap<String, Object> scope = new HashMap<>();
|
||||
scope.put("scope", project);
|
||||
auth.put("identity", identity);
|
||||
auth.put("scope", scope);
|
||||
HashMap<String, Object> bodyMap = new HashMap<>();
|
||||
bodyMap.put("auth", auth);
|
||||
String body = JSONUtil.toJsonStr(bodyMap);
|
||||
HttpResponse response = HttpRequest.post(iamTokenUrl).body(body).execute();
|
||||
return response.header("X-Subject-Token");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ak,sk,key,securityToken
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public static String getSecurityTokenAkSk(String token) {
|
||||
//组装获取临时ak/sk参数
|
||||
ArrayList<String> tokenList = new ArrayList<>();
|
||||
tokenList.add("token");
|
||||
HashMap<String, Object> tokenItemMap = new HashMap<>();
|
||||
tokenItemMap.put("id", token);
|
||||
tokenItemMap.put("duration_seconds", durationSeconds);
|
||||
HashMap<String, Object> tokenMethodsMap = new HashMap<>();
|
||||
tokenMethodsMap.put("methods", tokenList);
|
||||
tokenMethodsMap.put("token", tokenItemMap);
|
||||
HashMap<String, Object> tokenIdentityMap = new HashMap<>();
|
||||
tokenIdentityMap.put("identity", tokenMethodsMap);
|
||||
HashMap<String, Object> tokenAuthMap = new HashMap<>();
|
||||
tokenAuthMap.put("auth", tokenIdentityMap);
|
||||
String bodyStr = JSONUtil.toJsonStr(tokenAuthMap);
|
||||
HttpResponse response = HttpRequest.post(securityTokenUrl).body(bodyStr).execute();
|
||||
return response.body();
|
||||
}
|
||||
|
||||
public static MultipartFile getMultipartFile(InputStream inputStream, String fileName) {
|
||||
FileItem fileItem = createFileItem(inputStream, fileName);
|
||||
// CommonsMultipartFile是feign对multipartFile的封装,但是要FileItem类对象
|
||||
return new CommonsMultipartFile(fileItem);
|
||||
}
|
||||
public static FileItem createFileItem(InputStream inputStream, String fileName) {
|
||||
FileItemFactory factory = new DiskFileItemFactory(16, null);
|
||||
String textFieldName = "file";
|
||||
FileItem item = factory.createItem(textFieldName, MediaType.MULTIPART_FORM_DATA_VALUE, true, fileName);
|
||||
int bytesRead = 0;
|
||||
byte[] buffer = new byte[10 * 1024 * 1024];
|
||||
OutputStream os = null;
|
||||
// 使用输出流输出输入流的字节
|
||||
try {
|
||||
os = item.getOutputStream();
|
||||
while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
}
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.error("Stream copy exception", e);
|
||||
throw new IllegalArgumentException("文件上传失败");
|
||||
} finally {
|
||||
if (os != null) {
|
||||
try {
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
log.error("Stream close exception", e);
|
||||
}
|
||||
}
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.error("Stream close exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,17 @@
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
port: 8082
|
||||
spring:
|
||||
profiles:
|
||||
active: local
|
||||
application:
|
||||
name: ai-analytic-center
|
||||
name: ai-analytic-center-dev
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
enable: true
|
||||
namespace: a3f090cd-9c78-4580-a47a-a4b29278cec9
|
||||
group: dev
|
||||
server-addr: 10.37.44.229:8848
|
||||
file-extension: yaml
|
||||
refresh-enabled: true
|
||||
enable-remote-sync-config: true
|
||||
Reference in New Issue
Block a user