|
@@ -7,10 +7,12 @@ import com.gis.common.util.Result;
|
|
|
import com.gis.domain.dto.DirDto;
|
|
|
import com.gis.domain.dto.DirMoveDto;
|
|
|
import com.gis.domain.entity.DirEntity;
|
|
|
+import com.gis.domain.entity.WorkEntity;
|
|
|
import com.gis.mapper.DirMapper;
|
|
|
import com.gis.mapper.IBaseMapper;
|
|
|
import com.gis.service.DirService;
|
|
|
import com.gis.service.FodderService;
|
|
|
+import com.gis.service.WorkService;
|
|
|
import com.gis.tree.DirTreeUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -33,6 +35,9 @@ public class DirServiceImpl extends IBaseServiceImpl<DirEntity, Long> implements
|
|
|
@Autowired
|
|
|
FodderService fodderService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ WorkService workService;
|
|
|
+
|
|
|
@Override
|
|
|
public IBaseMapper<DirEntity, Long> getBaseMapper() {
|
|
|
return this.entityMapper;
|
|
@@ -72,16 +77,88 @@ public class DirServiceImpl extends IBaseServiceImpl<DirEntity, Long> implements
|
|
|
@Override
|
|
|
public Result move(DirMoveDto param) {
|
|
|
|
|
|
- this.updateParentId(param.getParentId(), param.getDirIds());
|
|
|
+ // 移动目录
|
|
|
+ this.updateParentId(param.getParentId(), param.getDirIds(), param.getAncestors());
|
|
|
+ // 移动素材
|
|
|
fodderService.updateDirId(param.getParentId(), param.getFodderIds());
|
|
|
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
- private void updateParentId(Long parentId, String dirIds){
|
|
|
+ /**
|
|
|
+ * 删除目录
|
|
|
+ * 若删除的文件夹包括图片、视频、音频,可直接删除
|
|
|
+ * 若删除的对象包括被全景作品或三维场景引用的全景图,则提示无法删除,文件夹或未被引用的素材可删除
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result remove(Long id) {
|
|
|
+ DirEntity entity = this.findById(id);
|
|
|
+ String type = entity.getType();
|
|
|
+ if ("pano".equals(type)){
|
|
|
+ // 查询子节点
|
|
|
+ String dirs = getChildIdById(id);
|
|
|
+ BaseRuntimeException.isTrue(checkPanoUse(dirs), ErrorEnum.FAILURE_CODE_3101.code(), ErrorEnum.FAILURE_CODE_3101.message());
|
|
|
+
|
|
|
+ this.remove(id);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 子目录跟子素材没有进行递归删除
|
|
|
+ this.remove(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据目录id获取子目录id
|
|
|
+ private String getChildIdById(Long id){
|
|
|
+ String format = StrUtil.format("SELECT id FROM tb_dir WHERE is_delete=0 and ( id = {} or find_in_set({} , ancestors ))", id, id);
|
|
|
+ List<String> list = entityMapper.getListStr(format);
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ String ids = null;
|
|
|
+ if (list.size() > 0){
|
|
|
+ for (String s : list) {
|
|
|
+ builder.append(s).append(",");
|
|
|
+ }
|
|
|
+ ids = builder.toString();
|
|
|
+ ids = StrUtil.subBefore(ids, ",", true);
|
|
|
+
|
|
|
+ }
|
|
|
+ log.info("查询的子目录跟本身目录id:{}", ids);
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查该目录下的场景是否被使用
|
|
|
+ private boolean checkPanoUse(String dirs){
|
|
|
+ log.info("检查的目录集合id: {}", dirs);
|
|
|
+ boolean isUser = false;
|
|
|
+ // 查询目录下的场景码
|
|
|
+ List<String> sceneCodes = fodderService.getSceneCodeByParentIds(dirs);
|
|
|
+ // 查找该用户的作品
|
|
|
+ List<WorkEntity> works = workService.getUserWork();
|
|
|
+ // 匹配场景码
|
|
|
+ for (String sceneCode : sceneCodes) {
|
|
|
+ for (WorkEntity entity : works) {
|
|
|
+ String codes = entity.getSceneCodes();
|
|
|
+ if (StrUtil.isNotBlank(codes)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (codes.contains(sceneCode)){
|
|
|
+ log.error("此场景:{} 被该作品:{} 引用", sceneCode, entity.getId());
|
|
|
+ isUser = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return isUser;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateParentId(Long parentId, String dirIds, String ancestors){
|
|
|
if (StrUtil.isNotBlank(dirIds)){
|
|
|
log.info("移动目录: {} 到 {}", dirIds, parentId);
|
|
|
- entityMapper.updateParentId(StrUtil.format("update tb_dir set parent_id={} where is_delete=0 and id in ({}) ", parentId, dirIds));
|
|
|
+ entityMapper.updateParentId(StrUtil.format("update tb_dir set parent_id={}, ancestors={} where is_delete=0 and id in ({}) ", parentId,ancestors, dirIds));
|
|
|
}
|
|
|
|
|
|
}
|