king
2023-10-09 b20d0f21e53b3730de9ad1e7d96f25512620ff77
src/utils/utils.js
@@ -2117,6 +2117,7 @@
    let status = 0
    let statusName = ''
    let detailId = ''
    let error = ''
    if (verify.flowType === 'start') {
      target = flow.cells.filter(cell => cell.mknode === 'start')[0]
@@ -2125,17 +2126,112 @@
        detailId = target.id
        status = target.mkdata.status
        statusName = target.mkdata.statusName
      } else {
        error = '工作流无开始节点'
      }
    } else if (_data.works_flow_param) {
      node = JSON.parse(window.decodeURIComponent(window.atob(_data.works_flow_param)))
      try {
        node = JSON.parse(window.decodeURIComponent(window.atob(_data.works_flow_param)))
      } catch (e) {
        node = null
      }
      if (node) {
        let lines = flow.cells.filter(cell => cell.shape === 'edge' && cell.source.cell === node.id)
        if (verify.flowType === 'reject') {
          line = lines.filter(cell => cell.mkdata.flowType === 'reject' || cell.mknode === 'startEdge')[0]
        } else {
          line = lines.filter(cell => cell.mkdata.flowType !== 'reject' && cell.mknode !== 'startEdge')[0]
          let endEdge = null
          lines = lines.filter(cell => {
            if (cell.mknode === 'endEdge') {
              endEdge = cell
              return false
            }
            return cell.mkdata.flowType !== 'reject' && cell.mknode !== 'startEdge'
          })
          if (lines.length === 0) {
            if (!endEdge) {
              error = '无可执行的流程分支'
            } else {
              line = endEdge
            }
          } else {
            let branchKey = verify.flowBranch ? verify.flowBranch.toLowerCase() : ''
            if (!branchKey) {
              lines.forEach(line => {
                if (line.mkdata.execCondition === 'open') {
                  error = '按钮未设置流程控制字段。'
                }
              })
              if (!error) {
                line = lines[0]
              }
            } else if (!_data.hasOwnProperty(branchKey)) {
              error = '行信息中无流程控制字段。'
            } else {
              if (endEdge) {
                line = endEdge
              }
              let equalLine = null
              let gtOrLtLine = []
              let unEqualLine = null
              let branchVal = _data[branchKey]
              if (branchVal && typeof(branchVal) === 'string' && !isNaN(branchVal)) {
                branchVal = +branchVal
              }
              lines.forEach(item => {
                if (item.mkdata.execCondition !== 'open') {
                  line = item
                } else {
                  if (item.mkdata.match === '=') {
                    if (item.mkdata.matchVal === branchVal + '') {
                      equalLine = item
                    }
                  } else if (item.mkdata.match === '!=') {
                    if (item.mkdata.matchVal !== branchVal + '') {
                      unEqualLine = item
                    }
                  } else {
                    if (item.mkdata.match === '<') {
                      if (item.mkdata.matchVal < branchVal) {
                        gtOrLtLine.push({...item, dist: Math.abs(item.mkdata.matchVal - branchVal)})
                      }
                    } else if (item.mkdata.match === '>') {
                      if (item.mkdata.matchVal > branchVal) {
                        gtOrLtLine.push({...item, dist: Math.abs(item.mkdata.matchVal - branchVal)})
                      }
                    } else if (item.mkdata.match === '<=') {
                      if (item.mkdata.matchVal <= branchVal) {
                        gtOrLtLine.push({...item, dist: Math.abs(item.mkdata.matchVal - branchVal)})
                      }
                    } else if (item.mkdata.match === '>=') {
                      if (item.mkdata.matchVal >= branchVal) {
                        gtOrLtLine.push({...item, dist: Math.abs(item.mkdata.matchVal - branchVal)})
                      }
                    }
                  }
                }
              })
              if (equalLine) {
                line = equalLine
              } else if (gtOrLtLine.length > 0) {
                gtOrLtLine.sort((a, b) => a.dist - b.dist)
                line = gtOrLtLine[0]
              } else if (unEqualLine) {
                line = unEqualLine
              }
            }
          }
        }
      } else {
        error = '行信息中工作流参数无法解析'
      }
      
      if (line) {
@@ -2143,7 +2239,11 @@
        status = line.mkdata.status
        statusName = line.mkdata.statusName
        target = flow.cells.filter(cell => cell.id === line.target.cell)[0]
      } else if (!error) {
        error = '工作流中无对应流程'
      }
    } else {
      error = '行信息中无工作流参数'
    }
    if (verify.flowSql === 'true' && target) {
@@ -2184,20 +2284,12 @@
      `
      }
    } else if (verify.flowSql === 'true') {
      target = flow.cells.filter(cell => cell.mknode === 'start')[0]
      if (target) {
        detailId = target.id
      }
      status = 0
      statusName = '异常'
      _sql += `
      /* 工作流异常sql */
      update s_my_works_flow set status=@status@,statusname=@statusname@,works_flow_param=@works_flow_param@,works_flow_detail_id=@works_flow_detail_id@,modifydate=getdate(),modifyuserid=@userid@,modifyuser=@username,modifystaff=@fullname
      where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0
      insert into s_my_works_flow_log (works_flow_id,works_flow_code,works_flow_name,works_flow_param,status,statusname,works_flow_detail_id,work_group,work_grade,upid)
      select @ID@,@works_flow_code@,@works_flow_name@ ,@works_flow_param@,@status@,@statusname@,@works_flow_detail_id@,@work_group@,@work_grade@,@time_id@
      select @ErrorCode='E',@retmsg='${error || '工作流执行异常'}' goto aaa
      `
    }