|
|
@@ -2,8 +2,11 @@ package com.etotem.cfc.service.impl;
|
|
|
|
|
|
import com.etotem.cfc.entity.User;
|
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
|
+import com.etotem.cfc.service.AIService;
|
|
|
import com.etotem.cfc.service.PortraitService;
|
|
|
import com.etotem.cfc.service.ProfileReadService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
@@ -13,10 +16,14 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class PortraitServiceImpl implements PortraitService {
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(PortraitServiceImpl.class);
|
|
|
+
|
|
|
@Resource
|
|
|
private UserMapper userMapper;
|
|
|
@Resource
|
|
|
private ProfileReadService profileReadService;
|
|
|
+ @Resource
|
|
|
+ private AIService aiService;
|
|
|
|
|
|
@Override
|
|
|
public String buildPortraitPrompt(Long userId, Long memberId) {
|
|
|
@@ -41,6 +48,36 @@ public class PortraitServiceImpl implements PortraitService {
|
|
|
userMapper.updateById(user);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String generatePortrait(Long userId, Long memberId) {
|
|
|
+ try {
|
|
|
+ String result = aiService.generateUserPortrait(userId, memberId, null);
|
|
|
+ if (result != null && !result.trim().isEmpty()) {
|
|
|
+ updatePortraitPrompt(userId, result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("AI 生成画像失败,回退到快照: userId={}, memberId={}", userId, memberId, e);
|
|
|
+ }
|
|
|
+ return renderSnapshot(memberId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String regeneratePortrait(Long userId, Long memberId) {
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ String currentPortrait = user != null ? user.getPortraitPrompt() : null;
|
|
|
+ try {
|
|
|
+ String result = aiService.generateUserPortrait(userId, memberId, currentPortrait);
|
|
|
+ if (result != null && !result.trim().isEmpty()) {
|
|
|
+ updatePortraitPrompt(userId, result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("AI 重画画像失败,使用旧画像: userId={}, memberId={}", userId, memberId, e);
|
|
|
+ }
|
|
|
+ return currentPortrait;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, Object> getPortrait(Long userId, Long targetUserId, Long memberId) {
|
|
|
Long effectiveUserId = (targetUserId != null) ? targetUserId : userId;
|