lyhzzz 1 vecka sedan
förälder
incheckning
2877fbebc9

+ 3 - 10
src/main/java/com/fdkankan/manage_jp/common/RedisKeyUtil.java

@@ -2,16 +2,9 @@ package com.fdkankan.manage_jp.common;
 
 public class RedisKeyUtil {
 
-
-    public static final String SCENE_UNUSED_NUMS = "4dkankan:scene:nums";
-    public static final String SCENE_NUMS_LOADING = "4dkankan:scene:nums:loading";
-    public static final String loginNum= "manage:login:userName:%s:ip:%s";
-
-    public static final String loginToken= "manage:login:token:%s";
-
-    public static final String laserCopyLock = "manage:laser:copy:lock:";
-
-
     public static final String SCENE_VERSION = "scenejson:num:%s";
     public static final String checkEditPermissionCacheKey = "manage:checkEditPermissionCacheKey:%s:%s";
+
+    public static final String LOGIN_USER = "manage:login.username:%s:token:%s";
+
 }

+ 2 - 0
src/main/java/com/fdkankan/manage_jp/common/ResultCode.java

@@ -60,6 +60,8 @@ public enum ResultCode  {
     REPEAT_ERROR(5036, "重复提交!"),
 
     SCENE_MOVE_ERROR(5037, "场景类型错误,不能迁移"),
+    USER_BAN(5038, "用户状态为禁用"),
+    COMPANY_DEL_ERROR(5039, "企业下存在设备,不可删除"),
 
     ;
 

+ 5 - 0
src/main/java/com/fdkankan/manage_jp/controller/CompanyController.java

@@ -10,6 +10,7 @@ import com.fdkankan.common.util.SecurityUtil;
 import com.fdkankan.manage_jp.common.PageInfo;
 import com.fdkankan.manage_jp.common.Result;
 import com.fdkankan.manage_jp.common.ResultCode;
+import com.fdkankan.manage_jp.entity.CameraDetail;
 import com.fdkankan.manage_jp.entity.Company;
 import com.fdkankan.manage_jp.entity.User;
 import com.fdkankan.manage_jp.exception.BusinessException;
@@ -158,6 +159,10 @@ public class CompanyController {
         if(StringUtils.isEmpty(param.getId())){
             throw new BusinessException(ResultCode.PARAM_ERROR);
         }
+        List<CameraDetail> listByCompanyId = cameraDetailService.getListByCompanyId(param.getId());
+        if(!listByCompanyId.isEmpty()){
+            throw new BusinessException(ResultCode.COMPANY_DEL_ERROR);
+        }
         companyService.removeById(param.getId());
 
         cameraDetailService.updateCompanyId(param.getId());

+ 2 - 7
src/main/java/com/fdkankan/manage_jp/controller/UserController.java

@@ -3,6 +3,7 @@ package com.fdkankan.manage_jp.controller;
 
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.fdkankan.common.util.JwtUtil;
+import com.fdkankan.manage_jp.common.RedisKeyUtil;
 import com.fdkankan.manage_jp.common.Result;
 import com.fdkankan.manage_jp.common.ResultCode;
 import com.fdkankan.manage_jp.entity.User;
@@ -114,13 +115,7 @@ public class UserController extends BaseController {
 
     @PostMapping("/enableUser")
     public Result enableUser(@RequestBody UserParam param){
-        if(param.getId() == null || param.getStatus() == null){
-            throw new BusinessException(ResultCode.PARAM_ERROR);
-        }
-        LambdaUpdateWrapper<User> wrapper = new LambdaUpdateWrapper<>();
-        wrapper.eq(User::getId,param.getId());
-        wrapper.set(User::getStatus,param.getStatus());
-        userService.update(wrapper);
+        userService.enableUser(param);
         return Result.success();
     }
 }

+ 3 - 0
src/main/java/com/fdkankan/manage_jp/entity/ScenePlus.java

@@ -126,4 +126,7 @@ public class ScenePlus implements Serializable {
 
     @TableField("map_show")
     private Integer mapShow;
+
+    @TableField(exist = false)
+    private String dataSource;
 }

+ 6 - 2
src/main/java/com/fdkankan/manage_jp/interceptor/UcenterInterceptor.java

@@ -3,8 +3,11 @@ package com.fdkankan.manage_jp.interceptor;
 
 import cn.hutool.http.ContentType;
 import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.common.util.JwtUtil;
+import com.fdkankan.manage_jp.common.RedisKeyUtil;
 import com.fdkankan.manage_jp.common.Result;
 import com.fdkankan.manage_jp.common.ResultCode;
+import com.fdkankan.manage_jp.entity.User;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -37,13 +40,14 @@ public class UcenterInterceptor implements HandlerInterceptor {
 			return false;
 		}
 		try {
-			String redisKey = String.format(RedisKey.TOKEN_V3,token);
+			String username = JwtUtil.getUsername(token);
+			String redisKey = String.format(RedisKeyUtil.LOGIN_USER,username,token);
 			if(redisUtil.hasKey(redisKey)){
 				redisUtil.expire(redisKey,2 * 60 * 60);
 				return true;
 			}
 		}catch (Exception e){
-			e.printStackTrace();
+			log.info("UcenterInterceptor-error:{}",e);
 		}
 		this.needLogin(request,response);
 		return false;

+ 10 - 0
src/main/java/com/fdkankan/manage_jp/mapper/ISceneProMapper.java

@@ -1,11 +1,15 @@
 package com.fdkankan.manage_jp.mapper;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fdkankan.manage_jp.entity.ScenePlus;
 import com.fdkankan.manage_jp.entity.ScenePro;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fdkankan.manage_jp.vo.request.SceneParam;
 import com.fdkankan.manage_jp.vo.response.SceneVo;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * <p>
@@ -19,4 +23,10 @@ import org.apache.ibatis.annotations.Mapper;
 public interface ISceneProMapper extends BaseMapper<ScenePro> {
 
     Page<SceneVo> pageList(Page<Object> page, SceneParam param);
+
+    List<ScenePro> getDelSceneNumV3();
+    List<ScenePlus> getDelSceneNumV4();
+
+    void updateDelSourceV3(@Param("num") String num);
+    void updateDelSourceV4(@Param("num") String num);
 }

+ 7 - 0
src/main/java/com/fdkankan/manage_jp/service/ISceneProService.java

@@ -1,5 +1,6 @@
 package com.fdkankan.manage_jp.service;
 
+import com.fdkankan.manage_jp.entity.ScenePlus;
 import com.fdkankan.manage_jp.entity.ScenePro;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fdkankan.manage_jp.entity.User;
@@ -45,4 +46,10 @@ public interface ISceneProService extends IService<ScenePro> {
     void openMapShow(List<String> sceneMapShowList);
 
     void moveUser(SceneParam param);
+
+    List<ScenePro> getDelSceneNumV3();
+    List<ScenePlus> getDelSceneNumV4();
+
+    void updateDelSourceV3(String num);
+    void updateDelSourceV4(String num);
 }

+ 2 - 0
src/main/java/com/fdkankan/manage_jp/service/IUserService.java

@@ -43,4 +43,6 @@ public interface IUserService extends IService<User> {
     List<User> allList(User param);
 
     List<User> getByCompanyId(Long companyId);
+
+    void enableUser(UserParam param);
 }

+ 18 - 0
src/main/java/com/fdkankan/manage_jp/service/impl/SceneProServiceImpl.java

@@ -553,4 +553,22 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         plusWr.set(ScenePlus::getMapShow,1);
         scenePlusService.update(plusWr);
     }
+
+    @Override
+    public List<ScenePro> getDelSceneNumV3() {
+        return this.getBaseMapper().getDelSceneNumV3();
+    }
+    @Override
+    public List<ScenePlus> getDelSceneNumV4() {
+        return this.getBaseMapper().getDelSceneNumV4();
+    }
+
+    @Override
+    public void updateDelSourceV3(String num) {
+        this.getBaseMapper().updateDelSourceV3(num);
+    }
+    @Override
+    public void updateDelSourceV4(String num) {
+        this.getBaseMapper().updateDelSourceV4(num);
+    }
 }

+ 28 - 1
src/main/java/com/fdkankan/manage_jp/service/impl/UserServiceImpl.java

@@ -9,6 +9,7 @@ import com.fdkankan.common.util.JwtUtil;
 import com.fdkankan.common.util.PasswordUtils;
 import com.fdkankan.common.util.SecurityUtil;
 import com.fdkankan.manage_jp.common.PageInfo;
+import com.fdkankan.manage_jp.common.RedisKeyUtil;
 import com.fdkankan.manage_jp.common.ResultCode;
 import com.fdkankan.manage_jp.entity.*;
 import com.fdkankan.manage_jp.exception.BusinessException;
@@ -117,6 +118,9 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
         if(!user.getPassword().equals(passwordCode)){
             throw new BusinessException(ResultCode.PASSWORD_ERROR);
         }
+        if(user.getStatus() == 0){
+            throw new BusinessException(ResultCode.USER_BAN);
+        }
         String token = this.redisLogin(user.getUserName(), JSONObject.toJSONString(user),"user");
         UserVo userVo = getUserVo(user);
         LoginVo vo = new LoginVo();
@@ -127,7 +131,7 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
 
     public String redisLogin(String userName,String value,String loginType){
         String token = JwtUtil.createJWT(-1,userName,loginType);
-        String redisKey = String.format(RedisKey.TOKEN_V3,token);
+        String redisKey = String.format(RedisKeyUtil.LOGIN_USER,userName,token);
         redisUtil.set(redisKey, value,2 * 60 * 60);
         return token;
     }
@@ -233,4 +237,27 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
         wrapper.eq(User::getCompanyId,companyId);
         return this.list(wrapper);
     }
+
+    @Override
+    public void enableUser(UserParam param) {
+        if(param.getId() == null || param.getStatus() == null){
+            throw new BusinessException(ResultCode.PARAM_ERROR);
+        }
+        User user = this.getById(param.getId());
+        if(user == null){
+            throw new BusinessException(ResultCode.USER_NOT_EXIST);
+        }
+        LambdaUpdateWrapper<User> wrapper = new LambdaUpdateWrapper<>();
+        wrapper.eq(User::getId,param.getId());
+        wrapper.set(User::getStatus,param.getStatus());
+        this.update(wrapper);
+
+        if(param.getStatus() == 0 ){
+            String redisKey = String.format(RedisKeyUtil.LOGIN_USER,user.getUserName(),"*");
+            Set<String> keys = redisUtil.keys(redisKey);
+            keys.forEach(e -> redisUtil.del(e));
+        }
+
+
+    }
 }

+ 119 - 4
src/main/java/com/fdkankan/manage_jp/task/TaskService.java

@@ -1,22 +1,24 @@
 package com.fdkankan.manage_jp.task;
 
+import cn.hutool.core.io.FileUtil;
 import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
+import com.fdkankan.manage_jp.config.ManageConfig;
 import com.fdkankan.manage_jp.entity.Project;
 import com.fdkankan.manage_jp.entity.ProjectSceneGps;
 import com.fdkankan.manage_jp.entity.ScenePlus;
+import com.fdkankan.manage_jp.entity.ScenePro;
 import com.fdkankan.manage_jp.httpClient.service.LaserService;
 import com.fdkankan.manage_jp.service.IProjectSceneGpsService;
 import com.fdkankan.manage_jp.service.ISceneProService;
 import com.fdkankan.manage_jp.vo.response.SceneGpsDb;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -77,4 +79,117 @@ public class TaskService {
         }
         sceneProService.openMapShow(sceneMapShowList);
     }
+
+
+
+
+    @Autowired
+    ManageConfig manageConfig;
+    @Autowired
+    FYunFileServiceInterface fYunFileServiceInterface;
+
+    @Scheduled(initialDelay = 3000,fixedDelay = 1000 * 60 * 60 *24)
+    public void delScene() {
+        List<ScenePro> scenePros = sceneProService.getDelSceneNumV3();
+        for (ScenePro scenePro : scenePros) {
+            if(StringUtils.isBlank(scenePro.getNum())){
+                continue;
+            }
+            delSource(scenePro.getNum(),scenePro.getDataSource());
+            sceneProService.updateDelSourceV3(scenePro.getNum());
+        }
+        List<ScenePlus> scenePluses = sceneProService.getDelSceneNumV4();
+        for (ScenePlus scenePlus : scenePluses) {
+            if(StringUtils.isBlank(scenePlus.getNum())){
+                continue;
+            }
+            delSource(scenePlus.getNum(),scenePlus.getDataSource());
+            sceneProService.updateDelSourceV4(scenePlus.getNum());
+        }
+    }
+
+    /**
+     * 删除场景nas和oss数据
+     * oss
+     * 正式:laser_p_data/场景码
+     * 测试:laser_u_data/场景码
+     * 原始资源 v3 v4
+     * 查看资源 scene_view_data  v4
+     * 编辑资源 scene_edit_data v4
+     * 缓存资源 scene_result_data v4
+     * data/data<num> v3
+     * images/images<num> v3
+     * video/video<num> v3
+     * voice/voice<num> v3
+     * scene/<num>
+     * downloads/scene/<num>
+     * downloads/scenes/<num>.zip
+     * downloads/extras/<num>_extras.zip
+     * downloads/extras/<num>_mesh.zip
+     */
+
+    public static List<String> meshOssPath = Arrays.asList(
+            "scene_view_data/%s",
+            "scene_edit_data/%s",
+            "data/data%s",
+            "images/images%s",
+            "video/video%s",
+            "voice/voice%s",
+            "scene/%s",
+            "downloads/scene/%s",
+            "downloads/scenes/%s.zip",
+            "downloads/extras/%s_extras.zip",
+            "downloads/extras/%s_mesh.zip"
+    );
+
+    public static List<String> meshNasDataSourcePath = Arrays.asList(
+            "%s_images",
+            "%s_laser_obj",
+            "%s_obj2Tiles",
+            "%s_obj2txt"
+    );
+    public static List<String> meshNasNumPath = Arrays.asList(
+            "/mnt/4Dkankan/scene_v4/%s",
+            "/mnt/4Dkankan/scene/data/data%s",
+            "/mnt/4Dkankan/scene/images/images%s",
+            "/mnt/4Dkankan/scene/voice/voice%s"
+    );
+    private void delSource(String num,String dataSource){
+        try {
+            String active = manageConfig.getActive();
+            String laserOssPath = "laser_u_data/"+ num;
+            if(active.contains("prod")){
+                laserOssPath= "laser_p_data/"+ num;
+            }
+            log.info("del-scene:{},oss-path:{}",num,laserOssPath);
+            fYunFileServiceInterface.deleteFolder(laserOssPath);
+
+            String origPath = dataSource.replace("/mnt/data","home");
+            log.info("del-scene:{},oss-orig-path:{}",num,origPath);
+            fYunFileServiceInterface.deleteFolder(origPath);
+
+            for (String meshPath : meshOssPath) {
+                log.info("del-scene:{},oss-path:{}",num,String.format(meshPath,num));
+                fYunFileServiceInterface.deleteFolder(String.format(meshPath,num));
+            }
+
+            for (String meshPath : meshNasNumPath) {
+                log.info("del-scene:{},nas-path:{}",num,String.format(meshPath,num));
+                FileUtil.del(String.format(meshPath,num));
+            }
+
+            if(StringUtils.isNotBlank(dataSource)){
+                log.info("del-scene:{},nas-path:{}",num,dataSource);
+                FileUtil.del(dataSource);
+                for (String meshPath : meshNasDataSourcePath) {
+                    log.info("del-scene:{},nas-path:{}",num,String.format(meshPath,dataSource));
+                    FileUtil.del(String.format(meshPath,dataSource));
+                }
+            }
+
+        }catch (Exception e){
+            log.info("删除失败:{}",e);
+        }
+
+    }
 }

+ 15 - 0
src/main/resources/mapper/manage_jp/SceneProMapper.xml

@@ -105,4 +105,19 @@
         </if>
     </sql>
 
+    <select id="getDelSceneNumV3" resultType="com.fdkankan.manage_jp.entity.ScenePro">
+        SELECT * FROM t_scene_pro WHERE rec_status = 'I' and del_source = 0
+    </select>
+
+    <select id="getDelSceneNumV4" resultType="com.fdkankan.manage_jp.entity.ScenePlus">
+        SELECT * FROM t_scene_plus s left join t_scene_plus_ext e on s.id = e.plus_id WHERE s.rec_status = 'I' and del_source = 0
+    </select>
+
+    <update id="updateDelSourceV3">
+        UPDATE t_scene_pro set del_source = 1 WHERE num = #{num}
+    </update>
+
+    <update id="updateDelSourceV4">
+        UPDATE t_scene_plus set del_source = 1 WHERE num = #{num}
+    </update>
 </mapper>