123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527 |
- package knowledge
- import (
- "encoding/json"
- "eta_gn/eta_api/controllers"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/knowledge"
- "eta_gn/eta_api/services"
- knowledgeServ "eta_gn/eta_api/services/knowledge"
- "eta_gn/eta_api/utils"
- "fmt"
- "html"
- "io/ioutil"
- "os"
- "path"
- "strconv"
- "strings"
- "time"
- "github.com/h2non/filetype"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/tealeg/xlsx"
- )
- // 分类
- type ResourceController struct {
- controllers.BaseAuthController
- }
- // ListReport
- // @Title 获取事件列表接口
- // @Description 获取事件列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param TimeType query string true "筛选的时间类别:publish_time(发布时间),modify_time(更新时间);approve_time(审批时间)"
- // @Param StartDate query string true "开始时间"
- // @Param EndDate query string true "结束时间"
- // @Param Frequency query string true "频度"
- // @Param ClassifyIds query int true "分类id, 多选, 英文逗号分隔"
- // @Param State query int true "状态"
- // @Param KeyWord query string true "搜索关键词"
- // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
- // @Param FilterReportType query string true "筛选事件类型,1:公共研报,2:共享研报,3:我的研报"
- // @Param IncludeFile query string true "是否包含文件, no:不包含"
- // @Param SourceFrom query string true "来源, 用英文逗号分隔"
- // @Param IsShowMe query string true "只看我, false:全部, true:只看我"
- // @Success 200 {object} knowledge.KnowledgeResourceListResp
- // @router /resource/list [get]
- func (this *ResourceController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- classifyIds := this.GetString("ClassifyIds")
- // 添加人
- addUserIds, _ := this.GetInt("SysUserIds")
- // 标签
- tagIds := this.GetString("TagIds")
- keyWord := this.GetString("Keyword")
- resourceType, _ := this.GetInt("ResourceType")
- sourceFrom := this.GetString("SourceFrom")
- includeFile := this.GetString("IncludeFile")
- IsShowMe, _ := this.GetBool("IsShowMe")
- 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{}
- condition += ` AND resource_type = ? `
- pars = append(pars, resourceType)
- if includeFile == "no" {
- condition += ` AND is_file = ? `
- pars = append(pars, 0)
- }
- if IsShowMe {
- condition += ` AND admin_id = ? `
- pars = append(pars, this.SysUser.AdminId)
- }
- if keyWord != "" {
- //按照空格划分为关键词数组
- keyWordArr := strings.Split(keyWord, " ")
- lengthKey := len(keyWordArr)
- if lengthKey == 1 {
- condition += ` AND (title LIKE ?) `
- pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
- } else if lengthKey > 1 {
- for k, v := range keyWordArr {
- if k == 0 {
- condition += ` AND (title LIKE ? `
- pars = utils.GetLikeKeywordPars(pars, v, 1)
- } else if k == lengthKey-1 {
- condition += ` OR title LIKE ? ) `
- pars = utils.GetLikeKeywordPars(pars, v, 1)
- } else {
- condition += ` OR title LIKE ? `
- pars = utils.GetLikeKeywordPars(pars, v, 1)
- }
- }
- }
- }
- if sourceFrom != "" {
- sourceArr := strings.Split(sourceFrom, ",")
- condition += ` AND source_from in (?) `
- pars = append(pars, sourceArr)
- }
- if classifyIds != "" {
- //转成数组,并把类型转成int
- classifyIdsArr := strings.Split(classifyIds, ",")
- var classifyIdsInt []int
- for _, v := range classifyIdsArr {
- classifyId, _ := strconv.Atoi(v)
- classifyIdsInt = append(classifyIdsInt, classifyId)
- }
- condition += ` AND classify_id in (?) `
- pars = append(pars, classifyIdsInt)
- }
- if addUserIds > 0 {
- // 转成数组,并把类型转成int
- addUserIdsArr := strings.Split(strconv.Itoa(addUserIds), ",")
- var addUserIdsInt []int
- for _, v := range addUserIdsArr {
- addUserId, _ := strconv.Atoi(v)
- addUserIdsInt = append(addUserIdsInt, addUserId)
- }
- condition += ` AND admin_id in (?) `
- pars = append(pars, addUserIdsInt)
- }
- if tagIds != "" {
- //转成数组,并把类型转成int
- tagIdsArr := strings.Split(tagIds, ",")
- var tagIdsInt []int
- for _, v := range tagIdsArr {
- tagId, _ := strconv.Atoi(v)
- tagIdsInt = append(tagIdsInt, tagId)
- }
- condition += ` AND tag_id in (?) `
- pars = append(pars, tagIdsInt)
- }
- var err error
- var total int
- var list []*knowledge.KnowledgeResourceList
- // 共享事件需要连表查询,所以需要单独写
- total, err = knowledge.GetKnowledgeResourceListCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- listTmp, err := knowledge.GetKnowledgeResourcePageList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- // 整理分类ID
- classifyFullNameMap := make(map[int]string)
- classifyIdsArr := make([]int, 0)
- for _, v := range listTmp {
- classifyIdsArr = append(classifyIdsArr, v.ClassifyId)
- }
- // 获取分类列表
- classifyList, err := knowledge.GetFullClassifyListByIdList(classifyIdsArr, resourceType)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- name := v.ClassifyName
- if v.ParentName != "" {
- name = v.ParentName + "/" + name
- }
- if v.RootName != "" {
- name = v.RootName + "/" + name
- }
- classifyFullNameMap[v.ClassifyId] = name
- }
- // 整理标签ID
- tagNameMap := make(map[int]string)
- tagIdsArr := make([]int, 0)
- for _, v := range listTmp {
- tagIdsArr = append(tagIdsArr, v.TagId)
- }
- // 获取标签列表
- tagObj := new(knowledge.KnowledgeTag)
- tagList, err := tagObj.GetListByIdList(tagIdsArr, resourceType)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- }
- for _, v := range tagList {
- tagNameMap[v.TagId] = v.TagName
- }
- for _, v := range listTmp {
- var startTime, endTime string
- if v.StartTime != nil && !v.StartTime.IsZero() {
- startTime = v.StartTime.In(time.Local).Format(utils.FormatDateTime)
- if resourceType == knowledge.KnowledgeResourceTypeOpinion || resourceType == knowledge.KnowledgeResourceTypeKnow {
- startTime = v.StartTime.In(time.Local).Format(utils.FormatDate)
- }
- }
- if v.EndTime != nil && !v.EndTime.IsZero() {
- endTime = v.EndTime.In(time.Local).Format(utils.FormatDateTime)
- if resourceType == knowledge.KnowledgeResourceTypeOpinion || resourceType == knowledge.KnowledgeResourceTypeKnow {
- endTime = v.EndTime.In(time.Local).Format(utils.FormatDate)
- }
- }
- modifyTime := v.ModifyTime.In(time.Local).Format(utils.FormatDateTime)
- createTime := v.CreateTime.In(time.Local).Format(utils.FormatDateTime)
- tmp := &knowledge.KnowledgeResourceList{
- KnowledgeResourceId: v.KnowledgeResourceId,
- ResourceType: v.ResourceType,
- ClassifyId: v.ClassifyId,
- Title: v.Title,
- CreateTime: createTime,
- ModifyTime: modifyTime,
- State: v.State,
- ResourceCode: v.ResourceCode,
- AdminId: v.AdminId,
- AdminRealName: v.AdminRealName,
- SourceFrom: v.SourceFrom,
- TagId: v.TagId,
- StartTime: startTime,
- EndTime: endTime,
- }
- // todo 编辑状态
- /*markStatus, err := services.UpdateReportEditMark(item.Id, 0, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = "查询标记状态失败"
- br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
- return
- }
- if markStatus.Status == 0 {
- item.CanEdit = true
- } else {
- item.Editor = markStatus.Editor
- }*/
- classifyName, ok := classifyFullNameMap[tmp.ClassifyId]
- if ok {
- tmp.ClassifyFullName = classifyName
- }
- tagName, ok := tagNameMap[v.TagId]
- if ok {
- tmp.TagName = tagName
- }
- list = append(list, tmp)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(knowledge.KnowledgeResourceListResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Search
- // @Title 获取事件列表接口
- // @Description 获取事件列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param TimeType query string true "筛选的时间类别:publish_time(发布时间),modify_time(更新时间);approve_time(审批时间)"
- // @Param StartDate query string true "开始时间"
- // @Param EndDate query string true "结束时间"
- // @Param Frequency query string true "频度"
- // @Param ClassifyIds query int true "分类id, 多选, 英文逗号分隔"
- // @Param SysUserIds query int true "用户id, 多选, 英文逗号分隔"
- // @Param State query int true "状态"
- // @Param KeyWord query string true "搜索关键词"
- // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
- // @Param FilterReportType query string true "筛选事件类型,1:公共研报,2:共享研报,3:我的研报"
- // @Param IncludeFile query string true "是否包含文件, no:不包含"
- // @Param SourceFrom query string true "来源, 用英文逗号分隔"
- // @Param IsShowMe query string true "只看我, false:全部, true:只看我"
- // @Success 200 {object} knowledge.KnowledgeResourceListResp
- // @router /resource/search_by_es [get]
- func (this *ResourceController) Search() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- classifyIds := this.GetString("ClassifyIds")
- // 添加人
- addUserIds := this.GetString("SysUserIds")
- // 标签
- tagIds := this.GetString("TagIds")
- keyWord := this.GetString("Keyword")
- resourceType, _ := this.GetInt("ResourceType")
- sourceFrom := this.GetString("SourceFrom")
- includeFile := this.GetString("IncludeFile")
- IsShowMe, _ := this.GetBool("IsShowMe")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- isIncludeFile := true
- if includeFile == "no" {
- isIncludeFile = false
- }
- var searchUserIds []int
- if addUserIds != "" {
- // 转成数组,并把类型转成int
- addUserIdsArr := strings.Split(addUserIds, ",")
- for _, v := range addUserIdsArr {
- addUserId, _ := strconv.Atoi(v)
- searchUserIds = append(searchUserIds, addUserId)
- }
- }
- var myId int
- if IsShowMe {
- myId = this.SysUser.AdminId
- }
- var sourceFromArr []string
- if sourceFrom != "" {
- sourceFromArr = strings.Split(sourceFrom, ",")
- }
- var classifyIdsInt []int
- if classifyIds != "" {
- //转成数组,并把类型转成int
- classifyIdsArr := strings.Split(classifyIds, ",")
- for _, v := range classifyIdsArr {
- classifyId, _ := strconv.Atoi(v)
- classifyIdsInt = append(classifyIdsInt, classifyId)
- }
- }
- var tagIdsInt []int
- if tagIds != "" {
- //转成数组,并把类型转成int
- tagIdsArr := strings.Split(tagIds, ",")
- for _, v := range tagIdsArr {
- tagId, _ := strconv.Atoi(v)
- tagIdsInt = append(tagIdsInt, tagId)
- }
- }
- listTmp, total, err := knowledgeServ.SearchKnowledgeResourceByEs(
- resourceType,
- keyWord,
- searchUserIds,
- myId,
- classifyIdsInt,
- sourceFromArr,
- tagIdsInt,
- isIncludeFile,
- startSize,
- pageSize,
- )
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- var list []*knowledge.KnowledgeResourceList
- // 整理分类ID
- classifyFullNameMap := make(map[int]string)
- classifyIdsArr := make([]int, 0)
- for _, v := range listTmp {
- classifyIdsArr = append(classifyIdsArr, v.ClassifyId)
- }
- // 获取分类列表
- classifyList, err := knowledge.GetFullClassifyListByIdList(classifyIdsArr, resourceType)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- name := v.ClassifyName
- if v.ParentName != "" {
- name = v.ParentName + "/" + name
- }
- if v.RootName != "" {
- name = v.RootName + "/" + name
- }
- classifyFullNameMap[v.ClassifyId] = name
- }
- // 整理标签ID
- tagNameMap := make(map[int]string)
- tagIdsArr := make([]int, 0)
- for _, v := range listTmp {
- tagIdsArr = append(tagIdsArr, v.TagId)
- }
- // 获取标签列表
- tagObj := new(knowledge.KnowledgeTag)
- tagList, err := tagObj.GetListByIdList(tagIdsArr, resourceType)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- }
- for _, v := range tagList {
- tagNameMap[v.TagId] = v.TagName
- }
- for _, v := range listTmp {
- var startTime, endTime string
- if v.StartTime != nil && !v.StartTime.IsZero() {
- startTime = v.StartTime.In(time.Local).Format(utils.FormatDateTime)
- if resourceType == knowledge.KnowledgeResourceTypeOpinion || resourceType == knowledge.KnowledgeResourceTypeKnow {
- startTime = v.StartTime.In(time.Local).Format(utils.FormatDate)
- }
- }
- if v.EndTime != nil && !v.EndTime.IsZero() {
- endTime = v.EndTime.In(time.Local).Format(utils.FormatDateTime)
- if resourceType == knowledge.KnowledgeResourceTypeOpinion || resourceType == knowledge.KnowledgeResourceTypeKnow {
- endTime = v.EndTime.In(time.Local).Format(utils.FormatDate)
- }
- }
- modifyTime := v.ModifyTime.In(time.Local).Format(utils.FormatDateTime)
- createTime := v.CreateTime.In(time.Local).Format(utils.FormatDateTime)
- tmp := &knowledge.KnowledgeResourceList{
- KnowledgeResourceId: v.KnowledgeResourceId,
- ResourceType: v.ResourceType,
- ClassifyId: v.ClassifyId,
- Title: v.Title,
- Content: v.Content,
- CreateTime: createTime,
- ModifyTime: modifyTime,
- State: v.State,
- ResourceCode: v.ResourceCode,
- AdminId: v.AdminId,
- AdminRealName: v.AdminRealName,
- SourceFrom: v.SourceFrom,
- TagId: v.TagId,
- StartTime: startTime,
- EndTime: endTime,
- }
- classifyName, ok := classifyFullNameMap[tmp.ClassifyId]
- if ok {
- tmp.ClassifyFullName = classifyName
- }
- tagName, ok := tagNameMap[v.TagId]
- if ok {
- tmp.TagName = tagName
- }
- list = append(list, tmp)
- }
- // list := make([]*knowledge.KnowledgeResourceList, 0, len(knowledges))
- // for _, v := range knowledges {
- // item := new(knowledge.KnowledgeResourceList)
- // item.KnowledgeResourceId = v.KnowledgeResourceId
- // item.ResourceType = v.ResourceType
- // item.ClassifyId = v.ClassifyId
- // item.Title = v.Title
- // item.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
- // item.ModifyTime = v.ModifyTime.Format(utils.FormatDateTime)
- // item.State = v.State
- // item.Content = v.Content
- // item.ResourceCode = v.ResourceCode
- // item.AdminId = v.AdminId
- // item.AdminRealName = v.AdminRealName
- // item.SourceFrom = v.SourceFrom
- // item.TagId = v.TagId
- // if v.StartTime != nil {
- // item.StartTime = v.StartTime.Format(utils.FormatDateTime)
- // }
- // if v.EndTime != nil {
- // item.EndTime = v.EndTime.Format(utils.FormatDateTime)
- // }
- // list = append(list, item)
- // }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp := new(knowledge.KnowledgeResourceListResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Add
- // @Title 新增事件接口
- // @Description 新增事件(区分事件类型)
- // @Param request body knowledge.AddReq true "type json string"
- // @Success 200 {object} knowledge.AddResp
- // @router /resource/add [post]
- func (this *ResourceController) Add() {
- 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 knowledge.AddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Title == `` {
- br.Msg = "标题不能为空"
- br.ErrMsg = "标题不能为空"
- br.IsSendEmail = false
- return
- }
- // 判断标题长度,如果超过600个字符则报错
- //fmt.Println(len(req.Title))
- if len(req.Title) > 600 {
- br.Msg = "标题过长"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "分类必填"
- br.ErrMsg = "分类必填"
- br.IsSendEmail = false
- return
- }
- if req.ResourceType == knowledge.KnowledgeResourceTypeEvent || req.ResourceType == knowledge.KnowledgeResourceTypePolicy {
- if req.StartTime == "" {
- br.Msg = "开始时间必填"
- br.ErrMsg = "开始时间必填"
- return
- }
- }
- item, err, errMsg := knowledgeServ.AddResource(&req, sysUser)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- resp := new(knowledge.AddResp)
- resp.KnowledgeResourceId = item.KnowledgeResourceId
- resp.ResourceCode = item.ResourceCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- }
- // Edit
- // @Title 编辑事件基础信息接口
- // @Description 编辑事件基础信息(不区分事件类型)
- // @Param request body knowledge.EditReq true "type json string"
- // @Success 200 {object} knowledge.EditResp
- // @router /resource/edit [post]
- func (this *ResourceController) Edit() {
- 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 knowledge.EditReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.KnowledgeResourceId <= 0 {
- br.Msg = "请选择事件"
- br.ErrMsg = "请选择事件"
- return
- }
- if req.Title == `` {
- br.Msg = "标题不能为空"
- br.ErrMsg = "标题不能为空"
- br.IsSendEmail = false
- return
- }
- if len(req.Title) > 600 {
- br.Msg = "标题过长"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "分类必填"
- br.ErrMsg = "分类必填"
- br.IsSendEmail = false
- return
- }
- if req.ResourceType == knowledge.KnowledgeResourceTypeEvent || req.ResourceType == knowledge.KnowledgeResourceTypePolicy {
- if req.StartTime == "" {
- br.Msg = "开始时间必填"
- br.ErrMsg = "开始时间必填"
- return
- }
- }
- // todo 更新标记key
- /*markStatus, err := services.UpdateReportEditMark(int(req.KnowledgeResourceId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
- return
- }*/
- resourceObj := new(knowledge.KnowledgeResource)
- resourceInfo, e := resourceObj.GetById(int(req.KnowledgeResourceId))
- if e != nil {
- if utils.IsErrNoRow(e) {
- br.Msg = "事件已被删除, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取事件失败, Err: " + e.Error()
- return
- }
- if resourceInfo.ResourceType != req.ResourceType {
- br.Msg = "事件类型错误"
- return
- }
- // 编辑事件信息
- err, errMsg := knowledgeServ.EditResource(resourceInfo, req, sysUser)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- resp := new(knowledge.EditResp)
- resp.KnowledgeResourceId = req.KnowledgeResourceId
- resp.ResourceCode = resourceInfo.ResourceCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- }
- // Detail
- // @Title 获取事件详情接口
- // @Description 获取事件详情
- // @Param request body knowledge.KnowledgeResourceDetailReq true "type json string"
- // @Success 200 {object} knowledge.KnowledgeResource
- // @router /resource/detail [get]
- func (this *ResourceController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- /*var req knowledge.KnowledgeResourceDetailReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.KnowledgeResourceId <= 0 {
- br.Msg = "参数错误"
- return
- }*/
- knowledgeResourceId, err := this.GetInt("KnowledgeResourceId")
- if err != nil {
- br.Msg = "获取参数失败!"
- br.ErrMsg = "获取参数失败,Err:" + err.Error()
- return
- }
- if knowledgeResourceId <= 0 {
- br.Msg = "参数错误"
- return
- }
- resourceType, _ := this.GetInt("ResourceType")
- resourceObj := new(knowledge.KnowledgeResource)
- item, err := resourceObj.GetById(knowledgeResourceId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "事件已被删除"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if item.ResourceType != resourceType {
- br.Msg = "事件类型错误"
- return
- }
- item.Content = html.UnescapeString(item.Content)
- resp := &knowledge.KnowledgeResourceDetailView{
- KnowledgeResource: item,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // SaveReportContent
- // @Title 保存草稿
- // @Description 保存草稿
- // @Param request body knowledge.SaveReportContent true "type json string"
- // @Success 200 {object} knowledge.KnowledgeResourceAuthorResp
- // @router /resource/saveContent [post]
- func (this *ResourceController) SaveReportContent() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- 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 knowledge.SaveReportContent
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- knowledgeResourceId := req.KnowledgeResourceId
- //noChangeFlag := req.NoChange
- if knowledgeResourceId <= 0 {
- resp := new(knowledge.SaveReportContentResp)
- resp.KnowledgeResourceId = knowledgeResourceId
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- return
- }
- // 获取事件详情
- /*resourceInfo, _ := knowledge.GetReportByknowledgeResourceId(req.KnowledgeResourceId)
- if resourceInfo != nil && resourceInfo.State == 2 {
- br.Msg = "该事件已发布,不允许编辑"
- br.ErrMsg = "该事件已发布,不允许编辑"
- br.IsSendEmail = false
- return
- }
- // 标记更新中
- {
- markStatus, err := services.UpdateReportEditMark(req.KnowledgeResourceId, 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- return
- }
- }
- // 内容有过修改的话,那么逻辑处理
- if noChangeFlag != 1 {
- content := req.Content
- if content == "" {
- content = this.GetString("Content")
- }
- if content != "" {
- e := utils.ContentXssCheck(req.Content)
- if e != nil {
- br.Msg = "存在非法标签"
- br.ErrMsg = "存在非法标签, Err: " + e.Error()
- return
- }
- contentClean, e := services.FilterReportContentBr(req.Content)
- if e != nil {
- br.Msg = "内容去除前后空格失败"
- br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
- return
- }
- content = contentClean
- contentSub, err := services.GetReportContentSub(content)
- if err != nil {
- go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
- //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
- }
- resourceInfo.Content = html.EscapeString(content)
- resourceInfo.ContentSub = html.EscapeString(contentSub)
- resourceInfo.ContentStruct = html.EscapeString(req.ContentStruct)
- resourceInfo.HeadImg = req.HeadImg
- resourceInfo.EndImg = req.EndImg
- resourceInfo.CanvasColor = req.CanvasColor
- resourceInfo.HeadResourceId = req.HeadResourceId
- resourceInfo.EndResourceId = req.EndResourceId
- resourceInfo.ModifyTime = time.Now()
- resourceInfo.ContentModifyTime = time.Now()
- updateCols := []string{"Content", "ContentSub", "ContentStruct", "HeadImg", "EndImg", "CanvasColor", "HeadResourceId", "EndResourceId", "ModifyTime", "ContentModifyTime"}
- err = resourceInfo.UpdateReport(updateCols)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- go knowledge.AddReportSaveLog(knowledgeResourceId, this.SysUser.AdminId, resourceInfo.Content, resourceInfo.ContentSub, resourceInfo.ContentStruct, resourceInfo.CanvasColor, this.SysUser.AdminName, resourceInfo.HeadResourceId, resourceInfo.EndResourceId)
- }
- }
- */
- resp := new(knowledge.SaveReportContentResp)
- resp.KnowledgeResourceId = knowledgeResourceId
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- }
- // BaseDetail
- // @Title 获取事件基础信息详情接口
- // @Description 获取事件基础信息详情接口
- // @Param request body knowledge.KnowledgeResourceDetailReq true "type json string"
- // @Success 200 {object} knowledge.KnowledgeResource
- // @router /resource/detail/base [get]
- func (this *ResourceController) BaseDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- /*var req knowledge.KnowledgeResourceDetailReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.KnowledgeResourceId <= 0 {
- br.Msg = "参数错误"
- return
- }*/
- /*knowledgeResourceId, err := this.GetInt("KnowledgeResourceId")
- if err != nil {
- br.Msg = "获取参数失败!"
- br.ErrMsg = "获取参数失败,Err:" + err.Error()
- return
- }
- if knowledgeResourceId <= 0 {
- br.Msg = "参数错误"
- return
- }
- resourceInfo, err := knowledge.GetReportById(knowledgeResourceId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "事件已被删除"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- // 基础信息就不获取章节信息了
- chapterList := make([]*knowledge.KnowledgeResourceChapter, 0)
- resourceInfo.Content = html.UnescapeString(resourceInfo.Content)
- resourceInfo.ContentSub = html.UnescapeString(resourceInfo.ContentSub)
- grandAdminList := make([]knowledge.KnowledgeResourceDetailViewAdmin, 0)
- permissionList := make([]knowledge.KnowledgeResourceDetailViewPermission, 0)
- // 处理事件授权用户列表
- {
- obj := report.ReportGrant{}
- grantList, tmpErr := obj.GetGrantListById(knowledgeResourceId)
- if tmpErr != nil {
- br.Msg = "获取章节id授权用户列表失败"
- br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
- return
- }
- if len(grantList) > 0 {
- grandAdminIdList := make([]int, 0)
- for _, v := range grantList {
- grandAdminIdList = append(grandAdminIdList, v.AdminId)
- }
- adminList, tmpErr := system.GetAdminListByIdList(grandAdminIdList)
- if tmpErr != nil {
- br.Msg = "获取章节id授权用户列表失败"
- br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
- return
- }
- for _, v := range adminList {
- grandAdminList = append(grandAdminList, knowledge.KnowledgeResourceDetailViewAdmin{
- AdminId: v.AdminId,
- AdminName: v.RealName,
- })
- }
- }
- }
- // 处理章节id关联品种id列表
- {
- minClassifyId := resourceInfo.ClassifyIdThird
- if minClassifyId <= 0 {
- minClassifyId = resourceInfo.ClassifyIdSecond
- }
- if minClassifyId <= 0 {
- minClassifyId = resourceInfo.ClassifyIdFirst
- }
- if minClassifyId <= 0 {
- br.Msg = "分类异常"
- br.ErrMsg = "分类异常"
- return
- }
- // 获取分类关联的品种id
- classifyPermissionList, tmpErr := knowledge.GetPermission(minClassifyId)
- if tmpErr != nil {
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取失败,Err:" + tmpErr.Error()
- return
- }
- if len(classifyPermissionList) > 0 {
- permissionIdList := make([]int, 0)
- for _, v := range classifyPermissionList {
- permissionIdList = append(permissionIdList, v.ChartPermissionId)
- }
- adminList, tmpErr := knowledge.GetChartPermissionByIdList(permissionIdList)
- if tmpErr != nil {
- br.Msg = "获取章节id授权用户列表失败"
- br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
- return
- }
- for _, v := range adminList {
- permissionList = append(permissionList, knowledge.KnowledgeResourceDetailViewPermission{
- PermissionId: v.ChartPermissionId,
- PermissionName: v.PermissionName,
- })
- }
- }
- }
- resp := &knowledge.KnowledgeResourceDetailView{
- ReportDetail: resourceInfo,
- ChapterList: chapterList,
- GrandAdminList: grandAdminList,
- PermissionList: permissionList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp*/
- }
- // Delete
- // @Title 删除事件接口
- // @Description 删除事件
- // @Param request body knowledge.DeleteReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /resource/delete [post]
- func (this *ResourceController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req knowledge.DeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.KnowledgeResourceId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,事件id不可为空"
- return
- }
- resourceObj := new(knowledge.KnowledgeResource)
- item, err := resourceObj.GetById(req.KnowledgeResourceId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "事件不存在"
- br.ErrMsg = "事件不存在"
- return
- }
- }
- if item.ResourceType != req.ResourceType {
- br.Msg = "事件类型不匹配"
- return
- }
- if err = item.Delete(req.KnowledgeResourceId); err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除事件失败, Err: " + err.Error()
- return
- }
- go func() {
- item.IsDelete = 1
- er := knowledgeServ.EsAddOrEditKnowledgeResource(item)
- if er != nil {
- utils.FileLog.Info("知识资源id:" + strconv.Itoa(req.KnowledgeResourceId) + ",删除事件同步es失败, Err: " + er.Error())
- }
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // ImportData
- // @Title Excel导入事件
- // @Description Excel导入事件
- // @Param EntryFile query file true "文件"
- // @Success 200 Ret=200 录入成功
- // @router /resource/import_add [post]
- func (c *ResourceController) ImportData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- resourceType, _ := c.GetInt("ResourceType")
- file, _, err := c.GetFile("EntryFile")
- if err != nil {
- br.Msg = "获取文件失败"
- br.ErrMsg = "获取文件失败,Err:" + err.Error()
- return
- }
- path := "./static/knowledge_import_" + strconv.Itoa(resourceType) + "_" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- defer file.Close()
- err = c.SaveToFile("EntryFile", path)
- if err != nil {
- br.Msg = "文件保存失败"
- br.ErrMsg = "文件保存失败,Err:" + err.Error()
- return
- }
- //if utils.RunMode == "debug" {
- defer os.Remove(path)
- //}
- successCount, failCount, err, errMsg := knowledgeServ.ImportResourceData(path, resourceType, sysUser)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- resp := models.EdbdataImportResp{
- SuccessCount: successCount,
- FailCount: failCount,
- }
- if failCount > 0 {
- if successCount == 0 {
- resp.Status = -1
- resp.Msg = "导入失败"
- } else {
- resp.Status = 1
- resp.Msg = "存在部分导入失败"
- }
- } else {
- resp.Status = 0
- }
- br.Msg = "导入成功"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // ImportFailListDownload
- // @Title 下载失败列表
- // @Description 下载失败列表
- // @Success 200 {object} models.EdbdataClassifyResp
- // @router /resource/download_fail [get]
- func (this *ResourceController) ImportFailListDownload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- resourceType, _ := this.GetInt("ResourceType")
- failObj := new(knowledge.KnowledgeImportFail)
- item, err := failObj.GetListBySysUserId(sysUser.AdminId, resourceType)
- if err != nil {
- br.Msg = "获取数据失败"
- br.Msg = "获取数据失败,Err:" + err.Error()
- return
- }
- xlsxFile := xlsx.NewFile()
- SheetName := "导入失败数据"
- if this.Lang == utils.EnLangVersion {
- SheetName = "Import Fail List"
- }
- sheet, err := xlsxFile.AddSheet(SheetName)
- if err != nil {
- br.Msg = "获取sheet失败"
- br.Msg = "获取sheet失败,Err:" + err.Error()
- return
- }
- if resourceType == knowledge.KnowledgeResourceTypeEvent || resourceType == knowledge.KnowledgeResourceTypePolicy {
- headRow := sheet.AddRow()
- headRow.AddCell().SetValue("开始日期")
- headRow.AddCell().SetValue("开始时间")
- headRow.AddCell().SetValue("结束日期")
- headRow.AddCell().SetValue("结束时间")
- headRow.AddCell().SetValue("标题")
- headRow.AddCell().SetValue("正文")
- headRow.AddCell().SetValue("来源")
- headRow.AddCell().SetValue("一级分类")
- headRow.AddCell().SetValue("二级分类")
- headRow.AddCell().SetValue("三级分类")
- headRow.AddCell().SetValue("标签")
- headRow.AddCell().SetValue("备注")
- for _, v := range item {
- row := sheet.AddRow()
- row.AddCell().SetValue(v.StartDate)
- row.AddCell().SetValue(v.StartTime)
- row.AddCell().SetValue(v.EndDate)
- row.AddCell().SetValue(v.EndTime)
- row.AddCell().SetValue(v.Title)
- row.AddCell().SetValue(v.Content)
- row.AddCell().SetValue(v.SourceFrom)
- row.AddCell().SetValue(v.ClassifyFirst)
- row.AddCell().SetValue(v.ClassifySecond)
- row.AddCell().SetValue(v.ClassifyThird)
- row.AddCell().SetValue(v.Tag)
- row.AddCell().SetValue(v.Remark)
- }
- } else {
- headRow := sheet.AddRow()
- headRow.AddCell().SetValue("时间")
- headRow.AddCell().SetValue("标题")
- headRow.AddCell().SetValue("正文")
- headRow.AddCell().SetValue("来源")
- headRow.AddCell().SetValue("一级分类")
- headRow.AddCell().SetValue("二级分类")
- headRow.AddCell().SetValue("三级分类")
- headRow.AddCell().SetValue("标签")
- headRow.AddCell().SetValue("备注")
- for _, v := range item {
- row := sheet.AddRow()
- row.AddCell().SetValue(v.StartDate)
- row.AddCell().SetValue(v.Title)
- row.AddCell().SetValue(v.Content)
- row.AddCell().SetValue(v.SourceFrom)
- row.AddCell().SetValue(v.ClassifyFirst)
- row.AddCell().SetValue(v.ClassifySecond)
- row.AddCell().SetValue(v.ClassifyThird)
- row.AddCell().SetValue(v.Tag)
- row.AddCell().SetValue(v.Remark)
- }
- }
- fileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- savePath := "./static/" + fileName
- err = xlsxFile.Save(savePath)
- if err != nil {
- br.Msg = "文件保存失败"
- br.ErrMsg = "文件保存失败,Err:" + err.Error()
- return
- }
- defer func() {
- os.Remove(savePath)
- }()
- finalFileName := "失败列表.xlsx"
- if this.Lang == utils.EnLangVersion {
- finalFileName = "Failure List.xlsx"
- }
- this.Ctx.Output.Download(savePath, finalFileName)
- }
- // ResourceUpload 上传文件
- // @Title 上传文件
- // @Description 上传文件
- // @Param MenuId query int true "目录ID"
- // @Param File query file true "文件"
- // @Success 200 Ret=200 操作成功
- // @router /resource/upload [post]
- func (this *ResourceController) ResourceUpload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- f, h, e := this.GetFile("File")
- if e != nil {
- br.Msg = "获取资源信息失败"
- br.ErrMsg = "获取资源信息失败, Err:" + e.Error()
- return
- }
- defer func() {
- _ = f.Close()
- }()
- // 不依赖于文件扩展名检查文件格式
- fileData, e := ioutil.ReadAll(f)
- if e != nil {
- br.Msg = "上传失败"
- br.ErrMsg = "读取文件失败, Err: " + e.Error()
- return
- }
- ext := path.Ext(h.Filename)
- //fmt.Println("ext", ext)
- kind, _ := filetype.Match(fileData)
- //fmt.Println("kind.Extension", kind.Extension)
- if ext != ".pdf" && ext != ".ppt" && ext != ".pptx" && ext != ".docx" && ext != ".doc" && kind.Extension != "pdf" && kind.Extension != "ppt" && kind.Extension != "pptx" && kind.Extension != "docx" && kind.Extension != "doc" {
- br.Msg = "文件格式有误"
- return
- }
- uploadDir := utils.STATIC_DIR + "hongze/" + time.Now().Format("20060102")
- if e = os.MkdirAll(uploadDir, utils.DIR_MOD); e != nil {
- br.Msg = "存储目录创建失败"
- br.ErrMsg = "存储目录创建失败, Err:" + e.Error()
- return
- }
- ossFileName := utils.GetRandStringNoSpecialChar(28) + ext
- filePath := uploadDir + "/" + ossFileName
- if e = this.SaveToFile("File", filePath); e != nil {
- br.Msg = "文件保存失败"
- br.ErrMsg = "文件保存失败, Err:" + e.Error()
- return
- }
- defer func() {
- _ = os.Remove(filePath)
- }()
- // 上传到阿里云
- ossDir := utils.RESOURCE_DIR + "knowledge_resource/"
- resourceUrl := ``
- savePath := ossDir + time.Now().Format("200601/20060102/") + ossFileName
- ossClient := services.NewOssClient()
- if ossClient == nil {
- br.Msg = "上传失败"
- br.ErrMsg = "初始化OSS服务失败"
- return
- }
- resourceUrl, e = ossClient.UploadFile(ossFileName, filePath, savePath)
- if e != nil {
- br.Msg = "文件上传失败"
- br.ErrMsg = "文件上传失败,Err:" + e.Error()
- return
- }
- resourceItem := &knowledge.UpdateResourceResp{
- FileUrl: resourceUrl,
- }
- br.Msg = "上传成功"
- br.Ret = 200
- br.Success = true
- br.Data = resourceItem
- }
- // GetSourceFrom
- // @Title 获取所有来源
- // @Description 获取所有来源
- // @Success 200 {object} models.EdbdataClassifyResp
- // @router /resource/source_from [get]
- func (this *ResourceController) GetSourceFrom() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- resourceType, _ := this.GetInt("ResourceType")
- keyword := this.GetString("Keyword")
- resourceObj := new(knowledge.KnowledgeResource)
- list, err := resourceObj.GetSourceFrom(keyword, resourceType)
- if err != nil {
- br.Msg = "获取数据失败"
- br.Msg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp := new(knowledge.GetSourceFromResp)
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // GetAdminList
- // @Title 获取所有创建人
- // @Description 获取所有创建人
- // @Success 200 {object} models.EdbdataClassifyResp
- // @router /resource/admins [get]
- func (this *ResourceController) GetAdminList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- resourceType, _ := this.GetInt("ResourceType")
- keyword := this.GetString("Keyword")
- resourceObj := new(knowledge.KnowledgeResource)
- list, err := resourceObj.GetAdmins(keyword, resourceType)
- if err != nil {
- br.Msg = "获取数据失败"
- br.Msg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp := new(knowledge.GetAdminsResp)
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // TemplateDownload
- // @Title 下载模板
- // @Description 下载模板
- // @Success 200 {object} models.EdbdataClassifyResp
- // @Param ResourceType query int false "来源:1:模板1;2:模板2"
- // @router /resource/template [get]
- func (this *ResourceController) TemplateDownload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- resourceType, _ := this.GetInt("ResourceType")
- downUrl := ""
- fileName := ""
- switch resourceType {
- case 1:
- downUrl = "./static/template/政策库上传模板.xlsx"
- fileName = "政策库上传模板.xlsx"
- case 2:
- downUrl = "./static/template/观点库上传模板.xlsx"
- fileName = "观点库上传模板.xlsx"
- case 3:
- downUrl = "./static/template/知识库上传模板.xlsx"
- fileName = "知识库上传模板.xlsx"
- default:
- downUrl = "./static/template/事件库上传模板.xlsx"
- fileName = "事件库上传模板.xlsx"
- }
- // 判断文件是否存在
- if _, err := os.Stat(downUrl); os.IsNotExist(err) {
- br.Msg = "文件不存在"
- return
- }
- fmt.Println(downUrl, fileName)
- this.Ctx.Output.Download(downUrl, fileName)
- //this.Ctx.Output.Download("./static/数据导入模板.xlsx", "数据导入模板.xlsx")
- br.Ret = 200
- br.Success = true
- br.Msg = "下载成功"
- }
- // BiDashboardTmpResourceList
- // @Title 获取bi看报中的知识资源列表
- // @Description 获取bi看报中的知识资源列表
- // @Success 200 {object} models.EdbdataClassifyResp
- // @Param biDashboardDetailId query int true "看板详情ID"
- // @router /resource/bi_dashboard/list [get]
- func (this *ResourceController) BiDashboardCacheResourceList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- biDashboardDetailId, _ := this.GetInt("BiDashboardDetailId")
- resp, msg, err := knowledgeServ.GetKnowledgeResourceTmpList(biDashboardDetailId, this.SysUser.AdminId)
- if err != nil {
- if msg == "" {
- msg = "获取数据失败"
- }
- br.Msg = msg
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // BiDashboardResourceSave
- // @Title 将知识资源库添加到bi看板
- // @Description 将知识资源库添加到bi看板
- // @Param request body knowledge.DeleteReq true "type json string"
- // @Success 200 {object} models.EdbdataClassifyResp
- // @router /resource/bi_dashboard/save [post]
- func (this *ResourceController) BiDashboardResourceSave() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req knowledge.BiDashboardResourceAddReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if len(req.KnowledgeResourceList) == 0 {
- // 则删除缓存中的数据
- err := utils.Rc.Delete(utils.CACHE_KEY_BI_DASHBOARD_PREPARE_RESOURCE + strconv.Itoa(this.SysUser.AdminId))
- if err != nil {
- br.Msg = "添加失败"
- br.ErrMsg = "删除缓存失败,Err:" + err.Error()
- return
- }
- br.Msg = "添加成功"
- br.Ret = 200
- br.Success = true
- return
- }
- cacheData, err := json.Marshal(req)
- if err != nil {
- br.Msg = "添加失败"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- err = utils.Rc.Put(utils.CACHE_KEY_BI_DASHBOARD_PREPARE_RESOURCE+strconv.Itoa(this.SysUser.AdminId), cacheData, time.Hour*24)
- if err != nil {
- br.Msg = "添加失败"
- br.ErrMsg = "添加失败,Err:" + err.Error()
- return
- }
- br.Msg = "添加成功"
- br.Ret = 200
- br.Success = true
- }
|