You've already forked FrameTour-BE
bug
This commit is contained in:
@ -0,0 +1,69 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ycwl.basic.mapper.DeviceMapper;
|
||||
import com.ycwl.basic.model.pc.device.entity.DeviceConfigEntity;
|
||||
import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
|
||||
import com.ycwl.basic.utils.SnowFlakeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DeviceRepository {
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
public static final String DEVICE_CACHE_KEY = "device:%s";
|
||||
public static final String DEVICE_CONFIG_CACHE_KEY = "device:%s:config";
|
||||
|
||||
public DeviceEntity getDevice(Long deviceId) {
|
||||
if (redisTemplate.hasKey(String.format(DEVICE_CACHE_KEY, deviceId))) {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_CACHE_KEY, deviceId)), DeviceEntity.class);
|
||||
}
|
||||
DeviceEntity device = deviceMapper.getByDeviceId(deviceId);
|
||||
if (null != device) {
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceId), JSONObject.toJSONString(device));
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
public DeviceEntity getDeviceByDeviceNo(String deviceNo) {
|
||||
if (redisTemplate.hasKey(String.format(DEVICE_CACHE_KEY, deviceNo))) {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_CACHE_KEY, deviceNo)), DeviceEntity.class);
|
||||
}
|
||||
DeviceEntity device = deviceMapper.getByDeviceNo(deviceNo);
|
||||
if (null != device) {
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), JSONObject.toJSONString(device));
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
public DeviceConfigEntity getDeviceConfig(Long deviceId) {
|
||||
if (redisTemplate.hasKey(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId))) {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId)), DeviceConfigEntity.class);
|
||||
}
|
||||
DeviceConfigEntity deviceConfig = deviceMapper.getConfigByDeviceId(deviceId);
|
||||
if (null == deviceConfig) {
|
||||
deviceConfig = new DeviceConfigEntity();
|
||||
deviceConfig.setId(SnowFlakeUtil.getLongId());
|
||||
deviceConfig.setDeviceId(deviceId);
|
||||
deviceMapper.addConfig(deviceConfig);
|
||||
}
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId), JSONObject.toJSONString(deviceConfig));
|
||||
return deviceConfig;
|
||||
}
|
||||
|
||||
public boolean clearDeviceCache(Long deviceId) {
|
||||
if (redisTemplate.hasKey(String.format(DEVICE_CACHE_KEY, deviceId))) {
|
||||
DeviceEntity device = getDevice(deviceId);
|
||||
redisTemplate.delete(String.format(DEVICE_CACHE_KEY, device.getNo()));
|
||||
redisTemplate.delete(String.format(DEVICE_CONFIG_CACHE_KEY, device.getNo()));
|
||||
}
|
||||
redisTemplate.delete(String.format(DEVICE_CACHE_KEY, deviceId));
|
||||
redisTemplate.delete(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ycwl.basic.mapper.FaceMapper;
|
||||
import com.ycwl.basic.mapper.FaceSampleMapper;
|
||||
import com.ycwl.basic.model.pc.face.entity.FaceEntity;
|
||||
import com.ycwl.basic.model.pc.faceSample.entity.FaceSampleEntity;
|
||||
import com.ycwl.basic.model.pc.faceSample.resp.FaceSampleRespVO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@ -24,14 +24,40 @@ public class FaceRepository {
|
||||
@Autowired
|
||||
private FaceSampleMapper faceSampleMapper;
|
||||
|
||||
public static final String FACE_CACHE_KEY = "face:%s";
|
||||
public static final String FACE_SAMPLE_CACHE_KEY = "face:%s:sample";
|
||||
|
||||
public FaceEntity getFace(Long id) {
|
||||
if (redisTemplate.hasKey(String.format(FACE_CACHE_KEY, id))) {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(FACE_CACHE_KEY, id)), FaceEntity.class);
|
||||
}
|
||||
FaceEntity face = faceMapper.get(id);
|
||||
if (face != null) {
|
||||
redisTemplate.opsForValue().set(String.format(FACE_CACHE_KEY, id), JSONObject.toJSONString(face));
|
||||
}
|
||||
return face;
|
||||
}
|
||||
|
||||
public List<FaceSampleEntity> getFaceSampleList(Long faceId) {
|
||||
FaceEntity face = faceMapper.get(faceId);
|
||||
if (redisTemplate.hasKey(String.format(FACE_SAMPLE_CACHE_KEY, faceId))) {
|
||||
return JSONObject.parseArray(redisTemplate.opsForValue().get(String.format(FACE_SAMPLE_CACHE_KEY, faceId)), FaceSampleEntity.class);
|
||||
}
|
||||
FaceEntity face = getFace(faceId);
|
||||
if (face == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (StringUtils.isBlank(face.getMatchSampleIds())) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return faceSampleMapper.listByIds(Arrays.stream(face.getMatchSampleIds().split(",")).map(Long::valueOf).collect(Collectors.toList()));
|
||||
List<FaceSampleEntity> list = faceSampleMapper.listByIds(Arrays.stream(face.getMatchSampleIds().split(",")).map(Long::valueOf).collect(Collectors.toList()));
|
||||
if (!list.isEmpty()) {
|
||||
redisTemplate.opsForValue().set(String.format(FACE_SAMPLE_CACHE_KEY, faceId), JSONObject.toJSONString(list));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void clearFaceCache(Long faceId) {
|
||||
redisTemplate.delete(String.format(FACE_CACHE_KEY, faceId));
|
||||
redisTemplate.delete(String.format(FACE_SAMPLE_CACHE_KEY, faceId));
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class OrderRepository {
|
||||
@Autowired
|
||||
@ -17,10 +19,11 @@ public class OrderRepository {
|
||||
|
||||
public boolean checkUserBuyItem(Long userId, int goodsType, Long goodsId) {
|
||||
if (redisTemplate.hasKey(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId))) {
|
||||
return true;
|
||||
return "1".equals(redisTemplate.opsForValue().get(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId)));
|
||||
}
|
||||
OrderEntity orderEntity = orderMapper.getUserBuyItem(userId, goodsType, goodsId);
|
||||
if (orderEntity == null) {
|
||||
redisTemplate.opsForValue().set(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId), "0", 60, TimeUnit.SECONDS);
|
||||
return false;
|
||||
}
|
||||
redisTemplate.opsForValue().set(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId), "1");
|
||||
|
@ -81,6 +81,12 @@ public class ScenicRepository {
|
||||
case 0:
|
||||
mpNotifyConfig.setVideoGeneratedTemplateId(item.getTemplateId());
|
||||
break;
|
||||
case 1:
|
||||
mpNotifyConfig.setVideoDownloadTemplateId(item.getTemplateId());
|
||||
break;
|
||||
case 2:
|
||||
mpNotifyConfig.setVideoPreExpireTemplateId(item.getTemplateId());
|
||||
break;
|
||||
}
|
||||
});
|
||||
redisTemplate.opsForValue().set(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId), JSONObject.toJSONString(mpNotifyConfig));
|
||||
@ -95,6 +101,22 @@ public class ScenicRepository {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getVideoDownloadTemplateId(Long scenicId) {
|
||||
ScenicMpNotifyVO scenicMpNotifyConfig = getScenicMpNotifyConfig(scenicId);
|
||||
if (scenicMpNotifyConfig != null) {
|
||||
return scenicMpNotifyConfig.getVideoDownloadTemplateId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getVideoPreExpireTemplateId(Long scenicId) {
|
||||
ScenicMpNotifyVO scenicMpNotifyConfig = getScenicMpNotifyConfig(scenicId);
|
||||
if (scenicMpNotifyConfig != null) {
|
||||
return scenicMpNotifyConfig.getVideoPreExpireTemplateId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void clearCache(Long scenicId) {
|
||||
redisTemplate.delete(String.format(SCENIC_CACHE_KEY, scenicId));
|
||||
redisTemplate.delete(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId));
|
||||
|
@ -17,10 +17,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
@Service // 临时这么用
|
||||
public class TemplateRepository {
|
||||
@Autowired
|
||||
private FaceMapper faceMapper;
|
||||
@Autowired
|
||||
private FaceSampleMapper faceSampleMapper;
|
||||
@Autowired
|
||||
private TemplateMapper templateMapper;
|
||||
@Autowired
|
||||
@ -39,6 +35,15 @@ public class TemplateRepository {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public int getTemplateMinimalPlaceholderCount(Long templateId) {
|
||||
TemplateConfigEntity config = getTemplateConfig(templateId);
|
||||
if (config == null || config.getMinimalPlaceholderFill() == null) {
|
||||
return 1;
|
||||
} else {
|
||||
return config.getMinimalPlaceholderFill();
|
||||
}
|
||||
}
|
||||
|
||||
public List<TemplateRespVO> getTemplateListByScenicId(Long scenicId) {
|
||||
List<Long> idList;
|
||||
if (redisTemplate.hasKey(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId))) {
|
||||
@ -69,6 +74,9 @@ public class TemplateRepository {
|
||||
}
|
||||
|
||||
public TemplateConfigEntity getTemplateConfig(Long templateId) {
|
||||
if (templateId == null) {
|
||||
return new TemplateConfigEntity();
|
||||
}
|
||||
if (redisTemplate.hasKey(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId))) {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId)), TemplateConfigEntity.class);
|
||||
}
|
||||
|
Reference in New Issue
Block a user