更新密码找回uniapp

This commit is contained in:
hero920103 committed 2026-11-16 17:22:50 +08:00
1 parent 7f9a66da0f
commit 3fdda89833
1304 files changed
+3503 -26132

No files matched your search

+23 -136
View File
@@ -1,13 +1,3 @@
// Package approval 提供自定义审批流的运行时引擎。
//
// 设计说明:
// - 配置侧(flow/node)与运行时(instance/task)分离:配置由租户/平台编辑,
// 运行时实例创建后不可编辑,节点信息以任务表快照为准,避免改配置影响在途单据;
// - 租户侧与平台侧共用本引擎,通过 scope 区分数据来源:
// 租户侧审批人取租户用户/租户角色/组织主管/职位,
// 平台侧审批人取平台用户/平台角色(平台账号不归属租户);
// - 当期只实现顺序链流转(按 sort 升序),prev_keys / next_keys / condition_expr
// 为条件分支预留,后续扩展无需改表。
package approval
import (
@@ -26,29 +16,26 @@ import (
"github.com/beego/beego/v2/core/logs"
)
// Approver 展开后的单个审批人
type Approver struct {
ID uint64
Name string
}
// SubmitInput 提交审批入参
type SubmitInput struct {
Scope int8 // 1租户侧 2平台侧
Tid uint64 // 租户ID(租户侧=本租户)
BizTid uint64 // 业务来源租户(平台侧必填)
Scope int8
Tid uint64
BizTid uint64
BizType string
FlowCode string // 按审批流编号发起(优先于 BizType 默认流)
FlowCode string
BizID uint64
BizTitle string
SubmitUID uint64 // 发起人ID(租户侧为 uid,平台侧为 AdminUser.id)
SubmitUID uint64
SubmitName string
DeptID uint64 // 发起人部门
FlowID uint64 // 指定流程;0 表示按 FlowCode/BizType 取流程
FormData map[string]interface{} // 发起表单数据,供条件分支求值
DeptID uint64
FlowID uint64
FormData map[string]interface{}
}
// Node 流程节点(两侧统一结构,承载图连线)
type Node struct {
ID uint64
NodeKey string
@@ -60,12 +47,11 @@ type Node struct {
AllowReturn int8
TimeoutHours int
Sort int
PrevKeys string // 前置节点 node_key 列表(逗号分隔)
NextKeys string // 后继节点 node_key 列表(逗号分隔)
ConditionExpr string // 作为条件网关某出边目标时的进入条件
PrevKeys string
NextKeys string
ConditionExpr string
}
// Flow 流程定义(两侧统一结构,含图索引)
type Flow struct {
ID uint64
BizType string
@@ -77,7 +63,6 @@ type Flow struct {
StartKey string
}
// ErrNoFlow 表示未找到可用流程
type ErrNoFlow struct {
BizType string
}
@@ -86,7 +71,6 @@ func (e *ErrNoFlow) Error() string {
return "未找到适用于该单据的审批流程"
}
// ErrNoApprover 表示节点未能解析出任何审批人
type ErrNoApprover struct {
NodeName string
NodeKey string
@@ -96,9 +80,6 @@ func (e *ErrNoApprover) Error() string {
return fmt.Sprintf("节点「%s」未解析到有效审批人,请检查审批人配置", e.NodeName)
}
// ============================ 配置读取 ============================
// tenantFlows 查询租户侧流程列表(可按 biz_type 过滤)
func tenantFlows(tid uint64, bizType string) ([]models.TenantApprovalFlow, error) {
qs := models.Orm.QueryTable(new(models.TenantApprovalFlow)).
Filter("tid", tid).
@@ -111,7 +92,6 @@ func tenantFlows(tid uint64, bizType string) ([]models.TenantApprovalFlow, error
return rows, err
}
// tenantFlowNodes 查询租户侧流程的全部节点(含开始/审批/条件/结束,携带图连线)
func tenantFlowNodes(flowID uint64) ([]Node, error) {
var rows []models.TenantApprovalNode
if _, err := models.Orm.QueryTable(new(models.TenantApprovalNode)).
@@ -142,7 +122,6 @@ func tenantFlowNodes(flowID uint64) ([]Node, error) {
return out, nil
}
// platformFlows 查询平台侧流程列表
func platformFlows(bizType string) ([]models.PlatformApprovalFlow, error) {
qs := models.Orm.QueryTable(new(models.PlatformApprovalFlow)).Filter("is_deleted", 0)
if bizType != "" {
@@ -153,7 +132,6 @@ func platformFlows(bizType string) ([]models.PlatformApprovalFlow, error) {
return rows, err
}
// platformFlowNodes 查询平台侧流程的全部节点(含图连线)
func platformFlowNodes(flowID uint64) ([]Node, error) {
var rows []models.PlatformApprovalNode
if _, err := models.Orm.QueryTable(new(models.PlatformApprovalNode)).
@@ -184,7 +162,6 @@ func platformFlowNodes(flowID uint64) ([]Node, error) {
return out, nil
}
// LoadFlow 按 scope 加载流程(flowID=0 时取该单据类型的默认启用流程)
func LoadFlow(scope int8, tid uint64, bizType string, flowID uint64) (*Flow, error) {
if scope == models.ApprovalScopePlatform {
var candidates []models.PlatformApprovalFlow
@@ -223,7 +200,6 @@ func LoadFlow(scope int8, tid uint64, bizType string, flowID uint64) (*Flow, err
return buildTenantFlow(pickTenantFlow(candidates))
}
// LoadFlowByCode 按审批流编号加载流程(供各程序按编号发起)
func LoadFlowByCode(scope int8, tid uint64, code string) (*Flow, error) {
code = strings.TrimSpace(code)
if code == "" {
@@ -245,7 +221,6 @@ func LoadFlowByCode(scope int8, tid uint64, code string) (*Flow, error) {
return buildTenantFlow(one)
}
// buildTenantFlow / buildPlatformFlow 装配租户/平台流程(含图索引)
func buildTenantFlow(f models.TenantApprovalFlow) (*Flow, error) {
nodes, err := tenantFlowNodes(f.ID)
if err != nil {
@@ -268,7 +243,6 @@ func buildPlatformFlow(f models.PlatformApprovalFlow) (*Flow, error) {
return assembleFlow(f.ID, f.BizType, f.FlowName, nodes), nil
}
// assembleFlow 构建图索引 ByKey 与入口 StartKey(优先开始类型节点,否则取无前置节点)
func assembleFlow(id uint64, bizType, name string, nodes []Node) *Flow {
f := &Flow{ID: id, BizType: bizType, FlowName: name, Nodes: nodes, ByKey: make(map[string]*Node, len(nodes))}
for i := range f.Nodes {
@@ -294,7 +268,6 @@ func assembleFlow(id uint64, bizType, name string, nodes []Node) *Flow {
return f
}
// pickTenantFlow 在候选流程中择优:优先「默认 + 启用」,其次任一启用,最后首条。
func pickTenantFlow(rows []models.TenantApprovalFlow) models.TenantApprovalFlow {
for _, r := range rows {
if r.IsDefault == 1 && r.Status == 1 {
@@ -309,7 +282,6 @@ func pickTenantFlow(rows []models.TenantApprovalFlow) models.TenantApprovalFlow
return rows[0]
}
// pickPlatformFlow 同 pickTenantFlow,平台侧口径。
func pickPlatformFlow(rows []models.PlatformApprovalFlow) models.PlatformApprovalFlow {
for _, r := range rows {
if r.IsDefault == 1 && r.Status == 1 {
@@ -324,9 +296,6 @@ func pickPlatformFlow(rows []models.PlatformApprovalFlow) models.PlatformApprova
return rows[0]
}
// ============================ 审批人解析 ============================
// parseIDs 解析逗号分隔的 ID 列表
func parseIDs(raw string) []uint64 {
out := make([]uint64, 0, 4)
for _, part := range strings.Split(raw, ",") {
@@ -341,8 +310,6 @@ func parseIDs(raw string) []uint64 {
return out
}
// resolveApprovers 按 scope 解析节点审批人。
// 发起人相关类型需要 SubmitInput 上下文。
func resolveApprovers(scope int8, node Node, in SubmitInput) ([]Approver, error) {
ids := parseIDs(node.ApproverIDs)
@@ -366,21 +333,18 @@ func resolveApprovers(scope int8, node Node, in SubmitInput) ([]Approver, error)
return []Approver{{ID: in.SubmitUID, Name: in.SubmitName}}, nil
case models.ApprovalApproverOrgLeader:
// 指定部门的负责人;approver_ids 存组织ID
if len(ids) == 0 {
return nil, nil
}
return orgLeaders(in.Tid, ids), nil
case models.ApprovalApproverInitLeader:
// 发起人所在部门负责人
if in.DeptID == 0 {
return nil, nil
}
return orgLeaders(in.Tid, []uint64{in.DeptID}), nil
case models.ApprovalApproverPosition:
// 指定职位(approver_ids 存 BackendPosition.id),按员工职位名匹配
if len(ids) == 0 {
return nil, nil
}
@@ -389,12 +353,6 @@ func resolveApprovers(scope int8, node Node, in SubmitInput) ([]Approver, error)
return nil, nil
}
// resolveNotifyTargets 解析通知节点的通知对象(支持多类型)。
// approver_ids 兼容两种存储格式:
// 1. 旧格式:纯数字 CSV —— 单类型,配合 node.ApproverType(历史数据);
// 2. 多选格式:"类型:ID" CSV(如 "1:52,5:0")—— 类型取值同 approver_type,
// 自动定位类型(5发起人本人 / 6发起人主管)无需指定对象,ID 占位 0。
// 各类型的解析结果按 ID 去重合并。
func resolveNotifyTargets(scope int8, node Node, in SubmitInput) ([]Approver, error) {
if !strings.Contains(node.ApproverIDs, ":") {
return resolveApprovers(scope, node, in)
@@ -433,7 +391,6 @@ func resolveNotifyTargets(scope int8, node Node, in SubmitInput) ([]Approver, er
return dedupeApprovers(merged), nil
}
// joinApproverIDs 把 ID 列表拼成 CSV(与 parseIDs 互逆)
func joinApproverIDs(ids []uint64) string {
parts := make([]string, 0, len(ids))
for _, id := range ids {
@@ -444,7 +401,6 @@ func joinApproverIDs(ids []uint64) string {
return strings.Join(parts, ",")
}
// tenantUsers 按 uid 取租户用户
func tenantUsers(tid uint64, uids []uint64) []Approver {
if len(uids) == 0 {
return nil
@@ -464,7 +420,6 @@ func tenantUsers(tid uint64, uids []uint64) []Approver {
return out
}
// tenantRoleUsers 按租户角色取全部成员
func tenantRoleUsers(tid uint64, roleIDs []uint64) []Approver {
if len(roleIDs) == 0 {
return nil
@@ -484,7 +439,6 @@ func tenantRoleUsers(tid uint64, roleIDs []uint64) []Approver {
return out
}
// platformUsers 按 id 取平台用户
func platformUsers(ids []uint64) []Approver {
if len(ids) == 0 {
return nil
@@ -503,7 +457,6 @@ func platformUsers(ids []uint64) []Approver {
return out
}
// platformRoleUsers 按平台角色取全部成员(AdminRole cid=1 为平台角色)
func platformRoleUsers(roleIDs []uint64) []Approver {
if len(roleIDs) == 0 {
return nil
@@ -522,7 +475,6 @@ func platformRoleUsers(roleIDs []uint64) []Approver {
return out
}
// orgLeaders 取组织负责人
func orgLeaders(tid uint64, orgIDs []uint64) []Approver {
var orgs []models.BackendOrganization
if _, err := models.Orm.QueryTable(new(models.BackendOrganization)).
@@ -531,7 +483,6 @@ func orgLeaders(tid uint64, orgIDs []uint64) []Approver {
All(&orgs); err != nil {
return nil
}
// 负责人可能指向员工ID,也可能指向租户用户uid,这里统一再查一次租户用户
leaderIDs := make([]uint64, 0, len(orgs))
for _, o := range orgs {
if o.LeaderID != nil && *o.LeaderID > 0 {
@@ -544,7 +495,6 @@ func orgLeaders(tid uint64, orgIDs []uint64) []Approver {
return tenantUsers(tid, leaderIDs)
}
// positionUsers 按职位取员工:职位ID → 职位名 → 员工(职位字段) → 登录账号 → 租户用户
func positionUsers(tid uint64, positionIDs []uint64) []Approver {
var positions []models.BackendPosition
if _, err := models.Orm.QueryTable(new(models.BackendPosition)).
@@ -594,7 +544,6 @@ func positionUsers(tid uint64, positionIDs []uint64) []Approver {
return out
}
// approverName 优先取姓名字段,回退到账号(平台侧 Account 为普通字符串)
func approverName(name *string, account string) string {
if s := firstNonEmptyPtr(name); s != "" {
return s
@@ -602,7 +551,6 @@ func approverName(name *string, account string) string {
return strings.TrimSpace(account)
}
// firstNonEmptyPtr 取第一个非空字符串指针的值
func firstNonEmptyPtr(vals ...*string) string {
for _, v := range vals {
if v != nil && strings.TrimSpace(*v) != "" {
@@ -612,7 +560,6 @@ func firstNonEmptyPtr(vals ...*string) string {
return ""
}
// dedupeApprovers 去重并保持顺序
func dedupeApprovers(in []Approver) []Approver {
seen := make(map[uint64]bool, len(in))
out := make([]Approver, 0, len(in))
@@ -626,9 +573,6 @@ func dedupeApprovers(in []Approver) []Approver {
return out
}
// ============================ 运行时:发起前的可用流查询 ============================
// AvailableFlow 业务侧选择用的轻量结构
type AvailableFlow struct {
FlowID uint64 `json:"flow_id"`
FlowCode string `json:"flow_code"`
@@ -636,12 +580,7 @@ type AvailableFlow struct {
BizType string `json:"biz_type"`
}
// ListAvailableFlows 按 bizType + 用户部门 过滤“当前可用”审批流。
// 直接查询 flow 表中 biz_type 匹配且 status=1 未删除的流程。
// 租户侧额外按 apply_dept_ids 部门过滤。
// 平台侧(scope=2)忽略部门过滤(因平台 flow 无 apply_dept_ids)。
func ListAvailableFlows(scope int8, tid uint64, bizType string, userOrgID uint64) ([]AvailableFlow, error) {
// 租户侧预计算一次当前用户组织的“祖先链”(含自身),选中上级部门或公司均命中
var path []uint64
if scope == models.ApprovalScopeTenant && userOrgID > 0 {
path = buildOrgPath(tid, userOrgID)
@@ -670,7 +609,6 @@ func ListAvailableFlows(scope int8, tid uint64, bizType string, userOrgID uint64
return out, nil
}
// deptMatch csv 空视为全公司通用;否则与 path (包含自身与祖先部门ID) 任一命中即命中。
func deptMatch(csv string, path []uint64) bool {
csv = strings.TrimSpace(csv)
if csv == "" {
@@ -691,7 +629,6 @@ func deptMatch(csv string, path []uint64) bool {
return false
}
// buildOrgPath 从当前部门沿 parent_id 向上追到根,返回含自身的 ID 链(环保护)
func buildOrgPath(tid, orgID uint64) []uint64 {
if orgID == 0 {
return nil
@@ -719,10 +656,6 @@ func buildOrgPath(tid, orgID uint64) []uint64 {
return out
}
// ============================ 运行时:提交 ============================
// Submit 提交单据进入审批,创建实例并按图展开首个可执行节点的任务。
// 优先按 FlowCode 命中流程;无审批节点时直接置为已通过。
func Submit(in SubmitInput) (uint64, error) {
var (
flow *Flow
@@ -768,9 +701,7 @@ func Submit(in SubmitInput) (uint64, error) {
notifyFn := func(n *Node) { fireNotifyTasks(uint64(instID), in, n) }
node, approvers := nextExecutable(flow, in.FormData, start, in, notifyFn)
if node == nil {
// 无可执行审批节点
if hasApproval {
// 配了审批节点但均无有效审批人:视为配置错误,回滚实例
_, _ = models.Orm.QueryTable(new(models.ApprovalInstance)).
Filter("id", instID).Update(orm.Params{"is_deleted": 1, "status": models.ApprovalInstanceCanceled})
return 0, &ErrNoApprover{NodeName: firstApprovalName, NodeKey: firstApprovalKey}
@@ -789,7 +720,6 @@ func Submit(in SubmitInput) (uint64, error) {
return uint64(instID), nil
}
// anyApprovalNode 判断流程是否含审批节点,并返回首个审批节点信息
func anyApprovalNode(flow *Flow) (bool, string, string) {
for i := range flow.Nodes {
if flow.Nodes[i].NodeType == models.ApprovalNodeApproval {
@@ -799,14 +729,12 @@ func anyApprovalNode(flow *Flow) (bool, string, string) {
return false, "", ""
}
// advanceFrom 从 cur 沿出边前进,遇条件网关求值选路,返回首个审批节点(nil 表示到终点)。
// onNotify 可选回调:当路径经过通知节点时触发,由调用方负责创建通知任务。
func advanceFrom(flow *Flow, formData map[string]interface{}, cur *Node, onNotify ...func(*Node)) *Node {
visited := make(map[string]bool)
node := pickNext(flow, formData, cur)
for node != nil {
if visited[node.NodeKey] {
return nil // 环保护
return nil
}
visited[node.NodeKey] = true
switch node.NodeType {
@@ -819,14 +747,13 @@ func advanceFrom(flow *Flow, formData map[string]interface{}, cur *Node, onNotif
onNotify[0](node)
}
node = pickNext(flow, formData, node)
default: // start / condition:继续向后
default:
node = pickNext(flow, formData, node)
}
}
return nil
}
// pickNext 取节点的下一个目标:普通节点取唯一出边;条件网关按各目标 condition_expr 互斥选路,空条件为默认分支
func pickNext(flow *Flow, formData map[string]interface{}, node *Node) *Node {
if node == nil {
return nil
@@ -857,8 +784,6 @@ func pickNext(flow *Flow, formData map[string]interface{}, node *Node) *Node {
return def
}
// nextExecutable 沿图找到下一个「有有效审批人」的审批节点;无人审批节点自动跳过
// nextExecutable 获取下一个可执行审批节点及其审批人(跳过通知节点并通过 onNotify 回调触发)
func nextExecutable(flow *Flow, formData map[string]interface{}, cur *Node, in SubmitInput, onNotify ...func(*Node)) (*Node, []Approver) {
node := advanceFrom(flow, formData, cur, onNotify...)
visited := make(map[string]bool)
@@ -879,7 +804,6 @@ func nextExecutable(flow *Flow, formData map[string]interface{}, cur *Node, in S
return nil, nil
}
// splitKeys 拆分逗号分隔的 node_key 列表
func splitKeys(raw string) []string {
out := make([]string, 0, 4)
for _, p := range strings.Split(raw, ",") {
@@ -890,7 +814,6 @@ func splitKeys(raw string) []string {
return out
}
// instanceFormData 解析实例的表单快照
func instanceFormData(inst *models.ApprovalInstance) map[string]interface{} {
if inst == nil || inst.FormData == nil || strings.TrimSpace(*inst.FormData) == "" {
return nil
@@ -902,7 +825,6 @@ func instanceFormData(inst *models.ApprovalInstance) map[string]interface{} {
return m
}
// submitFromInstance 由实例重建提交上下文(供推进时解析审批人)
func submitFromInstance(inst *models.ApprovalInstance, formData map[string]interface{}) SubmitInput {
return SubmitInput{
Scope: inst.Scope,
@@ -917,7 +839,6 @@ func submitFromInstance(inst *models.ApprovalInstance, formData map[string]inter
}
}
// createTasks 为一个节点展开审批任务
func createTasks(instID uint64, in SubmitInput, node Node, approvers []Approver) error {
timeout := node.TimeoutHours
if timeout <= 0 {
@@ -952,7 +873,6 @@ func createTasks(instID uint64, in SubmitInput, node Node, approvers []Approver)
return err
}
// 租户侧审批人同时推小程序订阅消息(授权过才有一次发送机会,失败不影响流程)
if in.Scope == models.ApprovalScopeTenant {
for _, a := range approvers {
approverID, nodeName := a.ID, node.NodeName
@@ -970,7 +890,6 @@ func createTasks(instID uint64, in SubmitInput, node Node, approvers []Approver)
return nil
}
// fireNotifyTasks 为通知节点创建已读通知任务(不阻塞流程)
func fireNotifyTasks(instID uint64, in SubmitInput, notifyNode *Node) {
recipients, _ := resolveNotifyTargets(in.Scope, *notifyNode, in)
recipients = dedupeApprovers(recipients)
@@ -998,7 +917,6 @@ func fireNotifyTasks(instID uint64, in SubmitInput, notifyNode *Node) {
_, _ = models.Orm.InsertMulti(len(tasks), tasks)
}
// finishInstance 结束实例
func finishInstance(instID uint64, status int8) {
now := time.Now()
_, _ = models.Orm.QueryTable(new(models.ApprovalInstance)).
@@ -1010,18 +928,14 @@ func finishInstance(instID uint64, status int8) {
SyncBizResult(instID, status)
}
// 报销单状态(与 yz_backend_reimbursements.status / 前端字典 oa_reimburse_status 一致)
const (
reimburseStatusApproved int8 = 2 // 已通过
reimburseStatusRejected int8 = 3 // 已驳回
reimburseStatusWithdrawn int8 = 4 // 已撤回
reimburseStatusApproved int8 = 2
reimburseStatusRejected int8 = 3
reimburseStatusWithdrawn int8 = 4
)
// BizTypeLegacyOA 早期报销单提交进审批引擎时写入的 biz_type(按模块 code 记录)。
// 与 ApprovalBizReimburse 一并识别,保证按老写法产生的在途/历史单据也能正常回写。
const BizTypeLegacyOA = "oa"
// IsReimburseBizType 判断审批实例是否属于 OA 报销单
func IsReimburseBizType(bizType string) bool {
switch strings.TrimSpace(bizType) {
case models.ApprovalBizReimburse, BizTypeLegacyOA:
@@ -1030,11 +944,6 @@ func IsReimburseBizType(bizType string) bool {
return false
}
// SyncBizResult 把审批实例的最终结果回写到对应业务单据,保证「审批中心」与业务列表状态一致。
//
// 目前覆盖 OA 报销单(biz_type=reimburse / 老写法 oa):按实例状态同步
// yz_backend_reimbursements.status,并补一条审批记录供业务详情页时间线展示。
// 撤回入口(不走 finishInstance)也会显式调用本函数,重复调用按最终态幂等。
func SyncBizResult(instID uint64, status int8) {
if instID == 0 {
return
@@ -1044,23 +953,23 @@ func SyncBizResult(instID uint64, status int8) {
Filter("id", instID).One(&inst); err != nil {
return
}
// 无业务单据ID的实例(纯手工审批)不回写任何业务表
if inst.BizID == 0 {
return
}
// 进销存单据:biz_type 形如 erp_purchase_in / erp_sales_out,终态回写单据状态,
// 「已生效」单据的效果(库存流水/往来账)在回写时同事务执行。
if strings.HasPrefix(inst.BizType, "erp_") {
erp.SyncErpDocResult(inst.BizType, inst.BizID, bizTenantID(&inst), status)
return
}
if inst.BizType == models.ApprovalBizAttendanceFix {
SyncAttendanceFixResult(&inst, status)
return
}
if !IsReimburseBizType(inst.BizType) {
return
}
syncReimburseResult(&inst, status)
}
// bizTenantID 业务单据所属租户:平台侧实例的 tid 恒为 0,来源租户记在 biz_tid。
func bizTenantID(inst *models.ApprovalInstance) uint64 {
if inst.Scope == models.ApprovalScopePlatform && inst.BizTid != 0 {
return inst.BizTid
@@ -1068,7 +977,6 @@ func bizTenantID(inst *models.ApprovalInstance) uint64 {
return inst.Tid
}
// syncReimburseResult 回写报销单状态:审批通过/驳回/撤回分别对应业务状态 2/3/4。
func syncReimburseResult(inst *models.ApprovalInstance, status int8) {
var bizStatus, action int8
switch status {
@@ -1092,7 +1000,6 @@ func syncReimburseResult(inst *models.ApprovalInstance, status int8) {
Filter("is_deleted", 0).One(&row); err != nil {
return
}
// 已是目标状态说明同步过,避免重复插入审批记录
if row.Status == bizStatus {
return
}
@@ -1104,7 +1011,6 @@ func syncReimburseResult(inst *models.ApprovalInstance, status int8) {
return
}
// 业务详情页的时间线读 yz_backend_approval_records,这里补记一条审批结果
actorID, actorName, comment := lastApprovalActor(inst)
_, _ = models.Orm.Insert(&models.BackendApprovalRecord{
Tid: tid, UID: approvalUint64Ptr(actorID), ReimbursementID: inst.BizID,
@@ -1113,7 +1019,6 @@ func syncReimburseResult(inst *models.ApprovalInstance, status int8) {
})
}
// lastApprovalActor 取实例上最近一次通过/驳回的审批人(撤回等场景回退到发起人)。
func lastApprovalActor(inst *models.ApprovalInstance) (uint64, string, string) {
var task models.ApprovalTask
if err := models.Orm.QueryTable(new(models.ApprovalTask)).
@@ -1139,27 +1044,21 @@ func approvalStringPtr(s string) *string {
return &s
}
// ============================ 运行时:审批 ============================
// ApproveInput 审批入参
type ApproveInput struct {
ApproverID uint64 // 审批人ID
ApproverID uint64
Pass bool
Comment string
// BizTid 平台侧操作时按业务租户校验/展示用(可留空)
BizTid uint64
}
// ApproveResult 审批结果
type ApproveResult struct {
InstanceID uint64
InstanceStat int8 // 实例新状态
CurrentNode string // 新当前节点(完成时为空)
InstanceStat int8
CurrentNode string
Finished bool
Message string
}
// Approve 处理一条审批任务:按或签/会签推进到下一节点或结束实例。
func Approve(taskID uint64, in ApproveInput) (*ApproveResult, error) {
var task models.ApprovalTask
if err := models.Orm.QueryTable(new(models.ApprovalTask)).
@@ -1188,7 +1087,6 @@ func Approve(taskID uint64, in ApproveInput) (*ApproveResult, error) {
now := time.Now()
// 驳回:整个实例结束(与退回上一节点区分)
if !in.Pass {
_, err := models.Orm.QueryTable(new(models.ApprovalTask)).
Filter("id", taskID).
@@ -1202,7 +1100,6 @@ func Approve(taskID uint64, in ApproveInput) (*ApproveResult, error) {
if err != nil {
return nil, err
}
// 同节点其余待办一并置为跳过,避免留下永远待办的僵尸任务
_, _ = models.Orm.QueryTable(new(models.ApprovalTask)).
Filter("instance_id", task.InstanceID).
Filter("node_key", task.NodeKey).
@@ -1219,7 +1116,6 @@ func Approve(taskID uint64, in ApproveInput) (*ApproveResult, error) {
}, nil
}
// 通过:更新当前任务
_, err := models.Orm.QueryTable(new(models.ApprovalTask)).
Filter("id", taskID).
Update(orm.Params{
@@ -1233,7 +1129,6 @@ func Approve(taskID uint64, in ApproveInput) (*ApproveResult, error) {
return nil, err
}
// 或签:任一通过即推进,会签:需全部通过
if task.MultiMode == models.ApprovalMultiAny {
_, _ = models.Orm.QueryTable(new(models.ApprovalTask)).
Filter("instance_id", task.InstanceID).
@@ -1256,11 +1151,9 @@ func Approve(taskID uint64, in ApproveInput) (*ApproveResult, error) {
}
}
// 当前节点完成 → 推进下一节点
return advance(task.InstanceID, task.NodeKey, in)
}
// advance 沿图推进到下一个可执行审批节点;无后继则结束实例
func advance(instID uint64, currentKey string, in ApproveInput) (*ApproveResult, error) {
var inst models.ApprovalInstance
if err := models.Orm.QueryTable(new(models.ApprovalInstance)).
@@ -1270,7 +1163,6 @@ func advance(instID uint64, currentKey string, in ApproveInput) (*ApproveResult,
flow, err := LoadFlow(inst.Scope, inst.Tid, inst.BizType, inst.FlowID)
if err != nil {
// 配置被删除时保守处理:按已完成结束
finishInstance(instID, models.ApprovalInstanceApproved)
return &ApproveResult{
InstanceID: instID,
@@ -1311,9 +1203,6 @@ func advance(instID uint64, currentKey string, in ApproveInput) (*ApproveResult,
}, nil
}
// ============================ 条件表达式求值 ============================
// evalCondition 求值条件表达式:支持 == != > >= < <= 与 && ||(不含括号)。空表达式恒真。
func evalCondition(expr string, data map[string]interface{}) bool {
expr = strings.TrimSpace(expr)
if expr == "" {
@@ -1355,7 +1244,6 @@ func evalAtom(s string, data map[string]interface{}) bool {
return false
}
// resolveCondVal 取字段值:支持点路径 a.b.c
func resolveCondVal(key string, data map[string]interface{}) interface{} {
if data == nil {
return nil
@@ -1464,7 +1352,6 @@ func condString(v interface{}) string {
}
}
// SortNodes 按 sort 升序排序(导出供配置端校验使用)
func SortNodes(nodes []Node) {
sort.SliceStable(nodes, func(i, j int) bool { return nodes[i].Sort < nodes[j].Sort })
}