78 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			78 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package model
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 	"github.com/fonchain_enterprise/fonchain-approval/api/approval"
 | |
| 	m2 "github.com/fonchain_enterprise/fonchain-approval/pkg/m"
 | |
| 	"gorm.io/plugin/soft_delete"
 | |
| 	"time"
 | |
| )
 | |
| 
 | |
| // Show 画展审批
 | |
| type Show struct {
 | |
| 	ID         uint64                `gorm:"primaryKey;column:id" json:"id"`       // ID
 | |
| 	DeletedAt  soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"`   // 删除时间
 | |
| 	CreatedAt  time.Time             `gorm:"column:created_at" json:"createdAt"`   // 创建时间
 | |
| 	UpdatedAt  time.Time             `gorm:"column:updated_at" json:"updatedAt"`   // 更新时间
 | |
| 	ArtistNum  uint64                `gorm:"column:artist_num" json:"artistNum"`   // 艺术家数量
 | |
| 	ShowAt     string                `gorm:"column:show_at" json:"showAt"`         // 画展时间
 | |
| 	ApprovalID uint64                `gorm:"column:approval_id" json:"approvalId"` // 关联申请的ID
 | |
| }
 | |
| 
 | |
| // TableName get sql table name.获取数据库表名
 | |
| func (m *Show) TableName() string {
 | |
| 	return "show"
 | |
| }
 | |
| 
 | |
| func (m *Show) SaveApprovalContent(in *approval.CreateRequest, a *Approval) error {
 | |
| 	m.ArtistNum = in.Show.ArtistNum
 | |
| 	m.ApprovalID = a.ID
 | |
| 	m.ShowAt = in.Show.ShowAt
 | |
| 	return DB.Create(&m).Error
 | |
| }
 | |
| 
 | |
| func (m *Show) UpdateApprovalContent(in *approval.CreateRequest, a *Approval) error {
 | |
| 
 | |
| 	var entity *Show
 | |
| 
 | |
| 	if err := DB.Where(&Show{ApprovalID: a.ID}).First(&entity).Error; err != nil {
 | |
| 		return errors.New(m2.ErrorNotFound)
 | |
| 	}
 | |
| 
 | |
| 	m.ID = entity.ID
 | |
| 	m.ArtistNum = in.Show.ArtistNum
 | |
| 	m.ShowAt = in.Show.ShowAt
 | |
| 	return DB.Save(&m).Error
 | |
| }
 | |
| 
 | |
| func (m *Show) BuildResContent(a *Approval, request *approval.CreateRequest) {
 | |
| 	if a.Show != nil {
 | |
| 		request.Show = &approval.Show{
 | |
| 			ID:        a.Show.ID,
 | |
| 			ArtistNum: a.Show.ArtistNum,
 | |
| 			ShowAt:    a.Show.ShowAt,
 | |
| 		}
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (m *Show) DeleteApproval(p *Approval) error {
 | |
| 	return DB.Where(&Show{ApprovalID: p.ID}).Delete(&Show{}).Error
 | |
| }
 | |
| 
 | |
| // ShowColumns get sql column name.获取数据库列名
 | |
| var ShowColumns = struct {
 | |
| 	ID        string
 | |
| 	DeletedAt string
 | |
| 	CreatedAt string
 | |
| 	UpdatedAt string
 | |
| 	ArtistNum string
 | |
| 	ShowAt    string
 | |
| }{
 | |
| 	ID:        "id",
 | |
| 	DeletedAt: "deleted_at",
 | |
| 	CreatedAt: "created_at",
 | |
| 	UpdatedAt: "updated_at",
 | |
| 	ArtistNum: "artist_num",
 | |
| 	ShowAt:    "show_at",
 | |
| }
 |