my_chart.go 56 KB

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