SceneCooperationServiceImpl.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. package com.fdkankan.ucenter.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.fdkankan.common.constant.SceneConstant;
  5. import com.fdkankan.redis.util.RedisUtil;
  6. import com.fdkankan.ucenter.common.PageInfo;
  7. import com.fdkankan.ucenter.common.RedisKeyUtil;
  8. import com.fdkankan.ucenter.common.SceneSourceUtil;
  9. import com.fdkankan.ucenter.common.constants.NacosProperty;
  10. import com.fdkankan.ucenter.common.constants.ResultCode;
  11. import com.fdkankan.ucenter.constant.LoginConstant;
  12. import com.fdkankan.ucenter.entity.*;
  13. import com.fdkankan.ucenter.exception.BusinessException;
  14. import com.fdkankan.ucenter.httpClient.service.LaserService;
  15. import com.fdkankan.ucenter.mapper.ISceneCooperationMapper;
  16. import com.fdkankan.ucenter.service.*;
  17. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  18. import com.fdkankan.ucenter.util.DateUserUtil;
  19. import com.fdkankan.ucenter.vo.request.SceneCooperationParam;
  20. import com.fdkankan.ucenter.vo.request.SceneParam;
  21. import com.google.common.collect.Lists;
  22. import com.sun.org.apache.bcel.internal.generic.RET;
  23. import org.apache.commons.lang3.StringUtils;
  24. import org.opencv.face.Face;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Service;
  27. import org.springframework.util.CollectionUtils;
  28. import org.springframework.util.ObjectUtils;
  29. import java.util.*;
  30. import java.util.stream.Collectors;
  31. /**
  32. * <p>
  33. * 服务实现类
  34. * </p>
  35. *
  36. * @author
  37. * @since 2022-07-04
  38. */
  39. @Service
  40. public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMapper, SceneCooperation> implements ISceneCooperationService {
  41. @Autowired
  42. ISceneProService sceneProService;
  43. @Autowired
  44. ISceneService sceneService;
  45. @Autowired
  46. IScenePlusService scenePlusService;
  47. @Autowired
  48. LaserService fdkkLaserService;
  49. @Autowired
  50. ISceneResourceCooperationService sceneResourceCooperationService;
  51. @Autowired
  52. ICameraService cameraService;
  53. @Autowired
  54. ICameraDetailService cameraDetailService;
  55. @Autowired
  56. ISceneResourceService sceneResourceService;
  57. @Autowired
  58. IUserService userService;
  59. @Autowired
  60. RedisUtil redisUtil;
  61. @Autowired
  62. IMailTemplateService mailTemplateService;
  63. @Autowired
  64. IProductOrderService productOrderService;
  65. @Autowired
  66. IProductCooperationService productCooperationService;
  67. @Autowired
  68. ISceneCooperationCountService sceneCooperationCountService;
  69. @Override
  70. public Long getCooperationSceneNum(Long userId, List<Integer> sceneSourceList) {
  71. Long cooperationSceneProNum = this.getBaseMapper().getCooperationSceneProNum(userId, sceneSourceList);
  72. Long cooperationScenePlusNum = this.getBaseMapper().getCooperationScenePlusNum(userId, sceneSourceList);
  73. return cooperationSceneProNum + cooperationScenePlusNum;
  74. }
  75. @Override
  76. public void deleteCooperationList(List<ScenePro> sceneProList,List<ScenePlus> scenePlusList,List<Long> userIds) {
  77. if(CollectionUtils.isEmpty(sceneProList) && CollectionUtils.isEmpty(scenePlusList)){
  78. return;
  79. }
  80. List<String> numList = sceneProList.stream().map(ScenePro::getNum).collect(Collectors.toList());
  81. List<String> numList2 = scenePlusList.stream().map(ScenePlus::getNum).collect(Collectors.toList());
  82. numList.addAll(numList2);
  83. this.deleteCooperationList(numList,userIds);
  84. }
  85. @Override
  86. public void deleteCooperationList(List<String> numList,List<Long> userIds) {
  87. if(CollectionUtils.isEmpty(numList) ){
  88. return;
  89. }
  90. LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
  91. wrapper.in(SceneCooperation::getSceneNum,numList);
  92. if(userIds != null && !userIds.isEmpty()){
  93. wrapper.in(SceneCooperation::getUserId,userIds);
  94. }
  95. List<SceneCooperation> list = this.list(wrapper);
  96. List<Long> ids = list.stream().map(SceneCooperation::getId).collect(Collectors.toList());
  97. if(ids.size() >0){
  98. this.removeByIds(ids);
  99. sceneResourceCooperationService.deleteBatchByCooperationIds(ids);
  100. }
  101. for (String num : numList) {
  102. redisUtil.hdel(RedisKeyUtil.SCENE_COOPERATION_NUM_USERID,num);
  103. }
  104. }
  105. @Override
  106. public List<SceneCooperation> saveBatchByList(List<String> numList, List<Long> userIds,String type,String sceneType) {
  107. List<SceneCooperation> list = new ArrayList<>();
  108. List<String> delList = new ArrayList<>();
  109. HashMap<String, List<User>> byNumList = this.getByNumList(numList,sceneType);
  110. for (Long userId : userIds) {
  111. for (String num : numList) {
  112. List<User> users = byNumList.get(num);
  113. if(users != null && !users.isEmpty()){
  114. List<Long> collect1 = users.stream().map(User::getId).collect(Collectors.toList());
  115. if("scene".equals(type) && numList.size() == 1){
  116. for (Long l : collect1) {
  117. if(!userIds.contains(l)){
  118. delList.add(num + "," +l);
  119. }
  120. }
  121. }
  122. if(collect1.contains(userId)){
  123. continue;
  124. }
  125. }
  126. SceneCooperation sceneCooperationEntity = new SceneCooperation();
  127. sceneCooperationEntity.setUserId(userId);
  128. sceneCooperationEntity.setSceneNum(num);
  129. sceneCooperationEntity.setSceneType(sceneType);
  130. sceneCooperationEntity.setRecStatus("A");
  131. sceneCooperationEntity.setCreateTime(DateUserUtil.getDate(new Date()));
  132. sceneCooperationEntity.setUpdateTime(DateUserUtil.getDate(new Date()));
  133. list.add(sceneCooperationEntity);
  134. }
  135. }
  136. if(!list.isEmpty()){
  137. for (SceneCooperation sceneCooperation : list) {
  138. redisUtil.hset(RedisKeyUtil.SCENE_COOPERATION_NUM_USERID, sceneCooperation.getSceneNum(), sceneCooperation.getUserId() + "");
  139. }
  140. this.saveBatch(list);
  141. }
  142. for (String num : delList) {
  143. String[] split = num.split(",");
  144. delCooperation(split[0],Long.valueOf(split[1]));
  145. }
  146. return list;
  147. }
  148. private void delCooperation(String num ,Long userId){
  149. redisUtil.hdel(RedisKeyUtil.SCENE_COOPERATION_NUM_USERID,num,userId.toString());
  150. LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
  151. wrapper.eq(SceneCooperation::getSceneNum,num);
  152. wrapper.eq(SceneCooperation::getUserId,userId);
  153. this.remove(wrapper);
  154. }
  155. @Override
  156. public JSONObject sceneResourceList(SceneCooperationParam param) {
  157. JSONObject jsonObject = new JSONObject();
  158. List<SceneResource> exclude = new ArrayList<>();
  159. SceneResource excludeEntity = new SceneResource();
  160. excludeEntity.setKeyWord("data");
  161. exclude.add(excludeEntity);
  162. jsonObject.put("exclude", exclude);
  163. if(param.getCameraId() != null){
  164. Camera cameraEntity = cameraService.getById(param.getCameraId());
  165. if(cameraEntity != null){
  166. CameraDetail cameraDetailEntity = cameraDetailService.getByCameraId(cameraEntity.getId());
  167. if(cameraDetailEntity.getCompanyId() != null && cameraDetailEntity.getCompanyId() == 1){
  168. jsonObject.put("exclude", new ArrayList<>());
  169. }
  170. }
  171. }
  172. List<ScenePro> sceneProList;
  173. List<ScenePlus> scenePlusList;
  174. //如果是场景协作,判断是V3的场景还是V4的场景,如果是v4场景,则查询v4的菜单资源
  175. if(param.getType() != null && param.getType() == 1){
  176. if(StringUtils.isEmpty(param.getSceneNum()) && CollectionUtils.isEmpty(param.getNumList())){
  177. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  178. }
  179. List<String> numList = param.getNumList();
  180. if(numList == null){
  181. numList= new ArrayList<>();
  182. numList.add(param.getSceneNum());
  183. }
  184. sceneProList = sceneProService.getListByNums(numList);
  185. scenePlusList = scenePlusService.getListByNums(numList);
  186. if(CollectionUtils.isEmpty(sceneProList) && CollectionUtils.isEmpty(scenePlusList)){
  187. throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
  188. }
  189. }else {
  190. //如果是相机协作,判断这个相机id下有没有V4的场景,如果有,则列出对应的菜单资源
  191. if(ObjectUtils.isEmpty(param.getCameraId()) && CollectionUtils.isEmpty(param.getCameraIdList())){
  192. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  193. }
  194. List<Long> cameraIdList = param.getCameraIdList();
  195. if(cameraIdList == null){
  196. cameraIdList= new ArrayList<>();
  197. cameraIdList.add(param.getCameraId());
  198. }
  199. sceneProList = sceneProService.getListByCameraIds(cameraIdList);
  200. scenePlusList = scenePlusService.getListByCameraIds(cameraIdList);
  201. }
  202. List<String> versionList = Lists.newArrayList();
  203. if(sceneProList.size() >0){
  204. versionList.add("v3");
  205. }
  206. if(scenePlusList.size() >0){
  207. versionList.add("v4");
  208. }
  209. if(versionList.size() <=0){
  210. versionList.add("v3");
  211. }
  212. List<SceneResource> results = sceneResourceService.getByVersion(versionList);
  213. jsonObject.put("include", results);
  214. return jsonObject;
  215. }
  216. @Override
  217. public JSONObject cooperationSceneListNew(SceneParam param, String username) {
  218. User user = userService.getByUserName(username);
  219. LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
  220. wrapper.eq(SceneCooperation::getUserId,user.getId());
  221. wrapper.eq(SceneCooperation::getSceneType,"mesh");
  222. List<SceneCooperation> list = this.list(wrapper);
  223. List<String> numList = list.parallelStream().map(SceneCooperation::getSceneNum).collect(Collectors.toList());
  224. if(numList.size() <=0){
  225. JSONObject jsonObject = new JSONObject();
  226. jsonObject.put("list", new ArrayList<>());
  227. jsonObject.put("total",0);
  228. return jsonObject;
  229. }
  230. param.setNumList(numList);
  231. param.setHasFolder(0);
  232. JSONObject jsonObject = sceneProService.newList(param, username);
  233. return jsonObject.getJSONObject("pageInfo") ;
  234. }
  235. @Override
  236. public void saveCooperation(SceneCooperationParam param, String loginUserName) {
  237. if(StringUtils.isEmpty(param.getUserName()) || StringUtils.isEmpty(param.getSceneNum())){
  238. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  239. }
  240. if(param.getUserName().equals( loginUserName)){
  241. throw new BusinessException(LoginConstant.FAILURE_CODE_3024, LoginConstant.FAILURE_MSG_3024);
  242. }
  243. User loginUser = userService.getByUserName(loginUserName);
  244. User user = userService.getByUserName(param.getUserName());
  245. if(user == null){
  246. throw new BusinessException(LoginConstant.FAILURE_CODE_3021, LoginConstant.FAILURE_MSG_3021);
  247. }
  248. String[] nums = param.getSceneNum().split(",");
  249. List<String> numList = Arrays.asList(nums);
  250. List<ScenePro> proList = sceneProService.getListByNums(numList);
  251. List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
  252. //this.deleteCooperationList(proList,plusList,Arrays.asList(user.getId()));
  253. saveCooperationCommon(loginUser,param.getLang(),Arrays.asList(user),proList,plusList,null,"scene","mesh");
  254. }
  255. @Override
  256. public ProductOrder saveBatchCooperation(SceneCooperationParam param, String loginUserName) {
  257. if( StringUtils.isEmpty(param.getSceneNum())){
  258. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  259. }
  260. String[] nums = param.getSceneNum().split(",");
  261. List<String> numList = Arrays.asList(nums);
  262. if(param.getUserNameList() == null || param.getUserNameList().isEmpty()){
  263. this.deleteCooperationList(numList,null);
  264. laserService.saveBatchCooperation(numList,new ArrayList<>(),loginUserName,param.getUserNameList(),"scene","update");
  265. return null;
  266. }
  267. if(param.getUserNameList().contains( loginUserName)){
  268. throw new BusinessException(LoginConstant.FAILURE_CODE_3024, LoginConstant.FAILURE_MSG_3024);
  269. }
  270. if(param.getUserNameList().size() >5){
  271. throw new BusinessException(ResultCode.COO_LIMIT_ERROR);
  272. }
  273. User loginUser = userService.getByUserName(loginUserName);
  274. if(numList.size() >1){
  275. HashMap<String, List<User>> byNumList = this.getByNumList(numList, param.getSceneType());
  276. for (String num : numList) {
  277. if(byNumList.get(num) != null && !byNumList.isEmpty()) {
  278. if (byNumList.get(num).size() + param.getUserNameList().size() > 5) {
  279. throw new BusinessException(ResultCode.COO_LIMIT_ERROR);
  280. }
  281. List<User> users = byNumList.get(num);
  282. Set<String> collect = users.stream().map(User::getUserName).collect(Collectors.toSet());
  283. if(collect.containsAll(param.getUserNameList())){
  284. throw new BusinessException(ResultCode.COO_LIMIT_ERROR2);
  285. }
  286. }
  287. }
  288. }
  289. List<User> users = new ArrayList<>();
  290. for (String userName : param.getUserNameList()) {
  291. User user = userService.getByUserName(userName);
  292. if(user == null){
  293. throw new BusinessException(LoginConstant.FAILURE_CODE_3021, LoginConstant.FAILURE_MSG_3021);
  294. }
  295. users.add(user);
  296. }
  297. ProductOrder productOrder = checkNeedPay(numList, users, loginUser, param.getPayType(), param.getTimeZone(),null,param.getLang(),param.getSceneType());
  298. if(productOrder == null){
  299. successAddCooperation(numList,users,param.getLang(),loginUser,param.getSceneType());
  300. }
  301. return productOrder;
  302. }
  303. @Override
  304. public ProductOrder saveCamera(SceneCooperationParam param, String loginUserName) {
  305. if(param.getCameraId() == null || StringUtils.isEmpty(param.getUserName())){
  306. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  307. }
  308. if(param.getUserName().equals( loginUserName)){
  309. throw new BusinessException(LoginConstant.FAILURE_CODE_3025, LoginConstant.FAILURE_MSG_3025);
  310. }
  311. User user = userService.getByUserName(param.getUserName());
  312. if(user == null){
  313. throw new BusinessException(LoginConstant.FAILURE_CODE_3015,LoginConstant.FAILURE_MSG_3015);
  314. }
  315. User loginUser = userService.getByUserName(loginUserName);
  316. Camera camera = cameraService.getById(param.getCameraId());
  317. CameraDetail cameraDetail = cameraDetailService.getByCameraId(param.getCameraId());
  318. if(camera == null || cameraDetail == null || cameraDetail.getUserId() == null){
  319. throw new BusinessException(ResultCode.CAMERA_NOT_EXIT);
  320. }
  321. if(!loginUser.getId().equals(cameraDetail.getUserId())){
  322. throw new BusinessException(ResultCode.NOT_PER);
  323. }
  324. if(cameraDetail.getCooperationUser() != null){
  325. throw new BusinessException(ResultCode.COO_ERROR);
  326. }
  327. List<ScenePro> v3List = sceneProService.getListByCameraId(param.getCameraId());
  328. List<ScenePlus> v4List = scenePlusService.getListByCameraId(param.getCameraId());
  329. List<String> v3NumList = v3List.stream().map(ScenePro::getNum).collect(Collectors.toList());
  330. List<String> v4NumList = v4List.stream().map(ScenePlus::getNum).collect(Collectors.toList());
  331. List<String> allList = new ArrayList<>();
  332. allList.addAll(v3NumList);
  333. allList.addAll(v4NumList);
  334. ProductOrder productOrder = checkNeedPay(allList, Arrays.asList(user), loginUser, param.getPayType(), param.getTimeZone(),param.getCameraId(),param.getLang(),null);
  335. if(productOrder == null){
  336. successAddCooperation(v3List,v4List,Arrays.asList(user),param.getLang(),loginUser,Arrays.asList(camera),null);
  337. cameraDetailService.updateCooperationByIds(Arrays.asList(param.getCameraId()),user.getId());
  338. }
  339. return productOrder;
  340. }
  341. private void successAddCooperation(List<String> numList, List<User> users, String lang, User loginUser,String sceneType){
  342. List<ScenePro> proList = sceneProService.getListByNums(numList);
  343. List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
  344. List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
  345. //this.deleteCooperationList(proList,plusList,userIds);
  346. saveCooperationCommon(loginUser,lang,users,proList,plusList,null,"scene",sceneType);
  347. }
  348. @Override
  349. public void successAddCooperation(List<String> numList,List<Long> userIds,Long loginUserId,Long cameraId,String lang,String sceneType,List<ProductCooperation> needPay ){
  350. //this.deleteCooperationList(numList,userIds);
  351. List<ScenePro> proList = sceneProService.getListByNums(numList);
  352. List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
  353. List<User> users = userService.listByIds(userIds);
  354. User user = userService.getById(loginUserId);
  355. if(cameraId != null ){
  356. Camera camera = cameraService.getById(cameraId);
  357. saveCooperationCommon(user,lang,users,proList,plusList,Arrays.asList(camera),"camera",sceneType);
  358. cameraDetailService.updateCooperationByIds(Arrays.asList(cameraId),userIds.get(0));
  359. }else {
  360. saveCooperationCommon(user,lang,users,proList,plusList,null,"scene",sceneType);
  361. }
  362. sceneCooperationCountService.saveCount(needPay,userIds.size());
  363. }
  364. private void successAddCooperation(List<ScenePro> v3List,List<ScenePlus> v4List,List<User> users,String lang,User loginUser,List<Camera>cameraList,String sceneType){
  365. List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
  366. //this.deleteCooperationList(v3List,v4List,userIds);
  367. saveCooperationCommon(loginUser,lang,users,v3List,v4List,cameraList,"camera",sceneType);
  368. }
  369. private ProductOrder checkNeedPay(List<String> numList, List<User> users,User loginUser,Integer payType,Integer timeZone,Long cameraId,String lang,String sceneType) {
  370. HashMap<String,String> needNumListMesh = new HashMap<>();
  371. HashMap<String,String> needNumListLaser =new HashMap<>();
  372. if(StringUtils.isBlank(sceneType)){
  373. needNumListMesh = getTotalCount(numList,users,"mesh",cameraId);
  374. needNumListLaser = getTotalCount(numList,users,"laser",cameraId);
  375. }else {
  376. needNumListMesh = getTotalCount(numList,users,sceneType,cameraId);
  377. }
  378. if(needNumListMesh.size() + needNumListLaser.size()<=0){
  379. return null;
  380. }
  381. ProductOrder productOrder = productOrderService.createOrder(needNumListMesh.size() + needNumListLaser.size(), "cooperation", loginUser, payType, timeZone, cameraId, lang, sceneType);
  382. productCooperationService.add(productOrder,users,numList,needNumListMesh,needNumListLaser,sceneType);
  383. return productOrder;
  384. }
  385. private HashMap<String,String> getTotalCount(List<String> numList, List<User> users,String sceneType,Long cameraId){
  386. List<SceneCooperationCount> freeCountList = sceneCooperationCountService.getByNumList(numList,sceneType);
  387. HashMap<String,Integer> freeMap = new HashMap<>();
  388. freeCountList.forEach(e -> freeMap.put(e.getNum(),e.getCount()));
  389. HashMap<String, List<User>> map = this.getByNumList(numList,sceneType);
  390. HashMap<String,String> needNumList = new HashMap<>();
  391. for (String num : numList) {
  392. Integer freeCount = freeMap.get(num) == null ? 1 :freeMap.get(num);
  393. List<User> dbUserList = map.get(num);
  394. if(dbUserList != null && !dbUserList.isEmpty()){
  395. List<Long> dbUserIds = dbUserList.stream().map(User::getId).collect(Collectors.toList());
  396. HashMap<Long,User> userHashMap = new HashMap<>();
  397. for (User user : users) {
  398. if(dbUserIds.contains(user.getId())){
  399. userHashMap.put(user.getId(),user);
  400. }
  401. }
  402. Integer totalSize = dbUserList.size() - userHashMap.size();
  403. if(numList.size() >1){
  404. freeCount = (totalSize > freeCount ? totalSize : (freeCount - totalSize));
  405. }else {
  406. freeCount = (totalSize > freeCount ? totalSize : freeCount) ;
  407. }
  408. }
  409. for (int i = 0 ; i< users.size() - freeCount;i++){
  410. needNumList.put(users.get(i).getId()+","+num,num);
  411. }
  412. }
  413. return needNumList;
  414. }
  415. @Autowired
  416. LaserService laserService;
  417. private void saveCooperationCommon(User LoginUser,String lang,List<User> userList,List<ScenePro> proList, List<ScenePlus> plusList,List<Camera >cameraList,String type,String sceneType){
  418. List<Long> userIds = userList.stream().map(User::getId).collect(Collectors.toList());
  419. Set<String> numList = new HashSet<>();
  420. List<String> v3List = proList.stream().map(ScenePro::getNum).collect(Collectors.toList());
  421. List<String> v4List = plusList.stream().map(ScenePlus::getNum).collect(Collectors.toList());
  422. numList.addAll(v3List);
  423. numList.addAll(v4List);
  424. List<ScenePro> collect1 = proList.stream().filter(e -> SceneSourceUtil.getLaserList().contains(e.getSceneSource())).collect(Collectors.toList());
  425. List<ScenePlus> collect2 = plusList.stream().filter(e -> SceneSourceUtil.getLaserList().contains(e.getSceneSource())).collect(Collectors.toList());
  426. Set<String> numList1 = collect1.stream().map(ScenePro::getNum).collect(Collectors.toSet());
  427. Set<String> numList2 = collect2.stream().map(ScenePlus::getNum).collect(Collectors.toSet());
  428. numList1.addAll(numList2);
  429. List<SceneCooperation> addList =new ArrayList<>();
  430. if( !numList.isEmpty()){
  431. if(StringUtils.isBlank(sceneType)){
  432. addList = this.saveBatchByList(new ArrayList<>(numList), userIds, type,"mesh");
  433. if(!numList1.isEmpty()){
  434. this.saveBatchByList(new ArrayList<>(numList1), userIds, type,"laser");
  435. }
  436. }else {
  437. addList = this.saveBatchByList(new ArrayList<>(numList), userIds, type,sceneType);
  438. }
  439. }
  440. List<Long> collect3 = addList.stream().map(SceneCooperation::getUserId).collect(Collectors.toList());
  441. for (User user : userList) {
  442. if("aws".equals(NacosProperty.uploadType)){
  443. if("camera".equals(type) && cameraList != null){
  444. HashMap<Long, Camera> cameraMap = new HashMap<>();
  445. cameraList.forEach(e -> cameraMap.put(e.getId(),e));
  446. mailTemplateService.sendCameraCooperation(cameraMap,user.getUserName(),lang);
  447. }else {
  448. if(collect3.contains(user.getId())){
  449. mailTemplateService.sendSceneCooperation(proList,plusList,user.getUserName(),lang);
  450. }
  451. }
  452. }
  453. }
  454. List<String> collect = userList.stream().map(User::getUserName).collect(Collectors.toList());
  455. List<String> snCodeList = new ArrayList<>();
  456. if(cameraList !=null ){
  457. snCodeList = cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList());
  458. }
  459. if(StringUtils.isNotBlank(sceneType) && "mesh".equals(sceneType)){
  460. return;
  461. }
  462. String operatingMode = numList.size() > 1 ? "add" :"update";
  463. laserService.saveBatchCooperation(new ArrayList<>(numList1),snCodeList,LoginUser.getUserName(),collect,type,operatingMode);
  464. }
  465. @Override
  466. public void deleteCooperation(SceneCooperationParam param, String username) {
  467. if(StringUtils.isEmpty(param.getSceneNum())){
  468. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  469. }
  470. String[] nums = param.getSceneNum().split(",");
  471. List<String> numList = Arrays.asList(nums);
  472. List<ScenePro> proList = sceneProService.getListByNums(numList);
  473. List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
  474. this.deleteCooperationList(proList,plusList,null);
  475. }
  476. @Override
  477. public List<SceneResource> getResourceByNum(String sceneNum) {
  478. if(StringUtils.isEmpty(sceneNum)){
  479. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  480. }
  481. LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
  482. wrapper.eq(SceneCooperation::getSceneNum,sceneNum);
  483. List<SceneCooperation> list = this.list(wrapper);
  484. if(list == null || list.size()<=0){
  485. return new ArrayList<>();
  486. }
  487. return sceneResourceService.getByCooperationId(list.get(0).getId());
  488. }
  489. @Override
  490. public List<String> getNumByUserIds(List<Long> userIds) {
  491. LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
  492. wrapper.in(SceneCooperation::getUserId,userIds);
  493. Set<String> collect = this.list(wrapper).parallelStream().map(SceneCooperation::getSceneNum).collect(Collectors.toSet());
  494. return new ArrayList<>(collect);
  495. }
  496. @Override
  497. public HashMap<String, List<User>> getByNumList(List<String> numList,String sceneType) {
  498. if(numList == null || numList.isEmpty()){
  499. return new HashMap<>();
  500. }
  501. LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
  502. wrapper.in(SceneCooperation::getSceneNum,numList);
  503. if(StringUtils.isNotBlank(sceneType)){
  504. wrapper.eq(SceneCooperation::getSceneType,sceneType);
  505. }
  506. List<SceneCooperation> list = this.list(wrapper);
  507. HashMap<String,List<User>> cooMap = new HashMap<>();
  508. if(list.size() >0){
  509. List<Long> userIds = list.parallelStream().map(SceneCooperation::getUserId).collect(Collectors.toList());
  510. if(userIds.size() >0){
  511. HashMap<Long, User> userMap = userService.getByIds(userIds);
  512. for (SceneCooperation entity : list) {
  513. User user = userMap.get(entity.getUserId());
  514. cooMap.computeIfAbsent(entity.getSceneNum(), k -> new ArrayList<>());
  515. if(!cooMap.get(entity.getSceneNum()).contains(user)){
  516. cooMap.get(entity.getSceneNum()).add(user);
  517. }
  518. }
  519. }
  520. }
  521. return cooMap;
  522. }
  523. @Override
  524. public List<SceneCooperation> getByNum(String num,String sceneType) {
  525. LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
  526. wrapper.eq(SceneCooperation::getSceneNum,num);
  527. wrapper.eq(SceneCooperation::getSceneType,sceneType);
  528. List<SceneCooperation> list = this.list(wrapper);
  529. return list;
  530. }
  531. @Override
  532. public Object cooperationSceneList(SceneParam param, String username) {
  533. return null;
  534. }
  535. }