123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443 |
- package controllers
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/report"
- "eta_gn/eta_api/models/smart_report"
- "eta_gn/eta_api/services"
- "eta_gn/eta_api/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- "html"
- "time"
- )
- // ReportHistoryController 报告
- type ReportHistoryController struct {
- BaseAuthController
- }
- // List
- // @Title 获取报告列表接口
- // @Description 获取报告列表
- // @Param ReportId query int true "报告ID"
- // @Param ReportChapterId query int true "报告ID"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} models.ReportListResp
- // @router /list [get]
- func (this *ReportHistoryController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- reportId, _ := this.GetInt("ReportId")
- reportChapterId, _ := this.GetInt("ReportChapterId")
- isShowMe, _ := this.GetBool("IsShowMe")
- if reportId <= 0 && reportChapterId <= 0 {
- br.Msg = "请选择报告"
- br.ErrMsg = "请选择报告"
- return
- }
- 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 reportId > 0 {
- condition += ` AND report_id = ? `
- pars = append(pars, reportId)
- }
- if reportChapterId > 0 {
- condition += ` AND report_chapter_id = ? `
- pars = append(pars, reportChapterId)
- }
- if isShowMe {
- condition += ` AND admin_id = ? `
- pars = append(pars, this.SysUser.AdminId)
- }
- var err error
- var total int
- var list []*models.ReportHistoryListItem
- historyObj := new(models.ReportHistory)
- total, err = historyObj.GetPageListCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- listTmp, err := historyObj.GetNoContentPageList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, item := range listTmp {
- tmp := new(models.ReportHistoryListItem)
- tmp.Id = item.Id
- tmp.ReportId = item.ReportId
- tmp.ReportChapterId = item.ReportChapterId
- tmp.CreateTime = item.CreateTime.Format(utils.FormatDateTime)
- tmp.AdminId = item.AdminId
- tmp.AdminName = item.AdminName
- tmp.Title = item.Title
- list = append(list, tmp)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.ReportHistoryListResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Delete
- // @Title 删除版本
- // @Description 删除版本
- // @Param Id query int true "版本ID"
- // @Success 200 {object} models.ReportListResp
- // @router /del [post]
- func (this *ReportHistoryController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DeleteReportHistoryReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Id <= 0 {
- br.Msg = "请选择报告版本"
- return
- }
- historyObj := new(models.ReportHistory)
- item, err := historyObj.GetById(req.Id)
- if err != nil {
- br.Msg = "该版本已删除"
- return
- }
- err = item.Delete()
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // Detail
- // @Title 获取报告历史版本详情接口
- // @Description 获取报告详情
- // @Param request body models.ReportDetailReq true "type json string"
- // @Success 200 {object} models.Report
- // @router /detail [get]
- func (this *ReportHistoryController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- id, _ := this.GetInt("Id")
- if id <= 0 {
- br.Msg = "请选择报告版本"
- return
- }
- historyObj := new(models.ReportHistory)
- history, err := historyObj.GetById(id)
- if err != nil {
- br.Msg = "该版本已删除"
- return
- }
- reportId := history.ReportId
- reportChapterId := history.ReportChapterId
- reportInfo, err := models.GetReportById(reportId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "报告已被删除"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- chapterList := make([]*models.ReportChapter, 0)
- if reportInfo.HasChapter == 1 && reportChapterId > 0 {
- chapter, e := models.GetReportChapterInfoById(reportChapterId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "章节已删除"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + e.Error()
- return
- }
- chapter.Content = html.UnescapeString(history.Content)
- chapter.ContentSub = html.UnescapeString(history.ContentSub)
- chapter.ContentStruct = html.UnescapeString(history.ContentStruct)
- chapter.LastModifyAdminName = history.AdminName
- chapter.ContentModifyTime = history.CreateTime
- chapter.LastModifyAdminId = history.AdminId
- chapterList = append(chapterList, chapter)
- } else {
- reportInfo.Title = history.Title
- reportInfo.Content = html.UnescapeString(history.Content)
- reportInfo.ContentSub = html.UnescapeString(history.ContentSub)
- reportInfo.ContentStruct = html.UnescapeString(history.ContentStruct)
- reportInfo.CanvasColor = history.CanvasColor
- reportInfo.LastModifyAdminName = history.AdminName
- reportInfo.LastModifyAdminId = history.AdminId
- reportInfo.ContentModifyTime = history.CreateTime.Format(utils.FormatDate)
- }
- if history.HeadResourceId > 0 {
- headResource, err := smart_report.GetResourceItemById(history.HeadResourceId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
- return
- }
- reportInfo.HeadImg = headResource.ImgUrl
- reportInfo.HeadStyle = headResource.Style
- } else {
- reportInfo.HeadImg = ""
- reportInfo.HeadStyle = ""
- }
- if history.EndResourceId > 0 {
- endResource, err := smart_report.GetResourceItemById(history.EndResourceId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
- return
- }
- reportInfo.EndImg = endResource.ImgUrl
- reportInfo.EndStyle = endResource.Style
- } else {
- reportInfo.EndImg = ""
- reportInfo.EndStyle = ""
- }
- resp := &models.ReportDetailView{
- ReportDetail: reportInfo,
- ChapterList: chapterList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Revert
- // @Title 恢复报告内容
- // @Description 恢复报告内容
- // @Param Id query int true "版本ID"
- // @Success 200 {object} models.ReportListResp
- // @router /revert [post]
- func (this *ReportHistoryController) Revert() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DeleteReportHistoryReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Id <= 0 {
- br.Msg = "请选择报告版本"
- return
- }
- historyObj := new(models.ReportHistory)
- history, err := historyObj.GetById(req.Id)
- if err != nil {
- br.Msg = "该版本已删除"
- return
- }
- // 获取报告详情
- reportInfo, err := models.GetReportByReportId(history.ReportId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "报告已删除"
- return
- }
- br.Msg = "获取报告失败"
- br.ErrMsg = "获取报告失败,Err:" + err.Error()
- return
- }
- if reportInfo.Id > 0 && reportInfo.State == 2 {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- br.IsSendEmail = false
- return
- }
- // 恢复章节
- if history.ReportChapterId > 0 {
- // 如果不是创建人,那么就要去查看是否授权
- reportChapterInfo, e := models.GetReportChapterInfoById(history.ReportChapterId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- br.Msg = "章节已删除"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + e.Error()
- return
- }
- if reportInfo.AdminId != this.SysUser.AdminId {
- // 授权用户权限校验
- chapterGrantObj := report.ReportChapterGrant{}
- _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(reportChapterInfo.ReportChapterId, this.SysUser.AdminId)
- if tmpErr != nil {
- if utils.IsErrNoRow(tmpErr) {
- br.Msg = "没有权限"
- br.ErrMsg = "没有权限"
- br.IsSendEmail = false
- return
- }
- br.Msg = "获取章节id授权用户失败"
- br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
- return
- }
- }
- // 标记更新中
- {
- markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, this.SysUser.AdminId, 1, this.SysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- br.IsSendEmail = false
- return
- }
- }
- reportChapterInfo.Title = history.Title
- reportChapterInfo.Content = history.Content
- reportChapterInfo.ContentSub = history.ContentSub
- reportChapterInfo.IsEdit = 1
- reportChapterInfo.ModifyTime = time.Now()
- reportChapterInfo.LastModifyAdminId = this.SysUser.AdminId
- reportChapterInfo.LastModifyAdminName = this.SysUser.RealName
- reportChapterInfo.ContentModifyTime = time.Now()
- reportChapterInfo.ContentStruct = history.ContentStruct
- updateCols := make([]string, 0)
- updateCols = append(updateCols, "Title", "Content", "ContentSub", "IsEdit", "ModifyTime")
- updateCols = append(updateCols, "LastModifyAdminId", "LastModifyAdminName", "ContentModifyTime", "ContentStruct")
- err = reportChapterInfo.Update(updateCols)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- } else {
- // 标记更新中
- {
- markStatus, err := services.UpdateReportEditMark(history.ReportId, 0, this.SysUser.AdminId, 1, this.SysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- return
- }
- }
- if history.HeadResourceId > 0 {
- headResource, err := smart_report.GetResourceItemById(history.HeadResourceId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
- return
- }
- reportInfo.HeadImg = headResource.ImgUrl
- } else {
- reportInfo.HeadImg = ""
- }
- if history.EndResourceId > 0 {
- endResource, err := smart_report.GetResourceItemById(history.EndResourceId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
- return
- }
- reportInfo.EndImg = endResource.ImgUrl
- } else {
- reportInfo.EndImg = ""
- }
- // 恢复报告
- // todo 标题是否需要恢复
- reportInfo.Title = history.Title
- reportInfo.Content = history.Content
- reportInfo.ContentSub = history.ContentSub
- reportInfo.ContentStruct = history.ContentStruct
- reportInfo.CanvasColor = history.CanvasColor
- reportInfo.HeadResourceId = history.HeadResourceId
- reportInfo.EndResourceId = history.EndResourceId
- reportInfo.ModifyTime = time.Now()
- reportInfo.ContentModifyTime = time.Now()
- updateCols := []string{"Title", "Content", "ContentSub", "ContentStruct", "HeadImg", "EndImg", "CanvasColor", "HeadResourceId", "EndResourceId", "ModifyTime", "ContentModifyTime"}
- err = reportInfo.UpdateReport(updateCols)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- }
- // 报告的最后编辑人
- reportInfo.LastModifyAdminId = this.SysUser.AdminId
- reportInfo.LastModifyAdminName = this.SysUser.RealName
- reportInfo.ModifyTime = time.Now()
- err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|