-
Notifications
You must be signed in to change notification settings - Fork 25
/
point_log.gen.go
151 lines (126 loc) · 4.41 KB
/
point_log.gen.go
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package dao
import (
"github.com/gin-gonic/gin"
"github.com/i2eco/egoshop/appgo/model/mysql"
"github.com/i2eco/egoshop/appgo/model/trans"
"github.com/i2eco/muses/pkg/logger"
"github.com/jinzhu/gorm"
"go.uber.org/zap"
)
type pointLog struct {
logger *logger.Client
db *gorm.DB
}
func InitPointLog(logger *logger.Client, db *gorm.DB) *pointLog {
return &pointLog{
logger: logger,
db: db,
}
}
// Create 新增一条记
func (g *pointLog) Create(c *gin.Context, db *gorm.DB, data *mysql.PointLog) (err error) {
if err = db.Create(data).Error; err != nil {
g.logger.Error("create pointLog create error", zap.Error(err))
return
}
return nil
}
// Update 根据主键更新一条记录
func (g *pointLog) Update(c *gin.Context, db *gorm.DB, paramId int, ups mysql.Ups) (err error) {
var sql = "`id`=?"
var binds = []interface{}{paramId}
if err = db.Table("point_log").Where(sql, binds...).Updates(ups).Error; err != nil {
g.logger.Error("point_log update error", zap.Error(err))
return
}
return
}
// UpdateX Update的扩展方法,根据Cond更新一条或多条记录
func (g *pointLog) UpdateX(c *gin.Context, db *gorm.DB, conds mysql.Conds, ups mysql.Ups) (err error) {
sql, binds := mysql.BuildQuery(conds)
if err = db.Table("point_log").Where(sql, binds...).Updates(ups).Error; err != nil {
g.logger.Error("point_log update error", zap.Error(err))
return
}
return
}
// Delete 根据主键删除一条记录。如果有delete_time则软删除,否则硬删除。
func (g *pointLog) Delete(c *gin.Context, db *gorm.DB, paramId int) (err error) {
var sql = "`id`=?"
var binds = []interface{}{paramId}
if err = db.Table("point_log").Where(sql, binds...).Delete(&mysql.PointLog{}).Error; err != nil {
g.logger.Error("point_log delete error", zap.Error(err))
return
}
return
}
// DeleteX Delete的扩展方法,根据Cond删除一条或多条记录。如果有delete_time则软删除,否则硬删除。
func (g *pointLog) DeleteX(c *gin.Context, db *gorm.DB, conds mysql.Conds) (err error) {
sql, binds := mysql.BuildQuery(conds)
if err = db.Table("point_log").Where(sql, binds...).Delete(&mysql.PointLog{}).Error; err != nil {
g.logger.Error("point_log delete error", zap.Error(err))
return
}
return
}
// Info 根据PRI查询单条记录
func (g *pointLog) Info(c *gin.Context, paramId int) (resp mysql.PointLog, err error) {
var sql = "`id`=?"
var binds = []interface{}{paramId}
if err = g.db.Table("point_log").Where(sql, binds...).First(&resp).Error; err != nil {
g.logger.Error("point_log info error", zap.Error(err))
return
}
return
}
// InfoX Info的扩展方法,根据Cond查询单条记录
func (g *pointLog) InfoX(c *gin.Context, conds mysql.Conds) (resp mysql.PointLog, err error) {
sql, binds := mysql.BuildQuery(conds)
if err = g.db.Table("point_log").Where(sql, binds...).First(&resp).Error; err != nil {
g.logger.Error("point_log info error", zap.Error(err))
return
}
return
}
// List 查询list,extra[0]为sorts
func (g *pointLog) List(c *gin.Context, conds mysql.Conds, extra ...string) (resp []mysql.PointLog, err error) {
sql, binds := mysql.BuildQuery(conds)
sorts := ""
if len(extra) >= 1 {
sorts = extra[0]
}
if err = g.db.Table("point_log").Where(sql, binds...).Order(sorts).Find(&resp).Error; err != nil {
g.logger.Error("point_log info error", zap.Error(err))
return
}
return
}
// ListMap 查询map,map遍历的时候是无序的,所以指定sorts参数没有意义
func (g *pointLog) ListMap(c *gin.Context, conds mysql.Conds) (resp map[int]mysql.PointLog, err error) {
sql, binds := mysql.BuildQuery(conds)
mysqlSlice := make([]mysql.PointLog, 0)
resp = make(map[int]mysql.PointLog, 0)
if err = g.db.Table("point_log").Where(sql, binds...).Find(&mysqlSlice).Error; err != nil {
g.logger.Error("point_log info error", zap.Error(err))
return
}
for _, value := range mysqlSlice {
resp[value.Id] = value
}
return
}
// ListPage 根据分页条件查询list
func (g *pointLog) ListPage(c *gin.Context, conds mysql.Conds, reqList *trans.ReqPage) (total int, respList []mysql.PointLog) {
if reqList.PageSize == 0 {
reqList.PageSize = 10
}
if reqList.Current == 0 {
reqList.Current = 1
}
sql, binds := mysql.BuildQuery(conds)
db := g.db.Table("point_log").Where(sql, binds...)
respList = make([]mysql.PointLog, 0)
db.Count(&total)
db.Order(reqList.Sort).Offset((reqList.Current - 1) * reqList.PageSize).Limit(reqList.PageSize).Find(&respList)
return
}