xiewenjie 3 лет назад
Родитель
Сommit
5ab7de0a30

+ 19 - 7
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/ModelUploadServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fdkk.sxz.webApi.service.impl;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
@@ -29,6 +30,7 @@ import com.fdkk.sxz.webApi.service.custom.ICustomProductService;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import net.oschina.j2cache.CacheChannel;
+import net.oschina.j2cache.CacheObject;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -86,6 +88,8 @@ public class ModelUploadServiceImpl extends BaseServiceImpl<IModelUploadMapper,
     @Autowired
     private CacheChannel cacheChannel;
 
+    private String region = "ModelUploadEntity";
+
     @Override
     public PageInfo<ModelUploadEntity> listByPage(RequestModelUpload param) {
         LambdaQueryWrapper<ModelUploadEntity> wrapper = Wrappers.lambdaQuery();
@@ -104,9 +108,9 @@ public class ModelUploadServiceImpl extends BaseServiceImpl<IModelUploadMapper,
         ModelUploadEntity entity = findById(id);
         boolean removeById = super.removeById(id);
         if (removeById) {
-            cacheChannel.evict("ModelUploadEntity", "id::" + id);
+            cacheChannel.evict(region, "id::" + id);
             if (ObjectUtil.isNotNull(entity)) {
-                cacheChannel.evict("ModelUploadEntity", "fileId::" + entity.getFileId());
+                cacheChannel.evict(region, "fileId::" + entity.getFileId());
             }
         }
         return removeById;
@@ -114,9 +118,17 @@ public class ModelUploadServiceImpl extends BaseServiceImpl<IModelUploadMapper,
 
     @Override
     public ModelUploadEntity findById(Long id) {
-        ModelUploadEntity entity = super.findById(id);
-        if (ObjectUtil.isNotNull(entity)) {
-            cacheChannel.set("ModelUploadEntity", "id::" + entity.getId(), entity, 60 * 30);
+        ModelUploadEntity entity = null;
+        if (cacheChannel.exists(region, "id::" + id)) {
+            CacheObject cache = cacheChannel.get(region, "id::" + id);
+            entity = BeanUtil.toBean(cache.getValue(), ModelUploadEntity.class);
+        } else {
+            entity = super.findById(entity);
+            if (ObjectUtil.isNotNull(entity)) {
+                cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
+                cacheChannel.set(region, "fileId::" + entity.getFileId(), entity, 60 * 30);
+
+            }
         }
         return entity;
     }
@@ -125,8 +137,8 @@ public class ModelUploadServiceImpl extends BaseServiceImpl<IModelUploadMapper,
     public boolean updateById(ModelUploadEntity entity) {
         boolean updateById = super.updateById(entity);
         if (updateById) {
-            cacheChannel.set("ModelUploadEntity", "id::" + entity.getId(), entity, 60 * 30);
-            cacheChannel.set("ModelUploadEntity", "fileId::" + entity.getFileId(), entity, 60 * 30);
+            cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
+            cacheChannel.set(region, "fileId::" + entity.getFileId(), entity, 60 * 30);
         }
         return updateById;
     }

+ 25 - 9
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/RenovationPartsAttachingServiceImpl.java

@@ -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;
     }

+ 16 - 6
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/RenovationPartsBrandServiceImpl.java

@@ -1,11 +1,13 @@
 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.RenovationPartsBrandEntity;
 import com.fdkk.sxz.webApi.mapper.IRenovationPartsBrandMapper;
 import com.fdkk.sxz.webApi.service.IRenovationPartsBrandService;
 import net.oschina.j2cache.CacheChannel;
+import net.oschina.j2cache.CacheObject;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -16,12 +18,20 @@ import org.springframework.stereotype.Service;
 public class RenovationPartsBrandServiceImpl extends BaseServiceImpl<IRenovationPartsBrandMapper, RenovationPartsBrandEntity> implements IRenovationPartsBrandService {
     @Autowired
     private CacheChannel cacheChannel;
-    
+
+    private String region = "RenovationPartsBrandEntity";
+
     @Override
     public RenovationPartsBrandEntity findById(Long id) {
-        RenovationPartsBrandEntity entity = super.findById(id);
-        if (ObjectUtil.isNotNull(entity)) {
-            cacheChannel.set("RenovationPartsBrandEntity", "id::" + entity.getId(), entity, 60 * 30);
+        RenovationPartsBrandEntity entity = null;
+        if (cacheChannel.exists(region, "id::" + id)) {
+            CacheObject cache = cacheChannel.get(region, "id::" + id);
+            entity = BeanUtil.toBean(cache.getValue(), RenovationPartsBrandEntity.class);
+        } else {
+            entity = super.findById(id);
+            if (ObjectUtil.isNotNull(entity)) {
+                cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
+            }
         }
         return entity;
     }
@@ -30,7 +40,7 @@ public class RenovationPartsBrandServiceImpl extends BaseServiceImpl<IRenovation
     public boolean updateById(RenovationPartsBrandEntity entity) {
         boolean updateById = super.updateById(entity);
         if (updateById) {
-            cacheChannel.set("RenovationPartsBrandEntity", "id::" + entity.getId(), entity, 60 * 30);
+            cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
         }
         return updateById;
     }
@@ -39,7 +49,7 @@ public class RenovationPartsBrandServiceImpl extends BaseServiceImpl<IRenovation
     public boolean removeById(Long id) {
         boolean removeById = super.removeById(id);
         if (removeById) {
-            cacheChannel.evict("RenovationPartsBrandEntity", "id::" + id);
+            cacheChannel.evict(region, "id::" + id);
         }
         return removeById;
     }

+ 15 - 5
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/RenovationPartsServiceImpl.java

@@ -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.RenovationPartsEntity;
@@ -10,6 +11,7 @@ import com.fdkk.sxz.webApi.mapper.*;
 import com.fdkk.sxz.webApi.service.IRenovationPartsService;
 import lombok.extern.slf4j.Slf4j;
 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;
@@ -40,11 +42,19 @@ public class RenovationPartsServiceImpl extends BaseServiceImpl<IRenovationParts
     @Autowired
     private IRenovationPartsSizeMapper renovationPartsSizeMapper;
 
+    private String region = "RenovationPartsEntity";
+
     @Override
     public RenovationPartsEntity findById(Long id) {
-        RenovationPartsEntity entity = super.findById(id);
-        if (ObjectUtil.isNotNull(entity)) {
-            cacheChannel.set("RenovationPartsEntity", "id::" + entity.getId(), entity, 60 * 30);
+        RenovationPartsEntity entity = null;
+        if (cacheChannel.exists(region, "id::" + id)) {
+            CacheObject cache = cacheChannel.get(region, "id::" + id);
+            entity = BeanUtil.toBean(cache.getValue(), RenovationPartsEntity.class);
+        } else {
+            entity = super.findById(entity);
+            if (ObjectUtil.isNotNull(entity)) {
+                cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
+            }
         }
         return entity;
     }
@@ -53,7 +63,7 @@ public class RenovationPartsServiceImpl extends BaseServiceImpl<IRenovationParts
     public boolean updateById(RenovationPartsEntity entity) {
         boolean updateById = super.updateById(entity);
         if (updateById) {
-            cacheChannel.set("RenovationPartsEntity", "id::" + entity.getId(), entity, 60 * 30);
+            cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
         }
         return updateById;
     }
@@ -62,7 +72,7 @@ public class RenovationPartsServiceImpl extends BaseServiceImpl<IRenovationParts
     public boolean removeById(Long id) {
         boolean removeById = super.removeById(id);
         if (removeById) {
-            cacheChannel.evict("RenovationPartsEntity", "id::" + id);
+            cacheChannel.evict(region, "id::" + id);
         }
         return removeById;
     }

+ 16 - 7
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/RenovationPartsSizeServiceImpl.java

@@ -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.RenovationPartsSizeEntity;
@@ -7,6 +8,7 @@ import com.fdkk.sxz.vo.response.ResponseRenovationPartsSize;
 import com.fdkk.sxz.webApi.mapper.IRenovationPartsSizeMapper;
 import com.fdkk.sxz.webApi.service.IRenovationPartsSizeService;
 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,6 +22,7 @@ public class RenovationPartsSizeServiceImpl extends BaseServiceImpl<IRenovationP
     @Autowired
     private CacheChannel cacheChannel;
 
+    private String region = "RenovationPartsSizeEntity";
 
     @Override
     public ResponseRenovationPartsSize findSizeByDetailId(Long id) {
@@ -32,9 +35,15 @@ public class RenovationPartsSizeServiceImpl extends BaseServiceImpl<IRenovationP
 
     @Override
     public RenovationPartsSizeEntity findById(Long id) {
-        RenovationPartsSizeEntity entity = super.findById(id);
-        if (ObjectUtil.isNotNull(entity)) {
-            cacheChannel.set("RenovationPartsSizeEntity", "id::" + entity.getId(), entity, 60 * 30);
+        RenovationPartsSizeEntity entity = null;
+        if (cacheChannel.exists(region, "id::" + id)) {
+            CacheObject cache = cacheChannel.get(region, "id::" + id);
+            entity = BeanUtil.toBean(cache.getValue(), RenovationPartsSizeEntity.class);
+        } else {
+            entity = super.findById(id);
+            if (ObjectUtil.isNotNull(entity)) {
+                cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
+            }
         }
         return entity;
     }
@@ -43,8 +52,8 @@ public class RenovationPartsSizeServiceImpl extends BaseServiceImpl<IRenovationP
     public boolean updateById(RenovationPartsSizeEntity entity) {
         boolean updateById = super.updateById(entity);
         if (updateById) {
-            cacheChannel.evict("ResponseRenovationPartsSize", "id::" + entity.getId());
-            cacheChannel.set("RenovationPartsSizeEntity", "id::" + entity.getId(), entity, 60 * 30);
+            cacheChannel.evict(region, "responseId::" + entity.getId());
+            cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
         }
         return updateById;
     }
@@ -53,8 +62,8 @@ public class RenovationPartsSizeServiceImpl extends BaseServiceImpl<IRenovationP
     public boolean removeById(Long id) {
         boolean removeById = super.removeById(id);
         if (removeById) {
-            cacheChannel.evict("ResponseRenovationPartsSize", "id::" + id);
-            cacheChannel.evict("RenovationPartsSizeEntity", "id::" + id);
+            cacheChannel.evict(region, "responseId::" + id);
+            cacheChannel.evict(region, "id::" + id);
         }
         return removeById;
     }

+ 14 - 5
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/RenovationPartsTypeServiceImpl.java

@@ -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.RenovationPartsTypeEntity;
@@ -7,6 +8,7 @@ import com.fdkk.sxz.vo.response.ResponseRenovationPartsType;
 import com.fdkk.sxz.webApi.mapper.IRenovationPartsTypeMapper;
 import com.fdkk.sxz.webApi.service.IRenovationPartsTypeService;
 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;
@@ -22,6 +24,7 @@ public class RenovationPartsTypeServiceImpl extends BaseServiceImpl<IRenovationP
 
     @Autowired
     private CacheChannel cacheChannel;
+    private String region = "RenovationPartsTypeEntity";
 
     @Override
     public List<ResponseRenovationPartsType> findTypeByPartsId(Long id) {
@@ -30,9 +33,15 @@ public class RenovationPartsTypeServiceImpl extends BaseServiceImpl<IRenovationP
 
     @Override
     public RenovationPartsTypeEntity findById(Long id) {
-        RenovationPartsTypeEntity entity = super.findById(id);
-        if (ObjectUtil.isNotNull(entity)) {
-            cacheChannel.set("RenovationPartsTypeEntity", "id::" + entity.getId(), entity, 60 * 30);
+        RenovationPartsTypeEntity entity = null;
+        if (cacheChannel.exists(region, "id::" + id)) {
+            CacheObject cache = cacheChannel.get(region, "id::" + id);
+            entity = BeanUtil.toBean(cache.getValue(), RenovationPartsTypeEntity.class);
+        } else {
+            entity = super.findById(id);
+            if (ObjectUtil.isNotNull(entity)) {
+                cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
+            }
         }
         return entity;
     }
@@ -41,7 +50,7 @@ public class RenovationPartsTypeServiceImpl extends BaseServiceImpl<IRenovationP
     public boolean updateById(RenovationPartsTypeEntity entity) {
         boolean updateById = super.updateById(entity);
         if (updateById) {
-            cacheChannel.set("RenovationPartsTypeEntity", "id::" + entity.getId(), entity, 60 * 30);
+            cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
         }
         return updateById;
     }
@@ -50,7 +59,7 @@ public class RenovationPartsTypeServiceImpl extends BaseServiceImpl<IRenovationP
     public boolean removeById(Long id) {
         boolean removeById = super.removeById(id);
         if (removeById) {
-            cacheChannel.evict("RenovationPartsTypeEntity", "id::" + id);
+            cacheChannel.evict(region, "id::" + id);
         }
         return removeById;
     }