mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
【解决todo】将 LambdaUpdateWrapper 隔离在 mapper,优化toSet toMap 使用 CollectionUtils
This commit is contained in:
parent
aa7c2cb251
commit
7c1e949d77
@ -1,12 +1,17 @@
|
||||
package cn.iocoder.yudao.module.ai.dal.mysql.image;
|
||||
|
||||
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO;
|
||||
import cn.iocoder.yudao.module.ai.enums.image.AiImageStatusEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AI 绘图 Mapper
|
||||
*
|
||||
@ -16,6 +21,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
public interface AiImageMapper extends BaseMapperX<AiImageDO> {
|
||||
|
||||
// TODO @fan:这个建议,直接使用 update,service 拼接要改的状态哈
|
||||
|
||||
/**
|
||||
* 更新 - 根据 messageId
|
||||
*
|
||||
@ -37,10 +43,29 @@ public interface AiImageMapper extends BaseMapperX<AiImageDO> {
|
||||
return this.selectOne(new LambdaQueryWrapperX<AiImageDO>().eq(AiImageDO::getTaskId, id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 - page
|
||||
*
|
||||
* @param userId
|
||||
* @param pageReqVO
|
||||
* @return
|
||||
*/
|
||||
default PageResult<AiImageDO> selectPage(Long userId, PageParam pageReqVO) {
|
||||
return selectPage(pageReqVO, new LambdaQueryWrapperX<AiImageDO>()
|
||||
.eq(AiImageDO::getUserId, userId)
|
||||
.orderByDesc(AiImageDO::getId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 - 根据 status 和 platform
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
default List<AiImageDO> selectByStatusAndPlatform(AiImageStatusEnum statusEnum, AiPlatformEnum platformEnum) {
|
||||
return this.selectList(new LambdaUpdateWrapper<AiImageDO>()
|
||||
.eq(AiImageDO::getStatus, statusEnum.getStatus())
|
||||
.eq(AiImageDO::getPlatform, platformEnum.getPlatform())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,13 +3,12 @@ package cn.iocoder.yudao.module.ai.job;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
||||
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.MidjourneyNotifyReqVO;
|
||||
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.image.AiImageStatusEnum;
|
||||
import cn.iocoder.yudao.module.ai.service.image.AiImageService;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -17,7 +16,6 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* midjourney job 定时拉去 midjourney 绘制状态
|
||||
@ -42,25 +40,17 @@ public class MidjourneyJob implements JobHandler {
|
||||
@Override
|
||||
public String execute(String param) throws Exception {
|
||||
// 1、获取 midjourney 平台,状态在 “进行中” 的 image
|
||||
// TODO @fan:43 和 51 其实有点重叠,日志,建议只打 51
|
||||
log.info("Midjourney 同步 - 开始...");
|
||||
// TODO @fan:Job、Service 等业务层,不要直接使用 LambdaUpdateWrapper,这样会导致 mapper 穿透到逻辑层。要收敛到 mapper 里。
|
||||
List<AiImageDO> imageList = imageMapper.selectList(
|
||||
new LambdaUpdateWrapper<AiImageDO>()
|
||||
.eq(AiImageDO::getStatus, AiImageStatusEnum.IN_PROGRESS.getStatus())
|
||||
.eq(AiImageDO::getPlatform, AiPlatformEnum.MIDJOURNEY.getPlatform())
|
||||
);
|
||||
List<AiImageDO> imageList = imageMapper.selectByStatusAndPlatform(AiImageStatusEnum.IN_PROGRESS, AiPlatformEnum.MIDJOURNEY);
|
||||
log.info("Midjourney 同步 - 任务数量 {}!", imageList.size());
|
||||
if (CollUtil.isEmpty(imageList)) {
|
||||
// TODO @fan:51 和 54,其实有点重叠。建议 51 挪到 55 之后打。
|
||||
return "Midjourney 同步 - 数量为空!";
|
||||
}
|
||||
log.info("Midjourney 同步 - 开始...");
|
||||
// 2、批量拉去 task 信息
|
||||
// TODO @fan:imageList.stream().map(AiImageDO::getTaskId).collect(Collectors.toSet())),可以使用 CollectionUtils.convertSet 简化
|
||||
List<MidjourneyApi.NotifyRequest> taskList = midjourneyApi
|
||||
.listByCondition(imageList.stream().map(AiImageDO::getTaskId).collect(Collectors.toSet()));
|
||||
// TODO @fan:taskList.stream().collect(Collectors.toMap(MidjourneyNotifyReqVO::getId, o -> o)),也可以使用 CollectionUtils.convertMap;本质上,重用 set、map 转换,要 convert 简化
|
||||
Map<String, MidjourneyApi.NotifyRequest> taskIdMap = taskList.stream().collect(Collectors.toMap(MidjourneyApi.NotifyRequest::id, o -> o));
|
||||
.listByCondition(CollectionUtils.convertSet(imageList, AiImageDO::getTaskId));
|
||||
Map<String, MidjourneyApi.NotifyRequest> taskIdMap
|
||||
= CollectionUtils.convertMap(taskList, MidjourneyApi.NotifyRequest::id);
|
||||
// 3、更新 image 状态
|
||||
List<AiImageDO> updateImageList = new ArrayList<>();
|
||||
for (AiImageDO aiImageDO : imageList) {
|
||||
|
Loading…
Reference in New Issue
Block a user