audit_flow_config.go 3.5 KB
package models

import (
	"fmt"
	"time"

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

type AuditFlowConfig struct {
	Id              int       `orm:"column(id);pk" 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.指定角色 4.特殊审核人 "`
	FromSpecialUser string    `orm:"column(from_special_user)" description:"特殊指定的审批单发起人"`
	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      uint      `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:"更新时间"`
}

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 GetAuditFlowConfigs(auditTemplateId int64, groupId int64) (v []*AuditFlowConfig, err error) {
	o := orm.NewOrm()
	sql := "select * from audit_flow_config  where audit_template_id=? and audit_group_id=? order by level"
	if _, err = o.Raw(sql, auditTemplateId, groupId).QueryRows(&v); err == nil {
		return
	}
	return
}

//按 1.模板编号  2.审核等级
//查询审核配置列表
func GetAuditFlowConfigsLevel(auditTemplateId int64, level int) (v []*AuditFlowConfig, err error) {
	o := orm.NewOrm()
	sql := "select * from audit_flow_config  where audit_template_id=? and level=?"
	if _, err = o.Raw(sql, auditTemplateId, level).QueryRows(&v); err == nil {
		return
	}
	return
}