فهرست منبع

修改缓存bug

xiewenjie 3 سال پیش
والد
کامیت
da4b8e4787

+ 63 - 61
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/ModelUploadServiceImpl.java

@@ -136,9 +136,13 @@ public class ModelUploadServiceImpl extends BaseServiceImpl<IModelUploadMapper,
     @Override
     public boolean updateById(ModelUploadEntity entity) {
         boolean updateById = super.updateById(entity);
-        if (updateById) {
+        ModelUploadEntity byId = super.findById(entity.getId());
+        if (updateById && ObjectUtil.isNotNull(byId)) {
             cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
             cacheChannel.set(region, "fileId::" + entity.getFileId(), entity, 60 * 30);
+        } else {
+            cacheChannel.evict(region, "id::" + entity.getId());
+            cacheChannel.evict(region, "fileId::" + entity.getFileId());
         }
         return updateById;
     }
@@ -310,75 +314,73 @@ public class ModelUploadServiceImpl extends BaseServiceImpl<IModelUploadMapper,
     @Override
     public ResponseModelCustom findCustom(Long id) {
         ModelUploadEntity entity = findById(id);
-
         ResponseModelCustom responseModelCustomUpload = new ResponseModelCustom();
-        responseModelCustomUpload.setId(entity.getId());
-        responseModelCustomUpload.setCreateTime(entity.getCreateTime());
-        responseModelCustomUpload.setUserId(entity.getUserId());
-        responseModelCustomUpload.setStatus(entity.getStatus());
-        responseModelCustomUpload.setProgress(entity.getProgress());
-        responseModelCustomUpload.setThumPath(entity.getThumPath());
-        responseModelCustomUpload.setThumStatus(entity.getThumStatus());
-        if (ObjectUtil.isNotNull(entity.getPartsDetailId())) {
-            CustomProductEntity customProductEntity = customProductService.findById(entity.getPartsDetailId());
-            responseModelCustomUpload.setName(customProductEntity.getName());
-            responseModelCustomUpload.setCustomTypeId(customProductEntity.getParentId());
-            responseModelCustomUpload.setModelId(customProductEntity.getId());
-        } else {
-            responseModelCustomUpload.setCustomTypeId(0L);
-        }
-
-        if (ObjectUtil.isNotNull(entity.getCacheData())) {
-            JSONObject cache = JSONObject.parseObject(entity.getCacheData());
-            if (cache.containsKey("cacheData")) {
-                JSONObject cacheData = cache.getJSONObject("cacheData");
-                responseModelCustomUpload.setWidth(cacheData.getDouble("width"));
-                responseModelCustomUpload.setDepth(cacheData.getDouble("depth"));
-                responseModelCustomUpload.setHeight(cacheData.getDouble("height"));
+        if (ObjectUtil.isNotNull(entity)) {
+            responseModelCustomUpload.setId(entity.getId());
+            responseModelCustomUpload.setCreateTime(entity.getCreateTime());
+            responseModelCustomUpload.setUserId(entity.getUserId());
+            responseModelCustomUpload.setStatus(entity.getStatus());
+            responseModelCustomUpload.setProgress(entity.getProgress());
+            responseModelCustomUpload.setThumPath(entity.getThumPath());
+            responseModelCustomUpload.setThumStatus(entity.getThumStatus());
+            if (ObjectUtil.isNotNull(entity.getPartsDetailId())) {
+                CustomProductEntity customProductEntity = customProductService.findById(entity.getPartsDetailId());
+                responseModelCustomUpload.setName(customProductEntity.getName());
+                responseModelCustomUpload.setCustomTypeId(customProductEntity.getParentId());
+                responseModelCustomUpload.setModelId(customProductEntity.getId());
             } else {
-                responseModelCustomUpload.setWidth(cache.getDouble("width"));
-                responseModelCustomUpload.setDepth(cache.getDouble("depth"));
-                responseModelCustomUpload.setHeight(cache.getDouble("height"));
+                responseModelCustomUpload.setCustomTypeId(0L);
             }
-
-        }
-        if (entity.getStatus() != -1) {
-            JSONArray componentArray = new JSONArray();
-            List<ComponentModelUploadEntity> componentModelUploadEntities = componentModelUploadService.findPartsModelUploadId(entity.getId());
-            for (ComponentModelUploadEntity componentModelUploadEntity : componentModelUploadEntities) {
-
-                JSONObject json = new JSONObject();
-                json.put("id", componentModelUploadEntity.getId());
-                json.put("name", componentModelUploadEntity.getFileId());
-
-
-                if (ObjectUtil.isNotNull(componentModelUploadEntity.getPartsDetailId())) {
-                    CustomComponentEntity componentEntity = customComponentService.findById(componentModelUploadEntity.getPartsDetailId());
-                    if (ObjectUtil.isNotNull(componentEntity)) {
-                        json.put("customComponentTypeId", componentEntity.getComponentTypeId());
-                        json.put("title", componentEntity.getName());
-                        json.put("modelId", componentEntity.getId());
-                    }
+            if (ObjectUtil.isNotNull(entity.getCacheData())) {
+                JSONObject cache = JSONObject.parseObject(entity.getCacheData());
+                if (cache.containsKey("cacheData")) {
+                    JSONObject cacheData = cache.getJSONObject("cacheData");
+                    responseModelCustomUpload.setWidth(cacheData.getDouble("width"));
+                    responseModelCustomUpload.setDepth(cacheData.getDouble("depth"));
+                    responseModelCustomUpload.setHeight(cacheData.getDouble("height"));
                 } else {
-                    json.put("customComponentTypeId", 0);
+                    responseModelCustomUpload.setWidth(cache.getDouble("width"));
+                    responseModelCustomUpload.setDepth(cache.getDouble("depth"));
+                    responseModelCustomUpload.setHeight(cache.getDouble("height"));
                 }
 
-                json.put("objPath", componentModelUploadEntity.getObjPath());
-                json.put("thumPath", componentModelUploadEntity.getThumPath());
-                json.put("mtlPath", componentModelUploadEntity.getMtlPath());
-                if (ObjectUtil.isNotNull(componentModelUploadEntity.getCacheData())) {
-                    JSONObject componentCache = JSON.parseObject(componentModelUploadEntity.getCacheData());
-                    json.put("width", componentCache.getJSONObject("deploy").getDouble("width"));
-                    json.put("depth", componentCache.getJSONObject("deploy").getDouble("depth"));
-                    json.put("height", componentCache.getJSONObject("deploy").getDouble("height"));
-                    json.put("origin", componentCache.get("origin"));
+            }
+            if (entity.getStatus() != -1) {
+                JSONArray componentArray = new JSONArray();
+                List<ComponentModelUploadEntity> componentModelUploadEntities = componentModelUploadService.findPartsModelUploadId(entity.getId());
+                for (ComponentModelUploadEntity componentModelUploadEntity : componentModelUploadEntities) {
+
+                    JSONObject json = new JSONObject();
+                    json.put("id", componentModelUploadEntity.getId());
+                    json.put("name", componentModelUploadEntity.getFileId());
+
+
+                    if (ObjectUtil.isNotNull(componentModelUploadEntity.getPartsDetailId())) {
+                        CustomComponentEntity componentEntity = customComponentService.findById(componentModelUploadEntity.getPartsDetailId());
+                        if (ObjectUtil.isNotNull(componentEntity)) {
+                            json.put("customComponentTypeId", componentEntity.getComponentTypeId());
+                            json.put("title", componentEntity.getName());
+                            json.put("modelId", componentEntity.getId());
+                        }
+                    } else {
+                        json.put("customComponentTypeId", 0);
+                    }
+
+                    json.put("objPath", componentModelUploadEntity.getObjPath());
+                    json.put("thumPath", componentModelUploadEntity.getThumPath());
+                    json.put("mtlPath", componentModelUploadEntity.getMtlPath());
+                    if (ObjectUtil.isNotNull(componentModelUploadEntity.getCacheData())) {
+                        JSONObject componentCache = JSON.parseObject(componentModelUploadEntity.getCacheData());
+                        json.put("width", componentCache.getJSONObject("deploy").getDouble("width"));
+                        json.put("depth", componentCache.getJSONObject("deploy").getDouble("depth"));
+                        json.put("height", componentCache.getJSONObject("deploy").getDouble("height"));
+                        json.put("origin", componentCache.get("origin"));
+                    }
+                    componentArray.add(json);
                 }
-                componentArray.add(json);
+                responseModelCustomUpload.setComponentSlots(componentArray);
             }
-            responseModelCustomUpload.setComponentSlots(componentArray);
         }
-
-
         return responseModelCustomUpload;
     }
 }

+ 8 - 3
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/RenovationPartsAttachingServiceImpl.java

@@ -72,10 +72,15 @@ public class RenovationPartsAttachingServiceImpl extends BaseServiceImpl<IRenova
     @Override
     public boolean updateById(RenovationPartsAttachingEntity entity) {
         boolean updateById = super.updateById(entity);
-        if (updateById) {
+        RenovationPartsAttachingEntity byId = super.findById(entity.getId());
+        if (updateById && ObjectUtil.isNotNull(byId)) {
+            cacheChannel.evict(region, "responseId::" + byId.getPartsDetailId());
+            cacheChannel.set(region, "detailId::" + byId.getPartsDetailId(), byId, 60 * 30);
+            cacheChannel.set(region, "id::" + byId.getId(), entity, 60 * 30);
+        } else {
             cacheChannel.evict(region, "responseId::" + entity.getPartsDetailId());
-            cacheChannel.set(region, "detailId::" + entity.getPartsDetailId(), entity, 60 * 30);
-            cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
+            cacheChannel.evict(region, "detailId::" + entity.getPartsDetailId());
+            cacheChannel.evict(region, "id::" + entity.getId());
         }
         return updateById;
     }

+ 4 - 1
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/RenovationPartsBrandServiceImpl.java

@@ -39,8 +39,11 @@ public class RenovationPartsBrandServiceImpl extends BaseServiceImpl<IRenovation
     @Override
     public boolean updateById(RenovationPartsBrandEntity entity) {
         boolean updateById = super.updateById(entity);
-        if (updateById) {
+        RenovationPartsBrandEntity byId = super.findById(entity.getId());
+        if (updateById && ObjectUtil.isNotNull(byId)) {
             cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
+        } else {
+            cacheChannel.evict(region, "id::" + entity.getId());
         }
         return updateById;
     }

+ 4 - 1
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/RenovationPartsColorServiceImpl.java

@@ -41,8 +41,11 @@ public class RenovationPartsColorServiceImpl extends BaseServiceImpl<IRenovation
     @Override
     public boolean updateById(RenovationPartsColorEntity entity) {
         boolean updateById = super.updateById(entity);
-        if (updateById) {
+        RenovationPartsColorEntity byId = super.findById(entity.getId());
+        if (updateById && ObjectUtil.isNotNull(byId)) {
             cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
+        } else {
+            cacheChannel.evict(region, "id::" + entity.getId());
         }
         return updateById;
     }

+ 4 - 1
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/RenovationPartsServiceImpl.java

@@ -62,8 +62,11 @@ public class RenovationPartsServiceImpl extends BaseServiceImpl<IRenovationParts
     @Override
     public boolean updateById(RenovationPartsEntity entity) {
         boolean updateById = super.updateById(entity);
-        if (updateById) {
+        RenovationPartsEntity byId = super.findById(entity.getId());
+        if (updateById && ObjectUtil.isNotNull(byId)) {
             cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
+        } else {
+            cacheChannel.evict(region, "id::" + entity.getId());
         }
         return updateById;
     }

+ 5 - 1
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/RenovationPartsSizeServiceImpl.java

@@ -51,9 +51,13 @@ public class RenovationPartsSizeServiceImpl extends BaseServiceImpl<IRenovationP
     @Override
     public boolean updateById(RenovationPartsSizeEntity entity) {
         boolean updateById = super.updateById(entity);
-        if (updateById) {
+        RenovationPartsSizeEntity byId = super.findById(entity.getId());
+        if (updateById && ObjectUtil.isNotNull(byId)) {
             cacheChannel.evict(region, "responseId::" + entity.getPartsDetailId());
             cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
+        } else {
+            cacheChannel.evict(region, "responseId::" + entity.getPartsDetailId());
+            cacheChannel.evict(region, "id::" + entity.getId());
         }
         return updateById;
     }

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

@@ -49,8 +49,12 @@ public class RenovationPartsTypeServiceImpl extends BaseServiceImpl<IRenovationP
     @Override
     public boolean updateById(RenovationPartsTypeEntity entity) {
         boolean updateById = super.updateById(entity);
-        if (updateById) {
+        RenovationPartsTypeEntity byId = super.findById(entity.getId());
+        if (updateById && ObjectUtil.isNotNull(byId)) {
             cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
+
+        } else {
+            cacheChannel.evict(region, "id::" + entity.getId());
         }
         return updateById;
     }