123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- package models
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- const (
- EnglishReportEmailLogSourceAli = 1 // 来源-阿里云
- EnglishReportEmailLogSourceTencent = 2 // 来源-腾讯云
- EnglishReportEmailLogStatusIng = -1 // 推送状态-已发送
- EnglishReportEmailLogStatusFail = 0 // 推送状态-发送失败
- EnglishReportEmailLogStatusSuccess = 1 // 推送状态-发送成功
- )
- // EnglishReportEmailLog 英文研报-邮件推送记录
- type EnglishReportEmailLog struct {
- Id int `gorm:"column:id;primaryKey;auto_increment:true" description:"邮箱日志ID"`
- ReportId int `gorm:"column:report_id" description:"报告ID或者线上路演ID"`
- ReportType int `gorm:"column:report_type" description:"类型:0英文研报,1英文线上路演"`
- EmailId int `gorm:"column:email_id" description:"邮箱ID"`
- Email string `gorm:"column:email" description:"邮箱地址"`
- SendData string `gorm:"column:send_data" description:"请求信息"`
- Result string `gorm:"column:result" description:"响应信息"`
- SendStatus int `gorm:"column:send_status" description:"发送状态:-1-已发送(一个中间状态,重新推送时可能会产生这种状态);0-发送失败;1-发送成功"`
- CreateTime time.Time `gorm:"column:create_time" description:"请求时间"`
- Source int `gorm:"column:source" description:"服务商:1-阿里云;2-腾讯云"`
- IsDeleted int `gorm:"column:is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
- CallbackData string `gorm:"column:callback_data" description:"回调信息"`
- ErrMsg string `gorm:"column:err_msg" description:"错误信息"`
- }
- func (item *EnglishReportEmailLog) TableName() string {
- return "english_report_email_log"
- }
- func (item *EnglishReportEmailLog) Create() (err error) {
- //o := orm.NewOrmUsingDB("rddp")
- //id, e := o.Insert(item)
- //if e != nil {
- // err = e
- // return
- //}
- //item.Id = int(id)
- err = global.DmSQL["rddp"].Create(item).Error
- return
- }
- func (item *EnglishReportEmailLog) Update(cols []string) (err error) {
- //o := orm.NewOrmUsingDB("rddp")
- //_, err = o.Update(item, cols...)
- err = global.DmSQL["rddp"].Select(cols).Updates(item).Error
- return
- }
- func (item *EnglishReportEmailLog) InsertMulti(items []*EnglishReportEmailLog) (err error) {
- //o := orm.NewOrmUsingDB("rddp")
- //_, err = o.InsertMulti(len(items), items)
- err = global.DmSQL["rddp"].CreateInBatches(items, utils.MultiAddNum).Error
- return
- }
- // GetEnglishReportEmailLogList 获取日志列表
- func GetEnglishReportEmailLogList(condition string, pars []interface{}) (list []*EnglishReportEmailLog, err error) {
- //o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM english_report_email_log WHERE is_deleted = 0 `
- if condition != `` {
- sql += condition
- }
- //_, err = o.Raw(sql, pars).QueryRows(&list)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&list).Error
- return
- }
- // EnglishReportEmailLogPageListResp 英文研报-邮件推送记录分页列表响应体
- type EnglishReportEmailLogPageListResp struct {
- List []*EnglishReportEmailLogPageList `description:"列表数据"`
- Paging *paging.PagingItem `description:"分页数据"`
- }
- // EnglishReportEmailLogPageList 英文研报-邮件推送记录分页列表
- type EnglishReportEmailLogPageList struct {
- SendId int `description:"推送ID"`
- ReportId int `description:"报告ID"`
- EmailId int `description:"邮箱ID"`
- Email string `description:"邮箱地址"`
- ResultMsg string `description:"结果详情"`
- SendStatus int `description:"发送状态:-1-已发送;0-发送失败;1-发送成功"`
- Source int `description:"服务商:1-阿里云;2-腾讯云"`
- CreateTime string `description:"创建时间"`
- }
- // GetEnglishReportEmailLogPageList 获取日志列表-分页
- func GetEnglishReportEmailLogPageList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*EnglishReportEmailLog, err error) {
- //o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM english_report_email_log WHERE is_deleted = 0 `
- sql += condition
- if order != "" {
- sql += order
- } else {
- sql += ` ORDER BY send_status ASC, create_time DESC`
- }
- totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
- //if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
- if err = global.DmSQL["rddp"].Raw(totalSQl, pars...).Scan(&total).Error; err != nil {
- return
- }
- sql += ` LIMIT ?,?`
- //_, err = o.Raw(sql, pars...).QueryRows(&list)
- pars = append(pars, startSize)
- pars = append(pars, pageSize)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&list).Error
- return
- }
- // GetEnglishReportEmailLogById 主键获取日志
- func GetEnglishReportEmailLogById(id int) (item *EnglishReportEmailLog, err error) {
- //o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM english_report_email_log WHERE is_deleted = 0 AND id = ? LIMIT 1`
- //err = o.Raw(sql, id).QueryRow(&item)
- err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error
- return
- }
- // DeleteEnglishReportEmailLogByIds IDs删除日志
- func DeleteEnglishReportEmailLogByIds(logIds []int) (err error) {
- if len(logIds) == 0 {
- return
- }
- //o := orm.NewOrmUsingDB("rddp")
- sql := `DELETE FROM english_report_email_log WHERE id IN (` + utils.GetOrmInReplace(len(logIds)) + `)`
- //sql := `UPDATE english_report_email_log SET is_deleted = 1 WHERE id IN (` + utils.GetOrmInReplace(len(logIds)) + `)`
- //_, err = o.Raw(sql, logIds).Exec()
- err = global.DmSQL["rddp"].Raw(sql, logIds).Exec(sql, logIds).Error
- return
- }
- // EnglishReportEmailLogFail 群发消息日志失败列表
- type EnglishReportEmailLogFail struct {
- HasFail int `description:"是否有失败记录: 0-无; 1-有"`
- ReportId int `description:"报告ID"`
- }
- // GetEnglishReportEmailLogFailList 获取群发消息日志失败列表
- func GetEnglishReportEmailLogFailList(reportType int) (list []*EnglishReportEmailLogFail, err error) {
- //o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT 1 AS has_fail, report_id FROM english_report_email_log WHERE report_type=? and is_deleted = 0 AND send_status = 0 GROUP BY report_id`
- //_, err = o.Raw(sql, reportType).QueryRows(&list)
- err = global.DmSQL["rddp"].Raw(sql, reportType).Find(&list).Error
- return
- }
- // GetEnglishReportEmailLog 获取邮件推送日志
- func GetEnglishReportEmailLog(condition string, pars []interface{}) (item *EnglishReportEmailLog, err error) {
- //o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM english_report_email_log WHERE 1 = 1 `
- sql += condition
- sql += ` ORDER BY id DESC LIMIT 1`
- //err = o.Raw(sql, pars).QueryRow(&item)
- err = global.DmSQL["rddp"].Raw(sql, pars...).First(&item).Error
- return
- }
- func (item *EnglishReportEmailLog) MultiUpdateResult(items []*EnglishReportEmailLog) (err error) {
- //o := orm.NewOrmUsingDB("rddp")
- //p, err := o.Raw("UPDATE english_report_email_log SET send_data = ?, result = ?, send_status = ?, err_msg = ? WHERE id = ?").Prepare()
- //if err != nil {
- // return
- //}
- //defer func() {
- // _ = p.Close()
- //}()
- //for _, v := range items {
- // _, err = p.Exec(v.SendData, v.Result, v.SendStatus, v.ErrMsg, v.Id)
- // if err != nil {
- // return
- // }
- //}
- tx := global.DmSQL["rddp"].Begin()
- for _, v := range items {
- err = tx.Exec("UPDATE english_report_email_log SET send_data = ?, result = ?, send_status = ?, err_msg = ? WHERE id = ?", v.SendData, v.Result, v.SendStatus, v.ErrMsg, v.Id).Error
- if err != nil {
- tx.Rollback()
- return
- }
- }
- tx.Commit()
- return
- }
|