package com.fdkankan.manage.httpClient.service; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.fdkankan.fyun.face.FYunFileServiceInterface; import com.fdkankan.manage.common.OssPath; import com.fdkankan.manage.common.ResultCode; import com.fdkankan.manage.common.ResultData; import com.fdkankan.manage.common.ZipFileReaderUtil; import com.fdkankan.manage.config.ManageConfig; import com.fdkankan.manage.entity.JyUser; import com.fdkankan.manage.entity.ScenePlus; import com.fdkankan.manage.entity.ScenePlusExt; import com.fdkankan.manage.exception.BusinessException; import com.fdkankan.manage.httpClient.client.FdKKClient; import com.fdkankan.manage.httpClient.param.UploadSceneOrigParamVo; import com.fdkankan.manage.service.IJyUserService; import com.fdkankan.manage.service.IScenePlusExtService; import com.fdkankan.manage.service.IScenePlusService; import com.fdkankan.manage.vo.request.UploadSceneCheckVo; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.List; @Service @Slf4j public class FdkkService { @Autowired FdKKClient fdKKClient; @Autowired IJyUserService jyUserService; @Autowired ManageConfig manageConfig; @Autowired FYunFileServiceInterface fYunFileServiceInterface; @Autowired IScenePlusExtService scenePlusExtService; @Autowired IScenePlusService scenePlusService; public void uploadSceneOrig(UploadSceneOrigParamVo paramVo){ try { paramVo.setFilePath(paramVo.getFilePath().replace(manageConfig.getQueryPath(),"")); JyUser jyUser = jyUserService.getBySysId(StpUtil.getLoginId()); paramVo.setUserId(jyUser.getUserId()); ResultData resultData = fdKKClient.uploadSceneOrig(paramVo, StpUtil.getTokenValue()); if(resultData.getCode() != 0){ throw new BusinessException(resultData.getCode(),resultData.getMessage()); } }catch (Exception e){ log.info("uploadSceneOrig:{}",e); throw new BusinessException(ResultCode.UPLOAD_ERROR); } } public UploadSceneCheckVo uploadSceneCheck(UploadSceneOrigParamVo paramVo) { try { JyUser loginUser = jyUserService.getBySysId(StpUtil.getLoginId()); String zipPath = paramVo.getFilePath().replace(manageConfig.getQueryPath(),manageConfig.getQueryPath() + "4dkankan/"); String content = ZipFileReaderUtil.readUtf8(zipPath, "data.fdage"); JSONObject jsonObject = JSONObject.parseObject(content); String uuidtime = jsonObject.getString("uuidtime"); List exts = scenePlusExtService.getLikeDataSource(uuidtime); if(exts == null || exts.isEmpty()){ return new UploadSceneCheckVo(0,""); } for (ScenePlusExt ext : exts) { ScenePlus scenePlus = scenePlusService.getById(ext.getPlusId()); if(scenePlus != null && scenePlus.getUserId() != null){ JyUser jyUser = jyUserService.getByUserId(scenePlus.getUserId()); if(jyUser != null && !jyUser.getId().equals(loginUser.getId())){ return new UploadSceneCheckVo(ResultCode.UPLOAD_SCENE_ERROR.code(),jyUser.getRyNo()); } if(jyUser != null){ return new UploadSceneCheckVo(ResultCode.UPLOAD_SCENE_ERROR2.code(),ResultCode.UPLOAD_SCENE_ERROR2.message()); } } } }catch (Exception e){ log.info("upload-scene-error:{}",e); } throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR); } public UploadSceneCheckVo checkUploadSceneOffline(String zipPath) { try { zipPath = zipPath.replace(manageConfig.getQueryPath(),manageConfig.getQueryPath() + "4dkankan/"); String sceneJsonStr = ZipFileReaderUtil.readUtf8(zipPath, "scene.json"); if(StrUtil.isEmpty(sceneJsonStr) || !JSONUtil.isJson(sceneJsonStr)){ throw new BusinessException(ResultCode.UPLOAD_SCENE_ERROR3); } JSONObject jsonObject = JSON.parseObject(sceneJsonStr); //校验版本 String offlineVersion = jsonObject.getString("offlineVersion"); String platformVersion = manageConfig.getPlatformVersion();//从数据中获取 if (offlineVersion == null || platformVersion == null) { return new UploadSceneCheckVo(ResultCode.UPLOAD_SCENE_ERROR4); } String[] offParts = offlineVersion.split("\\."); String[] pfParts = platformVersion.split("\\."); // 至少需要两位版本号 if (offParts.length < 2 || pfParts.length < 2) { return new UploadSceneCheckVo(ResultCode.UPLOAD_SCENE_ERROR4); } // 比较前两位 if (!offParts[0].equals(pfParts[0]) || !offParts[1].equals(pfParts[1])) { return new UploadSceneCheckVo(ResultCode.UPLOAD_SCENE_ERROR4); } // 前两位一致,检查第三位 if (Integer.parseInt(offParts[2]) < Integer.parseInt((pfParts[2]))) { return new UploadSceneCheckVo(ResultCode.UPLOAD_SCENE_ERROR5); } if (Integer.parseInt(offParts[2]) > Integer.parseInt((pfParts[2]))) { return new UploadSceneCheckVo(ResultCode.UPLOAD_SCENE_ERROR4); } String num = jsonObject.getString("num"); ScenePlus scenePlus = scenePlusService.getByNum(num); if(scenePlus != null){ throw new BusinessException(ResultCode.UPLOAD_SCENE_ERROR2); } return new UploadSceneCheckVo(0,""); }catch (BusinessException e){ throw e; }catch (Exception e){ log.info("upload-scene-error:{}",e); } throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR); } }