applyCap.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package model
  2. import (
  3. "errors"
  4. "project_management/app/e"
  5. "project_management/global"
  6. "project_management/utils"
  7. "strings"
  8. )
  9. type ApplyCap struct {
  10. utils.BaseModel
  11. CapId string `gorm:"type:varchar(50);" json:"cap_id" validate:"required"`
  12. CapName string `gorm:"type:varchar(50);" json:"cap_name" `
  13. AppId string `gorm:"type:varchar(50);" json:"app_id" validate:"required"`
  14. PcIsShow int `gorm:"type:int;" json:"pc_is_show"` // 是否pc端显示 1 显示 2 不显示
  15. MobileIsShow int `gorm:"type:int;" json:"mobile_is_show"` // 是否移动端显示 1 显示 2 不显示
  16. Sort int `gorm:"type:int;" json:"sort"` // 排序
  17. }
  18. func (a ApplyCap) DeleteApplyCAp(applycap ApplyCapabilities) e.Rescode {
  19. //TODO implement me
  20. tableName := "appcap_" + applycap.AppID
  21. tx := global.DBLink.Table(tableName).Where("cap_id = ?", applycap.CapID).Delete(ApplyCap{})
  22. if tx.Error != nil {
  23. return e.DELETEFAIL
  24. }
  25. if tx.RowsAffected > 0 {
  26. return e.SUCCESS
  27. }
  28. return e.DELETEFAIL
  29. }
  30. func (a ApplyCap) UpDateApplyCap(applycap ApplyCap) e.Rescode {
  31. //TODO implement me
  32. tableName := "appcap_" + applycap.AppId
  33. tx := global.DBLink.Table(tableName).Where("cap_id = ?", applycap.CapId).Updates(applycap)
  34. if tx.Error != nil {
  35. return e.UPDATEFAIL
  36. }
  37. if tx.RowsAffected > 0 {
  38. return e.SUCCESS
  39. }
  40. return e.UPDATEFAIL
  41. }
  42. func (a ApplyCap) ApplyCapList(appid string) ([]ApplyCap, error) {
  43. //TODO implement me
  44. tableName := "appcap_" + appid
  45. var applycap []ApplyCap
  46. tx := global.DBLink.Table(tableName).Order("sort asc").Find(&applycap)
  47. if tx.Error != nil {
  48. if strings.Contains(tx.Error.Error(), "Error 1146 (42S02)") {
  49. return applycap, errors.New(e.ThereAreNoFeatures.GetMsg())
  50. }
  51. }
  52. if tx.RowsAffected > 0 {
  53. return applycap, nil
  54. }
  55. return applycap, errors.New(e.FINDFAIL.GetMsg())
  56. }
  57. func (a ApplyCap) ApplyAddCap(applycap ApplyCapabilities) e.Rescode {
  58. //TODO implement me
  59. var caps Capabilities
  60. tableName := "appcap_" + applycap.AppID
  61. table := global.DBLink.Migrator().HasTable(tableName)
  62. if !table {
  63. global.DBLink.Table(tableName).AutoMigrate(&ApplyCap{})
  64. }
  65. tx := global.DBLink.Where("cap_id = ?", applycap.CapID).First(&caps)
  66. if tx.Error != nil {
  67. return e.CAPISNOT
  68. }
  69. a.CapId = applycap.CapID
  70. a.CapName = caps.CapName
  71. a.AppId = applycap.AppID
  72. a.PcIsShow = 1
  73. a.MobileIsShow = 1
  74. create := global.DBLink.Table(tableName).Create(&a)
  75. if create.Error != nil {
  76. return e.INSERTFAIL
  77. }
  78. return e.SUCCESS
  79. }