|
|
|
@ -37,6 +37,7 @@ import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
@ -65,6 +66,10 @@ public class AiGenerationServiceImpl implements AiGenerationService { |
|
|
|
private final AliyunFileService aliyunFileService; |
|
|
|
private final MiniPointRecordService pointRecordService; |
|
|
|
private final WxSubscribeService wxSubscribeService; |
|
|
|
private final StringRedisTemplate stringRedisTemplate; |
|
|
|
|
|
|
|
// Redis key 存储微信订阅消息跳转版本
|
|
|
|
private static final String WX_MINI_PROGRAM_STATE_KEY = "wx:subscribe:mini_program_state"; |
|
|
|
|
|
|
|
//OSS存储目录配置
|
|
|
|
private static final String OSS_IMAGE_DIR = "ai/image/"; |
|
|
|
@ -101,6 +106,9 @@ public class AiGenerationServiceImpl implements AiGenerationService { |
|
|
|
@Value("${subscribe.template}") |
|
|
|
private String subscribeTemplate; |
|
|
|
|
|
|
|
@Value("${subscribe.miniProgramState}") |
|
|
|
private String miniProgramState; |
|
|
|
|
|
|
|
//AI单图生成积分规则编码
|
|
|
|
private static final String AI_GENERATE_SINGLE_IMAGE_RULE = "AI_GENERATE_SINGLE_IMAGE"; |
|
|
|
//AI四宫格生成积分规则编码
|
|
|
|
@ -549,22 +557,7 @@ public class AiGenerationServiceImpl implements AiGenerationService { |
|
|
|
aiTaskMediaMapper.update(null, updateMediaWrapper); |
|
|
|
|
|
|
|
// 同步发送订阅消息通知
|
|
|
|
if (StrUtil.isNotBlank(subscribeTemplate)) { |
|
|
|
try { |
|
|
|
WxSubscribeSendForm sendForm = new WxSubscribeSendForm(); |
|
|
|
sendForm.setUserId(task.getMiniUserId()); |
|
|
|
sendForm.setTemplateId(subscribeTemplate); |
|
|
|
sendForm.setPage("pages/creation/list"); |
|
|
|
sendForm.setTemplateParams(Map.of( |
|
|
|
"thing5", "您的AI视频作品已完成", |
|
|
|
"time3", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm")), |
|
|
|
"phrase4", "待查看" |
|
|
|
)); |
|
|
|
wxSubscribeService.sendMessage(sendForm); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("视频任务{}发送订阅消息失败", task.getId(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
sendAiGenerateSuccessNotify(task.getMiniUserId(), subscribeTemplate, task.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
success = true; |
|
|
|
@ -744,23 +737,7 @@ public class AiGenerationServiceImpl implements AiGenerationService { |
|
|
|
aiTaskMediaMapper.update(null, updateMediaWrapper); |
|
|
|
|
|
|
|
// 同步发送订阅消息通知
|
|
|
|
if (StrUtil.isNotBlank(subscribeTemplate)) { |
|
|
|
try { |
|
|
|
WxSubscribeSendForm sendForm = new WxSubscribeSendForm(); |
|
|
|
sendForm.setUserId(task.getMiniUserId()); |
|
|
|
sendForm.setTemplateId(subscribeTemplate); |
|
|
|
sendForm.setPage("pages/creation/list"); |
|
|
|
// 根据实际模板字段调整参数
|
|
|
|
sendForm.setTemplateParams(Map.of( |
|
|
|
"thing5", "您的AI绘画作品已完成", |
|
|
|
"time3", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm")), |
|
|
|
"phrase4", "待查看" |
|
|
|
)); |
|
|
|
wxSubscribeService.sendMessage(sendForm); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("单图任务{}发送订阅消息失败", task.getId(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
sendAiGenerateSuccessNotify(task.getMiniUserId(), subscribeTemplate, task.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新任务状态
|
|
|
|
@ -794,6 +771,30 @@ public class AiGenerationServiceImpl implements AiGenerationService { |
|
|
|
return aiGenerationTaskMapper.update(null, updateWrapper) > 0; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取微信订阅消息跳转版本 |
|
|
|
* 优先级: 配置文件配置 > Redis配置 > 默认formal |
|
|
|
*/ |
|
|
|
private String getMiniProgramState() { |
|
|
|
if (StrUtil.isNotBlank(miniProgramState)) { |
|
|
|
return miniProgramState; |
|
|
|
} |
|
|
|
String redisState = stringRedisTemplate.opsForValue().get(WX_MINI_PROGRAM_STATE_KEY); |
|
|
|
if (StrUtil.isNotBlank(redisState)) { |
|
|
|
return redisState; |
|
|
|
} |
|
|
|
return "formal"; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void setMiniProgramState(String miniProgramState) { |
|
|
|
if (StrUtil.isBlank(miniProgramState)) { |
|
|
|
stringRedisTemplate.delete(WX_MINI_PROGRAM_STATE_KEY); |
|
|
|
} else { |
|
|
|
stringRedisTemplate.opsForValue().set(WX_MINI_PROGRAM_STATE_KEY, miniProgramState); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 下载外部URL到OSS,返回OSS访问地址 |
|
|
|
*/ |
|
|
|
@ -960,7 +961,7 @@ public class AiGenerationServiceImpl implements AiGenerationService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 发送AI绘画完成订阅消息通知 |
|
|
|
* 发送AI作品完成订阅消息通知 |
|
|
|
* @param userId 接收用户ID |
|
|
|
* @param templateId 订阅消息模板ID |
|
|
|
* @param taskId 任务ID(仅用于日志) |
|
|
|
@ -974,14 +975,15 @@ public class AiGenerationServiceImpl implements AiGenerationService { |
|
|
|
sendForm.setUserId(userId); |
|
|
|
sendForm.setTemplateId(templateId); |
|
|
|
sendForm.setPage("pages/creation/list"); |
|
|
|
sendForm.setMiniProgramState(getMiniProgramState()); |
|
|
|
sendForm.setTemplateParams(Map.of( |
|
|
|
"thing5", "您的AI绘画作品已完成", |
|
|
|
"thing5", "您的AI作品已完成", |
|
|
|
"time3", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm")), |
|
|
|
"phrase4", "待查看" |
|
|
|
)); |
|
|
|
wxSubscribeService.sendMessage(sendForm); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("四宫格图片任务{}发送订阅消息失败", taskId, e); |
|
|
|
log.error("AI任务{}发送订阅消息失败", taskId, e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|