123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- // Package document_manage
- // @Author gmy 2024/9/19 14:09:00
- package document_manage
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/models/document_manage_model"
- "eta/eta_api/services/document_manage_service"
- "eta/eta_api/utils"
- "strings"
- )
- // DocumentManageController 文档管理库
- type DocumentManageController struct {
- controllers.BaseAuthController
- }
- // ValidateUser
- // 处理响应和校验
- func ValidateUser(this *DocumentManageController, br *models.BaseResponse) bool {
- // 验证用户是否已登录
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return false
- }
- return true
- }
- // DocumentClassifyList
- // @Title 文档分类列表
- // @Description 文档分类列表
- // @Success 200 {object} []models.ClassifyVO
- // @router /document/classify/list [get]
- func (this *DocumentManageController) DocumentClassifyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- if !ValidateUser(this, br) {
- return
- }
- classifyList, err := document_manage_service.DocumentClassifyList()
- if err != nil {
- br.Msg = "获取分类列表失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = classifyList
- return
- }
- // DocumentVarietyList
- // @Title 文档品种列表
- // @Description 文档品种列表
- // @Success 200 {object} []models.ChartPermission
- // @router /document/variety/list [get]
- func (this *DocumentManageController) DocumentVarietyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- if !ValidateUser(this, br) {
- return
- }
- chartPermissionList, err := document_manage_service.DocumentVarietyList()
- if err != nil {
- br.Msg = "获取品种列表失败"
- br.ErrMsg = "获取品种列表失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = chartPermissionList
- return
- }
- // DocumentReportList
- // @Title 文档管理库报告列表
- // @Description 文档管理库报告列表
- // @Success 200 {object} document_manage_model.OutsideReportPage
- // @router /document/report/list [get]
- func (this *DocumentManageController) DocumentReportList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- if !ValidateUser(this, br) {
- return
- }
- // 文档类型 1-文档管理库 2-战研中心-pci
- documentType, err := this.GetInt("DocumentType")
- if err != nil {
- br.Msg = "获取文档类型失败"
- br.ErrMsg = "获取文档类型失败,Err:" + err.Error()
- return
- }
- if documentType == 0 {
- br.Msg = "文档类型不能为空"
- br.ErrMsg = "文档类型不能为空"
- return
- }
- chartPermissionIdString := this.GetString("ChartPermissionIdList")
- var chartPermissionIdList []string
- if strings.TrimSpace(chartPermissionIdString) != "" {
- chartPermissionIdList = strings.Split(chartPermissionIdString, ",")
- }
- classifyIdString := this.GetString("ClassifyIdList")
- var classifyIdList []string
- if strings.TrimSpace(classifyIdString) != "" {
- classifyIdList = strings.Split(classifyIdString, ",")
- }
- keyword := this.GetString("Keyword")
- orderField := this.GetString("OrderField")
- orderType := this.GetString("OrderType")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- documentReportPage, err := document_manage_service.DocumentReportList(documentType, chartPermissionIdList, classifyIdList, keyword, orderField, orderType, currentIndex, pageSize)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = documentReportPage
- return
- }
- // RuiSiReportList
- // @Title 睿思报告列表
- // @Description 睿思报告列表
- // @Success 200 {object} models.ReportListResp
- // @router /document/rui/si/report/list [get]
- func (this *DocumentManageController) RuiSiReportList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- if !ValidateUser(this, br) {
- return
- }
- classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
- classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
- classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
- keyword := this.GetString("Keyword")
- orderField := this.GetString("OrderField")
- orderType := this.GetString("OrderType")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- RuiSiReportPage, err := document_manage_service.RuiSiReportList(classifyIdFirst, classifyIdSecond, classifyIdThird, keyword, orderField, orderType, currentIndex, pageSize)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = RuiSiReportPage
- return
- }
- // DocumentRuiSiDetail
- // @Title 睿思报告详情
- // @Description 睿思报告详情
- // @Success 200 “获取成功”
- // @router /document/rui/si/detail [get]
- func (this *DocumentManageController) DocumentRuiSiDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- if !ValidateUser(this, br) {
- return
- }
- // 获取指标数据列表
- this.GetString("DocumentRuiSiDetail")
- reportId, err := this.GetInt("ReportId")
- if err != nil {
- br.Msg = "获取报告ID失败"
- br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
- return
- }
- reportDetail, err := document_manage_service.DocumentRuiSiDetail(reportId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "报告已被删除"
- return
- }
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = &reportDetail
- return
- }
- // DocumentSave
- // @Title 新建文档
- // @Description 新建文档
- // @Success 200 “操作成功”
- // @router /document/save [post]
- func (this *DocumentManageController) DocumentSave() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- if !ValidateUser(this, br) {
- return
- }
- sysUser := this.SysUser
- var req *document_manage_model.OutsideReportBO
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- req.SysUserId = sysUser.AdminId
- req.SysUserName = sysUser.RealName
- err := document_manage_service.DocumentSave(req)
- if err != nil {
- br.Msg = "保存文档失败"
- br.ErrMsg = "保存文档失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- // DocumentDetail
- // @Title 文档详情
- // @Description 文档详情
- // @Success 200 “操作成功”
- // @router /document/detail [get]
- func (this *DocumentManageController) DocumentDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- if !ValidateUser(this, br) {
- return
- }
- // 获取指标数据列表
- outsideReportId, err := this.GetInt("OutsideReportId")
- if err != nil {
- br.Msg = "获取报告ID失败"
- br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
- return
- }
- reportDetail, err := document_manage_service.DocumentReportDetail(outsideReportId)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = &reportDetail
- return
- }
- // DocumentUpdate
- // @Title 编辑文档
- // @Description 编辑文档
- // @Success 200 “操作成功”
- // @router /document/update [post]
- func (this *DocumentManageController) DocumentUpdate() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- if !ValidateUser(this, br) {
- return
- }
- var req *document_manage_model.OutsideReportBO
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- err := document_manage_service.DocumentUpdate(req)
- if err != nil {
- br.Msg = "修改文档失败"
- br.ErrMsg = "修改文档失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- // DocumentDelete
- // @Title 删除文档
- // @Description 删除文档
- // @Success 200 “操作成功”
- // @router /document/delete [post]
- func (this *DocumentManageController) DocumentDelete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- if !ValidateUser(this, br) {
- return
- }
- type DocumentDelete struct {
- OutsideReportId int `json:"OutsideReportId"`
- }
- var req *DocumentDelete
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- err := document_manage_service.DocumentDelete(req.OutsideReportId)
- if err != nil {
- br.Msg = "删除文档失败"
- br.ErrMsg = "删除文档失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
|