package semantic_analysis import ( "eta_gn/eta_api/global" "fmt" "strings" ) //type SaDocSection struct { // SaDocSectionId int `orm:"column(sa_doc_section_id);pk" description:"段落ID"` // DocId int `description:"文档ID"` // Content string `description:"段落内容"` // Sort int `description:"排序"` //} type SaDocSection struct { SaDocSectionId int `gorm:"primaryKey;column:sa_doc_section_id;type:int(10) unsigned;not null"` // 语义分析-文档段落表 DocId int `gorm:"index:idx_doc_id;column:doc_id;type:int(10) unsigned;not null;default:0"` // 文档Id Content string `gorm:"column:content;type:text"` // 段落内容 Sort int `gorm:"column:sort;type:int(10) unsigned;not null;default:0"` // 排序 } 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 := orm.NewOrm() //id, err := o.Insert(m) //if err != nil { // return //} //m.SaDocSectionId = int(id) err = global.DEFAULT_DmSQL.Create(m).Error return } func (m *SaDocSection) Update(cols []string) (err error) { // o := orm.NewOrm() //_, err = o.Update(m, cols...) err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error return } func (m *SaDocSection) Del() (err error) { // o := orm.NewOrm() sql := `DELETE FROM sa_doc_section WHERE sa_doc_section_id = ? LIMIT 1` //_, err = o.Raw(sql, m.SaDocSectionId).Exec() err = global.DEFAULT_DmSQL.Exec(sql, m.SaDocSectionId).Error return } func (m *SaDocSection) GetItemById(id int) (err error) { // o := orm.NewOrm() sql := `SELECT * FROM sa_doc_section WHERE sa_doc_section_id = ? LIMIT 1` //err = o.Raw(sql, id).QueryRow(&m) err = global.DEFAULT_DmSQL.Raw(sql, id).First(&m).Error return } func (m *SaDocSection) GetItemByCondition(condition string, pars []interface{}) (err error) { // o := orm.NewOrm() sql := `SELECT * FROM sa_doc_section WHERE 1=1 ` sql += condition sql += ` LIMIT 1` //err = o.Raw(sql, pars).QueryRow(&m) err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&m).Error return } func (m *SaDocSection) 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) err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error return } func (m *SaDocSection) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaDocSection, err error) { // o := orm.NewOrm() 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).QueryRows(&items) err = global.DEFAULT_DmSQL.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 := orm.NewOrm() 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).QueryRow(&total); err != nil { // return //} err = global.DEFAULT_DmSQL.Raw(totalSql, pars...).Scan(&total).Error if err != nil { return } sql += ` LIMIT ?,?` //_, err = o.Raw(sql, pars...).QueryRows(&items) err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error return } type SaDocSectionItem struct { SaDocSection UseNum int `description:"整段引用数量"` UsePartNum int `description:"片段引用数量"` }