SceneCooperationServiceImpl.java 28 KB

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