my_chart.go 59 KB

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