knowledge_resource_file.go 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. package knowledge
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. )
  6. type KnowledgeResourceFile struct {
  7. KnowledgeResourceFileId int `gorm:"column:knowledge_resource_file_id;primaryKey;autoIncrement"`
  8. KnowledgeResourceId int `gorm:"column:knowledge_resource_id"`
  9. FileUrl string `gorm:"column:file_url"`
  10. }
  11. func (k KnowledgeResourceFile) TableName() string {
  12. return "knowledge_resource_file"
  13. }
  14. func (k *KnowledgeResourceFile) BatchAdd(items []*KnowledgeResourceFile) (err error) {
  15. err = global.DmSQL["rddp"].CreateInBatches(items, utils.MultiAddNum).Error
  16. return
  17. }
  18. func (k *KnowledgeResourceFile) DeleteByResourceId(id int) (err error) {
  19. sql := "DELETE FROM knowledge_resource_file WHERE knowledge_resource_id =?"
  20. err = global.DmSQL["rddp"].Exec(sql, id).Error
  21. return
  22. }
  23. func (k *KnowledgeResourceFile) GetByResourceId(id int) (item []*KnowledgeResourceFile, err error) {
  24. sql := "SELECT * FROM knowledge_resource_file WHERE knowledge_resource_id =?"
  25. err = global.DmSQL["rddp"].Raw(sql, id).Find(&item).Error
  26. return
  27. }