diff --git a/javascript/youhong.ai/pcn/workflow_code_block.js b/javascript/youhong.ai/pcn/workflow_code_block.js index 290ce16..74e8d70 100644 --- a/javascript/youhong.ai/pcn/workflow_code_block.js +++ b/javascript/youhong.ai/pcn/workflow_code_block.js @@ -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) } - window.workflowCus.getLevelByScore(config) }) /* ******************* apa流程通过apa分数字段带出level字段eng ******************* */ diff --git a/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java b/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java index 44665b8..bf4d92b 100644 --- a/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java +++ b/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java @@ -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); @@ -69,7 +69,7 @@ public class HttpUtils { new LinkedBlockingQueue<>(1024), threadFactory, new ThreadPoolExecutor.AbortPolicy()); - String[] excludeProperties = {"locale","contentByteArr","response"}; + String[] excludeProperties = {"locale", "contentByteArr", "response"}; excludefilter.addExcludes(excludeProperties); } @@ -642,9 +642,9 @@ public class HttpUtils { httpUtilParamInfo = new HttpUtilParamInfo(); } httpUtilParamInfo.setResponse(apply); - if(apply.getResponseMap() == null){ + if (apply.getResponseMap() == null) { httpUtilParamInfo.setResponseString(apply.getEntityString()); - }else { + } else { httpUtilParamInfo.setResponseMap(apply.getResponseMap()); } httpUtilParamInfo.setResponseDate(new Date()); @@ -679,9 +679,9 @@ public class HttpUtils { httpUtilParamInfo = new HttpUtilParamInfo(); } httpUtilParamInfo.setResponse(apply); - if(apply.getResponseMap() == null){ + if (apply.getResponseMap() == null) { httpUtilParamInfo.setResponseString(apply.getEntityString()); - }else { + } else { httpUtilParamInfo.setResponseMap(apply.getResponseMap()); } httpUtilParamInfo.setResponseDate(new Date()); @@ -718,9 +718,9 @@ public class HttpUtils { responeVo.setCode(response.getStatusLine().getStatusCode()); responeVo.setResponse(response); httpUtilParamInfo.setResponse(responeVo); - if(responeVo.getResponseMap() == null){ + if (responeVo.getResponseMap() == null) { httpUtilParamInfo.setResponseString(responeVo.getEntityString()); - }else { + } else { httpUtilParamInfo.setResponseMap(responeVo.getResponseMap()); } httpUtilParamInfo.setResponseDate(new Date()); @@ -1042,14 +1042,14 @@ public class HttpUtils { */ private HttpPost uploadFileByInputStream(String url, List multipartFileList, Map params, Map 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); diff --git a/src/main/java/aiyh/utils/recordset/RecordsetUtil.java b/src/main/java/aiyh/utils/recordset/RecordsetUtil.java index a7b5370..9b2c5f5 100644 --- a/src/main/java/aiyh/utils/recordset/RecordsetUtil.java +++ b/src/main/java/aiyh/utils/recordset/RecordsetUtil.java @@ -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 getMapper(Class tClass) { if (tClass == null) { throw new BindingException("class is null!"); @@ -40,8 +41,7 @@ public class RecordsetUtil implements InvocationHandler { ResultMapper resultMapper = new ResultMapper(); 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); @@ -59,7 +59,7 @@ public class RecordsetUtil implements InvocationHandler { Update update = method.getAnnotation(Update.class); if (update != null) { -// 查询 + // 查询 String sql = update.value(); boolean custom = update.custom(); PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args); @@ -90,7 +90,7 @@ public class RecordsetUtil implements InvocationHandler { } Insert insert = method.getAnnotation(Insert.class); if (insert != null) { -// 查询 + // 查询 String sql = insert.value(); boolean custom = insert.custom(); PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args); @@ -114,7 +114,7 @@ public class RecordsetUtil implements InvocationHandler { } Delete delete = method.getAnnotation(Delete.class); if (delete != null) { -// 查询 + // 查询 String sql = delete.value(); boolean custom = delete.custom(); PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args); diff --git a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/controller/OrgChartController.java b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/controller/OrgChartController.java index f07666b..1f4ba06 100644 --- a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/controller/OrgChartController.java +++ b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/controller/OrgChartController.java @@ -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) { - User logInUser = HrmUserVarify.getUser(request, response); - List treeList = service.getOrgChartTree(logInUser); - return ApiResult.success(treeList); + try { + User logInUser = HrmUserVarify.getUser(request, response); + List 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 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()); + } } } diff --git a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapper/OrgChartMapper.java b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapper/OrgChartMapper.java index 742c417..864fb93 100644 --- a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapper/OrgChartMapper.java +++ b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/mapper/OrgChartMapper.java @@ -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 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); /** diff --git a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/service/OrgChartService.java b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/service/OrgChartService.java index cd235e6..8fdbd6f 100644 --- a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/service/OrgChartService.java +++ b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/service/OrgChartService.java @@ -41,84 +41,13 @@ public class OrgChartService { */ public List 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 hrmResourceList = mapper.selectAll(typeOfEmploymentField, lastNameEnField); - if (Objects.isNull(hrmResourceList) || hrmResourceList.isEmpty()) { - throw new CustomerException("查询不到相关人员!"); - } - //List hrmResourceDtoList = new ArrayList(); AtomicReference currentUser = new AtomicReference<>(); - /* ******************* 将pojo转换为Dto对象,对节点属性默认值赋值,找出当前用户并设置显示 ******************* */ - List 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 hrmResourceDtoList = getHrmResourceDtoList(userId, currentUser); /* ******************* 系统管理员默认全部展开哦 ******************* */ if (userId == 1) { - List 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 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 orgChartNodeVoList = null; @@ -157,6 +86,176 @@ public class OrgChartService { } + /** + *

getOrgChartTreeAll 获取所有的数据并默认展开

+ * 2022/12/16 17:21 + * ************************************************************ + * + * @param logInUser 当前登陆id + * @return List 最终树 + * @author youHong.ai ****************************************** + */ + public List getOrgChartTreeAll(User logInUser) { + int userId = logInUser.getUID(); + AtomicReference currentUser = new AtomicReference<>(); + List hrmResourceDtoList = getHrmResourceDtoList(userId, currentUser); + /* ******************* 系统管理员默认全部展开哦 ******************* */ + if (userId == 1) { + return systemAdminTree(hrmResourceDtoList); + } + filterCurrentSubCom(hrmResourceDtoList, currentUser, logInUser); + List 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()); + } + + + /** + *

filterCurrentSubCom 过滤当前分部的人员,并且设置用户上级标识

+ * 2022/12/16 17:16 + * ************************************************************ + * + * @param hrmResourceDtoList 人力资源dtolist + * @param currentUser 当前用户 + * @param logInUser 当前登陆用户 + * @author youHong.ai ****************************************** + */ + private void filterCurrentSubCom(List hrmResourceDtoList, + AtomicReference 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 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()); + + } + + + /** + *

systemAdminTree 系统管理员返回全部展开的数据

+ * 2022/12/16 17:15 + * ************************************************************ + * + * @param hrmResourceDtoList 人力资源dtolist + * @return List 树型list + * @author youHong.ai ****************************************** + */ + private List systemAdminTree(List hrmResourceDtoList) { + List 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()); + } + + /** + *

getHrmResourceDtoList 获取人力资源dto对象list

+ * 2022/12/16 17:09 + * ************************************************************ + * + * @param userId 当前登陆用户ID + * @param currentUser 当前登陆用户对象 + * @return List 人力资源dto对象list + * @author youHong.ai ****************************************** + */ + private List getHrmResourceDtoList(Integer userId, AtomicReference 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 hrmResourceList = mapper.selectAll(typeOfEmploymentField, lastNameEnField, + typeOfEmploymentTable, parentField, typeOfEmploymentIdField); + if (Objects.isNull(hrmResourceList) || hrmResourceList.isEmpty()) { + throw new CustomerException("查询不到相关人员!"); + } + //List hrmResourceDtoList = new ArrayList(); + /* ******************* 将pojo转换为Dto对象,对节点属性默认值赋值,找出当前用户并设置显示 ******************* */ + List 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; + } + /** *

计算节点所有子节点的数量

* 2022/12/3 17:55 diff --git a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java index ebc7b22..458f9f8 100644 --- a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java +++ b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java @@ -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()); diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java index 0c43783..b541e09 100644 --- a/src/test/java/youhong/ai/pcn/TestOrganization.java +++ b/src/test/java/youhong/ai/pcn/TestOrganization.java @@ -170,16 +170,16 @@ public class TestOrganization extends BaseTest { @Test public void testReadCsv() { String srcPath = GCONST.getSysFilePath() + "HRIS_PositionExport20221120" + ".csv"; -// String charset = "utf-8"; -// try (CSVReader csvReader = new CSVReaderBuilder(new BufferedReader(new InputStreamReader(new FileInputStream(new File(srcPath)), charset))).build()) { -// Iterator iterator = csvReader.iterator(); -// while (iterator.hasNext()) { -// Arrays.stream(iterator.next()).forEach(System.out::print); -// System.out.println(); -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } + // String charset = "utf-8"; + // try (CSVReader csvReader = new CSVReaderBuilder(new BufferedReader(new InputStreamReader(new FileInputStream(new File(srcPath)), charset))).build()) { + // Iterator iterator = csvReader.iterator(); + // while (iterator.hasNext()) { + // Arrays.stream(iterator.next()).forEach(System.out::print); + // System.out.println(); + // } + // } catch (Exception e) { + // e.printStackTrace(); + // } BufferedReader reader = null; String line = null; @@ -192,8 +192,8 @@ public class TestOrganization extends BaseTest { String[] fieldsArr = null; int lineNum = 0; int insertResult = 0; -// TableInfo tableInfo = new TableInfo(); -// tableInfo.setTableName(tableName); + // TableInfo tableInfo = new TableInfo(); + // tableInfo.setTableName(tableName); try { List> listField = new ArrayList<>(); while ((line = reader.readLine()) != null) { @@ -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 orgChartTree = orgChartService.getOrgChartTree(user); System.out.println(JSON.toJSONString(orgChartTree)); diff --git a/src/test/java/youhong/ai/pcn/WorkflowTest.java b/src/test/java/youhong/ai/pcn/WorkflowTest.java index 71f6738..70caf2a 100644 --- a/src/test/java/youhong/ai/pcn/WorkflowTest.java +++ b/src/test/java/youhong/ai/pcn/WorkflowTest.java @@ -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.*; /** *

流程相关测试

@@ -28,4 +38,127 @@ public class WorkflowTest extends BaseTest { .reduce(0, Integer::sum); System.out.println(sum); } + + + @Test + public void testEmail() { + String content = "

各位大佬:

\n" + + "

先前注册的gitea私有云仓库账号,域名备案已完成,现登陆仓库时请使用域名登陆!

\n" + + "
\n" + + "

私有仓库登陆地址:gitea私有仓库login

\n" + + "
\n" + + "

登陆账号为先前注册的账号:#{zhanghao},默认密码为用户名!

\n" + + "

如已绑定仓库,需要重新设置仓库远程地址,方法如下:

\n" + + "
\n" + + " 执行命令:
\n" + + " git remote -v\n" + + "
比如:\n" + + "

\n" + + " origin http://1.****.82/ecology/ebu_ecology_dev1.git (fetch)
\n" + + " origin http://1.****.82/ecology/ebu_ecology_dev1.git (push)\n" + + "

\n" + + "

查看到remote的名称,一般默认为 origin

\n" + + "
\n" + + " 执行命令:
\n" + + " git remote set-url origin https://gitea.yeyaguitu.cn/ecology/ebu_ecology_dev1.git\n" + + "

其中 origin 为查询到的remote的名称

"; + List> list = new ArrayList<>(); + list.add(new HashMap() {{ + put("name", "bokang.xiao"); + put("email", "ic_excellent@qq.com"); + }}); + list.add(new HashMap() {{ + put("name", "chaoyang.he"); + put("email", "chaoyang.he@weaver.com.cn"); + }}); + list.add(new HashMap() {{ + put("name", "jiacheng.deng"); + put("email", "jiacheng.deng@weaver.com.cn"); + }}); + list.add(new HashMap() {{ + put("name", "jiayong.cao"); + put("email", "jiayong.cao@weaver.com.cn"); + }}); + list.add(new HashMap() {{ + put("name", "jingwei.tao"); + put("email", "jingwei.tao@weaver.com.cn"); + }}); + list.add(new HashMap() {{ + put("name", "weilin.zhu"); + put("email", "bleach_725@163.com"); + }}); + list.add(new HashMap() {{ + put("name", "xuanran.wang"); + put("email", "xuanran.wang@weaver.com.cn"); + }}); + list.add(new HashMap() {{ + put("name", "xvqiang.ren"); + put("email", "1215877336@qq.com"); + }}); + list.add(new HashMap() {{ + put("name", "youhong.ai"); + put("email", "youhong.ai@weaver.com.cn"); + }}); + for (Map 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("", "") + // .replace("", "") + // .replace("", ""); + //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 { + + /** + * 将HTML转成PDF格式的文件。html文件的格式比较严格 + * + * @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(); + } +} +