SceneProServiceImpl.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  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.*;
  14. import com.fdkankan.manage.config.LaserConfig;
  15. import com.fdkankan.manage.config.ManageConfig;
  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.param.LaserSceneParam;
  20. import com.fdkankan.manage.httpClient.service.LaserService;
  21. import com.fdkankan.manage.entity.*;
  22. import com.fdkankan.manage.httpClient.vo.LaserUpdateUserVo;
  23. import com.fdkankan.manage.mapper.ISceneProMapper;
  24. import com.fdkankan.manage.service.*;
  25. import com.fdkankan.manage.util.SceneStatusUtil;
  26. import com.fdkankan.manage.vo.request.SceneParam;
  27. import com.fdkankan.manage.vo.response.CameraDataVo;
  28. import com.fdkankan.manage.vo.response.GroupByCount;
  29. import com.fdkankan.manage.vo.response.SceneVo;
  30. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  31. import lombok.extern.slf4j.Slf4j;
  32. import net.sf.jsqlparser.parser.JJTCCJSqlParserState;
  33. import org.apache.commons.lang3.StringUtils;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.beans.factory.annotation.Value;
  36. import org.springframework.stereotype.Service;
  37. import org.springframework.util.ObjectUtils;
  38. import javax.annotation.Resource;
  39. import java.io.File;
  40. import java.util.*;
  41. import java.util.concurrent.CompletableFuture;
  42. import java.util.stream.Collectors;
  43. /**
  44. * <p>
  45. * pro场景表 服务实现类
  46. * </p>
  47. *
  48. * @author
  49. * @since 2022-06-16
  50. */
  51. @Service
  52. @Slf4j
  53. public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
  54. @Autowired
  55. private ICameraService cameraService;
  56. @Autowired
  57. ICameraDetailService cameraDetailService;
  58. @Autowired
  59. ISceneService sceneService;
  60. @Autowired
  61. ISceneCopyLogService copyLogService;
  62. @Autowired
  63. IUserIncrementService userIncrementService;
  64. @Autowired
  65. IIncrementTypeService incrementTypeService;
  66. @Autowired
  67. ISceneProEditService sceneProEditService;
  68. @Autowired
  69. FYunFileServiceInterface fYunFileServiceInterface;
  70. @Autowired
  71. IScenePlusService scenePlusService;
  72. @Autowired
  73. IScene3dNumService scene3dNumService;
  74. @Autowired
  75. ISceneCopyLogService sceneCopyLogService;
  76. @Autowired
  77. IScenePlusExtService scenePlusExtService;
  78. @Autowired
  79. LaserService laserService;
  80. @Autowired
  81. LaserConfig laserConfig;
  82. @Autowired
  83. FdKKClient fdKKClient;
  84. @Autowired
  85. IFolderSceneService folderSceneService;
  86. @Autowired
  87. IJyUserService jyUserService;
  88. @Autowired
  89. IJySceneUserAuthService jySceneUserAuthService;
  90. @Autowired
  91. IJyUserShareService jyUserShareService;
  92. @Autowired
  93. ISysUserService sysUserService;
  94. @Autowired
  95. IJySceneAuthService jySceneAuthService;
  96. @Autowired
  97. IJyUserPlatformService jyUserPlatformService;
  98. @Autowired
  99. IUserService userService;
  100. @Autowired
  101. IJyMoveSceneLogService jyMoveSceneLogService;
  102. @Autowired
  103. IJySceneUploadService jySceneUploadService;
  104. @Autowired
  105. ICaseNumService caseNumService;
  106. @Autowired
  107. ICaseService caseService;
  108. @Autowired
  109. ManageConfig manageConfig;
  110. @Autowired
  111. RabbitMqProducer rabbitMqProducer;
  112. @Override
  113. public ScenePro getByNum(String num) {
  114. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  115. wrapper.eq(ScenePro::getNum,num);
  116. wrapper.eq(ScenePro::getIsUpgrade,0);
  117. List<ScenePro> list = this.list(wrapper);
  118. if(list == null || list.size() <=0){
  119. return null;
  120. }
  121. return list.get(0);
  122. }
  123. @Override
  124. public HashMap<Long, Long> getCountGroupByUserId(List<Long> userIdList,Integer isObj) {
  125. HashMap<Long,Long> map = new HashMap<>();
  126. List<GroupByCount> result = this.getBaseMapper().getCountGroupByUserId(userIdList,isObj);
  127. result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
  128. return map;
  129. }
  130. @Override
  131. public HashMap<Long, Long> getCountGroupByCameraId(List<Long> cameraIds) {
  132. HashMap<Long,Long> map = new HashMap<>();
  133. List<GroupByCount> result = this.getBaseMapper().getCountGroupByCameraId(cameraIds);
  134. result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
  135. return map;
  136. }
  137. @Override
  138. public void unbindCamera(Long cameraId) {
  139. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  140. wrapper.set(ScenePro::getUserId,null)
  141. .eq(ScenePro::getCameraId,cameraId);
  142. wrapper.eq(ScenePro::getIsUpgrade,0);
  143. this.update(wrapper);
  144. }
  145. @Override
  146. public List<ScenePro> getListByCameraId(Long cameraId) {
  147. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  148. wrapper.eq(ScenePro::getCameraId,cameraId);
  149. wrapper.eq(ScenePro::getIsUpgrade,0);
  150. return this.list(wrapper);
  151. }
  152. /**
  153. * @param payStatus -2 封存,为 1 解封
  154. */
  155. @Override
  156. public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId, Integer payStatus) {
  157. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  158. LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
  159. Long totalSpace = cameraDetail.getTotalSpace();
  160. UserIncrement userIncrement = userIncrementService.getByCameraId(cameraId);
  161. if(userIncrement!=null){
  162. IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
  163. if(incrementType!=null){
  164. if(incrementType.getCameraCapacity() == -1){
  165. totalSpace = -1L;
  166. }else {
  167. totalSpace = incrementType.getCameraCapacity() * 1024 * 1024L;
  168. }
  169. }
  170. }
  171. log.info("lockOrUnLockBySpace---cameraId:{},payStatus:{},totalSpace:{},useSpace{}",
  172. cameraId,payStatus,totalSpace,cameraDetail.getUsedSpace());
  173. if(payStatus == 1){ //解封,判断用户权益,用户会员权益无限容量
  174. wrapper.orderByAsc(ScenePro::getCreateTime);
  175. plusWr.orderByAsc(ScenePlus::getCreateTime);
  176. wrapper.eq(ScenePro::getPayStatus,-2);
  177. plusWr.eq(ScenePlus::getPayStatus,-2);
  178. }else {
  179. if (totalSpace >= cameraDetail.getUsedSpace()) {
  180. // 总容量大于已使用容量,不予封存
  181. return;
  182. }
  183. wrapper.orderByDesc(ScenePro::getCreateTime);
  184. plusWr.orderByDesc(ScenePlus::getCreateTime);
  185. wrapper.eq(ScenePro::getPayStatus,1);
  186. plusWr.eq(ScenePlus::getPayStatus,1);
  187. }
  188. wrapper.eq(ScenePro::getCameraId,cameraId)
  189. .eq(ScenePro::getIsUpgrade,0);
  190. plusWr.eq(ScenePlus::getCameraId,cameraId);
  191. List<ScenePro> list = this.list(wrapper);
  192. List<ScenePlus> plusList = scenePlusService.list(plusWr);
  193. Long beyondSpace = Math.abs(cameraDetail.getUsedSpace() - totalSpace);
  194. Long accumulateSpace = 0L;
  195. List<Long> lockedIds = new ArrayList<>();
  196. if(payStatus == 1){
  197. Long doSpace = getScenePlusLockedIds(lockedIds, plusList, totalSpace, beyondSpace, accumulateSpace);
  198. beyondSpace -= doSpace;
  199. getSceneLockedIds(lockedIds,list,totalSpace,beyondSpace,accumulateSpace);
  200. }else {
  201. Long doSpace = getSceneLockedIds(lockedIds, list, totalSpace, beyondSpace, accumulateSpace);
  202. beyondSpace -= doSpace;
  203. getScenePlusLockedIds(lockedIds,plusList,totalSpace,beyondSpace,accumulateSpace);
  204. }
  205. lockOrUnLockScenes(lockedIds,payStatus);
  206. }
  207. private Long getSceneLockedIds(List<Long> lockedIds ,List<ScenePro> list,Long count,Long beyondSpace,Long accumulateSpace){
  208. if (list != null && list.size() > 0){
  209. for (ScenePro scenePro : list){
  210. accumulateSpace += scenePro.getSpace();
  211. if (count ==-1 && accumulateSpace.compareTo(beyondSpace) > 0){
  212. return accumulateSpace - scenePro.getSpace();
  213. }
  214. lockedIds.add(scenePro.getId());
  215. }
  216. }
  217. return accumulateSpace;
  218. }
  219. private Long getScenePlusLockedIds(List<Long> lockedIds , List<ScenePlus> list, Long count, Long beyondSpace, Long accumulateSpace){
  220. if (list != null && list.size() > 0){
  221. List<Long> plusIds = list.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
  222. HashMap<Long, ScenePlusExt> byPlusIds = scenePlusExtService.getByPlusIds(plusIds);
  223. for (ScenePlus scenePlus : list){
  224. ScenePlusExt scenePlusExt = byPlusIds.get(scenePlus.getId());
  225. accumulateSpace += scenePlusExt.getSpace();
  226. if (count ==-1 && accumulateSpace.compareTo(beyondSpace) > 0){
  227. return accumulateSpace - scenePlusExt.getSpace();
  228. }
  229. lockedIds.add(scenePlus.getId());
  230. }
  231. }
  232. return accumulateSpace;
  233. }
  234. // payStatus 为 -2 封存,为 1 解封
  235. private void lockOrUnLockScenes(List<Long> lockedIds,Integer payStatus) {
  236. if (lockedIds == null || lockedIds.size() == 0){
  237. return;
  238. }
  239. LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<>();
  240. updateWrapper.set(ScenePro::getPayStatus,payStatus)
  241. .eq(ScenePro::getIsUpgrade,0)
  242. .in(ScenePro::getId,lockedIds);
  243. this.update(updateWrapper);
  244. LambdaUpdateWrapper<ScenePlus> updatePlusWrapper = new LambdaUpdateWrapper<>();
  245. updatePlusWrapper.set(ScenePlus::getPayStatus,payStatus)
  246. .in(ScenePlus::getId,lockedIds);
  247. scenePlusService.update(updatePlusWrapper);
  248. this.updateOssStatus(lockedIds,payStatus);
  249. }
  250. /**
  251. * 修改oss status.json中 payStatus
  252. */
  253. private void updateOssStatus(List<Long> lockedIds, Integer payStatus) {
  254. LambdaQueryWrapper<ScenePro> proWr = new LambdaQueryWrapper<>();
  255. proWr.eq(ScenePro::getIsUpgrade,0);
  256. proWr.in(ScenePro::getId,lockedIds);
  257. List<ScenePro> proList = this.list(proWr);
  258. LambdaQueryWrapper<ScenePlus> pluWr = new LambdaQueryWrapper<>();
  259. pluWr.in(ScenePlus::getId,lockedIds);
  260. List<ScenePlus> plusList = scenePlusService.list(pluWr);
  261. for (ScenePro scenePro : proList) {
  262. this.updateOssStatus(String.format(OssPath.v3_statusPath,scenePro.getNum()),payStatus);
  263. }
  264. for (ScenePlus scenePlus : plusList) {
  265. this.updateOssStatus(String.format(OssPath.v4_statusPath,scenePlus.getNum()),payStatus);
  266. }
  267. }
  268. /**
  269. * 从oss中获取文件,并重写,上传替换
  270. */
  271. private void updateOssStatus(String path,Integer payStatus) {
  272. try {
  273. if(!fYunFileServiceInterface.fileExist(path)){
  274. return;
  275. }
  276. String data = fYunFileServiceInterface.getFileContent("4dkankan",path);
  277. if(StringUtils.isBlank(data)){
  278. return;
  279. }
  280. JSONObject jsonObject = JSONObject.parseObject(data);
  281. jsonObject.put("payStatus",payStatus);
  282. String json = JSONUtil.toJsonStr(jsonObject);
  283. FileUtils.writeFile(OssPath.localStatusPath ,json);
  284. log.info("updateOssStatus--localPath:{},ossPath:{}",OssPath.localStatusPath,path);
  285. fYunFileServiceInterface.uploadFile(OssPath.localStatusPath,path);
  286. }catch (Exception e){
  287. e.printStackTrace();
  288. }finally {
  289. FileUtil.del(OssPath.localStatusPath);
  290. }
  291. }
  292. @Override
  293. public PageInfo pageList(SceneParam param) {
  294. SysUser byId = sysUserService.getById(Long.valueOf(StpUtil.getLoginId().toString()));
  295. JyUser jyUser = jyUserService.getBySysId(byId.getId());
  296. if(jyUser == null){
  297. throw new BusinessException(ResultCode.JY_ID_NO_EXIST);
  298. }
  299. if(byId.getRoleId() !=1 ){
  300. Integer loginPlatformId = jyUserPlatformService.getLoginPlatformId();
  301. if(loginPlatformId == null) {
  302. return PageInfo.PageInfo(new Page(param.getPageNum(),param.getPageSize()));
  303. }
  304. param.setPlatformId(loginPlatformId);
  305. if(byId.getRoleId() == 47L ){
  306. param.setUserId(jyUser.getUserId());
  307. }
  308. }
  309. List<String> openNums = null;
  310. List<String> authNumList = null;
  311. List<String> openAuthNumList = null;
  312. HashMap<String,JySceneUserAuth> authHashMap = new HashMap<>();
  313. HashMap<String,JySceneUserAuth> openHashMap = new HashMap<>();
  314. if(param.getSceneType() == 1){
  315. param.setNotUserId(jyUser.getUserId());
  316. //List<String> openNums = jySceneAuthService.getOpenNumList();
  317. openNums = jySceneAuthService.getNumListByPlatform(param.getPlatformId(),1);
  318. if(!openNums.isEmpty()){
  319. param.getAuthNumList().addAll(openNums);
  320. }
  321. List<JySceneUserAuth> jySceneUserAuths = jySceneUserAuthService.getByJyUserId(jyUser.getId());
  322. jySceneUserAuths.stream().filter(e ->e.getNum() != null && e.getAuthType() == 0).forEach( e-> authHashMap.put(e.getNum(),e));
  323. jySceneUserAuths.stream().filter(e ->e.getNum() != null && e.getAuthType() == 1).forEach( e-> openHashMap.put(e.getNum(),e));
  324. List<String> allAuthNum = new ArrayList<>();
  325. allAuthNum.addAll(authHashMap.keySet());
  326. allAuthNum.addAll(openHashMap.keySet());
  327. HashMap<String, JySceneAuth> authMap = jySceneAuthService.getByNumList(allAuthNum);
  328. if(!authHashMap.isEmpty()){
  329. authNumList = authHashMap.keySet().stream().filter(e -> authMap.get(e)!=null && authMap.get(e).getAuthType() == 0).collect(Collectors.toList());
  330. if(!authNumList.isEmpty()){
  331. param.getAuthNumList().addAll(authNumList);
  332. }
  333. }
  334. if(!openHashMap.isEmpty()){
  335. openAuthNumList = openHashMap.keySet().stream().filter(e -> authMap.get(e)!=null && authMap.get(e).getAuthType() == 1).collect(Collectors.toList());
  336. if(!openAuthNumList.isEmpty()){
  337. param.getAuthNumList().addAll(openAuthNumList);
  338. }
  339. }
  340. param.getAuthNumList().addAll(manageConfig.getNumList());
  341. List<JyUserShare> jyUserShares = jyUserShareService.getByJyUserId(jyUser.getId());
  342. List<Integer> mainUserIds = jyUserShares.stream().map(JyUserShare::getMainJyUserId).collect(Collectors.toList());
  343. HashMap<Integer,Long> roleMap = new HashMap<>();
  344. if(!mainUserIds.isEmpty()){
  345. List<JyUser> jyUsers = jyUserService.listByIds(mainUserIds);
  346. Set<Long> sysIds = jyUsers.stream().map(JyUser::getSysUserId).collect(Collectors.toSet());
  347. HashMap<Long, SysUser> byIds = sysUserService.getByIds(sysIds);
  348. jyUsers.forEach( e-> roleMap.put(e.getId(),byIds.get(e.getSysUserId()).getRoleId()));
  349. for (JyUser user : jyUsers) {
  350. Long roleId = roleMap.get(user.getId());
  351. if(user.getPlatformId() != null && (roleId == 45L || roleId == 48L)){
  352. param.getOtherPlatformIds().add(user.getPlatformId());
  353. }else {
  354. param.getOtherUserIds().add(user.getUserId());
  355. }
  356. }
  357. }
  358. if(param.getAuthNumList().isEmpty() && param.getOtherUserIds().isEmpty() && param.getOtherPlatformIds().isEmpty()){
  359. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  360. }
  361. }
  362. Page<SceneVo> page ;
  363. SceneTypeEnum enumByType ;
  364. if(param.getIsObj() != null){
  365. if(param.getIsObj() == 0){
  366. page = this.getBaseMapper().selectLaser(new Page<>(param.getPageNum(),param.getPageSize()),param);
  367. }else {
  368. page = this.getBaseMapper().selectMesh(new Page<>(param.getPageNum(),param.getPageSize()),param);
  369. }
  370. }else {
  371. if(param.getType() == null){
  372. page = this.getBaseMapper().pageList2(new Page<>(param.getPageNum(),param.getPageSize()),param);
  373. }else {
  374. enumByType = SceneTypeEnum.getEnumByType(param.getType());
  375. if(enumByType == null){
  376. throw new BusinessException(ResultCode.CAMERA_TYPE_ERROR);
  377. }
  378. param.setSceneSource(enumByType.getSceneSource());
  379. if(enumByType.getThreeCamera()){
  380. param.setThreeCamType(true);
  381. }else {
  382. param.setNotThreeCamType(true);
  383. }
  384. if(enumByType.getLaser()){
  385. page = this.getBaseMapper().selectLaser(new Page<>(param.getPageNum(),param.getPageSize()),param);
  386. }else {
  387. page = this.getBaseMapper().selectMesh(new Page<>(param.getPageNum(),param.getPageSize()),param);
  388. }
  389. }
  390. }
  391. List<SceneVo> records = page.getRecords();
  392. List<String> numList = records.parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
  393. HashMap<String,SceneCopyLog> map = copyLogService.getByNewNumList(numList);
  394. HashMap<String, Case> mapByNumList = caseNumService.getMapByNumList(numList);
  395. for (SceneVo record : page.getRecords()) {
  396. if( record.getSceneType().equals("laser") ){
  397. record.setStatus(laserService.toFdStatus(record.getStatus()));
  398. record.setWebSite(laserConfig.getLaserWebSite()+record.getNum());
  399. record.setPayStatus(1);
  400. }
  401. record.setStatusString(SceneStatusUtil.getStatusString(record));
  402. if(map !=null ){
  403. SceneCopyLog sceneCopyLog = map.get(record.getNum());
  404. if(sceneCopyLog != null){
  405. record.setCopyTime(sceneCopyLog.getCreateTime());
  406. record.setIsCopy(true);
  407. }
  408. }
  409. if( byId.getRoleId() == 1L || jyUser.getUserId().equals(record.getUserId())){
  410. record.setIsAuth(true);
  411. record.setEditAuth(true);
  412. record.setIsAuthOther(true);
  413. }else if((byId.getRoleId() == 45L || byId.getRoleId() == 48L) && jyUser.getPlatformId().equals(record.getPlatformId())){
  414. record.setIsAuth(true);
  415. record.setEditAuth(true);
  416. record.setIsAuthOther(true);
  417. } else if(param.getAuthNumList().contains(record.getNum())) {
  418. JySceneUserAuth jySceneUserAuth = null;
  419. if(openAuthNumList != null && openAuthNumList.contains(record.getNum())){
  420. jySceneUserAuth = openHashMap.get(record.getNum());
  421. }
  422. if(authNumList != null && authNumList.contains(record.getNum())){
  423. jySceneUserAuth = authHashMap.get(record.getNum());
  424. }
  425. if(jySceneUserAuth != null){
  426. if(jySceneUserAuth.getCanAuthLook() == 1 || jySceneUserAuth.getCanEditLook() == 1){
  427. record.setIsAuth(true);
  428. }
  429. record.setEditAuth(jySceneUserAuth.getEditAuth() == 1);
  430. if(jySceneUserAuth.getEditAuth() == 2){
  431. record.setEditAuth(jySceneUserAuth.getEditEndTime().getTime() > new Date().getTime());
  432. }
  433. }
  434. }else {
  435. record.setIsShare(true);
  436. }
  437. record.setType( param.getType() == null ?setSceneType(record.getSceneSource(),record.getThreeCamType(),record.getSceneType()) : param.getType());
  438. if(manageConfig.getNumList().contains(record.getNum()) || mapByNumList.get(record.getNum() + toFusionType(record.getType())) != null){
  439. record.setInCase(true);
  440. }
  441. }
  442. return PageInfo.PageInfo(page);
  443. }
  444. //0 四维看看,1看见场景,2 深时场景,3 三维模型,4深时obj,5深光点云,6深光mesh,7圆周率
  445. private Integer toFusionType(Integer type) {
  446. switch (type){
  447. case 5 :return 4;
  448. case 6 :return 5;
  449. case 7 :return 6;
  450. case 8 :return 7;
  451. default: return type;
  452. }
  453. }
  454. private Integer setSceneType(Integer sceneSource,String threeCamType,String sceneType) {
  455. if(sceneSource == 3 ){
  456. return 1;
  457. }
  458. if(sceneSource == 4 && sceneType.equals("laser")){
  459. return 2;
  460. }
  461. if(sceneSource == 4 && sceneType.equals("4dkankan")){
  462. return 5;
  463. }
  464. if(sceneSource == 5 && sceneType.equals("laser")){
  465. return 6;
  466. }
  467. if(sceneSource == 5 && sceneType.equals("4dkankan")){
  468. return 7;
  469. }
  470. return StringUtils.isBlank(threeCamType) ? 0 : 8;
  471. }
  472. @Override
  473. public Object sceneCount() {
  474. if( !manageConfig.getNumList().isEmpty()){
  475. return 1;
  476. }
  477. SysUser byId = sysUserService.getById(Long.valueOf(StpUtil.getLoginId().toString()));
  478. JyUser jyUser = jyUserService.getBySysId(byId.getId());
  479. LambdaQueryWrapper<ScenePlus> wrapper = new LambdaQueryWrapper<>();
  480. if(byId.getRoleId() != 1L ){
  481. Integer loginPlatformId = jyUserPlatformService.getLoginPlatformId();
  482. if(jyUser == null){
  483. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  484. }
  485. List<String> openNums = jySceneAuthService.getNumListByPlatform(loginPlatformId,1);
  486. if(!openNums.isEmpty()){
  487. return 1;
  488. }
  489. if(byId.getRoleId() !=45L && byId.getRoleId() != 48L){
  490. wrapper.eq(ScenePlus::getUserId,jyUser.getUserId());
  491. }
  492. List<JySceneUserAuth> list = jySceneUserAuthService.getByJyUserId(jyUser.getId());
  493. if(list.size() >0){
  494. return 1;
  495. }
  496. List<JyUserShare> jyUserShares = jyUserShareService.getByJyUserId(jyUser.getId());
  497. if(jyUserShares.size() >0){
  498. return 1;
  499. }
  500. }
  501. List<Long> userIds = new ArrayList<>();
  502. if(byId.getRoleId() == 45L || byId.getRoleId() == 48L){
  503. //获取本平台所有用户
  504. if(byId.getRoleId() == 48L){
  505. Integer loginPlatformId = jyUserPlatformService.getLoginPlatformId();
  506. if(loginPlatformId != null){
  507. userIds = jyUserService.getByUserIdPlatform(loginPlatformId);
  508. }
  509. }
  510. if(byId.getRoleId() == 45L){
  511. //获取江门平台用户
  512. List<JyUser> jyUsers = jyUserService.getListByJm();
  513. userIds = jyUsers.stream().map(JyUser::getUserId).collect(Collectors.toList());
  514. }
  515. if(userIds.isEmpty()){
  516. return 0;
  517. }
  518. wrapper.in(ScenePlus::getUserId,userIds);
  519. }
  520. return scenePlusService.count(wrapper);
  521. }
  522. @Override
  523. public void move(SceneParam param) {
  524. ScenePlus scenePlus = scenePlusService.getByNum(param.getNum());
  525. if(scenePlus== null ){
  526. throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
  527. }
  528. if(scenePlus.getSceneStatus() != -2){
  529. throw new BusinessException(SceneConstant.FAILURE_CODE_5037, SceneConstant.FAILURE_MSG_5037);
  530. }
  531. JyUser jyUser = jyUserService.getByRyNo(param.getRyNo());
  532. if(jyUser == null){
  533. throw new BusinessException(ResultCode.USER_NOT_EXIST);
  534. }
  535. caseService.checkNumInCase(param.getNum());
  536. JySceneUpload jySceneUpload = jySceneUploadService.getByNum(param.getNum());
  537. if(jySceneUpload == null){
  538. jySceneUpload = new JySceneUpload();
  539. jySceneUpload.setUploadId(scenePlus.getUserId());
  540. jySceneUpload.setNum(scenePlus.getNum());
  541. jySceneUploadService.save(jySceneUpload);
  542. }
  543. LambdaUpdateWrapper<ScenePlus> wrapper = new LambdaUpdateWrapper<>();
  544. wrapper.eq(ScenePlus::getId,scenePlus.getId());
  545. wrapper.set(ScenePlus::getUserId,jyUser.getUserId());
  546. scenePlusService.update(wrapper);
  547. jySceneAuthService.delByNumList(Arrays.asList(scenePlus.getNum()));
  548. jyMoveSceneLogService.saveLog(scenePlus.getNum(),scenePlus.getUserId(),jyUser.getUserId(),Long.valueOf(StpUtil.getLoginId().toString()));
  549. laserService.updateSceneUser(new LaserUpdateUserVo(scenePlus.getUserId(),jyUser.getRyNo(),jyUser.getUserId(),scenePlus.getNum()));
  550. }
  551. @Override
  552. public void copy(String sceneNum) throws Exception {
  553. ScenePro scenePro = this.getByNum(sceneNum);
  554. ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
  555. if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
  556. throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
  557. }
  558. Integer status = scenePro == null ? scenePlus.getSceneStatus() :scenePro.getStatus();
  559. if(status !=-2){
  560. throw new BusinessException(SceneConstant.FAILURE_CODE_5033, SceneConstant.FAILURE_MSG_5033);
  561. }
  562. // Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
  563. // Camera camera = cameraService.getById(cameraId);
  564. // if(camera == null){
  565. // throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
  566. // }
  567. // CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraId);
  568. // if(detailEntity == null){
  569. // throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
  570. // }
  571. // if(detailEntity.getType() == 10 || detailEntity.getType() == 11){
  572. // throw new BusinessException(ResultCode.SS_NO_COPY);
  573. // }
  574. HashMap<String, Object> param = new HashMap<>();
  575. param.put("num",sceneNum);
  576. JSONObject jsonObject = fdKKClient.copyScene(param, "m_a_n_a_g_e");
  577. Integer code = jsonObject.getInteger("code");
  578. if(code != 0){
  579. throw new BusinessException(jsonObject.getInteger("code"),jsonObject.getString("message"));
  580. }
  581. }
  582. @Override
  583. public void deleteByNum(String num) {
  584. Integer sceneSource = null;
  585. ScenePro scenePro = this.getByNum(num);
  586. Integer status = -2;
  587. if(scenePro!=null){
  588. sceneSource = scenePro.getSceneSource();
  589. status = scenePro.getStatus();
  590. this.removeById(scenePro.getId());
  591. }
  592. Scene scene = sceneService.getByNum(num);
  593. if(scene!=null){
  594. status = scene.getStatus();
  595. sceneService.removeById(scene.getId());
  596. }
  597. ScenePlus scenePlus = scenePlusService.getByNum(num);
  598. if(scenePlus!=null){
  599. status = scenePlus.getSceneStatus();
  600. sceneSource = scenePlus.getSceneSource();
  601. ScenePlusExt plusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  602. if(plusExt != null){
  603. scenePlusExtService.delByPlus(scenePlus.getId());
  604. }
  605. scenePlusService.removeById(scenePlus.getId());
  606. scenePlusExtService.delByPlus(scenePlus.getId());
  607. }
  608. if(sceneSource != null && (sceneSource == 4 || sceneSource == 5)){
  609. laserService.delete(num);
  610. }
  611. if(status == 0 ){
  612. HashMap<String,String> map = new HashMap<>();
  613. map.put("num",num);
  614. rabbitMqProducer.sendByWorkQueue("fanout-exchange-iterrupt-calling","",map);
  615. }
  616. // if(cameraId != null){
  617. // cameraDetailService.addUsedSpace(cameraId,space);
  618. // }
  619. }
  620. @Override
  621. public Long getKkCount(List<String> asList, String startTime,List<Long> userIds,String treeCamType) {
  622. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  623. wrapper.in(ScenePro::getSceneSource,asList);
  624. if(!userIds.isEmpty()){
  625. wrapper.in(ScenePro::getUserId,userIds);
  626. }
  627. wrapper.eq(ScenePro::getIsUpgrade,0);
  628. wrapper.lt(ScenePro::getCreateTime,startTime);
  629. long count = this.count(wrapper);
  630. LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
  631. wrapper2.in(ScenePlus::getSceneSource,asList);
  632. if(!userIds.isEmpty()){
  633. wrapper2.in(ScenePlus::getUserId,userIds);
  634. }
  635. if(StringUtils.isNotBlank(treeCamType)){
  636. wrapper2.isNotNull(ScenePlus::getThreeCamType);
  637. }else {
  638. wrapper2.isNull(ScenePlus::getThreeCamType);
  639. }
  640. wrapper2.lt(ScenePlus::getCreateTime,startTime);
  641. long count1 = scenePlusService.count(wrapper2);
  642. return count + count1;
  643. }
  644. @Override
  645. public Long getSsCount(List<String> asList, String startTime,List<Long> userIds) {
  646. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  647. wrapper.in(ScenePro::getSceneSource,asList);
  648. if(!userIds.isEmpty()){
  649. wrapper.in(ScenePro::getUserId,userIds);
  650. }
  651. wrapper.eq(ScenePro::getIsUpgrade,0);
  652. wrapper.lt(ScenePro::getCreateTime,startTime);
  653. LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
  654. wrapper2.in(ScenePlus::getSceneSource,asList);
  655. if(!userIds.isEmpty()){
  656. wrapper2.in(ScenePlus::getUserId,userIds);
  657. }
  658. wrapper2.lt(ScenePlus::getCreateTime,startTime);
  659. long count = scenePlusService.count(wrapper2);
  660. return this.count(wrapper) + count;
  661. }
  662. @Override
  663. public Long getSsObjCount(List<String> asList, String startTime,List<Long> userIds) {
  664. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  665. wrapper.in(ScenePro::getSceneSource,asList);
  666. if(!userIds.isEmpty()){
  667. wrapper.in(ScenePro::getUserId,userIds);
  668. }
  669. wrapper.eq(ScenePro::getIsUpgrade,0);
  670. if(StringUtils.isNotBlank(startTime)){
  671. wrapper.lt(ScenePro::getCreateTime,startTime);
  672. }
  673. wrapper.eq(ScenePro::getIsObj,1);
  674. LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
  675. wrapper2.in(ScenePlus::getSceneSource,asList);
  676. if(!userIds.isEmpty()){
  677. wrapper2.in(ScenePlus::getUserId,userIds);
  678. }
  679. if(StringUtils.isNotBlank(startTime)){
  680. wrapper2.lt(ScenePlus::getCreateTime,startTime);
  681. }
  682. List<ScenePlus> list = scenePlusService.list(wrapper2);
  683. List<Long> plusIds = list.stream().map(ScenePlus::getId).collect(Collectors.toList());
  684. long count = 0L;
  685. if(plusIds.size() >0){
  686. LambdaQueryWrapper<ScenePlusExt> wrapper3 = new LambdaQueryWrapper<>();
  687. wrapper3.in(ScenePlusExt::getPlusId,plusIds);
  688. wrapper3.eq(ScenePlusExt::getIsObj,1);
  689. count = scenePlusExtService.count(wrapper3);
  690. }
  691. return this.count(wrapper) + count;
  692. }
  693. @Override
  694. public HashMap<String, String> getSnCodeByNumList(Set<String> numList) {
  695. HashMap<String, Long> sceneMap = new HashMap<>();
  696. HashMap<Long, String> cameraMap = new HashMap<>();
  697. HashMap<String, String> snCodeMap = new HashMap<>();
  698. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  699. wrapper.eq(ScenePro::getIsUpgrade,0);
  700. wrapper.in(ScenePro::getNum,numList);
  701. List<ScenePro> list = this.list(wrapper);
  702. if(list.size() >0){
  703. list.forEach(entity -> sceneMap.put(entity.getNum(),entity.getCameraId()));
  704. }
  705. LambdaQueryWrapper<ScenePlus> wrapper2 = new LambdaQueryWrapper<>();
  706. wrapper2.in(ScenePlus::getNum,numList);
  707. List<ScenePlus> list2 = scenePlusService.list(wrapper2);
  708. if(list2.size() >0){
  709. list2.forEach(entity -> sceneMap.put(entity.getNum(),entity.getCameraId()));
  710. }
  711. if(sceneMap.size() <=0){
  712. return snCodeMap;
  713. }
  714. Set<Long> cameraIds = list.stream().map(ScenePro::getCameraId).collect(Collectors.toSet());
  715. Set<Long> cameraIds2 = list2.stream().map(ScenePlus::getCameraId).collect(Collectors.toSet());
  716. cameraIds.addAll(cameraIds2);
  717. if(cameraIds.size() >0){
  718. List<Camera> cameraList = cameraService.listByIds(cameraIds);
  719. cameraList.forEach(entity -> cameraMap.put(entity.getId(),entity.getSnCode()));
  720. for (String num : numList) {
  721. Long cameraId = sceneMap.get(num);
  722. if(cameraId != null){
  723. snCodeMap.put(num,cameraMap.get(cameraId));
  724. }
  725. }
  726. }
  727. return snCodeMap;
  728. }
  729. }