|
|
package main
import ( "git.ouxuan.net/hasaki-service/hasaki-sdk/hskdb" "git.ouxuan.net/hasaki-service/hasaki-sdk/hskgin" "xorm.io/xorm" )
type Temp3A60 struct { Id int }
// ----------------------------temp------------------------------------
//wherePrimaryKey 主键查询
func (TempLowHead3A60 *Temp3A60) wherePrimaryKey() (q interface{}, args []interface{}) { //todo 根据需求修改
return "`id`=?", []interface{}{ TempLowHead3A60.Id, } }
//whereData 列表查询筛选
func (TempLowHead3A60 *Temp3A60) whereData() (q interface{}, args []interface{}) { //todo
return "", nil }
//orderData 列表查询排序
func (TempLowHead3A60 *Temp3A60) orderData() string { //todo
return "`id` desc" }
//init 数据初始化,可附加更多数据
func (TempLowHead3A60 *Temp3A60) init() { //todo
}
//saveAllCols 保存时是否全量保存
func (TempLowHead3A60 *Temp3A60) isSaveAllCols() bool { return false }
//savePretreatment 保存前预处理
func (TempLowHead3A60 *Temp3A60) savePretreatment() error { //todo
return nil }
//deletePretreatment 删除前预处理
func (TempLowHead3A60 *Temp3A60) deletePretreatment() error { //todo
return nil }
func (TempLowHead3A60 *Temp3A60) getXorm() *xorm.Engine { //todo
return hskdb.GetXormAuto() }
// ----------------------------temp------------------------------------
//Save 保存或者新增,通过wherePrimaryKey查不到数据时,新增数据,否则修改数据,参数:isAllCols...
func (TempLowHead3A60 *Temp3A60) Save(isAllCols ...bool) (err error) { tmp := Temp3A60{} whereQuery, whereArgs := TempLowHead3A60.wherePrimaryKey() TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Get(&tmp) err = TempLowHead3A60.savePretreatment() if err != nil { return } if tmp.Id == 0 { _, err = TempLowHead3A60.getXorm().Insert(TempLowHead3A60) } else { if len(isAllCols) > 0 { if isAllCols[0] { _, err = TempLowHead3A60.getXorm().AllCols().Where(whereQuery, whereArgs...).Update(TempLowHead3A60) } else { _, err = TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Update(TempLowHead3A60) } } else { if TempLowHead3A60.isSaveAllCols() { _, err = TempLowHead3A60.getXorm().AllCols().Where(whereQuery, whereArgs...).Update(TempLowHead3A60) } else { _, err = TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Update(TempLowHead3A60) } } } return err }
//Load 为实例载入数据,数据来源取决于wherePrimaryKey查找实例中的数据
func (TempLowHead3A60 *Temp3A60) Load() (err error) { whereQuery, whereArgs := TempLowHead3A60.wherePrimaryKey() _, err = TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Get(TempLowHead3A60) TempLowHead3A60.init() return }
//Data 不进行分页的数据列表
func (TempLowHead3A60 *Temp3A60) Data() (data []Temp3A60) { q, args := TempLowHead3A60.whereData() _xorm := TempLowHead3A60.getXorm() session := _xorm.NewSession() defer func() { session.Close() }() if q != "" { session = session.Where(q, args...) }
order := TempLowHead3A60.orderData() if order != "" { session = session.OrderBy(order) }
session.Find(&data) for i := range data { data[i].init() } return }
//PageData 进行分页的数据列表,page从0开始
func (TempLowHead3A60 *Temp3A60) PageData(page, pageSize int) (data []Temp3A60, count int64) { q, args := TempLowHead3A60.whereData() _xorm := TempLowHead3A60.getXorm() session := _xorm.NewSession() defer func() { session.Close() }() if q != "" { session = session.Where(q, args...) }
order := TempLowHead3A60.orderData() if order != "" { session = session.OrderBy(order) }
count, _ = session.Limit(pageSize, page*pageSize).FindAndCount(&data) for i := range data { data[i].init() } return }
//Delete 删除数据
func (TempLowHead3A60 *Temp3A60) Delete() (err error) { whereQuery, whereArgs := TempLowHead3A60.wherePrimaryKey() err = TempLowHead3A60.deletePretreatment() if err != nil { return } _, err = TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Delete(TempLowHead3A60) return }
// ----------------------------temp------------------------------------
func InitializationHttpCrudPrefixHigHead3A60Temp3A60(router *hskgin.GinHelper, authoritys ...func(ctx *hskgin.GinContextHelper, TempLowHead3A60 *Temp3A60)) { var authority = func(ctx *hskgin.GinContextHelper, TempLowHead3A60 *Temp3A60) { } if len(authoritys) > 0 { authority = authoritys[0] }
router.Any("/Prefix3A60/TempLowHead3A60/get", func(ctx *hskgin.GinContextHelper) { req := &Temp3A60{} ctx.Bind(req) authority(ctx, req) err := req.Load() ctx.CheckErrDisplayByError(err) ctx.DisplayByData(req) })
router.Any("/Prefix3A60/TempLowHead3A60/save", func(ctx *hskgin.GinContextHelper) { req := &Temp3A60{} ctx.Bind(&req) authority(ctx, req) err := req.Save() ctx.CheckErrDisplayByError(err) err = req.Load() ctx.CheckErrDisplayByError(err) ctx.DisplayByData(req) })
router.Any("/Prefix3A60/TempLowHead3A60/data", func(ctx *hskgin.GinContextHelper) { req := &Temp3A60{} ctx.Bind(&req) authority(ctx, req) data := req.Data() ctx.DisplayByData(data) })
router.Any("/Prefix3A60/TempLowHead3A60/list", func(ctx *hskgin.GinContextHelper) { req := &Temp3A60{} ctx.Bind(&req) authority(ctx, req) page := ctx.ParamRequired2Page(true) data, count := req.PageData(page, 10) ctx.DisplayByPage(data, count) })
router.Any("/Prefix3A60/TempLowHead3A60/delete", func(ctx *hskgin.GinContextHelper) { req := &Temp3A60{} ctx.Bind(&req) authority(ctx, req) err := req.Delete() ctx.CheckErrDisplayByError(err) ctx.DisplayBySuccess("删除成功") }) }
// ----------------------------temp------------------------------------
|