Browse Source

元素库修改元素 同步去修改html

cr 2 weeks ago
parent
commit
f1cf712593

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

@@ -378,7 +378,7 @@ public class WbsTreeController extends BladeController {
     @ApiOperationSupport(order = 10)
     @ApiOperation(value = "编辑表单元素批量修改", notes = "传入WbsFormElement")
     @ApiImplicitParam(name = "ids", value = "元素的id集合", required = true)
-    public R updateBatchElements(@RequestBody List<WbsFormElement> wbsFormElementList, @RequestParam("initTableName") String initTableName) {
+    public R updateBatchElements(@RequestBody List<WbsFormElement> wbsFormElementList, @RequestParam("initTableName") String initTableName) throws Exception {
         return wbsFormElementService.updateAndSyn(wbsFormElementList, initTableName);
     }
 

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IWbsFormElementService.java

@@ -33,7 +33,7 @@ public interface IWbsFormElementService extends BaseService<WbsFormElement> {
 
     boolean deleteAndSyn(String ids, String elementName, String tableName);
 
-    R updateAndSyn(List<WbsFormElement> wbsFormElementList, String initTableName);
+    R updateAndSyn(List<WbsFormElement> wbsFormElementList, String initTableName) throws Exception;
 
     List<WbsFormElementDTO2> findWbsTreeTableSameLevel(String parentId);
 

+ 30 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsFormElementServiceImpl.java

@@ -6,6 +6,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.StringUtils;
+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.SnowFlakeUtil;
 import org.springblade.core.log.exception.ServiceException;
@@ -26,16 +30,21 @@ import org.springblade.manager.mapper.WbsTreePrivateMapper;
 import org.springblade.manager.service.IExcelTabService;
 import org.springblade.manager.service.ITableInfoService;
 import org.springblade.manager.service.IWbsFormElementService;
+import org.springblade.manager.utils.FileUtils;
 import org.springblade.manager.utils.WbsElementUtil;
 import org.springblade.manager.vo.WbsFormElementVO;
 import org.springblade.manager.vo.WbsFormElementVO2;
 import org.springblade.manager.vo.WbsNodeTableVO;
 import org.springblade.system.cache.ParamCache;
 import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.ResultSetExtractor;
+import org.springframework.jdbc.core.SingleColumnRowMapper;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.math.BigInteger;
 import java.text.ParseException;
 import java.util.*;
@@ -296,7 +305,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public R updateAndSyn(List<WbsFormElement> wbsFormElementList, String initTableName) {
+    public R updateAndSyn(List<WbsFormElement> wbsFormElementList, String initTableName) throws Exception {
         if (StringUtils.isEmpty(initTableName)) {
             return R.fail("未获取到initTableName对应实体表名称,操作失败");
         }
@@ -388,6 +397,26 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
                     }
                 }
             }
+
+            //元素库修改元素的同时要去修改html上面的元素
+            String sql="select DISTINCT html_url from m_wbs_tree_private where init_table_name='"+initTableName+"' and is_deleted=0 and html_url is not null";
+            List<String> htmlurls = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
+            if(!htmlurls.isEmpty()){
+                for (String htmlurl : htmlurls) {
+                    InputStream inputStream = FileUtils.getInputStreamByUrl(htmlurl);
+                    String htmlString = IoUtil.readToString(inputStream);
+                    Document doc = Jsoup.parse(htmlString);
+                    for (WbsFormElement wbsFormElement : wbsFormElements) {
+                        Elements elements = doc.select("[keyname^=" + wbsFormElement.getEKey() + "__]");;
+                        for (Element element : elements) {
+                            element.attr("placeholder", wbsFormElement.getEName());
+                        }
+                    }
+                    File writefile = new File(htmlurl);
+                    FileUtil.writeToFile(writefile, doc.html(), Boolean.parseBoolean("UTF-8"));
+                    inputStream.close();
+                }
+            }
         }
         return R.success("操作成功");
     }