TASK:aida;

This commit is contained in:
shahaibo
2024-09-27 14:42:30 +08:00
parent ea92e1f20d
commit 9f5c901502
20 changed files with 226 additions and 15 deletions

View File

@@ -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 {

View File

@@ -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);
}
}

View File

@@ -73,8 +73,8 @@ public class DesignController {
@ApiOperation(value = "sketchBoard upload generate design前裁剪")
@PostMapping("/sketchBoardsBoundingBox")
public Response<List<CollectionSketchVO>> sketchesBoundingBox(@Valid @RequestBody SketchesBoundingBoxDTO sketchesBoundingBoxDTO) {
return Response.success(designService.sketchesBoundingBox(sketchesBoundingBoxDTO));
public Response<List<CollectionSketchVO>> sketchesBoundingBox(@Valid @RequestBody ReDesignCollectionDTO reDesignCollectionDTO) {
return Response.success(designService.sketchesBoundingBox(reDesignCollectionDTO));
}
@ApiOperation(value = "通过designItemId获取模特图")

View File

@@ -107,4 +107,11 @@ public class ThirdPartyController {
public Response<String> getRedirectUrl() {
return Response.success(REDIRECT_URL);
}
@CrossOrigin
@ApiOperation(value = "updateNoLoginRequiredNew")
@PostMapping("/updateNoLoginRequiredNew")
public Response<String> updateNoLoginRequiredNew(@RequestBody NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request) {
return Response.success(accountService.updateNoLoginRequiredNew(noLoginRequiredDTO, request));
}
}

View File

@@ -40,6 +40,8 @@ public class Collection implements Serializable {
*/
private String moodTemplateId;
private String moodboardPosition;
/**
* 创建时间
*/

View File

@@ -42,4 +42,6 @@ public class ToProductImageResult implements Serializable {
@ApiModelProperty(value = "generate 结果类型")
private String resultType;
private Double brightenValue;
}

View File

@@ -27,10 +27,6 @@ public class DesignCollectionDTO {
@ApiModelProperty("手稿板图片id 数组")
private List<CollectionSketchDTO> sketchBoards;
// 2023.10版本去除该入参
// @ApiModelProperty("市场手稿板图片id 数组")
// private List<DesignCollectionElementDTO> 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;
}

View File

@@ -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;
}

View File

@@ -13,4 +13,5 @@ public class ToProductImageDTO {
private String prompt;
private BigDecimal imageStrength;
private String direction;
private Double brightenValue;
}

View File

@@ -35,4 +35,6 @@ public class UserLikeCollectionVO {
@ApiModelProperty("市场手稿板图片 数组")
private List<CollectionElementVO> marketingSketchs;
private String moodboardPosition;
}

View File

@@ -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<String, Object> 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");
}
}

View File

@@ -167,4 +167,6 @@ public interface AccountService extends IService<Account> {
Boolean viewsIncrease(Long id);
void registerUserToVisitor();
String updateNoLoginRequiredNew(NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request);
}

View File

@@ -14,7 +14,7 @@ public interface CollectionService extends IService<Collection> {
/**
* 保存collection
*/
Long saveCollection(Long accountId, String timeZone, String moodTemplateId);
Long saveCollection(Long accountId, String timeZone, String moodTemplateId, String moodboardPostion);
/**
* 根据主键查询

View File

@@ -43,6 +43,8 @@ public interface DesignService extends IService<Design> {
*/
DesignCollectionVO designItemList(Long designId);
List<Long> relationImageIds(DesignPythonObjects pythonObjects);
/**
* @return
*/
@@ -92,7 +94,7 @@ public interface DesignService extends IService<Design> {
void relationImageId(DesignPythonObjects objects);
List<CollectionSketchVO> sketchesBoundingBox(SketchesBoundingBoxDTO sketchesBoundingBoxDTO);
List<CollectionSketchVO> sketchesBoundingBox(ReDesignCollectionDTO reDesignCollectionDTO);
List<String> getModel(List<Long> designItemIdList);

View File

@@ -897,6 +897,57 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
"                        </html>";
}
@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<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Account::getUserName, "PolyU-SFT-" + id);
// queryWrapper.lambda().eq(Account::getBrowserIdentifiers, browserIdentifiers);
List<Account> 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 "<!DOCTYPE html>\n" +
"                        <html lang=\"en\">\n" +
"                        <head>\n" +
"                            <meta charset=\"UTF-8\">\n" +
"                            <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
"                            <title>Document</title>\n" +
" <link rel=\"icon\" href=\"https://polyu.aida.com.hk/favicon.ico\">\n" +
"                        </head>\n" +
"                        <body>\n" +
"                        </body>\n" +
"                            <script>\n" +
"                                window.location.href = 'https://polyu.aida.com.hk?" + id + "';\n" +
"                            </script>\n" +
"                        </html>";
}
public static boolean isStringInRange(String input) {
// 去除字符串两端的空格
input = input.trim();

View File

@@ -78,6 +78,9 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
@Value("${minio.bucketName.gradient}")
private String gradientBucketName;
@Resource
private RedisUtil redisUtil;
@Transactional(rollbackFor = Exception.class)
@Override
public CollectionElementVO upload(CollectionElementUploadDTO uploadDTO) {
@@ -101,6 +104,9 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
//保存element元素
CollectionElement collectionElement = resolveData(uploadDTO, userInfo, path, level2Type);
saveOne(collectionElement);
// if (!StringUtils.isEmpty(uploadDTO.getMoodboardPosition())) {
// redisUtil.saveMoodboardPosition(collectionElement.getId(), uploadDTO.getMoodboardPosition());
// }
CollectionElementVO collectionElementVO = CopyUtil.copyObject(collectionElement, CollectionElementVO.class);
collectionElementVO.setMinIOPath(collectionElementVO.getUrl());
collectionElementVO.setUrl(minioUtil.getPreSignedUrl(collectionElementVO.getUrl(), 24 * 60));

View File

@@ -7,6 +7,7 @@ import com.ai.da.common.enums.DesignTypeEnum;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.DateUtil;
import com.ai.da.common.utils.MinioUtil;
import com.ai.da.common.utils.RedisUtil;
import com.ai.da.mapper.primary.CollectionMapper;
import com.ai.da.mapper.primary.entity.Collection;
import com.ai.da.mapper.primary.entity.CollectionElement;
@@ -47,11 +48,12 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
@Transactional(rollbackFor = Exception.class)
@Override
public Long saveCollection(Long accountId, String timeZone, String moodTemplateId) {
public Long saveCollection(Long accountId, String timeZone, String moodTemplateId, String moodboardPostion) {
Collection collection = new Collection();
collection.setAccountId(accountId);
collection.setCreateDate(DateUtil.getByTimeZone(timeZone));
collection.setMoodTemplateId(moodTemplateId);
collection.setMoodboardPosition(moodboardPostion);
if (collectionMapper.insert(collection) <= 0) {
throw new BusinessException("save.collection.failed");
}
@@ -63,6 +65,9 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
return collectionMapper.selectById(id);
}
@Resource
private RedisUtil redisUtil;
@Override
public UserLikeCollectionVO chooseCollection(Long id) {
UserLikeCollectionVO response = new UserLikeCollectionVO();
@@ -78,6 +83,9 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
response.setMoodTemplateId(collection.getMoodTemplateId());
if (collection.getMoodTemplateId() != null) {
CollectionElement byId = collectionElementService.getById(response.getMoodTemplateId());
if (null != collection.getMoodboardPosition()) {
response.setMoodboardPosition(collection.getMoodboardPosition());
}
if (Objects.nonNull(byId)) {
response.setMoodTemplateName(byId.getName());
response.setMoodTemplateUrl(minioUtil.getPreSignedUrl(byId.getUrl(), 24 * 60));

View File

@@ -291,8 +291,20 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> 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<Long> elementIds = getElementId(elementVO);
//批量关联element 到 collection
collectionElementService.relationCollection(elementIds, collectionId);
@@ -367,8 +379,63 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
}
@Override
public List<CollectionSketchVO> sketchesBoundingBox(SketchesBoundingBoxDTO sketchesBoundingBoxDTO) {
List<CollectionSketchDTO> sketchBoards = sketchesBoundingBoxDTO.getSketchBoards();
public List<CollectionSketchVO> sketchesBoundingBox(ReDesignCollectionDTO reDesignDTO) {
List<CollectionSketchDTO> 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<Long> 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<Long> 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<CollectionElement> relationElements = collectionElementService.getByOnlyCollectionId(collectionId);
List<Long> relationElementIds = relationElements.stream().map(CollectionElement::getId).collect(Collectors.toList());
handleCollectionElementRelation(collectionId, null != collectionIdParam, relationElementIds);
}
if (CollectionUtil.isNotEmpty(sketchBoards)) {
List<CollectionSketchVO> result = new ArrayList<>();
List<CollectionSketchDTO> collect = sketchBoards.stream()
@@ -423,6 +490,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
return new ArrayList<>();
}
@Override
public List<Long> relationImageIds(DesignPythonObjects pythonObjects) {
List<Long> imageIds = new ArrayList<>();
if (Objects.isNull(pythonObjects)) {

View File

@@ -715,6 +715,9 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> 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);

View File

@@ -512,6 +512,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setIsLike(0);
toProductImageResult.setTaskId(taskId);
toProductImageResult.setUserLikeGroupId(userLikeGroupId);
if (toProductImageDTO.getBrightenValue() != null) {
toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue());
}
toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult);
@@ -527,6 +530,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
// toProductImageResult.setUrl(productImageUrl);
toProductImageResult.setIsLike(0);
toProductImageResult.setTaskId(taskId);
if (toProductImageDTO.getBrightenValue() != null) {
toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue());
}
toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult);