|
@@ -3,13 +3,15 @@ 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.common.SceneSourceUtil;
|
|
|
import com.fdkankan.ucenter.common.constants.NacosProperty;
|
|
|
+import com.fdkankan.ucenter.common.constants.ResultCode;
|
|
|
import com.fdkankan.ucenter.constant.LoginConstant;
|
|
|
import com.fdkankan.ucenter.entity.*;
|
|
|
+import com.fdkankan.ucenter.exception.BusinessException;
|
|
|
import com.fdkankan.ucenter.httpClient.service.LaserService;
|
|
|
import com.fdkankan.ucenter.mapper.ISceneCooperationMapper;
|
|
|
import com.fdkankan.ucenter.service.*;
|
|
@@ -18,7 +20,9 @@ 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 com.sun.org.apache.bcel.internal.generic.RET;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.opencv.face.Face;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
@@ -60,6 +64,12 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
|
|
|
RedisUtil redisUtil;
|
|
|
@Autowired
|
|
|
IMailTemplateService mailTemplateService;
|
|
|
+ @Autowired
|
|
|
+ IProductOrderService productOrderService;
|
|
|
+ @Autowired
|
|
|
+ IProductCooperationService productCooperationService;
|
|
|
+ @Autowired
|
|
|
+ ISceneCooperationCountService sceneCooperationCountService;
|
|
|
|
|
|
@Override
|
|
|
public Long getCooperationSceneNum(Long userId, List<Integer> sceneSourceList) {
|
|
@@ -69,15 +79,29 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void deleteCooperationList(List<ScenePro> sceneProList,List<ScenePlus> scenePlusList) {
|
|
|
+ public void deleteCooperationList(List<ScenePro> sceneProList,List<ScenePlus> scenePlusList,List<Long> userIds) {
|
|
|
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);
|
|
|
+ this.deleteCooperationList(numList,userIds,null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteCooperationList(List<String> numList,List<Long> userIds,String sceneType) {
|
|
|
+ if(CollectionUtils.isEmpty(numList) ){
|
|
|
+ return;
|
|
|
+ }
|
|
|
LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.in(SceneCooperation::getSceneNum,numList);
|
|
|
+ if(sceneType != null){
|
|
|
+ wrapper.eq(SceneCooperation::getSceneType,sceneType);
|
|
|
+ }
|
|
|
+ if(userIds != null && !userIds.isEmpty()){
|
|
|
+ wrapper.in(SceneCooperation::getUserId,userIds);
|
|
|
+ }
|
|
|
List<SceneCooperation> list = this.list(wrapper);
|
|
|
List<Long> ids = list.stream().map(SceneCooperation::getId).collect(Collectors.toList());
|
|
|
if(ids.size() >0){
|
|
@@ -90,48 +114,61 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void saveBatchByList(List<ScenePro> sceneProList, List<ScenePlus> scenePlusList, Long userId,List<Long> resourceIdList) {
|
|
|
+ public List<SceneCooperation> saveBatchByList(List<String> numList, List<Long> userIds,String type,String sceneType) {
|
|
|
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);
|
|
|
+ List<String> delList = new ArrayList<>();
|
|
|
+
|
|
|
+ HashMap<String, List<User>> byNumList = this.getByNumList(numList,sceneType);
|
|
|
+
|
|
|
+
|
|
|
+ for (Long userId : userIds) {
|
|
|
+ for (String num : numList) {
|
|
|
+ List<User> users = byNumList.get(num);
|
|
|
+ if(users != null && !users.isEmpty()){
|
|
|
+ List<Long> collect1 = users.stream().map(User::getId).collect(Collectors.toList());
|
|
|
+ if("scene".equals(type) && numList.size() == 1){
|
|
|
+ for (Long l : collect1) {
|
|
|
+ if(!userIds.contains(l)){
|
|
|
+ delList.add(num + "," +l);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(collect1.contains(userId)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ SceneCooperation sceneCooperationEntity = new SceneCooperation();
|
|
|
+ sceneCooperationEntity.setUserId(userId);
|
|
|
+ sceneCooperationEntity.setSceneNum(num);
|
|
|
+ sceneCooperationEntity.setSceneType(sceneType);
|
|
|
+ sceneCooperationEntity.setRecStatus("A");
|
|
|
+ sceneCooperationEntity.setCreateTime(DateUserUtil.getDate(new Date()));
|
|
|
+ sceneCooperationEntity.setUpdateTime(DateUserUtil.getDate(new Date()));
|
|
|
+ list.add(sceneCooperationEntity);
|
|
|
}
|
|
|
- if(resourceCooperationList.size() >0){
|
|
|
- sceneResourceCooperationService.saveBatch(resourceCooperationList,10000);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!list.isEmpty()){
|
|
|
+ for (SceneCooperation sceneCooperation : list) {
|
|
|
+ redisUtil.hset(RedisKeyUtil.SCENE_COOPERATION_NUM_USERID, sceneCooperation.getSceneNum(), sceneCooperation.getUserId() + "");
|
|
|
}
|
|
|
+ this.saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String num : delList) {
|
|
|
+ String[] split = num.split(",");
|
|
|
+ delCooperation(split[0],Long.valueOf(split[1]));
|
|
|
}
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void delCooperation(String num ,Long userId){
|
|
|
+ redisUtil.hdel(RedisKeyUtil.SCENE_COOPERATION_NUM_USERID,num,userId.toString());
|
|
|
+ LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SceneCooperation::getSceneNum,num);
|
|
|
+ wrapper.eq(SceneCooperation::getUserId,userId);
|
|
|
+ this.remove(wrapper);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -205,6 +242,7 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
|
|
|
User user = userService.getByUserName(username);
|
|
|
LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(SceneCooperation::getUserId,user.getId());
|
|
|
+ wrapper.eq(SceneCooperation::getSceneType,"mesh");
|
|
|
List<SceneCooperation> list = this.list(wrapper);
|
|
|
List<String> numList = list.parallelStream().map(SceneCooperation::getSceneNum).collect(Collectors.toList());
|
|
|
if(numList.size() <=0){
|
|
@@ -220,13 +258,15 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void saveCooperation(SceneCooperationParam param, String username) {
|
|
|
- if(StringUtils.isEmpty(param.getUserName()) || StringUtils.isEmpty(param.getSceneNum()) || StringUtils.isEmpty(param.getResourceIds())){
|
|
|
+ public void saveCooperation(SceneCooperationParam param, String loginUserName) {
|
|
|
+ if(StringUtils.isEmpty(param.getUserName()) || StringUtils.isEmpty(param.getSceneNum())){
|
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
}
|
|
|
- if(param.getUserName().equals( username)){
|
|
|
+ if(param.getUserName().equals( loginUserName)){
|
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3024, LoginConstant.FAILURE_MSG_3024);
|
|
|
}
|
|
|
+ User loginUser = userService.getByUserName(loginUserName);
|
|
|
+
|
|
|
User user = userService.getByUserName(param.getUserName());
|
|
|
if(user == null){
|
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3021, LoginConstant.FAILURE_MSG_3021);
|
|
@@ -235,32 +275,262 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
|
|
|
List<String> numList = Arrays.asList(nums);
|
|
|
List<ScenePro> proList = sceneProService.getListByNums(numList);
|
|
|
List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
|
|
|
- this.deleteCooperationList(proList,plusList);
|
|
|
-
|
|
|
- List<SceneResource> v3List = new ArrayList<>();
|
|
|
- List<SceneResource> v4List = new ArrayList<>();
|
|
|
- List<Long> resourceIdList = new ArrayList<>();
|
|
|
- if (StringUtils.isNotEmpty(param.getResourceIds())) {
|
|
|
- for (String rId : param.getResourceIds().split(",")) {
|
|
|
- resourceIdList.add(Long.valueOf(rId));
|
|
|
+ //this.deleteCooperationList(proList,plusList,Arrays.asList(user.getId()));
|
|
|
+
|
|
|
+ saveCooperationCommon(loginUser,param.getLang(),Arrays.asList(user),proList,plusList,null,"scene","mesh");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ProductOrder saveBatchCooperation(SceneCooperationParam param, String loginUserName) {
|
|
|
+ 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);
|
|
|
+
|
|
|
+ if(param.getUserNameList() == null || param.getUserNameList().isEmpty()){
|
|
|
+ this.deleteCooperationList(numList,null,param.getSceneType());
|
|
|
+ laserService.saveBatchCooperation(numList,new ArrayList<>(),param.getUserNameList(),"scene","update");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(param.getUserNameList().contains( loginUserName)){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3024, LoginConstant.FAILURE_MSG_3024);
|
|
|
+ }
|
|
|
+ if(param.getUserNameList().size() != new HashSet<>(param.getUserNameList()).size()){
|
|
|
+ throw new BusinessException(ResultCode.COO_LIMIT_ERROR2);
|
|
|
+ }
|
|
|
+ if(param.getUserNameList().size() >5){
|
|
|
+ throw new BusinessException(ResultCode.COO_LIMIT_ERROR);
|
|
|
+ }
|
|
|
+ User loginUser = userService.getByUserName(loginUserName);
|
|
|
+ if(numList.size() >1){
|
|
|
+ HashMap<String, List<User>> byNumList = this.getByNumList(numList, param.getSceneType());
|
|
|
+ for (String num : numList) {
|
|
|
+ if(byNumList.get(num) != null && !byNumList.isEmpty()) {
|
|
|
+ if (byNumList.get(num).size() + param.getUserNameList().size() > 5) {
|
|
|
+ throw new BusinessException(ResultCode.COO_LIMIT_ERROR);
|
|
|
+ }
|
|
|
+ List<User> users = byNumList.get(num);
|
|
|
+ Set<String> collect = users.stream().map(User::getUserName).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ if(collect.containsAll(param.getUserNameList())){
|
|
|
+ throw new BusinessException(ResultCode.COO_LIMIT_ERROR2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<User> users = new ArrayList<>();
|
|
|
+ for (String userName : param.getUserNameList()) {
|
|
|
+ User user = userService.getByUserName(userName);
|
|
|
+ if(user == null){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3021, LoginConstant.FAILURE_MSG_3021);
|
|
|
}
|
|
|
- List<SceneResource> sceneResources = sceneResourceService.listByIds(resourceIdList);
|
|
|
- v3List = sceneResources.stream().filter(entity -> entity.getVersion().equals("v3")).collect(Collectors.toList());
|
|
|
- v4List = sceneResources.stream().filter(entity -> entity.getVersion().equals("v4")).collect(Collectors.toList());
|
|
|
+ users.add(user);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ProductOrder productOrder = checkNeedPay(numList, users, loginUser, param.getPayType(), param.getTimeZone(),null,param.getLang(),param.getSceneType());
|
|
|
+
|
|
|
+ if(productOrder == null){
|
|
|
+ successAddCooperation(numList,users,param.getLang(),loginUser,param.getSceneType());
|
|
|
}
|
|
|
+ return productOrder;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- if(!v3List.isEmpty() && !proList.isEmpty()){
|
|
|
- List<Long> v3Ids = v3List.stream().map(SceneResource::getId).collect(Collectors.toList());
|
|
|
- this.saveBatchByList(proList,new ArrayList<>(),user.getId(),v3Ids);
|
|
|
+ @Override
|
|
|
+ public ProductOrder saveCamera(SceneCooperationParam param, String loginUserName) {
|
|
|
+ if(param.getCameraId() == null || StringUtils.isEmpty(param.getUserName())){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
+ }
|
|
|
+ if(param.getUserName().equals( loginUserName)){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3025, LoginConstant.FAILURE_MSG_3025);
|
|
|
+ }
|
|
|
+ User user = userService.getByUserName(param.getUserName());
|
|
|
+ if(user == null){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3015,LoginConstant.FAILURE_MSG_3015);
|
|
|
+ }
|
|
|
+ User loginUser = userService.getByUserName(loginUserName);
|
|
|
+ Camera camera = cameraService.getById(param.getCameraId());
|
|
|
+ CameraDetail cameraDetail = cameraDetailService.getByCameraId(param.getCameraId());
|
|
|
+ if(camera == null || cameraDetail == null || cameraDetail.getUserId() == null){
|
|
|
+ throw new BusinessException(ResultCode.CAMERA_NOT_EXIT);
|
|
|
+ }
|
|
|
+ if(!loginUser.getId().equals(cameraDetail.getUserId())){
|
|
|
+ throw new BusinessException(ResultCode.NOT_PER);
|
|
|
}
|
|
|
- if(!v4List.isEmpty() && !plusList.isEmpty()){
|
|
|
- List<Long> v4Ids = v4List.stream().map(SceneResource::getId).collect(Collectors.toList());
|
|
|
- this.saveBatchByList(new ArrayList<>(),plusList,user.getId(),v4Ids);
|
|
|
+ if(cameraDetail.getCooperationUser() != null){
|
|
|
+ throw new BusinessException(ResultCode.COO_ERROR);
|
|
|
}
|
|
|
|
|
|
- if("aws".equals(NacosProperty.uploadType)){
|
|
|
- mailTemplateService.sendSceneCooperation(proList,plusList,param.getUserName(),param.getLang());
|
|
|
+ List<ScenePro> v3List = sceneProService.getListByCameraId(param.getCameraId());
|
|
|
+ List<ScenePlus> v4List = scenePlusService.getListByCameraId(param.getCameraId());
|
|
|
+ List<String> v3NumList = v3List.stream().map(ScenePro::getNum).collect(Collectors.toList());
|
|
|
+ List<String> v4NumList = v4List.stream().map(ScenePlus::getNum).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<String> allList = new ArrayList<>();
|
|
|
+ allList.addAll(v3NumList);
|
|
|
+ allList.addAll(v4NumList);
|
|
|
+
|
|
|
+ ProductOrder productOrder = checkNeedPay(allList, Arrays.asList(user), loginUser, param.getPayType(), param.getTimeZone(),param.getCameraId(),param.getLang(),null);
|
|
|
+ if(productOrder == null){
|
|
|
+ successAddCooperation(v3List,v4List,Arrays.asList(user),param.getLang(),loginUser,Arrays.asList(camera),null);
|
|
|
+ cameraDetailService.updateCooperationByIds(Arrays.asList(param.getCameraId()),user.getId());
|
|
|
}
|
|
|
+
|
|
|
+ return productOrder;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void successAddCooperation(List<String> numList, List<User> users, String lang, User loginUser,String sceneType){
|
|
|
+ List<ScenePro> proList = sceneProService.getListByNums(numList);
|
|
|
+ List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
|
|
|
+ List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
|
|
|
+ //this.deleteCooperationList(proList,plusList,userIds);
|
|
|
+
|
|
|
+ saveCooperationCommon(loginUser,lang,users,proList,plusList,null,"scene",sceneType);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void successAddCooperation(List<String> numList,List<Long> userIds,Long loginUserId,Long cameraId,String lang,String sceneType,List<ProductCooperation> needPay ){
|
|
|
+ //this.deleteCooperationList(numList,userIds);
|
|
|
+ List<ScenePro> proList = sceneProService.getListByNums(numList);
|
|
|
+ List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
|
|
|
+ List<User> users = userService.listByIds(userIds);
|
|
|
+ User user = userService.getById(loginUserId);
|
|
|
+ if(cameraId != null ){
|
|
|
+ Camera camera = cameraService.getById(cameraId);
|
|
|
+ saveCooperationCommon(user,lang,users,proList,plusList,Arrays.asList(camera),"camera",sceneType);
|
|
|
+ cameraDetailService.updateCooperationByIds(Arrays.asList(cameraId),userIds.get(0));
|
|
|
+ }else {
|
|
|
+ saveCooperationCommon(user,lang,users,proList,plusList,null,"scene",sceneType);
|
|
|
+ }
|
|
|
+ sceneCooperationCountService.saveCount(needPay,userIds.size());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void successAddCooperation(List<ScenePro> v3List,List<ScenePlus> v4List,List<User> users,String lang,User loginUser,List<Camera>cameraList,String sceneType){
|
|
|
+ List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
|
|
|
+ //this.deleteCooperationList(v3List,v4List,userIds);
|
|
|
+ saveCooperationCommon(loginUser,lang,users,v3List,v4List,cameraList,"camera",sceneType);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private ProductOrder checkNeedPay(List<String> numList, List<User> users,User loginUser,Integer payType,Integer timeZone,Long cameraId,String lang,String sceneType) {
|
|
|
+ HashMap<String,String> needNumListMesh = new HashMap<>();
|
|
|
+ HashMap<String,String> needNumListLaser =new HashMap<>();
|
|
|
+ if(StringUtils.isBlank(sceneType)){
|
|
|
+ needNumListMesh = getTotalCount(numList,users,"mesh",cameraId);
|
|
|
+ needNumListLaser = getTotalCount(numList,users,"laser",cameraId);
|
|
|
+ }else {
|
|
|
+ needNumListMesh = getTotalCount(numList,users,sceneType,cameraId);
|
|
|
+ }
|
|
|
+ if(needNumListMesh.size() + needNumListLaser.size()<=0){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ ProductOrder productOrder = productOrderService.createOrder(needNumListMesh.size() + needNumListLaser.size(), "cooperation", loginUser, payType, timeZone, cameraId, lang, sceneType);
|
|
|
+ productCooperationService.add(productOrder,users,numList,needNumListMesh,needNumListLaser,sceneType);
|
|
|
+ return productOrder;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private HashMap<String,String> getTotalCount(List<String> numList, List<User> users,String sceneType,Long cameraId){
|
|
|
+ List<SceneCooperationCount> freeCountList = sceneCooperationCountService.getByNumList(numList,sceneType);
|
|
|
+ HashMap<String,Integer> freeMap = new HashMap<>();
|
|
|
+ freeCountList.forEach(e -> freeMap.put(e.getNum(),e.getCount()));
|
|
|
+
|
|
|
+ HashMap<String, List<User>> map = this.getByNumList(numList,sceneType);
|
|
|
+ HashMap<String,String> needNumList = new HashMap<>();
|
|
|
+ for (String num : numList) {
|
|
|
+ Integer freeCount = freeMap.get(num) == null ? 1 :freeMap.get(num);
|
|
|
+
|
|
|
+ List<User> dbUserList = map.get(num);
|
|
|
+
|
|
|
+ if(dbUserList != null && !dbUserList.isEmpty()){
|
|
|
+ List<Long> dbUserIds = dbUserList.stream().map(User::getId).collect(Collectors.toList());
|
|
|
+ HashMap<Long,User> userHashMap = new HashMap<>();
|
|
|
+ for (User user : users) {
|
|
|
+ if(dbUserIds.contains(user.getId())){
|
|
|
+ userHashMap.put(user.getId(),user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer totalSize = dbUserList.size() - userHashMap.size();
|
|
|
+
|
|
|
+ if(numList.size() >1){
|
|
|
+ freeCount = (totalSize > freeCount ? totalSize : (freeCount - totalSize));
|
|
|
+ }else {
|
|
|
+ freeCount = (totalSize > freeCount ? totalSize : freeCount) ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0 ; i< users.size() - freeCount;i++){
|
|
|
+ needNumList.put(users.get(i).getId()+","+num,num);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return needNumList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ LaserService laserService;
|
|
|
+
|
|
|
+ private void saveCooperationCommon(User LoginUser,String lang,List<User> userList,List<ScenePro> proList, List<ScenePlus> plusList,List<Camera >cameraList,String type,String sceneType){
|
|
|
+
|
|
|
+ List<Long> userIds = userList.stream().map(User::getId).collect(Collectors.toList());
|
|
|
+ Set<String> numList = new HashSet<>();
|
|
|
+ List<String> v3List = proList.stream().map(ScenePro::getNum).collect(Collectors.toList());
|
|
|
+ List<String> v4List = plusList.stream().map(ScenePlus::getNum).collect(Collectors.toList());
|
|
|
+ numList.addAll(v3List);
|
|
|
+ numList.addAll(v4List);
|
|
|
+
|
|
|
+ List<ScenePro> collect1 = proList.stream().filter(e -> SceneSourceUtil.getLaserList().contains(e.getSceneSource())).collect(Collectors.toList());
|
|
|
+ List<ScenePlus> collect2 = plusList.stream().filter(e -> SceneSourceUtil.getLaserList().contains(e.getSceneSource())).collect(Collectors.toList());
|
|
|
+ Set<String> numList1 = collect1.stream().map(ScenePro::getNum).collect(Collectors.toSet());
|
|
|
+ Set<String> numList2 = collect2.stream().map(ScenePlus::getNum).collect(Collectors.toSet());
|
|
|
+ numList1.addAll(numList2);
|
|
|
+
|
|
|
+
|
|
|
+ List<SceneCooperation> addList =new ArrayList<>();
|
|
|
+ if( !numList.isEmpty()){
|
|
|
+ if(StringUtils.isBlank(sceneType)){
|
|
|
+ addList = this.saveBatchByList(new ArrayList<>(numList), userIds, type,"mesh");
|
|
|
+ if(!numList1.isEmpty()){
|
|
|
+ this.saveBatchByList(new ArrayList<>(numList1), userIds, type,"laser");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ addList = this.saveBatchByList(new ArrayList<>(numList), userIds, type,sceneType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Long> collect3 = addList.stream().map(SceneCooperation::getUserId).collect(Collectors.toList());
|
|
|
+ for (User user : userList) {
|
|
|
+ if("aws".equals(NacosProperty.uploadType)){
|
|
|
+ if("camera".equals(type) && cameraList != null){
|
|
|
+ HashMap<Long, Camera> cameraMap = new HashMap<>();
|
|
|
+ cameraList.forEach(e -> cameraMap.put(e.getId(),e));
|
|
|
+ mailTemplateService.sendCameraCooperation(cameraMap,user.getUserName(),lang);
|
|
|
+ }else {
|
|
|
+ if(collect3.contains(user.getId())){
|
|
|
+ mailTemplateService.sendSceneCooperation(proList,plusList,user.getUserName(),lang);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<String> collect = userList.stream().map(User::getUserName).collect(Collectors.toList());
|
|
|
+ List<String> snCodeList = new ArrayList<>();
|
|
|
+ if(cameraList !=null ){
|
|
|
+ snCodeList = cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(sceneType) && "mesh".equals(sceneType)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String operatingMode = numList.size() > 1 ? "add" :"update";
|
|
|
+ laserService.saveBatchCooperation(new ArrayList<>(numList1),snCodeList,collect,type,operatingMode);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -272,7 +542,7 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
|
|
|
List<String> numList = Arrays.asList(nums);
|
|
|
List<ScenePro> proList = sceneProService.getListByNums(numList);
|
|
|
List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
|
|
|
- this.deleteCooperationList(proList,plusList);
|
|
|
+ this.deleteCooperationList(proList,plusList,null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -298,30 +568,40 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HashMap<String, User> getByNumList(List<String> numList) {
|
|
|
+ public HashMap<String, List<User>> getByNumList(List<String> numList,String sceneType) {
|
|
|
+ if(numList == null || numList.isEmpty()){
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.in(SceneCooperation::getSceneNum,numList);
|
|
|
+ if(StringUtils.isNotBlank(sceneType)){
|
|
|
+ wrapper.eq(SceneCooperation::getSceneType,sceneType);
|
|
|
+ }
|
|
|
List<SceneCooperation> list = this.list(wrapper);
|
|
|
- HashMap<String,User> cooMap = new HashMap<>();
|
|
|
+ HashMap<String,List<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())));
|
|
|
+ for (SceneCooperation entity : list) {
|
|
|
+ User user = userMap.get(entity.getUserId());
|
|
|
+ cooMap.computeIfAbsent(entity.getSceneNum(), k -> new ArrayList<>());
|
|
|
+ if(!cooMap.get(entity.getSceneNum()).contains(user)){
|
|
|
+ cooMap.get(entity.getSceneNum()).add(user);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return cooMap;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public SceneCooperation getByNum(String num) {
|
|
|
+ public List<SceneCooperation> getByNum(String num,String sceneType) {
|
|
|
LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(SceneCooperation::getSceneNum,num);
|
|
|
+ wrapper.eq(SceneCooperation::getSceneType,sceneType);
|
|
|
List<SceneCooperation> list = this.list(wrapper);
|
|
|
- if(list == null || list.size() <=0){
|
|
|
- return null;
|
|
|
- }
|
|
|
- return list.get(0);
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
@Override
|