bug修改
This commit is contained in:
parent
c8e155eaf6
commit
24a1b92fc4
@ -102,6 +102,12 @@ public class PaCollectionController extends BaseController {
|
||||
if (userid==null){
|
||||
return new Result(false, "用户不存在");
|
||||
}
|
||||
Integer count=entityService.lambdaQuery()
|
||||
.eq(PaCollection::getUserId,userid)
|
||||
.eq(PaCollection::getCreationId,entity.getCreationId()).count();
|
||||
if(count>0){
|
||||
return new Result(false, "请勿重复收藏作品");
|
||||
}
|
||||
entity.setState("t");
|
||||
entity.setUserId(userid);
|
||||
entity.setCreatetime(new Date());
|
||||
|
@ -81,6 +81,14 @@ public class AiPictureController {
|
||||
if (paServices==null)
|
||||
return new Result(false, "该服务不存在", "该服务不存在");
|
||||
|
||||
//服务单独判断
|
||||
if(aiPictureVo.getServiceId()==7 && aiPictureVo.getText().length()>6 ){
|
||||
return new Result(false, "字数超过限制", "字数超过限制");
|
||||
}
|
||||
if(aiPictureVo.getServiceId()==8 && aiPictureVo.getText().length()>200 ){
|
||||
return new Result(false, "字数超过限制", "字数超过限制");
|
||||
}
|
||||
|
||||
//进行扣费并记录日志
|
||||
Boolean pay=paVipCurrencyService.consume(userId,paServices);
|
||||
if (!pay){
|
||||
|
@ -64,7 +64,7 @@ public class ScheduledTasks {
|
||||
|
||||
|
||||
//每隔30秒拉取一次阿里云、火山生成结果
|
||||
// @Scheduled(fixedRate = 30*1000)
|
||||
@Scheduled(fixedRate = 30*1000)
|
||||
public void getCreationUrl() throws Exception {
|
||||
//2阿里云,3火山
|
||||
List<PaCreation> paCreations= paCreationService.lambdaQuery()
|
||||
@ -155,7 +155,7 @@ public class ScheduledTasks {
|
||||
aiPictureService.failureHandling(paCreation,e);
|
||||
ResultVo resultVo=new ResultVo();
|
||||
resultVo.setStatus("fail");
|
||||
resultVo.setReason(e.getMessage());
|
||||
resultVo.setReason(paCreation.getReason());
|
||||
return resultVo;
|
||||
}
|
||||
}
|
||||
@ -174,13 +174,13 @@ public class ScheduledTasks {
|
||||
// }else{
|
||||
cpAttachmentService.lambdaUpdate()
|
||||
.set(CpAttachment::getPath,ossUrl)
|
||||
.set(CpAttachment::getState,state)
|
||||
.set(CpAttachment::getState,"t")//图片状态永远为t
|
||||
.eq(CpAttachment::getId,paCreation.getPhotoId()).update();
|
||||
// }
|
||||
//更新收藏品状态
|
||||
//更新作品状态
|
||||
paCreationService.lambdaUpdate()
|
||||
.set(PaCreation::getState,state)
|
||||
.set(PaCreation::getReason,reason)
|
||||
.set(PaCreation::getState,state)//作品状态为create、t、fail
|
||||
// .set(PaCreation::getReason,reason)
|
||||
.eq(PaCreation::getId,paCreation.getId()).update();
|
||||
return ossUrl;
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ import okhttp3.MediaType;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -68,13 +70,19 @@ public class AiPictureServiceImpl implements AiPictureService {
|
||||
@Autowired
|
||||
private PaCreationService paCreationService;
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
@Autowired
|
||||
private PaAiTryonService paAiTryonService;
|
||||
@Autowired
|
||||
private VolcengineExConfig volcengineExConfig;
|
||||
@Value("${picture.fail}")
|
||||
private String fail;
|
||||
@Autowired
|
||||
private RestTemplateBuilder restTemplateBuilder;
|
||||
@Bean
|
||||
public RestTemplate getRestTemplate() {
|
||||
return restTemplateBuilder.build();
|
||||
}
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
@Override
|
||||
@SysLog(action = "AiPicture:ImageColoring", value = "百度:黑白图片上色")
|
||||
@ -103,11 +111,14 @@ public class AiPictureServiceImpl implements AiPictureService {
|
||||
cpAttachment.setPath(fail);
|
||||
cpAttachmentService.updateById(cpAttachment);
|
||||
String message=e.getMessage();
|
||||
JSONObject jsonObject=JSONObject.parseObject(message);
|
||||
if (jsonObject!=null) {
|
||||
Integer code = Integer.valueOf(jsonObject.getString("code"));
|
||||
paCreation.setReason(VolcengineUtil.getErrorMessage(code));
|
||||
|
||||
if (StringUtil.isNotBlank(message) && JSONUtil.isJSON(message)){
|
||||
JSONObject jsonObject=JSONObject.parseObject(message);
|
||||
if (jsonObject!=null) {
|
||||
Integer code = Integer.valueOf(jsonObject.getString("code"));
|
||||
paCreation.setReason(VolcengineUtil.getErrorMessage(code));
|
||||
}
|
||||
}else if(StringUtil.isNotBlank(message) && message.equals("400 Bad Request")){
|
||||
paCreation.setReason("输入内容不符合规范");
|
||||
}
|
||||
paCreation.setSystemCause(message);
|
||||
paCreation.setState("fail");
|
||||
@ -162,14 +173,10 @@ public class AiPictureServiceImpl implements AiPictureService {
|
||||
@Override
|
||||
@SysLog(action = "AiPicture:textToImage", value = "阿里云:文字生成图片")
|
||||
public void textToImage(AiPictureVo aiPictureVo,PaCreation paCreation) throws Exception {
|
||||
try {
|
||||
//异步请求阿里云URL,获取任务id
|
||||
String taskId=((Map)this.text2Images(aiPictureVo,paCreation)).get("task_id").toString();
|
||||
paCreation.setTaskId(taskId);
|
||||
paCreationService.updateById(paCreation);
|
||||
}catch (Exception e){
|
||||
failureHandling(paCreation,e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -594,14 +601,15 @@ public class AiPictureServiceImpl implements AiPictureService {
|
||||
|
||||
public Map text2Images(AiPictureVo aiPictureVo, PaCreation paCreation) {
|
||||
try {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(org.springframework.http.MediaType.APPLICATION_JSON);//固定,返回类型,只有json
|
||||
headers.set("Authorization", API_KEY);//固定,api密钥
|
||||
headers.set("X-DashScope-Async", "enable");//只有默认,异步提交任务
|
||||
String url="https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis";//文生图url
|
||||
Map<String, Object> input = new HashMap<>();//放到request中
|
||||
input.put("prompt", aiPictureVo.getPromt());//////////文本描述
|
||||
input.put("size", 1024*1024);//////////尺寸
|
||||
input.put("prompt", aiPictureVo.getText());//////////文本描述
|
||||
input.put("size", aiPictureVo.getSize());//////////尺寸
|
||||
Map<String, Object> parameters = new HashMap<>();//放到request中
|
||||
parameters.put("style", aiPictureVo.getOption());//////////类型
|
||||
parameters.put("n", 1);//////////数量
|
||||
|
26
src/main/java/com/pixelai/api/picture/util/JSONUtil.java
Normal file
26
src/main/java/com/pixelai/api/picture/util/JSONUtil.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.pixelai.api.picture.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
/**
|
||||
* @ClassName JSONUtils
|
||||
* @Description json验证工具
|
||||
* @Author zhangxin
|
||||
* @Date 2020-08-19
|
||||
**/
|
||||
public class JSONUtil {
|
||||
|
||||
public static boolean isJSON(String str) {
|
||||
boolean result = false;
|
||||
try {
|
||||
Object obj= JSON.parse(str);
|
||||
result = true;
|
||||
} catch (Exception e) {
|
||||
result=false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class VolcengineUtil {
|
||||
errorMessage="输出文本后审核未通过";
|
||||
break;
|
||||
case 50413:
|
||||
errorMessage="文本不符规范,请调整文本内容";
|
||||
errorMessage="文本不符合安全规范,请调整文本内容";
|
||||
break;
|
||||
case 60101:
|
||||
errorMessage="图像解析错误";
|
||||
@ -105,10 +105,13 @@ public class VolcengineUtil {
|
||||
errorMessage="图像尺寸超过限制";
|
||||
break;
|
||||
case 50429:
|
||||
errorMessage="当前使用人数过多,请重试";
|
||||
errorMessage="当前使用人数过多,请稍后再试";
|
||||
break;
|
||||
case 50501:
|
||||
errorMessage="服务器内部RPC错误,正在重试";
|
||||
errorMessage="服务器内部RPC错误,请稍后再试";
|
||||
break;
|
||||
case 50400:
|
||||
errorMessage="权限校验失败,请联系管理员";
|
||||
break;
|
||||
}
|
||||
return errorMessage;
|
||||
|
@ -28,4 +28,7 @@ public class AiPictureVo {
|
||||
@ApiModelProperty(value = "换衣-下衣url")
|
||||
private String bottomImageUrl;
|
||||
|
||||
@ApiModelProperty(value = "图片大小")
|
||||
private String size;
|
||||
|
||||
}
|
||||
|
@ -76,7 +76,7 @@
|
||||
show, edit, createtime, pwdupdatetime, state,salt
|
||||
</sql>
|
||||
|
||||
<select id="findByUsername" resultMap="BaseResultMap" parameterType="java.lang.String">
|
||||
<select id="findByUsername" resultMap="BaseResultMap" >
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM ac_user where username = #{username} and usertype = #{usertype} and state = 't'
|
||||
|
@ -28,7 +28,7 @@
|
||||
type,
|
||||
review_status
|
||||
from (select
|
||||
pa_creation."id",
|
||||
pa_collection."id",
|
||||
pa_creation."name",
|
||||
pa_creation.photo_id,
|
||||
pa_creation.user_id,
|
||||
|
@ -70,7 +70,8 @@
|
||||
ac_user.realname as upload_name,
|
||||
cp_label.name as label_name,
|
||||
pa_picture_wall.price as price,
|
||||
pa_services.name as service_name
|
||||
pa_services.name as service_name,
|
||||
pa_services.id as serviceId
|
||||
from pa_picture_wall
|
||||
left join ac_user on pa_picture_wall.userid=ac_user.id
|
||||
left join cp_label on pa_picture_wall.cp_label_id =cp_label.id
|
||||
|
Loading…
Reference in New Issue
Block a user