CaseServiceImpl.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. String createTime = sceneVo.getCreateTime();
  90. Model model = map.get(sceneVo.getNum());
  91. if(model == null){
  92. continue;
  93. }
  94. BeanUtils.copyProperties(model,sceneVo);
  95. sceneVo.setCreateTime(createTime);
  96. }
  97. }
  98. //官网删除的场景,删除对应资源
  99. List<String> kkNumList = param.getTypeMap().get(1);
  100. List<String> ssNumList = param.getTypeMap().get(2);
  101. if(kkNumList == null){
  102. kkNumList = new ArrayList<>();
  103. }
  104. if(ssNumList != null && ssNumList.size() >0){
  105. kkNumList.addAll(ssNumList);
  106. }
  107. if(kkNumList.size() >0){
  108. List<String> numList = listAll.parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
  109. for (String num : kkNumList) {
  110. if(!numList.contains(num)){
  111. caseNumService.deleteByNum(num);
  112. }
  113. }
  114. }
  115. List<String> numList = param.getTypeMap().get(3); //关联的三维模型
  116. if(numList!=null && numList.size() >0){
  117. List<Model> models = modelService.getListByModelIdStrs(numList);
  118. for (Model model : models) {
  119. SceneVo sceneVo = new SceneVo();
  120. BeanUtils.copyProperties(model,sceneVo);
  121. listAll.add(sceneVo);
  122. }
  123. }
  124. return listAll;
  125. }
  126. @Override
  127. public void addOrUpdate(CaseParam param, String token) {
  128. String userName = JwtUtil.getUsername(token);
  129. if(StringUtils.isEmpty(param.getCaseTitle())){
  130. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  131. }
  132. CaseEntity caseEntity ;
  133. if(param.getCaseId() == null){
  134. caseEntity = new CaseEntity();
  135. caseEntity.setUserName(userName);
  136. }else {
  137. caseEntity = this.getById(param.getCaseId());
  138. }
  139. caseEntity.setCaseTitle(param.getCaseTitle());
  140. caseEntity.setUpdateTime(null);
  141. this.saveOrUpdate(caseEntity);
  142. }
  143. @Override
  144. public void addScene(CaseParam param) {
  145. if(param.getCaseId() == null){
  146. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  147. }
  148. CaseEntity caseEntity = this.getById(param.getCaseId());
  149. if(caseEntity == null){
  150. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  151. }
  152. caseNumService.addBatch(param.getCaseId(),param.getSceneNumParam());
  153. }
  154. @Override
  155. public void delete(Integer caseId) {
  156. if(caseId == null){
  157. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  158. }
  159. //删除关联的场景
  160. caseNumService.deleteByCaseId(caseId);
  161. this.removeById(caseId);
  162. }
  163. @Override
  164. public List<HotVo> hotList(Integer caseId) {
  165. HashMap<Integer, List<String>> typeMap = caseNumService.getTypeMap(caseId);
  166. List<HotVo> listAll = new ArrayList<>();
  167. for (Integer type : typeMap.keySet()) {
  168. List<String> numList = typeMap.get(type);
  169. if(numList ==null || numList.size() <=0){
  170. continue;
  171. }
  172. List<HotVo> hotList = fdHotService.getHotList(numList, type);
  173. listAll.addAll(hotList);
  174. }
  175. return listAll;
  176. }
  177. @Override
  178. public List<CaseEntity> getByIds(List<Integer> caseIdIds) {
  179. LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
  180. wrapper.in(CaseEntity::getCaseId,caseIdIds);
  181. return this.list(wrapper);
  182. }
  183. }