You've already forked FrameTour-BE
生成视频时发送通知,其他调整
This commit is contained in:
@ -1,22 +1,35 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ycwl.basic.mapper.MpConfigMapper;
|
||||
import com.ycwl.basic.mapper.MpNotifyConfigMapper;
|
||||
import com.ycwl.basic.mapper.ScenicMapper;
|
||||
import com.ycwl.basic.model.pc.mp.MpConfigEntity;
|
||||
import com.ycwl.basic.model.pc.mp.MpNotifyConfigEntity;
|
||||
import com.ycwl.basic.model.pc.mp.ScenicMpNotifyVO;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ScenicRepository {
|
||||
@Autowired
|
||||
private ScenicMapper scenicMapper;
|
||||
@Autowired
|
||||
private MpConfigMapper mpConfigMapper;
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
public static final String SCENIC_CACHE_KEY = "scenic:%s";
|
||||
public static final String SCENIC_CONFIG_CACHE_KEY = "scenic:%s:config";
|
||||
public static final String SCENIC_MP_CACHE_KEY = "scenic:%s:mp";
|
||||
public static final String SCENIC_MP_NOTIFY_CACHE_KEY = "scenic:%s:mpNotify";
|
||||
@Autowired
|
||||
private MpNotifyConfigMapper mpNotifyConfigMapper;
|
||||
|
||||
public ScenicEntity getScenic(Long id) {
|
||||
if (redisTemplate.hasKey(String.format(SCENIC_CACHE_KEY, id))) {
|
||||
@ -40,8 +53,51 @@ public class ScenicRepository {
|
||||
return scenicConfig;
|
||||
}
|
||||
|
||||
public MpConfigEntity getScenicMpConfig(Long scenicId) {
|
||||
if (redisTemplate.hasKey(String.format(SCENIC_MP_CACHE_KEY, scenicId))) {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_MP_CACHE_KEY, scenicId)), MpConfigEntity.class);
|
||||
}
|
||||
ScenicEntity scenic = getScenic(scenicId);
|
||||
MpConfigEntity mpConfigEntity = mpConfigMapper.selectById(scenic.getMpId());
|
||||
if (mpConfigEntity != null) {
|
||||
redisTemplate.opsForValue().set(String.format(SCENIC_MP_CACHE_KEY, scenicId), JSONObject.toJSONString(mpConfigEntity));
|
||||
}
|
||||
return mpConfigEntity;
|
||||
}
|
||||
|
||||
public ScenicMpNotifyVO getScenicMpNotifyConfig(Long scenicId) {
|
||||
if (redisTemplate.hasKey(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId))) {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId)), ScenicMpNotifyVO.class);
|
||||
}
|
||||
MpConfigEntity mpConfig = getScenicMpConfig(scenicId);
|
||||
ScenicMpNotifyVO mpNotifyConfig = new ScenicMpNotifyVO();
|
||||
mpNotifyConfig.setAppId(mpConfig.getAppId());
|
||||
mpNotifyConfig.setAppSecret(mpConfig.getAppSecret());
|
||||
mpNotifyConfig.setMpId(mpConfig.getId());
|
||||
mpNotifyConfig.setAppState(mpConfig.getState());
|
||||
List<MpNotifyConfigEntity> mpNotifyConfigList = mpNotifyConfigMapper.listByMpId(mpConfig.getId());
|
||||
mpNotifyConfigList.forEach(item -> {
|
||||
switch (item.getType()) {
|
||||
case 0:
|
||||
mpNotifyConfig.setVideoGeneratedTemplateId(item.getTemplateId());
|
||||
break;
|
||||
}
|
||||
});
|
||||
redisTemplate.opsForValue().set(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId), JSONObject.toJSONString(mpNotifyConfig));
|
||||
return mpNotifyConfig;
|
||||
}
|
||||
|
||||
public String getVideoGeneratedTemplateId(Long scenicId) {
|
||||
ScenicMpNotifyVO scenicMpNotifyConfig = getScenicMpNotifyConfig(scenicId);
|
||||
if (scenicMpNotifyConfig != null) {
|
||||
return scenicMpNotifyConfig.getVideoGeneratedTemplateId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void clearCache(Long scenicId) {
|
||||
redisTemplate.delete(String.format(SCENIC_CACHE_KEY, scenicId));
|
||||
redisTemplate.delete(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user