image_sources.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. func (i *ImageSource) TableName() string {
  7. return "image_sources"
  8. }
  9. type ImageSource struct {
  10. Id int ` description:"Id"`
  11. ImgName string `description:"图片名称"`
  12. SrcUrl string `description:"图片资源"`
  13. PermissionId int `description:"品种"`
  14. Deleted int `description:"是否删除"`
  15. CreatedTime time.Time `description:"创建时间"`
  16. UpdatedTime time.Time `description:"更新时间"`
  17. }
  18. func (i *ImageSource) Insert() (insertId int64, err error) {
  19. o := orm.NewOrm()
  20. insertId, err = o.Insert(i)
  21. return
  22. }
  23. func (i *ImageSource) Update() (err error) {
  24. o := orm.NewOrm()
  25. _, err = o.Update(i, "img_name", "src_url", "permission_id")
  26. return
  27. }
  28. func (i *ImageSource) Delete() (err error) {
  29. o := orm.NewOrm()
  30. _, err = o.Update(i, "deleted")
  31. return
  32. }
  33. func GetImageIdByPermissionId(permissionId int) (items []int, err error) {
  34. o := orm.NewOrm()
  35. sql := "select id from image_sources where permission_id = ?"
  36. _, err = o.Raw(sql, permissionId).QueryRows(&items)
  37. return
  38. }
  39. func GetImageById(Id int) (item *ImageSource, err error) {
  40. o := orm.NewOrm()
  41. sql := "select id from image_sources where id = ?"
  42. err = o.Raw(sql, Id).QueryRow(&item)
  43. return
  44. }