This commit is contained in:
2025-07-27 08:59:08 +08:00
parent e9f44dd851
commit 563d83f849
35 changed files with 482 additions and 255 deletions

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.DeviceMapper;
import com.ycwl.basic.model.pc.device.entity.DeviceConfigEntity;
import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
@@ -27,26 +27,26 @@ public class DeviceRepository {
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);
return JacksonUtil.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), 3, TimeUnit.DAYS);
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceId), JacksonUtil.toJSONString(device), 3, TimeUnit.DAYS);
}
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);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_CACHE_KEY, deviceNo)), DeviceEntity.class);
}
DeviceEntity device = deviceMapper.getByDeviceNo(deviceNo);
if (null == device) {
device = deviceMapper.getByDeviceNo2(deviceNo);
}
if (null != device) {
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), JSONObject.toJSONString(device), 3, TimeUnit.DAYS);
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JSONObject.toJSONString(device), 3, TimeUnit.DAYS);
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), JacksonUtil.toJSONString(device), 3, TimeUnit.DAYS);
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JacksonUtil.toJSONString(device), 3, TimeUnit.DAYS);
} else {
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), "null", 60L, TimeUnit.SECONDS);
}
@@ -55,7 +55,7 @@ public class DeviceRepository {
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);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId)), DeviceConfigEntity.class);
}
DeviceConfigEntity deviceConfig = deviceMapper.getConfigByDeviceId(deviceId);
if (null == deviceConfig) {
@@ -64,7 +64,7 @@ public class DeviceRepository {
deviceConfig.setDeviceId(deviceId);
deviceMapper.addConfig(deviceConfig);
}
redisTemplate.opsForValue().set(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId), JSONObject.toJSONString(deviceConfig), 3, TimeUnit.DAYS);
redisTemplate.opsForValue().set(String.format(DEVICE_CONFIG_CACHE_KEY, deviceId), JacksonUtil.toJSONString(deviceConfig), 3, TimeUnit.DAYS);
return deviceConfig;
}
@@ -111,22 +111,22 @@ public class DeviceRepository {
device.setOnline(online);
device.setKeepaliveAt(keepaliveAt);
device.setIpAddr(ipAddr);
redisTemplate.opsForValue().set(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId), JSONObject.toJSONString(device), 3, TimeUnit.DAYS);
redisTemplate.opsForValue().set(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId), JacksonUtil.toJSONString(device), 3, TimeUnit.DAYS);
// deviceMapper.updateOnlineStatus(deviceId, ipAddr, online, keepaliveAt);
updateDeviceCache(device);
}
public DeviceEntity getOnlineStatus(Long deviceId) {
if (redisTemplate.hasKey(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId)), DeviceEntity.class);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId)), DeviceEntity.class);
} else {
return null;
}
}
private void updateDeviceCache(DeviceEntity device) {
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JSONObject.toJSONString(device));
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getNo()), JSONObject.toJSONString(device));
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JacksonUtil.toJSONString(device));
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getNo()), JacksonUtil.toJSONString(device));
}
public List<DeviceEntity> getAllDeviceByScenicId(Long scenicId) {

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.FaceMapper;
import com.ycwl.basic.mapper.FaceSampleMapper;
import com.ycwl.basic.model.pc.face.entity.FaceEntity;
@@ -30,11 +30,11 @@ public class FaceRepository {
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);
return JacksonUtil.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), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(FACE_CACHE_KEY, id), JacksonUtil.toJSONString(face), 12, TimeUnit.HOURS);
}
return face;
}

View File

@@ -1,7 +1,7 @@
package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ycwl.basic.utils.JacksonUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.ycwl.basic.mapper.OrderMapper;
import com.ycwl.basic.model.pc.order.entity.OrderEntity;
import com.ycwl.basic.model.pc.order.entity.OrderItemEntity;
@@ -27,25 +27,25 @@ public class OrderRepository {
public OrderEntity getOrder(Long orderId) {
if (redisTemplate.hasKey(String.format(ORDER_CACHE_KEY, orderId))) {
return JSON.parseObject(redisTemplate.opsForValue().get(String.format(ORDER_CACHE_KEY, orderId)), OrderEntity.class);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(ORDER_CACHE_KEY, orderId)), OrderEntity.class);
}
OrderEntity orderEntity = orderMapper.get(orderId);
if (orderEntity != null) {
redisTemplate.opsForValue().set(String.format(ORDER_CACHE_KEY, orderId), JSON.toJSONString(orderEntity), 60, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(String.format(ORDER_CACHE_KEY, orderId), JacksonUtil.toJSONString(orderEntity), 60, TimeUnit.SECONDS);
}
return orderEntity;
}
public List<OrderItemEntity> getOrderItems(Long orderId) {
if (redisTemplate.hasKey(String.format(ORDER_ITEMS_CACHE_KEY, orderId))) {
return JSON.parseArray(redisTemplate.opsForValue().get(String.format(ORDER_ITEMS_CACHE_KEY, orderId)), Long.class)
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(ORDER_ITEMS_CACHE_KEY, orderId)), new TypeReference<List<Long>>() {})
.stream().map(this::getOrderItemByOrderItemId).collect(Collectors.toList());
}
List<OrderItemEntity> orderItemEntities = orderMapper.listOrderItemByOrderId(orderId);
if (orderItemEntities != null) {
redisTemplate.opsForValue().set(
String.format(ORDER_ITEMS_CACHE_KEY, orderId),
JSONArray.toJSONString(orderItemEntities.stream().map(OrderItemEntity::getId).collect(Collectors.toList()))
JacksonUtil.toJSONString(orderItemEntities.stream().map(OrderItemEntity::getId).collect(Collectors.toList()))
);
}
return orderItemEntities;
@@ -53,11 +53,11 @@ public class OrderRepository {
public OrderItemEntity getOrderItemByOrderItemId(Long orderItemId) {
if (redisTemplate.hasKey(String.format(ORDER_ITEM_CACHE_KEY, orderItemId))) {
return JSON.parseObject(redisTemplate.opsForValue().get(String.format(ORDER_ITEM_CACHE_KEY, orderItemId)), OrderItemEntity.class);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(ORDER_ITEM_CACHE_KEY, orderItemId)), OrderItemEntity.class);
}
OrderItemEntity orderItemEntity = orderMapper.getOrderItem(orderItemId);
if (orderItemEntity != null) {
redisTemplate.opsForValue().set(String.format(ORDER_ITEM_CACHE_KEY, orderItemId), JSON.toJSONString(orderItemEntity));
redisTemplate.opsForValue().set(String.format(ORDER_ITEM_CACHE_KEY, orderItemId), JacksonUtil.toJSONString(orderItemEntity));
}
return orderItemEntity;
}

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSON;
import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.PriceConfigMapper;
import com.ycwl.basic.model.pc.price.entity.PriceConfigEntity;
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,13 +23,13 @@ public class PriceRepository {
String cacheKey = String.format(PRICE_SCENIC_TYPE_GOODS_CACHE, scenicId, type, goodsId);
PriceConfigEntity priceConfigEntity = null;
if (redisTemplate.hasKey(cacheKey)) {
priceConfigEntity = JSON.parseObject(redisTemplate.opsForValue().get(cacheKey), PriceConfigEntity.class);
priceConfigEntity = JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), PriceConfigEntity.class);
}
if (priceConfigEntity == null) {
priceConfigEntity = mapper.getPriceByScenicTypeGoods(scenicId, type, goodsId);
if (priceConfigEntity != null) {
redisTemplate.opsForValue().set(cacheKey, JSON.toJSONString(priceConfigEntity), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(PRICE_ID_CACHE, priceConfigEntity.getId()), JSON.toJSONString(priceConfigEntity), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(cacheKey, JacksonUtil.toJSONString(priceConfigEntity), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(PRICE_ID_CACHE, priceConfigEntity.getId()), JacksonUtil.toJSONString(priceConfigEntity), 12, TimeUnit.HOURS);
}
}
return priceConfigEntity;
@@ -39,7 +39,7 @@ public class PriceRepository {
String cacheKey = String.format(PRICE_ID_CACHE, id);
PriceConfigEntity priceConfigEntity = null;
if (redisTemplate.hasKey(cacheKey)) {
priceConfigEntity = JSON.parseObject(redisTemplate.opsForValue().get(cacheKey), PriceConfigEntity.class);
priceConfigEntity = JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), PriceConfigEntity.class);
}
return priceConfigEntity;
}

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.RenderWorkerMapper;
import com.ycwl.basic.model.pc.renderWorker.entity.RenderWorkerEntity;
import com.ycwl.basic.model.task.req.ClientStatusReqVo;
@@ -25,12 +25,12 @@ public class RenderWorkerRepository {
public RenderWorkerEntity getWorkerByAccessKey(String accessKey) {
String key = String.format(RENDER_WORKER_CACHE_KEY, accessKey);
if (redisTemplate.hasKey(key)) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(key), RenderWorkerEntity.class);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(key), RenderWorkerEntity.class);
}
RenderWorkerEntity renderWorker = mapper.findByAccessKey(accessKey);
if (renderWorker != null) {
redisTemplate.opsForValue().set(key, JSONObject.toJSONString(renderWorker), 1, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(RENDER_WORKER_CACHE_KEY, renderWorker.getId()), JSONObject.toJSONString(renderWorker), 1, TimeUnit.HOURS);
redisTemplate.opsForValue().set(key, JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(RENDER_WORKER_CACHE_KEY, renderWorker.getId()), JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
}
return renderWorker;
}
@@ -38,12 +38,12 @@ public class RenderWorkerRepository {
public RenderWorkerEntity getWorker(Long id) {
String key = String.format(RENDER_WORKER_CACHE_KEY, id);
if (redisTemplate.hasKey(key)) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(key), RenderWorkerEntity.class);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(key), RenderWorkerEntity.class);
}
RenderWorkerEntity renderWorker = mapper.getById(id);
if (renderWorker != null) {
redisTemplate.opsForValue().set(key, JSONObject.toJSONString(renderWorker), 1, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(RENDER_WORKER_CACHE_KEY, renderWorker.getAccessKey()), JSONObject.toJSONString(renderWorker), 1, TimeUnit.HOURS);
redisTemplate.opsForValue().set(key, JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(RENDER_WORKER_CACHE_KEY, renderWorker.getAccessKey()), JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
}
return renderWorker;
}
@@ -69,14 +69,14 @@ public class RenderWorkerRepository {
if (!redisTemplate.hasKey(key)) {
mapper.updateHost(id, worker);
}
redisTemplate.opsForValue().set(key, JSONObject.toJSONString(status), 1, TimeUnit.HOURS);
redisTemplate.opsForValue().set(key, JacksonUtil.toJSONString(status), 1, TimeUnit.HOURS);
}
public ClientStatusReqVo getWorkerHostStatus(Long id) {
String key = String.format(RENDER_WORKER_STATUS_CACHE_KEY, id);
if (redisTemplate.hasKey(key)) {
String status = redisTemplate.opsForValue().get(key);
return JSONObject.parseObject(status, ClientStatusReqVo.class);
return JacksonUtil.parseObject(status, ClientStatusReqVo.class);
}
return null;
}

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.MpConfigMapper;
import com.ycwl.basic.mapper.MpNotifyConfigMapper;
import com.ycwl.basic.mapper.ScenicMapper;
@@ -34,41 +34,41 @@ public class ScenicRepository {
public ScenicEntity getScenic(Long id) {
if (redisTemplate.hasKey(String.format(SCENIC_CACHE_KEY, id))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_CACHE_KEY, id)), ScenicEntity.class);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_CACHE_KEY, id)), ScenicEntity.class);
}
ScenicEntity scenic = scenicMapper.get(id);
if (scenic != null) {
redisTemplate.opsForValue().set(String.format(SCENIC_CACHE_KEY, id), JSONObject.toJSONString(scenic));
redisTemplate.opsForValue().set(String.format(SCENIC_CACHE_KEY, id), JacksonUtil.toJSONString(scenic));
}
return scenic;
}
public ScenicConfigEntity getScenicConfig(Long scenicId) {
if (redisTemplate.hasKey(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId)), ScenicConfigEntity.class);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId)), ScenicConfigEntity.class);
}
ScenicConfigEntity scenicConfig = scenicMapper.getConfig(scenicId);
if (scenicConfig != null) {
redisTemplate.opsForValue().set(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId), JSONObject.toJSONString(scenicConfig));
redisTemplate.opsForValue().set(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId), JacksonUtil.toJSONString(scenicConfig));
}
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);
return JacksonUtil.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));
redisTemplate.opsForValue().set(String.format(SCENIC_MP_CACHE_KEY, scenicId), JacksonUtil.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);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId)), ScenicMpNotifyVO.class);
}
MpConfigEntity mpConfig = getScenicMpConfig(scenicId);
if (mpConfig == null) {
@@ -93,7 +93,7 @@ public class ScenicRepository {
break;
}
});
redisTemplate.opsForValue().set(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId), JSONObject.toJSONString(mpNotifyConfig));
redisTemplate.opsForValue().set(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId), JacksonUtil.toJSONString(mpNotifyConfig));
return mpNotifyConfig;
}

View File

@@ -1,6 +1,7 @@
package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.utils.JacksonUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.ycwl.basic.mapper.FaceMapper;
import com.ycwl.basic.mapper.FaceSampleMapper;
import com.ycwl.basic.mapper.TemplateMapper;
@@ -56,10 +57,10 @@ public class TemplateRepository {
public List<TemplateRespVO> getTemplateListByScenicId(Long scenicId) {
List<Long> idList;
if (redisTemplate.hasKey(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId))) {
idList = JSONObject.parseArray(redisTemplate.opsForValue().get(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId)), Long.class);
idList = JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId)), new TypeReference<List<Long>>() {});
} else {
idList = templateMapper.listEnabledTemplateIdByScenicId(scenicId);
redisTemplate.opsForValue().set(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId), JSONObject.toJSONString(idList));
redisTemplate.opsForValue().set(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId), JacksonUtil.toJSONString(idList));
}
if (idList == null || idList.isEmpty()) {
return Collections.emptyList();
@@ -78,7 +79,7 @@ public class TemplateRepository {
public TemplateRespVO getTemplate(Long templateId) {
if (redisTemplate.hasKey(String.format(TEMPLATE_CACHE_KEY, templateId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(TEMPLATE_CACHE_KEY, templateId)), TemplateRespVO.class);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(TEMPLATE_CACHE_KEY, templateId)), TemplateRespVO.class);
}
TemplateRespVO template = templateMapper.getById(templateId);
if (template == null) {
@@ -86,7 +87,7 @@ public class TemplateRepository {
}
if (null == template.getPid() || template.getPid() == 0) {
template.setChildren(templateMapper.getByPid(templateId));
redisTemplate.opsForValue().set(String.format(TEMPLATE_CACHE_KEY, templateId), JSONObject.toJSONString(template));
redisTemplate.opsForValue().set(String.format(TEMPLATE_CACHE_KEY, templateId), JacksonUtil.toJSONString(template));
return template;
} else {
clearTemplateCache(templateId);
@@ -99,7 +100,7 @@ public class TemplateRepository {
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);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId)), TemplateConfigEntity.class);
}
TemplateConfigEntity templateConfig = templateMapper.getConfig(templateId);
if (templateConfig == null) {
@@ -108,7 +109,7 @@ public class TemplateRepository {
templateConfig.setTemplateId(templateId);
templateMapper.addConfig(templateConfig);
}
redisTemplate.opsForValue().set(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId), JSONObject.toJSONString(templateConfig));
redisTemplate.opsForValue().set(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId), JacksonUtil.toJSONString(templateConfig));
return templateConfig;
}

View File

@@ -1,6 +1,6 @@
package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSON;
import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.VideoMapper;
import com.ycwl.basic.model.pc.video.entity.MemberVideoEntity;
import com.ycwl.basic.model.pc.video.entity.VideoEntity;
@@ -25,24 +25,24 @@ public class VideoRepository {
public VideoEntity getVideo(Long videoId) {
if (redisTemplate.hasKey(String.format(VIDEO_CACHE_KEY, videoId))) {
return JSON.parseObject(redisTemplate.opsForValue().get(String.format(VIDEO_CACHE_KEY, videoId)), VideoEntity.class);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(VIDEO_CACHE_KEY, videoId)), VideoEntity.class);
}
VideoEntity video = videoMapper.getEntity(videoId);
if (video != null) {
redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, videoId), JSON.toJSONString(video), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, video.getTaskId()), JSON.toJSONString(video), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, videoId), JacksonUtil.toJSONString(video), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, video.getTaskId()), JacksonUtil.toJSONString(video), 12, TimeUnit.HOURS);
}
return video;
}
public VideoEntity getVideoByTaskId(Long taskId) {
if (redisTemplate.hasKey(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId))) {
return JSON.parseObject(redisTemplate.opsForValue().get(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId)), VideoEntity.class);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId)), VideoEntity.class);
}
VideoEntity video = videoMapper.findByTaskId(taskId);
if (video != null) {
redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId), JSON.toJSONString(video), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, video.getId()), JSON.toJSONString(video), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId), JacksonUtil.toJSONString(video), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, video.getId()), JacksonUtil.toJSONString(video), 12, TimeUnit.HOURS);
}
return video;
}

View File

@@ -1,8 +1,6 @@
package com.ycwl.basic.repository;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ycwl.basic.utils.JacksonUtil;
import com.ycwl.basic.mapper.TaskMapper;
import com.ycwl.basic.mapper.VideoMapper;
import com.ycwl.basic.model.pc.task.entity.TaskEntity;
@@ -27,11 +25,11 @@ public class VideoTaskRepository {
public TaskEntity getTaskById(Long taskId) {
if (redisTemplate.hasKey(String.format(TASK_CACHE_KEY, taskId))) {
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(TASK_CACHE_KEY, taskId)), TaskEntity.class);
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(TASK_CACHE_KEY, taskId)), TaskEntity.class);
} else {
TaskEntity task = taskMapper.get(taskId);
if (task != null && 1 == task.getStatus()) {
redisTemplate.opsForValue().set(String.format(TASK_CACHE_KEY, taskId), JSONObject.toJSONString(task), 12, TimeUnit.HOURS);
redisTemplate.opsForValue().set(String.format(TASK_CACHE_KEY, taskId), JacksonUtil.toJSONString(task), 12, TimeUnit.HOURS);
}
return task;
}
@@ -48,14 +46,14 @@ public class VideoTaskRepository {
return null;
}
Date shotTime = taskRespVO.getCreateTime();
JSONObject paramJson = JSON.parseObject(taskRespVO.getTaskParams());
JacksonUtil.JSONObjectCompat paramJson = JacksonUtil.JSONObjectCompat.parseObject(taskRespVO.getTaskParams());
if (paramJson != null) {
Optional<String> any = paramJson.keySet().stream().filter(StringUtils::isNumeric).findAny();
if (any.isPresent()) {
JSONArray jsonArray = paramJson.getJSONArray(any.get());
if (!jsonArray.isEmpty()) {
JSONObject jsonObject = jsonArray.getJSONObject(0);
if (jsonObject.containsKey("createTime")) {
var jsonArray = paramJson.getJSONArray(any.get());
if (jsonArray != null && !jsonArray.isEmpty()) {
JacksonUtil.JSONObjectCompat jsonObject = jsonArray.get(0);
if (jsonObject.getLong("createTime") != null) {
shotTime = new Date(jsonObject.getLong("createTime"));
}
}