fix
This commit is contained in:
24
model/fsmaplibrarymodel.go
Executable file
24
model/fsmaplibrarymodel.go
Executable file
@@ -0,0 +1,24 @@
|
||||
package model
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var _ FsMapLibraryModel = (*customFsMapLibraryModel)(nil)
|
||||
|
||||
type (
|
||||
// FsMapLibraryModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customFsMapLibraryModel.
|
||||
FsMapLibraryModel interface {
|
||||
fsMapLibraryModel
|
||||
}
|
||||
|
||||
customFsMapLibraryModel struct {
|
||||
*defaultFsMapLibraryModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewFsMapLibraryModel returns a model for the database table.
|
||||
func NewFsMapLibraryModel(conn sqlx.SqlConn) FsMapLibraryModel {
|
||||
return &customFsMapLibraryModel{
|
||||
defaultFsMapLibraryModel: newFsMapLibraryModel(conn),
|
||||
}
|
||||
}
|
||||
89
model/fsmaplibrarymodel_gen.go
Executable file
89
model/fsmaplibrarymodel_gen.go
Executable file
@@ -0,0 +1,89 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
fsMapLibraryFieldNames = builder.RawFieldNames(&FsMapLibrary{})
|
||||
fsMapLibraryRows = strings.Join(fsMapLibraryFieldNames, ",")
|
||||
fsMapLibraryRowsExpectAutoSet = strings.Join(stringx.Remove(fsMapLibraryFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
fsMapLibraryRowsWithPlaceHolder = strings.Join(stringx.Remove(fsMapLibraryFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
fsMapLibraryModel interface {
|
||||
Insert(ctx context.Context, data *FsMapLibrary) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*FsMapLibrary, error)
|
||||
Update(ctx context.Context, data *FsMapLibrary) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultFsMapLibraryModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
FsMapLibrary struct {
|
||||
Id int64 `db:"id"` // Id
|
||||
Title string `db:"title"` // 名称
|
||||
Info string `db:"info"` // 贴图数据
|
||||
Sort int64 `db:"sort"` // 排序
|
||||
Status int64 `db:"status"` // 状态 1启用
|
||||
Ctime int64 `db:"ctime"` // 创建时间
|
||||
TagId int64 `db:"tag_id"` // 模板标签id
|
||||
}
|
||||
)
|
||||
|
||||
func newFsMapLibraryModel(conn sqlx.SqlConn) *defaultFsMapLibraryModel {
|
||||
return &defaultFsMapLibraryModel{
|
||||
conn: conn,
|
||||
table: "`fs_map_library`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsMapLibraryModel) Delete(ctx context.Context, id int64) error {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultFsMapLibraryModel) FindOne(ctx context.Context, id int64) (*FsMapLibrary, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsMapLibraryRows, m.table)
|
||||
var resp FsMapLibrary
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsMapLibraryModel) Insert(ctx context.Context, data *FsMapLibrary) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?)", m.table, fsMapLibraryRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Title, data.Info, data.Sort, data.Status, data.Ctime, data.TagId)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultFsMapLibraryModel) Update(ctx context.Context, data *FsMapLibrary) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsMapLibraryRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.Title, data.Info, data.Sort, data.Status, data.Ctime, data.TagId, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultFsMapLibraryModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
31
model/gmodel/fsmaplibrarymodel.go
Executable file
31
model/gmodel/fsmaplibrarymodel.go
Executable file
@@ -0,0 +1,31 @@
|
||||
package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FsMapLibrary struct {
|
||||
Id int64 `gorm:"primary_key" json:"id"` // Id
|
||||
Title *string `gorm:"default:''" json:"title"` // 名称
|
||||
Info *string `gorm:"default:''" json:"info"` // 贴图数据
|
||||
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
|
||||
Status *int64 `gorm:"default:1" json:"status"` // 状态 1启用 0未启用
|
||||
Ctime *int64 `gorm:"default:0" json:"ctime"` // 创建时间
|
||||
TagId *int64 `gorm:"default:0" json:"tag_id"` // 模板标签id
|
||||
}
|
||||
type FsMapLibraryModel struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewFsMapLibraryModel(db *gorm.DB) *FsMapLibraryModel {
|
||||
return &FsMapLibraryModel{db}
|
||||
}
|
||||
|
||||
func (ml *FsMapLibraryModel) GetAllEnabledList(ctx context.Context) (resp []FsMapLibrary, err error) {
|
||||
err = ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`status` = ?", 1).Find(&resp).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package gmodel
|
||||
|
||||
import "gorm.io/gorm"
|
||||
import (
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FsProductTemplateTags struct {
|
||||
Id int64 `gorm:"primary_key" json:"id"` // ID
|
||||
@@ -15,3 +18,14 @@ type FsProductTemplateTagsModel struct {
|
||||
func NewFsProductTemplateTagsModel(db *gorm.DB) *FsProductTemplateTagsModel {
|
||||
return &FsProductTemplateTagsModel{db}
|
||||
}
|
||||
|
||||
func (pt *FsProductTemplateTagsModel) GetListByIds(ctx context.Context, ids []int64) (resp []FsProductTemplateTags, err error) {
|
||||
if len(ids) == 0 {
|
||||
return
|
||||
}
|
||||
err = pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`id` in (?)", ids).Find(&resp).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user