apisql_service.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package apisql_service
  2. /*
  3. import (
  4. "errors"
  5. "tmr-watch/models"
  6. )
  7. type Apisql struct {
  8. ID int
  9. Sqlstr string
  10. Sqlname string
  11. Returetype string
  12. Method string
  13. CreatedBy string
  14. ModifiedBy string
  15. PageNum int
  16. PageSize int
  17. }
  18. func (a *Apisql) Add() (id int, err error) {
  19. data := map[string]interface{}{
  20. "Sqlstr": a.Sqlstr,
  21. "Sqlname": a.Sqlname,
  22. "Returetype": a.Returetype,
  23. "Method": a.Method,
  24. }
  25. Sqlname, _ := models.CheckSqlname(a.Sqlname)
  26. if Sqlname {
  27. return 0, errors.New("名字重复,请更改!")
  28. }
  29. if id, err := models.AddApisql(data); err == nil {
  30. return id, err
  31. } else {
  32. return 0, err
  33. }
  34. }
  35. func (a *Apisql) Edit() error {
  36. data := map[string]interface{}{
  37. "Sqlstr": a.Sqlstr,
  38. "Sqlname": a.Sqlname,
  39. "Returetype": a.Returetype,
  40. "Method": a.Method,
  41. }
  42. Sqlname, _ := models.CheckSqlname(a.Sqlname)
  43. if Sqlname {
  44. return errors.New("名字重复,请更改!")
  45. }
  46. err := models.EditApisql(a.ID, data)
  47. if err != nil {
  48. return err
  49. }
  50. return nil
  51. }
  52. func (a *Apisql) GetByName() (*models.Apisql, error) {
  53. apisql, err := models.GetApisqlByName(a.Sqlname)
  54. if err != nil {
  55. return nil, err
  56. }
  57. return apisql, nil
  58. }
  59. func (a *Apisql) GetAll() ([]*models.Apisql, error) {
  60. if a.Sqlname != "" {
  61. maps := make(map[string]interface{})
  62. maps["deleted_on"] = 0
  63. maps["sqlname"] = a.Sqlname
  64. apisql, err := models.GetApisqls(a.PageNum, a.PageSize, maps)
  65. if err != nil {
  66. return nil, err
  67. }
  68. return apisql, nil
  69. } else {
  70. apisql, err := models.GetApisqls(a.PageNum, a.PageSize, a.getMaps())
  71. if err != nil {
  72. return nil, err
  73. }
  74. return apisql, nil
  75. }
  76. }
  77. func (a *Apisql) Delete() error {
  78. err := models.DeleteApisqlByName(a.Sqlname)
  79. if err != nil {
  80. return err
  81. }
  82. return nil
  83. }
  84. func (a *Apisql) ExistByID() (bool, error) {
  85. return models.ExistApisqlByID(a.ID)
  86. }
  87. func (a *Apisql) Count() (int, error) {
  88. return models.GetApisqlTotal(a.getMaps())
  89. }
  90. func (a *Apisql) getMaps() map[string]interface{} {
  91. maps := make(map[string]interface{})
  92. maps["deleted_on"] = 0
  93. return maps
  94. }
  95. */