Browse Source

Merge branch 'test'

lyhzzz 2 years ago
parent
commit
f419860800

+ 3 - 1
src/main/java/com/fdkankan/manage/common/ResultCode.java

@@ -66,7 +66,9 @@ public enum ResultCode  {
     DEL_UCENTER_ERROR(50049, "该用户已绑定相机,请先解绑再删除用户。"),
     DATA_TOO_LONG(50050, "长度超出限制!"),
     SS_SCENE_DOWN_ERROR(50051, "获取深时下载状态失败!"),
-    SS_GET_ERROR(50052, "访问深时失败!"),
+    MOVE_SCENE_ERROR(50052, "迁移失败!"),
+    SS_GET_ERROR(50053, "访问深时失败!"),
+    SCENE_IS_BUILDING(50054, "场景计算中,不能复制!"),
 
     ;
 

+ 0 - 2
src/main/java/com/fdkankan/manage/config/SaTokenConfigure.java

@@ -48,7 +48,6 @@ public class SaTokenConfigure {
                 .addInclude("/**").addExclude("/**/reMyselfPassword","/**/test/**","/**/inner/**")
                 // 认证函数: 每次请求执行
                 .setAuth(obj -> {
-                    log.info("---------- 进入Sa-Token全局认证 -----------");
                     // 登录认证 -- 拦截所有路由,并排除/user/doLogin 用于开放登录
                     SaRouter.match("/**", "/service/manage/login", r ->checkLogin() );
                     String menu = redisUtil.get(RedisKey.MANAGE_MENU);
@@ -75,7 +74,6 @@ public class SaTokenConfigure {
 
                 // 异常处理函数:每次认证函数发生异常时执行此函数
                 .setError(e -> {
-                    System.out.println("---------- 进入Sa-Token异常处理 -----------");
                     SaHolder.getResponse().setHeader("Content-Type", "application/json;charset=UTF-8");
                     ResultData aj ;
                     if (e instanceof NotLoginException) {	// 如果是未登录异常

+ 2 - 2
src/main/java/com/fdkankan/manage/exception/GlobalExceptionHandler.java

@@ -33,7 +33,7 @@ public class GlobalExceptionHandler {
     @ResponseBody
     @ExceptionHandler(value = BusinessException.class)
     public ResultData businessExceptionHandler(BusinessException e) {
-        log.info("业务异常code:{},message:{}", e.getCode(), e.getMessage());
+        log.error("业务异常code:{},message:{}", e.getCode(), e.getMessage());
         return ResultData.error(e.getCode(), e.getMessage());
     }
     /**
@@ -42,7 +42,7 @@ public class GlobalExceptionHandler {
     @ResponseBody
     @ExceptionHandler(value = com.fdkankan.common.exception.BusinessException.class)
     public ResultData businessExceptionHandler(com.fdkankan.common.exception.BusinessException e) {
-        log.info("业务异常code:{},message:{}", e.getCode(), e.getMessage());
+        log.error("业务异常code:{},message:{}", e.getCode(), e.getMessage());
         return ResultData.error(e.getCode(), e.getMessage());
     }
     /**

+ 1 - 1
src/main/java/com/fdkankan/manage/httpClient/service/LaserService.java

@@ -196,7 +196,7 @@ public class LaserService {
     public void move(String num, String snCode, String toSnCode,Long userId) {
         LaserSceneMoveParam param = new LaserSceneMoveParam();
         param.setSceneCode(num);
-        param.setSnCode(snCode);
+        //param.setSnCode(snCode);
         param.setToSnCode(toSnCode);
         param.setUserId(userId);
         if(userId != null){

+ 4 - 0
src/main/java/com/fdkankan/manage/mapper/ISceneProMapper.java

@@ -27,4 +27,8 @@ public interface ISceneProMapper extends BaseMapper<ScenePro> {
     List<GroupByCount> getCountGroupByCameraId(@Param("cameraIds") List<Long> cameraIds);
 
     Page<SceneVo> pageList(Page<SceneVo> page, SceneParam param);
+
+    List<GroupByCount> getPlusSpaceGroupByCameraId();
+
+    List<GroupByCount> getProSpaceGroupByCameraId();
 }

+ 2 - 0
src/main/java/com/fdkankan/manage/service/ICameraDetailService.java

@@ -39,4 +39,6 @@ public interface ICameraDetailService extends IService<CameraDetail> {
     void delAgentId(Integer agentId);
 
     List<CameraDetail> getByUserId(Long id);
+
+    void addUsedSpace(Long cameraId,Long space);
 }

+ 2 - 0
src/main/java/com/fdkankan/manage/service/ICameraService.java

@@ -39,4 +39,6 @@ public interface ICameraService extends IService<Camera> {
     Integer outs(List<CameraInOutParam> params);
 
     Integer updateCompany(List<CameraInOutParam> companyParams);
+
+    void initAllCameraSpace();
 }

+ 3 - 2
src/main/java/com/fdkankan/manage/service/ISceneProService.java

@@ -6,6 +6,7 @@ import com.fdkankan.manage.entity.ScenePlus;
 import com.fdkankan.manage.entity.ScenePro;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fdkankan.manage.vo.request.SceneParam;
+import com.fdkankan.manage.vo.response.GroupByCount;
 
 import java.util.HashMap;
 import java.util.List;
@@ -48,6 +49,6 @@ public interface ISceneProService extends IService<ScenePro> {
 
     HashMap<String, String> getSnCodeByNumList(Set<String> numList);
 
-    void updateFdage(String oldSnCode,String newSnCode,String dataSource);
 
-    }
+    HashMap<Long,Long > getSpaceGroupByCameraId();
+}

+ 16 - 1
src/main/java/com/fdkankan/manage/service/impl/CameraDetailServiceImpl.java

@@ -82,7 +82,7 @@ public class CameraDetailServiceImpl extends ServiceImpl<ICameraDetailMapper, Ca
         wrapper.set(CameraDetail::getTotalSpace,Long.parseLong(Constant.EXPANSION_SPACE_VALUE_1G ) * 10L);
         this.update(wrapper);
 
-        if(!"local".equals(CacheUtil.uploadType)){
+        if(!"local".equals(CacheUtil.uploadType) && cameraDetail.getType() !=10){
             sceneProService.lockOrUnLockBySpace(cameraDetail,cameraId,-2);     //封存场景
         }
 
@@ -217,4 +217,19 @@ public class CameraDetailServiceImpl extends ServiceImpl<ICameraDetailMapper, Ca
         wrapper.eq(CameraDetail::getUserId,userId);
         return this.list(wrapper);
     }
+
+    @Override
+    public void addUsedSpace(Long cameraId,Long space) {
+        if(space == null){
+            return;
+        }
+        CameraDetail cameraDetail = this.getByCameraId(cameraId);
+        long usedSpace = cameraDetail.getUsedSpace() - space ;
+        cameraDetail.setUsedSpace(usedSpace < 0 ? 0L :usedSpace);
+        //解封封存场景
+        if(cameraDetail.getType() != 10){
+            sceneProService.lockOrUnLockBySpace(cameraDetail,cameraDetail.getCameraId(),1);
+        }
+        this.updateById(cameraDetail);
+    }
 }

+ 18 - 0
src/main/java/com/fdkankan/manage/service/impl/CameraServiceImpl.java

@@ -472,4 +472,22 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
         return resultMap;
     }
 
+    @Override
+    public void initAllCameraSpace() {
+        List<Camera> list = this.list();
+        List<Long> cameraIds = list.stream().map(Camera::getId).collect(Collectors.toList());
+        List<CameraDetail> cameraDetails = cameraDetailService.getByCameraIds(cameraIds);
+        HashMap<Long, Long> map = sceneProService.getSpaceGroupByCameraId();
+        for (CameraDetail cameraDetail : cameraDetails) {
+            Long space = map.get(cameraDetail.getCameraId());
+            if(space != null){
+                space = space  > 0 ? space : 0;
+                LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
+                wrapper.eq(CameraDetail::getId,cameraDetail.getId());
+                wrapper.set(CameraDetail::getUsedSpace,space);
+                cameraDetailService.update(wrapper);
+            }
+        }
+
+    }
 }

+ 98 - 51
src/main/java/com/fdkankan/manage/service/impl/SceneProServiceImpl.java

@@ -2,6 +2,7 @@ package com.fdkankan.manage.service.impl;
 
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -132,6 +133,9 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
      */
     @Override
     public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId, Integer payStatus) {
+        if(cameraDetail == null){
+            cameraDetail = cameraDetailService.getByCameraId(cameraId);
+        }
         LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
         Long totalSpace = cameraDetail.getTotalSpace();
@@ -175,7 +179,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
 
         List<Long> lockedIds = new ArrayList<>();
 
-        if(totalSpace == -1 && payStatus == 1){
+        if(totalSpace == -1){
             List<Long> collect = list.stream().map(ScenePro::getId).collect(Collectors.toList());
             List<Long> collect2 = plusList.stream().map(ScenePlus::getId).collect(Collectors.toList());
             lockedIds.addAll(collect);
@@ -187,7 +191,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         Long beyondSpace =  0L;
         Long accumulateSpace = 0L;
         if(payStatus == 1){
-            beyondSpace =  totalSpace - cameraDetail.getTotalSpace();
+            beyondSpace =  totalSpace - cameraDetail.getUsedSpace();
             getScenePlusLockedIds(lockedIds, plusList, beyondSpace, accumulateSpace);
             getSceneLockedIds(lockedIds,list,beyondSpace,accumulateSpace);
         }else {
@@ -442,70 +446,83 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         if(cameraDetail.getType() == 10){       //深时场景
             laserService.move(param.getNum(),oldCamera.getSnCode(),camera.getSnCode(),cameraDetail.getUserId());
         }
-        updateFdage(oldCamera.getSnCode(),param.getSnCode(),dataSource);
+        updateFdageNewDataSource(scenePro,scenePlus,oldCamera.getSnCode(),param.getSnCode(),dataSource);
     }
 
-    @Override
-    public void updateFdage(String oldSnCode,String newSnCode,String dataSource) {
-        String localPath = String.format(OssPath.localFdagePath,dataSource)+"/data.fdage";
-        try {
-            String fdagePaht =  dataSource.replace("/mnt/data","home") +"/data.fdage";
-            String fileContent = fYunFileServiceInterface.getFileContent(fdagePaht);
-            String newJson = fileContent.replaceAll("(?i)"+oldSnCode,newSnCode.toLowerCase());
-            FileUtils.writeFile(localPath ,newJson);
-            log.info("updateFdage--localPath:{},ossPath:{}",localPath,fdagePaht);
-            String localPathBack = localPath+"_"+oldSnCode+"-"+newSnCode+"_"+Dateutils.getDateN(new Date())+".back";
-            String fdagePathBack = fdagePaht+"_"+oldSnCode+"-"+newSnCode+"_"+Dateutils.getDateN(new Date())+".back";
-
-            fYunFileServiceInterface.downloadFile(fdagePaht,localPathBack);
-            fYunFileServiceInterface.uploadFile(localPathBack,fdagePathBack);
-            fYunFileServiceInterface.uploadFile(localPath,fdagePaht);
-        }catch (Exception e){
-            log.error("updateFdage-error:oldSnCode:{},newSnCode:{},dataSource:{}",oldSnCode,newSnCode,dataSource);
-            log.error("updateFdage-error:",e);
-        }finally {
-            FileUtil.del(localPath);
+
+
+    private JSONObject updateFdageJson(JSONObject jsonObject,String newSnCode){
+        JSONObject cam = jsonObject.getJSONObject("cam");
+        if(cam != null){
+            cam.put("uuid",newSnCode.toLowerCase());      //替换相机sn uuid
         }
+        JSONArray points = jsonObject.getJSONArray("points");   //修改点位中的相机sn
+        if(points !=null){
+            for (Object point : points) {
+                JSONObject jobj = (JSONObject) point;
+                jobj.put("camera",newSnCode.toLowerCase());
+            }
+        }
+        jsonObject.put("creator",newSnCode.toLowerCase());      //替换相机拍摄sn
+        return jsonObject;
     }
 
-    public void updateFdageNewDataSource(String oldSnCode,String newSnCode,String dataSource) {
-        String localPath = String.format(OssPath.localFdagePath,dataSource);
+    /**
+     * 兼容,之前迁移,不使用旧snCode 替换新snCode。重写文件
+     */
+    public void updateFdageNewDataSource(ScenePro scenePro,ScenePlus scenePlus,String oldSnCode,String newSnCode,String dataSource) {
+        String localPathFdage = null;
         try {
-            String localPathFdage = String.format(OssPath.localFdagePath,dataSource)+"/data.fdage";
+            newSnCode = newSnCode.toLowerCase();
+            String fdagePaht =  dataSource.replace("/mnt/data","home") +"/data.fdage";
+            localPathFdage = String.format(OssPath.localFdagePath,fdagePaht);
 
-            String homeData =  dataSource.replace("/mnt/data","home");
-            ShellUtil.yunDownload(homeData,localPath);
+            String fileContent = fYunFileServiceInterface.getFileContent(fdagePaht);
 
-            String fileContent = FileUtils.readFile(localPathFdage);
-            String newJson = fileContent.replaceAll("(?i)"+oldSnCode,newSnCode.toLowerCase());
-            FileUtils.writeFile(localPathFdage ,newJson);
+            JSONObject jsonObject = updateFdageJson(JSONObject.parseObject(fileContent), newSnCode);
+            FileUtils.writeFile(localPathFdage ,JSONObject.toJSONString(jsonObject));
 
             String oldFdagePaht =  dataSource.replace("/mnt/data","home") ;
-            String newFdagePaht =  oldFdagePaht.replaceAll("(?i)"+oldSnCode,newSnCode.toLowerCase()) ;
-            ShellUtil.yunUpload(localPath,newFdagePaht);
-
-            log.info("updateFdage--localPath:{},ossPath:{}",localPath,newFdagePaht);
-            String newDataSource = dataSource.replaceAll("(?i)"+oldSnCode,newSnCode.toLowerCase()) ;
-            this.updateDataSource(dataSource,newDataSource);
-            fYunFileServiceInterface.deleteFolder(oldFdagePaht);
+            String[] split = oldFdagePaht.split("/");
+            String newFdagePath = split[0] +"/"+ newSnCode +"/"+ split[2] +"/"+ newSnCode +"_" + split[3].split("_")[1];
+            if(!oldFdagePaht.equals(newFdagePath)){
+                log.info("updateFdageCopy--复制oss资源--oldFdagePaht:{},newFdagePath:{}",oldFdagePaht,newFdagePath);
+                fYunFileServiceInterface.copyFileInBucket(oldFdagePaht,newFdagePath);
+                fYunFileServiceInterface.deleteFolder(oldFdagePaht);
+            }
+            fYunFileServiceInterface.copyFileInBucket(newFdagePath+"/data.fdage",newFdagePath+"/"+oldSnCode.toLowerCase()+"-"+newSnCode+"_"+Dateutils.getDate(new Date())+".data.fdage");
+            fYunFileServiceInterface.uploadFile(localPathFdage,newFdagePath+"/data.fdage");
+            log.info("updateFdage--localPathFdage:{},newFdagePath:{}",localPathFdage,newFdagePath);
+            String newDataSource = newFdagePath.replace("home","/mnt/data");
+            this.updateDataSource(scenePro,scenePlus,newDataSource);
         }catch (Exception e){
             log.error("updateFdage-error:oldSnCode:{},newSnCode:{},dataSource:{}",oldSnCode,newSnCode,dataSource);
             log.error("updateFdage-error:",e);
+            throw new BusinessException(ResultCode.MOVE_SCENE_ERROR);
         }finally {
-            FileUtil.del(localPath);
+            if(localPathFdage != null){
+                FileUtil.del(localPathFdage);
+            }
         }
     }
 
-    private void updateDataSource(String dataSource, String newDataSource) {
-        LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
-        wrapper.eq(ScenePro::getDataSource,dataSource);
-        wrapper.set(ScenePro::getDataSource,newDataSource);
-        this.update(wrapper);
 
-        LambdaUpdateWrapper<ScenePlusExt> wrapperPlus = new LambdaUpdateWrapper<>();
-        wrapperPlus.eq(ScenePlusExt::getDataSource,dataSource);
-        wrapperPlus.set(ScenePlusExt::getDataSource,newDataSource);
-        scenePlusExtService.update(wrapperPlus);
+    private void updateDataSource(ScenePro scenePro,ScenePlus scenePlus, String newDataSource) {
+        if(scenePro !=null){
+            LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
+            wrapper.eq(ScenePro::getId,scenePro.getId());
+            wrapper.eq(ScenePro::getIsUpgrade,0);
+            wrapper.set(ScenePro::getDataSource,newDataSource);
+            this.update(wrapper);
+        }
+        if(scenePlus !=null){
+            LambdaUpdateWrapper<ScenePlusExt> wrapperPlus = new LambdaUpdateWrapper<>();
+            wrapperPlus.eq(ScenePlusExt::getPlusId,scenePlus.getId());
+            wrapperPlus.set(ScenePlusExt::getDataSource,newDataSource);
+            scenePlusExtService.update(wrapperPlus);
+        }
+
+
     }
 
     @Override
@@ -524,9 +541,13 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         if(detailEntity == null){
             throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
         }
-        if(detailEntity.getType() == 10){
-            throw new BusinessException(ResultCode.SS_NO_COPY);
+        Integer sceneStatus = scenePro == null ? scenePlus.getSceneStatus() : scenePro.getStatus();
+        if(sceneStatus != -2){
+            throw new BusinessException(ResultCode.SCENE_IS_BUILDING);
         }
+//        if(detailEntity.getType() == 10  ){
+//            throw new BusinessException(ResultCode.SS_NO_COPY);
+//        }
 
         HashMap<String, Object> param = new HashMap<>();
         param.put("num",sceneNum);
@@ -537,9 +558,13 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
     @Override
     public void deleteByNum(String num) {
         Integer sceneSource = null;
+        Long cameraId = null;
+        Long space = null;
         ScenePro scenePro = this.getByNum(num);
         if(scenePro!=null){
+            cameraId = scenePro.getCameraId();
             sceneSource = scenePro.getSceneSource();
+            space = scenePro.getSpace();
             this.removeById(scenePro.getId());
         }
         Scene scene = sceneService.getByNum(num);
@@ -548,13 +573,21 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         }
         ScenePlus scenePlus = scenePlusService.getByNum(num);
         if(scenePlus!=null){
+            cameraId = scenePlus.getCameraId();
             sceneSource = scenePlus.getSceneSource();
+            ScenePlusExt plusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
+            if(plusExt != null){
+                space = plusExt.getSpace();
+                scenePlusExtService.delByPlus(scenePlus.getId());
+            }
             scenePlusService.removeById(scenePlus.getId());
-            scenePlusExtService.delByPlus(scenePlus.getId());
         }
         if(sceneSource != null && sceneSource == 4){
             laserService.delete(num);
         }
+        if(cameraId != null){
+            cameraDetailService.addUsedSpace(cameraId,space);
+        }
     }
 
     @Override
@@ -651,4 +684,18 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
 
         return snCodeMap;
     }
+
+    @Override
+    public  HashMap<Long,Long > getSpaceGroupByCameraId() {
+        List<GroupByCount> proSum = this.getBaseMapper().getProSpaceGroupByCameraId();
+        HashMap<Long,Long > map = new HashMap<>();
+        for (GroupByCount groupByCount : proSum) {
+            map.merge(groupByCount.getId(), groupByCount.getCount(), Long::sum);
+        }
+        List<GroupByCount > plusSum = this.getBaseMapper().getPlusSpaceGroupByCameraId();
+        for (GroupByCount groupByCount : plusSum) {
+            map.merge(groupByCount.getId(), groupByCount.getCount(), Long::sum);
+        }
+        return map;
+    }
 }

+ 15 - 1
src/main/java/com/fdkankan/manage/test/TestController.java

@@ -1,6 +1,7 @@
 package com.fdkankan.manage.test;
 
 import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
@@ -11,6 +12,8 @@ import com.fdkankan.common.util.SecurityUtil;
 import com.fdkankan.manage.common.FilePath;
 import com.fdkankan.manage.exception.BusinessException;
 import com.fdkankan.manage.httpClient.service.LaserService;
+import com.fdkankan.manage.service.ICameraService;
+import com.fdkankan.manage.service.IScenePlusService;
 import com.fdkankan.manage.service.ISceneProService;
 import com.fdkankan.manage.util.Dateutils;
 import com.fdkankan.manage.util.ExcelUtil;
@@ -32,15 +35,26 @@ public class TestController {
 
     @Autowired
     ISceneProService sceneProService;
+    @Autowired
+    FYunFileServiceInterface fYunFileServiceInterface;
+    @Autowired
+    ICameraService cameraService;
 
     @RequestMapping("/test")
     public ResultData test(@RequestParam(required = false) String oldSnCode,
                            @RequestParam(required = false)String newSnCode,
                            @RequestParam(required = false)String dataSource){
-       sceneProService.updateFdage(oldSnCode, newSnCode, dataSource);
+
         return ResultData.ok();
     }
 
+    @RequestMapping("/testCameraSpace")
+    public ResultData test(){
+        cameraService.initAllCameraSpace();
+        return ResultData.ok();
+    }
+
+
     /**
      * 导入excel
      * type 0 入库模板, 1出库模板 ,2 客户关联模板

+ 14 - 0
src/main/resources/mapper/manage/SceneProMapper.xml

@@ -86,4 +86,18 @@
             and s.create_time &lt;= #{param.endTime}
         </if>
     </sql>
+
+
+    <select id="getProSpaceGroupByCameraId" resultType="com.fdkankan.manage.vo.response.GroupByCount">
+        SELECT camera_id as id,sum(space) as count  FROM t_scene_pro
+        WHERE  rec_status = 'A'  and is_upgrade = 0  GROUP BY camera_id
+
+    </select>
+
+    <select id="getPlusSpaceGroupByCameraId" resultType="com.fdkankan.manage.vo.response.GroupByCount">
+        SELECT p.camera_id as id,sum(space) as count FROM t_scene_plus p left join  t_scene_plus_ext e on p.id = e.plus_id
+        WHERE  p.rec_status = 'A'  GROUP BY p.camera_id
+
+    </select>
+
 </mapper>