package com.fdkankan.scene.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.img.ImgUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.ZipUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fdkankan.common.constant.*; import com.fdkankan.common.exception.BusinessException; import com.fdkankan.common.util.FileUtils; import com.fdkankan.redis.constant.RedisKey; import com.fdkankan.redis.util.RedisClient; import com.fdkankan.scene.bean.BoxPhotoBean; import com.fdkankan.scene.bean.ResultData; import com.fdkankan.scene.bean.SceneJsonBean; import com.fdkankan.scene.bean.TagBean; import com.fdkankan.scene.entity.*; import com.fdkankan.scene.httpclient.CustomHttpClient; import com.fdkankan.scene.mapper.SceneEditInfoMapper; import com.fdkankan.scene.service.*; import com.fdkankan.scene.vo.*; import com.google.common.collect.Lists; import org.owasp.esapi.errors.EncodingException; import org.owasp.esapi.errors.ValidationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; /** *

* 服务实现类 *

* * @author * @since 2024-10-09 */ @DS("vr") @Service public class SceneEditInfoServiceImpl extends ServiceImpl implements SceneEditInfoService { private final static String SQL_ADD_VERSION = "version=version+"; @Value("${tieta.device-address:#{null}}") private String deviceAddress; // @Autowired private SceneEditControlsService sceneEditControlsService; @Resource private FYunFileService fYunFileService; @Resource private RedisClient redisClient; @Autowired private SceneEditInfoExtService sceneEditInfoExtService; @Autowired private SceneService sceneService; @Autowired private SceneFileMappingService sceneFileMappingService; @Resource CustomHttpClient customHttpClient; @Autowired private SceneAsynOperLogService sceneAsynOperLogService; @Autowired private ICommonService commonService; /** * 保存场景基础设置 * @param param * @return com.fdkankan.scene.vo.SceneEditInfoVO */ @Transactional @Override public SceneEditInfoVO saveScene(SceneEditInfoParamVO param) { //查询场景主表 Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); //场景不存在返回业务异常:场景为空 if(Objects.isNull(scenePlus)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId()); SceneEditControls sceneEditControlsDb = null; if(Objects.nonNull(sceneEditInfoDb)){ sceneEditControlsDb = sceneEditControlsService.getBySceneEditId(sceneEditInfoDb.getId()); } //用户上传的文件后缀名转小写 this.lowercaseExtName(param); SceneEditInfo sceneEditInfo = BeanUtil.copyProperties(param, SceneEditInfo.class); sceneEditInfo.setScenePlusId(scenePlus.getId()); //编辑数据表记录,有则更新,无则插入 if(Objects.isNull(sceneEditInfoDb)){ this.save(sceneEditInfo); }else{ sceneEditInfo.setId(sceneEditInfoDb.getId()); sceneEditInfo.setVersion(sceneEditInfoDb.getVersion() + 1); this.updateById(sceneEditInfo); } SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId()); if(Objects.isNull(sceneEditInfoExt)){ sceneEditInfoExt = new SceneEditInfoExt(); sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId()); sceneEditInfoExt.setScenePlusId(scenePlus.getId()); } if(Objects.nonNull(param.getSns())){ sceneEditInfoExt.setSnsInfo(JSON.toJSONString(param.getSns())); } if(Objects.nonNull(param.getStarted())){ sceneEditInfoExt.setStarted(JSON.toJSONString(param.getStarted())); } //更新场景编辑信息扩展表 sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt); if(Objects.nonNull(param.getControls())){ SceneEditControls sceneEditControls = BeanUtil.copyProperties(param.getControls(), SceneEditControls.class); sceneEditControls.setEditInfoId(sceneEditInfo.getId()); if(Objects.isNull(sceneEditControlsDb)){ sceneEditControlsService.save(sceneEditControls); }else{ sceneEditControls.setId(sceneEditControlsDb.getId()); sceneEditControlsService.updateById(sceneEditControls); } } scenePlus.setTitle(param.getTitle()); scenePlus.setDescription(param.getDescription()); //更新场景表 sceneService.updateById(scenePlus); SceneEditInfoVO result = BeanUtil.copyProperties(param, SceneEditInfoVO.class); result.setCreateTime(sceneEditInfo.getCreateTime()); return result; } private void lowercaseExtName(SceneEditInfoParamVO sceneEditInfo){ if(StrUtil.isNotEmpty(sceneEditInfo.getMusic())){ String extName = cn.hutool.core.io.FileUtil.extName(sceneEditInfo.getMusic()); if(StrUtil.isNotEmpty(extName)){ sceneEditInfo.setMusic(sceneEditInfo.getMusic().replace(extName, extName.toLowerCase())); } } if(StrUtil.isNotEmpty(sceneEditInfo.getMusicFile())){ String extName = cn.hutool.core.io.FileUtil.extName(sceneEditInfo.getMusicFile()); if(StrUtil.isNotEmpty(extName)){ sceneEditInfo.setMusicFile(sceneEditInfo.getMusicFile().replace(extName, extName.toLowerCase())); } } } @Override public SceneEditInfo getByScenePlusId(long scenePlusId) { return this.getOne(new LambdaQueryWrapper() .eq(SceneEditInfo::getScenePlusId, scenePlusId)); } private void publicFilterData(String num, Integer subgroup, String upTime, Integer cacheKeyHasTime, int filters) throws IOException, EncodingException, ValidationException { String userEditPath = String.format(UploadFilePath.USER_VIEW_PATH, num); String fileKey = userEditPath + "filter.json"; if(filters == CommonStatus.NO.code()){ sceneFileMappingService.delByNumAndKey(num, subgroup, upTime, fileKey); return; } String key = String.format(RedisKey.SCENE_filter_DATA, RedisKey.getNumStr(num, subgroup, upTime, cacheKeyHasTime)); List list = redisClient.lGet(key, 0, -1); JSONArray jsonArray = new JSONArray(); list.stream().forEach(str->jsonArray.add(JSON.parseObject(str))); fYunFileService.uploadFile(num, subgroup, upTime, JSON.toJSONBytes(jsonArray), userEditPath + "filter.json"); } @Override public SceneInfoVO getSceneInfo(String num, Integer subgroup, String upTimeKey, byte reqType) throws Exception{ SceneInfoReqType sceneInfoReqType = SceneInfoReqType.get(reqType); if(Objects.isNull(subgroup)){ subgroup = 0; } SceneInfoVO sceneInfo = null; switch (sceneInfoReqType){ //如果是编辑页面请求,查数据库 case EDIT: sceneInfo = this.getSceneInfo4Edit(num, subgroup, upTimeKey); //俊波要求这两个字段编辑页一定是1 sceneInfo.getControls().setShowDollhouse(CommonStatus.YES.code()); sceneInfo.getControls().setShowFloorplan(CommonStatus.YES.code()); break; //如果是查看页面请求,查redis case VIEW: sceneInfo = this.getSceneInfo4Edit(num, subgroup, upTimeKey); sceneInfo.setScenePassword(null); //俊波要求这两个字段查看页一定是0 sceneInfo.getControls().setShowDollhouse(CommonStatus.NO.code()); sceneInfo.getControls().setShowFloorplan(CommonStatus.NO.code()); //查询机房列表 List sceneList = sceneService.listByStationcode(sceneInfo.getStationCode()); List> roomList = new ArrayList<>(); for (Scene scene : sceneList) { if(scene.getNum().equals(sceneInfo.getNum())){ continue; } Map item = new HashMap<>(); item.put("stationCode", scene.getStationcode()); item.put("roomEntityID", scene.getNum()); item.put("title", scene.getTitle()); roomList.add(item); } sceneInfo.setEntityList(roomList); //查询历史列表 sceneInfo.setHistoryList(sceneService.listByNumLast3(sceneInfo.getNum())); break; default: break; } sceneInfo.setDeviceAddress(deviceAddress); return sceneInfo; } /** *

编辑页面获取场景详情信息 *

* @author dengsixing * @date 2022/1/21 * @param num * @return com.fdkankan.scene.vo.SceneInfoVO **/ private SceneInfoVO getSceneInfo4Edit(String num, Integer subgroup, String upTime) throws Exception{ Scene scenePlus = sceneService.getByNum(num, subgroup, upTime); if(Objects.isNull(scenePlus)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } upTime = scenePlus.getUpTimeKey(); SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId()); if(Objects.isNull(sceneEditInfo)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId()); SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId()); SceneInfoVO sceneInfoVO = new SceneInfoVO(); BeanUtil.copyProperties(sceneEditInfoExt, sceneInfoVO, "started"); BeanUtil.copyProperties(sceneEditInfo, sceneInfoVO); sceneInfoVO.setFloorPlanUpload(JSON.parseArray(sceneEditInfo.getFloorPlanUpload())); if(Objects.isNull(sceneInfoVO.getFloorPlanAngle())){ sceneInfoVO.setFloorPlanAngle(0f); } if(Objects.isNull(sceneInfoVO.getFloorPlanCompass())){ sceneInfoVO.setFloorPlanCompass(0f); } sceneInfoVO.setControls(BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class)); sceneInfoVO.setNum(num); sceneInfoVO.setSceneResolution(scenePlus.getSceneresolution()); sceneInfoVO.setSceneFrom(scenePlus.getScenefrom()); sceneInfoVO.setSceneKind(scenePlus.getScenekind()); sceneInfoVO.setModelKind(scenePlus.getModelkind()); if(CommonStatus.YES.code().intValue() == sceneEditInfoExt.getMosaic()){ sceneInfoVO.setMosaicList(this.getMosaicList(num, subgroup, upTime)); } sceneInfoVO.setSns(JSON.parseObject(sceneEditInfoExt.getSnsInfo())); sceneInfoVO.setStarted(JSON.parseObject(sceneEditInfoExt.getStarted())); sceneInfoVO.setSubgroup(scenePlus.getSubgroup()); sceneInfoVO.setStationCode(scenePlus.getStationcode()); sceneInfoVO.setExtinguisher(scenePlus.getExtinguisher()); long count = sceneService.count(new LambdaQueryWrapper().eq(Scene::getNum, num).eq(Scene::getUpTimeKey, upTime).ne(Scene::getSubgroup, 0)); if(count > 0){ sceneInfoVO.setHasHighAndLow(CommonStatus.YES.code()); }else{ sceneInfoVO.setHasHighAndLow(CommonStatus.NO.code()); } //读取全的vision.txt String visionTxtKey = String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.txt"; List sceneFileMappings = sceneFileMappingService.list( new LambdaQueryWrapper() .eq(SceneFileMapping::getNum, num) .eq(SceneFileMapping::getUpTime, upTime) .eq(SceneFileMapping::getKey, visionTxtKey) .eq(SceneFileMapping::getSubgroup, -1)); SceneFileMapping sceneFileMapping = null; if(CollUtil.isNotEmpty(sceneFileMappings)){ sceneFileMapping = sceneFileMappings.get(0); String content = null; try (InputStream inputStream = customHttpClient.downloadFileToInputStream(sceneFileMapping.getUrl())){ content = IoUtil.read(inputStream, StandardCharsets.UTF_8); } if(StrUtil.isNotEmpty(content)){ sceneInfoVO.setVisions(JSON.parseObject(content)); } } sceneInfoVO.setShootTime(scenePlus.getShootTime()); sceneInfoVO.setUpTime(scenePlus.getUpTime()); sceneInfoVO.setAlgorithmTime(scenePlus.getAlgorithmTime()); sceneInfoVO.setId(scenePlus.getId()); sceneInfoVO.setUpTimeKey(scenePlus.getUpTimeKey()); return sceneInfoVO; } @Override public ResultData saveCad(BaseDataParamVO param) throws Exception { String num = param.getNum(); Scene scenePlus = sceneService.getByNum(num, param.getSubgroup(),param.getUpTimeKey()); if(Objects.isNull(scenePlus)) throw new BusinessException(ErrorCode.FAILURE_CODE_5005); String editUserPath = String.format(UploadFilePath.USER_VIEW_PATH, num); JSONObject fileInfoJson = JSON.parseObject(param.getData()); Float angel = null; Float compass = null; String floorJsonData = fileInfoJson.getString("floorJsonData"); if(StrUtil.isNotBlank(floorJsonData)){ JSONObject jsonObject = JSON.parseObject(floorJsonData); angel = jsonObject.getFloat("angle"); compass = jsonObject.getFloat("compass"); } //处理户型图数据 //上传floorplan_user.json文件 fYunFileService.uploadFile(num, param.getSubgroup(), param.getUpTimeKey(), floorJsonData.getBytes(StandardCharsets.UTF_8), editUserPath + "floorplan.json"); //写入数据库 Integer floorPlanUser = null; if(StrUtil.isNotEmpty(floorJsonData)){ floorPlanUser = CommonStatus.YES.code(); } SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId()); if(Objects.nonNull(sceneEditInfoDb)){ LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() .setSql(SQL_ADD_VERSION + 1) .eq(SceneEditInfo::getId, sceneEditInfoDb.getId()); if(floorPlanUser != null){ updateWrapper.set(SceneEditInfo::getFloorPlanUser, floorPlanUser); } this.update(updateWrapper); }else{ sceneEditInfoDb = new SceneEditInfo(); sceneEditInfoDb.setScenePlusId(scenePlus.getId()); sceneEditInfoDb.setFloorPlanUser(floorPlanUser); this.save(sceneEditInfoDb); } SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoDb.getId()); if(Objects.isNull(sceneEditInfoExt)){ sceneEditInfoExt = new SceneEditInfoExt(); sceneEditInfoExt.setEditInfoId(sceneEditInfoDb.getId()); } if(Objects.nonNull(angel)){ sceneEditInfoExt.setFloorPlanAngle(angel); } if(Objects.nonNull(compass)){ sceneEditInfoExt.setFloorPlanCompass(compass); } sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt); return ResultData.ok(); } @Override public ResultData resetCad(String num, Integer subgroup, String upTime) throws IOException { Scene scenePlus = sceneService.getByNum(num, subgroup, upTime); if(Objects.isNull(scenePlus)) throw new BusinessException(ErrorCode.FAILURE_CODE_5005); SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId()); SceneEditInfoExt sceneEditInfoExt = null; if(Objects.nonNull(sceneEditInfoDb)){ LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() .setSql(SQL_ADD_VERSION + 1) .set(SceneEditInfo::getFloorPlanUser, CommonStatus.NO.code()) .eq(SceneEditInfo::getId, sceneEditInfoDb.getId()); this.update(updateWrapper); sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoDb.getId()); }else{ sceneEditInfoDb = new SceneEditInfo(); sceneEditInfoDb.setScenePlusId(scenePlus.getId()); sceneEditInfoDb.setFloorPlanUser(CommonStatus.NO.code()); this.save(sceneEditInfoDb); } if(Objects.isNull(sceneEditInfoExt)){ sceneEditInfoExt = new SceneEditInfoExt(); sceneEditInfoDb.setScenePlusId(scenePlus.getId()); sceneEditInfoExt.setEditInfoId(sceneEditInfoDb.getId()); } sceneEditInfoExt.setFloorPlanAngle(0f); sceneEditInfoExt.setFloorPlanCompass(0f); sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt); return ResultData.ok(); } @Override public ResultData renameCad(RenameCadParamVO param) throws IOException, EncodingException, ValidationException { Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); if(Objects.isNull(scenePlus)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } String key = String.format(UploadFilePath.USER_VIEW_PATH, param.getNum()) + "floorplan.json"; String floorplanJson = fYunFileService.getFileContent(key, param.getSubgroup(), param.getUpTimeKey()); if(StrUtil.isEmpty(floorplanJson)){ return ResultData.ok(); } Map renameMap = new HashMap<>(); param.getFloors().stream().forEach(floor->{ renameMap.put(floor.getSubgroup(), floor.getName()); }); JSONObject jsonObject = JSON.parseObject(floorplanJson); if(Objects.isNull(jsonObject)){ return ResultData.ok(); } JSONArray floorArr = jsonObject.getJSONArray("floors"); if(CollUtil.isEmpty(floorArr)){ return ResultData.ok(); } for (Object o : floorArr) { JSONObject item = (JSONObject)o; int subgroup = item.getIntValue("subgroup"); String name = renameMap.get(subgroup); if(StrUtil.isEmpty(name)){ continue; } item.put("name", name); } fYunFileService.uploadFile(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), jsonObject.toJSONString().getBytes(), key); return ResultData.ok(); } @Override public void upgradeVersionById(Long id) { this.update(new LambdaUpdateWrapper() .setSql(SQL_ADD_VERSION + 1) .eq(SceneEditInfo::getId, id)); } @Override public void upgradeVersionAndImgVersionById(Long id) { this.update(new LambdaUpdateWrapper() .setSql("version=version + " + 1) .setSql("img_version=img_version + " + 1) .eq(SceneEditInfo::getId, id)); } @Override public void upgradeSceneJsonVersion(String num, Integer subgroup, String upTime, Integer cacheKeyHasTime, int version, Integer imgVersion) throws IOException, EncodingException, ValidationException { //更新redis缓存版本号 String key = String.format(RedisKey.SCENE_JSON, RedisKey.getNumStr(num, subgroup, upTime, cacheKeyHasTime)); String sceneJson = redisClient.get(key); if(StrUtil.isNotEmpty(sceneJson)){ SceneJsonBean sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class); if(Objects.nonNull(version)){ sceneJsonBean.setVersion(version); } if(Objects.nonNull(imgVersion)){ sceneJsonBean.setImgVersion(imgVersion); } redisClient.add(key, JSON.toJSONString(sceneJsonBean)); } //更新oss scene.json版本号 String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json"; sceneJson= fYunFileService.getFileContent(sceneJsonPath, subgroup, upTime); if(StrUtil.isNotEmpty(sceneJson)){ SceneJsonBean sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class); if(Objects.nonNull(version)){ sceneJsonBean.setVersion(version); } if(Objects.nonNull(imgVersion)){ sceneJsonBean.setImgVersion(imgVersion); } fYunFileService.uploadFile(num, subgroup, upTime, JSON.toJSONString(sceneJsonBean).getBytes(StandardCharsets.UTF_8), sceneJsonPath); } } // @Override // public ResultData uploadPanorama(String num, Integer subgroup, String upTime, MultipartFile file) throws Exception { // // if(!file.getOriginalFilename().endsWith(".zip") && !file.getOriginalFilename().endsWith(".jpg")){ // throw new BusinessException(ErrorCode.FAILURE_CODE_7007, "jpg或者zip"); // } // // Scene scenePlus = sceneService.getByNum(num, subgroup, upTime); // if(scenePlus == null){ // throw new BusinessException(ErrorCode.FAILURE_CODE_5005); // } // // //查询是否存在等待中的异步操作记录,如果存在,抛出业务异常,终止操作 // sceneAsynOperLogService.checkSceneAsynOper(scenePlus.getId(), null, SceneAsynModuleType.UPLOAD_DOWNLOAD.code() , SceneAsynFuncType.PANORAMIC_IMAGE.code()); // // //清除全景图异步操作记录,防止再次下载的时候请求到旧的压缩包 // sceneAsynOperLogService.cleanLog(scenePlus.getId(), SceneAsynModuleType.UPLOAD_DOWNLOAD.code(), SceneAsynFuncType.PANORAMIC_IMAGE.code()); // // //原始计算根目录 // String numStr = RedisKey.getNumStr(num, subgroup, upTime, scenePlus.getCacheKeyHasTime()); // String path = String.format(ConstantFilePath.SCENE_USER_PATH_V4, numStr); // //全景图计算根目录 // String target = path + "_images"; // //解压缩文件存放目录 // String targetImagesPath = target + "/extras/images/"; // //压缩文件保存目录 // String zipTargetFilePath = targetImagesPath + file.getOriginalFilename(); // // //先删除本地文件 // FileUtil.del(targetImagesPath); // File targetFile = new File(zipTargetFilePath); // if(!targetFile.getParentFile().exists()){ // targetFile.getParentFile().mkdirs(); // } // file.transferTo(targetFile); // // //如果是压缩包上传,需要解压缩 // int async = CommonStatus.NO.code(); // if(file.getOriginalFilename().endsWith(".zip")){ // // //标记为异步处理 // async = CommonStatus.YES.code(); // // //解压zip包 // ZipUtil.unzip(zipTargetFilePath,targetImagesPath, CharsetUtil.CHARSET_GBK); // //删除压缩包 // FileUtil.del(zipTargetFilePath); // } // // //判断文件夹目录结构,图片必须放在压缩包根目录下,不支持空文件夹或其他格式文件上传 // File[] files = new File(targetImagesPath).listFiles(); // Arrays.stream(files).forEach(item->{ // if(item.isDirectory()){ // throw new BusinessException(ErrorCode.FAILURE_CODE_7018); // } // }); // // //获取解压后的文件列表 // List uploadFileList = FileUtils.getFileList(targetImagesPath); // if(CollUtil.isEmpty(uploadFileList)){ // throw new BusinessException(ErrorCode.FAILURE_CODE_5062); // } // // //判断是否有可用的jpg文件 // boolean existJpg = false; // if(CollUtil.isNotEmpty(uploadFileList)){ // existJpg = uploadFileList.stream().anyMatch(str -> { // if(str.endsWith(".jpg")){ // return true; // } // return false; // }); // } // if(!existJpg){ // throw new BusinessException(ErrorCode.FAILURE_CODE_5062); // } // // //比对图片列表,不存在的要返回名称集合 // List sceneFileMappings = sceneFileMappingService.getByScene(num, subgroup, upTime); // List panList = sceneFileMappings.stream().filter(v -> v.getKey().contains("images/pan/high/")).collect(Collectors.toList()); // Map panMap = panList.stream().collect(Collectors.toMap(v -> FileUtil.getName(v.getKey()), v -> v)); // List panoramaImageList = panList.stream().map(v -> FileUtil.getName(v.getKey())).collect(Collectors.toList()); // // List notExistFileList = uploadFileList.stream().filter(filePath -> { // filePath = filePath.substring(filePath.lastIndexOf(File.separator) + 1); // if(CollUtil.isEmpty(panoramaImageList) || panoramaImageList.contains(filePath)){ // return false; // } // return true; // }).collect(Collectors.toList()); // // if(CollUtil.isNotEmpty(notExistFileList)){ // //删除错误文件 // notExistFileList.parallelStream().forEach(filePath->{ // FileUtil.del(filePath); // }); // } // // //判断成功的图片,如果成功图片为0,就直接返回,不需要执行算法 // uploadFileList = FileUtils.getFileList(targetImagesPath); // if(CollUtil.isEmpty(uploadFileList)){ // if(CollUtil.isNotEmpty(notExistFileList)){ // notExistFileList = notExistFileList.stream().map(filePath -> { // return filePath.substring(filePath.lastIndexOf(File.separator) + 1); // }).collect(Collectors.toList()); // } // return ResultData.ok(new UploadPanoramaVO(0,0, notExistFileList)); // } // // //上传 // Map map = new HashMap<>(); // // String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num); // // //如果部分成功,则需要返回成功数量和失败列表 // if(CollUtil.isNotEmpty(notExistFileList)){ // notExistFileList = notExistFileList.stream().map(filePath -> { // return filePath.substring(filePath.lastIndexOf(File.separator) + 1); // }).collect(Collectors.toList()); // } // // UploadPanoramaVO uploadPanoramaVO = new UploadPanoramaVO(); // uploadPanoramaVO.setAsyn(async); // if(async == CommonStatus.YES.code().intValue()){ // List finalUploadFileList = uploadFileList; // List finalNotExistFileList = notExistFileList; // CompletableFuture.runAsync(() -> { // SceneAsynOperLog sceneAsynOperLog = new SceneAsynOperLog(); // sceneAsynOperLog.setNum(num); // sceneAsynOperLog.setOperType(SceneAsynOperType.UPLOAD.code()); // sceneAsynOperLog.setModule(SceneAsynModuleType.UPLOAD_DOWNLOAD.code()); // sceneAsynOperLog.setFunc(SceneAsynFuncType.PANORAMIC_IMAGE.code()); // if(CollUtil.isNotEmpty(finalNotExistFileList)){ // Map extData = new HashMap<>(); // extData.put("successCnt", finalUploadFileList.size()); // extData.put("failList", finalNotExistFileList); // sceneAsynOperLog.setExtData(JSON.toJSONString(extData)); // } // sceneAsynOperLogService.save(sceneAsynOperLog); // try { // this.uploadPanoramaHandler(num,subgroup,upTime,target,imgViewPath, finalUploadFileList,targetImagesPath); // sceneAsynOperLog.setState(CommonOperStatus.SUCCESS.code()); // } catch (Exception e) { // log.error("上传全景图报错,num:" + num, e); // sceneAsynOperLog.setState(CommonOperStatus.FAILD.code()); // } // sceneAsynOperLogService.updateById(sceneAsynOperLog); // }); // }else{ // this.uploadPanoramaHandler(num,subgroup,upTime,target,imgViewPath,uploadFileList,targetImagesPath); // if(CollUtil.isNotEmpty(notExistFileList)){ // uploadPanoramaVO.setSuccessCnt(uploadFileList.size()); // uploadPanoramaVO.setFailList(notExistFileList); // } // } // // FileUtil.del(target); // return ResultData.ok(uploadPanoramaVO); // } // // public void uploadPanoramaHandler(String num, Integer subgroup, String upTime, String target, String imgViewPath, List uploadFileList, String targetImagesPath) throws Exception { // // Map map = new HashMap<>(); // String resultPath = target + File.separator + "results/"; // FileUtil.mkdir(resultPath); // // //4K // String highPath = resultPath + "pan/high/"; // //512 // String lowPath = resultPath + "pan/low/"; // List origImgs = FileUtil.listFileNames(targetImagesPath); // for (String origImg : origImgs) { // FileUtil.copy(targetImagesPath + origImg, highPath + origImg, true); // map.put(highPath + origImg, imgViewPath + "pan/high/" + origImg); // ImgUtil.scale(new File(highPath + origImg), new File(lowPath + origImg), 0.125f); // map.put(lowPath + origImg, imgViewPath + "pan/low/" + origImg); // } // // if(map.size()>0) { // fYunFileService.uploadMulFiles(num, subgroup, upTime, map); // } // // //更新数据库版本号 // Scene scenePlus = sceneService.getByNum(num, subgroup, upTime); // SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId()); // this.upgradeVersionAndImgVersionById(sceneEditInfo.getId()); // //更新scenejson缓存和oss文件版本号 // this.upgradeSceneJsonVersion(num, subgroup, upTime, scenePlus.getCacheKeyHasTime(), sceneEditInfo.getVersion() + 1, sceneEditInfo.getImgVersion() + 1); // } // // @Override // public ResultData downloadPanorama(FileParamVO param) throws Exception { // // String num = param.getNum(); // Integer subgroup = param.getSubgroup(); // String upTimeKey = param.getUpTimeKey(); // String fileName = param.getFileName(); // // Scene scenePlus = sceneService.getByNum(num, subgroup, upTimeKey); // if(Objects.isNull(scenePlus)){ // throw new BusinessException(ErrorCode.FAILURE_CODE_5005); // } // // //查询是否存在等待中的异步操作记录,如果存在,抛出业务异常,终止操作 // sceneAsynOperLogService.checkSceneAsynOper(scenePlus.getId(),null, SceneAsynModuleType.UPLOAD_DOWNLOAD.code() , SceneAsynFuncType.PANORAMIC_IMAGE.code()); // // String numStr = RedisKey.getNumStr(num, subgroup, upTimeKey, scenePlus.getCacheKeyHasTime()); // String cachePath = String.format(ConstantFilePath.SCENE_CACHE, numStr); // String localImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, numStr); // // String cacheFormat = "downloads/scene/%s/caches/"; // String cacheImageFormat = "downloads/scene/%s/caches/images/"; // // List sceneFileMappings = sceneFileMappingService.getByScene(num, subgroup, upTimeKey); // List panList = sceneFileMappings.stream().filter(v -> v.getKey().contains("images/pan/high/")).collect(Collectors.toList()); // Map panMap = panList.stream().collect(Collectors.toMap(v -> FileUtil.getName(v.getKey()), v -> v)); // //// List panoramaImageList = panList.stream().map(v -> FileUtil.getName(v.getKey())).collect(Collectors.toList()); // // Map map = new HashMap<>(); // // //标记是否是异步操作,默认是同步操作 // //如果入参文件名不为空,则是单个文件下载,不需要打包 // if(StrUtil.isNotEmpty(fileName)){ // if(!panMap.keySet().contains(fileName)){ // throw new BusinessException(ErrorCode.FAILURE_CODE_5063); // } // String url = panMap.get(fileName).getKey(); // String downloadName = fileName; // map.put("asyn", CommonStatus.NO.code()); // map.put("fileUrl", url); // map.put("fileName", downloadName); // return ResultData.ok(map); // }else{ // //清除旧的下载记录 // sceneAsynOperLogService.cleanLog(scenePlus.getId(), SceneAsynModuleType.UPLOAD_DOWNLOAD.code(), SceneAsynFuncType.PANORAMIC_IMAGE.code(), SceneAsynOperType.DOWNLOAD.code()); // // //开始异步执行下载全景图压缩包操作 // CompletableFuture.runAsync(() -> { // SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId()); // SceneAsynOperLog sceneAsynOperLog = new SceneAsynOperLog(); // sceneAsynOperLog.setNum(num); // sceneAsynOperLog.setSceneId(scenePlus.getId()); // sceneAsynOperLog.setOperType(SceneAsynOperType.DOWNLOAD.code()); // sceneAsynOperLog.setModule(SceneAsynModuleType.UPLOAD_DOWNLOAD.code()); // sceneAsynOperLog.setFunc(SceneAsynFuncType.PANORAMIC_IMAGE.code()); // sceneAsynOperLog.setVersion(sceneEditInfo.getImgVersion()); // sceneAsynOperLogService.save(sceneAsynOperLog); // try { // // //下载到本地目录 // FileUtil.del(localImagesPath); // for (SceneFileMapping sceneFileMapping : panList) { // customHttpClient.downloadFile(sceneFileMapping.getUrl(), localImagesPath, fileName); // // } // // String downloadName = num + "_images.zip"; // //打包 // String zipPath = cachePath + downloadName; // ZipUtil.zip(localImagesPath, zipPath); // //上传压缩包 // fYunFileService.uploadFile(num, subgroup,upTimeKey,zipPath, String.format(cacheFormat, num) + downloadName); // String url = String.format(cacheFormat, num) + downloadName; // //删除本地压缩包 // FileUtil.del(zipPath); // //删除本地目录 // FileUtil.del(localImagesPath); // sceneAsynOperLog.setState(CommonOperStatus.SUCCESS.code()); // sceneAsynOperLog.setUrl(url); // }catch (Exception e){ // sceneAsynOperLog.setState(CommonOperStatus.FAILD.code()); // log.error("下载全景图压缩包失败,num:" + num, e); // } // sceneAsynOperLogService.saveOrUpdate(sceneAsynOperLog); // }); // // map.put("asyn", CommonStatus.YES.code()); // return ResultData.ok(map); // } // } @Override public void saveTagsToSceneEditInfo(String num, Integer subgroup, String upTime, Integer cacheKeyHasTime, SceneEditInfo sceneEditInfo){ //查询缓存是否包含热点数据 String key = String.format(RedisKey.SCENE_HOT_DATA, RedisKey.getNumStr(num, subgroup, upTime, cacheKeyHasTime)); Map allTagsMap = redisClient.hmget(key); boolean hashTags = false; for (Map.Entry tagMap : allTagsMap.entrySet()) { if(StrUtil.isEmpty(tagMap.getValue())){ continue; } hashTags = true; break; } //更改热点状态 sceneEditInfo.setTags(hashTags ? CommonStatus.YES.code() : CommonStatus.NO.code()); //version 是空的代表 sceneEditInfo记录集不存在 if(sceneEditInfo.getVersion() != null){ sceneEditInfo.setVersion(sceneEditInfo.getVersion() + 1); } } @Override public ResultData checkKey(SceneCheckKeyParamVO param) throws Exception { Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); if(Objects.isNull(scenePlus)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId()); if(!param.getPassword().equals(sceneEditInfo.getScenePassword())){ throw new BusinessException(ErrorCode.FAILURE_CODE_5021); } return ResultData.ok(); } @Override public ResultData addMosaics(BaseDataParamVO param) throws Exception { Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); if(Objects.isNull(scenePlus)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId()); Map map = new HashMap<>(); JSONArray jsonArray = JSON.parseArray(param.getData()); for (Object o : jsonArray) { JSONObject mosaic = (JSONObject) o; String panoId = mosaic.getString("panoId"); if(StrUtil.isEmpty(panoId)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5012); } map.put(panoId, JSON.toJSONString(mosaic)); } String key = String.format(RedisKey.SCENE_MOSAIC_DATA, RedisKey.getNumStr(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime())); redisClient.hmset(key, map); //更新数据库 this.updateMosaicFlag(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime()); //更新版本号 this.upgradeVersionById(sceneEditInfo.getId()); return ResultData.ok(); } private void updateMosaicFlag(String num, Integer subgroup, String upTime, Integer cacheKeyHasTime){ Scene scenePlus = sceneService.getByNum(num, subgroup, upTime); SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByScenePlusId(scenePlus.getId()); String key = String.format(RedisKey.SCENE_MOSAIC_DATA, RedisKey.getNumStr(num, subgroup, upTime, cacheKeyHasTime)); Map hmget = redisClient.hmget(key); if(CollUtil.isNotEmpty(hmget)){ sceneEditInfoExt.setMosaic(CommonStatus.YES.code()); }else{ sceneEditInfoExt.setMosaic(CommonStatus.NO.code()); } sceneEditInfoExtService.updateById(sceneEditInfoExt); } @Override public ResultData listLinkPan(String num, Integer subgroup, String upTime) throws Exception { JSONObject result = new JSONObject(); // //查询场景关联数据 List tags = Lists.newArrayList(); result.put("tags", tags); // //封装styles数据 List styles = Lists.newArrayList(); result.put("styles", styles); return ResultData.ok(result); } @Override public ResultData deleteMosaics(DeleteMosaicParamVO param) throws Exception { Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); if(Objects.isNull(scenePlus)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId()); String key = String.format(RedisKey.SCENE_MOSAIC_DATA, RedisKey.getNumStr(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime())); redisClient.hdel(key, param.getPanoIdList()); //更新数据库 this.updateMosaicFlag(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime()); //更新版本号 this.upgradeVersionById(sceneEditInfo.getId()); return ResultData.ok(); } @Override public List getMosaicList(String num, Integer subgroup, String upTime) throws Exception { Scene scene = sceneService.getByNum(num, subgroup, upTime); if(Objects.isNull(scene)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } String key = String.format(RedisKey.SCENE_MOSAIC_DATA, RedisKey.getNumStr(num, subgroup, upTime, scene.getCacheKeyHasTime())); Map map = redisClient.hmget(key); if(CollUtil.isEmpty(map)){ ResultData.ok(new String[0]); } return map.values().stream() .map(mosaic-> JSON.parseObject(mosaic)) .collect(Collectors.toList()); } @Override public ResultData addWaterMark(BaseFileParamVO param) throws Exception { Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); if(Objects.isNull(scenePlus)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService .getByScenePlusId(scenePlus.getId()); sceneEditInfoExt.setWaterMark(param.getFileName()); sceneEditInfoExtService.updateById(sceneEditInfoExt); return ResultData.ok(); } @Override public ResultData deleteWaterMark(BaseFileParamVO param) throws Exception { Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); if(Objects.isNull(scenePlus)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } String key = String.format(UploadFilePath.USER_VIEW_PATH, param.getNum()) + param.getFileName(); fYunFileService.deleteFile(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), key); SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByScenePlusId(scenePlus.getId()); sceneEditInfoExt.setWaterMark(""); sceneEditInfoExtService.updateById(sceneEditInfoExt); return ResultData.ok(); } @Override public ResultData saveFilter(SaveFiltersParamVO param) throws Exception { Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); if(Objects.isNull(scenePlus)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } String key = String.format(RedisKey.SCENE_filter_DATA, RedisKey.getNumStr(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime())); //前端将全量数据传过来,所以这里先清空历史数据,然后保存前端数据即可 redisClient.del(key); JSONArray filterArr = JSON.parseArray(param.getData()); int filters = CommonStatus.YES.code(); //如果页面选择恢复默认,filters字段值为否 if(Objects.nonNull(param.getReset()) && param.getReset() == CommonStatus.YES.code().intValue()){ filters = CommonStatus.NO.code(); }else{ if(CollUtil.isNotEmpty(filterArr)){ List filterList = filterArr.stream().map(v->JSON.toJSONString(v)).collect(Collectors.toList()); redisClient.lLeftPush(key, filterList); }else{ filters = CommonStatus.NO.code(); } } //更新数据库 SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByScenePlusId(scenePlus.getId()); sceneEditInfoExt.setFilters(filters); sceneEditInfoExtService.updateById(sceneEditInfoExt); //更新版本号 this.upgradeVersionById(sceneEditInfoExt.getEditInfoId()); this.publicFilterData(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime(), filters); return ResultData.ok(); } @Override public ResultData listFilter(BaseSceneParamVO param) throws Exception { Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); if(Objects.isNull(scenePlus)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } //查询redis String key = String.format(RedisKey.SCENE_filter_DATA, RedisKey.getNumStr(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime())); List list = redisClient.lGet(key, 0, -1); List collect = list.stream().map(str -> JSON.parseObject(str)).collect(Collectors.toList()); return ResultData.ok(collect); } @Override public ResultData saveVideoBox(FileNameAndDataParamVO param) throws Exception { JSONObject boxVideo = JSONObject.parseObject(param.getData()); String sid = boxVideo.getString("sid"); if(StrUtil.isEmpty(sid)){ throw new BusinessException(ErrorCode.PARAM_REQUIRED); } Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); if(Objects.isNull(scenePlus)) throw new BusinessException(ErrorCode.FAILURE_CODE_5005); SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId()); //转换视频格式 commonService.transferToFlv(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime(), param.getFileName()); //生成boxVideos数据 String boxVideos = this.createBoxVideos(sid, boxVideo, sceneEditInfo, OperationType.ADDORUPDATE.code()); //更新数据库 this.updateBoxVideos(sceneEditInfo, scenePlus.getId(), boxVideos); return ResultData.ok(); } @Override public ResultData deleteVideoBox(DeleteSidParamVO param) throws Exception { Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); if(Objects.isNull(scenePlus)) throw new BusinessException(ErrorCode.FAILURE_CODE_5005); SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId()); //根据sid移除json String boxVideos = this.createBoxVideos(param.getSid(), null, sceneEditInfo, OperationType.DELETE.code()); //写数据库 this.updateBoxVideos(sceneEditInfo,scenePlus.getId(),boxVideos); return ResultData.ok(); } private String createBoxVideos(String sid, JSONObject boxVideo, SceneEditInfo sceneEditInfo, int type) throws Exception{ String boxVideos = null; if(sceneEditInfo != null){ boxVideos = sceneEditInfo.getBoxVideos(); } JSONArray boxVideosJson = null; if (StrUtil.isNotEmpty(boxVideos)) { boxVideosJson = JSONArray.parseArray(boxVideos); }else { boxVideosJson = new JSONArray(); } if(boxVideosJson.size() > 0){ int i = 1; long timeInMillis = Calendar.getInstance().getTimeInMillis(); for (Object o : boxVideosJson) { JSONObject item = (JSONObject)o; if(Objects.nonNull(item.getLong(ConstantField.CREATE_TIME))){ continue; } item.put(ConstantField.CREATE_TIME, timeInMillis - (i++)); } } String result = null; //删除 if(type == OperationType.DELETE.code()){ Set deleteVidoeFile = new HashSet<>(); Set deletePicFile = new HashSet<>(); if(boxVideosJson.size() == 0) return null; for(int i=0;i() .setSql("version = version + 1") .set("box_videos", boxVideos) .eq("id", sceneEditInfo.getId())); } } @Override public ResultData saveBoxPhoto(BaseDataParamVO param) throws Exception { JSONObject boxPhoto = JSONObject.parseObject(param.getData()); String sid = boxPhoto.getString("sid"); if(StrUtil.isEmpty(sid)){ throw new BusinessException(ErrorCode.PARAM_REQUIRED, sid); } Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); if(Objects.isNull(scenePlus)) throw new BusinessException(ErrorCode.FAILURE_CODE_5005); SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId()); //生成boxVideos数据 String boxPhotos = this.createBoxPhotos(sid, boxPhoto, sceneEditInfo, OperationType.ADDORUPDATE.code()); //更新数据库 this.updateBoxPhotos(sceneEditInfo, boxPhotos); return ResultData.ok(); } @Override public ResultData deleteBoxPhoto(DeleteSidParamVO param) throws Exception { Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey()); if(Objects.isNull(scenePlus)) throw new BusinessException(ErrorCode.FAILURE_CODE_5005); SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId()); //根据sid移除json String boxPhotos = this.createBoxPhotos(param.getSid(), null, sceneEditInfo, OperationType.DELETE.code()); //写数据库 this.updateBoxPhotos(sceneEditInfo, boxPhotos); return ResultData.ok(); } private void updateBoxPhotos(SceneEditInfo sceneEditInfo, String boxPhotos){ this.update(new LambdaUpdateWrapper() .set(SceneEditInfo::getBoxPhotos, boxPhotos) .setSql("version = version + 1") .eq(SceneEditInfo::getId, sceneEditInfo.getId())); } private String createBoxPhotos(String sid, JSONObject boxPhoto, SceneEditInfo sceneEditInfo, int type) throws Exception{ String boxPhotos = null; if(sceneEditInfo != null){ boxPhotos = sceneEditInfo.getBoxPhotos(); } JSONArray boxPhotosJson = null; if (StrUtil.isNotEmpty(boxPhotos)) { boxPhotosJson = JSONArray.parseArray(boxPhotos); }else { boxPhotosJson = new JSONArray(); } String result = null; //删除 if(type == OperationType.DELETE.code()){ Set deleteFile = new HashSet<>(); if(boxPhotosJson.size() == 0) return null; for(int i=0;i list = Lists.newArrayList(); for (Object o : boxPhotosJson) { JSONObject jsonObject = (JSONObject)o; list.add(BoxPhotoBean.builder().createTime(jsonObject.getLong(ConstantField.CREATE_TIME)).boxPhoto(jsonObject).build()); } //按创建时间倒叙排序 list.sort(Comparator.comparingLong(BoxPhotoBean::getCreateTime).reversed()); // list转JSONArray JSONArray array = new JSONArray(); list.stream().forEach(bean->{ array.add(bean.getBoxPhoto()); }); result = array.toJSONString(); } return result; } }