package semantic_analysis import ( "eta/eta_api/global" "eta/eta_api/utils" "fmt" "strings" ) type SaDocSection struct { SaDocSectionId int `orm:"column(sa_doc_section_id);pk" gorm:"primaryKey" description:"段落ID"` DocId int `description:"文档ID"` Content string `description:"段落内容"` Sort int `description:"排序"` } var SaDocSectionColumns = struct { SaDocSectionId string DocId string Content string Sort string }{ SaDocSectionId: "sa_doc_section_id", DocId: "doc_id", Content: "content", Sort: "sort", } func (m *SaDocSection) TableName() string { return "sa_doc_section" } func (m *SaDocSection) Create() (err error) { o := global.DbMap[utils.DbNameMaster] err = o.Create(m).Error return } func (m *SaDocSection) Update(cols []string) (err error) { o := global.DbMap[utils.DbNameMaster] err = o.Select(cols).Updates(m).Error return } func (m *SaDocSection) Del() (err error) { o := global.DbMap[utils.DbNameMaster] sql := `DELETE FROM sa_doc_section WHERE sa_doc_section_id = ? LIMIT 1` err = o.Exec(sql, m.SaDocSectionId).Error return } func (m *SaDocSection) GetItemById(id int) (err error) { o := global.DbMap[utils.DbNameMaster] sql := `SELECT * FROM sa_doc_section WHERE sa_doc_section_id = ? LIMIT 1` err = o.Raw(sql, id).First(&m).Error return } func (m *SaDocSection) GetItemByCondition(condition string, pars []interface{}) (err error) { o := global.DbMap[utils.DbNameMaster] sql := `SELECT * FROM sa_doc_section WHERE 1=1 ` sql += condition sql += ` LIMIT 1` err = o.Raw(sql, pars...).First(&m).Error return } func (m *SaDocSection) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { o := global.DbMap[utils.DbNameMaster] sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition) err = o.Raw(sql, pars...).Scan(&count).Error return } func (m *SaDocSection) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaDocSection, err error) { o := global.DbMap[utils.DbNameMaster] fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY sort ASC` 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...).Find(&items).Error return } func (m *SaDocSection) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaDocSection, err error) { o := global.DbMap[utils.DbNameMaster] fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY sort ASC` 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...).Scan(&total).Error; err != nil { return } sql += ` LIMIT ?,?` pars = append(pars, startSize, pageSize) err = o.Raw(sql, pars...).Find(&items).Error return } type SaDocSectionItem struct { SaDocSection UseNum int `description:"整段引用数量"` UsePartNum int `description:"片段引用数量"` }