my_chart.go 67 KB

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