123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846 |
- package controllers
- import (
- "encoding/json"
- "eta_gn/eta_report/models"
- "eta_gn/eta_report/services"
- "eta_gn/eta_report/services/knowledge"
- "eta_gn/eta_report/utils"
- "fmt"
- "strconv"
- "strings"
- "time"
- )
- // ReportOpenController 报告开放接口
- type ReportOpenController struct {
- BaseOpenController
- }
- // ClassifyTree
- // @Title 报告分类
- // @Description 报告分类接口
- // @Param ClassifyType query int false "分类类型:0-全部(不传默认为0);1-研报;2-PPT"
- // @Param OutId query string false "用户工号Id"
- // @Success 200 {object} models.ClassifyTreeItem
- // @router /report/classify [get]
- func (this *ReportOpenController) ClassifyTree() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyType, _ := this.GetInt("ClassifyType", 0)
- outId := this.GetString("OutId")
- if classifyType < 0 || classifyType > 2 {
- classifyType = 0
- }
- // 获取分类列表, 格式化分类树
- classifyOb := new(models.Classify)
- cond := ``
- pars := make([]interface{}, 0)
- if classifyType > 0 {
- cond += ` AND classify_type = ?`
- pars = append(pars, classifyType)
- }
- classifyList, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "parent_id ASC, sort ASC, create_time ASC")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取分类列表失败,%v", e)
- return
- }
- if outId == "" {
- br.Msg = "工号不能为空"
- return
- }
- list := make([]*models.Classify, 0)
- classifyObj := new(models.ClassifyVisible)
- visibleUsers, err := classifyObj.GetClassifyVisibleAll()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取可见用户失败,%v", err)
- return
- }
- adminObj := new(models.Admin)
- admin, e := adminObj.GetAdminByOutId(outId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- br.Msg = "工号不存在"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取管理员信息失败,%v", e)
- return
- }
- visibleUsersMap := make(map[int][]int)
- for _, v := range visibleUsers {
- visibleUsersMap[v.ClassifyId] = append(visibleUsersMap[v.ClassifyId], v.AdminId)
- }
- for _, v := range classifyList {
- if visibleUser, ok := visibleUsersMap[v.Id]; ok {
- if !utils.InArrayByInt(visibleUser, admin.AdminId) {
- continue
- }
- }
- list = append(list, v)
- }
- resp := services.GetReportClassifyTreeRecursive(list, 0)
- resp = services.RecursiveFilterNoChildTreeClassify(resp)
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // ReportCreate
- // @Title 生成报告
- // @Description 生成报告接口
- // @Param request body models.ReportCreateReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /report/create [post]
- func (this *ReportOpenController) ReportCreate() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.ReportCreateReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常"
- br.ErrMsg = fmt.Sprintf("参数解析失败,%v", e)
- return
- }
- if req.ReportId <= 0 {
- br.Msg = "报告ID有误"
- br.ErrMsg = fmt.Sprintf("智力共享报告ID有误, %d", req.ReportId)
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- req.Title = strings.TrimSpace(req.Title)
- if req.Title == "" {
- br.Msg = "请输入报告标题"
- return
- }
- req.EndTime = strings.TrimSpace(req.EndTime)
- if req.EndTime == "" {
- br.Msg = "请输入课题结束时间"
- return
- }
- topicTime, e := time.ParseInLocation(utils.FormatDateTime, req.EndTime, time.Local)
- if e != nil {
- br.Msg = "课题结束时间格式有误"
- return
- }
- req.Creator = strings.TrimSpace(req.Creator)
- if req.Creator == "" {
- br.Msg = "请输入创建人工号"
- return
- }
- // 查询分类,根据分类创建对应类型的研报
- classifyOb := new(models.Classify)
- classify, e := classifyOb.GetItemById(req.ClassifyId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- br.Msg = "分类不存在"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
- return
- }
- // 校验报告ID是否已存在, 已存在返回已有的报告ID
- reportExist, pptExist := services.GetReportByOutReportId(req.ReportId)
- if reportExist != nil && reportExist.Id > 0 {
- resp := new(models.ReportCreateResp)
- resp.ReportId = reportExist.Id
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- if pptExist != nil && pptExist.PptId > 0 {
- resp := new(models.ReportCreateResp)
- resp.ReportId = pptExist.PptId
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- // 研报类型
- var reportId int
- if classify.ClassifyType == utils.ReportTypeDefault {
- reportId, e = services.CreateReport(req.ReportId, req.ClassifyId, req.Title, topicTime, req.Creator, req.Authors)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("新增报告失败, %v", e)
- return
- }
- }
- // PPT类型
- if classify.ClassifyType == utils.ReportTypePPT {
- reportId, e = services.CreatePptReport(req.ReportId, req.ClassifyId, req.Title, topicTime, req.Creator, req.Authors)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("新增PPT报告失败, %v", e)
- return
- }
- }
- resp := new(models.ReportCreateResp)
- resp.ReportId = reportId
- //resp.ReportCode = reportCode
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // ReportModify
- // @Title 编辑报告
- // @Description 编辑报告接口
- // @Param request body models.ReportModifyReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /report/modify [post]
- func (this *ReportOpenController) ReportModify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.ReportModifyReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常"
- br.ErrMsg = fmt.Sprintf("参数解析失败,%v", e)
- return
- }
- if req.ReportId <= 0 {
- br.Msg = "报告ID有误"
- br.ErrMsg = fmt.Sprintf("智力共享报告ID有误, %d", req.ReportId)
- return
- }
- req.Title = strings.TrimSpace(req.Title)
- if req.Title == "" {
- br.Msg = "请输入报告标题"
- return
- }
- req.EndTime = strings.TrimSpace(req.EndTime)
- if req.EndTime == "" {
- br.Msg = "请输入课题结束时间"
- return
- }
- topicTime, e := time.ParseInLocation(utils.FormatDateTime, req.EndTime, time.Local)
- if e != nil {
- br.Msg = "课题结束时间格式有误"
- return
- }
- reportExist, pptExist := services.GetReportByOutReportId(req.ReportId)
- if reportExist == nil && pptExist == nil {
- br.Msg = "报告不存在"
- br.ErrMsg = fmt.Sprintf("报告不存在, OutReportId: %d", req.ReportId)
- return
- }
- // 研报类型
- if reportExist != nil && reportExist.Id > 0 {
- if reportExist.State == models.ReportStatePass {
- br.Msg = "报告已发布,不可编辑"
- return
- }
- if e = services.EditReport(reportExist, req.Title, topicTime, req.Authors); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("编辑报告失败, %v", e)
- return
- }
- }
- // PPT类型
- if pptExist != nil && pptExist.PptId > 0 {
- if pptExist.State == models.ReportStatePass {
- br.Msg = "报告已发布,不可编辑"
- return
- }
- if e = services.EditPptReport(pptExist, req.Title, topicTime, req.Authors); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("编辑PPT报告失败, %v", e)
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // ReportApprove
- // @Title 审批报告
- // @Description 审批报告接口
- // @Param request body models.ReportApproveReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /report/approve [post]
- func (this *ReportOpenController) ReportApprove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.ReportApproveReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常"
- br.ErrMsg = fmt.Sprintf("参数解析失败,%v", e)
- return
- }
- if len(req.ReportIds) == 0 {
- br.Msg = "报告ID有误"
- br.ErrMsg = fmt.Sprintf("智力共享报告ID有误, %v", req.ReportIds)
- return
- }
- if req.ApproveType != 1 && req.ApproveType != 2 && req.ApproveType != 3 && req.ApproveType != 4 {
- br.Msg = "审批类型异常"
- br.ErrMsg = fmt.Sprintf("审批类型异常, %d", req.ApproveType)
- return
- }
- // 先做校验后执行, 报告很可能是研报和PPT类型混着一起审批的
- updateReports := make([]*models.Report, 0)
- updatePpts := make([]*models.PptV2, 0)
- for _, v := range req.ReportIds {
- reportExist, pptExist := services.GetReportByOutReportId(v)
- if reportExist == nil && pptExist == nil {
- utils.FileLog.Info(fmt.Sprintf("ReportApprove-报告ID: %d不存在", v))
- continue
- }
- // 通过和驳回需要审批中/已驳回状态,撤回、提审暂不做限制(若报告未撰写完毕,提审会把状态从待提交直接变为待审批,那么就是撰写终止附件不会再传回去了,这种情况是允许的)
- if reportExist != nil && reportExist.Id > 0 {
- if (req.ApproveType == 1 || req.ApproveType == 2) && reportExist.State != models.ReportStateWaitApprove && reportExist.State != models.ReportStateRefused {
- utils.FileLog.Info(fmt.Sprintf("ReportApprove-报告当前状态不允许审批, OutId: %d, State: %d", v, reportExist.State))
- continue
- }
- updateReports = append(updateReports, reportExist)
- }
- if pptExist != nil && pptExist.PptId > 0 {
- if (req.ApproveType == 1 || req.ApproveType == 2) && pptExist.State != models.ReportStateWaitApprove && pptExist.State != models.ReportStateRefused {
- utils.FileLog.Info(fmt.Sprintf("ReportApprove-PPT当前状态不允许审批, OutId: %d, State: %d", v, pptExist.State))
- continue
- }
- updatePpts = append(updatePpts, pptExist)
- }
- }
- // 审批人
- approveUser := new(models.Admin)
- {
- ob := new(models.Admin)
- cond := ` AND out_id = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, req.ApproveUser)
- admin, e := ob.GetItemByCondition(cond, pars, "")
- if e != nil && !utils.IsErrNoRow(e) {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("获取审批人信息失败, %v", e)
- return
- }
- if admin != nil && admin.AdminId > 0 {
- approveUser = admin
- }
- }
- if approveUser.AdminId == 0 {
- utils.FileLog.Info(fmt.Sprintf("ReportApprove-无审批人信息, OutId: %s", req.ApproveUser))
- }
- reportMessages := make([]*models.ReportMessage, 0)
- afterApproveMap := map[int]int{
- 1: models.ReportStatePass,
- 2: models.ReportStateRefused,
- 3: models.ReportStateWaitSubmit,
- 4: models.ReportStateWaitApprove,
- }
- if len(updateReports) > 0 {
- for _, v := range updateReports {
- updateCols := []string{"State", "ModifyTime"}
- v.State = afterApproveMap[req.ApproveType]
- v.ModifyTime = time.Now()
- if v.State == models.ReportStatePass || v.State == models.ReportStateRefused {
- v.ApproveTime = time.Now()
- updateCols = append(updateCols, "ApproveTime")
- }
- if e := v.Update(updateCols); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("更新报告状态失败, %v", e)
- return
- }
- if req.ApproveType == 1 {
- // 审批通过,将PPT或研报加入报告库中
- go func() {
- msg, err := knowledge.ReportKnowledgeResourceAdd(v.Title, []string{v.DetailPdfUrl}, v.AdminId, v.AdminRealName, "市场研究报告/内部报告/日常报告", "市场信息研究所", time.Now())
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("ReportKnowledgeResourceAdd-报告知识资源库添加失败,reportId:%d,msg:%s,err: %v", v.Id, msg, err))
- return
- }
- }()
- go func() {
- // 审批通过,将摘要加入知识资源库观点中
- var classifyId int
- if v.ClassifyIdThird > 0 {
- classifyId = v.ClassifyIdThird
- } else if v.ClassifyIdSecond > 0 {
- classifyId = v.ClassifyIdSecond
- } else {
- classifyId = v.ClassifyIdFirst
- }
- v.Abstract = strings.TrimSpace(v.Abstract)
- if v.Abstract == "" {
- return
- }
- classifyId, err := knowledge.ReportKnowledgeResourceClassifyCheckAndSave(classifyId)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("ReportKnowledgeResourceClassifyCheckAndSave-报告分类保存失败,reportId:%d,classifyId:%d,err: %v", v.Id, classifyId, err))
- return
- }
- msg, err := knowledge.ViewPointSave(0, v.AdminId, v.AdminRealName, v.Title, v.Abstract, "市场信息研究所", "", classifyId, &v.ApproveTime)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("ViewPointSave-报告摘要知识资源库添加失败,reportId:%d,msg:%s,err: %v", v.Id, msg, err))
- return
- }
- }()
- }
- if req.ApproveType == 3 || req.ApproveType == 4 {
- // 撤回/提审暂不发消息
- continue
- }
- // 创作人和协作人
- userIds := make([]int, 0)
- userIds = append(userIds, v.AdminId)
- {
- grantOb := new(models.ReportGrant)
- grantCond := ` AND report_id = ?`
- grantPars := make([]interface{}, 0)
- grantPars = append(grantPars, v.Id)
- grants, e := grantOb.GetItemsByCondition(grantCond, grantPars, []string{"admin_id"}, "")
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("获取报告协作人失败, %v", e)
- return
- }
- for _, v := range grants {
- if utils.InArrayByInt(userIds, v.AdminId) {
- continue
- }
- userIds = append(userIds, v.AdminId)
- }
- }
- // 发送系统消息给创建人和协作人
- var messageType int
- var tips string
- var extraContent string
- if v.State == models.ReportStatePass {
- messageType = models.ReportMessageTypeApprovePass
- tips = "已通过审批!"
- }
- if v.State == models.ReportStateRefused {
- messageType = models.ReportMessageTypeApproveRefuse
- tips = "已被驳回,点击查看详情!"
- // 审批详情信息
- var extra models.ReportMessageApproveItem
- extra.Title = v.Title
- extra.ApproveType = 2
- extra.ApproveUserId = approveUser.AdminId
- extra.ApproveUserName = approveUser.RealName
- extra.ApproveRemark = req.Suggestion
- b, e := json.Marshal(extra)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("消息通知-审批信息JSON格式化失败, %v", e)
- return
- }
- extraContent = string(b)
- }
- for _, u := range userIds {
- m := new(models.ReportMessage)
- m.SendUserId = approveUser.AdminId
- m.ReceiveUserId = u
- m.Content = fmt.Sprintf("您提交的【%s】%s", v.Title, tips)
- m.ExtraContent = extraContent
- m.ReportType = utils.ReportTypeDefault
- m.ReportId = v.Id
- m.MessageType = messageType
- m.CreateTime = time.Now()
- m.ModifyTime = time.Now()
- reportMessages = append(reportMessages, m)
- }
- }
- }
- if len(updatePpts) > 0 {
- for _, v := range updatePpts {
- updateCols := []string{"State", "ModifyTime"}
- v.State = afterApproveMap[req.ApproveType]
- v.ModifyTime = time.Now()
- if v.State == models.ReportStatePass || v.State == models.ReportStateRefused {
- v.ApproveTime = time.Now()
- updateCols = append(updateCols, "ApproveTime")
- }
- if e := v.Update(updateCols); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("更新报告状态失败, %v", e)
- return
- }
- if req.ApproveType == 1 {
- // 审批通过,将PPT或研报加入报告库中
- go func() {
- msg, err := knowledge.ReportKnowledgeResourceAdd(v.Title, []string{v.PptxUrl}, v.AdminId, v.AdminRealName, "市场研究报告/内部报告/日常报告", "市场信息研究所", time.Now())
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("ReportKnowledgeResourceAdd-PPT知识资源报告库添加失败,pptId:%d,msg:%s,err: %v", v.PptId, msg, err))
- return
- }
- }()
- go func() {
- // 审批通过,将摘要加入知识资源库观点中
- v.Abstract = strings.TrimSpace(v.Abstract)
- if v.Abstract == "" {
- return
- }
- classifyId, err := knowledge.ReportKnowledgeResourceClassifyCheckAndSave(v.ClassifyId)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("ReportKnowledgeResourceClassifyCheckAndSave-PPT分类保存失败,pptId:%d,classifyId:%d,err: %v", v.PptId, v.ClassifyId, err))
- return
- }
- msg, err := knowledge.ViewPointSave(0, v.AdminId, v.AdminRealName, v.Title, v.Abstract, "市场信息研究所", "", classifyId, &v.ApproveTime)
- if err != nil {
- utils.FileLog.Error(fmt.Sprintf("ViewPointSave-ppt摘要知识库添加失败,pptId:%d,msg:%s,err: %v", v.PptId, msg, err))
- return
- }
- }()
- }
- if req.ApproveType == 3 || req.ApproveType == 4 {
- // 撤回/提审暂不发消息
- continue
- }
- // 创建人和协作人
- userIds := make([]int, 0)
- userIds = append(userIds, v.AdminId)
- if v.CollaborateUsers != "" {
- partnerArr := strings.Split(v.CollaborateUsers, ",")
- for _, p := range partnerArr {
- uid, _ := strconv.Atoi(p)
- if uid > 0 && !utils.InArrayByInt(userIds, uid) {
- userIds = append(userIds, uid)
- }
- }
- }
- // 发送系统消息给创建人和协作人
- var messageType int
- var tips string
- var extraContent string
- if v.State == models.ReportStatePass {
- messageType = models.ReportMessageTypeApprovePass
- tips = "已通过审批!"
- }
- if v.State == models.ReportStateRefused {
- messageType = models.ReportMessageTypeApproveRefuse
- tips = "已被驳回,点击查看详情!"
- // 审批详情信息
- var extra models.ReportMessageApproveItem
- extra.Title = v.Title
- extra.ApproveType = 2
- extra.ApproveUserId = approveUser.AdminId
- extra.ApproveUserName = approveUser.RealName
- extra.ApproveRemark = req.Suggestion
- b, e := json.Marshal(extra)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("消息通知-审批信息JSON格式化失败, %v", e)
- return
- }
- extraContent = string(b)
- }
- for _, u := range userIds {
- m := new(models.ReportMessage)
- m.SendUserId = approveUser.AdminId
- m.ReceiveUserId = u
- m.Content = fmt.Sprintf("您提交的【%s】%s", v.Title, tips)
- m.ExtraContent = extraContent
- m.ReportType = utils.ReportTypePPT
- m.ReportId = v.PptId
- m.MessageType = messageType
- m.CreateTime = time.Now()
- m.ModifyTime = time.Now()
- reportMessages = append(reportMessages, m)
- }
- }
- }
- // 消息通知
- if len(reportMessages) > 0 {
- messageOb := new(models.ReportMessage)
- if e := messageOb.CreateMulti(reportMessages); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("批量新增报告消息失败, %v", e)
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // ReportRemove
- // @Title 删除报告
- // @Description 删除报告接口
- // @Param request body models.ReportRemoveReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /report/remove [post]
- func (this *ReportOpenController) ReportRemove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.ReportRemoveReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常"
- br.ErrMsg = fmt.Sprintf("参数解析失败,%v", e)
- return
- }
- if len(req.ReportIds) == 0 {
- br.Msg = "报告ID有误"
- br.ErrMsg = fmt.Sprintf("智力共享报告ID有误, %v", req.ReportIds)
- return
- }
- // TODO:(可选优化)若报告的状态是已审批状态,那么把OutReportId置空,不做物理删除
- for _, v := range req.ReportIds {
- reportExist, pptExist := services.GetReportByOutReportId(v)
- // 不存在忽略即可
- if reportExist == nil && pptExist == nil {
- continue
- }
- // 研报类型
- if reportExist != nil && reportExist.Id > 0 {
- if e := reportExist.Remove(); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("删除报告失败, %v", e)
- return
- }
- }
- // PPT类型
- if pptExist != nil && pptExist.PptId > 0 {
- if e := pptExist.Remove(); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("删除PPT报告失败, %v", e)
- return
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // ViewPointSave
- // @Title 观点保存
- // @Description 观点保存
- // @Param request body models.ReportViewPointReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /viewpoint/save [post]
- func (this *ReportOpenController) ViewPointSave() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req *models.ReportViewPointSaveReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常"
- br.ErrMsg = fmt.Sprintf("参数解析失败,%v", e)
- return
- }
- req.Content = strings.TrimSpace(req.Content)
- req.Title = strings.TrimSpace(req.Title)
- req.Category = strings.TrimSpace(req.Category)
- if req.Title == "" {
- br.Msg = "观点标题不能为空"
- return
- }
- if req.Content == "" {
- br.Msg = "观点内容不能为空"
- return
- }
- if req.Category == "" {
- br.Msg = "观点分类不能为空"
- return
- }
- if req.DataDate == "" {
- br.Msg = "观点日期不能为空"
- return
- }
- dataDate, err := time.ParseInLocation(utils.FormatDateTime, req.DataDate, time.Local)
- if err != nil {
- br.Msg = "观点日期格式不正确"
- return
- }
- msg, err := knowledge.ViewPointSave(req.Id, 0, "", req.Title, req.Content, req.DataSource, req.Category, 0, &dataDate)
- if err != nil {
- if msg == "" {
- msg = "保存观点失败"
- }
- br.Msg = msg
- br.ErrMsg = fmt.Sprintf("保存观点失败, %v", err)
- return
- }
- br.Msg = "保存观点成功"
- br.Success = true
- br.Ret = 200
- }
- // @Title 观点删除
- // @Description 观点删除
- // @Param request body models.ReportViewPointReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /viewpoint/delete [post]
- func (this *ReportOpenController) ViewPointDelete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req *models.ReportViewPointDeleteRep
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常"
- br.ErrMsg = fmt.Sprintf("参数解析失败,%v", e)
- return
- }
- if req.Id == nil {
- br.Msg = "观点ID不能为空"
- return
- }
- obj := new(models.KnowledgeResource)
- obj, err := obj.GetKnowledgeResourceByOutId(*req.Id)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "观点不存在"
- return
- }
- br.Msg = "删除观点失败"
- br.ErrMsg = fmt.Sprintf("删除观点失败, %v", err)
- return
- }
- obj.IsDelete = 1
- if err = obj.Update([]string{"IsDelete"}); err != nil {
- br.Msg = "删除观点失败"
- br.ErrMsg = fmt.Sprintf("删除观点失败, %v", err)
- return
- }
- updateMap := map[string]interface{}{
- "IsDelete": "1",
- }
- err = knowledge.UpdateEsKnowledgeResource(obj.KnowledgeResourceId, updateMap)
- if err != nil {
- br.Msg = "删除观点失败"
- br.ErrMsg = fmt.Sprintf("es删除观点失败, %v", err)
- return
- }
- br.Msg = "删除观点成功"
- br.Success = true
- br.Ret = 200
- }
- // @Title 知识资源报告库上传
- // @Description 知识资源报告库上传
- // @Param request body string/int true/false "Description"
- // @Success 200 string "操作成功"
- // @router /report/knowledge/upload [post]
- func (this *ReportOpenController) ReportKnowledgeUpload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.ReportKnowledgeUploadRep
- if e := this.BindForm(&req); e != nil {
- br.Msg = "参数解析异常"
- br.ErrMsg = fmt.Sprintf("参数解析失败,%v", e)
- return
- }
- pushTime, err := time.Parse(utils.FormatDateTime, req.PushTime)
- if err != nil {
- br.Msg = "发布时间格式不正确"
- return
- }
- fileUrls, msg, err := knowledge.UploadFormFile(this.Ctx.Request.MultipartForm.File)
- if err != nil {
- if msg == "" {
- msg = "上传失败"
- }
- br.Msg = msg
- br.ErrMsg = fmt.Sprintf("上传失败, %v", err)
- return
- }
- msg, err = knowledge.ReportKnowledgeResourceAdd(req.Title, fileUrls, 0, "", req.ClassifyPath, req.Source, pushTime)
- if err != nil {
- if msg == "" {
- msg = "保存失败"
- }
- br.Msg = msg
- br.ErrMsg = fmt.Sprintf("保存失败, %v", err)
- return
- }
- br.Ret = 200
- br.Msg = "上传成功"
- br.Success = true
- }
|