package controllers import ( "encoding/json" "eta_gn/eta_api/models" "eta_gn/eta_api/services" "eta_gn/eta_api/services/alarm_msg" "eta_gn/eta_api/utils" "fmt" "github.com/beego/beego/v2/server/web" "github.com/h2non/filetype" "github.com/tealeg/xlsx" "html" "io" "os" "path" "path/filepath" "strconv" "strings" "time" ) // ReportController 报告 type ReportController struct { BaseAuthController } // ReportCommonController 报告 type ReportCommonController struct { BaseCommonController } // ReportUploadCommonController 报告上传 type ReportUploadCommonController struct { web.Controller } // Delete // @Title 删除报告接口 // @Description 删除报告 // @Param request body models.DeleteReq true "type json string" // @Success 200 Ret=200 删除成功 // @router /delete [post] func (this *ReportController) Delete() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.DeleteReq 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 } if err := services.DeleteReportAndChapter(req.ReportIds); err != nil { br.Msg = "删除失败" br.ErrMsg = "删除报告失败, Err: " + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "删除成功" } // Upload // @Title 图片上传 // @Description 图片上传接口 // @Param file query file true "文件" // @Success 200 新增成功 // @router /upload [post] func (this *ReportController) Upload() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() f, h, err := this.GetFile("file") if err != nil { br.Msg = "获取资源信息失败" br.ErrMsg = "获取资源信息失败,Err:" + err.Error() return } fileData, e := io.ReadAll(f) if e != nil { br.Msg = "上传失败" br.ErrMsg = "读取文件失败, Err: " + e.Error() return } pass := filetype.IsImage(fileData) if !pass { br.Msg = "文件格式有误" br.ErrMsg = "文件格式有误" return } ext := path.Ext(h.Filename) dateDir := time.Now().Format("20060102") uploadDir := utils.STATIC_DIR + "hongze/" + dateDir err = os.MkdirAll(uploadDir, utils.DIR_MOD) if err != nil { br.Msg = "存储目录创建失败" br.ErrMsg = "存储目录创建失败,Err:" + err.Error() return } randStr := utils.GetRandStringNoSpecialChar(28) fileName := randStr + ext fpath := uploadDir + "/" + fileName defer f.Close() //关闭上传文件 err = this.SaveToFile("file", fpath) if err != nil { br.Msg = "文件上传失败" br.ErrMsg = "文件上传失败,Err:" + err.Error() return } resourceUrl := `` //上传到阿里云 和 minio //if utils.ObjectStorageClient == "minio" { // resourceUrl, err = services.UploadImgToMinIo(fileName, fpath) // if err != nil { // br.Msg = "文件上传失败" // br.ErrMsg = "文件上传失败,Err:" + err.Error() // return // } //} else { // resourceUrl, err = services.UploadAliyunV2(fileName, fpath) // if err != nil { // br.Msg = "文件上传失败" // br.ErrMsg = "文件上传失败,Err:" + err.Error() // return // } //} ossClient := services.NewOssClient() if ossClient == nil { br.Msg = "上传失败" br.ErrMsg = "初始化OSS服务失败" return } resourceUrl, err = ossClient.UploadFile(fileName, fpath, "") if err != nil { br.Msg = "文件上传失败" br.ErrMsg = "文件上传失败,Err:" + err.Error() return } defer func() { os.Remove(fpath) }() item := new(models.Resource) item.ResourceUrl = resourceUrl item.ResourceType = 1 item.CreateTime = time.Now() newId, err := models.AddResource(item) if err != nil { br.Msg = "资源上传失败" br.ErrMsg = "资源上传失败,Err:" + err.Error() return } resp := new(models.ResourceResp) resp.Id = newId resp.ResourceUrl = resourceUrl br.Msg = "上传成功" br.Ret = 200 br.Success = true br.Data = resp return } // ClassifyIdDetail // @Title 根据分类获取最近一次报告详情接口 // @Description 根据分类获取最近一次报告详情 // @Param request body models.ClassifyIdDetailReq true "type json string" // @Success 200 {object} models.Report // @router /classifyIdDetail [get] func (this *ReportController) ClassifyIdDetail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() //classify_id_first=34&classify_id_second=36 /*var req models.ClassifyIdDetailReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return }*/ classifyIdFirst, _ := this.GetInt("classify_id_first") if classifyIdFirst <= 0 { classifyIdFirst, _ = this.GetInt("ClassifyIdFirst") } classifyIdSecond, _ := this.GetInt("classify_id_second") if classifyIdSecond <= 0 { classifyIdSecond, _ = this.GetInt("ClassifyIdSecond") } item, err := models.GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败!" br.ErrMsg = "获取失败,Err:" + err.Error() return } if item != nil { item.Content = html.UnescapeString(item.Content) item.ContentSub = html.UnescapeString(item.ContentSub) } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = item } // SendTemplateMsg // @Title 模板消息推送接口 // @Description 模板消息推送 // @Param request body models.SendTemplateMsgReq true "type json string" // @Success 200 Ret=200 推送成功 // @router /sendTemplateMsg [post] func (this *ReportController) SendTemplateMsg() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() br.Ret = 200 br.Success = true br.Msg = "操作成功" return } // Author // @Title 获取报告作者接口 // @Description 获取报告作者 // @Param AuthorType query int true "来源类型,1:中文,2:英文" // @Param StartDate query string true "开始时间" // @Success 200 {object} models.ReportAuthorResp // @router /author [get] func (this *ReportController) Author() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() keyword := this.GetString("Keyword") var condition string var pars []interface{} condition += ` AND author_type = 1 AND enable = 1` if keyword != `` { condition += ` AND report_author like ? ` pars = append(pars, utils.GetLikeKeyword(keyword)) } _, items, err := models.GetReportAuthorList(condition, pars, 0, 10000) if err != nil { br.Msg = "获取失败!" br.ErrMsg = "获取失败,Err:" + err.Error() return } resp := models.ReportAuthorResp{ List: items, } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // UploadImg // @Title 图片上传 // @Description 图片上传接口 // @Param File query file true "文件" // @Success 200 上传成功 // @router /uploadImg [post] func (this *ReportUploadCommonController) UploadImg() { var err error defer func() { if err != nil { fmt.Println("文件上传失败:", err.Error()) go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+" 文件上传失败:"+err.Error(), 3) //go utils.SendEmail(utils.APPNAME+"失败提醒", "URI:"+this.Ctx.Input.URI()+" 文件上传失败:"+err.Error(), utils.EmailSendToUsers) } }() f, h, err := this.GetFile("file") if err != nil { return } defer f.Close() //关闭上传文件 // 不依赖于文件扩展名检查文件格式 fileData, e := io.ReadAll(f) if e != nil { err = fmt.Errorf("读取文件失败, Err: %s", e.Error()) return } pass := filetype.IsImage(fileData) if !pass { kind, _ := filetype.Match(fileData) if kind.Extension != "pdf" { err = fmt.Errorf("文件格式有误") return } fmt.Printf("File type: %s. MIME: %s\n", kind.Extension, kind.MIME.Value) } ext := path.Ext(h.Filename) dateDir := time.Now().Format("20060102") uploadDir := utils.STATIC_DIR + "hongze/" + dateDir err = os.MkdirAll(uploadDir, utils.DIR_MOD) if err != nil { return } randStr := utils.GetRandStringNoSpecialChar(28) fileName := randStr + ext fpath := uploadDir + "/" + fileName err = this.SaveToFile("file", fpath) if err != nil { return } defer func() { os.Remove(fpath) }() // 上传至对象存储 resourceUrl := `` ossClient := services.NewOssClient() if ossClient == nil { err = fmt.Errorf("初始化OSS服务失败") return } resourceUrl, err = ossClient.UploadFile(fileName, fpath, "") if err != nil { err = fmt.Errorf("文件上传失败, Err: %s", err.Error()) return } item := new(models.Resource) item.ResourceUrl = resourceUrl item.ResourceType = 1 item.CreateTime = time.Now() newId, err := models.AddResource(item) if err != nil { return } resp := new(models.ResourceResp) resp.Id = newId resp.ResourceUrl = resourceUrl this.Data["json"] = map[string]string{"link": resourceUrl} this.ServeJSON() } // Export // @Title 研报浏览数据导出 // @Description 研报浏览数据导出接口 // @Param ReportIds query string true "报告id,多个报告用英文,隔开" // @Success 200 {object} company.CompanyListResp // @router /report_view_record/export [get] func (this *ReportController) Export() { 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 } reportIds := this.GetString("ReportIds") if reportIds == "" { br.Msg = "请选择需要下载的报告" br.ErrMsg = "请选择需要下载的报告" return } //生成excel文件 dir, err := os.Executable() exPath := filepath.Dir(dir) downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx" xlsxFile := xlsx.NewFile() if err != nil { br.Msg = "生成文件失败" br.ErrMsg = "生成文件失败" return } //只有权益研究员,以及超管可以下载 if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_RESEARCHR && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN { br.Msg = "没有下载权限" br.ErrMsg = "没有下载权限" return } //普通样式 style := xlsx.NewStyle() alignment := xlsx.Alignment{ Horizontal: "center", Vertical: "center", WrapText: true, } //设置默认字体和文字大小 xlsx.SetDefaultFont(12, "宋体") style.Alignment = alignment style.ApplyAlignment = true //标题样式 titleStyle := xlsx.NewStyle() titleFont := xlsx.NewFont(20, "宋体") titleFont.Bold = true titleStyle.Font = *titleFont titleStyle.Alignment = alignment //titleStyle.ApplyAlignment = true //表头 headerStyle := xlsx.NewStyle() headerFont := xlsx.NewFont(12, "宋体") headerFont.Bold = true headerStyle.Font = *headerFont headerStyle.Alignment = alignment headerStyle.ApplyAlignment = true defer func() { os.Remove(downLoadnFilePath) }() //记录已经命名了的表单名称 sheetNameMap := make(map[string]int) reportSlice := strings.Split(reportIds, ",") for _, reportIdStr := range reportSlice { reportId, convErr := strconv.Atoi(reportIdStr) if convErr != nil { br.Msg = "报告传参异常" br.ErrMsg = "报告传参异常" return } report, reportErr := models.GetReportById(reportId) if reportErr != nil { br.Msg = "查询报告异常" br.ErrMsg = "查询报告异常:" + reportErr.Error() return } //查询浏览记录 _, viewList, err := models.GetViewListByReportId(reportId) //fmt.Println(total) //fmt.Println(viewList) //fmt.Println(err) if err != nil { br.Msg = "查询报告浏览记录异常" br.ErrMsg = "查询报告浏览记录异常:" + err.Error() return } //导入报表 //报表名称 createTime, _ := time.Parse(utils.FormatDateTime, report.CreateTime) timeStr := createTime.Format("0102") reportName := report.Title + "(" + timeStr + ")" //表单名称 sheetName := reportName //判断当前sheet表单map中是否已经存在该表单名称,如果存在,那么需要添加后缀,并给sheet表单map中赋值次数加1处理;不存在,那么还是使用当前名称,并给sheet表单map中赋值次数为1 if n, ok := sheetNameMap[sheetName]; ok == true { n++ sheetName = sheetName + "_" + strconv.Itoa(n) sheetNameMap[sheetName] = n } else { sheetNameMap[sheetName] = 1 } sheel, err := xlsxFile.AddSheet(sheetName) if err != nil { br.Msg = "新增Sheet失败" br.ErrMsg = "新增Sheet失败,Err:" + err.Error() return } //设置列宽 sheel.SetColWidth(0, 0, 28) sheel.SetColWidth(1, 1, 18) sheel.SetColWidth(2, 2, 18) sheel.SetColWidth(3, 3, 18) sheel.SetColWidth(4, 4, 40) //标题行 titleRow := sheel.AddRow() titleRow.SetHeight(40) //标题列 titleCell := titleRow.AddCell() titleCell.HMerge = 4 //向右合并列数,不包括自身列 //报表标题名称 titleCell.SetValue(reportName) titleCell.SetStyle(titleStyle) //表头 headerRow := sheel.AddRow() headerRow.SetHeight(18) timeHeaderCell := headerRow.AddCell() timeHeaderCell.SetValue("浏览时间") timeHeaderCell.SetStyle(headerStyle) nameHeaderCell := headerRow.AddCell() nameHeaderCell.SetValue("用户名称") nameHeaderCell.SetStyle(headerStyle) mobileHeaderCell := headerRow.AddCell() mobileHeaderCell.SetValue("手机号") mobileHeaderCell.SetStyle(headerStyle) emailHeaderCell := headerRow.AddCell() emailHeaderCell.SetValue("邮箱") emailHeaderCell.SetStyle(headerStyle) companyHeaderCell := headerRow.AddCell() companyHeaderCell.SetValue("所属企业客户名称") companyHeaderCell.SetStyle(headerStyle) for _, v := range viewList { dataRow := sheel.AddRow() dataRow.SetHeight(18) timeCell := dataRow.AddCell() timeCell.SetString(v.CreateTime.Format(utils.FormatDateTime)) timeCell.SetStyle(style) nameCell := dataRow.AddCell() nameCell.SetString(v.RealName) nameCell.SetStyle(style) mobileCell := dataRow.AddCell() mobileCell.SetString(v.Mobile) mobileCell.SetStyle(style) emailCell := dataRow.AddCell() emailCell.SetString(v.Email) emailCell.SetStyle(style) companyCell := dataRow.AddCell() companyCell.SetString(v.CompanyName) companyCell.SetStyle(style) } } err = xlsxFile.Save(downLoadnFilePath) if err != nil { br.Msg = "保存文件失败" br.ErrMsg = "保存文件失败" return } randStr := time.Now().Format(utils.FormatDateTimeUnSpace) downloadFileName := "研报浏览记录" + randStr + ".xlsx" this.Ctx.Output.Download(downLoadnFilePath, downloadFileName) br.Ret = 200 br.Success = true br.Msg = "导出成功" } // ThsSendTemplateMsg // @Title 客群消息推送接口 // @Description 客群消息推送接口 // @Param request body models.SendTemplateMsgReq true "type json string" // @Success 200 Ret=200 推送成功 // @router /ths/sendTemplateMsg [post] func (this *ReportController) ThsSendTemplateMsg() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.ThsSendTemplateMsgReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } for _, v := range req.ReportId { if v <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } //加锁,避免重复点击造成的多次推送 { redisKey := fmt.Sprint("report:send:ths:", v) ok := utils.Rc.SetNX(redisKey, 1, time.Second*300) if !ok { br.Msg = "报告已推送客群,请勿重复推送" return } defer func() { utils.Rc.Delete(redisKey) }() } report, err := models.GetReportById(v) if err != nil { if utils.IsErrNoRow(err) { br.Msg = "报告已经被删除,请刷新页面" br.ErrMsg = "报告已经被删除,请刷新页面,req:" + string(this.Ctx.Input.RequestBody) return } br.Msg = "获取报告信息失败" br.ErrMsg = "获取报告信息失败,req:" + string(this.Ctx.Input.RequestBody) return } if report.ThsMsgIsSend == 1 { br.Msg = "消息已推送,请勿重复操作" br.ErrMsg = "模板消息已推送,请勿重复操作1" return } err = models.ModifyReportThsMsgIsSend(report) if err != nil { br.Msg = "发送失败" br.ErrMsg = "发送失败,Err:" + err.Error() return } } br.Ret = 200 br.Success = true br.Msg = "发送成功" } // GetDayWeekReportChapterTypeList // @Title 获取晨报周报章节类型列表 // @Description 获取晨报周报章节类型列表 // @Param StopType query string true "停更类型 stop; disable;" // @Success 200 {object} models.ReportListResp // @router /getDayWeekReportChapterTypeList [get] func (this *ReportController) GetDayWeekReportChapterTypeList() { 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 } br.Ret = 200 br.Success = true br.Msg = "操作成功" return } // GetDayWeekReportPauseTime // @Title 获取晨报周报的更新暂停时间 // @Description 获取晨报周报的更新暂停时间 // @Success 200 {object} models.ReportListResp // @router /getDayWeekReportPauseTime [get] func (this *ReportController) GetDayWeekReportPauseTime() { 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 } br.Ret = 200 br.Success = true br.Msg = "操作成功" return } // EditDayWeekReport // @Title 编辑晨周报 // @Description 编辑晨周报 // @Param request body models.SaveDayWeekReportReq true "type json string" // @Success 200 Ret=200 保存成功 // @router /editDayWeekReport [post] func (this *ReportController) EditDayWeekReport() { 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 } br.Ret = 200 br.Success = true br.Msg = "操作成功" return } // GetLastDayWeekReportChapter // @Title 获取上一篇已发表的晨周报章节内容 // @Description 获取上一篇已发表的晨周报章节内容 // @Param TypeId query int true "品种ID" // @Param ReportType query string true "报告类型 day-晨报; week-周报; " // @Success 200 {object} company.CompanyListResp // @router /getLastDayWeekReportChapter [get] func (this *ReportController) GetLastDayWeekReportChapter() { 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 } br.Ret = 200 br.Success = true br.Msg = "操作成功" return } // GetChapterTrendTag // @Title 获取章节趋势标签列表 // @Description 获取章节趋势标签列表 // @Success 200 Ret=200 获取成功 // @router /getChapterTrendTag [get] func (this *ReportController) GetChapterTrendTag() { 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 } list, err := models.GetKeyWordListByFrom("trend") if err != nil { br.Msg = "获取章节趋势标签列表失败" br.ErrMsg = "获取章节趋势标签列表失败, Err: " + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = list } // GetDayReportTickerList // @Title 获取晨报数据指标列表 // @Description 获取晨报数据指标列表 // @Param ReportChapterId query int true "章节ID" // @Success 200 Ret=200 保存成功 // @router /getDayReportTickerList [get] func (this *ReportController) GetDayReportTickerList() { 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 } br.Ret = 200 br.Success = true br.Msg = "操作成功" return } // GetDayWeekReportVideoList // @Title 获取晨周报音视频列表 // @Description 获取晨周报音视频列表 // @Param ReportId query int true "报告ID" // @Success 200 Ret=200 保存成功 // @router /getDayWeekReportVideoList [get] func (this *ReportController) GetDayWeekReportVideoList() { 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, _ := this.GetInt("ReportId") if reportId <= 0 { br.Msg = "参数有误" return } list, err := models.GetReportChapterVideoList(reportId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取报告音频列表失败, Err: " + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = list } // IsLastDayWeekReportChapter // @Title 是否为晨周报本期最后一个发布的报告 // @Description 是否为晨周报本期最后一个发布的报告 // @Param ReportChapterId query int true "报告章节ID" // @Success 200 Ret=200 获取成功 // @router /isLastDayWeekReportChapter [get] func (this *ReportController) IsLastDayWeekReportChapter() { 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 } br.Ret = 200 br.Success = true br.Msg = "操作成功" return } // PublishDayWeekReport // @Title 发布晨周报 // @Description 发布晨周报 // @Param request body models.PublishDayWeekReportReq true "type json string" // @Success 200 Ret=200 操作成功 // @router /publishDayWeekReport [post] func (this *ReportController) PublishDayWeekReport() { 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 } br.Ret = 200 br.Success = true br.Msg = "操作成功" return } // GetStopDayWeekReportChapterTypeList // @Title 获取暂停更新的晨报周报章节类型列表 // @Description 获取暂停更新的晨报周报章节类型列表 // @Success 200 {object} models.ReportListResp // @router /getStopDayWeekReportChapterTypeList [get] func (this *ReportController) GetStopDayWeekReportChapterTypeList() { 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 } br.Ret = 200 br.Success = true br.Msg = "获取成功" return } // MarkEditStatus // @Title 标记报告编辑状态 // @Description 标记报告编辑状态接口 // @Param request body request.MarkEditEnReport true "type json string" // @Success 200 标记成功 ;202 标记成功 // @router /mark [post] func (this *ReportController) MarkEditStatus() { 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 } var req models.MarkEditReport err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ReportId <= 0 { br.Msg = "缺少报告Id" return } if req.Status < 0 { br.Msg = "标记状态异常" return } //更新标记key data, err := services.UpdateReportEditMark(req.ReportId, req.ReportChapterId, sysUser.AdminId, req.Status, sysUser.RealName, this.Lang) if err != nil { br.Msg = err.Error() return } msg := "标记成功" br.Ret = 200 br.Success = true br.Msg = msg br.Data = data } // SendMsg // @Title 模板消息/客群消息推送接口 // @Description 模板消息/客群消息推送接口 // @Param request body models.SendTemplateMsgReq true "type json string" // @Success 200 {object} models.SendTemplateMsgResp // @router /sendMsg [post] func (this *ReportController) SendMsg() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.SendTemplateMsgReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ReportId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } // 加锁,避免重复点击造成的多次推送 { redisKey := fmt.Sprint("report:send:ths:", req.ReportId) ok := utils.Rc.SetNX(redisKey, 1, time.Second*300) if !ok { br.Msg = "报告已推送, 请勿重复推送" return } defer func() { _ = utils.Rc.Delete(redisKey) }() } reportInfo, e := models.GetReportByReportId(req.ReportId) if e != nil { br.Msg = "报告不存在或已被删除, 请刷新页面" br.ErrMsg = "获取报告失败, Err: " + e.Error() return } if reportInfo.MsgIsSend == 1 && reportInfo.ThsMsgIsSend == 1 { br.Msg = "消息已推送,请勿重复操作" br.ErrMsg = "消息已推送,请勿重复操作" return } // 更新报告发布时间 videoNameDate := `(` + time.Now().Format("0102") + `)` if err = models.UpdateReportPublishTime(req.ReportId, videoNameDate); err != nil { br.Msg = "修改报告发布时间失败" br.ErrMsg = "修改发布时间失败,Err:" + err.Error() return } if err = models.UpdateReportChapterPublishTime(req.ReportId, videoNameDate); err != nil { br.Msg = "修改章节发布时间失败" br.ErrMsg = "修改发布时间失败,Err:" + err.Error() return } // 可能存在历史数据两个只推了一个所以此处加个判断 // 推送模板消息 if reportInfo.MsgIsSend == 0 { go services.SendMiniProgramReportWxMsg(reportInfo.Id) } // 更新推送消息状态 reportInfo.MsgIsSend = 1 reportInfo.ThsMsgIsSend = 1 reportInfo.MsgSendTime = time.Now() reportInfo.ModifyTime = time.Now() err = reportInfo.UpdateReport([]string{"MsgIsSend", "ThsMsgIsSend", "MsgSendTime", "ModifyTime"}) if err != nil { br.Msg = "推送失败" br.ErrMsg = "更新报告消息状态失败, Err:" + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "推送成功" br.IsAddLog = true br.Data = models.SendTemplateMsgResp{ ReportId: reportInfo.Id, MsgSendTime: reportInfo.MsgSendTime.Format(utils.FormatDateTime), } } // CheckDayWeekReportChapterVideo // @Title 获取暂停更新的晨报周报章节类型列表 // @Description 获取暂停更新的晨报周报章节类型列表 // @Param ReportId query string true "报告ID" // @Success 200 {object} models.ReportListResp // @router /CheckDayWeekReportChapterVideo [get] func (this *ReportController) CheckDayWeekReportChapterVideo() { 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 } reqReportId := this.GetString("ReportId") reportId, _ := strconv.Atoi(reqReportId) if reportId <= 0 { br.Msg = "报告ID有误" return } // 获取章节列表 chapterList, err := models.GetChapterListByReportId(reportId) if err != nil { br.Msg = "获取章节列表失败" br.ErrMsg = "获取章节列表失败, Err: " + err.Error() return } typeNameArr := make([]string, 0) for _, v := range chapterList { if v.VideoUrl == "" || (v.VideoUrl != "" && v.VideoKind == 2) { typeNameArr = append(typeNameArr, v.TypeName) } } br.Ret = 200 br.Success = true br.Msg = "保存成功" br.Data = typeNameArr }