123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307 |
- package data_manage
- import (
- "encoding/json"
- "eta_gn/eta_api/controllers"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/models/system"
- "eta_gn/eta_api/services/data"
- "eta_gn/eta_api/services/data/data_manage_permission"
- "eta_gn/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "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 "搜索关键词"
- // @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 && !utils.IsErrNoRow(err) {
- 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 + `%' OR chart_name_en LIKE '%` + keyWord + `%' )`
- }
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- 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 && utils.IsErrNoRow(err)) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- br.Success = true
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.MyChartClassifyResp)
- if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- br.Msg = "移动失败"
- br.ErrMsg = "获取获取当前账号下的排序第一条的分类信息失败,Err:" + err.Error()
- return
- }
- //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
- if firstClassify != nil && firstClassify.MyChartClassifyId > 0 && 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- 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 utils.IsErrNoRow(e) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- 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 && utils.IsErrNoRow(err)) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- 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 && utils.IsErrNoRow(err)) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- br.Success = true
- br.Msg = "获取公共分类信息失败"
- br.ErrMsg = "获取公共分类信息失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.PublicChartClassifyResp)
- if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- br.Success = true
- br.Msg = "获取用户可见分类列表失败"
- br.ErrMsg = "获取用户可见分类列表失败, Err:" + err.Error()
- return
- }
- resp := new(data_manage.MyChartClassifyResp)
- if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
- 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
- }
- // 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 utils.IsErrNoRow(e) {
- 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
- }
|