diff --git a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java index df7d8677..98cd0f4f 100644 --- a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java +++ b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java @@ -7,6 +7,7 @@ import com.ai.da.mapper.primary.*; import com.ai.da.mapper.primary.entity.*; import com.ai.da.mapper.secondary.AttributeRetrievalMapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; @@ -31,7 +32,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; - +@Slf4j @Component public class MyTaskScheduler { diff --git a/src/main/java/com/ai/da/common/utils/RedisUtil.java b/src/main/java/com/ai/da/common/utils/RedisUtil.java index 66ba1ab3..f1a1c0be 100644 --- a/src/main/java/com/ai/da/common/utils/RedisUtil.java +++ b/src/main/java/com/ai/da/common/utils/RedisUtil.java @@ -240,4 +240,13 @@ public class RedisUtil { return redisTemplate.opsForValue().increment(key, 0); } + public final static String MOODBOARD_POSITION_KEY = "moodboard:position:"; + + public void saveMoodboardPosition(Long id, String moodboardPosition) { + addToString(MOODBOARD_POSITION_KEY + id, moodboardPosition); + } + + public String getMoodboardPosition(Long id) { + return getFromString(MOODBOARD_POSITION_KEY + id); + } } diff --git a/src/main/java/com/ai/da/controller/DesignController.java b/src/main/java/com/ai/da/controller/DesignController.java index 87fe11a6..2ea463c1 100644 --- a/src/main/java/com/ai/da/controller/DesignController.java +++ b/src/main/java/com/ai/da/controller/DesignController.java @@ -73,8 +73,8 @@ public class DesignController { @ApiOperation(value = "sketchBoard upload generate design前裁剪") @PostMapping("/sketchBoardsBoundingBox") - public Response> sketchesBoundingBox(@Valid @RequestBody SketchesBoundingBoxDTO sketchesBoundingBoxDTO) { - return Response.success(designService.sketchesBoundingBox(sketchesBoundingBoxDTO)); + public Response> sketchesBoundingBox(@Valid @RequestBody ReDesignCollectionDTO reDesignCollectionDTO) { + return Response.success(designService.sketchesBoundingBox(reDesignCollectionDTO)); } @ApiOperation(value = "通过designItemId获取模特图") diff --git a/src/main/java/com/ai/da/controller/ThirdPartyController.java b/src/main/java/com/ai/da/controller/ThirdPartyController.java index 1f4f64c3..0e7f95fd 100644 --- a/src/main/java/com/ai/da/controller/ThirdPartyController.java +++ b/src/main/java/com/ai/da/controller/ThirdPartyController.java @@ -107,4 +107,11 @@ public class ThirdPartyController { public Response getRedirectUrl() { return Response.success(REDIRECT_URL); } + + @CrossOrigin + @ApiOperation(value = "updateNoLoginRequiredNew") + @PostMapping("/updateNoLoginRequiredNew") + public Response updateNoLoginRequiredNew(@RequestBody NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request) { + return Response.success(accountService.updateNoLoginRequiredNew(noLoginRequiredDTO, request)); + } } diff --git a/src/main/java/com/ai/da/mapper/primary/entity/Collection.java b/src/main/java/com/ai/da/mapper/primary/entity/Collection.java index 73f9a769..9b653eb3 100644 --- a/src/main/java/com/ai/da/mapper/primary/entity/Collection.java +++ b/src/main/java/com/ai/da/mapper/primary/entity/Collection.java @@ -40,6 +40,8 @@ public class Collection implements Serializable { */ private String moodTemplateId; + private String moodboardPosition; + /** * 创建时间 */ diff --git a/src/main/java/com/ai/da/mapper/primary/entity/ToProductImageResult.java b/src/main/java/com/ai/da/mapper/primary/entity/ToProductImageResult.java index 4731a6dd..3838b9f5 100644 --- a/src/main/java/com/ai/da/mapper/primary/entity/ToProductImageResult.java +++ b/src/main/java/com/ai/da/mapper/primary/entity/ToProductImageResult.java @@ -42,4 +42,6 @@ public class ToProductImageResult implements Serializable { @ApiModelProperty(value = "generate 结果类型") private String resultType; + + private Double brightenValue; } diff --git a/src/main/java/com/ai/da/model/dto/DesignCollectionDTO.java b/src/main/java/com/ai/da/model/dto/DesignCollectionDTO.java index ae68bd36..478483c4 100644 --- a/src/main/java/com/ai/da/model/dto/DesignCollectionDTO.java +++ b/src/main/java/com/ai/da/model/dto/DesignCollectionDTO.java @@ -27,10 +27,6 @@ public class DesignCollectionDTO { @ApiModelProperty("手稿板图片id 数组") private List sketchBoards; - // 2023.10版本去除该入参 -// @ApiModelProperty("市场手稿板图片id 数组") -// private List marketingSketchs; - @NotNull(message = "systemScale.cannot.be.empty") @ApiModelProperty("系统取图比列") private BigDecimal systemScale; @@ -65,4 +61,6 @@ public class DesignCollectionDTO { @ApiModelProperty("python端design进程ID") private String processId; + private String moodboardPostion; + } diff --git a/src/main/java/com/ai/da/model/dto/ReDesignCollectionDTO.java b/src/main/java/com/ai/da/model/dto/ReDesignCollectionDTO.java index 080c203f..b72a690a 100644 --- a/src/main/java/com/ai/da/model/dto/ReDesignCollectionDTO.java +++ b/src/main/java/com/ai/da/model/dto/ReDesignCollectionDTO.java @@ -14,7 +14,6 @@ import java.util.List; @ApiModel("重新设计Collection 入参") public class ReDesignCollectionDTO { - @NotNull(message = "collectionId.cannot.be.empty") @ApiModelProperty("collectionId") private Long collectionId; @@ -64,4 +63,8 @@ public class ReDesignCollectionDTO { @NotBlank(message = "processId.cannot.be.empty") @ApiModelProperty("python端design进程ID") private String processId; + + private String moodboardPosition; + + private String moodTemplateId; } diff --git a/src/main/java/com/ai/da/model/dto/ToProductImageDTO.java b/src/main/java/com/ai/da/model/dto/ToProductImageDTO.java index 93263027..66b8697e 100644 --- a/src/main/java/com/ai/da/model/dto/ToProductImageDTO.java +++ b/src/main/java/com/ai/da/model/dto/ToProductImageDTO.java @@ -13,4 +13,5 @@ public class ToProductImageDTO { private String prompt; private BigDecimal imageStrength; private String direction; + private Double brightenValue; } diff --git a/src/main/java/com/ai/da/model/vo/UserLikeCollectionVO.java b/src/main/java/com/ai/da/model/vo/UserLikeCollectionVO.java index ac87037f..8850ae66 100644 --- a/src/main/java/com/ai/da/model/vo/UserLikeCollectionVO.java +++ b/src/main/java/com/ai/da/model/vo/UserLikeCollectionVO.java @@ -35,4 +35,6 @@ public class UserLikeCollectionVO { @ApiModelProperty("市场手稿板图片 数组") private List marketingSketchs; + + private String moodboardPosition; } diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index e6f29713..3fa9ef28 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -3526,4 +3526,44 @@ public class PythonService { response.close(); } } + + public void bright(String url, Double brightenValue) { + OkHttpClient client = new OkHttpClient().newBuilder() + .connectTimeout(30, TimeUnit.SECONDS) + .pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒) + .readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒) + .writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒) + .build(); + MediaType mediaType = MediaType.parse("application/json"); + //关闭FastJson的引用检测 防止出现$ref 现象 + Map map = new HashMap<>(); + map.put("image_url", url); + map.put("brighten_value", brightenValue); + log.info("bright请求python 参数:####{}", map); + String param = JSON.toJSONString(map, SerializerFeature.WriteNullStringAsEmpty); + log.info(param); + RequestBody body = RequestBody.create(mediaType, param); + Request request = new Request.Builder() +// .url(accessPythonIp + ":" + accessPythonPort + "/api/generate_product_image") +// .url(accessPythonIp + ":9996/api/generate_product_image") + .url(accessPythonIp + ":" + accessPythonPort + "/api/brighten") + .method("POST", body) + .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==") + .addHeader("Content-Type", "application/json") + .build(); + Response response; + String responseBody; + try { + response = client.newCall(request).execute(); + } catch (IOException ioException) { + log.error("PythonService##bright异常###{}", ExceptionUtil.getThrowableList(ioException)); + throw new BusinessException("bright.interface.exception"); + } + if (response.isSuccessful()) { + return; + } + log.error("PythonService##bright异常response###{}", response); + //生成失败 + throw new BusinessException("bright.interface.exception"); + } } diff --git a/src/main/java/com/ai/da/service/AccountService.java b/src/main/java/com/ai/da/service/AccountService.java index 01b7d03e..69aec0f2 100644 --- a/src/main/java/com/ai/da/service/AccountService.java +++ b/src/main/java/com/ai/da/service/AccountService.java @@ -167,4 +167,6 @@ public interface AccountService extends IService { Boolean viewsIncrease(Long id); void registerUserToVisitor(); + + String updateNoLoginRequiredNew(NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request); } diff --git a/src/main/java/com/ai/da/service/CollectionService.java b/src/main/java/com/ai/da/service/CollectionService.java index 919ebf4f..41cb5760 100644 --- a/src/main/java/com/ai/da/service/CollectionService.java +++ b/src/main/java/com/ai/da/service/CollectionService.java @@ -14,7 +14,7 @@ public interface CollectionService extends IService { /** * 保存collection */ - Long saveCollection(Long accountId, String timeZone, String moodTemplateId); + Long saveCollection(Long accountId, String timeZone, String moodTemplateId, String moodboardPostion); /** * 根据主键查询 diff --git a/src/main/java/com/ai/da/service/DesignService.java b/src/main/java/com/ai/da/service/DesignService.java index 0558f185..b346c8bf 100644 --- a/src/main/java/com/ai/da/service/DesignService.java +++ b/src/main/java/com/ai/da/service/DesignService.java @@ -43,6 +43,8 @@ public interface DesignService extends IService { */ DesignCollectionVO designItemList(Long designId); + List relationImageIds(DesignPythonObjects pythonObjects); + /** * @return */ @@ -92,7 +94,7 @@ public interface DesignService extends IService { void relationImageId(DesignPythonObjects objects); - List sketchesBoundingBox(SketchesBoundingBoxDTO sketchesBoundingBoxDTO); + List sketchesBoundingBox(ReDesignCollectionDTO reDesignCollectionDTO); List getModel(List designItemIdList); diff --git a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java index 6a82b081..e8daaa59 100644 --- a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java @@ -897,6 +897,57 @@ public class AccountServiceImpl extends ServiceImpl impl "                        "; } + @Override + @Transactional(rollbackFor = Exception.class) + public String updateNoLoginRequiredNew(NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request) { + // 验证机房注册序列号(001-100) + String id = noLoginRequiredDTO.getId(); + if (!isStringInRange(id)) { + throw new BusinessException("Illegal serial number."); + } + // 获取真实 IP 地址,考虑了经过代理的情况 + String ipAddress = request.getHeader("X-Forwarded-For"); + if (ipAddress == null || ipAddress.isEmpty() || "unknown".equalsIgnoreCase(ipAddress)) { + ipAddress = request.getHeader("Proxy-Client-IP"); + } + if (ipAddress == null || ipAddress.isEmpty() || "unknown".equalsIgnoreCase(ipAddress)) { + ipAddress = request.getHeader("WL-Proxy-Client-IP"); + } + if (ipAddress == null || ipAddress.isEmpty() || "unknown".equalsIgnoreCase(ipAddress)) { + ipAddress = request.getRemoteAddr(); + } + String browserIdentifiers = ipAddress + "," + id; + // 构建查询条件,查找已注册的账户数量 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(Account::getUserName, "PolyU-SFT-" + id); +// queryWrapper.lambda().eq(Account::getBrowserIdentifiers, browserIdentifiers); + List existingAccounts = accountMapper.selectList(queryWrapper); + + // 检查序列号是否被注册 + if (!CollectionUtil.isNotEmpty(existingAccounts)) { + throw new BusinessException("Updated serial number not found."); + } + + Account account = existingAccounts.get(0); + account.setBrowserIdentifiers(browserIdentifiers); + accountMapper.updateById(account); + + return "\n" + + "                        \n" + + "                        \n" + + "                            \n" + + "                            \n" + + "                            Document\n" + + " \n" + + "                        \n" + + "                        \n" + + "                        \n" + + "                            \n" + + "                        "; + } + public static boolean isStringInRange(String input) { // 去除字符串两端的空格 input = input.trim(); diff --git a/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java index 521b4ab0..c2a807f7 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java @@ -78,6 +78,9 @@ public class CollectionElementServiceImpl extends ServiceImpl impleme collectionElementService.editPrintBoardsElement(elementVO, designDTO.getPrintBoards()); } //保存collection - Long collectionId = (null == collectionIdParam) ? - collectionService.saveCollection(userInfo.getId(), designDTO.getTimeZone(), designDTO.getMoodTemplateId()) : collectionIdParam; + Long collectionId; + if (null == collectionIdParam) { + collectionId = collectionService.saveCollection(userInfo.getId(), designDTO.getTimeZone(), designDTO.getMoodTemplateId(), designDTO.getMoodboardPostion()); + }else { + collectionId = collectionIdParam; + Collection byId = collectionService.getById(collectionIdParam); + if (!designDTO.getMoodboardPostion().equals(byId.getMoodboardPosition())) { + byId.setMoodboardPosition(designDTO.getMoodboardPostion()); + } + if (!designDTO.getMoodTemplateId().equals(byId.getMoodTemplateId())) { + byId.setMoodTemplateId(designDTO.getMoodTemplateId()); + } + collectionService.updateById(byId); + } List elementIds = getElementId(elementVO); //批量关联element 到 collection collectionElementService.relationCollection(elementIds, collectionId); @@ -367,8 +379,63 @@ public class DesignServiceImpl extends ServiceImpl impleme } @Override - public List sketchesBoundingBox(SketchesBoundingBoxDTO sketchesBoundingBoxDTO) { - List sketchBoards = sketchesBoundingBoxDTO.getSketchBoards(); + public List sketchesBoundingBox(ReDesignCollectionDTO reDesignDTO) { + List sketchBoards = new ArrayList<>(); + for (CollectionSketchDTO dto : reDesignDTO.getSketchBoards()) { + // 这里假设 CollectionSketchDTO 有一个复制构造函数,或者你可以手动复制它的属性 + CollectionSketchDTO newDto = CopyUtil.copyObject(dto, CollectionSketchDTO.class); + sketchBoards.add(newDto); + } + + if (null != reDesignDTO.getCollectionId()) { + //校验collection + Collection collection = collectionService.getById(reDesignDTO.getCollectionId()); + if (Objects.isNull(collection)) { + throw new BusinessException("collection.not.found"); + } + if (!reDesignDTO.getMoodboardPosition().equals(collection.getMoodboardPosition())) { + collection.setMoodboardPosition(reDesignDTO.getMoodboardPosition()); + } + if (!reDesignDTO.getMoodTemplateId().equals(collection.getMoodTemplateId())) { + collection.setMoodTemplateId(reDesignDTO.getMoodTemplateId()); + } + collectionService.updateById(collection); + //校验collection element + DesignCollectionDTO designCollectionDTO = CopyUtil.copyObject(reDesignDTO, DesignCollectionDTO.class); + ValidateElementVO elementVO = collectionElementService.validateElement(designCollectionDTO); + //计算并删除对应的未关联的element + List longs = calculateNoRelationElement(reDesignDTO.getCollectionId(), elementVO.getUsedElementIds()); + if (!CollectionUtils.isEmpty(longs)) { + collectionElementService.batchDelete(longs); + } + //redesign + DesignCollectionDTO designDTO = CopyUtil.copyObject(reDesignDTO, DesignCollectionDTO.class); + Long collectionIdParam = reDesignDTO.getCollectionId(); + if (CollectionUtil.isNotEmpty(designDTO.getSketchBoards())) { + //编辑sketchBoard + collectionElementService.editSketchBoardsElement(elementVO, designDTO.getSketchBoards()); + } + if (CollectionUtil.isNotEmpty(designDTO.getPrintBoards())) { + //编辑printBoard + collectionElementService.editPrintBoardsElement(elementVO, designDTO.getPrintBoards()); + } + //保存collection + Long collectionId = collectionIdParam; + List elementIds = getElementId(elementVO); + //批量关联element 到 collection + collectionElementService.relationCollection(elementIds, collectionId); + //library转化为collection(生成) + saveCollectionElemntsByLibrarys(elementVO, collectionId); + //generate转化为collection(生成) + saveCollectionElemntsByGenerates(elementVO, collectionId); + //保存颜色版 + collectionElementService.saveColorBoard(designDTO.getColorBoards(), collectionId, designDTO.getTimeZone()); + + //处理关联关系,修复element覆盖得情况 + List relationElements = collectionElementService.getByOnlyCollectionId(collectionId); + List relationElementIds = relationElements.stream().map(CollectionElement::getId).collect(Collectors.toList()); + handleCollectionElementRelation(collectionId, null != collectionIdParam, relationElementIds); + } if (CollectionUtil.isNotEmpty(sketchBoards)) { List result = new ArrayList<>(); List collect = sketchBoards.stream() @@ -423,6 +490,7 @@ public class DesignServiceImpl extends ServiceImpl impleme return new ArrayList<>(); } + @Override public List relationImageIds(DesignPythonObjects pythonObjects) { List imageIds = new ArrayList<>(); if (Objects.isNull(pythonObjects)) { diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index 3b83ca8d..afeb8565 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -715,6 +715,9 @@ public class GenerateServiceImpl extends ServiceImpl i // throw new BusinessException(""); } ToProductImageResult toProductImageResult = toProductImageResults.get(0); + if (toProductImageResult.getBrightenValue() != null && toProductImageResult.getBrightenValue() != 1.0) { + pythonService.bright(url, toProductImageResult.getBrightenValue()); + } toProductImageResult.setUrl(url); toProductImageResult.setResultType("Relight"); toProductImageResultMapper.updateById(toProductImageResult); diff --git a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java index 9dff1679..acc1d205 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -512,6 +512,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl