Browse Source

英文研报记录邮箱PV

hsun 2 years ago
parent
commit
d7e2634636

+ 43 - 1
controllers/english_report.go

@@ -1,8 +1,12 @@
 package controllers
 
 import (
+	"errors"
 	"hongze/hongze_api/models"
+	"hongze/hongze_api/services/alarm_msg"
+	"hongze/hongze_api/utils"
 	"html"
+	"time"
 )
 
 //报告分享
@@ -12,7 +16,8 @@ type EnglishReportShareController struct {
 
 // @Title 日评详情
 // @Description 日评详情接口
-// @Param   ReportCode   query   string  true       "报告唯一编码"
+// @Param   ReportCode   query   string  true	"报告唯一编码"
+// @Param   ShareEmail   query   string  false	"分享的邮箱"
 // @Success 200 {object} models.ReportShareDetailResp
 // @router /share/detail [get]
 func (this *EnglishReportShareController) EnglishReportDetail() {
@@ -43,6 +48,43 @@ func (this *EnglishReportShareController) EnglishReportDetail() {
 	report.ContentSub = html.UnescapeString(report.ContentSub)
 	report.Content = html.UnescapeString(report.Content)
 
+	// 记录邮箱
+	shareEmail := this.GetString("ShareEmail")
+	if shareEmail != "" {
+		go func() {
+			var errMsg error
+			defer func() {
+				if errMsg != nil {
+					alarm_msg.SendAlarmMsg(utils.APPNAME+"更新英文报告邮箱PV失败, Err: "+errMsg.Error(), 2)
+				}
+			}()
+
+			userEmail, e := models.GetEnglishReportEmailByEmail(shareEmail)
+			if e != nil && e.Error() != utils.ErrNoRow() {
+				errMsg = errors.New("获取客户邮箱信息失败, Err:" + e.Error())
+				return
+			}
+			if userEmail == nil {
+				return
+			}
+			// 更新报告邮箱pv(冗余)
+			if e = models.UpdateEnglishReportEmailCounts(reportCode); e != nil {
+				errMsg = errors.New("更新报告邮箱PV失败, Err:" + e.Error())
+				return
+			}
+			// 记录邮箱PV
+			pv := &models.EnglishReportEmailPV{
+				ReportId:   report.Id,
+				EmailId:    userEmail.Id,
+				CreateTime: time.Now().Local(),
+			}
+			if e = pv.Create(); e != nil {
+				errMsg = errors.New("新增邮箱PV失败, Err: " + e.Error())
+				return
+			}
+		}()
+	}
+
 	resp := new(models.EnglishReportShareDetailResp)
 	resp.Report = report
 	br.Ret = 200

+ 1 - 0
models/db.go

@@ -49,5 +49,6 @@ func init() {
 		new(WxUserCode),
 		new(UserRecord),
 		new(YbApplyRecord),
+		new(EnglishReportEmailPV),
 	)
 }

+ 8 - 3
models/english_report.go

@@ -29,7 +29,6 @@ type EnglishReportDetail struct {
 	ChapterType        string `description:"章节类型 day-晨报 week-周报"`
 }
 
-
 func GetEnglishReportByCode(reportCode string) (item *EnglishReportDetail, err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	sql := `SELECT * FROM english_report WHERE report_code=?`
@@ -37,7 +36,6 @@ func GetEnglishReportByCode(reportCode string) (item *EnglishReportDetail, err e
 	return
 }
 
-
 type EnglishReportShareDetailResp struct {
 	Report *EnglishReportDetail `description:"报告"`
 }
@@ -47,4 +45,11 @@ func UpdateEnglishReportCounts(reportCode string) (err error) {
 	sql := `UPDATE english_report SET pv = pv+1 WHERE report_code = ?  `
 	_, err = o.Raw(sql, reportCode).Exec()
 	return
-}
+}
+
+func UpdateEnglishReportEmailCounts(reportCode string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `UPDATE english_report SET pv_email = pv_email+1 WHERE report_code = ?  `
+	_, err = o.Raw(sql, reportCode).Exec()
+	return
+}

+ 108 - 0
models/english_report_email.go

@@ -0,0 +1,108 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"time"
+)
+
+// EnglishReportEmail 英文研报-邮箱
+type EnglishReportEmail struct {
+	Id         int       `orm:"column(id);pk" description:"邮箱ID"`
+	Name       string    `description:"客户名称"`
+	Email      string    `description:"邮箱地址"`
+	AdminId    int       `description:"创建人ID"`
+	AdminName  string    `description:"创建人姓名"`
+	CreateTime time.Time `description:"创建时间"`
+	ModifyTime time.Time `description:"更新时间"`
+}
+
+func (item *EnglishReportEmail) TableName() string {
+	return "english_report_email"
+}
+
+// EnglishReportEmailSaveReq 保存邮箱请求体
+type EnglishReportEmailSaveReq struct {
+	Id    int    `description:"邮箱ID, 大于0为编辑"`
+	Name  string `description:"客户名称"`
+	Email string `description:"邮箱地址"`
+}
+
+func (item *EnglishReportEmail) Create() (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	id, err := o.Insert(item)
+	if err != nil {
+		return
+	}
+	item.Id = int(id)
+	return
+}
+
+func (item *EnglishReportEmail) Update(cols []string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Update(item, cols...)
+	return
+}
+
+// GetEnglishReportEmailById 主键获取邮箱
+func GetEnglishReportEmailById(id int) (item *EnglishReportEmail, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM english_report_email WHERE id = ? LIMIT 1`
+	err = o.Raw(sql, id).QueryRow(&item)
+	return
+}
+
+// EnglishReportEmailPageListResp 分页列表响应体
+type EnglishReportEmailPageListResp struct {
+	List   []*EnglishReportEmailResp
+	Paging *paging.PagingItem `description:"分页数据"`
+}
+
+// EnglishReportEmailResp 邮箱响应体
+type EnglishReportEmailResp struct {
+	Id         int    `description:"邮箱ID"`
+	Name       string `description:"客户名称"`
+	Email      string `description:"邮箱地址"`
+	AdminName  string `description:"创建人姓名"`
+	CreateTime string `description:"创建时间"`
+}
+
+// GetEnglishReportEmailPageList 获取邮箱列表-分页
+func GetEnglishReportEmailPageList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*EnglishReportEmail, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM english_report_email WHERE 1 = 1 `
+	sql += condition
+	if order != "" {
+		sql += order
+	} else {
+		sql += ` ORDER BY create_time DESC`
+	}
+	totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
+	if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
+		return
+	}
+	sql += ` LIMIT ?,?`
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
+	return
+}
+
+// GetEnglishReportEmailByEmail 地址获取邮箱
+func GetEnglishReportEmailByEmail(email string) (item *EnglishReportEmail, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM english_report_email WHERE email = ? LIMIT 1`
+	err = o.Raw(sql, email).QueryRow(&item)
+	return
+}
+
+// EnglishReportEmailDelReq 删除邮箱请求体
+type EnglishReportEmailDelReq struct {
+	EmailId int `description:"邮箱ID"`
+}
+
+// DelEnglishReportEmail 删除邮箱
+func DelEnglishReportEmail(id int) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `DELETE FROM english_report_email WHERE id = ? LIMIT 1`
+	_, err = o.Raw(sql, id).Exec()
+	return
+}

+ 28 - 0
models/english_report_email_pv.go

@@ -0,0 +1,28 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// EnglishReportEmailPV 英文研报-邮箱pv
+type EnglishReportEmailPV struct {
+	Id         int       `orm:"column(id);pk"`
+	ReportId   int       `description:"英文报告ID"`
+	EmailId    int       `description:"邮箱ID"`
+	CreateTime time.Time `description:"创建时间"`
+}
+
+func (item *EnglishReportEmailPV) TableName() string {
+	return "english_report_email_pv"
+}
+
+func (item *EnglishReportEmailPV) Create() (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	id, err := o.Insert(item)
+	if err != nil {
+		return
+	}
+	item.Id = int(id)
+	return
+}