chance_check_result.go
3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
}
//获取机会所有筛选结果
func GetCheckResultsByChanceId(chanceId int64) (v []*ChanceCheckResult, err error) {
o := orm.NewOrm()
sql := "select * from chance_check_result where chance_id =? order by check_pid,check_id"
if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil {
return
}
return
}
func GetCheckResultsByCheckId(chanceId int64, checkId int) (v []*ChanceCheckResult, err error) {
o := orm.NewOrm()
sql := "select * from chance_check_result where chance_id =? and check_id=? order by id"
if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId, checkId); err != nil {
return
}
return
}