CaseServiceImpl.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package com.fdkankan.fusion.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.fdkankan.fusion.common.ResultCode;
  5. import com.fdkankan.fusion.entity.Model;
  6. import com.fdkankan.fusion.exception.BusinessException;
  7. import com.fdkankan.fusion.common.PageInfo;
  8. import com.fdkankan.fusion.common.util.JwtUtil;
  9. import com.fdkankan.fusion.entity.CaseEntity;
  10. import com.fdkankan.fusion.mapper.ICaseMapper;
  11. import com.fdkankan.fusion.request.CaseParam;
  12. import com.fdkankan.fusion.request.ScenePram;
  13. import com.fdkankan.fusion.response.HotVo;
  14. import com.fdkankan.fusion.response.SceneVo;
  15. import com.fdkankan.fusion.service.*;
  16. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  17. import org.apache.commons.lang3.StringUtils;
  18. import org.springframework.beans.BeanUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21. import java.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.stream.Collectors;
  25. /**
  26. * <p>
  27. * 服务实现类
  28. * </p>
  29. *
  30. * @author
  31. * @since 2022-07-27
  32. */
  33. @Service
  34. public class CaseServiceImpl extends ServiceImpl<ICaseMapper, CaseEntity> implements ICaseService {
  35. @Autowired
  36. ISceneService sceneService;
  37. @Autowired
  38. ICaseNumService caseNumService;
  39. @Autowired
  40. FdHotService fdHotService;
  41. @Autowired
  42. IModelService modelService;
  43. @Autowired
  44. IFusionNumService fusionNumService;
  45. @Override
  46. public PageInfo pageList(CaseParam param,String token) {
  47. String userName = JwtUtil.getUsername(token);
  48. LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
  49. if(StringUtils.isNotBlank(param.getCaseTitle())){
  50. wrapper.like(CaseEntity::getCaseTitle,param.getCaseTitle());
  51. }
  52. wrapper.eq(CaseEntity::getUserName,userName);
  53. wrapper.orderByDesc(CaseEntity::getCreateTime);
  54. Page<CaseEntity> page = this.page( new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
  55. return PageInfo.PageInfo(page);
  56. }
  57. @Override
  58. public List<SceneVo> sceneList(CaseParam param, String token) {
  59. if(param.getCaseId() == null){
  60. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  61. }
  62. if(param.getTypeMap() == null){
  63. HashMap<Integer, List<String>> typeMap = caseNumService.getTypeMap(param.getCaseId());
  64. param.setTypeMap(typeMap);
  65. }
  66. List<SceneVo> listAll = new ArrayList<>();
  67. for (Integer type : param.getTypeMap().keySet()) {
  68. List<String> numList = param.getTypeMap().get(type);
  69. if(numList ==null || numList.size() <=0 || type ==3){
  70. continue;
  71. }
  72. ScenePram scenePram = new ScenePram();
  73. scenePram.setType(type);
  74. scenePram.setPageNum(1);
  75. scenePram.setPageSize(99999);
  76. scenePram.setNumList(param.getTypeMap().get(type));
  77. PageInfo pageInfo = sceneService.pageList(scenePram,token);
  78. List<SceneVo> list1 = (List<SceneVo>) pageInfo.getList();
  79. listAll.addAll(list1);
  80. }
  81. if(listAll.size() >0){
  82. List<String> numList = listAll.parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
  83. //设置模型
  84. List<Model> modelList = modelService.getListByNum(numList);
  85. HashMap<String,Model> map = new HashMap<>();
  86. modelList.forEach(entity-> map.put(entity.getNum(),entity));
  87. for (SceneVo sceneVo : listAll) {
  88. String createTime = sceneVo.getCreateTime();
  89. Model model = map.get(sceneVo.getNum());
  90. if(model == null){
  91. continue;
  92. }
  93. BeanUtils.copyProperties(model,sceneVo);
  94. sceneVo.setCreateTime(createTime);
  95. }
  96. }
  97. //官网删除的场景,删除对应资源
  98. List<String> kkNumList = param.getTypeMap().get(0);
  99. List<String> ssNumList = param.getTypeMap().get(1);
  100. if(kkNumList == null){
  101. kkNumList = new ArrayList<>();
  102. }
  103. if(ssNumList != null && ssNumList.size() >0){
  104. kkNumList.addAll(ssNumList);
  105. }
  106. if(kkNumList.size() >0){
  107. List<String> numList = listAll.parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
  108. List<String> delNumList = new ArrayList<>();
  109. for (String num : kkNumList) {
  110. if(!numList.contains(num)){
  111. delNumList.add(num);
  112. }
  113. }
  114. caseNumService.deleteByNum(param.getCaseId(),delNumList);
  115. }
  116. List<String> numList = param.getTypeMap().get(3); //关联的三维模型
  117. if(numList!=null && numList.size() >0){
  118. List<Model> models = modelService.getListByModelIdStrs(numList);
  119. for (Model model : models) {
  120. SceneVo sceneVo = new SceneVo();
  121. BeanUtils.copyProperties(model,sceneVo);
  122. listAll.add(sceneVo);
  123. }
  124. }
  125. //相机解绑,标注,测量隐藏,视图
  126. for (SceneVo sceneVo : listAll) {
  127. if(!sceneVo.getBind() || sceneVo.getStatus() == 3){
  128. fusionNumService.hideOrShow(sceneVo.getModelId(),sceneVo.getNum(),1);
  129. }else {
  130. fusionNumService.hideOrShow(sceneVo.getModelId(),sceneVo.getNum(),0);
  131. }
  132. }
  133. listAll.removeIf(sceneVo -> !sceneVo.getBind());
  134. return listAll;
  135. }
  136. @Override
  137. public void addOrUpdate(CaseParam param, String token) {
  138. String userName = JwtUtil.getUsername(token);
  139. if(StringUtils.isEmpty(param.getCaseTitle())){
  140. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  141. }
  142. CaseEntity caseEntity ;
  143. if(param.getCaseId() == null){
  144. caseEntity = new CaseEntity();
  145. caseEntity.setUserName(userName);
  146. }else {
  147. caseEntity = this.getById(param.getCaseId());
  148. }
  149. caseEntity.setCaseTitle(param.getCaseTitle());
  150. caseEntity.setUpdateTime(null);
  151. this.saveOrUpdate(caseEntity);
  152. }
  153. @Override
  154. public void addScene(CaseParam param) {
  155. if(param.getCaseId() == null){
  156. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  157. }
  158. CaseEntity caseEntity = this.getById(param.getCaseId());
  159. if(caseEntity == null){
  160. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  161. }
  162. caseNumService.addBatch(param.getCaseId(),param.getSceneNumParam());
  163. }
  164. @Override
  165. public void delete(Integer caseId) {
  166. if(caseId == null){
  167. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  168. }
  169. //删除关联的场景
  170. caseNumService.deleteByCaseId(caseId);
  171. this.removeById(caseId);
  172. }
  173. @Override
  174. public List<HotVo> hotList(Integer caseId) {
  175. HashMap<Integer, List<String>> typeMap = caseNumService.getTypeMap(caseId);
  176. List<HotVo> listAll = new ArrayList<>();
  177. for (Integer type : typeMap.keySet()) {
  178. List<String> numList = typeMap.get(type);
  179. if(numList ==null || numList.size() <=0){
  180. continue;
  181. }
  182. List<HotVo> hotList = fdHotService.getHotList(numList, type);
  183. listAll.addAll(hotList);
  184. }
  185. return listAll;
  186. }
  187. @Override
  188. public List<CaseEntity> getByIds(List<Integer> caseIdIds) {
  189. LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
  190. wrapper.in(CaseEntity::getCaseId,caseIdIds);
  191. return this.list(wrapper);
  192. }
  193. }