|
@@ -194,3 +194,108 @@ func (m *WechatArticle) GetPageListByCondition(condition string, pars []interfac
|
|
|
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+type WechatArticleAndPlatform struct {
|
|
|
+ WechatArticleId int `gorm:"column:wechat_article_id;type:int(10) UNSIGNED;primaryKey;not null;" description:""`
|
|
|
+ WechatPlatformId int `gorm:"column:wechat_platform_id;type:int(11);comment:归属公众号id;default:0;" description:"归属公众号id"`
|
|
|
+ FakeId string `gorm:"column:fake_id;type:varchar(255);comment:公众号唯一id;" description:"公众号唯一id"`
|
|
|
+ Title string `gorm:"column:title;type:varchar(255);comment:标题;" description:"标题"`
|
|
|
+ Link string `gorm:"column:link;type:varchar(255);comment:链接;" description:"链接"`
|
|
|
+ CoverUrl string `gorm:"column:cover_url;type:varchar(255);comment:公众号封面;" description:"公众号封面"`
|
|
|
+ Description string `gorm:"column:description;type:varchar(255);comment:描述;" description:"描述"`
|
|
|
+ Content string `gorm:"column:content;type:longtext;comment:报告详情;" description:"报告详情"`
|
|
|
+ TextContent string `gorm:"column:text_content;type:text;comment:文本内容;" description:"文本内容"`
|
|
|
+ Abstract string `gorm:"column:abstract;type:text;comment:摘要;" description:"摘要"`
|
|
|
+ Country string `gorm:"column:country;type:varchar(255);comment:国家;" description:"国家"`
|
|
|
+ Province string `gorm:"column:province;type:varchar(255);comment:省;" description:"省"`
|
|
|
+ City string `gorm:"column:city;type:varchar(255);comment:市;" description:"市"`
|
|
|
+ ArticleCreateTime time.Time `gorm:"column:article_create_time;type:datetime;comment:报告创建时间;default:NULL;" description:"报告创建时间"`
|
|
|
+ IsDeleted int `gorm:"column:is_deleted;type:tinyint(4);comment:是否删除,0:未删除,1: 已删除;default:0;" description:"是否删除,0:未删除,1: 已删除"`
|
|
|
+ ModifyTime time.Time `gorm:"column:modify_time;type:datetime;comment:修改时间;default:NULL;" description:"修改时间"`
|
|
|
+ CreateTime time.Time `gorm:"column:create_time;type:datetime;comment:入库时间;default:NULL;" description:"入库时间"`
|
|
|
+ Nickname string `gorm:"column:nickname;type:varchar(255);comment:公众号名称;" description:"nickname"` // 公众号名称
|
|
|
+ Alias string `gorm:"column:alias;type:varchar(255);comment:别名;" description:"alias"` // 别名
|
|
|
+ RoundHeadImg string `gorm:"column:round_head_img;type:varchar(255);comment:头像;" description:"round_head_img"` // 头像
|
|
|
+}
|
|
|
+
|
|
|
+func (m *WechatArticleAndPlatform) ToView() WechatArticleView {
|
|
|
+ var articleCreateTime, modifyTime, createTime string
|
|
|
+
|
|
|
+ if !m.ArticleCreateTime.IsZero() {
|
|
|
+ articleCreateTime = m.ArticleCreateTime.Format(utils.FormatDateTime)
|
|
|
+ }
|
|
|
+ if !m.CreateTime.IsZero() {
|
|
|
+ createTime = m.CreateTime.Format(utils.FormatDateTime)
|
|
|
+ }
|
|
|
+ if !m.ModifyTime.IsZero() {
|
|
|
+ modifyTime = m.ModifyTime.Format(utils.FormatDateTime)
|
|
|
+ }
|
|
|
+ return WechatArticleView{
|
|
|
+ WechatArticleId: m.WechatArticleId,
|
|
|
+ WechatPlatformId: m.WechatPlatformId,
|
|
|
+ FakeId: m.FakeId,
|
|
|
+ Title: m.Title,
|
|
|
+ Link: m.Link,
|
|
|
+ CoverUrl: m.CoverUrl,
|
|
|
+ Description: m.Description,
|
|
|
+ Content: m.Content,
|
|
|
+ TextContent: m.TextContent,
|
|
|
+ Abstract: m.Abstract,
|
|
|
+ Country: m.Country,
|
|
|
+ Province: m.Province,
|
|
|
+ City: m.City,
|
|
|
+ ArticleCreateTime: articleCreateTime,
|
|
|
+ ModifyTime: modifyTime,
|
|
|
+ CreateTime: createTime,
|
|
|
+ WechatPlatformName: m.Nickname,
|
|
|
+ WechatPlatformRoundHeadImg: m.RoundHeadImg,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (m *WechatArticle) ArticleAndPlatformListToViewList(list []*WechatArticleAndPlatform) (wechatArticleViewList []WechatArticleView) {
|
|
|
+ wechatArticleViewList = make([]WechatArticleView, 0)
|
|
|
+
|
|
|
+ for _, v := range list {
|
|
|
+ wechatArticleViewList = append(wechatArticleViewList, v.ToView())
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *WechatArticle) GetListByPlatformCondition(field, condition string, pars []interface{}, startSize, pageSize int) (items []*WechatArticleAndPlatform, 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
|
|
|
+ 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)
|
|
|
+ pars = append(pars, startSize, pageSize)
|
|
|
+ err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Find(&items).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *WechatArticle) 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)
|
|
|
+ err = global.DbMap[utils.DbNameAI].Raw(sqlStr, pars...).Scan(&intNull).Error
|
|
|
+ if err == nil && intNull.Valid {
|
|
|
+ total = int(intNull.Int64)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *WechatArticle) GetPageListByPlatformCondition(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*WechatArticleAndPlatform, 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)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|