SceneProServiceImpl.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. package com.fdkankan.manage.service.impl;
  2. import cn.hutool.core.io.FileUtil;
  3. import cn.hutool.json.JSONUtil;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  7. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  8. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  9. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  10. import com.fdkankan.common.constant.SceneConstant;
  11. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  12. import com.fdkankan.manage.common.*;
  13. import com.fdkankan.manage.exception.BusinessException;
  14. import com.fdkankan.common.util.*;
  15. import com.fdkankan.manage.httpClient.client.FdKKClient;
  16. import com.fdkankan.manage.httpClient.service.LaserService;
  17. import com.fdkankan.manage.entity.*;
  18. import com.fdkankan.manage.mapper.ISceneProMapper;
  19. import com.fdkankan.manage.service.*;
  20. import com.fdkankan.manage.util.Dateutils;
  21. import com.fdkankan.manage.util.SceneStatusUtil;
  22. import com.fdkankan.manage.vo.request.SceneParam;
  23. import com.fdkankan.manage.vo.response.CameraDataVo;
  24. import com.fdkankan.manage.vo.response.GroupByCount;
  25. import com.fdkankan.manage.vo.response.SceneVo;
  26. import lombok.extern.slf4j.Slf4j;
  27. import org.apache.commons.lang3.StringUtils;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.beans.factory.annotation.Value;
  30. import org.springframework.stereotype.Service;
  31. import org.springframework.util.ObjectUtils;
  32. import javax.annotation.Resource;
  33. import java.io.File;
  34. import java.util.*;
  35. import java.util.concurrent.CompletableFuture;
  36. import java.util.stream.Collectors;
  37. /**
  38. * <p>
  39. * pro场景表 服务实现类
  40. * </p>
  41. *
  42. * @author
  43. * @since 2022-06-16
  44. */
  45. @Service
  46. @Slf4j
  47. public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
  48. @Autowired
  49. private ICameraService cameraService;
  50. @Autowired
  51. ICameraDetailService cameraDetailService;
  52. @Autowired
  53. ISceneService sceneService;
  54. @Autowired
  55. ISceneCopyLogService copyLogService;
  56. @Autowired
  57. IUserIncrementService userIncrementService;
  58. @Autowired
  59. IIncrementTypeService incrementTypeService;
  60. @Autowired
  61. ISceneProEditService sceneProEditService;
  62. @Autowired
  63. FYunFileServiceInterface fYunFileServiceInterface;
  64. @Autowired
  65. IScenePlusService scenePlusService;
  66. @Autowired
  67. IScene3dNumService scene3dNumService;
  68. @Autowired
  69. ISceneCopyLogService sceneCopyLogService;
  70. @Autowired
  71. IScenePlusExtService scenePlusExtService;
  72. @Autowired
  73. LaserService laserService;
  74. @Autowired
  75. FdKKClient fdKKClient;
  76. @Autowired
  77. IFolderSceneService folderSceneService;
  78. @Autowired
  79. ISceneBuildProcessLogService sceneBuildProcessLogService;
  80. @Override
  81. public ScenePro getByNum(String num) {
  82. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  83. wrapper.eq(ScenePro::getNum,num);
  84. wrapper.eq(ScenePro::getIsUpgrade,0);
  85. List<ScenePro> list = this.list(wrapper);
  86. if(list == null || list.size() <=0){
  87. return null;
  88. }
  89. return list.get(0);
  90. }
  91. @Override
  92. public HashMap<Long, Long> getCountGroupByUserId(List<Long> userIdList,Integer isObj) {
  93. HashMap<Long,Long> map = new HashMap<>();
  94. List<GroupByCount> result = this.getBaseMapper().getCountGroupByUserId(userIdList,isObj);
  95. result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
  96. return map;
  97. }
  98. @Override
  99. public HashMap<Long, Long> getCountGroupByCameraId(List<Long> cameraIds) {
  100. HashMap<Long,Long> map = new HashMap<>();
  101. List<GroupByCount> result = this.getBaseMapper().getCountGroupByCameraId(cameraIds);
  102. result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
  103. return map;
  104. }
  105. @Override
  106. public void unbindCamera(Long cameraId) {
  107. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  108. wrapper.set(ScenePro::getUserId,null)
  109. .eq(ScenePro::getCameraId,cameraId);
  110. wrapper.eq(ScenePro::getIsUpgrade,0);
  111. this.update(wrapper);
  112. }
  113. @Override
  114. public List<ScenePro> getListByCameraId(Long cameraId) {
  115. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  116. wrapper.eq(ScenePro::getCameraId,cameraId);
  117. wrapper.eq(ScenePro::getIsUpgrade,0);
  118. return this.list(wrapper);
  119. }
  120. /**
  121. * @param payStatus -2 封存,为 1 解封
  122. */
  123. @Override
  124. public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId, Integer payStatus) {
  125. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  126. LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
  127. Long totalSpace = cameraDetail.getTotalSpace();
  128. UserIncrement userIncrement = userIncrementService.getByCameraId(cameraId);
  129. if(userIncrement!=null){
  130. IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
  131. if(incrementType!=null){
  132. if(incrementType.getCameraCapacity() == -1){
  133. totalSpace = -1L;
  134. }else {
  135. totalSpace = incrementType.getCameraCapacity() * 1024* 1024 * 1024L;
  136. }
  137. }
  138. }
  139. log.info("lockOrUnLockBySpace---cameraId:{},payStatus:{},totalSpace:{},useSpace{}",
  140. cameraId,payStatus,totalSpace,cameraDetail.getUsedSpace());
  141. if(payStatus == 1){ //解封,判断用户权益,用户会员权益无限容量
  142. wrapper.orderByAsc(ScenePro::getCreateTime);
  143. plusWr.orderByAsc(ScenePlus::getCreateTime);
  144. wrapper.eq(ScenePro::getPayStatus,-2);
  145. plusWr.eq(ScenePlus::getPayStatus,-2);
  146. }else {
  147. if (totalSpace == -1 || totalSpace >= cameraDetail.getUsedSpace()) {
  148. // 总容量大于已使用容量,不予封存
  149. return;
  150. }
  151. wrapper.orderByDesc(ScenePro::getCreateTime);
  152. plusWr.orderByDesc(ScenePlus::getCreateTime);
  153. wrapper.eq(ScenePro::getPayStatus,1);
  154. plusWr.eq(ScenePlus::getPayStatus,1);
  155. }
  156. wrapper.eq(ScenePro::getCameraId,cameraId)
  157. .eq(ScenePro::getIsUpgrade,0);
  158. plusWr.eq(ScenePlus::getCameraId,cameraId);
  159. List<ScenePro> list = this.list(wrapper);
  160. List<ScenePlus> plusList = scenePlusService.list(plusWr);
  161. List<Long> lockedIds = new ArrayList<>();
  162. if(totalSpace == -1 && payStatus == 1){
  163. List<Long> collect = list.stream().map(ScenePro::getId).collect(Collectors.toList());
  164. List<Long> collect2 = plusList.stream().map(ScenePlus::getId).collect(Collectors.toList());
  165. lockedIds.addAll(collect);
  166. lockedIds.addAll(collect2);
  167. lockOrUnLockScenes(lockedIds,payStatus); // 无限容量 全部解封
  168. return;
  169. }
  170. Long beyondSpace = 0L;
  171. Long accumulateSpace = 0L;
  172. if(payStatus == 1){
  173. beyondSpace = totalSpace - cameraDetail.getTotalSpace();
  174. getScenePlusLockedIds(lockedIds, plusList, beyondSpace, accumulateSpace);
  175. getSceneLockedIds(lockedIds,list,beyondSpace,accumulateSpace);
  176. }else {
  177. beyondSpace = cameraDetail.getUsedSpace() - totalSpace;
  178. getSceneLockedIds(lockedIds, list, beyondSpace, accumulateSpace);
  179. getScenePlusLockedIds(lockedIds,plusList,beyondSpace,accumulateSpace);
  180. }
  181. lockOrUnLockScenes(lockedIds,payStatus);
  182. }
  183. @Override
  184. public void lockOrUnLockBySpace(ScenePro scenePro, ScenePlus scenePlus,Integer payStatus) {
  185. List<Long> lockedIds = new ArrayList<>();
  186. if(scenePro!= null){
  187. lockedIds.add(scenePro.getId());
  188. }
  189. if(scenePlus!= null){
  190. lockedIds.add(scenePlus.getId());
  191. }
  192. lockOrUnLockScenes(lockedIds,payStatus); // 无限容量 全部解封
  193. }
  194. private void getSceneLockedIds(List<Long> lockedIds , List<ScenePro> list, Long beyondSpace, Long accumulateSpace){
  195. if (list != null && list.size() > 0){
  196. for (ScenePro scenePro : list){
  197. accumulateSpace += scenePro.getSpace();
  198. if (accumulateSpace.compareTo(beyondSpace) > 0){
  199. break;
  200. }
  201. lockedIds.add(scenePro.getId());
  202. }
  203. }
  204. }
  205. private void getScenePlusLockedIds(List<Long> lockedIds , List<ScenePlus> list, Long beyondSpace, Long accumulateSpace){
  206. if (list != null && list.size() > 0){
  207. List<Long> plusIds = list.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
  208. HashMap<Long, ScenePlusExt> byPlusIds = scenePlusExtService.getByPlusIds(plusIds);
  209. for (ScenePlus scenePlus : list){
  210. ScenePlusExt scenePlusExt = byPlusIds.get(scenePlus.getId());
  211. accumulateSpace += scenePlusExt.getSpace();
  212. if (accumulateSpace.compareTo(beyondSpace) > 0){
  213. break;
  214. }
  215. lockedIds.add(scenePlus.getId());
  216. }
  217. }
  218. }
  219. // payStatus 为 -2 封存,为 1 解封
  220. private void lockOrUnLockScenes(List<Long> lockedIds,Integer payStatus) {
  221. if (lockedIds == null || lockedIds.size() == 0){
  222. return;
  223. }
  224. LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<>();
  225. updateWrapper.set(ScenePro::getPayStatus,payStatus)
  226. .eq(ScenePro::getIsUpgrade,0)
  227. .in(ScenePro::getId,lockedIds);
  228. this.update(updateWrapper);
  229. LambdaUpdateWrapper<ScenePlus> updatePlusWrapper = new LambdaUpdateWrapper<>();
  230. updatePlusWrapper.set(ScenePlus::getPayStatus,payStatus)
  231. .in(ScenePlus::getId,lockedIds);
  232. scenePlusService.update(updatePlusWrapper);
  233. this.updateOssStatus(lockedIds,payStatus);
  234. }
  235. /**
  236. * 修改oss status.json中 payStatus
  237. */
  238. private void updateOssStatus(List<Long> lockedIds, Integer payStatus) {
  239. LambdaQueryWrapper<ScenePro> proWr = new LambdaQueryWrapper<>();
  240. proWr.eq(ScenePro::getIsUpgrade,0);
  241. proWr.in(ScenePro::getId,lockedIds);
  242. List<ScenePro> proList = this.list(proWr);
  243. LambdaQueryWrapper<ScenePlus> pluWr = new LambdaQueryWrapper<>();
  244. pluWr.in(ScenePlus::getId,lockedIds);
  245. List<ScenePlus> plusList = scenePlusService.list(pluWr);
  246. for (ScenePro scenePro : proList) {
  247. this.updateOssStatus(String.format(OssPath.v3_statusPath,scenePro.getNum()),payStatus);
  248. }
  249. for (ScenePlus scenePlus : plusList) {
  250. this.updateOssStatus(String.format(OssPath.v4_statusPath,scenePlus.getNum()),payStatus);
  251. }
  252. }
  253. /**
  254. * 从oss中获取文件,并重写,上传替换
  255. */
  256. private void updateOssStatus(String path,Integer payStatus) {
  257. String localPath = String.format(OssPath.localStatusPath, path);
  258. try {
  259. if(!fYunFileServiceInterface.fileExist(path)){
  260. return;
  261. }
  262. String data = fYunFileServiceInterface.getFileContent("4dkankan",path);
  263. if(StringUtils.isBlank(data)){
  264. return;
  265. }
  266. JSONObject jsonObject = JSONObject.parseObject(data);
  267. jsonObject.put("payStatus",payStatus);
  268. String json = JSONUtil.toJsonStr(jsonObject);
  269. FileUtils.writeFile(localPath,json);
  270. log.info("updateOssStatus--localPath:{},ossPath:{}",localPath,path);
  271. fYunFileServiceInterface.uploadFile(localPath,path);
  272. }catch (Exception e){
  273. e.printStackTrace();
  274. }finally {
  275. FileUtil.del(localPath);
  276. }
  277. }
  278. @Override
  279. public PageInfo pageList(SceneParam param) {
  280. if(param.getType() == 2){ //深时
  281. return laserService.pageList(param);
  282. }
  283. if(param.getType() == 3){ //双目lite
  284. return sceneService.pageList(param);
  285. }
  286. Page<SceneVo> page = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
  287. List<SceneVo> records = page.getRecords();
  288. HashMap<String,SceneCopyLog> map = null;
  289. if(records.size() >0){
  290. List<String> numList = records.parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
  291. map = copyLogService.getByNewNumList(numList);
  292. }
  293. for (SceneVo record : page.getRecords()) {
  294. record.setStatusString(SceneStatusUtil.getStatusString(record));
  295. if(map !=null ){
  296. SceneCopyLog sceneCopyLog = map.get(record.getNum());
  297. if(sceneCopyLog != null){
  298. record.setCopyTime(sceneCopyLog.getCreateTime());
  299. record.setIsCopy(true);
  300. }
  301. }
  302. if(record.getStatus() == -1){ //计算失败
  303. SceneBuildProcessLog sceneBuildProcessLog = sceneBuildProcessLogService.getByNum(record.getNum());
  304. if(sceneBuildProcessLog != null){
  305. record.setSceneBuildProcessLog(sceneBuildProcessLog);
  306. record.setBuildErrorReason(SceneBuildProcessLogEnum.getReason(sceneBuildProcessLog.getProcess()));
  307. }
  308. }
  309. }
  310. return PageInfo.PageInfo(page);
  311. }
  312. @Override
  313. public void move(SceneParam param) {
  314. Camera camera = cameraService.getBySnCode(param.getSnCode());
  315. if(camera == null){
  316. throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXIST);
  317. }
  318. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  319. if(cameraDetail == null){
  320. throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXIST);
  321. }
  322. ScenePro scenePro = this.getByNum(param.getNum());
  323. ScenePlus scenePlus = scenePlusService.getByNum(param.getNum());
  324. if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
  325. throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
  326. }
  327. Integer status = scenePro == null ? scenePlus.getSceneStatus() : scenePro.getStatus();
  328. if(status == 0){
  329. throw new BusinessException(SceneConstant.FAILURE_CODE_5037, SceneConstant.FAILURE_MSG_5037);
  330. }
  331. Long sceneCameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
  332. Long space = scenePro == null ? 0 :scenePro.getSpace();
  333. String dataSource = scenePro == null ? null :scenePro.getDataSource();
  334. if(scenePlus !=null){
  335. ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  336. space = scenePlusExt.getSpace();
  337. dataSource = scenePlusExt.getDataSource();
  338. }
  339. space = space == null ? 0 :space;
  340. Long newUseSpace = space + cameraDetail.getUsedSpace();
  341. Long totalSpace = cameraDetail.getTotalSpace();
  342. UserIncrement userIncrement = userIncrementService.getByCameraId(camera.getId());
  343. if(userIncrement!=null){
  344. IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
  345. if(incrementType!=null){
  346. if(incrementType.getCameraCapacity() == -1){
  347. totalSpace = -1L;
  348. }else {
  349. totalSpace = incrementType.getCameraCapacity() * 1024 *1024 * 1024L;
  350. }
  351. }
  352. }
  353. //深时场景无限容量
  354. if(cameraDetail.getType() != 10 && totalSpace !=-1 && newUseSpace > totalSpace){
  355. throw new BusinessException(ResultCode.CAMERA_SPACE_ERROR);
  356. }
  357. Camera oldCamera = cameraService.getById(sceneCameraId);
  358. if(oldCamera == null){
  359. throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
  360. }
  361. CameraDetail oldCameraDetail = cameraDetailService.getByCameraId(oldCamera.getId());
  362. if(oldCameraDetail == null){
  363. throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
  364. }
  365. if(oldCameraDetail.getCameraId().equals(cameraDetail.getCameraId())){
  366. throw new BusinessException(ResultCode.CAMERA_NOT_MOVE);
  367. }
  368. if(!oldCameraDetail.getType().equals(cameraDetail.getType())){
  369. throw new BusinessException(ResultCode.CAMERA_TYPE_NOT_ERROR);
  370. }
  371. Long oldUseSpace = oldCameraDetail.getUsedSpace() - space < 0 ? 0 : oldCameraDetail.getUsedSpace() - space;
  372. oldCameraDetail.setUsedSpace(oldUseSpace);
  373. Long subSpace = oldCameraDetail.getTotalSpace() - oldUseSpace;
  374. if(oldCameraDetail.getType() != 10 && subSpace >0){ //有剩余容量解封容量内场景
  375. this.lockOrUnLockBySpace(oldCameraDetail,oldCameraDetail.getCameraId(),1);
  376. }
  377. Integer payStatus = scenePro == null ? scenePlus.getPayStatus() : scenePro.getPayStatus();
  378. if(cameraDetail.getType() != 10 && payStatus!=1){ //有剩余容量解封容量内场景
  379. this.lockOrUnLockBySpace(scenePro,scenePlus,1);
  380. }
  381. cameraDetailService.updateById(oldCameraDetail);
  382. cameraDetail.setUsedSpace(newUseSpace);
  383. cameraDetailService.updateById(cameraDetail);
  384. if(scenePro!=null){
  385. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  386. wrapper.eq(ScenePro::getId,scenePro.getId());
  387. wrapper.set(ScenePro::getCameraId,camera.getId());
  388. wrapper.set(ScenePro::getUserId,cameraDetail.getUserId());
  389. this.update(wrapper);
  390. //场景迁移到另外的相机清除本身在的文件夹
  391. folderSceneService.delBySceneId(scenePro.getId());
  392. }
  393. if(scenePlus!=null){
  394. LambdaUpdateWrapper<ScenePlus> wrapper = new LambdaUpdateWrapper<>();
  395. wrapper.eq(ScenePlus::getId,scenePlus.getId());
  396. wrapper.set(ScenePlus::getCameraId,camera.getId());
  397. wrapper.set(ScenePlus::getUserId,cameraDetail.getUserId());
  398. scenePlusService.update(wrapper);
  399. folderSceneService.delBySceneId(scenePlus.getId());
  400. }
  401. if(cameraDetail.getType() == 10){ //深时场景
  402. laserService.move(param.getNum(),oldCamera.getSnCode(),camera.getSnCode(),cameraDetail.getUserId());
  403. }
  404. updateFdageNewDataSource(oldCamera.getSnCode(),param.getSnCode(),dataSource);
  405. }
  406. private JSONObject updateFdageJson(JSONObject jsonObject,String newSnCode){
  407. JSONObject cam = jsonObject.getJSONObject("cam");
  408. if(cam != null){
  409. cam.put("uuid",newSnCode.toLowerCase()); //替换 相机sn
  410. }
  411. JSONArray points = jsonObject.getJSONArray("points"); //修改点位中的相机sn
  412. if(points !=null){
  413. for (Object point : points) {
  414. JSONObject jobj = (JSONObject) point;
  415. jobj.put("camera",newSnCode.toLowerCase());
  416. }
  417. }
  418. jsonObject.put("creator",newSnCode.toLowerCase());
  419. return jsonObject;
  420. }
  421. public void updateFdageNewDataSource(String oldSnCode,String newSnCode,String dataSource) {
  422. String localPathFdage = null;
  423. try {
  424. String fdagePaht = dataSource.replace("/mnt/data","home") +"/data.fdage";
  425. localPathFdage = String.format(OssPath.localFdagePath,fdagePaht);
  426. String fileContent = fYunFileServiceInterface.getFileContent(fdagePaht);
  427. JSONObject jsonObject = updateFdageJson(JSONObject.parseObject(fileContent), newSnCode);
  428. FileUtils.writeFile(localPathFdage ,JSONObject.toJSONString(jsonObject));
  429. String oldFdagePaht = dataSource.replace("/mnt/data","home") ;
  430. String[] split = oldFdagePaht.split("/");
  431. String newFdagePath = split[0] +"/"+ newSnCode +"/"+ split[2] +"/"+ newSnCode +"_" + split[3].split("_")[1];
  432. if(!oldFdagePaht.equals(newFdagePath)){
  433. log.info("updateFdageCopy--复制oss资源--oldFdagePaht:{},newFdagePath:{}",oldFdagePaht,newFdagePath);
  434. fYunFileServiceInterface.copyFileInBucket(oldFdagePaht,newFdagePath);
  435. fYunFileServiceInterface.deleteFolder(oldFdagePaht);
  436. }
  437. fYunFileServiceInterface.uploadFile(localPathFdage,newFdagePath);
  438. log.info("updateFdage--localPathFdage:{},newFdagePath:{}",localPathFdage,newFdagePath);
  439. String newDataSource = newFdagePath.replace("home","/mnt/data");
  440. this.updateDataSource(dataSource,newDataSource);
  441. }catch (Exception e){
  442. log.error("updateFdage-error:oldSnCode:{},newSnCode:{},dataSource:{}",oldSnCode,newSnCode,dataSource);
  443. log.error("updateFdage-error:",e);
  444. }finally {
  445. if(localPathFdage != null){
  446. //FileUtil.del(localPathFdage);
  447. }
  448. }
  449. }
  450. private void updateDataSource(String dataSource, String newDataSource) {
  451. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  452. wrapper.eq(ScenePro::getDataSource,dataSource);
  453. wrapper.eq(ScenePro::getIsUpgrade,0);
  454. wrapper.set(ScenePro::getDataSource,newDataSource);
  455. this.update(wrapper);
  456. LambdaUpdateWrapper<ScenePlusExt> wrapperPlus = new LambdaUpdateWrapper<>();
  457. wrapperPlus.eq(ScenePlusExt::getDataSource,dataSource);
  458. wrapperPlus.set(ScenePlusExt::getDataSource,newDataSource);
  459. scenePlusExtService.update(wrapperPlus);
  460. }
  461. @Override
  462. public void copy(String sceneNum) throws Exception {
  463. ScenePro scenePro = this.getByNum(sceneNum);
  464. ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
  465. if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
  466. throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
  467. }
  468. Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
  469. Camera camera = cameraService.getById(cameraId);
  470. if(camera == null){
  471. throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
  472. }
  473. CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraId);
  474. if(detailEntity == null){
  475. throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
  476. }
  477. if(detailEntity.getType() == 10){
  478. throw new BusinessException(ResultCode.SS_NO_COPY);
  479. }
  480. HashMap<String, Object> param = new HashMap<>();
  481. param.put("num",sceneNum);
  482. fdKKClient.copyScene(param,"m_a_n_a_g_e");
  483. }
  484. @Override
  485. public void deleteByNum(String num) {
  486. Integer sceneSource = null;
  487. ScenePro scenePro = this.getByNum(num);
  488. if(scenePro!=null){
  489. sceneSource = scenePro.getSceneSource();
  490. this.removeById(scenePro.getId());
  491. }
  492. Scene scene = sceneService.getByNum(num);
  493. if(scene!=null){
  494. sceneService.removeById(scene.getId());
  495. }
  496. ScenePlus scenePlus = scenePlusService.getByNum(num);
  497. if(scenePlus!=null){
  498. sceneSource = scenePlus.getSceneSource();
  499. scenePlusService.removeById(scenePlus.getId());
  500. scenePlusExtService.delByPlus(scenePlus.getId());
  501. }
  502. if(sceneSource != null && sceneSource == 4){
  503. laserService.delete(num);
  504. }
  505. }
  506. @Override
  507. public Long getKkCount(List<String> asList, String startTime) {
  508. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  509. wrapper.in(ScenePro::getSceneSource,asList);
  510. wrapper.eq(ScenePro::getIsUpgrade,0);
  511. wrapper.lt(ScenePro::getCreateTime,startTime);
  512. long count = this.count(wrapper);
  513. LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
  514. wrapper2.in(ScenePlus::getSceneSource,asList);
  515. wrapper2.lt(ScenePlus::getCreateTime,startTime);
  516. long count1 = scenePlusService.count(wrapper2);
  517. return count + count1;
  518. }
  519. @Override
  520. public Long getSsCount(List<String> asList, String startTime) {
  521. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  522. wrapper.in(ScenePro::getSceneSource,asList);
  523. wrapper.eq(ScenePro::getIsUpgrade,0);
  524. wrapper.lt(ScenePro::getCreateTime,startTime);
  525. LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
  526. wrapper2.in(ScenePlus::getSceneSource,asList);
  527. wrapper2.lt(ScenePlus::getCreateTime,startTime);
  528. long count = scenePlusService.count(wrapper2);
  529. return this.count(wrapper) + count;
  530. }
  531. @Override
  532. public Long getSsObjCount(List<String> asList, String startTime) {
  533. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  534. wrapper.in(ScenePro::getSceneSource,asList);
  535. wrapper.eq(ScenePro::getIsUpgrade,0);
  536. if(StringUtils.isNotBlank(startTime)){
  537. wrapper.lt(ScenePro::getCreateTime,startTime);
  538. }
  539. wrapper.eq(ScenePro::getIsObj,1);
  540. LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
  541. wrapper2.in(ScenePlus::getSceneSource,asList);
  542. if(StringUtils.isNotBlank(startTime)){
  543. wrapper2.lt(ScenePlus::getCreateTime,startTime);
  544. }
  545. List<ScenePlus> list = scenePlusService.list(wrapper2);
  546. List<Long> plusIds = list.stream().map(ScenePlus::getId).collect(Collectors.toList());
  547. long count = 0L;
  548. if(plusIds.size() >0){
  549. LambdaQueryWrapper<ScenePlusExt> wrapper3 = new LambdaQueryWrapper<>();
  550. wrapper3.in(ScenePlusExt::getPlusId,plusIds);
  551. wrapper3.eq(ScenePlusExt::getIsObj,1);
  552. count = scenePlusExtService.count(wrapper3);
  553. }
  554. return this.count(wrapper) + count;
  555. }
  556. @Override
  557. public HashMap<String, String> getSnCodeByNumList(Set<String> numList) {
  558. HashMap<String, Long> sceneMap = new HashMap<>();
  559. HashMap<Long, String> cameraMap = new HashMap<>();
  560. HashMap<String, String> snCodeMap = new HashMap<>();
  561. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  562. wrapper.eq(ScenePro::getIsUpgrade,0);
  563. wrapper.in(ScenePro::getNum,numList);
  564. List<ScenePro> list = this.list(wrapper);
  565. if(list.size() >0){
  566. list.forEach(entity -> sceneMap.put(entity.getNum(),entity.getCameraId()));
  567. }
  568. LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
  569. wrapper2.in(ScenePlus::getNum,numList);
  570. List<ScenePlus> list2 = scenePlusService.list(wrapper2);
  571. if(list2.size() >0){
  572. list2.forEach(entity -> sceneMap.put(entity.getNum(),entity.getCameraId()));
  573. }
  574. if(sceneMap.size() <=0){
  575. return snCodeMap;
  576. }
  577. Set<Long> cameraIds = list.stream().map(ScenePro::getCameraId).collect(Collectors.toSet());
  578. Set<Long> cameraIds2 = list2.stream().map(ScenePlus::getCameraId).collect(Collectors.toSet());
  579. cameraIds.addAll(cameraIds2);
  580. if(cameraIds.size() >0){
  581. List<Camera> cameraList = cameraService.listByIds(cameraIds);
  582. cameraList.forEach(entity -> cameraMap.put(entity.getId(),entity.getSnCode()));
  583. for (String num : numList) {
  584. Long cameraId = sceneMap.get(num);
  585. if(cameraId != null){
  586. snCodeMap.put(num,cameraMap.get(cameraId));
  587. }
  588. }
  589. }
  590. return snCodeMap;
  591. }
  592. }