1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273 |
- 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;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2024-10-09
- */
- @DS("vr")
- @Service
- public class SceneEditInfoServiceImpl extends ServiceImpl<SceneEditInfoMapper, SceneEditInfo> 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<SceneEditInfo>()
- .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<String> 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<Scene> sceneList = sceneService.listByStationcode(sceneInfo.getStationCode());
- List<Map<String, String>> roomList = new ArrayList<>();
- for (Scene scene : sceneList) {
- if(scene.getNum().equals(sceneInfo.getNum())){
- continue;
- }
- Map<String, String> 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;
- }
- /**
- * <p>
- 编辑页面获取场景详情信息
- * </p>
- * @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<Scene>().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<SceneFileMapping> sceneFileMappings = sceneFileMappingService.list(
- new LambdaQueryWrapper<SceneFileMapping>()
- .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<SceneEditInfo> updateWrapper = new LambdaUpdateWrapper<SceneEditInfo>()
- .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<SceneEditInfo> updateWrapper = new LambdaUpdateWrapper<SceneEditInfo>()
- .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<Integer, String> 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<SceneEditInfo>()
- .setSql(SQL_ADD_VERSION + 1)
- .eq(SceneEditInfo::getId, id));
- }
- @Override
- public void upgradeVersionAndImgVersionById(Long id) {
- this.update(new LambdaUpdateWrapper<SceneEditInfo>()
- .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<String> 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<SceneFileMapping> sceneFileMappings = sceneFileMappingService.getByScene(num, subgroup, upTime);
- // List<SceneFileMapping> panList = sceneFileMappings.stream().filter(v -> v.getKey().contains("images/pan/high/")).collect(Collectors.toList());
- // Map<String, SceneFileMapping> panMap = panList.stream().collect(Collectors.toMap(v -> FileUtil.getName(v.getKey()), v -> v));
- // List<String> panoramaImageList = panList.stream().map(v -> FileUtil.getName(v.getKey())).collect(Collectors.toList());
- //
- // List<String> 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<String, String> 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<String> finalUploadFileList = uploadFileList;
- // List<String> 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<String, Object> 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<String> uploadFileList, String targetImagesPath) throws Exception {
- //
- // Map<String, String> 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<String> 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<SceneFileMapping> sceneFileMappings = sceneFileMappingService.getByScene(num, subgroup, upTimeKey);
- // List<SceneFileMapping> panList = sceneFileMappings.stream().filter(v -> v.getKey().contains("images/pan/high/")).collect(Collectors.toList());
- // Map<String, SceneFileMapping> panMap = panList.stream().collect(Collectors.toMap(v -> FileUtil.getName(v.getKey()), v -> v));
- //
- //// List<String> panoramaImageList = panList.stream().map(v -> FileUtil.getName(v.getKey())).collect(Collectors.toList());
- //
- // Map<String, Object> 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<String, String> allTagsMap = redisClient.hmget(key);
- boolean hashTags = false;
- for (Map.Entry<String, String> 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<String, String> 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<String, String> 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<JSONObject> tags = Lists.newArrayList();
- result.put("tags", tags);
- // //封装styles数据
- List<JSONObject> 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<JSONObject> 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<String, String> 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<String> 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<String> list = redisClient.lGet(key, 0, -1);
- List<JSONObject> 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<String> deleteVidoeFile = new HashSet<>();
- Set<String> deletePicFile = new HashSet<>();
- if(boxVideosJson.size() == 0)
- return null;
- for(int i=0;i<boxVideosJson.size();++i){
- JSONObject ele = boxVideosJson.getJSONObject(i);
- if(ele.getString("sid").equals(sid)){
- String poster = ele.getString("poster");
- if(StrUtil.isNotEmpty(poster))
- deletePicFile.add(poster);
- String url = ele.getString("url");
- if(StrUtil.isNotEmpty(url)){
- deleteVidoeFile.add(url);
- deleteVidoeFile.add(url.replace(".mp4",".flv"));
- }
- boxVideosJson.remove(i);
- }
- }
- }else{
- boxVideo.put(ConstantField.CREATE_TIME, Calendar.getInstance().getTimeInMillis());
- //更新
- boolean exist = false;
- for(int i=0;i<boxVideosJson.size();++i){
- JSONObject ele = boxVideosJson.getJSONObject(i);
- if(ele.getString("sid").equals(sid)){
- boxVideosJson.set(i, boxVideo);
- exist = true;
- }
- }
- //新增
- if(!exist){
- boxVideosJson.add(boxVideo);
- }
- boxVideosJson.clear();
- boxVideosJson.add(boxVideo);
- }
- if(boxVideosJson.size() != 0){
- result = boxVideosJson.toJSONString();
- }
- return result;
- }
- private void updateBoxVideos(SceneEditInfo sceneEditInfo, Long scenePlusId, String boxVideos){
- if(Objects.isNull(sceneEditInfo)){
- sceneEditInfo = new SceneEditInfo();
- sceneEditInfo.setScenePlusId(scenePlusId);
- sceneEditInfo.setBoxVideos(boxVideos);
- this.save(sceneEditInfo);
- }else{
- this.update(new UpdateWrapper<SceneEditInfo>()
- .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<SceneEditInfo>()
- .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<String> deleteFile = new HashSet<>();
- if(boxPhotosJson.size() == 0)
- return null;
- for(int i=0;i<boxPhotosJson.size();++i){
- JSONObject ele = boxPhotosJson.getJSONObject(i);
- if(ele.getString("sid").equals(sid)){
- String poster = ele.getString("poster");
- if(StrUtil.isNotEmpty(poster))
- deleteFile.add(poster);
- String url = ele.getString("url");
- if(StrUtil.isNotEmpty(url))
- deleteFile.add(url);
- boxPhotosJson.remove(i);
- }
- }
- }else{
- //更新
- boolean exist = false;
- for(int i=0;i<boxPhotosJson.size();++i){
- JSONObject ele = boxPhotosJson.getJSONObject(i);
- if(ele.getString("sid").equals(sid)){
- boxPhoto.put(ConstantField.CREATE_TIME, ele.getLong(ConstantField.CREATE_TIME));
- boxPhotosJson.set(i, boxPhoto);
- exist = true;
- }
- }
- //新增
- if(!exist){
- boxPhoto.put(ConstantField.CREATE_TIME, Calendar.getInstance().getTimeInMillis());
- boxPhotosJson.add(boxPhoto);
- }
- }
- if(boxPhotosJson.size() != 0){
- List<BoxPhotoBean> 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;
- }
- }
|