Procházet zdrojové kódy

后管-WBS管理-调整表单-默认值,改为在html上面操作数据,不设计数据库

LHB před 2 měsíci
rodič
revize
a5015be899

+ 19 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/TextdictInfoController.java

@@ -102,6 +102,11 @@ public class TextdictInfoController extends BladeController {
     @ApiOperationSupport(order = 2)
     @ApiOperation(value = "分页", notes = "传入textdictInfo")
     public R<IPage<TextdictInfo>> list(TextdictInfo textdictInfo, Query query) {
+        if(textdictInfo.getType() == 4){
+            return R.data(textdictInfoService.analysisHtmlDefault(textdictInfo.getTabId()));
+        }
+
+
         IPage<TextdictInfo> pages = textdictInfoService.page(Condition.getPage(query), Condition.getQueryWrapper(textdictInfo));
         return R.data(pages);
     }
@@ -155,7 +160,15 @@ public class TextdictInfoController extends BladeController {
     @PostMapping("/remove")
     @ApiOperationSupport(order = 7)
     @ApiOperation(value = "逻辑删除", notes = "传入ids")
-    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids,@ApiParam(value = "wbs p_key_id", required = true) @RequestParam String tabId) throws FileNotFoundException {
+    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids,
+                    @ApiParam(value = "wbs p_key_id", required = true) @RequestParam String tabId,
+                    @ApiParam(value = "colKey", required = false) @RequestParam String colKey,
+                    @ApiParam(value = "type", required = false) @RequestParam Integer type) throws FileNotFoundException {
+        if(type == 4){
+            textdictInfoService.removeHtmlDefault(tabId,colKey);
+            return R.success("删除成功");
+        }
+
         //获取节点信息
 
         WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.getByPKeyId(Long.parseLong(tabId));
@@ -559,6 +572,11 @@ public class TextdictInfoController extends BladeController {
     @ApiOperationSupport(order = 7)
     @ApiOperation(value = "保存默认值", notes = "保存默认值")
     public R<String> saveDefaulVal(@Valid @RequestBody TextdictBy345VO textdictInfo) throws Exception {
+        if(textdictInfo.getType() == 4){
+            textdictInfoService.saveHtmlDefault(textdictInfo);
+            return R.success("操作成功");
+        }
+
 
         //当前清表信息
         WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.getByPKeyId(textdictInfo.getTableId());

+ 7 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/ITextdictInfoService.java

@@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import org.springblade.core.tool.api.R;
 import org.springblade.manager.dto.RangeInfo;
 import org.springblade.manager.entity.TextdictInfo;
+import org.springblade.manager.vo.TextdictBy345VO;
 import org.springblade.manager.vo.TextdictDataInfoVO;
 import org.springblade.manager.vo.TextdictInfoVO;
 import org.springblade.core.mp.base.BaseService;
@@ -47,4 +48,10 @@ public interface ITextdictInfoService extends IService<TextdictInfo> {
     void deleDataInfoById(String id);
 
     TextdictInfo selectTextdictInfoOne(String id,String sigRoleId,String projectId);
+
+    IPage<TextdictInfo> analysisHtmlDefault(String tabId);
+
+    void removeHtmlDefault(String tabId, String colKey);
+
+    void saveHtmlDefault(TextdictBy345VO textdictInfo);
 }

+ 128 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/TextdictInfoServiceImpl.java

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