Explorar el Código

获取redis token

wuweihao hace 4 años
padre
commit
5efbea1fe6

+ 8 - 2
720yun_fd_manage/gis_application/src/main/resources/application-sit.properties

@@ -32,14 +32,20 @@ spring.datasource.druid.web-stat-filter.enabled=true
 spring.datasource.druid.stat-view-servlet.enabled=true
 
 
-# redis \uFFFD\u05B2\uFFFD\u02BD\uFFFD\uFFFD
-spring.redis.cluster.nodes=127.0.0.1:6379
+# Redis\u6570\u636E\u5E93\u7D22\u5F15\uFF08\u9ED8\u8BA4\u4E3A0\uFF09
 spring.redis.database=0
+spring.redis.host=127.0.0.1
+spring.redis.port=6379
 spring.redis.password=
+# \u8FDE\u63A5\u8D85\u65F6\u65F6\u95F4 \u5355\u4F4D ms\uFF08\u6BEB\u79D2\uFF09
 spring.redis.timeout=3000ms
+# \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u9ED8\u8BA4\u503C\u4E5F\u662F8\u3002
 spring.redis.jedis.pool.max-idle=8
+#\u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u9ED8\u8BA4\u503C\u4E5F\u662F0\u3002
 spring.redis.jedis.pool.min-idle=0
+# \u5982\u679C\u8D4B\u503C\u4E3A-1\uFF0C\u5219\u8868\u793A\u4E0D\u9650\u5236\uFF1B\u5982\u679Cpool\u5DF2\u7ECF\u5206\u914D\u4E86maxActive\u4E2Ajedis\u5B9E\u4F8B\uFF0C\u5219\u6B64\u65F6pool\u7684\u72B6\u6001\u4E3Aexhausted(\u8017\u5C3D)\u3002
 spring.redis.jedis.pool.max-active=8
+# \u7B49\u5F85\u53EF\u7528\u8FDE\u63A5\u7684\u6700\u5927\u65F6\u95F4\uFF0C\u5355\u4F4D\u6BEB\u79D2\uFF0C\u9ED8\u8BA4\u503C\u4E3A-1\uFF0C\u8868\u793A\u6C38\u4E0D\u8D85\u65F6\u3002\u5982\u679C\u8D85\u8FC7\u7B49\u5F85\u65F6\u95F4\uFF0C\u5219\u76F4\u63A5\u629B\u51FAJedisConnectionException
 spring.redis.jedis.pool.max-wait=-1ms
 
 #rabbit MQ

+ 12 - 0
720yun_fd_manage/gis_common/src/main/java/com/gis/common/constant/MsgCode.java

@@ -0,0 +1,12 @@
+package com.gis.common.constant;
+
+/**
+ * Created by owen on 2021/3/19 0019 10:13
+ *
+ * 错误码
+ */
+public class MsgCode {
+
+    public final static Integer e3001 = 3001;
+    public final static String m3001 = "场景已使用";
+}

+ 11 - 7
720yun_fd_manage/gis_common/src/main/java/com/gis/common/shiro/MyRealm.java

@@ -80,6 +80,16 @@ public class MyRealm extends AuthorizingRealm {
         }
 
 
+        // 这里redis的key是token, value是用户信息,所以只要有返回结果,就算是验证通过
+        String tokenKey = "token#" + token;
+        String redisToken = redisTemplate.opsForValue().get(tokenKey);
+        if (redisToken == null) {
+            log.error("redis token is null");
+            throw new JwtAuthenticationException(5001, "redis token is null");
+
+        }
+
+
         // 解密获得username,用于和数据库进行对比
         String username = JwtUtil.getUsername(token);
         if (username == null) {
@@ -93,13 +103,7 @@ public class MyRealm extends AuthorizingRealm {
 //            throw new JwtAuthenticationException(5001, "User didn't existed!");
 //        }
 
-        // 这里redis的key是token, value是用户信息,所以只要有返回结果,就算是验证通过
-//        String redisToken = redisTemplate.opsForValue().get(token);
-//        if (redisToken == null) {
-//            log.error("redis token is null");
-//            throw new JwtAuthenticationException(5001, "redis token is null");
-//
-//        }
+
 
 
 //        if (! JwtUtil.isVerify(token, username)) {

+ 3 - 0
720yun_fd_manage/gis_domain/src/main/java/com/gis/domain/dto/FodderDto.java

@@ -3,6 +3,8 @@ package com.gis.domain.dto;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import javax.validation.constraints.Size;
+
 /**
  * Created by owen on 2021/2/23 0023 16:39
  */
@@ -12,6 +14,7 @@ public class FodderDto {
     @ApiModelProperty(value = "id, 修改时必须传,新增忽略", name = "id")
     private Long id;
 
+    @Size(max = 50, message = "长度不能大于50位")
     @ApiModelProperty(value = "名称")
     private String name;
 

+ 2 - 0
720yun_fd_manage/gis_domain/src/main/java/com/gis/domain/dto/FodderPageDto.java

@@ -12,4 +12,6 @@ public class FodderPageDto extends PageDto {
     @ApiModelProperty(value = "类型, 全景图:pano, 图片:image, 音频:audio, 视频:video")
     private String type;
 
+
+
 }

+ 1 - 38
720yun_fd_manage/gis_mapper/src/main/java/com/gis/mapper/SceneMapper.java

@@ -15,50 +15,13 @@ import java.util.List;
 public interface SceneMapper extends IBaseMapper<SceneEntity, Long> {
 
 
-
-    @Update("UPDATE tb_scene SET is_index=#{index}")
-    void setIndex(Integer index);
-
-
-
-    @Update("UPDATE tb_scene SET is_index=#{index} where id = #{id}")
-    void setIndexById(Long id, Integer index);
-
     @Select("select * from tb_scene where is_delete = 0 and scene_code = #{sceneCode}")
-    SceneEntity findBySceneCode(String sceneCode);
-
-    @Select("select * from tb_scene where is_delete = 0 and vr_model_id = #{vrModelId}")
-    SceneEntity findByVrModelId(String vrModelId);
-
-    @Select("select * from tb_scene where is_delete = 0 and vr_model_id = #{vrModelId}")
-    List<SceneEntity> findByVrModelId2(String vrModelId);
+    List<SceneEntity> findBySceneCode(String sceneCode);
 
-    @Select("select * from tb_scene where is_delete = 0 and vr_model_id = #{vrModelId} and house_id = #{houseId}")
-    SceneEntity findByVrModelIdAndHouseId(String vrModelId, String houseId);
-
-    @Select("select * from tb_scene where is_delete = 0 and is_index = 1 and create_user_id = #{userName} ")
-    List<SceneEntity> getIndex(String userName);
-
-    @Select("select * from tb_scene where is_delete = 0 and house_id = #{houseId}")
-    List<SceneEntity> findByHouseId(String houseId);
-
-    @Select("select * from tb_scene where is_delete = 0 and house_id = #{houseId} and type = #{type} order by sort asc, create_time asc ")
-    List<SceneEntity> findByHouseIdAndType(String houseId, String type);
 
     @Update("UPDATE tb_scene SET sort=#{sort} where id = #{id}")
     void setSortById(String id, String sort);
 
-    @Select("select scene_code from tb_scene where is_delete = 0 and status >= #{status} and type = #{type} and house_id = #{houseId}")
-    List<String> getVrSceneCode(String houseId, String status, String type);
-
-    @Update("UPDATE tb_scene SET is_delete = 1 where is_delete = 0 AND house_id = #{houseId}")
-    void houseRemove(String houseId);
-
-    @Update("UPDATE tb_scene SET status = #{status} where is_delete = 0 AND house_id = #{houseId}")
-    void houseAudit(String houseId, String status);
-
-    @Select("select * from tb_scene where is_delete = 0 and status = #{status} and house_id = #{houseId}")
-    List<SceneEntity> findByHouseIdAndStatus(String houseId, String status);
 
     /**
      * for update 锁表更新完,才能进行更新,需要开启事务

+ 2 - 2
720yun_fd_manage/gis_mapper/src/main/java/com/gis/mapper/provider/FodderProvider.java

@@ -28,7 +28,7 @@ public class FodderProvider {
             sql.append(" and ( type = '").append(type).append("' )");
         }
 
-        sql.append(" order by create_time asc");
+        sql.append(" order by create_time desc");
 
         log.info("sql: {}", sql.toString());
         return sql.toString();
@@ -54,7 +54,7 @@ public class FodderProvider {
             sql.append(" and ( name like '%").append(searchKey).append("%' )");
         }
 
-        sql.append(" order by create_time asc");
+        sql.append(" order by create_time desc");
 
         log.info("sql: {}", sql.toString());
         return sql.toString();

+ 1 - 1
720yun_fd_manage/gis_service/src/main/java/com/gis/service/SceneService.java

@@ -22,7 +22,7 @@ public interface SceneService extends IBaseService<SceneEntity, Long> {
 
     Result editXml(XmlDataDto param);
 
-    SceneEntity findBySceneCode(String sceneCode);
+    List<SceneEntity> findBySceneCode(String sceneCode);
 
     Result editSomeData(EditSomeDataDto param);
 

+ 2 - 2
720yun_fd_manage/gis_service/src/main/java/com/gis/service/impl/FodderServiceImpl.java

@@ -79,8 +79,8 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
         String time = DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS");
         String fileName = file.getOriginalFilename();
         String suffix = StringUtils.substringAfterLast(fileName, ".");
-        if (suffix.length() > 200) {
-            return Result.failure(3003, "文件名称不允许超过200个字节");
+        if (suffix.length() > 50) {
+            return Result.failure(3003, "文件名称不允许超过50个字节");
         }
         String newName = time  + "."  +suffix;
         String dirType = "fodder/";

+ 1 - 1
720yun_fd_manage/gis_service/src/main/java/com/gis/service/impl/SceneServiceImpl.java

@@ -384,7 +384,7 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
     }
 
     @Override
-    public SceneEntity findBySceneCode(String sceneCode) {
+    public List<SceneEntity> findBySceneCode(String sceneCode) {
         return entityMapper.findBySceneCode(sceneCode);
     }
 

+ 17 - 2
720yun_fd_manage/gis_web/src/main/java/com/gis/web/controller/FodderController.java

@@ -1,10 +1,12 @@
 package com.gis.web.controller;
 
 
+import com.gis.common.constant.MsgCode;
 import com.gis.common.util.Result;
 import com.gis.domain.dto.*;
 import com.gis.domain.entity.CatalogEntity;
 import com.gis.domain.entity.FodderEntity;
+import com.gis.domain.entity.SceneEntity;
 import com.gis.domain.entity.WorkEntity;
 import com.gis.service.FodderService;
 import com.gis.service.SceneService;
@@ -20,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.Date;
+import java.util.List;
 
 
 /**
@@ -29,12 +32,14 @@ import java.util.Date;
 @Api(tags = "我的素材")
 @RestController
 @RequestMapping("manage/fodder")
-//@RequestMapping("aa/fodder")
 public class FodderController extends BaseController {
 
     @Autowired
     private FodderService fodderService;
 
+    @Autowired
+    SceneService sceneService;
+
     @ApiOperation(value = "上传素材", notes = "type:类型, 全景图:pano, 图片:image, 音频:audio, 视频:video")
     @PostMapping("upload/{type}")
     public Result upload(MultipartFile file, @PathVariable String type) {
@@ -68,8 +73,18 @@ public class FodderController extends BaseController {
     public Result remove( @PathVariable Long id) {
         FodderEntity entity = fodderService.findById(id);
         if (entity == null) {
-            return Result.success();
+            return Result.failure("对象不存在, id: " + id);
         }
+
+        // 检查全景图是否被引用
+        if ("pano".equals(entity.getType())) {
+            List<SceneEntity> list = sceneService.findBySceneCode(entity.getSceneCode());
+            if (list.size() > 0) {
+                log.error("场景已使用,不能删除");
+                return Result.failure(MsgCode.e3001, MsgCode.m3001);
+            }
+        }
+
         entity.setIsDelete(1);
         entity.setUpdateTime(new Date());
         fodderService.update(entity);

+ 4 - 4
720yun_fd_manage/gis_web/src/main/java/com/gis/web/controller/SceneController.java

@@ -63,11 +63,11 @@ public class SceneController extends BaseController {
 
 
     @ApiOperation("场景详情")
-    @GetMapping("detail/{sceneCode}")
-    public Result detail(@PathVariable String sceneCode) {
-        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
+    @GetMapping("detail/{id}")
+    public Result detail(@PathVariable Long id) {
+        SceneEntity entity = sceneService.findById(id);
         if (entity == null) {
-            log.error("对象不存在, 场景码:{}", sceneCode);
+            log.error("对象不存在, 场景ID:{}", id);
             return Result.failure("对象不存在");
         }
         return Result.success(entity);

+ 27 - 0
720yun_fd_manage/gis_web/src/main/java/com/gis/web/controller/WebController.java

@@ -11,6 +11,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.*;
 
 
@@ -28,6 +29,10 @@ public class WebController extends BaseController {
     private CatalogService catalogService;
 
     @Autowired
+    private RedisTemplate<String, String> redisTemplate;
+
+
+    @Autowired
     WorkService workService;
 
     @ApiOperation(value = "作品列表", position = 1)
@@ -52,4 +57,26 @@ public class WebController extends BaseController {
         return Result.success(entity);
     }
 
+
+
+    @ApiOperation(value = "检查token是否有效" , position = 3)
+    @GetMapping("checkToken")
+    public Result checkToken() {
+        String token = getToken();
+        if (token == null) {
+            log.error("token is null");
+            return Result.failure(5001, "Token为空");
+        }
+
+        String redisKey = "token#"+ token;
+        String redisToken = redisTemplate.opsForValue().get(redisKey);
+        if (redisToken != null) {
+            return Result.success();
+        }
+
+        log.error("redis token is null");
+        return Result.failure(5001, "Token无效");
+
+    }
+
 }

+ 1 - 0
720yun_fd_manage/remark-m.md

@@ -43,6 +43,7 @@
 # sit 是用的四维看看测试服务器  
     web: https://test.4dkankan.com/panorama/material.html
     13112311178    11111111Aa
+    15015980188 Hao123456
     doc: http://120.25.146.52:8001/doc.html