案例-公文流程实现撤回时收回意见

发布于 2026-05-25

需求描述

在公文流程撤回提交、批准这些意见还保留在流程中,不能像流程收回那样收回意见,需要实现和流程收回一样的效果

实现思路

拦截公文的撤回接口,撤回时更改签字意见状态

实现说明

  • 代理DoWidthDrawCmd类,这个类是公文撤回用到的
  • 判断有没有勾选恢复我的办理权限,如果没有勾选则按标准逻辑执行

Pasted image 20260407103054.png

  • 如果勾选了选恢复我的办理权限,则需要修改当前操作者在前一个节点提交的意见,将意见状态变为保存

Pasted image 20260407103128.png

源码

package com.customization.lgerp.proxy.yll.odocWidthDraw;

import com.engine.core.cfg.annotation.CommandDynamicProxy;
import com.engine.core.exception.ECException;
import com.engine.core.interceptor.AbstractCommandProxy;
import com.engine.core.interceptor.Command;
import com.engine.odoc.cmd.withdraw.DoWidthDrawCmd;
import com.engine.odoc.cmd.withdraw.constant.ApiConstant;
import weaver.conn.RecordSetTrans;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import weaver.workflow.request.RequestOperationLogManager;
import weaver.workflow.request.entity.OperateLogBean;
import weaver.workflow.request.entity.RequestOperateEntityTableNameEnum;
import weaver.workflow.request.entity.RequestOperationTableInfo;

import java.util.Map;

/**
 * @author 姚礼林
 * @desc FW20221216-0010 公文撤回开发,撤回时实现和流程收回一样的效果,删除提交时的意见,意见保留在表单的意见框内 <br>
 * 实现原理:拦截公文的撤回接口,撤回时更改签字意见状态
 * @date 2022/12/19
 */

@CommandDynamicProxy(target = DoWidthDrawCmd.class, desc = "拦截公文撤回接口")
public class DoWidthDrawProxyCmd extends AbstractCommandProxy<Map<String, Object>> {

    private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());

    @Override
    public Map<String, Object> execute(Command<Map<String, Object>> command) {
        DoWidthDrawCmd doWidthDrawCmd = (DoWidthDrawCmd) command;
        String myTodo = (String) ((DoWidthDrawCmd) command).getParams().get("myTodo");
        int requestId = Util.getIntValue(doWidthDrawCmd.getRequest().getParameter("requestid"));
        // 如果没有勾选恢复我的办理权限,则按照原有撤回逻辑执行
        if ("0".equals(myTodo)) {
            return nextExecute(command);
        }

        Map<String, Object> result = nextExecute(command);
        // 撤回失败不执行意见收回
        if (result.get(ApiConstant.API_STATUS) == null) {
            return result;
        }
        // 收回意见
        updateRequestLog(requestId,doWidthDrawCmd.getUser());

        return result;
    }

    /**
     * 修改签字意见日志,收回上次操作的意见
     *
     * @param requestId 流程请求id
     * @param user 用户
     */
    private void updateRequestLog(int requestId,User user) {
        RecordSetTrans rst = new RecordSetTrans();
        // 获取当前操作者的最后一次操作记录,只包括提交、批准、退回
        String getLastRecordSql = "select max(logid) logid from workflow_requestlog where (logtype='0' or logtype='2' or logtype='3')" +
                "and operator=? and requestid = ?";
        try {
            rst.executeQuery(getLastRecordSql,user.getUID(),requestId);
            rst.next();
            String lastRecordId = rst.getString("logid");
            // 更新意见状态为保存
            String updateLogSql = "update workflow_requestlog set logtype='1' where logid = ?";
            rst.executeUpdate(updateLogSql,lastRecordId);
        }catch (Exception e) {
            rst.rollback();
            e.printStackTrace();
            this.writeLog(e.getMessage());
            throw new ECException(this.getClass().getName() + "," + e.getMessage());
        }

        rst.commit();
    }

    private void writeLog(String message) {
        logger.error(message);
    }

}