audit_flow_config.go 3.8 KB
package models

import (
	"fmt"
	"time"

	"github.com/astaxie/beego/orm"
)

type AuditFlowConfig struct {
	Id              int       `orm:"column(id);auto" description:"唯一编号"`
	AuditTemplateId int64     `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"`
	AuditGroupId    int64     `orm:"column(audit_group_id)" description:"审核组id (同一个审批批次)"`
	Level           int       `orm:"column(level)" description:"审批层级顺序,审批步骤 第几步"`
	AuditFlowType   int       `orm:"column(audit_flow_type)" description:"审核流类型 1.部门长 2.指定成员 3.指定角色"`
	FromSpecialUser string    `orm:"column(from_special_user);size(500)" description:"特殊指定的审批单发起人 json [ ]"`
	ToRole          string    `orm:"column(to_role);null" description:"指定角色"`
	ToUser          string    `orm:"column(to_user);null" description:"指定人"`
	FlowType        int       `orm:"column(flow_type)" description:"审批类型 1:正常审核  2:特殊审核"`
	ActionType      int       `orm:"column(action_type)" description:"审批执行方式【1:or】【2:and】"`
	CreateAt        time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
	UpdateAt        time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
	ConfigData      string    `orm:"column(config_data);null" description:"配置数据-冗余"`
}

//审核对象
const (
	AuditByDepartmentor = iota + 1 //部门长
	AuditByUser                    //指定用户
	AuditByRole                    //指定角色
	//AuditBySpecailUser             //特殊人员
)

//审核方式
const (
	ActionTypeAnd = 1 //会签
	ActionTypeOr  = 2 //或签
)

//审核类型
const (
	FlowTypeNormal  = iota + 1 //正常审核流程
	FlowTypeSpecail            //特殊审核流程
)

//审核人为空
const (
	NoApproverPass    = 1 //自动通过
	NoApproverToAdmin = 2 //转交给公司管理员
)

var (
	DeleteAuditFlowConfigSql = "delete from audit_flow_config where audit_template_id=?"
)

func (t *AuditFlowConfig) TableName() string {
	return "audit_flow_config"
}

func init() {
	orm.RegisterModel(new(AuditFlowConfig))
}

// AddAuditFlowConfig insert a new AuditFlowConfig into database and returns
// last inserted Id on success.
func AddAuditFlowConfig(m *AuditFlowConfig) (id int64, err error) {
	o := orm.NewOrm()
	id, err = o.Insert(m)
	return
}

// GetAuditFlowConfigById retrieves AuditFlowConfig by Id. Returns error if
// Id doesn't exist
func GetAuditFlowConfigById(id int) (v *AuditFlowConfig, err error) {
	o := orm.NewOrm()
	v = &AuditFlowConfig{Id: id}
	if err = o.Read(v); err == nil {
		return v, nil
	}
	return nil, err
}

// UpdateAuditFlowConfig updates AuditFlowConfig by Id and returns error if
// the record to be updated doesn't exist
func UpdateAuditFlowConfigById(m *AuditFlowConfig) (err error) {
	o := orm.NewOrm()
	v := AuditFlowConfig{Id: m.Id}
	// ascertain id exists in the database
	if err = o.Read(&v); err == nil {
		var num int64
		if num, err = o.Update(m); err == nil {
			fmt.Println("Number of records updated in database:", num)
		}
	}
	return
}

// DeleteAuditFlowConfig deletes AuditFlowConfig by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAuditFlowConfig(id int) (err error) {
	o := orm.NewOrm()
	v := AuditFlowConfig{Id: id}
	// ascertain id exists in the database
	if err = o.Read(&v); err == nil {
		var num int64
		if num, err = o.Delete(&AuditFlowConfig{Id: id}); err == nil {
			fmt.Println("Number of records deleted in database:", num)
		}
	}
	return
}

func GetAuditFlowConfig(id int64) ([]*AuditFlowConfig, error) {
	o := orm.NewOrm()
	var (
		err    error
		result []*AuditFlowConfig
	)
	_, err = o.QueryTable(&AuditFlowConfig{}).
		Filter("audit_template_id", id).
		All(&result)
	return result, err
}