SceneProServiceImpl.java 26 KB

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