123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- package com.fdkankan.fusion.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.fusion.common.ResultCode;
- import com.fdkankan.fusion.entity.Model;
- import com.fdkankan.fusion.exception.BusinessException;
- import com.fdkankan.fusion.common.PageInfo;
- import com.fdkankan.fusion.common.util.JwtUtil;
- import com.fdkankan.fusion.entity.CaseEntity;
- import com.fdkankan.fusion.mapper.ICaseMapper;
- import com.fdkankan.fusion.request.CaseParam;
- import com.fdkankan.fusion.request.ScenePram;
- import com.fdkankan.fusion.response.HotVo;
- import com.fdkankan.fusion.response.SceneVo;
- import com.fdkankan.fusion.service.*;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2022-07-27
- */
- @Service
- public class CaseServiceImpl extends ServiceImpl<ICaseMapper, CaseEntity> implements ICaseService {
- @Autowired
- ISceneService sceneService;
- @Autowired
- ICaseNumService caseNumService;
- @Autowired
- FdHotService fdHotService;
- @Autowired
- IModelService modelService;
- @Autowired
- IFusionNumService fusionNumService;
- @Override
- public PageInfo pageList(CaseParam param,String token) {
- String userName = JwtUtil.getUsername(token);
- LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
- if(StringUtils.isNotBlank(param.getCaseTitle())){
- wrapper.like(CaseEntity::getCaseTitle,param.getCaseTitle());
- }
- wrapper.eq(CaseEntity::getUserName,userName);
- wrapper.orderByDesc(CaseEntity::getCreateTime);
- Page<CaseEntity> page = this.page( new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
- return PageInfo.PageInfo(page);
- }
- @Override
- public List<SceneVo> sceneList(CaseParam param, String token) {
- if(param.getCaseId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(param.getTypeMap() == null){
- HashMap<Integer, List<String>> typeMap = caseNumService.getTypeMap(param.getCaseId());
- param.setTypeMap(typeMap);
- }
- List<SceneVo> listAll = new ArrayList<>();
- for (Integer type : param.getTypeMap().keySet()) {
- List<String> numList = param.getTypeMap().get(type);
- if(numList ==null || numList.size() <=0 || type ==3){
- continue;
- }
- ScenePram scenePram = new ScenePram();
- scenePram.setType(type);
- scenePram.setPageNum(1);
- scenePram.setPageSize(99999);
- scenePram.setNumList(param.getTypeMap().get(type));
- PageInfo pageInfo = sceneService.pageList(scenePram,token);
- List<SceneVo> list1 = (List<SceneVo>) pageInfo.getList();
- listAll.addAll(list1);
- }
- if(listAll.size() >0){
- List<String> numList = listAll.parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
- //设置模型
- List<Model> modelList = modelService.getListByNum(numList);
- HashMap<String,Model> map = new HashMap<>();
- modelList.forEach(entity-> map.put(entity.getNum(),entity));
- for (SceneVo sceneVo : listAll) {
- String createTime = sceneVo.getCreateTime();
- Model model = map.get(sceneVo.getNum());
- if(model == null){
- continue;
- }
- BeanUtils.copyProperties(model,sceneVo);
- sceneVo.setCreateTime(createTime);
- }
- }
- //官网删除的场景,删除对应资源
- List<String> kkNumList = param.getTypeMap().get(0);
- List<String> ssNumList = param.getTypeMap().get(1);
- if(kkNumList == null){
- kkNumList = new ArrayList<>();
- }
- if(ssNumList != null && ssNumList.size() >0){
- kkNumList.addAll(ssNumList);
- }
- if(kkNumList.size() >0){
- List<String> numList = listAll.parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
- List<String> delNumList = new ArrayList<>();
- for (String num : kkNumList) {
- if(!numList.contains(num)){
- delNumList.add(num);
- }
- }
- caseNumService.deleteByNum(param.getCaseId(),delNumList);
- }
- List<String> numList = param.getTypeMap().get(3); //关联的三维模型
- if(numList!=null && numList.size() >0){
- List<Model> models = modelService.getListByModelIdStrs(numList);
- for (Model model : models) {
- SceneVo sceneVo = new SceneVo();
- BeanUtils.copyProperties(model,sceneVo);
- listAll.add(sceneVo);
- }
- }
- //相机解绑,标注,测量隐藏,视图
- for (SceneVo sceneVo : listAll) {
- if(!sceneVo.getBind() || sceneVo.getStatus() == 3){
- fusionNumService.hideOrShow(sceneVo.getModelId(),sceneVo.getNum(),1);
- }else {
- fusionNumService.hideOrShow(sceneVo.getModelId(),sceneVo.getNum(),0);
- }
- }
- listAll.removeIf(sceneVo -> !sceneVo.getBind());
- return listAll;
- }
- @Override
- public void addOrUpdate(CaseParam param, String token) {
- String userName = JwtUtil.getUsername(token);
- if(StringUtils.isEmpty(param.getCaseTitle())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- CaseEntity caseEntity ;
- if(param.getCaseId() == null){
- caseEntity = new CaseEntity();
- caseEntity.setUserName(userName);
- }else {
- caseEntity = this.getById(param.getCaseId());
- }
- caseEntity.setCaseTitle(param.getCaseTitle());
- caseEntity.setUpdateTime(null);
- this.saveOrUpdate(caseEntity);
- }
- @Override
- public void addScene(CaseParam param) {
- if(param.getCaseId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- CaseEntity caseEntity = this.getById(param.getCaseId());
- if(caseEntity == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- caseNumService.addBatch(param.getCaseId(),param.getSceneNumParam());
- }
- @Override
- public void delete(Integer caseId) {
- if(caseId == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- //删除关联的场景
- caseNumService.deleteByCaseId(caseId);
- this.removeById(caseId);
- }
- @Override
- public List<HotVo> hotList(Integer caseId) {
- HashMap<Integer, List<String>> typeMap = caseNumService.getTypeMap(caseId);
- List<HotVo> listAll = new ArrayList<>();
- for (Integer type : typeMap.keySet()) {
- List<String> numList = typeMap.get(type);
- if(numList ==null || numList.size() <=0){
- continue;
- }
- List<HotVo> hotList = fdHotService.getHotList(numList, type);
- listAll.addAll(hotList);
- }
- return listAll;
- }
- @Override
- public List<CaseEntity> getByIds(List<Integer> caseIdIds) {
- LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(CaseEntity::getCaseId,caseIdIds);
- return this.list(wrapper);
- }
- }
|