2 Commits 8ca2f0faa1 ... 87d3512c43

Author SHA1 Message Date
  hsun 87d3512c43 Merge branch 'feature/poster_create_1209' 2 weeks ago
  hsun 7679fef341 研报小程序海报优化 2 weeks ago
3 changed files with 90 additions and 0 deletions
  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

@@ -1316,7 +1316,11 @@ func (this *ReportController) PublishCancelReport() {
 	}
 	go func() {
 		_, _ = models.AddReportStateRecord(recordItem)
+
+		// 重置小程序详情页海报
+		_ = services.ResetMiniProgramReportDetailCover(reportInfo.Id)
 	}()
+
 	br.Ret = 200
 	br.Success = true
 }
@@ -1645,6 +1649,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"
 	"github.com/rdlucklib/rdluck_tools/file"
@@ -1496,3 +1498,37 @@ func GetReportWaterMarkPdf(reportInfo *models.Report, sysUser *system.Admin) {
 	waterMarkStr := fmt.Sprintf("%s - %s", sysUser.RealName, sysUser.Mobile)
 	GeneralWaterMarkPdf(filePath, waterMarkStr)
 }
+
+// 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
+}