Pārlūkot izejas kodu

Merge branch 'feature/poster_create_1209' into debug

hsun 2 nedēļas atpakaļ
vecāks
revīzija
cbc1b4a22d
3 mainītis faili ar 90 papildinājumiem un 0 dzēšanām
  1. 9 0
      controllers/report_v2.go
  2. 45 0
      models/yb/yb_poster_resource.go
  3. 36 0
      services/report_v2.go

+ 9 - 0
controllers/report_v2.go

@@ -1339,7 +1339,11 @@ func (this *ReportController) PublishCancelReport() {
 	}
 	go func() {
 		_, _ = models.AddReportStateRecord(recordItem)
+
+		// 重置小程序详情页海报
+		_ = services.ResetMiniProgramReportDetailCover(reportInfo.Id)
 	}()
+
 	br.Ret = 200
 	br.Success = true
 }
@@ -1668,6 +1672,11 @@ func (this *ReportController) CancelApprove() {
 	//	return
 	//}
 
+	// 重置小程序详情页海报
+	go func() {
+		_ = services.ResetMiniProgramReportDetailCover(reportItem.Id)
+	}()
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"

+ 45 - 0
models/yb/yb_poster_resource.go

@@ -0,0 +1,45 @@
+package yb
+
+import (
+	"eta/eta_api/utils"
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"strings"
+	"time"
+)
+
+// YbPosterResource 研报小程序海报
+type YbPosterResource struct {
+	Id         int       `orm:"column(id);pk" description:"价格驱动ID"`
+	Path       string    `description:"请求路径"`
+	ImgUrl     string    `description:"图片地址"`
+	Type       string    `description:"类型 poster-海报; qrcode-太阳码"`
+	Version    string    `description:"版本号"`
+	CreateTime time.Time `description:"创建时间"`
+}
+
+func (m *YbPosterResource) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*YbPosterResource, err error) {
+	o := orm.NewOrmUsingDB("weekly")
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM yb_poster_resource WHERE 1=1 %s %s`, fields, condition, order)
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+func (m *YbPosterResource) RemovePosters(ids []int) (err error) {
+	num := len(ids)
+	if num == 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("weekly")
+	sql := fmt.Sprintf(`DELETE FROM yb_poster_resource WHERE id IN (%s) LIMIT %d`, utils.GetOrmInReplace(num), num)
+	_, err = o.Raw(sql, ids).Exec()
+	return
+}

+ 36 - 0
services/report_v2.go

@@ -8,6 +8,8 @@ import (
 	"eta/eta_api/models/report"
 	"eta/eta_api/models/report_approve"
 	"eta/eta_api/models/system"
+	"eta/eta_api/models/yb"
+	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/utils"
 	"fmt"
 	"html"
@@ -1655,3 +1657,37 @@ func FilterShareUrl() web.FilterFunc {
 		utils.ApiLog.Info(fmt.Sprintf("原始请求为:%s, 已修改请求路径为:%s?%s", path, newPath, q.Encode()))
 	}
 }
+
+// ResetMiniProgramReportDetailCover 重置小程序报告封面
+func ResetMiniProgramReportDetailCover(reportId int) (err error) {
+	if utils.MYSQL_WEEKLY_URL == `` {
+		return
+	}
+	defer func() {
+		if err != nil {
+			tips := fmt.Sprintf("ResetMiniProgramReportDetailCover-重置小程序报告封面失败, %v", err)
+			utils.FileLog.Info(tips)
+			alarm_msg.SendAlarmMsg(tips, 2)
+		}
+	}()
+
+	ob := new(yb.YbPosterResource)
+	cond := fmt.Sprintf(` AND path LIKE 'reportDetailCover?ReportId=%d&%%'`, reportId)
+	pars := make([]interface{}, 0)
+	list, e := ob.GetItemsByCondition(cond, pars, []string{"id"}, "")
+	if e != nil {
+		err = fmt.Errorf("获取报告海报失败, %v", e)
+		return
+	}
+	if len(list) == 0 {
+		return
+	}
+	var removeIds []int
+	for _, v := range list {
+		removeIds = append(removeIds, v.Id)
+	}
+	if e = ob.RemovePosters(removeIds); e != nil {
+		err = fmt.Errorf("清除报告海报失败, %v", e)
+	}
+	return
+}