CameraServiceImpl.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. package com.fdkankan.manage.service.impl;
  2. import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.fdkankan.common.constant.Constant;
  8. import com.fdkankan.common.util.MD5;
  9. import com.fdkankan.manage.common.*;
  10. import com.fdkankan.manage.entity.*;
  11. import com.fdkankan.manage.exception.BusinessException;
  12. import com.fdkankan.common.util.DateUtil;
  13. import com.fdkankan.manage.constant.CameraConstant;
  14. import com.fdkankan.manage.mapper.ICameraMapper;
  15. import com.fdkankan.manage.service.*;
  16. import com.fdkankan.manage.util.Dateutils;
  17. import com.fdkankan.manage.vo.request.CameraInOutParam;
  18. import com.fdkankan.manage.vo.request.CameraParam;
  19. import com.fdkankan.manage.vo.response.CameraDataVo;
  20. import com.fdkankan.manage.vo.response.CameraDetailVo;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.beans.factory.annotation.Value;
  25. import org.springframework.stereotype.Service;
  26. import java.util.*;
  27. import java.util.stream.Collectors;
  28. /**
  29. * <p>
  30. * 相机主表 服务实现类
  31. * </p>
  32. *
  33. * @author
  34. * @since 2022-06-16
  35. */
  36. @Service
  37. @Slf4j
  38. public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implements ICameraService {
  39. @Autowired
  40. ICameraDetailService cameraDetailService;
  41. @Autowired
  42. ISceneService sceneService;
  43. @Autowired
  44. ISceneProService sceneProService;
  45. @Autowired
  46. IUserIncrementService userIncrementService;
  47. @Autowired
  48. ISceneResourceCameraService sceneResourceCameraService;
  49. @Autowired
  50. IScenePlusService scenePlusService;
  51. @Autowired
  52. ICompanyService companyService;
  53. @Autowired
  54. IExcelService excelService;
  55. @Autowired
  56. IOrderService orderService;
  57. @Autowired
  58. ICameraTypeService cameraTypeService;
  59. @Override
  60. public List<Camera> getListByCameraIdList(List<Long> cameraIdList) {
  61. LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
  62. wrapper.in(Camera::getId,cameraIdList);
  63. return this.list(wrapper);
  64. }
  65. @Override
  66. public Camera getBySnCode(String snCode) {
  67. LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
  68. wrapper.eq(Camera::getSnCode,snCode);
  69. List<Camera> list = this.list(wrapper);
  70. if(list == null || list.size() <=0 ){
  71. return null;
  72. }
  73. return list.get(0);
  74. }
  75. private List<Camera> getBySnCodes(List<String> snCodeList) {
  76. LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
  77. wrapper.in(Camera::getSnCode,snCodeList);
  78. return this.list(wrapper);
  79. }
  80. private List<Camera> getByOutSnCodes(List<String> snCodeList) {
  81. return this.getBaseMapper().getByOutSnCodes(snCodeList);
  82. }
  83. @Override
  84. public void unbindCamera(Long cameraId) {
  85. userIncrementService.unbindCamera(cameraId); //取消关联用户权益
  86. cameraDetailService.unbindCamera(cameraId); //取消相机用户关联
  87. sceneService.unbindCamera(cameraId); //取消关联场景
  88. sceneProService.unbindCamera(cameraId); //取消关联场景
  89. scenePlusService.unbindCamera(cameraId); //取消关联场景
  90. sceneResourceCameraService.unbindCamera(cameraId); //删除协作相机
  91. }
  92. @Override
  93. public PageInfo pageList(CameraParam param) {
  94. Page<CameraDetailVo> voPage = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
  95. return PageInfo.PageInfo(voPage);
  96. }
  97. @Override
  98. public void in(String wifiName) {
  99. if(StringUtils.isEmpty(wifiName) ){
  100. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  101. }
  102. List<CameraType> list = cameraTypeService.list();
  103. Set<String> wifiNamePrefixList = list.stream().map(CameraType::getWifiNamePrefix).collect(Collectors.toSet());
  104. if(!wifiName.contains("_")){
  105. throw new BusinessException(ResultCode.WIFI_NAME_ERROR);
  106. }
  107. String[] split = wifiName.split("_");
  108. String cameraPrefix = split[0] +"_";
  109. String snCode = split[1];
  110. if(!wifiNamePrefixList.contains(cameraPrefix)){
  111. throw new BusinessException(ResultCode.WIFI_NAME_ERROR);
  112. }
  113. HashMap<String,CameraType> cameraTypeMap = new HashMap<>();
  114. list.forEach(entity->cameraTypeMap.put(entity.getWifiNamePrefix(),entity));
  115. if(cameraTypeMap.get(cameraPrefix) == null){
  116. throw new BusinessException(ResultCode.WIFI_NAME_ERROR);
  117. }
  118. LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
  119. wrapper.eq(Camera::getSnCode,snCode);
  120. long count = this.count(wrapper);
  121. if(count > 0){
  122. throw new BusinessException(ResultCode.WIFI_NAME_REPEAT);
  123. }
  124. saveBatchCamera(Collections.singletonList(wifiName),cameraTypeMap);
  125. }
  126. private Integer saveBatchCamera(List<String> wifiNameList,HashMap<String,CameraType> cameraTypeMap){
  127. HashSet<String> wifiNameSet = new HashSet<>(wifiNameList);
  128. List<Camera> cameraList = new ArrayList<>();
  129. for (String wifiName : wifiNameSet) {
  130. String[] res = wifiName.split("_");
  131. if(res.length !=2 || StringUtils.isBlank(res[1])){
  132. throw new BusinessException(ResultCode.WIFI_NAME_ERROR);
  133. }
  134. if(cameraTypeMap.get(res[0] +"_") == null){
  135. throw new BusinessException(ResultCode.WIFI_NAME_ERROR);
  136. }
  137. Camera camera = new Camera();
  138. camera.setWifiName(wifiName);
  139. camera.setSnCode(res[1]);
  140. camera.setChildName(res[1]);
  141. camera.setWifiPassword(CameraConstant.WIFI_PASSWORD_VALUE);
  142. camera.setChildPassword(CameraConstant.CHILD_PASSWORD_VALUE);
  143. camera.setActivatedTime(DateUtil.date2String(new Date(),DateUtil.DEFAULT_DATE_FORMAT));
  144. cameraList.add(camera);
  145. }
  146. this.saveBatch(cameraList);
  147. List<CameraDetail> cameraDetailList = new ArrayList<>();
  148. for (Camera camera : cameraList) {
  149. CameraDetail cameraDetail = new CameraDetail();
  150. cameraDetail.setAgency(CameraConstant.DEFAULT_AGENT);
  151. cameraDetail.setCameraId(camera.getId());
  152. cameraDetail.setCountry(0);//默认中国
  153. String wifiNamePrix = camera.getWifiName().split("_")[0]+"_";
  154. CameraType cameraType = cameraTypeMap.get(wifiNamePrix);
  155. cameraDetail.setType(cameraType.getCameraType());
  156. if (1 == cameraDetail.getType() || 9 == cameraDetail.getType() || 10 == cameraDetail.getType() || 13 == cameraDetail.getType()){
  157. cameraDetail.setTotalSpace(Long.valueOf(Constant.CAMERA_BASE_SPACE_VALUE));
  158. cameraDetail.setUsedSpace(0L);
  159. }
  160. if("aws".equals(CacheUtil.uploadType)){
  161. cameraDetail.setCountry(1);//1-国外
  162. }
  163. cameraDetail.setGoodsId(null);
  164. if("local".equals(CacheUtil.uploadType)) { //本地版本 ,入库即出库,并且添加无限期会员权限
  165. cameraDetail.setCountry(2);
  166. cameraDetail.setOwn(2);
  167. cameraDetail.setOutTime(Dateutils.getDate(new Date()));
  168. }
  169. cameraDetailList.add(cameraDetail);
  170. }
  171. return cameraDetailService.saveBatch(cameraDetailList) ? cameraList.size() : 0;
  172. }
  173. @Override
  174. public Integer ins(List<String> wifiNameList){
  175. List<CameraType> cameraTypeList = cameraTypeService.list();
  176. Set<String> wifiNamePrefixList = cameraTypeList.stream().map(CameraType::getWifiNamePrefix).collect(Collectors.toSet());
  177. List<Integer> errorRow = getErrorRow(wifiNameList,wifiNamePrefixList);
  178. HashMap<String,CameraType> cameraTypeMap = new HashMap<>();
  179. cameraTypeList.forEach(entity->cameraTypeMap.put(entity.getWifiNamePrefix(),entity));
  180. excelService.toExcelError(errorRow);
  181. List<String> snCodeList = new ArrayList<>();
  182. for (String wifiName : wifiNameList) {
  183. snCodeList.add(wifiName.split("_")[1]);
  184. }
  185. LambdaQueryWrapper<Camera> wrapper = new LambdaQueryWrapper<>();
  186. wrapper.in(Camera::getSnCode,snCodeList);
  187. List<Camera> list = this.list(wrapper);
  188. if(list.size() >0){
  189. List<String> newList = list.parallelStream().map(Camera::getSnCode).collect(Collectors.toList());
  190. List<Integer> errorRow2 = getErrorRow(snCodeList, newList);
  191. excelService.toExcelError(errorRow2);
  192. }
  193. return saveBatchCamera(wifiNameList,cameraTypeMap);
  194. }
  195. private List<Integer> getErrorRow(List<String> wifiNameList,Set<String> wifiNamePrefixList){
  196. List<Integer> errorIndexList = new ArrayList<>();
  197. Set<String> wifiNameSet = new HashSet<>();
  198. Integer index = 0;
  199. for (String wifiName : wifiNameList) {
  200. index ++;
  201. if(StringUtils.isBlank(wifiName)){
  202. errorIndexList.add(index);
  203. continue;
  204. }
  205. if(wifiNameSet.contains(wifiName)){
  206. errorIndexList.add(index);
  207. continue;
  208. }
  209. String[] split = wifiName.split("_");
  210. String cameraPrefix = split[0] +"_";
  211. String snCode = split[1];
  212. if(!wifiNamePrefixList.contains(cameraPrefix)){
  213. errorIndexList.add(index);
  214. }
  215. wifiNameSet.add(wifiName);
  216. }
  217. return errorIndexList;
  218. }
  219. private List<Integer> getErrorRow(List<String> wifiNameList,List<String> dbList){
  220. List<Integer> errorIndexList = new ArrayList<>();
  221. if(dbList.size() <=0){
  222. return errorIndexList;
  223. }
  224. Integer index = 0;
  225. for (String wifiName : wifiNameList) {
  226. index ++;
  227. if(dbList.contains(wifiName)){
  228. errorIndexList.add(index);
  229. }
  230. }
  231. return errorIndexList;
  232. }
  233. @Override
  234. public void out(CameraInOutParam param) {
  235. if(param.getOutType() == null || param.getId() == null){
  236. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  237. }
  238. if(StringUtils.isNotBlank(param.getCompanyName())){
  239. Company company = companyService.getCompanyByName(param.getCompanyName());
  240. if(company == null){
  241. throw new BusinessException(ResultCode.COMPANY_NAME_NOT_EXIST);
  242. }
  243. param.setCompanyId(company.getId());
  244. }
  245. Camera camera = this.getById(param.getId());
  246. if(camera == null){
  247. throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
  248. }
  249. CameraDetail detail = cameraDetailService.getByCameraId(camera.getId());
  250. if(detail ==null){
  251. throw new BusinessException(ResultCode.CAMERA_NOT_IN);
  252. }
  253. HashMap<Long,CameraDetail> detailMap = new HashMap<>();
  254. detailMap.put(detail.getCameraId(),detail);
  255. this.saveBatchDetail(detailMap, Collections.singletonList(param));
  256. }
  257. @Override
  258. public Integer outs(List<CameraInOutParam> params){
  259. setCompanyIdByDb(params);
  260. checkOrderSn(params);
  261. HashMap<String, Object> resultMap = getResultMap(params,1);
  262. HashMap<Long,CameraDetail> detailMap = (HashMap<Long, CameraDetail>) resultMap.get("detailMap");
  263. HashMap<String, Camera> snCodeMap = (HashMap<String, Camera>) resultMap.get("snCodeMap");
  264. for (CameraInOutParam param : params) {
  265. if(param.getId() == null){
  266. param.setId(snCodeMap.get(param.getSnCode()).getId());
  267. }
  268. }
  269. return this.saveBatchDetail(detailMap,params);
  270. }
  271. private void checkOrderSn(List<CameraInOutParam> params) {
  272. List<String> orderSnList = params.stream().map(CameraInOutParam::getOrderSn).collect(Collectors.toList());
  273. if(orderSnList.size() >0){
  274. List<Order> orders = orderService.getByOrderSnList(orderSnList);
  275. List<String> dbOrderSn = orders.stream().map(Order::getOrderSn).collect(Collectors.toList());
  276. List<Integer> errorList = new ArrayList<>();
  277. Integer index = 0;
  278. for (String sn : orderSnList) {
  279. index ++;
  280. if(StringUtils.isBlank(sn)){
  281. continue;
  282. }
  283. if(!dbOrderSn.contains(sn)){
  284. log.error("excel-export-error-->:订单号不存在不存在:index:{},orderSn:{}",index+3,sn);
  285. errorList.add(index);
  286. }
  287. }
  288. excelService.toExcelError(errorList);
  289. }
  290. }
  291. private Integer saveBatchDetail(HashMap<Long, CameraDetail> detailMap, List<CameraInOutParam> params){
  292. List<CameraDetail> cameraDetails = new ArrayList<>();
  293. for (CameraInOutParam param : params) {
  294. CameraDetail cameraDetail = detailMap.get(param.getId());
  295. if(cameraDetail == null){
  296. throw new BusinessException(ResultCode.CAMERA_NOT_IN);
  297. }
  298. if(param.getAgentId() != null){
  299. cameraDetail.setAgentId(param.getAgentId());
  300. }
  301. cameraDetail.setOrderSn(param.getOrderSn());
  302. cameraDetail.setOwn(param.getOutType());
  303. cameraDetail.setCompanyId(param.getCompanyId());
  304. cameraDetail.setOutTime(Dateutils.getDate(new Date()));
  305. cameraDetails.add(cameraDetail);
  306. }
  307. return cameraDetailService.saveOrUpdateBatch(cameraDetails) ? cameraDetails.size() : 0;
  308. }
  309. private void checkSnCode(List<String> snCodeList,List<String> dbSnCode) {
  310. HashMap<String,Integer> map = new HashMap<>();
  311. List<Integer> errorList = new ArrayList<>();
  312. Integer index = 0;
  313. for (String snCode : snCodeList) {
  314. index ++;
  315. if(StringUtils.isBlank(snCode)){
  316. log.error("excel-export-error-->:index:{},snCode不存在:snCode:{}",index+3,snCode);
  317. errorList.add(index);
  318. }
  319. if(map.get(snCode) == null){
  320. map.put(snCode,1);
  321. }else {
  322. map.put(snCode,2);
  323. log.error("excel-export-error-->:index:{},snCode已存在:snCode:{}",index+3,snCode);
  324. errorList.add(index);
  325. }
  326. }
  327. excelService.toExcelError(errorList);
  328. Integer index2 = 0;
  329. for (String snCode : snCodeList) {
  330. index2 ++;
  331. if(!dbSnCode.contains(snCode)){
  332. log.error("excel-export-error-->:index:{},snCode未入库:snCode:{}",index2+3,snCode);
  333. errorList.add(index2);
  334. }
  335. }
  336. excelService.toExcelError(errorList);
  337. }
  338. @Override
  339. public void updateCamera(CameraInOutParam param) {
  340. if(param.getId() == null|| param.getOutType() == null){
  341. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  342. }
  343. CameraDetail cameraDetail = cameraDetailService.getByCameraId(param.getId());
  344. if(cameraDetail == null){
  345. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  346. }
  347. LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
  348. wrapper.eq(CameraDetail::getId,cameraDetail.getId());
  349. if(StringUtils.isNotBlank(param.getCompanyName())){
  350. Company company = companyService.getCompanyByName(param.getCompanyName());
  351. if(company == null){
  352. throw new BusinessException(ResultCode.COMPANY_NAME_NOT_EXIST);
  353. }
  354. wrapper.set(CameraDetail::getCompanyId,company.getId());
  355. }else {
  356. wrapper.set(CameraDetail::getCompanyId,null);
  357. }
  358. if(StringUtils.isNotBlank(param.getOrderSn())){
  359. Order orderSn = orderService.getByOrderSn(param.getOrderSn());
  360. if(orderSn == null ){
  361. throw new BusinessException(ResultCode.ORDER_SN_ERROR);
  362. }
  363. wrapper.set(CameraDetail::getOrderSn,orderSn.getOrderSn());
  364. }else {
  365. wrapper.set(CameraDetail::getOrderSn,null);
  366. }
  367. if(param.getAgentId() != null){
  368. wrapper.set(CameraDetail::getAgentId,param.getAgentId());
  369. }else {
  370. wrapper.set(CameraDetail::getAgentId,null);
  371. }
  372. wrapper.set(CameraDetail::getOwn,param.getOutType());
  373. cameraDetailService.update(wrapper);
  374. }
  375. @Override
  376. public void deleteCamera(Long id) {
  377. if(id == null){
  378. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  379. }
  380. CameraDetail cameraDetail = cameraDetailService.getByCameraId(id);
  381. if(cameraDetail !=null && cameraDetail.getUserId()!=null){
  382. throw new BusinessException(ResultCode.CAMERA_DEL_ERROR);
  383. }
  384. this.removeById(id);
  385. cameraDetailService.deleteByCameraId(id);
  386. }
  387. @Override
  388. public Integer updateCompany(List<CameraInOutParam> companyParams) {
  389. setCompanyIdByDb(companyParams);
  390. HashMap<String, Object> resultMap = getResultMap(companyParams,2);
  391. HashMap<Long, CameraDetail> detailMap = (HashMap<Long, CameraDetail>) resultMap.get("detailMap");
  392. HashMap<String, Camera> snCodeMap = (HashMap<String, Camera>) resultMap.get("snCodeMap");
  393. List<CameraDetail> updateDetailList = new ArrayList<>();
  394. for (CameraInOutParam companyParam : companyParams) {
  395. Camera camera = snCodeMap.get(companyParam.getSnCode());
  396. CameraDetail cameraDetail = detailMap.get(camera.getId());
  397. cameraDetail.setCompanyId(companyParam.getCompanyId());
  398. updateDetailList.add(cameraDetail);
  399. }
  400. return cameraDetailService.updateBatchById(updateDetailList) ? updateDetailList.size() : 0;
  401. }
  402. private void setCompanyIdByDb(List<CameraInOutParam> companyParams){
  403. List<String> companyNames = companyParams.parallelStream().map(CameraInOutParam::getCompanyName).collect(Collectors.toList());
  404. List<Company> companyList = companyService.getCompanyByNames(companyNames);
  405. HashMap<String,Long> companyNameMap = new HashMap<>();
  406. for (Company company : companyList) {
  407. companyNameMap.put(company.getCompanyName(),company.getId());
  408. }
  409. List<Integer> errorList = new ArrayList<>();
  410. Integer index = 0;
  411. for (CameraInOutParam companyParam : companyParams) {
  412. index ++;
  413. if(StringUtils.isNotBlank(companyParam.getCompanyName())){
  414. if(companyNameMap.get(companyParam.getCompanyName()) == null){
  415. log.error("outError-->出库错误:客户名称不存在:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
  416. ,companyParam.getSnCode(),companyParam.getOutType(),companyParam.getCompanyName(),companyParam.getOrderSn(),companyParam.getAgentId());
  417. errorList.add(index);
  418. }
  419. companyParam.setCompanyId(companyNameMap.get(companyParam.getCompanyName()));
  420. }
  421. }
  422. excelService.toExcelError(errorList);
  423. }
  424. private HashMap<String, Object> getResultMap(List<CameraInOutParam> params,Integer type){
  425. HashMap<String,Object> resultMap = new HashMap<>();
  426. List<String> snCodeList = params.parallelStream().map(CameraInOutParam::getSnCode).collect(Collectors.toList());
  427. List<Camera> cameraList = new ArrayList<>();
  428. if(type == 1){
  429. cameraList = this.getBySnCodes(snCodeList);
  430. }
  431. if(type == 2){
  432. cameraList = this.getByOutSnCodes(snCodeList);
  433. }
  434. checkSnCode(snCodeList,cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList()));
  435. List<Long> cameraIds = cameraList.parallelStream().map(Camera::getId).collect(Collectors.toList());
  436. List<CameraDetail> cameraDetails = cameraDetailService.getByCameraIds(cameraIds);
  437. HashMap<Long,CameraDetail> detailMap = new HashMap<>();
  438. for (CameraDetail cameraDetail : cameraDetails) {
  439. detailMap.put(cameraDetail.getCameraId(),cameraDetail);
  440. }
  441. HashMap<String,Camera> snCodeMap = new HashMap<>();
  442. for (Camera camera : cameraList) {
  443. snCodeMap.put(camera.getSnCode(),camera);
  444. }
  445. List<Integer> errorList = new ArrayList<>();
  446. for (String snCode : snCodeList) {
  447. Camera camera = snCodeMap.get(snCode);
  448. if(camera == null || detailMap.get(camera.getId()) ==null){
  449. log.error("excel-export-error-->:相机未入库:snCode:{}",snCode);
  450. errorList.add(snCodeList.indexOf(snCode) );
  451. }
  452. }
  453. excelService.toExcelError(errorList);
  454. resultMap.put("detailMap",detailMap);
  455. resultMap.put("snCodeMap",snCodeMap);
  456. return resultMap;
  457. }
  458. @Override
  459. public void initAllCameraSpace(Long userId) {
  460. List<Long> cameraIds ;
  461. List<CameraDetail> cameraDetails;
  462. if(userId != null){
  463. cameraDetails = cameraDetailService.getByUserId(userId);
  464. }else {
  465. List<Camera> list = this.list();
  466. cameraIds = list.stream().map(Camera::getId).collect(Collectors.toList());
  467. cameraDetails = cameraDetailService.getByCameraIds(cameraIds);
  468. }
  469. if(cameraDetails == null || cameraDetails.size() <=0){
  470. return;
  471. }
  472. HashMap<Long, Long> map = sceneProService.getSpaceGroupByCameraId();
  473. for (CameraDetail cameraDetail : cameraDetails) {
  474. Long space = map.get(cameraDetail.getCameraId());
  475. if(space != null){
  476. space = space > 0 ? space : 0;
  477. LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
  478. wrapper.eq(CameraDetail::getId,cameraDetail.getId());
  479. wrapper.set(CameraDetail::getUsedSpace,space);
  480. cameraDetailService.update(wrapper);
  481. }
  482. }
  483. }
  484. }