Kaynağa Gözat

修复upPath 前缀问题

dsx 1 yıl önce
ebeveyn
işleme
1434e9fbd9

+ 62 - 62
src/main/java/com/fdkankan/scene/Interceptor/CheckViewBizAuthAspect.java

@@ -144,68 +144,68 @@ public class CheckViewBizAuthAspect {
 			}
 
 			//校验token
-//			if(!interruptCheck){
-//				log.info("num:{}", num);
-//				log.info("token:{}", request.getHeader("token"));
-//				String token = request.getHeader("token");
-//				if(StrUtil.isNotEmpty(token)){
-//					SSOUser user = jmgaSSOLoginHelper.getSsoUser(token);
-//					if(Objects.isNull(user)){
-//						throw new BusinessException(ErrorCode.AUTH_FAIL.code(), ErrorCode.TOKEN_NOT_FOUND.message());
-//					}
-//					JyUser jyUser = jyUserService.getBySysUserId(user.getId().intValue());
-//					log.info("user:{}", JSON.toJSONString(user));
-//					ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
-//					if(Objects.isNull(scenePlus)){
-//						throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
-//					}
-//					log.info("scenePlus:{}", scenePlus);
-//					if(Objects.isNull(scenePlus.getUserId()) || Objects.isNull(jyUser) || jyUser.getUserId() != scenePlus.getUserId().intValue()){
-//						throw new BusinessException(ErrorCode.AUTH_FAIL.code(), "无权访问");
-//					}else{
-//						interruptCheck = true;
-//						userName = user.getUserName();
-//					}
-//				}
-//
-//			}
-
-//			if(!interruptCheck){
-//				//查询场景是否业务授权
-//				JySceneAuth jySceneAuth = jySceneAuthService.getByNum(num);
-//				if(!Objects.isNull(jySceneAuth) && jySceneAuth.getAuthType() == 0){
-//					//业务授权校验用户名密码
-//					userName = (String) params.get("userName");
-//					String password = (String) params.get("password");
-//					if(StrUtil.isEmpty(userName) || StrUtil.isEmpty(password)){
-//						throw new BusinessException(ErrorCode.USERNAME_PASSWORD_REQUIRE);
-//					}
-//					//查询用户
-//					JyUser jyUser = jyUserService.getByJyNo(userName);
-//					if(Objects.isNull(jyUser)){
-//						throw new BusinessException(ErrorCode.PASSWORD_ERROR);
-//					}
-//					JySceneUserAuth jySceneUserAuth = jySceneUserAuthService.getSceneViewAuth(num, jyUser.getId());
-//					if(Objects.isNull(jySceneUserAuth)){
-//						throw new BusinessException(ErrorCode.AUTH_FAIL.code(), "无权访问");
-//					}
-//					if (jySceneUserAuth.getLookAuth() == 2 && jySceneUserAuth.getLookEndTime().before(Calendar.getInstance().getTime())){
-//						throw new BusinessException(ErrorCode.AUTH_FAIL.code(), "超出访问截止时间");
-//					}
-//
-//					//如果授权校验通过,校验密码是否正确
-//					User user = userService.findByUserName(userName);
-//					if(Objects.isNull(user)){
-//						throw new BusinessException(ErrorCode.PASSWORD_ERROR);
-//					}
-//					//模拟前端密码加密规则生成前端密码
-//					password = SecurityUtil.MD5(Base64Converter.decode(password));
-//					//数据库密码比对
-//					if(Objects.isNull(user) || !password.equals(user.getPassword())){
-//						throw new BusinessException(ErrorCode.PASSWORD_ERROR);
-//					}
-//				}
-//			}
+			if(!interruptCheck){
+				log.info("num:{}", num);
+				log.info("token:{}", request.getHeader("token"));
+				String token = request.getHeader("token");
+				if(StrUtil.isNotEmpty(token)){
+					SSOUser user = jmgaSSOLoginHelper.getSsoUser(token);
+					if(Objects.isNull(user)){
+						throw new BusinessException(ErrorCode.AUTH_FAIL.code(), ErrorCode.TOKEN_NOT_FOUND.message());
+					}
+					JyUser jyUser = jyUserService.getBySysUserId(user.getId().intValue());
+					log.info("user:{}", JSON.toJSONString(user));
+					ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
+					if(Objects.isNull(scenePlus)){
+						throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+					}
+					log.info("scenePlus:{}", scenePlus);
+					if(Objects.isNull(scenePlus.getUserId()) || Objects.isNull(jyUser) || jyUser.getUserId() != scenePlus.getUserId().intValue()){
+						throw new BusinessException(ErrorCode.AUTH_FAIL.code(), "无权访问");
+					}else{
+						interruptCheck = true;
+						userName = user.getUserName();
+					}
+				}
+
+			}
+
+			if(!interruptCheck){
+				//查询场景是否业务授权
+				JySceneAuth jySceneAuth = jySceneAuthService.getByNum(num);
+				if(!Objects.isNull(jySceneAuth) && jySceneAuth.getAuthType() == 0){
+					//业务授权校验用户名密码
+					userName = (String) params.get("userName");
+					String password = (String) params.get("password");
+					if(StrUtil.isEmpty(userName) || StrUtil.isEmpty(password)){
+						throw new BusinessException(ErrorCode.USERNAME_PASSWORD_REQUIRE);
+					}
+					//查询用户
+					JyUser jyUser = jyUserService.getByJyNo(userName);
+					if(Objects.isNull(jyUser)){
+						throw new BusinessException(ErrorCode.PASSWORD_ERROR);
+					}
+					JySceneUserAuth jySceneUserAuth = jySceneUserAuthService.getSceneViewAuth(num, jyUser.getId());
+					if(Objects.isNull(jySceneUserAuth)){
+						throw new BusinessException(ErrorCode.AUTH_FAIL.code(), "无权访问");
+					}
+					if (jySceneUserAuth.getLookAuth() == 2 && jySceneUserAuth.getLookEndTime().before(Calendar.getInstance().getTime())){
+						throw new BusinessException(ErrorCode.AUTH_FAIL.code(), "超出访问截止时间");
+					}
+
+					//如果授权校验通过,校验密码是否正确
+					User user = userService.findByUserName(userName);
+					if(Objects.isNull(user)){
+						throw new BusinessException(ErrorCode.PASSWORD_ERROR);
+					}
+					//模拟前端密码加密规则生成前端密码
+					password = SecurityUtil.MD5(Base64Converter.decode(password));
+					//数据库密码比对
+					if(Objects.isNull(user) || !password.equals(user.getPassword())){
+						throw new BusinessException(ErrorCode.PASSWORD_ERROR);
+					}
+				}
+			}
 		}catch (BusinessException e){
 			//写入日志
 			sysLog.setUserName(userName);

+ 85 - 75
src/main/java/com/fdkankan/scene/init/InitDataHandler.java

@@ -1,75 +1,85 @@
-//package com.fdkankan.scene.init;
-//
-//import cn.hutool.core.collection.CollUtil;
-//import com.alibaba.fastjson.JSON;
-//import com.alibaba.fastjson.JSONObject;
-//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-//import com.fdkankan.download.bean.DownLoadTaskBean;
-//import com.fdkankan.redis.constant.RedisKey;
-//import com.fdkankan.redis.constant.RedisLockKey;
-//import com.fdkankan.redis.util.RedisLockUtil;
-//import com.fdkankan.redis.util.RedisUtil;
-//import com.fdkankan.scene.entity.ScenePlus;
-//import com.fdkankan.scene.entity.ScenePlusExt;
-//import com.fdkankan.scene.service.IScenePlusExtService;
-//import com.fdkankan.scene.service.IScenePlusService;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.boot.CommandLineRunner;
-//import org.springframework.data.redis.core.RedisTemplate;
-//import org.springframework.stereotype.Component;
-//
-//import java.util.List;
-//import java.util.stream.Collectors;
-//
-///**
-// * <p>
-// * 应用启动校验是否有下载任务正在进行,如有过就重新入队头,从新下载
-// * </p>
-// *
-// * @author dengsixing
-// * @since 2022/2/22
-// **/
-//@Component
-//public class InitDataHandler implements CommandLineRunner {
-//
-//    @Autowired
-//    RedisUtil redisUtil;
-//    @Autowired
-//    RedisTemplate redisTemplate;
-//    @Autowired
-//    RedisLockUtil redisLockUtil;
-//    @Autowired
-//    private IScenePlusService scenePlusService;
-//    @Autowired
-//    private IScenePlusExtService scenePlusExtService;
-//
-//    @Override
-//    public void run(String... args) throws Exception {
-//
-//        List<ScenePlusExt> scenePlusExtList = scenePlusExtService.list(new LambdaQueryWrapper<ScenePlusExt>().like(ScenePlusExt::getVideos, "/oss/"));
-//        if(CollUtil.isNotEmpty(scenePlusExtList)){
-//            scenePlusExtList.stream().forEach(ext -> {
-//                ScenePlus scenePlus = scenePlusService.getById(ext.getPlusId());
-//
-//                JSONObject jsonObject = JSON.parseObject(ext.getVideos());
-//                String upPath = jsonObject.getString("upPath");
-//                jsonObject.put("upPath", upPath.replace("/oss/", ""));
-//
-//                String key = String.format(RedisKey.SCENE_JSON, scenePlus.getNum());
-//                String sceneJsonStr = redisUtil.get(key);
-//                JSONObject sceneJsonObj = JSON.parseObject(sceneJsonStr);
-//                sceneJsonObj.getJSONObject()
-//
-//
-//            });
-//
-//
-//
-//        }
-//
-//
-//    }
-//
-//
-//
-//}
+package com.fdkankan.scene.init;
+
+import cn.hutool.core.collection.CollUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
+import com.fdkankan.model.constants.UploadFilePath;
+import com.fdkankan.redis.constant.RedisKey;
+import com.fdkankan.redis.util.RedisLockUtil;
+import com.fdkankan.redis.util.RedisUtil;
+import com.fdkankan.scene.entity.ScenePlus;
+import com.fdkankan.scene.entity.ScenePlusExt;
+import com.fdkankan.scene.service.IScenePlusExtService;
+import com.fdkankan.scene.service.IScenePlusService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+/**
+ * <p>
+ * 应用启动校验是否有下载任务正在进行,如有过就重新入队头,从新下载
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/2/22
+ **/
+@Component
+public class InitDataHandler implements CommandLineRunner {
+
+    @Autowired
+    RedisUtil redisUtil;
+    @Autowired
+    RedisTemplate redisTemplate;
+    @Autowired
+    RedisLockUtil redisLockUtil;
+    @Autowired
+    private IScenePlusService scenePlusService;
+    @Autowired
+    private IScenePlusExtService scenePlusExtService;
+    @Resource
+    private FYunFileServiceInterface fYunFileService;
+
+    @Override
+    public void run(String... args) throws Exception {
+
+        List<ScenePlusExt> scenePlusExtList = scenePlusExtService.list(new LambdaQueryWrapper<ScenePlusExt>().like(ScenePlusExt::getVideos, "/oss/"));
+        if(CollUtil.isNotEmpty(scenePlusExtList)){
+            scenePlusExtList.stream().forEach(ext -> {
+                ScenePlus scenePlus = scenePlusService.getById(ext.getPlusId());
+
+                //修改数据库
+                JSONObject jsonObject = JSON.parseObject(ext.getVideos());
+                String upPath = jsonObject.getString("upPath");
+                jsonObject.put("upPath", upPath.replace("/oss/", ""));
+                ext.setVideos(jsonObject.toJSONString());
+                scenePlusExtService.updateById(ext);
+
+                //修改redis缓存
+                String key = String.format(RedisKey.SCENE_JSON, scenePlus.getNum());
+                String sceneJsonStr = redisUtil.get(key);
+                JSONObject sceneJsonObj = JSON.parseObject(sceneJsonStr);
+                sceneJsonObj.put("videos", jsonObject.toJSONString());
+                redisUtil.set(key, sceneJsonObj.toJSONString());
+
+                //修改scene.json
+                String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, scenePlus.getNum()).concat("scene.json");
+                fYunFileService.uploadFile(sceneJsonObj.toJSONString().getBytes(StandardCharsets.UTF_8), sceneJsonPath);
+            });
+
+
+
+        }
+
+
+    }
+
+
+
+}