Browse Source

正式环境批量替换someData文件

wuweihao 3 năm trước cách đây
mục cha
commit
223b7e1927

+ 13 - 2
720yun_fd_manage/gis_application/src/main/resources/application-loc.properties

@@ -75,13 +75,24 @@ spring.rabbitmq.template.mandatory=true
 
 
 # oss info
+#oss.point=http://oss-cn-shenzhen.aliyuncs.com
+#oss.key=LTAIUrvuHqj8pvry
+#oss.secrecy=JLOVl0k8Ke0aaM8nLMMiUAZ3EiiqI4
+#oss.bucket=oss-xiaoan
+#oss.type=oss
+#oss.file.path=${project.name}/
+#oss.domain=http://ossxiaoan.4dage.com/
+
+# pro oss info
 oss.point=http://oss-cn-shenzhen.aliyuncs.com
 oss.key=LTAIUrvuHqj8pvry
 oss.secrecy=JLOVl0k8Ke0aaM8nLMMiUAZ3EiiqI4
-oss.bucket=oss-xiaoan
+oss.bucket=4dkankan
 oss.type=oss
 oss.file.path=${project.name}/
-oss.domain=http://ossxiaoan.4dage.com/
+# \u56DB\u7EF4\u770B\u770Boss cdn\u57DF\u540D
+oss.domain=https://4dkk.4dage.com/
+
 
 # swagger2 \u8BBE\u7F6E\u5168\u5C40\u5B57\u4F53\u683C\u5F0F\u4E3Autf-8
 swagger.package=com.gis.web.controller

+ 16 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/service/TestService.java

@@ -0,0 +1,16 @@
+package com.gis.service;
+
+
+import com.gis.common.util.Result;
+import com.gis.domain.entity.IconEntity;
+import org.springframework.web.multipart.MultipartFile;
+
+
+/**
+ * Created by owen on 2020/3/11 0011 16:14
+ */
+public interface TestService  {
+
+
+    Result batchReplaceSomeData(String isBatch);
+}

+ 213 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/service/impl/TestServiceImpl.java

@@ -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);
+
+    }
+
+}

+ 26 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/util/ReplaceVo.java

@@ -0,0 +1,26 @@
+package com.gis.util;
+
+import lombok.Data;
+
+/**
+ * Created by owen on 2021/12/23 0023 16:06
+ */
+@Data
+public class ReplaceVo {
+
+    // 旧名字
+    private String oName;
+
+    private String createTime;
+
+    private String userId;
+
+    // 旧名字
+    private String oCode;
+
+    private String nName;
+
+    private String nCode;
+
+    private String workId;
+}

+ 135 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/util/SomeDataReplace.java

@@ -0,0 +1,135 @@
+package com.gis.util;
+
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.http.HttpUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.crypto.hash.Hash;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Created by owen on 2021/12/23 0023 15:23
+ *
+ * 批量替换someData文件
+ */
+@Slf4j
+public class SomeDataReplace {
+
+
+    /**
+     * 读取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);
+        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);
+
+                this.writeFile(dirPath + "/someData.json", list);
+
+                log.info("替换第: {} 个, 场景码: {}", i, dirName);
+            }
+            i++;
+
+            if (!"0".equals(isBatch)){
+                if (i==1){
+                    log.info("单个执行");
+                    break;
+                }
+            }
+
+        }
+    }
+
+    /**
+     * 写文件
+     * @param inPath 输入文件地址
+     */
+    private void writeFile(String inPath, List<ReplaceVo> list){
+        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)){
+                s = s.replaceAll(oCode, vo.getNCode());
+                s = s.replaceAll(oName, vo.getNName());
+            }
+        }
+
+        FileUtil.writeUtf8String(s, inPath);
+        log.info("someData更新完成: {}", inPath);
+    }
+
+
+
+
+}

+ 11 - 0
720yun_fd_manage/gis_web/src/main/java/com/gis/web/controller/TestController.java

@@ -11,6 +11,7 @@ import com.gis.common.util.Result;
 import com.gis.domain.entity.SceneEntity;
 import com.gis.mapper.SceneMapper;
 import com.gis.service.SceneService;
+import com.gis.service.TestService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -59,6 +60,9 @@ public class TestController extends BaseController {
     @Autowired
     private RedisTemplate<String, String> redisTemplate;
 
+    @Autowired
+    TestService testService;
+
 
 
 
@@ -212,6 +216,13 @@ public class TestController extends BaseController {
     }
 
 
+//    @GetMapping("batchReplaceSomeData")
+//    @ApiOperation(value = "2021-12-23_批量替换someData", notes = "isBatch,0:批量替换, 其他单个替换")
+//    public Result batchReplaceSomeData(String isBatch){
+//        return testService.batchReplaceSomeData(isBatch);
+//    }
+
+