lyhzzz hace 5 meses
padre
commit
8af756a6a8

+ 1 - 1
src/main/java/com/fdkankan/ucenter/service/ISceneCooperationCountService.java

@@ -15,7 +15,7 @@ import java.util.List;
  */
 public interface ISceneCooperationCountService extends IService<SceneCooperationCount> {
 
-    void saveCount(List<String> numList, Integer size,String sceneType);
+    void saveCount(List<String> numList, Integer size,String sceneType,String type);
 
      List<SceneCooperationCount> getByNumList(List<String> numList,String sceneType);
 

+ 24 - 16
src/main/java/com/fdkankan/ucenter/service/impl/SceneCooperationCountServiceImpl.java

@@ -4,16 +4,16 @@ import com.alibaba.druid.sql.visitor.functions.Concat;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.fdkankan.ucenter.entity.SceneCooperationCount;
+import com.fdkankan.ucenter.entity.User;
 import com.fdkankan.ucenter.mapper.ISceneCooperationCountMapper;
 import com.fdkankan.ucenter.service.ISceneCooperationCountService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.ucenter.service.ISceneCooperationService;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -27,11 +27,21 @@ import java.util.stream.Collectors;
 @Service
 public class SceneCooperationCountServiceImpl extends ServiceImpl<ISceneCooperationCountMapper, SceneCooperationCount> implements ISceneCooperationCountService {
 
+    @Autowired
+    ISceneCooperationService sceneCooperationService;
     @Override
-    public void saveCount(List<String> numList, Integer size,String sceneType) {
-        if(numList == null || numList.isEmpty() || size <=1){
+    public void saveCount(List<String> numList, Integer size,String sceneType,String type) {
+        if(numList == null || numList.isEmpty() || size <=0){
             return;
         }
+        if("scene".equals(type) && size<=1){
+            return;
+        }
+        HashMap<String, List<User>> userMap = new HashMap<>();
+        if("camera".equals(type)){
+            userMap = sceneCooperationService.getByNumList(numList, sceneType);
+        }
+
         List<SceneCooperationCount> sceneCooperationCounts = this.getByNumList(numList,sceneType);
         Set<String> dbNumList = sceneCooperationCounts.stream().map(SceneCooperationCount::getNum).collect(Collectors.toSet());
         Set<String> addNumList = new HashSet<>(numList);
@@ -39,10 +49,11 @@ public class SceneCooperationCountServiceImpl extends ServiceImpl<ISceneCooperat
         List<SceneCooperationCount> saveList = new ArrayList<>();
         for (String num : addNumList) {
             if(!dbNumList.contains(num)){
+                List<User> users = userMap.get(num);
                 SceneCooperationCount count = new SceneCooperationCount();
                 count.setSceneType(sceneType);
                 count.setNum(num);
-                count.setCount(size);
+                count.setCount(users.size() + size);
                 saveList.add(count);
             }
         }
@@ -50,18 +61,15 @@ public class SceneCooperationCountServiceImpl extends ServiceImpl<ISceneCooperat
             this.saveBatch(saveList);
         }
 
-        Set<Integer> updateList = new HashSet<>();
         for (SceneCooperationCount sceneCooperationCount : sceneCooperationCounts) {
-            if(sceneCooperationCount.getCount() < size){
-                updateList.add(sceneCooperationCount.getId());
+            List<User> users = userMap.get(sceneCooperationCount.getNum());
+            if(sceneCooperationCount.getCount() < users.size() + size){
+                LambdaUpdateWrapper<SceneCooperationCount> wrapper = new LambdaUpdateWrapper<>();
+                wrapper.eq(SceneCooperationCount::getId,sceneCooperationCount.getId());
+                wrapper.set(SceneCooperationCount::getCount,users.size() + size);
+                this.update(wrapper);
             }
         }
-        if(!updateList.isEmpty()){
-            LambdaUpdateWrapper<SceneCooperationCount> wrapper = new LambdaUpdateWrapper<>();
-            wrapper.in(SceneCooperationCount::getId,updateList);
-            wrapper.set(SceneCooperationCount::getCount,size);
-            this.update(wrapper);
-        }
     }
 
     @Override

+ 3 - 3
src/main/java/com/fdkankan/ucenter/service/impl/SceneCooperationServiceImpl.java

@@ -387,10 +387,10 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
             saveCooperationCommon(user,lang,users,proList,plusList,null,"scene",sceneType);
         }
         if(StringUtils.isBlank(sceneType)){
-            sceneCooperationCountService.saveCount(numList,userIds.size(),"mesh");
-            sceneCooperationCountService.saveCount(numList,userIds.size(),"laser");
+            sceneCooperationCountService.saveCount(numList,userIds.size(),"mesh","camera");
+            sceneCooperationCountService.saveCount(numList,userIds.size(),"laser","camera");
         }else {
-            sceneCooperationCountService.saveCount(numList,userIds.size(),sceneType);
+            sceneCooperationCountService.saveCount(numList,userIds.size(),sceneType,"scene");
         }
 
     }