2025-10-30 10:02:46 +08:00
|
|
|
|
// Code generated by goctl. DO NOT EDIT.
|
|
|
|
|
|
// versions:
|
|
|
|
|
|
// goctl version: 1.9.2
|
|
|
|
|
|
|
|
|
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
"database/sql"
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
"strings"
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
socialServiceGovernmentprogramFieldNames = builder.RawFieldNames(&SocialServiceGovernmentprogram{})
|
|
|
|
|
|
socialServiceGovernmentprogramRows = strings.Join(socialServiceGovernmentprogramFieldNames, ",")
|
|
|
|
|
|
socialServiceGovernmentprogramRowsExpectAutoSet = strings.Join(stringx.Remove(socialServiceGovernmentprogramFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
|
|
|
|
socialServiceGovernmentprogramRowsWithPlaceHolder = strings.Join(stringx.Remove(socialServiceGovernmentprogramFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
|
|
socialServiceGovernmentprogramModel interface {
|
|
|
|
|
|
Insert(ctx context.Context, data *SocialServiceGovernmentprogram) (sql.Result, error)
|
|
|
|
|
|
FindOne(ctx context.Context, id int64) (*SocialServiceGovernmentprogram, error)
|
|
|
|
|
|
Update(ctx context.Context, data *SocialServiceGovernmentprogram) error
|
|
|
|
|
|
Delete(ctx context.Context, id int64) error
|
2025-10-30 14:24:20 +08:00
|
|
|
|
Count(ctx context.Context) (int64, error)
|
|
|
|
|
|
ListByPage(ctx context.Context, offset, limit int) ([]*SocialServiceGovernmentprogram, error)
|
2025-10-30 10:02:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
defaultSocialServiceGovernmentprogramModel struct {
|
|
|
|
|
|
conn sqlx.SqlConn
|
|
|
|
|
|
table string
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SocialServiceGovernmentprogram struct {
|
|
|
|
|
|
Id int64 `db:"id"` // 主键ID
|
|
|
|
|
|
Title string `db:"title"` // 标题
|
|
|
|
|
|
Subtitle string `db:"subtitle"` // 副标题
|
|
|
|
|
|
CoverUrl string `db:"cover_url"` // 封面图片URL
|
|
|
|
|
|
Intro string `db:"intro"` // 简介(纯文字)
|
|
|
|
|
|
Content sql.NullString `db:"content"` // 内容(Markdown格式)
|
|
|
|
|
|
ImageEditors string `db:"image_editors"` // 图片编辑者名单(多个用逗号分隔)
|
|
|
|
|
|
TextEditors string `db:"text_editors"` // 文字编辑者名单(多个用逗号分隔)
|
|
|
|
|
|
ChiefEditor string `db:"chief_editor"` // 总编辑
|
|
|
|
|
|
Proofreaders string `db:"proofreaders"` // 校对者名单(多个用逗号分隔)
|
|
|
|
|
|
Reviewers string `db:"reviewers"` // 审核者名单(多个用逗号分隔)
|
|
|
|
|
|
PublishTime time.Time `db:"publish_time"` // 发布时间(默认插入时的当前时间)
|
|
|
|
|
|
UpdateTime time.Time `db:"update_time"` // 最后更改时间(自动更新)
|
|
|
|
|
|
IsDelete int64 `db:"is_delete"` // 逻辑删除标识:0-未删除,1-已删除
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func newSocialServiceGovernmentprogramModel(conn sqlx.SqlConn) *defaultSocialServiceGovernmentprogramModel {
|
|
|
|
|
|
return &defaultSocialServiceGovernmentprogramModel{
|
|
|
|
|
|
conn: conn,
|
|
|
|
|
|
table: "`social_service_governmentprogram`",
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *defaultSocialServiceGovernmentprogramModel) Delete(ctx context.Context, id int64) error {
|
2025-10-30 14:24:20 +08:00
|
|
|
|
// 软删除:更新is_delete字段为1(1=已删除),保留数据记录
|
|
|
|
|
|
query := fmt.Sprintf("UPDATE %s SET `is_delete` = 1, `update_time` = NOW() WHERE `id` = ? AND `is_delete` = 0", m.table)
|
2025-10-30 10:02:46 +08:00
|
|
|
|
_, err := m.conn.ExecCtx(ctx, query, id)
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *defaultSocialServiceGovernmentprogramModel) FindOne(ctx context.Context, id int64) (*SocialServiceGovernmentprogram, error) {
|
2025-10-30 14:24:20 +08:00
|
|
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? and `is_delete` = 0 limit 1", socialServiceGovernmentprogramRows, m.table)
|
2025-10-30 10:02:46 +08:00
|
|
|
|
var resp SocialServiceGovernmentprogram
|
|
|
|
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
|
|
|
|
|
switch err {
|
|
|
|
|
|
case nil:
|
|
|
|
|
|
return &resp, nil
|
|
|
|
|
|
case sqlx.ErrNotFound:
|
|
|
|
|
|
return nil, ErrNotFound
|
|
|
|
|
|
default:
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *defaultSocialServiceGovernmentprogramModel) Insert(ctx context.Context, data *SocialServiceGovernmentprogram) (sql.Result, error) {
|
|
|
|
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, socialServiceGovernmentprogramRowsExpectAutoSet)
|
|
|
|
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.Title, data.Subtitle, data.CoverUrl, data.Intro, data.Content, data.ImageEditors, data.TextEditors, data.ChiefEditor, data.Proofreaders, data.Reviewers, data.PublishTime, data.IsDelete)
|
|
|
|
|
|
return ret, err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *defaultSocialServiceGovernmentprogramModel) Update(ctx context.Context, data *SocialServiceGovernmentprogram) error {
|
|
|
|
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, socialServiceGovernmentprogramRowsWithPlaceHolder)
|
|
|
|
|
|
_, err := m.conn.ExecCtx(ctx, query, data.Title, data.Subtitle, data.CoverUrl, data.Intro, data.Content, data.ImageEditors, data.TextEditors, data.ChiefEditor, data.Proofreaders, data.Reviewers, data.PublishTime, data.IsDelete, data.Id)
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-30 14:24:20 +08:00
|
|
|
|
func (m *defaultSocialServiceGovernmentprogramModel) Count(ctx context.Context) (int64, error) {
|
|
|
|
|
|
query := fmt.Sprintf("select count(*) from %s where `is_delete` = 0", m.table)
|
|
|
|
|
|
var total int64
|
|
|
|
|
|
err := m.conn.QueryRowCtx(ctx, &total, query)
|
|
|
|
|
|
return total, err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 分页查询列表数据(带偏移量+限制条数+软删除过滤)
|
|
|
|
|
|
func (m *defaultSocialServiceGovernmentprogramModel) ListByPage(ctx context.Context, offset, limit int) ([]*SocialServiceGovernmentprogram, error) {
|
|
|
|
|
|
query := fmt.Sprintf(
|
|
|
|
|
|
"select %s from %s where `is_delete` = 0 order by `id` desc limit ?, ?",
|
|
|
|
|
|
socialServiceGovernmentprogramRows, // 包内全局变量直接引用,无前缀
|
|
|
|
|
|
m.table,
|
|
|
|
|
|
)
|
|
|
|
|
|
var list []*SocialServiceGovernmentprogram // 包内结构体直接引用,无model.前缀
|
|
|
|
|
|
err := m.conn.QueryRowsCtx(ctx, &list, query, offset, limit)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
return list, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-30 10:02:46 +08:00
|
|
|
|
func (m *defaultSocialServiceGovernmentprogramModel) tableName() string {
|
|
|
|
|
|
return m.table
|
|
|
|
|
|
}
|