123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- package com.fdkankan.ucenter.service.impl;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.fdkankan.common.constant.SceneConstant;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.redis.util.RedisUtil;
- import com.fdkankan.ucenter.common.PageInfo;
- import com.fdkankan.ucenter.common.RedisKeyUtil;
- import com.fdkankan.ucenter.constant.LoginConstant;
- import com.fdkankan.ucenter.entity.*;
- import com.fdkankan.ucenter.httpClient.service.LaserService;
- import com.fdkankan.ucenter.mapper.ISceneCooperationMapper;
- import com.fdkankan.ucenter.service.*;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.ucenter.util.DateUserUtil;
- import com.fdkankan.ucenter.vo.request.SceneCooperationParam;
- import com.fdkankan.ucenter.vo.request.SceneParam;
- import com.google.common.collect.Lists;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.util.CollectionUtils;
- import org.springframework.util.ObjectUtils;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2022-07-04
- */
- @Service
- public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMapper, SceneCooperation> implements ISceneCooperationService {
- @Autowired
- ISceneProService sceneProService;
- @Autowired
- ISceneService sceneService;
- @Autowired
- IScenePlusService scenePlusService;
- @Autowired
- LaserService fdkkLaserService;
- @Autowired
- ISceneResourceCooperationService sceneResourceCooperationService;
- @Autowired
- ICameraService cameraService;
- @Autowired
- ICameraDetailService cameraDetailService;
- @Autowired
- ISceneResourceService sceneResourceService;
- @Autowired
- IUserService userService;
- @Autowired
- RedisUtil redisUtil;
- @Autowired
- IMailTemplateService mailTemplateService;
- @Override
- public Long getCooperationSceneNum(Long userId, List<Integer> sceneSourceList) {
- Long cooperationSceneProNum = this.getBaseMapper().getCooperationSceneProNum(userId, sceneSourceList);
- Long cooperationScenePlusNum = this.getBaseMapper().getCooperationScenePlusNum(userId, sceneSourceList);
- return cooperationSceneProNum + cooperationScenePlusNum;
- }
- @Override
- public void deleteCooperationList(List<ScenePro> sceneProList,List<ScenePlus> scenePlusList) {
- if(CollectionUtils.isEmpty(sceneProList) && CollectionUtils.isEmpty(scenePlusList)){
- return;
- }
- List<String> numList = sceneProList.stream().map(ScenePro::getNum).collect(Collectors.toList());
- List<String> numList2 = scenePlusList.stream().map(ScenePlus::getNum).collect(Collectors.toList());
- numList.addAll(numList2);
- LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(SceneCooperation::getSceneNum,numList);
- List<SceneCooperation> list = this.list(wrapper);
- List<Long> ids = list.stream().map(SceneCooperation::getId).collect(Collectors.toList());
- if(ids.size() >0){
- this.removeByIds(ids);
- sceneResourceCooperationService.deleteBatchByCooperationIds(ids);
- }
- for (String num : numList) {
- redisUtil.hdel(RedisKeyUtil.SCENE_COOPERATION_NUM_USERID,num);
- }
- }
- @Override
- public void saveBatchByList(List<ScenePro> sceneProList, List<ScenePlus> scenePlusList, Long userId,List<Long> resourceIdList) {
- List<SceneCooperation> list = new ArrayList<>();
- for (ScenePro scenePro : sceneProList) {
- SceneCooperation sceneCooperationEntity = new SceneCooperation();
- sceneCooperationEntity.setUserId(userId);
- sceneCooperationEntity.setSceneNum(scenePro.getNum());
- sceneCooperationEntity.setRecStatus("A");
- sceneCooperationEntity.setCreateTime(DateUserUtil.getDate(new Date()));
- sceneCooperationEntity.setUpdateTime(DateUserUtil.getDate(new Date()));
- list.add(sceneCooperationEntity);
- }
- for (ScenePlus scenePlus : scenePlusList) {
- SceneCooperation sceneCooperationEntity = new SceneCooperation();
- sceneCooperationEntity.setUserId(userId);
- sceneCooperationEntity.setSceneNum(scenePlus.getNum());
- sceneCooperationEntity.setRecStatus("A");
- sceneCooperationEntity.setCreateTime(DateUserUtil.getDate(new Date()));
- sceneCooperationEntity.setUpdateTime(DateUserUtil.getDate(new Date()));
- list.add(sceneCooperationEntity);
- }
- for (SceneCooperation sceneCooperation : list) {
- redisUtil.hset(RedisKeyUtil.SCENE_COOPERATION_NUM_USERID, sceneCooperation.getSceneNum(), sceneCooperation.getUserId() + "");
- }
- this.saveBatch(list);
- if(resourceIdList.size() >0){
- List<SceneResourceCooperation> resourceCooperationList = new ArrayList<>();
- for (SceneCooperation sceneCooperation : list) {
- for (Long resourceId : resourceIdList) {
- SceneResourceCooperation sceneResourceCooperation = new SceneResourceCooperation();
- sceneResourceCooperation.setSceneResourceId(resourceId);
- sceneResourceCooperation.setSceneCooperationId(sceneCooperation.getId());
- sceneResourceCooperation.setRecStatus("A");
- sceneResourceCooperation.setCreateTime(DateUserUtil.getDate(new Date()));
- sceneResourceCooperation.setUpdateTime(DateUserUtil.getDate(new Date()));
- resourceCooperationList.add(sceneResourceCooperation);
- }
- }
- if(resourceCooperationList.size() >0){
- sceneResourceCooperationService.saveBatch(resourceCooperationList,10000);
- }
- }
- }
- @Override
- public JSONObject sceneResourceList(SceneCooperationParam param) {
- JSONObject jsonObject = new JSONObject();
- List<SceneResource> exclude = new ArrayList<>();
- SceneResource excludeEntity = new SceneResource();
- excludeEntity.setKeyWord("data");
- exclude.add(excludeEntity);
- jsonObject.put("exclude", exclude);
- if(param.getCameraId() != null){
- Camera cameraEntity = cameraService.getById(param.getCameraId());
- if(cameraEntity != null){
- CameraDetail cameraDetailEntity = cameraDetailService.getByCameraId(cameraEntity.getId());
- if(cameraDetailEntity.getCompanyId() != null && cameraDetailEntity.getCompanyId() == 1){
- jsonObject.put("exclude", new ArrayList<>());
- }
- }
- }
- List<ScenePro> sceneProList;
- List<ScenePlus> scenePlusList;
- //如果是场景协作,判断是V3的场景还是V4的场景,如果是v4场景,则查询v4的菜单资源
- if(param.getType() != null && param.getType() == 1){
- if(StringUtils.isEmpty(param.getSceneNum()) && CollectionUtils.isEmpty(param.getNumList())){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- List<String> numList = param.getNumList();
- if(numList == null){
- numList= new ArrayList<>();
- numList.add(param.getSceneNum());
- }
- sceneProList = sceneProService.getListByNums(numList);
- scenePlusList = scenePlusService.getListByNums(numList);
- if(CollectionUtils.isEmpty(sceneProList) && CollectionUtils.isEmpty(scenePlusList)){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
- }
- }else {
- //如果是相机协作,判断这个相机id下有没有V4的场景,如果有,则列出对应的菜单资源
- if(ObjectUtils.isEmpty(param.getCameraId()) && CollectionUtils.isEmpty(param.getCameraIdList())){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- List<Long> cameraIdList = param.getCameraIdList();
- if(cameraIdList == null){
- cameraIdList= new ArrayList<>();
- cameraIdList.add(param.getCameraId());
- }
- sceneProList = sceneProService.getListByCameraIds(cameraIdList);
- scenePlusList = scenePlusService.getListByCameraIds(cameraIdList);
- }
- List<String> versionList = Lists.newArrayList();
- if(sceneProList.size() >0){
- versionList.add("v3");
- }
- if(scenePlusList.size() >0){
- versionList.add("v4");
- }
- if(versionList.size() <=0){
- versionList.add("v3");
- }
- List<SceneResource> results = sceneResourceService.getByVersion(versionList);
- jsonObject.put("include", results);
- return jsonObject;
- }
- @Override
- public JSONObject cooperationSceneListNew(SceneParam param, String username) {
- User user = userService.getByUserName(username);
- LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(SceneCooperation::getUserId,user.getId());
- List<SceneCooperation> list = this.list(wrapper);
- List<String> numList = list.parallelStream().map(SceneCooperation::getSceneNum).collect(Collectors.toList());
- if(numList.size() <=0){
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("list", new ArrayList<>());
- jsonObject.put("total",0);
- return jsonObject;
- }
- param.setNumList(numList);
- param.setHasFolder(0);
- JSONObject jsonObject = sceneProService.newList(param, username);
- return jsonObject.getJSONObject("pageInfo") ;
- }
- @Override
- public void saveCooperation(SceneCooperationParam param, String username) {
- if(StringUtils.isEmpty(param.getUserName()) || StringUtils.isEmpty(param.getSceneNum()) || StringUtils.isEmpty(param.getResourceIds())){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- if(param.getUserName().equals( username)){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3024, LoginConstant.FAILURE_MSG_3024);
- }
- User user = userService.getByUserName(param.getUserName());
- if(user == null){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3021, LoginConstant.FAILURE_MSG_3021);
- }
- String[] nums = param.getSceneNum().split(",");
- List<String> numList = Arrays.asList(nums);
- List<ScenePro> proList = sceneProService.getListByNums(numList);
- List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
- this.deleteCooperationList(proList,plusList);
- List<Long> resourceIdList = new ArrayList<>();
- if (StringUtils.isNotEmpty(param.getResourceIds())) {
- for (String rId : param.getResourceIds().split(",")) {
- resourceIdList.add(Long.valueOf(rId));
- }
- }
- this.saveBatchByList(proList,plusList,user.getId(),resourceIdList);
- mailTemplateService.sendSceneCooperation(proList,plusList,param.getUserName(),param.getLang());
- }
- @Override
- public void deleteCooperation(SceneCooperationParam param, String username) {
- if(StringUtils.isEmpty(param.getSceneNum())){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- String[] nums = param.getSceneNum().split(",");
- List<String> numList = Arrays.asList(nums);
- List<ScenePro> proList = sceneProService.getListByNums(numList);
- List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
- this.deleteCooperationList(proList,plusList);
- }
- @Override
- public List<SceneResource> getResourceByNum(String sceneNum) {
- if(StringUtils.isEmpty(sceneNum)){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(SceneCooperation::getSceneNum,sceneNum);
- List<SceneCooperation> list = this.list(wrapper);
- if(list == null || list.size()<=0){
- return new ArrayList<>();
- }
- return sceneResourceService.getByCooperationId(list.get(0).getId());
- }
- @Override
- public List<String> getNumByUserIds(List<Long> userIds) {
- LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(SceneCooperation::getUserId,userIds);
- Set<String> collect = this.list(wrapper).parallelStream().map(SceneCooperation::getSceneNum).collect(Collectors.toSet());
- return new ArrayList<>(collect);
- }
- @Override
- public HashMap<String, User> getByNumList(List<String> numList) {
- LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(SceneCooperation::getSceneNum,numList);
- List<SceneCooperation> list = this.list(wrapper);
- HashMap<String,User> cooMap = new HashMap<>();
- if(list.size() >0){
- List<Long> userIds = list.parallelStream().map(SceneCooperation::getUserId).collect(Collectors.toList());
- if(userIds.size() >0){
- HashMap<Long, User> userMap = userService.getByIds(userIds);
- list.forEach(entity -> cooMap.put(entity.getSceneNum(),userMap.get(entity.getUserId())));
- }
- }
- return cooMap;
- }
- @Override
- public SceneCooperation getByNum(String num) {
- LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(SceneCooperation::getSceneNum,num);
- List<SceneCooperation> list = this.list(wrapper);
- if(list == null || list.size() <=0){
- return null;
- }
- return list.get(0);
- }
- @Override
- public Object cooperationSceneList(SceneParam param, String username) {
- return null;
- }
- }
|