base_from_rzd_classify.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // @Author gmy 2024/8/7 9:26:00
  2. package models
  3. import (
  4. "errors"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. type BaseFromRzdClassify struct {
  8. BaseFromRzdClassifyId int `orm:"column(base_from_rzd_classify_id);pk"`
  9. CreateTime string `orm:"column(create_time)"`
  10. ModifyTime string `orm:"column(modify_time)"`
  11. ClassifyName string `orm:"column(classify_name)"`
  12. ParentId int `orm:"column(parent_id)"`
  13. Sort int `orm:"column(sort)"`
  14. ClassifyNameEn string `orm:"column(classify_name_en)"`
  15. }
  16. func init() {
  17. orm.RegisterModel(new(BaseFromRzdClassify))
  18. }
  19. // GetRzdClassifyByName 根据分类名称查询
  20. func GetRzdClassifyByName(classifyName string) (item *BaseFromRzdClassify, err error) {
  21. o := orm.NewOrm()
  22. sql := `SELECT * FROM base_from_rzd_classify WHERE classify_name=?`
  23. err = o.Raw(sql, classifyName).QueryRow(&item)
  24. if errors.Is(err, orm.ErrNoRows) {
  25. return nil, nil
  26. }
  27. return
  28. }
  29. // AddRzdClassify 新增分类
  30. func AddRzdClassify(classify *BaseFromRzdClassify) (int64, error) {
  31. o := orm.NewOrm()
  32. id, err := o.Insert(classify)
  33. if err != nil {
  34. return 0, err
  35. }
  36. return id, nil
  37. }