dependency.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type DependencyModel interface {
  7. List(db *gorm.DB, pagination *Pagination) ([]AdmDependency, error)
  8. Count(db *gorm.DB) (int64, error)
  9. Update(db *gorm.DB, values interface{}) error
  10. GetSourceByTaskId(db *gorm.DB) (*AdmDataList, error)
  11. }
  12. type AdmDependency 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. CreatedAt int64 `gorm:"column:created_at" json:"created_at" form:"created_at"`
  18. UpdatedAt int64 `gorm:"column:updated_at" json:"updated_at" form:"updated_at"`
  19. }
  20. type defaultDependency struct {
  21. tableName string
  22. fields string
  23. }
  24. func NewDependency() DependencyModel {
  25. return &defaultDependency{
  26. tableName: "t_adm_task_dependency",
  27. fields: "`id`, `task_id`, `source_code`, `created_at`, `updated_at`",
  28. }
  29. }
  30. func (d *defaultDependency) List(db *gorm.DB, pagination *Pagination) ([]AdmDependency, error) {
  31. var res []AdmDependency
  32. err := database.List(db, &res, database.Option{
  33. TableName: d.tableName,
  34. Fields: d.fields,
  35. Limit: pagination.Limit,
  36. OffSet: pagination.Offset,
  37. })
  38. return res, err
  39. }
  40. func (d *defaultDependency) Count(db *gorm.DB) (int64, error) {
  41. return database.Count(db, database.Option{
  42. TableName: d.tableName,
  43. })
  44. }
  45. func (d *defaultDependency) Update(db *gorm.DB, values interface{}) error {
  46. return database.Update(db, values, database.Option{
  47. TableName: d.tableName,
  48. })
  49. }
  50. type DependencyInfo struct {
  51. TableName string `gorm:"column:table_name" json:"table_name" form:"table_name"`
  52. Desc string `gorm:"column:desc" json:"desc" form:"desc"`
  53. }
  54. func (d *defaultDependency) GetSourceByTaskId(db *gorm.DB) (*AdmDataList, error) {
  55. var res AdmDataList
  56. err := database.Get(db, &res, database.Option{
  57. TableName: d.tableName + " AS t1",
  58. Fields: "t2.*",
  59. Joins: []string{"LEFT JOIN t_adm_data_management AS t2 ON t1.source_code = t2.source_code"},
  60. })
  61. return &res, err
  62. }