package com.fdkankan.fusion.service.impl; import cn.dev33.satoken.stp.StpUtil; 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.entity.TmUser; import com.fdkankan.fusion.exception.BusinessException; import com.fdkankan.fusion.common.PageInfo; 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; /** *

* 服务实现类 *

* * @author * @since 2022-07-27 */ @Service public class CaseServiceImpl extends ServiceImpl implements ICaseService { @Autowired ISceneService sceneService; @Autowired ICaseNumService caseNumService; @Autowired ICaseFilesService caseFilesService; @Autowired IModelService modelService; @Autowired IFusionNumService fusionNumService; @Autowired ITmProjectService tmProjectService; @Autowired ITmDepartmentService tmDepartmentService; @Autowired ITmUserService tmUserService; @Override public PageInfo pageList(CaseParam param,String userName) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if(StringUtils.isNotBlank(param.getCaseTitle())){ wrapper.like(CaseEntity::getCaseTitle,param.getCaseTitle()); } List deptIds = tmDepartmentService.getDeptIds(); if(deptIds.size() <=0){ return PageInfo.PageInfo(new Page<>(param.getPageNum(),param.getPageSize())); } List userList = tmUserService.getByDeptIds(deptIds); List userNameList = userList.stream().map(TmUser::getUserName).collect(Collectors.toList()); if(userNameList.size()<=0){ return PageInfo.PageInfo(new Page<>(param.getPageNum(),param.getPageSize())); } wrapper.in(CaseEntity::getUserName,userNameList); //wrapper.eq(CaseEntity::getUserName,userName); wrapper.eq(CaseEntity::getType,0); wrapper.orderByDesc(CaseEntity::getCreateTime); Page page = this.page( new Page<>(param.getPageNum(), param.getPageSize()), wrapper); return PageInfo.PageInfo(page); } @Override public List sceneList(CaseParam param) { if(param.getCaseId() == null){ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS); } if(param.getTypeMap() == null){ HashMap> typeMap = caseNumService.getTypeMap(param.getCaseId()); param.setTypeMap(typeMap); } List listAll = new ArrayList<>(); for (Integer type : param.getTypeMap().keySet()) { List 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); List list1 = (List) pageInfo.getList(); listAll.addAll(list1); } if(listAll.size() >0){ List numList = listAll.parallelStream().map(SceneVo::getNum).collect(Collectors.toList()); //设置模型 HashMap map = modelService.getMapByNum(numList); for (SceneVo sceneVo : listAll) { String createTime = sceneVo.getCreateTime(); Model model = map.get(sceneVo.getNum() + sceneVo.getType()); if(model == null){ continue; } BeanUtils.copyProperties(model,sceneVo); sceneVo.setCreateTime(createTime); } } //官网删除的场景,删除对应资源 for (Integer type : param.getTypeMap().keySet()) { List dbNumList = listAll.stream().filter(entity -> entity.getType().equals(type)).map(SceneVo::getNum).collect(Collectors.toList()); this.deleteNotInScene(param.getTypeMap().get(type), dbNumList,type,param.getCaseId(),listAll); } //相机解绑,标注,测量隐藏,视图 for (SceneVo sceneVo : listAll) { if(!sceneVo.getBind() || (sceneVo.getStatus()!=null && sceneVo.getStatus() == 3)){ fusionNumService.hideOrShow(sceneVo.getModelId(),sceneVo.getNum(),1); }else { fusionNumService.hideOrShow(sceneVo.getModelId(),sceneVo.getNum(),0); } } listAll.removeIf(sceneVo -> !sceneVo.getBind()); //关联的三维模型 List numList = param.getTypeMap().get(3); if(numList!=null && numList.size() >0){ List models = modelService.getListByModelIdStrs(numList); for (Model model : models) { SceneVo sceneVo = new SceneVo(); sceneVo.setStatus(2); BeanUtils.copyProperties(model,sceneVo); listAll.add(sceneVo); } } return listAll; } private void deleteNotInScene(List numList,List obNumList,Integer type,Integer caseId,List sceneVos) { if(type == 3){ //上传的三维模型,无需处理 return; } if(numList.size() >0){ List delNumList = new ArrayList<>(); for (String num : numList) { if(!obNumList.contains(num)){ delNumList.add(num); } } List delNumList2 = new ArrayList<>(); for (SceneVo sceneVo : sceneVos) { if(sceneVo.getStatus() !=2 && sceneVo.getStatus() !=3 && sceneVo.getType().equals(type)){ delNumList2.add(sceneVo.getNum()); } } caseNumService.deleteByNum(caseId,delNumList,type); fusionNumService.deleteByNumList(caseId,delNumList2,false,type); } } @Override public void addOrUpdate(CaseParam param, String userName) { 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); caseFilesService.deleteByCaseId(caseId); this.removeById(caseId); } @Override public List getByIds(List caseIdIds) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.in(CaseEntity::getCaseId,caseIdIds); return this.list(wrapper); } @Override public CaseEntity getByTmProjectId(String projectId) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(CaseEntity::getTmProjectId,projectId); return this.getOne(wrapper); } @Override public void updateIdenTityStatus(Integer caseId, Integer status) { CaseEntity caseEntity = this.getById(caseId); if(caseEntity != null && StringUtils.isNotBlank(caseEntity.getTmProjectId())){ tmProjectService.updateIdenTityStatus(caseEntity.getTmProjectId(),status); } } }