123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- package models
- import (
- "eta_gn/eta_api/global"
- "fmt"
- "strings"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- // ReportMessageConfig 研报ICE订阅号消息推送配置表
- type ReportMessageConfig struct {
- ConfigId int64 `gorm:"column:config_id;primaryKey;autoIncrement" description:"主键ID"`
- ClassifyId int `gorm:"column:classify_id;default:0" description:"分类ID"`
- NotifyUsers string `gorm:"column:notify_users" description:"通知用户列表"`
- CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
- ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
- }
- // TableName 设置表名
- func (m *ReportMessageConfig) TableName() string {
- return "report_message_config"
- }
- // Create 创建配置
- func (m *ReportMessageConfig) Create() (err error) {
- err = global.DmSQL["rddp"].Create(m).Error
- return
- }
- // Update 更新配置
- func (m *ReportMessageConfig) Update(cols []string) (err error) {
- err = global.DmSQL["rddp"].Select(cols).Updates(m).Error
- return
- }
- // GetItemById 根据ID获取配置
- func (m *ReportMessageConfig) GetItemById(id int64) (item *ReportMessageConfig, err error) {
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE config_id = ? LIMIT 1`, m.TableName())
- err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error
- return
- }
- // GetItemByClassifyId 根据分类ID获取配置
- func (m *ReportMessageConfig) GetItemByClassifyId(classifyId int) (item *ReportMessageConfig, err error) {
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE classify_id = ? LIMIT 1`, m.TableName())
- err = global.DmSQL["rddp"].Raw(sql, classifyId).First(&item).Error
- return
- }
- // GetItemsByCondition 根据条件获取配置列表
- func (m *ReportMessageConfig) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*ReportMessageConfig, err error) {
- 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 %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
- return
- }
- // GetPageItemsByCondition 分页获取配置列表
- func (m *ReportMessageConfig) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*ReportMessageConfig, err error) {
- 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 %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
- pars = append(pars, startSize)
- pars = append(pars, pageSize)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
- return
- }
- // GetCountByCondition 获取符合条件的配置数量
- func (m *ReportMessageConfig) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
- return
- }
- // ReportMessageConfigListReq 配置列表请求参数
- type ReportMessageConfigListReq struct {
- PageSize int `form:"PageSize"`
- CurrentIndex int `form:"CurrentIndex"`
- ClassifyId int `form:"ClassifyId" description:"分类ID"`
- }
- // ReportMessageConfigListResp 配置列表响应体
- type ReportMessageConfigListResp struct {
- List []*ReportMessageConfig
- Paging *paging.PagingItem `description:"分页数据"`
- }
- // ReportMessageConfigAddReq 新增配置请求体
- type ReportMessageConfigAddReq struct {
- ClassifyId int `json:"classify_id" description:"分类ID"`
- NotifyUsers string `json:"notify_users" description:"通知用户列表"`
- }
- // ReportMessageConfigEditReq 编辑配置请求体
- type ReportMessageConfigEditReq struct {
- ConfigId int64 `json:"config_id" description:"配置ID"`
- ClassifyId int `json:"classify_id" description:"分类ID"`
- NotifyUsers string `json:"notify_users" description:"通知用户列表"`
- }
- // ReportMessageRecord 研报ICE订阅号消息推送记录表
- type ReportMessageRecord struct {
- MessageId int64 `gorm:"column:message_id;primaryKey;autoIncrement" description:"主键ID"`
- ReportId int64 `gorm:"column:report_id" description:"关联的研报ID"`
- ReportTitle string `gorm:"column:report_title" description:"研报标题"`
- PptId int64 `gorm:"column:ppt_id" description:"关联的PPT ID"`
- ClassifyId int `gorm:"column:classify_id;default:0" description:"分类ID"`
- ClassifyType int8 `gorm:"column:classify_type" description:"分类类型1-研报,2-PPT"`
- SendAdminId int64 `gorm:"column:send_admin_id" description:"发送者ID"`
- SendTime time.Time `gorm:"column:send_time" description:"发送时间"`
- ReceiveAdminId int64 `gorm:"column:receive_admin_id" description:"接收者ID"`
- ReceiveAdminCode string `gorm:"column:receive_admin_code" description:"接收者编码"`
- Status int8 `gorm:"column:status" description:"状态;1发送成功,2发送失败"`
- TaskId string `gorm:"column:task_id" description:"任务ID"`
- CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
- ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
- Content string `gorm:"column:content" description:"消息内容"`
- Url string `gorm:"column:url" description:"消息URL"`
- }
- type ReportIceMsgRecordListItem struct {
- MessageId int64 `description:"主键ID"`
- ReportId int64 `description:"关联的研报ID"`
- ReportTitle string `description:"研报标题"`
- PptId int64 `description:"关联的PPT ID"`
- ClassifyId int `description:"分类ID"`
- ClassifyFullName string `description:"分类名称"`
- ClassifyType int8 `description:"分类类型:1-研报,2-PPT"`
- SendAdminId int64 `description:"发送者ID"`
- SendAdminName string `description:"发送者名称"`
- SendTime string `description:"发送时间"`
- ReceiveAdminId int64 `description:"接收者ID"`
- ReceiveAdminName string `description:"接收者名称"`
- Status int8 `description:"状态:1发送成功,2发送失败"`
- CreateTime string `description:"创建时间"`
- }
- // TableName 设置表名
- func (ReportMessageRecord) TableName() string {
- return "report_message_record"
- }
- type ReportIceMsgConfigReq struct {
- ClassifyId int `description:"分类ID"`
- NotifyUsers []int `description:"通知用户列表"`
- }
- // 查询配置是否已存在
- func (m *ReportMessageConfig) IsExist(classifyId int) (bool, error) {
- var count int64
- err := global.DmSQL["rddp"].Model(&ReportMessageConfig{}).Where("classify_id = ?", classifyId).Count(&count).Error
- return count > 0, err
- }
- // 查询消息推送记录列表
- func (m *ReportMessageRecord) GetList(condition string, pars []interface{}, startSize, pageSize int) (list []*ReportMessageRecord, err error) {
- // 使用子查询获取每组最新的一条记录
- fields := "*"
- subQuery := fmt.Sprintf(`
- SELECT MAX(message_id) as max_id
- FROM %s
- WHERE 1=1 %s
- GROUP BY COALESCE(report_id, ''), COALESCE(ppt_id, ''), receive_admin_id
- `, m.TableName(), condition)
-
- // 主查询使用 IN 子查询获取完整记录
- sql := fmt.Sprintf(`
- SELECT %s
- FROM %s
- WHERE message_id IN (%s)
- ORDER BY create_time DESC, message_id DESC
- LIMIT ?,?
- `, fields, m.TableName(), subQuery)
- pars = append(pars, startSize)
- pars = append(pars, pageSize)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&list).Error
- return
- }
- // 查询消息推送记录列表数量
- func (m *ReportMessageRecord) GetListCount(condition string, pars []interface{}) (count int, err error) {
- sql := fmt.Sprintf(`SELECT COUNT(*)
- FROM (
- SELECT 1
- FROM %s
- WHERE 1=1 %s
- GROUP BY COALESCE(report_id, ''), COALESCE(ppt_id, ''), receive_admin_id
- ) t`, m.TableName(), condition)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
- return
- }
- // 批量新增推送记录
- func (m *ReportMessageRecord) BatchAdd(list []*ReportMessageRecord) (err error) {
- err = global.DmSQL["rddp"].Create(list).Error
- return
- }
- // ReportIceMsgRecordListResp 消息推送记录列表响应体
- type ReportIceMsgRecordListResp struct {
- List []*ReportIceMsgRecordListItem
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type ReportIceMsgPushReq struct {
- ReportId int `description:"研报ID"`
- PptId int `description:"PPT ID"`
- }
- type ReportIceMsgPushResp struct {
- MsgSendTime time.Time `description:"消息发送时间"`
- }
- func (m *ReportMessageConfig) GetListByClassifyIdList(classifyIdList []int) (list []*ReportMessageConfig, err error) {
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE classify_id IN (?)`, m.TableName())
- err = global.DmSQL["rddp"].Raw(sql, classifyIdList).Find(&list).Error
- return
- }
- // 查询消息推送记录
- func (m *ReportMessageRecord) GetSuccessRecordAdminIdsByReportId(reportId int, title, content, url string) (adminIds []int, err error) {
- sql := fmt.Sprintf(`SELECT DISTINCT receive_admin_id FROM %s WHERE report_id = ? AND report_title = ? AND content = ? AND url = ? AND status = 1`, m.TableName())
- err = global.DmSQL["rddp"].Raw(sql, reportId, title, content, url).Scan(&adminIds).Error
- return
- }
- // 查询消息推送记录
- func (m *ReportMessageRecord) GetSuccessRecordAdminIdsByPptId(pptId int, title, content, url string) (adminIds []int, err error) {
- sql := fmt.Sprintf(`SELECT DISTINCT receive_admin_id FROM %s WHERE ppt_id = ? AND ppt_title = ? AND ppt_content = ? AND ppt_url = ? AND status = 1`, m.TableName())
- err = global.DmSQL["rddp"].Raw(sql, pptId, title, content, url).Scan(&adminIds).Error
- return
- }
|