package model import ( "errors" "project_management/app/e" "project_management/global" "project_management/utils" "strings" ) type ApplyCap struct { utils.BaseModel CapId string `gorm:"type:varchar(50);" json:"cap_id" validate:"required"` CapName string `gorm:"type:varchar(50);" json:"cap_name" ` AppId string `gorm:"type:varchar(50);" json:"app_id" validate:"required"` PcIsShow int `gorm:"type:int;" json:"pc_is_show"` // 是否pc端显示 1 显示 2 不显示 MobileIsShow int `gorm:"type:int;" json:"mobile_is_show"` // 是否移动端显示 1 显示 2 不显示 Sort int `gorm:"type:int;" json:"sort"` // 排序 } func (a ApplyCap) DeleteApplyCAp(applycap ApplyCapabilities) e.Rescode { //TODO implement me tableName := "appcap_" + applycap.AppID tx := global.DBLink.Table(tableName).Where("cap_id = ?", applycap.CapID).Delete(ApplyCap{}) if tx.Error != nil { return e.DELETEFAIL } if tx.RowsAffected > 0 { return e.SUCCESS } return e.DELETEFAIL } func (a ApplyCap) UpDateApplyCap(applycap ApplyCap) e.Rescode { //TODO implement me tableName := "appcap_" + applycap.AppId tx := global.DBLink.Table(tableName).Where("cap_id = ?", applycap.CapId).Updates(applycap) if tx.Error != nil { return e.UPDATEFAIL } if tx.RowsAffected > 0 { return e.SUCCESS } return e.UPDATEFAIL } func (a ApplyCap) ApplyCapList(appid string) ([]ApplyCap, error) { //TODO implement me tableName := "appcap_" + appid var applycap []ApplyCap tx := global.DBLink.Table(tableName).Order("sort asc").Find(&applycap) if tx.Error != nil { if strings.Contains(tx.Error.Error(), "Error 1146 (42S02)") { return applycap, errors.New(e.ThereAreNoFeatures.GetMsg()) } } if tx.RowsAffected > 0 { return applycap, nil } return applycap, errors.New(e.FINDFAIL.GetMsg()) } func (a ApplyCap) ApplyAddCap(applycap ApplyCapabilities) e.Rescode { //TODO implement me var caps Capabilities tableName := "appcap_" + applycap.AppID table := global.DBLink.Migrator().HasTable(tableName) if !table { global.DBLink.Table(tableName).AutoMigrate(&ApplyCap{}) } tx := global.DBLink.Where("cap_id = ?", applycap.CapID).First(&caps) if tx.Error != nil { return e.CAPISNOT } a.CapId = applycap.CapID a.CapName = caps.CapName a.AppId = applycap.AppID a.PcIsShow = 1 a.MobileIsShow = 1 create := global.DBLink.Table(tableName).Create(&a) if create.Error != nil { return e.INSERTFAIL } return e.SUCCESS }