From a691c6def9070993347f41a922eef850e3cf1bb4 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Mon, 17 Apr 2023 22:47:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=BE=E5=AD=97=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../youhong.ai/deerge/workflow_code_block.js | 114 + .../aiyh/utils/action/SafeCusBaseAction.java | 10 +- .../utils/action/mapper/SafeActionMapper.java | 20 + .../impl/RequestLogShowOrHiddenImpl.java | 1 - .../mapper/InterceptRequestLogMapper.java | 9 +- .../util/PrivacyRequestLogUtil.java | 93 +- .../biz/requestForm/RequestRemindBiz.java | 2186 +++++++++++++++++ .../ai/taibao/email/BlackListExpansion.java | 21 + .../ai/taibao/email/BlackListRegister.java | 38 + .../email/impl/InitBlackListServiceImpl.java | 64 + .../mapper/InitBlackEmailListMapper.java | 44 + .../config/enumtype/GetValueTypeEnum.java | 74 +- .../commons/config/mapper/DealWithMapper.java | 21 + .../config/service/DealWithMapping.java | 35 +- .../sapdocking/VoucherPayableAction.java | 14 +- .../sapdocking/VoucherPayableNewAction.java | 246 ++ .../youhong/ai/haripijiu/TestHaRiPiJiu.java | 5 +- src/test/java/youhong/ai/pcn/UtilTest.java | 4 + .../java/youhong/ai/taibao/TestTaiBao.java | 11 + .../java/youhong/ai/utiltest/GenericTest.java | 8 + 20 files changed, 2944 insertions(+), 74 deletions(-) create mode 100644 javascript/youhong.ai/deerge/workflow_code_block.js create mode 100644 src/main/java/aiyh/utils/action/mapper/SafeActionMapper.java create mode 100644 src/main/java/com/engine/workflow/biz/requestForm/RequestRemindBiz.java create mode 100644 src/main/java/com/engine/youhong/ai/taibao/email/BlackListExpansion.java create mode 100644 src/main/java/com/engine/youhong/ai/taibao/email/BlackListRegister.java create mode 100644 src/main/java/com/engine/youhong/ai/taibao/email/impl/InitBlackListServiceImpl.java create mode 100644 src/main/java/com/engine/youhong/ai/taibao/email/mapper/InitBlackEmailListMapper.java create mode 100644 src/main/java/weaver/xiao/commons/config/mapper/DealWithMapper.java create mode 100644 src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/VoucherPayableNewAction.java diff --git a/javascript/youhong.ai/deerge/workflow_code_block.js b/javascript/youhong.ai/deerge/workflow_code_block.js new file mode 100644 index 0000000..e663aeb --- /dev/null +++ b/javascript/youhong.ai/deerge/workflow_code_block.js @@ -0,0 +1,114 @@ +/* ******************* 德尔格 明细物料历史数据折扣带出提示 by youhong.ai ******************* */ +$(() => { + let type = { + // 等于 + equalTo: (value, target) => value == target, + // 不等于 + notEqual: (value, target) => value != target, + // 大于 + greaterThan: (value, target) => +value > +target, + // 小于 + lessThan: (value, target) => +value < +target + } + // 值类型 + let valueType = { + // 固定值 + fixValue: 0, + // 流程字段 + field: 1 + } + let config = { + // 主表,填main + table: 'main', + // 明细表,明细1为detail_1,明细2为detail_2 + detail: 'detail_1', + redField: 'zk', + // 条件集合 + conditions: [{ + // 所属表 + table: 'detail_1', + // 字段 + field: 'wllx', + // 对比值 + value: 0, + // 值的类型 + valueType: valueType.fixValue, + // 值字段所在表 + valueTable: '', + // 条件类型 + type: type.equalTo + }, { + // 所属表 + table: 'detail_1', + // 字段 + field: 'zkdc', + // 对比值 + value: 'zk', + // 值的类型 + valueType: valueType.field, + // 值字段所在表 + valueTable: 'detail_1', + // 条件类型 + type: type.notEqual + }] + } + + runJs() + + function runJs() { + let detailAllRowIndexStr = WfForm.getDetailAllRowIndexStr(config.detail); + let rowIndexArr = detailAllRowIndexStr.split(","); + let flag = true + rowIndexArr.forEach(rowIndex => { + if (flag) { + flag = isTrue(rowIndex) + } else { + isTrue(rowIndex) + } + }) + if (!flag) { + WfForm.showConfirm("当前订单折扣不等于默认折扣"); + } + } + + + function isTrue(rowIndex) { + let flag = true + for (let i = 0; i < config.conditions.length; i++) { + let item = config.conditions[i] + let fieldId = WfForm.convertFieldNameToId(config, item.table) + let fieldMark = `${fieldId}_${rowIndex}` + let fieldValue = WfForm.getFieldValue(fieldMark) + if (item.valueType == valueType.fixValue) { + if (item.type(fieldValue, item.value)) { + continue + } + renderRed(`${WfForm.convertFieldNameToId(config.redField, config.detail)}_${rowIndex}`) + flag = false + } + if (item.valueType == valueType.field) { + if (item.type(fieldValue, WfForm.getFieldValue(item.value, item.valueTable))) { + continue + } + renderRed(`${WfForm.convertFieldNameToId(config.redField, config.detail)}_${rowIndex}`) + flag = false + } + } + return flag + } + + function renderRed(fieldMark) { + $(`#oTable0 .detail_odd_row.detail_data_row div[data-fieldmark='${fieldMark}'] .wf-form-input`).css({ + color: '#FFF', + background: 'red', + }) + $(`#oTable0 .detail_odd_row.detail_data_row div[data-fieldmark='${fieldMark}'] .wf-form-input input`).css({ + 'border-color': 'red', + background: 'red', + color: '#FFF' + }) + } +}) + +/* ******************* 德尔格 明细物料历史数据折扣带出提示 end ******************* */ + diff --git a/src/main/java/aiyh/utils/action/SafeCusBaseAction.java b/src/main/java/aiyh/utils/action/SafeCusBaseAction.java index 4812e87..dbf0b05 100644 --- a/src/main/java/aiyh/utils/action/SafeCusBaseAction.java +++ b/src/main/java/aiyh/utils/action/SafeCusBaseAction.java @@ -1,6 +1,7 @@ package aiyh.utils.action; import aiyh.utils.Util; +import aiyh.utils.action.mapper.SafeActionMapper; import aiyh.utils.excention.CustomerException; import com.google.common.base.Strings; import org.apache.log4j.Logger; @@ -29,6 +30,8 @@ public abstract class SafeCusBaseAction implements Action { protected final Logger log = Util.getLogger(); private final Map actionHandleMethod = new HashMap<>(); + private final SafeActionMapper mapper = Util.getMapper(SafeActionMapper.class); + /** *

初始化流程默认的处理方法

*/ @@ -191,7 +194,12 @@ public abstract class SafeCusBaseAction implements Action { protected Map getMainTableValue(RequestInfo requestInfo) { // 获取主表数据 Property[] propertyArr = requestInfo.getMainTableInfo().getProperty(); - return getStringMap(propertyArr); + Map result = getStringMap(propertyArr); + RequestManager requestManager = requestInfo.getRequestManager(); + String billTable = requestManager.getBillTableName(); + String id = mapper.selectIdByRequest(billTable, requestInfo.getRequestid()); + result.put("id", id); + return result; } @NotNull diff --git a/src/main/java/aiyh/utils/action/mapper/SafeActionMapper.java b/src/main/java/aiyh/utils/action/mapper/SafeActionMapper.java new file mode 100644 index 0000000..26956c9 --- /dev/null +++ b/src/main/java/aiyh/utils/action/mapper/SafeActionMapper.java @@ -0,0 +1,20 @@ +package aiyh.utils.action.mapper; + +import aiyh.utils.annotation.recordset.ParamMapper; +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; + +/** + *

+ * + *

create: 2023/4/17 17:47

+ * + * @author youHong.ai + */ +@SqlMapper +public interface SafeActionMapper { + + @Select("select id from $t{billTable} where requestid = #{requestId}") + String selectIdByRequest(@ParamMapper("billTable") String billTable, + @ParamMapper("requestId") String requestId); +} diff --git a/src/main/java/com/customization/youhong/deerge/requestlog/impl/RequestLogShowOrHiddenImpl.java b/src/main/java/com/customization/youhong/deerge/requestlog/impl/RequestLogShowOrHiddenImpl.java index b0f6be4..5516037 100644 --- a/src/main/java/com/customization/youhong/deerge/requestlog/impl/RequestLogShowOrHiddenImpl.java +++ b/src/main/java/com/customization/youhong/deerge/requestlog/impl/RequestLogShowOrHiddenImpl.java @@ -38,7 +38,6 @@ public class RequestLogShowOrHiddenImpl extends AbstractServiceProxy implements Logger log = Util.getLogger(); try { privacyRequestLogUtil.requestLogList(result, params, request); - log.info("最终的返回结果: " + JSON.toJSONString(result)); } catch (Exception e) { log.error("filter request log list error!" + Util.getErrString(e)); } diff --git a/src/main/java/com/customization/youhong/deerge/requestlog/mapper/InterceptRequestLogMapper.java b/src/main/java/com/customization/youhong/deerge/requestlog/mapper/InterceptRequestLogMapper.java index f367c08..902a088 100644 --- a/src/main/java/com/customization/youhong/deerge/requestlog/mapper/InterceptRequestLogMapper.java +++ b/src/main/java/com/customization/youhong/deerge/requestlog/mapper/InterceptRequestLogMapper.java @@ -4,6 +4,7 @@ import aiyh.utils.annotation.recordset.*; import com.customization.youhong.deerge.requestlog.pojo.RequestLogPrivacyEntity; import java.util.List; +import java.util.Map; /** *

拦截签字意见隐私处理

@@ -24,11 +25,11 @@ public interface InterceptRequestLogMapper { * @param operator 操作者 * @return 签字意见id */ - @Select("select logid from workflow_requestlog where REQUESTID = #{requestId} " + + @Select("select logid,operatetime from workflow_requestlog where REQUESTID = #{requestId} " + "and NODEID = #{nodeId} and OPERATOR = #{operator} order by LOGID desc ") - Integer selectRequestLogId(@ParamMapper("requestId") String requestId, - @ParamMapper("nodeId") String nodeId, - @ParamMapper("operator") String operator); + List> selectRequestLogId(@ParamMapper("requestId") String requestId, + @ParamMapper("nodeId") String nodeId, + @ParamMapper("operator") String operator); /** *

更新隐私信息

diff --git a/src/main/java/com/customization/youhong/deerge/requestlog/util/PrivacyRequestLogUtil.java b/src/main/java/com/customization/youhong/deerge/requestlog/util/PrivacyRequestLogUtil.java index 99168e2..9fa1c99 100644 --- a/src/main/java/com/customization/youhong/deerge/requestlog/util/PrivacyRequestLogUtil.java +++ b/src/main/java/com/customization/youhong/deerge/requestlog/util/PrivacyRequestLogUtil.java @@ -12,10 +12,7 @@ import weaver.hrm.HrmUserVarify; import weaver.hrm.User; import javax.servlet.http.HttpServletRequest; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -58,10 +55,29 @@ public class PrivacyRequestLogUtil { } logger.info("添加隐私按钮!未开启隐私"); // 未开启隐私,更新签字意见隐私信息为不隐私 - Integer logId = mapper.selectRequestLogId(requestId, nodeId, userId); - if (logId > 0) { - mapper.updateRequestLogStatus(logId, userId, nodeId, requestId, "0"); + List> nodeIdMapList = mapper.selectRequestLogId(requestId, nodeId, userId); + logger.info("查询的log日志列表:" + nodeIdMapList); + if (CollectionUtil.isEmpty(nodeIdMapList)) { + return; } + Map firstLog = nodeIdMapList.get(0); + String operateTime = Util.null2String(firstLog.get("operatetime")); + List logList = new ArrayList<>(); + for (Map item : nodeIdMapList) { + String itemOperateTime = Util.null2String(item.get("operatetime")); + int logId = Integer.parseInt(Util.null2String(item.get("logid"))); + if (operateTime.equals(itemOperateTime)) { + logList.add(logId); + } else { + break; + } + } + for (Integer logId : logList) { + if (logId > 0) { + mapper.updateRequestLogStatus(logId, userId, nodeId, requestId, "0"); + } + } + } /** @@ -74,26 +90,45 @@ public class PrivacyRequestLogUtil { * @param enablePrivacy 是否开启隐私 */ private void insertRequestPrivacyLog(String userId, String nodeId, String requestId, String field5, String enablePrivacy) { - Integer logId = mapper.selectRequestLogId(requestId, nodeId, userId); Logger logger = Util.getLogger(); - logger.info("查询到的logId是:" + logId); - if (logId <= 0) { - throw new CustomerException("request log id query error!\n"); + + List> nodeIdMapList = mapper.selectRequestLogId(requestId, nodeId, userId); + logger.info("查询的log日志列表:" + nodeIdMapList); + if (CollectionUtil.isEmpty(nodeIdMapList)) { + return; } - Integer dataId = mapper.selectRequestLogDataId(requestId, nodeId, userId, String.valueOf(logId)); - logger.info("查询到的数据id是:" + logId); - if (dataId <= 0) { - // 插入logId隐私信息 - dataId = Util.getModeDataId("uf_privacy_log_info", 1); + Map firstLog = nodeIdMapList.get(0); + String operateTime = Util.null2String(firstLog.get("operatetime")); + List logList = new ArrayList<>(); + for (Map item : nodeIdMapList) { + String itemOperateTime = Util.null2String(item.get("operatetime")); + int logId = Integer.parseInt(Util.null2String(item.get("logid"))); + if (operateTime.equals(itemOperateTime)) { + logList.add(logId); + } else { + break; + } } - Boolean flag = mapper.insertPrivacyLog(dataId, logId, userId, nodeId, requestId, field5, enablePrivacy); - if (!flag) { - logger.info("更新失败签字意见隐私信息失败!"); - Util.deleteModeId("uf_privacy_log_info", dataId); - } else { - Util.rebuildModeDataShare(1, - Integer.parseInt(Util.getModeIdByTableName("uf_privacy_log_info")), - dataId); + for (Integer logId : logList) { + logger.info("查询到的logId是:" + logId); + if (logId <= 0) { + throw new CustomerException("request log id query error!\n"); + } + Integer dataId = mapper.selectRequestLogDataId(requestId, nodeId, userId, String.valueOf(logId)); + logger.info("查询到的数据id是:" + logId); + if (dataId <= 0) { + // 插入logId隐私信息 + dataId = Util.getModeDataId("uf_privacy_log_info", 1); + } + Boolean flag = mapper.insertPrivacyLog(dataId, logId, userId, nodeId, requestId, field5, enablePrivacy); + if (!flag) { + logger.info("更新失败签字意见隐私信息失败!"); + Util.deleteModeId("uf_privacy_log_info", dataId); + } else { + Util.rebuildModeDataShare(1, + Integer.parseInt(Util.getModeIdByTableName("uf_privacy_log_info")), + dataId); + } } } @@ -120,8 +155,6 @@ public class PrivacyRequestLogUtil { } String[] split = targetHrm.split(","); List hrmIds = Arrays.asList(split); - logger.info("查询到hrmIds数据:" + JSON.toJSONString(hrmIds)); - logger.info("当前用户Id:" + userId); if (hrmIds.contains(userId)) { // 默认签字意见隐私 insertRequestPrivacyLog(userId, nodeId, requestId, field5, "1"); @@ -139,21 +172,17 @@ public class PrivacyRequestLogUtil { */ public void requestLogList(Map result, Map params, HttpServletRequest request) { - Logger logger = Util.getLogger(); String isMonitor = request.getParameter("ismonitor"); boolean isPrint = "1".equals(Util.null2String(request.getParameter("isprint"))); String requestId = Util.null2String(params.get("requestid")); User user = HrmUserVarify.getUser(request, null); - logger.info("结果: " + JSON.toJSONString(result)); if (isPrint) { // 打印 hiddenAll(result, requestId); - logger.info("最终的结果: " + JSON.toJSONString(result)); return; } // 是流程监控 if (!StrUtil.isBlank(isMonitor)) { - logger.info("流程监控最终的结果: " + JSON.toJSONString(result)); return; } @@ -163,7 +192,6 @@ public class PrivacyRequestLogUtil { if (CollectionUtil.isEmpty(privacyUserList)) { // 不存在签字意见组中,所有隐私信息不可查看 hiddenAll(result, requestId); - logger.info("不在隐私组最终的结果: " + JSON.toJSONString(result)); return; } // 查询非本组隐私的隐私信息 @@ -197,6 +225,7 @@ public class PrivacyRequestLogUtil { */ private static void hiddenContentOrHiddenLog(Map result, List> logList, List privacyLogIdList) { String showContent = Util.getCusConfigValueNullOrEmpty("REQUEST_LOG_SHOW_CONTENT", "false"); + String requestLogShowContentDefault = Util.getCusConfigValueNullOrEmpty("requestLogShowContentDefault", ""); if (!Boolean.parseBoolean(showContent)) { List> newLogList = logList.stream() .filter(item -> !privacyLogIdList.contains(Util.null2String(item.get("logid")))) @@ -207,7 +236,7 @@ public class PrivacyRequestLogUtil { List> newLogList = logList.stream() .peek(item -> { if (privacyLogIdList.contains(Util.null2String(item.get("logid")))) { - item.put("log_remarkHtml", ""); + item.put("log_remarkHtml", requestLogShowContentDefault); } }) .collect(Collectors.toList()); diff --git a/src/main/java/com/engine/workflow/biz/requestForm/RequestRemindBiz.java b/src/main/java/com/engine/workflow/biz/requestForm/RequestRemindBiz.java new file mode 100644 index 0000000..6f3df02 --- /dev/null +++ b/src/main/java/com/engine/workflow/biz/requestForm/RequestRemindBiz.java @@ -0,0 +1,2186 @@ +package com.engine.workflow.biz.requestForm; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.api.sms.util.SmsSendUtil; +import com.engine.common.biz.EncryptConfigBiz; +import com.engine.core.impl.CommandExecutorUtil; +import com.engine.email.biz.EmailApprovalService; +import com.engine.workflow.biz.freeNode.FreeNodeBiz; +import com.engine.workflow.cmd.requestForm.emailApprove.GetEmailApproveParamCmd; +import com.engine.workflow.cmd.requestForm.remind.GetEmailRemindUrlCmd; +import com.engine.workflow.constant.RemindTypeEnum; +import com.engine.workflow.util.GetCustomLevelUtil; +import com.engine.workflow.util.WfToDocUtil; +import com.engine.youhong.ai.taibao.email.BlackListExpansion; +import com.engine.youhong.ai.taibao.email.BlackListRegister; +import com.google.common.base.Strings; +import weaver.conn.RecordSet; +import weaver.email.EmailApprovalRunnable; +import weaver.email.EmailWorkRunnable; +import weaver.general.*; +import weaver.hrm.User; +import weaver.hrm.online.HrmUserOnlineMap; +import weaver.interfaces.workflow.browser.Browser; +import weaver.interfaces.workflow.browser.BrowserBean; +import weaver.sms.SMSSaveAndSend; +import weaver.sms.SmsFromMouldEnum; +import weaver.systeminfo.SystemEnv; +import weaver.workflow.logging.Logger; +import weaver.workflow.logging.LoggerFactory; +import weaver.workflow.request.RequestDoc; +import weaver.workflow.request.RequestManager; +import weaver.workflow.request.WFAutoApproveUtils; +import weaver.workflow.request.entity.RequestOperateEntityTableNameEnum; +import weaver.workflow.workflow.WFManager; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.*; + +/** + * @author jhush + * @desc 流程提醒 + * @date 2019/1/16 + */ +public class RequestRemindBiz { + + private final static Logger log = LoggerFactory.getLogger(RequestRemindBiz.class); + + public static final String SYSTEM_FIELD_LEVEL = "${fieldid_-2}"; + public static final String SYSTEM_FIELD_TITLE = "${fieldid_-3}"; + public static final String SYSTEM_FIELD_TITLE_LINK = "${fieldid_-3_link}"; + public static final String SYSTEM_FIELD_CREATEDATA = "${fieldid_-4}"; + public static final String SYSTEM_FIELD_APPROVE_BTN = "${fieldid_-5}"; + + public static final String APPROVE_PARAM_SIGN = "[ecParam]"; + public static final String APPROVE_PARAM = APPROVE_PARAM_SIGN + "%s" + APPROVE_PARAM_SIGN; + + + private User user; + + private String requestId; + private String wfId; + private String src; + private Map fieldDatas = null; + private Map> remindContent = null; + private Map> defaultRemindContent = null; + + public RequestRemindBiz() { + } + + public RequestRemindBiz(User user) { + if (user == null) user = new User(1); + this.user = user; + } + + public RequestRemindBiz(User user, int reqId, int wfId, String src) { + this(user); + this.requestId = String.valueOf(reqId); + this.wfId = String.valueOf(wfId); + this.src = src; + } + + /** + * 流程提醒 + * + * @param requestId + * @param wfId + * @param submitType + * @param remindType + * @param onLine + */ + public void requestRemind(int requestId, int wfId, String submitType, RemindTypeEnum remindType, int onLine) { + + Set currentNodeUser = this.getCurrentNodeUser(Util.null2String(requestId), onLine); + String remindUser = String.join(",", currentNodeUser); + this.printLog("2、rquestid: +" + requestId + ",userid:" + user.getUID() + ",user: " + remindUser); + + Map params = new HashMap<>(); + params.put("reminder", remindUser); + params.put("requestId", requestId); + params.put("workflowId", wfId); + params.put("submitType", submitType); + + if (remindType.getCode().equals(RemindTypeEnum.SMS.getCode())) this.requestRemind(params, RemindTypeEnum.SMS); + if (remindType.getCode().equals(RemindTypeEnum.EMAIL.getCode())) + this.requestRemind(params, RemindTypeEnum.EMAIL); + + } + + + /** + * 新创建的流程,给创建人发送提醒 + * + * @param requestId + * @param wfId + * @param submitType + * @param remindType + * @param onLine + */ + public void requestCreateRemind(int requestId, int wfId, String submitType, RemindTypeEnum remindType, int onLine) { + + Set userList = new HashSet<>(); + String sql = "select currentnodeid from workflow_requestbase where requestid = ? and currentnodetype=0"; + RecordSet rs = new RecordSet(); + rs.executeQuery(sql, requestId); + if (rs.next()) { + String currentnodeid = rs.getString(1); + sql = "select userid from workflow_currentoperator where requestid = ? and nodeid = ? and isremark in(0,1,4,6,7) "; + rs.executeQuery(sql, requestId, currentnodeid); + while (rs.next()) { + String userId = Util.null2String(rs.getString("userid")); + if (onLine == 1) { // 离线才发 + HrmUserOnlineMap hrmUserOnlineMap = HrmUserOnlineMap.getInstance(); + if (!hrmUserOnlineMap.isOnline(Util.getIntValue(userId))) { + userList.add(userId); + } + } else { + userList.add(userId); + } + } + String remindUser = String.join(",", userList); + + Map params = new HashMap<>(); + params.put("reminder", remindUser); + params.put("requestId", requestId); + params.put("workflowId", wfId); + params.put("submitType", submitType); + + if (remindType.getCode().equals(RemindTypeEnum.SMS.getCode())) + this.requestRemind(params, RemindTypeEnum.SMS); + if (remindType.getCode().equals(RemindTypeEnum.EMAIL.getCode())) + this.requestRemind(params, RemindTypeEnum.EMAIL); + } else { + new BaseBean().writeLog("当前流程不在创建节点requestId:" + requestId); + } + } + + /** + * 流程进入自动审批时,先提醒自动审批前当前节点上的抄送人 + * + * @param requestManager + */ + public void autoApproveCCRemind(int currentNodeId, RequestManager requestManager) { + + String requestId = String.valueOf(requestManager.getRequestid()); + + int wfId = requestManager.getWorkflowid(); + + RecordSet rs = new RecordSet(); + rs.executeQuery("select nodeid from workflow_requestoperatelog where requestid = ? and operatetype='submit' order by id desc", requestId); + if (rs.next()) { + int nodeId = Util.getIntValue(rs.getString(1)); + if (nodeId != currentNodeId) { + Set users = new HashSet<>(); + String sql = "select userid from workflow_currentoperator where requestid = ? and usertype = 0 and nodeid = ? and isremark in(8,9)"; + rs.executeQuery(sql, requestId, currentNodeId); + while (rs.next()) { + users.add(Util.null2String(rs.getString(1))); + } + + Map> defaultRemindContent = this.getDefaultRemindContent(); // 默认提醒内容 + Map fieldDatas = this.getFieldData(requestId); + + rs.executeQuery("select remindscope from workflow_base where id = ? ", wfId); + rs.next(); + int remindscope = Util.getIntValue(rs.getString("remindscope"), 0); + if (remindscope == 1) { + rs.executeQuery("select id,remindTypes,contenttype from wf_emailremind_set where workflowid = ? and nodeid = ? and ccNoRemind = 0", wfId, currentNodeId); + if (rs.next()) { + int id = rs.getInt(1); + String remindTypes = rs.getString(2); + int contenttype = rs.getInt(3); + String[] remindTypesArr = remindTypes.split(","); + for (String remindType : remindTypesArr) { + if (contenttype == 1) { + + String title = null; + String content = null; + int formData = 0; + int signData = 0; + int attachmentData = 0; + rs.executeQuery("select title,content,contentType,isformdata,issigndata,isattachmentdata from wf_emailremind_content " + + "where remindSetId = ? and remindType=? ", id, remindType); + while (rs.next()) { + String contentType = rs.getString(3); + if (contentType.equals(RemindTypeEnum.CC.getCode())) { + title = rs.getString(1); + content = rs.getString(2); + formData = Util.getIntValue(rs.getString(4), 0); + signData = Util.getIntValue(rs.getString(5), 0); + attachmentData = Util.getIntValue(rs.getString(6), 0); + } + } + + if (RemindTypeEnum.SMS.getCode().equals(remindType)) { + Map> contentMap = this.getRemindContent(String.valueOf(wfId), RemindTypeEnum.SMS.getCode()); + Map info = contentMap.get(RemindTypeEnum.CC.getCode()); + if (info == null) info = defaultRemindContent.get(RemindTypeEnum.CC.getCode()); + content = Strings.isNullOrEmpty(content) ? Util.null2String(info.get("content")) : content; + content = content.replace("_link", ""); // 默认内容中带有超链接字段 + content = Util.toHtmlMode(this.replaceFieldValue(fieldDatas, content)); + this.sendSMS(String.join(",", users), content, requestId); + } + if (RemindTypeEnum.EMAIL.getCode().equals(remindType)) { + Map> contentMap = this.getRemindContent(String.valueOf(wfId), RemindTypeEnum.EMAIL.getCode()); + Map info = contentMap.get(RemindTypeEnum.CC.getCode()); + if (info == null) info = defaultRemindContent.get(RemindTypeEnum.CC.getCode()); + title = Strings.isNullOrEmpty(title) ? Util.null2String(info.get("title")) : title; + content = Strings.isNullOrEmpty(content) ? Util.null2String(info.get("content")) : content; + Set allAttchment = new LinkedHashSet<>(); + if (formData == 1) { + allAttchment.add(this.getRequestFormPdf(requestId, signData, -1)); + } + if (attachmentData == 1) + allAttchment.addAll(this.getRequestAttachment(requestId, String.valueOf(wfId))); + + title = this.replaceFieldValue(fieldDatas, title); + content = this.replaceFieldValue(fieldDatas, content); + this.sendEmail(String.join(",", users), title, content, requestId, String.join(",", allAttchment)); + } + + } else { + if (RemindTypeEnum.SMS.getCode().equals(remindType)) { + Map> contentMap = this.getRemindContent(String.valueOf(wfId), RemindTypeEnum.SMS.getCode()); + Map info = contentMap.get(RemindTypeEnum.CC.getCode()); + if (info == null) info = defaultRemindContent.get(RemindTypeEnum.CC.getCode()); + String content = Util.null2String(info.get("content")); + content = content.replace("_link", ""); // 默认内容中带有超链接字段 + content = Util.toHtmlMode(this.replaceFieldValue(fieldDatas, content)); + this.sendSMS(String.join(",", users), content, requestId); + } + if (RemindTypeEnum.EMAIL.getCode().equals(remindType)) { + Map> contentMap = this.getRemindContent(String.valueOf(wfId), RemindTypeEnum.EMAIL.getCode()); + Map info = contentMap.get(RemindTypeEnum.CC.getCode()); + if (info == null) info = defaultRemindContent.get(RemindTypeEnum.CC.getCode()); + String title = Util.null2String(info.get("title")); + String content = Util.null2String(info.get("content")); + int formData = Util.getIntValue(Util.null2String(info.get("isFormData")), 0); + int signData = Util.getIntValue(Util.null2String(info.get("isSignData")), 0); + int attachmentData = Util.getIntValue(Util.null2String(info.get("isAttachmentData")), 0); + Set allAttchment = new LinkedHashSet<>(); + if (formData == 1) { + allAttchment.add(this.getRequestFormPdf(requestId, signData, -1)); + } + if (attachmentData == 1) + allAttchment.addAll(this.getRequestAttachment(requestId, String.valueOf(wfId))); + title = this.replaceFieldValue(fieldDatas, title); + content = this.replaceFieldValue(fieldDatas, content); + this.sendEmail(String.join(",", users), title, content, requestId, String.join(",", allAttchment)); + } + } + } + } + } else { + WFManager wfManager = getWfInfo(String.valueOf(wfId)); + boolean isCCNotRemind = "1".equals(wfManager.getIsCCNoRemind()); + if (!isCCNotRemind) { + + String defaultSmsRemind = wfManager.getIsDefaultSmsRemind(); + String defaultEmailRemind = wfManager.getIsDefaultEmailRemind(); + String mailMessageType = wfManager.getMailMessageType(); + String messageType = wfManager.getMessageType(); + + if ("1".equals(defaultSmsRemind) || "1".equals(messageType)) { + Map> contentMap = this.getRemindContent(String.valueOf(wfId), RemindTypeEnum.SMS.getCode()); + Map info = contentMap.get(RemindTypeEnum.CC.getCode()); + if (info == null) info = defaultRemindContent.get(RemindTypeEnum.CC.getCode()); + String content = Util.null2String(info.get("content")); + content = content.replace("_link", ""); // 默认内容中带有超链接字段 + content = Util.toHtmlMode(this.replaceFieldValue(fieldDatas, content)); + this.sendSMS(String.join(",", users), content, requestId); + } + if ("1".equals(defaultEmailRemind) || "1".equals(mailMessageType)) { + Map> contentMap = this.getRemindContent(String.valueOf(wfId), RemindTypeEnum.EMAIL.getCode()); + Map info = contentMap.get(RemindTypeEnum.CC.getCode()); + if (info == null) info = defaultRemindContent.get(RemindTypeEnum.CC.getCode()); + String title = Util.null2String(info.get("title")); + String content = Util.null2String(info.get("content")); + int formData = Util.getIntValue(Util.null2String(info.get("isFormData")), 0); + int signData = Util.getIntValue(Util.null2String(info.get("isSignData")), 0); + int attachmentData = Util.getIntValue(Util.null2String(info.get("isAttachmentData")), 0); + Set allAttchment = new LinkedHashSet<>(); + if (formData == 1) { + allAttchment.add(this.getRequestFormPdf(requestId, signData, -1)); + } + if (attachmentData == 1) + allAttchment.addAll(this.getRequestAttachment(requestId, String.valueOf(wfId))); + title = this.replaceFieldValue(fieldDatas, title); + content = this.replaceFieldValue(fieldDatas, content); + this.sendEmail(String.join(",", users), title, content, requestId, String.join(",", allAttchment)); + + } + } + } + } + } + } + + /** + * 流程自动审批失败,提醒当前节点除抄送人之外的人员 + * + * @param requestManager + */ + public void failAutoApproveRemind(RequestManager requestManager) { + + int requestId = requestManager.getRequestid(); + int wfId = requestManager.getWorkflowid(); + int currentNoidId = requestManager.getNextNodeid(); + + + RecordSet rs = new RecordSet(); + Set users = new HashSet<>(); + + String sql = "select userid from workflow_currentoperator where requestid = ? and usertype = 0 and nodeid = ? and isremark in(0,1,4,6,7) "; + rs.executeQuery(sql, requestId, currentNoidId); + while (rs.next()) { + users.add(Util.null2String(rs.getString(1))); + } + + Map params = new HashMap<>(); + params.put("reminder", String.join(",", users)); + params.put("requestId", requestId); + params.put("workflowId", wfId); + params.put("submitType", "submit"); + + rs.executeQuery("select remindscope from workflow_base where id = ? ", wfId); + rs.next(); + int remindscope = Util.getIntValue(rs.getString("remindscope"), 0); + if (remindscope == 1) { + this.requestRemind(params, RemindTypeEnum.EMAIL); + return; + } + WFManager wfManager = getWfInfo(String.valueOf(wfId)); + String defaultSmsRemind = wfManager.getIsDefaultSmsRemind(); + String defaultEmailRemind = wfManager.getIsDefaultEmailRemind(); + String mailMessageType = wfManager.getMailMessageType(); + String messageType = wfManager.getMessageType(); + + if ("1".equals(defaultSmsRemind) || "1".equals(messageType)) this.requestRemind(params, RemindTypeEnum.SMS); + if ("1".equals(defaultEmailRemind) || "1".equals(mailMessageType)) + this.requestRemind(params, RemindTypeEnum.EMAIL); + this.requestEmailApproveRemind(this.wfId, this.requestId, src); + } + + /** + * 流程自动审批成功 + * 1、如果继续自动审批,不做任何提醒 + * 2、非自动审批,提醒自动审批后停留节点的操作者 + * + * @param requestManager + */ + public void successAutoApproveRemind(RequestManager requestManager) { + + List nextNodeids = requestManager.getNextnodeids(); + Map nodeInfoCache = requestManager.getNodeInfoCache(); + Set nodeInfoCacheKey = nodeInfoCache.keySet(); + + Set nodeIds = new HashSet<>(); + for (Object id : nextNodeids) { + int intId = Util.getIntValue((String) id); + boolean exists = false; + for (Integer cacheId : nodeInfoCacheKey) { + if (cacheId == intId) { + exists = true; + break; + } + } + if (!exists) { + nodeIds.add(String.valueOf(intId)); + } + } + this.printLog("successAutoApproveRemind nodeIds:" + nodeIds); + if (nodeIds.isEmpty()) return; + + int requestId = requestManager.getRequestid(); + int wfId = requestManager.getWorkflowid(); + + RecordSet rs = new RecordSet(); + Set users = new HashSet<>(); + + rs.executeQuery("select detailinfo from workflow_requestoperatelog where operatetype ='submit' and requestid = ? " + + " and ( isinvalid is null or isinvalid = '') order by id desc ", requestId); + if (rs.next()) { + String newIds = ""; + String detailInfo = Util.null2String(rs.getString(1)); + JSONObject jsonObject = JSONObject.parseObject(detailInfo); + if (jsonObject != null) { + JSONObject operaterInfo = jsonObject.getJSONObject("workflow_currentoperator"); + if (operaterInfo != null) { + newIds = operaterInfo.getString("newIds"); + } + } + if (newIds.length() > 0) { + String sql = "select userid from workflow_currentoperator where requestid = ? and usertype = 0 and isremark in(0,1,4,6,7,8,9) "; + sql += " and " + Util.getSubINClause(newIds, "id", "in"); + rs.executeQuery(sql, requestId); + while (rs.next()) { + users.add(Util.null2String(rs.getString(1))); + } + } + } + // 修正D节点中有1234个会签操作者,123自动审批成功后,4无法收到消息的问题 + String nodeIdStr = String.join(",", nodeIds); + String sql = "select userid from workflow_currentoperator where requestid = ? and usertype = 0 and isremark in(0,1,4,6,7) "; + sql += " and " + Util.getSubINClause(nodeIdStr, "nodeid", "in") + " and islasttimes =1 "; + rs.executeQuery(sql, requestId); + while (rs.next()) { + users.add(Util.null2String(rs.getString(1))); + } + + String reminder = String.join(",", users); + this.printLog("successAutoApproveRemind requestId:" + requestId + ",userd :" + reminder); + + Map params = new HashMap<>(); + params.put("reminder", reminder); + params.put("requestId", requestId); + params.put("workflowId", wfId); + params.put("submitType", "submit"); + params.put("nextNodeIds", nodeIdStr); + + this.requestEmailApproveRemind2(params); + + rs.executeQuery("select remindscope from workflow_base where id = ? ", wfId); + rs.next(); + int remindscope = Util.getIntValue(rs.getString("remindscope"), 0); + if (remindscope == 1) { + this.requestRemind(params, RemindTypeEnum.EMAIL); + return; + } + WFManager wfManager = getWfInfo(String.valueOf(wfId)); + String defaultSmsRemind = wfManager.getIsDefaultSmsRemind(); + String defaultEmailRemind = wfManager.getIsDefaultEmailRemind(); + String mailMessageType = wfManager.getMailMessageType(); + String messageType = wfManager.getMessageType(); + + if ("1".equals(defaultSmsRemind) || "1".equals(messageType)) this.requestRemind(params, RemindTypeEnum.SMS); + if ("1".equals(defaultEmailRemind) || "1".equals(mailMessageType)) + this.requestRemind(params, RemindTypeEnum.EMAIL); + + } + + /** + * 流程超时处理 + * + * @param requestid + * @param workflowid + */ + public void autoFlowRemind(int requestid, int workflowid, int flownextoperator) { + // 短信发起人 + RecordSet rs = new RecordSet(); + rs.executeQuery("select operator from workflow_requestLog where requestid = ? order by logid desc ", requestid); + rs.next(); + int operator = Util.getIntValue(rs.getString(1), 1); + this.user = new User(operator); + // 提醒 + if (flownextoperator == 1 || flownextoperator == 4) { + this.requestSubmitRemind4WebService(requestid, workflowid, -1, -1); + } else if (flownextoperator == 3) { + this.requestSubmitRemind4WebService(requestid, workflowid, "reject", -1, -1); + } else if (flownextoperator == 0) { // 超时干预 + + WFManager wfManager = getWfInfo(String.valueOf(workflowid)); + String defaultSmsRemind = wfManager.getIsDefaultSmsRemind(); + String defaultEmailRemind = wfManager.getIsDefaultEmailRemind(); + + // 提醒新增的人员 + List users = new ArrayList<>(); + String sql = "select a.userid from workflow_currentoperator a,workflow_requestbase b where a.nodeid = b.currentnodeid and a.requestid = b.requestid and a.isremark = 5 and b.requestid = ? "; + rs.executeQuery(sql, requestid); + while (rs.next()) { + users.add(Util.null2String(rs.getString(1))); + } + + Map params = new HashMap<>(); + params.put("reminder", String.join(",", users)); + params.put("requestId", requestid); + params.put("workflowId", workflowid); + params.put("submitType", "submit"); + + if ("1".equals(defaultSmsRemind)) this.requestRemind(params, RemindTypeEnum.SMS); + if ("1".equals(defaultEmailRemind)) this.requestRemind(params, RemindTypeEnum.EMAIL); + } + } + + /** + * 其他创建流程接口发送提醒 + * + * @param requestid + * @param workflowid + */ + public void requestSubmitRemind4WebService(int requestid, int workflowid, int sms, int email) { + this.requestSubmitRemind4WebService(requestid, workflowid, "submit", sms, email); + } + + /** + * 供创建流程接口使用,发送流程提醒 + * + * @param requestid + * @param workflowid + * @param submitType + * @param sms 自定义短信提醒标识,有该标识不使用系统设置中的配置 + * @param email 自定义邮件提醒标识,有该标识不使用系统设置中的配置 + */ + public void requestSubmitRemind4WebService(int requestid, int workflowid, String submitType, int sms, int email) { + + boolean isflowNext = RequestRemindBiz.isflowNext(requestid, submitType, user.getUID()); + this.printLog("requestSubmitRemind4WebService requestid:" + requestid + "submitType:" + submitType + "isflowNext:" + isflowNext); + + try { + WFManager wfManager = getWfInfo(String.valueOf(workflowid)); + int messageType = Util.getIntValue(Util.null2String(wfManager.getMessageType()), -1); + int mailMessageType = Util.getIntValue(Util.null2String(wfManager.getMailMessageType())); + int isDefaultSmsRemind = Util.getIntValue(Util.null2String(wfManager.getIsDefaultSmsRemind())); + int isDefaultEmailRemind = Util.getIntValue(Util.null2String(wfManager.getIsDefaultEmailRemind())); + + RecordSet rs = new RecordSet(); + rs.executeQuery("select remindscope from workflow_base where id = ?", workflowid); + if (rs.next()) { + int remindScope = rs.getInt(1); + if (remindScope == 1) { + email = 1; + sms = -1; + } else { + if (sms == -1 && (messageType >= 1 || isDefaultSmsRemind == 1)) sms = 1; + if (email == -1 && (mailMessageType == 1 || isDefaultEmailRemind == 1)) email = 1; + } + } + if (isflowNext) { + if (sms == 1) this.requestRemind(requestid, workflowid, submitType, RemindTypeEnum.SMS, messageType); + if (email == 1) this.requestRemind(requestid, workflowid, submitType, RemindTypeEnum.EMAIL, 0); + } else { + this.doRemind(requestid, user.getUID(), workflowid, submitType, String.valueOf(sms), String.valueOf(email)); + // 流程停留在创建节点,发送提醒 + if (sms == 1) + this.requestCreateRemind(requestid, workflowid, submitType, RemindTypeEnum.SMS, messageType); + if (email == 1) this.requestCreateRemind(requestid, workflowid, submitType, RemindTypeEnum.EMAIL, 0); + } + this.requestEmailApproveRemind(String.valueOf(workflowid), String.valueOf(requestid), submitType); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 流程提醒 + * + * @param params + * @param typeEnum + * @return + */ + public Map requestRemind(Map params, RemindTypeEnum typeEnum) { + + Map results = new HashMap<>(); + String requestId = Util.null2String(params.get("requestId")); + String remindUser = Util.null2String(params.get("reminder")); // 提醒人 + String wfId = Util.null2String(params.get("workflowId")); + String submitType = Util.null2String(params.get("submitType")); // 流程提交类型 + this.wfId = wfId; + this.requestId = requestId; + this.fieldDatas = this.getFieldData(requestId); + this.remindContent = this.getRemindContent(wfId, typeEnum.getCode()); + this.defaultRemindContent = this.getDefaultRemindContent(); + + if (Strings.isNullOrEmpty(remindUser)) { + this.printLog("6、requestRemind remindUser is empty. requestId:" + requestId); + results.put("success", false); + results.put("msg", "user set is empty"); + return results; + } + + RecordSet rs = new RecordSet(); + if (this.isArchiveNoRemind(wfId, requestId, rs)) return results; + + String allNextNodeIds = this.getSendNodes(requestId); + String nextNodeIds = Util.null2String(params.get("nextNodeIds")); // 依次逐个处理节点自动审批时节点ID + if (!Strings.isNullOrEmpty(nextNodeIds)) { + allNextNodeIds += "," + nextNodeIds; + } + String[] allNextNodeIdsArr = allNextNodeIds.split(","); + Set removeRepeat = new HashSet<>(); + for (int s = 0, len = allNextNodeIdsArr.length; s < len; s++) { + removeRepeat.add(allNextNodeIdsArr[s]); + } + allNextNodeIds = String.join(",", removeRepeat); + + this.printLog("4、rquestid: +" + requestId + ",userid:" + user.getUID() + ",nodes: " + allNextNodeIds); + + rs.executeQuery("select remindscope from workflow_base where id = ? ", wfId); + rs.next(); + int remindscope = Util.getIntValue(rs.getString("remindscope"), 0); + if (remindscope == 1) { + this.remindWithNode(remindUser, submitType, allNextNodeIds); + return results; + } + this.remindWithDefault(remindUser, submitType, allNextNodeIds, typeEnum); + + return results; + } + + /** + * 流程邮件审批提醒 + * + * @param wfId + * @param requestId + * @param submitType + * @param + * @return + */ + public Map requestEmailApproveRemind(String wfId, String requestId, String submitType) { + + Map results = new HashMap<>(); + RecordSet rs = new RecordSet(); + rs.executeQuery("select isEmailRemind from workflow_base where id = ?", wfId); + if (rs.next()) { + int isEmailRemind = Util.getIntValue(rs.getString("isEmailRemind"), 0); + if (isEmailRemind == 0) return results; + } + rs.executeQuery("select isEMailApprove,nodescope,defaultTitle,defaultContent,isFormData,isSignData,isAttachmentData from wf_emailapprove_set where workflowId = ? ", wfId); + if (rs.next()) { + int isEMailApprove = Util.getIntValue(rs.getString("isEMailApprove"), 0); + if (isEMailApprove == 1) { + + Set currentNodeUser = this.getCurrentNodeUser(Util.null2String(requestId), 0); + String remindUser = String.join(",", currentNodeUser); + this.printLog("13、rquestid: +" + requestId + ",userid:" + user.getUID() + ",user: " + remindUser); + + String emailCode = RemindTypeEnum.EMAIL.getCode(); + this.wfId = wfId; + this.requestId = requestId; + this.fieldDatas = this.getFieldData(requestId); + this.remindContent = this.getRemindContent(wfId, emailCode); + this.defaultRemindContent = this.getDefaultRemindContent(); + + if (Strings.isNullOrEmpty(remindUser)) { + this.printLog("6、requestRemind remindUser is empty. requestId:" + requestId); + results.put("success", false); + results.put("msg", "user set is empty"); + return results; + } + + String allNextNodeIds = this.getSendNodes(requestId); + this.printLog("12、rquestid: +" + requestId + ",userid:" + user.getUID() + ",nodes: " + allNextNodeIds); + + String defaultTitle = rs.getString("defaultTitle"); + String defaultContent = rs.getString("defaultContent"); + int isFormData = Util.getIntValue(rs.getString("isFormData"), 0); + int isSignData = Util.getIntValue(rs.getString("isSignData"), 0); + int isAttachmentData = Util.getIntValue(rs.getString("isAttachmentData"), 0); + int nodescope = Util.getIntValue(rs.getString("nodescope"), 0); + + if (nodescope == 1) { + this.approveRemindWithNode(defaultTitle, defaultContent, remindUser, submitType, allNextNodeIds, isFormData, isSignData, isAttachmentData); + return results; + } + this.approveRemindWithDefault(defaultTitle, defaultContent, remindUser, submitType, allNextNodeIds, isFormData, isSignData, isAttachmentData); + return results; + } + } + return results; + } + + + /** + * 流程自动审批 流程邮件审批提醒 + * + * @param + * @return + */ + public Map requestEmailApproveRemind2(Map params) { + + String wfId = Util.null2String(params.get("workflowId")); + String requestId = Util.null2String(params.get("requestId")); + String submitType = Util.null2String(params.get("submitType")); + String remindUser = Util.null2String(params.get("reminder")); + String nextNodeIds = Util.null2String(params.get("nextNodeIds")); + + Map results = new HashMap<>(); + RecordSet rs = new RecordSet(); + rs.executeQuery("select isEmailRemind from workflow_base where id = ?", wfId); + if (rs.next()) { + int isEmailRemind = Util.getIntValue(rs.getString("isEmailRemind"), 0); + if (isEmailRemind == 0) return results; + } + rs.executeQuery("select isEMailApprove,nodescope,defaultTitle,defaultContent,isFormData,isSignData,isAttachmentData from wf_emailapprove_set where workflowId = ? ", wfId); + if (rs.next()) { + int isEMailApprove = Util.getIntValue(rs.getString("isEMailApprove"), 0); + if (isEMailApprove == 1) { + + this.printLog("14、rquestid: +" + requestId + ",userid:" + user.getUID() + ",user: " + remindUser); + + String emailCode = RemindTypeEnum.EMAIL.getCode(); + this.wfId = wfId; + this.requestId = requestId; + this.fieldDatas = this.getFieldData(requestId); + this.remindContent = this.getRemindContent(wfId, emailCode); + this.defaultRemindContent = this.getDefaultRemindContent(); + + if (Strings.isNullOrEmpty(remindUser)) { + this.printLog("6、requestRemind remindUser is empty. requestId:" + requestId); + results.put("success", false); + results.put("msg", "user set is empty"); + return results; + } + + if (this.isArchiveNoRemind(wfId, requestId, rs)) return results; + + String allNextNodeIds = this.getSendNodes(requestId); + if (!Strings.isNullOrEmpty(nextNodeIds)) { + allNextNodeIds += "," + nextNodeIds; + } + String[] allNextNodeIdsArr = allNextNodeIds.split(","); + Set removeRepeat = new HashSet<>(); + for (int s = 0, len = allNextNodeIdsArr.length; s < len; s++) { + removeRepeat.add(allNextNodeIdsArr[s]); + } + allNextNodeIds = String.join(",", removeRepeat); + + this.printLog("15、rquestid: +" + requestId + ",userid:" + user.getUID() + ",nodes: " + allNextNodeIds); + + String defaultTitle = rs.getString("defaultTitle"); + String defaultContent = rs.getString("defaultContent"); + int isFormData = Util.getIntValue(rs.getString("isFormData"), 0); + int isSignData = Util.getIntValue(rs.getString("isSignData"), 0); + int isAttachmentData = Util.getIntValue(rs.getString("isAttachmentData"), 0); + int nodescope = Util.getIntValue(rs.getString("nodescope"), 0); + + if (nodescope == 1) { + this.approveRemindWithNode(defaultTitle, defaultContent, remindUser, submitType, allNextNodeIds, isFormData, isSignData, isAttachmentData); + return results; + } + this.approveRemindWithDefault(defaultTitle, defaultContent, remindUser, submitType, allNextNodeIds, isFormData, isSignData, isAttachmentData); + return results; + } + } + return results; + } + + + /** + * 节点邮件审批 + * + * @param defaultTitle + * @param defaultContent + * @param remindUser + * @param submitType + * @param isSignData + * @param isAttachmentData + */ + private void approveRemindWithNode(String defaultTitle, String defaultContent, String remindUser, String submitType, String allNextNodeIds, + int isFormData, int isSignData, int isAttachmentData) { + String nodeCondition = Util.getSubINClause(allNextNodeIds, "nodeId", "in"); + RecordSet rs = new RecordSet(); + rs.executeQuery("select nodeid,contentType,title,content,isFormData,isSignData,isAttachmentData from " + + " wf_emailapprove_content where workflowId = ? and " + nodeCondition, wfId); + while (rs.next()) { + + String nodeId = rs.getString("nodeid"); + boolean isDefault = Util.getIntValue(rs.getString("contentType"), 0) == 0; + + String title = rs.getString("title"); + String content = rs.getString("content"); + if (Strings.isNullOrEmpty(title) || isDefault) title = defaultTitle; + if (Strings.isNullOrEmpty(content) || isDefault) content = defaultContent; + + int formData = isDefault ? isFormData : Util.getIntValue(rs.getString("isFormData"), 0); + int attachmentData = isDefault ? isAttachmentData : Util.getIntValue(rs.getString("isAttachmentData"), 0); + Set allAttchment = new LinkedHashSet<>(); + if (formData == 1) { + int signData = isDefault ? isSignData : Util.getIntValue(rs.getString("isSignData"), 0); + allAttchment.add(this.getRequestFormPdf(requestId, signData, -1)); + } + if (attachmentData == 1) allAttchment.addAll(this.getRequestAttachment(requestId, wfId)); + + // 4、该节点所有操作者 + Map users = this.getSendUsers(String.valueOf(requestId), remindUser, submitType, nodeId); + for (String key : users.keySet()) { + String userIdStr = users.get(key); + + if (Strings.isNullOrEmpty(userIdStr)) continue; + + // 审批、确认、退回做邮件审批 + boolean isApprove = this.isApproveAction(key); + if (isApprove) { + + Map approveRemindContent = remindContent.get(RemindTypeEnum.APPROVAL.getCode()); + if (approveRemindContent == null) + approveRemindContent = defaultRemindContent.get(RemindTypeEnum.APPROVAL.getCode()); + + if (Strings.isNullOrEmpty(title)) title = approveRemindContent.get("title"); + if (Strings.isNullOrEmpty(content)) content = approveRemindContent.get("content"); + // 追加邮件审批按钮 + if (content.indexOf(RequestRemindBiz.SYSTEM_FIELD_APPROVE_BTN) < 0) { + content += "
" + RequestRemindBiz.SYSTEM_FIELD_APPROVE_BTN; + } + String[] userIdArr = userIdStr.split(","); + for (String userId : userIdArr) { + Map btnDatas = this.getEmailApproveBtn(requestId, nodeId, userId); + fieldDatas.putAll(btnDatas); + String _title = title; + String _content = content; + _title = this.replaceFieldValue(fieldDatas, _title); + _content = this.replaceFieldValue(fieldDatas, _content); + this.sendEmail4Approve(userId, _title, _content, requestId, String.join(",", allAttchment)); + } + } + } + } + + } + + /** + * 默认邮件审批 + * + * @param defaultTitle 审批标题 + * @param defaultContent 审批内容 + * @param remindUser + * @param submitType + * @param sendNodeId + * @param isFormData + * @param isSignData + * @param isAttachmentData + */ + private void approveRemindWithDefault(String defaultTitle, String defaultContent, String remindUser, String submitType, + String sendNodeId, int isFormData, int isSignData, int isAttachmentData) { + Set allAttchment = new LinkedHashSet<>(); + if (isFormData == 1) { + allAttchment.add(this.getRequestFormPdf(requestId, isSignData, -1)); + } + if (isAttachmentData == 1) allAttchment.addAll(this.getRequestAttachment(requestId, wfId)); + + String[] nodeIds = sendNodeId.split(","); + for (String nodeId : nodeIds) { + Map users = this.getSendUsers(String.valueOf(requestId), remindUser, submitType, nodeId); + for (String key : users.keySet()) { + String userIdStr = users.get(key); + if (Strings.isNullOrEmpty(userIdStr)) continue; + + // 审批、确认、退回做邮件审批 + boolean isApprove = this.isApproveAction(key); + if (isApprove) { + + Map approveRemindContent = remindContent.get(RemindTypeEnum.APPROVAL.getCode()); + if (approveRemindContent == null) + approveRemindContent = defaultRemindContent.get(RemindTypeEnum.APPROVAL.getCode()); + + if (Strings.isNullOrEmpty(defaultTitle)) defaultTitle = approveRemindContent.get("title"); + if (Strings.isNullOrEmpty(defaultContent)) defaultContent = approveRemindContent.get("content"); + if (defaultContent.indexOf(RequestRemindBiz.SYSTEM_FIELD_APPROVE_BTN) < 0) { + defaultContent += "
" + RequestRemindBiz.SYSTEM_FIELD_APPROVE_BTN; + } + String[] userIdArr = userIdStr.split(","); + for (String userId : userIdArr) { + Map btnDatas = this.getEmailApproveBtn(requestId, nodeId, userId); + fieldDatas.putAll(btnDatas); + String title = defaultTitle; + String content = defaultContent; + title = this.replaceFieldValue(fieldDatas, title); + content = this.replaceFieldValue(fieldDatas, content); + this.sendEmail4Approve(userId, title, content, requestId, String.join(",", allAttchment)); + } + } + } + } + } + + /** + * 节点自定义提醒 + * + * @param remindUser + * @param submitType + * @param sendNodeId + */ + private void remindWithNode(String remindUser, String submitType, String sendNodeId) { + RecordSet rs = new RecordSet(); + // + rs.executeQuery("select isEmailRemind,isSmsRemind from workflow_base where id = ?", wfId); + int isEmailRemind = 0; + int isSmsRemind = 0; + if (rs.next()) { + isEmailRemind = rs.getInt(1); + isSmsRemind = rs.getInt(2); + } + String[] sendNodeArr = sendNodeId.split(","); + for (String nodeId : sendNodeArr) { + // 节点自定义 + rs.executeQuery("select id,contenttype,remindtypes,ccNoremind from wf_emailremind_set where workflowid=? and nodeid=?", wfId, nodeId); + if (rs.next()) { + String remindtypes = rs.getString("remindtypes"); + if (Strings.isNullOrEmpty(remindtypes)) { + this.printLog("11、rquestid: +" + requestId + ",userid:" + user.getUID() + ",节点没有自定义设置提醒:" + nodeId); + continue; + } + int contenttype = Util.getIntValue(rs.getString("contenttype"), 0); + int ccNoremind = Util.getIntValue(rs.getString("ccNoremind"), 0); + int remindSetId = rs.getInt("id"); + + String[] remindtypesArr = remindtypes.split(","); + for (String typeEnum : remindtypesArr) { + Map> nodeRemindContent = new HashMap<>(); + if (isEmailRemind != 1 && typeEnum.equals(RemindTypeEnum.EMAIL.getCode())) continue; + if (isSmsRemind != 1 && typeEnum.equals(RemindTypeEnum.SMS.getCode())) continue; + this.remindContent = this.getRemindContent(wfId, typeEnum); + if (contenttype == 1) { + rs.executeQuery("select contentType,title,content,isFormData,isSignData,isAttachmentData from wf_emailremind_content where remindSetId=? and remindType=?", remindSetId, typeEnum); + while (rs.next()) { + String contentType = rs.getString("contentType"); + String title = rs.getString("title"); + String content = rs.getString("content"); + String isFormData = rs.getString("isFormData"); + String isSignData = rs.getString("isSignData"); + String isAttachmentData = rs.getString("isAttachmentData"); + + Map contentMap = new HashMap<>(); + contentMap.put("title", title); + contentMap.put("content", content); + contentMap.put("isFormData", isFormData); + contentMap.put("isSignData", isSignData); + contentMap.put("isAttachmentData", isAttachmentData); + nodeRemindContent.put(contentType, contentMap); + } + } + + Map users = this.getSendUsers(String.valueOf(requestId), remindUser, submitType, nodeId); + for (String key : users.keySet()) { + if (Strings.isNullOrEmpty(users.get(key))) continue; + if (this.isEmailApprove(key, wfId, nodeId)) continue; + if (key.equals(RemindTypeEnum.CC.getCode()) && ccNoremind == 1) continue; + + Map info = nodeRemindContent.get(key); + Map nodeInfo = nodeRemindContent.get(key); + if (info == null) info = remindContent.get(key); + if (info == null) info = defaultRemindContent.get(key); + if (contenttype != 1) nodeInfo = info; + if (RemindTypeEnum.EMAIL.getCode().equals(typeEnum)) { + String title = Util.null2String(info.get("title")); + String content = Util.null2String(info.get("content")); + + int formData = 0; + int signData = 0; + int attachmentData = 0; + if (nodeInfo != null) { + formData = Util.getIntValue(Util.null2String(nodeInfo.get("isFormData")), 0); + signData = Util.getIntValue(Util.null2String(nodeInfo.get("isSignData")), 0); + attachmentData = Util.getIntValue(Util.null2String(nodeInfo.get("isAttachmentData")), 0); + } + Set allAttchment = new LinkedHashSet<>(); + if (formData == 1) { + allAttchment.add(this.getRequestFormPdf(requestId, signData, -1)); + } + if (attachmentData == 1) allAttchment.addAll(this.getRequestAttachment(requestId, wfId)); + title = this.replaceFieldValue(fieldDatas, title); + content = this.replaceFieldValue(fieldDatas, content); + this.sendEmail(users.get(key), title, content, requestId, String.join(",", allAttchment)); + } + + if (RemindTypeEnum.SMS.getCode().equals(typeEnum)) { + String content = Util.null2String(info.get("content")); + content = content.replace("_link", ""); // 默认内容中带有超链接字段 + content = Util.toHtmlMode(this.replaceFieldValue(fieldDatas, content)); + this.sendSMS(users.get(key), content, requestId); + } + } + } + } else { + this.printLog("7、rquestid: +" + requestId + ",userid:" + user.getUID() + ",节点没有自定义设置提醒:" + nodeId); + } + } + } + + /** + * 默认邮件提醒 + * + * @param remindUser + * @param submitType + * @param sendNodeId + * @param typeEnum + */ + private void remindWithDefault(String remindUser, String submitType, String sendNodeId, RemindTypeEnum typeEnum) { + + + WFManager manager = getWfInfo(this.wfId); + int ccNotRemind = Util.getIntValue(manager.getIsCCNoRemind()); + + String[] sendNodeArr = sendNodeId.split(","); + for (String nodeId : sendNodeArr) { + Map users = this.getSendUsers(this.requestId, remindUser, submitType, nodeId); + for (String key : users.keySet()) { + if (this.isEmailApprove(key, wfId, nodeId)) continue; + if (Strings.isNullOrEmpty(users.get(key))) continue; + if (ccNotRemind == 1 && key.equals(RemindTypeEnum.CC.getCode())) continue; + + Map info = this.remindContent.get(key); + if (info == null) info = this.defaultRemindContent.get(key); + + if (typeEnum.getCode().equals(RemindTypeEnum.EMAIL.getCode())) { + String title = Util.null2String(info.get("title")); + String content = Util.null2String(info.get("content")); + int formData = Util.getIntValue(Util.null2String(info.get("isFormData")), 0); + int signData = Util.getIntValue(Util.null2String(info.get("isSignData")), 0); + int attachmentData = Util.getIntValue(Util.null2String(info.get("isAttachmentData")), 0); + Set allAttchment = new LinkedHashSet<>(); + if (formData == 1) { + allAttchment.add(this.getRequestFormPdf(requestId, signData, -1)); + } + if (attachmentData == 1) allAttchment.addAll(this.getRequestAttachment(requestId, wfId)); + title = this.replaceFieldValue(this.fieldDatas, title); + content = this.replaceFieldValue(this.fieldDatas, content); + this.sendEmail(users.get(key), title, content, this.requestId, String.join(",", allAttchment)); + } + + if (typeEnum.getCode().equals(RemindTypeEnum.SMS.getCode())) { + String content = Util.null2String(info.get("content")); + content = content.replace("_link", ""); // 默认内容中带有超链接字段 + content = Util.toHtmlMode(this.replaceFieldValue(this.fieldDatas, content)); + this.sendSMS(users.get(key), content, this.requestId); + } + } + } + } + + /** + * 替换字符串中的占位符 + * + * @param str + * @return + */ + public String replaceFieldValue(Map fieldDatas, String str) { + try { + for (String key : fieldDatas.keySet()) { + String fieldValue = Util.null2String(fieldDatas.get(key)); + fieldValue = Util.formatMultiLang(fieldValue, String.valueOf(user.getLanguage())); + fieldValue = RequestRemindBiz.parseSpecialChar(fieldValue); + key = RequestRemindBiz.parseSpecialChar(key); + str = str.replaceAll(key, fieldValue); + } + } catch (Exception e) { + e.printStackTrace(); + } + return str; + } + + /** + * 获取人员信息,并根据操作类型分组 + * + * @param requestId + * @param remindUser + * @return + */ + private Map getSendUsers(String requestId, String remindUser, String submitType, String sendNodeId) { + + Map users = new HashMap<>(); + + Set approvaUsers = new HashSet<>(); // 审批 + Set confirmUsers = new HashSet<>(); // 确认 + Set archiveUsers = new HashSet<>(); // 归档 + Set ccUsers = new HashSet<>(); // 抄送 + + if ("reject".equals(submitType)) { + users.put(RemindTypeEnum.BACK.getCode(), remindUser); + } else if ("forward".equals(submitType)) { + users.put(RemindTypeEnum.FORWARD.getCode(), remindUser); + } else if ("trans".equals(submitType)) { + users.put(RemindTypeEnum.TRANS.getCode(), remindUser); + } else if ("take".equals(submitType)) { + users.put(RemindTypeEnum.TAKE.getCode(), remindUser); + } else if ("chuanyue".equals(submitType)) { + users.put(RemindTypeEnum.CHUANYUE.getCode(), remindUser); + } else { + RecordSet rs = new RecordSet(); + String sql = "select wf.userid,wf.isremark,wf.preisremark," + + "(CASE WHEN nodeid < -1 THEN (SELECT nodetype FROM workflow_freenode t WHERE t.id = wf.nodeid ) " + + "ELSE (SELECT nodetype FROM workflow_flownode t1 WHERE t1.nodeid = wf.nodeid) end) AS nodetype " + + "from workflow_currentoperator wf where wf.usertype = 0 and wf.requestid = ? and " + + Util.getSubINClause(sendNodeId, "wf.nodeid", "IN") + " and " + + Util.getSubINClause(remindUser, "wf.userid", "IN"); + + this.printLog("8、getSendUsers sql:" + sql + ",requestid:" + requestId); + rs.executeQuery(sql, requestId); + while (rs.next()) { + String id = Util.null2String(rs.getString("userid")); + int isremark = Util.getIntValue(Util.null2String(rs.getString("isremark"))); + if (isremark == 2) continue; + int preisremark = Util.getIntValue(Util.null2String(rs.getString("preisremark"))); + int nodeType = Util.getIntValue(Util.null2String(rs.getString("nodetype"))); + if (isremark == 0 || isremark == 5 || (isremark != 4 && preisremark == 0)) { + if (nodeType == 1) {// 审批 + approvaUsers.add(id); + } else {// 确认 + confirmUsers.add(id); + } + } else if (isremark == 4) {// 归档 + archiveUsers.add(id); + } else {// 8,9抄送 + ccUsers.add(id); + } + } + + users.put(RemindTypeEnum.APPROVAL.getCode(), String.join(",", approvaUsers)); + users.put(RemindTypeEnum.ARCHIVE.getCode(), String.join(",", archiveUsers)); + users.put(RemindTypeEnum.CONFIRM.getCode(), String.join(",", confirmUsers)); + users.put(RemindTypeEnum.CC.getCode(), String.join(",", ccUsers)); + } + this.printLog("10、rquestid: +" + requestId + ",userid:" + user.getUID() + ",usersJson: " + JSONObject.toJSONString(users)); + return users; + } + + /** + * 获取流程提交后,实际到达的节点 + * + * @param requestId + * @return + */ + private String getSendNodes(String requestId) { + + Set nodeid = new HashSet(); + RecordSet rs = new RecordSet(); + rs.executeQuery("select detailinfo from workflow_requestoperatelog where requestid = ? and (isinvalid is null or isinvalid <> 1) and operatorid = ? order by id desc", requestId, user.getUID()); + if (rs.next()) { + String detailInfo = rs.getString("detailinfo"); + JSONObject tables = JSONObject.parseObject(detailInfo); + if (tables == null) return null; + + JSONObject operatorTable = tables.getJSONObject(RequestOperateEntityTableNameEnum.CURRENTOPERATOR.getTableName()); + if (operatorTable == null) return null; + + // 新增操作者 + String newIds = operatorTable.getString("newIds"); + if (!Strings.isNullOrEmpty(newIds)) { + rs.executeQuery("select nodeid from workflow_currentoperator where requestid = ? and " + Util.getSubINClause(newIds, "id", "in"), requestId); + while (rs.next()) { + nodeid.add(rs.getString(1)); + } + } + + Set operateId = new HashSet<>(); + JSONArray modifyDatas = operatorTable.getJSONArray("modifyData"); + for (int i = 0, len = modifyDatas.size(); i < len; i++) { + JSONObject datas = modifyDatas.getJSONObject(i); + String fieldName = datas.getString("fieldName"); + // A征询B,B回复时,A的操作者ID + if ("takisremark".equals(fieldName)) { + int nVal = datas.getIntValue("nVal"); + int oVal = datas.getIntValue("oVal"); + if (oVal == -2 && nVal == 0) operateId.add(datas.getString("entityId")); + } + // A征询B,B征询C,C回复时,B的操作者ID + if ("isremark".equals(fieldName)) { + int nVal = datas.getIntValue("nVal"); + int oVal = datas.getIntValue("oVal"); + if (oVal == 2 && nVal == 1) operateId.add(datas.getString("entityId")); + } + } + if (!operateId.isEmpty()) { + rs.executeQuery("select nodeid from workflow_currentoperator where " + + Util.getSubINClause(String.join(",", operateId), "id", "in")); + while (rs.next()) { + nodeid.add(rs.getString(1)); + } + } + } + return String.join(",", nodeid); + } + + /** + * 获取提醒内容 + * + * @param wfId + * @return + */ + private Map> getRemindContent(String wfId, String remindType) { + + RecordSet rs = new RecordSet(); + + Map> contentMap = new HashMap<>(); + rs.executeQuery("select * from workflow_remindcontent where workflowid=? and remindType=?", wfId, remindType); + + while (rs.next()) { + String remindContentType = Util.null2String(rs.getString("contenttype")); + String title = Util.null2String(rs.getString("title")); + String content = Util.null2String(rs.getString("content")); + String isFormData = Util.null2String(rs.getString("isFormData")); + String isSignData = Util.null2String(rs.getString("isSignData")); + String isAttachmentData = Util.null2String(rs.getString("isAttachmentData")); + + Map info = new HashMap<>(); + info.put("title", title); + info.put("content", content); + info.put("isFormData", isFormData); + info.put("isSignData", isSignData); + info.put("isAttachmentData", isAttachmentData); + + contentMap.put(remindContentType, info); + } + return contentMap; + } + + /** + * 获取默认提醒内容 + * + * @return + */ + public Map> getDefaultRemindContent() { + + Map> contentMap = new HashMap<>(); + + List remindContentType = RemindTypeEnum.getRemindContentType(); + Properties prop = this.getProp(); + for (RemindTypeEnum e : remindContentType) { + + String title = prop.getProperty(String.format("remind.msg.%s.title.value", e.getCode()), ""); + String content = prop.getProperty(String.format("remind.msg.%s.content.value", e.getCode()), ""); + String isFormData = prop.getProperty(String.format("remind.default.formdata", e.getCode()), ""); + String isSignData = prop.getProperty(String.format("remind.default.signdata", e.getCode()), ""); + String isAttachmentData = prop.getProperty(String.format("remind.default.attachmentdata", e.getCode()), ""); + + Map info = new HashMap<>(); + info.put("title", title); + info.put("content", content); + info.put("isFormData", isFormData); + info.put("isSignData", isSignData); + info.put("isAttachmentData", isAttachmentData); + + contentMap.put(e.getCode(), info); + } + + return contentMap; + } + + /** + * @param wfId + * @return + */ + private static WFManager getWfInfo(String wfId) { + WFManager wfManager = new WFManager(); + wfManager.setWfid(Util.getIntValue(wfId)); + try { + wfManager.getWfInfo(); + } catch (Exception e) { + new BaseBean().writeLog(e); + } + return wfManager; + } + + /** + * 获取流程当前节点操作者 + * + * @param requestId + * @return + */ + public Set getCurrentNodeUser(String requestId, int onLine) { + + Set userList = new HashSet<>(); + + RecordSet rs = new RecordSet(); + // 利用 workflow_requestoperatelog 查找当前人员,避免一个节点多次参与流转时,将前几次参与时的人员也找了出来 + String newIds = ""; + rs.executeQuery("select max(id) from workflow_requestoperatelog where (isinvalid is null or isinvalid <> 1 )" + + " and (operatetype = 'submit' or operatetype = 'reject' or operatetype = 'forceover' or operatetype='intervenor') and operatorid = ? and requestid = ?", user.getUID(), requestId); + if (rs.next()) { + String maxId = Util.null2String(rs.getString(1)); + rs.executeQuery("select detailInfo from workflow_requestoperatelog where id = ?", maxId); + if (rs.next()) { + String detailInfo = Util.null2String(rs.getString(1)); + JSONObject jsonObject = JSONObject.parseObject(detailInfo); + if (jsonObject != null) { + // 1、先检验workflow_currentoperator + JSONObject operaterInfo = jsonObject.getJSONObject("workflow_currentoperator"); + if (operaterInfo != null) { + newIds = operaterInfo.getString("newIds"); + } + } + } + } + if (Strings.isNullOrEmpty(newIds)) return userList; + + String sql = "select userid from workflow_currentoperator where requestid = ? and usertype = 0 and " + + Util.getSubINClause(newIds, "id", "in") + " and isremark in(0,1,4,6,7,8,9) "; + rs.executeQuery(sql, requestId); + while (rs.next()) { + String userId = Util.null2String(rs.getString("userid")); + if (onLine == 1) { // 离线才发 + HrmUserOnlineMap hrmUserOnlineMap = HrmUserOnlineMap.getInstance(); + if (!hrmUserOnlineMap.isOnline(Util.getIntValue(userId))) { + userList.add(userId); + } + } else { + userList.add(userId); + } + } + + return userList; + } + + /** + * 获取配置文件 + * + * @return + */ + public Properties getProp() { + + String root = GCONST.getPropertyPath(); + Properties prop = null; + + File f = new File(root + "MailMessage.properties"); + if (f.exists()) { + InputStreamReader is = null; + try { + is = new InputStreamReader(new FileInputStream(f), "gbk"); + prop = new Properties(); + prop.load(is); + } catch (IOException e) { + } finally { + if (is != null) { + try { + is.close(); + } catch (Exception e) { + } + } + } + } + return prop; + } + + /** + * 是否开启流程提醒 + * + * @param wfManager + * @return + */ + public static boolean isOpenRemind(WFManager wfManager) { + + int isSmsRemind = Util.getIntValue(wfManager.getIsSmsRemind(), 0); + int isEmailRemind = Util.getIntValue(wfManager.getIsEmailRemind(), 0); + int mailMessageType = Util.getIntValue(wfManager.getMailMessageType(), 0); + + return (isSmsRemind + isEmailRemind + mailMessageType) > 0; + } + + /** + * 流程提交是否流转到了下一个节点 + * + * @param requestId + * @param src + * @return + */ + public static boolean isflowNext(int requestId, String src, int userId) { + + if ("intervenor".equals(src)) return true; + + boolean isflowNext = false; + RecordSet rs = new RecordSet(); + rs.executeQuery("select max(id) from workflow_requestoperatelog where (isinvalid is null or isinvalid <> 1 ) and (operatetype = 'submit' or operatetype = 'reject') and operatorid = ? and requestid = ?", userId, requestId); + if (rs.next()) { + String maxId = Util.null2String(rs.getString(1)); + rs.executeQuery("select detailInfo from workflow_requestoperatelog where id = ?", maxId); + if (rs.next()) { + String detailInfo = Util.null2String(rs.getString(1)); + JSONObject jsonObject = JSONObject.parseObject(detailInfo); + if (jsonObject != null) { + // 1、先检验workflow_currentoperator + JSONObject operaterInfo = jsonObject.getJSONObject("workflow_currentoperator"); + if (operaterInfo != null) { + String newIds = operaterInfo.getString("newIds"); + if (Strings.isNullOrEmpty(newIds)) return isflowNext; + } + // 2、 + JSONObject requestBase = jsonObject.getJSONObject("workflow_requestbase"); + if (requestBase != null) { + JSONArray modifyDatas = requestBase.getJSONArray("modifyData"); + for (int i = 0; i < modifyDatas.size(); i++) { + JSONObject data = modifyDatas.getJSONObject(i); + String fieldName = data.getString("fieldName"); + if ("currentnodeid".equals(fieldName)) { + int oVal = Util.getIntValue(Util.null2String(data.getString("oVal"))); + int nVal = Util.getIntValue(Util.null2String(data.getString("nVal"))); + if (nVal != oVal) { + isflowNext = true; + } + } + } + } + } + } + + } + return isflowNext; + } + + /** + * 获取表单数据 + * + * @param requestId + * @return + */ + private Map getFieldData(String requestId) { + + Map fieldDatas = new HashMap<>(); + + int isBill = 1; + int formid = -1; + + RecordSet rs = new RecordSet(); + rs.executeQuery("select workflowid,requestnamenew,requestlevel,createdate,createtime " + + "from workflow_requestbase where requestid=?", requestId); + rs.next(); + String wfId = Util.null2String(rs.getString("workflowid")); + String requestname = Util.null2String(rs.getString("requestnamenew")); + requestname = Util.formatMultiLang(requestname); // 处理多语言 + requestname = requestname.replaceAll("", "").replaceAll("", ""); + requestname = requestname.replaceAll("", "").replaceAll("", ""); + + String requestlevel = Util.null2String(rs.getString("requestlevel")); + + String createdate = Util.null2String(rs.getString("createdate")); + String createtime = Util.null2String(rs.getString("createtime")); + + // 判断老表单还是新表单 + rs.executeQuery("select isbill,formid from workflow_base where id=?", wfId); + if (rs.next()) { + isBill = Util.getIntValue(Util.null2String(rs.getString("isbill"))); + formid = Util.getIntValue(Util.null2String(rs.getString("formid"))); + } + RecordSet recordSet = new RecordSet(); + if (isBill == 1) { + recordSet.executeQuery("select id,fieldname from workflow_billfield where billid= ? and viewtype = 0", formid); + } else { + recordSet.executeQuery("select fd.id,fd.fieldname from" + + " workflow_formfield ff,workflow_formdict fd where ff.formid = ? and ff.fieldid = fd.id", formid); + } + while (recordSet.next()) { + String fieldId = Util.null2String(recordSet.getString("id")); + fieldDatas.put(String.format("${fieldid_%s}", fieldId), + this.getFiledValue(isBill, formid, Util.getIntValue(requestId), fieldId)); + } + requestlevel = Util.null2String(GetCustomLevelUtil.getLevel(requestlevel + "", user.getLanguage())); + + String requestNameLink = this.parseEmailLink(requestname, requestId); + + fieldDatas.put(RequestRemindBiz.SYSTEM_FIELD_LEVEL, requestlevel); + fieldDatas.put(RequestRemindBiz.SYSTEM_FIELD_TITLE, requestname); + fieldDatas.put(RequestRemindBiz.SYSTEM_FIELD_TITLE_LINK, requestNameLink); + fieldDatas.put(RequestRemindBiz.SYSTEM_FIELD_CREATEDATA, String.format("%s %s", createdate, createtime)); + + return fieldDatas; + } + + /** + * 获取各节点对应的审批按钮Html信息 + * + * @param requestId + * @param nodeId + * @param userId + * @return + */ + private Map getEmailApproveBtn(String requestId, String nodeId, String userId) { + + Map fieldDatas = new HashMap<>(); + + int languageId = User.getUserLang(Util.getIntValue(userId)); + RecordSet rs = new RecordSet(); + rs.executeQuery("select workflowid,requestnamenew " + + " from workflow_requestbase where requestid=?", requestId); + rs.next(); + String wfId = Util.null2String(rs.getString("workflowid")); + String requestnamenew = Util.null2String(rs.getString("requestnamenew")); + int nodeid = Util.getIntValue(nodeId); + if (nodeid < -1) { + nodeId = String.valueOf(FreeNodeBiz.getExtendNodeId(nodeid)); + } + // 节点类型:审批节点或者确认节点 + rs.executeQuery("select nodetype from workflow_flownode " + + " where workflowid = ? and nodeid= ?", wfId, nodeId); + rs.next(); + int nodetype = Util.getIntValue(rs.getString("nodetype"), -1); + if (nodetype == 3) { + fieldDatas.put(SYSTEM_FIELD_APPROVE_BTN, "(仅审批节点和确认节点有邮件审批按钮)"); + } else { + String submitname = ""; // 提交按钮的名称 : 创建, 审批, 实现 + String rejectName = "";// 退回 + rs.executeQuery("select submitname7,submitname8,submitname9,rejectName7,rejectName8,rejectName9 " + + " from workflow_nodecustomrcmenu where wfid = ? and nodeid= ?", wfId, nodeId); + rs.next(); + switch (languageId) { + case 8: + submitname = Util.null2String(rs.getString("submitname8")); + rejectName = Util.null2String(rs.getString("rejectName8")); + break; + case 9: + submitname = Util.null2String(rs.getString("submitname9")); + rejectName = Util.null2String(rs.getString("rejectName9")); + break; + default: + submitname = Util.null2String(rs.getString("submitname7")); + rejectName = Util.null2String(rs.getString("rejectName7")); + break; + } + + String defaultApproveBtn = null; // 提交 + String defaultConfirmBtn = null; // 批准 + String defaultRejectName = null; + rs.executeQuery("select submitName_0,submitName_1,rejectName from SystemCustomMenuSet"); + if (rs.next()) { + defaultApproveBtn = Util.processBody(Util.null2String(rs.getString("submitName_0")).trim(), + String.valueOf(languageId)); + defaultConfirmBtn = Util.processBody(Util.null2String(rs.getString("submitName_1")).trim(), + String.valueOf(languageId)); + defaultRejectName = Util.null2String(rs.getString("rejectName")); + } + if (Strings.isNullOrEmpty(submitname)) { + if (nodetype == 1) { + submitname = Strings.isNullOrEmpty(defaultApproveBtn) ? + SystemEnv.getHtmlLabelName(142, user.getLanguage()) : defaultApproveBtn; // 审批 + } else if (nodetype == 2 || nodetype == 0) { + submitname = Strings.isNullOrEmpty(defaultConfirmBtn) ? + SystemEnv.getHtmlLabelName(725, user.getLanguage()) : defaultConfirmBtn; // 确认 + } + } + if (Strings.isNullOrEmpty(rejectName)) { + rejectName = Strings.isNullOrEmpty(defaultRejectName) ? + SystemEnv.getHtmlLabelName(236, user.getLanguage()) : defaultRejectName; // 退回 + } + + String submitBtnHtml = ""; + EmailApprovalService emailApprovalService = new EmailApprovalService(); + Map emailApproveParams = new HashMap<>(); + emailApproveParams.put("nodeId", nodeId); + emailApproveParams.put("userId", userId); + emailApproveParams.put("reqId", requestId); + emailApproveParams.put("judgeFormMustInput", "1"); + + if (nodetype == 1) { + emailApproveParams.put("src", RequestEmailApproveBiz.SUBMIT); + String submitParams = this.getEmailApproveParams(emailApproveParams); + String encryptString = String.format(APPROVE_PARAM, submitParams); + submitBtnHtml = emailApprovalService.getRequestSubmitBtnHtml(requestnamenew, encryptString, submitname, languageId); + + emailApproveParams.put("src", RequestEmailApproveBiz.REJECT); + submitParams = this.getEmailApproveParams(emailApproveParams); + encryptString = String.format(APPROVE_PARAM, submitParams); + String rejectBtnHtml = emailApprovalService.getRequestRejectBtnHtml(requestnamenew, encryptString, rejectName, languageId); + submitBtnHtml += "   " + rejectBtnHtml; + } else if (nodetype == 2 || nodetype == 0) { + emailApproveParams.put("src", RequestEmailApproveBiz.SUBMIT); + String submitParams = this.getEmailApproveParams(emailApproveParams); + String encryptString = String.format(APPROVE_PARAM, submitParams); + submitBtnHtml = emailApprovalService.getRequestSubmitBtnHtml(requestnamenew, encryptString, submitname, languageId); + } + + fieldDatas.put(SYSTEM_FIELD_APPROVE_BTN, submitBtnHtml); + } + return fieldDatas; + } + + /** + * 邮件审批参数 + * + * @param params + * @return + */ + private String getEmailApproveParams(Map params) { + + Map requestParam = CommandExecutorUtil.execute(new GetEmailApproveParamCmd(user, params)); + String paramJsonStr = JSONObject.toJSONString(requestParam); + paramJsonStr = Base64.getEncoder().encodeToString(paramJsonStr.getBytes(StandardCharsets.UTF_8)); + + return paramJsonStr; + } + + /** + * @param requestNameNew + * @param requestId + * @return + */ + public String parseEmailLink(String requestNameNew, String requestId) { + + Map result = CommandExecutorUtil.execute(new GetEmailRemindUrlCmd(user, null, requestId, requestNameNew)); + + return (String) result.get("url"); + } + + /** + * 获取字段值 + */ + private String getFiledValue(int isbill, int formId, int requestId, String tempField) { + + String fieldValue = ""; + + String tablename = ""; + RecordSet rs1 = new RecordSet(); + RecordSet rs2 = new RecordSet(); + RecordSet rs3 = new RecordSet(); + if (isbill == 0) { + rs1.executeQuery("select workflow_formdict.fieldname,workflow_fieldlable.fieldlable,fieldhtmltype,type,workflow_formdict.fielddbtype from workflow_formdict,workflow_fieldlable where workflow_formdict.id=" + tempField + " and workflow_formdict.id=workflow_fieldlable.fieldid and workflow_fieldlable.formid= ? and langurageid= ?", formId, user.getLanguage()); + } else { + rs1.execute("select fieldname,fieldlabel,fieldhtmltype,type,fielddbtype from workflow_billfield where id=" + tempField); + } + if (rs1.next()) { + String tempLabel = rs1.getString(2); + String htmtype = rs1.getString(3); + String types = rs1.getString(4); + String fielddbtype = rs1.getString(5); + if (isbill == 1) { + tempLabel = SystemEnv.getHtmlLabelName(Util.getIntValue(tempLabel, -1), user.getLanguage()); + rs2.executeQuery("select tablename from workflow_bill where id = ?", formId); + if (rs2.next()) { + tablename = rs2.getString(1); + } + } + if ("7".equals(htmtype)) { + rs3.executeQuery("select type,fieldid,displayname,linkaddress,descriptivetext from workflow_specialfield a, workflow_billfield b where a.fieldid = b.id and a.isform='0' and a.isbill='1' and a.fieldid=?", tempField); + while (rs3.next()) { + int type = rs3.getInt("type"); + String tempValue = ""; + if (type == 1) { + tempValue = rs3.getString("displayname"); // 标题处舍去超链接 + } else { + tempValue = rs3.getString("descriptivetext"); + } + if (!tempValue.equals("")) { + if (fieldValue.equals("")) { + fieldValue = tempValue; + } else { + fieldValue = fieldValue + "," + tempValue; + } + } + } + } else { + if (!"".equals(tablename)) { + rs1.execute("select " + rs1.getString(1) + " from " + tablename + " where requestid=" + requestId); + rs1.isAutoDecrypt(false); + if (rs1.next()) { + + String tempValue = rs1.getString(1); + tempValue = EncryptConfigBiz.forceFormatDecryptData(tempValue); + if (htmtype.equals("3") && ("402".equals(types) || "403".equals(types))) { + return tempValue; + } else if (htmtype.equals("3") && types.equals("290")) { + if (!Strings.isNullOrEmpty(tempValue)) { + fieldValue = Strings.isNullOrEmpty(fieldValue) ? tempValue : fieldValue + ", " + tempValue; + } + } else if (htmtype.equals("3") && (types.equals("161") || types.equals("162"))) { + try { + ArrayList tempshowidlist = Util.TokenizerString(tempValue, ","); + tempValue = ""; + Browser browser = (Browser) StaticObj.getServiceByFullname(fielddbtype, Browser.class); + for (Object k : tempshowidlist) { + try { + BrowserBean bb = browser.searchById(String.valueOf(k)); + String name = Util.null2String(bb.getName()); + if (tempValue.equals("")) { + tempValue += name; + } else { + tempValue += " " + name; + } + } catch (Exception e) { + } + + } + } catch (Exception ee) { + } + + } else if (htmtype.equals("3") || htmtype.equals("6") || htmtype.equals("5")) { + try { + RequestDoc rd = new RequestDoc(); + tempValue = rd.getFieldValue(htmtype, types, tempValue, user.getLanguage(), tempField, "" + isbill, fielddbtype, ""); + } catch (Exception ee) { + } + + } else if (htmtype.equals("9")) { + if (!tempValue.equals("")) { + String lastAddr = ""; + String[] fields; + String[] locations = tempValue.split(LocateUtil.SPLIT_LOCATION); + for (int i = locations.length - 1; i >= 0; i--) { + if (locations[i].equals("")) { + continue; + } + fields = locations[i].split(LocateUtil.SPLIT_FIELD); + if (fields.length > 3 && !fields[3].equals("")) { + lastAddr = fields[3]; + break; + } + } + tempValue = lastAddr; + } + } + if (!(rs1.getString(1)).equals("") && !(htmtype.equals("3") && types.equals("290"))) { + if (!(htmtype.equals("9") && tempValue.equals(""))) { + fieldValue = Strings.isNullOrEmpty(fieldValue) ? tempValue : fieldValue + ", " + tempValue; + } + } + } + } + } + } + return Util.formatStringIfMultilang(fieldValue); + } + + /** + * 通过邮件方式发送提醒 + * + * @param sendUsers + * @param title + * @param content + */ + private void sendEmail(String sendUsers, String title, String content, String requestId, String allAttchment) { + + this.printLog("Request Email remind info:user=" + sendUsers + ";title=" + title + ";requestId=" + requestId); + if (Strings.isNullOrEmpty(sendUsers)) return; + + RecordSet rs = new RecordSet(); + + // 流程测试 + rs.executeQuery("select 1 from workflow_requestbase where requestid = ? and (deleted = 0 or deleted is null)", requestId); + if (!rs.next()) return; + Set mailAddress = new HashSet(); + rs.executeQuery("select hr.email from HrmResource hr where status in (0,1,2,3) AND " + Util.getSubINClause(sendUsers, "id", "in")); + while (rs.next()) { + String email = Util.null2String(rs.getString("email")); + if (!Strings.isNullOrEmpty(email)) { + mailAddress.add(email); + } + } + /* ******************* youhong.ai 添加发送邮箱的黑名单拓展start ******************* */ + for (BlackListExpansion blackListExpansion : BlackListRegister.getExpansionList()) { + Set mailAddress1 = blackListExpansion.sendEmailHandler(mailAddress); + if (Objects.nonNull(mailAddress1)) { + mailAddress = mailAddress1; + } + } + /* ******************* youhong.ai 添加发送邮箱的黑名单拓展 end ******************* */ + if (mailAddress.isEmpty()) return; + EmailWorkRunnable.threadModeReminder(String.join(",", mailAddress), "", "", title, content, allAttchment); + } + + /** + * 发送审批邮件 + * + * @param sendUsers + * @param title + * @param content + */ + private void sendEmail4Approve(String sendUsers, String title, String content, String requestId, String allAttchment) { + + this.printLog("Request Email approve info:user=" + sendUsers + ";title=" + title + ";requestId=" + requestId); + if (Strings.isNullOrEmpty(sendUsers)) return; + + RecordSet rs = new RecordSet(); + + // 流程测试 + rs.executeQuery("select 1 from workflow_requestbase where requestid = ? and (deleted = 0 or deleted is null)", requestId); + if (!rs.next()) return; + Set mailAddress = new HashSet(); + rs.executeQuery("select hr.email from HrmResource hr where status in (0,1,2,3) AND " + Util.getSubINClause(sendUsers, "id", "in")); + while (rs.next()) { + String email = Util.null2String(rs.getString("email")); + if (!Strings.isNullOrEmpty(email)) { + mailAddress.add(email); + } + } + /* ******************* youhong.ai 添加发送邮箱的黑名单拓展start ******************* */ + for (BlackListExpansion blackListExpansion : BlackListRegister.getExpansionApproveList()) { + Set mailAddress1 = blackListExpansion.sendEmailHandler(mailAddress); + if (Objects.nonNull(mailAddress1)) { + mailAddress = mailAddress1; + } + } + /* ******************* youhong.ai 添加发送邮箱的黑名单拓展 end ******************* */ + EmailApprovalRunnable.threadModeReminder(String.join(",", mailAddress), title, content, String.valueOf(requestId), allAttchment); + } + + /** + * 通过短信方式发送提醒 + * + * @param sendUsers 提醒人员 + * @param content 提醒内容 + * @param requestId + */ + private void sendSMS(String sendUsers, String content, String requestId) { + this.printLog("Request SMS remind info:user=" + sendUsers + ";title=" + content + ";requestId=" + requestId); + if (Strings.isNullOrEmpty(sendUsers)) return; + try { + content = content.replaceAll("<", "<").replaceAll(">", ">"); + RecordSet rs = new RecordSet(); + // 流程测试 + rs.executeQuery("select 1 from workflow_requestbase where requestid = ? and (deleted = 0 or deleted is null)", requestId); + if (!rs.next()) return; + + rs.executeQuery("select hr.id,hr.mobile from HrmResource hr where status in (0,1,2,3) AND " + Util.getSubINClause(sendUsers, "id", "in")); + Set sendUserPhone = new HashSet<>(); + while (rs.next()) { + + String userId = Util.null2String(rs.getString("id")); + String userPhone = Util.null2String(rs.getString("mobile")); + + if (sendUserPhone.contains(userPhone) || Strings.isNullOrEmpty(userPhone)) continue; + sendUserPhone.add(userPhone); + SMSSaveAndSend smsSaveAndSend = new SMSSaveAndSend(); + smsSaveAndSend.setMessage(SmsSendUtil.getSignMessage(user, content)); + smsSaveAndSend.setRechrmnumber(userPhone); + smsSaveAndSend.setReccrmnumber(""); + smsSaveAndSend.setCustomernumber(""); + + smsSaveAndSend.setRechrmids(userId); + smsSaveAndSend.setReccrmids(""); + smsSaveAndSend.setSendnumber(""); + smsSaveAndSend.setRequestid(Integer.parseInt(requestId)); + smsSaveAndSend.setUserid(user.getUID()); + smsSaveAndSend.setUsertype(user.getLogintype()); + smsSaveAndSend.setFrommould(SmsFromMouldEnum.WORKFLOW); + smsSaveAndSend.send(); + } + } catch (Exception e) { + } + } + + /** + * 流程提交不流转到下一节点,判断会签、依次逐个处理、循环上级审批 + * + * @param requestid + * @param userid + * @param wfId + * @param src + * @param isDefaultSmsRemind + * @param isDefaultEmailRemind + */ + public void doRemind(int requestid, int userid, int wfId, String src, String isDefaultSmsRemind, String isDefaultEmailRemind) { + RecordSet rs = new RecordSet(); + this.printLog("9、doRemind start requestId:" + requestid); + rs.executeQuery("select detailInfo from workflow_requestoperatelog where requestid = ? and operatorid = ? order by operatedate desc,operatetime desc", requestid, userid); + if (rs.next()) { + String detailInfo = Util.null2String(rs.getString("detailInfo")); + JSONObject jsonObject = JSONObject.parseObject(detailInfo); + JSONObject operators = null; + if (jsonObject != null) operators = jsonObject.getJSONObject("workflow_currentoperator"); + if (operators != null) { + String newIds = operators.getString("newIds"); + if (!Strings.isNullOrEmpty(newIds)) { + Set userIds = new HashSet<>(); + rs.executeQuery("select userid from workflow_currentoperator where " + Util.getSubINClause(newIds, "id", "IN")); + while (rs.next()) { + userIds.add(Util.null2String(rs.getString("userid"))); + } + Map params = new HashMap<>(); + params.put("reminder", String.join(",", userIds)); + params.put("requestId", requestid); + params.put("workflowId", wfId); + params.put("submitType", src); + if ("1".equals(isDefaultSmsRemind)) this.requestRemind(params, RemindTypeEnum.SMS); + if ("1".equals(isDefaultEmailRemind)) this.requestRemind(params, RemindTypeEnum.EMAIL); + } + } + } + } + + public static void updateRemindTypes(String remindTypes, int requestid) { + RecordSet recordSet = new RecordSet(); + recordSet.executeUpdate("update workflow_requestbase set remindTypes=? where requestid = ?", remindTypes, requestid); + } + + /** + * 获取主表字段方法供提醒内容设置界面使用,默认增加(流程标题)这个系统字段 + * + * @return + */ + public List> getMainFields(String workflowId) { + + int isBill = -1; + int formId = -1; + + RecordSet rs = new RecordSet(); + String sql = "SELECT formid , isbill FROM workflow_base WHERE id = ?"; + rs.executeQuery(sql, workflowId); + if (rs.next()) { + isBill = rs.getInt("isBill"); + formId = rs.getInt("formId"); + } + + List> fields = new ArrayList<>(); + // 系统字段请求标题 + Map requestTitle = new HashMap<>(); + requestTitle.put("key", SYSTEM_FIELD_TITLE); + requestTitle.put("showname", SystemEnv.getHtmlLabelName(26876, user.getLanguage())); + requestTitle.put("multClickable", true); + requestTitle.put("clickable", true); + + fields.add(requestTitle); + + Map requestTitleLink = new HashMap<>(); + requestTitleLink.put("key", SYSTEM_FIELD_TITLE_LINK); + requestTitleLink.put("showname", SystemEnv.getHtmlLabelName(391184, user.getLanguage())); + requestTitleLink.put("multClickable", true); + requestTitleLink.put("clickable", true); + fields.add(requestTitleLink); + + Map emergencyLevel = new HashMap<>(); + emergencyLevel.put("key", SYSTEM_FIELD_LEVEL); + emergencyLevel.put("showname", SystemEnv.getHtmlLabelName(15534, user.getLanguage())); + emergencyLevel.put("multClickable", true); + emergencyLevel.put("clickable", true); + fields.add(emergencyLevel); + + Map createDate = new HashMap<>(); + createDate.put("key", SYSTEM_FIELD_CREATEDATA); + createDate.put("showname", SystemEnv.getHtmlLabelName(502863, user.getLanguage())); + createDate.put("multClickable", true); + createDate.put("clickable", true); + fields.add(createDate); + + Map field = null; + // 主表字段 + if (isBill == 1) { + sql = "SELECT " + + " f.id, f.fieldname," + + " l.labelname " + + " FROM " + + " workflow_billfield f " + + " LEFT JOIN ( SELECT * FROM HTMLLABELInfo WHERE languageid = ? ) l ON f.fieldlabel= l.indexid " + + "WHERE " + + " f.billid = ? " + + " AND f.viewtype = 0"; + rs.executeQuery(sql, user.getLanguage(), formId); + } else { + rs.executeQuery("select fd.id,fd.fieldname,fd.description as labelname from workflow_formfield ff,workflow_formdict fd where ff.formid = ? and ff.fieldid = fd.id", formId); + } + while (rs.next()) { + int fieldId = Util.getIntValue(Util.null2String(rs.getString("id"))); + String fieldName = Util.null2String(rs.getString("labelname")); + if (Strings.isNullOrEmpty(fieldName)) { + fieldName = Util.null2String(rs.getString("fieldname")); + } + field = new HashMap<>(); + field.put("key", String.format("${fieldid_%s}", fieldId)); + field.put("showname", Util.formatMultiLang(fieldName)); + field.put("multClickable", true); + field.put("clickable", true); + fields.add(field); + } + + return fields; + } + + /** + * @param workflowId + * @return + */ + public List> getMainFields4EmailApprove(String workflowId) { + + List> mainFields = getMainFields(workflowId); + + // 增加流程审批按钮 + Map emailApproveBtn = new HashMap<>(); + emailApproveBtn.put("key", SYSTEM_FIELD_APPROVE_BTN); + emailApproveBtn.put("showname", SystemEnv.getHtmlLabelName(527685, user.getLanguage())); + emailApproveBtn.put("clickable", false); + emailApproveBtn.put("multClickable", false); + mainFields.add(emailApproveBtn); + + return mainFields; + } + + /** + * 下一节点中,除去自动审批的节点(自动审批节点不需要提醒) + * + * @param requestManager + * @return + */ + public Set remindNodes(RequestManager requestManager) { + + List nextNodeids = requestManager.getNextnodeids(); + Map nodeInfoCache = requestManager.getNodeInfoCache(); + Set nodeInfoCacheKey = nodeInfoCache.keySet(); + + Set nodeIds = new HashSet<>(); + for (Object id : nextNodeids) { + int intId = Util.getIntValue((String) id); + boolean exists = false; + for (Integer cacheId : nodeInfoCacheKey) { + if (cacheId == intId) { + exists = true; + break; + } + } + if (!exists) { + nodeIds.add(String.valueOf(intId)); + } + } + + return nodeIds; + } + + /** + * 处理特殊字符 + * + * @param sourceStr + * @return + */ + public static String parseSpecialChar(String sourceStr) { + + return sourceStr.replace("\\", "\\\\") + .replace("$", "\\$") + .replace("{", "\\{") + .replace("}", "\\}") + .replace("*", "\\*") + .replace("[", "\\[") + .replace("]", "\\]") + .replace("(", "\\(") + .replace(")", "\\)") + .replace(".", "\\.") + .replace("+", "\\+"); + } + + /** + * 流程表单转PDF + * TODO 模板ID + * + * @param requestid + * @param keepsign 保留签字意见 + * @param modeid 模板ID + * @return + */ + private String getRequestFormPdf(String requestid, int keepsign, int modeid) { + WfToDocUtil wfdocUtil = new WfToDocUtil(); + Map params = new HashMap(); + params.put("requestid", requestid); + params.put("onlyHtml", 0); + params.put("keepsign", keepsign); + Map modeImage = wfdocUtil.getFileId(params, user); + return Util.null2String(modeImage.get("pdf")); + } + + /** + * 获取流程主表附件字段 + * TODO 明细表附件字段、签字意见附件 + * + * @param requestid + * @return + */ + private Set getRequestAttachment(String requestid, String wfId) { + + Set attachmentId = new HashSet<>(); + // 判断老表单还是新表单 + RecordSet rs = new RecordSet(); + rs.executeQuery("select isbill,formid from workflow_base where id=?", wfId); + int isBill = 0; + int formid = -1; + if (rs.next()) { + isBill = Util.getIntValue(Util.null2String(rs.getString("isbill"))); + formid = Util.getIntValue(Util.null2String(rs.getString("formid"))); + } + if (isBill == 1) { + Set fieldName = new HashSet<>(); + rs.executeQuery("select fieldname from workflow_billfield where billid = ? and fieldhtmltype = 6 and viewtype= 0", formid); + while (rs.next()) { + fieldName.add(rs.getString("fieldname")); + } + if (!fieldName.isEmpty()) { + rs.executeQuery("select tablename from workflow_bill where id = ?", formid); + rs.next(); + String tablename = rs.getString("tablename"); + String columns = String.join(",", fieldName); + rs.executeQuery("select " + columns + " from " + tablename + " where requestid = ?", requestid); + rs.next(); + String[] columnName = rs.getColumnName(); + for (String col : columnName) { + attachmentId.add(rs.getString(col)); + } + } + } else { + Set fieldName = new HashSet<>(); + rs.executeQuery("select fd.fieldname from workflow_formfield ff,workflow_formdict fd where ff.formid = ? and ff.fieldid = fd.id and ff.isdetail<>1 and fd.fieldhtmltype = 6", formid); + while (rs.next()) { + fieldName.add(rs.getString("fieldname")); + } + if (!fieldName.isEmpty()) { + String columns = String.join(",", fieldName); + rs.executeQuery("select " + columns + " from workflow_form where requestid = ?", requestid); + rs.next(); + String[] columnName = rs.getColumnName(); + for (String col : columnName) { + attachmentId.add(rs.getString(col)); + } + } + } + String docIds = String.join(",", attachmentId); + this.printLog(requestid + " --getRequestAttachment--" + docIds); + Set imagefileId = new HashSet<>(); + if (Strings.isNullOrEmpty(docIds)) return imagefileId; + rs.executeQuery("select imagefileid from docimagefile where " + Util.getSubINClause(docIds, "docid", "in")); + while (rs.next()) { + imagefileId.add(rs.getString(1)); + } + this.printLog(requestid + " --getRequestAttachment--" + String.join(",", imagefileId)); + return imagefileId; + } + + private boolean isArchiveNoRemind(String wfId, String requestId, RecordSet rs) { + + rs.executeQuery("select 1 from workflow_base where id = ? and remindscope = 1", wfId); + if (rs.next()) { + return false; + } + + WFManager wfManager = RequestRemindBiz.getWfInfo(wfId); + int notRemindifArchived = Util.getIntValue(wfManager.getNotRemindifArchived(), 0); + int archiveNoMailAlert = Util.getIntValue(wfManager.getArchiveNoMailAlert(), 0); + int archiveNoMsgAlert = Util.getIntValue(wfManager.getArchiveNoMsgAlert(), 0); + int isArchiveNoRemind = Util.getIntValue(wfManager.getIsArchiveNoRemind(), 0); + + isArchiveNoRemind += (notRemindifArchived + archiveNoMailAlert + archiveNoMsgAlert); + if (isArchiveNoRemind > 0) { + this.printLog("5、requestRemind isArchiveNoRemind. requestId:" + requestId); + rs.executeQuery("select 1 from workflow_requestbase where requestid=? and currentnodetype = '3' ", requestId); + return rs.next(); + } + return false; + } + + /** + * 当前操作是否为审批行为 + * + * @param submitType + * @return + */ + private boolean isApproveAction(String submitType) { + return (submitType.equals(RemindTypeEnum.APPROVAL.getCode()) + || submitType.equals(RemindTypeEnum.BACK.getCode()) + || submitType.equals(RemindTypeEnum.CONFIRM.getCode())); + } + + /** + * 提醒节点是否有邮件审批 + * + * @param submitType + * @param wfId + * @param nodeId + * @return + */ + private boolean isEmailApprove(String submitType, String wfId, String nodeId) { + boolean isApproveAction = this.isApproveAction(submitType); + RecordSet rs = new RecordSet(); + rs.executeQuery("select isEMailApprove,nodescope from wf_emailapprove_set where workflowId = ? ", wfId); + if (rs.next()) { + int isEMailApprove = rs.getInt(1); + int nodescope = rs.getInt(2); + if (isEMailApprove == 0) return false; + if (isEMailApprove == 1 && isApproveAction) { + if (nodescope == 0) return true; + rs.executeQuery("select 1 from wf_emailapprove_content where workflowid = ? and nodeid = ? ", wfId, nodeId); + return rs.next(); + } + } + return false; + } + + + private void printLog(String info) { + String threadName = Thread.currentThread().getName(); + log.info(threadName + "--" + info); + } +} diff --git a/src/main/java/com/engine/youhong/ai/taibao/email/BlackListExpansion.java b/src/main/java/com/engine/youhong/ai/taibao/email/BlackListExpansion.java new file mode 100644 index 0000000..986f2bf --- /dev/null +++ b/src/main/java/com/engine/youhong/ai/taibao/email/BlackListExpansion.java @@ -0,0 +1,21 @@ +package com.engine.youhong.ai.taibao.email; + +import java.util.Set; + +/** + *

黑名单扩展接口

+ * + *

create: 2023/4/14 17:07

+ * + * @author youHong.ai + */ +public interface BlackListExpansion { + + /** + *

发送邮件

+ * + * @param mailAddress 邮箱地址 + * @return 邮箱地址 + */ + Set sendEmailHandler(Set mailAddress); +} diff --git a/src/main/java/com/engine/youhong/ai/taibao/email/BlackListRegister.java b/src/main/java/com/engine/youhong/ai/taibao/email/BlackListRegister.java new file mode 100644 index 0000000..4d63bd3 --- /dev/null +++ b/src/main/java/com/engine/youhong/ai/taibao/email/BlackListRegister.java @@ -0,0 +1,38 @@ +package com.engine.youhong.ai.taibao.email; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + *

注册信息

+ * + *

create: 2023/4/14 17:09

+ * + * @author youHong.ai + */ +public class BlackListRegister { + + private static final List EXPANSION_LIST = new ArrayList<>(); + private static final List EXPANSION_APPROVE_LIST = new ArrayList<>(); + + public static void registerExpansion(BlackListExpansion blackListExpansion) { + if (Objects.nonNull(blackListExpansion)) { + EXPANSION_LIST.add(blackListExpansion); + } + } + + public static void registerAPPROVEExpansion(BlackListExpansion blackListExpansion) { + if (Objects.nonNull(blackListExpansion)) { + EXPANSION_APPROVE_LIST.add(blackListExpansion); + } + } + + public static List getExpansionList() { + return EXPANSION_LIST; + } + + public static List getExpansionApproveList() { + return EXPANSION_APPROVE_LIST; + } +} diff --git a/src/main/java/com/engine/youhong/ai/taibao/email/impl/InitBlackListServiceImpl.java b/src/main/java/com/engine/youhong/ai/taibao/email/impl/InitBlackListServiceImpl.java new file mode 100644 index 0000000..cb6e5e6 --- /dev/null +++ b/src/main/java/com/engine/youhong/ai/taibao/email/impl/InitBlackListServiceImpl.java @@ -0,0 +1,64 @@ +package com.engine.youhong.ai.taibao.email.impl; + +import aiyh.utils.Util; +import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil; +import com.engine.youhong.ai.taibao.email.BlackListRegister; +import com.engine.youhong.ai.taibao.email.mapper.InitBlackEmailListMapper; +import com.weaverboot.frame.ioc.anno.classAnno.WeaSysInitComponent; +import com.weaverboot.frame.ioc.anno.methodAnno.WeaSysInit; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + *

初始化扩展信息

+ * + *

create: 2023/4/14 17:15

+ * + * @author youHong.ai + */ + +@WeaSysInitComponent("注册email黑名单拦截器") +public class InitBlackListServiceImpl { + + private final InitBlackEmailListMapper mapper = Util.getMapper(InitBlackEmailListMapper.class); + + @WeaSysInit(order = 1, description = "注册拦截邮箱黑名单") + public void init() { + Util.getLogger().info("注册拦截邮箱黑名单,init"); + BlackListRegister.registerExpansion(set -> { + if (Objects.isNull(set)) { + return null; + } + List hrmList = mapper.selectWorkflowBlackEmailList(); + String ids = Util.join(hrmList, ","); + List blackEmailList = mapper.selectEmailListByHrmIds(ids); + if (CollectionUtil.isEmpty(blackEmailList)) { + return set; + } + return set.stream() + .filter(item -> !blackEmailList.contains(item)) + .collect(Collectors.toSet()); + }); + } + + @WeaSysInit(order = 2, description = "注册拦截邮箱黑名单") + public void initApprove() { + Util.getLogger().info("注册拦截邮箱黑名单,initApprove"); + BlackListRegister.registerAPPROVEExpansion(set -> { + if (Objects.isNull(set)) { + return null; + } + String ids = mapper.selectWorkflowApproveBlackEmailList(); + List blackEmailList = mapper.selectEmailListByHrmIds(ids); + if (CollectionUtil.isEmpty(blackEmailList)) { + return set; + } + return set.stream() + .filter(item -> !blackEmailList.contains(item)) + .collect(Collectors.toSet()); + }); + } + +} diff --git a/src/main/java/com/engine/youhong/ai/taibao/email/mapper/InitBlackEmailListMapper.java b/src/main/java/com/engine/youhong/ai/taibao/email/mapper/InitBlackEmailListMapper.java new file mode 100644 index 0000000..cb23cce --- /dev/null +++ b/src/main/java/com/engine/youhong/ai/taibao/email/mapper/InitBlackEmailListMapper.java @@ -0,0 +1,44 @@ +package com.engine.youhong.ai.taibao.email.mapper; + +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; + +import java.util.List; + +/** + *

+ * + *

create: 2023/4/14 17:20

+ * + * @author youHong.ai + */ +@SqlMapper +public interface InitBlackEmailListMapper { + + + /** + *

查询流程黑名单

+ * + * @return email黑名单 + */ + @Select("select black_hrm from uf_black_email_conf where type = 0") + List selectWorkflowBlackEmailList(); + + /** + *

查询流程黑名单

+ * + * @return email黑名单 + */ + @Select("select email from uf_black_email_conf where type = 1") + String selectWorkflowApproveBlackEmailList(); + + + /** + *

根据人员id查询邮件id

+ * + * @param ids 人员ids + * @return 邮件列表 + */ + @Select("select email from hrmresource where id in ($t{ids})") + List selectEmailListByHrmIds(String ids); +} diff --git a/src/main/java/weaver/xiao/commons/config/enumtype/GetValueTypeEnum.java b/src/main/java/weaver/xiao/commons/config/enumtype/GetValueTypeEnum.java index 51727d2..1b27887 100644 --- a/src/main/java/weaver/xiao/commons/config/enumtype/GetValueTypeEnum.java +++ b/src/main/java/weaver/xiao/commons/config/enumtype/GetValueTypeEnum.java @@ -10,35 +10,47 @@ import java.util.Map; */ public enum GetValueTypeEnum { - - WORKFLOW_FIELD("0"), - DEFAULT_VALUE("1"), - CURRENT_TIME("3"), - CUS_SQL("4"), - REQUEST_ID("5"), - MAIN_DATA_ID("6"), - RANDOM("7"), - ATTACHMENT("8"), - - CUS_INTERFACE("9"), - - CUS_FIELD("10"); - - private static final Map LOOK_UP = new HashMap<>(8); - - static { - for (GetValueTypeEnum getValueTypeEnum : EnumSet.allOf(GetValueTypeEnum.class)) { - LOOK_UP.put(getValueTypeEnum.value, getValueTypeEnum); - } - } - - public final String value; - - GetValueTypeEnum(String value) { - this.value = value; - } - - public static GetValueTypeEnum getEnum(String value) { - return LOOK_UP.get(value); - } + /** 流程字段 */ + WORKFLOW_FIELD("0"), + /** 默认值 */ + DEFAULT_VALUE("1"), + /** 当前时间 */ + CURRENT_TIME("3"), + /** 自定义sql */ + CUS_SQL("4"), + /** 流程请求id */ + REQUEST_ID("5"), + /** 主表数据id */ + MAIN_DATA_ID("6"), + /** 随机值 */ + RANDOM("7"), + /** 附件 */ + ATTACHMENT("8"), + /** 自定义接口 */ + + CUS_INTERFACE("9"), + + /** 自定义字段 */ + CUS_FIELD("10"), + + /** 自定义mapper sql */ + CUS_MAPPER_SQL("11"); + + private static final Map LOOK_UP = new HashMap<>(8); + + static { + for (GetValueTypeEnum getValueTypeEnum : EnumSet.allOf(GetValueTypeEnum.class)) { + LOOK_UP.put(getValueTypeEnum.value, getValueTypeEnum); + } + } + + public final String value; + + GetValueTypeEnum(String value) { + this.value = value; + } + + public static GetValueTypeEnum getEnum(String value) { + return LOOK_UP.get(value); + } } diff --git a/src/main/java/weaver/xiao/commons/config/mapper/DealWithMapper.java b/src/main/java/weaver/xiao/commons/config/mapper/DealWithMapper.java new file mode 100644 index 0000000..bd4684b --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/mapper/DealWithMapper.java @@ -0,0 +1,21 @@ +package weaver.xiao.commons.config.mapper; + +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; +import aiyh.utils.annotation.recordset.SqlString; + +import java.util.Map; + +/** + *

+ * + *

create: 2023/4/17 22:21

+ * + * @author youHong.ai + */ +@SqlMapper +public interface DealWithMapper { + + @Select(custom = true) + String selectCustomSql(@SqlString String sql, Map params); +} 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 1219d1e..956879a 100644 --- a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java +++ b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java @@ -15,6 +15,7 @@ import weaver.xiao.commons.config.enumtype.GetValueTypeEnum; import weaver.xiao.commons.config.enumtype.ParamTypeEnum; import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue; import weaver.xiao.commons.config.interfacies.CusInterfaceListValue; +import weaver.xiao.commons.config.mapper.DealWithMapper; import weaver.xiao.commons.exception.ValueDealException; import weaver.zwl.common.ToolUtil; @@ -57,6 +58,16 @@ public class DealWithMapping extends ToolUtil { private RecordSet tempRs; + private DealWithMapper mapper = null; + + { + try { + mapper = aiyh.utils.Util.getMapper(DealWithMapper.class); + } catch (Exception e) { + this.writeErrorLog("缺少 aiyh_utils.jar依赖,初始化失败!"); + } + } + /** *

将日期字符串转换为Date对象

* @@ -123,9 +134,9 @@ public class DealWithMapping extends ToolUtil { */ String val = Util.null2String(rs.getString(i)); BigDecimal decimal; - if(StringUtils.isBlank(val)){ + if (StringUtils.isBlank(val)) { decimal = new BigDecimal("0"); - }else { + } else { decimal = new BigDecimal(val); } map.put(key, decimal); @@ -748,6 +759,16 @@ public class DealWithMapping extends ToolUtil { value = detailMap.get(valueContext.trim()); } break; + case CUS_MAPPER_SQL: { + Map param = new HashMap<>(); + param.put("main", mainMap); + param.put("dt", detailMap); + if (mapper == null) { + throw new RuntimeException("缺少 aiyh_utils.jar依赖,无法使用mapper!"); + } + value = mapper.selectCustomSql(valueContext, param); + } + break; default: throw new ValueDealException("不支持的取值方式"); } @@ -1088,6 +1109,16 @@ public class DealWithMapping extends ToolUtil { } } break; + case CUS_MAPPER_SQL: { + Map param = new HashMap<>(); + param.put("main", mainMap); + param.put("dt", detailMap); + if (mapper == null) { + throw new RuntimeException("缺少 aiyh_utils.jar依赖,无法使用mapper!"); + } + value = mapper.selectCustomSql(valueContext, param); + } + break; default: throw new ValueDealException("不支持的取值方式"); } diff --git a/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/VoucherPayableAction.java b/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/VoucherPayableAction.java index 8ed33c8..a0d146d 100644 --- a/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/VoucherPayableAction.java +++ b/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/VoucherPayableAction.java @@ -72,6 +72,16 @@ public class VoucherPayableAction extends SafeCusBaseAction { @RequiredMark("ip") private String ip; + + @PrintParamMark + @RequiredMark("应付凭证远程文件名称前缀") + private String pavFileName; + + + @PrintParamMark + @RequiredMark("付款凭证远程文件名称前缀") + private String pmvFileName; + @PrintParamMark @ActionOptionalParam(desc = "是否删除生成的临时本地文件,true - 删除 false - 不删除", value = "false") private String deleteTemp = "false"; @@ -86,10 +96,10 @@ public class VoucherPayableAction extends SafeCusBaseAction { String fileName = ""; String remotePath = ""; if (Integer.parseInt(voucherType) == 1) { - fileName = "Pav" + Util.getTime("yyyyMMddHHmmss") + ".txt"; + fileName = pavFileName + Util.getTime("yyyyMMddHHmmssSSSS") + ".txt"; remotePath = pavRemotePath; } else if (Integer.parseInt(voucherType) == 2) { - fileName = "Pmv" + Util.getTime("yyyyMMddHHmmss") + ".txt"; + fileName = pmvFileName + Util.getTime("yyyyMMddHHmmssSSSS") + ".txt"; remotePath = pmvRemotePath; } log.info("远程连接地址:" + "smb://" + ip + remotePath); diff --git a/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/VoucherPayableNewAction.java b/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/VoucherPayableNewAction.java new file mode 100644 index 0000000..7fbe5fa --- /dev/null +++ b/src/main/java/weaver/youhong/ai/haripijiu/action/sapdocking/VoucherPayableNewAction.java @@ -0,0 +1,246 @@ +package weaver.youhong.ai.haripijiu.action.sapdocking; + +import aiyh.utils.Util; +import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.*; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.tool.cn.hutool.core.lang.Assert; +import lombok.Setter; +import org.jetbrains.annotations.NotNull; +import weaver.general.GCONST; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; +import weaver.xiao.commons.config.entity.RequestMappingConfig; +import weaver.xiao.commons.config.service.DealWithMapping; +import weaver.youhong.ai.haripijiu.action.sapdocking.util.SmbjUtil; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + *

对私凭证action

+ * + *

create: 2023/4/17 14:57

+ * + * @author youHong.ai + */ +@ActionDesc(author = "youhong.ai", value = "对私凭证action") +@Setter +public class VoucherPayableNewAction extends SafeCusBaseAction { + + + private final DealWithMapping dealWithMapping = new DealWithMapping(); + + @PrintParamMark + @RequiredMark("请求参数配置表配置唯一标识字段!") + @ActionDefaultTestValue("duisi") + private String onlyMark; + + @PrintParamMark + @ActionOptionalParam(value = "false", desc = "是否自动提交流程 false : 不提交; true : 提交") + private String submitAction = "false"; + + @PrintParamMark + @ActionOptionalParam(value = "true", desc = "是否失败后阻断流程, false : 不阻断; true: 阻断") + private String block = "true"; + + @PrintParamMark + @RequiredMark("凭证类型,1- 应付凭证; 2- 付款凭证") + private String voucherType; + + + @PrintParamMark + @RequiredMark("应付凭证远程路径") + private String pavRemotePath; + + + @PrintParamMark + @RequiredMark("付款凭证远程路径") + private String pmvRemotePath; + + @PrintParamMark + @RequiredMark("用户名") + private String userName; + + @PrintParamMark + @RequiredMark("密码") + private String password; + + + @PrintParamMark + @RequiredMark("ip") + private String ip; + + + @PrintParamMark + @RequiredMark("应付凭证远程文件名称前缀") + private String pavFileName; + + + @PrintParamMark + @RequiredMark("付款凭证远程文件名称前缀") + private String pmvFileName; + + @PrintParamMark + @ActionOptionalParam(desc = "是否删除生成的临时本地文件,true - 删除 false - 不删除", value = "false") + private String deleteTemp = "false"; + + + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + + try { + SmbjUtil smbjUtil = new SmbjUtil(); + String tempFilePath = getFile(billTable, requestInfo); + String fileName = ""; + String remotePath = ""; + if (Integer.parseInt(voucherType) == 1) { + fileName = pavFileName + Util.getTime("yyyyMMddHHmmssSSSS") + ".txt"; + remotePath = pavRemotePath; + } else if (Integer.parseInt(voucherType) == 2) { + fileName = pmvFileName + Util.getTime("yyyyMMddHHmmssSSSS") + ".txt"; + remotePath = pmvRemotePath; + } + log.info("远程连接地址:" + "smb://" + ip + remotePath); + log.info("本地文件地址: " + tempFilePath); + smbjUtil.smbPut("smb://" + ip + remotePath, tempFilePath, userName, password, fileName); + if (Boolean.parseBoolean(deleteTemp)) { + Files.delete(Paths.get(tempFilePath)); + } + /* ******************* 是否提交流程 ******************* */ + if (Boolean.parseBoolean(submitAction)) { + this.submitWorkflow(requestId, user.getUID()); + } + } catch (Exception e) { + log.error("推送应付款凭证失败!" + e.getMessage()); + if (Boolean.parseBoolean(block)) { + throw new CustomerException(e.getMessage(), e); + } + } + } + + public void submitWorkflow(String requestId, Integer userId) { + Util.submitWorkflowThread(Integer.parseInt(requestId), userId, "sap对接自动提交流程!"); + } + + private String getFile(String billTable, RequestInfo requestInfo) { + dealWithMapping.setMainTable(billTable); + RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark); + Map requestParam = dealWithMapping.getRequestParam(getObjMainTableValue(requestInfo), requestMappingConfig); + Assert.notEmpty(requestParam, "query config error, can not query result by onlyMark:[{}],Please check the configuration table", onlyMark); + // 借方 + List debit = (List) requestParam.get("debit"); + // 贷方 + List creditSide = (List) requestParam.get("creditSide"); + // 凭证头 + Map heads = (Map) requestParam.get("heads"); + Assert.notEmpty(heads, "No relevant voucher header data was found. Please check the configuration table and process table data."); + Assert.notEmpty(debit, "No relevant voucher details have been queried. Please check whether there is data in the process schedule."); + Assert.notEmpty(creditSide, "No credit data was found. Please check whether the configuration table is configured correctly and whether the process data exists."); + return createFile(debit, creditSide, heads); + } + + + private String createFile(List debit, List creditSide, Map heads) { + StringBuilder sb = new StringBuilder(); + // 写入凭证头 + List headKeys = new ArrayList<>(); + for (Map.Entry entry : heads.entrySet()) { + headKeys.add(entry.getKey()); + } + headKeys = sortKey(headKeys); + for (String headKey : headKeys) { + sb.append(heads.get(headKey)).append("\t"); + } + sb.deleteCharAt(sb.lastIndexOf("\t")); + sb.append("\r\n"); + // 写入借方信息 + writeList(debit, sb); + // 写入贷方信息 + writeList(creditSide, sb); + String filePath = getFilePath(); + try { + OutputStreamWriter out = new OutputStreamWriter( + Files.newOutputStream(Paths.get(filePath)), StandardCharsets.UTF_8); + out.write(sb.toString()); + out.close(); + + } catch (IOException e) { + throw new CustomerException(Util.logStr("can not writer file [{}]", filePath)); + } + + return filePath; + } + + private void writeList(List list, StringBuilder sb) { + Map firstMap = (Map) list.get(0); + List keys = new ArrayList<>(); + for (Map.Entry entry : firstMap.entrySet()) { + keys.add(entry.getKey()); + } + if (list.size() > 1) { + Map secondMap = (Map) list.get(1); + for (Map.Entry entry : secondMap.entrySet()) { + if (keys.contains(entry.getKey())) { + continue; + } + keys.add(entry.getKey()); + } + } + keys = sortKey(keys); + for (Object o : list) { + Map map = (Map) o; + for (String key : keys) { + if (map.containsKey(key)) { + sb.append(map.get(key)) + .append("\t"); + } + } + sb.deleteCharAt(sb.lastIndexOf("\t")); + sb.append("\r\n"); + } + } + + private List sortKey(List list) { + return list.stream() + .map(Integer::parseInt) + .sorted() + .map(Util::null2String) + .collect(Collectors.toList()); + } + + @NotNull + private String getFilePath() { + String sysFilePath = GCONST.getSysFilePath(); + String filePath; + if (sysFilePath.endsWith(File.separator)) { + filePath = sysFilePath + "cus_temp" + File.separator + "voucher-new" + File.separator + + System.currentTimeMillis() + "-voucher-new-" + UUID.randomUUID() + ".txt"; + } else { + filePath = sysFilePath + File.separator + "cus_temp" + File.separator + "voucher" + File.separator + + System.currentTimeMillis() + "-voucher-new-" + UUID.randomUUID() + ".txt"; + } + Path path = Paths.get(filePath); + if (!Files.exists(path)) { + Path parent = path.getParent(); + try { + Files.createDirectories(parent); + } catch (IOException e) { + throw new CustomerException(Util.logStr("can not create file [{}]", filePath)); + } + } + return filePath; + } + + +} diff --git a/src/test/java/youhong/ai/haripijiu/TestHaRiPiJiu.java b/src/test/java/youhong/ai/haripijiu/TestHaRiPiJiu.java index 50f1450..681fb1c 100644 --- a/src/test/java/youhong/ai/haripijiu/TestHaRiPiJiu.java +++ b/src/test/java/youhong/ai/haripijiu/TestHaRiPiJiu.java @@ -1,10 +1,12 @@ package youhong.ai.haripijiu; import aiyh.utils.GenerateFileUtil; +import aiyh.utils.Util; import basetest.BaseTest; import org.junit.Test; import weaver.youhong.ai.haripijiu.action.sapdocking.ReceiptAndPaymentAction; import weaver.youhong.ai.haripijiu.action.sapdocking.VoucherPayableAction; +import weaver.youhong.ai.haripijiu.action.sapdocking.VoucherPayableNewAction; /** *

测试

@@ -24,6 +26,7 @@ public class TestHaRiPiJiu extends BaseTest { @Test public void test1() { - + + Util.actionTest(VoucherPayableNewAction.class, 405407); } } diff --git a/src/test/java/youhong/ai/pcn/UtilTest.java b/src/test/java/youhong/ai/pcn/UtilTest.java index 1c1a056..142899d 100644 --- a/src/test/java/youhong/ai/pcn/UtilTest.java +++ b/src/test/java/youhong/ai/pcn/UtilTest.java @@ -296,4 +296,8 @@ public class UtilTest extends BaseTest { } + @Test + public void testSS() { + out.println(Util.getTime("yyyyMMddHHmmssSSSS")); + } } diff --git a/src/test/java/youhong/ai/taibao/TestTaiBao.java b/src/test/java/youhong/ai/taibao/TestTaiBao.java index 8e125c1..58a4d1c 100644 --- a/src/test/java/youhong/ai/taibao/TestTaiBao.java +++ b/src/test/java/youhong/ai/taibao/TestTaiBao.java @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONArray; import com.api.youhong.ai.taibao.fcuntionlist.service.FunctionListService; import com.api.youhong.ai.taibao.qikan.service.PeriodicalService; import com.cloudstore.dev.api.util.Util_DataCache; +import com.engine.youhong.ai.taibao.email.mapper.InitBlackEmailListMapper; import org.junit.Test; import weaver.conn.RecordSet; import weaver.general.BaseBean; @@ -158,4 +159,14 @@ public class TestTaiBao extends BaseTest { public void testTableModelId() { System.out.println(Util.getModeIdByTableName("uf_privacy_log_info")); } + + + @Test + public void testEmailSelect() { + InitBlackEmailListMapper mapper = Util.getMapper(InitBlackEmailListMapper.class); + List hrmList = mapper.selectWorkflowBlackEmailList(); + String ids = Util.join(hrmList, ","); + List strings = mapper.selectEmailListByHrmIds(ids); + System.out.println(JSON.toJSONString(strings)); + } } diff --git a/src/test/java/youhong/ai/utiltest/GenericTest.java b/src/test/java/youhong/ai/utiltest/GenericTest.java index 86a43a4..a038ea5 100644 --- a/src/test/java/youhong/ai/utiltest/GenericTest.java +++ b/src/test/java/youhong/ai/utiltest/GenericTest.java @@ -1,9 +1,11 @@ package youhong.ai.utiltest; +import aiyh.utils.GenerateFileUtil; import aiyh.utils.Util; import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil; import basetest.BaseTest; import org.junit.Test; +import weaver.youhong.ai.haripijiu.action.sapdocking.VoucherPayableNewAction; import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; @@ -82,4 +84,10 @@ public class GenericTest extends BaseTest { System.out.println(aClass); } + @Test + public void testGre() { + GenerateFileUtil.createActionDocument(VoucherPayableNewAction.class); + } + + } \ No newline at end of file