富文本工具类
This commit is contained in:
parent
87a0a83461
commit
c05c65a4e2
@ -1,13 +1,19 @@
|
|||||||
package com.ruoyi.winery.controller.goods;
|
package com.ruoyi.winery.controller.goods;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import com.itextpdf.styledxmlparser.jsoup.Jsoup;
|
||||||
|
import com.itextpdf.styledxmlparser.jsoup.nodes.Document;
|
||||||
|
import com.itextpdf.styledxmlparser.jsoup.nodes.Element;
|
||||||
|
import com.itextpdf.styledxmlparser.jsoup.select.Elements;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.winery.utils.RichTextUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -110,6 +116,11 @@ public class GoodsMainController extends BaseController {
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(UsernamePasswordAuthenticationToken token, @RequestBody GoodsMain goodsMain) {
|
public AjaxResult add(UsernamePasswordAuthenticationToken token, @RequestBody GoodsMain goodsMain) {
|
||||||
goodsMain.setDeptId(getDeptId());
|
goodsMain.setDeptId(getDeptId());
|
||||||
|
String richText = goodsMain.getGoodsDesc();
|
||||||
|
if (richText != null && StringUtils.isNotEmpty(richText)) {
|
||||||
|
Document doc = RichTextUtil.setImgStyle(richText, "width: 100%");
|
||||||
|
goodsMain.setGoodsDesc(doc.body().children().toString());
|
||||||
|
}
|
||||||
return toAjax(iWineryGoodsService.save(goodsMain) ? 1 : 0);
|
return toAjax(iWineryGoodsService.save(goodsMain) ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +132,11 @@ public class GoodsMainController extends BaseController {
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@RequestBody GoodsMain goodsMain) {
|
public AjaxResult edit(@RequestBody GoodsMain goodsMain) {
|
||||||
goodsMain.setUpdateBy(getUsername());
|
goodsMain.setUpdateBy(getUsername());
|
||||||
|
String richText = goodsMain.getGoodsDesc();
|
||||||
|
if (richText != null && StringUtils.isNotEmpty(richText)) {
|
||||||
|
Document doc = RichTextUtil.setImgStyle(richText, "width: 100%");
|
||||||
|
goodsMain.setGoodsDesc(doc.body().children().toString());
|
||||||
|
}
|
||||||
return toAjax(iWineryGoodsService.updateById(goodsMain) ? 1 : 0);
|
return toAjax(iWineryGoodsService.updateById(goodsMain) ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.ruoyi.winery.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.itextpdf.styledxmlparser.jsoup.Jsoup;
|
||||||
|
import com.itextpdf.styledxmlparser.jsoup.nodes.Document;
|
||||||
|
import com.itextpdf.styledxmlparser.jsoup.nodes.Element;
|
||||||
|
import com.itextpdf.styledxmlparser.jsoup.select.Elements;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kino
|
||||||
|
* @since 2021/01/19 9:49
|
||||||
|
*/
|
||||||
|
public class RichTextUtil {
|
||||||
|
|
||||||
|
public static Document setImgStyle(String richText, String style) {
|
||||||
|
Document doc = Jsoup.parse(richText);
|
||||||
|
Elements img = doc.getElementsByTag("img");
|
||||||
|
if (CollUtil.isNotEmpty(img)) {
|
||||||
|
for (Element i : img) {
|
||||||
|
String s = i.attr("style");
|
||||||
|
if (StringUtils.isEmpty(s)) {
|
||||||
|
i.attr("style", style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
}
|
@ -81,7 +81,8 @@ public class CommonController {
|
|||||||
|
|
||||||
|
|
||||||
String fileName = cosUtils.upload(type, file);
|
String fileName = cosUtils.upload(type, file);
|
||||||
String url = serverConfig.getUrl() + "/common/file?fileName=" + fileName;
|
// String url = serverConfig.getUrl() + "/common/file?fileName=" + fileName;
|
||||||
|
String url = "https://winery-1257413599.cos.ap-beijing.myqcloud.com/" + fileName;
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
ajax.put("fileName", fileName);
|
ajax.put("fileName", fileName);
|
||||||
ajax.put("url", url);
|
ajax.put("url", url);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user