|
@@ -1,27 +1,38 @@
|
|
|
package com.gis.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.gis.common.constant.ConfigConstant;
|
|
|
import com.gis.common.util.*;
|
|
|
import com.gis.domain.dto.PageDto;
|
|
|
+import com.gis.domain.dto.SomeDataDto;
|
|
|
import com.gis.domain.dto.WorkDto;
|
|
|
import com.gis.domain.entity.CatalogEntity;
|
|
|
+import com.gis.domain.entity.SceneEntity;
|
|
|
import com.gis.domain.entity.WorkEntity;
|
|
|
+import com.gis.domain.tree.CatalogTree;
|
|
|
+import com.gis.domain.vo.WorkInfoVo;
|
|
|
import com.gis.mapper.CatalogMapper;
|
|
|
import com.gis.mapper.SceneMapper;
|
|
|
import com.gis.mapper.WorkMapper;
|
|
|
import com.gis.mapper.IBaseMapper;
|
|
|
import com.gis.service.CatalogService;
|
|
|
+import com.gis.service.SceneService;
|
|
|
import com.gis.service.WorkService;
|
|
|
+import com.gis.tree.CatalogTreeUtil;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -51,6 +62,12 @@ public class WorkServiceImpl extends IBaseServiceImpl<WorkEntity, Long> implemen
|
|
|
@Autowired
|
|
|
SceneMapper sceneMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ SceneService sceneService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AliyunOssUtil aliyunOssUtil;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public IBaseMapper<WorkEntity, Long> getBaseMapper() {
|
|
@@ -58,7 +75,6 @@ public class WorkServiceImpl extends IBaseServiceImpl<WorkEntity, Long> implemen
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public Result search(PageDto param) {
|
|
|
startPage(param);
|
|
@@ -66,78 +82,69 @@ public class WorkServiceImpl extends IBaseServiceImpl<WorkEntity, Long> implemen
|
|
|
return Result.success(new PageInfo<>(search));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 目前只是用来保存密码, 也可以使用保存实体信息
|
|
|
+ */
|
|
|
@Override
|
|
|
public Result<WorkEntity> entitySave(WorkDto param) {
|
|
|
Long id = param.getId();
|
|
|
- int isPassword = 0;
|
|
|
- if (StringUtils.isNotBlank(param.getPassword())) {
|
|
|
- isPassword = 1;
|
|
|
+ WorkEntity entity = this.findById(id);
|
|
|
+
|
|
|
+ if (entity == null) {
|
|
|
+ return Result.failure("对象不存在");
|
|
|
}
|
|
|
- WorkEntity entity = null;
|
|
|
- if (id == null) {
|
|
|
- entity = new WorkEntity();
|
|
|
- BeanUtils.copyProperties(param, entity);
|
|
|
- entity.setUserId(getUserNameForToken());
|
|
|
- entity.setIsPassword(isPassword);
|
|
|
- this.save(entity);
|
|
|
- } else {
|
|
|
- entity = this.findById(id);
|
|
|
-
|
|
|
- if (entity == null) {
|
|
|
- return Result.failure("对象不存在");
|
|
|
- }
|
|
|
- BeanUtils.copyProperties(param, entity);
|
|
|
-
|
|
|
- // 创建二维码
|
|
|
- String qrCode = entity.getQrCode();
|
|
|
- if (StringUtils.isBlank(qrCode)) {
|
|
|
- // 二维码url
|
|
|
- String url = configConstant.domain4dKK + "/panorama/show.html?id=" + id;
|
|
|
- qrCode = qrCodeUtils.generateLogoQrCode(url, configConstant.serverBasePath, configConstant.ossBasePath, configConstant.ossDomain);
|
|
|
- entity.setQrCode(qrCode);
|
|
|
- entity.setShare(url);
|
|
|
- }
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
|
|
|
- if (entity.getStatus() == 0) {
|
|
|
- // 设置为显示状态
|
|
|
- entity.setStatus(1);
|
|
|
- // 创建默认场景
|
|
|
- initCatalog(id);
|
|
|
- }
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ this.update(entity);
|
|
|
|
|
|
- entity.setUpdateTime(new Date());
|
|
|
- entity.setIsPassword(isPassword);
|
|
|
- this.update(entity);
|
|
|
- }
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 创建默认场景
|
|
|
- * @param workId
|
|
|
- */
|
|
|
- private void initCatalog(Long workId) {
|
|
|
- List<CatalogEntity> list = catalogMapper.findByWorkId(workId);
|
|
|
- if (list.size() == 0) {
|
|
|
- CatalogEntity entity = new CatalogEntity();
|
|
|
- entity.setName("全部场景");
|
|
|
- entity.setWorkId(workId);
|
|
|
- catalogService.save(entity);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public Result<WorkEntity> entityAdd() {
|
|
|
WorkEntity entity = new WorkEntity();
|
|
|
entity.setUserId(getUserNameForToken());
|
|
|
this.save(entity);
|
|
|
+
|
|
|
+ // 创建someData
|
|
|
+
|
|
|
+ // 获取文件内容
|
|
|
+ String content = FileUtils.getResourceContent("data/someData.json");
|
|
|
+
|
|
|
+ Long id = entity.getId();
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(content);
|
|
|
+ jsonObject.put("id", id + "");
|
|
|
+
|
|
|
+
|
|
|
+ // 创建二维码、二维码url
|
|
|
+ String shareUrl = configConstant.domain4dKK + "/panorama/show.html?id=" + id;
|
|
|
+ String qrCode = qrCodeUtils.generateLogoQrCode(shareUrl, configConstant.serverBasePath, configConstant.ossBasePath, configConstant.ossDomain);
|
|
|
+ jsonObject.put("share", shareUrl);
|
|
|
+ jsonObject.put("qrCode", qrCode);
|
|
|
+
|
|
|
+
|
|
|
+ String baseSomeDataPath = id + "/someData.json";
|
|
|
+
|
|
|
+ String ossKeyPath = configConstant.ossBasePath + baseSomeDataPath;
|
|
|
+
|
|
|
+ try {
|
|
|
+ aliyunOssUtil.upload(jsonObject.toJSONString().getBytes(), ossKeyPath);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ String ossUrl = configConstant.ossDomain + ossKeyPath;
|
|
|
+ log.info("ossSomeData:{}", ossUrl);
|
|
|
+
|
|
|
return Result.success(entity);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public Result remove(Long id) {
|
|
|
WorkEntity entity = this.findById(id);
|
|
@@ -160,5 +167,121 @@ public class WorkServiceImpl extends IBaseServiceImpl<WorkEntity, Long> implemen
|
|
|
entityMapper.addVisit(id);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result<WorkInfoVo> getDetail(Long id) {
|
|
|
+ WorkEntity entity = this.findById(id);
|
|
|
+ if (entity == null) {
|
|
|
+ return Result.failure("对象不存在");
|
|
|
+ }
|
|
|
+ WorkInfoVo workInfoVo = new WorkInfoVo();
|
|
|
+ BeanUtils.copyProperties(entity, workInfoVo);
|
|
|
+
|
|
|
+ // 获取分组信息
|
|
|
+ List<CatalogEntity> list = catalogService.findByWorkId(id);
|
|
|
+
|
|
|
+ // 处理第二级
|
|
|
+ Stream<CatalogEntity> stream2 = list.stream();
|
|
|
+ Stream<CatalogEntity> sub = stream2.filter(s -> s.getParentId() != null);
|
|
|
+ List<CatalogEntity> catalogs = sub.collect(Collectors.toList());
|
|
|
+ workInfoVo.setCatalogs(catalogs);
|
|
|
+
|
|
|
+
|
|
|
+ // 处理第一级
|
|
|
+ CatalogTreeUtil treeUtil = new CatalogTreeUtil(list);
|
|
|
+ List<CatalogTree> trees = treeUtil.buildTree();
|
|
|
+
|
|
|
+ List<CatalogEntity> c1 = new ArrayList<>();
|
|
|
+ for (CatalogTree tree : trees) {
|
|
|
+ CatalogEntity catalogEntity = new CatalogEntity();
|
|
|
+ BeanUtils.copyProperties(tree, catalogEntity);
|
|
|
+ // 有子结节
|
|
|
+ List<CatalogTree> children = tree.getChildren();
|
|
|
+
|
|
|
+ // 子节点
|
|
|
+ List<Long> child = new ArrayList<>();
|
|
|
+ if (children.size() > 0) {
|
|
|
+ for (CatalogTree son : children) {
|
|
|
+ child.add(son.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catalogEntity.setChildren(child);
|
|
|
+ c1.add(catalogEntity);
|
|
|
+ }
|
|
|
+ workInfoVo.setCatalogRoot(c1);
|
|
|
+
|
|
|
+ // 处理场景
|
|
|
+ List<SceneEntity> scenes = sceneService.findByWorkId(id);
|
|
|
+ workInfoVo.setScenes(scenes);
|
|
|
+
|
|
|
+ return Result.success(workInfoVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result edit(SomeDataDto param) {
|
|
|
+
|
|
|
+ // 更新作品信息
|
|
|
+ boolean isEdit = editEntity(param);
|
|
|
+ if (!isEdit) {
|
|
|
+ return Result.failure("对象不存在");
|
|
|
+ }
|
|
|
+ log.info("更新作品完成");
|
|
|
+ // 保存someData.json
|
|
|
+ editSomeData( param);
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新作品实体信息
|
|
|
+ */
|
|
|
+ private boolean editEntity(SomeDataDto param) {
|
|
|
+
|
|
|
+ Long id = param.getId();
|
|
|
+ WorkEntity entity = this.findById(id);
|
|
|
+ if (entity == null) {
|
|
|
+ log.error("对象不存在: " + id);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ String someData = param.getSomeData();
|
|
|
+ JSONObject sd = JSONObject.parseObject(someData);
|
|
|
+ entity.setName(sd.getString("name"));
|
|
|
+ entity.setDescription(sd.getString("description"));
|
|
|
+ entity.setIcon(sd.getString("icon"));
|
|
|
+ entity.setShare(sd.getString("share"));
|
|
|
+ entity.setQrCode(sd.getString("qrCode"));
|
|
|
+ entity.setStatus(sd.getInteger("status"));
|
|
|
+
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ this.update(entity);
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新someData.json
|
|
|
+ */
|
|
|
+ private void editSomeData(SomeDataDto param) {
|
|
|
+
|
|
|
+ Long id = param.getId();
|
|
|
+ String baseSomeDathPath = id + "/someData.json";
|
|
|
+ String saveSomeDataPath = configConstant.serverBasePath + baseSomeDathPath;
|
|
|
+ // 写入服务器
|
|
|
+ FileUtil.writeUtf8String(param.getSomeData(), saveSomeDataPath);
|
|
|
+
|
|
|
+ // 保存oss
|
|
|
+ if (!FileUtil.isFile(saveSomeDataPath)) {
|
|
|
+ Result.failure("服务器someData.json文件不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ String ossKeyPath = configConstant.ossBasePath + baseSomeDathPath;
|
|
|
+ aliyunOssUtil.upload(saveSomeDataPath, ossKeyPath);
|
|
|
+ log.info("someData.json 上传完成 : {}", ossKeyPath);
|
|
|
+ String ossUrl = configConstant.ossDomain + ossKeyPath;
|
|
|
+ log.info("ossUrl: {}", ossUrl);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|