SceneCooperationServiceImpl.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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. List<SceneCooperation> list = this.list(wrapper);
  222. List<String> numList = list.parallelStream().map(SceneCooperation::getSceneNum).collect(Collectors.toList());
  223. if(numList.size() <=0){
  224. JSONObject jsonObject = new JSONObject();
  225. jsonObject.put("list", new ArrayList<>());
  226. jsonObject.put("total",0);
  227. return jsonObject;
  228. }
  229. param.setNumList(numList);
  230. param.setHasFolder(0);
  231. JSONObject jsonObject = sceneProService.newList(param, username);
  232. return jsonObject.getJSONObject("pageInfo") ;
  233. }
  234. @Override
  235. public void saveCooperation(SceneCooperationParam param, String loginUserName) {
  236. if(StringUtils.isEmpty(param.getUserName()) || StringUtils.isEmpty(param.getSceneNum())){
  237. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  238. }
  239. if(param.getUserName().equals( loginUserName)){
  240. throw new BusinessException(LoginConstant.FAILURE_CODE_3024, LoginConstant.FAILURE_MSG_3024);
  241. }
  242. User loginUser = userService.getByUserName(loginUserName);
  243. User user = userService.getByUserName(param.getUserName());
  244. if(user == null){
  245. throw new BusinessException(LoginConstant.FAILURE_CODE_3021, LoginConstant.FAILURE_MSG_3021);
  246. }
  247. String[] nums = param.getSceneNum().split(",");
  248. List<String> numList = Arrays.asList(nums);
  249. List<ScenePro> proList = sceneProService.getListByNums(numList);
  250. List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
  251. //this.deleteCooperationList(proList,plusList,Arrays.asList(user.getId()));
  252. saveCooperationCommon(loginUser,param.getLang(),Arrays.asList(user),proList,plusList,null,"scene","mesh");
  253. }
  254. @Override
  255. public ProductOrder saveBatchCooperation(SceneCooperationParam param, String loginUserName) {
  256. if( StringUtils.isEmpty(param.getSceneNum())){
  257. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  258. }
  259. String[] nums = param.getSceneNum().split(",");
  260. List<String> numList = Arrays.asList(nums);
  261. if(param.getUserNameList() == null || param.getUserNameList().isEmpty()){
  262. this.deleteCooperationList(numList,null);
  263. return null;
  264. }
  265. if(param.getUserNameList().contains( loginUserName)){
  266. throw new BusinessException(LoginConstant.FAILURE_CODE_3024, LoginConstant.FAILURE_MSG_3024);
  267. }
  268. if(param.getUserNameList().size() >5){
  269. throw new BusinessException(ResultCode.COO_LIMIT_ERROR);
  270. }
  271. User loginUser = userService.getByUserName(loginUserName);
  272. if(numList.size() >1){
  273. HashMap<String, List<User>> byNumList = this.getByNumList(numList, param.getSceneType());
  274. for (String num : byNumList.keySet()) {
  275. if(byNumList.get(num).size() + param.getUserNameList().size() >5){
  276. throw new BusinessException(ResultCode.COO_LIMIT_ERROR);
  277. }
  278. }
  279. }
  280. List<User> users = new ArrayList<>();
  281. for (String userName : param.getUserNameList()) {
  282. User user = userService.getByUserName(userName);
  283. if(user == null){
  284. throw new BusinessException(LoginConstant.FAILURE_CODE_3021, LoginConstant.FAILURE_MSG_3021);
  285. }
  286. users.add(user);
  287. }
  288. ProductOrder productOrder = checkNeedPay(numList, users, loginUser, param.getPayType(), param.getTimeZone(),null,param.getLang(),param.getSceneType());
  289. if(productOrder == null){
  290. successAddCooperation(numList,users,param.getLang(),loginUser,param.getSceneType());
  291. }
  292. return productOrder;
  293. }
  294. @Override
  295. public ProductOrder saveCamera(SceneCooperationParam param, String loginUserName) {
  296. if(param.getCameraId() == null || StringUtils.isEmpty(param.getUserName())){
  297. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  298. }
  299. if(param.getUserName().equals( loginUserName)){
  300. throw new BusinessException(LoginConstant.FAILURE_CODE_3025, LoginConstant.FAILURE_MSG_3025);
  301. }
  302. User user = userService.getByUserName(param.getUserName());
  303. if(user == null){
  304. throw new BusinessException(LoginConstant.FAILURE_CODE_3015,LoginConstant.FAILURE_MSG_3015);
  305. }
  306. User loginUser = userService.getByUserName(loginUserName);
  307. Camera camera = cameraService.getById(param.getCameraId());
  308. CameraDetail cameraDetail = cameraDetailService.getByCameraId(param.getCameraId());
  309. if(camera == null || cameraDetail == null || cameraDetail.getUserId() == null){
  310. throw new BusinessException(ResultCode.CAMERA_NOT_EXIT);
  311. }
  312. if(!loginUser.getId().equals(cameraDetail.getUserId())){
  313. throw new BusinessException(ResultCode.NOT_PER);
  314. }
  315. if(cameraDetail.getCooperationUser() != null){
  316. throw new BusinessException(ResultCode.COO_ERROR);
  317. }
  318. List<ScenePro> v3List = sceneProService.getListByCameraId(param.getCameraId());
  319. List<ScenePlus> v4List = scenePlusService.getListByCameraId(param.getCameraId());
  320. List<String> v3NumList = v3List.stream().map(ScenePro::getNum).collect(Collectors.toList());
  321. List<String> v4NumList = v4List.stream().map(ScenePlus::getNum).collect(Collectors.toList());
  322. List<String> allList = new ArrayList<>();
  323. allList.addAll(v3NumList);
  324. allList.addAll(v4NumList);
  325. ProductOrder productOrder = checkNeedPay(allList, Arrays.asList(user), loginUser, param.getPayType(), param.getTimeZone(),param.getCameraId(),param.getLang(),null);
  326. if(productOrder == null){
  327. successAddCooperation(v3List,v4List,Arrays.asList(user),param.getLang(),loginUser,Arrays.asList(camera),null);
  328. cameraDetailService.updateCooperationByIds(Arrays.asList(param.getCameraId()),user.getId());
  329. }
  330. return productOrder;
  331. }
  332. private void successAddCooperation(List<String> numList, List<User> users, String lang, User loginUser,String sceneType){
  333. List<ScenePro> proList = sceneProService.getListByNums(numList);
  334. List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
  335. List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
  336. //this.deleteCooperationList(proList,plusList,userIds);
  337. saveCooperationCommon(loginUser,lang,users,proList,plusList,null,"scene",sceneType);
  338. }
  339. @Override
  340. public void successAddCooperation(List<String> numList,List<Long> userIds,Long loginUserId,Long cameraId,String lang,String sceneType,List<ProductCooperation> needPay ){
  341. //this.deleteCooperationList(numList,userIds);
  342. List<ScenePro> proList = sceneProService.getListByNums(numList);
  343. List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
  344. List<User> users = userService.listByIds(userIds);
  345. User user = userService.getById(loginUserId);
  346. if(cameraId != null ){
  347. Camera camera = cameraService.getById(cameraId);
  348. saveCooperationCommon(user,lang,users,proList,plusList,Arrays.asList(camera),"camera",sceneType);
  349. cameraDetailService.updateCooperationByIds(Arrays.asList(cameraId),userIds.get(0));
  350. }else {
  351. saveCooperationCommon(user,lang,users,proList,plusList,null,"scene",sceneType);
  352. }
  353. sceneCooperationCountService.saveCount(needPay,userIds.size());
  354. }
  355. private void successAddCooperation(List<ScenePro> v3List,List<ScenePlus> v4List,List<User> users,String lang,User loginUser,List<Camera>cameraList,String sceneType){
  356. List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
  357. //this.deleteCooperationList(v3List,v4List,userIds);
  358. saveCooperationCommon(loginUser,lang,users,v3List,v4List,cameraList,"camera",sceneType);
  359. }
  360. private ProductOrder checkNeedPay(List<String> numList, List<User> users,User loginUser,Integer payType,Integer timeZone,Long cameraId,String lang,String sceneType) {
  361. HashMap<String,String> needNumListMesh = new HashMap<>();
  362. HashMap<String,String> needNumListLaser =new HashMap<>();
  363. if(StringUtils.isBlank(sceneType)){
  364. needNumListMesh = getTotalCount(numList,users,"mesh",cameraId);
  365. needNumListLaser = getTotalCount(numList,users,"laser",cameraId);
  366. }else {
  367. needNumListMesh = getTotalCount(numList,users,sceneType,cameraId);
  368. }
  369. if(needNumListMesh.size() + needNumListLaser.size()<=0){
  370. return null;
  371. }
  372. ProductOrder productOrder = productOrderService.createOrder(needNumListMesh.size() + needNumListLaser.size(), "cooperation", loginUser, payType, timeZone, cameraId, lang, sceneType);
  373. productCooperationService.add(productOrder,users,numList,needNumListMesh,needNumListLaser,sceneType);
  374. return productOrder;
  375. }
  376. private HashMap<String,String> getTotalCount(List<String> numList, List<User> users,String sceneType,Long cameraId){
  377. List<SceneCooperationCount> freeCountList = sceneCooperationCountService.getByNumList(numList,sceneType);
  378. HashMap<String,Integer> freeMap = new HashMap<>();
  379. freeCountList.forEach(e -> freeMap.put(e.getNum(),e.getCount()));
  380. HashMap<String, List<User>> map = this.getByNumList(numList,sceneType);
  381. HashMap<String,String> needNumList = new HashMap<>();
  382. for (String num : numList) {
  383. Integer freeCount = freeMap.get(num) == null ? 1 :freeMap.get(num);
  384. List<User> dbUserList = map.get(num);
  385. if(dbUserList != null && !dbUserList.isEmpty()){
  386. if(numList.size() >1){
  387. freeCount = (dbUserList.size() > freeCount ? dbUserList.size() : (freeCount - dbUserList.size()));
  388. }else {
  389. freeCount = (dbUserList.size() > freeCount ? dbUserList.size() : freeCount) ;
  390. }
  391. }
  392. for (int i = 0 ; i< users.size() -freeCount;i++){
  393. needNumList.put(users.get(i).getId()+","+num,num);
  394. }
  395. }
  396. return needNumList;
  397. }
  398. @Autowired
  399. LaserService laserService;
  400. private void saveCooperationCommon(User LoginUser,String lang,List<User> userList,List<ScenePro> proList, List<ScenePlus> plusList,List<Camera >cameraList,String type,String sceneType){
  401. List<Long> userIds = userList.stream().map(User::getId).collect(Collectors.toList());
  402. Set<String> numList = new HashSet<>();
  403. List<String> v3List = proList.stream().map(ScenePro::getNum).collect(Collectors.toList());
  404. List<String> v4List = plusList.stream().map(ScenePlus::getNum).collect(Collectors.toList());
  405. numList.addAll(v3List);
  406. numList.addAll(v4List);
  407. List<ScenePro> collect1 = proList.stream().filter(e -> SceneSourceUtil.getLaserList().contains(e.getSceneSource())).collect(Collectors.toList());
  408. List<ScenePlus> collect2 = plusList.stream().filter(e -> SceneSourceUtil.getLaserList().contains(e.getSceneSource())).collect(Collectors.toList());
  409. Set<String> numList1 = collect1.stream().map(ScenePro::getNum).collect(Collectors.toSet());
  410. Set<String> numList2 = collect2.stream().map(ScenePlus::getNum).collect(Collectors.toSet());
  411. numList1.addAll(numList2);
  412. List<SceneCooperation> addList =new ArrayList<>();
  413. if( !numList.isEmpty()){
  414. if(StringUtils.isBlank(sceneType)){
  415. addList = this.saveBatchByList(new ArrayList<>(numList), userIds, type,"mesh");
  416. if(!numList1.isEmpty()){
  417. this.saveBatchByList(new ArrayList<>(numList1), userIds, type,"laser");
  418. }
  419. }else {
  420. addList = this.saveBatchByList(new ArrayList<>(numList), userIds, type,sceneType);
  421. }
  422. }
  423. List<Long> collect3 = addList.stream().map(SceneCooperation::getUserId).collect(Collectors.toList());
  424. for (User user : userList) {
  425. if("aws".equals(NacosProperty.uploadType)){
  426. if("camera".equals(type) && cameraList != null){
  427. HashMap<Long, Camera> cameraMap = new HashMap<>();
  428. cameraList.forEach(e -> cameraMap.put(e.getId(),e));
  429. mailTemplateService.sendCameraCooperation(cameraMap,user.getUserName(),lang);
  430. }else {
  431. if(collect3.contains(user.getId())){
  432. mailTemplateService.sendSceneCooperation(proList,plusList,user.getUserName(),lang);
  433. }
  434. }
  435. }
  436. }
  437. List<String> collect = userList.stream().map(User::getUserName).collect(Collectors.toList());
  438. List<String> snCodeList = new ArrayList<>();
  439. if(cameraList !=null ){
  440. snCodeList = cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList());
  441. }
  442. if(StringUtils.isNotBlank(sceneType) && "mesh".equals(sceneType)){
  443. return;
  444. }
  445. laserService.saveBatchCooperation(new ArrayList<>(numList1),snCodeList,LoginUser.getUserName(),collect,type);
  446. }
  447. @Override
  448. public void deleteCooperation(SceneCooperationParam param, String username) {
  449. if(StringUtils.isEmpty(param.getSceneNum())){
  450. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  451. }
  452. String[] nums = param.getSceneNum().split(",");
  453. List<String> numList = Arrays.asList(nums);
  454. List<ScenePro> proList = sceneProService.getListByNums(numList);
  455. List<ScenePlus> plusList = scenePlusService.getListByNums(numList);
  456. this.deleteCooperationList(proList,plusList,null);
  457. }
  458. @Override
  459. public List<SceneResource> getResourceByNum(String sceneNum) {
  460. if(StringUtils.isEmpty(sceneNum)){
  461. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  462. }
  463. LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
  464. wrapper.eq(SceneCooperation::getSceneNum,sceneNum);
  465. List<SceneCooperation> list = this.list(wrapper);
  466. if(list == null || list.size()<=0){
  467. return new ArrayList<>();
  468. }
  469. return sceneResourceService.getByCooperationId(list.get(0).getId());
  470. }
  471. @Override
  472. public List<String> getNumByUserIds(List<Long> userIds) {
  473. LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
  474. wrapper.in(SceneCooperation::getUserId,userIds);
  475. Set<String> collect = this.list(wrapper).parallelStream().map(SceneCooperation::getSceneNum).collect(Collectors.toSet());
  476. return new ArrayList<>(collect);
  477. }
  478. @Override
  479. public HashMap<String, List<User>> getByNumList(List<String> numList,String sceneType) {
  480. if(numList == null || numList.isEmpty()){
  481. return new HashMap<>();
  482. }
  483. LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
  484. wrapper.in(SceneCooperation::getSceneNum,numList);
  485. if(StringUtils.isNotBlank(sceneType)){
  486. wrapper.eq(SceneCooperation::getSceneType,sceneType);
  487. }
  488. List<SceneCooperation> list = this.list(wrapper);
  489. HashMap<String,List<User>> cooMap = new HashMap<>();
  490. if(list.size() >0){
  491. List<Long> userIds = list.parallelStream().map(SceneCooperation::getUserId).collect(Collectors.toList());
  492. if(userIds.size() >0){
  493. HashMap<Long, User> userMap = userService.getByIds(userIds);
  494. for (SceneCooperation entity : list) {
  495. User user = userMap.get(entity.getUserId());
  496. cooMap.computeIfAbsent(entity.getSceneNum(), k -> new ArrayList<>());
  497. if(!cooMap.get(entity.getSceneNum()).contains(user)){
  498. cooMap.get(entity.getSceneNum()).add(user);
  499. }
  500. }
  501. }
  502. }
  503. return cooMap;
  504. }
  505. @Override
  506. public List<SceneCooperation> getByNum(String num,String sceneType) {
  507. LambdaQueryWrapper<SceneCooperation> wrapper = new LambdaQueryWrapper<>();
  508. wrapper.eq(SceneCooperation::getSceneNum,num);
  509. wrapper.eq(SceneCooperation::getSceneType,sceneType);
  510. List<SceneCooperation> list = this.list(wrapper);
  511. return list;
  512. }
  513. @Override
  514. public Object cooperationSceneList(SceneParam param, String username) {
  515. return null;
  516. }
  517. }