CaseServiceImpl.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.ICaseNumService;
  16. import com.fdkankan.fusion.service.ICaseService;
  17. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  18. import com.fdkankan.fusion.service.IModelService;
  19. import com.fdkankan.fusion.service.ISceneService;
  20. import org.apache.commons.lang3.StringUtils;
  21. import org.springframework.beans.BeanUtils;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24. import java.util.ArrayList;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. import java.util.stream.Collectors;
  28. /**
  29. * <p>
  30. * 服务实现类
  31. * </p>
  32. *
  33. * @author
  34. * @since 2022-07-27
  35. */
  36. @Service
  37. public class CaseServiceImpl extends ServiceImpl<ICaseMapper, CaseEntity> implements ICaseService {
  38. @Autowired
  39. ISceneService sceneService;
  40. @Autowired
  41. ICaseNumService caseNumService;
  42. @Autowired
  43. FdHotService fdHotService;
  44. @Autowired
  45. IModelService modelService;
  46. @Override
  47. public PageInfo pageList(CaseParam param,String token) {
  48. String userName = JwtUtil.getUsername(token);
  49. LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
  50. if(StringUtils.isNotBlank(param.getCaseTitle())){
  51. wrapper.like(CaseEntity::getCaseTitle,param.getCaseTitle());
  52. }
  53. wrapper.eq(CaseEntity::getUserName,userName);
  54. wrapper.orderByDesc(CaseEntity::getCreateTime);
  55. Page<CaseEntity> page = this.page( new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
  56. return PageInfo.PageInfo(page);
  57. }
  58. @Override
  59. public List<SceneVo> sceneList(CaseParam param, String token) {
  60. if(param.getCaseId() == null){
  61. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  62. }
  63. if(param.getTypeMap() == null){
  64. HashMap<Integer, List<String>> typeMap = caseNumService.getTypeMap(param.getCaseId());
  65. param.setTypeMap(typeMap);
  66. }
  67. List<SceneVo> listAll = new ArrayList<>();
  68. for (Integer type : param.getTypeMap().keySet()) {
  69. List<String> numList = param.getTypeMap().get(type);
  70. if(numList ==null || numList.size() <=0 || type ==3){
  71. continue;
  72. }
  73. ScenePram scenePram = new ScenePram();
  74. scenePram.setType(type);
  75. scenePram.setPageNum(1);
  76. scenePram.setPageSize(99999);
  77. scenePram.setNumList(param.getTypeMap().get(type));
  78. PageInfo pageInfo = sceneService.pageList(scenePram,token);
  79. List<SceneVo> list1 = (List<SceneVo>) pageInfo.getList();
  80. listAll.addAll(list1);
  81. }
  82. if(listAll.size() >0){
  83. List<String> numList = listAll.parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
  84. //设置模型
  85. List<Model> modelList = modelService.getListByNum(numList);
  86. HashMap<String,Model> map = new HashMap<>();
  87. modelList.forEach(entity-> map.put(entity.getNum(),entity));
  88. for (SceneVo sceneVo : listAll) {
  89. BeanUtils.copyProperties(map.get(sceneVo.getNum()),sceneVo);
  90. }
  91. }
  92. List<String> numList = param.getTypeMap().get(3); //关联的三维模型
  93. if(numList!=null && numList.size() >0){
  94. List<Model> models = modelService.getListByModelIdStrs(numList);
  95. for (Model model : models) {
  96. SceneVo sceneVo = new SceneVo();
  97. BeanUtils.copyProperties(model,sceneVo);
  98. listAll.add(sceneVo);
  99. }
  100. }
  101. return listAll;
  102. }
  103. @Override
  104. public void addOrUpdate(CaseParam param, String token) {
  105. String userName = JwtUtil.getUsername(token);
  106. if(StringUtils.isEmpty(param.getCaseTitle())){
  107. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  108. }
  109. CaseEntity caseEntity ;
  110. if(param.getCaseId() == null){
  111. caseEntity = new CaseEntity();
  112. caseEntity.setUserName(userName);
  113. }else {
  114. caseEntity = this.getById(param.getCaseId());
  115. }
  116. caseEntity.setCaseTitle(param.getCaseTitle());
  117. caseEntity.setUpdateTime(null);
  118. this.saveOrUpdate(caseEntity);
  119. }
  120. @Override
  121. public void addScene(CaseParam param) {
  122. if(param.getCaseId() == null){
  123. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  124. }
  125. CaseEntity caseEntity = this.getById(param.getCaseId());
  126. if(caseEntity == null){
  127. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  128. }
  129. caseNumService.addBatch(param.getCaseId(),param.getSceneNumParam());
  130. }
  131. @Override
  132. public void delete(Integer caseId) {
  133. if(caseId == null){
  134. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  135. }
  136. //删除关联的场景
  137. caseNumService.deleteByCaseId(caseId);
  138. this.removeById(caseId);
  139. }
  140. @Override
  141. public List<HotVo> hotList(Integer caseId) {
  142. HashMap<Integer, List<String>> typeMap = caseNumService.getTypeMap(caseId);
  143. List<HotVo> listAll = new ArrayList<>();
  144. for (Integer type : typeMap.keySet()) {
  145. List<String> numList = typeMap.get(type);
  146. if(numList ==null || numList.size() <=0){
  147. continue;
  148. }
  149. List<HotVo> hotList = fdHotService.getHotList(numList, type);
  150. listAll.addAll(hotList);
  151. }
  152. return listAll;
  153. }
  154. }