添加研究实习项目和乡村政府项目实现model

This commit is contained in:
2025-10-30 10:02:46 +08:00
parent 69804fea74
commit 5e3269f1bf
6 changed files with 264 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ SocialServiceGovernmentprogramModel = (*customSocialServiceGovernmentprogramModel)(nil)
type (
// SocialServiceGovernmentprogramModel is an interface to be customized, add more methods here,
// and implement the added methods in customSocialServiceGovernmentprogramModel.
SocialServiceGovernmentprogramModel interface {
socialServiceGovernmentprogramModel
withSession(session sqlx.Session) SocialServiceGovernmentprogramModel
}
customSocialServiceGovernmentprogramModel struct {
*defaultSocialServiceGovernmentprogramModel
}
)
// NewSocialServiceGovernmentprogramModel returns a model for the database table.
func NewSocialServiceGovernmentprogramModel(conn sqlx.SqlConn) SocialServiceGovernmentprogramModel {
return &customSocialServiceGovernmentprogramModel{
defaultSocialServiceGovernmentprogramModel: newSocialServiceGovernmentprogramModel(conn),
}
}
func (m *customSocialServiceGovernmentprogramModel) withSession(session sqlx.Session) SocialServiceGovernmentprogramModel {
return NewSocialServiceGovernmentprogramModel(sqlx.NewSqlConnFromSession(session))
}

View File

@@ -0,0 +1,98 @@
// 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
}
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 {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultSocialServiceGovernmentprogramModel) FindOne(ctx context.Context, id int64) (*SocialServiceGovernmentprogram, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", socialServiceGovernmentprogramRows, m.table)
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
}
func (m *defaultSocialServiceGovernmentprogramModel) tableName() string {
return m.table
}

View File

@@ -0,0 +1,5 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var ErrNotFound = sqlx.ErrNotFound