relation.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type RelationModel interface {
  7. List(db *gorm.DB, pagination *Pagination) ([]AdmRelation, error)
  8. Count(db *gorm.DB) (int64, error)
  9. Update(db *gorm.DB, values interface{}) error
  10. Get(db *gorm.DB) (*AdmRelation, error)
  11. }
  12. type AdmRelation struct {
  13. ID int64 `gorm:"column:id" json:"id" form:"id"`
  14. TaskId int64 `gorm:"column:task_id" json:"task_id" form:"task_id"`
  15. Desc string `gorm:"column:desc" json:"desc" form:"desc"`
  16. SourceCode string `gorm:"column:source_code" json:"source_code" form:"source_code"`
  17. IsOn string `gorm:"column:is_on" json:"is_on" form:"is_on"`
  18. CreatedAt int64 `gorm:"column:created_at" json:"created_at" form:"created_at"`
  19. UpdatedAt int64 `gorm:"column:updated_at" json:"updated_at" form:"updated_at"`
  20. }
  21. type defaultRelation struct {
  22. tableName string
  23. fields string
  24. }
  25. func NewRelation() RelationModel {
  26. return &defaultRelation{
  27. tableName: "t_adm_task_data_relation",
  28. fields: "`id`, `task_id`, `source_code`, `is_on`, `created_at`, `updated_at`",
  29. }
  30. }
  31. func (d *defaultRelation) List(db *gorm.DB, pagination *Pagination) ([]AdmRelation, error) {
  32. var res []AdmRelation
  33. err := database.List(db, &res, database.Option{
  34. TableName: d.tableName,
  35. Fields: d.fields,
  36. Limit: pagination.Limit,
  37. OffSet: pagination.Offset,
  38. })
  39. return res, err
  40. }
  41. func (d *defaultRelation) Count(db *gorm.DB) (int64, error) {
  42. return database.Count(db, database.Option{
  43. TableName: d.tableName,
  44. })
  45. }
  46. func (d *defaultRelation) Update(db *gorm.DB, values interface{}) error {
  47. return database.Update(db, values, database.Option{
  48. TableName: d.tableName,
  49. })
  50. }
  51. func (d *defaultRelation) Get(db *gorm.DB) (*AdmRelation, error) {
  52. var res AdmRelation
  53. err := database.Get(db, &res, database.Option{
  54. TableName: d.tableName,
  55. Fields: d.fields,
  56. })
  57. return &res, err
  58. }
  59. type DataTaskInfo struct {
  60. Id int64 `gorm:"column:id" json:"id" form:"id"`
  61. TaskId int64 `gorm:"column:task_id" json:"task_id" form:"task_id"`
  62. TaskName string `gorm:"column:task_name" json:"task_name" form:"task_name"`
  63. IsOn int32 `gorm:"column:is_on" json:"is_on" form:"is_on"`
  64. }