|
@@ -1,326 +1,326 @@
|
|
|
-package com.backendsys.service.Ai.Aizn;
|
|
|
-
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.json.JSONObject;
|
|
|
-import cn.hutool.json.JSONUtil;
|
|
|
-import com.backendsys.aspect.HttpRequestAspect;
|
|
|
-import com.backendsys.exception.CustException;
|
|
|
-import com.backendsys.modules.common.config.redis.utils.RedisUtil;
|
|
|
-import com.backendsys.entity.Ai.Aizn.AiznImageStyleDTO;
|
|
|
-import com.backendsys.entity.Ai.Aizn.AiznIntelligentClipTaskDTO;
|
|
|
-import com.backendsys.entity.Ai.Aizn.AiznImageTaskVO;
|
|
|
-import com.backendsys.entity.Ai.Aizn.AiznInteractClipTask.AiznInteractClipTaskDTO;
|
|
|
-import com.backendsys.entity.Ai.Aizn.AiznModel.AiznModelTaskDTO;
|
|
|
-import com.backendsys.mapper.Ai.Aizn.AiznImageTaskMapper;
|
|
|
-import com.backendsys.service.SDKService.SDKTencent.SDKTencentCOSService;
|
|
|
-import com.backendsys.service.System.SysResourceService;
|
|
|
-import com.backendsys.utils.ListUtil;
|
|
|
-import com.backendsys.utils.MapUtil;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.fzzixun.openapi.sdk.client.OpenClient;
|
|
|
-import com.fzzixun.openapi.sdk.common.RequestMethod;
|
|
|
-import com.fzzixun.openapi.sdk.request.CommonRequest;
|
|
|
-import com.fzzixun.openapi.sdk.response.CommonResponse;
|
|
|
-import org.redisson.api.RLock;
|
|
|
-import org.redisson.api.RedissonClient;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.annotation.Lazy;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-@Service
|
|
|
-public class AiznModelServiceImpl implements AiznModelService {
|
|
|
-
|
|
|
- @Lazy
|
|
|
- @Autowired
|
|
|
- RedissonClient redissonClient;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private HttpRequestAspect httpRequestAspect;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private AiznService aiznService;
|
|
|
- @Autowired
|
|
|
- private AiznImageTaskMapper aiznImageTaskMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SysResourceService sysResourceService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SDKTencentCOSService sdkTencentCOSService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private RedisUtil redisUtil;
|
|
|
-
|
|
|
- /**
|
|
|
- * [紫鸟] 获取风格/场景配置数据 (https://open.ziniao.com/manage/apiTest/809)
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Map<String, Object> getImageStyle(AiznImageStyleDTO aiznImageStyleDTO) {
|
|
|
-
|
|
|
- Integer type = aiznImageStyleDTO.getType();
|
|
|
-
|
|
|
- // -- 业务参数 -------------------------------------------------------------------
|
|
|
- JSONObject object = new JSONObject();
|
|
|
- object.set("showType", aiznImageStyleDTO.getShow_type()); // 展示类型 0.默认
|
|
|
- object.set("type", type); // 类型 1.AI绘图
|
|
|
-
|
|
|
- String redisKey = "getImageStyle-" + type;
|
|
|
- String redisCacheObject = redisUtil.getCacheObject(redisKey);
|
|
|
- if (StrUtil.isNotEmpty(redisCacheObject)) {
|
|
|
- // [缓存存在] 读取缓存
|
|
|
- Map<String, Object> result = new LinkedHashMap<>();
|
|
|
- try {
|
|
|
- System.out.println("[缓存存在] 读取缓存");
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- List<Map<String, Object>> respData = mapper.readValue(redisCacheObject, List.class);
|
|
|
- result.put("type", type);
|
|
|
- result.put("total", respData.size());
|
|
|
- result.put("list", ListUtil.convertToUnderscoreCase(respData)); // 将返回结果:首字母大写命名 转换为 下划线命名
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return result;
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- // -- 实现方法 -------------------------------------------------------------------
|
|
|
- OpenClient client = aiznService.getOpenClient();
|
|
|
- CommonRequest request = new CommonRequest("/linkfox-ai/image/v1/make/style", RequestMethod.POST_JSON);
|
|
|
- request.setBizContent(object.toString());
|
|
|
-
|
|
|
- // -- 返回结果 -------------------------------------------------------------------
|
|
|
- CommonResponse response = client.executeAppToken(request, aiznService.getAppToken());
|
|
|
- JSONObject resp = aiznService.checkResponse(response);
|
|
|
- if ((Integer) resp.get("code") == 200) {
|
|
|
-
|
|
|
- // -- 成功 ------------------------------------------------------------------
|
|
|
- List<Map<String, Object>> respData = (List<Map<String, Object>>) resp.get("data");
|
|
|
- Map<String, Object> result = new LinkedHashMap<>();
|
|
|
- result.put("type", type);
|
|
|
- result.put("total", respData.size());
|
|
|
- result.put("list", ListUtil.convertToUnderscoreCase(respData)); // 将返回结果:首字母大写命名 转换为 下划线命名
|
|
|
-
|
|
|
- // [缓存不存在] 加入缓存
|
|
|
- try {
|
|
|
- System.out.println("[缓存不存在] 加入缓存 (30秒过期)");
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- String respDataStr = mapper.writeValueAsString(respData);
|
|
|
- System.out.println(respDataStr);
|
|
|
- redisUtil.setCacheObject(redisKey, respDataStr, 30, TimeUnit.SECONDS);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- // --------------------------------------------------------------------------
|
|
|
-
|
|
|
- } else {
|
|
|
- System.out.println(resp);
|
|
|
- Integer code = resp.get("code") != null ? (Integer) resp.get("code") : 6001;
|
|
|
- throw new CustException("功能暂不可用,请联系管理员", code, resp);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * [紫鸟] 智能抠图 (发起任务) (创建任务记录) (扣积分)
|
|
|
- * (智能抠图:https://open.ziniao.com/manage/apiTest/810)
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Map<String, Object> makeIntelligentClipTask(AiznIntelligentClipTaskDTO aiznIntelligentClipTaskDTO) {
|
|
|
-
|
|
|
- RLock lock = redissonClient.getLock("makeModelTask");
|
|
|
- try { lock.tryLock(3, TimeUnit.SECONDS);
|
|
|
-
|
|
|
- // -- 业务参数 -------------------------------------------------------------------
|
|
|
- JSONObject object = new JSONObject();
|
|
|
- object.set("imageUrl", aiznIntelligentClipTaskDTO.getImage_url()); // 图片
|
|
|
- object.set("subType", aiznIntelligentClipTaskDTO.getSub_type()); // 子类型,1:通用,2:人像,3:商品 9:服饰
|
|
|
- object.set("outputNum", 1); // 输出张数,固定 1
|
|
|
-
|
|
|
- // -- 实现方法 -------------------------------------------------------------------
|
|
|
- OpenClient client = aiznService.getOpenClient();
|
|
|
- CommonRequest request = new CommonRequest("/linkfox-ai/image/v1/make/create/3", RequestMethod.POST_JSON);
|
|
|
- request.setBizContent(object.toString());
|
|
|
-
|
|
|
- // -- 返回结果 -------------------------------------------------------------------
|
|
|
- CommonResponse response = client.executeAppToken(request, aiznService.getAppToken());
|
|
|
- JSONObject resp = aiznService.checkResponse(response);
|
|
|
- if ((Integer) resp.get("code") == 200) {
|
|
|
-
|
|
|
- // -- 成功 ------------------------------------------------------------------
|
|
|
- Map<String, Object> respData = (Map<String, Object>) resp.get("data");
|
|
|
- System.out.println(respData);
|
|
|
-
|
|
|
- // -- 将制作结果插入到数据表 -----------------------------------------------------
|
|
|
- AiznImageTaskVO vo = new AiznImageTaskVO();
|
|
|
- vo.setTask_id((String) respData.get("id"));
|
|
|
- vo.setUser_id(httpRequestAspect.getUserId());
|
|
|
- vo.setTask_type("INTELLIGENT_CLIP");
|
|
|
- vo.setImage_url((String) respData.get("imageUrl"));
|
|
|
- vo.setTask_submit_json(JSONUtil.toJsonStr(respData));
|
|
|
- aiznImageTaskMapper.insertAiznImageTask(vo);
|
|
|
- // --------------------------------------------------------------------------
|
|
|
-
|
|
|
- // -- 扣除对应的本地积分 (ZnModel, IntelligentClip, 智能抠图) --------------------
|
|
|
- sysResourceService.consumptionPoint("ZnModel", "IntelligentClip", null);
|
|
|
-
|
|
|
- return MapUtil.convertToUnderscoreCase(respData);
|
|
|
- // --------------------------------------------------------------------------
|
|
|
-
|
|
|
- } else {
|
|
|
- System.out.println(resp);
|
|
|
- Integer code = resp.get("code") != null ? (Integer) resp.get("code") : 6001;
|
|
|
- throw new CustException("功能暂不可用,请联系管理员", code, resp);
|
|
|
- }
|
|
|
-
|
|
|
- } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
|
- } finally { lock.unlock(); }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * [紫鸟] 交互抠图 (直接返回结果)
|
|
|
- * (交互抠图:https://open.ziniao.com/manage/apiTest/838)
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Map<String, Object> makeInteractClipTask(AiznInteractClipTaskDTO aiznInteractClipTaskDTO) {
|
|
|
-
|
|
|
- RLock lock = redissonClient.getLock("makeInteractClipTask");
|
|
|
- try { lock.tryLock(3, TimeUnit.SECONDS);
|
|
|
-
|
|
|
- // -- 业务参数 -------------------------------------------------------------------
|
|
|
- JSONObject object = new JSONObject();
|
|
|
- object.set("imageUrl", aiznInteractClipTaskDTO.getImage_url()); // 原图
|
|
|
-
|
|
|
- // [参数命名转换] 下划线 转 小驼峰
|
|
|
- List<Map<String, Object>> pointList = aiznInteractClipTaskDTO.getPoint_list().stream().map(point -> {
|
|
|
- Map<String, Object> map = new LinkedHashMap<>();
|
|
|
- map.put("x", point.getX());
|
|
|
- map.put("y", point.getY());
|
|
|
- map.put("isSelect", point.getIs_select());
|
|
|
- return map;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- // 点位操作列表
|
|
|
- object.set("pointList", pointList);
|
|
|
-
|
|
|
- object.set("scoreUrl", aiznInteractClipTaskDTO.getScore_url()); // 概率图
|
|
|
- object.set("featureUrl", aiznInteractClipTaskDTO.getFeature_url()); // 全局分割图
|
|
|
-
|
|
|
- // -- 实现方法 -------------------------------------------------------------------
|
|
|
- OpenClient client = aiznService.getOpenClient();
|
|
|
- CommonRequest request = new CommonRequest("/linkfox-ai/image/v1/make/process/interactCutout", RequestMethod.POST_JSON);
|
|
|
- request.setBizContent(object.toString());
|
|
|
-
|
|
|
- // -- 返回结果 -------------------------------------------------------------------
|
|
|
- CommonResponse response = client.executeAppToken(request, aiznService.getAppToken());
|
|
|
- JSONObject resp = aiznService.checkResponse(response);
|
|
|
- if ((Integer) resp.get("code") == 200) {
|
|
|
-
|
|
|
- // -- 成功 ------------------------------------------------------------------
|
|
|
- Map<String, Object> respData = (Map<String, Object>) resp.get("data");
|
|
|
- System.out.println(respData);
|
|
|
-
|
|
|
- return MapUtil.convertToUnderscoreCase(respData);
|
|
|
- // --------------------------------------------------------------------------
|
|
|
-
|
|
|
- } else {
|
|
|
- System.out.println(resp);
|
|
|
- Integer code = resp.get("code") != null ? (Integer) resp.get("code") : 6001;
|
|
|
- throw new CustException("功能暂不可用,请联系管理员", code, resp);
|
|
|
- }
|
|
|
-
|
|
|
- } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
|
- } finally { lock.unlock(); }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * [紫鸟] AI换模特 (发起任务) (创建任务记录) (扣积分)
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Map<String, Object> makeModelTask(AiznModelTaskDTO aiznModelTaskDTO) {
|
|
|
-
|
|
|
- RLock lock = redissonClient.getLock("makeModelTask");
|
|
|
- try { lock.tryLock(3, TimeUnit.SECONDS);
|
|
|
-
|
|
|
-// // 自定义描述时 scene 字段不能跟 style 字段共存,
|
|
|
-// if (aiznModelTaskDTO.getStyle() != null && aiznModelTaskDTO.getExtend_fields().getScene() != null) {
|
|
|
-// throw new CustException("自定义描述时,style 与 extend_fields.scene 不能共存");
|
|
|
+//package com.backendsys.service.Ai.Aizn;
|
|
|
+//
|
|
|
+//import cn.hutool.core.util.StrUtil;
|
|
|
+//import cn.hutool.json.JSONObject;
|
|
|
+//import cn.hutool.json.JSONUtil;
|
|
|
+//import com.backendsys.aspect.HttpRequestAspect;
|
|
|
+//import com.backendsys.exception.CustException;
|
|
|
+//import com.backendsys.modules.common.config.redis.utils.RedisUtil;
|
|
|
+//import com.backendsys.entity.Ai.Aizn.AiznImageStyleDTO;
|
|
|
+//import com.backendsys.entity.Ai.Aizn.AiznIntelligentClipTaskDTO;
|
|
|
+//import com.backendsys.entity.Ai.Aizn.AiznImageTaskVO;
|
|
|
+//import com.backendsys.entity.Ai.Aizn.AiznInteractClipTask.AiznInteractClipTaskDTO;
|
|
|
+//import com.backendsys.entity.Ai.Aizn.AiznModel.AiznModelTaskDTO;
|
|
|
+//import com.backendsys.mapper.Ai.Aizn.AiznImageTaskMapper;
|
|
|
+//import com.backendsys.service.SDKService.SDKTencent.SDKTencentCOSService;
|
|
|
+//import com.backendsys.service.System.SysResourceService;
|
|
|
+//import com.backendsys.utils.ListUtil;
|
|
|
+//import com.backendsys.utils.MapUtil;
|
|
|
+//import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+//import com.fzzixun.openapi.sdk.client.OpenClient;
|
|
|
+//import com.fzzixun.openapi.sdk.common.RequestMethod;
|
|
|
+//import com.fzzixun.openapi.sdk.request.CommonRequest;
|
|
|
+//import com.fzzixun.openapi.sdk.response.CommonResponse;
|
|
|
+//import org.redisson.api.RLock;
|
|
|
+//import org.redisson.api.RedissonClient;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.context.annotation.Lazy;
|
|
|
+//import org.springframework.stereotype.Service;
|
|
|
+//
|
|
|
+//import java.util.LinkedHashMap;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.Map;
|
|
|
+//import java.util.concurrent.TimeUnit;
|
|
|
+//import java.util.stream.Collectors;
|
|
|
+//
|
|
|
+//@Service
|
|
|
+//public class AiznModelServiceImpl implements AiznModelService {
|
|
|
+//
|
|
|
+// @Lazy
|
|
|
+// @Autowired
|
|
|
+// RedissonClient redissonClient;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private HttpRequestAspect httpRequestAspect;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private AiznService aiznService;
|
|
|
+// @Autowired
|
|
|
+// private AiznImageTaskMapper aiznImageTaskMapper;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private SysResourceService sysResourceService;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private SDKTencentCOSService sdkTencentCOSService;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private RedisUtil redisUtil;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * [紫鸟] 获取风格/场景配置数据 (https://open.ziniao.com/manage/apiTest/809)
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public Map<String, Object> getImageStyle(AiznImageStyleDTO aiznImageStyleDTO) {
|
|
|
+//
|
|
|
+// Integer type = aiznImageStyleDTO.getType();
|
|
|
+//
|
|
|
+// // -- 业务参数 -------------------------------------------------------------------
|
|
|
+// JSONObject object = new JSONObject();
|
|
|
+// object.set("showType", aiznImageStyleDTO.getShow_type()); // 展示类型 0.默认
|
|
|
+// object.set("type", type); // 类型 1.AI绘图
|
|
|
+//
|
|
|
+// String redisKey = "getImageStyle-" + type;
|
|
|
+// String redisCacheObject = redisUtil.getCacheObject(redisKey);
|
|
|
+// if (StrUtil.isNotEmpty(redisCacheObject)) {
|
|
|
+// // [缓存存在] 读取缓存
|
|
|
+// Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+// try {
|
|
|
+// System.out.println("[缓存存在] 读取缓存");
|
|
|
+// ObjectMapper mapper = new ObjectMapper();
|
|
|
+// List<Map<String, Object>> respData = mapper.readValue(redisCacheObject, List.class);
|
|
|
+// result.put("type", type);
|
|
|
+// result.put("total", respData.size());
|
|
|
+// result.put("list", ListUtil.convertToUnderscoreCase(respData)); // 将返回结果:首字母大写命名 转换为 下划线命名
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
// }
|
|
|
-
|
|
|
- // -- 业务参数 -------------------------------------------------------------------
|
|
|
- JSONObject object = new JSONObject();
|
|
|
- object.set("imageUrl", aiznModelTaskDTO.getImage_url()); // 原图
|
|
|
- object.set("style", aiznModelTaskDTO.getStyle()); // 模特类型 与自定义模特头部图必填其一 预设值 调用风格接口 type = 6
|
|
|
- object.set("outputNum", aiznModelTaskDTO.getOutput_num()); // 数量 (1~4)
|
|
|
-
|
|
|
- Map<String, Object> extendFields = new LinkedHashMap<>();
|
|
|
- extendFields.put("imageSegUrl", aiznModelTaskDTO.getExtend_fields().getImage_seg_url());
|
|
|
- extendFields.put("imageSegSubType", aiznModelTaskDTO.getExtend_fields().getImage_seg_subtype());
|
|
|
- extendFields.put("scene", aiznModelTaskDTO.getExtend_fields().getScene());
|
|
|
- extendFields.put("modelPrompt", aiznModelTaskDTO.getExtend_fields().getModel_prompt());
|
|
|
-
|
|
|
- Map<String, Object> customModel = new LinkedHashMap<>();
|
|
|
-
|
|
|
- if (aiznModelTaskDTO.getExtend_fields().getCustom_model() != null) {
|
|
|
- customModel.put("modelHeadImageUrl", aiznModelTaskDTO.getExtend_fields().getCustom_model().getModel_head_image_url());
|
|
|
- }
|
|
|
- extendFields.put("customModel", customModel);
|
|
|
-
|
|
|
- object.set("extendFields", extendFields);
|
|
|
-
|
|
|
- System.out.println("Params:");
|
|
|
- System.out.println(object.toString());
|
|
|
-
|
|
|
- // -- 实现方法 -------------------------------------------------------------------
|
|
|
- OpenClient client = aiznService.getOpenClient();
|
|
|
- CommonRequest request = new CommonRequest("/linkfox-ai/image/v1/make/create/9", RequestMethod.POST_JSON);
|
|
|
-
|
|
|
- request.setBizContent(object.toString());
|
|
|
-
|
|
|
- // -- 返回结果 -------------------------------------------------------------------
|
|
|
- CommonResponse response = client.executeAppToken(request, aiznService.getAppToken());
|
|
|
- JSONObject resp = aiznService.checkResponse(response);
|
|
|
- if ((Integer) resp.get("code") == 200) {
|
|
|
-
|
|
|
- // -- 成功 ------------------------------------------------------------------
|
|
|
- Map<String, Object> respData = (Map<String, Object>) resp.get("data");
|
|
|
- System.out.println(respData);
|
|
|
-
|
|
|
- // -- 将制作结果插入到数据表 -----------------------------------------------------
|
|
|
- AiznImageTaskVO vo = new AiznImageTaskVO();
|
|
|
- vo.setTask_id((String) respData.get("id"));
|
|
|
- vo.setUser_id(httpRequestAspect.getUserId());
|
|
|
- vo.setTask_type("MODEL");
|
|
|
- vo.setImage_url((String) respData.get("imageUrl"));
|
|
|
- vo.setTask_submit_json(JSONUtil.toJsonStr(respData));
|
|
|
- aiznImageTaskMapper.insertAiznImageTask(vo);
|
|
|
-
|
|
|
- // -- 消耗积分 (查询对应积分,查询我的积分,更新我的积分,新增积分记录) --------------------------------
|
|
|
- sysResourceService.consumptionPoint("ZnModel", "MakeModel", aiznModelTaskDTO.getOutput_num());
|
|
|
- // -----------------------------------------------------------------------------------------
|
|
|
-
|
|
|
- return MapUtil.convertToUnderscoreCase(respData);
|
|
|
- // --------------------------------------------------------------------------
|
|
|
-
|
|
|
- } else {
|
|
|
- System.out.println(resp);
|
|
|
- Integer code = resp.get("code") != null ? (Integer) resp.get("code") : 6001;
|
|
|
- throw new CustException("功能暂不可用,请联系管理员", code, resp);
|
|
|
- }
|
|
|
-
|
|
|
- } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
|
- } finally { lock.unlock(); }
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+// return result;
|
|
|
+//
|
|
|
+// } else {
|
|
|
+//
|
|
|
+// // -- 实现方法 -------------------------------------------------------------------
|
|
|
+// OpenClient client = aiznService.getOpenClient();
|
|
|
+// CommonRequest request = new CommonRequest("/linkfox-ai/image/v1/make/style", RequestMethod.POST_JSON);
|
|
|
+// request.setBizContent(object.toString());
|
|
|
+//
|
|
|
+// // -- 返回结果 -------------------------------------------------------------------
|
|
|
+// CommonResponse response = client.executeAppToken(request, aiznService.getAppToken());
|
|
|
+// JSONObject resp = aiznService.checkResponse(response);
|
|
|
+// if ((Integer) resp.get("code") == 200) {
|
|
|
+//
|
|
|
+// // -- 成功 ------------------------------------------------------------------
|
|
|
+// List<Map<String, Object>> respData = (List<Map<String, Object>>) resp.get("data");
|
|
|
+// Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+// result.put("type", type);
|
|
|
+// result.put("total", respData.size());
|
|
|
+// result.put("list", ListUtil.convertToUnderscoreCase(respData)); // 将返回结果:首字母大写命名 转换为 下划线命名
|
|
|
+//
|
|
|
+// // [缓存不存在] 加入缓存
|
|
|
+// try {
|
|
|
+// System.out.println("[缓存不存在] 加入缓存 (30秒过期)");
|
|
|
+// ObjectMapper mapper = new ObjectMapper();
|
|
|
+// String respDataStr = mapper.writeValueAsString(respData);
|
|
|
+// System.out.println(respDataStr);
|
|
|
+// redisUtil.setCacheObject(redisKey, respDataStr, 30, TimeUnit.SECONDS);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+//
|
|
|
+// return result;
|
|
|
+// // --------------------------------------------------------------------------
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// System.out.println(resp);
|
|
|
+// Integer code = resp.get("code") != null ? (Integer) resp.get("code") : 6001;
|
|
|
+// throw new CustException("功能暂不可用,请联系管理员", code, resp);
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * [紫鸟] 智能抠图 (发起任务) (创建任务记录) (扣积分)
|
|
|
+// * (智能抠图:https://open.ziniao.com/manage/apiTest/810)
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public Map<String, Object> makeIntelligentClipTask(AiznIntelligentClipTaskDTO aiznIntelligentClipTaskDTO) {
|
|
|
+//
|
|
|
+// RLock lock = redissonClient.getLock("makeModelTask");
|
|
|
+// try { lock.tryLock(3, TimeUnit.SECONDS);
|
|
|
+//
|
|
|
+// // -- 业务参数 -------------------------------------------------------------------
|
|
|
+// JSONObject object = new JSONObject();
|
|
|
+// object.set("imageUrl", aiznIntelligentClipTaskDTO.getImage_url()); // 图片
|
|
|
+// object.set("subType", aiznIntelligentClipTaskDTO.getSub_type()); // 子类型,1:通用,2:人像,3:商品 9:服饰
|
|
|
+// object.set("outputNum", 1); // 输出张数,固定 1
|
|
|
+//
|
|
|
+// // -- 实现方法 -------------------------------------------------------------------
|
|
|
+// OpenClient client = aiznService.getOpenClient();
|
|
|
+// CommonRequest request = new CommonRequest("/linkfox-ai/image/v1/make/create/3", RequestMethod.POST_JSON);
|
|
|
+// request.setBizContent(object.toString());
|
|
|
+//
|
|
|
+// // -- 返回结果 -------------------------------------------------------------------
|
|
|
+// CommonResponse response = client.executeAppToken(request, aiznService.getAppToken());
|
|
|
+// JSONObject resp = aiznService.checkResponse(response);
|
|
|
+// if ((Integer) resp.get("code") == 200) {
|
|
|
+//
|
|
|
+// // -- 成功 ------------------------------------------------------------------
|
|
|
+// Map<String, Object> respData = (Map<String, Object>) resp.get("data");
|
|
|
+// System.out.println(respData);
|
|
|
+//
|
|
|
+// // -- 将制作结果插入到数据表 -----------------------------------------------------
|
|
|
+// AiznImageTaskVO vo = new AiznImageTaskVO();
|
|
|
+// vo.setTask_id((String) respData.get("id"));
|
|
|
+// vo.setUser_id(httpRequestAspect.getUserId());
|
|
|
+// vo.setTask_type("INTELLIGENT_CLIP");
|
|
|
+// vo.setImage_url((String) respData.get("imageUrl"));
|
|
|
+// vo.setTask_submit_json(JSONUtil.toJsonStr(respData));
|
|
|
+// aiznImageTaskMapper.insertAiznImageTask(vo);
|
|
|
+// // --------------------------------------------------------------------------
|
|
|
+//
|
|
|
+// // -- 扣除对应的本地积分 (ZnModel, IntelligentClip, 智能抠图) --------------------
|
|
|
+// sysResourceService.consumptionPoint("ZnModel", "IntelligentClip", null);
|
|
|
+//
|
|
|
+// return MapUtil.convertToUnderscoreCase(respData);
|
|
|
+// // --------------------------------------------------------------------------
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// System.out.println(resp);
|
|
|
+// Integer code = resp.get("code") != null ? (Integer) resp.get("code") : 6001;
|
|
|
+// throw new CustException("功能暂不可用,请联系管理员", code, resp);
|
|
|
+// }
|
|
|
+//
|
|
|
+// } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
|
+// } finally { lock.unlock(); }
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * [紫鸟] 交互抠图 (直接返回结果)
|
|
|
+// * (交互抠图:https://open.ziniao.com/manage/apiTest/838)
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public Map<String, Object> makeInteractClipTask(AiznInteractClipTaskDTO aiznInteractClipTaskDTO) {
|
|
|
+//
|
|
|
+// RLock lock = redissonClient.getLock("makeInteractClipTask");
|
|
|
+// try { lock.tryLock(3, TimeUnit.SECONDS);
|
|
|
+//
|
|
|
+// // -- 业务参数 -------------------------------------------------------------------
|
|
|
+// JSONObject object = new JSONObject();
|
|
|
+// object.set("imageUrl", aiznInteractClipTaskDTO.getImage_url()); // 原图
|
|
|
+//
|
|
|
+// // [参数命名转换] 下划线 转 小驼峰
|
|
|
+// List<Map<String, Object>> pointList = aiznInteractClipTaskDTO.getPoint_list().stream().map(point -> {
|
|
|
+// Map<String, Object> map = new LinkedHashMap<>();
|
|
|
+// map.put("x", point.getX());
|
|
|
+// map.put("y", point.getY());
|
|
|
+// map.put("isSelect", point.getIs_select());
|
|
|
+// return map;
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+// // 点位操作列表
|
|
|
+// object.set("pointList", pointList);
|
|
|
+//
|
|
|
+// object.set("scoreUrl", aiznInteractClipTaskDTO.getScore_url()); // 概率图
|
|
|
+// object.set("featureUrl", aiznInteractClipTaskDTO.getFeature_url()); // 全局分割图
|
|
|
+//
|
|
|
+// // -- 实现方法 -------------------------------------------------------------------
|
|
|
+// OpenClient client = aiznService.getOpenClient();
|
|
|
+// CommonRequest request = new CommonRequest("/linkfox-ai/image/v1/make/process/interactCutout", RequestMethod.POST_JSON);
|
|
|
+// request.setBizContent(object.toString());
|
|
|
+//
|
|
|
+// // -- 返回结果 -------------------------------------------------------------------
|
|
|
+// CommonResponse response = client.executeAppToken(request, aiznService.getAppToken());
|
|
|
+// JSONObject resp = aiznService.checkResponse(response);
|
|
|
+// if ((Integer) resp.get("code") == 200) {
|
|
|
+//
|
|
|
+// // -- 成功 ------------------------------------------------------------------
|
|
|
+// Map<String, Object> respData = (Map<String, Object>) resp.get("data");
|
|
|
+// System.out.println(respData);
|
|
|
+//
|
|
|
+// return MapUtil.convertToUnderscoreCase(respData);
|
|
|
+// // --------------------------------------------------------------------------
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// System.out.println(resp);
|
|
|
+// Integer code = resp.get("code") != null ? (Integer) resp.get("code") : 6001;
|
|
|
+// throw new CustException("功能暂不可用,请联系管理员", code, resp);
|
|
|
+// }
|
|
|
+//
|
|
|
+// } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
|
+// } finally { lock.unlock(); }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * [紫鸟] AI换模特 (发起任务) (创建任务记录) (扣积分)
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public Map<String, Object> makeModelTask(AiznModelTaskDTO aiznModelTaskDTO) {
|
|
|
+//
|
|
|
+// RLock lock = redissonClient.getLock("makeModelTask");
|
|
|
+// try { lock.tryLock(3, TimeUnit.SECONDS);
|
|
|
+//
|
|
|
+//// // 自定义描述时 scene 字段不能跟 style 字段共存,
|
|
|
+//// if (aiznModelTaskDTO.getStyle() != null && aiznModelTaskDTO.getExtend_fields().getScene() != null) {
|
|
|
+//// throw new CustException("自定义描述时,style 与 extend_fields.scene 不能共存");
|
|
|
+//// }
|
|
|
+//
|
|
|
+// // -- 业务参数 -------------------------------------------------------------------
|
|
|
+// JSONObject object = new JSONObject();
|
|
|
+// object.set("imageUrl", aiznModelTaskDTO.getImage_url()); // 原图
|
|
|
+// object.set("style", aiznModelTaskDTO.getStyle()); // 模特类型 与自定义模特头部图必填其一 预设值 调用风格接口 type = 6
|
|
|
+// object.set("outputNum", aiznModelTaskDTO.getOutput_num()); // 数量 (1~4)
|
|
|
+//
|
|
|
+// Map<String, Object> extendFields = new LinkedHashMap<>();
|
|
|
+// extendFields.put("imageSegUrl", aiznModelTaskDTO.getExtend_fields().getImage_seg_url());
|
|
|
+// extendFields.put("imageSegSubType", aiznModelTaskDTO.getExtend_fields().getImage_seg_subtype());
|
|
|
+// extendFields.put("scene", aiznModelTaskDTO.getExtend_fields().getScene());
|
|
|
+// extendFields.put("modelPrompt", aiznModelTaskDTO.getExtend_fields().getModel_prompt());
|
|
|
+//
|
|
|
+// Map<String, Object> customModel = new LinkedHashMap<>();
|
|
|
+//
|
|
|
+// if (aiznModelTaskDTO.getExtend_fields().getCustom_model() != null) {
|
|
|
+// customModel.put("modelHeadImageUrl", aiznModelTaskDTO.getExtend_fields().getCustom_model().getModel_head_image_url());
|
|
|
+// }
|
|
|
+// extendFields.put("customModel", customModel);
|
|
|
+//
|
|
|
+// object.set("extendFields", extendFields);
|
|
|
+//
|
|
|
+// System.out.println("Params:");
|
|
|
+// System.out.println(object.toString());
|
|
|
+//
|
|
|
+// // -- 实现方法 -------------------------------------------------------------------
|
|
|
+// OpenClient client = aiznService.getOpenClient();
|
|
|
+// CommonRequest request = new CommonRequest("/linkfox-ai/image/v1/make/create/9", RequestMethod.POST_JSON);
|
|
|
+//
|
|
|
+// request.setBizContent(object.toString());
|
|
|
+//
|
|
|
+// // -- 返回结果 -------------------------------------------------------------------
|
|
|
+// CommonResponse response = client.executeAppToken(request, aiznService.getAppToken());
|
|
|
+// JSONObject resp = aiznService.checkResponse(response);
|
|
|
+// if ((Integer) resp.get("code") == 200) {
|
|
|
+//
|
|
|
+// // -- 成功 ------------------------------------------------------------------
|
|
|
+// Map<String, Object> respData = (Map<String, Object>) resp.get("data");
|
|
|
+// System.out.println(respData);
|
|
|
+//
|
|
|
+// // -- 将制作结果插入到数据表 -----------------------------------------------------
|
|
|
+// AiznImageTaskVO vo = new AiznImageTaskVO();
|
|
|
+// vo.setTask_id((String) respData.get("id"));
|
|
|
+// vo.setUser_id(httpRequestAspect.getUserId());
|
|
|
+// vo.setTask_type("MODEL");
|
|
|
+// vo.setImage_url((String) respData.get("imageUrl"));
|
|
|
+// vo.setTask_submit_json(JSONUtil.toJsonStr(respData));
|
|
|
+// aiznImageTaskMapper.insertAiznImageTask(vo);
|
|
|
+//
|
|
|
+// // -- 消耗积分 (查询对应积分,查询我的积分,更新我的积分,新增积分记录) --------------------------------
|
|
|
+// sysResourceService.consumptionPoint("ZnModel", "MakeModel", aiznModelTaskDTO.getOutput_num());
|
|
|
+// // -----------------------------------------------------------------------------------------
|
|
|
+//
|
|
|
+// return MapUtil.convertToUnderscoreCase(respData);
|
|
|
+// // --------------------------------------------------------------------------
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// System.out.println(resp);
|
|
|
+// Integer code = resp.get("code") != null ? (Integer) resp.get("code") : 6001;
|
|
|
+// throw new CustException("功能暂不可用,请联系管理员", code, resp);
|
|
|
+// }
|
|
|
+//
|
|
|
+// } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
|
+// } finally { lock.unlock(); }
|
|
|
+// }
|
|
|
+//
|
|
|
+//}
|