123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package semantic_analysis
- import (
- "eta_gn/eta_api/global"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strings"
- "time"
- )
- type SaLabel struct {
- SaLabelId int `gorm:"primaryKey;column:sa_label_id;type:int(10) unsigned;not null"` // 语义分析-标签Id
- LabelName string `gorm:"column:label_name;type:varchar(128);not null;default:''"` // 标签名称
- SysAdminId int `gorm:"column:sys_admin_id;type:int(10) unsigned;not null;default:0"` // 创建人Id
- SysAdminName string `gorm:"column:sys_admin_name;type:varchar(128);not null;default:''"` // 创建人姓名
- CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
- ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间
- }
- var SaLabelColumns = struct {
- SaLabelId string
- LabelName string
- SysAdminId string
- SysAdminName string
- CreateTime string
- ModifyTime string
- }{
- SaLabelId: "sa_label_id",
- LabelName: "label_name",
- SysAdminId: "sys_admin_id",
- SysAdminName: "sys_admin_name",
- CreateTime: "create_time",
- ModifyTime: "modify_time",
- }
- func (m *SaLabel) TableName() string {
- return "sa_label"
- }
- func (m *SaLabel) Create() (err error) {
- err = global.DEFAULT_DmSQL.Create(m).Error
- return
- }
- func (m *SaLabel) Update(cols []string) (err error) {
- err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error
- return
- }
- func (m *SaLabel) Del() (err error) {
- sql := `DELETE FROM sa_label WHERE sa_label_id = ? LIMIT 1`
- err = global.DEFAULT_DmSQL.Exec(sql, m.SaLabelId).Error
- return
- }
- func (m *SaLabel) GetItemById(id int) (err error) {
- sql := `SELECT * FROM sa_label WHERE sa_label_id = ? LIMIT 1`
- err = global.DEFAULT_DmSQL.Raw(sql, id).First(&m).Error
- return
- }
- func (m *SaLabel) GetItemByCondition(condition string, pars []interface{}) (err error) {
- sql := `SELECT * FROM sa_label WHERE 1=1 `
- sql += condition
- sql += ` LIMIT 1`
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&m).Error
- return
- }
- func (m *SaLabel) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
- return
- }
- func (m *SaLabel) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaLabel, err error) {
- 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 = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
- func (m *SaLabel) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaLabel, err error) {
- 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`
- err = global.DEFAULT_DmSQL.Raw(totalSql, pars...).Scan(&total).Error
- if err != nil {
- return
- }
- sql += ` LIMIT ?,?`
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
- type SaLabelAddReq struct {
- LabelName string `description:"标签名称"`
- }
- type SaLabelEditReq struct {
- SaLabelId int `description:"标签ID"`
- SaLabelAddReq
- }
- type SaLabelDelReq struct {
- SaLabelId int `description:"标签ID"`
- }
- type SaLabelPageListResp struct {
- List []*SaLabelItem
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type SaLabelItem struct {
- SaLabelId int `description:"标签ID"`
- LabelName string `description:"标签名称"`
- UserNum int `description:"引用数量"`
- SysAdminId int `description:"创建人ID"`
- SysAdminName string `description:"创建人姓名"`
- CreateTime string `description:"创建时间"`
- }
|