1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package model
- import (
- "git.getensh.com/common/gopkgsv2/database"
- "gorm.io/gorm"
- )
- type DependencyModel interface {
- List(db *gorm.DB, pagination *Pagination) ([]AdmDependency, error)
- Count(db *gorm.DB) (int64, error)
- Update(db *gorm.DB, values interface{}) error
- GetSourceByTaskId(db *gorm.DB) (*AdmDataList, error)
- }
- type AdmDependency struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- TaskId int64 `gorm:"column:task_id" json:"task_id" form:"task_id"`
- Desc string `gorm:"column:desc" json:"desc" form:"desc"`
- SourceCode string `gorm:"column:source_code" json:"source_code" form:"source_code"`
- CreatedAt int64 `gorm:"column:created_at" json:"created_at" form:"created_at"`
- UpdatedAt int64 `gorm:"column:updated_at" json:"updated_at" form:"updated_at"`
- }
- type defaultDependency struct {
- tableName string
- fields string
- }
- func NewDependency() DependencyModel {
- return &defaultDependency{
- tableName: "t_adm_task_dependency",
- fields: "`id`, `task_id`, `source_code`, `created_at`, `updated_at`",
- }
- }
- func (d *defaultDependency) List(db *gorm.DB, pagination *Pagination) ([]AdmDependency, error) {
- var res []AdmDependency
- err := database.List(db, &res, database.Option{
- TableName: d.tableName,
- Fields: d.fields,
- Limit: pagination.Limit,
- OffSet: pagination.Offset,
- })
- return res, err
- }
- func (d *defaultDependency) Count(db *gorm.DB) (int64, error) {
- return database.Count(db, database.Option{
- TableName: d.tableName,
- })
- }
- func (d *defaultDependency) Update(db *gorm.DB, values interface{}) error {
- return database.Update(db, values, database.Option{
- TableName: d.tableName,
- })
- }
- type DependencyInfo struct {
- TableName string `gorm:"column:table_name" json:"table_name" form:"table_name"`
- Desc string `gorm:"column:desc" json:"desc" form:"desc"`
- }
- func (d *defaultDependency) GetSourceByTaskId(db *gorm.DB) (*AdmDataList, error) {
- var res AdmDataList
- err := database.Get(db, &res, database.Option{
- TableName: d.tableName + " AS t1",
- Fields: "t2.*",
- Joins: []string{"LEFT JOIN t_adm_data_management AS t2 ON t1.source_code = t2.source_code"},
- })
- return &res, err
- }
|