1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975 |
- package data_manage
- import (
- "encoding/json"
- "eta/eta_mobile/controllers"
- "eta/eta_mobile/models"
- "eta/eta_mobile/models/data_manage"
- "eta/eta_mobile/models/system"
- "eta/eta_mobile/services/data"
- "eta/eta_mobile/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strconv"
- "strings"
- "time"
- )
- // MyChartController 我的图库
- type MyChartController struct {
- controllers.BaseAuthController
- }
- // ChartList
- // @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)
- if chartClassifyId > 0 {
- 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(" + chartClassifyId + ") "
- //pars = append(pars, chartClassifyId)
- }
- if keyWord != "" {
- condition += ` AND ( chart_name 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 {
- 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.MyChartClassify, 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
- }
- // ClassifyAdd
- // @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.GetMyChartClassifyMastSort(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
- }
- // ClassifyEdit
- // @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
- }
- // ClassifyDelete
- // @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
- }
- //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
- }
- // MyChartAdd
- // @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 {
- //获取最大的排序字段
- //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 = 0
- _, 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
- }
- // MyChartDelete
- // @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
- }
- // MyChartEdit
- // @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"
- // @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")
- 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 (a.admin_id=? or d.is_public=1)"
- pars = append(pars, sysUser.AdminId)
- if myChartClassifyId > 0 {
- condition += " AND c.my_chart_classify_id=? "
- pars = append(pars, myChartClassifyId)
- }
- 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)
- 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 _, ok := myChartMap[list[i].ChartInfoId]; ok {
- list[i].IsAdd = true
- }
- }
- 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
- }
- // MyChartMove
- // @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)
- }
- } 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
- }
- } 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
- }
- if newSort >= 0 {
- err = data_manage.MyChartMove(newSort, adminId, req.MyChartId, req.MyChartClassifyId)
- if err != nil {
- br.Msg = "移动失败!"
- br.ErrMsg = "移动失败,Err:" + err.Error()
- return
- }
- } else {
- utils.FileLog.Info("MyChartMove Sort=0:" + string(this.Ctx.Input.RequestBody))
- }
- //新增操作日志
- {
- 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
- }
- // ChartRecommendList
- // @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)
- for i := 0; i < listLen; i++ {
- if _, ok := myChartMap[list[i].ChartInfoId]; ok {
- list[i].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
- }
- // MyChartSearch
- // @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)
- for i := 0; i < listLen; i++ {
- list[i].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
- }
- if len(list) <= 0 {
- list = make([]*data_manage.MyChartList, 0)
- }
- for _, v := range list {
- v.IsAdd = true
- }
- 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()) {
- items := make([]data_manage.PublicChartClassifyItem, 0)
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- publicChartClassifyItemList := make([]data_manage.PublicChartClassifyItem, 0)
- 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
- }
- }
- for _, v := range list {
- realName, ok := adminMap[v.AdminId]
- if !ok {
- realName = ``
- }
- publicChartClassifyItem := data_manage.PublicChartClassifyItem{
- MyChartClassifyId: v.MyChartClassifyId,
- MyChartClassifyName: v.MyChartClassifyName,
- AdminId: v.AdminId,
- RealName: realName,
- IsPublic: v.IsPublic,
- IsCompanyPublic: v.IsCompanyPublic,
- }
- publicChartClassifyItemList = append(publicChartClassifyItemList, publicChartClassifyItem)
- }
- resp.List = publicChartClassifyItemList
- 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
- }
- // Locate
- // @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/locate [get]
- func (this *MyChartController) Locate() {
- 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
- }
- classifyId, _ := this.GetInt("ChartClassifyId")
- keyword := this.GetString("KeyWord")
- mine, _ := this.GetBool("IsShowMe") // 只看我的
- condition := ` AND source = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, utils.CHART_SOURCE_DEFAULT) // 普通图表
- orderRule := ``
- {
- if keyword != "" {
- k := fmt.Sprint("%", keyword, "%")
- condition += ` AND chart_name LIKE ?`
- pars = append(pars, k)
- }
- if mine {
- condition += ` AND sys_user_id = ?`
- pars = append(pars, sysUser.AdminId)
- }
- if classifyId > 0 {
- strIds, e := data_manage.GetChartClassify(classifyId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表分类信息失败, GetChartClassify Err: " + e.Error()
- return
- }
- if strIds == "" {
- br.Msg = "获取失败"
- br.ErrMsg = "图表分类为空"
- return
- }
- condition += fmt.Sprintf(` AND chart_classify_id IN (%s)`, strIds)
- }
- }
- // 当前账号的不可见指标
- {
- ids := make([]int, 0)
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- conf, e := obj.GetAllChartListByAdminId(sysUser.AdminId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置失败, Err: " + e.Error()
- return
- }
- for _, v := range conf {
- ids = append(ids, v.ChartInfoId)
- }
- if len(ids) > 0 {
- condition += fmt.Sprintf(` AND chart_info_id NOT IN (%s)`, utils.GetOrmInReplace(len(ids)))
- pars = append(pars, ids)
- }
- }
- // 获取图表
- list := make([]*data_manage.ChartInfoLocate, 0)
- charts, e := data_manage.GetChartItems(condition, pars, orderRule)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表列表失败, Err: " + e.Error()
- return
- }
- if len(charts) == 0 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- return
- }
- // 二级分类
- classifies, e := data_manage.GetSecondaryChartClassifyWithSort()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表分类排序失败, Err: " + e.Error()
- return
- }
- classifyIdName := make(map[int]string)
- for _, c := range classifies {
- classifyIdName[c.ChartClassifyId] = c.ChartClassifyName
- }
- // 分类ID大于0时, 优先分类排序, 其次图表排序
- if classifyId > 0 {
- for _, cl := range classifies {
- for _, ch := range charts {
- if ch.ChartClassifyId != cl.ChartClassifyId {
- continue
- }
- v := new(data_manage.ChartInfoLocate)
- v.ChartInfoId = ch.ChartInfoId
- v.ChartName = ch.ChartName
- v.ChartType = ch.ChartType
- v.ChartClassifyId = ch.ChartClassifyId
- v.ChartClassifyName = cl.ChartClassifyName
- v.UniqueCode = ch.UniqueCode
- v.Source = ch.Source
- v.StartDate = ch.StartDate
- v.EndDate = ch.EndDate
- v.SeasonStartDate = ch.SeasonStartDate
- v.SeasonEndDate = ch.SeasonEndDate
- v.DateType = ch.DateType
- v.Calendar = ch.Calendar
- list = append(list, v)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- return
- }
- // 分类ID为0时
- for _, ch := range charts {
- v := new(data_manage.ChartInfoLocate)
- v.ChartInfoId = ch.ChartInfoId
- v.ChartName = ch.ChartName
- v.ChartType = ch.ChartType
- v.ChartClassifyId = ch.ChartClassifyId
- v.ChartClassifyName = classifyIdName[v.ChartClassifyId]
- v.UniqueCode = ch.UniqueCode
- v.Source = ch.Source
- v.StartDate = ch.StartDate
- v.EndDate = ch.EndDate
- v.SeasonStartDate = ch.SeasonStartDate
- v.SeasonEndDate = ch.SeasonEndDate
- v.DateType = ch.DateType
- v.Calendar = ch.Calendar
- list = append(list, v)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
|