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.
 
 

108 lines
3.0 KiB

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------------------------------------
func (TempLowHead3A60 *Temp3A60) where() (q interface{}, args []interface{}) {
//todo 根据需求修改
return "`id`=?", []interface{}{
TempLowHead3A60.Id,
}
}
func (TempLowHead3A60 *Temp3A60) getXorm() *xorm.Engine {
return hskdb.GetXormAuto()
}
func (TempLowHead3A60 *Temp3A60) Save(isAllCols ...bool) (err error) {
tmp := Temp3A60{}
whereQuery, whereArgs := TempLowHead3A60.where()
TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Get(&tmp)
if tmp.Id == 0 {
_, err = TempLowHead3A60.getXorm().Insert(TempLowHead3A60)
} else {
if len(isAllCols) > 0 && isAllCols[0] {
_, err = TempLowHead3A60.getXorm().AllCols().Where(whereQuery, whereArgs...).Update(TempLowHead3A60)
} else {
_, err = TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Update(TempLowHead3A60)
}
}
return err
}
func (TempLowHead3A60 *Temp3A60) Load() (err error) {
whereQuery, whereArgs := TempLowHead3A60.where()
_, err = TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Get(&TempLowHead3A60)
return
}
func (TempLowHead3A60 *Temp3A60) Data() (data []Temp3A60) {
TempLowHead3A60.getXorm().OrderBy("id desc").Find(&data)
return
}
func (TempLowHead3A60 *Temp3A60) PageData(page, pageSize int) (data []Temp3A60, count int64) {
count, _ = TempLowHead3A60.getXorm().OrderBy("id desc").Limit(pageSize, page*pageSize).FindAndCount(&data)
return
}
func (TempLowHead3A60 *Temp3A60) Delete() (err error) {
whereQuery, whereArgs := TempLowHead3A60.where()
_, err = TempLowHead3A60.getXorm().Where(whereQuery, whereArgs...).Delete(&TempLowHead3A60)
return
}
//该方法请不要放在db文件中
func InitializationTemp3A60(router *hskgin.GinHelper) {
var authority = func(ctx *hskgin.GinContextHelper) {
//todo 权限控制
}
router.Any("/Prefix3A60/TempLowHead3A60/get", func(ctx *hskgin.GinContextHelper) {
authority(ctx)
req := Temp3A60{}
ctx.Bind(&req)
err := req.Load()
ctx.CheckErrDisplayByError(err)
ctx.DisplayByData(req)
})
router.Any("/Prefix3A60/TempLowHead3A60/save", func(ctx *hskgin.GinContextHelper) {
authority(ctx)
req := Temp3A60{}
ctx.Bind(&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) {
authority(ctx)
req := Temp3A60{}
ctx.Bind(&req)
data := req.Data()
ctx.DisplayByData(data)
})
router.Any("/Prefix3A60/TempLowHead3A60/list", func(ctx *hskgin.GinContextHelper) {
authority(ctx)
req := Temp3A60{}
ctx.Bind(&req)
page := ctx.ParamRequired2Page(true)
data, count := req.PageData(page, 10)
ctx.DisplayByPage(data, count)
})
}
// ----------------------------temp------------------------------------