|
|
|
@ -112,7 +112,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
switch (param.getPlatform()){ |
|
|
|
case "1": |
|
|
|
//查询抖音用户信息
|
|
|
|
TiktokUser tiktokUser = tiktokUserService.getUserById(param.getPainterId()); |
|
|
|
TiktokUser tiktokUser = tiktokUserService.getUserById(param.getPainterId(),param.getAppType()); |
|
|
|
//检查画意值是否足够,不足则直接提示不足请充值或完成相应任务
|
|
|
|
if (param.getGoldNum() > tiktokUser.getGoldNum()) { |
|
|
|
throw new ServiceException("画意值不足!请充值或完成相应任务获取", TiktokConstant.GOLD_NUM_IS_NOT_ENOUGH); |
|
|
|
@ -123,7 +123,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
break; |
|
|
|
case "2": |
|
|
|
//查询快手用户信息
|
|
|
|
FhUser fhUser = fhUserService.getUserById(param.getPainterId()); |
|
|
|
FhUser fhUser = fhUserService.getUserById(param.getPainterId(),param.getAppType()); |
|
|
|
//检查画意值是否足够,不足则直接提示不足请充值或完成相应任务
|
|
|
|
if (param.getGoldNum() > fhUser.getGoldNum()) { |
|
|
|
throw new ServiceException("画意值不足!请充值或完成相应任务获取", TiktokConstant.GOLD_NUM_IS_NOT_ENOUGH); |
|
|
|
@ -134,7 +134,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
break; |
|
|
|
case "3": |
|
|
|
//查询微信用户信息
|
|
|
|
WxUser wxUser = wxUserService.getUserById(param.getPainterId()); |
|
|
|
WxUser wxUser = wxUserService.getUserById(param.getPainterId(),param.getAppType()); |
|
|
|
//检查画意值是否足够,不足则直接提示不足请充值或完成相应任务
|
|
|
|
if (param.getGoldNum() > wxUser.getGoldNum()) { |
|
|
|
throw new ServiceException("画意值不足!请充值或完成相应任务获取", TiktokConstant.GOLD_NUM_IS_NOT_ENOUGH); |
|
|
|
@ -218,6 +218,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
paint.setWidth(param.getWidth() == null ? "512" : String.valueOf(param.getWidth())); |
|
|
|
paint.setIsShow("1"); |
|
|
|
paint.setSource(param.getPlatform()); |
|
|
|
paint.setAppType(param.getAppType()); |
|
|
|
paint.setPainterId(param.getPainterId()); |
|
|
|
paint.setPainterName(param.getPainterName()); |
|
|
|
aiPaintService.insert(paint); |
|
|
|
@ -226,6 +227,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
goldLog.setGoldNum(param.getGoldNum()); |
|
|
|
goldLog.setUserId(param.getPainterId()); |
|
|
|
goldLog.setSource(param.getPlatform()); |
|
|
|
goldLog.setAppType(param.getAppType()); |
|
|
|
goldLog.setReason(GoldEnum.PAINT.getValue()); |
|
|
|
goldLogService.insert(goldLog); |
|
|
|
} |
|
|
|
@ -331,6 +333,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
paint.setWidth(param.getWidth() == null ? "512" : String.valueOf(param.getWidth())); |
|
|
|
paint.setIsShow("1"); |
|
|
|
paint.setSource(param.getPlatform()); |
|
|
|
paint.setAppType(param.getAppType()); |
|
|
|
paint.setPainterId(param.getPainterId()); |
|
|
|
paint.setPainterName(param.getPainterName()); |
|
|
|
aiPaintService.insert(paint); |
|
|
|
@ -339,6 +342,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
goldLog.setGoldNum(param.getGoldNum()); |
|
|
|
goldLog.setUserId(param.getPainterId()); |
|
|
|
goldLog.setSource(param.getPlatform()); |
|
|
|
goldLog.setAppType(param.getAppType()); |
|
|
|
goldLog.setReason(GoldEnum.PAINT.getValue()); |
|
|
|
goldLogService.insert(goldLog); |
|
|
|
} |
|
|
|
@ -435,6 +439,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
paint.setWidth(param.getWidth() == null ? "512" : String.valueOf(param.getWidth())); |
|
|
|
paint.setIsShow("1"); |
|
|
|
paint.setSource(param.getPlatform()); |
|
|
|
paint.setAppType(param.getAppType()); |
|
|
|
paint.setPainterId(param.getPainterId()); |
|
|
|
paint.setPainterName(param.getPainterName()); |
|
|
|
aiPaintService.insert(paint); |
|
|
|
@ -443,6 +448,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
goldLog.setGoldNum(param.getGoldNum()); |
|
|
|
goldLog.setUserId(param.getPainterId()); |
|
|
|
goldLog.setSource(param.getPlatform()); |
|
|
|
goldLog.setAppType(param.getAppType()); |
|
|
|
goldLog.setReason(GoldEnum.PAINT.getValue()); |
|
|
|
goldLogService.insert(goldLog); |
|
|
|
} |
|
|
|
@ -464,7 +470,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
switch (param.getPlatform()){ |
|
|
|
case "1": |
|
|
|
//查询抖音用户信息
|
|
|
|
TiktokUser tiktokUser = tiktokUserService.getUserById(param.getPainterId()); |
|
|
|
TiktokUser tiktokUser = tiktokUserService.getUserById(param.getPainterId(),param.getAppType()); |
|
|
|
//检查画意值是否足够,不足则直接提示不足请充值或完成相应任务
|
|
|
|
if (param.getGoldNum() > tiktokUser.getGoldNum()) { |
|
|
|
throw new ServiceException("画意值不足!请充值或完成相应任务获取", TiktokConstant.GOLD_NUM_IS_NOT_ENOUGH); |
|
|
|
@ -475,7 +481,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
break; |
|
|
|
case "2": |
|
|
|
//查询快手用户信息
|
|
|
|
FhUser fhUser = fhUserService.getUserById(param.getPainterId()); |
|
|
|
FhUser fhUser = fhUserService.getUserById(param.getPainterId(),param.getAppType()); |
|
|
|
//检查画意值是否足够,不足则直接提示不足请充值或完成相应任务
|
|
|
|
if (param.getGoldNum() > fhUser.getGoldNum()) { |
|
|
|
throw new ServiceException("画意值不足!请充值或完成相应任务获取", TiktokConstant.GOLD_NUM_IS_NOT_ENOUGH); |
|
|
|
@ -486,7 +492,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
break; |
|
|
|
case "3": |
|
|
|
//查询微信用户信息
|
|
|
|
WxUser wxUser = wxUserService.getUserById(param.getPainterId()); |
|
|
|
WxUser wxUser = wxUserService.getUserById(param.getPainterId(),param.getAppType()); |
|
|
|
//检查画意值是否足够,不足则直接提示不足请充值或完成相应任务
|
|
|
|
if (param.getGoldNum() > wxUser.getGoldNum()) { |
|
|
|
throw new ServiceException("画意值不足!请充值或完成相应任务获取", TiktokConstant.GOLD_NUM_IS_NOT_ENOUGH); |
|
|
|
@ -503,6 +509,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
goldLog.setGoldNum(param.getGoldNum()); |
|
|
|
goldLog.setUserId(param.getPainterId()); |
|
|
|
goldLog.setSource(param.getPlatform()); |
|
|
|
goldLog.setAppType(param.getAppType()); |
|
|
|
goldLog.setReason(GoldEnum.COUPLE_HEAD.getValue()); |
|
|
|
goldLogService.insert(goldLog); |
|
|
|
|
|
|
|
@ -526,15 +533,15 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
String boyHeadStr = "1个男孩" + activePrompt + resultPrompt; |
|
|
|
//女头提示词
|
|
|
|
String girlHeadStr = "1个女孩" + activePrompt + resultPrompt; |
|
|
|
String boyHead = getCoupleHead(boyHeadStr,negaPrompt,param.getPlatform(), param.getPainterId(), param.getPainterName(), param.getStyleName(),button,contentPrompt); |
|
|
|
String boyHead = getCoupleHead(boyHeadStr,negaPrompt,param.getPlatform(),param.getAppType(), param.getPainterId(), param.getPainterName(), param.getStyleName(),button,contentPrompt); |
|
|
|
log.info("腾讯男头像提示词为:【{}】",girlHeadStr); |
|
|
|
String girlHead = getCoupleHead(girlHeadStr,negaPrompt,param.getPlatform(), param.getPainterId(), param.getPainterName(), param.getStyleName(),button,contentPrompt); |
|
|
|
String girlHead = getCoupleHead(girlHeadStr,negaPrompt,param.getPlatform(),param.getAppType(),param.getPainterId(), param.getPainterName(), param.getStyleName(),button,contentPrompt); |
|
|
|
log.info("腾讯女头像提示词为:【{}】",girlHeadStr); |
|
|
|
List<String> imgList = new ArrayList<>(); |
|
|
|
imgList.add(boyHead); |
|
|
|
imgList.add(girlHead); |
|
|
|
return imgList; |
|
|
|
}else{ |
|
|
|
}else if(button == AiPaintButtonEnum.SD.getCode()){ |
|
|
|
//采用sd
|
|
|
|
try{ |
|
|
|
//最终结果词
|
|
|
|
@ -552,9 +559,9 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
//女头提示词
|
|
|
|
String girlHeadStr = "(1girl)" + activePrompt + prompt; |
|
|
|
|
|
|
|
String boyHead = getCoupleHead(boyHeadStr,negaPrompt,param.getPlatform(), param.getPainterId(), param.getPainterName(), param.getStyleName(),button,contentPrompt); |
|
|
|
String boyHead = getCoupleHead(boyHeadStr,negaPrompt,param.getPlatform(),param.getAppType(), param.getPainterId(), param.getPainterName(), param.getStyleName(),button,contentPrompt); |
|
|
|
log.info("sd男头像提示词为:【{}】",boyHeadStr); |
|
|
|
String girlHead = getCoupleHead(girlHeadStr,negaPrompt,param.getPlatform(), param.getPainterId(), param.getPainterName(), param.getStyleName(),button,contentPrompt); |
|
|
|
String girlHead = getCoupleHead(girlHeadStr,negaPrompt,param.getPlatform(),param.getAppType(), param.getPainterId(), param.getPainterName(), param.getStyleName(),button,contentPrompt); |
|
|
|
log.info("sd女头像提示词为:【{}】",girlHeadStr); |
|
|
|
List<String> imgList = new ArrayList<>(); |
|
|
|
imgList.add(boyHead); |
|
|
|
@ -563,23 +570,38 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
}catch (Exception e){ |
|
|
|
log.error("文本翻译错误!"+e); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//采用flagStudio
|
|
|
|
//男头提示词
|
|
|
|
String boyHeadStr = "1个男孩" + activePrompt + resultPrompt; |
|
|
|
//女头提示词
|
|
|
|
String girlHeadStr = "1个女孩" + activePrompt + resultPrompt; |
|
|
|
String boyHead = getCoupleHead(boyHeadStr,negaPrompt,param.getPlatform(),param.getAppType(), param.getPainterId(), param.getPainterName(), param.getStyleName(),button,contentPrompt); |
|
|
|
log.info("flagStudio男头像提示词为:【{}】",girlHeadStr); |
|
|
|
String girlHead = getCoupleHead(girlHeadStr,negaPrompt,param.getPlatform(),param.getAppType(), param.getPainterId(), param.getPainterName(), param.getStyleName(),button,contentPrompt); |
|
|
|
log.info("flagStudio女头像提示词为:【{}】",girlHeadStr); |
|
|
|
List<String> imgList = new ArrayList<>(); |
|
|
|
imgList.add(boyHead); |
|
|
|
imgList.add(girlHead); |
|
|
|
return imgList; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 情侣头像专用绘制方法 |
|
|
|
* @param button sd/tx |
|
|
|
* @param button sd/tx/flagStudio |
|
|
|
* @param headStr 头像描述词 |
|
|
|
* @param negaPrompt 反向描述词 |
|
|
|
* @param platform 平台 |
|
|
|
* @param appType app类型 |
|
|
|
* @param painterId 绘图者id |
|
|
|
* @param painterName 绘图者名称 |
|
|
|
* @param styleName 风格名称 |
|
|
|
* @param protoHead 原用户输入的描述词 |
|
|
|
* @return - |
|
|
|
*/ |
|
|
|
private String getCoupleHead(String headStr,String negaPrompt,String platform,Long painterId,String painterName,String styleName,int button,String protoHead){ |
|
|
|
private String getCoupleHead(String headStr,String negaPrompt,String platform,String appType,Long painterId,String painterName,String styleName,int button,String protoHead){ |
|
|
|
|
|
|
|
if(button == AiPaintButtonEnum.TX.getCode()){ |
|
|
|
//采用腾讯文生图
|
|
|
|
@ -637,17 +659,17 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
paint.setWidth("768"); |
|
|
|
paint.setIsShow("1"); |
|
|
|
paint.setSource(platform); |
|
|
|
paint.setAppType(appType); |
|
|
|
paint.setPainterId(painterId); |
|
|
|
paint.setPainterName(painterName); |
|
|
|
aiPaintService.insert(paint); |
|
|
|
|
|
|
|
return image; |
|
|
|
} |
|
|
|
} catch (TencentCloudSDKException e) { |
|
|
|
log.error("腾讯文生图情侣头像调用错误!"+e.getMessage()); |
|
|
|
throw new ServiceException(e.getMessage(),500); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
}else if(button == AiPaintButtonEnum.SD.getCode()){ |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
Double eta = 0.0; |
|
|
|
Integer batchSize = 1; |
|
|
|
@ -704,6 +726,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
paint.setWidth("512"); |
|
|
|
paint.setIsShow("1"); |
|
|
|
paint.setSource(platform); |
|
|
|
paint.setAppType(appType); |
|
|
|
paint.setPainterId(painterId); |
|
|
|
paint.setPainterName(painterName); |
|
|
|
aiPaintService.insert(paint); |
|
|
|
@ -715,6 +738,75 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
throw new ServiceException("情侣头像绘制失败!",500); |
|
|
|
} |
|
|
|
return null; |
|
|
|
}else{ |
|
|
|
//FlagStudio
|
|
|
|
try{ |
|
|
|
//获取token
|
|
|
|
JSONObject tokenObject = restTemplate.getForObject(flagStudioConfig.getTokenUrl() + "?apikey=" + flagStudioConfig.getApiKey(), JSONObject.class); |
|
|
|
String token = ""; |
|
|
|
if(tokenObject != null && tokenObject.getString("code").equals("200")){ |
|
|
|
token = tokenObject.getJSONObject("data").getString("token"); |
|
|
|
} |
|
|
|
//组装参数并发送
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("prompt", headStr); //存预设词+用户输入词
|
|
|
|
map.put("guidance_scale",7.5); //精细度可调
|
|
|
|
map.put("height",512); |
|
|
|
map.put("width",512); |
|
|
|
map.put("negative_prompts",negaPrompt); |
|
|
|
map.put("sampler","ddim"); //采样风格可调
|
|
|
|
map.put("seed",0); //种子
|
|
|
|
map.put("steps",50); //采样步数可调
|
|
|
|
map.put("style",styleName); //风格
|
|
|
|
map.put("upsample",1); |
|
|
|
log.info("请求flagStudio请求体为:【{}】", JSON.toJSONString(map)); |
|
|
|
// 构建你的请求头
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
headers.set("Content-Type", "application/json"); |
|
|
|
headers.set("Accept", "application/json"); |
|
|
|
headers.set("token",token); |
|
|
|
// 组合请求头与请求体参数
|
|
|
|
HttpEntity<String> requestEntity = new HttpEntity<>(JSONObject.toJSONString(map), headers); |
|
|
|
JSONObject jsonObject = restTemplate.postForObject(flagStudioConfig.getTxt2ImgUrl(), requestEntity, JSONObject.class); |
|
|
|
if(jsonObject != null && jsonObject.getString("data") != null && jsonObject.getString("code").equals("200") && jsonObject.getString("nsfw").equals("0")) { |
|
|
|
String imgUrl = jsonObject.getString("data"); |
|
|
|
List<String> list = new ArrayList<>(); |
|
|
|
list.add(imgUrl); |
|
|
|
String paintId = null; |
|
|
|
Date paintTime = null; |
|
|
|
for (String image : list) { |
|
|
|
//base64转file
|
|
|
|
MultipartFile file = new Base64ToMultipartFileUtils(image, "data:image/png;base64", "file", "tempSDImg"); |
|
|
|
//上传图片到七牛云/minio
|
|
|
|
//String imgStr = remoteFileService.uploadBanner(file).getData();
|
|
|
|
//上传图片到七牛云并存入sd文件夹
|
|
|
|
String imgStr = remoteFileService.uploadQiNiu(file,7).getData(); |
|
|
|
//保存生辰该图片到ai绘画表
|
|
|
|
AiPaint paint = new AiPaint(); |
|
|
|
paintId = IdUtil.getSnowflakeNextIdStr(); |
|
|
|
paintTime = new Date(); |
|
|
|
paint.setPaintId(paintId); |
|
|
|
paint.setCreateTime(paintTime); |
|
|
|
paint.setImgUrl(imgStr); |
|
|
|
paint.setPrompt(protoHead); //只存储用户输入的内容
|
|
|
|
paint.setNegativePrompt(negaPrompt); |
|
|
|
paint.setModel("flagStudio情侣头像"); |
|
|
|
paint.setStyleName(styleName); |
|
|
|
paint.setHeight("512"); |
|
|
|
paint.setWidth("512"); |
|
|
|
paint.setIsShow("1"); |
|
|
|
paint.setSource(platform); |
|
|
|
paint.setAppType(appType); |
|
|
|
paint.setPainterId(painterId); |
|
|
|
paint.setPainterName(painterName); |
|
|
|
aiPaintService.insert(paint); |
|
|
|
return image; |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("FlagStudio文生图调用错误!"+e.getMessage()); |
|
|
|
throw new ServiceException(e.getMessage(),500); |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
@ -725,13 +817,13 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void addPlatformUserAiPaintNum(String platform, Long userId, int paintNum) { |
|
|
|
public void addPlatformUserAiPaintNum(String platform, String appType,Long userId, int paintNum) { |
|
|
|
//判断是哪个平台的
|
|
|
|
switch (platform){ |
|
|
|
//抖音
|
|
|
|
case "1": |
|
|
|
//查询用户信息
|
|
|
|
TiktokUser tiktokUser = tiktokUserService.getUserById(userId); |
|
|
|
TiktokUser tiktokUser = tiktokUserService.getUserById(userId,appType); |
|
|
|
tiktokUser.setGoldNum(tiktokUser.getGoldNum()+paintNum); |
|
|
|
//更新用户信息
|
|
|
|
tiktokUserService.updateTiktokUser(tiktokUser); |
|
|
|
@ -739,7 +831,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
//快手
|
|
|
|
case "2": |
|
|
|
//查询用户信息
|
|
|
|
FhUser fhUser = fhUserService.getUserById(userId); |
|
|
|
FhUser fhUser = fhUserService.getUserById(userId,appType); |
|
|
|
fhUser.setGoldNum(fhUser.getGoldNum()+paintNum); |
|
|
|
//更新用户信息
|
|
|
|
fhUserService.updateFhUser(fhUser); |
|
|
|
@ -747,7 +839,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
|
//微信
|
|
|
|
case "3": |
|
|
|
//查询用户信息
|
|
|
|
WxUser wxUser = wxUserService.getUserById(userId); |
|
|
|
WxUser wxUser = wxUserService.getUserById(userId,appType); |
|
|
|
wxUser.setGoldNum(wxUser.getGoldNum()+paintNum); |
|
|
|
//更新用户信息
|
|
|
|
wxUserService.updateWxUser(wxUser); |
|
|
|
|