|
|
@@ -13,6 +13,7 @@ import com.ejlchina.searcher.util.MapBuilder;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import com.yhlxj.dao.mapper.GroupsRelationMapper;
|
|
|
import com.yhlxj.dao.mapper.MidjourneyPaintingPlazaMapper;
|
|
|
+import com.yhlxj.dao.mapper.midjourney.MidjourneyUserConversationMapper;
|
|
|
import com.yhlxj.dao.mapper.midjourney.MidjourneyUserMapper;
|
|
|
import com.yhlxj.dao.model.dto.*;
|
|
|
import com.yhlxj.dao.model.entity.GroupsRelation;
|
|
|
@@ -67,9 +68,11 @@ public class MidjourneyController {
|
|
|
|
|
|
private final MidjourneyPaintingPlazaMapper midjourneyPaintingPlazaMapper;
|
|
|
|
|
|
- public MidjourneyUser getUser(Integer mode){
|
|
|
+ private final MidjourneyUserConversationMapper conversationMapper;
|
|
|
+
|
|
|
+ public MidjourneyUser getUser(){
|
|
|
String userToken = request.getHeader("user-token");
|
|
|
- return midjourneyService.getUser(userToken,mode);
|
|
|
+ return midjourneyService.getUser(userToken);
|
|
|
}
|
|
|
|
|
|
@GetMapping("/midjourneyMirrorWithToken/{userToken}")
|
|
|
@@ -85,20 +88,17 @@ public class MidjourneyController {
|
|
|
/**
|
|
|
* 检查用户次数
|
|
|
*/
|
|
|
- public Long checkUserLimit(MidjourneyUser user){
|
|
|
+ public Long checkUserLimit(MidjourneyUser user,Integer mode){
|
|
|
Long num = 0L;
|
|
|
if (user.getExpireTime().before(new Date())){
|
|
|
throw BusinessRuntimeException.getInstance("账号已过期");
|
|
|
}
|
|
|
- if (user.getMode() == 1){
|
|
|
+ if (mode == 1){
|
|
|
|
|
|
num = redisService.decr(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + user.getId(), 1L);
|
|
|
|
|
|
if (num < 0) {
|
|
|
- user.setMode(2);
|
|
|
- midjourneyUserMapper.update(null, Wrappers.lambdaUpdate(MidjourneyUser.class).eq(MidjourneyUser::getId, user.getId()).set(MidjourneyUser::getMode, user.getMode()));
|
|
|
redisService.incr(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + user.getId(), 1L);
|
|
|
-
|
|
|
}else {
|
|
|
int i = midjourneyUserMapper.decFastNum(user.getId(), 1, user.getMjFastNum());
|
|
|
if (i == 0) {
|
|
|
@@ -107,7 +107,7 @@ public class MidjourneyController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (user.getMode() == 2){
|
|
|
+ if (mode == 2){
|
|
|
Object relax = redisService.get(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + user.getId());
|
|
|
|
|
|
if (relax != null){
|
|
|
@@ -169,7 +169,7 @@ public class MidjourneyController {
|
|
|
*/
|
|
|
@GetMapping("/whoami")
|
|
|
public Result<MidjourneyUser> queryUser(){
|
|
|
- MidjourneyUser user = getUser(null);
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(user);
|
|
|
}
|
|
|
|
|
|
@@ -181,16 +181,17 @@ public class MidjourneyController {
|
|
|
@NoSubmit
|
|
|
public Result<MidjourneyUserConversation> submitImagine(@RequestBody SubmitImagineDTO submitImagineDTO) {
|
|
|
log.info("提交Imagine任务,提示:{}",submitImagineDTO.getPrompt());
|
|
|
- MidjourneyUser user = getUser(submitImagineDTO.getMode());
|
|
|
- Long num = checkUserLimit(user);
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
+ Integer mode = submitImagineDTO.getMode();
|
|
|
+ Long num = checkUserLimit(user, mode);
|
|
|
if (num != null && num < 0){
|
|
|
throw BusinessRuntimeException.getInstance("次数已用完");
|
|
|
}
|
|
|
MidjourneyUserConversation conversation;
|
|
|
try {
|
|
|
- conversation = midjourneyService.submitImagine(user, submitImagineDTO.getPrompt(), submitImagineDTO.getBotType(), submitImagineDTO.getBase64Array());
|
|
|
+ conversation = midjourneyService.submitImagine(user, mode, submitImagineDTO.getPrompt(), submitImagineDTO.getBotType(), submitImagineDTO.getBase64Array());
|
|
|
} catch (Exception e) {
|
|
|
- recoverUserLimit(user.getId(), user.getMode(),num);
|
|
|
+ recoverUserLimit(user.getId(), mode,num);
|
|
|
throw BusinessRuntimeException.getInstance(e.getMessage());
|
|
|
}
|
|
|
//syncUser(user.getId(), user.getMode(), num);
|
|
|
@@ -204,16 +205,17 @@ public class MidjourneyController {
|
|
|
@NoSubmit
|
|
|
public Result<MidjourneyUserConversation> submitDescribe(@RequestBody SubmitDescribeDTO submitDescribeDTO) {
|
|
|
log.info("提交Describe任务");
|
|
|
- MidjourneyUser user = getUser(submitDescribeDTO.getMode());
|
|
|
- Long num = checkUserLimit(user);
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
+ Integer mode = submitDescribeDTO.getMode();
|
|
|
+ Long num = checkUserLimit(user,mode);
|
|
|
if (num != null && num < 0){
|
|
|
throw BusinessRuntimeException.getInstance("次数已用完");
|
|
|
}
|
|
|
MidjourneyUserConversation conversation;
|
|
|
try {
|
|
|
- conversation = midjourneyService.submitDescribe(user, submitDescribeDTO.getBotType(),submitDescribeDTO.getBase64());
|
|
|
+ conversation = midjourneyService.submitDescribe(user, mode,submitDescribeDTO.getBotType(),submitDescribeDTO.getBase64());
|
|
|
} catch (Exception e) {
|
|
|
- recoverUserLimit(user.getId(), user.getMode(),num);
|
|
|
+ recoverUserLimit(user.getId(), mode,num);
|
|
|
throw BusinessRuntimeException.getInstance(e.getMessage());
|
|
|
}
|
|
|
//syncUser(user.getId(), user.getMode(), num);
|
|
|
@@ -227,16 +229,17 @@ public class MidjourneyController {
|
|
|
@NoSubmit
|
|
|
public Result<MidjourneyUserConversation> submitBlend(@RequestBody SubmitBlendDTO submitBlendDTO) {
|
|
|
log.info("提交Blend任务 dimensions:{},base64数组长度:{}", submitBlendDTO.getDimensions(), submitBlendDTO.getBase64Array().size());
|
|
|
- MidjourneyUser user = getUser(submitBlendDTO.getMode());
|
|
|
- Long num = checkUserLimit(user);
|
|
|
+ Integer mode = submitBlendDTO.getMode();
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
+ Long num = checkUserLimit(user,mode);
|
|
|
if (num != null && num < 0){
|
|
|
throw BusinessRuntimeException.getInstance("次数已用完");
|
|
|
}
|
|
|
MidjourneyUserConversation conversation;
|
|
|
try {
|
|
|
- conversation = midjourneyService.submitBlend(user, submitBlendDTO.getDimensions(), submitBlendDTO.getBotType(), submitBlendDTO.getBase64Array());
|
|
|
+ conversation = midjourneyService.submitBlend(user, mode,submitBlendDTO.getDimensions(), submitBlendDTO.getBotType(), submitBlendDTO.getBase64Array());
|
|
|
} catch (Exception e) {
|
|
|
- recoverUserLimit(user.getId(), user.getMode(),num);
|
|
|
+ recoverUserLimit(user.getId(), mode,num);
|
|
|
throw BusinessRuntimeException.getInstance(e.getMessage());
|
|
|
}
|
|
|
//syncUser(user.getId(), user.getMode(), num);
|
|
|
@@ -250,16 +253,17 @@ public class MidjourneyController {
|
|
|
@NoSubmit
|
|
|
public Result<MidjourneyUserConversation> submitModal(@RequestBody SubmitModalDTO submitModalDTO) {
|
|
|
log.info("提交Modal任务,taskId:{},提示:{}",submitModalDTO.getTaskId(),submitModalDTO.getPrompt());
|
|
|
- MidjourneyUser user = getUser(submitModalDTO.getMode());
|
|
|
- Long num = checkUserLimit(user);
|
|
|
+ Integer mode = submitModalDTO.getMode();
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
+ Long num = checkUserLimit(user,mode);
|
|
|
if (num != null && num < 0){
|
|
|
throw BusinessRuntimeException.getInstance("次数已用完");
|
|
|
}
|
|
|
MidjourneyUserConversation conversation;
|
|
|
try {
|
|
|
- conversation = midjourneyService.submitModal(user, submitModalDTO.getTaskId(), submitModalDTO.getPrompt(), submitModalDTO.getMaskBase64());
|
|
|
+ conversation = midjourneyService.submitModal(user, mode, submitModalDTO.getTaskId(), submitModalDTO.getPrompt(), submitModalDTO.getMaskBase64());
|
|
|
} catch (Exception e) {
|
|
|
- recoverUserLimit(user.getId(), user.getMode(),num);
|
|
|
+ recoverUserLimit(user.getId(), mode,num);
|
|
|
throw BusinessRuntimeException.getInstance(e.getMessage());
|
|
|
}
|
|
|
//syncUser(user.getId(), user.getMode(), num);
|
|
|
@@ -273,16 +277,17 @@ public class MidjourneyController {
|
|
|
@NoSubmit
|
|
|
public Result<MidjourneyUserConversation> submitShorten(@RequestBody SubmitShortenDTO submitShortenDTO) {
|
|
|
log.info("提交Shorten任务 提示词:{}",submitShortenDTO.getPrompt());
|
|
|
- MidjourneyUser user = getUser(submitShortenDTO.getMode());
|
|
|
- Long num = checkUserLimit(user);
|
|
|
+ Integer mode = submitShortenDTO.getMode();
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
+ Long num = checkUserLimit(user,mode);
|
|
|
if (num != null && num < 0){
|
|
|
throw BusinessRuntimeException.getInstance("次数已用完");
|
|
|
}
|
|
|
MidjourneyUserConversation conversation;
|
|
|
try {
|
|
|
- conversation = midjourneyService.submitShorten(user, submitShortenDTO.getBotType(), submitShortenDTO.getPrompt());
|
|
|
+ conversation = midjourneyService.submitShorten(user, mode, submitShortenDTO.getBotType(), submitShortenDTO.getPrompt());
|
|
|
} catch (Exception e) {
|
|
|
- recoverUserLimit(user.getId(), user.getMode(),num);
|
|
|
+ recoverUserLimit(user.getId(),mode,num);
|
|
|
throw BusinessRuntimeException.getInstance(e.getMessage());
|
|
|
}
|
|
|
//syncUser(user.getId(), user.getMode(), num);
|
|
|
@@ -296,19 +301,24 @@ public class MidjourneyController {
|
|
|
@NoSubmit
|
|
|
public Result<Object> action(@RequestBody SubmitActionDTO actionDTO) {
|
|
|
log.info("任务id:{},执行动作:{}",actionDTO.getTaskId(),actionDTO.getCustomId());
|
|
|
- MidjourneyUser user = getUser(actionDTO.getMode());
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
+ MidjourneyUserConversation midjourneyUserConversation = conversationMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUserConversation.class).eq(MidjourneyUserConversation::getTaskId, actionDTO.getTaskId()).last("limit 1"));
|
|
|
+ if (midjourneyUserConversation == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("关联任务不存在或已失效");
|
|
|
+ }
|
|
|
+ Integer mode = midjourneyUserConversation.getMode();
|
|
|
Long num = 0L;
|
|
|
if (!actionDTO.getCustomId().contains("BOOKMARK")) {
|
|
|
- num = checkUserLimit(user);
|
|
|
+ num = checkUserLimit(user,mode);
|
|
|
if (num != null && num < 0) {
|
|
|
throw BusinessRuntimeException.getInstance("次数已用完");
|
|
|
}
|
|
|
}
|
|
|
Object conversation;
|
|
|
try {
|
|
|
- conversation = midjourneyService.submitAction(user, actionDTO.getTaskId(), actionDTO.getCustomId(),num, actionDTO.getBotType());
|
|
|
+ conversation = midjourneyService.submitAction(user,midjourneyUserConversation,mode, actionDTO.getTaskId(), actionDTO.getCustomId(),num, actionDTO.getBotType());
|
|
|
} catch (Exception e) {
|
|
|
- recoverUserLimit(user.getId(), user.getMode(),num);
|
|
|
+ recoverUserLimit(user.getId(), mode,num);
|
|
|
throw BusinessRuntimeException.getInstance(e.getMessage());
|
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(conversation);
|
|
|
@@ -320,17 +330,17 @@ public class MidjourneyController {
|
|
|
@NoSubmit
|
|
|
public Result<Object> seed(@RequestBody SubmitSeedDTO seedDTO) {
|
|
|
log.info("任务id:{},执行动作:{}",seedDTO.getTaskId(), "seed");
|
|
|
- MidjourneyUser user = getUser(seedDTO.getMode());
|
|
|
-
|
|
|
- Long num = checkUserLimit(user);
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
+ Integer mode = seedDTO.getMode();
|
|
|
+ Long num = checkUserLimit(user,mode);
|
|
|
if (num != null && num < 0) {
|
|
|
throw BusinessRuntimeException.getInstance("次数已用完");
|
|
|
}
|
|
|
Object conversation;
|
|
|
try {
|
|
|
- conversation = midjourneyService.submitSeed(user, seedDTO.getTaskId(), seedDTO.getBotType());
|
|
|
+ conversation = midjourneyService.submitSeed(user, mode, seedDTO.getTaskId(), seedDTO.getBotType());
|
|
|
} catch (Exception e) {
|
|
|
- recoverUserLimit(user.getId(), user.getMode(),num);
|
|
|
+ recoverUserLimit(user.getId(), mode,num);
|
|
|
throw BusinessRuntimeException.getInstance(e.getMessage());
|
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(conversation);
|
|
|
@@ -342,7 +352,7 @@ public class MidjourneyController {
|
|
|
*/
|
|
|
@GetMapping("/conversation/list")
|
|
|
public Result<SearchResult<MidjourneyUserConversation>> conversationList(){
|
|
|
- MidjourneyUser user = getUser(null);
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
log.info("查询会话列表 userId:{}",user.getId());
|
|
|
MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(beanSearcher.search(MidjourneyUserConversation.class,
|
|
|
@@ -356,7 +366,7 @@ public class MidjourneyController {
|
|
|
*/
|
|
|
@GetMapping("/conversation/listByIds")
|
|
|
public Result<List<MidjourneyUserConversation>> conversationListByIds(Integer mode,@RequestParam(value = "ids" ) List<Long> ids) throws Exception {
|
|
|
- MidjourneyUser user = getUser(mode);
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
log.info("根据ids查询会话 userId:{}",user.getId());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyService.listConversationByIds(mode,ids));
|
|
|
}
|
|
|
@@ -367,7 +377,7 @@ public class MidjourneyController {
|
|
|
@PostMapping("/conversation/{id}/cancel")
|
|
|
@NoSubmit
|
|
|
public Result<MidjourneyUserConversation> conversationCancel(@PathVariable("id") Long id){
|
|
|
- MidjourneyUser user = getUser(null);
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
log.info("取消任务 id:{}",id);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyService.cancelConversation(user,id));
|
|
|
}
|
|
|
@@ -383,7 +393,7 @@ public class MidjourneyController {
|
|
|
if (midjourneyUser == null) {
|
|
|
throw BusinessRuntimeException.getInstance("参数错误");
|
|
|
}
|
|
|
- midjourneyUser.setMode(mode);
|
|
|
+ //midjourneyUser.setMode(mode);
|
|
|
midjourneyUserMapper.updateById(midjourneyUser);
|
|
|
//redisService.del(RedisService.key.MIDJOURNEY_USER.getName() + midjourneyUser.getUserToken());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
@@ -429,7 +439,7 @@ public class MidjourneyController {
|
|
|
*/
|
|
|
@GetMapping("/get/painting/record")
|
|
|
public Result<SearchResult<MidjourneyUserPaintingDayRecordView>> getPaintingRecord(String prompt, Boolean bookmark) {
|
|
|
- MidjourneyUser user = getUser(null);
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
String condition = String.format(" and mc.user_id = %s", user.getId());
|
|
|
if (StrUtil.isNotBlank(prompt)) {
|
|
|
condition += String.format(" and mc.prompt like '%%%s%%'", prompt);
|