|
@@ -17,13 +17,18 @@
|
|
|
package org.springblade.manager.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
|
import org.jsoup.nodes.Element;
|
|
|
import org.jsoup.select.Elements;
|
|
|
+import org.springblade.common.constant.CommonConstant;
|
|
|
+import org.springblade.common.utils.CommonUtil;
|
|
|
+import org.springblade.core.tool.utils.FileUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.IoUtil;
|
|
|
+import org.springblade.core.tool.utils.ResourceUtil;
|
|
|
import org.springblade.manager.entity.TextdictInfo;
|
|
|
import org.springblade.manager.entity.WbsTreePrivate;
|
|
|
import org.springblade.manager.mapper.TextdictInfoMapper;
|
|
@@ -31,11 +36,16 @@ import org.springblade.manager.mapper.WbsTreePrivateMapper;
|
|
|
import org.springblade.manager.service.ISignConfigService;
|
|
|
import org.springblade.manager.service.ITextdictInfoService;
|
|
|
import org.springblade.manager.utils.FileUtils;
|
|
|
+import org.springblade.manager.vo.TextdictBy345VO;
|
|
|
import org.springblade.manager.vo.TextdictInfoVO;
|
|
|
+import org.springblade.system.cache.ParamCache;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -170,4 +180,122 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void saveHtmlDefault(TextdictBy345VO textdictInfo) {
|
|
|
+ String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
|
|
|
+ String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
|
|
|
+ WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.getByPKeyId(textdictInfo.getTableId());
|
|
|
+ try {
|
|
|
+ File file1 = ResourceUtil.getFile(wbsTreePrivate.getHtmlUrl());
|
|
|
+ InputStream fileInputStream;
|
|
|
+ if (file1.exists()) {
|
|
|
+ fileInputStream = new FileInputStream(file1);
|
|
|
+ } else {
|
|
|
+ String path = sys_file_net_url + wbsTreePrivate.getHtmlUrl().replaceAll("//", "/").replaceAll(file_path, "");
|
|
|
+ fileInputStream = CommonUtil.getOSSInputStream(path);
|
|
|
+ }
|
|
|
+ String htmlString = IoUtil.readToString(fileInputStream);
|
|
|
+ //样式集合
|
|
|
+ Document doc = Jsoup.parse(htmlString);
|
|
|
+ //解析
|
|
|
+ Element table = doc.select("table").first();
|
|
|
+
|
|
|
+ Elements trs = table.select("tr");
|
|
|
+ Element element = trs.get(textdictInfo.getTrIndex()).select("td").get(textdictInfo.getTdIndex());
|
|
|
+
|
|
|
+ if (element.html().indexOf("el-input") >= 0 ) {
|
|
|
+ element.children().removeAttr("defText");
|
|
|
+ element.children().attr("defText", textdictInfo.getTextId());
|
|
|
+ } else {
|
|
|
+ element.children().removeAttr("defText");
|
|
|
+ element.attr("defText", textdictInfo.getTextId());
|
|
|
+ }
|
|
|
+ File writeFile = new File(wbsTreePrivate.getHtmlUrl());
|
|
|
+ FileUtil.writeToFile(writeFile, doc.html(), Boolean.parseBoolean("UTF-8"));
|
|
|
+
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<TextdictInfo> analysisHtmlDefault(String tabId) {
|
|
|
+ String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
|
|
|
+ String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
|
|
|
+
|
|
|
+ WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.getByPKeyId(Long.parseLong(tabId));
|
|
|
+ IPage<TextdictInfo> textdictInfoPage = new Page<TextdictInfo>();
|
|
|
+ try {
|
|
|
+ File file1 = ResourceUtil.getFile(wbsTreePrivate.getHtmlUrl());
|
|
|
+ InputStream fileInputStream;
|
|
|
+ if (file1.exists()) {
|
|
|
+ fileInputStream = new FileInputStream(file1);
|
|
|
+ } else {
|
|
|
+ String path = sys_file_net_url + wbsTreePrivate.getHtmlUrl().replaceAll("//", "/").replaceAll(file_path, "");
|
|
|
+ fileInputStream = CommonUtil.getOSSInputStream(path);
|
|
|
+ }
|
|
|
+ String htmlString = IoUtil.readToString(fileInputStream);
|
|
|
+ //样式集合
|
|
|
+ Document doc = Jsoup.parse(htmlString);
|
|
|
+ //解析
|
|
|
+ Element table = doc.select("table").first();
|
|
|
+ Elements elements = table.select("[defText]");
|
|
|
+
|
|
|
+ ArrayList<TextdictInfo> textdictInfos = new ArrayList<>();
|
|
|
+ for (Element element : elements) {
|
|
|
+ TextdictInfo textdictInfo = new TextdictInfo();
|
|
|
+ String keyname = element.attr("keyname");
|
|
|
+ String placeholder = element.attr("placeholder");
|
|
|
+ String defText = element.attr("defText");
|
|
|
+ textdictInfo.setColKey(keyname);
|
|
|
+ textdictInfo.setColName(placeholder);
|
|
|
+ textdictInfo.setSigRoleName(defText);
|
|
|
+ textdictInfo.setType(4);
|
|
|
+ textdictInfos.add(textdictInfo);
|
|
|
+ }
|
|
|
+ textdictInfoPage.setRecords(textdictInfos);
|
|
|
+ return textdictInfoPage;
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void removeHtmlDefault(String tabId, String colKey) {
|
|
|
+ String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
|
|
|
+ String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
|
|
|
+
|
|
|
+ WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.getByPKeyId(Long.parseLong(tabId));
|
|
|
+ try {
|
|
|
+ File file1 = ResourceUtil.getFile(wbsTreePrivate.getHtmlUrl());
|
|
|
+ InputStream fileInputStream;
|
|
|
+ if (file1.exists()) {
|
|
|
+ fileInputStream = new FileInputStream(file1);
|
|
|
+ } else {
|
|
|
+ String path = sys_file_net_url + wbsTreePrivate.getHtmlUrl().replaceAll("//", "/").replaceAll(file_path, "");
|
|
|
+ fileInputStream = CommonUtil.getOSSInputStream(path);
|
|
|
+ }
|
|
|
+ String htmlString = IoUtil.readToString(fileInputStream);
|
|
|
+ //样式集合
|
|
|
+ Document doc = Jsoup.parse(htmlString);
|
|
|
+ //解析
|
|
|
+ Element table = doc.select("table").first();
|
|
|
+ Elements elements = table.select("[defText]");
|
|
|
+ for (Element element : elements) {
|
|
|
+ String keyname = element.attr("keyname");
|
|
|
+ if(Objects.equals(colKey,keyname)){
|
|
|
+ element.removeAttr("defText");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //重写html
|
|
|
+ File writeFile = new File(wbsTreePrivate.getHtmlUrl());
|
|
|
+ FileUtil.writeToFile(writeFile, doc.html(), Boolean.parseBoolean("UTF-8"));
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|