my_chart.go 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/data_manage"
  7. "eta_gn/eta_api/models/system"
  8. "eta_gn/eta_api/services/data"
  9. "eta_gn/eta_api/services/data/data_manage_permission"
  10. "eta_gn/eta_api/utils"
  11. "fmt"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // 我的图库
  18. type MyChartController struct {
  19. controllers.BaseAuthController
  20. }
  21. // @Title ETA图表列表接口
  22. // @Description ETA图表列表接口
  23. // @Param PageSize query int true "每页数据条数"
  24. // @Param CurrentIndex query int true "当前页页码,从1开始"
  25. // @Param ChartClassifyId query int true "分类id"
  26. // @Param KeyWord query string true "搜索关键词"
  27. // @Success 200 {object} data_manage.ChartListResp
  28. // @router /chart/list [get]
  29. func (this *MyChartController) ChartList() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. sysUser := this.SysUser
  36. if sysUser == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录,SysUser Is Empty"
  39. br.Ret = 408
  40. return
  41. }
  42. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  43. pageSize, _ := this.GetInt("PageSize")
  44. currentIndex, _ := this.GetInt("CurrentIndex")
  45. keyWord := this.GetString("KeyWord")
  46. var total int
  47. page := paging.GetPaging(currentIndex, pageSize, total)
  48. var startSize int
  49. if pageSize <= 0 {
  50. pageSize = utils.PageSize20
  51. }
  52. if currentIndex <= 0 {
  53. currentIndex = 1
  54. }
  55. startSize = paging.StartIndex(currentIndex, pageSize)
  56. var condition string
  57. var pars []interface{}
  58. // 普通图表
  59. condition += ` AND source = ? `
  60. pars = append(pars, utils.CHART_SOURCE_DEFAULT)
  61. if chartClassifyId > 0 {
  62. chartClassifyId, err := data_manage.GetChartClassify(chartClassifyId)
  63. if err != nil && !utils.IsErrNoRow(err) {
  64. br.Msg = "获取图表信息失败"
  65. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  66. return
  67. }
  68. condition += " AND chart_classify_id IN(" + chartClassifyId + ") "
  69. //pars = append(pars, chartClassifyId)
  70. }
  71. if keyWord != "" {
  72. condition += ` AND ( chart_name LIKE '%` + keyWord + `%' OR chart_name_en LIKE '%` + keyWord + `%' )`
  73. }
  74. condition += ` AND sys_user_id = ? `
  75. pars = append(pars, sysUser.AdminId)
  76. // 获取当前账号的不可见指标
  77. noPermissionChartIdList := make([]int, 0)
  78. {
  79. obj := data_manage.EdbInfoNoPermissionAdmin{}
  80. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  81. if err != nil && !utils.IsErrNoRow(err) {
  82. br.Msg = "获取失败"
  83. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  84. return
  85. }
  86. for _, v := range confList {
  87. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  88. }
  89. }
  90. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  91. if lenNoPermissionChartIdList > 0 {
  92. condition += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  93. pars = append(pars, noPermissionChartIdList)
  94. }
  95. //获取图表信息
  96. list, err := data_manage.GetChartListByCondition(condition, pars, startSize, pageSize)
  97. if err != nil && !utils.IsErrNoRow(err) {
  98. br.Success = true
  99. br.Msg = "获取图表信息失败"
  100. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  101. return
  102. }
  103. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  104. if err != nil && !utils.IsErrNoRow(err) {
  105. br.Msg = "获取图表信息失败"
  106. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  107. return
  108. }
  109. myChartMap := make(map[int]*data_manage.MyChartView)
  110. for _, v := range myChartList {
  111. myChartMap[v.ChartInfoId] = v
  112. }
  113. listLen := len(list)
  114. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  115. if listLen > 0 {
  116. // 分类id
  117. classifyIdList := make([]int, 0)
  118. // 当前列表中的分类map
  119. classifyMap := make(map[int]*data_manage.ChartClassify)
  120. for _, v := range list {
  121. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  122. }
  123. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  124. if err != nil {
  125. br.Msg = "获取失败"
  126. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  127. return
  128. }
  129. for _, v := range classifyList {
  130. classifyMap[v.ChartClassifyId] = v
  131. }
  132. // 已授权分类id
  133. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  134. if err != nil {
  135. br.Msg = "获取失败"
  136. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  137. return
  138. }
  139. // 权限
  140. for k, chartViewInfo := range list {
  141. if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
  142. list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  143. }
  144. }
  145. chartInfoIds := ""
  146. for _, v := range list {
  147. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  148. }
  149. if chartInfoIds != "" {
  150. chartInfoIds = strings.Trim(chartInfoIds, ",")
  151. //判断是否需要展示英文标识
  152. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  153. if e != nil {
  154. br.Msg = "获取失败"
  155. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  156. return
  157. }
  158. for _, v := range edbList {
  159. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  160. }
  161. }
  162. }
  163. for i := 0; i < listLen; i++ {
  164. //判断是否需要展示英文标识
  165. if edbTmpList, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  166. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, edbTmpList, list[i].Source, list[i].ChartType)
  167. }
  168. if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
  169. list[i].IsAdd = true
  170. list[i].MyChartId = existItem.MyChartId
  171. list[i].MyChartClassifyId = existItem.MyChartClassifyId
  172. }
  173. }
  174. resp := new(data_manage.ChartListResp)
  175. if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
  176. items := make([]*data_manage.ChartInfoView, 0)
  177. resp.Paging = page
  178. resp.List = items
  179. br.Ret = 200
  180. br.Success = true
  181. br.Msg = "获取成功"
  182. return
  183. }
  184. dataCount, err := data_manage.GetChartListCountByCondition(condition, pars)
  185. if err != nil && !utils.IsErrNoRow(err) {
  186. br.Msg = "获取指标信息失败"
  187. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  188. return
  189. }
  190. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  191. resp.Paging = page
  192. resp.List = list
  193. br.Ret = 200
  194. br.Success = true
  195. br.Msg = "获取成功"
  196. br.Data = resp
  197. }
  198. // ClassifyList
  199. // @Title 我的图表-分类列表接口
  200. // @Description 我的图表-分类列表接口
  201. // @Success 200 {object} data_manage.MyChartClassifyResp
  202. // @router /classify/list [get]
  203. func (this *MyChartController) ClassifyList() {
  204. br := new(models.BaseResponse).Init()
  205. defer func() {
  206. this.Data["json"] = br
  207. this.ServeJSON()
  208. }()
  209. sysUser := this.SysUser
  210. if sysUser == nil {
  211. br.Msg = "请登录"
  212. br.ErrMsg = "请登录,SysUser Is Empty"
  213. br.Ret = 408
  214. return
  215. }
  216. //获取图表信息
  217. list, err := data_manage.GetMyChartClassifyAll(sysUser.AdminId)
  218. if err != nil && !utils.IsErrNoRow(err) {
  219. br.Success = true
  220. br.Msg = "获取分类信息失败"
  221. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  222. return
  223. }
  224. resp := new(data_manage.MyChartClassifyResp)
  225. if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
  226. items := make([]*data_manage.MyChartClassifyItem, 0)
  227. resp.List = items
  228. br.Ret = 200
  229. br.Success = true
  230. br.Msg = "获取成功"
  231. return
  232. }
  233. //resp.List = list
  234. // 获取图表分类下各自的图表数
  235. chartsNumMap, e := data.GetMyChartClassifyIdNumMap(sysUser.AdminId)
  236. if e != nil {
  237. br.Msg = "获取失败"
  238. br.ErrMsg = "获取失败, GetMyChartClassifyIdNumMap Err: " + e.Error()
  239. return
  240. }
  241. results := make([]*data_manage.MyChartClassifyItem, 0)
  242. for _, v := range list {
  243. results = append(results, data_manage.FormatMyChartClassify2Item(v, chartsNumMap[v.MyChartClassifyId]))
  244. }
  245. resp.List = results
  246. language := `CN`
  247. // 指标显示的语言
  248. {
  249. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  250. if configDetail != nil {
  251. language = configDetail.ConfigValue
  252. } else {
  253. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  254. if configDetail != nil {
  255. language = configDetail.ConfigValue
  256. }
  257. }
  258. }
  259. resp.Language = language
  260. br.Ret = 200
  261. br.Success = true
  262. br.Msg = "获取成功"
  263. br.Data = resp
  264. }
  265. // @Title 新增我的图表分类
  266. // @Description 新增我的图表接口
  267. // @Param request body data_manage.MyChartClassifyAddReq true "type json string"
  268. // @Success 200 Ret=200 保存成功
  269. // @router /classify/add [post]
  270. func (this *MyChartController) ClassifyAdd() {
  271. br := new(models.BaseResponse).Init()
  272. defer func() {
  273. this.Data["json"] = br
  274. this.ServeJSON()
  275. }()
  276. sysUser := this.SysUser
  277. if sysUser == nil {
  278. br.Msg = "请登录"
  279. br.ErrMsg = "请登录,SysUser Is Empty"
  280. br.Ret = 408
  281. return
  282. }
  283. var req data_manage.MyChartClassifyAddReq
  284. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  285. if err != nil {
  286. br.Msg = "参数解析异常!"
  287. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  288. return
  289. }
  290. if req.MyChartClassifyName == "" {
  291. br.Msg = "请输入分类名称"
  292. br.IsSendEmail = false
  293. return
  294. }
  295. var condition string
  296. var pars []interface{}
  297. condition += " AND admin_id=? "
  298. pars = append(pars, sysUser.AdminId)
  299. condition += " AND my_chart_classify_name=? "
  300. pars = append(pars, req.MyChartClassifyName)
  301. count, err := data_manage.GetMyChartClassifyCountByCondition(condition, pars)
  302. if err != nil {
  303. br.Msg = "保存失败"
  304. br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  305. return
  306. }
  307. if count > 0 {
  308. br.Msg = "分类已存在,请重新输入"
  309. br.IsSendEmail = false
  310. return
  311. }
  312. // 获取我的图库分类的最大排序值
  313. sort, err := data_manage.GetMyChartClassifyMinSort(sysUser.AdminId)
  314. if err != nil {
  315. br.Msg = "保存失败"
  316. br.ErrMsg = "保存失败,获取最大排序失败,Err:" + err.Error()
  317. return
  318. }
  319. item := new(data_manage.MyChartClassify)
  320. item.AdminId = sysUser.AdminId
  321. item.MyChartClassifyName = req.MyChartClassifyName
  322. item.Sort = sort - 1
  323. item.ModifyTime = time.Now()
  324. item.CreateTime = time.Now()
  325. err = data_manage.AddMyChartClassify(item)
  326. if err != nil {
  327. br.Msg = "保存失败"
  328. br.ErrMsg = "保存失败,Err:" + err.Error()
  329. return
  330. }
  331. //新增操作日志
  332. {
  333. edbLog := new(data_manage.MyChartLog)
  334. edbLog.MyChartId = 0
  335. edbLog.ChartInfoId = 0
  336. edbLog.SysUserId = sysUser.AdminId
  337. edbLog.SysUserRealName = sysUser.RealName
  338. edbLog.CreateTime = time.Now()
  339. edbLog.Content = string(this.Ctx.Input.RequestBody)
  340. edbLog.Status = "新增分类"
  341. edbLog.Method = this.Ctx.Input.URI()
  342. go data_manage.AddMyChartLog(edbLog)
  343. }
  344. br.Ret = 200
  345. br.Msg = "保存成功"
  346. br.Success = true
  347. br.IsAddLog = true
  348. }
  349. // @Title 编辑我的图表分类
  350. // @Description 编辑我的图表接口
  351. // @Param request body data_manage.MyChartClassifyEditReq true "type json string"
  352. // @Success 200 Ret=200 保存成功
  353. // @router /classify/edit [post]
  354. func (this *MyChartController) ClassifyEdit() {
  355. br := new(models.BaseResponse).Init()
  356. defer func() {
  357. this.Data["json"] = br
  358. this.ServeJSON()
  359. }()
  360. sysUser := this.SysUser
  361. if sysUser == nil {
  362. br.Msg = "请登录"
  363. br.ErrMsg = "请登录,SysUser Is Empty"
  364. br.Ret = 408
  365. return
  366. }
  367. var req data_manage.MyChartClassifyEditReq
  368. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  369. if err != nil {
  370. br.Msg = "参数解析异常!"
  371. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  372. return
  373. }
  374. if req.MyChartClassifyName == "" {
  375. br.Msg = "请输入分类名称"
  376. br.IsSendEmail = false
  377. return
  378. }
  379. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  380. if err != nil && !utils.IsErrNoRow(err) {
  381. br.Msg = "保存失败"
  382. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  383. return
  384. }
  385. if item == nil {
  386. br.Msg = "分类不存在"
  387. br.ErrMsg = "分类不存在,Err:" + err.Error()
  388. return
  389. }
  390. var condition string
  391. var pars []interface{}
  392. condition += " AND admin_id=? "
  393. pars = append(pars, sysUser.AdminId)
  394. condition += " AND my_chart_classify_name=? "
  395. pars = append(pars, req.MyChartClassifyName)
  396. condition += " AND my_chart_classify_id<>? "
  397. pars = append(pars, req.MyChartClassifyId)
  398. //判断名称是否已经存在
  399. count, err := data_manage.GetMyChartClassifyCountByCondition(condition, pars)
  400. if err != nil {
  401. br.Msg = "保存失败"
  402. br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  403. return
  404. }
  405. if count > 0 {
  406. br.Msg = "分类已存在,请重新输入"
  407. br.IsSendEmail = false
  408. return
  409. }
  410. err = data_manage.ModifyMyChartClassify(req.MyChartClassifyId, req.MyChartClassifyName)
  411. if err != nil {
  412. br.Msg = "保存失败"
  413. br.ErrMsg = "保存失败,Err:" + err.Error()
  414. return
  415. }
  416. //新增操作日志
  417. {
  418. edbLog := new(data_manage.MyChartLog)
  419. edbLog.MyChartId = 0
  420. edbLog.ChartInfoId = 0
  421. edbLog.SysUserId = sysUser.AdminId
  422. edbLog.SysUserRealName = sysUser.RealName
  423. edbLog.CreateTime = time.Now()
  424. edbLog.Content = string(this.Ctx.Input.RequestBody)
  425. edbLog.Status = "编辑分类"
  426. edbLog.Method = this.Ctx.Input.URI()
  427. go data_manage.AddMyChartLog(edbLog)
  428. }
  429. br.Ret = 200
  430. br.Msg = "保存成功"
  431. br.Success = true
  432. br.IsAddLog = true
  433. }
  434. // ClassifyMove
  435. // @Title 移动我的图表分类
  436. // @Description 移动我的图表分类接口
  437. // @Param request body data_manage.MyChartClassifyMoveReq true "type json string"
  438. // @Success 200 Ret=200 移动成功
  439. // @router /classify/move [post]
  440. func (this *MyChartController) ClassifyMove() {
  441. br := new(models.BaseResponse).Init()
  442. defer func() {
  443. this.Data["json"] = br
  444. this.ServeJSON()
  445. }()
  446. sysUser := this.SysUser
  447. if sysUser == nil {
  448. br.Msg = "请登录"
  449. br.ErrMsg = "请登录,SysUser Is Empty"
  450. br.Ret = 408
  451. return
  452. }
  453. var req data_manage.MyChartClassifyMoveReq
  454. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  455. if err != nil {
  456. br.Msg = "参数解析异常!"
  457. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  458. return
  459. }
  460. //查询该分类存不存在
  461. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  462. if err != nil && !utils.IsErrNoRow(err) {
  463. br.Msg = "移动失败,找不到该分类"
  464. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  465. return
  466. }
  467. if item == nil {
  468. br.Msg = "分类不存在"
  469. br.ErrMsg = "分类不存在,Err:" + err.Error()
  470. return
  471. }
  472. updateCol := make([]string, 0)
  473. //如果有传入 上一个兄弟节点分类id
  474. if req.PrevClassifyId > 0 {
  475. prevClassify, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.PrevClassifyId)
  476. if err != nil {
  477. br.Msg = "移动失败"
  478. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  479. return
  480. }
  481. //如果是移动在两个兄弟节点之间
  482. if req.NextClassifyId > 0 {
  483. //下一个兄弟节点
  484. nextClassify, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.NextClassifyId)
  485. if err != nil {
  486. br.Msg = "移动失败"
  487. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  488. return
  489. }
  490. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  491. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == item.Sort {
  492. //变更兄弟节点的排序
  493. updateSortStr := `sort + 2`
  494. _ = data_manage.UpdateMyChartClassifySortByClassifyId(sysUser.AdminId, prevClassify.MyChartClassifyId, prevClassify.Sort, updateSortStr)
  495. } else {
  496. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  497. if nextClassify.Sort-prevClassify.Sort == 1 {
  498. //变更兄弟节点的排序
  499. updateSortStr := `sort + 1`
  500. _ = data_manage.UpdateMyChartClassifySortByClassifyId(sysUser.AdminId, 0, prevClassify.Sort, updateSortStr)
  501. }
  502. }
  503. }
  504. item.Sort = prevClassify.Sort + 1
  505. item.ModifyTime = time.Now()
  506. updateCol = append(updateCol, "Sort", "ModifyTime")
  507. } else {
  508. firstClassify, err := data_manage.GetFirstMyChartClassifyByAdminId(sysUser.AdminId)
  509. if err != nil && !utils.IsErrNoRow(err) {
  510. br.Msg = "移动失败"
  511. br.ErrMsg = "获取获取当前账号下的排序第一条的分类信息失败,Err:" + err.Error()
  512. return
  513. }
  514. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  515. if firstClassify != nil && firstClassify.MyChartClassifyId > 0 && firstClassify.Sort == 0 {
  516. updateSortStr := ` sort + 1 `
  517. _ = data_manage.UpdateMyChartClassifySortByClassifyId(sysUser.AdminId, firstClassify.MyChartClassifyId-1, 0, updateSortStr)
  518. }
  519. item.Sort = 0 //那就是排在第一位
  520. item.ModifyTime = time.Now()
  521. updateCol = append(updateCol, "Sort", "ModifyTime")
  522. }
  523. //更新
  524. if len(updateCol) > 0 {
  525. err = item.Update(updateCol)
  526. if err != nil {
  527. br.Msg = "移动失败"
  528. br.ErrMsg = "修改失败,Err:" + err.Error()
  529. return
  530. }
  531. }
  532. //新增操作日志
  533. {
  534. edbLog := new(data_manage.MyChartLog)
  535. edbLog.MyChartId = 0
  536. edbLog.ChartInfoId = 0
  537. edbLog.SysUserId = sysUser.AdminId
  538. edbLog.SysUserRealName = sysUser.RealName
  539. edbLog.CreateTime = time.Now()
  540. edbLog.Content = string(this.Ctx.Input.RequestBody)
  541. edbLog.Status = "移动分类"
  542. edbLog.Method = this.Ctx.Input.URI()
  543. go data_manage.AddMyChartLog(edbLog)
  544. }
  545. br.Ret = 200
  546. br.Msg = "保存成功"
  547. br.Success = true
  548. br.IsAddLog = true
  549. }
  550. // @Title 删除我的图表分类
  551. // @Description 删除我的图表接口
  552. // @Param request body data_manage.MyChartClassifyDeleteReq true "type json string"
  553. // @Success 200 Ret=200 保存成功
  554. // @router /classify/delete [post]
  555. func (this *MyChartController) ClassifyDelete() {
  556. br := new(models.BaseResponse).Init()
  557. defer func() {
  558. this.Data["json"] = br
  559. this.ServeJSON()
  560. }()
  561. sysUser := this.SysUser
  562. if sysUser == nil {
  563. br.Msg = "请登录"
  564. br.ErrMsg = "请登录,SysUser Is Empty"
  565. br.Ret = 408
  566. return
  567. }
  568. var req data_manage.MyChartClassifyDeleteReq
  569. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  570. if err != nil {
  571. br.Msg = "参数解析异常!"
  572. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  573. return
  574. }
  575. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  576. if err != nil && !utils.IsErrNoRow(err) {
  577. br.Msg = "保存失败"
  578. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  579. return
  580. }
  581. if item == nil {
  582. br.Msg = "分类已被删除"
  583. br.ErrMsg = "分类已被删除,Err:" + err.Error()
  584. return
  585. }
  586. nodeOb := new(data_manage.ChartFrameworkNode)
  587. cond := ` AND my_chart_classify_id = ?`
  588. pars := make([]interface{}, 0)
  589. pars = append(pars, req.MyChartClassifyId)
  590. nodes, e := nodeOb.GetItemsByCondition(cond, pars, []string{}, "")
  591. if e != nil {
  592. br.Msg = "获取失败"
  593. br.ErrMsg = "获取我的图表分类关联的框架节点失败, Err: " + e.Error()
  594. return
  595. }
  596. if len(nodes) > 0 {
  597. br.Msg = "该图分类已添加节点链接, 不允许删除"
  598. return
  599. }
  600. //var condition string
  601. //var pars []interface{}
  602. //
  603. //condition += " AND admin_id=? "
  604. //pars = append(pars, sysUser.AdminId)
  605. //
  606. //condition += " AND my_chart_classify_id=? "
  607. //pars = append(pars, req.MyChartClassifyId)
  608. ////判断是否包含图表
  609. //count, err := data_manage.GetMyChartClassifyMappingCountByCondition(condition, pars)
  610. //if err != nil {
  611. // br.Msg = "保存失败"
  612. // br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  613. // return
  614. //}
  615. //if count > 0 {
  616. // br.Msg = "此分类下含有图表,不可删除"
  617. // br.IsSendEmail = false
  618. // return
  619. //}
  620. err = data_manage.DeleteMyChartClassify(req.MyChartClassifyId)
  621. if err != nil {
  622. br.Msg = "删除失败"
  623. br.ErrMsg = "删除失败,Err:" + err.Error()
  624. return
  625. }
  626. //新增操作日志
  627. {
  628. edbLog := new(data_manage.MyChartLog)
  629. edbLog.MyChartId = 0
  630. edbLog.ChartInfoId = 0
  631. edbLog.SysUserId = sysUser.AdminId
  632. edbLog.SysUserRealName = sysUser.RealName
  633. edbLog.CreateTime = time.Now()
  634. edbLog.Content = string(this.Ctx.Input.RequestBody)
  635. edbLog.Status = "删除分类"
  636. edbLog.Method = this.Ctx.Input.URI()
  637. go data_manage.AddMyChartLog(edbLog)
  638. }
  639. br.Ret = 200
  640. br.Msg = "删除成功"
  641. br.Success = true
  642. br.IsAddLog = true
  643. }
  644. // @Title 新增我的图表
  645. // @Description 新增我的图表接口
  646. // @Param request body data_manage.MyChartAddReq true "type json string"
  647. // @Success 200 Ret=200 保存成功
  648. // @router /add [post]
  649. func (this *MyChartController) MyChartAdd() {
  650. br := new(models.BaseResponse).Init()
  651. defer func() {
  652. this.Data["json"] = br
  653. this.ServeJSON()
  654. }()
  655. sysUser := this.SysUser
  656. if sysUser == nil {
  657. br.Msg = "请登录"
  658. br.ErrMsg = "请登录,SysUser Is Empty"
  659. br.Ret = 408
  660. return
  661. }
  662. var req data_manage.MyChartAddReq
  663. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  664. if err != nil {
  665. br.Msg = "参数解析异常!"
  666. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  667. return
  668. }
  669. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  670. if err != nil && !utils.IsErrNoRow(err) {
  671. br.Msg = "获取图表信息失败!"
  672. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  673. return
  674. }
  675. if chartItem == nil {
  676. br.Msg = "此图表已被删除!"
  677. br.ErrMsg = "此图表已被删除,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
  678. return
  679. }
  680. var condition string
  681. var pars []interface{}
  682. condition += " AND admin_id=? "
  683. pars = append(pars, sysUser.AdminId)
  684. condition += " AND chart_info_id=? "
  685. pars = append(pars, req.ChartInfoId)
  686. existItem, err := data_manage.GetMyChartDetailByCondition(condition, pars)
  687. if err != nil && !utils.IsErrNoRow(err) {
  688. br.Msg = "保存失败"
  689. br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  690. return
  691. }
  692. resp := new(data_manage.MyChartAddResp)
  693. var myChartClassifyId string
  694. if existItem != nil { //修改
  695. fmt.Println("modify")
  696. for _, v := range req.MyChartClassifyId {
  697. myChartClassifyId += strconv.Itoa(v) + ","
  698. }
  699. resp.MyChartInfoId = existItem.MyChartId
  700. err = data_manage.MoveMyChartClassify(sysUser.AdminId, existItem.MyChartId, req.MyChartClassifyId)
  701. if err != nil {
  702. br.Msg = "保存失败"
  703. br.ErrMsg = "保存我的图表失败,MoveMyChartClassify,Err:" + err.Error()
  704. return
  705. }
  706. } else {
  707. myChart := &data_manage.MyChart{
  708. //MyChartId: 0,
  709. ChartInfoId: chartItem.ChartInfoId,
  710. Source: chartItem.Source,
  711. AdminId: sysUser.AdminId,
  712. CreateTime: time.Now(),
  713. ModifyTime: time.Now(),
  714. }
  715. newMyChartId, err := data_manage.AddMyChart(myChart)
  716. if err != nil {
  717. br.Msg = "保存失败"
  718. br.ErrMsg = "保存我的图表失败,Err:" + err.Error()
  719. return
  720. }
  721. //step := float64(65536)
  722. for _, v := range req.MyChartClassifyId {
  723. var sort float64
  724. // 查找最小排序值
  725. firstMapItem, _ := data_manage.GetMyChartSort(sysUser.AdminId, v, 0)
  726. if firstMapItem != nil {
  727. sort = firstMapItem.Sort
  728. }
  729. //获取最大的排序字段
  730. //count, _ := data_manage.GetMyChartMaxSort(sysUser.AdminId, v)
  731. mappingItem := new(data_manage.MyChartClassifyMapping)
  732. mappingItem.AdminId = sysUser.AdminId
  733. mappingItem.MyChartId = int(newMyChartId)
  734. mappingItem.MyChartClassifyId = v
  735. mappingItem.CreateTime = time.Now()
  736. mappingItem.ModifyTime = time.Now()
  737. //mappingItem.Sort = (float64(count) + 1) * step
  738. mappingItem.Sort = sort
  739. _, err = data_manage.AddMyChartClassifyMapping(mappingItem)
  740. if err != nil {
  741. br.Msg = "保存失败"
  742. br.ErrMsg = "保存我的图表AddMyChartClassifyMapping失败,Err:" + err.Error()
  743. return
  744. }
  745. myChartClassifyId += strconv.Itoa(v) + ","
  746. }
  747. //新增操作日志
  748. {
  749. edbLog := new(data_manage.MyChartLog)
  750. edbLog.MyChartId = myChart.MyChartId
  751. edbLog.ChartInfoId = myChart.ChartInfoId
  752. edbLog.SysUserId = sysUser.AdminId
  753. edbLog.SysUserRealName = sysUser.RealName
  754. edbLog.CreateTime = time.Now()
  755. edbLog.Content = string(this.Ctx.Input.RequestBody)
  756. edbLog.Status = "新增我的图表"
  757. edbLog.Method = this.Ctx.Input.URI()
  758. go data_manage.AddMyChartLog(edbLog)
  759. }
  760. resp.MyChartInfoId = int(newMyChartId)
  761. }
  762. resp.MyChartClassifyId = strings.Trim(myChartClassifyId, ",")
  763. //更新es
  764. if resp.MyChartInfoId > 0 {
  765. go data.EsAddOrEditMyChartInfoByMyChartId(resp.MyChartInfoId)
  766. }
  767. br.Ret = 200
  768. br.Msg = "保存成功"
  769. br.Success = true
  770. br.Data = resp
  771. br.IsAddLog = true
  772. }
  773. // MyChartAddToClassify
  774. // @Title 将图表加入到我的图表分类
  775. // @Description 新增我的图表接口
  776. // @Param request body data_manage.MyChartAddReq true "type json string"
  777. // @Success 200 Ret=200 保存成功
  778. // @router /add_to_classify [post]
  779. func (this *MyChartController) MyChartAddToClassify() {
  780. br := new(models.BaseResponse).Init()
  781. defer func() {
  782. this.Data["json"] = br
  783. this.ServeJSON()
  784. }()
  785. sysUser := this.SysUser
  786. if sysUser == nil {
  787. br.Msg = "请登录"
  788. br.ErrMsg = "请登录,SysUser Is Empty"
  789. br.Ret = 408
  790. return
  791. }
  792. var req data_manage.MyChartAddReq
  793. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  794. if err != nil {
  795. br.Msg = "参数解析异常!"
  796. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  797. return
  798. }
  799. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  800. if err != nil && !utils.IsErrNoRow(err) {
  801. br.Msg = "获取图表信息失败!"
  802. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  803. return
  804. }
  805. if chartItem == nil {
  806. br.Msg = "此图表已被删除!"
  807. br.ErrMsg = "此图表已被删除,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
  808. return
  809. }
  810. var condition string
  811. var pars []interface{}
  812. condition += " AND admin_id=? "
  813. pars = append(pars, sysUser.AdminId)
  814. condition += " AND chart_info_id=? "
  815. pars = append(pars, req.ChartInfoId)
  816. existItem, err := data_manage.GetMyChartDetailByCondition(condition, pars)
  817. if err != nil && !utils.IsErrNoRow(err) {
  818. br.Msg = "保存失败"
  819. br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  820. return
  821. }
  822. resp := new(data_manage.MyChartAddResp)
  823. var myChartClassifyId string
  824. if existItem != nil { //修改
  825. fmt.Println("modify")
  826. for _, v := range req.MyChartClassifyId {
  827. myChartClassifyId += strconv.Itoa(v) + ","
  828. }
  829. resp.MyChartInfoId = existItem.MyChartId
  830. err = data_manage.AddMyChartToMyChartClassify(sysUser.AdminId, existItem.MyChartId, req.MyChartClassifyId)
  831. if err != nil {
  832. br.Msg = "保存失败"
  833. br.ErrMsg = "保存我的图表失败,MoveMyChartClassify,Err:" + err.Error()
  834. return
  835. }
  836. } else {
  837. myChart := &data_manage.MyChart{
  838. //MyChartId: 0,
  839. ChartInfoId: chartItem.ChartInfoId,
  840. Source: chartItem.Source,
  841. AdminId: sysUser.AdminId,
  842. CreateTime: time.Now(),
  843. ModifyTime: time.Now(),
  844. }
  845. newMyChartId, err := data_manage.AddMyChart(myChart)
  846. if err != nil {
  847. br.Msg = "保存失败"
  848. br.ErrMsg = "保存我的图表失败,Err:" + err.Error()
  849. return
  850. }
  851. step := float64(65536)
  852. for _, v := range req.MyChartClassifyId {
  853. //获取最大的排序字段
  854. count, _ := data_manage.GetMyChartMaxSort(sysUser.AdminId, v)
  855. mappingItem := new(data_manage.MyChartClassifyMapping)
  856. mappingItem.AdminId = sysUser.AdminId
  857. mappingItem.MyChartId = int(newMyChartId)
  858. mappingItem.MyChartClassifyId = v
  859. mappingItem.CreateTime = time.Now()
  860. mappingItem.ModifyTime = time.Now()
  861. mappingItem.Sort = (float64(count) + 1) * step
  862. _, err = data_manage.AddMyChartClassifyMapping(mappingItem)
  863. if err != nil {
  864. br.Msg = "保存失败"
  865. br.ErrMsg = "保存我的图表AddMyChartClassifyMapping失败,Err:" + err.Error()
  866. return
  867. }
  868. myChartClassifyId += strconv.Itoa(v) + ","
  869. }
  870. //新增操作日志
  871. {
  872. edbLog := new(data_manage.MyChartLog)
  873. edbLog.MyChartId = myChart.MyChartId
  874. edbLog.ChartInfoId = myChart.ChartInfoId
  875. edbLog.SysUserId = sysUser.AdminId
  876. edbLog.SysUserRealName = sysUser.RealName
  877. edbLog.CreateTime = time.Now()
  878. edbLog.Content = string(this.Ctx.Input.RequestBody)
  879. edbLog.Status = "新增我的图表"
  880. edbLog.Method = this.Ctx.Input.URI()
  881. go data_manage.AddMyChartLog(edbLog)
  882. }
  883. resp.MyChartInfoId = int(newMyChartId)
  884. }
  885. resp.MyChartClassifyId = strings.Trim(myChartClassifyId, ",")
  886. //更新es
  887. if resp.MyChartInfoId > 0 {
  888. go data.EsAddOrEditMyChartInfoByMyChartId(resp.MyChartInfoId)
  889. }
  890. br.Ret = 200
  891. br.Msg = "保存成功"
  892. br.Success = true
  893. br.Data = resp
  894. br.IsAddLog = true
  895. }
  896. // GetMyChartClassifyIdList
  897. // @Title 根据我的图表id获取所属分类列表
  898. // @Description 根据我的图表id获取所属分类列表接口
  899. // @Param query ChartInfoId int `description:"图表id"`
  900. // @Success 200 {object} []int
  901. // @router /get_mychart_classify_id_list [get]
  902. func (this *MyChartController) GetMyChartClassifyIdList() {
  903. br := new(models.BaseResponse).Init()
  904. defer func() {
  905. this.Data["json"] = br
  906. this.ServeJSON()
  907. }()
  908. sysUser := this.SysUser
  909. if sysUser == nil {
  910. br.Msg = "请登录"
  911. br.ErrMsg = "请登录,SysUser Is Empty"
  912. br.Ret = 408
  913. return
  914. }
  915. chartInfoId, _ := this.GetInt("ChartInfoId")
  916. if chartInfoId <= 0 {
  917. br.Msg = "请传入图表id"
  918. br.IsSendEmail = false
  919. return
  920. }
  921. //图表分类id列表
  922. chartClassifyIdList := make([]int, 0)
  923. var condition string
  924. var pars []interface{}
  925. condition += " AND admin_id=? AND chart_info_id=? "
  926. pars = append(pars, sysUser.AdminId, chartInfoId)
  927. existItem, _ := data_manage.GetMyChartDetailByCondition(condition, pars)
  928. if existItem != nil {
  929. myChartClassifyList, err := data_manage.GetMyChartClassifyList(existItem.MyChartId)
  930. if err != nil && !utils.IsErrNoRow(err) {
  931. br.Msg = "获取图表信息失败!"
  932. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  933. return
  934. }
  935. for _, v := range myChartClassifyList {
  936. chartClassifyIdList = append(chartClassifyIdList, v.MyChartClassifyId)
  937. }
  938. }
  939. br.Ret = 200
  940. br.Msg = "获取成功"
  941. br.Success = true
  942. br.Data = chartClassifyIdList
  943. }
  944. // @Title 删除-我的图表-中的图表
  945. // @Description 删除-我的图表-中的图表接口
  946. // @Param request body data_manage.MyChartDeleteReq true "type json string"
  947. // @Success 200 Ret=200 保存成功
  948. // @router /delete [post]
  949. func (this *MyChartController) MyChartDelete() {
  950. setNxKey := "MyChartDelete_"
  951. deleteCache := true
  952. br := new(models.BaseResponse).Init()
  953. defer func() {
  954. if deleteCache {
  955. utils.Rc.Delete(setNxKey)
  956. }
  957. this.Data["json"] = br
  958. this.ServeJSON()
  959. }()
  960. sysUser := this.SysUser
  961. if sysUser == nil {
  962. br.Msg = "请登录"
  963. br.ErrMsg = "请登录,SysUser Is Empty"
  964. br.Ret = 408
  965. return
  966. }
  967. var req data_manage.MyChartDeleteReq
  968. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  969. if err != nil {
  970. br.Msg = "参数解析异常!"
  971. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  972. return
  973. }
  974. setNxKey += strconv.Itoa(req.MyChartId) + strconv.Itoa(req.MyChartClassifyId)
  975. if !utils.Rc.SetNX(setNxKey, 1, 3*time.Second) {
  976. deleteCache = false
  977. br.Msg = "系统处理中,请稍后重试!"
  978. br.IsSendEmail = false
  979. return
  980. }
  981. if req.MyChartId <= 0 {
  982. br.Msg = "参数错误!"
  983. br.ErrMsg = "参数错误,Err:" + string(this.Ctx.Input.RequestBody)
  984. return
  985. }
  986. isDelMyChart, err := data_manage.DeleteMyChart(req.MyChartId, req.MyChartClassifyId)
  987. if err != nil {
  988. br.Msg = "移除失败!"
  989. br.ErrMsg = "移除失败,Err:" + err.Error()
  990. return
  991. }
  992. //新增操作日志
  993. {
  994. edbLog := new(data_manage.MyChartLog)
  995. edbLog.MyChartId = 0
  996. edbLog.ChartInfoId = 0
  997. edbLog.SysUserId = sysUser.AdminId
  998. edbLog.SysUserRealName = sysUser.RealName
  999. edbLog.CreateTime = time.Now()
  1000. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1001. edbLog.Status = "删除-我的图表-中的图表"
  1002. edbLog.Method = this.Ctx.Input.URI()
  1003. go data_manage.AddMyChartLog(edbLog)
  1004. }
  1005. if isDelMyChart {
  1006. //如果确实删除了,那么就去ES同步删除
  1007. go data.EsDeleteMyChartInfoByMyChartId(req.MyChartId)
  1008. } else {
  1009. //如果只是删除了关系,那么就去ES同步更新数据
  1010. go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
  1011. }
  1012. br.Ret = 200
  1013. br.Msg = "移除成功"
  1014. br.Success = true
  1015. br.IsAddLog = true
  1016. }
  1017. // @Title 编辑我的图表
  1018. // @Description 编辑我的图表接口
  1019. // @Param request body data_manage.MyChartEditReq true "type json string"
  1020. // @Success 200 Ret=200 保存成功
  1021. // @router /edit [post]
  1022. func (this *MyChartController) MyChartEdit() {
  1023. br := new(models.BaseResponse).Init()
  1024. defer func() {
  1025. this.Data["json"] = br
  1026. this.ServeJSON()
  1027. }()
  1028. sysUser := this.SysUser
  1029. if sysUser == nil {
  1030. br.Msg = "请登录"
  1031. br.ErrMsg = "请登录,SysUser Is Empty"
  1032. br.Ret = 408
  1033. return
  1034. }
  1035. var req data_manage.MyChartEditReq
  1036. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1037. if err != nil {
  1038. br.Msg = "参数解析异常!"
  1039. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1040. return
  1041. }
  1042. for _, v := range req.MyChartClassifyId {
  1043. myChartClassifyId := v
  1044. count, _ := data_manage.GetMyChartClassifyMappingCount(sysUser.AdminId, req.MyChartId, myChartClassifyId)
  1045. if count <= 0 {
  1046. mappingItem := new(data_manage.MyChartClassifyMapping)
  1047. mappingItem.AdminId = sysUser.AdminId
  1048. mappingItem.MyChartId = req.MyChartId
  1049. mappingItem.MyChartClassifyId = myChartClassifyId
  1050. mappingItem.CreateTime = time.Now()
  1051. _, err = data_manage.AddMyChartClassifyMapping(mappingItem)
  1052. }
  1053. }
  1054. err = data_manage.DeleteMyChartClassifyMapping(sysUser.AdminId, req.MyChartId, req.CurrentMyChartClassifyId)
  1055. if err != nil {
  1056. br.Msg = "保存失败!"
  1057. br.ErrMsg = "保存失败,移除分类失败,Err:" + err.Error()
  1058. return
  1059. }
  1060. //新增操作日志
  1061. {
  1062. edbLog := new(data_manage.MyChartLog)
  1063. edbLog.MyChartId = 0
  1064. edbLog.ChartInfoId = 0
  1065. edbLog.SysUserId = sysUser.AdminId
  1066. edbLog.SysUserRealName = sysUser.RealName
  1067. edbLog.CreateTime = time.Now()
  1068. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1069. edbLog.Status = "编辑我的图表"
  1070. edbLog.Method = this.Ctx.Input.URI()
  1071. go data_manage.AddMyChartLog(edbLog)
  1072. }
  1073. //更新es
  1074. if req.MyChartId > 0 {
  1075. go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
  1076. }
  1077. br.Ret = 200
  1078. br.Msg = "保存成功"
  1079. br.Success = true
  1080. br.IsAddLog = true
  1081. }
  1082. // MyChartList
  1083. // @Title 我的图表-列表接口
  1084. // @Description 我的图表-列表接口
  1085. // @Param PageSize query int true "每页数据条数"
  1086. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1087. // @Param MyChartClassifyId query int true "我的图表分类id"
  1088. // @Param MyChartId query int true "我的图表id"
  1089. // @Param IsShared query bool false "是否可分享(如从图库框架请求的属于可分享的)"
  1090. // @Success 200 {object} data_manage.MyChartListResp
  1091. // @router /list [get]
  1092. func (this *MyChartController) MyChartList() {
  1093. br := new(models.BaseResponse).Init()
  1094. defer func() {
  1095. this.Data["json"] = br
  1096. this.ServeJSON()
  1097. }()
  1098. sysUser := this.SysUser
  1099. if sysUser == nil {
  1100. br.Msg = "请登录"
  1101. br.ErrMsg = "请登录,SysUser Is Empty"
  1102. br.Ret = 408
  1103. return
  1104. }
  1105. myChartClassifyId, _ := this.GetInt("MyChartClassifyId")
  1106. pageSize, _ := this.GetInt("PageSize")
  1107. currentIndex, _ := this.GetInt("CurrentIndex")
  1108. myChartId, _ := this.GetInt("MyChartId")
  1109. isShared, _ := this.GetBool("IsShared")
  1110. var total int
  1111. page := paging.GetPaging(currentIndex, pageSize, total)
  1112. var startSize int
  1113. if pageSize <= 0 {
  1114. pageSize = utils.PageSize20
  1115. }
  1116. if currentIndex <= 0 {
  1117. currentIndex = 1
  1118. }
  1119. startSize = paging.StartIndex(currentIndex, pageSize)
  1120. var condition string
  1121. var pars []interface{}
  1122. chartAdminId := sysUser.AdminId
  1123. if myChartClassifyId > 0 {
  1124. condition += " AND c.my_chart_classify_id=? "
  1125. pars = append(pars, myChartClassifyId)
  1126. // 可共享
  1127. if isShared {
  1128. myClassify, e := data_manage.GetMyChartClassifyByClassifyId(myChartClassifyId)
  1129. if e != nil {
  1130. if utils.IsErrNoRow(e) {
  1131. br.Msg = "分类已被删除, 请刷新页面"
  1132. return
  1133. }
  1134. br.Msg = "获取失败"
  1135. br.ErrMsg = "获取分类失败, Err: " + e.Error()
  1136. return
  1137. }
  1138. chartAdminId = myClassify.AdminId
  1139. }
  1140. }
  1141. condition += " AND (a.admin_id = ? OR d.is_public = 1)"
  1142. pars = append(pars, chartAdminId)
  1143. if myChartId > 0 {
  1144. condition += " AND a.my_chart_id=? "
  1145. pars = append(pars, myChartId)
  1146. }
  1147. // 获取当前账号的不可见指标
  1148. noPermissionChartIdList := make([]int, 0)
  1149. {
  1150. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1151. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1152. if err != nil && !utils.IsErrNoRow(err) {
  1153. br.Msg = "获取失败"
  1154. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1155. return
  1156. }
  1157. for _, v := range confList {
  1158. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1159. }
  1160. }
  1161. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  1162. if lenNoPermissionChartIdList > 0 {
  1163. condition += ` AND b.chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  1164. pars = append(pars, noPermissionChartIdList)
  1165. }
  1166. //获取图表信息
  1167. list, err := data_manage.GetMyChartListByCondition(condition, pars, startSize, pageSize)
  1168. if err != nil && !utils.IsErrNoRow(err) {
  1169. br.Success = true
  1170. br.Msg = "获取图表信息失败"
  1171. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1172. return
  1173. }
  1174. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  1175. if err != nil && !utils.IsErrNoRow(err) {
  1176. br.Msg = "获取图表信息失败"
  1177. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  1178. return
  1179. }
  1180. myChartMap := make(map[int]int)
  1181. chartInfoIds := ""
  1182. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  1183. for _, v := range myChartList {
  1184. myChartMap[v.ChartInfoId] = v.ChartInfoId
  1185. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  1186. }
  1187. if chartInfoIds != "" {
  1188. chartInfoIds = strings.Trim(chartInfoIds, ",")
  1189. //判断是否需要展示英文标识
  1190. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  1191. if e != nil {
  1192. br.Msg = "获取失败"
  1193. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  1194. return
  1195. }
  1196. for _, v := range edbList {
  1197. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  1198. }
  1199. }
  1200. listLen := len(list)
  1201. if listLen > 0 {
  1202. // 分类id
  1203. classifyIdList := make([]int, 0)
  1204. // 当前列表中的分类map
  1205. classifyMap := make(map[int]*data_manage.ChartClassify)
  1206. for _, v := range list {
  1207. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1208. }
  1209. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1210. if err != nil {
  1211. br.Msg = "获取失败"
  1212. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  1213. return
  1214. }
  1215. for _, v := range classifyList {
  1216. classifyMap[v.ChartClassifyId] = v
  1217. }
  1218. // 已授权分类id
  1219. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1220. if err != nil {
  1221. br.Msg = "获取失败"
  1222. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1223. return
  1224. }
  1225. // 权限
  1226. for i, chartViewInfo := range list {
  1227. //判断是否需要展示英文标识
  1228. if edbTmpList, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  1229. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, edbTmpList, list[i].Source, list[i].ChartType)
  1230. }
  1231. if _, ok := myChartMap[list[i].ChartInfoId]; ok {
  1232. list[i].IsAdd = true
  1233. }
  1234. // 数据权限
  1235. if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
  1236. list[i].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1237. } else if chartViewInfo.ChartClassifyId == 0 {
  1238. list[i].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, 0, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1239. }
  1240. }
  1241. }
  1242. resp := new(data_manage.MyChartListResp)
  1243. if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
  1244. items := make([]*data_manage.MyChartList, 0)
  1245. resp.Paging = page
  1246. resp.List = items
  1247. br.Ret = 200
  1248. br.Success = true
  1249. br.Msg = "获取成功"
  1250. return
  1251. }
  1252. total, err = data_manage.GetMyChartListCountByCondition(condition, pars)
  1253. if err != nil && !utils.IsErrNoRow(err) {
  1254. br.Msg = "获取信息失败"
  1255. br.ErrMsg = "获取我的图表数据总数失败,Err:" + err.Error()
  1256. return
  1257. }
  1258. page = paging.GetPaging(currentIndex, pageSize, total)
  1259. resp.Paging = page
  1260. resp.List = list
  1261. br.Ret = 200
  1262. br.Success = true
  1263. br.Msg = "获取成功"
  1264. br.Data = resp
  1265. }
  1266. // @Title 移动我的图表接口
  1267. // @Description 移动我的图表接口
  1268. // @Success 200 {object} data_manage.MoveMyChartReq
  1269. // @router /move [post]
  1270. func (this *MyChartController) MyChartMove() {
  1271. br := new(models.BaseResponse).Init()
  1272. defer func() {
  1273. this.Data["json"] = br
  1274. this.ServeJSON()
  1275. }()
  1276. sysUser := this.SysUser
  1277. if sysUser == nil {
  1278. br.Msg = "请登录"
  1279. br.ErrMsg = "请登录,SysUser Is Empty"
  1280. br.Ret = 408
  1281. return
  1282. }
  1283. adminId := sysUser.AdminId
  1284. var req data_manage.MoveMyChartReq
  1285. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1286. if err != nil {
  1287. br.Msg = "参数解析异常!"
  1288. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1289. return
  1290. }
  1291. //step := float64(65536)
  1292. var newSort float64
  1293. if req.PrevMyChartId <= 0 {
  1294. firstMapItem, err := data_manage.GetMyChartSort(adminId, req.MyChartClassifyId, 0)
  1295. if err != nil {
  1296. br.Msg = "获取数据失败!"
  1297. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1298. return
  1299. }
  1300. //if firstMapItem.Sort <= 0 {
  1301. // firstSort := step / float64(2)
  1302. // err = data_manage.MyChartMove(firstSort, adminId, firstMapItem.MyChartId, firstMapItem.MyChartClassifyId)
  1303. // if err != nil {
  1304. // br.Msg = "移动失败!"
  1305. // br.ErrMsg = "移动失败,Err:" + err.Error()
  1306. // return
  1307. // }
  1308. // newSort = step / float64(4)
  1309. //} else {
  1310. // newSort = firstMapItem.Sort / float64(2)
  1311. //}
  1312. newSort = firstMapItem.Sort - 1
  1313. } else if req.NextMyChartId <= 0 {
  1314. latestMapItem, err := data_manage.GetMyChartSort(adminId, req.MyChartClassifyId, 1)
  1315. if err != nil {
  1316. br.Msg = "获取数据失败!"
  1317. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1318. return
  1319. }
  1320. //if latestMapItem.Sort <= 0 {
  1321. // latestSort := step / float64(2)
  1322. // err = data_manage.MyChartMove(latestSort, adminId, latestMapItem.MyChartId, latestMapItem.MyChartClassifyId)
  1323. // if err != nil {
  1324. // br.Msg = "移动失败!"
  1325. // br.ErrMsg = "移动失败,Err:" + err.Error()
  1326. // return
  1327. // }
  1328. // newSort = step / float64(4)
  1329. //} else {
  1330. // newSort = latestMapItem.Sort + (step / float64(2)) - 1
  1331. //}
  1332. newSort = latestMapItem.Sort + 1
  1333. } else {
  1334. preMapItem, err := data_manage.GetMyChartClassifyMapping(adminId, req.PrevMyChartId, req.MyChartClassifyId)
  1335. if err != nil {
  1336. br.Msg = "获取数据失败!"
  1337. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1338. return
  1339. }
  1340. nextMapItem, err := data_manage.GetMyChartClassifyMapping(adminId, req.NextMyChartId, req.MyChartClassifyId)
  1341. if err != nil {
  1342. br.Msg = "获取数据失败!"
  1343. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1344. return
  1345. }
  1346. newSort = (preMapItem.Sort + nextMapItem.Sort) / 2
  1347. newSort = preMapItem.Sort + 1
  1348. var updateSortStr string
  1349. if preMapItem.Sort == nextMapItem.Sort {
  1350. //变更兄弟节点的排序(sort同级)
  1351. updateSortStr = `sort + 2`
  1352. } else if nextMapItem.Sort-preMapItem.Sort == 1 {
  1353. //变更兄弟节点的排序(sort只相差一级)
  1354. updateSortStr = `sort + 1`
  1355. }
  1356. if updateSortStr != `` {
  1357. _ = data_manage.UpdateMyChartSortByClassifyId(req.MyChartClassifyId, int(preMapItem.Sort), preMapItem.MyChartClassifyMappingId, updateSortStr)
  1358. }
  1359. }
  1360. //if newSort >= 0 {
  1361. //
  1362. //} else {
  1363. // utils.FileLog.Info("MyChartMove Sort=0:" + string(this.Ctx.Input.RequestBody))
  1364. //}
  1365. err = data_manage.MyChartMove(newSort, adminId, req.MyChartId, req.MyChartClassifyId)
  1366. if err != nil {
  1367. br.Msg = "移动失败!"
  1368. br.ErrMsg = "移动失败,Err:" + err.Error()
  1369. return
  1370. }
  1371. //新增操作日志
  1372. {
  1373. edbLog := new(data_manage.MyChartLog)
  1374. edbLog.MyChartId = 0
  1375. edbLog.ChartInfoId = 0
  1376. edbLog.SysUserId = sysUser.AdminId
  1377. edbLog.SysUserRealName = sysUser.RealName
  1378. edbLog.CreateTime = time.Now()
  1379. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1380. edbLog.Status = "移动我的图表"
  1381. edbLog.Method = this.Ctx.Input.URI()
  1382. go data_manage.AddMyChartLog(edbLog)
  1383. }
  1384. //更新es
  1385. if req.MyChartId > 0 {
  1386. go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
  1387. }
  1388. br.Ret = 200
  1389. br.Success = true
  1390. br.Msg = "移动成功"
  1391. br.IsAddLog = true
  1392. }
  1393. // @Title ETA图表-推荐列表接口
  1394. // @Description ETA图表-推荐列表接口
  1395. // @Param ChartClassifyId query int true "分类id"
  1396. // @Success 200 {object} data_manage.ChartRecommendListResp
  1397. // @router /chart/recommend/list [get]
  1398. func (this *MyChartController) ChartRecommendList() {
  1399. br := new(models.BaseResponse).Init()
  1400. defer func() {
  1401. this.Data["json"] = br
  1402. this.ServeJSON()
  1403. }()
  1404. sysUser := this.SysUser
  1405. if sysUser == nil {
  1406. br.Msg = "请登录"
  1407. br.ErrMsg = "请登录,SysUser Is Empty"
  1408. br.Ret = 408
  1409. return
  1410. }
  1411. pageSize := 6
  1412. currentIndex := 1
  1413. var startSize int
  1414. startSize = paging.StartIndex(currentIndex, pageSize)
  1415. var condition string
  1416. var pars []interface{}
  1417. if sysUser.AdminId > 0 {
  1418. condition += " AND a.admin_id=? "
  1419. pars = append(pars, sysUser.AdminId)
  1420. }
  1421. //获取图表信息
  1422. list, err := data_manage.GetRecommendChartListByCondition(condition, pars, startSize, pageSize)
  1423. if err != nil && !utils.IsErrNoRow(err) {
  1424. br.Success = true
  1425. br.Msg = "获取图表信息失败"
  1426. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1427. return
  1428. }
  1429. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  1430. if err != nil && !utils.IsErrNoRow(err) {
  1431. br.Msg = "获取图表信息失败"
  1432. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  1433. return
  1434. }
  1435. myChartMap := make(map[int]int)
  1436. for _, v := range myChartList {
  1437. myChartMap[v.ChartInfoId] = v.ChartInfoId
  1438. }
  1439. listLen := len(list)
  1440. if listLen > 0 {
  1441. // 分类id
  1442. classifyIdList := make([]int, 0)
  1443. // 当前列表中的分类map
  1444. classifyMap := make(map[int]*data_manage.ChartClassify)
  1445. for _, v := range list {
  1446. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1447. }
  1448. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1449. if err != nil {
  1450. br.Msg = "获取失败"
  1451. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  1452. return
  1453. }
  1454. for _, v := range classifyList {
  1455. classifyMap[v.ChartClassifyId] = v
  1456. }
  1457. // 已授权分类id
  1458. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1459. if err != nil {
  1460. br.Msg = "获取失败"
  1461. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1462. return
  1463. }
  1464. // 权限
  1465. for k, chartViewInfo := range list {
  1466. if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
  1467. list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1468. }
  1469. if _, ok := myChartMap[list[k].ChartInfoId]; ok {
  1470. list[k].IsAdd = true
  1471. }
  1472. }
  1473. }
  1474. resp := new(data_manage.ChartRecommendListResp)
  1475. if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
  1476. items := make([]*data_manage.ChartInfoView, 0)
  1477. resp.List = items
  1478. br.Ret = 200
  1479. br.Success = true
  1480. br.Msg = "获取成功"
  1481. return
  1482. }
  1483. resp.List = list
  1484. br.Ret = 200
  1485. br.Success = true
  1486. br.Msg = "获取成功"
  1487. br.Data = resp
  1488. }
  1489. // @Title 我的图表-列表接口
  1490. // @Description 我的图表-列表接口
  1491. // @Param KeyWord query string true "搜索关键词"
  1492. // @Success 200 {object} data_manage.MyChartListResp
  1493. // @router /search [get]
  1494. func (this *MyChartController) MyChartSearch() {
  1495. br := new(models.BaseResponse).Init()
  1496. defer func() {
  1497. this.Data["json"] = br
  1498. this.ServeJSON()
  1499. }()
  1500. sysUser := this.SysUser
  1501. if sysUser == nil {
  1502. br.Msg = "请登录"
  1503. br.ErrMsg = "请登录,SysUser Is Empty"
  1504. br.Ret = 408
  1505. return
  1506. }
  1507. var condition string
  1508. var pars []interface{}
  1509. condition += " AND a.admin_id=? "
  1510. pars = append(pars, sysUser.AdminId)
  1511. keyWord := this.GetString("KeyWord")
  1512. if keyWord != "" {
  1513. condition += ` AND chart_name LIKE '%` + keyWord + `%' `
  1514. }
  1515. //获取图表信息
  1516. list, err := data_manage.GetMyChartSearchByCondition(condition, pars)
  1517. if err != nil && !utils.IsErrNoRow(err) {
  1518. br.Success = true
  1519. br.Msg = "获取图表信息失败"
  1520. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1521. return
  1522. }
  1523. listLen := len(list)
  1524. if listLen > 0 {
  1525. // 分类id
  1526. classifyIdList := make([]int, 0)
  1527. // 当前列表中的分类map
  1528. classifyMap := make(map[int]*data_manage.ChartClassify)
  1529. for _, v := range list {
  1530. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1531. }
  1532. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1533. if err != nil {
  1534. br.Msg = "获取失败"
  1535. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  1536. return
  1537. }
  1538. for _, v := range classifyList {
  1539. classifyMap[v.ChartClassifyId] = v
  1540. }
  1541. // 已授权分类id
  1542. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1543. if err != nil {
  1544. br.Msg = "获取失败"
  1545. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1546. return
  1547. }
  1548. // 权限
  1549. for k, chartViewInfo := range list {
  1550. if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
  1551. list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1552. }
  1553. list[k].IsAdd = true
  1554. }
  1555. }
  1556. resp := new(data_manage.MyChartSearchListResp)
  1557. if list == nil {
  1558. list = make([]*data_manage.MyChartList, 0)
  1559. }
  1560. resp.List = list
  1561. br.Ret = 200
  1562. br.Success = true
  1563. br.Msg = "获取成功"
  1564. br.Data = resp
  1565. }
  1566. // MyChartSearchByEs
  1567. // @Title 我的图表-列表接口
  1568. // @Description 我的图表-列表接口
  1569. // @Param Keyword query string true "搜索关键词"
  1570. // @Success 200 {object} data_manage.MyChartListResp
  1571. // @router /search_by_es [get]
  1572. func (this *MyChartController) MyChartSearchByEs() {
  1573. br := new(models.BaseResponse).Init()
  1574. defer func() {
  1575. this.Data["json"] = br
  1576. this.ServeJSON()
  1577. }()
  1578. sysUser := this.SysUser
  1579. if sysUser == nil {
  1580. br.Msg = "请登录"
  1581. br.ErrMsg = "请登录,SysUser Is Empty"
  1582. br.Ret = 408
  1583. return
  1584. }
  1585. pageSize, _ := this.GetInt("PageSize")
  1586. currentIndex, _ := this.GetInt("CurrentIndex")
  1587. var startSize int
  1588. if pageSize <= 0 {
  1589. pageSize = utils.PageSize20
  1590. }
  1591. if currentIndex <= 0 {
  1592. currentIndex = 1
  1593. }
  1594. startSize = paging.StartIndex(currentIndex, pageSize)
  1595. keyword := this.GetString("Keyword")
  1596. // 获取当前账号的不可见指标
  1597. noPermissionChartIdList := make([]int, 0)
  1598. {
  1599. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1600. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1601. if err != nil && !utils.IsErrNoRow(err) {
  1602. br.Msg = "获取失败"
  1603. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1604. return
  1605. }
  1606. for _, v := range confList {
  1607. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1608. }
  1609. }
  1610. //获取图表信息
  1611. list, total, err := data.EsSearchMyChartInfo(keyword, sysUser.AdminId, noPermissionChartIdList, startSize, pageSize)
  1612. if err != nil {
  1613. br.Msg = "获取失败"
  1614. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1615. return
  1616. }
  1617. lenList := len(list)
  1618. if lenList <= 0 {
  1619. list = make([]*data_manage.MyChartList, 0)
  1620. } else {
  1621. // 分类id
  1622. classifyIdList := make([]int, 0)
  1623. // 图表id
  1624. chartInfoIdList := make([]int, 0)
  1625. // 当前列表中的分类map
  1626. chartClassifyMap := make(map[int]*data_manage.ChartClassify)
  1627. // 当前列表中的图表map
  1628. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  1629. for _, v := range list {
  1630. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1631. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  1632. }
  1633. // 分类
  1634. {
  1635. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1636. if err != nil {
  1637. if err != nil {
  1638. br.Msg = "获取失败"
  1639. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  1640. return
  1641. }
  1642. }
  1643. for _, tmpClassifyInfo := range classifyList {
  1644. chartClassifyMap[tmpClassifyInfo.ChartClassifyId] = tmpClassifyInfo
  1645. }
  1646. }
  1647. // 图表
  1648. {
  1649. tmpChartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  1650. if err != nil {
  1651. br.Msg = "获取失败"
  1652. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  1653. return
  1654. }
  1655. for _, tmpChartInfo := range tmpChartList {
  1656. chartInfoMap[tmpChartInfo.ChartInfoId] = tmpChartInfo
  1657. }
  1658. }
  1659. // 已授权分类id
  1660. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  1661. if err != nil {
  1662. br.Msg = "获取失败"
  1663. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1664. return
  1665. }
  1666. // 权限
  1667. for k, tmpChartViewInfo := range list {
  1668. list[k].IsAdd = true
  1669. chartViewInfo, ok := chartInfoMap[tmpChartViewInfo.ChartInfoId]
  1670. if !ok {
  1671. continue
  1672. }
  1673. if currClassify, ok := chartClassifyMap[chartViewInfo.ChartClassifyId]; ok {
  1674. list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1675. }
  1676. }
  1677. }
  1678. page := paging.GetPaging(currentIndex, pageSize, int(total))
  1679. resp := data_manage.MyChartSearchListResp{
  1680. List: list,
  1681. Paging: page,
  1682. }
  1683. br.Ret = 200
  1684. br.Success = true
  1685. br.Msg = "获取成功"
  1686. br.Data = resp
  1687. }
  1688. // PublicClassifyList
  1689. // @Title 我的图表-公共分类列表接口
  1690. // @Description 我的图表-公共分类列表接口
  1691. // @Success 200 {object} data_manage.MyChartClassifyResp
  1692. // @router /classify/public_list [get]
  1693. func (this *MyChartController) PublicClassifyList() {
  1694. br := new(models.BaseResponse).Init()
  1695. defer func() {
  1696. this.Data["json"] = br
  1697. this.ServeJSON()
  1698. }()
  1699. sysUser := this.SysUser
  1700. if sysUser == nil {
  1701. br.Msg = "请登录"
  1702. br.ErrMsg = "请登录,SysUser Is Empty"
  1703. br.Ret = 408
  1704. return
  1705. }
  1706. //获取图表信息
  1707. list, err := data_manage.GetPublicChartClassifyAllExceptMy(sysUser.AdminId)
  1708. if err != nil && !utils.IsErrNoRow(err) {
  1709. br.Success = true
  1710. br.Msg = "获取公共分类信息失败"
  1711. br.ErrMsg = "获取公共分类信息失败,Err:" + err.Error()
  1712. return
  1713. }
  1714. resp := new(data_manage.PublicChartClassifyResp)
  1715. if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
  1716. resp.List = make([]data_manage.PublicChartClassifyList, 0)
  1717. br.Ret = 200
  1718. br.Success = true
  1719. br.Msg = "获取成功"
  1720. return
  1721. }
  1722. // 创建人姓名
  1723. adminIdStr := make([]string, 0)
  1724. for _, v := range list {
  1725. adminIdStr = append(adminIdStr, fmt.Sprint(v.AdminId))
  1726. }
  1727. adminMap := make(map[int]string)
  1728. adminList, _ := system.GetSysAdminByIdSlice(adminIdStr)
  1729. if len(adminList) > 0 {
  1730. for _, adminInfo := range adminList {
  1731. adminMap[adminInfo.AdminId] = adminInfo.RealName
  1732. }
  1733. }
  1734. respList := make([]data_manage.PublicChartClassifyList, 0)
  1735. existMap := make(map[int]bool, 0)
  1736. itemsMap := make(map[int][]data_manage.PublicChartClassifyItem, 0)
  1737. for _, v := range list {
  1738. realName := adminMap[v.AdminId]
  1739. if realName == "" {
  1740. // 忽略掉被删掉的用户
  1741. continue
  1742. }
  1743. if itemsMap[v.AdminId] == nil {
  1744. itemsMap[v.AdminId] = make([]data_manage.PublicChartClassifyItem, 0)
  1745. }
  1746. itemsMap[v.AdminId] = append(itemsMap[v.AdminId], data_manage.PublicChartClassifyItem{
  1747. MyChartClassifyId: v.MyChartClassifyId,
  1748. MyChartClassifyName: v.MyChartClassifyName,
  1749. AdminId: v.AdminId,
  1750. RealName: realName,
  1751. IsPublic: v.IsPublic,
  1752. IsCompanyPublic: v.IsCompanyPublic,
  1753. })
  1754. var menu data_manage.PublicChartClassifyList
  1755. if existMap[v.AdminId] {
  1756. continue
  1757. }
  1758. existMap[v.AdminId] = true
  1759. menu.MenuAdminId = v.AdminId
  1760. menu.MenuName = fmt.Sprintf("%s的图库", realName)
  1761. respList = append(respList, menu)
  1762. }
  1763. for k, v := range respList {
  1764. respList[k].Items = itemsMap[v.MenuAdminId]
  1765. }
  1766. resp.List = respList
  1767. language := `CN`
  1768. // 指标显示的语言
  1769. {
  1770. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  1771. if configDetail != nil {
  1772. language = configDetail.ConfigValue
  1773. } else {
  1774. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  1775. if configDetail != nil {
  1776. language = configDetail.ConfigValue
  1777. }
  1778. }
  1779. }
  1780. resp.Language = language
  1781. br.Ret = 200
  1782. br.Success = true
  1783. br.Msg = "获取成功"
  1784. br.Data = resp
  1785. }
  1786. // ModifyClassifyPublicStatus
  1787. // @Title 修改我的图表分类的是否可见
  1788. // @Description 修改我的图表分类的是否可见接口
  1789. // @Param request body data_manage.ModifyChartClassifyPublicReq true "type json string"
  1790. // @Success 200 Ret=200 修改成功
  1791. // @router /classify/modify_public [post]
  1792. func (this *MyChartController) ModifyClassifyPublicStatus() {
  1793. br := new(models.BaseResponse).Init()
  1794. defer func() {
  1795. this.Data["json"] = br
  1796. this.ServeJSON()
  1797. }()
  1798. sysUser := this.SysUser
  1799. if sysUser == nil {
  1800. br.Msg = "请登录"
  1801. br.ErrMsg = "请登录,SysUser Is Empty"
  1802. br.Ret = 408
  1803. return
  1804. }
  1805. var req data_manage.ModifyChartClassifyPublicReq
  1806. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1807. if err != nil {
  1808. br.Msg = "参数解析异常!"
  1809. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1810. return
  1811. }
  1812. //查询该分类存不存在
  1813. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  1814. if err != nil && !utils.IsErrNoRow(err) {
  1815. br.Msg = "修改失败,找不到该分类"
  1816. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1817. return
  1818. }
  1819. if item == nil {
  1820. br.Msg = "分类不存在"
  1821. br.ErrMsg = "分类不存在,Err:" + err.Error()
  1822. return
  1823. }
  1824. item.IsPublic = req.IsPublic
  1825. item.PublicTime = time.Now()
  1826. if req.IsPublic == 0 {
  1827. // 取消公开同时取消客户公开
  1828. item.IsCompanyPublic = 0
  1829. }
  1830. err = item.Update([]string{"IsPublic", "PublicTime", "IsCompanyPublic"})
  1831. if err != nil {
  1832. br.Msg = "修改失败"
  1833. br.ErrMsg = "修改是否公开失败,Err:" + err.Error()
  1834. return
  1835. }
  1836. //新增操作日志
  1837. {
  1838. edbLog := new(data_manage.MyChartLog)
  1839. edbLog.MyChartId = 0
  1840. edbLog.ChartInfoId = 0
  1841. edbLog.SysUserId = sysUser.AdminId
  1842. edbLog.SysUserRealName = sysUser.RealName
  1843. edbLog.CreateTime = time.Now()
  1844. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1845. edbLog.Status = "修改分类是否公开"
  1846. edbLog.Method = this.Ctx.Input.URI()
  1847. go data_manage.AddMyChartLog(edbLog)
  1848. }
  1849. br.Ret = 200
  1850. br.Msg = "修改成功"
  1851. br.Success = true
  1852. br.IsAddLog = true
  1853. }
  1854. // CopyClassifyAndChart
  1855. // @Title 复制我的图表分类
  1856. // @Description 复制我的图表分类接口
  1857. // @Param request body data_manage.CopyChartClassifyReq true "type json string"
  1858. // @Success 200 Ret=200 复制成功
  1859. // @router /classify/copy [post]
  1860. func (this *MyChartController) CopyClassifyAndChart() {
  1861. br := new(models.BaseResponse).Init()
  1862. defer func() {
  1863. this.Data["json"] = br
  1864. this.ServeJSON()
  1865. }()
  1866. sysUser := this.SysUser
  1867. if sysUser == nil {
  1868. br.Msg = "请登录"
  1869. br.ErrMsg = "请登录,SysUser Is Empty"
  1870. br.Ret = 408
  1871. return
  1872. }
  1873. var req data_manage.CopyChartClassifyReq
  1874. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1875. if err != nil {
  1876. br.Msg = "参数解析异常!"
  1877. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1878. return
  1879. }
  1880. //查询该公共分类存不存在
  1881. item, err := data_manage.GetPublicMyChartClassifyById(req.MyChartClassifyId)
  1882. if err != nil && !utils.IsErrNoRow(err) {
  1883. br.Msg = "复制失败,找不到该分类"
  1884. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1885. return
  1886. }
  1887. if item == nil {
  1888. br.Msg = "分类不存在"
  1889. br.ErrMsg = "分类不存在,Err:" + err.Error()
  1890. return
  1891. }
  1892. //获取所有的分类名称
  1893. chartClassifyList, err := data_manage.GetMyChartClassifyAll(sysUser.AdminId)
  1894. //生成新的分类名称
  1895. newChartClassifyName := generateMyChartClassifyName(item.MyChartClassifyName, 1, chartClassifyList)
  1896. //复制分类
  1897. newMyChartClassify, err := data_manage.CopyPublicMyChartClassifyById(item.MyChartClassifyId, sysUser.AdminId, newChartClassifyName)
  1898. if err != nil {
  1899. br.Msg = "复制失败"
  1900. br.ErrMsg = "复制失败,Err:" + err.Error()
  1901. return
  1902. }
  1903. //新增操作日志
  1904. {
  1905. edbLog := new(data_manage.MyChartLog)
  1906. edbLog.MyChartId = 0
  1907. edbLog.ChartInfoId = 0
  1908. edbLog.SysUserId = sysUser.AdminId
  1909. edbLog.SysUserRealName = sysUser.RealName
  1910. edbLog.CreateTime = time.Now()
  1911. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1912. edbLog.Status = "复制分类"
  1913. edbLog.Method = this.Ctx.Input.URI()
  1914. go data_manage.AddMyChartLog(edbLog)
  1915. }
  1916. br.Data = newMyChartClassify
  1917. br.Ret = 200
  1918. br.Msg = "复制成功"
  1919. br.Success = true
  1920. br.IsAddLog = true
  1921. }
  1922. // generateMyChartClassifyName 生成我的图库分类名称
  1923. func generateMyChartClassifyName(myChartClassifyName string, count int, chartClassifyList []*data_manage.MyChartClassify) (newChartClassifyName string) {
  1924. newChartClassifyName = fmt.Sprint(myChartClassifyName, count)
  1925. for _, v := range chartClassifyList {
  1926. if v.MyChartClassifyName == newChartClassifyName {
  1927. count++
  1928. newChartClassifyName = generateMyChartClassifyName(fmt.Sprint(myChartClassifyName), count, chartClassifyList)
  1929. return
  1930. }
  1931. }
  1932. return
  1933. }
  1934. // ModifyClassifyPublicStatus
  1935. // @Title 修改公共分类是否用户可见
  1936. // @Description 修改公共分类是否用户可见接口
  1937. // @Param request body data_manage.ModifyChartClassifyCompanyPublicReq true "type json string"
  1938. // @Success 200 Ret=200 修改成功
  1939. // @router /classify/modify_company_public [post]
  1940. func (this *MyChartController) ModifyClassifyCompanyPublicStatus() {
  1941. br := new(models.BaseResponse).Init()
  1942. defer func() {
  1943. this.Data["json"] = br
  1944. this.ServeJSON()
  1945. }()
  1946. sysUser := this.SysUser
  1947. if sysUser == nil {
  1948. br.Msg = "请登录"
  1949. br.ErrMsg = "请登录,SysUser Is Empty"
  1950. br.Ret = 408
  1951. return
  1952. }
  1953. var req data_manage.ModifyChartClassifyCompanyPublicReq
  1954. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1955. if err != nil {
  1956. br.Msg = "参数解析异常!"
  1957. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1958. return
  1959. }
  1960. item, err := data_manage.GetPublicMyChartClassifyById(req.MyChartClassifyId)
  1961. if err != nil {
  1962. br.Msg = "找不到该分类"
  1963. br.ErrMsg = "获取分类信息失败, Err:" + err.Error()
  1964. return
  1965. }
  1966. if item.IsPublic != 1 {
  1967. br.Msg = "该分类未公开,不可设置为用户可见"
  1968. br.ErrMsg = "该分类未公开,不可设置为用户可见"
  1969. return
  1970. }
  1971. item.IsCompanyPublic = req.IsCompanyPublic
  1972. item.CompanyPublicTime = time.Now()
  1973. err = item.Update([]string{"IsCompanyPublic", "CompanyPublicTime"})
  1974. if err != nil {
  1975. br.Msg = "修改失败"
  1976. br.ErrMsg = "修改是否用户可见失败, Err:" + err.Error()
  1977. return
  1978. }
  1979. {
  1980. edbLog := new(data_manage.MyChartLog)
  1981. edbLog.MyChartId = 0
  1982. edbLog.ChartInfoId = 0
  1983. edbLog.SysUserId = sysUser.AdminId
  1984. edbLog.SysUserRealName = sysUser.RealName
  1985. edbLog.CreateTime = time.Now()
  1986. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1987. edbLog.Status = "修改用户是否可见"
  1988. edbLog.Method = this.Ctx.Input.URI()
  1989. go data_manage.AddMyChartLog(edbLog)
  1990. }
  1991. br.Ret = 200
  1992. br.Msg = "修改成功"
  1993. br.Success = true
  1994. br.IsAddLog = true
  1995. }
  1996. // CompanyPublicClassifyList
  1997. // @Title 我的图表-用户可见分类列表
  1998. // @Description 我的图表-用户可见分类列表接口
  1999. // @Param Keyword query string false "分类名称关键词"
  2000. // @Success 200 {object} data_manage.MyChartClassifyResp
  2001. // @router /classify/company_public_list [get]
  2002. func (this *MyChartController) CompanyPublicClassifyList() {
  2003. br := new(models.BaseResponse).Init()
  2004. defer func() {
  2005. this.Data["json"] = br
  2006. this.ServeJSON()
  2007. }()
  2008. sysUser := this.SysUser
  2009. if sysUser == nil {
  2010. br.Msg = "请登录"
  2011. br.ErrMsg = "请登录,SysUser Is Empty"
  2012. br.Ret = 408
  2013. return
  2014. }
  2015. var condition string
  2016. var pars []interface{}
  2017. keyword := this.GetString("Keyword")
  2018. if keyword != "" {
  2019. keyword = "%" + keyword + "%"
  2020. condition += ` AND my_chart_classify_name LIKE ? `
  2021. pars = append(pars, keyword)
  2022. }
  2023. list, err := data_manage.GetCompanyPublicClassifyList(condition, pars)
  2024. if err != nil && !utils.IsErrNoRow(err) {
  2025. br.Success = true
  2026. br.Msg = "获取用户可见分类列表失败"
  2027. br.ErrMsg = "获取用户可见分类列表失败, Err:" + err.Error()
  2028. return
  2029. }
  2030. resp := new(data_manage.MyChartClassifyResp)
  2031. if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
  2032. items := make([]*data_manage.MyChartClassifyItem, 0)
  2033. resp.List = items
  2034. br.Ret = 200
  2035. br.Success = true
  2036. br.Msg = "获取成功"
  2037. return
  2038. }
  2039. results := make([]*data_manage.MyChartClassifyItem, 0)
  2040. for _, v := range list {
  2041. results = append(results, data_manage.FormatMyChartClassify2Item(v, 0))
  2042. }
  2043. resp.List = results
  2044. //resp.List = list
  2045. br.Ret = 200
  2046. br.Success = true
  2047. br.Msg = "获取成功"
  2048. br.Data = resp
  2049. }
  2050. // ClassifyFrameworkNodeList
  2051. // @Title 我的图表分类-关联的框架节点列表
  2052. // @Description 我的图表分类-关联的框架节点列表
  2053. // @Param MyChartClassifyId query int false "图表分类ID"
  2054. // @Success 200 Ret=200 获取成功
  2055. // @router /classify/framework_node_list [get]
  2056. func (this *MyChartController) ClassifyFrameworkNodeList() {
  2057. br := new(models.BaseResponse).Init()
  2058. defer func() {
  2059. if br.ErrMsg == "" {
  2060. br.IsSendEmail = true
  2061. }
  2062. this.Data["json"] = br
  2063. this.ServeJSON()
  2064. }()
  2065. sysUser := this.SysUser
  2066. if sysUser == nil {
  2067. br.Msg = "请登录"
  2068. br.ErrMsg = "请登录,SysUser Is Empty"
  2069. br.Ret = 408
  2070. return
  2071. }
  2072. classifyId, _ := this.GetInt("MyChartClassifyId")
  2073. if classifyId <= 0 {
  2074. br.Msg = "参数有误"
  2075. br.ErrMsg = fmt.Sprintf("参数有误, MyChartClassifyId: %d", classifyId)
  2076. return
  2077. }
  2078. _, e := data_manage.GetMyChartClassifyById(sysUser.AdminId, classifyId)
  2079. if e != nil {
  2080. if utils.IsErrNoRow(e) {
  2081. br.Msg = "分类不存在, 请刷新页面"
  2082. return
  2083. }
  2084. br.Msg = "获取失败"
  2085. br.ErrMsg = "获取分类信息失败, Err:" + e.Error()
  2086. return
  2087. }
  2088. nodeOb := new(data_manage.ChartFrameworkNode)
  2089. cond := ` AND my_chart_classify_id = ?`
  2090. pars := make([]interface{}, 0)
  2091. pars = append(pars, classifyId)
  2092. nodes, e := nodeOb.GetItemsByCondition(cond, pars, []string{}, "")
  2093. if e != nil {
  2094. br.Msg = "获取失败"
  2095. br.ErrMsg = "获取我的图表分类关联的框架节点失败, Err: " + e.Error()
  2096. return
  2097. }
  2098. resp := make([]*data_manage.ChartFrameworkNodeItem, 0)
  2099. for _, v := range nodes {
  2100. resp = append(resp, data_manage.FormatChartFrameworkNode2Item(v, 0))
  2101. }
  2102. br.Data = resp
  2103. br.Ret = 200
  2104. br.Msg = "获取成功"
  2105. br.Success = true
  2106. }