|
@@ -0,0 +1,213 @@
|
|
|
+package com.gis.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import com.gis.common.constant.ConfigConstant;
|
|
|
+import com.gis.common.util.AliyunOssUtil;
|
|
|
+import com.gis.common.util.FileUtils;
|
|
|
+import com.gis.common.util.Result;
|
|
|
+import com.gis.domain.entity.IconEntity;
|
|
|
+import com.gis.mapper.IBaseMapper;
|
|
|
+import com.gis.mapper.IconMapper;
|
|
|
+import com.gis.service.IconService;
|
|
|
+import com.gis.service.TestService;
|
|
|
+import com.gis.util.ReplaceVo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.junit.Test;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by owen on 2021/11/08 0011 16:16
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class TestServiceImpl implements TestService {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ConfigConstant configConstant;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ FileUtils fileUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AliyunOssUtil aliyunOssUtil;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Result upload(MultipartFile file) {
|
|
|
+ Map<String, Object> map = fileUtils.renameUploadOssBye(file, configConstant.ossBasePath, configConstant.ossDomain, "icon/");
|
|
|
+ IconEntity entity = new IconEntity();
|
|
|
+ entity.setFileName((String) map.get("fileName"));
|
|
|
+ Object ossUrl = map.get("ossUrl");
|
|
|
+ entity.setOssPath(ossUrl.toString());
|
|
|
+
|
|
|
+
|
|
|
+ return Result.success(ossUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result batchReplaceSomeData(String isBatch) {
|
|
|
+ String basePath = "F:\\work\\四维-全景看看\\data\\";
|
|
|
+ String replacePath = basePath + "replace.csv";
|
|
|
+ List<String> str = FileUtil.readLines(replacePath, "utf-8");
|
|
|
+ //字符串转对象
|
|
|
+ ReplaceVo vo;
|
|
|
+ Set<String> workIds = new HashSet<>();
|
|
|
+ List<ReplaceVo> list = new ArrayList<>();
|
|
|
+ for (int i = 1; i < str.size(); i++) {
|
|
|
+ String s = str.get(i);
|
|
|
+ String[] split = s.split(",");
|
|
|
+ vo = new ReplaceVo();
|
|
|
+ vo.setOName(split[0]);
|
|
|
+ vo.setCreateTime(split[1]);
|
|
|
+ vo.setUserId(split[2]);
|
|
|
+ vo.setOCode(split[3]);
|
|
|
+ vo.setOName(split[4]);
|
|
|
+ vo.setNCode(split[5]);
|
|
|
+ vo.setWorkId(split[6]);
|
|
|
+
|
|
|
+ workIds.add(vo.getWorkId());
|
|
|
+ list.add(vo);
|
|
|
+ }
|
|
|
+ // 下载someData.json
|
|
|
+// downloadSomeDataJson(workIds, basePath);
|
|
|
+ editSomeData(basePath, isBatch, list);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取replace.csv
|
|
|
+ *
|
|
|
+ * https://www.4dkankan.com/panorama/show.html?id=606&vr=fd720_7B6nNaWQO
|
|
|
+ *
|
|
|
+ * https://www.4dkankan.com/panorama/show.html?id=566&vr=fd720_1jKqSxWLe
|
|
|
+ *
|
|
|
+ * fd720_1AOhUJZoI -> fd720_A6yCltViq
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void readReplaceFile(){
|
|
|
+ String basePath = "F:\\work\\四维-全景看看\\data\\";
|
|
|
+ String replacePath = basePath + "replace.csv";
|
|
|
+ List<String> str = FileUtil.readLines(replacePath, "utf-8");
|
|
|
+ //字符串转对象
|
|
|
+ ReplaceVo vo;
|
|
|
+ Set<String> workIds = new HashSet<>();
|
|
|
+ List<ReplaceVo> list = new ArrayList<>();
|
|
|
+ for (int i = 1; i < str.size(); i++) {
|
|
|
+ String s = str.get(i);
|
|
|
+ String[] split = s.split(",");
|
|
|
+ vo = new ReplaceVo();
|
|
|
+ vo.setOName(split[0]);
|
|
|
+ vo.setCreateTime(split[1]);
|
|
|
+ vo.setUserId(split[2]);
|
|
|
+ vo.setOCode(split[3]);
|
|
|
+ vo.setOName(split[4]);
|
|
|
+ vo.setNCode(split[5]);
|
|
|
+ vo.setWorkId(split[6]);
|
|
|
+
|
|
|
+ workIds.add(vo.getWorkId());
|
|
|
+ list.add(vo);
|
|
|
+ }
|
|
|
+ // 下载someData.json
|
|
|
+// downloadSomeDataJson(workIds, basePath);
|
|
|
+ // 编辑oss
|
|
|
+ editSomeData(basePath, "1", list);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param workIds 590, 580, 582, 571, 583, 573, 584, 585, 586, 575, 587, 588, 577, 566, 589, 578, 579, 568, 606
|
|
|
+ * @param basePath
|
|
|
+ */
|
|
|
+ private void downloadSomeDataJson(Set<String> workIds, String basePath) {
|
|
|
+ log.info("workIds: {}", workIds);
|
|
|
+ log.info("保存路径: {}", basePath);
|
|
|
+ //https://4dkk.4dage.com/720yun_fd_manage/606/someData.json?m=
|
|
|
+ String baseUrl = "https://4dkk.4dage.com/720yun_fd_manage/";
|
|
|
+ String url;
|
|
|
+ for (String workId : workIds) {
|
|
|
+ // oss下载someData.json
|
|
|
+ url = baseUrl + workId + "/someData.json?m="+ System.currentTimeMillis();
|
|
|
+ HttpUtil.downloadFile(url, basePath + workId + "/someData.json");
|
|
|
+ log.info("下载someData完成: {}", workId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void editSomeData(String basePath, String isBatch, List<ReplaceVo> list){
|
|
|
+ File[] faFiles = new File(basePath).listFiles();
|
|
|
+ int i = 0;
|
|
|
+ for (File file : faFiles) {
|
|
|
+ String dirPath = file.getAbsolutePath();
|
|
|
+ String dirName = file.getName();
|
|
|
+ if (FileUtil.isDirectory(dirPath)){
|
|
|
+ log.info("工作目录:{}", dirPath);
|
|
|
+ log.info("工作码: {}", dirName);
|
|
|
+ String outPath = dirPath + "/b/someData.json";
|
|
|
+ this.writeFile(dirPath + "/someData.json",outPath, list, dirName);
|
|
|
+
|
|
|
+ log.info("替换第: {} 个, 场景码: {}", i, dirName);
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+
|
|
|
+ if (!"0".equals(isBatch)){
|
|
|
+ if (i==1){
|
|
|
+ log.info("单个执行");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 写文件
|
|
|
+ * @param inPath 输入文件地址
|
|
|
+ */
|
|
|
+ private void writeFile(String inPath, String outPath, List<ReplaceVo> list, String workId){
|
|
|
+ if (!FileUtil.isFile(inPath)) {
|
|
|
+ log.error("场景码输入文件不存在,请检查 : {}", inPath);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String s = FileUtil.readUtf8String(inPath);
|
|
|
+ for (ReplaceVo vo : list) {
|
|
|
+ String oCode = vo.getOCode();
|
|
|
+ String oName = vo.getOName();
|
|
|
+ if (s.contains(oCode) || s.contains(oName)){
|
|
|
+ log.info("有替换内容, 旧场景码:{}, 新场景码:{}", oCode, vo.getNCode());
|
|
|
+ s = s.replaceAll(oCode, vo.getNCode());
|
|
|
+ s = s.replaceAll(oName, vo.getNName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ FileUtil.writeUtf8String(s, outPath);
|
|
|
+ log.info("someData更新完成: {}", outPath);
|
|
|
+
|
|
|
+ // 更新到oss
|
|
|
+ ossUploadSomeData(outPath, workId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ossUploadSomeData(String srcPath, String workId){
|
|
|
+ log.info("oss准备上传: {}", srcPath);
|
|
|
+ String targetPath = configConstant.ossBasePath + workId + "/someData.json";
|
|
|
+ log.info("oss上传地址: {}", targetPath);
|
|
|
+ aliyunOssUtil.upload(srcPath, targetPath);
|
|
|
+ log.info("上传oss完成: {}", targetPath);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|