package zbooksoft.fams.delegate; import com.ruili.wcp.common.SpringContextUtil; import com.ruili.wcp.data.entity.management.FlowRuntimeExecution; import com.ruili.wcp.data.entity.management.User; import com.ruili.wcp.engine.flow.delegate.DelegateTask; import com.ruili.wcp.engine.flow.delegate.TaskListener; import org.apache.shiro.SecurityUtils; import zbooksoft.fams.common.BusinessException; import zbooksoft.fams.service.AssetApplyService; /** * 资产使用流程最后审批节点的“操作完成前”事件:审批通过时回写资产卡片与流转记录。 * 放在“操作完成前”而不是“离开节点时”,是因为平台提交流程没有事务,离开节点时任务已流转,回写失败无法阻断 * @author ycq * @date 2026-10-16 */ public class AssetApplyApproveListener implements TaskListener { @Override public void notify(DelegateTask delegateTask) throws Exception { FlowRuntimeExecution execution = delegateTask.getProcessInstance(); AssetApplyService service = (AssetApplyService) SpringContextUtil.getBean(AssetApplyService.class); Object sessionUser = SecurityUtils.getSubject().getSession().getAttribute("user"); User user = sessionUser instanceof User ? (User) sessionUser : null; try { service.approve(service.typeOfTable(execution.getTableId()), execution.getKeyId(), user == null ? null : user.getUserId(), user == null ? "" : user.getTrueName()); } catch (BusinessException e) { throw new Exception(e.getMessage(), e); } } }