Forráskód Böngészése

Merge remote-tracking branch 'origin/master'

dengsixing 2 éve
szülő
commit
25dbf15d19
21 módosított fájl, 453 hozzáadás és 82 törlés
  1. 20 0
      src/main/java/com/fdkankan/ucenter/bean/SceneBean.java
  2. 63 0
      src/main/java/com/fdkankan/ucenter/bean/SceneClean.java
  3. 13 1
      src/main/java/com/fdkankan/ucenter/controller/inner/InnerController.java
  4. 17 3
      src/main/java/com/fdkankan/ucenter/httpClient/service/LaserService.java
  5. 26 0
      src/main/java/com/fdkankan/ucenter/mapper/ISceneCleanMapper.java
  6. 24 0
      src/main/java/com/fdkankan/ucenter/service/ISceneCleanService.java
  7. 2 0
      src/main/java/com/fdkankan/ucenter/service/IScenePlusExtService.java
  8. 3 3
      src/main/java/com/fdkankan/ucenter/service/impl/CameraDetailServiceImpl.java
  9. 4 6
      src/main/java/com/fdkankan/ucenter/service/impl/CameraServiceImpl.java
  10. 15 23
      src/main/java/com/fdkankan/ucenter/service/impl/DownService.java
  11. 7 0
      src/main/java/com/fdkankan/ucenter/service/impl/FusionService.java
  12. 1 3
      src/main/java/com/fdkankan/ucenter/service/impl/InnerServiceImpl.java
  13. 1 1
      src/main/java/com/fdkankan/ucenter/service/impl/OrderServiceImpl.java
  14. 119 0
      src/main/java/com/fdkankan/ucenter/service/impl/SceneCleanServiceImpl.java
  15. 7 0
      src/main/java/com/fdkankan/ucenter/service/impl/ScenePlusExtServiceImpl.java
  16. 45 22
      src/main/java/com/fdkankan/ucenter/service/impl/SceneProServiceImpl.java
  17. 1 1
      src/main/java/com/fdkankan/ucenter/service/impl/UserIncrementServiceImpl.java
  18. 27 12
      src/main/java/com/fdkankan/ucenter/task/TaskService.java
  19. 10 1
      src/main/java/com/fdkankan/ucenter/vo/request/DownNumParam.java
  20. 7 6
      src/main/resources/bootstrap-prod.yml
  21. 41 0
      src/main/resources/mapper/ucenter/SceneCleanMapper.xml

+ 20 - 0
src/main/java/com/fdkankan/ucenter/bean/SceneBean.java

@@ -0,0 +1,20 @@
+package com.fdkankan.ucenter.bean;
+
+import lombok.Data;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/10/9
+ **/
+@Data
+public class SceneBean {
+
+    private String num;
+
+    private String dataSource;
+
+}

+ 63 - 0
src/main/java/com/fdkankan/ucenter/bean/SceneClean.java

@@ -0,0 +1,63 @@
+package com.fdkankan.ucenter.bean;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author 
+ * @since 2022-10-09
+ */
+@Getter
+@Setter
+@TableName("t_scene_clean")
+public class SceneClean implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 场景码
+     */
+    @TableField("num")
+    private String num;
+
+    /**
+     * 是否已清除资源(0-否,1-是)
+     */
+    @TableField("state")
+    private Integer state;
+
+    /**
+     * 创建时间
+     */
+    @TableField("create_time")
+    private Date createTime;
+
+    /**
+     * 更新时间
+     */
+    @TableField("update_time")
+    private Date updateTime;
+
+    /**
+     * A-有效,I-无效
+     */
+    @TableLogic(value = "A", delval = "I")
+    @TableField("rec_status")
+    private String recStatus;
+
+
+}

+ 13 - 1
src/main/java/com/fdkankan/ucenter/controller/inner/InnerController.java

@@ -63,6 +63,18 @@ public class InnerController extends BaseController {
      * 查询场景资源路径
      * 查询场景资源路径
      */
      */
     @CheckInnerApiPermit
     @CheckInnerApiPermit
+    @GetMapping("/getAllSceneDbInfo")
+    public Result getAllSceneDbInfo(String num){
+        if(ObjectUtils.isEmpty(num)){
+            return Result.failure("请输入场景码");
+        }
+        return innerService.querySceneNum(num);
+    }
+
+    /**
+     * 查询场景资源路径
+     */
+    @CheckInnerApiPermit
     @GetMapping("/downloadCapture")
     @GetMapping("/downloadCapture")
     public Result downloadCapture(String num){
     public Result downloadCapture(String num){
         if(ObjectUtils.isEmpty(num)){
         if(ObjectUtils.isEmpty(num)){
@@ -71,7 +83,7 @@ public class InnerController extends BaseController {
         return innerService.downloadCapture(num);
         return innerService.downloadCapture(num);
     }
     }
     /**
     /**
-     * 根据场景码获取场景码版本
+     * 根据场景码获取场景码版本 深时使用
      */
      */
     @GetMapping("/_getSceneNumVersion")
     @GetMapping("/_getSceneNumVersion")
     public Result getSceneNumVersion(@RequestParam(required = false) String num) throws Exception{
     public Result getSceneNumVersion(@RequestParam(required = false) String num) throws Exception{

+ 17 - 3
src/main/java/com/fdkankan/ucenter/httpClient/service/LaserService.java

@@ -69,10 +69,10 @@ public class LaserService {
 
 
 
 
     public void disableCooperation(HashMap<Long, CameraDetail> detailMap, HashMap<Long, Camera> cameraMap ){
     public void disableCooperation(HashMap<Long, CameraDetail> detailMap, HashMap<Long, Camera> cameraMap ){
-        this.disableCooperation(getCooperationParam(detailMap,cameraMap,null));
+        this.disableCooperation(getCooperationdDisableParam(detailMap,cameraMap));
     }
     }
     public void enableCameraCooperation(HashMap<Long,CameraDetail> detailMap,HashMap<Long,Camera> cameraMap ,String username){
     public void enableCameraCooperation(HashMap<Long,CameraDetail> detailMap,HashMap<Long,Camera> cameraMap ,String username){
-        this.enableCameraCooperation(getCooperationParam(detailMap,cameraMap,username));
+        this.enableCameraCooperation(getCooperationSaveParam(detailMap,cameraMap,username));
     }
     }
 
 
     public void disableCooperation(List<Map<String, String>> params) {
     public void disableCooperation(List<Map<String, String>> params) {
@@ -82,7 +82,7 @@ public class LaserService {
         laserClient.cooperationDisable(params);
         laserClient.cooperationDisable(params);
     }
     }
 
 
-    public  List<Map<String, String>> getCooperationParam(HashMap<Long,CameraDetail> detailMap,HashMap<Long,Camera> cameraMap ,String username){
+    public  List<Map<String, String>> getCooperationdDisableParam(HashMap<Long,CameraDetail> detailMap,HashMap<Long,Camera> cameraMap ){
         List<Map<String, String>> laserParams = new ArrayList<>();
         List<Map<String, String>> laserParams = new ArrayList<>();
         List<Long> userIds = new ArrayList<>();
         List<Long> userIds = new ArrayList<>();
         for (Long aLong : detailMap.keySet()) {
         for (Long aLong : detailMap.keySet()) {
@@ -106,6 +106,20 @@ public class LaserService {
         }
         }
         return laserParams;
         return laserParams;
     }
     }
+    public  List<Map<String, String>> getCooperationSaveParam(HashMap<Long,CameraDetail> detailMap,HashMap<Long,Camera> cameraMap ,String username){
+        List<Map<String, String>> laserParams = new ArrayList<>();
+            for (Long cameraId : detailMap.keySet()) {
+                CameraDetail cameraDetail = detailMap.get(cameraId);
+                if (cameraDetail.getType() == CameraTypeEnum.LASER_TURN.getType()) {
+                    Camera cameraEntity = cameraMap.get(cameraId);
+                    Map<String, String> param = new HashMap<>();
+                    param.put("snCode", cameraEntity.getSnCode());
+                    param.put("cooperationUserName", username);
+                    laserParams.add(param);
+                }
+            }
+        return laserParams;
+    }
 
 
     public void enableCameraCooperation(List<Map<String, String>> params) {
     public void enableCameraCooperation(List<Map<String, String>> params) {
         if(params.size() <=0){
         if(params.size() <=0){

+ 26 - 0
src/main/java/com/fdkankan/ucenter/mapper/ISceneCleanMapper.java

@@ -0,0 +1,26 @@
+package com.fdkankan.ucenter.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fdkankan.ucenter.bean.SceneBean;
+import com.fdkankan.ucenter.bean.SceneClean;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author 
+ * @since 2022-10-09
+ */
+@Mapper
+public interface ISceneCleanMapper extends BaseMapper<SceneClean> {
+
+    List<SceneBean> selectNeadCleanScene(@Param("index") long index, @Param("size") int size, @Param("time") Date time);
+
+    List<SceneClean> findAllByDateSource(@Param("dataSource") String dataSource);
+}

+ 24 - 0
src/main/java/com/fdkankan/ucenter/service/ISceneCleanService.java

@@ -0,0 +1,24 @@
+package com.fdkankan.ucenter.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.ucenter.bean.SceneBean;
+import com.fdkankan.ucenter.bean.SceneClean;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author 
+ * @since 2022-10-09
+ */
+public interface ISceneCleanService extends IService<SceneClean> {
+
+    void sceneCleanResource();
+
+    List<SceneBean> selectNeadCleanScene(long index, int size, Date time);
+
+}

+ 2 - 0
src/main/java/com/fdkankan/ucenter/service/IScenePlusExtService.java

@@ -21,4 +21,6 @@ public interface IScenePlusExtService extends IService<ScenePlusExt> {
     HashMap<Long,ScenePlusExt> getByPlusIds(List<Long> plusIds);
     HashMap<Long,ScenePlusExt> getByPlusIds(List<Long> plusIds);
 
 
     ScenePlusExt getByUnicode(String unicode);
     ScenePlusExt getByUnicode(String unicode);
+
+    List<ScenePlusExt> getSsObj();
 }
 }

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

@@ -103,15 +103,15 @@ public class CameraDetailServiceImpl extends ServiceImpl<ICameraDetailMapper, Ca
     public void unbindCamera(List<Long> cameraIds) {
     public void unbindCamera(List<Long> cameraIds) {
         HashMap<Long, CameraDetail> detailMap = this.getByCameraIds(cameraIds);
         HashMap<Long, CameraDetail> detailMap = this.getByCameraIds(cameraIds);
         HashMap<Long, Camera> cameraMap = cameraService.getByIds(cameraIds);
         HashMap<Long, Camera> cameraMap = cameraService.getByIds(cameraIds);
-        for (Long cameraId : detailMap.keySet()) {
-            CameraDetail cameraDetail = detailMap.get(cameraId);
+        for (CameraDetail cameraDetail : detailMap.values()) {
             LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
             LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
             wrapper.eq(CameraDetail::getId,cameraDetail.getId());
             wrapper.eq(CameraDetail::getId,cameraDetail.getId());
             wrapper.set(CameraDetail::getUserId,null);
             wrapper.set(CameraDetail::getUserId,null);
             wrapper.set(CameraDetail::getCooperationUser,null);
             wrapper.set(CameraDetail::getCooperationUser,null);
             wrapper.set(CameraDetail::getTotalSpace,Long.parseLong(Constant.EXPANSION_SPACE_VALUE_1G ) * 10L);
             wrapper.set(CameraDetail::getTotalSpace,Long.parseLong(Constant.EXPANSION_SPACE_VALUE_1G ) * 10L);
             this.update(wrapper);
             this.update(wrapper);
-            sceneProService.lockOrUnLockBySpace(cameraDetail,cameraId,-2);     //封存场景
+            cameraDetail.setTotalSpace(Long.parseLong(Constant.EXPANSION_SPACE_VALUE_1G ) * 10L);
+            sceneProService.lockOrUnLockBySpace(cameraDetail,cameraDetail.getCameraId(),-2);     //封存场景
         }
         }
         //恢复10G基本容量
         //恢复10G基本容量
 
 

+ 4 - 6
src/main/java/com/fdkankan/ucenter/service/impl/CameraServiceImpl.java

@@ -244,14 +244,12 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
                 throw new BusinessException(AppConstant.FAILURE_CODE_4010, code +"-"+ AppConstant.FAILURE_MSG_4010);
                 throw new BusinessException(AppConstant.FAILURE_CODE_4010, code +"-"+ AppConstant.FAILURE_MSG_4010);
             }
             }
         }
         }
-        HashMap<Long ,Camera> cameraHashMap = new HashMap<>();
-        list.forEach(camera -> cameraHashMap.put(camera.getId(),camera));
-        List<Long> cameraIds = list.stream().map(Camera::getId).collect(Collectors.toList());
+        Map<Long, Camera> cameraHashMap = list.stream().collect(Collectors.toMap(Camera::getId, camera -> camera, (o1, o2) -> o1));
+        List<Long> cameraIds = new ArrayList<>(cameraHashMap.keySet());
         HashMap<Long, CameraDetail> detailHashMap = cameraDetailService.getByCameraIds(cameraIds);
         HashMap<Long, CameraDetail> detailHashMap = cameraDetailService.getByCameraIds(cameraIds);
-        for (Long cameraId : detailHashMap.keySet()) {
-            CameraDetail detail = detailHashMap.get(cameraId);
+        for (CameraDetail detail : detailHashMap.values()) {
             if(detail.getUserId() != null){
             if(detail.getUserId() != null){
-                throw new BusinessException(CameraConstant.FAILURE_CODE_6010, cameraHashMap.get(cameraId).getSnCode() +"-"+ CameraConstant.FAILURE_MSG_6010);
+                throw new BusinessException(CameraConstant.FAILURE_CODE_6010, cameraHashMap.get(detail.getCameraId()).getSnCode() +"-"+ CameraConstant.FAILURE_MSG_6010);
             }
             }
         }
         }
 
 

+ 15 - 23
src/main/java/com/fdkankan/ucenter/service/impl/DownService.java

@@ -178,33 +178,25 @@ public class DownService implements IDownService {
         SceneDownloadLog sceneDownloadLog = sceneDownloadLogService.getByStatusAndNum(sceneNum,0,isUp);
         SceneDownloadLog sceneDownloadLog = sceneDownloadLogService.getByStatusAndNum(sceneNum,0,isUp);
 
 
         DownloadProcessVo downloadProcessVo = JSONObject.parseObject(result, DownloadProcessVo.class);
         DownloadProcessVo downloadProcessVo = JSONObject.parseObject(result, DownloadProcessVo.class);
-        switch (downloadProcessVo.getStatus()) {
-            case DownloadStatusEnum.DOWNLOAD_SUCCESS_CODE:
-                String url = downloadProcessVo.getUrl();
-                if (!StringUtils.isEmpty(url)) {
-                    sceneDownloadLog.setDownloadUrl(url);
-                    sceneDownloadLog.setStatus(1);
+        if(sceneDownloadLog != null){
+            switch (downloadProcessVo.getStatus()) {
+                case DownloadStatusEnum.DOWNLOAD_SUCCESS_CODE:
+                    String url = downloadProcessVo.getUrl();
+                    if (!StringUtils.isEmpty(url)) {
+                        sceneDownloadLog.setDownloadUrl(url);
+                        sceneDownloadLog.setStatus(1);
+                        break;
+                    }
+                case DownloadStatusEnum.DOWNLOAD_FAILED_CODE:
+                    sceneDownloadLog.setStatus(-1);
+                    userService.updateDownloadNum(userId, -1);
                     break;
                     break;
-                }
-            case DownloadStatusEnum.DOWNLOAD_FAILED_CODE:
-                sceneDownloadLog.setStatus(-1);
-                userService.updateDownloadNum(userId, -1);
-                break;
+            }
+            sceneDownloadLogService.updateById(sceneDownloadLog);
         }
         }
-        sceneDownloadLogService.updateById(sceneDownloadLog);
+
         return downloadProcessVo;
         return downloadProcessVo;
     }
     }
 
 
 
 
-    public static void main(String[] args) {
-        Integer aaa = new Integer(1002);
-        switch (aaa){
-            case DownloadStatusEnum.DOWNLOAD_SUCCESS_CODE:
-                System.out.println(123);
-        }
-
-
-
-    }
-
 }
 }

+ 7 - 0
src/main/java/com/fdkankan/ucenter/service/impl/FusionService.java

@@ -69,6 +69,13 @@ public class FusionService implements IFusionService {
             resourceList = Arrays.asList(1,2,12,13,14);
             resourceList = Arrays.asList(1,2,12,13,14);
         }else if(param.getType()!= null && param.getType() == 1){       //看见
         }else if(param.getType()!= null && param.getType() == 1){       //看见
             resourceList = Collections.singletonList(3);
             resourceList = Collections.singletonList(3);
+        }else if(param.getType()!=null && param.getType() == 4){
+            resourceList = Collections.singletonList(4);
+            List<ScenePlusExt> plusExtList = scenePlusExtService.getSsObj();
+            List<Long> plusIds = plusExtList.stream().map(ScenePlusExt::getPlusId).collect(Collectors.toList());
+            if(plusIds.size() >0){
+                wrapper.in(ScenePlus::getId,plusIds);
+            }
         }
         }
         if(param.getStatus() !=null && param.getStatus() == 2){
         if(param.getStatus() !=null && param.getStatus() == 2){
             wrapper.eq(ScenePlus::getSceneStatus,-2);           //计算成功
             wrapper.eq(ScenePlus::getSceneStatus,-2);           //计算成功

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

@@ -19,6 +19,7 @@ import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
 
 
 import java.io.File;
 import java.io.File;
 import java.util.Objects;
 import java.util.Objects;
@@ -35,9 +36,6 @@ import java.util.Objects;
 @Service
 @Service
 public class InnerServiceImpl implements IInnerService {
 public class InnerServiceImpl implements IInnerService {
 
 
-    @Value("${inner.customToken}")
-    private String customToken;
-
     @Autowired
     @Autowired
     private ISceneProService sceneProService;
     private ISceneProService sceneProService;
     @Autowired
     @Autowired

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

@@ -288,7 +288,7 @@ public class OrderServiceImpl extends ServiceImpl<IOrderMapper, Order> implement
         if(param.getAbroad() == 1 && param.getPayType() != 2){
         if(param.getAbroad() == 1 && param.getPayType() != 2){
             throw new BusinessException(OrderConstant.FAILURE_CODE_8004, OrderConstant.FAILURE_MSG_8004);
             throw new BusinessException(OrderConstant.FAILURE_CODE_8004, OrderConstant.FAILURE_MSG_8004);
         }
         }
-        IncrementType incrementType = incrementTypeService.getById(param.getSkuSn());
+        IncrementType incrementType = incrementTypeService.getById(param.getIncrementType());
         if(incrementType == null){
         if(incrementType == null){
           throw new BusinessException(OrderConstant.FAILURE_CODE_8004, OrderConstant.FAILURE_MSG_8004);
           throw new BusinessException(OrderConstant.FAILURE_CODE_8004, OrderConstant.FAILURE_MSG_8004);
         }
         }

+ 119 - 0
src/main/java/com/fdkankan/ucenter/service/impl/SceneCleanServiceImpl.java

@@ -0,0 +1,119 @@
+package com.fdkankan.ucenter.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.common.constant.CommonStatus;
+import com.fdkankan.common.util.DateUtil;
+import com.fdkankan.common.util.FileUtils;
+import com.fdkankan.redis.constant.RedisKey;
+import com.fdkankan.redis.constant.RedisLockKey;
+import com.fdkankan.redis.util.RedisLockUtil;
+import com.fdkankan.ucenter.bean.SceneBean;
+import com.fdkankan.ucenter.bean.SceneClean;
+import com.fdkankan.ucenter.mapper.ISceneCleanMapper;
+import com.fdkankan.ucenter.service.ISceneCleanService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author 
+ * @since 2022-10-09
+ */
+@RefreshScope
+@Service
+@Slf4j
+public class SceneCleanServiceImpl extends ServiceImpl<ISceneCleanMapper, SceneClean> implements ISceneCleanService {
+
+    @Autowired
+    private RedisLockUtil redisLockUtil;
+
+    @Value("${scene.clean.size:10}")
+    private Integer sceneCleanSize;
+
+    @Transactional
+    @Override
+    public void sceneCleanResource(){
+        // 获取redis 锁
+        boolean lock = redisLockUtil.lock(RedisLockKey.LOCK_SCENE_CLEAN, RedisKey.EXPIRE_TIME_2_HOUR);
+        if(!lock){
+            log.warn("未获取到清除资源锁,退出任务!");
+            return;
+        }
+
+        Date time = DateUtil.delay(Calendar.getInstance().getTime(), -7, Calendar.MONTH);
+        time.setHours(0);
+        time.setMinutes(0);
+        time.setSeconds(0);
+
+        //查询需要清理资源的场景
+        List<SceneBean> sceneProEntityList = selectNeadCleanScene(0,sceneCleanSize, time);
+        //如果查出来的场景集合是空,证明已经没有场景资源需要删除,则需要把查询下表删除,等待下一次定时任务执行
+        if (CollectionUtils.isEmpty(sceneProEntityList)) {
+            return;
+        }
+        List<String> numList = sceneProEntityList.parallelStream().map(SceneBean::getNum).collect(Collectors.toList());
+        List<SceneClean> insertList = new ArrayList<>();
+        List<SceneClean> updateList = this.list(new LambdaQueryWrapper<SceneClean>().in(SceneClean::getNum, numList));
+        Set<String> updateSet = updateList.stream().map(SceneClean::getNum).collect(Collectors.toSet());
+        sceneProEntityList.stream().forEach(scene -> {
+            if (StringUtils.isNotBlank(scene.getDataSource())) {
+                // 查询该资源的最新计算时间
+                List<SceneClean> scenes = findAllByDateSource(scene.getDataSource());
+                if (scenes.get(0).getCreateTime().before(time)) {
+                    try {
+                        FileUtils.deleteDirectory(scene.getDataSource());
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                        updateSet.remove(scene.getNum());
+                        return;
+                    }
+                }
+            }
+            if (!updateSet.contains(scene.getNum())) {
+                SceneClean sceneCleanEntity = new SceneClean();
+                sceneCleanEntity.setState(1);
+                sceneCleanEntity.setNum(scene.getNum());
+                sceneCleanEntity.setCreateTime(new Date());
+                sceneCleanEntity.setUpdateTime(new Date());
+                sceneCleanEntity.setRecStatus("A");
+                insertList.add(sceneCleanEntity);
+            }
+        });
+
+        //写库
+        if(!CollectionUtils.isEmpty(insertList)){
+            this.saveBatch(insertList);
+        }
+        if(!CollectionUtils.isEmpty(updateSet)){
+            this.update(new LambdaUpdateWrapper<SceneClean>()
+                    .set(SceneClean::getState, CommonStatus.YES.code())
+                    .set(SceneClean::getUpdateTime,new Date())
+                    .in(SceneClean::getNum, updateSet));
+        }
+
+        redisLockUtil.unlock(RedisLockKey.LOCK_SCENE_CLEAN);
+    }
+
+    private List<SceneClean> findAllByDateSource(String dataSource) {
+        return this.baseMapper.findAllByDateSource(dataSource);
+    }
+
+    @Override
+    public List<SceneBean> selectNeadCleanScene(long index, int size, Date time) {
+        return this.baseMapper.selectNeadCleanScene(index, size, time);
+    }
+}

+ 7 - 0
src/main/java/com/fdkankan/ucenter/service/impl/ScenePlusExtServiceImpl.java

@@ -53,4 +53,11 @@ public class ScenePlusExtServiceImpl extends ServiceImpl<IScenePlusExtMapper, Sc
         }
         }
         return null;
         return null;
     }
     }
+
+    @Override
+    public List<ScenePlusExt> getSsObj() {
+        LambdaQueryWrapper<ScenePlusExt> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(ScenePlusExt::getIsObj,1);
+        return this.list(wrapper);
+    }
 }
 }

+ 45 - 22
src/main/java/com/fdkankan/ucenter/service/impl/SceneProServiceImpl.java

@@ -82,6 +82,8 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
     @Autowired
     @Autowired
     private IUserIncrementService userIncrementService;
     private IUserIncrementService userIncrementService;
     @Autowired
     @Autowired
+    private IIncrementTypeService incrementTypeService;
+    @Autowired
     private IScenePlusExtService scenePlusExtService;
     private IScenePlusExtService scenePlusExtService;
     @Autowired
     @Autowired
     private ISceneEditInfoService sceneEditInfoService;
     private ISceneEditInfoService sceneEditInfoService;
@@ -179,14 +181,27 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
     public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId, Integer payStatus) {
     public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId, Integer payStatus) {
         LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
-        Long count = 0L;
+        Long totalSpace = cameraDetail.getTotalSpace();
+        UserIncrement userIncrement = userIncrementService.getByCameraId(cameraId);
+        if(userIncrement!=null){
+            IncrementType incrementType = incrementTypeService.getById(userIncrement.getId());
+            if(incrementType.getCameraCapacity() == -1){
+                totalSpace   = -1L;
+            }else {
+                totalSpace = incrementType.getCameraCapacity() * 1024 * 1024L;
+            }
+        }
+
         if(payStatus == 1){         //解封,判断用户权益,用户会员权益无限容量
         if(payStatus == 1){         //解封,判断用户权益,用户会员权益无限容量
-            count = userIncrementService.getValidCountByCameraId(cameraId);
             wrapper.orderByAsc(ScenePro::getCreateTime);
             wrapper.orderByAsc(ScenePro::getCreateTime);
             plusWr.orderByAsc(ScenePlus::getCreateTime);
             plusWr.orderByAsc(ScenePlus::getCreateTime);
             wrapper.eq(ScenePro::getPayStatus,-2);
             wrapper.eq(ScenePro::getPayStatus,-2);
             plusWr.eq(ScenePlus::getPayStatus,-2);
             plusWr.eq(ScenePlus::getPayStatus,-2);
         }else {
         }else {
+            if (totalSpace >= cameraDetail.getUsedSpace()) {
+                // 总容量大于已使用容量,不予封存
+                return;
+            }
             wrapper.orderByDesc(ScenePro::getCreateTime);
             wrapper.orderByDesc(ScenePro::getCreateTime);
             plusWr.orderByDesc(ScenePlus::getCreateTime);
             plusWr.orderByDesc(ScenePlus::getCreateTime);
             wrapper.eq(ScenePro::getPayStatus,1);
             wrapper.eq(ScenePro::getPayStatus,1);
@@ -201,15 +216,17 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         List<ScenePro> list = this.list(wrapper);
         List<ScenePro> list = this.list(wrapper);
         List<ScenePlus> plusList = scenePlusService.list(plusWr);
         List<ScenePlus> plusList = scenePlusService.list(plusWr);
 
 
-        Long beyondSpace = Math.abs(cameraDetail.getUsedSpace() - cameraDetail.getTotalSpace());
+        Long beyondSpace = Math.abs(cameraDetail.getUsedSpace() - totalSpace);
         Long accumulateSpace = 0L;
         Long accumulateSpace = 0L;
         List<Long> lockedIds = new ArrayList<>();
         List<Long> lockedIds = new ArrayList<>();
         if(payStatus == 1){
         if(payStatus == 1){
-            getScenePlusLockedIds(lockedIds,plusList,count,beyondSpace,accumulateSpace);
-            getSceneLockedIds(lockedIds,list,count,beyondSpace,accumulateSpace);
+            Long doSpace = getScenePlusLockedIds(lockedIds, plusList, totalSpace, beyondSpace, accumulateSpace);
+            beyondSpace -= doSpace;
+            getSceneLockedIds(lockedIds,list,totalSpace,beyondSpace,accumulateSpace);
         }else {
         }else {
-            getSceneLockedIds(lockedIds,list,count,beyondSpace,accumulateSpace);
-            getScenePlusLockedIds(lockedIds,plusList,count,beyondSpace,accumulateSpace);
+            Long doSpace = getSceneLockedIds(lockedIds, list, totalSpace, beyondSpace, accumulateSpace);
+            beyondSpace -= doSpace;
+            getScenePlusLockedIds(lockedIds,plusList,totalSpace,beyondSpace,accumulateSpace);
         }
         }
 
 
         lockOrUnLockScenes(lockedIds,payStatus);
         lockOrUnLockScenes(lockedIds,payStatus);
@@ -217,30 +234,32 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
 
 
 
 
 
 
-    private void getSceneLockedIds(List<Long> lockedIds ,List<ScenePro> list,Long count,Long beyondSpace,Long accumulateSpace){
+    private Long getSceneLockedIds(List<Long> lockedIds ,List<ScenePro> list,Long count,Long beyondSpace,Long accumulateSpace){
         if (list != null && list.size() > 0){
         if (list != null && list.size() > 0){
             for (ScenePro scenePro : list){
             for (ScenePro scenePro : list){
                 accumulateSpace += scenePro.getSpace();
                 accumulateSpace += scenePro.getSpace();
-                if (count ==0 && accumulateSpace.compareTo(beyondSpace) > 0){
-                    break;
+                if (count ==-1 && accumulateSpace.compareTo(beyondSpace) > 0){
+                    return  accumulateSpace - scenePro.getSpace();
                 }
                 }
                 lockedIds.add(scenePro.getId());
                 lockedIds.add(scenePro.getId());
             }
             }
         }
         }
+        return  accumulateSpace;
     }
     }
-    private void getScenePlusLockedIds(List<Long> lockedIds ,List<ScenePlus> list,Long count,Long beyondSpace,Long accumulateSpace){
+    private Long getScenePlusLockedIds(List<Long> lockedIds , List<ScenePlus> list, Long count, Long beyondSpace, Long accumulateSpace){
         if (list != null && list.size() > 0){
         if (list != null && list.size() > 0){
             List<Long> plusIds = list.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
             List<Long> plusIds = list.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
             HashMap<Long, ScenePlusExt> byPlusIds = scenePlusExtService.getByPlusIds(plusIds);
             HashMap<Long, ScenePlusExt> byPlusIds = scenePlusExtService.getByPlusIds(plusIds);
             for (ScenePlus scenePlus : list){
             for (ScenePlus scenePlus : list){
                 ScenePlusExt scenePlusExt = byPlusIds.get(scenePlus.getId());
                 ScenePlusExt scenePlusExt = byPlusIds.get(scenePlus.getId());
                 accumulateSpace += scenePlusExt.getSpace();
                 accumulateSpace += scenePlusExt.getSpace();
-                if (count ==0 && accumulateSpace.compareTo(beyondSpace) > 0){
-                    break;
+                if (count ==-1 && accumulateSpace.compareTo(beyondSpace) > 0){
+                    return  accumulateSpace - scenePlusExt.getSpace();
                 }
                 }
                 lockedIds.add(scenePlus.getId());
                 lockedIds.add(scenePlus.getId());
             }
             }
         }
         }
+        return accumulateSpace;
     }
     }
 
 
 
 
@@ -401,14 +420,6 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
                     Integer count = sceneService.getCountByUserId(user.getId());
                     Integer count = sceneService.getCountByUserId(user.getId());
                     vo.setSceneNum(Long.valueOf(count));
                     vo.setSceneNum(Long.valueOf(count));
                 }
                 }
-                if(vo.getIsFolder() == 0  && vo.getStatus() !=null){
-                    if(vo.getStatus() == 500){      //500状态为数据库中手动修改值,当场景本身异常,算法,算不了
-                        vo.setStatus(-1);
-                    }
-                    if(vo.getStatus() == -1){       //计算失败,钉钉通知之后,判定是否重算,还是修改为 500
-                        vo.setStatus(0);
-                    }
-                }
             }
             }
         }
         }
         //设置协作者信息
         //设置协作者信息
@@ -426,7 +437,19 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
             }
             }
         }
         }
 
 
-        List<SceneVo> sceneList = sceneVoPage.getRecords().parallelStream().filter(entity -> entity.getIsFolder() == 0).collect(Collectors.toList());
+        List<SceneVo> sceneList = sceneVoPage.getRecords().parallelStream().filter(entity -> entity.getIsFolder() == 0)
+                .peek(vo->{
+                    if (ObjectUtils.isEmpty(vo.getStatus())) {
+                        return;
+                    }
+                    if (vo.getStatus().equals(500)) {      //500状态为数据库中手动修改值,当场景本身异常,算法,算不了
+                        vo.setStatus(-1);
+                    }
+                    if (vo.getStatus().equals(-1)) {       //计算失败,钉钉通知之后,判定是否重算,还是修改为 500
+                        vo.setStatus(0);
+                    }
+                }).collect(Collectors.toList());
+
         if(sceneList.size() >0){
         if(sceneList.size() >0){
             folderList.addAll(sceneList);
             folderList.addAll(sceneList);
         }
         }

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

@@ -81,8 +81,8 @@ public class UserIncrementServiceImpl extends ServiceImpl<IUserIncrementMapper,
         }
         }
         Page<UserIncrement> page = new Page<>(param.getPageNum(), param.getPageSize());
         Page<UserIncrement> page = new Page<>(param.getPageNum(), param.getPageSize());
         LambdaQueryWrapper<UserIncrement> queryWrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<UserIncrement> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(UserIncrement::getIsExpired,0);
         queryWrapper.eq(UserIncrement::getUserId,user.getId());
         queryWrapper.eq(UserIncrement::getUserId,user.getId());
+        queryWrapper.and(i ->i.eq(UserIncrement::getIsExpired,0).or().isNotNull(UserIncrement::getCameraId));
         if(cameraIdList!=null ){
         if(cameraIdList!=null ){
             queryWrapper.in(UserIncrement::getCameraId,cameraIdList);
             queryWrapper.in(UserIncrement::getCameraId,cameraIdList);
         }
         }

+ 27 - 12
src/main/java/com/fdkankan/ucenter/task/TaskService.java

@@ -1,28 +1,23 @@
 package com.fdkankan.ucenter.task;
 package com.fdkankan.ucenter.task;
 
 
-import cn.hutool.core.collection.CollUtil;
 import com.fdkankan.common.util.DateUtil;
 import com.fdkankan.common.util.DateUtil;
 import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.ucenter.common.RedisKeyUtil;
 import com.fdkankan.ucenter.common.RedisKeyUtil;
 import com.fdkankan.ucenter.common.StatisticsUtil;
 import com.fdkankan.ucenter.common.StatisticsUtil;
 import com.fdkankan.ucenter.constant.QrCodeFilePath;
 import com.fdkankan.ucenter.constant.QrCodeFilePath;
-import java.io.File;
-import java.util.Date;
-import java.util.Map;
-import java.util.Objects;
-
-import com.fdkankan.ucenter.service.IOrderService;
-import com.fdkankan.ucenter.service.ISceneProService;
-import com.fdkankan.ucenter.service.ISceneStatisticsService;
-import com.fdkankan.ucenter.service.IUserIncrementService;
-import lombok.extern.slf4j.Slf4j;
+import com.fdkankan.ucenter.service.*;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 
 
+import java.io.File;
+import java.util.Date;
+import java.util.Map;
+import java.util.Objects;
+
 @Component
 @Component
 public class TaskService {
 public class TaskService {
 
 
@@ -31,7 +26,10 @@ public class TaskService {
     @Autowired
     @Autowired
     RedisUtil redisUtil;
     RedisUtil redisUtil;
     @Autowired
     @Autowired
-    ISceneProService sceneProService;
+    private ISceneProService sceneProService;
+
+    @Autowired
+    private ISceneCleanService sceneCleanService;
 
 
     @Scheduled(cron = "0 */10 * * * ?")
     @Scheduled(cron = "0 */10 * * * ?")
     public void delLoginQrCode(){
     public void delLoginQrCode(){
@@ -142,5 +140,22 @@ public class TaskService {
         }
         }
     }
     }
 
 
+    /**
+     * 清理场景nas资源
+     * 执行时间:每天凌晨
+     * 删除条件:场景计算时间大于6个月且未删除过资源
+     */
+    @Scheduled(cron = "0 0 0/2 * * ?")
+    public void sceneCleanResource() {
+        log.info("每天凌晨12:00开始执行定时任务:清除场景计算目录");
+        try {
+            sceneCleanService.sceneCleanResource();
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        log.info("清除场景计算目录任务执行完成");
+    }
+
 
 
 }
 }

+ 10 - 1
src/main/java/com/fdkankan/ucenter/vo/request/DownNumParam.java

@@ -1,6 +1,7 @@
 package com.fdkankan.ucenter.vo.request;
 package com.fdkankan.ucenter.vo.request;
 
 
 import lombok.Data;
 import lombok.Data;
+import org.apache.commons.lang3.StringUtils;
 
 
 @Data
 @Data
 public class DownNumParam {
 public class DownNumParam {
@@ -13,5 +14,13 @@ public class DownNumParam {
     private String userName;
     private String userName;
 
 
     private Long  incrementId;
     private Long  incrementId;
-    private Integer incrementType = 1;
+
+    private Integer incrementType ;
+
+    public Integer getIncrementType() {
+        if(incrementType == null && StringUtils.isNotBlank(skuSn) && StringUtils.isNumeric(skuSn)){
+            return  Integer.valueOf(skuSn);
+        }
+        return 1;
+    }
 }
 }

+ 7 - 6
src/main/resources/bootstrap-prod.yml

@@ -4,16 +4,16 @@ spring:
   cloud:
   cloud:
     nacos:
     nacos:
       config:
       config:
-        server-addr: 120.24.144.164:8848
+        server-addr: 172.20.1.63:8848
         file-extension: yaml
         file-extension: yaml
-        namespace: 4dkankan-test
+        namespace: 4dkankan-v4-prod
         extension-configs:
         extension-configs:
           - data-id: 4dkankan-center-ucenter.yaml
           - data-id: 4dkankan-center-ucenter.yaml
             group: DEFAULT_GROUP
             group: DEFAULT_GROUP
             refresh: true
             refresh: true
         shared-configs:
         shared-configs:
 
 
-          - data-id: common-redis-config-52.yaml
+          - data-id: common-redis-config.yaml
             group: DEFAULT_GROUP
             group: DEFAULT_GROUP
             refresh: true
             refresh: true
 
 
@@ -21,20 +21,21 @@ spring:
             group: DEFAULT_GROUP
             group: DEFAULT_GROUP
             refresh: true
             refresh: true
 
 
-          - data-id: other-config.yaml
+          - data-id: common-config.yaml
             group: DEFAULT_GROUP
             group: DEFAULT_GROUP
             refresh: true
             refresh: true
 
 
-          - data-id: common-upload-config.yaml
+          - data-id: common-fyun-config.yaml
             group: DEFAULT_GROUP
             group: DEFAULT_GROUP
             refresh: true
             refresh: true
 
 
           - data-id: forest-config.yaml
           - data-id: forest-config.yaml
             group: DEFAULT_GROUP
             group: DEFAULT_GROUP
             refresh: true
             refresh: true
+
       discovery:
       discovery:
         server-addr: ${spring.cloud.nacos.config.server-addr}
         server-addr: ${spring.cloud.nacos.config.server-addr}
-        namespace: 4dkankan-test
+        namespace: ${spring.cloud.nacos.config.namespace}
 
 
 
 
 
 

+ 41 - 0
src/main/resources/mapper/ucenter/SceneCleanMapper.xml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fdkankan.ucenter.mapper.ISceneCleanMapper">
+
+  <select id="selectNeadCleanScene" resultType="com.fdkankan.ucenter.bean.SceneBean">
+    select t.num, t.data_source from (
+      SELECT p.num, p.data_source
+      FROM t_scene_pro p
+      WHERE p.status != 0 and p.is_upgrade != 1 and p.create_time <![CDATA[ <= ]]> #{time}
+      and p.num NOT IN (
+          SELECT c.num FROM t_scene_clean c WHERE c.state = 1
+      )
+
+      union
+
+      SELECT p.num, e.data_source
+      FROM t_scene_plus p
+      left join t_scene_plus_ext e on p.id = e.plus_id
+      WHERE p.scene_status != 0 and e.algorithm_time <![CDATA[ <= ]]> #{time}
+      and p.num NOT IN (
+          SELECT c.num FROM t_scene_clean c WHERE c.state = 1
+      )
+    ) t
+    LIMIT #{index},#{size}
+  </select>
+
+  <select id="findAllByDateSource" resultType="com.fdkankan.ucenter.bean.SceneClean">
+    select t.create_time from (
+    SELECT p.create_time
+    FROM t_scene_pro p
+    WHERE p.data_source = #{dataSource}
+
+    union
+
+    SELECT p.algorithm_time
+    FROM t_scene_plus_ext p
+    WHERE p.data_source = #{dataSource}
+    ) t order by create_time desc
+  </select>
+
+</mapper>