PC效果图
手机端效果图
一.添加按钮并定义按钮事件
为了批量注册到所有流程页面使用ECODE开发
1.1移动端register.js 代码
let enable = true;
const config = {
1165: {}
}
const NewForwardControl = (props, Com) => {
const acParams = {
appId: '${appId}',
name: 'CustomNewForwardControl',
isPage: true,
noCss: true
}
const AddCom = ecodeSDK.getAsyncCom(acParams);
const NewCom = Com;
return (<React.Fragment><AddCom { ...props } /> <NewCom { ...props } _noOverwrite /> </React.Fragment>);
}
ecodeSDK.overwriteMobileClassFnQueueMapSet('Tabs', {
fn: (Com, newProps) => {
if (!enable) return;
const { hash } = window.location;
if (!hash.startsWith('#/req')) return;
if (!WfForm) return;
if (!WfForm.getBaseInfo()) return;
let requestId = WfForm.getBaseInfo().requestid;
if (requestId == '' || requestId == '-1') return;
return {
com: NewForwardControl.bind(this, newProps, Com),
props: newProps
};
}
});
1.2PC端register.js 代码
ecodeSDK.overwritePropsFnQueueMapSet('WeaReqTop', {//组件名
fn: (newProps) => {
if (!checkUrl()) return;
if (!newProps.buttons) return;
const acParams = {
appId: '${appId}',
name: 'UrgeCusBtn',
isPage: false,
noCss: true,
props: {}
}
const Com = ecodeSDK.getAsyncCom(acParams);
newProps.buttons.push(Com)
},
order: 0,
desc: '添加催办按钮'
});
function checkUrl() {
if (ecodeSDK.checkLPath("/spa/workflow/static4form/index.html") && WfForm.getBaseInfo().requestid != '-1') {
return true;
}
return false;
}
2.1移动端index.js代码
const { observer, inject } = mobxReact;
const { withRouter } = ReactRouterDom;
let isRun = false
@withRouter
@inject('wfOperateStore')
@inject('wfSignInputStore')
@observer
class CustomNewForwardControl extends React.Component {
constructor(props) { //初始化,固定语法
super(props);
}
componentDidMount() {
setTimeout(() => {
if (isRun) return;
this.rewriteFn()
}, 1000);
//定义自定义点击事件
const doSomething = () => {
let requestid = WfForm.getBaseInfo().requestid;
console.log("requestid:" + requestid);
$.ajax({
url: '/OA开发文件夹/interfaces/jsp/PushOAMsg.jsp',
data: { 'requestId': requestid },
type: 'get',
success: function (res) {
if (res.success) {
WfForm.showMessage(res.msg, 3, 3);
}
}
})
}
window.doSomething = doSomething;
}
rewriteFn() {
//重写转发按钮
const { wfOperateStore } = this.props;
let { rightMenu } = wfOperateStore;
let rm = mobx.toJS(rightMenu.rightMenus);
// 新添加按钮
let newMenu = {
funParams: {},
isLockShow: false,
isMobile: true,
isPortal: true,
isTest: true,
isTop: "1",
menuFun: "doSomething()",
menuIcon: "icon-workflow-Right-menu-Preservation",
menuName: "催办", // 事件名称
order: 2,
systemMenuType: "CUSTOMIZE",
systemSmallType: 0,
type: "BTN_CUSTOMIZE",
}
//console.log(rm[0]);
//rm.splice(1, 0, newMenu)
//rm.push(newMenu)
let rmNew = [];
for (let i = 0; i < rm.length; i++) {
rmNew.push(rm[i]);
}
rmNew.push(newMenu);
//console.log(newMenu);
rightMenu.rightMenus = rmNew;
wfOperateStore.setRightMenu(mobx.toJS(rightMenu));
isRun = true;
}
componentDidUpdate() {
// this.rewriteFn();
}
render() {
console.log('render');
return (
<React.Fragment />
)
}
}
//发布模块
ecodeSDK.setCom('${appId}', 'CustomNewForwardControl', CustomNewForwardControl);
2.2PC端index.js代码
const { Button, Modal, message: Message } = antd;
const { WeaTools, WeaLoadingGlobal } = ecCom;
class UrgeCusBtn extends React.Component {
constructor(props) {
super(props);
this.state = {
};
}
callPushOAMsgApi = () => {
WeaTools.callApi("/OA开发文件夹/interfaces/jsp/PushOAMsg.jsp?requestId=" + WfForm.getBaseInfo().requestid, "GET").then(res => {
if (res.success) {
Message.success(res.msg, 3);
} else {
Message.error(res.msg, 3);
}
})
}
render() {
return (
<div>
<Button type="primary" _noOverwrite onClick={ this.callPushOAMsgApi }>催办</Button>
</div>
);
}
}
ecodeSDK.setCom('${appId}', 'UrgeCusBtn', UrgeCusBtn);
二.定义催办消息接口(PushOAMsg.jsp文件)
<%@ page import="cn.hutool.core.collection.CollUtil" %>
<%@ page import="cn.hutool.core.util.ObjectUtil" %>
<%@ page import="cn.hutool.core.util.StrUtil" %>
<%@ page import="cn.hutool.http.ContentType" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.cloudstore.dev.api.bean.MessageBean" %>
<%@ page import="com.cloudstore.dev.api.bean.MessageType" %>
<%@ page import="com.cloudstore.dev.api.util.Util_Message" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.HashSet" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.stream.Collectors" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%!
private static final BaseBean BASE_BEAN = new BaseBean();
%>
<%
JSONObject result = new JSONObject();
try {
User user = HrmUserVarify.checkUser(request, response);
if (ObjectUtil.isEmpty(user)) {
result.put("code", 500);
result.put("success", false);
result.put("msg", "人员未登录");
response.setContentType(ContentType.JSON.getValue());
response.getWriter().print(result);
return;
}
String requestId = request.getParameter("requestId");
if (StrUtil.isBlank(requestId)) {
result.put("code", 500);
result.put("success", false);
result.put("msg", "参数requestId为空!");
response.setContentType(ContentType.JSON.getValue());
response.getWriter().print(result);
return;
}
JSONObject workflowInfo = getWorkflowInfo(requestId);
BASE_BEAN.writeLog("获取到的当前流程信息:" + workflowInfo);
String currentnodetype = workflowInfo.getString("currentnodetype");
if ("0".equals(currentnodetype)) {
result.put("code", 200);
result.put("success", true);
result.put("msg", "该流程暂未提交,无需催办");
response.getWriter().print(result);
response.setContentType(ContentType.JSON.getValue());
return;
}
if ("3".equals(currentnodetype)) {
result.put("code", 200);
result.put("success", true);
result.put("msg", "该流程已归档,无需催办");
response.getWriter().print(result);
response.setContentType(ContentType.JSON.getValue());
return;
}
//接收人id
Set<String> userIdList = getCurrentOperate(requestId);
// 排除当前操作人
userIdList = userIdList.stream().filter(v -> !v.equals(String.valueOf(user.getUID()))).collect(Collectors.toSet());
BASE_BEAN.writeLog("获取到的当前流程未操作者:" + userIdList);
if (userIdList.size() == 0) {
result.put("code", 200);
result.put("success", true);
result.put("msg", "当前节点无其他审批人,无需催办");
response.setContentType(ContentType.JSON.getValue());
response.getWriter().print(result);
return;
}
//标题
String title = workflowInfo.getString("title");
//内容
String context = "有待办流程需要您处理,请加急处理该流程" +
"<br/>创建人:" + workflowInfo.getString("creater") +
"<br/>创建时间:" + workflowInfo.getString("createDateTime");
//PC端链接
String linkUrl = "/workflow/request/ViewRequestForwardSPA.jsp?requestid=" + requestId;
//移动端链接
String linkMobileUrl = "/spa/workflow/static4mobileform/index.html#/req?requestid=" + requestId;
sendOAMsg(userIdList, title, context, linkUrl, linkMobileUrl);
List<String> userNameList = getUserNameList(CollUtil.join(userIdList, ","));
result.put("code", 200);
result.put("success", true);
result.put("userIdList", userIdList);
result.put("userNameList", userNameList);
result.put("msg", "催办成功,已提醒[" + CollUtil.join(userNameList, ",") + "]审批");
response.setContentType(ContentType.JSON.getValue());
response.getWriter().print(result);
} catch (Exception e) {
result.put("code", 500);
result.put("success", false);
result.put("msg", "系统异常,请联系管理员!");
response.setContentType(ContentType.JSON.getValue());
response.getWriter().print(result);
}
%>
<%!
public List<String> getUserNameList(String userIds) {
String[] userIdArr = userIds.split(",");
List<String> result = new ArrayList<>();
for (String userId : userIdArr) {
String userName = getUserName(userId);
result.add(userName);
}
return result;
}
public static JSONObject getWorkflowInfo(String requestId) {
RecordSet rs = new RecordSet();
String sql = "SELECT requestname,requestnamenew,creater,createdate,createtime,currentnodetype FROM workflow_requestbase WHERE requestid = ?";
rs.executeQuery(sql, requestId);
JSONObject workflowInfo = new JSONObject();
if (rs.next()) {
workflowInfo.put("title", rs.getString("requestnamenew"));
workflowInfo.put("creater", "1".equals(rs.getString("creater")) ? "系统管理员" : getUserName(rs.getString("creater")));
workflowInfo.put("createDateTime", rs.getString("createdate") + " " + rs.getString("createtime"));
workflowInfo.put("currentnodetype", rs.getString("currentnodetype"));
}
return workflowInfo;
}
public static Set<String> getCurrentOperate(String requestId) {
RecordSet rs = new RecordSet();
String sql = "SELECT userid FROM workflow_currentoperator WHERE REQUESTID = ? AND processUser IS NULL AND isremark = 0";
rs.executeQuery(sql, requestId);
Set<String> userIdList = new HashSet<>();
while (rs.next()) {
userIdList.add(rs.getString("userid"));
}
return userIdList;
}
public static void sendOAMsg(Set<String> userIdList, String title, String context, String linkUrl, String linkMobileUrl) {
MessageType messageType = MessageType.newInstance(100);//自定义类型
try {
MessageBean messageBean = Util_Message.createMessage(messageType, userIdList, title, context, linkUrl, linkMobileUrl);
//创建人id
messageBean.setCreater(1);
//消息来源code +“|”+业务id 需要修改消息状态时传入
// messageBean.setTargetId("100|22");
Util_Message.store(messageBean);
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getUserName(String userId) {
RecordSet rs = new RecordSet();
String sql = "SELECT lastname FROM hrmresource WHERE id = ?";
rs.executeQuery(sql, userId);
String userName = "";
if (rs.next()) {
userName = rs.getString("lastname");
}
return userName;
}
%>
三.后台消息配置
路径后台应用中心》消息中心》消息类型设置
EM PC端消息主页地址和EM 移动端消息主页地址仿照其他消息设置修改下链接参数ID
四.Emobile7云桥流程催办消息应用搭建
钉钉集成消息管理配置(选择到E9后台创建的消息类型名称)