SceneCooperationServiceImpl.java 32 KB

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