package com.hotent.runtime.script; import java.io.IOException; import java.text.ParseException; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.Map.Entry; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import javax.annotation.Resource; import cn.hutool.core.util.ObjectUtil; import com.fasterxml.jackson.databind.node.*; import com.hotent.base.datasource.DatabaseContext; import com.hotent.base.manager.CommonManager; import com.hotent.base.util.*; import com.hotent.base.util.Base64; import com.hotent.runtime.model.enums.UserParamsEnums; import com.hotent.runtime.utils.SubCalcUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.exception.ExceptionUtils; import org.springframework.context.annotation.Primary; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.JsonNode; import com.hotent.base.cache.annotation.Cacheable; import com.hotent.base.cache.annotation.FirstCache; import com.hotent.base.constants.CacheKeyConst; import com.hotent.base.context.BaseContext; import com.hotent.base.exception.BaseException; import com.hotent.base.feign.BpmRuntimeFeignService; import com.hotent.base.feign.FormFeignService; import com.hotent.base.feign.PortalFeignService; import com.hotent.base.feign.UCFeignService; import com.hotent.base.groovy.IScript; import com.hotent.base.model.CommonResult; import com.hotent.base.util.time.DateFormatUtil; import com.hotent.base.util.time.DateUtil; import com.hotent.base.util.time.TimeUtil; import com.hotent.bpm.api.cmd.ActionCmd; import com.hotent.bpm.api.constant.BpmConstants; import com.hotent.bpm.api.constant.ExtractType; import com.hotent.bpm.api.context.ContextThreadUtil; import com.hotent.bpm.api.model.delegate.BpmDelegateTask; import com.hotent.bpm.api.model.identity.BpmIdentity; import com.hotent.bpm.api.service.BoDataService; import com.hotent.bpm.api.service.BpmTaskActionService; import com.hotent.bpm.engine.task.cmd.DefaultTaskFinishCmd; import com.hotent.bpm.listener.BusDataUtil; import com.hotent.bpm.model.identity.DefaultBpmIdentity; import com.hotent.bpm.natapi.task.NatTaskService; import com.hotent.bpm.persistence.manager.BpmBusLinkManager; import com.hotent.bpm.persistence.manager.BpmDefinitionManager; import com.hotent.bpm.persistence.manager.BpmProcessInstanceManager; import com.hotent.bpm.persistence.model.BpmBusLink; import com.hotent.bpm.persistence.model.BpmExeStack; import com.hotent.bpm.persistence.model.DefaultBpmDefinition; import com.hotent.bpm.persistence.model.DefaultBpmProcessInstance; import com.hotent.bpm.persistence.model.DefaultBpmTask; import com.hotent.bpm.util.BoDataUtil; import com.hotent.runtime.manager.IProcessManager; import com.hotent.runtime.params.StartFlowParamObject; import com.hotent.runtime.params.StartResult; import com.hotent.uc.api.constant.GroupTypeConstant; import com.hotent.uc.api.impl.service.UserServiceImpl; import com.hotent.uc.api.impl.util.ContextUtil; import com.hotent.uc.api.model.IGroup; import com.hotent.uc.api.model.IUser; /** * 系统配置中的常用脚本。 * * @author ray */ @Component public class ScriptImpl implements IScript { @Resource PortalFeignService portalFeignService; @Resource BpmProcessInstanceManager bpmProcessInstanceManager; @Resource BoDataService boDataService; @Resource UCFeignService uCFeignService; @Resource IProcessManager iProcessService; @Resource UserServiceImpl userServiceImpl; @Resource BaseContext baseContext; @Resource BpmDefinitionManager bpmDefinitionManager; @Resource NatTaskService natTaskService; @Resource DatabaseContext databaseContext; @Resource CommonManager commonManager; private final String FIELD_PREFIX = "F_"; private final String CurrentGroupIdPrefix = "CurrentGroupId:"; /** * 获取当前用户ID。 * * @return */ public Set getCurrentUserIdSet() { Set set = new HashSet(); set.add(ContextUtil.getCurrentUser().getUserId()); return set; } /** * 获取当前用户对象。 * * @return */ public IUser getCurrentUser() { return ContextUtil.getCurrentUser(); } /** * 获取当前用户ID。 * * @return */ public String getCurrentUserId() { return ContextUtil.getCurrentUser().getUserId(); } /** * 获取当前用户帐号。 * * @return */ public String getCurrentAccount() { return ContextUtil.getCurrentUser().getAccount(); } /** * 获取当前用户的当前组织id * * @return * @throws Exception */ public String getCurrentGroupId() throws Exception { String userId = ContextUtil.getCurrentUserId(); ScriptImpl bean = AppUtil.getBean(getClass()); String groupIdFromCache = bean.getCurrentGroupIdFromCache(userId); return StringUtil.isEmpty(groupIdFromCache) ? ContextUtil.getCurrentGroupId() : groupIdFromCache; } /** * 获取当前用户的当前组织名称。 * * @return * @throws IOException */ public String getCurrentGroupName() throws IOException { IGroup currentGroup = ContextUtil.getCurrentGroup(); if (currentGroup == null) { return null; } return currentGroup.getName(); } /** * 根据别名生成流水号。 * *
     * 使用方法:
     * scriptImpl.getNextNo("globalNo");
     * 
* * @param alias 流水号配置别名。 * @return */ public String getNextNo(String alias) { return portalFeignService.getNextIdByAlias(alias); } /** * 判断命令是否是 DefaultTaskFinishCmd * * @param processCmd * @return */ public boolean isDefaultTaskFinishCmd(ActionCmd processCmd) { return DefaultTaskFinishCmd.class.getName().equals(processCmd.getClass().getName()); } /** * 判断数据是否在系统中存在。 * * @param boData * @param fieldName 字段名 * @return * @messages 消息 */ public void validBoDataExist(ObjectNode boData, String fieldName, String messages) { JdbcTemplate jdbcTemplate = (JdbcTemplate) AppUtil.getBean("jdbcTemplate"); ObjectNode boEnt = (ObjectNode) boData.get("boEnt"); boolean isAdd = true; String pk = boEnt.get("pkKey").asText().toLowerCase(); if (boEnt.findValues("pk") != null && StringUtil.isNotEmpty(String.valueOf(boEnt.get(pk).asText()))) { isAdd = false; } String sql = ""; Object[] aryObj = null; Object obj = boData.get(fieldName); String val = ""; if (BeanUtils.isNotEmpty(obj)) { val = obj.toString().trim(); } // 添加 if (isAdd) { aryObj = new Object[1]; aryObj[0] = val; sql = "select count(*) from " + boEnt.get("tableName").asText() + " where " + FIELD_PREFIX + fieldName + "=?"; } // 更新数据 else { aryObj = new Object[2]; aryObj[0] = val; aryObj[1] = boData.get(boEnt.get("pkKey").asText()); sql = "select count(*) from " + boEnt.get("tableName").asText() + " where " + FIELD_PREFIX + fieldName + "=? and " + boEnt.get("pkKey").asText() + "!=?"; } Integer rtn = jdbcTemplate.queryForObject(sql, aryObj, Integer.class); if (rtn > 0) { if (StringUtil.isNotEmpty(messages)) { throw new RuntimeException(messages); } else { throw new RuntimeException(val + "数据已经存在,请检查表单数据!"); } } } /** * 全部角色 * * @return */ public Set getRoles() { Set set = new LinkedHashSet(); List listRole = uCFeignService.getAllRole(); for (ObjectNode role : listRole) { BpmIdentity identity = new DefaultBpmIdentity(role.get("id").asText(), role.get("name").asText(), BpmIdentity.TYPE_GROUP); identity.setType(BpmIdentity.TYPE_GROUP); identity.setExtractType(ExtractType.EXACT_NOEXACT); identity.setGroupType(GroupTypeConstant.ROLE.key()); set.add(identity); } return set; } /** * 判断某个用户是否属于某个角色 * * @param account 用户賬號 * @param roleAlias 角色别名 * @return */ public boolean isUserInRole(String account, String roleAlias) { if (StringUtil.isEmpty(account) || StringUtil.isEmpty(roleAlias)) { return false; } List listRole = uCFeignService.getRoleListByAccount(account); if (BeanUtils.isNotEmpty(listRole)) { for (ObjectNode role : listRole) { if (roleAlias.equals(role.get("code").asText())) { return true; } } } return false; } /** * 获取cmd对象 * * @return */ public ActionCmd getActionCmd() { ActionCmd cmd = ContextThreadUtil.getActionCmd(); return cmd; } /** * 获取当前用户的主组织名称 * * @return */ public String getIUserMainOrgName() { ObjectNode org = uCFeignService.getMainGroup(ContextUtil.getCurrentUser().getUserId()); if (BeanUtils.isNotEmpty(org)) { return org.get("name").asText(); } return null; } /** * 获取当前用户的主组织ID * * @return */ public String getIUserMainOrgID() { ObjectNode org = uCFeignService.getMainGroup(ContextUtil.getCurrentUser().getUserId()); if (BeanUtils.isNotEmpty(org)) { return org.get("id").asText(); } return null; } /** * 获取当前用户的岗位名称 * * @return */ public Set getIUserPostName() { Set set = new HashSet(); List orgRels = uCFeignService.getPosListByAccount(ContextUtil.getCurrentUser().getAccount()); if (BeanUtils.isNotEmpty(orgRels)) { for (ObjectNode orgRel : orgRels) { set.add(orgRel.get("name").asText()); } } return set; } /** * 获取当前用户的岗位ID * * @return */ public Set getIUserPostID() { Set set = new HashSet(); List orgRels = uCFeignService.getPosListByAccount(ContextUtil.getCurrentUser().getAccount()); if (BeanUtils.isNotEmpty(orgRels)) { for (ObjectNode orgRel : orgRels) { set.add(orgRel.get("id").asText()); } } return set; } /** * 获取当前用户的角色名称 * * @return */ public Set getIUserRoleName() { Set set = new HashSet(); List roles = uCFeignService.getRoleListByAccount(ContextUtil.getCurrentUser().getAccount()); if (BeanUtils.isNotEmpty(roles)) { for (ObjectNode role : roles) { set.add(role.get("name").asText()); } } return set; } /** * 获取当前用户的角色ID * * @return */ public Set getIUserRoleID() { Set set = new HashSet(); List roles = uCFeignService.getRoleListByAccount(ContextUtil.getCurrentUser().getUserId()); if (BeanUtils.isNotEmpty(roles)) { for (ObjectNode role : roles) { set.add(role.get("id").asText()); } } return set; } /** * 获取当前用户名称 * * @return */ public String getCurrentUserName() { return ContextUtil.getCurrentUser().getFullname(); } /** * 根据新闻公告id修改其数据审批状态为审批通过 1。审批中。2.审批通过 */ public void getNewsStatusById() throws Exception { ActionCmd actionCmd = getActionCmd(); BpmBusLinkManager bpmBusLinkManager = AppUtil.getBean(BpmBusLinkManager.class); if (BeanUtils.isNotEmpty(actionCmd)) { Map linkMap = bpmBusLinkManager.getMapByInstId(actionCmd.getInstId()); ObjectNode jsonObject = (ObjectNode) JsonUtil.toJsonNode(actionCmd.getBusData()); // BO Map数据。 Map jsonMap = BoDataUtil.getMap(jsonObject); FormFeignService formFeignService = AppUtil.getBean(FormFeignService.class); for (String key : jsonMap.keySet()) { ObjectNode def = formFeignService.getBodefByAlias(key); BpmBusLink busLink = linkMap.get(def.get("alias").asText()); PortalFeignService portalFeignService = AppUtil.getBean(PortalFeignService.class); portalFeignService.publicMsgNews(busLink.getBusinesskeyStr()); } } } public Boolean isSynchronize(String nodeIds, String actionName) throws Exception { Boolean flag = true; ActionCmd actionCmd = getActionCmd(); if (BeanUtils.isNotEmpty(actionCmd)) { BpmRuntimeFeignService bean = AppUtil.getBean(BpmRuntimeFeignService.class); String lastNodeIds = "";// 最后一个任务节点ID if (BeanUtils.isNotEmpty(actionCmd.getTransitVars("parentStack"))) { BpmExeStack bpmExeStack = (BpmExeStack) actionCmd.getTransitVars("parentStack"); lastNodeIds = bpmExeStack.getNodeId(); } String lastActionName = actionCmd.getActionName();// 最后一个任务节点审批处理的状态 flag = bean.isSynchronize(actionCmd.getInstId(), nodeIds, actionName, lastActionName, lastNodeIds); } return flag; } /** * 获取当前日期,例如"2002-11-06" * * @return */ public String getCurrentDate() { return TimeUtil.getCurrentDate(); } /** * 获取当前日期,按指定格式输出 * * @return */ public String getCurrentDateByStyle(String style) { return DateUtil.getCurrentTime(style); } /** * 更新主表字段值 * * @param defCode 业务对象编码 * @param field 字段名称 * @param value 字段值 * @throws Exception */ public void updateMainField(String defCode, String field, Object value) throws Exception { ActionCmd cmd = ContextThreadUtil.getActionCmd(); String instId = cmd.getInstId(); DefaultBpmProcessInstance instance = bpmProcessInstanceManager.get(instId); ObjectNode jsonObject = JsonUtil.createObjectNode(); //如果有实例信息,则根据实例信息取最新的表单数据来更新。 if (StringUtil.isNotEmpty(defCode) && StringUtil.isNotEmpty(field) && BeanUtils.isNotEmpty(instance)) { List oldBoDatas = boDataService.getDataByInst(instance); if (BeanUtils.isEmpty(oldBoDatas)) { throw new RuntimeException(String.format("根据实例id:%s未查找到表单数据", instId)); } boolean isUpdate = false; for (ObjectNode obj : oldBoDatas) { if (defCode.equals(JsonUtil.getString(obj, "boDefAlias")) && BeanUtils.isNotEmpty(obj.get("boEnt")) && BeanUtils.isNotEmpty(obj.get("boEnt").get("attributeList"))) { ArrayNode attrs = (ArrayNode) obj.get("boEnt").get("attributeList"); for (JsonNode jsonNode : attrs) { if (field.equals(jsonNode.get("name").asText())) { isUpdate = true; break; } } } } // 如果从数据库取出来的bodata的attributeList,没找到这个字段。则该字段不存在,直接return不做更新。 if (!isUpdate) { return; } jsonObject = BoDataUtil.hanlerData(instance, "", oldBoDatas); // 没有实例信息,但是cmd里面有busdata和流程实例对象,则用busdata来更新 } else if (StringUtil.isNotEmpty(cmd.getBusData()) && BeanUtils.isNotEmpty(cmd.getTransitVars(BpmConstants.PROCESS_INST))) { instance = (DefaultBpmProcessInstance) cmd.getTransitVars(BpmConstants.PROCESS_INST); jsonObject = (ObjectNode) JsonUtil.toJsonNode(cmd.getBusData()); } else { // 两者都没有。则return return; } Iterator> iterator = jsonObject.fields(); while (iterator.hasNext()) { Entry next = iterator.next(); String key = next.getKey(); if (key.equals(defCode)) { ObjectNode ywdxObj = (ObjectNode) next.getValue(); if (BeanUtils.isNotEmpty(ywdxObj)) { if (value instanceof Integer) { ywdxObj.put(field, (int) value); } else { ywdxObj.put(field, (String) value); } } } } BusDataUtil.updateBoData(instance, "", JsonUtil.toJson(jsonObject)); cmd.setBusData(JsonUtil.toJson(jsonObject)); } /** * 根据实例id更新主表字段值 * * @param instId 实例id * @param defCode 业务对象编码 * @param field 字段名称 * @param value 字段值 * @throws Exception */ public void updateMainField(String instId, String defCode, String field, Object value) throws Exception { DefaultBpmProcessInstance instance = bpmProcessInstanceManager.get(instId); if (StringUtil.isNotEmpty(defCode) && StringUtil.isNotEmpty(field) && BeanUtils.isNotEmpty(instance)) { List oldBoDatas = boDataService.getDataByInst(instance); ObjectNode jsonObject = BoDataUtil.hanlerData(instance, "", oldBoDatas); Iterator> iterator = jsonObject.fields(); boolean isUpdate = false; while (iterator.hasNext()) { Entry next = iterator.next(); String key = next.getKey(); if (key.equals(defCode)) { ObjectNode ywdxObj = (ObjectNode) next.getValue(); if (BeanUtils.isNotEmpty(ywdxObj)) { Iterator> fieldIterator = ywdxObj.fields(); while (fieldIterator.hasNext()) { String fieldKey = fieldIterator.next().getKey(); if (fieldKey.equals(field)) { if (value instanceof Integer) { ywdxObj.put(field, (int) value); } else { ywdxObj.put(field, (String) value); } isUpdate = true; break; } } } } } if (isUpdate) { BusDataUtil.updateBoData(instance, "", JsonUtil.toJsonString(jsonObject)); } } } /** * 更新子表字段值 * * @param mainDefCode 主表bo定义编码 * @param subDefCode 子表bo定义编码 * @param index 更新子表数据行序号 * @param field 更新子表字段 * @param value 更新子表字段值 * @throws Exception */ public void updateSubField(String mainDefCode, String subDefCode, int index, String field, Object value) throws Exception { ActionCmd cmd = ContextThreadUtil.getActionCmd(); if (StringUtil.isNotEmpty(mainDefCode) && StringUtil.isNotEmpty(field)) { String busData = cmd.getBusData(); ObjectNode jsonObject = (ObjectNode) JsonUtil.toJsonNode(busData); Iterator> iterator = jsonObject.fields(); boolean isUpdate = false; while (iterator.hasNext()) { Entry next = iterator.next(); String key = next.getKey(); if (key.equals(mainDefCode)) { ObjectNode ywdxObj = (ObjectNode) next.getValue(); if (BeanUtils.isNotEmpty(ywdxObj)) { Iterator> fieldIterator = ywdxObj.fields(); while (fieldIterator.hasNext()) { Entry mainNext = fieldIterator.next(); if (mainNext.getKey().contains("sub_")) { String fieldKey = mainNext.getKey().replace("sub_", ""); if (fieldKey.equals(subDefCode)) { ArrayNode subArrayObj = (ArrayNode) mainNext.getValue(); if (BeanUtils.isNotEmpty(subArrayObj) && subArrayObj.size() >= (index + 1)) { ObjectNode subObj = (ObjectNode) subArrayObj.get(index); Iterator> subIterator = subObj.fields(); while (subIterator.hasNext()) { Entry subNext = subIterator.next(); String subFieldKey = subNext.getKey(); if (subFieldKey.equals(field)) { if (value instanceof Integer) { subObj.put(field, (int) value); } else { subObj.put(field, (String) value); } isUpdate = true; break; } } } } } } } } } DefaultBpmProcessInstance instance = bpmProcessInstanceManager.get(cmd.getInstId()); if (isUpdate && BeanUtils.isNotEmpty(instance)) { BusDataUtil.updateBoData(instance, "", JsonUtil.toJson(jsonObject)); cmd.setBusData(JsonUtil.toJson(jsonObject)); } } } /** * 获取子表字段值 * * @param ywdxCode 业务对象编码 * @param subTableName 子表表名 * @param field 字段名称 * @return * @throws IOException */ public Object getSubFiledValue(String defCode, String subTableName, String field) throws IOException { ActionCmd cmd = ContextThreadUtil.getActionCmd(); if (StringUtil.isNotEmpty(defCode) && StringUtil.isNotEmpty(subTableName) && StringUtil.isNotEmpty(field)) { String busData = cmd.getBusData(); ObjectNode jsonObject = (ObjectNode) JsonUtil.toJsonNode(busData); Iterator> iterator = jsonObject.fields(); while (iterator.hasNext()) { String key = iterator.next().getKey(); if (key.equals(defCode)) { ObjectNode ywdxObj = (ObjectNode) jsonObject.get(key); if (BeanUtils.isNotEmpty(ywdxObj)) { Iterator> fieldIterator = ywdxObj.fields(); while (fieldIterator.hasNext()) { String fieldKey = fieldIterator.next().getKey(); String subName = "sub_" + subTableName; if (fieldKey.equals(subName)) { ObjectNode subObj = (ObjectNode) jsonObject.get(subName); if (BeanUtils.isNotEmpty(subObj)) { Iterator> subIterator = ywdxObj.fields(); while (subIterator.hasNext()) { String subFiledKey = fieldIterator.next().getKey(); if (subFiledKey.equals(field)) { return ywdxObj.get(field); } } } } } } } } } return null; } /** * 根据下标获取子表字段值 * * @param defCode * @param subTableCode * @param subFieldCode * @param index * @return * @throws Exception */ public String getSubFieldValueByIndex(String defCode, String subTableCode, String subFieldCode, int index) throws Exception { ActionCmd cmd = ContextThreadUtil.getActionCmd(); if (StringUtil.isNotEmpty(defCode) && StringUtil.isNotEmpty(subTableCode)) { String busData = cmd.getBusData(); ObjectNode jsonObject = (ObjectNode) JsonUtil.toJsonNode(busData); Iterator> iterator = jsonObject.fields(); String subTabName = "sub_" + subTableCode; while (iterator.hasNext()) { Entry next = iterator.next(); String key = next.getKey(); if (key.equals(defCode)) { ObjectNode ywdxObj = (ObjectNode) next.getValue(); if (BeanUtils.isNotEmpty(ywdxObj)) { Iterator> fieldIterator = ywdxObj.fields(); while (fieldIterator.hasNext()) { Entry mainNext = fieldIterator.next(); if (mainNext.getKey().equals(subTabName)) { ArrayNode subArrayObj = (ArrayNode) mainNext.getValue(); if (BeanUtils.isNotEmpty(subArrayObj) && subArrayObj.size() >= index) { return JsonUtil.getString(subArrayObj.get(index - 1), subFieldCode, ""); } } } } } } } return ""; } public static boolean littleThen(String st1, String st2) { if (BeanUtils.isNotEmpty(st1) && BeanUtils.isNotEmpty(st1)) { return st1.compareTo(st2) < 0; } return false; } public static boolean LargeThen(String st1, String st2) { if (BeanUtils.isNotEmpty(st1) && BeanUtils.isNotEmpty(st1)) { return st1.compareTo(st2) > 0; } return false; } public static boolean equals(String st1, String st2) { if (BeanUtils.isEmpty(st1) && BeanUtils.isEmpty(st2)) { return true; } if (BeanUtils.isNotEmpty(st1) && BeanUtils.isNotEmpty(st1)) { return st1.equals(st2); } return false; } public static boolean contains(String st1, String st2) { if (BeanUtils.isNotEmpty(st1) && BeanUtils.isNotEmpty(st1)) { return st1.contains(st2); } return false; } /** * 判断子表子表中是否有某一行的字段名为指定值 * * @param arr 子表集合 * @param field 字段名 * @param value 字段值 */ public static boolean subContains(ArrayNode arr, String field, String value) throws Exception { if (BeanUtils.isEmpty(arr)) { return false; } for (JsonNode node : arr) { JsonNode v = node.get(field); if (null == v || v.getNodeType().equals(JsonNodeType.NULL)) { continue; } if (v.getNodeType().equals(JsonNodeType.STRING) || v.getNodeType().equals(JsonNodeType.NUMBER)) { if (v.asText().contains(value)) { return true; } } } return false; } /** * 开始时间是否大于结束时间 * * @param startTime 开始时间 * @param endTime 结束时间 * @return */ public static boolean isDateLarge(LocalDateTime startTime, LocalDateTime endTime) { if (BeanUtils.isEmpty(startTime)) { return false; } if (BeanUtils.isEmpty(endTime)) { return true; } return startTime.toEpochSecond(ZoneOffset.of("+8")) - endTime.toEpochSecond(ZoneOffset.of("+8")) > 0; } public static boolean dateIsNull(LocalDateTime startTime) { return BeanUtils.isEmpty(startTime); } public static boolean dateIsNull(String startTime) { return BeanUtils.isEmpty(startTime); } public static boolean isDateLarge(LocalDateTime startTime, String endTime) { if (BeanUtils.isEmpty(startTime)) { return false; } if (BeanUtils.isEmpty(endTime)) { return true; } try { LocalDateTime date = DateFormatUtil.parse(endTime); return startTime.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) > 0; } catch (ParseException e) { e.printStackTrace(); } return false; } public static boolean isDateLarge(String startTime, String endTime) { if (BeanUtils.isEmpty(startTime)) { return false; } if (BeanUtils.isEmpty(endTime)) { return true; } try { LocalDateTime sdate = DateFormatUtil.parse(startTime); LocalDateTime date = DateFormatUtil.parse(endTime); return sdate.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) > 0; } catch (ParseException e) { e.printStackTrace(); } return false; } /** * 开始时间是否大于等于结束时间 * * @param startTime 开始时间 * @param endTime 结束时间 * @return */ public static boolean isDateLargeEquals(LocalDateTime startTime, LocalDateTime endTime) { if (BeanUtils.isEmpty(startTime)) { return false; } if (BeanUtils.isEmpty(endTime)) { return true; } return startTime.toEpochSecond(ZoneOffset.of("+8")) - endTime.toEpochSecond(ZoneOffset.of("+8")) >= 0; } public static boolean isDateLargeEquals(LocalDateTime startTime, String endTime) { if (BeanUtils.isEmpty(startTime)) { return false; } if (BeanUtils.isEmpty(endTime)) { return true; } try { LocalDateTime date = DateFormatUtil.parse(endTime); return startTime.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) >= 0; } catch (ParseException e) { e.printStackTrace(); } return false; } public static boolean isDateLargeEquals(String startTime, String endTime) { if (BeanUtils.isEmpty(startTime)) { return false; } if (BeanUtils.isEmpty(endTime)) { return true; } try { LocalDateTime sdate = DateFormatUtil.parse(startTime); LocalDateTime date = DateFormatUtil.parse(endTime); return sdate.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) >= 0; } catch (ParseException e) { e.printStackTrace(); } return false; } /** * 开始时间是否小于结束时间 * * @param startTime 开始时间 * @param endTime 结束时间 * @return */ public static boolean isDateLittle(LocalDateTime startTime, LocalDateTime endTime) { if (BeanUtils.isEmpty(startTime) && BeanUtils.isNotEmpty(endTime)) { return true; } if (BeanUtils.isEmpty(endTime)) { return false; } return startTime.toEpochSecond(ZoneOffset.of("+8")) - endTime.toEpochSecond(ZoneOffset.of("+8")) < 0; } public static boolean isDateLittle(LocalDateTime startTime, String endTime) { if (BeanUtils.isEmpty(startTime)) { return true; } if (BeanUtils.isEmpty(endTime)) { return false; } try { LocalDateTime date = DateFormatUtil.parse(endTime); return startTime.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) < 0; } catch (ParseException e) { e.printStackTrace(); } return false; } public static boolean isDateLittle(String startTime, String endTime) { if (BeanUtils.isEmpty(startTime)) { return true; } if (BeanUtils.isEmpty(endTime)) { return false; } try { LocalDateTime sdate = DateFormatUtil.parse(startTime); LocalDateTime edate = DateFormatUtil.parse(endTime); return sdate.toEpochSecond(ZoneOffset.of("+8")) - edate.toEpochSecond(ZoneOffset.of("+8")) < 0; } catch (ParseException e) { e.printStackTrace(); } return false; } /** * 开始时间是否小于等于结束时间 * * @param startTime 开始时间 * @param endTime 结束时间 * @return */ public static boolean isDateLittleEquals(LocalDateTime startTime, LocalDateTime endTime) { if (BeanUtils.isEmpty(startTime) && BeanUtils.isNotEmpty(endTime)) { return true; } if (BeanUtils.isEmpty(endTime)) { return false; } return startTime.toEpochSecond(ZoneOffset.of("+8")) - endTime.toEpochSecond(ZoneOffset.of("+8")) <= 0; } public static boolean isDateLittleEquals(LocalDateTime startTime, String endTime) { if (BeanUtils.isEmpty(startTime)) { return true; } if (BeanUtils.isEmpty(endTime)) { return false; } try { LocalDateTime date = DateFormatUtil.parse(endTime); return startTime.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) <= 0; } catch (ParseException e) { e.printStackTrace(); } return false; } public static boolean isDateLittleEquals(String startTime, String endTime) { if (BeanUtils.isEmpty(startTime)) { return true; } if (BeanUtils.isEmpty(endTime)) { return false; } try { LocalDateTime sdate = DateFormatUtil.parse(startTime); LocalDateTime edate = DateFormatUtil.parse(endTime); return sdate.toEpochSecond(ZoneOffset.of("+8")) - edate.toEpochSecond(ZoneOffset.of("+8")) <= 0; } catch (ParseException e) { e.printStackTrace(); } return false; } /** * 开始时间是否等于结束时间 * * @param startTime 开始时间 * @param endTime 结束时间 * @return */ public static boolean isDateEquals(LocalDateTime startTime, LocalDateTime endTime) { if (BeanUtils.isEmpty(startTime) && BeanUtils.isEmpty(endTime)) { return true; } if (BeanUtils.isNotEmpty(startTime) && BeanUtils.isNotEmpty(endTime)) { return startTime.toEpochSecond(ZoneOffset.of("+8")) - endTime.toEpochSecond(ZoneOffset.of("+8")) == 0; } return false; } public static boolean isDateEquals(LocalDateTime startTime, String endTime) { if (BeanUtils.isEmpty(startTime) && BeanUtils.isEmpty(endTime)) { return true; } if (BeanUtils.isNotEmpty(startTime) && BeanUtils.isNotEmpty(endTime)) { try { LocalDateTime date = DateFormatUtil.parse(endTime); return startTime.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) < 0; } catch (ParseException e) { e.printStackTrace(); } } return false; } public static boolean isDateEquals(String startTime, String endTime) { if (BeanUtils.isEmpty(startTime) && BeanUtils.isEmpty(endTime)) { return true; } if (BeanUtils.isNotEmpty(startTime) && BeanUtils.isNotEmpty(endTime)) { try { LocalDateTime sdate = DateFormatUtil.parse(startTime); LocalDateTime date = DateFormatUtil.parse(endTime); return sdate.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) < 0; } catch (ParseException e) { e.printStackTrace(); } } return false; } /** * 日期时间是否属于范围内 * * @param time 需要比较的时间 * @param boundary 范围,两个时间逗号隔开:如 2020-05-06 00:00:00,2020-06-25 01:01:01 * @return */ public static boolean isDateBelongTo(String time, String boundary) { if (BeanUtils.isEmpty(time) || BeanUtils.isEmpty(boundary)) { return false; } try { LocalDateTime date = DateFormatUtil.parse(time); String[] boundaryArr = boundary.split(","); if (boundaryArr.length != 2) { return false; } LocalDateTime sdate = DateFormatUtil.parse(boundaryArr[0]); LocalDateTime edate = DateFormatUtil.parse(boundaryArr[1]); return date.toEpochSecond(ZoneOffset.of("+8")) >= sdate.toEpochSecond(ZoneOffset.of("+8")) && date.toEpochSecond(ZoneOffset.of("+8")) <= edate.toEpochSecond(ZoneOffset.of("+8")); } catch (ParseException e) { e.printStackTrace(); } return false; } public void testStart(String instid) throws Exception { StartFlowParamObject startFlowParamObject = new StartFlowParamObject(); startFlowParamObject.setFlowKey("csjdlc"); startFlowParamObject.setAccount("admin"); ContextThreadUtil.clearTaskMap(); ContextThreadUtil.cleanCommuVars(); ContextUtil.clearAll(); CompletableFuture start = iProcessService.start(startFlowParamObject); System.out.println(start.get().getState()); } public void startNewWithCurFlowData(String startUsers, String newFlowKey) throws Exception { if (StringUtil.isEmpty(startUsers)) { return; } List users = userServiceImpl.getUserByAccounts(startUsers); if (BeanUtils.isEmpty(users)) { return; } ActionCmd actionCmd = getActionCmd(); StartFlowParamObject startFlowParamObject = new StartFlowParamObject(); startFlowParamObject.setFlowKey(newFlowKey); startFlowParamObject.setData(Base64.getBase64(actionCmd.getBusData())); ExecutorService executorService = Executors.newCachedThreadPool(); for (IUser iUser : users) { executorService.execute(() -> { try { ContextUtil.setCurrentUser(iUser); baseContext.setTempTenantId(iUser.getTenantId()); startFlowParamObject.setAccount(iUser.getAccount()); iProcessService.start(startFlowParamObject); } catch (Exception e) { e.printStackTrace(); } }); } } /** * 数字是否属于范围内 * * @param num 需要比较的数字 * @param boundary 范围,两个时间逗号隔开:如 0,100 * @return */ public static boolean isNumberBelongTo(Integer num, String boundary) { if (BeanUtils.isEmpty(num) || BeanUtils.isEmpty(boundary)) { return false; } String[] boundaryArr = boundary.split(","); if (boundaryArr.length != 2) { return false; } Integer start = Integer.valueOf(boundaryArr[0]); Integer end = Integer.valueOf(boundaryArr[1]); return start <= num && num <= end; } /** * 字符串是否属于数组集合内 * * @param target 需要比较的字符串 * @param boundary 英文逗号隔开的字符串数组:如 aaa,bbb,ccc * @return */ public static boolean isStringBelongTo(String target, String boundary) { if (BeanUtils.isEmpty(target) || BeanUtils.isEmpty(boundary)) { return false; } String[] boundaryArr = boundary.split(","); if (boundaryArr.length <= 0) { return false; } List list = Arrays.asList(boundaryArr); return list.contains(target); } /** * demo脚本,根据所传账号查询用户,使用用户名更新表单字段 * * @param account * @param attrName * @param formPath * @throws Exception */ public void updateFormData(String account, String bodefName, String fileName) throws Exception { if (StringUtil.isNotEmpty(account) && StringUtil.isNotEmpty(bodefName) && StringUtil.isNotEmpty(fileName)) { ObjectNode header = JsonUtil.getMapper().createObjectNode(); String token = "admin:" + EncryptUtil.encrypt("feignCallEncry"); header.put("Authorization", "Basic " + Base64.getBase64(token)); String string = FluentUtil.get( "http://ip:port/api/user/v1/user/getUser?userNumber" + "" + "&account=" + account, Base64.getBase64(JsonUtil.toJson(header))); if (BeanUtils.isNotEmpty(string)) { ObjectNode jsonNode = (ObjectNode) JsonUtil.toJsonNode(string); String userName = jsonNode.get("fullname").asText(); updateMainField(bodefName, fileName, userName); } } } /** * @param account * @param checkValue * @param destination * @throws Exception */ public void getDataAndCheckBack(BpmDelegateTask delegateTask, String account, String checkValue, String skipNode) throws Exception { if (StringUtil.isNotEmpty(account) && StringUtil.isNotEmpty(checkValue)) { ObjectNode header = JsonUtil.getMapper().createObjectNode(); String token = "admin:" + EncryptUtil.encrypt("feignCallEncry"); header.put("Authorization", "Basic " + Base64.getBase64(token)); String string = FluentUtil.get( "http://ip:port/api/user/v1/user/getUser?userNumber" + "" + "&account=" + account, Base64.getBase64(JsonUtil.toJson(header))); if (BeanUtils.isNotEmpty(string)) { ObjectNode jsonNode = (ObjectNode) JsonUtil.toJsonNode(string); String userName = jsonNode.get("fullname").asText(); if (userName.equals(checkValue)) { ExecutorService executorService = Executors.newCachedThreadPool(); executorService.execute(() -> { try { IUser userByAccount = userServiceImpl.getUserByAccount("admin"); Thread.sleep(2000); ContextUtil.setCurrentUser(userByAccount); baseContext.setTempTenantId(userByAccount.getTenantId()); DefaultTaskFinishCmd cmd = new DefaultTaskFinishCmd(); ContextThreadUtil.setActionCmd(cmd); cmd.setTaskId(delegateTask.getId()); if (StringUtil.isEmpty(skipNode)) { cmd.addTransitVars(BpmConstants.SKIP_NODE, "UserTask4"); } else { cmd.addTransitVars(BpmConstants.SKIP_NODE, skipNode); } cmd.setActionName("agree"); BpmTaskActionService bpmTaskActionService = AppUtil.getBean(BpmTaskActionService.class); bpmTaskActionService.finishTask(cmd); } catch (Exception e) { e.printStackTrace(); } }); } } } } /** * 获取当前年份 * * @return 年份 */ public String getCurrentYear() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy"); return LocalDateTime.now().format(formatter); } /** * 获取当前月份 * * @return 月份 */ public String getCurrentMonth() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM"); return LocalDateTime.now().format(formatter); } /** * 获取当前用户填制单位id * * @return * @throws Exception */ public String getFillOrgId(String demId) throws Exception { String orgId = ""; CommonResult result = uCFeignService.getFillOrg(demId, ""); if (result.getState()) { JsonNode orgNode = (JsonNode) result.getValue(); if (orgNode.has("id")) { orgId = orgNode.get("id").asText(); } } if (StringUtil.isEmpty(orgId)) { throw new RuntimeException("获取当前填制单位失败!"); } return orgId; } /** * 获取当前用户填制单位 * * @return * @throws Exception */ public Map getFillOrg(String demId) throws Exception { CommonResult result = uCFeignService.getFillOrg(demId, ""); Map org = null; if (result.getState()) { JsonNode orgNode = (JsonNode) result.getValue(); if (orgNode.has("id")) { org = new HashMap(); org.put("id", orgNode.get("id").asText()); org.put("code", orgNode.get("code").asText()); org.put("name", orgNode.get("name").asText()); } } if (BeanUtils.isEmpty(org)) { throw new RuntimeException("获取当前填制单位失败!"); } return org; } /** * 获取当前用户主岗位内容 * * @return */ public String getMainPostName(String fileName) { ObjectNode orgRels = getMainPost(); if (BeanUtils.isNotEmpty(orgRels) && orgRels.has(fileName)) { return orgRels.get(fileName).asText(); } return ""; } /** * 获取当前用户主岗位名称 */ public String getCurrentMainPostName() { return getMainPostName("name"); } /** * 获取当前用户主岗位ID */ public String getCurrentMainPostId() { return getMainPostName("id"); } /** * 获取当前用户主岗位编码 */ public String getCurrentMainPostCode() { return getMainPostName("code"); } private ObjectNode getMainPost() { List orgRels = uCFeignService.getPosListByAccount(ContextUtil.getCurrentUser().getAccount()); ObjectNode orgRel = null; if (BeanUtils.isNotEmpty(orgRels)) { for (ObjectNode post : orgRels) { if (1 == (post.get("isMaster").asInt())) { orgRel = post; break; } } if (orgRels.size() == 1 && BeanUtils.isEmpty(orgRel)) { orgRel = orgRels.get(0); } } return orgRel; } public String getString(Object object) { if (BeanUtils.isNotEmpty(object)) { if (object instanceof LocalDateTime) { return DateFormatUtil.formaDatetTime((LocalDateTime) object); } return object.toString(); } return ""; } public IUser getUser(String userId) throws IOException { return userServiceImpl.getUserById(userId); } public List> querySql(String datasourceAlias, String sql) { List> maps = databaseContext.switchDS(datasourceAlias, () -> commonManager.query(sql), e -> { throw new BaseException(e.getMessage()); }); return maps; } public void executeSql(String datasourceAlias, String sql) { databaseContext.switchDS(datasourceAlias, () -> commonManager.execute(sql), e -> { throw new BaseException(e.getMessage()); }); } public String executeSql(String sql) { if (StringUtil.isEmpty(sql)) { throw new BaseException("sql不能为空"); } JdbcTemplate jdbcTemplate = (JdbcTemplate) AppUtil.getBean("jdbcTemplate"); if (sql.contains("<#id#>")) { try { ActionCmd cmd = ContextThreadUtil.getActionCmd(); if (BeanUtils.isNotEmpty(cmd) && StringUtil.isNotEmpty(cmd.getInstId())) { JsonNode node = JsonUtil.toJsonNode(cmd.getBusData()); if (node.fields().hasNext()) { JsonNode boData = node.fields().next().getValue(); if (BeanUtils.isNotEmpty(boData) && BeanUtils.isNotEmpty(boData.get("id_"))) { sql = sql.replace("<#id#>", boData.get("id_").asText()); } } } } catch (Exception e) { throw new BaseException("表单数据获取失败"); } } try { if (StringUtil.isEmpty(sql)) return ""; if (isProcedure(sql)) { //执行存储过程 executeSqlForUpdate(sql, jdbcTemplate); return ""; } else { sql = sql.replaceAll("''", "'"); List list = jdbcTemplate.queryForList(sql, String.class); if (list != null && list.size() > 0) { return list.get(0); } else { return ""; } } } catch (Exception e) { //e.printStackTrace(); //return "请检查sql 语句是否正确"; throw new BaseException("请检查sql语句是否正确"); } } /** * 判断是否是执行存储过程 */ private boolean isProcedure(String sql) { sql = sql.trim().replace("\'", ""); if (StringUtil.isEmpty(sql)) { return false; } sql = sql.toUpperCase(); return sql.startsWith("CALL") || sql.startsWith("BEGIN"); } /** * 执行存储过程 */ private void executeSqlForUpdate(String sql, JdbcTemplate jdbcTemplate) { jdbcTemplate.setQueryTimeout(30); jdbcTemplate.execute(sql); } /** * 判断当前用户是否有该角色 */ public boolean isCurrentInRole(String roleAlias) { return isUserInRole(ContextUtil.getCurrentUser().getAccount(), roleAlias); } /** * 根据别名执行服务 * * @param data */ public void executeServiceJob(String data) throws Exception { if (StringUtil.isNotEmpty(data)) { ActionCmd cmd = ContextThreadUtil.getActionCmd(); Map vars = cmd.getVariables(); String instId = cmd.getInstId(); DefaultBpmProcessInstance instance = bpmProcessInstanceManager.get(instId); if (BeanUtils.isNotEmpty(instance)) { List oldBoDatas = boDataService.getDataByInst(instance); if (BeanUtils.isEmpty(oldBoDatas)) { throw new RuntimeException(String.format("根据实例id:%s未查找到表单数据", instId)); } BpmDelegateTask delegateTask = null; DefaultBpmTask bpmTask = null; if (BeanUtils.isNotEmpty(cmd.getTransitVars(BpmConstants.BPM_TASK))) { bpmTask = (DefaultBpmTask) cmd.getTransitVars(BpmConstants.BPM_TASK); if (BeanUtils.isNotEmpty(bpmTask)) { //流程引擎任务 if (StringUtil.isNotZeroEmpty(bpmTask.getTaskId())) { delegateTask = natTaskService.getByTaskId(bpmTask.getTaskId()); } } } ObjectNode jsonObject = BoDataUtil.hanlerData(instance, "", oldBoDatas); JsonNode jsonNode = JsonUtil.toJsonNode(data); if (jsonNode.isArray()) { ArrayNode excutorAry = (ArrayNode) jsonNode; for (JsonNode item : excutorAry) { Boolean isSuccess = true; try { //别名 String alias = item.get("alias").asText(); ArrayNode inputAry = (ArrayNode) item.get("inputs"); for (JsonNode input : inputAry) { ObjectNode objectNode = (ObjectNode) input; if (BeanUtils.isNotEmpty(objectNode.get("value"))) { String value = objectNode.get("value").asText(); if (value.contains(".")) { //表单变量 String[] obj = value.split("\\."); if (obj.length > 0) { String defCode = obj[0]; String field = obj[1]; Iterator> iterator = jsonObject.fields(); while (iterator.hasNext()) { Entry next = iterator.next(); String objKey = next.getKey(); ObjectNode ywdxObj = (ObjectNode) next.getValue(); if (objKey.equals(defCode) && BeanUtils.isNotEmpty(ywdxObj)) { if (BeanUtils.isNotEmpty(ywdxObj.get(field))) { objectNode.set("value", ywdxObj.get(field)); } } } } } else { if (BeanUtils.isNotEmpty(vars.get(value))) { objectNode.set("value", JsonUtil.toJsonNode(vars.get(value))); } } } } //调用接口 String paramData = JsonUtil.toJsonString(inputAry); String type = item.get("type").asText(); Object result = null; if ("interface".equals(type)) { //接口管理 result = portalFeignService.executeIntefaceJob(alias, null, null, paramData); } else if ("service".equals(type)) { //服务编排 result = portalFeignService.executeServiceJob(alias, paramData); } if (BeanUtils.isNotEmpty(result)) { JsonNode resultNode = JsonUtil.toJsonNode(result); ArrayNode outputAry = (ArrayNode) item.get("outputs"); for (JsonNode output : outputAry) { String key = output.get("key").asText(); if (BeanUtils.isNotEmpty(output.get("value"))) { Object keyData = null; if (resultNode.isArray()) { ArrayNode resultAry = (ArrayNode) resultNode; for (JsonNode execute : resultAry) { if (BeanUtils.isNotEmpty(execute.get(key))) { keyData = execute.get(key); break; } } } else { if (BeanUtils.isNotEmpty(resultNode.get(key))) { keyData = resultNode.get(key); } } String value = output.get("value").asText(); if (value.contains(".")) { //表单变量 String[] obj = value.split("\\."); if (obj.length > 0) { String defCode = obj[0]; String field = obj[1]; Iterator> iterator = jsonObject.fields(); while (iterator.hasNext()) { Entry next = iterator.next(); String objKey = next.getKey(); ObjectNode ywdxObj = (ObjectNode) next.getValue(); if (objKey.equals(defCode) && BeanUtils.isNotEmpty(ywdxObj)) { if (BeanUtils.isNotEmpty(ywdxObj.get(field))) { if (BeanUtils.isNotEmpty(keyData)) { ywdxObj.set(field, JsonUtil.toJsonNode(keyData)); } } } } } } else { //流程变量 if (vars.containsKey(value) && BeanUtils.isNotEmpty(keyData)) { if (BeanUtils.isNotEmpty(delegateTask)) { delegateTask.setVariable(value, JsonUtil.toJsonNode(keyData)); } } } } } //更新表单数据 BusDataUtil.updateBoData(instance, "", JsonUtil.toJson(jsonObject)); cmd.setBusData(JsonUtil.toJson(jsonObject)); buildServiceLog(isSuccess, item, instance, bpmTask, JsonUtil.toJsonString(result)); } else { //保存调用日志 isSuccess = false; buildServiceLog(isSuccess, item, instance, bpmTask, null); } } catch (Exception e) { //保存调用日志 isSuccess = false; String response = ExceptionUtils.getRootCauseMessage(e); buildServiceLog(isSuccess, item, instance, bpmTask, response); } } } } else { //没有获取到流程实例id,代表流程已经启动但是表单节点的数据还没有保存到实例表和表单数据表中,此时可以操作cmd修改开始节点下一个节点的数据 JsonNode jsonNode = JsonUtil.toJsonNode(data); if (jsonNode.isArray()) { ArrayNode excutorAry = (ArrayNode) jsonNode; for (JsonNode item : excutorAry) { Boolean isSuccess = true; try { //别名 String alias = item.get("alias").asText(); ArrayNode inputAry = (ArrayNode) item.get("inputs"); JsonNode busDataNode = JsonUtil.toJsonNode(cmd.getBusData()); for (JsonNode input : inputAry) { ObjectNode objectNode = (ObjectNode) input; if (BeanUtils.isNotEmpty(objectNode.get("value"))) { String value = objectNode.get("value").asText(); if (value.contains(".")) { //表单变量 String[] obj = value.split("\\."); if (obj.length > 0) { String defCode = obj[0]; String field = obj[1]; objectNode.set("value", busDataNode.get(defCode).get(field)); } } else { if (BeanUtils.isNotEmpty(vars.get(value))) { objectNode.set("value", JsonUtil.toJsonNode(vars.get(value))); } } } } //调用接口 String paramData = JsonUtil.toJsonString(inputAry); String type = item.get("type").asText(); Object result = null; if ("interface".equals(type)) { //接口管理 result = portalFeignService.executeIntefaceJob(alias, null, null, paramData); } else if ("service".equals(type)) { //服务编排 result = portalFeignService.executeServiceJob(alias, paramData); } if (BeanUtils.isNotEmpty(result)) { JsonNode resultNode = JsonUtil.toJsonNode(result); ArrayNode outputAry = (ArrayNode) item.get("outputs"); for (JsonNode output : outputAry) { String key = output.get("key").asText(); if (BeanUtils.isNotEmpty(output.get("value"))) { Object keyData = null; if (resultNode.isArray()) { ArrayNode resultAry = (ArrayNode) resultNode; for (JsonNode execute : resultAry) { if (BeanUtils.isNotEmpty(execute.get(key))) { keyData = execute.get(key); break; } } } else { if (BeanUtils.isNotEmpty(resultNode.get(key))) { keyData = resultNode.get(key); } } String value = output.get("value").asText(); if (value.contains(".")) { //表单变量 String[] obj = value.split("\\."); if (obj.length > 0) { String defCode = obj[0]; String field = obj[1]; ObjectNode node = (ObjectNode) busDataNode.get(defCode); node.set(field, JsonUtil.toJsonNode(keyData)); } } else { //流程变量 if (vars.containsKey(value) && BeanUtils.isNotEmpty(keyData)) { if (BeanUtils.isNotEmpty(vars)) { vars.put(value, JsonUtil.toJsonNode(keyData)); } } } } } //更新表单数据 cmd.setBusData(JsonUtil.toJson(busDataNode)); } else { //保存调用日志 isSuccess = false; buildServiceLog(isSuccess, item, instance, null, null); } } catch (Exception e) { //保存调用日志 isSuccess = false; String response = ExceptionUtils.getRootCauseMessage(e); buildServiceLog(isSuccess, item, instance, null, response); } } } } } } /** * 保存调用日志 * * @param isSuccess * @param item * @param instance * @param bpmTask * @param response */ private void buildServiceLog(Boolean isSuccess, JsonNode item, DefaultBpmProcessInstance instance, DefaultBpmTask bpmTask, String response) throws Exception { IUser user = ContextUtil.getCurrentUser(); String alias = item.get("alias").asText(); String type = item.get("type").asText(); //构建日志参数 ObjectNode objectNode = JsonUtil.getMapper().createObjectNode(); objectNode.put("isSuccess", isSuccess ? "1" : "0"); objectNode.put("alias", alias); objectNode.put("type", type); if (instance != null) { objectNode.put("subject", instance.getSubject()); objectNode.put("procDefId", instance.getProcDefId()); objectNode.put("procDefKey", instance.getProcDefKey()); objectNode.put("procInstId", instance.getId()); //流程定义 DefaultBpmDefinition bpmDefinition = bpmDefinitionManager.getById(instance.getProcDefId()); if (BeanUtils.isNotEmpty(bpmDefinition)) { objectNode.put("procDefName", bpmDefinition.getName()); } } //任务相关参数 if (BeanUtils.isNotEmpty(bpmTask)) { objectNode.put("taskId", bpmTask.getId()); objectNode.put("nodeId", bpmTask.getNodeId()); } //调用人 objectNode.put("userId", user.getUserId()); objectNode.put("userAccount", user.getAccount()); objectNode.put("userName", user.getFullname()); //调用时间 objectNode.putPOJO("callTime", DateUtil.getCurrentDate()); //调用结果 objectNode.put("response", response); portalFeignService.saveServiceLog(objectNode); } @Cacheable(value = CacheKeyConst.EIP_UC_CURRENT_USER_GROUP_ID, key = "#userId", firstCache = @FirstCache(expireTime = 100, timeUnit = TimeUnit.DAYS)) public String getCurrentGroupIdFromCache(String userId) { return null; } /** * 判断子表中某一行满足某个条件, 默认为false */ public boolean subFieldContain(JsonNode subArray, String field, String op, Object value, String dataType) { return SubCalcUtils.subFieldContain(subArray, field, op, value, dataType); } /** * 判断子表中是否存在某一行不满足条件的 */ public boolean subFieldNotContain(JsonNode subArray, String field, String op, Object value, String dateType) { return SubCalcUtils.subFieldNotContain(subArray, field, op, value, dateType); } /** * 转换数据拼接sql * * @return * @throws Exception */ public String getSql(String names) throws Exception { StringBuilder sb = new StringBuilder("("); if (StringUtils.isNotBlank(names)) { String[] split = names.split(","); for (int i = 0; i < split.length; i++) { String s = split[i]; sb.append("'").append(s).append("'"); if (i != split.length - 1) { sb.append(","); } } sb.append(")"); return sb.toString(); } return ""; } //获取指定用户当前所属组织 public ArrayList getCurrentOrg(String account){ ArrayList orgIds = new ArrayList(); ObjectNode listOrgs = uCFeignService.getUserParamByCode(account, UserParamsEnums.dqzz.getCode()); if (BeanUtils.isNotEmpty(listOrgs)) { orgIds.add(listOrgs.get("value").asText()); } return orgIds; } //当前登陆用户的ID private static final String LOGIN_USER = "loginUser"; //当前登陆用户所属组织的ID private static final String LOGIN_USER_ORGS = "loginUserOrgs"; //当前登陆用户所属组织及下属组织的ID private static final String LOGIN_USER_SUB_ORGS = "loginUserSubOrgs"; //当前登陆用户所属组织及所有下属组织的ID private static final String LOGIN_USER_ALL_SUB_ORGS = "loginUserAllSubOrgs"; //当前登录用户所在组织 所有上下 组织id private static final String LOGIN_USER_ALL_ORGS = "loginUserAllOrgs"; //当前登陆用户 当前所在组织 private static final String LOGIN_USER_CURORGS = "loginUserCurOrgs"; //当前登陆用户 当前所在组织及下属组织的ID private static final String LOGIN_USER_SUB_CURORGS = "loginUserSubCurOrgs"; public ArrayList getDataPermission(String type) { ArrayList orgIds = new ArrayList(); IUser currentUser = ContextUtil.getCurrentUser(); if (BeanUtils.isNotEmpty(type)) { if (LOGIN_USER.equals(type)) { orgIds.add(currentUser.getUserId()); } else if (LOGIN_USER_ORGS.equals(type)) { String currentUserOrgIds = currentUser.getAttrbuite("CURRENT_USER_ORGIDS"); if (StringUtil.isNotEmpty(currentUserOrgIds)) { String[] oids = currentUserOrgIds.split(","); Set oidSet = new HashSet(Arrays.asList(oids)); orgIds.addAll(oidSet); } } else if (LOGIN_USER_SUB_ORGS.equals(type)) { String currentUserSubOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserSubOrgIds()) ? AuthenticationUtil.getCurrentUserSubOrgIds() : ""; String currentUserOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserOrgIds()) ? AuthenticationUtil.getCurrentUserOrgIds() : ""; currentUserSubOrgIds += "," + currentUserOrgIds; String[] oids = new String[]{}; if (StringUtil.isNotEmpty(currentUserSubOrgIds)) { oids = currentUserSubOrgIds.split(","); } if (oids.length == 0) { oids = new String[]{"-1"}; } Set oidSet = new HashSet(Arrays.asList(oids)); orgIds.addAll(oidSet); } else if (LOGIN_USER_ALL_SUB_ORGS.equals(type)) { String currentUserSubOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserSubOrgIds()) ? AuthenticationUtil.getCurrentUserSubOrgIds() : ""; String currentUserOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserOrgIds()) ? AuthenticationUtil.getCurrentUserOrgIds() : ""; currentUserSubOrgIds += "," + currentUserOrgIds; String[] oids = new String[]{}; if (StringUtil.isNotEmpty(currentUserSubOrgIds)) { oids = currentUserSubOrgIds.split(","); } if (oids.length == 0) { oids = new String[]{"-1"}; } Set oidSet = new HashSet<>(Arrays.asList(oids)); orgIds.addAll(oidSet); } else if (LOGIN_USER_ALL_ORGS.equals(type)) { ArrayNode department = uCFeignService.getOrgListByUserId(getCurrentUserId()); for (JsonNode node : department) { //所有上级组织 ObjectNode dept = (ObjectNode) node; String id = dept.get("id").asText(); String path = dept.get("path").asText(); String[] pathlist = path.split("\\."); Set oidSet1 = new HashSet<>(Arrays.asList(pathlist)); orgIds.addAll(oidSet1); //所有下级组织 // String currentUserSubOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserSubOrgIds()) ? AuthenticationUtil.getCurrentUserSubOrgIds() : ""; // String currentUserOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserOrgIds()) ? AuthenticationUtil.getCurrentUserOrgIds() : ""; // currentUserSubOrgIds += "," + currentUserOrgIds; // String[] oids = new String[]{}; // if (StringUtil.isNotEmpty(currentUserSubOrgIds)) { // oids = currentUserSubOrgIds.split(","); // } // if (oids.length == 0) { // oids = new String[]{"-1"}; // } // Set oidSet = new HashSet<>(Arrays.asList(oids)); Set oidSet = new HashSet<>(); List orgsByparentId = uCFeignService.getChildOrg(id);//从数据库取下属组织数据,解决缓存中的组织不全问题 if (ObjectUtil.isNotEmpty(orgsByparentId)) { for (ObjectNode jsonNodes : orgsByparentId) { oidSet.add(jsonNodes.get("id").asText()); } } String currentUserOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserOrgIds()) ? AuthenticationUtil.getCurrentUserOrgIds() : ""; if (ObjectUtil.isNotEmpty(currentUserOrgIds)) { oidSet.add(currentUserOrgIds); } orgIds.addAll(oidSet); } } else if (LOGIN_USER_CURORGS.equals(type)) { //当前登陆用户 当前所在组织 ObjectNode listOrgs = uCFeignService.getUserParamByCode(currentUser.getAccount(), UserParamsEnums.dqzz.getCode()); if (BeanUtils.isNotEmpty(listOrgs)) { orgIds.add(listOrgs.get("value").asText()); } }else if (LOGIN_USER_SUB_CURORGS.equals(type)){ ObjectNode listOrgs = uCFeignService.getUserParamByCode(currentUser.getAccount(), UserParamsEnums.dqzz.getCode()); if (BeanUtils.isNotEmpty(listOrgs)) { orgIds.add(listOrgs.get("value").asText()); List value = uCFeignService.getChildOrg(listOrgs.get("value").asText()); if (BeanUtils.isNotEmpty(value)) { for (ObjectNode org : value) { orgIds.add(org.get("id").asText()); } } } } } return orgIds; } }