balance_table.go 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  1. package excel
  2. import (
  3. "archive/zip"
  4. "encoding/json"
  5. "errors"
  6. "eta/eta_api/models"
  7. "eta/eta_api/models/data_manage"
  8. "eta/eta_api/models/data_manage/excel"
  9. "eta/eta_api/models/data_manage/excel/request"
  10. "eta/eta_api/models/data_manage/excel/response"
  11. "eta/eta_api/models/system"
  12. "eta/eta_api/services/data"
  13. "eta/eta_api/services/data/data_manage_permission"
  14. excelService "eta/eta_api/services/data/excel"
  15. etaTrialService "eta/eta_api/services/eta_trial"
  16. excel2 "eta/eta_api/services/excel"
  17. "eta/eta_api/utils"
  18. "fmt"
  19. "github.com/tealeg/xlsx"
  20. "io/ioutil"
  21. "os"
  22. "sort"
  23. "strconv"
  24. "strings"
  25. "time"
  26. )
  27. // GetChildTable
  28. // @Title 获取子表
  29. // @Description 获取子表
  30. // @Param request body request.MixedTableCellDataReq true "type json string"
  31. // @router /excel_info/child_table [get]
  32. func (c *ExcelInfoController) GetChildTable() {
  33. br := new(models.BaseResponse).Init()
  34. defer func() {
  35. c.Data["json"] = br
  36. c.ServeJSON()
  37. }()
  38. sysUser := c.SysUser
  39. if sysUser == nil {
  40. br.Msg = "请登录"
  41. br.ErrMsg = "请登录,SysUser Is Empty"
  42. br.Ret = 408
  43. return
  44. }
  45. parentId, _ := c.GetInt("ParentId")
  46. if parentId <= 0 {
  47. br.Msg = "请选择父表"
  48. return
  49. }
  50. list := make([]*excel.ExcelInfo, 0)
  51. // 查询所有子表
  52. childList, err := excel.GetChildExcelInfoByParentId(parentId)
  53. if err != nil {
  54. br.Msg = "查询子表失败"
  55. return
  56. }
  57. if len(childList) > 0 {
  58. list = childList
  59. }
  60. resp := &response.BalanceChildTableResp{List: list}
  61. br.Ret = 200
  62. br.Success = true
  63. br.Msg = "查询成功"
  64. br.Data = resp
  65. }
  66. // Rename
  67. // @Title 表格重命名接口
  68. // @Description 表格重命名接口
  69. // @Param request body request.EditExcelInfoReq true "type json string"
  70. // @Success 200 {object} response.AddExcelInfoResp
  71. // @router /excel_info/rename [post]
  72. func (c *ExcelInfoController) Rename() {
  73. br := new(models.BaseResponse).Init()
  74. defer func() {
  75. c.Data["json"] = br
  76. c.ServeJSON()
  77. }()
  78. sysUser := c.SysUser
  79. if sysUser == nil {
  80. br.Msg = "请登录"
  81. br.ErrMsg = "请登录,SysUser Is Empty"
  82. br.Ret = 408
  83. return
  84. }
  85. var req request.RenameExcelInfoReq
  86. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  87. if err != nil {
  88. br.Msg = "参数解析异常!"
  89. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  90. return
  91. }
  92. if req.ExcelInfoId <= 0 {
  93. br.Msg = "请传入ETA表格标识!"
  94. return
  95. }
  96. req.ExcelName = strings.Trim(req.ExcelName, " ")
  97. if req.ExcelName == "" {
  98. br.Msg = "请填写表格名称!"
  99. br.IsSendEmail = false
  100. return
  101. }
  102. excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  103. if err != nil {
  104. br.Msg = "获取ETA表格失败"
  105. br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
  106. return
  107. }
  108. //判断表格是否存在
  109. var condition string
  110. var pars []interface{}
  111. condition += " AND excel_info_id != ? AND excel_classify_id=? AND excel_name=? AND parent_id=?"
  112. pars = append(pars, req.ExcelInfoId, excelInfo.ExcelClassifyId, req.ExcelName, excelInfo.ParentId)
  113. // 获取分类下是否存在该表格名称
  114. count, err := excel.GetExcelInfoCountByCondition(condition, pars)
  115. if err != nil {
  116. br.Msg = "ETA判断表格名称是否存在失败"
  117. br.ErrMsg = "判断ETA表格名称是否存在失败,Err:" + err.Error()
  118. return
  119. }
  120. if count > 0 {
  121. br.Msg = "ETA表格名称已存在,请重新填写"
  122. br.IsSendEmail = false
  123. return
  124. }
  125. // 操作权限校验, 增加协作人判断
  126. {
  127. checkExcelInfo := excelInfo
  128. if excelInfo.Source == utils.BALANCE_TABLE {
  129. checkExcelInfoId := excelInfo.ExcelInfoId
  130. if excelInfo.BalanceType == 1 {
  131. checkExcelInfoId = excelInfo.RelExcelInfoId
  132. } else {
  133. if excelInfo.ParentId > 0 {
  134. checkExcelInfoId = excelInfo.ParentId
  135. }
  136. }
  137. if checkExcelInfoId != excelInfo.ExcelInfoId {
  138. checkExcelInfo, err = excel.GetExcelInfoById(checkExcelInfoId)
  139. if err != nil {
  140. br.Msg = "获取平衡表格信息失败"
  141. br.ErrMsg = "获取平衡表格信息失败,Err:" + err.Error()
  142. return
  143. }
  144. }
  145. }
  146. // 数据权限
  147. haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  148. if e != nil {
  149. br.Msg = "获取ETA表格权限失败"
  150. br.ErrMsg = "获取表格权限信息失败,Err" + e.Error()
  151. return
  152. }
  153. button := excelService.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
  154. if !button.OpButton {
  155. br.Msg = "无操作权限"
  156. br.IsSendEmail = false
  157. return
  158. }
  159. }
  160. excelInfo.ModifyTime = time.Now()
  161. excelInfo.ExcelName = req.ExcelName
  162. excelInfo.UpdateUserId = sysUser.AdminId
  163. excelInfo.UpdateUserRealName = sysUser.RealName
  164. // 自动保存时不会传缩略图,也就不更新这个字段
  165. updateExcelInfoParams := []string{"ModifyTime", "ExcelName", "UpdateUserId", "UpdateUserRealName"}
  166. err = excelInfo.Update(updateExcelInfoParams)
  167. if err != nil {
  168. br.Msg = "保存失败"
  169. br.ErrMsg = "保存失败,Err:" + err.Error()
  170. return
  171. }
  172. resp := response.AddExcelInfoResp{
  173. ExcelInfoId: excelInfo.ExcelInfoId,
  174. UniqueCode: excelInfo.UniqueCode,
  175. }
  176. //删除公共图库那边的缓存
  177. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelInfo.UniqueCode)
  178. br.Ret = 200
  179. br.Success = true
  180. br.Msg = "修改成功"
  181. br.Data = resp
  182. br.IsAddLog = true
  183. }
  184. // SaveExcelWorker
  185. // @Title 新增编辑表格协作人接口
  186. // @Description 新增编辑表格协作人接口
  187. // @Param request body request.EditExcelInfoReq true "type json string"
  188. // @Success 200 {object} response.AddExcelInfoResp
  189. // @router /excel_info/worker/save [post]
  190. func (c *ExcelInfoController) SaveExcelWorker() {
  191. br := new(models.BaseResponse).Init()
  192. defer func() {
  193. c.Data["json"] = br
  194. c.ServeJSON()
  195. }()
  196. sysUser := c.SysUser
  197. if sysUser == nil {
  198. br.Msg = "请登录"
  199. br.ErrMsg = "请登录,SysUser Is Empty"
  200. br.Ret = 408
  201. return
  202. }
  203. var req request.SaveExcelInfoWorkerReq
  204. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  205. if err != nil {
  206. br.Msg = "参数解析异常!"
  207. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  208. return
  209. }
  210. if req.ExcelInfoId <= 0 {
  211. br.Msg = "请传入ETA表格标识!"
  212. return
  213. }
  214. excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  215. if err != nil {
  216. br.Msg = "获取ETA表格失败"
  217. br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
  218. return
  219. }
  220. if excelInfo.SysUserId != sysUser.AdminId {
  221. br.Msg = "您没有权限操作!"
  222. br.ErrMsg = "您没有权限操作!"
  223. return
  224. }
  225. // 操作权限校验, 增加协作人判断
  226. {
  227. // 数据权限
  228. haveOperaAuth, err := data_manage_permission.CheckExcelPermissionByExcelInfoId(excelInfo.ExcelInfoId, excelInfo.ExcelClassifyId, excelInfo.IsJoinPermission, c.SysUser.AdminId)
  229. if err != nil {
  230. br.Msg = "获取ETA表格失败"
  231. br.ErrMsg = "获取ETA表格权限失败,Err:" + err.Error()
  232. return
  233. }
  234. button := excelService.GetExcelInfoOpButton(sysUser, excelInfo.SysUserId, excelInfo.Source, haveOperaAuth)
  235. if !button.OpButton {
  236. br.Msg = "无操作权限"
  237. br.IsSendEmail = false
  238. return
  239. }
  240. }
  241. obj := new(excel.ExcelWorker)
  242. notDeleteWorkerIds := make([]string, 0)
  243. workerMap := make(map[int]struct{})
  244. if req.SysUserIds != "" {
  245. notDeleteWorkerIds = strings.Split(req.SysUserIds, ",")
  246. }
  247. existList, err := obj.GetByExcelInfoId(req.ExcelInfoId)
  248. if err != nil {
  249. br.Msg = "获取表格协作人失败!"
  250. br.ErrMsg = "获取表格协作人失败,Err:" + err.Error()
  251. return
  252. }
  253. for _, v := range existList {
  254. workerMap[v.SysUserId] = struct{}{}
  255. }
  256. addIds := make([]int, 0)
  257. for _, v := range notDeleteWorkerIds {
  258. id, _ := strconv.Atoi(v)
  259. if _, ok := workerMap[id]; !ok {
  260. addIds = append(addIds, id)
  261. }
  262. }
  263. // 查询协作人姓名
  264. adminList, err := system.GetAdminListByIdListWithoutEnable(addIds)
  265. addList := make([]*excel.ExcelWorker, 0)
  266. for _, v := range adminList {
  267. addList = append(addList, &excel.ExcelWorker{
  268. ExcelInfoId: req.ExcelInfoId,
  269. SysUserId: v.AdminId,
  270. SysUserRealName: v.RealName,
  271. CreateTime: time.Now(),
  272. ModifyTime: time.Now(),
  273. })
  274. }
  275. // 保存协作人
  276. err = obj.AddWorker(req.ExcelInfoId, addList, notDeleteWorkerIds)
  277. if err != nil {
  278. br.Msg = "保存失败"
  279. br.ErrMsg = "保存失败,Err:" + err.Error()
  280. return
  281. }
  282. br.Ret = 200
  283. br.Success = true
  284. br.Msg = "操作成功"
  285. }
  286. // GetWorker
  287. // @Title 查询协作人接口
  288. // @Description 新增编辑表格协作人接口
  289. // @Param request body request.EditExcelInfoReq true "type json string"
  290. // @Success 200 {object} response.AddExcelInfoResp
  291. // @router /excel_info/worker [get]
  292. func (c *ExcelInfoController) GetWorker() {
  293. br := new(models.BaseResponse).Init()
  294. defer func() {
  295. c.Data["json"] = br
  296. c.ServeJSON()
  297. }()
  298. sysUser := c.SysUser
  299. if sysUser == nil {
  300. br.Msg = "请登录"
  301. br.ErrMsg = "请登录,SysUser Is Empty"
  302. br.Ret = 408
  303. return
  304. }
  305. excelInfoId, _ := c.GetInt("ExcelInfoId")
  306. if excelInfoId <= 0 {
  307. br.Msg = "请选择表格"
  308. br.ErrMsg = "ExcelInfoId未传"
  309. br.IsSendEmail = false
  310. return
  311. }
  312. obj := new(excel.ExcelWorker)
  313. list, err := obj.GetByExcelInfoId(excelInfoId)
  314. if err != nil {
  315. br.Msg = "获取表格协作人失败!"
  316. br.ErrMsg = "获取表格协作人失败,Err:" + err.Error()
  317. return
  318. }
  319. ret := &response.BalanceTableWorkerResp{List: list}
  320. br.Data = ret
  321. br.Ret = 200
  322. br.Success = true
  323. br.Msg = "操作成功"
  324. }
  325. // BalanceChartInfoAdd
  326. // @Title 新增图表接口
  327. // @Description 新增图表接口
  328. // @Param request body data_manage.AddChartInfoReq true "type json string"
  329. // @Success 200 {object} data_manage.AddChartInfoResp
  330. // @router /excel_info/balance/chart_add [post]
  331. func (c *ExcelInfoController) BalanceChartInfoAdd() {
  332. br := new(models.BaseResponse).Init()
  333. defer func() {
  334. c.Data["json"] = br
  335. c.ServeJSON()
  336. }()
  337. sysUser := c.SysUser
  338. if sysUser == nil {
  339. br.Msg = "请登录"
  340. br.ErrMsg = "请登录,SysUser Is Empty"
  341. br.Ret = 408
  342. return
  343. }
  344. deleteCache := true
  345. cacheKey := "CACHE_EXCEL_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  346. defer func() {
  347. if deleteCache {
  348. utils.Rc.Delete(cacheKey)
  349. }
  350. }()
  351. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  352. deleteCache = false
  353. br.Msg = "系统处理中,请稍后重试!"
  354. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  355. return
  356. }
  357. var req request.AddBalanceTableChartReq
  358. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  359. if err != nil {
  360. br.Msg = "参数解析异常!"
  361. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  362. return
  363. }
  364. req.ChartName = strings.Trim(req.ChartName, " ")
  365. if req.ChartName == "" {
  366. br.Msg = "请填写图表名称!"
  367. return
  368. }
  369. // 获取表格信息
  370. excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  371. if err != nil {
  372. br.Msg = "获取ETA表格失败"
  373. return
  374. }
  375. if excelInfo.Source != utils.BALANCE_TABLE {
  376. br.Msg = "EXCEL类型错误!"
  377. return
  378. }
  379. // 操作权限校验, 增加协作人判断
  380. {
  381. checkExcelInfo := excelInfo
  382. if excelInfo.Source == utils.BALANCE_TABLE {
  383. checkExcelInfoId := excelInfo.ExcelInfoId
  384. if excelInfo.BalanceType == 1 {
  385. checkExcelInfoId = excelInfo.RelExcelInfoId
  386. } else {
  387. if excelInfo.ParentId > 0 {
  388. checkExcelInfoId = excelInfo.ParentId
  389. }
  390. }
  391. if checkExcelInfoId != excelInfo.ExcelInfoId {
  392. checkExcelInfo, err = excel.GetExcelInfoById(checkExcelInfoId)
  393. if err != nil {
  394. br.Msg = "获取平衡表格信息失败"
  395. br.ErrMsg = "获取平衡表格信息失败,Err:" + err.Error()
  396. return
  397. }
  398. }
  399. }
  400. // 数据权限
  401. haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  402. if e != nil {
  403. br.Msg = "获取ETA表格权限失败"
  404. br.ErrMsg = "获取表格权限信息失败,Err" + e.Error()
  405. return
  406. }
  407. button := excelService.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
  408. if !button.OpButton {
  409. br.Msg = "无操作权限"
  410. br.IsSendEmail = false
  411. return
  412. }
  413. }
  414. // 判断如果是静态表,则查询表数据,落库
  415. dataListMap := make(map[int][]*data_manage.EdbDataList)
  416. if excelInfo.BalanceType == 1 {
  417. newExcelDataMap, excelAllRows, excelAllCols, e, errMsg := excelService.GetBalanceExcelData(excelInfo, c.Lang)
  418. if e != nil {
  419. br.Msg = "获取表格数据失败"
  420. if errMsg != "" {
  421. br.Msg = errMsg
  422. }
  423. br.ErrMsg = "获取表格数据失败,Err:" + e.Error()
  424. return
  425. }
  426. for k, mapping := range req.ChartEdbInfoList {
  427. tmpMapping := &excel.ExcelChartEdb{
  428. ExcelChartEdbId: k,
  429. DateSequence: mapping.DateSequenceStr,
  430. DataSequence: mapping.DataSequenceStr,
  431. }
  432. er, msg := excelService.GetBalanceExcelEdbData(tmpMapping, newExcelDataMap, dataListMap, excelAllRows, excelAllCols)
  433. if er != nil {
  434. utils.FileLog.Info(fmt.Sprintf(" 获取图表,指标信息失败 Err:%s, %s", msg, er.Error()))
  435. continue
  436. }
  437. }
  438. }
  439. chartInfo, err, errMsg, isSendEmail := data.AddBalanceExcelChart(excelInfo, req, sysUser, dataListMap)
  440. if err != nil {
  441. br.Msg = "保存失败"
  442. if errMsg != `` {
  443. br.Msg = errMsg
  444. }
  445. br.ErrMsg = err.Error()
  446. br.IsSendEmail = isSendEmail
  447. return
  448. }
  449. resp := new(data_manage.AddChartInfoResp)
  450. resp.ChartInfoId = chartInfo.ChartInfoId
  451. resp.UniqueCode = chartInfo.UniqueCode
  452. resp.ChartType = req.ChartType
  453. //新增操作日志
  454. {
  455. chartLog := new(data_manage.ChartInfoLog)
  456. chartLog.ChartInfoId = chartInfo.ChartInfoId
  457. chartLog.ChartName = req.ChartName
  458. chartLog.ChartClassifyId = 0
  459. chartLog.SysUserId = sysUser.AdminId
  460. chartLog.SysUserRealName = sysUser.RealName
  461. chartLog.UniqueCode = chartInfo.UniqueCode
  462. chartLog.CreateTime = time.Now()
  463. chartLog.Content = string(c.Ctx.Input.RequestBody)
  464. chartLog.Status = "新增图表"
  465. chartLog.Method = c.Ctx.Input.URI()
  466. go data_manage.AddChartInfoLog(chartLog)
  467. }
  468. // 试用平台更新用户累计新增图表数
  469. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  470. if e != nil {
  471. br.Msg = "操作失败"
  472. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  473. return
  474. }
  475. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  476. go func() {
  477. var r etaTrialService.EtaTrialUserReq
  478. r.Mobile = adminItem.Mobile
  479. _, _ = etaTrialService.UpdateUserChartNum(r)
  480. }()
  481. }
  482. br.Ret = 200
  483. br.Success = true
  484. br.Msg = "保存成功"
  485. br.Data = resp
  486. br.IsAddLog = true
  487. }
  488. // BalanceChartInfoEdit
  489. // @Title 编辑图表接口
  490. // @Description 新增图表接口
  491. // @Param request body data_manage.AddChartInfoReq true "type json string"
  492. // @Success 200 {object} data_manage.AddChartInfoResp
  493. // @router /excel_info/balance/chart_edit [post]
  494. func (c *ExcelInfoController) BalanceChartInfoEdit() {
  495. br := new(models.BaseResponse).Init()
  496. defer func() {
  497. c.Data["json"] = br
  498. c.ServeJSON()
  499. }()
  500. sysUser := c.SysUser
  501. if sysUser == nil {
  502. br.Msg = "请登录"
  503. br.ErrMsg = "请登录,SysUser Is Empty"
  504. br.Ret = 408
  505. return
  506. }
  507. deleteCache := true
  508. cacheKey := "CACHE_EXCEL_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  509. defer func() {
  510. if deleteCache {
  511. utils.Rc.Delete(cacheKey)
  512. }
  513. }()
  514. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  515. deleteCache = false
  516. br.Msg = "系统处理中,请稍后重试!"
  517. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  518. return
  519. }
  520. var req request.AddBalanceTableChartReq
  521. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  522. if err != nil {
  523. br.Msg = "参数解析异常!"
  524. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  525. return
  526. }
  527. req.ChartName = strings.Trim(req.ChartName, " ")
  528. if req.ChartName == "" {
  529. br.Msg = "请填写图表名称!"
  530. return
  531. }
  532. if req.ChartInfoId <= 0 {
  533. br.Msg = "请选择图表"
  534. return
  535. }
  536. // 获取表格信息
  537. excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  538. if err != nil {
  539. br.Msg = "获取ETA表格失败"
  540. return
  541. }
  542. if excelInfo.Source != utils.BALANCE_TABLE {
  543. br.Msg = "EXCEL类型错误!"
  544. return
  545. }
  546. // 操作权限校验, 增加协作人判断
  547. {
  548. checkExcelInfo := excelInfo
  549. if excelInfo.Source == utils.BALANCE_TABLE {
  550. checkExcelInfoId := excelInfo.ExcelInfoId
  551. if excelInfo.BalanceType == 1 {
  552. checkExcelInfoId = excelInfo.RelExcelInfoId
  553. } else {
  554. if excelInfo.ParentId > 0 {
  555. checkExcelInfoId = excelInfo.ParentId
  556. }
  557. }
  558. if checkExcelInfoId != excelInfo.ExcelInfoId {
  559. checkExcelInfo, err = excel.GetExcelInfoById(checkExcelInfoId)
  560. if err != nil {
  561. br.Msg = "获取平衡表格信息失败"
  562. br.ErrMsg = "获取平衡表格信息失败,Err:" + err.Error()
  563. return
  564. }
  565. }
  566. }
  567. // 数据权限
  568. haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  569. if e != nil {
  570. br.Msg = "获取ETA表格权限失败"
  571. br.ErrMsg = "获取表格权限信息失败,Err" + e.Error()
  572. return
  573. }
  574. button := excelService.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
  575. if !button.OpButton {
  576. br.Msg = "无操作权限"
  577. br.IsSendEmail = false
  578. return
  579. }
  580. }
  581. // 判断如果是静态表,则查询表数据,落库
  582. dataListMap := make(map[int][]*data_manage.EdbDataList)
  583. if excelInfo.BalanceType == 1 {
  584. newExcelDataMap, excelAllRows, excelAllCols, e, errMsg := excelService.GetBalanceExcelData(excelInfo, c.Lang)
  585. if e != nil {
  586. br.Msg = "获取表格数据失败"
  587. if errMsg != "" {
  588. br.Msg = errMsg
  589. }
  590. br.ErrMsg = "获取表格数据失败,Err:" + e.Error()
  591. return
  592. }
  593. for k, mapping := range req.ChartEdbInfoList {
  594. tmpMapping := &excel.ExcelChartEdb{
  595. ExcelChartEdbId: k,
  596. DateSequence: mapping.DateSequenceStr,
  597. DataSequence: mapping.DataSequenceStr,
  598. }
  599. er, msg := excelService.GetBalanceExcelEdbData(tmpMapping, newExcelDataMap, dataListMap, excelAllRows, excelAllCols)
  600. if er != nil {
  601. utils.FileLog.Info(fmt.Sprintf(" 获取图表,指标信息失败 Err:%s, %s", msg, er.Error()))
  602. continue
  603. }
  604. }
  605. }
  606. chartItem, err, errMsg, isSendEmail := data.EditBalanceExcelChart(excelInfo, req, sysUser, dataListMap)
  607. if err != nil {
  608. br.Msg = "保存失败"
  609. if errMsg != `` {
  610. br.Msg = errMsg
  611. }
  612. br.ErrMsg = err.Error()
  613. br.IsSendEmail = isSendEmail
  614. return
  615. }
  616. resp := new(data_manage.AddChartInfoResp)
  617. resp.ChartInfoId = chartItem.ChartInfoId
  618. resp.UniqueCode = chartItem.UniqueCode
  619. resp.ChartType = req.ChartType
  620. //新增操作日志
  621. {
  622. chartLog := new(data_manage.ChartInfoLog)
  623. chartLog.ChartName = chartItem.ChartName
  624. chartLog.ChartInfoId = req.ChartInfoId
  625. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  626. chartLog.SysUserId = sysUser.AdminId
  627. chartLog.SysUserRealName = sysUser.RealName
  628. chartLog.UniqueCode = chartItem.UniqueCode
  629. chartLog.CreateTime = time.Now()
  630. chartLog.Content = string(c.Ctx.Input.RequestBody)
  631. chartLog.Status = "编辑图表"
  632. chartLog.Method = c.Ctx.Input.URL()
  633. go data_manage.AddChartInfoLog(chartLog)
  634. }
  635. br.Ret = 200
  636. br.Success = true
  637. br.Msg = "保存成功"
  638. br.Data = resp
  639. br.IsAddLog = true
  640. }
  641. // GetBalanceChartList
  642. // @Title 获取平衡表表关联的图表
  643. // @Description 获取平衡表表关联的图表
  644. // @Param request body request.MixedTableCellDataReq true "type json string"
  645. // @router /excel_info/balance/chart_list [get]
  646. func (c *ExcelInfoController) GetBalanceChartList() {
  647. br := new(models.BaseResponse).Init()
  648. defer func() {
  649. c.Data["json"] = br
  650. c.ServeJSON()
  651. }()
  652. sysUser := c.SysUser
  653. if sysUser == nil {
  654. br.Msg = "请登录"
  655. br.ErrMsg = "请登录,SysUser Is Empty"
  656. br.Ret = 408
  657. return
  658. }
  659. excelInfoId, _ := c.GetInt("ExcelInfoId")
  660. if excelInfoId <= 0 {
  661. br.Msg = "请选择平衡表"
  662. return
  663. }
  664. // 查询所有子表
  665. excelInfo, err := excel.GetExcelInfoById(excelInfoId)
  666. if err != nil {
  667. if err.Error() == utils.ErrNoRow() {
  668. br.Msg = "表格不存在"
  669. return
  670. }
  671. br.Msg = "查询子表失败"
  672. br.ErrMsg = "查询子表失败,Err:" + err.Error()
  673. return
  674. }
  675. list := make([]*data_manage.BalanceChartInfoDetailResp, 0)
  676. chartInfoList, mappingListMap, dataListMap, err, errMsg := excelService.GetBalanceExcelChartList(excelInfo, "")
  677. if err != nil {
  678. if errMsg != "" {
  679. br.Msg = errMsg
  680. br.ErrMsg = err.Error()
  681. return
  682. } else {
  683. br.Msg = "查询图表失败"
  684. br.ErrMsg = "查询图表失败,Err:" + err.Error()
  685. }
  686. return
  687. }
  688. for _, chartInfo := range chartInfoList {
  689. mappingList, ok := mappingListMap[chartInfo.ChartInfoId]
  690. if !ok {
  691. br.Msg = "未找到图表关联的指标信息"
  692. return
  693. }
  694. var chartInfoResp *data_manage.ChartInfoDetailResp
  695. chartInfoResp, err, errMsg = data.GetBalanceExcelChartDetail(chartInfo, mappingList, sysUser, dataListMap)
  696. if err != nil {
  697. br.Msg = "查询图表详情失败"
  698. br.ErrMsg = "查询图表详情失败,Err:" + err.Error()
  699. return
  700. }
  701. chartEdbList := make([]*data_manage.ExcelChartEdbView, 0)
  702. for _, v := range mappingList {
  703. tmp := &data_manage.ExcelChartEdbView{
  704. ExcelChartEdbId: v.ExcelChartEdbId,
  705. DateSequenceStr: v.DateSequence,
  706. DataSequenceStr: v.DataSequence,
  707. FromTag: v.FromTag,
  708. }
  709. chartEdbList = append(chartEdbList, tmp)
  710. }
  711. balanceChartInfoResp := &data_manage.BalanceChartInfoDetailResp{
  712. ChartInfoDetailResp: chartInfoResp,
  713. ExcelEdbList: chartEdbList,
  714. }
  715. list = append(list, balanceChartInfoResp)
  716. }
  717. ret := &data_manage.BalanceTableChartListResp{List: list}
  718. br.Ret = 200
  719. br.Success = true
  720. br.Msg = "查询成功"
  721. br.Data = ret
  722. }
  723. // DeleteBalanceChart
  724. // @Title 删除平衡表图表
  725. // @Description 删除平衡表图表
  726. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  727. // @Success 200 Ret=200 删除成功
  728. // @router /excel_info/balance/chart_del [post]
  729. func (c *ExcelInfoController) DeleteBalanceChart() {
  730. br := new(models.BaseResponse).Init()
  731. defer func() {
  732. c.Data["json"] = br
  733. c.ServeJSON()
  734. }()
  735. sysUser := c.SysUser
  736. if sysUser == nil {
  737. br.Msg = "请登录"
  738. br.ErrMsg = "请登录,SysUser Is Empty"
  739. br.Ret = 408
  740. return
  741. }
  742. var req data_manage.DeleteChartClassifyReq
  743. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  744. if err != nil {
  745. br.Msg = "参数解析异常!"
  746. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  747. return
  748. }
  749. if req.ChartInfoId <= 0 {
  750. br.Msg = "参数错误"
  751. br.IsSendEmail = false
  752. return
  753. }
  754. //删除图表
  755. if req.ChartInfoId > 0 {
  756. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  757. if err != nil {
  758. if err.Error() == utils.ErrNoRow() {
  759. br.Msg = "图表已删除,请刷新页面"
  760. br.ErrMsg = "指标不存在,Err:" + err.Error()
  761. return
  762. } else {
  763. br.Msg = "删除失败"
  764. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  765. return
  766. }
  767. }
  768. if chartInfo == nil {
  769. br.Msg = "图表已删除,请刷新页面"
  770. return
  771. }
  772. // 操作权限校验, 增加协作人判断
  773. {
  774. // 获取表格信息
  775. excelInfo, e := excel.GetExcelInfoByChartInfoId(req.ChartInfoId)
  776. if e != nil {
  777. br.Msg = "获取ETA表格失败"
  778. return
  779. }
  780. checkExcelInfo := excelInfo
  781. if excelInfo.Source == utils.BALANCE_TABLE {
  782. checkExcelInfoId := excelInfo.ExcelInfoId
  783. if excelInfo.BalanceType == 1 {
  784. checkExcelInfoId = excelInfo.RelExcelInfoId
  785. } else {
  786. if excelInfo.ParentId > 0 {
  787. checkExcelInfoId = excelInfo.ParentId
  788. }
  789. }
  790. if checkExcelInfoId != excelInfo.ExcelInfoId {
  791. checkExcelInfo, e = excel.GetExcelInfoById(checkExcelInfoId)
  792. if e != nil {
  793. br.Msg = "获取平衡表格信息失败"
  794. br.ErrMsg = "获取平衡表格信息失败,Err:" + e.Error()
  795. return
  796. }
  797. }
  798. }
  799. // 数据权限
  800. haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  801. if e != nil {
  802. br.Msg = "获取ETA表格权限失败"
  803. br.ErrMsg = "获取表格权限信息失败,Err" + e.Error()
  804. return
  805. }
  806. button := excelService.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
  807. if !button.OpButton {
  808. br.Msg = "无操作权限"
  809. br.IsSendEmail = false
  810. return
  811. }
  812. }
  813. // 获取引用该图表的MyCharts, 用于ES删除
  814. var myCond string
  815. var myPars []interface{}
  816. myCond += ` AND a.chart_info_id = ? `
  817. myPars = append(myPars, req.ChartInfoId)
  818. myCharts, e := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(myCond, myPars)
  819. if e != nil {
  820. br.Msg = "删除失败"
  821. br.ErrMsg = "获取引用图表的MyChats失败, Err: " + e.Error()
  822. return
  823. }
  824. myIds := make([]int, 0)
  825. for _, m := range myCharts {
  826. myIds = append(myIds, m.MyChartId)
  827. }
  828. //删除图表及关联指标
  829. e = excel.DeleteBalanceExcelChartInfoAndData(req.ChartInfoId)
  830. if e != nil {
  831. br.Msg = "删除失败"
  832. br.ErrMsg = "删除失败,Err:" + e.Error()
  833. return
  834. }
  835. //删除ES
  836. {
  837. go data.EsDeleteChartInfo(req.ChartInfoId)
  838. // 删除MY ETA 图表 es数据
  839. //go data.EsDeleteMyChartInfoByChartInfoId(req.ChartInfoId)
  840. go data.EsDeleteMyChartInfoByMyChartIds(myIds)
  841. }
  842. //新增操作日志
  843. {
  844. chartLog := new(data_manage.ChartInfoLog)
  845. chartLog.ChartName = chartInfo.ChartName
  846. chartLog.ChartInfoId = req.ChartInfoId
  847. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  848. chartLog.SysUserId = sysUser.AdminId
  849. chartLog.SysUserRealName = sysUser.RealName
  850. chartLog.UniqueCode = chartInfo.UniqueCode
  851. chartLog.CreateTime = time.Now()
  852. chartLog.Content = string(c.Ctx.Input.RequestBody)
  853. chartLog.Status = "删除图表"
  854. chartLog.Method = c.Ctx.Input.URI()
  855. go data_manage.AddChartInfoLog(chartLog)
  856. }
  857. }
  858. br.Ret = 200
  859. br.Msg = "删除成功"
  860. br.Success = true
  861. br.IsAddLog = true
  862. }
  863. // BalanceSeasonChartLegendPreview
  864. // @Title 季节性图例预览接口
  865. // @Description 季节性图例预览接口
  866. // @Param request body request.BalanceSeasonChartLegendPreviewReq true "type json string"
  867. // @Success 200 {object} data_manage.BalanceSeasonChartLegendPreviewResp
  868. // @router /excel_info/balance/chartLegend/preview [post]
  869. func (c *ExcelInfoController) BalanceSeasonChartLegendPreview() {
  870. br := new(models.BaseResponse).Init()
  871. defer func() {
  872. c.Data["json"] = br
  873. c.ServeJSON()
  874. }()
  875. sysUser := c.SysUser
  876. if sysUser == nil {
  877. br.Msg = "请登录"
  878. br.ErrMsg = "请登录,SysUser Is Empty"
  879. br.Ret = 408
  880. return
  881. }
  882. var req request.BalanceSeasonChartLegendPreviewReq
  883. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  884. if err != nil {
  885. br.Msg = "参数解析异常!"
  886. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  887. return
  888. }
  889. if len(req.DateArr) == 0 || len(req.DateArr) == 0 || len(req.DateArr) != len(req.DataArr) {
  890. br.Msg = "请输入正确的日期和数据"
  891. return
  892. }
  893. newDataMap := make(map[int]float64)
  894. for i, v := range req.DataArr {
  895. fv, e := strconv.ParseFloat(v, 64)
  896. if e != nil {
  897. br.Msg = "数据格式错误"
  898. return
  899. }
  900. newDataMap[i] = fv
  901. }
  902. //组装成excelEdbData
  903. dataList := make([]*data_manage.EdbDataList, 0)
  904. for i, v := range req.DateArr {
  905. dataTime, e := time.ParseInLocation(utils.FormatDate, v, time.Local)
  906. if e != nil {
  907. br.Msg = "日期格式错误"
  908. br.ErrMsg = v + "日期格式错误,Err:" + e.Error()
  909. return
  910. }
  911. timestamp := dataTime.UnixNano() / 1e6
  912. tmp := &data_manage.EdbDataList{
  913. EdbDataId: i,
  914. DataTime: v,
  915. DataTimestamp: timestamp,
  916. Value: newDataMap[i],
  917. }
  918. dataList = append(dataList, tmp)
  919. }
  920. // 对dataList 根据dataTimestamp 进行排序
  921. sort.Slice(dataList, func(i, j int) bool {
  922. return dataList[i].DataTimestamp < dataList[j].DataTimestamp
  923. })
  924. list, err, errMsg := data.GetBalanceExcelSeasonChartLegendPreview(dataList, req.Calendar, req.SeasonExtraConfig)
  925. if err != nil {
  926. if errMsg != "" {
  927. br.Msg = errMsg
  928. } else {
  929. br.Msg = "预览失败"
  930. }
  931. br.ErrMsg = err.Error()
  932. return
  933. }
  934. ret := &data_manage.BalanceSeasonChartLegendPreviewResp{List: list}
  935. br.Data = ret
  936. br.Ret = 200
  937. br.Success = true
  938. br.Msg = "操作成功"
  939. }
  940. // AddStaticExcel
  941. // @Title 新增静态表
  942. // @Description 新增静态表
  943. // @Param request body request.EditExcelInfoReq true "type json string"
  944. // @Success 200 {object} response.AddExcelInfoResp
  945. // @router /excel_info/balance/static/add [post]
  946. func (c *ExcelInfoController) AddStaticExcel() {
  947. br := new(models.BaseResponse).Init()
  948. defer func() {
  949. c.Data["json"] = br
  950. c.ServeJSON()
  951. }()
  952. sysUser := c.SysUser
  953. if sysUser == nil {
  954. br.Msg = "请登录"
  955. br.ErrMsg = "请登录,SysUser Is Empty"
  956. br.Ret = 408
  957. return
  958. }
  959. var req request.AddBalanceStaticExcelInfoReq
  960. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  961. if err != nil {
  962. br.Msg = "参数解析异常!"
  963. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  964. return
  965. }
  966. if req.ExcelInfoId <= 0 {
  967. br.Msg = "请传入ETA表格标识!"
  968. return
  969. }
  970. cacheKey := "CACHE_TABLE_INFO_BALANCE_STATIC_ADD_" + strconv.Itoa(req.ExcelInfoId)
  971. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  972. br.Msg = "系统处理中,请稍后重试!"
  973. br.ErrMsg = "系统处理中,请稍后重试!"
  974. return
  975. }
  976. defer func() {
  977. _ = utils.Rc.Delete(cacheKey)
  978. }()
  979. req.VersionName = strings.Trim(req.VersionName, " ")
  980. if req.VersionName == "" {
  981. br.Msg = "请填写版本名称!"
  982. br.IsSendEmail = false
  983. return
  984. }
  985. // 获取原ETA表格信息
  986. oldExcelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  987. if err != nil {
  988. br.Msg = "获取ETA表格失败"
  989. return
  990. }
  991. // 操作权限校验, 增加协作人判断
  992. {
  993. // 数据权限
  994. haveOperaAuth, err := data_manage_permission.CheckExcelPermissionByExcelInfoId(oldExcelInfo.ExcelInfoId, oldExcelInfo.ExcelClassifyId, oldExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  995. if err != nil {
  996. br.Msg = "获取ETA表格失败"
  997. br.ErrMsg = "获取ETA表格权限失败,Err:" + err.Error()
  998. return
  999. }
  1000. button := excelService.GetExcelInfoOpButton(sysUser, oldExcelInfo.SysUserId, oldExcelInfo.Source, haveOperaAuth)
  1001. if !button.OpButton {
  1002. br.Msg = "无操作权限"
  1003. br.IsSendEmail = false
  1004. return
  1005. }
  1006. }
  1007. // 查询出每个子表的内容,并将内容转为静态版本
  1008. excelDataMap := make(map[int]map[int][]*data_manage.EdbDataList)
  1009. //查询动态表所有的子表,并复制为静态表
  1010. condition := " AND parent_id = ? AND balance_type = 0 "
  1011. var pars []interface{}
  1012. pars = append(pars, req.ExcelInfoId)
  1013. childExcelList, err := excel.GetExcelInfoListByCondition(condition, pars)
  1014. if err != nil {
  1015. br.Msg = "获取子表失败"
  1016. br.ErrMsg = fmt.Sprintf("获取子表失败 %s", err.Error())
  1017. return
  1018. }
  1019. for k, childExcelInfo := range childExcelList {
  1020. //得到表格数据并落库
  1021. newExcelDataMap, excelAllRows, excelAllCols, e, errMsg := excelService.GetBalanceExcelData(childExcelInfo, c.Lang)
  1022. if e != nil {
  1023. br.Msg = "获取表格数据失败"
  1024. if errMsg != "" {
  1025. br.Msg = errMsg
  1026. }
  1027. br.ErrMsg = "获取表格数据失败,Err:" + e.Error()
  1028. return
  1029. }
  1030. tmpMappingList, e := excel.GetExcelChartEdbMappingByExcelInfoId(childExcelInfo.ExcelInfoId)
  1031. if e != nil {
  1032. br.Msg = "获取图表,指标信息失败"
  1033. br.ErrMsg = fmt.Sprintf(" 获取图表,指标信息失败 Err:%s", err.Error())
  1034. return
  1035. }
  1036. if len(tmpMappingList) > 0 {
  1037. for _, mapping := range tmpMappingList {
  1038. child, ok := excelDataMap[mapping.ChartInfoId]
  1039. if !ok {
  1040. child = make(map[int][]*data_manage.EdbDataList)
  1041. }
  1042. er, msg := excelService.GetBalanceExcelEdbData(mapping, newExcelDataMap, child, excelAllRows, excelAllCols)
  1043. if er != nil {
  1044. utils.FileLog.Info(fmt.Sprintf(" 获取图表,指标信息失败 Err:%s, %s", msg, er.Error()))
  1045. continue
  1046. }
  1047. excelDataMap[mapping.ChartInfoId] = child
  1048. }
  1049. }
  1050. content, e := excelService.TransferBalanceExcelContentToStatic(childExcelInfo, c.Lang)
  1051. if e != nil {
  1052. br.Msg = "动态内容转成静态失败"
  1053. br.ErrMsg = fmt.Sprintf("动态内容转成静态失败 %s", e.Error())
  1054. return
  1055. }
  1056. childExcelList[k].Content = content
  1057. }
  1058. excelInfo, err, errMsg, isSendEmail := data.AddBalanceStaticExcel(oldExcelInfo, oldExcelInfo.ExcelClassifyId, req.VersionName, sysUser, 0, req.ExcelInfoId, 1, childExcelList, true, excelDataMap)
  1059. if err != nil {
  1060. br.Msg = "复制失败"
  1061. if errMsg != `` {
  1062. br.Msg = errMsg
  1063. }
  1064. br.ErrMsg = "复制失败,Err:" + err.Error()
  1065. br.IsSendEmail = isSendEmail
  1066. return
  1067. }
  1068. resp := new(response.AddExcelInfoResp)
  1069. resp.ExcelInfoId = excelInfo.ExcelInfoId
  1070. resp.UniqueCode = excelInfo.UniqueCode
  1071. br.Ret = 200
  1072. br.Success = true
  1073. br.Msg = "保存成功"
  1074. br.Data = resp
  1075. br.IsAddLog = true
  1076. }
  1077. // BalanceVersionList
  1078. // @Title 查询平衡表版本号列表
  1079. // @Description 查询平衡表版本号列表
  1080. // @Param request body request.EditExcelInfoReq true "type json string"
  1081. // @Success 200 {object} response.AddExcelInfoResp
  1082. // @router /excel_info/balance/version [get]
  1083. func (c *ExcelInfoController) BalanceVersionList() {
  1084. br := new(models.BaseResponse).Init()
  1085. defer func() {
  1086. c.Data["json"] = br
  1087. c.ServeJSON()
  1088. }()
  1089. sysUser := c.SysUser
  1090. if sysUser == nil {
  1091. br.Msg = "请登录"
  1092. br.ErrMsg = "请登录,SysUser Is Empty"
  1093. br.Ret = 408
  1094. return
  1095. }
  1096. excelInfoId, _ := c.GetInt("ExcelInfoId")
  1097. if excelInfoId <= 0 {
  1098. br.Msg = "请选择表格"
  1099. br.ErrMsg = "ExcelInfoId未传"
  1100. br.IsSendEmail = false
  1101. return
  1102. }
  1103. excelInfo, err := excel.GetExcelInfoById(excelInfoId)
  1104. if err != nil {
  1105. br.Msg = "获取ETA表格失败"
  1106. br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
  1107. return
  1108. }
  1109. if excelInfo.Source != utils.BALANCE_TABLE {
  1110. br.Msg = "请选择平衡表"
  1111. return
  1112. }
  1113. if excelInfo.BalanceType != 0 && excelInfo.ParentId != 0 {
  1114. br.Msg = "请选择动态平衡表"
  1115. return
  1116. }
  1117. list := make([]*response.BalanceTableVersionListItem, 0)
  1118. list = append(list, &response.BalanceTableVersionListItem{
  1119. ExcelInfoId: excelInfo.ExcelInfoId,
  1120. UniqueCode: excelInfo.UniqueCode,
  1121. BalanceType: excelInfo.BalanceType,
  1122. RelExcelInfoId: excelInfo.RelExcelInfoId,
  1123. VersionName: "动态表", //todo 有个默认的版本名称
  1124. })
  1125. //查询动态表所有的子表,并复制为静态表
  1126. condition := " AND rel_excel_info_id=? AND parent_id = 0 AND balance_type = 1 "
  1127. var pars []interface{}
  1128. pars = append(pars, excelInfoId)
  1129. staticList, err := excel.GetNoContentExcelInfoListByConditionNoPage(condition, pars)
  1130. if err != nil {
  1131. br.Msg = "获取子表失败"
  1132. br.ErrMsg = fmt.Sprintf("获取子表失败 %s", err.Error())
  1133. return
  1134. }
  1135. for _, staticInfo := range staticList {
  1136. tmp := &response.BalanceTableVersionListItem{
  1137. ExcelInfoId: staticInfo.ExcelInfoId,
  1138. UniqueCode: staticInfo.UniqueCode,
  1139. BalanceType: staticInfo.BalanceType,
  1140. RelExcelInfoId: staticInfo.RelExcelInfoId,
  1141. VersionName: staticInfo.VersionName,
  1142. }
  1143. list = append(list, tmp)
  1144. }
  1145. ret := &response.BalanceTableVersionListResp{List: list}
  1146. br.Data = ret
  1147. br.Ret = 200
  1148. br.Success = true
  1149. br.Msg = "操作成功"
  1150. }
  1151. // ModifyBalanceExcelVersion
  1152. // @Title 版本号重命名
  1153. // @Description 版本号重命名
  1154. // @Param request body request.AddBalanceStaticExcelInfoReq true "type json string"
  1155. // @Success 200 {object} response.AddExcelInfoResp
  1156. // @router /excel_info/balance/version/modify [post]
  1157. func (c *ExcelInfoController) ModifyBalanceExcelVersion() {
  1158. br := new(models.BaseResponse).Init()
  1159. defer func() {
  1160. c.Data["json"] = br
  1161. c.ServeJSON()
  1162. }()
  1163. sysUser := c.SysUser
  1164. if sysUser == nil {
  1165. br.Msg = "请登录"
  1166. br.ErrMsg = "请登录,SysUser Is Empty"
  1167. br.Ret = 408
  1168. return
  1169. }
  1170. var req request.AddBalanceStaticExcelInfoReq
  1171. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1172. if err != nil {
  1173. br.Msg = "参数解析异常!"
  1174. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1175. return
  1176. }
  1177. if req.ExcelInfoId <= 0 {
  1178. br.Msg = "请传入ETA表格标识!"
  1179. return
  1180. }
  1181. req.VersionName = strings.Trim(req.VersionName, " ")
  1182. if req.VersionName == "" {
  1183. br.Msg = "请填写版本名称!"
  1184. br.IsSendEmail = false
  1185. return
  1186. }
  1187. excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  1188. if err != nil {
  1189. br.Msg = "获取ETA表格失败"
  1190. br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
  1191. return
  1192. }
  1193. if excelInfo.Source != utils.BALANCE_TABLE {
  1194. br.Msg = "请选择平衡表"
  1195. return
  1196. }
  1197. if excelInfo.BalanceType != 1 && excelInfo.ParentId != 0 {
  1198. br.Msg = "请选择静态表"
  1199. return
  1200. }
  1201. // 操作权限校验, 增加协作人判断
  1202. {
  1203. checkExcelInfo := excelInfo
  1204. if excelInfo.Source == utils.BALANCE_TABLE {
  1205. checkExcelInfoId := excelInfo.ExcelInfoId
  1206. if excelInfo.BalanceType == 1 {
  1207. checkExcelInfoId = excelInfo.RelExcelInfoId
  1208. } else {
  1209. if excelInfo.ParentId > 0 {
  1210. checkExcelInfoId = excelInfo.ParentId
  1211. }
  1212. }
  1213. if checkExcelInfoId != excelInfo.ExcelInfoId {
  1214. checkExcelInfo, err = excel.GetExcelInfoById(checkExcelInfoId)
  1215. if err != nil {
  1216. br.Msg = "获取平衡表格信息失败"
  1217. br.ErrMsg = "获取平衡表格信息失败,Err:" + err.Error()
  1218. return
  1219. }
  1220. }
  1221. }
  1222. // 数据权限
  1223. haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  1224. if e != nil {
  1225. br.Msg = "获取ETA表格权限失败"
  1226. br.ErrMsg = "获取表格权限信息失败,Err" + e.Error()
  1227. return
  1228. }
  1229. button := excelService.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
  1230. if !button.OpButton {
  1231. br.Msg = "无操作权限"
  1232. br.IsSendEmail = false
  1233. return
  1234. }
  1235. }
  1236. // 检验分类下是否存在该版本号
  1237. {
  1238. var condition string
  1239. var pars []interface{}
  1240. condition += " AND rel_excel_info_id=? AND parent_id=0"
  1241. pars = append(pars, req.ExcelInfoId)
  1242. condition += " AND version_name=? "
  1243. pars = append(pars, req.VersionName)
  1244. count, tmpErr := excel.GetExcelInfoCountByCondition(condition, pars)
  1245. if tmpErr != nil {
  1246. br.Msg = "查询版本名称失败"
  1247. br.ErrMsg = tmpErr.Error()
  1248. return
  1249. }
  1250. if count > 0 {
  1251. br.Msg = "表格版本名称已存在,请重新填写版本名称"
  1252. br.IsSendEmail = false
  1253. return
  1254. }
  1255. }
  1256. excelInfo.ModifyTime = time.Now()
  1257. excelInfo.VersionName = req.VersionName
  1258. updateExcelInfoParams := []string{"ModifyTime", "VersionName"}
  1259. // todo 同步修改静态表中的图表和指标名称
  1260. // ETA表格信息变更
  1261. err = excelInfo.Update(updateExcelInfoParams)
  1262. if err != nil {
  1263. br.Msg = "操作失败"
  1264. br.ErrMsg = "操作失败,Err:" + err.Error()
  1265. return
  1266. }
  1267. br.Ret = 200
  1268. br.Success = true
  1269. br.Msg = "操作成功"
  1270. br.IsAddLog = true
  1271. }
  1272. func downloadBalanceTable(excelInfo *excel.ExcelInfo, lang string) (savePath, zipName string, uploadDir string, err error, errMsg string) {
  1273. dateDir := time.Now().Format("20060102")
  1274. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1275. uploadDir = "static/xls/" + dateDir + "/" + randStr
  1276. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  1277. if err != nil {
  1278. return
  1279. }
  1280. fileList := make([]string, 0)
  1281. if excelInfo.ParentId != 0 && excelInfo.BalanceType != 0 {
  1282. errMsg = "平衡表类型错误"
  1283. err = fmt.Errorf("平衡表类型错误 ")
  1284. return
  1285. }
  1286. //复制静态表
  1287. staticCondition := " AND parent_id = 0 AND balance_type = 1 AND rel_excel_info_id=? "
  1288. var staticPars []interface{}
  1289. staticPars = append(staticPars, excelInfo.ExcelInfoId)
  1290. excelList, err := excel.GetExcelInfoListByCondition(staticCondition, staticPars)
  1291. if err != nil {
  1292. errMsg = "获取表格失败"
  1293. err = fmt.Errorf("获取表格失败 %s", err.Error())
  1294. return
  1295. }
  1296. excelList = append(excelList, excelInfo)
  1297. for _, staticExcelInfo := range excelList {
  1298. cCondition := " AND parent_id = ?"
  1299. var cPars []interface{}
  1300. cPars = append(cPars, staticExcelInfo.ExcelInfoId)
  1301. childList, e := excel.GetExcelInfoListByCondition(cCondition, cPars)
  1302. if e != nil {
  1303. errMsg = "获取子表失败"
  1304. err = fmt.Errorf("获取子表失败 %s", err.Error())
  1305. return
  1306. }
  1307. xlsxFile := xlsx.NewFile()
  1308. fileName := staticExcelInfo.ExcelName + ".xlsx"
  1309. fpath := uploadDir + "/" + fileName
  1310. for _, childExcelInfo := range childList {
  1311. var result request.MixedTableReq
  1312. err = json.Unmarshal([]byte(childExcelInfo.Content), &result)
  1313. if err != nil {
  1314. errMsg = "获取失败"
  1315. err = fmt.Errorf("表格json转结构体失败,Err:" + err.Error())
  1316. return
  1317. }
  1318. newResult, er, msg := excelService.GetMixedTableCellData(result, lang)
  1319. if er != nil {
  1320. err = er
  1321. errMsg = msg
  1322. return
  1323. }
  1324. tableData, er := excel2.GetTableDataByMixedTableData(newResult, false)
  1325. if er != nil {
  1326. errMsg = "获取失败"
  1327. err = fmt.Errorf("转换成table失败,Err:" + err.Error())
  1328. return
  1329. }
  1330. // 将单个sheet的数据写入到excel
  1331. err = tableData.WriteExcelSheetData(xlsxFile, childExcelInfo.ExcelName)
  1332. if err != nil {
  1333. return
  1334. }
  1335. }
  1336. //处理excel文件
  1337. //return
  1338. err = xlsxFile.Save(fpath)
  1339. if err != nil {
  1340. return
  1341. }
  1342. fileList = append(fileList, fileName)
  1343. }
  1344. // 创建zip
  1345. zipName = excelInfo.ExcelName + ".zip"
  1346. savePath = uploadDir + "/" + zipName
  1347. fmt.Println(savePath)
  1348. zipFile, err := os.Create(savePath)
  1349. if err != nil {
  1350. return
  1351. }
  1352. zipWriter := zip.NewWriter(zipFile)
  1353. // 生成zip过程中报错关闭
  1354. defer func() {
  1355. if err != nil {
  1356. zipWriter.Close()
  1357. zipFile.Close()
  1358. }
  1359. //os.Remove(savePath)
  1360. }()
  1361. //写入zip
  1362. for i := 0; i < len(fileList); i++ {
  1363. ioWriter, e := zipWriter.Create(fileList[i])
  1364. if e != nil {
  1365. err = fmt.Errorf("创建zip失败,Err:" + e.Error())
  1366. if os.IsPermission(e) {
  1367. fmt.Println("权限不足: ", e)
  1368. return
  1369. }
  1370. return
  1371. }
  1372. fullPath := uploadDir + "/" + fileList[i]
  1373. content, e := ioutil.ReadFile(fullPath)
  1374. if e != nil {
  1375. err = fmt.Errorf("读取文件失败,Err:" + e.Error())
  1376. return
  1377. }
  1378. ioWriter.Write(content)
  1379. }
  1380. // 生成zip后关闭,否则下载文件会损坏
  1381. zipWriter.Close()
  1382. zipFile.Close()
  1383. //this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1384. return
  1385. }
  1386. func refreshBalanceTable(excelDetail response.ExcelInfoDetail, lang string) (err error) {
  1387. edbInfoIds := make([]int, 0)
  1388. edbInfoIdExist := make(map[int]bool)
  1389. if excelDetail.ParentId > 0 {
  1390. newResult := excelDetail.TableData.(request.MixedTableReq)
  1391. newData := newResult.Data
  1392. if len(newData) > 0 {
  1393. for _, t := range newData {
  1394. for _, v := range t {
  1395. if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
  1396. edbInfoIdExist[v.EdbInfoId] = true
  1397. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  1398. }
  1399. }
  1400. }
  1401. }
  1402. // 清除缓存
  1403. key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelDetail.UniqueCode
  1404. if utils.Re == nil {
  1405. _ = utils.Rc.Delete(key)
  1406. }
  1407. } else {
  1408. //查询父表和子表
  1409. cCondition := " AND parent_id = ? AND balance_type=0"
  1410. var cPars []interface{}
  1411. cPars = append(cPars, excelDetail.ExcelInfoId)
  1412. childList, e := excel.GetExcelInfoListByCondition(cCondition, cPars)
  1413. if e != nil {
  1414. err = fmt.Errorf("获取子表失败 %s", err.Error())
  1415. return
  1416. }
  1417. // 遍历
  1418. for _, child := range childList {
  1419. var result request.MixedTableReq
  1420. err = json.Unmarshal([]byte(child.Content), &result)
  1421. if err != nil {
  1422. err = errors.New("表格json转结构体失败,Err:" + err.Error())
  1423. return
  1424. }
  1425. var newData [][]request.MixedTableCellDataReq
  1426. newData, err, _ = excelService.GetMixedTableCellData(result, lang)
  1427. if err != nil {
  1428. return
  1429. }
  1430. if len(newData) > 0 {
  1431. for _, t := range newData {
  1432. for _, v := range t {
  1433. if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
  1434. edbInfoIdExist[v.EdbInfoId] = true
  1435. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  1436. }
  1437. }
  1438. }
  1439. }
  1440. // 清除缓存
  1441. key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + child.UniqueCode
  1442. if utils.Re == nil {
  1443. _ = utils.Rc.Delete(key)
  1444. }
  1445. }
  1446. }
  1447. if len(edbInfoIds) > 0 {
  1448. err, _ = data.EdbInfoRefreshAllFromBaseV3(edbInfoIds, false, true, false)
  1449. if err != nil {
  1450. err = fmt.Errorf("刷新混合表格数据失败, Err: " + err.Error())
  1451. return
  1452. }
  1453. }
  1454. return
  1455. }
  1456. // BalanceChartInfoBaseEdit
  1457. // @Title 编辑图表基础信息接口
  1458. // @Description 编辑图表基础信息接口
  1459. // @Param request body data_manage.EditChartEnInfoBaseReq true "type json string"
  1460. // @Success Ret=200 编辑成功
  1461. // @router /excel_info/balance/chart_base_edit [post]
  1462. func (this *ExcelInfoController) BalanceChartInfoBaseEdit() {
  1463. br := new(models.BaseResponse).Init()
  1464. defer func() {
  1465. this.Data["json"] = br
  1466. this.ServeJSON()
  1467. }()
  1468. sysUser := this.SysUser
  1469. if sysUser == nil {
  1470. br.Msg = "请登录"
  1471. br.ErrMsg = "请登录,SysUser Is Empty"
  1472. br.Ret = 408
  1473. return
  1474. }
  1475. var req data_manage.EditChartInfoBaseReq
  1476. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1477. if err != nil {
  1478. br.Msg = "参数解析异常!"
  1479. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1480. return
  1481. }
  1482. req.ChartName = strings.Trim(req.ChartName, " ")
  1483. if req.ChartInfoId <= 0 {
  1484. br.Msg = "请选择图表"
  1485. return
  1486. }
  1487. //判断指标名称是否存在
  1488. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1489. if err != nil {
  1490. if err.Error() == utils.ErrNoRow() {
  1491. br.Msg = "图表已被删除,请刷新页面"
  1492. br.ErrMsg = "图表已被删除,请刷新页面"
  1493. return
  1494. }
  1495. br.Msg = "获取图表信息失败"
  1496. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1497. return
  1498. }
  1499. // 判断是否有传入对应的指标配置
  1500. noEdbInfoType := []int{10}
  1501. if len(req.ChartEdbInfoList) <= 0 && !utils.InArrayByInt(noEdbInfoType, chartItem.ChartType) {
  1502. br.Msg = "请选择指标!"
  1503. return
  1504. }
  1505. var edbCondition string
  1506. var edbPars []interface{}
  1507. for _, v := range req.ChartEdbInfoList {
  1508. edbInfoId := v.EdbInfoId
  1509. edbInfo, err := excel.GetExcelChartEdbById(edbInfoId)
  1510. if err != nil {
  1511. if err.Error() == utils.ErrNoRow() {
  1512. br.Msg = "图表不存在!"
  1513. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  1514. return
  1515. } else {
  1516. br.Msg = "获取图表信息失败!"
  1517. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  1518. return
  1519. }
  1520. }
  1521. if edbInfo == nil {
  1522. br.Msg = "指标不存在!"
  1523. br.ErrMsg = "指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  1524. return
  1525. }
  1526. //判断指标名称是否重复
  1527. if v.EdbName != "" {
  1528. edbCondition = ""
  1529. edbPars = make([]interface{}, 0)
  1530. edbCondition += " AND excel_chart_edb_id<>? AND chart_info_id=?"
  1531. edbPars = append(edbPars, edbInfo.ExcelChartEdbId, chartItem.ChartInfoId)
  1532. switch this.Lang {
  1533. case utils.EnLangVersion:
  1534. edbCondition += " AND edb_name_en =? "
  1535. default:
  1536. edbCondition += " AND edb_name =? "
  1537. }
  1538. edbPars = append(edbPars, v.EdbName)
  1539. edbExist, err := excel.GetBalanceChartEdbByCondition(edbCondition, edbPars)
  1540. if err != nil {
  1541. if err.Error() != utils.ErrNoRow() {
  1542. br.Msg = "判断英文指标名称是否存在失败"
  1543. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  1544. return
  1545. }
  1546. }
  1547. if err == nil && edbExist.ExcelChartEdbId > 0 {
  1548. br.Msg = edbExist.EdbName + ":" + v.EdbName + "指标名称已存在"
  1549. br.ErrMsg = "指标名称已存在,请重新填写"
  1550. br.IsSendEmail = false
  1551. return
  1552. }
  1553. }
  1554. }
  1555. if req.ChartName != "" || req.ExtraConfig != `` {
  1556. var condition string
  1557. var pars []interface{}
  1558. condition += " AND chart_info_id<>? "
  1559. pars = append(pars, req.ChartInfoId)
  1560. switch this.Lang {
  1561. case utils.EnLangVersion:
  1562. condition += " AND chart_name_en = ? "
  1563. default:
  1564. condition += " AND chart_name = ? "
  1565. }
  1566. pars = append(pars, req.ChartName)
  1567. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  1568. if err != nil {
  1569. if err.Error() != utils.ErrNoRow() {
  1570. br.Msg = "判断英文图表名称是否存在失败"
  1571. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  1572. return
  1573. }
  1574. }
  1575. if err == nil && existItem.ChartInfoId > 0 {
  1576. br.Msg = existItem.ChartName + ":" + req.ChartName + "图表名称已存在"
  1577. return
  1578. }
  1579. }
  1580. err = excel.EditBalanceChartBaseInfoAndEdbEnInfo(&req, chartItem, this.Lang)
  1581. if err != nil {
  1582. br.Msg = "保存失败"
  1583. br.ErrMsg = "保存失败,Err:" + err.Error()
  1584. return
  1585. }
  1586. //添加es数据
  1587. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  1588. //修改my eta es数据
  1589. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  1590. //新增操作日志
  1591. {
  1592. chartLog := new(data_manage.ChartInfoLog)
  1593. chartLog.ChartName = chartItem.ChartName
  1594. chartLog.ChartInfoId = req.ChartInfoId
  1595. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  1596. chartLog.SysUserId = sysUser.AdminId
  1597. chartLog.SysUserRealName = sysUser.RealName
  1598. chartLog.UniqueCode = chartItem.UniqueCode
  1599. chartLog.CreateTime = time.Now()
  1600. chartLog.Content = string(this.Ctx.Input.RequestBody)
  1601. chartLog.Status = "编辑图表英文信息"
  1602. chartLog.Method = this.Ctx.Input.URL()
  1603. go data_manage.AddChartInfoLog(chartLog)
  1604. }
  1605. //清除缓存
  1606. if utils.Re == nil && utils.Rc != nil {
  1607. utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  1608. utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  1609. }
  1610. br.Ret = 200
  1611. br.Success = true
  1612. br.Msg = "编辑成功"
  1613. br.IsAddLog = true
  1614. }