You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 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"
)
// Bundle 画展包审批
type Bundle struct {
ID uint64 `gorm:"column:id" json:"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"` // 更新时间
ReceivedAt string `gorm:"column:received_at" json:"receivedAt"` // 领取时间
2 years ago
ReturnAt string `gorm:"column:return_at" json:"ReturnAt"` // 领取时间
ApplicationsNum uint64 `gorm:"column:applications_num" json:"applicationsNum"` // 申请数量
ApprovalID uint64 `gorm:"column:approval_id" json:"approvalId"` // 绑定的申请id
}
// TableName get sql table name.获取数据库表名
func (m *Bundle) TableName() string {
return "bundle"
}
2 years ago
func (m *Bundle) SaveApprovalContent(in *approval.CreateRequest, a *Approval) error {
m.ApprovalID = a.ID
m.ReceivedAt = in.Bundle.ReceivedAt
2 years ago
m.ReturnAt = in.Bundle.ReturnAt
m.ApplicationsNum = in.Bundle.ApplicationsNum
return DB.Create(&m).Error
}
2 years ago
func (m *Bundle) UpdateApprovalContent(in *approval.CreateRequest, a *Approval) error {
var entity *Bundle
if err := DB.Where(&Bundle{ApprovalID: a.ID}).First(&entity).Error; err != nil {
return errors.New(m2.ErrorNotFound)
}
m.ID = entity.ID
//m.ApprovalID = a.ID
m.ReceivedAt = in.Bundle.ReceivedAt
m.ApplicationsNum = in.Bundle.ApplicationsNum
return DB.Save(&m).Error
}
2 years ago
func (m *Bundle) BuildResContent(a *Approval, request *approval.CreateRequest) {
if a.Bundle != nil {
request.Bundle = &approval.Bundle{
ID: a.Bundle.ID,
ReceivedAt: a.Bundle.ReceivedAt,
ApplicationsNum: a.Bundle.ApplicationsNum,
}
}
}
func (m *Bundle) DeleteApproval(p *Approval) error {
return DB.Where(&Bundle{ApprovalID: p.ID}).Delete(&Bundle{}).Error
}