chance_check_result.go 2.8 KB
package models

import (
	"fmt"
	"opp/internal/utils"
	"time"

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

type ChanceCheckResult struct {
	Id            int64     `orm:"column(id);pk"`
	ChanceId      int64     `orm:"column(chance_id)"`
	GroupId       int64     `orm:"column(group_id);null"`
	CheckPid      int64     `orm:"column(check_pid)"`
	CheckId       int       `orm:"column(check_id);null"`
	CheckItem     string    `orm:"column(check_item);size(20);null" description:"检查项"`
	Answer        string    `orm:"column(answer);size(50);null" description:"回答"`
	Reason        string    `orm:"column(reason);size(200);null" description:"理由"`
	UserCompanyId int64     `orm:"column(user_company_id);null"`
	CreateAt      time.Time `orm:"column(create_at);type(timestamp);null"`
}

func (t *ChanceCheckResult) TableName() string {
	return "chance_check_result"
}

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

var (
	SqlGetUserCheckResults = `select * from chance_check_result where chance_id =? and user_company_id=? order by group_id,check_id` //机会自查数据
)

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

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

// UpdateChanceCheckResult updates ChanceCheckResult by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceCheckResultById(m *ChanceCheckResult) (err error) {
	o := orm.NewOrm()
	v := ChanceCheckResult{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
}

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

//获取机会所有审核人
func GetCheckResultAllSubmitters(chanceId int64) (v []int64, err error) {
	o := orm.NewOrm()
	sql := "select DISTINCT user_company_id from chance_check_result where chance_id=?"
	if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil {
		return
	}
	return
}