123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package models
- import (
- "eta_gn/eta_api/global"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strings"
- "time"
- )
- type OutLink struct {
- Id int `gorm:"column:id;primaryKey;autoIncrement;type:int" orm:"column(id);pk;auto" description:"自增序号"`
- Title string `gorm:"column:title;type:varchar(255)" orm:"column(title)" description:"菜单名称"`
- Url string `gorm:"column:url;type:varchar(255)" orm:"column(url)" description:"链接地址"`
- SysAdminId int `gorm:"column:sys_admin_id;type:int" orm:"column(sys_admin_id)" description:"创建人ID"`
- SysAdminName string `gorm:"column:sys_admin_name;type:varchar(255)" orm:"column(sys_admin_name)" description:"创建人姓名"`
- CreateTime time.Time `gorm:"column:create_time;type:datetime" orm:"column(create_time)" description:"创建时间"`
- ModifyTime time.Time `gorm:"column:modify_time;type:datetime" orm:"column(modify_time)" description:"修改时间"`
- }
- type OutLinkItem struct {
- Id int `description:"自增序号"`
- Title string `description:"菜单名称"`
- Url string `description:"链接地址"`
- CreateTime string `description:"创建时间"`
- ModifyTime string `description:"修改时间"`
- }
- type OutLinkListResp struct {
- List []*OutLinkItem
- UserCode string
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type OutLinkSaveReq struct {
- Id int `description:"序号"`
- Title string `description:"菜单名称"`
- Url string `description:"链接地址"`
- }
- type OutLinkReq struct {
- Id int `description:"序号"`
- }
- func (ol *OutLink) TableName() string {
- return "out_link"
- }
- func (ol *OutLink) Create() (err error) {
- err = global.DEFAULT_DmSQL.Create(ol).Error
- return
- }
- func (ol *OutLink) GetItemById(id int) (err error) {
- sql := `SELECT * FROM out_link WHERE id = ? LIMIT 1`
- err = global.DEFAULT_DmSQL.Raw(sql, id).First(ol).Error
- return
- }
- func (ol *OutLink) GetItemsByCondition(condition string, pars []interface{}, orderRule string) (items []*OutLink, err error) {
- sql := `SELECT * FROM out_link WHERE 1=1 `
- sql += condition
- order := ` ORDER BY create_time ASC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql += order
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
- func (ol *OutLink) Update(cols []string) (err error) {
- err = global.DEFAULT_DmSQL.Model(ol).Select(cols).Updates(ol).Error
- return
- }
- func (ol *OutLink) Del() (err error) {
- sql := `DELETE FROM out_link WHERE id = ? LIMIT 1`
- err = global.DEFAULT_DmSQL.Exec(sql, ol.Id).Error
- return
- }
- func (ol *OutLink) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, ol.TableName(), condition)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
- return
- }
- func (ol *OutLink) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*OutLink, err error) {
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY create_time ASC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, ol.TableName(), condition, order)
- totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
- if err = global.DEFAULT_DmSQL.Raw(totalSql, pars...).Scan(&total).Error; err != nil {
- return
- }
- sql += ` LIMIT ?,?`
- pars = append(pars, startSize)
- pars = append(pars, pageSize)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
|