package dao

import "server/global"

type Description struct {
	global.GVA_MODEL
	ProjectProcessId int    `json:"projectProcessId" form:"projectProcessId" gorm:"comment:项目审批id"`
	ApprovalOpinion  string `json:"approvalOpinion" form:"approvalOpinion" gorm:"comment:审批意见"`
	NodeId           int    `json:"nodeId" form:"nodeId" gorm:"comment:节点id"`
	Node             Node   `json:"node" form:"node" gorm:"foreignKey:NodeId;references:id;"`
	ApprovalTime     string `json:"approvalTime" form:"approvalTime" gorm:"comment:审批时间"`
	OptionResult     string `json:"optionResult" form:"optionResult" gorm:"comment:操作结果"`
}

func (Description) TableName() string {
	return "description"
}

func QueryDescriptionByProjectProcessId(projectProcessId int) (descriptions []Description, err error) {
	err = global.GVA_DB.Model(&Description{}).Where("projectProcessId=?", projectProcessId).Find(&descriptions).Error
	return descriptions, err
}

func (d Description) CreateDescription() error {
	return global.GVA_DB.Create(&d).Error
}

func (d Description) UpdateDescription() error {
	return global.GVA_DB.Where("id = ?", d.ID).Updates(&d).Error
}

func (d Description) DeleteDescription() error {
	return global.GVA_DB.Unscoped().Delete(&d).Error
}
