123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_mini_crm_ht/models"
- "eta/eta_mini_crm_ht/models/request"
- "eta/eta_mini_crm_ht/models/response"
- "eta/eta_mini_crm_ht/services"
- "eta/eta_mini_crm_ht/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strconv"
- "strings"
- "time"
- )
- type MessageController struct {
- BaseAuthController
- }
- // ReportList
- // @Title 研报列表
- // @Description pdf研报列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
- // @Param KeyWord query string true "报告标题/创建人"
- // @Param SortType query string true "排序方式"
- // @Success 200 {object} models.ReportAuthorResp
- // @router /reportList [get]
- func (this *MessageController) ReportList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- permissionIds := this.GetString("PermissionIds")
- analystNames := this.GetString("AnalystNames")
- sortType := this.GetString("SortType")
- KeyWord := this.GetString("KeyWord")
- var permissionCondition string
- var condition string
- var pars []interface{}
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- if KeyWord != "" {
- condition += " AND title like '%" + KeyWord + "%'"
- }
- var permissionPars []interface{}
- var classifyPars []interface{}
- var htPermissions []int
- if permissionIds != "" {
- permissionArr := strings.Split(permissionIds, ",")
- for _, permissionId := range permissionArr {
- perId, _ := strconv.Atoi(permissionId)
- htPermissions = append(htPermissions, perId)
- permissionPars = append(permissionPars, perId)
- }
- permissionCondition += " AND chart_permission_id in (" + utils.GetOrmReplaceHolder(len(permissionPars)) + ")"
- classifyIds, err := models.GetClassifyIdsByPermissionIds(permissionCondition, permissionPars)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "eta获取品种信息失败,Err:" + err.Error()
- return
- }
- if len(classifyIds) == 0 {
- br.Ret = 200
- br.Success = true
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp := new(response.ReportListResp)
- resp.List = []*models.ReportView{}
- resp.Paging = page
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- classifyCondition := " AND COALESCE(NULLIF(classify_id_third,0),NULLIF(classify_id_second,0),classify_id_first) in (" + utils.GetOrmReplaceHolder(len(classifyIds)) + ")"
- classifyPars = append(classifyPars, classifyIds)
- var orgIds []int
- // eta
- orgIds, _ = models.GetETAReportIdsByCondition(classifyCondition, classifyPars)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取报告表ids失败,Err:" + err.Error()
- return
- }
- //海通
- names, err := models.GetPermissionNames(htPermissions)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取品种名称失败,Err:" + err.Error()
- return
- }
- if len(orgIds) == 0 && len(names) == 0 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp := new(response.ReportListResp)
- resp.List = []*models.ReportView{}
- resp.Paging = page
- br.Data = resp
- return
- } else if len(orgIds) == 0 {
- condition += "And (plate_name in (" + utils.GetOrmReplaceHolder(len(names)) + ") And source ='HT')"
- pars = append(pars, names)
- } else if len(names) == 0 {
- condition += "AND ( org_id in (" + utils.GetOrmReplaceHolder(len(orgIds)) + ") And source ='ETA') "
- pars = append(pars, orgIds)
- } else {
- condition += "AND ( (org_id in (" + utils.GetOrmReplaceHolder(len(orgIds)) + ") And source ='ETA') or (plate_name in (" + utils.GetOrmReplaceHolder(len(names)) + ") And source ='HT'))"
- pars = append(pars, orgIds)
- pars = append(pars, names)
- }
- }
- if analystNames != "" {
- condition += " AND ("
- analystNameArr := strings.Split(analystNames, ",")
- for i := 0; i < len(analystNameArr); i++ {
- condition += "(author like '%" + analystNameArr[i] + "%')"
- if i != len(analystNameArr)-1 {
- condition += " OR "
- }
- }
- condition += " )"
- //pars = append(pars, analystNameArr)
- }
- sortCondition := " ORDER BY published_time "
- if sortType == "" {
- sortType = "DESC"
- }
- sortCondition = sortCondition + sortType
- total, err := models.GetReportCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取报告列表统计失败,Err:" + err.Error()
- return
- }
- startSize := utils.StartIndex(currentIndex, pageSize)
- reportList, err := models.GetReportByCondition(condition, sortCondition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
- return
- }
- var reportViewList []*models.ReportView
- for _, report := range reportList {
- reportView := report.ToView()
- reportViewList = append(reportViewList, reportView)
- }
- for _, report := range reportViewList {
- switch report.Source {
- case "ETA":
- var classifyId int
- classifyId, err = models.GetETAReportById(report.OrgId)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取eta报告失败,Err:" + err.Error()
- return
- }
- var list []int
- list, err = models.GetByPermissionIdsByClassifyId(classifyId)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取eta品种信息失败,Err:" + err.Error()
- return
- }
- if len(list) > 0 {
- var names []string
- names, err = models.GetPermissionNames(list)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取eta品种名称信息失败,Err:" + err.Error()
- return
- }
- report.PermissionNames = strings.Join(names, ",")
- }
- case "HT":
- report.PermissionNames = report.PlateName
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(response.ReportListResp)
- resp.List = reportViewList
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Data = resp
- br.Msg = "获取成功"
- }
- // AudioList
- // @Title 研报列表
- // @Description pdf研报列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
- // @Param KeyWord query string true "报告标题/创建人"
- // @Param SortType query string true "排序方式"
- // @Success 200 {object} models.ReportAuthorResp
- // @router /audioList [get]
- func (this *MessageController) AudioList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- permissionIds := this.GetString("PermissionIds")
- analystIds := this.GetString("AnalystIds")
- sortType := this.GetString("SortType")
- KeyWord := this.GetString("KeyWord")
- var permissionCondition string
- var condition string
- var pars []interface{}
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- if KeyWord != "" {
- condition += " AND media_name like '%" + KeyWord + "%'"
- }
- var permissionPars []interface{}
- if permissionIds != "" {
- permissionArr := strings.Split(permissionIds, ",")
- for _, permissionId := range permissionArr {
- perId, _ := strconv.Atoi(permissionId)
- permissionPars = append(permissionPars, perId)
- }
- permissionCondition += " AND permission_id in (" + utils.GetOrmReplaceHolder(len(permissionPars)) + ")"
- ids, err := models.GetMappingsByCondition(permissionCondition, permissionPars)
- if err != nil {
- br.Msg = "查询失败"
- br.Msg = "筛选品种信息失败,Err:" + err.Error()
- return
- }
- if len(ids) == 0 {
- br.Ret = 200
- br.Success = true
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp := new(response.MessageMediaListResp)
- resp.List = []*models.MessageMedia{}
- resp.Paging = page
- br.Data = resp
- br.Msg = "获取成功"
- return
- }
- condition += " AND id in (" + utils.GetOrmReplaceHolder(len(ids)) + ")"
- pars = append(pars, ids)
- }
- if analystIds != "" {
- analystIdArr := strings.Split(analystIds, ",")
- var authorIds []int
- for _, analystId := range analystIdArr {
- id, _ := strconv.Atoi(analystId)
- authorIds = append(authorIds, id)
- }
- condition += " AND author_id in (" + utils.GetOrmReplaceHolder(len(authorIds)) + ")"
- pars = append(pars, authorIds)
- }
- sortCondition := " ORDER BY published_time "
- if sortType == "" {
- sortType = "DESC"
- }
- sortCondition = sortCondition + sortType
- total, err := models.GetMediaCountByCondition(models.Audio, condition, pars)
- if err != nil {
- br.Msg = "获取研报列表失败"
- br.ErrMsg = "获取研报列表统计失败,Err:" + err.Error()
- return
- }
- startSize := utils.StartIndex(currentIndex, pageSize)
- reportList, err := models.GetMediaByCondition(models.Audio, condition, sortCondition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取研报列表失败"
- br.ErrMsg = "获取研报列表失败,Err:" + err.Error()
- return
- }
- var reportViewList []*models.MessageMedia
- for _, report := range reportList {
- reportView := report.ToMessageView()
- reportViewList = append(reportViewList, reportView)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(response.MessageMediaListResp)
- resp.List = reportViewList
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Data = resp
- br.Msg = "获取成功"
- }
- // VideoList
- // @Title 研报列表
- // @Description pdf研报列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
- // @Param KeyWord query string true "报告标题/创建人"
- // @Param SortType query string true "排序方式"
- // @Success 200 {object} models.ReportAuthorResp
- // @router /videoList [get]
- func (this *MessageController) VideoList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- permissionIds := this.GetString("PermissionIds")
- analystIds := this.GetString("AnalystIds")
- sortType := this.GetString("SortType")
- KeyWord := this.GetString("KeyWord")
- var permissionCondition string
- var condition string
- var pars []interface{}
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- if KeyWord != "" {
- condition += " AND media_name like '%" + KeyWord + "%'"
- }
- var permissionPars []interface{}
- if permissionIds != "" {
- permissionArr := strings.Split(permissionIds, ",")
- for _, permissionId := range permissionArr {
- perId, _ := strconv.Atoi(permissionId)
- permissionPars = append(permissionPars, perId)
- }
- permissionCondition += " AND permission_id in (" + utils.GetOrmReplaceHolder(len(permissionPars)) + ")"
- ids, err := models.GetMappingsByCondition(permissionCondition, permissionPars)
- if err != nil {
- br.Msg = "查询失败"
- br.Msg = "筛选品种信息失败,Err:" + err.Error()
- return
- }
- if len(ids) == 0 {
- br.Ret = 200
- br.Success = true
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp := new(response.MessageMediaListResp)
- resp.List = []*models.MessageMedia{}
- resp.Paging = page
- br.Msg = "获取成功"
- return
- }
- condition += " AND id in (" + utils.GetOrmReplaceHolder(len(ids)) + ")"
- pars = append(pars, ids)
- }
- if analystIds != "" {
- analystIdArr := strings.Split(analystIds, ",")
- var authorIds []int
- for _, analystId := range analystIdArr {
- id, _ := strconv.Atoi(analystId)
- authorIds = append(authorIds, id)
- }
- condition += " AND author_id in (" + utils.GetOrmReplaceHolder(len(authorIds)) + ")"
- pars = append(pars, authorIds)
- }
- sortCondition := " ORDER BY published_time "
- if sortType == "" {
- sortType = "DESC"
- }
- sortCondition = sortCondition + sortType
- total, err := models.GetMediaCountByCondition(models.Video, condition, pars)
- if err != nil {
- br.Msg = "获取视频列表失败"
- br.ErrMsg = "获取视频列表统计失败,Err:" + err.Error()
- return
- }
- startSize := utils.StartIndex(currentIndex, pageSize)
- List, err := models.GetMediaByCondition(models.Video, condition, sortCondition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取视频列表失败"
- br.ErrMsg = "获取视频列表失败,Err:" + err.Error()
- return
- }
- var reportViewList []*models.MessageMedia
- for _, report := range List {
- reportView := report.ToMessageView()
- reportViewList = append(reportViewList, reportView)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(response.MessageMediaListResp)
- resp.List = reportViewList
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Data = resp
- br.Msg = "获取成功"
- }
- const (
- Report string = "report"
- Audio string = "audio"
- Video string = "video"
- )
- // SendTemplateMsg
- // @Title 研报列表
- // @Description pdf研报列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
- // @Param KeyWord query string true "报告标题/创建人"
- // @Param SortType query string true "排序方式"
- // @Success 200 {object} models.ReportAuthorResp
- // @router /sendTemplateMsg [post]
- func (this *MessageController) SendTemplateMsg() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.WxMessageReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if req.DataId <= 0 {
- br.Msg = "DataId为空"
- return
- }
- if req.DataType == "" {
- br.Msg = "DataType为空"
- return
- }
- var template services.SendWxTemplate
- if req.DataType == Report {
- var report *models.Report
- report, err = models.GetReportById(req.DataId)
- if err != nil {
- br.Msg = "发送模版消息失败"
- br.ErrMsg = "获取报告失败"
- return
- }
- switch report.Source {
- case "ETA":
- var classifyId int
- var ids []int
- var names []string
- classifyId, err = models.GetETAReportIdByClassifyId(report.OrgId)
- ids, err = models.GetByPermissionIdsByClassifyId(classifyId)
- if err != nil {
- br.Msg = "发送模版消息失败"
- br.ErrMsg = fmt.Sprintf("获取eta品种信息失败,Err:%v", err)
- return
- }
- names, err = models.GetPermissionNames(ids)
- if err != nil {
- br.Msg = "发送模版消息失败"
- br.ErrMsg = fmt.Sprintf("获取eta品种信息失败,Err:%v", err)
- return
- }
- template.Keyword1 = strings.Join(names, ",")
- case "HT":
- template.Keyword1 = "ht"
- default:
- template.Keyword1 = ""
- }
- template.Keyword2 = report.Title
- template.Keyword3 = report.PublishedTime
- template.Keyword4 = report.Abstract
- err = report.UpdateSendStatus(models.SEND)
- if err != nil {
- br.Msg = "发送模版消息失败"
- br.ErrMsg = fmt.Sprintf("更新发送状态失败,Err:%v", err)
- return
- }
- }
- if req.DataType == Audio {
- var media *models.Media
- media, err = models.GetMediaById(models.Audio, req.DataId)
- if err != nil {
- br.Msg = "发送模版消息失败"
- br.ErrMsg = "获取音频失败"
- return
- }
- template.Keyword1 = "线上音频"
- template.Keyword2 = media.MediaName
- template.Keyword3 = media.CreatedTime.Format(time.DateTime)
- err = media.UpdateSendStatus(models.SEND)
- if err != nil {
- br.Msg = "发送模版消息失败"
- br.ErrMsg = fmt.Sprintf("更新发送状态失败,Err:%v", err)
- return
- }
- }
- if req.DataType == Video {
- var media *models.Media
- media, err = models.GetMediaById(models.Video, req.DataId)
- if err != nil {
- br.Msg = "发送模版消息失败"
- br.ErrMsg = "获取音频失败"
- return
- }
- template.Keyword1 = "线上视频"
- template.Keyword2 = media.MediaName
- template.Keyword3 = media.CreatedTime.Format(time.DateTime)
- err = media.UpdateSendStatus(models.SEND)
- if err != nil {
- br.Msg = "发送模版消息失败"
- br.ErrMsg = fmt.Sprintf("更新发送状态失败,Err:%v", err)
- return
- }
- }
- users, err := models.GetTemplateUserList()
- if err != nil {
- br.Msg = "发送模版消息失败"
- br.ErrMsg = "获取用户OPENID失败,Err:" + err.Error()
- return
- }
- var openIds []*services.OpenIdList
- for _, user := range users {
- openIdItem := &services.OpenIdList{
- OpenId: user.GzhOpenId,
- UserId: user.Id,
- FollowingGzh: user.FollowingGzh,
- }
- if openIdItem.OpenId != "" && openIdItem.FollowingGzh {
- openIds = append(openIds, openIdItem)
- }
- }
- err = services.SendMultiTemplateMsg(template, openIds, req.DataId, req.DataType)
- if err != nil {
- if req.DataType == Report {
- var report *models.Report
- report, err = models.GetReportById(req.DataId)
- if err != nil {
- return
- }
- _ = report.UpdateSendStatus(models.UNSEND)
- }
- if req.DataType == Audio {
- var media *models.Media
- media, err = models.GetMediaById(models.Audio, req.DataId)
- if err != nil {
- return
- }
- _ = media.UpdateSendStatus(models.UNSEND)
- }
- if req.DataType == Video {
- var media *models.Media
- media, err = models.GetMediaById(models.Video, req.DataId)
- if err != nil {
- return
- }
- _ = media.UpdateSendStatus(models.SEND)
- }
- br.Msg = "发送模板消息失败"
- br.ErrMsg = "发送模板消息失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Data = nil
- br.Msg = "发送成功"
- }
|