12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333 |
- package data_manage
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/system"
- "eta/eta_api/services/data"
- "eta/eta_api/services/data/data_manage_permission"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "sort"
- "strconv"
- "strings"
- "time"
- )
- // 我的图库
- type MyChartController struct {
- controllers.BaseAuthController
- }
- // @Title ETA图表列表接口
- // @Description ETA图表列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ChartClassifyId query int true "分类id"
- // @Param KeyWord query string true "搜索关键词"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /chart/list [get]
- func (this *MyChartController) ChartList() {
- 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
- }
- chartClassifyId, _ := this.GetInt("ChartClassifyId")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyWord := this.GetString("KeyWord")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- // 普通图表
- condition += ` AND source = ? `
- pars = append(pars, utils.CHART_SOURCE_DEFAULT)
- chartClassifyIds := make([]int, 0)
- if chartClassifyId > 0 {
- list, e := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取图表分类失败, Err: %v", e)
- return
- }
- parents := data.GetChartClassifyChildrenRecursive(list, chartClassifyId)
- sort.Slice(parents, func(i, j int) bool {
- return parents[i].Level < parents[i].Level
- })
- for _, v := range parents {
- chartClassifyIds = append(chartClassifyIds, v.ChartClassifyId)
- }
- //chartClassifyId, err := data_manage.GetChartClassify(chartClassifyId)
- //if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "获取图表信息失败"
- // br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
- // return
- //}
- condition += " AND chart_classify_id IN(" + utils.GetOrmInReplace(len(chartClassifyIds)) + ") "
- pars = append(pars, chartClassifyIds)
- }
- if keyWord != "" {
- condition += ` AND ( chart_name LIKE '%` + keyWord + `%' OR chart_name_en LIKE '%` + keyWord + `%' )`
- }
- //只看我的
- isShowMe, _ := this.GetBool("IsShowMe")
- if isShowMe {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, sysUser.AdminId)
- }
- // 获取当前账号的不可见指标
- noPermissionChartIdList := make([]int, 0)
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
- }
- }
- lenNoPermissionChartIdList := len(noPermissionChartIdList)
- if lenNoPermissionChartIdList > 0 {
- condition += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
- pars = append(pars, noPermissionChartIdList)
- }
- //获取图表信息
- list, err := data_manage.GetChartListByCondition(condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
- return
- }
- myChartMap := make(map[int]*data_manage.MyChartView)
- for _, v := range myChartList {
- myChartMap[v.ChartInfoId] = v
- }
- listLen := len(list)
- chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
- if listLen > 0 {
- // 分类id
- classifyIdList := make([]int, 0)
- // 当前列表中的分类map
- classifyMap := make(map[int]*data_manage.ChartClassify)
- for _, v := range list {
- classifyIdList = append(classifyIdList, v.ChartClassifyId)
- }
- classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ChartClassifyId] = v
- }
- // 已授权分类id
- permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- // 权限
- for k, chartViewInfo := range list {
- if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
- list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- }
- }
- chartInfoIds := ""
- for _, v := range list {
- chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
- }
- if chartInfoIds != "" {
- chartInfoIds = strings.Trim(chartInfoIds, ",")
- //判断是否需要展示英文标识
- edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
- return
- }
- for _, v := range edbList {
- chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
- }
- }
- }
- for i := 0; i < listLen; i++ {
- //判断是否需要展示英文标识
- if edbTmpList, ok := chartEdbMap[list[i].ChartInfoId]; ok {
- list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, edbTmpList, list[i].Source, list[i].ChartType)
- }
- if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
- list[i].IsAdd = true
- list[i].MyChartId = existItem.MyChartId
- list[i].MyChartClassifyId = existItem.MyChartClassifyId
- }
- }
- resp := new(data_manage.ChartListResp)
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*data_manage.ChartInfoView, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- dataCount, err := data_manage.GetChartListCountByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ClassifyList
- // @Title 我的图表-分类列表接口
- // @Description 我的图表-分类列表接口
- // @Success 200 {object} data_manage.MyChartClassifyResp
- // @router /classify/list [get]
- func (this *MyChartController) ClassifyList() {
- 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
- }
- //获取图表信息
- list, err := data_manage.GetMyChartClassifyAll(sysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.MyChartClassifyResp)
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*data_manage.MyChartClassifyItem, 0)
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- //resp.List = list
- // 获取图表分类下各自的图表数
- chartsNumMap, e := data.GetMyChartClassifyIdNumMap(sysUser.AdminId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, GetMyChartClassifyIdNumMap Err: " + e.Error()
- return
- }
- results := make([]*data_manage.MyChartClassifyItem, 0)
- for _, v := range list {
- results = append(results, data_manage.FormatMyChartClassify2Item(v, chartsNumMap[v.MyChartClassifyId]))
- }
- resp.List = results
- language := `CN`
- // 指标显示的语言
- {
- configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
- if configDetail != nil {
- language = configDetail.ConfigValue
- } else {
- configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
- if configDetail != nil {
- language = configDetail.ConfigValue
- }
- }
- }
- resp.Language = language
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 新增我的图表分类
- // @Description 新增我的图表接口
- // @Param request body data_manage.MyChartClassifyAddReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /classify/add [post]
- func (this *MyChartController) ClassifyAdd() {
- 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 data_manage.MyChartClassifyAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.MyChartClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- var condition string
- var pars []interface{}
- condition += " AND admin_id=? "
- pars = append(pars, sysUser.AdminId)
- condition += " AND my_chart_classify_name=? "
- pars = append(pars, req.MyChartClassifyName)
- count, err := data_manage.GetMyChartClassifyCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "分类已存在,请重新输入"
- br.IsSendEmail = false
- return
- }
- // 获取我的图库分类的最大排序值
- sort, err := data_manage.GetMyChartClassifyMinSort(sysUser.AdminId)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,获取最大排序失败,Err:" + err.Error()
- return
- }
- item := new(data_manage.MyChartClassify)
- item.AdminId = sysUser.AdminId
- item.MyChartClassifyName = req.MyChartClassifyName
- item.Sort = sort - 1
- item.ModifyTime = time.Now()
- item.CreateTime = time.Now()
- err = data_manage.AddMyChartClassify(item)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.MyChartLog)
- edbLog.MyChartId = 0
- edbLog.ChartInfoId = 0
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增分类"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddMyChartLog(edbLog)
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // @Title 编辑我的图表分类
- // @Description 编辑我的图表接口
- // @Param request body data_manage.MyChartClassifyEditReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /classify/edit [post]
- func (this *MyChartController) ClassifyEdit() {
- 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 data_manage.MyChartClassifyEditReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.MyChartClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "保存失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- if item == nil {
- br.Msg = "分类不存在"
- br.ErrMsg = "分类不存在,Err:" + err.Error()
- return
- }
- var condition string
- var pars []interface{}
- condition += " AND admin_id=? "
- pars = append(pars, sysUser.AdminId)
- condition += " AND my_chart_classify_name=? "
- pars = append(pars, req.MyChartClassifyName)
- condition += " AND my_chart_classify_id<>? "
- pars = append(pars, req.MyChartClassifyId)
- //判断名称是否已经存在
- count, err := data_manage.GetMyChartClassifyCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "分类已存在,请重新输入"
- br.IsSendEmail = false
- return
- }
- err = data_manage.ModifyMyChartClassify(req.MyChartClassifyId, req.MyChartClassifyName)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.MyChartLog)
- edbLog.MyChartId = 0
- edbLog.ChartInfoId = 0
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "编辑分类"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddMyChartLog(edbLog)
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // ClassifyMove
- // @Title 移动我的图表分类
- // @Description 移动我的图表分类接口
- // @Param request body data_manage.MyChartClassifyMoveReq true "type json string"
- // @Success 200 Ret=200 移动成功
- // @router /classify/move [post]
- func (this *MyChartController) ClassifyMove() {
- 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 data_manage.MyChartClassifyMoveReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- //查询该分类存不存在
- item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "移动失败,找不到该分类"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- if item == nil {
- br.Msg = "分类不存在"
- br.ErrMsg = "分类不存在,Err:" + err.Error()
- return
- }
- updateCol := make([]string, 0)
- //如果有传入 上一个兄弟节点分类id
- if req.PrevClassifyId > 0 {
- prevClassify, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.PrevClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果是移动在两个兄弟节点之间
- if req.NextClassifyId > 0 {
- //下一个兄弟节点
- nextClassify, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.NextClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
- if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == item.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = data_manage.UpdateMyChartClassifySortByClassifyId(sysUser.AdminId, prevClassify.MyChartClassifyId, prevClassify.Sort, updateSortStr)
- } else {
- //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
- if nextClassify.Sort-prevClassify.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = data_manage.UpdateMyChartClassifySortByClassifyId(sysUser.AdminId, 0, prevClassify.Sort, updateSortStr)
- }
- }
- }
- item.Sort = prevClassify.Sort + 1
- item.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
- firstClassify, err := data_manage.GetFirstMyChartClassifyByAdminId(sysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "移动失败"
- br.ErrMsg = "获取获取当前账号下的排序第一条的分类信息失败,Err:" + err.Error()
- return
- }
- //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
- if firstClassify != nil && firstClassify.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateMyChartClassifySortByClassifyId(sysUser.AdminId, firstClassify.MyChartClassifyId-1, 0, updateSortStr)
- }
- item.Sort = 0 //那就是排在第一位
- item.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
- //更新
- if len(updateCol) > 0 {
- err = item.Update(updateCol)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- }
- //新增操作日志
- {
- edbLog := new(data_manage.MyChartLog)
- edbLog.MyChartId = 0
- edbLog.ChartInfoId = 0
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "移动分类"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddMyChartLog(edbLog)
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // @Title 删除我的图表分类
- // @Description 删除我的图表接口
- // @Param request body data_manage.MyChartClassifyDeleteReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /classify/delete [post]
- func (this *MyChartController) ClassifyDelete() {
- 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 data_manage.MyChartClassifyDeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "保存失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- if item == nil {
- br.Msg = "分类已被删除"
- br.ErrMsg = "分类已被删除,Err:" + err.Error()
- return
- }
- nodeOb := new(data_manage.ChartFrameworkNode)
- cond := ` AND my_chart_classify_id = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, req.MyChartClassifyId)
- nodes, e := nodeOb.GetItemsByCondition(cond, pars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取我的图表分类关联的框架节点失败, Err: " + e.Error()
- return
- }
- if len(nodes) > 0 {
- br.Msg = "该图分类已添加节点链接, 不允许删除"
- return
- }
- //var condition string
- //var pars []interface{}
- //
- //condition += " AND admin_id=? "
- //pars = append(pars, sysUser.AdminId)
- //
- //condition += " AND my_chart_classify_id=? "
- //pars = append(pars, req.MyChartClassifyId)
- ////判断是否包含图表
- //count, err := data_manage.GetMyChartClassifyMappingCountByCondition(condition, pars)
- //if err != nil {
- // br.Msg = "保存失败"
- // br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
- // return
- //}
- //if count > 0 {
- // br.Msg = "此分类下含有图表,不可删除"
- // br.IsSendEmail = false
- // return
- //}
- err = data_manage.DeleteMyChartClassify(req.MyChartClassifyId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.MyChartLog)
- edbLog.MyChartId = 0
- edbLog.ChartInfoId = 0
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "删除分类"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddMyChartLog(edbLog)
- }
- br.Ret = 200
- br.Msg = "删除成功"
- br.Success = true
- br.IsAddLog = true
- }
- // @Title 新增我的图表
- // @Description 新增我的图表接口
- // @Param request body data_manage.MyChartAddReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /add [post]
- func (this *MyChartController) MyChartAdd() {
- 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 data_manage.MyChartAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败!"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- if chartItem == nil {
- br.Msg = "此图表已被删除!"
- br.ErrMsg = "此图表已被删除,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
- return
- }
- var condition string
- var pars []interface{}
- condition += " AND admin_id=? "
- pars = append(pars, sysUser.AdminId)
- condition += " AND chart_info_id=? "
- pars = append(pars, req.ChartInfoId)
- existItem, err := data_manage.GetMyChartDetailByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.MyChartAddResp)
- var myChartClassifyId string
- if existItem != nil { //修改
- fmt.Println("modify")
- for _, v := range req.MyChartClassifyId {
- myChartClassifyId += strconv.Itoa(v) + ","
- }
- resp.MyChartInfoId = existItem.MyChartId
- err = data_manage.MoveMyChartClassify(sysUser.AdminId, existItem.MyChartId, req.MyChartClassifyId)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存我的图表失败,MoveMyChartClassify,Err:" + err.Error()
- return
- }
- } else {
- myChart := &data_manage.MyChart{
- //MyChartId: 0,
- ChartInfoId: chartItem.ChartInfoId,
- Source: chartItem.Source,
- AdminId: sysUser.AdminId,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- newMyChartId, err := data_manage.AddMyChart(myChart)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存我的图表失败,Err:" + err.Error()
- return
- }
- //step := float64(65536)
- for _, v := range req.MyChartClassifyId {
- var sort float64
- // 查找最小排序值
- firstMapItem, _ := data_manage.GetMyChartSort(sysUser.AdminId, v, 0)
- if firstMapItem != nil {
- sort = firstMapItem.Sort
- }
- //获取最大的排序字段
- //count, _ := data_manage.GetMyChartMaxSort(sysUser.AdminId, v)
- mappingItem := new(data_manage.MyChartClassifyMapping)
- mappingItem.AdminId = sysUser.AdminId
- mappingItem.MyChartId = int(newMyChartId)
- mappingItem.MyChartClassifyId = v
- mappingItem.CreateTime = time.Now()
- mappingItem.ModifyTime = time.Now()
- //mappingItem.Sort = (float64(count) + 1) * step
- mappingItem.Sort = sort
- _, err = data_manage.AddMyChartClassifyMapping(mappingItem)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存我的图表AddMyChartClassifyMapping失败,Err:" + err.Error()
- return
- }
- myChartClassifyId += strconv.Itoa(v) + ","
- }
- //新增操作日志
- {
- edbLog := new(data_manage.MyChartLog)
- edbLog.MyChartId = myChart.MyChartId
- edbLog.ChartInfoId = myChart.ChartInfoId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增我的图表"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddMyChartLog(edbLog)
- }
- resp.MyChartInfoId = int(newMyChartId)
- }
- resp.MyChartClassifyId = strings.Trim(myChartClassifyId, ",")
- //更新es
- if resp.MyChartInfoId > 0 {
- go data.EsAddOrEditMyChartInfoByMyChartId(resp.MyChartInfoId)
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.Data = resp
- br.IsAddLog = true
- }
- // MyChartAddToClassify
- // @Title 将图表加入到我的图表分类
- // @Description 新增我的图表接口
- // @Param request body data_manage.MyChartAddReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /add_to_classify [post]
- func (this *MyChartController) MyChartAddToClassify() {
- 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 data_manage.MyChartAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败!"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- if chartItem == nil {
- br.Msg = "此图表已被删除!"
- br.ErrMsg = "此图表已被删除,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
- return
- }
- var condition string
- var pars []interface{}
- condition += " AND admin_id=? "
- pars = append(pars, sysUser.AdminId)
- condition += " AND chart_info_id=? "
- pars = append(pars, req.ChartInfoId)
- existItem, err := data_manage.GetMyChartDetailByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.MyChartAddResp)
- var myChartClassifyId string
- if existItem != nil { //修改
- fmt.Println("modify")
- for _, v := range req.MyChartClassifyId {
- myChartClassifyId += strconv.Itoa(v) + ","
- }
- resp.MyChartInfoId = existItem.MyChartId
- err = data_manage.AddMyChartToMyChartClassify(sysUser.AdminId, existItem.MyChartId, req.MyChartClassifyId)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存我的图表失败,MoveMyChartClassify,Err:" + err.Error()
- return
- }
- } else {
- myChart := &data_manage.MyChart{
- //MyChartId: 0,
- ChartInfoId: chartItem.ChartInfoId,
- Source: chartItem.Source,
- AdminId: sysUser.AdminId,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- newMyChartId, err := data_manage.AddMyChart(myChart)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存我的图表失败,Err:" + err.Error()
- return
- }
- step := float64(65536)
- for _, v := range req.MyChartClassifyId {
- //获取最大的排序字段
- count, _ := data_manage.GetMyChartMaxSort(sysUser.AdminId, v)
- mappingItem := new(data_manage.MyChartClassifyMapping)
- mappingItem.AdminId = sysUser.AdminId
- mappingItem.MyChartId = int(newMyChartId)
- mappingItem.MyChartClassifyId = v
- mappingItem.CreateTime = time.Now()
- mappingItem.ModifyTime = time.Now()
- mappingItem.Sort = (float64(count) + 1) * step
- _, err = data_manage.AddMyChartClassifyMapping(mappingItem)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存我的图表AddMyChartClassifyMapping失败,Err:" + err.Error()
- return
- }
- myChartClassifyId += strconv.Itoa(v) + ","
- }
- //新增操作日志
- {
- edbLog := new(data_manage.MyChartLog)
- edbLog.MyChartId = myChart.MyChartId
- edbLog.ChartInfoId = myChart.ChartInfoId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增我的图表"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddMyChartLog(edbLog)
- }
- resp.MyChartInfoId = int(newMyChartId)
- }
- resp.MyChartClassifyId = strings.Trim(myChartClassifyId, ",")
- //更新es
- if resp.MyChartInfoId > 0 {
- go data.EsAddOrEditMyChartInfoByMyChartId(resp.MyChartInfoId)
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.Data = resp
- br.IsAddLog = true
- }
- // GetMyChartClassifyIdList
- // @Title 根据我的图表id获取所属分类列表
- // @Description 根据我的图表id获取所属分类列表接口
- // @Param query ChartInfoId int `description:"图表id"`
- // @Success 200 {object} []int
- // @router /get_mychart_classify_id_list [get]
- func (this *MyChartController) GetMyChartClassifyIdList() {
- 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
- }
- chartInfoId, _ := this.GetInt("ChartInfoId")
- if chartInfoId <= 0 {
- br.Msg = "请传入图表id"
- br.IsSendEmail = false
- return
- }
- //图表分类id列表
- chartClassifyIdList := make([]int, 0)
- var condition string
- var pars []interface{}
- condition += " AND admin_id=? AND chart_info_id=? "
- pars = append(pars, sysUser.AdminId, chartInfoId)
- existItem, _ := data_manage.GetMyChartDetailByCondition(condition, pars)
- if existItem != nil {
- myChartClassifyList, err := data_manage.GetMyChartClassifyList(existItem.MyChartId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败!"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- for _, v := range myChartClassifyList {
- chartClassifyIdList = append(chartClassifyIdList, v.MyChartClassifyId)
- }
- }
- br.Ret = 200
- br.Msg = "获取成功"
- br.Success = true
- br.Data = chartClassifyIdList
- }
- // @Title 删除-我的图表-中的图表
- // @Description 删除-我的图表-中的图表接口
- // @Param request body data_manage.MyChartDeleteReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /delete [post]
- func (this *MyChartController) MyChartDelete() {
- setNxKey := "MyChartDelete_"
- deleteCache := true
- br := new(models.BaseResponse).Init()
- defer func() {
- if deleteCache {
- utils.Rc.Delete(setNxKey)
- }
- 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 data_manage.MyChartDeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- setNxKey += strconv.Itoa(req.MyChartId) + strconv.Itoa(req.MyChartClassifyId)
- if !utils.Rc.SetNX(setNxKey, 1, 3*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.IsSendEmail = false
- return
- }
- if req.MyChartId <= 0 {
- br.Msg = "参数错误!"
- br.ErrMsg = "参数错误,Err:" + string(this.Ctx.Input.RequestBody)
- return
- }
- isDelMyChart, err := data_manage.DeleteMyChart(req.MyChartId, req.MyChartClassifyId)
- if err != nil {
- br.Msg = "移除失败!"
- br.ErrMsg = "移除失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.MyChartLog)
- edbLog.MyChartId = 0
- edbLog.ChartInfoId = 0
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "删除-我的图表-中的图表"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddMyChartLog(edbLog)
- }
- if isDelMyChart {
- //如果确实删除了,那么就去ES同步删除
- go data.EsDeleteMyChartInfoByMyChartId(req.MyChartId)
- } else {
- //如果只是删除了关系,那么就去ES同步更新数据
- go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
- }
- br.Ret = 200
- br.Msg = "移除成功"
- br.Success = true
- br.IsAddLog = true
- }
- // @Title 编辑我的图表
- // @Description 编辑我的图表接口
- // @Param request body data_manage.MyChartEditReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /edit [post]
- func (this *MyChartController) MyChartEdit() {
- 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 data_manage.MyChartEditReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- for _, v := range req.MyChartClassifyId {
- myChartClassifyId := v
- count, _ := data_manage.GetMyChartClassifyMappingCount(sysUser.AdminId, req.MyChartId, myChartClassifyId)
- if count <= 0 {
- mappingItem := new(data_manage.MyChartClassifyMapping)
- mappingItem.AdminId = sysUser.AdminId
- mappingItem.MyChartId = req.MyChartId
- mappingItem.MyChartClassifyId = myChartClassifyId
- mappingItem.CreateTime = time.Now()
- _, err = data_manage.AddMyChartClassifyMapping(mappingItem)
- }
- }
- err = data_manage.DeleteMyChartClassifyMapping(sysUser.AdminId, req.MyChartId, req.CurrentMyChartClassifyId)
- if err != nil {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败,移除分类失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.MyChartLog)
- edbLog.MyChartId = 0
- edbLog.ChartInfoId = 0
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "编辑我的图表"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddMyChartLog(edbLog)
- }
- //更新es
- if req.MyChartId > 0 {
- go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // MyChartList
- // @Title 我的图表-列表接口
- // @Description 我的图表-列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param MyChartClassifyId query int true "我的图表分类id"
- // @Param MyChartId query int true "我的图表id"
- // @Param IsShared query bool false "是否可分享(如从图库框架请求的属于可分享的)"
- // @Success 200 {object} data_manage.MyChartListResp
- // @router /list [get]
- func (this *MyChartController) MyChartList() {
- 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
- }
- myChartClassifyId, _ := this.GetInt("MyChartClassifyId")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- myChartId, _ := this.GetInt("MyChartId")
- isShared, _ := this.GetBool("IsShared")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- chartAdminId := sysUser.AdminId
- if myChartClassifyId > 0 {
- condition += " AND c.my_chart_classify_id=? "
- pars = append(pars, myChartClassifyId)
- // 可共享
- if isShared {
- myClassify, e := data_manage.GetMyChartClassifyByClassifyId(myChartClassifyId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "分类已被删除, 请刷新页面"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类失败, Err: " + e.Error()
- return
- }
- chartAdminId = myClassify.AdminId
- }
- }
- condition += " AND (a.admin_id = ? OR d.is_public = 1)"
- pars = append(pars, chartAdminId)
- if myChartId > 0 {
- condition += " AND a.my_chart_id=? "
- pars = append(pars, myChartId)
- }
- // 获取当前账号的不可见指标
- noPermissionChartIdList := make([]int, 0)
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
- }
- }
- lenNoPermissionChartIdList := len(noPermissionChartIdList)
- if lenNoPermissionChartIdList > 0 {
- condition += ` AND b.chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
- pars = append(pars, noPermissionChartIdList)
- }
- //获取图表信息
- list, err := data_manage.GetMyChartListByCondition(condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
- return
- }
- myChartMap := make(map[int]int)
- chartInfoIds := ""
- chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
- for _, v := range myChartList {
- myChartMap[v.ChartInfoId] = v.ChartInfoId
- chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
- }
- if chartInfoIds != "" {
- chartInfoIds = strings.Trim(chartInfoIds, ",")
- //判断是否需要展示英文标识
- edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
- return
- }
- for _, v := range edbList {
- chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
- }
- }
- listLen := len(list)
- if listLen > 0 {
- // 分类id
- classifyIdList := make([]int, 0)
- // 当前列表中的分类map
- classifyMap := make(map[int]*data_manage.ChartClassify)
- for _, v := range list {
- classifyIdList = append(classifyIdList, v.ChartClassifyId)
- }
- classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ChartClassifyId] = v
- }
- // 已授权分类id
- permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- // 权限
- for i, chartViewInfo := range list {
- //判断是否需要展示英文标识
- if edbTmpList, ok := chartEdbMap[list[i].ChartInfoId]; ok {
- list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, edbTmpList, list[i].Source, list[i].ChartType)
- }
- if _, ok := myChartMap[list[i].ChartInfoId]; ok {
- list[i].IsAdd = true
- }
- // 数据权限
- if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
- list[i].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- } else if chartViewInfo.ChartClassifyId == 0 {
- list[i].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, 0, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- }
- }
- }
- resp := new(data_manage.MyChartListResp)
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*data_manage.MyChartList, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- total, err = data_manage.GetMyChartListCountByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取我的图表数据总数失败,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 移动我的图表接口
- // @Description 移动我的图表接口
- // @Success 200 {object} data_manage.MoveMyChartReq
- // @router /move [post]
- func (this *MyChartController) MyChartMove() {
- 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
- }
- adminId := sysUser.AdminId
- var req data_manage.MoveMyChartReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- //step := float64(65536)
- var newSort float64
- if req.PrevMyChartId <= 0 {
- firstMapItem, err := data_manage.GetMyChartSort(adminId, req.MyChartClassifyId, 0)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
- return
- }
- //if firstMapItem.Sort <= 0 {
- // firstSort := step / float64(2)
- // err = data_manage.MyChartMove(firstSort, adminId, firstMapItem.MyChartId, firstMapItem.MyChartClassifyId)
- // if err != nil {
- // br.Msg = "移动失败!"
- // br.ErrMsg = "移动失败,Err:" + err.Error()
- // return
- // }
- // newSort = step / float64(4)
- //} else {
- // newSort = firstMapItem.Sort / float64(2)
- //}
- newSort = firstMapItem.Sort - 1
- } else if req.NextMyChartId <= 0 {
- latestMapItem, err := data_manage.GetMyChartSort(adminId, req.MyChartClassifyId, 1)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
- return
- }
- //if latestMapItem.Sort <= 0 {
- // latestSort := step / float64(2)
- // err = data_manage.MyChartMove(latestSort, adminId, latestMapItem.MyChartId, latestMapItem.MyChartClassifyId)
- // if err != nil {
- // br.Msg = "移动失败!"
- // br.ErrMsg = "移动失败,Err:" + err.Error()
- // return
- // }
- // newSort = step / float64(4)
- //} else {
- // newSort = latestMapItem.Sort + (step / float64(2)) - 1
- //}
- newSort = latestMapItem.Sort + 1
- } else {
- preMapItem, err := data_manage.GetMyChartClassifyMapping(adminId, req.PrevMyChartId, req.MyChartClassifyId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
- return
- }
- nextMapItem, err := data_manage.GetMyChartClassifyMapping(adminId, req.NextMyChartId, req.MyChartClassifyId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
- return
- }
- newSort = (preMapItem.Sort + nextMapItem.Sort) / 2
- newSort = preMapItem.Sort + 1
- var updateSortStr string
- if preMapItem.Sort == nextMapItem.Sort {
- //变更兄弟节点的排序(sort同级)
- updateSortStr = `sort + 2`
- } else if nextMapItem.Sort-preMapItem.Sort == 1 {
- //变更兄弟节点的排序(sort只相差一级)
- updateSortStr = `sort + 1`
- }
- if updateSortStr != `` {
- _ = data_manage.UpdateMyChartSortByClassifyId(req.MyChartClassifyId, int(preMapItem.Sort), preMapItem.MyChartClassifyMappingId, updateSortStr)
- }
- }
- //if newSort >= 0 {
- //
- //} else {
- // utils.FileLog.Info("MyChartMove Sort=0:" + string(this.Ctx.Input.RequestBody))
- //}
- err = data_manage.MyChartMove(newSort, adminId, req.MyChartId, req.MyChartClassifyId)
- if err != nil {
- br.Msg = "移动失败!"
- br.ErrMsg = "移动失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.MyChartLog)
- edbLog.MyChartId = 0
- edbLog.ChartInfoId = 0
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "移动我的图表"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddMyChartLog(edbLog)
- }
- //更新es
- if req.MyChartId > 0 {
- go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "移动成功"
- br.IsAddLog = true
- }
- // @Title ETA图表-推荐列表接口
- // @Description ETA图表-推荐列表接口
- // @Param ChartClassifyId query int true "分类id"
- // @Success 200 {object} data_manage.ChartRecommendListResp
- // @router /chart/recommend/list [get]
- func (this *MyChartController) ChartRecommendList() {
- 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
- }
- pageSize := 6
- currentIndex := 1
- var startSize int
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if sysUser.AdminId > 0 {
- condition += " AND a.admin_id=? "
- pars = append(pars, sysUser.AdminId)
- }
- //获取图表信息
- list, err := data_manage.GetRecommendChartListByCondition(condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
- return
- }
- myChartMap := make(map[int]int)
- for _, v := range myChartList {
- myChartMap[v.ChartInfoId] = v.ChartInfoId
- }
- listLen := len(list)
- if listLen > 0 {
- // 分类id
- classifyIdList := make([]int, 0)
- // 当前列表中的分类map
- classifyMap := make(map[int]*data_manage.ChartClassify)
- for _, v := range list {
- classifyIdList = append(classifyIdList, v.ChartClassifyId)
- }
- classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ChartClassifyId] = v
- }
- // 已授权分类id
- permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- // 权限
- for k, chartViewInfo := range list {
- if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
- list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- }
- if _, ok := myChartMap[list[k].ChartInfoId]; ok {
- list[k].IsAdd = true
- }
- }
- }
- resp := new(data_manage.ChartRecommendListResp)
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*data_manage.ChartInfoView, 0)
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 我的图表-列表接口
- // @Description 我的图表-列表接口
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} data_manage.MyChartListResp
- // @router /search [get]
- func (this *MyChartController) MyChartSearch() {
- 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 condition string
- var pars []interface{}
- condition += " AND a.admin_id=? "
- pars = append(pars, sysUser.AdminId)
- keyWord := this.GetString("KeyWord")
- if keyWord != "" {
- condition += ` AND chart_name LIKE '%` + keyWord + `%' `
- }
- //获取图表信息
- list, err := data_manage.GetMyChartSearchByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- listLen := len(list)
- if listLen > 0 {
- // 分类id
- classifyIdList := make([]int, 0)
- // 当前列表中的分类map
- classifyMap := make(map[int]*data_manage.ChartClassify)
- for _, v := range list {
- classifyIdList = append(classifyIdList, v.ChartClassifyId)
- }
- classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ChartClassifyId] = v
- }
- // 已授权分类id
- permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- // 权限
- for k, chartViewInfo := range list {
- if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
- list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- }
- list[k].IsAdd = true
- }
- }
- resp := new(data_manage.MyChartSearchListResp)
- if list == nil {
- list = make([]*data_manage.MyChartList, 0)
- }
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // MyChartSearchByEs
- // @Title 我的图表-列表接口
- // @Description 我的图表-列表接口
- // @Param Keyword query string true "搜索关键词"
- // @Success 200 {object} data_manage.MyChartListResp
- // @router /search_by_es [get]
- func (this *MyChartController) MyChartSearchByEs() {
- 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
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyword := this.GetString("Keyword")
- // 获取当前账号的不可见指标
- noPermissionChartIdList := make([]int, 0)
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
- }
- }
- //获取图表信息
- list, total, err := data.EsSearchMyChartInfo(keyword, sysUser.AdminId, noPermissionChartIdList, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- lenList := len(list)
- if lenList <= 0 {
- list = make([]*data_manage.MyChartList, 0)
- } else {
- // 分类id
- classifyIdList := make([]int, 0)
- // 图表id
- chartInfoIdList := make([]int, 0)
- // 当前列表中的分类map
- chartClassifyMap := make(map[int]*data_manage.ChartClassify)
- // 当前列表中的图表map
- chartInfoMap := make(map[int]*data_manage.ChartInfo)
- for _, v := range list {
- classifyIdList = append(classifyIdList, v.ChartClassifyId)
- chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
- }
- // 分类
- {
- classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
- if err != nil {
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- }
- for _, tmpClassifyInfo := range classifyList {
- chartClassifyMap[tmpClassifyInfo.ChartClassifyId] = tmpClassifyInfo
- }
- }
- // 图表
- {
- tmpChartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
- return
- }
- for _, tmpChartInfo := range tmpChartList {
- chartInfoMap[tmpChartInfo.ChartInfoId] = tmpChartInfo
- }
- }
- // 已授权分类id
- permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- // 权限
- for k, tmpChartViewInfo := range list {
- list[k].IsAdd = true
- chartViewInfo, ok := chartInfoMap[tmpChartViewInfo.ChartInfoId]
- if !ok {
- continue
- }
- if currClassify, ok := chartClassifyMap[chartViewInfo.ChartClassifyId]; ok {
- list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- }
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp := data_manage.MyChartSearchListResp{
- List: list,
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // PublicClassifyList
- // @Title 我的图表-公共分类列表接口
- // @Description 我的图表-公共分类列表接口
- // @Success 200 {object} data_manage.MyChartClassifyResp
- // @router /classify/public_list [get]
- func (this *MyChartController) PublicClassifyList() {
- 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
- }
- //获取图表信息
- list, err := data_manage.GetPublicChartClassifyAllExceptMy(sysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取公共分类信息失败"
- br.ErrMsg = "获取公共分类信息失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.PublicChartClassifyResp)
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- resp.List = make([]data_manage.PublicChartClassifyList, 0)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- // 创建人姓名
- adminIdStr := make([]string, 0)
- for _, v := range list {
- adminIdStr = append(adminIdStr, fmt.Sprint(v.AdminId))
- }
- adminMap := make(map[int]string)
- adminList, _ := system.GetSysAdminByIdSlice(adminIdStr)
- if len(adminList) > 0 {
- for _, adminInfo := range adminList {
- adminMap[adminInfo.AdminId] = adminInfo.RealName
- }
- }
- respList := make([]data_manage.PublicChartClassifyList, 0)
- existMap := make(map[int]bool, 0)
- itemsMap := make(map[int][]data_manage.PublicChartClassifyItem, 0)
- for _, v := range list {
- realName := adminMap[v.AdminId]
- if realName == "" {
- // 忽略掉被删掉的用户
- continue
- }
- if itemsMap[v.AdminId] == nil {
- itemsMap[v.AdminId] = make([]data_manage.PublicChartClassifyItem, 0)
- }
- itemsMap[v.AdminId] = append(itemsMap[v.AdminId], data_manage.PublicChartClassifyItem{
- MyChartClassifyId: v.MyChartClassifyId,
- MyChartClassifyName: v.MyChartClassifyName,
- AdminId: v.AdminId,
- RealName: realName,
- IsPublic: v.IsPublic,
- IsCompanyPublic: v.IsCompanyPublic,
- })
- var menu data_manage.PublicChartClassifyList
- if existMap[v.AdminId] {
- continue
- }
- existMap[v.AdminId] = true
- menu.MenuAdminId = v.AdminId
- menu.MenuName = fmt.Sprintf("%s的图库", realName)
- respList = append(respList, menu)
- }
- for k, v := range respList {
- respList[k].Items = itemsMap[v.MenuAdminId]
- }
- resp.List = respList
- language := `CN`
- // 指标显示的语言
- {
- configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
- if configDetail != nil {
- language = configDetail.ConfigValue
- } else {
- configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
- if configDetail != nil {
- language = configDetail.ConfigValue
- }
- }
- }
- resp.Language = language
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ModifyClassifyPublicStatus
- // @Title 修改我的图表分类的是否可见
- // @Description 修改我的图表分类的是否可见接口
- // @Param request body data_manage.ModifyChartClassifyPublicReq true "type json string"
- // @Success 200 Ret=200 修改成功
- // @router /classify/modify_public [post]
- func (this *MyChartController) ModifyClassifyPublicStatus() {
- 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 data_manage.ModifyChartClassifyPublicReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- //查询该分类存不存在
- item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "修改失败,找不到该分类"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- if item == nil {
- br.Msg = "分类不存在"
- br.ErrMsg = "分类不存在,Err:" + err.Error()
- return
- }
- item.IsPublic = req.IsPublic
- item.PublicTime = time.Now()
- if req.IsPublic == 0 {
- // 取消公开同时取消客户公开
- item.IsCompanyPublic = 0
- }
- err = item.Update([]string{"IsPublic", "PublicTime", "IsCompanyPublic"})
- if err != nil {
- br.Msg = "修改失败"
- br.ErrMsg = "修改是否公开失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.MyChartLog)
- edbLog.MyChartId = 0
- edbLog.ChartInfoId = 0
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "修改分类是否公开"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddMyChartLog(edbLog)
- }
- br.Ret = 200
- br.Msg = "修改成功"
- br.Success = true
- br.IsAddLog = true
- }
- // CopyClassifyAndChart
- // @Title 复制我的图表分类
- // @Description 复制我的图表分类接口
- // @Param request body data_manage.CopyChartClassifyReq true "type json string"
- // @Success 200 Ret=200 复制成功
- // @router /classify/copy [post]
- func (this *MyChartController) CopyClassifyAndChart() {
- 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 data_manage.CopyChartClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- //查询该公共分类存不存在
- item, err := data_manage.GetPublicMyChartClassifyById(req.MyChartClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "复制失败,找不到该分类"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- if item == nil {
- br.Msg = "分类不存在"
- br.ErrMsg = "分类不存在,Err:" + err.Error()
- return
- }
- //获取所有的分类名称
- chartClassifyList, err := data_manage.GetMyChartClassifyAll(sysUser.AdminId)
- //生成新的分类名称
- newChartClassifyName := generateMyChartClassifyName(item.MyChartClassifyName, 1, chartClassifyList)
- //复制分类
- newMyChartClassify, err := data_manage.CopyPublicMyChartClassifyById(item.MyChartClassifyId, sysUser.AdminId, newChartClassifyName)
- if err != nil {
- br.Msg = "复制失败"
- br.ErrMsg = "复制失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.MyChartLog)
- edbLog.MyChartId = 0
- edbLog.ChartInfoId = 0
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "复制分类"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddMyChartLog(edbLog)
- }
- br.Data = newMyChartClassify
- br.Ret = 200
- br.Msg = "复制成功"
- br.Success = true
- br.IsAddLog = true
- }
- // generateMyChartClassifyName 生成我的图库分类名称
- func generateMyChartClassifyName(myChartClassifyName string, count int, chartClassifyList []*data_manage.MyChartClassify) (newChartClassifyName string) {
- newChartClassifyName = fmt.Sprint(myChartClassifyName, count)
- for _, v := range chartClassifyList {
- if v.MyChartClassifyName == newChartClassifyName {
- count++
- newChartClassifyName = generateMyChartClassifyName(fmt.Sprint(myChartClassifyName), count, chartClassifyList)
- return
- }
- }
- return
- }
- // ModifyClassifyPublicStatus
- // @Title 修改公共分类是否用户可见
- // @Description 修改公共分类是否用户可见接口
- // @Param request body data_manage.ModifyChartClassifyCompanyPublicReq true "type json string"
- // @Success 200 Ret=200 修改成功
- // @router /classify/modify_company_public [post]
- func (this *MyChartController) ModifyClassifyCompanyPublicStatus() {
- 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 data_manage.ModifyChartClassifyCompanyPublicReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- item, err := data_manage.GetPublicMyChartClassifyById(req.MyChartClassifyId)
- if err != nil {
- br.Msg = "找不到该分类"
- br.ErrMsg = "获取分类信息失败, Err:" + err.Error()
- return
- }
- if item.IsPublic != 1 {
- br.Msg = "该分类未公开,不可设置为用户可见"
- br.ErrMsg = "该分类未公开,不可设置为用户可见"
- return
- }
- item.IsCompanyPublic = req.IsCompanyPublic
- item.CompanyPublicTime = time.Now()
- err = item.Update([]string{"IsCompanyPublic", "CompanyPublicTime"})
- if err != nil {
- br.Msg = "修改失败"
- br.ErrMsg = "修改是否用户可见失败, Err:" + err.Error()
- return
- }
- {
- edbLog := new(data_manage.MyChartLog)
- edbLog.MyChartId = 0
- edbLog.ChartInfoId = 0
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "修改用户是否可见"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddMyChartLog(edbLog)
- }
- br.Ret = 200
- br.Msg = "修改成功"
- br.Success = true
- br.IsAddLog = true
- }
- // CompanyPublicClassifyList
- // @Title 我的图表-用户可见分类列表
- // @Description 我的图表-用户可见分类列表接口
- // @Param Keyword query string false "分类名称关键词"
- // @Success 200 {object} data_manage.MyChartClassifyResp
- // @router /classify/company_public_list [get]
- func (this *MyChartController) CompanyPublicClassifyList() {
- 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 condition string
- var pars []interface{}
- keyword := this.GetString("Keyword")
- if keyword != "" {
- keyword = "%" + keyword + "%"
- condition += ` AND my_chart_classify_name LIKE ? `
- pars = append(pars, keyword)
- }
- list, err := data_manage.GetCompanyPublicClassifyList(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取用户可见分类列表失败"
- br.ErrMsg = "获取用户可见分类列表失败, Err:" + err.Error()
- return
- }
- resp := new(data_manage.MyChartClassifyResp)
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*data_manage.MyChartClassifyItem, 0)
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- results := make([]*data_manage.MyChartClassifyItem, 0)
- for _, v := range list {
- results = append(results, data_manage.FormatMyChartClassify2Item(v, 0))
- }
- resp.List = results
- //resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- //func init() {
- // data.AddAllMyChartInfo()
- //}
- // ClassifyFrameworkNodeList
- // @Title 我的图表分类-关联的框架节点列表
- // @Description 我的图表分类-关联的框架节点列表
- // @Param MyChartClassifyId query int false "图表分类ID"
- // @Success 200 Ret=200 获取成功
- // @router /classify/framework_node_list [get]
- func (this *MyChartController) ClassifyFrameworkNodeList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = true
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- classifyId, _ := this.GetInt("MyChartClassifyId")
- if classifyId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, MyChartClassifyId: %d", classifyId)
- return
- }
- _, e := data_manage.GetMyChartClassifyById(sysUser.AdminId, classifyId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "分类不存在, 请刷新页面"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类信息失败, Err:" + e.Error()
- return
- }
- nodeOb := new(data_manage.ChartFrameworkNode)
- cond := ` AND my_chart_classify_id = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, classifyId)
- nodes, e := nodeOb.GetItemsByCondition(cond, pars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取我的图表分类关联的框架节点失败, Err: " + e.Error()
- return
- }
- resp := make([]*data_manage.ChartFrameworkNodeItem, 0)
- for _, v := range nodes {
- resp = append(resp, data_manage.FormatChartFrameworkNode2Item(v, 0))
- }
- br.Data = resp
- br.Ret = 200
- br.Msg = "获取成功"
- br.Success = true
- }
|