You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.6 KiB

4 years ago
  1. package main
  2. import (
  3. "git.ouxuan.net/hasaki-service/hasaki-sdk/hskdb"
  4. "git.ouxuan.net/hasaki-service/hasaki-sdk/hskgin"
  5. )
  6. type Temp3A60 struct {
  7. Id int
  8. }
  9. // ----------------------------temp------------------------------------
  10. func (that *Temp3A60) where() (q interface{}, args []interface{}) {
  11. //todo 根据需求修改
  12. return "`id`=?", []interface{}{
  13. that.Id,
  14. }
  15. }
  16. func (that *Temp3A60) Save(isCols ...bool) (err error) {
  17. tmp := Temp3A60{}
  18. whereQuery, whereArgs := that.where()
  19. hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Get(&tmp)
  20. if tmp.Id == 0 {
  21. _, err = hskdb.GetXormAuto().Insert(that)
  22. } else {
  23. if len(isCols) > 0 && isCols[0] {
  24. _, err = hskdb.GetXormAuto().AllCols().Where(whereQuery, whereArgs...).Update(that)
  25. } else {
  26. _, err = hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Update(that)
  27. }
  28. }
  29. return err
  30. }
  31. func (that *Temp3A60) Load() (err error) {
  32. whereQuery, whereArgs := that.where()
  33. _, err = hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Get(&that)
  34. return
  35. }
  36. func (that *Temp3A60) Data() (data []Temp3A60) {
  37. hskdb.GetXormAuto().OrderBy("id desc").Find(&data)
  38. return
  39. }
  40. func (that *Temp3A60) PageData(page, pageSize int) (data []Temp3A60, count int64) {
  41. count, _ = hskdb.GetXormAuto().OrderBy("id desc").Limit(pageSize, page*pageSize).FindAndCount(&data)
  42. return
  43. }
  44. func (that *Temp3A60) Delete() (err error) {
  45. whereQuery, whereArgs := that.where()
  46. _, err = hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Delete(&that)
  47. return
  48. }
  49. //该方法请不要放在db文件中
  50. func InitializationTemp3A60(router *hskgin.GinHelper) {
  51. var authority = func(ctx *hskgin.GinContextHelper) {
  52. //todo 权限控制
  53. }
  54. router.Any("/?????/Temp3A60/get", func(ctx *hskgin.GinContextHelper) {
  55. authority(ctx)
  56. req := Temp3A60{}
  57. ctx.Bind(&req)
  58. err := req.Load()
  59. ctx.CheckErrDisplayByError(err)
  60. ctx.DisplayByData(req)
  61. })
  62. router.Any("/?????/Temp3A60/save", func(ctx *hskgin.GinContextHelper) {
  63. authority(ctx)
  64. req := Temp3A60{}
  65. ctx.Bind(&req)
  66. err := req.Save()
  67. ctx.CheckErrDisplayByError(err)
  68. err = req.Load()
  69. ctx.CheckErrDisplayByError(err)
  70. ctx.DisplayByData(req)
  71. })
  72. router.Any("/?????/Temp3A60/data", func(ctx *hskgin.GinContextHelper) {
  73. authority(ctx)
  74. req := Temp3A60{}
  75. ctx.Bind(&req)
  76. data := req.Data()
  77. ctx.DisplayByData(data)
  78. })
  79. router.Any("/?????/Temp3A60/list", func(ctx *hskgin.GinContextHelper) {
  80. authority(ctx)
  81. req := Temp3A60{}
  82. ctx.Bind(&req)
  83. page := ctx.ParamRequired2Page(true)
  84. data, count := req.PageData(page, 10)
  85. ctx.DisplayByPage(data, count)
  86. })
  87. }
  88. // ----------------------------temp------------------------------------