You've already forked FrameTour-BE
Merge branch 'refs/heads/order_v2'
# Conflicts: # src/main/java/com/ycwl/basic/controller/mobile/manage/AppScenicAccountController.java
This commit is contained in:
@@ -324,7 +324,7 @@ public class FaceServiceImpl implements FaceService {
|
||||
}
|
||||
} else {
|
||||
// 重新切视频逻辑
|
||||
if (scenicConfig != null && !Integer.valueOf(1).equals(scenicConfig.getDisableSourceVideo())) {
|
||||
if (scenicConfig != null && !Boolean.TRUE.equals(scenicConfig.getDisableSourceVideo())) {
|
||||
long videoCount = memberSourceEntityList.stream().filter(item -> item.getType().equals(1)).count();
|
||||
long photoCount = memberSourceEntityList.stream().filter(item -> item.getType().equals(2)).count();
|
||||
if (photoCount > videoCount) {
|
||||
@@ -443,7 +443,7 @@ public class FaceServiceImpl implements FaceService {
|
||||
sourceVideoContent.setLockType(-1);
|
||||
sourceImageContent.setLockType(-1);
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(faceRespVO.getScenicId());
|
||||
if (!Integer.valueOf(1).equals(scenicConfig.getDisableSourceImage())) {
|
||||
if (!Boolean.TRUE.equals(scenicConfig.getDisableSourceImage())) {
|
||||
IsBuyRespVO isBuyRespVO = orderBiz.isBuy(userId, faceRespVO.getScenicId(), 2, faceId);
|
||||
sourceImageContent.setSourceType(isBuyRespVO.getGoodsType());
|
||||
sourceImageContent.setContentId(isBuyRespVO.getGoodsId());
|
||||
@@ -462,7 +462,7 @@ public class FaceServiceImpl implements FaceService {
|
||||
sourceImageContent.setFreeCount((int) freeCount);
|
||||
contentList.add(sourceImageContent);
|
||||
}
|
||||
if (!Integer.valueOf(1).equals(scenicConfig.getDisableSourceVideo())) {
|
||||
if (!Boolean.TRUE.equals(scenicConfig.getDisableSourceVideo())) {
|
||||
IsBuyRespVO isBuyRespVO = orderBiz.isBuy(userId, faceRespVO.getScenicId(), 1, faceId);
|
||||
sourceVideoContent.setSourceType(isBuyRespVO.getGoodsType());
|
||||
sourceVideoContent.setContentId(isBuyRespVO.getGoodsId());
|
||||
|
||||
@@ -57,6 +57,7 @@ import com.ycwl.basic.utils.SnowFlakeUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.context.annotation.ScopedProxyMode;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -78,7 +79,7 @@ import java.util.stream.Collectors;
|
||||
* @Date:2024/12/3 13:54
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Service("OrderServiceOldImpl")
|
||||
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@@ -86,6 +87,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(value = "OrderServiceOldImpl")
|
||||
private OrderServiceImpl self;
|
||||
@Autowired
|
||||
private SourceMapper sourceMapper;
|
||||
|
||||
@@ -1,38 +1,29 @@
|
||||
package com.ycwl.basic.service.pc.impl;
|
||||
|
||||
import com.ycwl.basic.utils.JacksonUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.facebody.FaceBodyFactory;
|
||||
import com.ycwl.basic.facebody.adapter.IFaceBodyAdapter;
|
||||
import com.ycwl.basic.mapper.ScenicAccountMapper;
|
||||
import com.ycwl.basic.mapper.ScenicMapper;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
|
||||
import com.ycwl.basic.integration.scenic.dto.scenic.ScenicV2DTO;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
|
||||
import com.ycwl.basic.model.pc.scenic.req.ScenicAddOrUpdateReq;
|
||||
import com.ycwl.basic.model.pc.scenic.req.ScenicReqQuery;
|
||||
import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
|
||||
import com.ycwl.basic.pay.PayFactory;
|
||||
import com.ycwl.basic.pay.adapter.IPayAdapter;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import com.ycwl.basic.service.pc.ScenicService;
|
||||
import com.ycwl.basic.service.task.TaskFaceService;
|
||||
import com.ycwl.basic.storage.StorageFactory;
|
||||
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
||||
import com.ycwl.basic.storage.exceptions.StorageUnsupportedException;
|
||||
import com.ycwl.basic.util.ScenicConfigManager;
|
||||
import com.ycwl.basic.util.TtlCacheMap;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import com.ycwl.basic.utils.SnowFlakeUtil;
|
||||
import com.ycwl.basic.utils.JacksonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static com.ycwl.basic.constant.FaceConstant.USER_FACE_DB_NAME;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
@@ -41,199 +32,39 @@ import static com.ycwl.basic.constant.FaceConstant.USER_FACE_DB_NAME;
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ScenicServiceImpl implements ScenicService {
|
||||
@Autowired
|
||||
private ScenicMapper scenicMapper;
|
||||
@Autowired
|
||||
private ScenicAccountMapper scenicAccountMapper;
|
||||
@Autowired
|
||||
private TaskFaceService taskFaceService;
|
||||
@Autowired
|
||||
private ScenicRepository scenicRepository;
|
||||
|
||||
// TTL缓存配置,默认10分钟过期
|
||||
private static final long DEFAULT_CACHE_TTL_MINUTES = 10;
|
||||
|
||||
// 使用TTL缓存替代静态Map
|
||||
private static final TtlCacheMap<Long, IStorageAdapter> scenicStorageAdapterCache =
|
||||
new TtlCacheMap<>(TimeUnit.MINUTES.toMillis(DEFAULT_CACHE_TTL_MINUTES));
|
||||
private static final TtlCacheMap<Long, IStorageAdapter> scenicTmpStorageAdapterCache =
|
||||
new TtlCacheMap<>(TimeUnit.MINUTES.toMillis(DEFAULT_CACHE_TTL_MINUTES));
|
||||
private static final TtlCacheMap<Long, IStorageAdapter> scenicLocalStorageAdapterCache =
|
||||
new TtlCacheMap<>(TimeUnit.MINUTES.toMillis(DEFAULT_CACHE_TTL_MINUTES));
|
||||
private static final TtlCacheMap<Long, IFaceBodyAdapter> scenicFaceBodyAdapterCache =
|
||||
new TtlCacheMap<>(TimeUnit.MINUTES.toMillis(DEFAULT_CACHE_TTL_MINUTES));
|
||||
private static final TtlCacheMap<Long, IPayAdapter> scenicPayAdapterCache =
|
||||
new TtlCacheMap<>(TimeUnit.MINUTES.toMillis(DEFAULT_CACHE_TTL_MINUTES));
|
||||
|
||||
@Override
|
||||
public ApiResponse<PageInfo<ScenicRespVO>> pageQuery(ScenicReqQuery scenicReqQuery) {
|
||||
PageHelper.startPage(scenicReqQuery.getPageNum(), scenicReqQuery.getPageSize());
|
||||
List<ScenicRespVO> list = scenicMapper.list(scenicReqQuery);
|
||||
PageInfo<ScenicRespVO> pageInfo = new PageInfo<>(list);
|
||||
return ApiResponse.success(pageInfo);
|
||||
@Deprecated
|
||||
public ApiResponse<List<ScenicV2DTO>> list(ScenicReqQuery scenicReqQuery) {
|
||||
return ApiResponse.success(scenicRepository.list(scenicReqQuery));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<List<ScenicRespVO>> list(ScenicReqQuery scenicReqQuery) {
|
||||
return ApiResponse.success(scenicMapper.list(scenicReqQuery));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<ScenicRespVO> getById(Long id) {
|
||||
return ApiResponse.success(scenicMapper.getById(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApiResponse<Boolean> add(ScenicAddOrUpdateReq scenicAddReq) {
|
||||
Long scenicId = SnowFlakeUtil.getLongId();
|
||||
scenicAddReq.setId(scenicId);
|
||||
int add = scenicMapper.add(scenicAddReq);
|
||||
ScenicAccountEntity scenicAccount = scenicAccountMapper.getByAccount(scenicAddReq.getAccount());
|
||||
if (scenicAccount == null) {
|
||||
scenicAccount = new ScenicAccountEntity();
|
||||
scenicAccount.setId(SnowFlakeUtil.getLongId());
|
||||
scenicAccount.setName(scenicAddReq.getName() + "管理员");
|
||||
scenicAccount.setAccount(scenicAddReq.getAccount());
|
||||
scenicAccount.setPassword(scenicAddReq.getPassword());
|
||||
scenicAccount.setIsSuper(1);
|
||||
scenicAccountMapper.add(scenicAccount);
|
||||
}
|
||||
scenicAccountMapper.addAccountScenicRelation(scenicAccount.getId(), scenicId, 1);
|
||||
if (add > 0) {
|
||||
return ApiResponse.success(true);
|
||||
} else {
|
||||
return ApiResponse.fail("景区添加失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApiResponse<Boolean> deleteById(Long id) {
|
||||
int i = scenicMapper.deleteById(id);
|
||||
if (i > 0) {
|
||||
scenicAccountMapper.deleteRelationByScenicId(id);
|
||||
IFaceBodyAdapter adapter = getScenicFaceBodyAdapter(id);
|
||||
Thread.ofVirtual().start(() -> {
|
||||
adapter.deleteFaceDb(id.toString());
|
||||
adapter.deleteFaceDb(USER_FACE_DB_NAME + id);
|
||||
});
|
||||
scenicMapper.deleteConfigByScenicId(id);
|
||||
scenicRepository.clearCache(id);
|
||||
scenicFaceBodyAdapterMap.remove(id);
|
||||
scenicStorageAdapterMap.remove(id);
|
||||
scenicPayAdapterMap.remove(id);
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
return ApiResponse.fail("景区删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<Boolean> update(ScenicAddOrUpdateReq scenicUpdateReq) {
|
||||
if (scenicUpdateReq.getId() == null) {
|
||||
return ApiResponse.fail("参数错误");
|
||||
}
|
||||
if (StringUtils.isNotBlank(scenicUpdateReq.getAccount()) && StringUtils.isNotBlank(scenicUpdateReq.getPassword())) {
|
||||
ScenicAccountEntity scenicAccount = scenicAccountMapper.getByAccount(scenicUpdateReq.getAccount());
|
||||
if (scenicAccount != null) {
|
||||
if (!scenicAccount.getScenicId().equals(scenicUpdateReq.getId())) {
|
||||
return ApiResponse.fail("账号已存在");
|
||||
}
|
||||
}
|
||||
ScenicAccountEntity account = scenicAccountMapper.getSuperAccountOfScenic(scenicUpdateReq.getId());
|
||||
if (account != null) {
|
||||
account.setAccount(scenicUpdateReq.getAccount());
|
||||
account.setPassword(scenicUpdateReq.getPassword());
|
||||
scenicAccountMapper.update(account);
|
||||
} else {
|
||||
account = new ScenicAccountEntity();
|
||||
account.setId(SnowFlakeUtil.getLongId());
|
||||
account.setName(scenicUpdateReq.getName() + "管理员");
|
||||
account.setAccount(scenicUpdateReq.getAccount());
|
||||
account.setPassword(scenicUpdateReq.getPassword());
|
||||
account.setIsSuper(1);
|
||||
scenicAccountMapper.add(account);
|
||||
}
|
||||
scenicAccountMapper.addAccountScenicRelation(account.getId(), scenicUpdateReq.getId(), 1);
|
||||
}
|
||||
int i = scenicMapper.update(scenicUpdateReq);
|
||||
if (i > 0) {
|
||||
scenicRepository.clearCache(scenicUpdateReq.getId());
|
||||
scenicFaceBodyAdapterMap.remove(scenicUpdateReq.getId());
|
||||
scenicStorageAdapterMap.remove(scenicUpdateReq.getId());
|
||||
scenicTmpStorageAdapterMap.remove(scenicUpdateReq.getId());
|
||||
scenicLocalStorageAdapterMap.remove(scenicUpdateReq.getId());
|
||||
scenicPayAdapterMap.remove(scenicUpdateReq.getId());
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
return ApiResponse.fail("景区修改失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<Boolean> updateStatus(Long id) {
|
||||
int i = scenicMapper.updateStatus(id);
|
||||
if (i > 0) {
|
||||
scenicRepository.clearCache(id);
|
||||
scenicFaceBodyAdapterMap.remove(id);
|
||||
scenicStorageAdapterMap.remove(id);
|
||||
scenicTmpStorageAdapterMap.remove(id);
|
||||
scenicLocalStorageAdapterMap.remove(id);
|
||||
scenicPayAdapterMap.remove(id);
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
return ApiResponse.fail("景区状态修改失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<Boolean> addConfig(ScenicConfigEntity scenicConfig) {
|
||||
if (scenicConfig.getId() == null) {
|
||||
scenicConfig.setId(SnowFlakeUtil.getLongId());
|
||||
}
|
||||
int i = scenicMapper.addConfig(scenicConfig);
|
||||
if (i > 0) {
|
||||
scenicRepository.clearCache(scenicConfig.getScenicId());
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
return ApiResponse.fail("景区配置添加失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<Boolean> updateConfigById(ScenicConfigEntity scenicConfig) {
|
||||
int i = scenicMapper.updateConfigById(scenicConfig);
|
||||
if (i > 0) {
|
||||
scenicRepository.clearCache(scenicConfig.getScenicId());
|
||||
scenicFaceBodyAdapterMap.remove(scenicConfig.getScenicId());
|
||||
scenicStorageAdapterMap.remove(scenicConfig.getScenicId());
|
||||
scenicTmpStorageAdapterMap.remove(scenicConfig.getScenicId());
|
||||
scenicLocalStorageAdapterMap.remove(scenicConfig.getScenicId());
|
||||
scenicPayAdapterMap.remove(scenicConfig.getScenicId());
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
return ApiResponse.fail("景区配置修改失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScenicConfigEntity getConfig(Long id) {
|
||||
return scenicRepository.getScenicConfig(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveConfig(Long configId, ScenicConfigEntity config) {
|
||||
config.setId(configId);
|
||||
if (config.getScenicId() == null) {
|
||||
throw new RuntimeException("景区ID不能为空");
|
||||
}
|
||||
scenicMapper.updateConfigById(config);
|
||||
scenicRepository.clearCache(config.getScenicId());
|
||||
scenicFaceBodyAdapterMap.remove(config.getScenicId());
|
||||
scenicStorageAdapterMap.remove(config.getScenicId());
|
||||
scenicTmpStorageAdapterMap.remove(config.getScenicId());
|
||||
scenicLocalStorageAdapterMap.remove(config.getScenicId());
|
||||
scenicPayAdapterMap.remove(config.getScenicId());
|
||||
}
|
||||
|
||||
|
||||
private static final Map<Long, IStorageAdapter> scenicStorageAdapterMap = new ConcurrentHashMap<>();
|
||||
@Override
|
||||
public IStorageAdapter getScenicStorageAdapter(Long scenicId) {
|
||||
return scenicStorageAdapterMap.computeIfAbsent(scenicId, (key) -> {
|
||||
return scenicStorageAdapterCache.computeIfAbsent(scenicId, (key) -> {
|
||||
IStorageAdapter adapter;
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId);
|
||||
if (scenicConfig != null && scenicConfig.getStoreType() != null) {
|
||||
ScenicConfigManager scenicConfig = scenicRepository.getScenicConfigManager(scenicId);
|
||||
if (Strings.isNotBlank(scenicConfig.getString("store_type"))) {
|
||||
try {
|
||||
adapter = StorageFactory.get(scenicConfig.getStoreType());
|
||||
adapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getStoreConfigJson(), Map.class));
|
||||
adapter = StorageFactory.get(scenicConfig.getString("store_type"));
|
||||
adapter.loadConfig(scenicConfig.getObject("store_config_json", Map.class));
|
||||
} catch (StorageUnsupportedException ignored) {
|
||||
return StorageFactory.use("video");
|
||||
}
|
||||
@@ -243,16 +74,15 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
return adapter;
|
||||
});
|
||||
}
|
||||
private static final Map<Long, IStorageAdapter> scenicTmpStorageAdapterMap = new ConcurrentHashMap<>();
|
||||
@Override
|
||||
public IStorageAdapter getScenicTmpStorageAdapter(Long scenicId) {
|
||||
return scenicTmpStorageAdapterMap.computeIfAbsent(scenicId, (key) -> {
|
||||
return scenicTmpStorageAdapterCache.computeIfAbsent(scenicId, (key) -> {
|
||||
IStorageAdapter adapter;
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId);
|
||||
if (scenicConfig != null && scenicConfig.getTmpStoreType() != null) {
|
||||
ScenicConfigManager scenicConfig = scenicRepository.getScenicConfigManager(scenicId);
|
||||
if (Strings.isNotBlank(scenicConfig.getString("tmp_store_type"))) {
|
||||
try {
|
||||
adapter = StorageFactory.get(scenicConfig.getTmpStoreType());
|
||||
adapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getTmpStoreConfigJson(), Map.class));
|
||||
adapter = StorageFactory.get(scenicConfig.getString("tmp_store_type"));
|
||||
adapter.loadConfig(scenicConfig.getObject("tmp_store_config_json", Map.class));
|
||||
} catch (StorageUnsupportedException ignored) {
|
||||
return getScenicStorageAdapter(scenicId);
|
||||
}
|
||||
@@ -262,16 +92,15 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
return adapter;
|
||||
});
|
||||
}
|
||||
private static final Map<Long, IStorageAdapter> scenicLocalStorageAdapterMap = new ConcurrentHashMap<>();
|
||||
@Override
|
||||
public IStorageAdapter getScenicLocalStorageAdapter(Long scenicId) {
|
||||
return scenicLocalStorageAdapterMap.computeIfAbsent(scenicId, (key) -> {
|
||||
return scenicLocalStorageAdapterCache.computeIfAbsent(scenicId, (key) -> {
|
||||
IStorageAdapter adapter;
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId);
|
||||
if (scenicConfig != null && scenicConfig.getLocalStoreType() != null) {
|
||||
ScenicConfigManager scenicConfig = scenicRepository.getScenicConfigManager(scenicId);
|
||||
if (Strings.isNotBlank(scenicConfig.getString("local_store_type"))) {
|
||||
try {
|
||||
adapter = StorageFactory.get(scenicConfig.getLocalStoreType());
|
||||
adapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getLocalStoreConfigJson(), Map.class));
|
||||
adapter = StorageFactory.get(scenicConfig.getString("local_store_type"));
|
||||
adapter.loadConfig(scenicConfig.getObject("local_store_config_json", Map.class));
|
||||
} catch (StorageUnsupportedException ignored) {
|
||||
return getScenicStorageAdapter(scenicId);
|
||||
}
|
||||
@@ -282,15 +111,14 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
});
|
||||
}
|
||||
|
||||
private static final Map<Long, IFaceBodyAdapter> scenicFaceBodyAdapterMap = new ConcurrentHashMap<>();
|
||||
@Override
|
||||
public IFaceBodyAdapter getScenicFaceBodyAdapter(Long scenicId) {
|
||||
return scenicFaceBodyAdapterMap.computeIfAbsent(scenicId, (key) -> {
|
||||
return scenicFaceBodyAdapterCache.computeIfAbsent(scenicId, (key) -> {
|
||||
IFaceBodyAdapter adapter;
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId);
|
||||
if (scenicConfig != null && scenicConfig.getFaceType() != null) {
|
||||
adapter = FaceBodyFactory.getAdapter(scenicConfig.getFaceType());
|
||||
adapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getFaceConfigJson(), Map.class));
|
||||
ScenicConfigManager scenicConfig = scenicRepository.getScenicConfigManager(scenicId);
|
||||
if (Strings.isNotBlank(scenicConfig.getString("face_type"))) {
|
||||
adapter = FaceBodyFactory.getAdapter(scenicConfig.getString("face_type"));
|
||||
adapter.loadConfig(scenicConfig.getObject("face_config_json", Map.class));
|
||||
} else {
|
||||
adapter = FaceBodyFactory.use();
|
||||
}
|
||||
@@ -298,19 +126,108 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
});
|
||||
}
|
||||
|
||||
private static final Map<Long, IPayAdapter> scenicPayAdapterMap = new ConcurrentHashMap<>();
|
||||
@Override
|
||||
public IPayAdapter getScenicPayAdapter(Long scenicId) {
|
||||
return scenicPayAdapterMap.computeIfAbsent(scenicId, (key) -> {
|
||||
return scenicPayAdapterCache.computeIfAbsent(scenicId, (key) -> {
|
||||
IPayAdapter adapter;
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId);
|
||||
if (scenicConfig != null && scenicConfig.getPayType() != null) {
|
||||
adapter = PayFactory.getAdapter(scenicConfig.getPayType());
|
||||
adapter.loadConfig(JacksonUtil.parseObject(scenicConfig.getPayConfigJson(), Map.class));
|
||||
ScenicConfigManager scenicConfig = scenicRepository.getScenicConfigManager(scenicId);
|
||||
if (Strings.isNotBlank(scenicConfig.getString("pay_type"))) {
|
||||
adapter = PayFactory.getAdapter(scenicConfig.getString("pay_type"));
|
||||
adapter.loadConfig(scenicConfig.getObject("pay_config_json", Map.class));
|
||||
} else {
|
||||
adapter = PayFactory.use();
|
||||
}
|
||||
return adapter;
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== 缓存管理方法 ====================
|
||||
|
||||
/**
|
||||
* 清除指定景区的所有适配器缓存
|
||||
*
|
||||
* @param scenicId 景区ID
|
||||
*/
|
||||
public void clearScenicAdapterCache(Long scenicId) {
|
||||
log.info("清除景区 {} 的所有适配器缓存", scenicId);
|
||||
scenicStorageAdapterCache.remove(scenicId);
|
||||
scenicTmpStorageAdapterCache.remove(scenicId);
|
||||
scenicLocalStorageAdapterCache.remove(scenicId);
|
||||
scenicFaceBodyAdapterCache.remove(scenicId);
|
||||
scenicPayAdapterCache.remove(scenicId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有适配器缓存
|
||||
*/
|
||||
public void clearAllAdapterCache() {
|
||||
log.info("清除所有适配器缓存");
|
||||
scenicStorageAdapterCache.clear();
|
||||
scenicTmpStorageAdapterCache.clear();
|
||||
scenicLocalStorageAdapterCache.clear();
|
||||
scenicFaceBodyAdapterCache.clear();
|
||||
scenicPayAdapterCache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动触发过期缓存清理
|
||||
*
|
||||
* @return 清理的过期缓存项总数
|
||||
*/
|
||||
public int cleanupExpiredCache() {
|
||||
log.info("手动触发过期缓存清理");
|
||||
int totalCleaned = 0;
|
||||
totalCleaned += scenicStorageAdapterCache.cleanupExpired();
|
||||
totalCleaned += scenicTmpStorageAdapterCache.cleanupExpired();
|
||||
totalCleaned += scenicLocalStorageAdapterCache.cleanupExpired();
|
||||
totalCleaned += scenicFaceBodyAdapterCache.cleanupExpired();
|
||||
totalCleaned += scenicPayAdapterCache.cleanupExpired();
|
||||
log.info("清理了 {} 个过期缓存项", totalCleaned);
|
||||
return totalCleaned;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存统计信息
|
||||
*
|
||||
* @return 缓存统计信息
|
||||
*/
|
||||
public String getCacheStats() {
|
||||
StringBuilder stats = new StringBuilder();
|
||||
stats.append("=== ScenicServiceImpl 缓存统计信息 ===\n");
|
||||
stats.append("Storage Adapter Cache: ").append(scenicStorageAdapterCache.getStats()).append("\n");
|
||||
stats.append("Tmp Storage Adapter Cache: ").append(scenicTmpStorageAdapterCache.getStats()).append("\n");
|
||||
stats.append("Local Storage Adapter Cache: ").append(scenicLocalStorageAdapterCache.getStats()).append("\n");
|
||||
stats.append("FaceBody Adapter Cache: ").append(scenicFaceBodyAdapterCache.getStats()).append("\n");
|
||||
stats.append("Pay Adapter Cache: ").append(scenicPayAdapterCache.getStats()).append("\n");
|
||||
return stats.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置所有缓存统计信息
|
||||
*/
|
||||
public void resetCacheStats() {
|
||||
log.info("重置所有缓存统计信息");
|
||||
scenicStorageAdapterCache.resetStats();
|
||||
scenicTmpStorageAdapterCache.resetStats();
|
||||
scenicLocalStorageAdapterCache.resetStats();
|
||||
scenicFaceBodyAdapterCache.resetStats();
|
||||
scenicPayAdapterCache.resetStats();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定景区缓存的剩余TTL时间
|
||||
*
|
||||
* @param scenicId 景区ID
|
||||
* @return 各类型适配器缓存的剩余TTL时间(毫秒)
|
||||
*/
|
||||
public String getScenicCacheTtl(Long scenicId) {
|
||||
StringBuilder ttlInfo = new StringBuilder();
|
||||
ttlInfo.append("景区 ").append(scenicId).append(" 缓存TTL信息:\n");
|
||||
ttlInfo.append("Storage: ").append(scenicStorageAdapterCache.getRemainTtl(scenicId)).append("ms\n");
|
||||
ttlInfo.append("TmpStorage: ").append(scenicTmpStorageAdapterCache.getRemainTtl(scenicId)).append("ms\n");
|
||||
ttlInfo.append("LocalStorage: ").append(scenicLocalStorageAdapterCache.getRemainTtl(scenicId)).append("ms\n");
|
||||
ttlInfo.append("FaceBody: ").append(scenicFaceBodyAdapterCache.getRemainTtl(scenicId)).append("ms\n");
|
||||
ttlInfo.append("Pay: ").append(scenicPayAdapterCache.getRemainTtl(scenicId)).append("ms\n");
|
||||
return ttlInfo.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.ycwl.basic.model.pc.template.entity.TemplateConfigEntity;
|
||||
import com.ycwl.basic.model.pc.template.entity.TemplateEntity;
|
||||
import com.ycwl.basic.model.pc.template.req.TemplateReqQuery;
|
||||
import com.ycwl.basic.model.pc.template.resp.TemplateRespVO;
|
||||
import com.ycwl.basic.pricing.enums.ProductType;
|
||||
import com.ycwl.basic.pricing.service.IPricingManagementService;
|
||||
import com.ycwl.basic.service.pc.TemplateService;
|
||||
import com.ycwl.basic.repository.TemplateRepository;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
@@ -30,6 +32,8 @@ public class TemplateServiceImpl implements TemplateService {
|
||||
private TemplateMapper templateMapper;
|
||||
@Autowired
|
||||
private TemplateRepository templateRepository;
|
||||
@Autowired
|
||||
private IPricingManagementService pricingManagementService;
|
||||
|
||||
@Override
|
||||
public ApiResponse<PageInfo<TemplateRespVO>> pageQuery(TemplateReqQuery templateReqQuery) {
|
||||
@@ -75,6 +79,7 @@ public class TemplateServiceImpl implements TemplateService {
|
||||
templateMapper.add(item);
|
||||
});
|
||||
}
|
||||
pricingManagementService.quickSetupProductPrice(ProductType.VLOG_VIDEO.getCode(), template.getId().toString(), template.getScenicId().toString(), template.getName(), template.getPrice(), template.getSlashPrice(), "个");
|
||||
if (i > 0) {
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
@@ -112,6 +117,7 @@ public class TemplateServiceImpl implements TemplateService {
|
||||
});
|
||||
}
|
||||
templateRepository.clearTemplateCache(template.getId());
|
||||
pricingManagementService.quickSetupProductPrice(ProductType.VLOG_VIDEO.getCode(), template.getId().toString(), template.getScenicId().toString(), template.getName(), template.getPrice(), template.getSlashPrice(), "个");
|
||||
if (i > 0) {
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
|
||||
Reference in New Issue
Block a user