|
@@ -1,193 +1,193 @@
|
|
|
-package com.gis.service.impl;
|
|
|
-
|
|
|
-import com.gis.common.constant.MsgCode;
|
|
|
-import com.gis.common.util.Result;
|
|
|
-import com.gis.domain.dto.BaseDto;
|
|
|
-import com.gis.domain.dto.CatalogDto;
|
|
|
-import com.gis.domain.entity.CatalogEntity;
|
|
|
-import com.gis.domain.entity.SceneEntity;
|
|
|
-import com.gis.domain.tree.CatalogTree;
|
|
|
-import com.gis.domain.vo.CatalogSceneTree;
|
|
|
-import com.gis.domain.vo.CatalogVo;
|
|
|
-import com.gis.mapper.CatalogMapper;
|
|
|
-import com.gis.mapper.IBaseMapper;
|
|
|
-import com.gis.mapper.SceneMapper;
|
|
|
-import com.gis.service.CatalogService;
|
|
|
-import com.gis.service.SceneService;
|
|
|
-import com.gis.tree.CatalogTreeUtil;
|
|
|
-import com.gis.tree.SceneTreeUtil;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import javax.transaction.Transactional;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by owen on 2020/3/11 0011 16:16
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@Service
|
|
|
-@Transactional
|
|
|
-public class CatalogServiceImpl extends IBaseServiceImpl<CatalogEntity, Long> implements CatalogService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CatalogMapper entityMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SceneMapper sceneMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- SceneService sceneService;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public IBaseMapper<CatalogEntity, Long> getBaseMapper() {
|
|
|
- return this.entityMapper;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result saveEntity(CatalogDto param) {
|
|
|
- Long id = param.getId();
|
|
|
- CatalogEntity entity = null;
|
|
|
- if (id == null) {
|
|
|
- entity = new CatalogEntity();
|
|
|
- BeanUtils.copyProperties(param, entity);
|
|
|
- save(entity);
|
|
|
-
|
|
|
- // 若场景二级分组,把父分组场景移动到二级分组
|
|
|
- Long oldCatalogId = entity.getParentId();
|
|
|
- if (oldCatalogId != null) {
|
|
|
- sceneMapper.setCatalogByCatalogId(entity.getId(), oldCatalogId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- } else {
|
|
|
- entity = findById(id);
|
|
|
- if (entity == null) {
|
|
|
- log.error("对象不存在: " + id);
|
|
|
- Result.failure("对象不存在");
|
|
|
- }
|
|
|
-
|
|
|
- BeanUtils.copyProperties(param, entity);
|
|
|
- entity.setUpdateTime(new Date());
|
|
|
- update(entity);
|
|
|
-
|
|
|
- }
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result getCatalog(Long workId) {
|
|
|
- List<CatalogEntity> list = entityMapper.findByWorkId(workId);
|
|
|
- CatalogTreeUtil treeUtil = new CatalogTreeUtil(list);
|
|
|
- List<CatalogTree> catalogTrees = treeUtil.buildTree();
|
|
|
- return Result.success(treeUtil.buildTree());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result getScene(Long catalogId) {
|
|
|
- return Result.success(sceneService.findByCatalogId(catalogId));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public CatalogVo voFindById(Long catalogId) {
|
|
|
- return entityMapper.voFindById(catalogId);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<CatalogEntity> findByParentId(Long parentId) {
|
|
|
- return entityMapper.findByParentId(parentId);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result editEntity(BaseDto param) {
|
|
|
- Long id = param.getId();
|
|
|
- CatalogEntity entity = findById(id);
|
|
|
- if (entity == null) {
|
|
|
- log.error("对象不存在: " + id);
|
|
|
- Result.failure("对象不存在");
|
|
|
- }
|
|
|
-
|
|
|
- BeanUtils.copyProperties(param, entity);
|
|
|
- entity.setUpdateTime(new Date());
|
|
|
- update(entity);
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<CatalogEntity> findByWorkId(Long id) {
|
|
|
-
|
|
|
- return entityMapper.findByWorkId(id);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result listTree(Long workId) {
|
|
|
- List<CatalogEntity> list = entityMapper.findByWorkId(workId);
|
|
|
- CatalogTreeUtil treeUtil = new CatalogTreeUtil(list, sceneMapper);
|
|
|
- return Result.success(treeUtil.buildTree());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result webListTree(Long workId) {
|
|
|
- List<CatalogSceneTree> list = entityMapper.afindByWorkId(workId);
|
|
|
-
|
|
|
- SceneTreeUtil sceneTreeUtil = new SceneTreeUtil(list);
|
|
|
- return Result.success(sceneTreeUtil.buildTree());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result remove(Long id) {
|
|
|
-
|
|
|
- CatalogEntity entity = this.findById(id);
|
|
|
- if (entity == null) {
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
- List<SceneEntity> workScenes = sceneService.findByWorkId(entity.getWorkId());
|
|
|
- List<SceneEntity> catalogScenes = sceneService.findByCatalogId(id);
|
|
|
- if ((workScenes.size()-catalogScenes.size()) <= 0) {
|
|
|
- return Result.failure(MsgCode.e3002,"请至少保留一个场景");
|
|
|
- }
|
|
|
-
|
|
|
- // 递归删除
|
|
|
- this.delete(id);
|
|
|
-
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private void delete(Long id){
|
|
|
- CatalogEntity entity = this.findById(id);
|
|
|
- if (entity == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- entity.setIsDelete(1);
|
|
|
- entity.setUpdateTime(new Date());
|
|
|
- this.update(entity);
|
|
|
-
|
|
|
- // 删除分组,需要把对应的场景删除
|
|
|
- sceneMapper.setDeleteByCatalogId(id);
|
|
|
-
|
|
|
- List<CatalogEntity> parentList = entityMapper.findByParentId(id);
|
|
|
- if (parentList.size() > 0) {
|
|
|
- for (CatalogEntity catalogEntity : parentList) {
|
|
|
- // 递归删除
|
|
|
- delete(catalogEntity.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+//package com.gis.service.impl;
|
|
|
+//
|
|
|
+//import com.gis.common.constant.MsgCode;
|
|
|
+//import com.gis.common.util.Result;
|
|
|
+//import com.gis.domain.dto.BaseDto;
|
|
|
+//import com.gis.domain.dto.CatalogDto;
|
|
|
+//import com.gis.domain.entity.CatalogEntity;
|
|
|
+//import com.gis.domain.entity.SceneEntity;
|
|
|
+//import com.gis.domain.tree.CatalogTree;
|
|
|
+//import com.gis.domain.vo.CatalogSceneTree;
|
|
|
+//import com.gis.domain.vo.CatalogVo;
|
|
|
+//import com.gis.mapper.CatalogMapper;
|
|
|
+//import com.gis.mapper.IBaseMapper;
|
|
|
+//import com.gis.mapper.SceneMapper;
|
|
|
+//import com.gis.service.CatalogService;
|
|
|
+//import com.gis.service.SceneService;
|
|
|
+//import com.gis.tree.CatalogTreeUtil;
|
|
|
+//import com.gis.tree.SceneTreeUtil;
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
+//import org.springframework.beans.BeanUtils;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.stereotype.Service;
|
|
|
+//
|
|
|
+//import javax.transaction.Transactional;
|
|
|
+//import java.util.Date;
|
|
|
+//import java.util.List;
|
|
|
+//
|
|
|
+//
|
|
|
+///**
|
|
|
+// * Created by owen on 2020/3/11 0011 16:16
|
|
|
+// */
|
|
|
+//@Slf4j
|
|
|
+//@Service
|
|
|
+//@Transactional
|
|
|
+//public class CatalogServiceImpl extends IBaseServiceImpl<CatalogEntity, Long> implements CatalogService {
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private CatalogMapper entityMapper;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private SceneMapper sceneMapper;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// SceneService sceneService;
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public IBaseMapper<CatalogEntity, Long> getBaseMapper() {
|
|
|
+// return this.entityMapper;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Result saveEntity(CatalogDto param) {
|
|
|
+// Long id = param.getId();
|
|
|
+// CatalogEntity entity = null;
|
|
|
+// if (id == null) {
|
|
|
+// entity = new CatalogEntity();
|
|
|
+// BeanUtils.copyProperties(param, entity);
|
|
|
+// save(entity);
|
|
|
+//
|
|
|
+// // 若场景二级分组,把父分组场景移动到二级分组
|
|
|
+// Long oldCatalogId = entity.getParentId();
|
|
|
+// if (oldCatalogId != null) {
|
|
|
+// sceneMapper.setCatalogByCatalogId(entity.getId(), oldCatalogId);
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// entity = findById(id);
|
|
|
+// if (entity == null) {
|
|
|
+// log.error("对象不存在: " + id);
|
|
|
+// Result.failure("对象不存在");
|
|
|
+// }
|
|
|
+//
|
|
|
+// BeanUtils.copyProperties(param, entity);
|
|
|
+// entity.setUpdateTime(new Date());
|
|
|
+// update(entity);
|
|
|
+//
|
|
|
+// }
|
|
|
+// return Result.success();
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Result getCatalog(String workId) {
|
|
|
+// List<CatalogEntity> list = entityMapper.findByWorkId(workId);
|
|
|
+// CatalogTreeUtil treeUtil = new CatalogTreeUtil(list);
|
|
|
+// List<CatalogTree> catalogTrees = treeUtil.buildTree();
|
|
|
+// return Result.success(treeUtil.buildTree());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Result getScene(Long catalogId) {
|
|
|
+// return Result.success(sceneService.findByCatalogId(catalogId));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public CatalogVo voFindById(Long catalogId) {
|
|
|
+// return entityMapper.voFindById(catalogId);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<CatalogEntity> findByParentId(Long parentId) {
|
|
|
+// return entityMapper.findByParentId(parentId);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Result editEntity(BaseDto param) {
|
|
|
+// Long id = param.getId();
|
|
|
+// CatalogEntity entity = findById(id);
|
|
|
+// if (entity == null) {
|
|
|
+// log.error("对象不存在: " + id);
|
|
|
+// Result.failure("对象不存在");
|
|
|
+// }
|
|
|
+//
|
|
|
+// BeanUtils.copyProperties(param, entity);
|
|
|
+// entity.setUpdateTime(new Date());
|
|
|
+// update(entity);
|
|
|
+// return Result.success();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<CatalogEntity> findByWorkId(String id) {
|
|
|
+//
|
|
|
+// return entityMapper.findByWorkId(id);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Result listTree(String workId) {
|
|
|
+// List<CatalogEntity> list = entityMapper.findByWorkId(workId);
|
|
|
+// CatalogTreeUtil treeUtil = new CatalogTreeUtil(list, sceneMapper);
|
|
|
+// return Result.success(treeUtil.buildTree());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Result webListTree(String workId) {
|
|
|
+// List<CatalogSceneTree> list = entityMapper.afindByWorkId(workId);
|
|
|
+//
|
|
|
+// SceneTreeUtil sceneTreeUtil = new SceneTreeUtil(list);
|
|
|
+// return Result.success(sceneTreeUtil.buildTree());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Result remove(Long id) {
|
|
|
+//
|
|
|
+// CatalogEntity entity = this.findById(id);
|
|
|
+// if (entity == null) {
|
|
|
+// return Result.success();
|
|
|
+// }
|
|
|
+//
|
|
|
+// List<SceneEntity> workScenes = sceneService.findByWorkId(entity.getWorkId());
|
|
|
+// List<SceneEntity> catalogScenes = sceneService.findByCatalogId(id);
|
|
|
+// if ((workScenes.size()-catalogScenes.size()) <= 0) {
|
|
|
+// return Result.failure(MsgCode.e3002,"请至少保留一个场景");
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 递归删除
|
|
|
+// this.delete(id);
|
|
|
+//
|
|
|
+// return Result.success();
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// private void delete(Long id){
|
|
|
+// CatalogEntity entity = this.findById(id);
|
|
|
+// if (entity == null) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// entity.setIsDelete(1);
|
|
|
+// entity.setUpdateTime(new Date());
|
|
|
+// this.update(entity);
|
|
|
+//
|
|
|
+// // 删除分组,需要把对应的场景删除
|
|
|
+// sceneMapper.setDeleteByCatalogId(id);
|
|
|
+//
|
|
|
+// List<CatalogEntity> parentList = entityMapper.findByParentId(id);
|
|
|
+// if (parentList.size() > 0) {
|
|
|
+// for (CatalogEntity catalogEntity : parentList) {
|
|
|
+// // 递归删除
|
|
|
+// delete(catalogEntity.getId());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//}
|