修改方法重载中docid没设置的bug

main
youHong.ai 2022-12-19 19:49:02 +08:00
parent e99562c417
commit 242080e581
9 changed files with 394 additions and 122 deletions

View File

@ -208,6 +208,9 @@ window.workflowCus = Object.assign(window.workflowCus ? window.workflowCus : {},
getLevelByScore: async function (config) {
let scoreFiled = config.scoreFiled
let score = Utils.getFiledValueByName(scoreFiled);
if(score == 0 || score == ''){
return
}
let result = await Utils.api({
url: "/api/ayh/workflow/apa/level",
data: {
@ -225,10 +228,20 @@ window.workflowCus = Object.assign(window.workflowCus ? window.workflowCus : {},
/* ******************* apa流程通过apa分数字段带出level字段 ******************* */
$(() => {
let config = {
scoreFiled: "",
levelField: ""
scoreFiled: "apafsptyg",
levelField: "level1"
}
try {
setTimeout(()=>{
WfForm.bindFieldChangeEvent(Utils.convertNameObjToId(config.scoreFiled),()=>{
console.log("asdfasdfasdfsadfasdf")
window.workflowCus.getLevelByScore(config)
})
window.workflowCus.getLevelByScore(config)
},100)
}catch (err){
console.log(err)
}
})
/* ******************* apa流程通过apa分数字段带出level字段eng ******************* */

View File

@ -51,14 +51,14 @@ public class HttpUtils {
private final GlobalCache globalCache = new GlobalCache();
// 线程池
private final ThreadPoolExecutor executorService;
private final PropertyPreFilters filters = new PropertyPreFilters();
private final PropertyPreFilters.MySimplePropertyPreFilter excludefilter = filters.addFilter();
// 默认编码
private String DEFAULT_ENCODING = "UTF-8";
/**
* basic
*/
private CredentialsProvider credentialsProvider = null;
private final PropertyPreFilters filters = new PropertyPreFilters();
private final PropertyPreFilters.MySimplePropertyPreFilter excludefilter = filters.addFilter();
{
// private final ExecutorService executorService = Executors.newFixedThreadPool(3);
@ -1042,14 +1042,14 @@ public class HttpUtils {
*/
private HttpPost uploadFileByInputStream(String url, List<HttpMultipartFile> multipartFileList,
Map<String, Object> params, Map<String, String> headers) {
log.info(Util.logStr("start request : url is [{}],other param [\n{}\n],heard [\n{}\n]", url, JSONObject.toJSONString(params,
excludefilter,
SerializerFeature.PrettyFormat,
SerializerFeature.WriteDateUseDateFormat),
JSONObject.toJSONString(headers,
excludefilter,
SerializerFeature.PrettyFormat,
SerializerFeature.WriteDateUseDateFormat)));
//log.info(Util.logStr("start request : url is [{}],other param [\n{}\n],heard [\n{}\n]", url, JSONObject.toJSONString(params,
// excludefilter,
// SerializerFeature.PrettyFormat,
// SerializerFeature.WriteDateUseDateFormat),
// JSONObject.toJSONString(headers,
// excludefilter,
// SerializerFeature.PrettyFormat,
// SerializerFeature.WriteDateUseDateFormat)));
HttpUtilParamInfo httpUtilParamInfo = new HttpUtilParamInfo();
httpUtilParamInfo.setParams(params);
httpUtilParamInfo.setUrl(url);

View File

@ -13,8 +13,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* @author EBU7-dev1-ayh
* create 2021/12/19 0019 14:39
* @author EBU7-dev1-ayh create 2021/12/19 0019 14:39
*/
@ -22,6 +21,8 @@ public class RecordsetUtil implements InvocationHandler {
private final RecordSet recordSet = new RecordSet();
private final RecordSet rs = new RecordSet();
public <T> T getMapper(Class<T> tClass) {
if (tClass == null) {
throw new BindingException("class is null!");
@ -41,7 +42,6 @@ public class RecordsetUtil implements InvocationHandler {
Select select = method.getAnnotation(Select.class);
if (select != null) {
// 查询
RecordSet rs = new RecordSet();
String sql = select.value();
boolean custom = select.custom();
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);

View File

@ -1,6 +1,7 @@
package com.api.youhong.ai.pcn.organization.orgchart.controller;
import aiyh.utils.ApiResult;
import aiyh.utils.Util;
import com.api.youhong.ai.pcn.organization.orgchart.service.OrgChartService;
import com.api.youhong.ai.pcn.organization.orgchart.vo.OrgChartNodeVo;
import weaver.hrm.HrmUserVarify;
@ -35,8 +36,28 @@ public class OrgChartController {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String getOrgChartTree(@Context HttpServletRequest request, @Context HttpServletResponse response) {
try {
User logInUser = HrmUserVarify.getUser(request, response);
List<OrgChartNodeVo> treeList = service.getOrgChartTree(logInUser);
return ApiResult.success(treeList);
} catch (Exception e) {
Util.getLogger().error("get chart tree error ! \n" + Util.getErrString(e));
return ApiResult.error("get chart tree error!" + e.getMessage());
}
}
@Path("get-all")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String getOrgChartTreeAll(@Context HttpServletRequest request, @Context HttpServletResponse response) {
try {
User logInUser = HrmUserVarify.getUser(request, response);
List<OrgChartNodeVo> treeList = service.getOrgChartTreeAll(logInUser);
return ApiResult.success(treeList);
} catch (Exception e) {
Util.getLogger().error("get all chart tree error ! \n" + Util.getErrString(e));
return ApiResult.error("get all chart tree error!" + e.getMessage());
}
}
}

View File

@ -40,7 +40,7 @@ public interface OrgChartMapper {
" hrm.departmentid department_id, " +
" dept.DEPARTMENTNAME department_name, " +
" job.JOBTITLENAME job_title_name, " +
" cus1.$t{typeOfEmploymentFiled} type_of_employment " +
" uftb.$t{parentField} type_of_employment " +
"from hrmresource hrm " +
" inner join hrmjobtitles job on hrm.JOBTITLE = job.id " +
" inner join cus_fielddata cus on cus.ID = hrm.ID " +
@ -50,9 +50,13 @@ public interface OrgChartMapper {
" and cus1.scope = 'HrmCustomFieldByInfoType' " +
" and cus1.scopeid = -1" +
" inner join hrmdepartment dept on dept.id = hrm.DEPARTMENTID " +
" inner join $t{typeOfEmploymentTable} uftb on uftb.$t{typeOfEmploymentIdField} = cus1.$t{typeOfEmploymentFiled} " +
"where hrm.status in (0, 1)")
List<HrmResource> selectAll(@ParamMapper("typeOfEmploymentFiled") String typeOfEmploymentField,
@ParamMapper("lastNameEnField") String lastNameEnField);
@ParamMapper("lastNameEnField") String lastNameEnField,
@ParamMapper("typeOfEmploymentTable") String typeOfEmploymentTable,
@ParamMapper("parentField") String parentField,
@ParamMapper("typeOfEmploymentIdField") String typeOfEmploymentIdField);
/**

View File

@ -41,84 +41,13 @@ public class OrgChartService {
*/
public List<OrgChartNodeVo> getOrgChartTree(User logInUser) {
int userId = logInUser.getUID();
String typeOfEmploymentField = Util.getCusConfigValue("typeOfEmploymentField");
Assert.notBlank(typeOfEmploymentField, "config [typeOfEmploymentField] is null or blank!");
String lastNameEnField = Util.getCusConfigValue("lastNameEnField");
Assert.notBlank(lastNameEnField, "config [lastNameEnField] is null or blank!");
List<HrmResource> hrmResourceList = mapper.selectAll(typeOfEmploymentField, lastNameEnField);
if (Objects.isNull(hrmResourceList) || hrmResourceList.isEmpty()) {
throw new CustomerException("查询不到相关人员!");
}
//List<HrmResourceDto> hrmResourceDtoList = new ArrayList();
AtomicReference<HrmResourceDto> currentUser = new AtomicReference<>();
/* ******************* 将pojo转换为Dto对象对节点属性默认值赋值找出当前用户并设置显示 ******************* */
List<HrmResourceDto> hrmResourceDtoList = hrmResourceList.stream()
.map(struct::hrmResourceToDto)
.peek(item -> Builder.startSet(item)
.with(HrmResourceDto::setShow, 0)
.with(HrmResourceDto::setShowBrother, 0)
.with(HrmResourceDto::setShowChildren, 0)
.endSet())
.collect(Collectors.toList());
hrmResourceDtoList.stream()
.peek(item -> {
if (item.getManagerId() == userId) {
item.setShow(1);
}
})
.filter(item -> item.getId() == userId)
.forEach(item -> {
Builder.startSet(item)
.with(HrmResourceDto::setShow, 1)
.with(HrmResourceDto::setShowBrother, 1)
.with(HrmResourceDto::setShowChildren, 1)
.with(HrmResourceDto::setCurrent, true)
.endSet();
currentUser.set(item);
});
List<HrmResourceDto> hrmResourceDtoList = getHrmResourceDtoList(userId, currentUser);
/* ******************* 系统管理员默认全部展开哦 ******************* */
if (userId == 1) {
List<OrgChartNodeVo> collect = hrmResourceDtoList.stream()
.map(struct::hrmResourceDtoToVo)
.peek(item -> Builder.startSet(item)
.with(OrgChartNodeVo::setShow, 1)
.with(OrgChartNodeVo::setShowBrother, 1)
.with(OrgChartNodeVo::setShowChildren, 1)
.with(OrgChartNodeVo::setCurrent, true)
.endSet())
.collect(Collectors.toList());
return Util.listToTree(collect, OrgChartNodeVo::getId, OrgChartNodeVo::getManagerId,
OrgChartNodeVo::getChildren, OrgChartNodeVo::setChildren,
parentId -> parentId == null || parentId <= 0)
.stream().peek(item -> Builder.startSet(item)
.with(OrgChartNodeVo::setIsRoot, true)
.with(OrgChartNodeVo::setCurrent, true)
.endSet())
.peek(item -> recursionChildrenNums(item, 0))
.collect(Collectors.toList());
return systemAdminTree(hrmResourceDtoList);
}
Assert.notNull(currentUser.get(), "not find current login user info!");
/* ******************* 根据当前登陆人的分部来过滤 ******************* */
hrmResourceDtoList = hrmResourceDtoList.stream()
.filter(item -> logInUser.getUserSubCompany1() == item.getSubCompanyId())
.collect(Collectors.toList());
/* ******************* 查找当前登陆人员的所有上级 ******************* */
String currentUserManagerStr = currentUser.get().getManagerStr();
if (Objects.isNull(currentUserManagerStr)) {
currentUserManagerStr = "";
}
currentUserManagerStr = Util.removeSeparator(currentUserManagerStr, ",");
List<Integer> currentUserManagerList = Arrays.stream(currentUserManagerStr.split(","))
.map(Integer::parseInt)
.collect(Collectors.toList());
/* ******************* 对当前用户的所有直接上级设置标识 ******************* */
hrmResourceDtoList.stream()
.filter(item -> currentUserManagerList.contains(item.getId()))
.forEach(item -> Builder.startSet(item)
.with(HrmResourceDto::setShowChildren, 1)
.with(HrmResourceDto::setCurrentParent, true)
.endSet());
filterCurrentSubCom(hrmResourceDtoList, currentUser, logInUser);
/* ******************* 查询当前用户的是否全部展示或显示小红点的配置信息 ******************* */
ShowPointOrAll showPointOrAll = mapper.selectShowPointOrAll(userId);
List<OrgChartNodeVo> orgChartNodeVoList = null;
@ -157,6 +86,176 @@ public class OrgChartService {
}
/**
* <h2>getOrgChartTreeAll </h2>
* <i>2022/12/16 17:21</i>
* ************************************************************
*
* @param logInUser id
* @return List<OrgChartNodeVo>
* @author youHong.ai ******************************************
*/
public List<OrgChartNodeVo> getOrgChartTreeAll(User logInUser) {
int userId = logInUser.getUID();
AtomicReference<HrmResourceDto> currentUser = new AtomicReference<>();
List<HrmResourceDto> hrmResourceDtoList = getHrmResourceDtoList(userId, currentUser);
/* ******************* 系统管理员默认全部展开哦 ******************* */
if (userId == 1) {
return systemAdminTree(hrmResourceDtoList);
}
filterCurrentSubCom(hrmResourceDtoList, currentUser, logInUser);
List<OrgChartNodeVo> orgChartNodeVoList = null;
/* ******************* 转换dto为Vo并且设置根节点标识 ******************* */
orgChartNodeVoList = hrmResourceDtoList.stream()
.map(struct::hrmResourceDtoToVo)
.peek(item ->
Builder.startSet(item)
.with(OrgChartNodeVo::setShow, 1)
.with(OrgChartNodeVo::setShowBrother, 1)
.with(OrgChartNodeVo::setShowChildren, 1)
.endSet()
).collect(Collectors.toList());
return Util.listToTree(orgChartNodeVoList, OrgChartNodeVo::getId,
OrgChartNodeVo::getManagerId, OrgChartNodeVo::getChildren,
OrgChartNodeVo::setChildren,
parentId -> parentId == null || parentId <= 0)
.stream()
.peek(item -> item.setIsRoot(true))
.peek(item -> recursionChildrenNums(item, 0))
.collect(Collectors.toList());
}
/**
* <h2>filterCurrentSubCom </h2>
* <i>2022/12/16 17:16</i>
* ************************************************************
*
* @param hrmResourceDtoList dtolist
* @param currentUser
* @param logInUser
* @author youHong.ai ******************************************
*/
private void filterCurrentSubCom(List<HrmResourceDto> hrmResourceDtoList,
AtomicReference<HrmResourceDto> currentUser,
User logInUser) {
Assert.notNull(currentUser.get(), "not find current login user info!");
/* ******************* 根据当前登陆人的分部来过滤 ******************* */
hrmResourceDtoList = hrmResourceDtoList.stream()
.filter(item -> logInUser.getUserSubCompany1() == item.getSubCompanyId())
.collect(Collectors.toList());
/* ******************* 查找当前登陆人员的所有上级 ******************* */
String currentUserManagerStr = currentUser.get().getManagerStr();
if (Objects.isNull(currentUserManagerStr) || "".equals(currentUserManagerStr)) {
currentUserManagerStr = "0";
}
currentUserManagerStr = Util.removeSeparator(currentUserManagerStr, ",");
List<Integer> currentUserManagerList = Arrays.stream(currentUserManagerStr.split(","))
.map(Integer::parseInt)
.collect(Collectors.toList());
/* ******************* 对当前用户的所有直接上级设置标识 ******************* */
hrmResourceDtoList.stream()
.filter(item -> currentUserManagerList.contains(item.getId()))
.forEach(item -> Builder.startSet(item)
.with(HrmResourceDto::setShowChildren, 1)
.with(HrmResourceDto::setCurrentParent, true)
.endSet());
}
/**
* <h2>systemAdminTree </h2>
* <i>2022/12/16 17:15</i>
* ************************************************************
*
* @param hrmResourceDtoList dtolist
* @return List<OrgChartNodeVo> list
* @author youHong.ai ******************************************
*/
private List<OrgChartNodeVo> systemAdminTree(List<HrmResourceDto> hrmResourceDtoList) {
List<OrgChartNodeVo> collect = hrmResourceDtoList.stream()
.map(struct::hrmResourceDtoToVo)
.peek(item -> Builder.startSet(item)
.with(OrgChartNodeVo::setShow, 1)
.with(OrgChartNodeVo::setShowBrother, 1)
.with(OrgChartNodeVo::setShowChildren, 1)
.with(OrgChartNodeVo::setCurrent, true)
.endSet())
.collect(Collectors.toList());
return Util.listToTree(collect, OrgChartNodeVo::getId, OrgChartNodeVo::getManagerId,
OrgChartNodeVo::getChildren, OrgChartNodeVo::setChildren,
parentId -> parentId == null || parentId <= 0)
.stream().peek(item -> Builder.startSet(item)
.with(OrgChartNodeVo::setIsRoot, true)
.with(OrgChartNodeVo::setCurrent, true)
.endSet())
.peek(item -> recursionChildrenNums(item, 0))
.collect(Collectors.toList());
}
/**
* <h2>getHrmResourceDtoList dtolist</h2>
* <i>2022/12/16 17:09</i>
* ************************************************************
*
* @param userId ID
* @param currentUser
* @return List<HrmResourceDto> dtolist
* @author youHong.ai ******************************************
*/
private List<HrmResourceDto> getHrmResourceDtoList(Integer userId, AtomicReference<HrmResourceDto> currentUser) {
// 人员类型自定义字段
String typeOfEmploymentField = Util.getCusConfigValue("typeOfEmploymentField");
Assert.notBlank(typeOfEmploymentField, "config [typeOfEmploymentField] is null or blank!");
// 英文自定义名称字段
String lastNameEnField = Util.getCusConfigValue("lastNameEnField");
Assert.notBlank(lastNameEnField, "config [lastNameEnField] is null or blank!");
// 人员类型id字段 建模表
String typeOfEmploymentIdField = Util.getCusConfigValue("typeOfEmploymentIdField");
Assert.notBlank(typeOfEmploymentIdField, "config [typeOfEmploymentIdField] is null or blank!");
// 人员类型父级字段 建模表
String parentField = Util.getCusConfigValue("parentField");
Assert.notBlank(parentField, "config [parentField] is null or blank!");
// 人员类型建模表表名
String typeOfEmploymentTable = Util.getCusConfigValue("typeOfEmploymentTable");
Assert.notBlank(typeOfEmploymentTable, "config [typeOfEmploymentTable] is null or blank!");
// 查询所有人员信息
List<HrmResource> hrmResourceList = mapper.selectAll(typeOfEmploymentField, lastNameEnField,
typeOfEmploymentTable, parentField, typeOfEmploymentIdField);
if (Objects.isNull(hrmResourceList) || hrmResourceList.isEmpty()) {
throw new CustomerException("查询不到相关人员!");
}
//List<HrmResourceDto> hrmResourceDtoList = new ArrayList();
/* ******************* 将pojo转换为Dto对象对节点属性默认值赋值找出当前用户并设置显示 ******************* */
List<HrmResourceDto> hrmResourceDtoList = hrmResourceList.stream()
.map(struct::hrmResourceToDto)
.peek(item -> Builder.startSet(item)
.with(HrmResourceDto::setShow, 0)
.with(HrmResourceDto::setShowBrother, 0)
.with(HrmResourceDto::setShowChildren, 0)
.endSet())
.collect(Collectors.toList());
hrmResourceDtoList.stream()
.peek(item -> {
if (Objects.equals(item.getManagerId(), userId)) {
item.setShow(1);
}
})
.filter(item -> Objects.equals(item.getId(), userId))
.forEach(item -> {
Builder.startSet(item)
.with(HrmResourceDto::setShow, 1)
.with(HrmResourceDto::setShowBrother, 1)
.with(HrmResourceDto::setShowChildren, 1)
.with(HrmResourceDto::setCurrent, true)
.endSet();
currentUser.set(item);
});
return hrmResourceDtoList;
}
/**
* <h2></h2>
* <i>2022/12/3 17:55</i>

View File

@ -649,6 +649,8 @@ public class DealWithMapping extends ToolUtil {
for (DocImageFile docImageFile : docImageFiles) {
MultipartFile multipartFile = new MultipartFile();
InputStream fileInputStream = ImageFileManager.getInputStreamById(docImageFile.getImageFileId());
multipartFile.setDocId(docImageFile.getDocId());
multipartFile.setImageFileId(docImageFile.getImageFileId());
multipartFile.setFileKey(paramName);
multipartFile.setStream(fileInputStream);
multipartFile.setFileName(docImageFile.getImageFileName());

View File

@ -233,7 +233,7 @@ public class TestOrganization extends BaseTest {
@Test
public void testOrgChart() {
User user = new User(1);
User user = new User(35);
OrgChartService orgChartService = new OrgChartService();
List<OrgChartNodeVo> orgChartTree = orgChartService.getOrgChartTree(user);
System.out.println(JSON.toJSONString(orgChartTree));

View File

@ -1,12 +1,22 @@
package youhong.ai.pcn;
import aiyh.utils.Util;
import aiyh.utils.httpUtil.util.HttpUtils;
import basetest.BaseTest;
import com.itextpdf.text.pdf.BaseFont;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.xhtmlrenderer.pdf.ITextFontResolver;
import org.xhtmlrenderer.pdf.ITextRenderer;
import weaver.email.EmailWorkRunnable;
import weaver.general.GCONST;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.*;
/**
* <h1></h1>
@ -28,4 +38,127 @@ public class WorkflowTest extends BaseTest {
.reduce(0, Integer::sum);
System.out.println(sum);
}
@Test
public void testEmail() {
String content = "<p><b>各位大佬:</b></p>\n" +
" <p>先前注册的gitea私有云仓库账号域名备案已完成现登陆仓库时请使用域名登陆</p>\n" +
" <br>\n" +
" <p>私有仓库登陆地址:<a href=\"https://gitea.yeyaguitu.cn/\">gitea私有仓库login</a></p>\n" +
" <br>\n" +
" <p>登陆账号为先前注册的账号:<b>#{zhanghao}</b>,默认密码为用户名!</p>\n" +
"<p>如已绑定仓库,需要重新设置仓库远程地址,方法如下:</p>\n" +
"<div>\n" +
" <b>执行命令:</b><br>\n" +
" git remote -v\n" +
" <br>比如:\n" +
" <p>\n" +
" origin http://1.****.82/ecology/ebu_ecology_dev1.git (fetch)<br>\n" +
" origin http://1.****.82/ecology/ebu_ecology_dev1.git (push)\n" +
" <p>\n" +
" <p>查看到remote的名称一般默认为 origin</p>\n" +
" <br>\n" +
" <b>执行命令:</b><br>\n" +
" git remote set-url origin https://gitea.yeyaguitu.cn/ecology/ebu_ecology_dev1.git\n" +
" <p>其中 origin 为查询到的remote的名称</p>";
List<Map<String, String>> list = new ArrayList<>();
list.add(new HashMap<String, String>() {{
put("name", "bokang.xiao");
put("email", "ic_excellent@qq.com");
}});
list.add(new HashMap<String, String>() {{
put("name", "chaoyang.he");
put("email", "chaoyang.he@weaver.com.cn");
}});
list.add(new HashMap<String, String>() {{
put("name", "jiacheng.deng");
put("email", "jiacheng.deng@weaver.com.cn");
}});
list.add(new HashMap<String, String>() {{
put("name", "jiayong.cao");
put("email", "jiayong.cao@weaver.com.cn");
}});
list.add(new HashMap<String, String>() {{
put("name", "jingwei.tao");
put("email", "jingwei.tao@weaver.com.cn");
}});
list.add(new HashMap<String, String>() {{
put("name", "weilin.zhu");
put("email", "bleach_725@163.com");
}});
list.add(new HashMap<String, String>() {{
put("name", "xuanran.wang");
put("email", "xuanran.wang@weaver.com.cn");
}});
list.add(new HashMap<String, String>() {{
put("name", "xvqiang.ren");
put("email", "1215877336@qq.com");
}});
list.add(new HashMap<String, String>() {{
put("name", "youhong.ai");
put("email", "youhong.ai@weaver.com.cn");
}});
for (Map<String, String> map : list) {
EmailWorkRunnable.threadModeReminder(map.get("email"), "域名变更提醒补充", content.replace("#{zhanghao}", map.get("name")));
}
}
@Test
public void testPdfFromWorkflow() throws Exception {
// 创建和初始化URL
//URL oracleURL = new URL("https://ecology.yeyaguitu.cn/spa/workflow/static4form/index.html#/main/workflow/req?requestid=50051&ismode=2&ismonitor=0&f_weaver_belongto_usertype=0&f_weaver_belongto_userid=1&urger=0&modeid=34&isprint=1");
// 获取网页作为输入流
//InputStream is = oracleURL.openStream();
//ITextRenderer renderer = new ITextRenderer();
//renderer.setDocument();
//OutputStream os = new FileOutputStream(GCONST.getSysFilePath() + "testpdf.pdf");
//renderer.layout();
//renderer.createPDF(os);
//os.close();
// 初始化HTML加载选项
//HtmlLoadOptions htmloptions = new HtmlLoadOptions();
// 将流加载到Document对象中
//Document pdfDocument = new Document(is, htmloptions);
// 将输出另存为PDF格式
//pdfDocument.save(GCONST.getSysFilePath() + "HTML-to-PDF.pdf");
HttpUtils httpUtils = new HttpUtils();
String htmlUrl = "https://ecology.yeyaguitu.cn/spa/workflow/static4form/index.html#/main/workflow/req?requestid=50051&ismode=2&ismonitor=0&f_weaver_belongto_usertype=0&f_weaver_belongto_userid=1&urger=0&modeid=34&isprint=1";
log.info(Util.logStr("页面路径:{}", htmlUrl));
String html = httpUtils.apiGet(htmlUrl).getEntityString();
//String htmlContent = html.replace("<!DOCTYPE html>", "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
// .replace("<!doctype html>", "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
// .replace("<html lang=\"en\" xmlns:th=\"http://www.thymeleaf.org\">", "<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">");
//log.info(Util.logStr("html内容\n{}", htmlContent));
File pdf = new File(GCONST.getSysFilePath() + "test.pdf");
Document document = Jsoup.parse(html);
String html1 = document.html();
HtmPdfUtil.html2pdf(html1, pdf);
}
}
class HtmPdfUtil {
/**
* HTMLPDFhtml
*
* @param htmlContent
* @param pdfFile
* @throws Exception
*/
public static void html2pdf(String htmlContent, File pdfFile) throws Exception {
OutputStream os = new FileOutputStream(pdfFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(htmlContent);
// 中文
ITextFontResolver fontResolver = renderer.getFontResolver();
ClassPathResource resource = new ClassPathResource("font/simsun.ttc");
fontResolver.addFont(resource.getURL().toString(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
renderer.layout();
renderer.createPDF(os);
os.close();
}
}