123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package semantic_analysis
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strings"
- "time"
- )
- type SaDocClassify struct {
- SaDocClassifyId int `orm:"column(sa_doc_classify_id);pk" description:"分类ID"`
- ClassifyName string `description:"分类名称"`
- CoverImg string `description:"封面图"`
- SysAdminId int `description:"创建人ID"`
- SysAdminName string `description:"创建人名称"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- }
- var SaDocClassifyColumns = struct {
- SaDocClassifyId string
- ClassifyName string
- CoverImg string
- SysAdminId string
- SysAdminName string
- CreateTime string
- ModifyTime string
- }{
- SaDocClassifyId: "sa_doc_classify_id",
- ClassifyName: "classify_name",
- CoverImg: "cover_img",
- SysAdminId: "sys_admin_id",
- SysAdminName: "sys_admin_name",
- CreateTime: "create_time",
- ModifyTime: "modify_time",
- }
- func (m *SaDocClassify) TableName() string {
- return "sa_doc_classify"
- }
- func (m *SaDocClassify) Create() (err error) {
- o := orm.NewOrm()
- id, err := o.Insert(m)
- if err != nil {
- return
- }
- m.SaDocClassifyId = int(id)
- return
- }
- func (m *SaDocClassify) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(m, cols...)
- return
- }
- func (m *SaDocClassify) Del() (err error) {
- o := orm.NewOrm()
- sql := `DELETE FROM sa_doc_classify WHERE sa_doc_classify_id = ? LIMIT 1`
- _, err = o.Raw(sql, m.SaDocClassifyId).Exec()
- return
- }
- func (m *SaDocClassify) GetItemById(id int) (err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM sa_doc_classify WHERE sa_doc_classify_id = ? LIMIT 1`
- err = o.Raw(sql, id).QueryRow(&m)
- return
- }
- func (m *SaDocClassify) GetItemByCondition(condition string, pars []interface{}) (err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM sa_doc_classify WHERE 1=1 `
- sql += condition
- sql += ` LIMIT 1`
- err = o.Raw(sql, pars).QueryRow(&m)
- return
- }
- func (m *SaDocClassify) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func (m *SaDocClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaDocClassify, err error) {
- o := orm.NewOrm()
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- func (m *SaDocClassify) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaDocClassify, err error) {
- o := orm.NewOrm()
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
- if err = o.Raw(totalSql, pars).QueryRow(&total); err != nil {
- return
- }
- sql += ` LIMIT ?,?`
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- type SaDocClassifyAddReq struct {
- ClassifyName string `description:"分类名称"`
- CoverImg string `description:"封面图"`
- }
- type SaDocClassifyEditReq struct {
- SaDocClassifyId int `description:"分类ID"`
- SaDocClassifyAddReq
- }
- type SaDocClassifyDelReq struct {
- SaDocClassifyId int `description:"分类ID"`
- }
- type SaDocClassifyPageListResp struct {
- List []*SaDocClassifyItem
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type SaDocClassifyItem struct {
- SaDocClassifyId int `description:"分类ID"`
- ClassifyName string `description:"分类名称"`
- CoverImg string `description:"封面图"`
- SysAdminId int `description:"创建人ID"`
- SysAdminName string `description:"创建人名称"`
- CreateTime string `description:"创建时间"`
- Children []*SaDocClassifyChildrenItem `description:"分类下的文档"`
- }
- type SaDocClassifyChildrenItem struct {
- SaDocId int `description:"文档ID"`
- Title string `description:"文档标题"`
- Theme string `description:"文档主题"`
- CreateTime string `description:"创建时间"`
- UseNum int `description:"引用数"`
- }
|