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.

216 lines
5.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
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. "xorm.io/xorm"
  6. )
  7. type Temp3A60 struct {
  8. Id int
  9. }
  10. // ----------------------------temp------------------------------------
  11. //wherePrimaryKey 主键查询
  12. func (TempLowHead3A60 *Temp3A60) wherePrimaryKey() (q interface{}, args []interface{}) {
  13. //todo 根据需求修改
  14. return "`id`=?", []interface{}{
  15. TempLowHead3A60.Id,
  16. }
  17. }
  18. //whereData 列表查询筛选
  19. func (TempLowHead3A60 *Temp3A60) whereData() (q interface{}, args []interface{}) {
  20. //todo
  21. return "", nil
  22. }
  23. //orderData 列表查询排序
  24. func (TempLowHead3A60 *Temp3A60) orderData() string {
  25. //todo
  26. return "`id` desc"
  27. }
  28. //init 数据初始化,可附加更多数据
  29. func (TempLowHead3A60 *Temp3A60) init() {
  30. //todo
  31. }
  32. //saveAllCols 保存时是否全量保存
  33. func (TempLowHead3A60 *Temp3A60) isSaveAllCols() bool {
  34. return false
  35. }
  36. //savePretreatment 保存前预处理
  37. func (TempLowHead3A60 *Temp3A60) savePretreatment() error {
  38. //todo
  39. return nil
  40. }
  41. //deletePretreatment 删除前预处理
  42. func (TempLowHead3A60 *Temp3A60) deletePretreatment() error {
  43. //todo
  44. return nil
  45. }
  46. func (TempLowHead3A60 *Temp3A60) getXorm() *xorm.Engine {
  47. //todo
  48. return hskdb.GetXormAuto()
  49. }
  50. // ----------------------------temp------------------------------------
  51. //Save 保存或者新增,通过wherePrimaryKey查不到数据时,新增数据,否则修改数据,参数:isAllCols...
  52. func (TempLowHead3A60 *Temp3A60) Save(isAllCols ...bool) (err error) {
  53. tmp := Temp3A60{}
  54. whereQuery, whereArgs := TempLowHead3A60.wherePrimaryKey()
  55. TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Get(&tmp)
  56. err = TempLowHead3A60.savePretreatment()
  57. if err != nil {
  58. return
  59. }
  60. if tmp.Id == 0 {
  61. _, err = TempLowHead3A60.getXorm().Insert(TempLowHead3A60)
  62. } else {
  63. if len(isAllCols) > 0 {
  64. if isAllCols[0] {
  65. _, err = TempLowHead3A60.getXorm().AllCols().Where(whereQuery, whereArgs...).Update(TempLowHead3A60)
  66. } else {
  67. _, err = TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Update(TempLowHead3A60)
  68. }
  69. } else {
  70. if TempLowHead3A60.isSaveAllCols() {
  71. _, err = TempLowHead3A60.getXorm().AllCols().Where(whereQuery, whereArgs...).Update(TempLowHead3A60)
  72. } else {
  73. _, err = TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Update(TempLowHead3A60)
  74. }
  75. }
  76. }
  77. return err
  78. }
  79. //Load 为实例载入数据,数据来源取决于wherePrimaryKey查找实例中的数据
  80. func (TempLowHead3A60 *Temp3A60) Load() (err error) {
  81. whereQuery, whereArgs := TempLowHead3A60.wherePrimaryKey()
  82. _, err = TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Get(TempLowHead3A60)
  83. TempLowHead3A60.init()
  84. return
  85. }
  86. //Data 不进行分页的数据列表
  87. func (TempLowHead3A60 *Temp3A60) Data() (data []Temp3A60) {
  88. q, args := TempLowHead3A60.whereData()
  89. _xorm := TempLowHead3A60.getXorm()
  90. session := _xorm.NewSession()
  91. defer func() {
  92. session.Close()
  93. }()
  94. if q != "" {
  95. session = session.Where(q, args...)
  96. }
  97. order := TempLowHead3A60.orderData()
  98. if order != "" {
  99. session = session.OrderBy(order)
  100. }
  101. session.Find(&data)
  102. for i := range data {
  103. data[i].init()
  104. }
  105. return
  106. }
  107. //PageData 进行分页的数据列表,page从0开始
  108. func (TempLowHead3A60 *Temp3A60) PageData(page, pageSize int) (data []Temp3A60, count int64) {
  109. q, args := TempLowHead3A60.whereData()
  110. _xorm := TempLowHead3A60.getXorm()
  111. session := _xorm.NewSession()
  112. defer func() {
  113. session.Close()
  114. }()
  115. if q != "" {
  116. session = session.Where(q, args...)
  117. }
  118. order := TempLowHead3A60.orderData()
  119. if order != "" {
  120. session = session.OrderBy(order)
  121. }
  122. count, _ = session.Limit(pageSize, page*pageSize).FindAndCount(&data)
  123. for i := range data {
  124. data[i].init()
  125. }
  126. return
  127. }
  128. //Delete 删除数据
  129. func (TempLowHead3A60 *Temp3A60) Delete() (err error) {
  130. whereQuery, whereArgs := TempLowHead3A60.wherePrimaryKey()
  131. err = TempLowHead3A60.deletePretreatment()
  132. if err != nil {
  133. return
  134. }
  135. _, err = TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Delete(TempLowHead3A60)
  136. return
  137. }
  138. // ----------------------------temp------------------------------------
  139. func InitializationHttpCrudPrefixHigHead3A60Temp3A60(router *hskgin.GinHelper, authoritys ...func(ctx *hskgin.GinContextHelper, TempLowHead3A60 *Temp3A60)) {
  140. var authority = func(ctx *hskgin.GinContextHelper, TempLowHead3A60 *Temp3A60) {
  141. }
  142. if len(authoritys) > 0 {
  143. authority = authoritys[0]
  144. }
  145. router.Any("/Prefix3A60/TempLowHead3A60/get", func(ctx *hskgin.GinContextHelper) {
  146. req := &Temp3A60{}
  147. ctx.Bind(req)
  148. authority(ctx, req)
  149. err := req.Load()
  150. ctx.CheckErrDisplayByError(err)
  151. ctx.DisplayByData(req)
  152. })
  153. router.Any("/Prefix3A60/TempLowHead3A60/save", func(ctx *hskgin.GinContextHelper) {
  154. req := &Temp3A60{}
  155. ctx.Bind(&req)
  156. authority(ctx, req)
  157. err := req.Save()
  158. ctx.CheckErrDisplayByError(err)
  159. err = req.Load()
  160. ctx.CheckErrDisplayByError(err)
  161. ctx.DisplayByData(req)
  162. })
  163. router.Any("/Prefix3A60/TempLowHead3A60/data", func(ctx *hskgin.GinContextHelper) {
  164. req := &Temp3A60{}
  165. ctx.Bind(&req)
  166. authority(ctx, req)
  167. data := req.Data()
  168. ctx.DisplayByData(data)
  169. })
  170. router.Any("/Prefix3A60/TempLowHead3A60/list", func(ctx *hskgin.GinContextHelper) {
  171. req := &Temp3A60{}
  172. ctx.Bind(&req)
  173. authority(ctx, req)
  174. page := ctx.ParamRequired2Page(true)
  175. data, count := req.PageData(page, 10)
  176. ctx.DisplayByPage(data, count)
  177. })
  178. router.Any("/Prefix3A60/TempLowHead3A60/delete", func(ctx *hskgin.GinContextHelper) {
  179. req := &Temp3A60{}
  180. ctx.Bind(&req)
  181. authority(ctx, req)
  182. err := req.Delete()
  183. ctx.CheckErrDisplayByError(err)
  184. ctx.DisplayBySuccess("删除成功")
  185. })
  186. }
  187. // ----------------------------temp------------------------------------