TASK:模块化;
This commit is contained in:
@@ -282,4 +282,10 @@ public class SavedCollectionController {
|
||||
public Response<String> brandDNAUpload(@RequestParam("file") MultipartFile file, @RequestParam("brandId") Long brandId) throws IOException {
|
||||
return Response.success(userLikeGroupService.brandDNAUpload(file, brandId));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "brandDNAGenerate")
|
||||
@PostMapping("/brandDNAGenerate")
|
||||
public Response<BrandDNAGenerateVO> brandDNAGenerate(@RequestParam("prompt") String prompt) {
|
||||
return Response.success(userLikeGroupService.brandDNAGenerate(prompt));
|
||||
}
|
||||
}
|
||||
|
||||
14
src/main/java/com/ai/da/model/vo/BrandDNAGenerateVO.java
Normal file
14
src/main/java/com/ai/da/model/vo/BrandDNAGenerateVO.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.ai.da.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BrandDNAGenerateVO {
|
||||
private String brandName;
|
||||
|
||||
private String brandSlogan;
|
||||
|
||||
private String brandLogo;
|
||||
|
||||
private String minioUrl;
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import com.google.common.collect.Maps;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import org.apache.catalina.User;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -4136,4 +4137,55 @@ public class PythonService {
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject brandDNAGenerate(String prompt) {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
|
||||
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
|
||||
.build();
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
//关闭FastJson的引用检测 防止出现$ref 现象
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("prompt", prompt);
|
||||
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
||||
map.put("user_id", userHolder.getId());
|
||||
log.info("brandDNAGenerate请求python 参数:####{}", map);
|
||||
String param = JSON.toJSONString(map, SerializerFeature.WriteNullStringAsEmpty);
|
||||
log.info(param);
|
||||
RequestBody body = RequestBody.create(mediaType, param);
|
||||
Request request = new Request.Builder()
|
||||
// .url(accessPythonIp + ":" + accessPythonPort + "/api/generate_product_image")
|
||||
// .url(accessPythonIp + ":9996/api/generate_product_image")
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/GenerateBrand")
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response;
|
||||
String responseBody;
|
||||
try {
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService##brandDNAGenerate异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
throw new BusinessException("brandDNAGenerate.interface.exception");
|
||||
}
|
||||
if (response.isSuccessful()) {
|
||||
try {
|
||||
if (Objects.nonNull(response.body())) {
|
||||
responseBody = response.body().string();
|
||||
JSONObject responseObject = JSON.parseObject(responseBody);
|
||||
log.info("PythonService##responseObject###{}", responseObject);
|
||||
return responseObject;
|
||||
}
|
||||
throw new BusinessException("brandDNAGenerate.interface.exception");
|
||||
} catch (IOException | JSONException e) {
|
||||
log.error("PythonService##brandDNAGenerate异常###{}", e.getMessage());
|
||||
throw new BusinessException("brandDNAGenerate.interface.exception");
|
||||
}
|
||||
}
|
||||
log.error("PythonService##brandDNAGenerate异常response###{}", response);
|
||||
//生成失败
|
||||
throw new BusinessException("brandDNAGenerate.interface.exception");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,4 +89,6 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
|
||||
String brandDNAUpload(MultipartFile file, Long brandId) throws IOException;
|
||||
|
||||
PageBaseResponse<BrandDNAVO> brandDNAPage(BrandDNAQueryDTO brandDNAQueryDTO);
|
||||
|
||||
BrandDNAGenerateVO brandDNAGenerate(String prompt);
|
||||
}
|
||||
|
||||
@@ -1938,4 +1938,15 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
});
|
||||
return PageBaseResponse.success(convert);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BrandDNAGenerateVO brandDNAGenerate(String prompt) {
|
||||
BrandDNAGenerateVO vo = new BrandDNAGenerateVO();
|
||||
JSONObject jsonObject = pythonService.brandDNAGenerate(prompt);
|
||||
vo.setBrandSlogan(jsonObject.getString("brand_slogan"));
|
||||
vo.setBrandName(jsonObject.getString("brand_name"));
|
||||
vo.setBrandLogo(jsonObject.getString("brand_logo"));
|
||||
vo.setMinioUrl(minioUtil.getPreSignedUrl(vo.getBrandLogo(), 24 * 60));
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user