|
@@ -13,7 +13,7 @@ type WechatArticleAbstract struct {
|
|
|
WechatArticleId int `gorm:"column:wechat_article_id;type:int(9) UNSIGNED;comment:关联的微信报告id;default:0;" description:"关联的微信报告id"`
|
|
|
Content string `gorm:"column:content;type:longtext;comment:摘要内容;" description:"content"` // 摘要内容
|
|
|
Version int `gorm:"column:version;type:int(10) UNSIGNED;comment:版本号;default:1;" description:"版本号"`
|
|
|
- VectorKey string `gorm:"column:vector_key;type:varchar(255);comment:向量key标识;" json:"vector_key"` // 向量key标识
|
|
|
+ VectorKey string `gorm:"column:vector_key;type:varchar(255);comment:向量key标识;" description:"向量key标识"`
|
|
|
ModifyTime time.Time `gorm:"column:modify_time;type:datetime;default:NULL;" description:"modify_time"`
|
|
|
CreateTime time.Time `gorm:"column:create_time;type:datetime;default:NULL;" description:"create_time"`
|
|
|
}
|
|
@@ -52,12 +52,34 @@ func (m *WechatArticleAbstract) Update(updateCols []string) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func (m *WechatArticleAbstract) Del() (err error) {
|
|
|
+ err = global.DbMap[utils.DbNameAI].Delete(&m).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func (m *WechatArticleAbstract) GetById(id int) (item *WechatArticleAbstract, err error) {
|
|
|
err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s = ?", WechatArticleAbstractColumns.WechatArticleAbstractID), id).First(&item).Error
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func (m *WechatArticleAbstract) GetByIdList(idList []int) (items []*WechatArticleAbstract, err error) {
|
|
|
+ err = global.DbMap[utils.DbNameAI].Where(fmt.Sprintf("%s in (?) ", WechatArticleAbstractColumns.WechatArticleAbstractID), idList).Find(&items).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *WechatArticleAbstract) DelByIdList(idList []int) (err error) {
|
|
|
+ if len(idList) <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sqlStr := fmt.Sprintf(`delete from %s where %s in (?)`, m.TableName(), WechatArticleAbstractColumns.WechatArticleAbstractID)
|
|
|
+ err = global.DbMap[utils.DbNameAI].Exec(sqlStr, idList).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// GetByWechatArticleId
|
|
|
// @Description: 根据报告id获取摘要
|
|
|
// @author: Roc
|
|
@@ -72,14 +94,64 @@ func (m *WechatArticleAbstract) GetByWechatArticleId(id int) (item *WechatArticl
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func (m *WechatArticleAbstract) GetListByPlatformCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*WechatArticleAndPlatform, err error) {
|
|
|
+type WechatArticleAbstractView struct {
|
|
|
+ WechatArticleAbstractId int `gorm:"column:wechat_article_abstract_id;type:int(9) UNSIGNED;primaryKey;not null;" description:"wechat_article_abstract_id"`
|
|
|
+ WechatArticleId int `gorm:"column:wechat_article_id;type:int(9) UNSIGNED;comment:关联的微信报告id;default:0;" description:"关联的微信报告id"`
|
|
|
+ Abstract string `gorm:"column:abstract;type:longtext;comment:摘要内容;" description:"摘要内容"` //
|
|
|
+ Version int `gorm:"column:version;type:int(10) UNSIGNED;comment:版本号;default:1;" description:"版本号"`
|
|
|
+ VectorKey string `gorm:"column:vector_key;type:varchar(255);comment:向量key标识;" description:"向量key标识"`
|
|
|
+ ModifyTime string `gorm:"column:modify_time;type:datetime;default:NULL;" description:"modify_time"`
|
|
|
+ CreateTime string `gorm:"column:create_time;type:datetime;default:NULL;" description:"create_time"`
|
|
|
+ Title string `gorm:"column:title;type:varchar(255);comment:标题;" description:"标题"`
|
|
|
+ Link string `gorm:"column:link;type:varchar(255);comment:链接;" description:"链接"`
|
|
|
+ TagId int `gorm:"column:tag_id;type:int(9) UNSIGNED;comment:品种id;default:0;" description:"品种id"`
|
|
|
+}
|
|
|
+
|
|
|
+type WechatArticleAbstractItem struct {
|
|
|
+ WechatArticleAbstractId int `gorm:"column:wechat_article_abstract_id;type:int(9) UNSIGNED;primaryKey;not null;" description:"wechat_article_abstract_id"`
|
|
|
+ WechatArticleId int `gorm:"column:wechat_article_id;type:int(9) UNSIGNED;comment:关联的微信报告id;default:0;" description:"关联的微信报告id"`
|
|
|
+ Abstract string `gorm:"column:abstract;type:longtext;comment:摘要内容;" description:"摘要内容"` //
|
|
|
+ Version int `gorm:"column:version;type:int(10) UNSIGNED;comment:版本号;default:1;" description:"版本号"`
|
|
|
+ VectorKey string `gorm:"column:vector_key;type:varchar(255);comment:向量key标识;" description:"向量key标识"`
|
|
|
+ ModifyTime time.Time `gorm:"column:modify_time;type:datetime;default:NULL;" description:"modify_time"`
|
|
|
+ CreateTime time.Time `gorm:"column:create_time;type:datetime;default:NULL;" description:"create_time"`
|
|
|
+ Title string `gorm:"column:title;type:varchar(255);comment:标题;" description:"标题"`
|
|
|
+ Link string `gorm:"column:link;type:varchar(255);comment:链接;" description:"链接"`
|
|
|
+ TagId int `gorm:"column:tag_id;type:int(9) UNSIGNED;comment:品种id;default:0;" description:"品种id"`
|
|
|
+}
|
|
|
+
|
|
|
+func (m *WechatArticleAbstractItem) ToView() WechatArticleAbstractView {
|
|
|
+ return WechatArticleAbstractView{
|
|
|
+ WechatArticleAbstractId: m.WechatArticleAbstractId,
|
|
|
+ WechatArticleId: m.WechatArticleId,
|
|
|
+ Abstract: m.Abstract,
|
|
|
+ Version: m.Version,
|
|
|
+ VectorKey: m.VectorKey,
|
|
|
+ ModifyTime: utils.DateStrToDateTimeStr(m.ModifyTime),
|
|
|
+ CreateTime: utils.DateStrToDateTimeStr(m.CreateTime),
|
|
|
+ Title: m.Title,
|
|
|
+ Link: m.Link,
|
|
|
+ TagId: m.TagId,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (m *WechatArticleAbstract) WechatArticleAbstractItem(list []*WechatArticleAbstractItem) (wechatArticleViewList []WechatArticleAbstractView) {
|
|
|
+ wechatArticleViewList = make([]WechatArticleAbstractView, 0)
|
|
|
+
|
|
|
+ for _, v := range list {
|
|
|
+ wechatArticleViewList = append(wechatArticleViewList, v.ToView())
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *WechatArticleAbstract) GetListByPlatformCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*WechatArticleAbstractItem, err error) {
|
|
|
if field == "" {
|
|
|
field = "*"
|
|
|
}
|
|
|
sqlStr := fmt.Sprintf(`SELECT %s FROM %s AS a
|
|
|
- JOIN wechat_platform AS b ON a.wechat_platform_id=b.wechat_platform_id
|
|
|
- JOIN wechat_platform AS b ON a.wechat_platform_id=b.wechat_platform_id
|
|
|
- WHERE 1=1 AND a.is_deleted=0 %s order by a.article_create_time DESC,a.wechat_article_id DESC LIMIT ?,?`, field, m.TableName(), condition)
|
|
|
+ JOIN wechat_article AS b ON a.wechat_article_id=b.wechat_article_id
|
|
|
+ JOIN wechat_platform AS c ON b.wechat_platform_id=c.wechat_platform_id
|
|
|
+ WHERE 1=1 AND b.is_deleted=0 %s order by a.modify_time DESC,a.wechat_article_abstract_id DESC LIMIT ?,?`, field, m.TableName(), condition)
|
|
|
pars = append(pars, startSize, pageSize)
|
|
|
err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Find(&items).Error
|
|
|
|
|
@@ -89,8 +161,9 @@ func (m *WechatArticleAbstract) GetListByPlatformCondition(field, condition stri
|
|
|
func (m *WechatArticleAbstract) GetCountByPlatformCondition(condition string, pars []interface{}) (total int, err error) {
|
|
|
var intNull sql.NullInt64
|
|
|
sqlStr := fmt.Sprintf(`SELECT COUNT(1) total FROM %s AS a
|
|
|
- JOIN wechat_platform AS b ON a.wechat_platform_id=b.wechat_platform_id
|
|
|
- WHERE 1=1 AND a.is_deleted=0 %s`, m.TableName(), condition)
|
|
|
+ JOIN wechat_article AS b ON a.wechat_article_id=b.wechat_article_id
|
|
|
+ JOIN wechat_platform AS c ON b.wechat_platform_id=c.wechat_platform_id
|
|
|
+ WHERE 1=1 AND b.is_deleted=0 %s`, m.TableName(), condition)
|
|
|
err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Scan(&intNull).Error
|
|
|
if err == nil && intNull.Valid {
|
|
|
total = int(intNull.Int64)
|
|
@@ -99,14 +172,57 @@ func (m *WechatArticleAbstract) GetCountByPlatformCondition(condition string, pa
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func (m *WechatArticleAbstract) GetPageListByPlatformCondition(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*WechatArticleAndPlatform, err error) {
|
|
|
+func (m *WechatArticleAbstract) GetPageListByPlatformCondition(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*WechatArticleAbstractItem, err error) {
|
|
|
|
|
|
total, err = m.GetCountByPlatformCondition(condition, pars)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
if total > 0 {
|
|
|
- items, err = m.GetListByPlatformCondition(`a.wechat_article_id,a.wechat_platform_id,a.fake_id,a.title,a.link,a.cover_url,a.description,a.country,a.province,a.city,a.article_create_time,a.modify_time,a.create_time,b.nickname,b.round_head_img`, condition, pars, startSize, pageSize)
|
|
|
+ items, err = m.GetListByPlatformCondition(`a.wechat_article_abstract_id,a.wechat_article_id,a.content AS abstract,a.version,a.vector_key,b.title,b.link,a.modify_time,a.create_time`, condition, pars, startSize, pageSize)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *WechatArticleAbstract) GetListByTagAndPlatformCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*WechatArticleAbstractItem, err error) {
|
|
|
+ if field == "" {
|
|
|
+ field = "*"
|
|
|
+ }
|
|
|
+ sqlStr := fmt.Sprintf(`SELECT %s FROM %s AS a
|
|
|
+ JOIN wechat_article AS b ON a.wechat_article_id=b.wechat_article_id
|
|
|
+ JOIN wechat_platform AS c ON b.wechat_platform_id=c.wechat_platform_id
|
|
|
+ JOIN wechat_platform_tag_mapping AS d ON c.wechat_platform_id=d.wechat_platform_id
|
|
|
+ WHERE 1=1 AND b.is_deleted=0 %s order by a.modify_time DESC,a.wechat_article_abstract_id DESC LIMIT ?,?`, field, m.TableName(), condition)
|
|
|
+ pars = append(pars, startSize, pageSize)
|
|
|
+ err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Find(&items).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *WechatArticleAbstract) GetCountByTagAndPlatformCondition(condition string, pars []interface{}) (total int, err error) {
|
|
|
+ var intNull sql.NullInt64
|
|
|
+ sqlStr := fmt.Sprintf(`SELECT COUNT(1) total FROM %s AS a
|
|
|
+ JOIN wechat_article AS b ON a.wechat_article_id=b.wechat_article_id
|
|
|
+ JOIN wechat_platform AS c ON b.wechat_platform_id=c.wechat_platform_id
|
|
|
+ JOIN wechat_platform_tag_mapping AS d ON c.wechat_platform_id=d.wechat_platform_id
|
|
|
+ WHERE 1=1 AND b.is_deleted=0 %s`, m.TableName(), condition)
|
|
|
+ err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Scan(&intNull).Error
|
|
|
+ if err == nil && intNull.Valid {
|
|
|
+ total = int(intNull.Int64)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *WechatArticleAbstract) GetPageListByTagAndPlatformCondition(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*WechatArticleAbstractItem, err error) {
|
|
|
+
|
|
|
+ total, err = m.GetCountByTagAndPlatformCondition(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if total > 0 {
|
|
|
+ items, err = m.GetListByTagAndPlatformCondition(`a.wechat_article_abstract_id,a.wechat_article_id,a.content AS abstract,a.version,a.vector_key,a.modify_time,a.create_time,b.title,b.link,d.tag_id`, condition, pars, startSize, pageSize)
|
|
|
}
|
|
|
|
|
|
return
|