image_conf.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type ImageConf struct {
  8. ImageConfId int `gorm:"column:image_conf_id;primaryKey;autoIncrement:true"`
  9. CreateTime time.Time `gorm:"column:create_time;autoCreateTime" description:"消息时间"`
  10. ModifyTime time.Time `gorm:"column:modify_time;autoUpdateTime" description:"更新时间"`
  11. ImageName string `gorm:"column:image_name;type:varchar(64);not null;default:''" description:"图片名称"`
  12. Url string `gorm:"column:url;type:varchar(512);not null;default:''" description:"图片地址"`
  13. ConfType int `gorm:"column:conf_type;type:tinyint(4) unsigned;not null;default:1" description:"配置类型 1-ppt素材"`
  14. ImageType int `gorm:"column:image_type;type:tinyint(4) unsigned;not null;default:1" description:"图片类型 1-封面图 2-背景图 3-封底图"`
  15. }
  16. type ImageConfPage struct {
  17. List []*ImageConf
  18. Paging *paging.PagingItem `description:"分页数据"`
  19. }
  20. // BatchAddImageMaterials 新增图片素材
  21. func BatchAddImageMaterials(items []*ImageConf, batchSize int) (err error) {
  22. err = global.DmSQL["rddp"].CreateInBatches(items, batchSize).Error
  23. return
  24. }
  25. // GetImageConfByName 根据图片名称查询
  26. func GetImageConfByName(imageName string) (item *ImageConf, err error) {
  27. item = &ImageConf{}
  28. err = global.DmSQL["rddp"].Where("image_name = ?", imageName).First(item).Error
  29. if err.Error() == "record not found" {
  30. return nil, nil
  31. }
  32. return item, nil
  33. }
  34. // GetImageConfByCondition 根据条件查询图片素材
  35. func GetImageConfByCondition(condition string, pars []interface{}) (list []*ImageConf, err error) {
  36. err = global.DmSQL["rddp"].Where(condition, pars...).Find(&list).Error
  37. return
  38. }
  39. // GetImageConfByConditionCount 根据条件查询图片素材数量
  40. func GetImageConfByConditionCount(condition string, pars []interface{}) (count int64, err error) {
  41. err = global.DmSQL["rddp"].Model(&ImageConf{}).Where(condition, pars...).Count(&count).Error
  42. return
  43. }