【解决todo】所有转换都不依赖 convert 采用 BeanUtils

This commit is contained in:
cherishsince 2024-05-30 10:18:55 +08:00
parent 2eade5ad5b
commit 1c0cf4b860
3 changed files with 16 additions and 98 deletions

View File

@ -1,15 +1,10 @@
package cn.iocoder.yudao.module.ai.controller.admin.image.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
import java.util.Map;
// TODO @fan可以考虑复用 AiImageDallRespVO统一成 AIImageRespVO
@ -22,7 +17,7 @@ import java.util.Map;
*/
@Data
@Accessors(chain = true)
public class AiImageListRespVO extends PageParam {
public class AiImagePageMyRespVO extends PageParam {
@Schema(description = "id编号", example = "1")
private Long id;

View File

@ -1,74 +0,0 @@
package cn.iocoder.yudao.module.ai.convert;
import org.springframework.ai.models.midjourney.MidjourneyMessage;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDallReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDallRespVO;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageListRespVO;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageMidjourneyOperationsVO;
import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
// TODO @fanconvert 可以考虑去掉使用 BeanUtils.copy 替代
/**
* ai image convert
*
* @author fansili
* @time 2024/4/18 16:39
* @since 1.0
*/
@Mapper
public interface AiImageConvert {
AiImageConvert INSTANCE = Mappers.getMapper(AiImageConvert.class);
/**
* 转换 - AiImageDallDrawingRespVO
*
* @param req
* @return
*/
AiImageDallRespVO convertAiImageDallDrawingRespVO(AiImageDO req);
/**
* 转换 - AiImageDallDrawingRespVO
*
* @param req
* @return
*/
AiImageDallRespVO convertAiImageDallDrawingRespVO(AiImageDallReqVO req);
/**
* 转换 - AiImageListRespVO
*
* @param list
* @return
*/
List<AiImageListRespVO> convertAiImageListRespVO(List<AiImageDO> list);
/**
* 转换 - AiImageListRespVO
*
* @param aiImageDO
* @return
*/
AiImageListRespVO convertAiImageListRespVO(AiImageDO aiImageDO);
/**
* 转换 - AiImageMidjourneyOperationsVO
*
* @param component
* @return
*/
AiImageMidjourneyOperationsVO convertAiImageMidjourneyOperationsVO(MidjourneyMessage.Component component);
/**
* 转换 - AiImageDO
*
* @param req
* @return
*/
AiImageDO convertAiImageDO(AiImageDallReqVO req);
}

View File

@ -2,23 +2,19 @@ package cn.iocoder.yudao.module.ai.service.image.midjourneyHandler;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.ai.models.midjourney.MidjourneyMessage;
import org.springframework.ai.models.midjourney.constants.MidjourneyGennerateStatusEnum;
import org.springframework.ai.models.midjourney.webSocket.MidjourneyMessageHandler;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageMidjourneyOperationsVO;
import cn.iocoder.yudao.module.ai.convert.AiImageConvert;
import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO;
import cn.iocoder.yudao.module.ai.dal.mysql.image.AiImageMapper;
import cn.iocoder.yudao.module.ai.enums.AiImageStatusEnum;
import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.models.midjourney.MidjourneyMessage;
import org.springframework.ai.models.midjourney.constants.MidjourneyGennerateStatusEnum;
import org.springframework.ai.models.midjourney.webSocket.MidjourneyMessageHandler;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* yudao message handler
@ -113,15 +109,16 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler {
}
private List<AiImageMidjourneyOperationsVO> getMidjourneyOperationsList(MidjourneyMessage midjourneyMessage) {
// 为空直接返回
if (CollUtil.isEmpty(midjourneyMessage.getComponents())) {
return Collections.emptyList();
}
// component 转成 AiImageMidjourneyOperationsVO
return midjourneyMessage.getComponents().stream()
.map(componentType -> componentType.getComponents().stream()
.map(AiImageConvert.INSTANCE::convertAiImageMidjourneyOperationsVO)
.collect(Collectors.toList()))
.toList().stream().flatMap(List::stream).toList();
// // 为空直接返回
// if (CollUtil.isEmpty(midjourneyMessage.getComponents())) {
// return Collections.emptyList();
// }
// // component 转成 AiImageMidjourneyOperationsVO
// return midjourneyMessage.getComponents().stream()
// .map(componentType -> componentType.getComponents().stream()
// .map(AiImageConvert.INSTANCE::convertAiImageMidjourneyOperationsVO)
// .collect(Collectors.toList()))
// .toList().stream().flatMap(List::stream).toList();
return null;
}
}