|
@@ -1,6 +1,7 @@
|
|
|
package com.fdkankan.indoor.core.service.impl;
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fdkankan.indoor.base.constant.CmdConstant;
|
|
@@ -254,6 +255,110 @@ public class OwenServiceImpl implements OwenService {
|
|
|
return Result.success("执行完成");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param isBatch 是否批量修改, 为0时进行批量修改
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result batchDefault(String isBatch) {
|
|
|
+ // sDri: 工作目录
|
|
|
+ String sDir = "/var/www/html/laser/maxkk/";
|
|
|
+ if ("dev".equals(configConstant.active)){
|
|
|
+ sDir = "F:\\work\\四维-激光相机\\data\\文件替换\\";
|
|
|
+
|
|
|
+ }
|
|
|
+ log.info("工作目录:{}", sDir);
|
|
|
+ String baseCssPath = sDir + "default/css/style.css";
|
|
|
+ String baseIndexJsPath = sDir + "default/js/index.js";
|
|
|
+ String baseIndexHtmlPath = sDir + "default/index.html";
|
|
|
+ String baseImgPath = sDir + "default/img";
|
|
|
+ File[] faFiles = new File(sDir).listFiles();
|
|
|
+ int i = 0;
|
|
|
+ for (File file : faFiles) {
|
|
|
+ String dirPath = file.getAbsolutePath();
|
|
|
+ String dirName = file.getName();
|
|
|
+ if (FileUtil.isDirectory(dirPath) && dirName.startsWith("t-")){
|
|
|
+ log.info("场景码目录:{}", dirPath);
|
|
|
+ log.info("目录场景码: {}", dirName);
|
|
|
+
|
|
|
+ // 替换css
|
|
|
+ this.writeFile(baseCssPath, sDir + dirName + "/css/style.css");
|
|
|
+ this.writeFile(baseIndexJsPath, sDir + dirName + "/js/index.js");
|
|
|
+ String sceneCodeIndexHtmlPath = sDir + dirName + "/index.html";
|
|
|
+ String title = getTitleByIndexHtml(sceneCodeIndexHtmlPath);
|
|
|
+ this.writeIndexHtml(baseIndexHtmlPath, sceneCodeIndexHtmlPath, dirName, title);
|
|
|
+ this.copyImg(baseImgPath, sDir + dirName + "/img");
|
|
|
+ i ++;
|
|
|
+ log.info("替换第: {} 个, 场景码: {}", i, dirName);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!"0".equals(isBatch)){
|
|
|
+ if (i==1){
|
|
|
+ log.info("单个执行");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return Result.success("替换数量:" + i);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String getTitleByIndexHtml(String indexPath){
|
|
|
+ if (!FileUtil.isFile(indexPath)) {
|
|
|
+ log.error("场景码输入文件不存在,请检查 : {}", indexPath);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ List<String> list = FileUtil.readLines(indexPath, "utf-8");
|
|
|
+ String title = "";
|
|
|
+ for (String line: list) {
|
|
|
+ line = StrUtil.trim(line);
|
|
|
+ if (line.startsWith("<title>") && line.endsWith("</title>")){
|
|
|
+ log.info("line: {}", line);
|
|
|
+ line = StrUtil.subBefore(line, "</title>", true);
|
|
|
+ line = StrUtil.subAfter(line, "<title>", true);
|
|
|
+ title = line;
|
|
|
+ log.info("标题: {}", title);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return title;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void copyImg(String inPath, String outPath){
|
|
|
+ FileUtil.copyContent(FileUtil.newFile(inPath), FileUtil.newFile(outPath), true);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 写文件
|
|
|
+ * @param inPath 输入文件地址
|
|
|
+ * @param outPath 输出文件地址
|
|
|
+ */
|
|
|
+ private void writeFile(String inPath, String outPath){
|
|
|
+ if (!FileUtil.isFile(inPath)) {
|
|
|
+ log.error("场景码输入文件不存在,请检查 : {}", inPath);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String s = FileUtil.readUtf8String(inPath);
|
|
|
+ FileUtil.writeUtf8String(s, outPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void writeIndexHtml(String inPath, String outPath, String sceneCode, String title){
|
|
|
+ String s = FileUtil.readUtf8String(inPath);
|
|
|
+ // 替换场景码
|
|
|
+ s = s.replaceAll("@replace", sceneCode);
|
|
|
+ if (StrUtil.isBlank(title)){
|
|
|
+ title = sceneCode;
|
|
|
+ }
|
|
|
+ s = s.replaceAll("@title", title);
|
|
|
+ FileUtil.writeUtf8String(s, outPath);
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testbatch(){
|
|
|
|