| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- package com.fdkankan.fusion.service.impl;
- import cn.dev33.satoken.context.SaHolder;
- import cn.dev33.satoken.stp.StpUtil;
- import cn.hutool.core.bean.BeanUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.fusion.common.ResultCode;
- import com.fdkankan.fusion.common.ResultData;
- import com.fdkankan.fusion.common.util.NumTypeUtils;
- import com.fdkankan.fusion.entity.*;
- import com.fdkankan.fusion.exception.BusinessException;
- import com.fdkankan.fusion.common.PageInfo;
- import com.fdkankan.fusion.mapper.ICaseMapper;
- import com.fdkankan.fusion.request.CaseParam;
- import com.fdkankan.fusion.request.ScenePram;
- import com.fdkankan.fusion.response.CaseVo;
- import com.fdkankan.fusion.response.FusionAndSceneVo;
- 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.time.Period;
- import java.util.*;
- 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
- ICaseFilesService caseFilesService;
- @Autowired
- IModelService modelService;
- @Autowired
- IFusionNumService fusionNumService;
- @Autowired
- ITmProjectService tmProjectService;
- @Autowired
- ITmDepartmentService tmDepartmentService;
- @Autowired
- ITmUserService tmUserService;
- @Autowired
- ITmCameraService tmCameraService;
- @Autowired
- ICaseSettingsService caseSettingsService;
- @Autowired
- IMapConfigService mapConfigService;
- @Autowired
- IScenePlusService scenePlusService;
- @Autowired
- ICaseFusionService caseFusionService;
- @Autowired
- ISceneDeptShareService sceneDeptShareService;
- @Override
- public PageInfo pageList(CaseParam param) {
- LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
- if(StringUtils.isNotBlank(param.getCaseTitle())){
- wrapper.like(CaseEntity::getCaseTitle,param.getCaseTitle());
- }
- List<String> deptIds = new ArrayList<>();
- String share = SaHolder.getRequest().getHeader("sharePassword");
- if(StringUtils.isNotBlank(share) ){ //分享请求头
- wrapper.eq(CaseEntity::getMapShow,true);
- }else {
- String deptId = tmDepartmentService.getDeptId();
- if(param.getSearchType() == 0){
- deptIds.add(deptId);
- }
- if(param.getSearchType() == 1){ //下级共享给上级场景
- List<Integer> caseIds = sceneDeptShareService.getCaseIdsListByDeptId(deptId);
- param.setCaseIds(caseIds);
- }
- if(param.getSearchType() == 2){ //当前组织及下级组织的数据
- List<TmDepartment> sonByDeptId = tmDepartmentService.getSonByDeptId(deptId);
- deptIds.add(deptId);
- deptIds.addAll(sonByDeptId.stream().map(TmDepartment::getId).collect(Collectors.toList()));
- }
- if(param.getCaseIds().isEmpty() && deptIds.size() <=0){
- return PageInfo.PageInfo(new Page<>(param.getPageNum(),param.getPageSize()));
- }
- }
- if(!deptIds.isEmpty()){
- wrapper.in(CaseEntity::getDeptId,deptIds);
- }
- if(!param.getCaseIds().isEmpty()){
- wrapper.in(CaseEntity::getCaseId,param.getCaseIds());
- }
- wrapper.eq(CaseEntity::getType,0);
- wrapper.orderByDesc(CaseEntity::getCreateTime);
- Page<CaseEntity> page = this.page( new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
- Set<String> tmProIds = page.getRecords().stream().filter(entity -> StringUtils.isNotBlank(entity.getTmProjectId()))
- .map(CaseEntity::getTmProjectId).collect(Collectors.toSet());
- HashMap<String, TmProject> proMap = tmProjectService.getMapByIds(tmProIds);
- for (CaseEntity record : page.getRecords()) {
- if(StringUtils.isNotBlank(record.getTmProjectId())){
- TmProject project = proMap.get(record.getTmProjectId());
- if(project != null){
- record.setDeptId(project.getDeptId());
- }
- }
- }
- List<Integer> mapIds = page.getRecords().stream().map(CaseEntity::getMapId).collect(Collectors.toList());
- if(!mapIds.isEmpty()){
- HashMap<Integer,MapConfig> map = mapConfigService.getMapByIds(mapIds);
- for (CaseEntity caseEntity : page.getRecords()) {
- if(caseEntity.getMapId() != null && map.get(caseEntity.getMapId()) != null){
- MapConfig mapConfig = map.get(caseEntity.getMapId());
- caseEntity.setMapConfig(mapConfig);
- }
- }
- }
- Set<String> deptIds1 = page.getRecords().stream().filter(entity -> StringUtils.isNotBlank(entity.getDeptId()))
- .map(CaseEntity::getDeptId).collect(Collectors.toSet());
- HashMap<String, TmDepartment> mapByDeptIds = tmDepartmentService.getMapByDeptIds(deptIds1);
- for (CaseEntity record : page.getRecords()) {
- TmDepartment department = mapByDeptIds.get(record.getDeptId());
- if(department != null){
- record.setDeptName(department.getName());
- }
- List<CaseSettings> caseSettings = caseSettingsService.getByCaseId(record.getCaseId());
- if(!caseSettings.isEmpty()){
- CaseSettings caseSettings1 = caseSettings.get(0);
- if(caseSettings1 != null){
- record.setCover(caseSettings1.getCover());
- }
- }
- }
- return PageInfo.PageInfo(page);
- }
- @Override
- public List<SceneVo> sceneList(CaseParam param) {
- if(param.getCaseId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- List<SceneVo> listAll = new ArrayList<>();
- List<CaseNumEntity> numListByCase = caseNumService.getByCaseId(param.getCaseId());
- List<String> meshNumList = numListByCase.stream().filter(e ->! NumTypeUtils.isLaser(e.getNumType())).map(CaseNumEntity::getNum).collect(Collectors.toList());
- List<String> laserNumList = numListByCase.stream().filter(e -> NumTypeUtils.isLaser(e.getNumType())).map(CaseNumEntity::getNum).collect(Collectors.toList());
- if(!meshNumList.isEmpty()){
- List<SceneVo> meshSceneList = scenePlusService.getMeshList(meshNumList);
- HashMap<String, Model> meshModelMap = modelService.getMapByNum(meshNumList,1);
- for (SceneVo sceneVo : meshSceneList) {
- Model model = meshModelMap.get(sceneVo.getNum());
- if(model != null){
- BeanUtils.copyProperties(model,sceneVo);
- }
- }
- listAll.addAll(meshSceneList);
- }
- if(!laserNumList.isEmpty()){
- List<SceneVo> laserSceneList = scenePlusService.getLaserList(laserNumList);
- HashMap<String, Model> laserModelMap = modelService.getMapByNum(laserNumList,0);
- for (SceneVo sceneVo : laserSceneList) {
- Model model = laserModelMap.get(sceneVo.getNum());
- if(model != null){
- BeanUtils.copyProperties(model,sceneVo);
- }
- }
- listAll.addAll(laserSceneList);
- }
- return listAll;
- }
- @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();
- TmUser tmUser = tmUserService.getByUserName(userName);
- caseEntity.setDeptId(tmUser.getDeptId());
- caseEntity.setUserName(userName);
- }else {
- caseEntity = this.getById(param.getCaseId());
- }
- caseEntity.setCaseTitle(param.getCaseTitle());
- caseEntity.setMapShow(param.getMapShow());
- caseEntity.setLatAndLong(param.getLatAndLong());
- caseEntity.setMapUrl(param.getMapUrl());
- caseEntity.setUpdateTime(null);
- this.saveOrUpdate(caseEntity);
- if(param.getSceneNumParam() != null && !param.getSceneNumParam().isEmpty()){
- caseNumService.addBatch(param.getCaseId(),param.getSceneNumParam());
- }
- }
- @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<CaseEntity> getByIds(List<Integer> caseIdIds) {
- LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(CaseEntity::getCaseId,caseIdIds);
- return this.list(wrapper);
- }
- @Override
- public CaseEntity getByTmProjectId(String projectId) {
- LambdaQueryWrapper<CaseEntity> 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);
- }
- }
- @Override
- public String getDeptId(Integer caseId) {
- CaseEntity caseEntity = this.getById(caseId);
- String deptId = caseEntity.getDeptId();
- if(caseEntity.getType() ==1){
- deptId = tmProjectService.getById(caseEntity.getTmProjectId()).getDeptId();
- }
- return deptId;
- }
- @Override
- public CaseVo getInfo(Integer caseId,Boolean isLogin) {
- CaseEntity caseEntity = this.getById(caseId);
- if(caseEntity == null){
- return null;
- }
- CaseVo caseVo = new CaseVo();
- BeanUtil.copyProperties(caseEntity,caseVo);
- if(caseEntity.getTmProjectId() != null){
- TmProject tmProject = tmProjectService.getById(caseEntity.getTmProjectId());
- if(tmProject!= null && tmProject.getIsDelete()!=0){
- throw new BusinessException(ResultCode.CASE_NOT_EXITS);
- }
- caseVo.setTmProject(tmProject);
- caseVo.setCaseTitle(tmProject.getProjectName());
- }
- if(isLogin){
- checkCaseAuth(caseVo);
- }
- return caseVo;
- }
- private void checkCaseAuth(CaseVo caseVo) {
- String share = SaHolder.getRequest().getHeader("sharePassword");
- if(StringUtils.isNotBlank(share) ) { //分享请求头
- return;
- }
- if(!StpUtil.isLogin()){
- throw new BusinessException(ResultCode.USER_NOT_LOGIN);
- }
- String page = SaHolder.getRequest().getHeader("page");
- if(StringUtils.isBlank(page) ) {
- throw new BusinessException(ResultCode.USER_NOT_LOGIN);
- }
- String deptId =(String) StpUtil.getExtra("deptId");
- //获取共享数据
- List<SceneDeptShare> sceneDeptShares = sceneDeptShareService.getByCaseIdAndDeptId(caseVo.getCaseId(),deptId);
- //0不共享,1查看,2编辑
- if(!sceneDeptShares.isEmpty()){
- for (SceneDeptShare sceneDeptShare : sceneDeptShares) {
- if(sceneDeptShare.getIsAuth() == 2){
- return;
- }
- if(sceneDeptShare.getIsAuth() == 1 && "view".equals(page)){
- return;
- }
- }
- }
- List<String> deptIds = tmDepartmentService.getDeptIds();
- if(deptIds.size() <=0){
- throw new BusinessException(ResultCode.NOT_PERMISSION);
- }
- String caseDeptId = caseVo.getDeptId();
- if(caseVo.getTmProject() != null){
- caseDeptId = caseVo.getTmProject().getDeptId();
- }
- List<String> deptIds2 = tmDepartmentService.getSonByDeptIdAndDeptIds(deptIds, deptId);
- if(!deptIds2.contains(caseDeptId)){
- throw new BusinessException(ResultCode.NOT_PERMISSION);
- }
- }
- @Override
- public void addFusionIds(CaseParam param) {
- if(param.getCaseId() == null || param.getFusionIds() == null ){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(param.getFusionIds().isEmpty()){
- List<CaseNumEntity> byCaseId = caseNumService.getByCaseId(param.getCaseId());
- if(byCaseId.isEmpty()){
- throw new BusinessException(ResultCode.REMOVE_ERROR);
- }
- }
- caseFusionService.addFusionIds(param.getFusionIds(),param.getCaseId());
- }
- @Override
- public List<FusionAndSceneVo> getFusionAndScene(Integer caseId, String type) {
- if(caseId == null || StringUtils.isBlank(type)){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- List<FusionAndSceneVo> voList = new ArrayList<>();
- if("fusion".equals(type)){
- List<CaseFusion> byCaseId = caseFusionService.getListByCaseId(caseId);
- for (CaseFusion caseFusion : byCaseId) {
- FusionAndSceneVo vo = new FusionAndSceneVo();
- vo.setTitle(caseFusion.getFusionTitle());
- vo.setFusionId(caseFusion.getFusionId());
- vo.setType("fusion");
- voList.add(vo);
- }
- return voList;
- }
- if("scene".equals(type)){
- List<CaseNumEntity> caseNums = caseNumService.getByCaseId(caseId);
- List<String> numList = caseNums.stream().map(CaseNumEntity::getNum).collect(Collectors.toList());
- List<ScenePlus> scenePlusList = scenePlusService.getByNumList(numList);
- HashMap<String, ScenePlus> map = new HashMap<>();
- scenePlusList.forEach(e-> map.put(e.getNum(),e));
- for (CaseNumEntity caseNum : caseNums) {
- ScenePlus scenePlus = map.get(caseNum.getNum());
- if(scenePlus == null){
- continue;
- }
- FusionAndSceneVo vo = new FusionAndSceneVo();
- vo.setSceneNumId(caseNum.getId());
- vo.setTitle(scenePlus.getTitle());
- vo.setNum(scenePlus.getNum());
- vo.setSceneType(caseNum.getNumType());
- vo.setType("scene");
- voList.add(vo);
- }
- return voList;
- }
- return voList;
- }
- @Override
- public void setMapShow(Integer caseId, Integer mapShow) {
- LambdaUpdateWrapper<CaseEntity> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(CaseEntity::getCaseId,caseId);
- wrapper.set(CaseEntity::getMapShow,mapShow);
- this.update(wrapper);
- }
- }
|