This commit is contained in:
parent
d60710ca82
commit
d350fb0057
|
|
@ -537,7 +537,7 @@ func (m *Controller) TagDelete(c *gin.Context) {
|
|||
}
|
||||
|
||||
func (m *Controller) NewsAsync(c *gin.Context) {
|
||||
var req proto.NewsListReq
|
||||
var req proto.NewsAsyncReq
|
||||
if err := m.bindJSON(c, &req); err != nil {
|
||||
log.Errorf("%s", err)
|
||||
return
|
||||
|
|
@ -547,7 +547,7 @@ func (m *Controller) NewsAsync(c *gin.Context) {
|
|||
if ctx != nil {
|
||||
ok = m.CheckPrivilege(c, ctx, privilege.NewsAccess)
|
||||
}
|
||||
resp, total, code := m.BizCore.NewsList(ctx, &req, ok)
|
||||
resp, total, code := m.BizCore.NewsAsync(ctx, &req, ok)
|
||||
if !code.Ok() {
|
||||
m.Error(c, code)
|
||||
return
|
||||
|
|
@ -556,7 +556,7 @@ func (m *Controller) NewsAsync(c *gin.Context) {
|
|||
}
|
||||
|
||||
func (m *Controller) NewsPullNew(c *gin.Context) {
|
||||
var req proto.NewsListReq
|
||||
var req proto.NewsPullNewReq
|
||||
if err := m.bindJSON(c, &req); err != nil {
|
||||
log.Errorf("%s", err)
|
||||
return
|
||||
|
|
@ -566,7 +566,7 @@ func (m *Controller) NewsPullNew(c *gin.Context) {
|
|||
if ctx != nil {
|
||||
ok = m.CheckPrivilege(c, ctx, privilege.NewsAccess)
|
||||
}
|
||||
resp, total, code := m.BizCore.NewsList(ctx, &req, ok)
|
||||
resp, total, code := m.BizCore.NewsPullNew(ctx, &req, ok)
|
||||
if !code.Ok() {
|
||||
m.Error(c, code)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -896,3 +896,30 @@ func (m *BizCore) TagDelete(ctx *itypes.Context, req *proto.TagDeleteReq) (resp
|
|||
|
||||
return &proto.TagDeleteResp{}, itypes.BizOK
|
||||
}
|
||||
|
||||
func (m *BizCore) NewsAsync(ctx *itypes.Context, req *proto.NewsAsyncReq, needExtra bool) (resp *proto.NewsAsyncResp, total int64, code itypes.BizCode) {
|
||||
var err error
|
||||
var dos []*models.NewsDO
|
||||
dos, total, err = m.newsDAO.QueryAsync(&dao.NewsAsyncCondition{
|
||||
Org_Id: req.Org_Id,
|
||||
Digest: req.Digest,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, 0, itypes.NewBizCodeDatabaseError(err.Error())
|
||||
}
|
||||
return &proto.NewsAsyncResp{
|
||||
List: dos,
|
||||
}, total, itypes.BizOK
|
||||
}
|
||||
|
||||
func (m *BizCore) NewsPullNew(ctx *itypes.Context, req *proto.NewsPullNewReq) (resp *proto.NewsPullNewResp, total int64, code itypes.BizCode) {
|
||||
dos, total, err := m.newsDAO.QueryPullNew(&dao.NewsPullNewCondition{
|
||||
OrgIDs: req.OrgIDs,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, 0, itypes.NewBizCodeDatabaseError(err.Error())
|
||||
}
|
||||
return &proto.NewsPullNewResp{
|
||||
List: dos,
|
||||
}, total, itypes.BizOK
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,15 @@ import (
|
|||
"github.com/civet148/sqlca/v2"
|
||||
)
|
||||
|
||||
type NewsAsyncCondition struct {
|
||||
Org_Id int64
|
||||
Digest string
|
||||
}
|
||||
|
||||
type NewsPullNewCondition struct {
|
||||
OrgIDs []int64 `json:"org_ids"`
|
||||
}
|
||||
|
||||
const (
|
||||
NewsState_NotPublish = 0 //未发布
|
||||
NewsState_Published = 1 //已发布到订阅列表
|
||||
|
|
@ -206,3 +215,109 @@ func (dao *NewsDAO) QueryList(cond *NewsCondition) (dos []*models.NewsDO, total
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (dao *NewsDAO) QueryAsync(cond *NewsAsyncCondition) (dos []*models.NewsDO, total int64, err error) {
|
||||
e := dao.db.Model(&dos).
|
||||
Table(models.TableNameNews).
|
||||
Select(
|
||||
models.NEWS_COLUMN_ID,
|
||||
models.NEWS_COLUMN_ORG_ID,
|
||||
models.NEWS_COLUMN_SPIDER_ID,
|
||||
models.NEWS_COLUMN_PNAME_ID,
|
||||
models.NEWS_COLUMN_TAG,
|
||||
models.NEWS_COLUMN_CATEGORY,
|
||||
models.NEWS_COLUMN_MAIN_TITLE,
|
||||
models.NEWS_COLUMN_SUB_TITLE,
|
||||
models.NEWS_COLUMN_SUMMARY,
|
||||
models.NEWS_COLUMN_KEYWORDS,
|
||||
models.NEWS_COLUMN_SEO_KEYWORDS,
|
||||
models.NEWS_COLUMN_TAGS,
|
||||
models.NEWS_COLUMN_URL,
|
||||
models.NEWS_COLUMN_IMAGE_URL,
|
||||
models.NEWS_COLUMN_LOGO_URL,
|
||||
models.NEWS_COLUMN_MODEL_PARAMETER,
|
||||
models.NEWS_COLUMN_CONTENT,
|
||||
models.NEWS_COLUMN_IS_HOTSPOT,
|
||||
models.NEWS_COLUMN_IS_OVERWRITTEN,
|
||||
models.NEWS_COLUMN_IS_DELETED,
|
||||
models.NEWS_COLUMN_IS_REPLICATE,
|
||||
models.NEWS_COLUMN_STATE,
|
||||
models.NEWS_COLUMN_CREATED_TIME,
|
||||
models.NEWS_COLUMN_UPDATED_TIME,
|
||||
models.NEWS_COLUMN_EXTRA_DATA,
|
||||
)
|
||||
|
||||
if cond.Org_Id != 0 {
|
||||
e.Eq(models.NEWS_COLUMN_ORG_ID, cond.Org_Id)
|
||||
}
|
||||
_, total, err = e.QueryEx()
|
||||
if err != nil {
|
||||
return nil, 0, log.Errorf(err.Error())
|
||||
}
|
||||
|
||||
// == digest过滤逻辑 ==
|
||||
if cond.Digest != "" {
|
||||
filtered := make([]*models.NewsDO, 0, len(dos))
|
||||
for _, v := range dos {
|
||||
digestVal, _ := v.ExtraData["digest"]
|
||||
if ds, ok := digestVal.(string); ok {
|
||||
if ds != cond.Digest {
|
||||
filtered = append(filtered, v)
|
||||
}
|
||||
// 相等就不加
|
||||
} else {
|
||||
// 取不到digest字段,保留
|
||||
filtered = append(filtered, v)
|
||||
}
|
||||
}
|
||||
dos = filtered
|
||||
total = int64(len(filtered))
|
||||
}
|
||||
|
||||
log.Infof(".................[DEBUG] QueryAsync 返回数据: %+v", dos)
|
||||
return
|
||||
}
|
||||
|
||||
func (dao *NewsDAO) QueryPullNew(cond *NewsPullNewCondition) (dos []*models.NewsDO, total int64, err error) {
|
||||
e := dao.db.Model(&dos).
|
||||
Table(models.TableNameNews).
|
||||
Select(
|
||||
models.NEWS_COLUMN_ID,
|
||||
models.NEWS_COLUMN_ORG_ID,
|
||||
models.NEWS_COLUMN_SPIDER_ID,
|
||||
models.NEWS_COLUMN_PNAME_ID,
|
||||
models.NEWS_COLUMN_TAG,
|
||||
models.NEWS_COLUMN_CATEGORY,
|
||||
models.NEWS_COLUMN_MAIN_TITLE,
|
||||
models.NEWS_COLUMN_SUB_TITLE,
|
||||
models.NEWS_COLUMN_SUMMARY,
|
||||
models.NEWS_COLUMN_KEYWORDS,
|
||||
models.NEWS_COLUMN_SEO_KEYWORDS,
|
||||
models.NEWS_COLUMN_TAGS,
|
||||
models.NEWS_COLUMN_URL,
|
||||
models.NEWS_COLUMN_IMAGE_URL,
|
||||
models.NEWS_COLUMN_LOGO_URL,
|
||||
models.NEWS_COLUMN_MODEL_PARAMETER,
|
||||
models.NEWS_COLUMN_CONTENT,
|
||||
models.NEWS_COLUMN_IS_HOTSPOT,
|
||||
models.NEWS_COLUMN_IS_OVERWRITTEN,
|
||||
models.NEWS_COLUMN_IS_DELETED,
|
||||
models.NEWS_COLUMN_IS_REPLICATE,
|
||||
models.NEWS_COLUMN_STATE,
|
||||
models.NEWS_COLUMN_CREATED_TIME,
|
||||
models.NEWS_COLUMN_UPDATED_TIME,
|
||||
models.NEWS_COLUMN_EXTRA_DATA,
|
||||
)
|
||||
|
||||
// 只按 org_ids 过滤
|
||||
if len(cond.OrgIDs) > 0 {
|
||||
e.NotIn(models.NEWS_COLUMN_ORG_ID, cond.OrgIDs)
|
||||
}
|
||||
_, total, err = e.QueryEx()
|
||||
if err != nil {
|
||||
return nil, 0, log.Errorf(err.Error())
|
||||
}
|
||||
|
||||
log.Infof(".................[DEBUG] QueryPullNew 返回数据: %+v", dos)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -280,7 +280,7 @@ type TagDeleteReq struct {
|
|||
type TagDeleteResp struct {
|
||||
}
|
||||
|
||||
type NewsAsync struct {
|
||||
type NewsAsyncReq struct {
|
||||
Org_Id int64 `json:"org_id"`
|
||||
Digest string `json:"digest"`
|
||||
}
|
||||
|
|
@ -288,3 +288,15 @@ type NewsAsync struct {
|
|||
type NewsAsyncResp struct {
|
||||
List []*models.NewsDO `json:"list"`
|
||||
}
|
||||
|
||||
type NewsPullNewReq struct {
|
||||
OrgIDs []int64 `json:"org_ids"`
|
||||
}
|
||||
|
||||
type NewsPullNewResp struct {
|
||||
List []*models.NewsDO `json:"list"`
|
||||
}
|
||||
|
||||
type NewsAsyncBatchReq struct {
|
||||
List []NewsAsyncReq `json:"list"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue