|
@@ -1,5 +1,6 @@
|
|
|
package com.fdkk.sxz.webApi.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.fdkk.sxz.base.impl.BaseServiceImpl;
|
|
|
import com.fdkk.sxz.entity.RenovationPartsAttachingEntity;
|
|
@@ -7,6 +8,7 @@ import com.fdkk.sxz.vo.response.ResponseRenovationPartsAttaching;
|
|
|
import com.fdkk.sxz.webApi.mapper.IRenovationPartsAttachingMapper;
|
|
|
import com.fdkk.sxz.webApi.service.IRenovationPartsAttachingService;
|
|
|
import net.oschina.j2cache.CacheChannel;
|
|
|
+import net.oschina.j2cache.CacheObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -20,20 +22,34 @@ public class RenovationPartsAttachingServiceImpl extends BaseServiceImpl<IRenova
|
|
|
@Autowired
|
|
|
private CacheChannel cacheChannel;
|
|
|
|
|
|
+ private String region = "PartsAttachingEntity";
|
|
|
+
|
|
|
@Override
|
|
|
public ResponseRenovationPartsAttaching findAttachinByDetailId(Long id) {
|
|
|
- ResponseRenovationPartsAttaching entity = getBaseMapper().findAttachinByDetailId(id);
|
|
|
- if (ObjectUtil.isNotNull(entity)) {
|
|
|
- cacheChannel.set("ResponseRenovationPartsAttaching", "id::" + entity.getId(), entity, 60 * 30);
|
|
|
+ ResponseRenovationPartsAttaching entity = null;
|
|
|
+ if (cacheChannel.exists(region, "responseId::" + id)) {
|
|
|
+ CacheObject cache = cacheChannel.get(region, "responseId::" + id);
|
|
|
+ entity = BeanUtil.toBean(cache.getValue(), ResponseRenovationPartsAttaching.class);
|
|
|
+ } else {
|
|
|
+ entity = getBaseMapper().findAttachinByDetailId(id);
|
|
|
+ if (ObjectUtil.isNotNull(entity)) {
|
|
|
+ cacheChannel.set(region, "responseId::" + entity.getId(), entity, 60 * 30);
|
|
|
+ }
|
|
|
}
|
|
|
return entity;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public RenovationPartsAttachingEntity findByDetailId(Long id) {
|
|
|
- RenovationPartsAttachingEntity entity = getBaseMapper().findByDetailId(id);
|
|
|
- if (ObjectUtil.isNotNull(id)) {
|
|
|
- cacheChannel.set("PartsAttachingEntity", "id::" + entity.getId(), entity, 60 * 30);
|
|
|
+ RenovationPartsAttachingEntity entity = null;
|
|
|
+ if (cacheChannel.exists(region, "detailId::" + id)) {
|
|
|
+ CacheObject cache = cacheChannel.get(region, "detailId::" + id);
|
|
|
+ entity = BeanUtil.toBean(cache.getValue(), RenovationPartsAttachingEntity.class);
|
|
|
+ } else {
|
|
|
+ entity = getBaseMapper().findByDetailId(id);
|
|
|
+ if (ObjectUtil.isNotNull(entity)) {
|
|
|
+ cacheChannel.set(region, "detailId::" + entity.getId(), entity, 60 * 30);
|
|
|
+ }
|
|
|
}
|
|
|
return entity;
|
|
|
}
|
|
@@ -42,7 +58,7 @@ public class RenovationPartsAttachingServiceImpl extends BaseServiceImpl<IRenova
|
|
|
public boolean updateById(RenovationPartsAttachingEntity entity) {
|
|
|
boolean updateById = super.updateById(entity);
|
|
|
if (updateById) {
|
|
|
- cacheChannel.set("PartsAttachingEntity", "id::" + entity.getId(), entity, 60 * 30);
|
|
|
+ cacheChannel.set(region, "detailId::" + entity.getId(), entity, 60 * 30);
|
|
|
}
|
|
|
return updateById;
|
|
|
}
|
|
@@ -51,8 +67,8 @@ public class RenovationPartsAttachingServiceImpl extends BaseServiceImpl<IRenova
|
|
|
public boolean removeById(Long id) {
|
|
|
boolean removeById = super.removeById(id);
|
|
|
if (removeById) {
|
|
|
- cacheChannel.evict("ResponseRenovationPartsAttaching", "id::" + id);
|
|
|
- cacheChannel.evict("PartsAttachingEntity", "id::" + id);
|
|
|
+ cacheChannel.evict(region, "responseId::" + id);
|
|
|
+ cacheChannel.evict(region, "detailId::" + id);
|
|
|
}
|
|
|
return removeById;
|
|
|
}
|