12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568 |
- 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.KnowledgeResourceTypeReport || 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.KnowledgeResourceTypeReport || 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 reqList []knowledge.AddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqList)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- for _, req := range reqList {
- 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 || req.ResourceType == knowledge.KnowledgeResourceTypeOpinion {
- if req.StartTime == "" {
- br.Msg = "开始时间必填"
- br.ErrMsg = "开始时间必填"
- return
- }
- }
- _, 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 || req.ResourceType == knowledge.KnowledgeResourceTypeOpinion {
- 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 = "下载成功"
- }
- // Public
- // @Title 设置知识库事件公开接口
- // @Description 设置知识库事件公开接口
- // @Param request body knowledge.AddReq true "type json string"
- // @Success 200 {object} knowledge.AddResp
- // @router /resource/public [post]
- func (this *ResourceController) Public() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- var req knowledge.PublicReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- msg, err := knowledgeServ.SetKnowledgeResourcePublic(req.KnowledgeResourceId)
- if err != nil {
- if msg == "" {
- msg = "设置失败"
- }
- br.Msg = msg
- br.ErrMsg = "设置失败,Err:" + err.Error()
- return
- }
- br.Msg = "设置成功"
- br.Ret = 200
- br.Success = true
- }
- // 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
- }
|