SceneProServiceImpl.java 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. package com.fdkankan.manage.service.impl;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import cn.hutool.core.bean.BeanUtil;
  4. import cn.hutool.core.io.FileUtil;
  5. import cn.hutool.json.JSONUtil;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  9. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  10. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  11. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  12. import com.fdkankan.common.constant.SceneConstant;
  13. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  14. import com.fdkankan.manage.common.*;
  15. import com.fdkankan.manage.constant.SceneTypeLabelEnum;
  16. import com.fdkankan.manage.exception.BusinessException;
  17. import com.fdkankan.common.util.*;
  18. import com.fdkankan.manage.httpClient.client.FdKKClient;
  19. import com.fdkankan.manage.httpClient.service.LaserService;
  20. import com.fdkankan.manage.entity.*;
  21. import com.fdkankan.manage.httpClient.service.OverallService;
  22. import com.fdkankan.manage.mapper.IScenePlusMapper;
  23. import com.fdkankan.manage.mapper.ISceneProMapper;
  24. import com.fdkankan.manage.mq.common.MqQueueUtil;
  25. import com.fdkankan.manage.mq.param.ScenePayStatusVo;
  26. import com.fdkankan.manage.mq.param.SceneRestStoreVo;
  27. import com.fdkankan.manage.service.*;
  28. import com.fdkankan.manage.util.CameraUtils;
  29. import com.fdkankan.manage.util.DateUtils;
  30. import com.fdkankan.manage.util.SceneStatusUtil;
  31. import com.fdkankan.manage.vo.request.SceneParam;
  32. import com.fdkankan.manage.vo.request.SetFeedOptionParam;
  33. import com.fdkankan.manage.vo.response.*;
  34. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  35. import com.fdkankan.redis.util.RedisUtil;
  36. import lombok.extern.slf4j.Slf4j;
  37. import org.apache.commons.lang3.StringUtils;
  38. import org.springframework.beans.factory.annotation.Autowired;
  39. import org.springframework.stereotype.Service;
  40. import java.util.*;
  41. import java.util.stream.Collectors;
  42. /**
  43. * <p>
  44. * pro场景表 服务实现类
  45. * </p>
  46. *
  47. * @author
  48. * @since 2022-06-16
  49. */
  50. @Service
  51. @Slf4j
  52. public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
  53. @Autowired
  54. private ICameraService cameraService;
  55. @Autowired
  56. ICameraDetailService cameraDetailService;
  57. @Autowired
  58. ISceneService sceneService;
  59. @Autowired
  60. ISceneCopyLogService copyLogService;
  61. @Autowired
  62. IUserIncrementService userIncrementService;
  63. @Autowired
  64. IIncrementTypeService incrementTypeService;
  65. @Autowired
  66. ISceneProEditService sceneProEditService;
  67. @Autowired
  68. FYunFileServiceInterface fYunFileServiceInterface;
  69. @Autowired
  70. IScenePlusService scenePlusService;
  71. @Autowired
  72. IScene3dNumService scene3dNumService;
  73. @Autowired
  74. ISceneCopyLogService sceneCopyLogService;
  75. @Autowired
  76. IScenePlusExtService scenePlusExtService;
  77. @Autowired
  78. LaserService laserService;
  79. @Autowired
  80. FdKKClient fdKKClient;
  81. @Autowired
  82. IFolderSceneService folderSceneService;
  83. @Autowired
  84. ISceneBuildProcessLogService sceneBuildProcessLogService;
  85. @Autowired
  86. ISceneMoveLogService sceneMoveLogService;
  87. @Autowired
  88. ISceneResourceCameraService sceneResourceCameraService;
  89. @Autowired
  90. ISceneDelLogService sceneDelLogService;
  91. @Autowired
  92. RabbitMqProducer rabbitMqProducer;
  93. @Autowired
  94. RedisUtil redisUtil;
  95. @Autowired
  96. ISceneColdStorageService sceneColdStorageService;
  97. @Autowired
  98. ICommonService commonService;
  99. @Autowired
  100. IUserService userService;
  101. @Autowired
  102. IMqSendLogService mqSendLogService;
  103. @Autowired
  104. OverallService overallService;
  105. @Autowired
  106. ICameraTypeService cameraTypeService;
  107. @Autowired
  108. IFeedbackOptionService feedbackOptionService;
  109. @Override
  110. public ScenePro getByNum(String num) {
  111. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  112. wrapper.eq(ScenePro::getNum,num);
  113. wrapper.eq(ScenePro::getIsUpgrade,0);
  114. List<ScenePro> list = this.list(wrapper);
  115. if(list == null || list.size() <=0){
  116. return null;
  117. }
  118. return list.get(0);
  119. }
  120. @Override
  121. public HashMap<Long, Long> getCountGroupByUserId(List<Long> userIdList) {
  122. HashMap<Long,Long> map = new HashMap<>();
  123. List<GroupByCount> result = this.getBaseMapper().getCountGroupByUserId(userIdList);
  124. result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
  125. return map;
  126. }
  127. @Override
  128. public HashMap<Long, Long> getCountGroupByCameraId(List<Long> cameraIds) {
  129. HashMap<Long,Long> map = new HashMap<>();
  130. List<GroupByCount> result = this.getBaseMapper().getCountGroupByCameraId(cameraIds);
  131. result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
  132. return map;
  133. }
  134. @Override
  135. public void unbindCamera(Long cameraId) {
  136. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  137. wrapper.set(ScenePro::getUserId,null)
  138. .eq(ScenePro::getCameraId,cameraId);
  139. wrapper.eq(ScenePro::getIsUpgrade,0);
  140. this.update(wrapper);
  141. }
  142. @Override
  143. public List<ScenePro> getListByCameraId(Long cameraId) {
  144. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  145. wrapper.eq(ScenePro::getCameraId,cameraId);
  146. wrapper.eq(ScenePro::getIsUpgrade,0);
  147. return this.list(wrapper);
  148. }
  149. /**
  150. * @param payStatus -2 封存,为 1 解封
  151. */
  152. @Override
  153. public void lockOrUnLockBySpace(CameraDetail cameraDetail) {
  154. if(cameraDetail == null ){
  155. return;
  156. }
  157. if(!"aws".equals(CacheUtil.uploadType) && cameraTypeService.isLaser(cameraDetail.getType())){
  158. return;
  159. }
  160. ScenePayStatusVo scenePayStatusVo = new ScenePayStatusVo(cameraDetail.getCameraId());
  161. Map<String, Object> map = BeanUtil.beanToMap(scenePayStatusVo);
  162. rabbitMqProducer.sendByWorkQueue(MqQueueUtil.ucenterScenePayStatusQueue, map);
  163. }
  164. @Override
  165. public void lockOrUnLockBySpace(Long cameraId) {
  166. CameraDetail cameraDetail = cameraDetailService.getByCameraId(cameraId);
  167. this.lockOrUnLockBySpace(cameraDetail);
  168. }
  169. /**
  170. * 从oss中获取文件,并重写,上传替换
  171. */
  172. private void updateOssStatus(String path,Integer payStatus,String updateStatus) {
  173. String localPath = String.format(OssPath.localStatusPath, path);
  174. try {
  175. if(!fYunFileServiceInterface.fileExist(path)){
  176. return;
  177. }
  178. String data = fYunFileServiceInterface.getFileContent(path);
  179. if(StringUtils.isBlank(data)){
  180. return;
  181. }
  182. JSONObject jsonObject = JSONObject.parseObject(data);
  183. jsonObject.put(updateStatus,payStatus);
  184. String json = JSONUtil.toJsonStr(jsonObject);
  185. FileUtils.writeFile(localPath,json);
  186. log.info("updateOssStatus--localPath:{},ossPath:{}",localPath,path);
  187. fYunFileServiceInterface.uploadFile(localPath,path);
  188. }catch (Exception e){
  189. e.printStackTrace();
  190. }finally {
  191. FileUtil.del(localPath);
  192. }
  193. }
  194. @Override
  195. public PageInfo pageList(SceneParam param) {
  196. SceneTypeLabelEnum sceneTypeLabelEnum = null;
  197. if(param.getType() != null){
  198. sceneTypeLabelEnum = SceneTypeLabelEnum.getByLabelType(param.getType());
  199. if(sceneTypeLabelEnum == null){
  200. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  201. }
  202. }
  203. if(param.getType() != null && param.getType() == 3){ //双目lite
  204. return sceneService.pageList(param);
  205. }
  206. //优化查询,去掉left join
  207. //snCode 查询,userName 查询,companyId查询
  208. //snCode回显,userName回显
  209. if(StringUtils.isNotBlank(param.getSnCode())){
  210. List<Camera> cameraList = cameraService.getLikeBySnCode(param.getSnCode());
  211. List<Long> cameraIds = cameraList.stream().map(Camera::getId).collect(Collectors.toList());
  212. param.setCameraIds(cameraIds);
  213. }
  214. if(StringUtils.isNotBlank(param.getUserName())){
  215. List<User> userList = userService.getLikeByUserName(param.getUserName());
  216. List<Long> userIds = userList.stream().map(User::getId).collect(Collectors.toList());
  217. param.setUserIds(userIds);
  218. }
  219. if(param.getCompanyId() != null){
  220. List<CameraDetail> details = cameraDetailService.getListByCompanyId(param.getCompanyId());
  221. List<Long> cameraIds = details.stream().map(CameraDetail::getCameraId).collect(Collectors.toList());
  222. if(param.getCameraIds() == null || param.getCameraIds().isEmpty()){
  223. param.setCameraIds(cameraIds);
  224. }else {
  225. List<Long> intersection = cameraIds.stream().filter(param.getCameraIds()::contains).collect(Collectors.toList());
  226. param.setCameraIds(intersection);
  227. }
  228. }
  229. if((param.getCameraIds() != null && param.getCameraIds().size()<=0) || (param.getUserIds() != null && param.getUserIds().size()<=0)){
  230. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  231. }
  232. HashMap<String, JSONObject> laserMap = new HashMap<>();
  233. param.setIsLaser(sceneTypeLabelEnum != null && sceneTypeLabelEnum.getLaser());
  234. Page<SceneVo> page = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
  235. List<SceneVo> records = page.getRecords();
  236. HashMap<String,SceneCopyLog> map = null;
  237. HashMap<String,SceneColdStorage> coldStorageMap = null;
  238. HashMap<Long, User> userMap = null;
  239. HashMap<Long, Camera> cameraMap = null;
  240. HashMap<String,MqSendLog> mqSendLogMap = null;
  241. List<String> sceneNumList = page.getRecords().stream().map(SceneVo::getNum).collect(Collectors.toList());
  242. List<Integer> feedbackOptionIds = page.getRecords().stream().map(SceneVo::getFeedbackOptionId).collect(Collectors.toList());
  243. HashMap<Integer, FeedbackOption> mapByIds = feedbackOptionService.getMapByIds(new HashSet<>(feedbackOptionIds));
  244. if(!records.isEmpty()){
  245. map = copyLogService.getByNewNumList(sceneNumList);
  246. coldStorageMap = sceneColdStorageService.getByNumList(sceneNumList);
  247. List<Long> userIds = records.parallelStream().map(SceneVo::getUserId).collect(Collectors.toList());
  248. userMap = userService.getByIds(userIds);
  249. List<Long> cameraIds = records.parallelStream().map(SceneVo::getCameraId).collect(Collectors.toList());
  250. cameraMap = cameraService.getByIds(cameraIds);
  251. if(param.getIsLaser()){
  252. laserMap = laserService.list(sceneNumList,sceneTypeLabelEnum.getSceneSource().get(0));
  253. }
  254. List<String> modelingNumList = page.getRecords().stream().filter(e -> e.getStatus() == 0).map(SceneVo::getNum).collect(Collectors.toList());
  255. if(!modelingNumList.isEmpty()){
  256. mqSendLogMap = mqSendLogService.getByNumList(modelingNumList);
  257. }
  258. }
  259. for (SceneVo record : page.getRecords()) {
  260. if(param.getIsLaser()){
  261. JSONObject ssObj = laserMap.get(record.getNum());
  262. if(ssObj!=null){
  263. record.setSceneName(ssObj.getString("title"));
  264. record.setThumb(ssObj.getString("thumb"));
  265. record.setWebSite(ssObj.getString("webSite"));
  266. record.setIsObj(ssObj.getInteger("buildObjStatus"));
  267. record.setViewCount(ssObj.getInteger("viewCount"));
  268. record.setStatus(toFdStatus(ssObj.getInteger("status")));
  269. record.setAlgorithmTime(ssObj.getString("algorithmTime"));
  270. }else if(record.getStatus() != 0){
  271. record.setStatus(-1);
  272. record.setWebSite(null);
  273. }
  274. }else {
  275. if(record.getSceneSource() != null && (SceneTypeLabelEnum.isLaserBySceneSource(record.getSceneSource()))){
  276. record.setComputeTime(record.getMeshComputeTime());
  277. }
  278. if(CameraUtils.isLaser(record.getSceneSource(),record.getIsObj())){
  279. record.setSceneName(record.getLaserTitle());
  280. }
  281. }
  282. if(record.getStatus() != -2){
  283. record.setComputeTime(null);
  284. record.setAlgorithmTime(null);
  285. }
  286. record.setStatusString(SceneStatusUtil.getStatusString(record));
  287. if(userMap != null){
  288. User user = userMap.get(record.getUserId());
  289. if(user != null){
  290. record.setUserName(user.getUserName());
  291. }
  292. }
  293. if(cameraMap != null){
  294. Camera camera = cameraMap.get(record.getCameraId());
  295. if(camera != null){
  296. record.setSnCode(camera.getSnCode());
  297. }
  298. }
  299. if(map !=null ){
  300. SceneCopyLog sceneCopyLog = map.get(record.getNum());
  301. if(sceneCopyLog != null){
  302. record.setCopyTime(sceneCopyLog.getCreateTime());
  303. record.setIsCopy(true);
  304. }
  305. }
  306. if(coldStorageMap != null){
  307. SceneColdStorage sceneColdStorage = coldStorageMap.get(record.getNum());
  308. if(sceneColdStorage != null){
  309. record.setIsColdStorage(true);
  310. }
  311. }
  312. if(record.getStatus() == -1){ //计算失败
  313. SceneBuildProcessLog sceneBuildProcessLog = sceneBuildProcessLogService.getByNum(record.getNum());
  314. String process = null;
  315. if(sceneBuildProcessLog !=null){
  316. process = sceneBuildProcessLog.getProcess();
  317. }
  318. record.setBuildErrorReason(SceneBuildProcessLogEnum.getReason(process));
  319. }
  320. record.setAddressComponent(commonService.getAddressComponent(record.getGps()));
  321. if(mqSendLogMap!=null){
  322. MqSendLog mqSendLog = mqSendLogMap.get(record.getNum());
  323. if(mqSendLog != null){
  324. record.setStatusString("排队中");
  325. record.setStatus(-4);
  326. }
  327. }
  328. FeedbackOption feedbackOption = mapByIds.get(record.getFeedbackOptionId());
  329. if(feedbackOption != null){
  330. record.setFeedbackOptionName(feedbackOption.getNameCn());
  331. }else {
  332. record.setFeedbackOptionId(null);
  333. }
  334. }
  335. return PageInfo.PageInfo(page);
  336. }
  337. private Integer toFdStatus(Integer status) {
  338. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  339. switch (status) {
  340. case 0:
  341. case 4:
  342. return 0;
  343. case 2:
  344. return -2;
  345. case 3:
  346. return -3;
  347. default:
  348. return -1;
  349. }
  350. }
  351. @Override
  352. public synchronized Integer move(SceneParam param) {
  353. Camera camera = cameraService.getBySnCode(param.getSnCode());
  354. if(camera == null){
  355. throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXIST);
  356. }
  357. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  358. if(cameraDetail == null){
  359. throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXIST);
  360. }
  361. Integer successNum = 1;
  362. HashSet<Long> cameraIds = new HashSet<>();
  363. if(StringUtils.isNotBlank(param.getNum())){
  364. moveScene(param.getNum(),camera,cameraDetail,cameraIds);
  365. }else {
  366. successNum = param.getNumList().size();
  367. for (String num : param.getNumList()) {
  368. try {
  369. moveScene(num,camera,cameraDetail,cameraIds);
  370. }catch (Exception e){
  371. successNum --;
  372. log.info("move-scene-error:num:{},errorNum:{},error:{}",num,successNum,e.getMessage());
  373. }
  374. }
  375. }
  376. for (Long cameraId : cameraIds) {
  377. this.lockOrUnLockBySpace(cameraId);
  378. }
  379. return successNum;
  380. }
  381. private void moveScene(String num,Camera camera,CameraDetail cameraDetail, HashSet<Long> cameraIds){
  382. ScenePro scenePro = this.getByNum(num);
  383. ScenePlus scenePlus = scenePlusService.getByNum(num);
  384. if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
  385. throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
  386. }
  387. Integer status = scenePro == null ? scenePlus.getSceneStatus() : scenePro.getStatus();
  388. if(status != -2){
  389. throw new BusinessException(SceneConstant.FAILURE_CODE_5037, SceneConstant.FAILURE_MSG_5037);
  390. }
  391. Long sceneCameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
  392. Long space = scenePro == null ? 0 :scenePro.getSpace();
  393. String dataSource = scenePro == null ? null :scenePro.getDataSource();
  394. if(scenePlus !=null){
  395. ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  396. space = scenePlusExt.getSpace();
  397. dataSource = scenePlusExt.getDataSource();
  398. }
  399. space = space == null ? 0 :space;
  400. Boolean checkSpace = cameraDetailService.checkSpace(cameraDetail, space);
  401. //深时场景无限容量
  402. if( !checkSpace){
  403. throw new BusinessException(ResultCode.CAMERA_SPACE_ERROR);
  404. }
  405. Camera oldCamera = cameraService.getById(sceneCameraId);
  406. if(oldCamera == null){
  407. throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
  408. }
  409. CameraDetail oldCameraDetail = cameraDetailService.getByCameraId(oldCamera.getId());
  410. if(oldCameraDetail == null){
  411. throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
  412. }
  413. if(oldCameraDetail.getCameraId().equals(cameraDetail.getCameraId())){
  414. throw new BusinessException(ResultCode.CAMERA_NOT_MOVE);
  415. }
  416. if(!oldCameraDetail.getType().equals(cameraDetail.getType())){
  417. throw new BusinessException(ResultCode.CAMERA_TYPE_NOT_ERROR);
  418. }
  419. Long oldUseSpace = oldCameraDetail.getUsedSpace() - space < 0 ? 0 : oldCameraDetail.getUsedSpace() - space;
  420. if("GB".equals(oldCameraDetail.getUnit())){
  421. oldUseSpace = 1L;
  422. }
  423. Long subSpace = oldCameraDetail.getTotalSpace() - oldUseSpace;
  424. if(scenePro!=null){
  425. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  426. wrapper.eq(ScenePro::getId,scenePro.getId());
  427. wrapper.set(ScenePro::getCameraId,camera.getId());
  428. wrapper.set(ScenePro::getUserId,cameraDetail.getUserId());
  429. // wrapper.set(ScenePro::getStatus,0);
  430. // this.updateOssStatus(String.format(OssPath.v3_statusPath,scenePro.getNum()),0,"status");
  431. this.update(wrapper);
  432. //场景迁移到另外的相机清除本身在的文件夹
  433. folderSceneService.delBySceneId(scenePro.getId());
  434. }
  435. if(scenePlus!=null){
  436. LambdaUpdateWrapper<ScenePlus> wrapper = new LambdaUpdateWrapper<>();
  437. wrapper.eq(ScenePlus::getId,scenePlus.getId());
  438. wrapper.set(ScenePlus::getCameraId,camera.getId());
  439. wrapper.set(ScenePlus::getUserId,cameraDetail.getUserId());
  440. //wrapper.set(ScenePlus::getSceneStatus,0);
  441. //this.updateOssStatus(String.format(OssPath.v4_statusPath,scenePlus.getNum()),0,"status");
  442. scenePlusService.update(wrapper);
  443. folderSceneService.delBySceneId(scenePlus.getId());
  444. }
  445. //协作相机
  446. sceneResourceCameraService.setCooperationUser(cameraDetail,num);
  447. //String newDataSource = updateFdageNewDataSource(scenePro, scenePlus, oldCamera.getSnCode(), param.getSnCode(), dataSource);
  448. Boolean newIsLaser = cameraTypeService.isLaser(cameraDetail.getType());
  449. Boolean oldIsLaser = cameraTypeService.isLaser(oldCameraDetail.getType());
  450. if(newIsLaser){ //深时场景
  451. //迁移深时 dataSource
  452. //FileUtil.move(new File(dataSource +"_laserData"),new File(newDataSource+"_laserData"),true);
  453. laserService.move(num,oldCamera.getSnCode(),camera.getSnCode(),cameraDetail.getUserId(),dataSource);
  454. }
  455. if(!"aws".equals(CacheUtil.uploadType) && !oldIsLaser && subSpace >0){ //有剩余容量解封容量内场景
  456. cameraIds.add(oldCameraDetail.getCameraId());
  457. }
  458. if(!"aws".equals(CacheUtil.uploadType) && !oldIsLaser){ //有剩余容量解封容量内场景
  459. cameraIds.add(cameraDetail.getCameraId());
  460. }
  461. if("aws".equals(CacheUtil.uploadType) && subSpace >0){ //有剩余容量解封容量内场景
  462. cameraIds.add(oldCameraDetail.getCameraId());
  463. }
  464. if("aws".equals(CacheUtil.uploadType)){ //有剩余容量解封容量内场景
  465. cameraIds.add(cameraDetail.getCameraId());
  466. }
  467. sceneMoveLogService.saveLog(scenePro,scenePlus,camera.getSnCode(),oldCamera.getSnCode(),dataSource,dataSource, null);
  468. laserService.moveWenBao(num,oldCamera.getSnCode(),camera.getSnCode(),cameraDetail.getUserId(),dataSource);
  469. }
  470. private JSONObject updateFdageJson(JSONObject jsonObject,String newSnCode){
  471. JSONObject cam = jsonObject.getJSONObject("cam");
  472. if(cam != null){
  473. cam.put("uuid",newSnCode.toLowerCase()); //替换相机sn uuid
  474. }
  475. JSONArray points = jsonObject.getJSONArray("points"); //修改点位中的相机sn
  476. if(points !=null){
  477. for (Object point : points) {
  478. JSONObject jobj = (JSONObject) point;
  479. jobj.put("camera",newSnCode.toLowerCase());
  480. }
  481. }
  482. jsonObject.put("creator",newSnCode.toLowerCase()); //替换相机拍摄sn
  483. return jsonObject;
  484. }
  485. /**
  486. * 兼容,之前迁移,不使用旧snCode 替换新snCode。重写文件
  487. */
  488. public String updateFdageNewDataSource(ScenePro scenePro,ScenePlus scenePlus,String oldSnCode,String newSnCode,String dataSource) {
  489. String localPathFdage = null;
  490. try {
  491. newSnCode = newSnCode.toLowerCase();
  492. String fdagePaht = dataSource.replace("/mnt/data","home") +"/data.fdage";
  493. if(!fYunFileServiceInterface.fileExist(fdagePaht)){
  494. return dataSource;
  495. }
  496. localPathFdage = String.format(OssPath.localFdagePath,fdagePaht);
  497. String fileContent = fYunFileServiceInterface.getFileContent(fdagePaht);
  498. JSONObject jsonObject = updateFdageJson(JSONObject.parseObject(fileContent), newSnCode);
  499. FileUtils.writeFile(localPathFdage ,JSONObject.toJSONString(jsonObject));
  500. String oldFdagePaht = dataSource.replace("/mnt/data","home") ;
  501. String[] split = oldFdagePaht.split("/");
  502. String newFdagePath = split[0] +"/"+ newSnCode +"/"+ split[2] +"/"+ newSnCode +"_" + split[3].split("_")[1];
  503. String delPath = null;
  504. if(!oldFdagePaht.equals(newFdagePath)){
  505. log.info("updateFdageCopy--复制oss资源--oldFdagePaht:{},newFdagePath:{}",oldFdagePaht,newFdagePath);
  506. fYunFileServiceInterface.copyFileInBucket(oldFdagePaht,newFdagePath);
  507. delPath = oldFdagePaht;
  508. }
  509. fYunFileServiceInterface.uploadFile(localPathFdage,newFdagePath+"/data.fdage");
  510. log.info("updateFdage--localPathFdage:{},newFdagePath:{}",localPathFdage,newFdagePath);
  511. String newDataSource = newFdagePath.replace("home","/mnt/data");
  512. this.updateDataSource(scenePro,scenePlus,newDataSource);
  513. if(delPath != null){
  514. fYunFileServiceInterface.deleteFolder(oldFdagePaht);
  515. }
  516. sceneMoveLogService.saveLog(scenePro,scenePlus,oldSnCode,newSnCode,dataSource,newDataSource, fileContent);
  517. return newDataSource;
  518. }catch (Exception e){
  519. log.error("updateFdage-error:oldSnCode:{},newSnCode:{},dataSource:{}",oldSnCode,newSnCode,dataSource);
  520. log.error("updateFdage-error:",e);
  521. throw new BusinessException(ResultCode.MOVE_SCENE_ERROR);
  522. }finally {
  523. if(localPathFdage != null){
  524. FileUtil.del(localPathFdage);
  525. }
  526. if(scenePro!=null){
  527. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  528. wrapper.eq(ScenePro::getId,scenePro.getId());
  529. wrapper.set(ScenePro::getStatus,-2);
  530. this.update(wrapper);
  531. this.updateOssStatus(String.format(OssPath.v3_statusPath,scenePro.getNum()),-2,"status");
  532. }
  533. if(scenePlus!=null){
  534. LambdaUpdateWrapper<ScenePlus> wrapper = new LambdaUpdateWrapper<>();
  535. wrapper.eq(ScenePlus::getId,scenePlus.getId());
  536. wrapper.set(ScenePlus::getSceneStatus,-2);
  537. scenePlusService.update(wrapper);
  538. this.updateOssStatus(String.format(OssPath.v4_statusPath,scenePlus.getNum()),-2,"status");
  539. }
  540. }
  541. }
  542. private void updateDataSource(ScenePro scenePro,ScenePlus scenePlus, String newDataSource) {
  543. if(scenePro !=null){
  544. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  545. wrapper.eq(ScenePro::getId,scenePro.getId());
  546. wrapper.eq(ScenePro::getIsUpgrade,0);
  547. wrapper.set(ScenePro::getDataSource,newDataSource);
  548. this.update(wrapper);
  549. }
  550. if(scenePlus !=null){
  551. LambdaUpdateWrapper<ScenePlusExt> wrapperPlus = new LambdaUpdateWrapper<>();
  552. wrapperPlus.eq(ScenePlusExt::getPlusId,scenePlus.getId());
  553. wrapperPlus.set(ScenePlusExt::getDataSource,newDataSource);
  554. scenePlusExtService.update(wrapperPlus);
  555. }
  556. }
  557. @Override
  558. public void copy(String sceneNum) {
  559. ScenePro scenePro = this.getByNum(sceneNum);
  560. ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
  561. if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
  562. throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
  563. }
  564. Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
  565. Camera camera = cameraService.getById(cameraId);
  566. if(camera == null){
  567. throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
  568. }
  569. CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraId);
  570. if(detailEntity == null){
  571. throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
  572. }
  573. Integer sceneStatus = scenePro == null ? scenePlus.getSceneStatus() : scenePro.getStatus();
  574. if(sceneStatus != -2){
  575. throw new BusinessException(ResultCode.SCENE_IS_BUILDING);
  576. }
  577. Long needSpace = 0L;
  578. if(scenePro != null){
  579. needSpace = scenePro.getSpace();
  580. }
  581. if(scenePlus != null){
  582. ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  583. if(scenePlusExt != null && scenePlusExt.getSpace() != null){
  584. needSpace = scenePlusExt.getSpace();
  585. }
  586. }
  587. Boolean checkSpace = cameraDetailService.checkSpace(detailEntity, needSpace);
  588. if(!checkSpace){
  589. throw new BusinessException(ResultCode.CAMERA_SPACE_ERROR);
  590. }
  591. HashMap<String, Object> param = new HashMap<>();
  592. param.put("num",sceneNum);
  593. JSONObject jsonObject = fdKKClient.copyScene(param, "m_a_n_a_g_e");
  594. Integer code = jsonObject.getInteger("code");
  595. if(code != 0){
  596. throw new BusinessException(ResultCode.CAMERA_SPACE_ERROR);
  597. }
  598. }
  599. @Override
  600. public void deleteByNum(String num) {
  601. Integer sceneSource = null;
  602. Long cameraId = null;
  603. ScenePro scenePro = this.getByNum(num);
  604. Scene scene = sceneService.getByNum(num);
  605. ScenePlus scenePlus = scenePlusService.getByNum(num);
  606. Integer status = null;
  607. if(scenePro!=null){
  608. cameraId = scenePro.getCameraId();
  609. sceneSource = scenePro.getSceneSource();
  610. status = scenePro.getStatus();
  611. }
  612. if(scene!=null){
  613. cameraId = scene.getCameraId();
  614. status = scene.getStatus();
  615. }
  616. if(scenePlus!=null){
  617. cameraId = scenePlus.getCameraId();
  618. sceneSource = scenePlus.getSceneSource();
  619. status = scenePlus.getSceneStatus();
  620. }
  621. HashMap<String, MqSendLog> mqSendLogHashMap = mqSendLogService.getByNumList(Arrays.asList(num));
  622. String redisKey = "mq-wait:queue:num:"+num;
  623. if(!mqSendLogHashMap.isEmpty()){
  624. for (String key : mqSendLogHashMap.keySet()) {
  625. if(!redisUtil.hasKey(redisKey)){
  626. mqSendLogService.removeById(mqSendLogHashMap.get(key).getId());
  627. status = -1;
  628. }
  629. }
  630. }
  631. if(status != null && status == 0){
  632. throw new BusinessException(ResultCode.CAN_NOT_DEL_MODELING_SCENE);
  633. }
  634. if(scenePro!=null){
  635. this.removeById(scenePro.getId());
  636. }
  637. if(scene!=null){
  638. sceneService.removeById(scene.getId());
  639. }
  640. if(scenePlus!=null){
  641. ScenePlusExt plusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  642. if(plusExt != null){
  643. scenePlusExtService.delByPlus(scenePlus.getId());
  644. }
  645. scenePlusService.removeById(scenePlus.getId());
  646. }
  647. if(CameraUtils.isLaser(sceneSource)){
  648. laserService.delete(num);
  649. }
  650. //overallService.delete(num);
  651. if(cameraId != null){
  652. cameraDetailService.initSpace(cameraId);
  653. this.lockOrUnLockBySpace(cameraId);
  654. }
  655. sceneDelLogService.saveLog(num, StpUtil.getLoginId());
  656. }
  657. @Override
  658. public Long getKkCount(List<String> asList, String startTime) {
  659. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  660. wrapper.in(ScenePro::getSceneSource,asList);
  661. wrapper.eq(ScenePro::getIsUpgrade,0);
  662. wrapper.lt(ScenePro::getCreateTime,startTime);
  663. long count = this.count(wrapper);
  664. LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
  665. wrapper2.in(ScenePlus::getSceneSource,asList);
  666. wrapper2.lt(ScenePlus::getCreateTime,startTime);
  667. long count1 = scenePlusService.count(wrapper2);
  668. return count + count1;
  669. }
  670. @Override
  671. public Long getSsCount(List<String> asList, String startTime) {
  672. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  673. wrapper.in(ScenePro::getSceneSource,asList);
  674. wrapper.eq(ScenePro::getIsUpgrade,0);
  675. wrapper.lt(ScenePro::getCreateTime,startTime);
  676. LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
  677. wrapper2.in(ScenePlus::getSceneSource,asList);
  678. wrapper2.lt(ScenePlus::getCreateTime,startTime);
  679. long count = scenePlusService.count(wrapper2);
  680. return this.count(wrapper) + count;
  681. }
  682. @Override
  683. public Long getSsObjCount(List<String> asList, String startTime) {
  684. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  685. wrapper.in(ScenePro::getSceneSource,asList);
  686. wrapper.eq(ScenePro::getIsUpgrade,0);
  687. if(StringUtils.isNotBlank(startTime)){
  688. wrapper.lt(ScenePro::getCreateTime,startTime);
  689. }
  690. wrapper.eq(ScenePro::getIsObj,1);
  691. LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
  692. wrapper2.in(ScenePlus::getSceneSource,asList);
  693. if(StringUtils.isNotBlank(startTime)){
  694. wrapper2.lt(ScenePlus::getCreateTime,startTime);
  695. }
  696. List<ScenePlus> list = scenePlusService.list(wrapper2);
  697. List<Long> plusIds = list.stream().map(ScenePlus::getId).collect(Collectors.toList());
  698. long count = 0L;
  699. if(plusIds.size() >0){
  700. LambdaQueryWrapper<ScenePlusExt> wrapper3 = new LambdaQueryWrapper<>();
  701. wrapper3.in(ScenePlusExt::getPlusId,plusIds);
  702. wrapper3.eq(ScenePlusExt::getIsObj,1);
  703. count = scenePlusExtService.count(wrapper3);
  704. }
  705. return this.count(wrapper) + count;
  706. }
  707. @Override
  708. public HashMap<String, String> getSnCodeByNumList(Set<String> numList) {
  709. HashMap<String, Long> sceneMap = new HashMap<>();
  710. HashMap<Long, String> cameraMap = new HashMap<>();
  711. HashMap<String, String> snCodeMap = new HashMap<>();
  712. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  713. wrapper.eq(ScenePro::getIsUpgrade,0);
  714. wrapper.in(ScenePro::getNum,numList);
  715. List<ScenePro> list = this.list(wrapper);
  716. if(list.size() >0){
  717. list.forEach(entity -> sceneMap.put(entity.getNum(),entity.getCameraId()));
  718. }
  719. LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
  720. wrapper2.in(ScenePlus::getNum,numList);
  721. List<ScenePlus> list2 = scenePlusService.list(wrapper2);
  722. if(list2.size() >0){
  723. list2.forEach(entity -> sceneMap.put(entity.getNum(),entity.getCameraId()));
  724. }
  725. if(sceneMap.size() <=0){
  726. return snCodeMap;
  727. }
  728. Set<Long> cameraIds = list.stream().map(ScenePro::getCameraId).collect(Collectors.toSet());
  729. Set<Long> cameraIds2 = list2.stream().map(ScenePlus::getCameraId).collect(Collectors.toSet());
  730. cameraIds.addAll(cameraIds2);
  731. if(cameraIds.size() >0){
  732. List<Camera> cameraList = cameraService.listByIds(cameraIds);
  733. cameraList.forEach(entity -> cameraMap.put(entity.getId(),entity.getSnCode()));
  734. for (String num : numList) {
  735. Long cameraId = sceneMap.get(num);
  736. if(cameraId != null){
  737. snCodeMap.put(num,cameraMap.get(cameraId));
  738. }
  739. }
  740. List<CameraDetail> cameraIds1 = cameraDetailService.getByCameraIds(cameraList.stream().map(Camera::getId).collect(Collectors.toList()));
  741. for (CameraDetail cameraDetail : cameraIds1) {
  742. snCodeMap.put(cameraMap.get(cameraDetail.getCameraId()), CameraUtils.getCameraTypeStr(cameraDetail.getType()));
  743. }
  744. }
  745. return snCodeMap;
  746. }
  747. @Override
  748. public HashMap<Long,Long > getSpaceGroupByCameraId() {
  749. List<GroupByCount> proSum = this.getBaseMapper().getProSpaceGroupByCameraId();
  750. HashMap<Long,Long > map = new HashMap<>();
  751. for (GroupByCount groupByCount : proSum) {
  752. map.merge(groupByCount.getId(), groupByCount.getCount()==null?0:groupByCount.getCount(), Long::sum);
  753. }
  754. List<GroupByCount > plusSum = this.getBaseMapper().getPlusSpaceGroupByCameraId();
  755. for (GroupByCount groupByCount : plusSum) {
  756. map.merge(groupByCount.getId(), groupByCount.getCount()==null?0:groupByCount.getCount(), Long::sum);
  757. }
  758. return map;
  759. }
  760. @Override
  761. public void rebuildScene(String num,String from) {
  762. String redisKey2 = String.format(RedisKeyUtil.numShootKey, num);
  763. redisUtil.del(redisKey2);
  764. String dataSource = null;
  765. ScenePro scenePro = this.getByNum(num);
  766. if(scenePro!=null && scenePro.getSceneSource() != 4){
  767. throw new BusinessException(ResultCode.V3_SCENE_REBUILD);
  768. }
  769. ScenePlus scenePlus = scenePlusService.getByNum(num);
  770. if(scenePlus == null && scenePro == null){
  771. throw new BusinessException(ResultCode.SCENE_NOT_EXIST);
  772. }
  773. if(scenePro != null){
  774. dataSource = scenePro.getDataSource();
  775. }
  776. if(scenePlus != null){
  777. ScenePlusExt scenePlusExt= scenePlusExtService.getByPlusId(scenePlus.getId());
  778. if(scenePlusExt!= null){
  779. dataSource = scenePlusExt.getDataSource();
  780. }
  781. }
  782. if(StringUtils.isBlank(dataSource)){
  783. throw new BusinessException(ResultCode.SCENE_REBUILD_ERROR);
  784. }
  785. Long countByNewNum = sceneCopyLogService.getCountByNewNum(num);
  786. if(countByNewNum >0){
  787. throw new BusinessException(ResultCode.COPY_NUM_NOTREBUILD);
  788. }
  789. SceneColdStorage coldStorage = sceneColdStorageService.getByNum(num);
  790. if(coldStorage != null){
  791. throw new BusinessException(ResultCode.SCENE_REBUILD_ERROR2);
  792. }
  793. if(!fYunFileServiceInterface.fileExist(dataSource.replace("/mnt/data","home")+"/data.fdage")){
  794. throw new BusinessException(ResultCode.SCENE_REBUILD_ERROR);
  795. }
  796. HashMap<String,Object> paramMap = new HashMap<>();
  797. paramMap.put("num",num);
  798. paramMap.put("from",from == null ? "manage":from);
  799. try {
  800. JSONObject jsonObject = fdKKClient.rebuildScene(paramMap);
  801. Integer code = jsonObject.getInteger("code");
  802. if(code != 0){
  803. log.error("场景重算失败:{},{}",num,jsonObject);
  804. throw new BusinessException(ResultCode.SCENE_REBUILD_ERROR.code(), jsonObject.getString("msg"));
  805. }
  806. }catch (Exception e){
  807. throw new BusinessException(ResultCode.SCENE_REBUILD_ERROR);
  808. }
  809. }
  810. @Override
  811. public void restStore(String num) {
  812. if(StringUtils.isBlank(num)){
  813. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  814. }
  815. String redisKey = String.format(RedisKeyUtil.restStoreKey, num);
  816. if(redisUtil.hasKey(redisKey)){
  817. throw new BusinessException(ResultCode.SCENE_STORE_ING);
  818. }
  819. SceneColdStorage sceneColdStorage = sceneColdStorageService.getByNum(num);
  820. if(sceneColdStorage == null){
  821. throw new BusinessException(ResultCode.SCENE_NOT_STORE);
  822. }
  823. String dataSource = scenePlusService.getDataSourceByNum(num);
  824. if(StringUtils.isBlank(dataSource)){
  825. throw new BusinessException(ResultCode.SCENE_NOT_EXIST);
  826. }
  827. String homePath = dataSource.replace("/mnt/data","home");
  828. SceneRestStoreVo sceneRestStoreVo = new SceneRestStoreVo(num,sceneColdStorage.getColdBucket(),sceneColdStorage.getBucket(),homePath);
  829. Map<String, Object> map = BeanUtil.beanToMap(sceneRestStoreVo);
  830. redisUtil.set(redisKey,homePath);
  831. rabbitMqProducer.sendByWorkQueue(MqQueueUtil.sceneRestoreQueue,map);
  832. //threadService.checkRestore(num,sceneColdStorage.getColdBucket(),sceneColdStorage.getBucket(),homePath);
  833. }
  834. @Override
  835. public void restStoreSuccess(String num) {
  836. Integer sceneResource = null;
  837. ScenePro scenePro = this.getByNum(num);
  838. Date time = DateUtils.dateAddOneMonth(new Date(),-11);
  839. String date = DateUtils.getDate(time);
  840. if(scenePro!=null ){
  841. sceneResource = scenePro.getSceneSource();
  842. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  843. wrapper.eq(ScenePro::getId,scenePro.getId());
  844. wrapper.set(ScenePro::getCreateTime,date);
  845. this.update(wrapper);
  846. }
  847. ScenePlus scenePlus = scenePlusService.getByNum(num);
  848. if(scenePlus != null ){
  849. sceneResource = scenePlus.getSceneSource();
  850. ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  851. if(scenePlusExt != null){
  852. LambdaUpdateWrapper<ScenePlusExt> wrapper = new LambdaUpdateWrapper<>();
  853. wrapper.eq(ScenePlusExt::getId,scenePlusExt.getId());
  854. wrapper.set(ScenePlusExt::getAlgorithmTime,date);
  855. scenePlusExtService.update(wrapper);
  856. }
  857. }
  858. //深时场景通知修改计算完成时间
  859. if(CameraUtils.isLaser(sceneResource)){
  860. HashMap<String,String> map = new HashMap<>();
  861. map.put("sceneCode",num);
  862. map.put("algorithmTime",date);
  863. rabbitMqProducer.sendByWorkQueue(MqQueueUtil.laserUnfreezeScene,map);
  864. }
  865. }
  866. @Override
  867. public Object getRestStoreProcess(String num) {
  868. if(StringUtils.isBlank(num)){
  869. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  870. }
  871. SceneColdStorage sceneColdStorage = sceneColdStorageService.getByNum(num);
  872. if(sceneColdStorage == null){
  873. throw new BusinessException(ResultCode.SCENE_NOT_STORE);
  874. }
  875. String dataSource = scenePlusService.getDataSourceByNum(num);
  876. if(StringUtils.isBlank(dataSource)){
  877. throw new BusinessException(ResultCode.SCENE_NOT_EXIST);
  878. }
  879. String homePath = dataSource.replace("/mnt/data","home");
  880. return fYunFileServiceInterface.getRestoreFolderProcess(sceneColdStorage.getColdBucket(),homePath);
  881. }
  882. @Override
  883. public Long getSpaceSumByCameraId(Long cameraId) {
  884. Long spaceSumByCameraId = this.getBaseMapper().getSpaceSumByCameraId(cameraId);
  885. return spaceSumByCameraId == null ? 0:spaceSumByCameraId;
  886. }
  887. @Override
  888. public Long getCountByCameraId(Long cameraId) {
  889. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  890. wrapper.eq(ScenePro::getIsUpgrade,0);
  891. wrapper.eq(ScenePro::getCameraId,cameraId);
  892. wrapper.in(ScenePro::getStatus,0,-2);
  893. return this.count(wrapper);
  894. }
  895. @Override
  896. public void updateTitleByNum(String sceneNum, String sceneNewTitle) {
  897. LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<>();
  898. updateWrapper.eq(ScenePro::getNum,sceneNum);
  899. updateWrapper.set(ScenePro::getLaserTitle,sceneNewTitle);
  900. this.update(updateWrapper);
  901. }
  902. @Override
  903. public Object labelList() {
  904. return SceneTypeLabelEnum.getAllProperties();
  905. }
  906. @Override
  907. public void setFeedbackOption(SetFeedOptionParam param) {
  908. LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<>();
  909. updateWrapper.eq(ScenePro::getNum,param.getNum());
  910. updateWrapper.set(ScenePro::getFeedbackOptionId,param.getFeedbackOptionId());
  911. this.update(updateWrapper);
  912. LambdaUpdateWrapper<ScenePlus> updateWrapper2 = new LambdaUpdateWrapper<>();
  913. updateWrapper2.eq(ScenePlus::getNum,param.getNum());
  914. updateWrapper2.set(ScenePlus::getFeedbackOptionId,param.getFeedbackOptionId());
  915. scenePlusService.update(updateWrapper2);
  916. LambdaUpdateWrapper<Scene> updateWrapper3 = new LambdaUpdateWrapper<>();
  917. updateWrapper3.eq(Scene::getNum,param.getNum());
  918. updateWrapper3.set(Scene::getFeedbackOptionId,param.getFeedbackOptionId());
  919. sceneService.update(updateWrapper3);
  920. }
  921. @Autowired
  922. IScenePlusMapper scenePlusMapper;
  923. @Override
  924. public void reDelScene(List<String> numList) {
  925. List<String> laserNumList = new ArrayList<>();
  926. List<String> qjkkNumList = new ArrayList<>();
  927. List<ScenePro> sceneProList = this.getBaseMapper().selectDelPro(numList);
  928. if(!sceneProList.isEmpty()){
  929. List<Long> proIds = sceneProList.stream().map(ScenePro::getId).collect(Collectors.toList());
  930. this.getBaseMapper().reDelScenePro(numList);
  931. this.getBaseMapper().reDelSceneProEdit(proIds);
  932. List<String> lNumList = sceneProList.stream().filter(e -> CameraUtils.isLaser(e.getSceneSource())).map(ScenePro::getNum).collect(Collectors.toList());
  933. if(!lNumList.isEmpty()){
  934. laserNumList.addAll(lNumList);
  935. }
  936. List<String> lNumList2 = sceneProList.stream().filter(e -> CameraUtils.isQjkk(e.getSceneSource())).map(ScenePro::getNum).collect(Collectors.toList());
  937. if(!lNumList2.isEmpty()){
  938. qjkkNumList.addAll(lNumList2);
  939. }
  940. }
  941. List<ScenePlus> scenePlusList = scenePlusMapper.selectDelPro(numList);
  942. if(!scenePlusList.isEmpty()){
  943. List<Long> plusIds = scenePlusList.stream().map(ScenePlus::getId).collect(Collectors.toList());
  944. scenePlusMapper.reDelScenePro(numList);
  945. scenePlusMapper.reDelSceneProEdit(plusIds);
  946. List<String> lNumList = scenePlusList.stream().filter(e -> CameraUtils.isLaser(e.getSceneSource())).map(ScenePlus::getNum).collect(Collectors.toList());
  947. if(!lNumList.isEmpty()){
  948. laserNumList.addAll(lNumList);
  949. }
  950. List<String> lNumList2 = scenePlusList.stream().filter(e -> CameraUtils.isQjkk(e.getSceneSource())).map(ScenePlus::getNum).collect(Collectors.toList());
  951. if(!lNumList2.isEmpty()){
  952. qjkkNumList.addAll(lNumList2);
  953. }
  954. }
  955. if(!laserNumList.isEmpty()){
  956. HashMap<String,Object> map = new HashMap<>();
  957. map.put("numList",laserNumList);
  958. rabbitMqProducer.sendByWorkQueue(MqQueueUtil.RECOVER_SCENE,map);
  959. }
  960. if(!qjkkNumList.isEmpty()){
  961. HashMap<String,Object> map = new HashMap<>();
  962. map.put("numList",qjkkNumList);
  963. rabbitMqProducer.sendByWorkQueue(MqQueueUtil.PANO_RECOVER_SCENE,map);
  964. }
  965. }
  966. }