|
|
@@ -1,6 +1,7 @@
|
|
|
package com.cyksj.service.midjourney.impl;
|
|
|
|
|
|
import cn.hutool.core.lang.UUID;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
@@ -8,6 +9,7 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
+import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.mapper.*;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
@@ -17,6 +19,7 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.imageio.stream.FileImageOutputStream;
|
|
|
import java.io.IOException;
|
|
|
@@ -50,7 +53,8 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
|
|
|
private final MidjourneyUserMapper midjourneyUserMapper;
|
|
|
|
|
|
@Override
|
|
|
- public void addAccount(MidjourneyAccount midjourneyAccount) {
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
+ public void addAccount(MidjourneyAccount midjourneyAccount) throws Exception {
|
|
|
baseMapper.insert(midjourneyAccount);
|
|
|
addAcount(midjourneyAccount);
|
|
|
//拉取plus服务账号实例id
|
|
|
@@ -60,6 +64,7 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
public void removeAccount(Long id) {
|
|
|
MidjourneyAccount midjourneyAccount = baseMapper.selectById(id);
|
|
|
if (midjourneyAccount == null) {
|
|
|
@@ -71,6 +76,7 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
public void updateAccount(MidjourneyAccount midjourneyAccount) {
|
|
|
baseMapper.updateById(midjourneyAccount);
|
|
|
updAccount(midjourneyAccount);
|
|
|
@@ -97,9 +103,10 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
|
|
|
baseMapper.updateById(midjourneyAccount);
|
|
|
}
|
|
|
|
|
|
- private void addAcount(MidjourneyAccount midjourneyAccount) {
|
|
|
+
|
|
|
+ private void addAcount(MidjourneyAccount midjourneyAccount) throws Exception {
|
|
|
Map<String, Object> accountParam = createAccountParam(midjourneyAccount);
|
|
|
- String body = HttpUtil.post(HOST + "/mj/account/create", accountParam);
|
|
|
+ String body = HttpRequest.post(HOST + "/mj/account/create").body(Jsons.toJson(accountParam)).execute().body();
|
|
|
log.info("addAccount body:{}", body);
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(body);
|
|
|
if (jsonObject.getInt("code") != 1) {
|
|
|
@@ -125,14 +132,10 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Long getAccount(Long id) {
|
|
|
- String body = HttpRequest.post(HOST + "/mj/account/query").form("remark",id).execute().body();
|
|
|
+ private Long getAccount(Long id) throws Exception {
|
|
|
+ String body = HttpRequest.post(HOST + "/mj/account/query").body(Jsons.toJson(MapUtil.of("remark", id))).execute().body();
|
|
|
log.info("getAccount body:{}", body);
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(body);
|
|
|
- if (jsonObject.getInt("code") != 1) {
|
|
|
- throw BusinessRuntimeException.getInstance("getAccount error message:" + jsonObject.getStr("description"));
|
|
|
- }
|
|
|
-
|
|
|
return JSONUtil.parseObj(JSONUtil.parseArray(jsonObject.getStr("content")).get(0)).get("id", Long.class);
|
|
|
}
|
|
|
|