123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589 |
- package english_report
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_ETA_mobile_api/controllers"
- "hongze/hongze_ETA_mobile_api/models"
- "hongze/hongze_ETA_mobile_api/models/company"
- "hongze/hongze_ETA_mobile_api/services"
- "hongze/hongze_ETA_mobile_api/utils"
- "html"
- "sort"
- "strconv"
- "strings"
- )
- // EnglishReportController 研报活动模块
- type EnglishReportController struct {
- controllers.BaseAuthController
- }
- // @Title 获取报告详情接口
- // @Description 获取报告详情
- // @Param request body models.ReportDetailReq true "type json string"
- // @Success 200 {object} models.EnglishReportDetailView
- // @router /detail [get]
- func (this *EnglishReportController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- reportId, err := this.GetInt("ReportId")
- if err != nil {
- br.Msg = "获取参数失败!"
- br.ErrMsg = "获取参数失败,Err:" + err.Error()
- return
- }
- if reportId <= 0 {
- br.Msg = "参数错误"
- return
- }
- item, err := models.GetEnglishReportById(reportId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- item.Content = html.UnescapeString(item.Content)
- item.ContentSub = html.UnescapeString(item.ContentSub)
- // 获取邮件配置-是否有权限群发
- conf := new(models.EnglishReportEmailConf)
- authKey := "english_report_email_conf"
- confAuth, e := company.GetConfigDetailByCode(authKey)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取群发邮件权限失败, Err: " + e.Error()
- return
- }
- if confAuth.ConfigValue == "" {
- br.Msg = "获取失败"
- br.ErrMsg = "群发邮件配置为空"
- return
- }
- if e := json.Unmarshal([]byte(confAuth.ConfigValue), &conf); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "群发邮件配置有误"
- return
- }
- authOk := false
- authArr := strings.Split(conf.SendAuthGroup, ",")
- if utils.InArrayByStr(authArr, sysUser.RoleTypeCode) {
- authOk = true
- }
- item.EmailAuth = authOk
- // 是否有群发邮件失败的记录,标记红点
- failList, e := models.GetEnglishReportEmailLogFailList(0)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取群发邮件记录失败, Err: " + e.Error()
- return
- }
- failMap := make(map[int]bool, 0)
- for i := range failList {
- failMap[failList[i].ReportId] = true
- }
- item.EmailHasFail = failMap[item.Id]
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = item
- }
- // @Title 获取报告列表接口
- // @Description 获取报告列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param StartDate query string true "开始时间"
- // @Param EndDate query string true "结束时间"
- // @Param Frequency query string true "频度"
- // @Param ClassifyNameFirst query string true "一级分类名称"
- // @Param ClassifyNameSecond query string true "二级分类名称"
- // @Param State query int true "状态"
- // @Param KeyWord query string true "搜索关键词"
- // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
- // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
- // @Success 200 {object} models.ReportListResp
- // @router /list [get]
- func (this *EnglishReportController) ListReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- frequency := this.GetString("Frequency")
- classifyNameFirst := this.GetString("ClassifyNameFirst")
- classifyNameSecond := this.GetString("ClassifyNameSecond")
- state, _ := this.GetInt("State")
- keyWord := this.GetString("KeyWord")
- companyType := this.GetString("CompanyType")
- // 群发邮件状态筛选
- emailState, _ := this.GetInt("EmailState")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if keyWord != "" {
- condition += ` AND (title LIKE '%` + keyWord + `%' OR author LIKE '%` + keyWord + `%' ) `
- }
- if startDate != "" {
- condition += ` AND create_time >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND create_time <= ? `
- pars = append(pars, endDate)
- }
- if frequency != "" {
- condition += ` AND frequency = ? `
- pars = append(pars, frequency)
- }
- if classifyNameFirst != "" {
- condition += ` AND classify_name_first = ? `
- pars = append(pars, classifyNameFirst)
- }
- if classifyNameSecond != "" {
- condition += ` AND classify_name_second = ? `
- pars = append(pars, classifyNameSecond)
- }
- if state > 0 {
- condition += ` AND state = ? `
- pars = append(pars, state)
- }
- // 未群发邮件(包含推送邮件失败的)
- if emailState == 1 {
- failIds, e := models.GetHasFailEmailLogReportIds()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取存在邮件推送失败记录的英文报告IDs失败, Err:" + e.Error()
- return
- }
- condition += ` AND email_state = 0`
- if len(failIds) > 0 {
- condition += ` OR id IN (` + utils.GetOrmInReplace(len(failIds)) + `)`
- pars = append(pars, failIds)
- }
- }
- // 已群发邮件
- if emailState == 2 {
- successIds, e := models.GetSuccessEmailLogReportIds()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取邮件推送记录均为成功的英文报告IDs失败, Err:" + e.Error()
- return
- }
- condition += ` AND email_state = 1`
- if len(successIds) > 0 {
- condition += ` AND id IN (` + utils.GetOrmInReplace(len(successIds)) + `)`
- pars = append(pars, successIds)
- }
- }
- total, err := models.GetEnglishReportListCount(condition, pars, companyType)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, err := models.GetEnglishReportList(condition, pars, companyType, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- // 获取邮件配置-是否有权限群发
- conf := new(models.EnglishReportEmailConf)
- authKey := "english_report_email_conf"
- confAuth, e := company.GetConfigDetailByCode(authKey)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取群发邮件权限失败, Err: " + e.Error()
- return
- }
- if confAuth.ConfigValue == "" {
- br.Msg = "获取失败"
- br.ErrMsg = "群发邮件配置为空"
- return
- }
- if e := json.Unmarshal([]byte(confAuth.ConfigValue), &conf); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "群发邮件配置有误"
- return
- }
- authOk := false
- authArr := strings.Split(conf.SendAuthGroup, ",")
- if utils.InArrayByStr(authArr, sysUser.RoleTypeCode) {
- authOk = true
- }
- // 是否有群发邮件失败的记录,标记红点
- failList, e := models.GetEnglishReportEmailLogFailList(0)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取群发邮件记录失败, Err: " + e.Error()
- return
- }
- failMap := make(map[int]bool, 0)
- for i := range failList {
- failMap[failList[i].ReportId] = true
- }
- for _, item := range list {
- if item.State == 2 {
- item.ShareUrl = "https://share.hzinsights.com/reportEn?code=" + item.ReportCode
- }
- item.EmailAuth = authOk
- item.EmailHasFail = failMap[item.Id]
- // 邮箱PV大于0的时候, 不展示最初版本的PV
- if item.PvEmail > 0 {
- item.Pv = 0
- }
- /*key := fmt.Sprint(`crm:enReport:edit:`, item.Id)
- opUserId, _ := utils.Rc.RedisInt(key)
- //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
- if opUserId <= 0 || (opUserId == this.SysUser.AdminId) {
- item.CanEdit = true
- } else {
- adminInfo, errAdmin := system.GetSysUserById(opUserId)
- if errAdmin != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
- return
- }
- item.Editor = adminInfo.RealName
- }*/
- markStatus, err := services.UpdateEnReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName)
- if err != nil {
- br.Msg = "查询标记状态失败"
- br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
- return
- }
- if markStatus.Status == 0 {
- item.CanEdit = true
- } else {
- item.Editor = markStatus.Editor
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.EnglishReportListResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 获取分类列表
- // @Description 获取分类列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "检索关键词"
- // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
- // @Success 200 {object} models.EnglishClassifyListResp
- // @router /classify/list [get]
- func (this *EnglishReportController) ListClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyWord := this.GetString("KeyWord")
- classifyType, _ := this.GetInt("ClassifyType", 0)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp := new(models.EnglishClassifyListResp)
- list, err := models.GetEnglishClassifyList(startSize, pageSize, keyWord, classifyType)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- total, err := models.GetEnglishClassifyListCount(keyWord, classifyType)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if total == 0 {
- resp.List = make([]*models.EnglishClassifyList, 0)
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- var parentIds []int
- for _, v := range list {
- parentIds = append(parentIds, v.Id)
- }
- childMap := make(map[int][]*models.EnglishClassify)
- tmpList, err := models.GetEnglishClassifyChildByParentIds(parentIds, keyWord, classifyType)
- if err != nil {
- br.Msg = "获取二级分类失败"
- br.ErrMsg = "获取二级分类失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpList {
- childMap[v.ParentId] = append(childMap[v.ParentId], v)
- }
- for _, v := range list {
- if child, ok := childMap[v.Id]; ok {
- v.Child = child
- }
- }
- var sortList models.RSClassifyList
- sortList = list
- sort.Sort(sortList)
- for _, item := range sortList {
- var sortChildList models.RSChildClassifyList
- sortChildList = item.Child
- sort.Sort(sortChildList)
- item.Child = sortChildList
- }
- resp.List = sortList
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 删除分类列表
- // @Description 删除分类列表
- // @Param ClassifyId int true "分类名称"
- // @Param ParentId query int true "父级Id"
- // @Success 200 保存成功
- // @router /classify/delete [get]
- func (this *EnglishReportController) DelClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyId, _ := this.GetInt("ClassifyId")
- //parentId, _ := this.GetInt("ParentId")
- classifyInfo, err := models.GetEnglishReportClassifyById(classifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "当前分类不存在"
- br.ErrMsg = "当前分类不存在"
- return
- }
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- count, err := models.GetEnglishClassifyChildCounts(classifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "请先删除该分类下关联分类"
- br.Ret = 403
- return
- }
- if classifyInfo.ClassifyType == 0 {
- reportCount, e := models.GetEnglishReportCounts(classifyId, classifyInfo.ParentId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取失败,Err:" + e.Error()
- return
- }
- if reportCount > 0 {
- br.Msg = "该分类有关联报告,不允许删除"
- br.Ret = 403
- return
- }
- } else {
- videoCount, e := models.GetEnglishVideoCounts(classifyId, classifyInfo.ParentId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取失败,Err:" + e.Error()
- return
- }
- if videoCount > 0 {
- br.Msg = "该分类有关联的路演视频,不允许删除"
- br.Ret = 403
- return
- }
- }
- if err = models.DeleteEnglishClassify(classifyId); err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除报告失败, Err: " + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // @Title 发布报告接口
- // @Description 发布报告
- // @Param request body models.PublishReq true "type json string"
- // @Success 200 Ret=200 发布成功
- // @router /publish [post]
- func (this *EnglishReportController) PublishReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.PublishReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- reportIds := req.ReportIds
- if reportIds == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,报告id不可为空"
- return
- }
- reportArr := strings.Split(reportIds, ",")
- for _, v := range reportArr {
- vint, err := strconv.Atoi(v)
- if err != nil {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,Err:" + err.Error()
- return
- }
- report, err := models.GetEnglishReportById(vint)
- if err != nil {
- br.Msg = "获取报告信息失败"
- br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
- return
- }
- if report == nil {
- br.Msg = "报告不存在"
- return
- }
- var tmpErr error
- if report.Content == "" {
- br.Msg = "报告内容为空,不可发布"
- br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
- return
- }
- if tmpErr = models.PublishEnglishReportById(report.Id); tmpErr != nil {
- br.Msg = "报告发布失败"
- br.ErrMsg = "报告发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
- return
- }
- go func() {
- _ = services.UpdateEnglishReportEs(report.Id, 2)
- }()
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "发布成功"
- }
- // @Title 取消发布报告接口
- // @Description 取消发布报告
- // @Param request body models.PublishCancelReq true "type json string"
- // @Success 200 Ret=200 取消发布成功
- // @router /publish/cancel [post]
- func (this *EnglishReportController) PublishCancleReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.PublishCancelReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ReportIds <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,报告id不可为空"
- return
- }
- err = models.PublishCancelEnglishReport(req.ReportIds)
- if err != nil {
- br.Msg = "取消发布失败"
- br.ErrMsg = "取消发布失败,Err:" + err.Error()
- return
- }
- // 更新es里的报告状态
- go func() {
- _ = services.UpdateEnglishReportEs(req.ReportIds, 1)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "取消发布成功"
- }
|