balance_table.go 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743
  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. "io/ioutil"
  20. "os"
  21. "sort"
  22. "strconv"
  23. "strings"
  24. "time"
  25. "github.com/tealeg/xlsx"
  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. // 写入ES
  1072. go func() {
  1073. excel2.EsAddOrEditExcel(excelInfo.ExcelInfoId)
  1074. }()
  1075. br.Ret = 200
  1076. br.Success = true
  1077. br.Msg = "保存成功"
  1078. br.Data = resp
  1079. br.IsAddLog = true
  1080. }
  1081. // BalanceVersionList
  1082. // @Title 查询平衡表版本号列表
  1083. // @Description 查询平衡表版本号列表
  1084. // @Param request body request.EditExcelInfoReq true "type json string"
  1085. // @Success 200 {object} response.AddExcelInfoResp
  1086. // @router /excel_info/balance/version [get]
  1087. func (c *ExcelInfoController) BalanceVersionList() {
  1088. br := new(models.BaseResponse).Init()
  1089. defer func() {
  1090. c.Data["json"] = br
  1091. c.ServeJSON()
  1092. }()
  1093. sysUser := c.SysUser
  1094. if sysUser == nil {
  1095. br.Msg = "请登录"
  1096. br.ErrMsg = "请登录,SysUser Is Empty"
  1097. br.Ret = 408
  1098. return
  1099. }
  1100. excelInfoId, _ := c.GetInt("ExcelInfoId")
  1101. if excelInfoId <= 0 {
  1102. br.Msg = "请选择表格"
  1103. br.ErrMsg = "ExcelInfoId未传"
  1104. br.IsSendEmail = false
  1105. return
  1106. }
  1107. excelInfo, err := excel.GetExcelInfoById(excelInfoId)
  1108. if err != nil {
  1109. br.Msg = "获取ETA表格失败"
  1110. br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
  1111. return
  1112. }
  1113. if excelInfo.Source != utils.BALANCE_TABLE {
  1114. br.Msg = "请选择平衡表"
  1115. return
  1116. }
  1117. if excelInfo.BalanceType != 0 && excelInfo.ParentId != 0 {
  1118. br.Msg = "请选择动态平衡表"
  1119. return
  1120. }
  1121. list := make([]*response.BalanceTableVersionListItem, 0)
  1122. list = append(list, &response.BalanceTableVersionListItem{
  1123. ExcelInfoId: excelInfo.ExcelInfoId,
  1124. UniqueCode: excelInfo.UniqueCode,
  1125. BalanceType: excelInfo.BalanceType,
  1126. RelExcelInfoId: excelInfo.RelExcelInfoId,
  1127. VersionName: "动态表", //todo 有个默认的版本名称
  1128. })
  1129. //查询动态表所有的子表,并复制为静态表
  1130. condition := " AND rel_excel_info_id=? AND parent_id = 0 AND balance_type = 1 "
  1131. var pars []interface{}
  1132. pars = append(pars, excelInfoId)
  1133. staticList, err := excel.GetNoContentExcelInfoListByConditionNoPage(condition, pars)
  1134. if err != nil {
  1135. br.Msg = "获取子表失败"
  1136. br.ErrMsg = fmt.Sprintf("获取子表失败 %s", err.Error())
  1137. return
  1138. }
  1139. for _, staticInfo := range staticList {
  1140. tmp := &response.BalanceTableVersionListItem{
  1141. ExcelInfoId: staticInfo.ExcelInfoId,
  1142. UniqueCode: staticInfo.UniqueCode,
  1143. BalanceType: staticInfo.BalanceType,
  1144. RelExcelInfoId: staticInfo.RelExcelInfoId,
  1145. VersionName: staticInfo.VersionName,
  1146. }
  1147. list = append(list, tmp)
  1148. }
  1149. ret := &response.BalanceTableVersionListResp{List: list}
  1150. br.Data = ret
  1151. br.Ret = 200
  1152. br.Success = true
  1153. br.Msg = "操作成功"
  1154. }
  1155. // ModifyBalanceExcelVersion
  1156. // @Title 版本号重命名
  1157. // @Description 版本号重命名
  1158. // @Param request body request.AddBalanceStaticExcelInfoReq true "type json string"
  1159. // @Success 200 {object} response.AddExcelInfoResp
  1160. // @router /excel_info/balance/version/modify [post]
  1161. func (c *ExcelInfoController) ModifyBalanceExcelVersion() {
  1162. br := new(models.BaseResponse).Init()
  1163. defer func() {
  1164. c.Data["json"] = br
  1165. c.ServeJSON()
  1166. }()
  1167. sysUser := c.SysUser
  1168. if sysUser == nil {
  1169. br.Msg = "请登录"
  1170. br.ErrMsg = "请登录,SysUser Is Empty"
  1171. br.Ret = 408
  1172. return
  1173. }
  1174. var req request.AddBalanceStaticExcelInfoReq
  1175. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1176. if err != nil {
  1177. br.Msg = "参数解析异常!"
  1178. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1179. return
  1180. }
  1181. if req.ExcelInfoId <= 0 {
  1182. br.Msg = "请传入ETA表格标识!"
  1183. return
  1184. }
  1185. req.VersionName = strings.Trim(req.VersionName, " ")
  1186. if req.VersionName == "" {
  1187. br.Msg = "请填写版本名称!"
  1188. br.IsSendEmail = false
  1189. return
  1190. }
  1191. excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  1192. if err != nil {
  1193. br.Msg = "获取ETA表格失败"
  1194. br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
  1195. return
  1196. }
  1197. if excelInfo.Source != utils.BALANCE_TABLE {
  1198. br.Msg = "请选择平衡表"
  1199. return
  1200. }
  1201. if excelInfo.BalanceType != 1 && excelInfo.ParentId != 0 {
  1202. br.Msg = "请选择静态表"
  1203. return
  1204. }
  1205. // 操作权限校验, 增加协作人判断
  1206. {
  1207. checkExcelInfo := excelInfo
  1208. if excelInfo.Source == utils.BALANCE_TABLE {
  1209. checkExcelInfoId := excelInfo.ExcelInfoId
  1210. if excelInfo.BalanceType == 1 {
  1211. checkExcelInfoId = excelInfo.RelExcelInfoId
  1212. } else {
  1213. if excelInfo.ParentId > 0 {
  1214. checkExcelInfoId = excelInfo.ParentId
  1215. }
  1216. }
  1217. if checkExcelInfoId != excelInfo.ExcelInfoId {
  1218. checkExcelInfo, err = excel.GetExcelInfoById(checkExcelInfoId)
  1219. if err != nil {
  1220. br.Msg = "获取平衡表格信息失败"
  1221. br.ErrMsg = "获取平衡表格信息失败,Err:" + err.Error()
  1222. return
  1223. }
  1224. }
  1225. }
  1226. // 数据权限
  1227. haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  1228. if e != nil {
  1229. br.Msg = "获取ETA表格权限失败"
  1230. br.ErrMsg = "获取表格权限信息失败,Err" + e.Error()
  1231. return
  1232. }
  1233. button := excelService.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
  1234. if !button.OpButton {
  1235. br.Msg = "无操作权限"
  1236. br.IsSendEmail = false
  1237. return
  1238. }
  1239. }
  1240. // 检验分类下是否存在该版本号
  1241. {
  1242. var condition string
  1243. var pars []interface{}
  1244. condition += " AND rel_excel_info_id=? AND parent_id=0"
  1245. pars = append(pars, req.ExcelInfoId)
  1246. condition += " AND version_name=? "
  1247. pars = append(pars, req.VersionName)
  1248. count, tmpErr := excel.GetExcelInfoCountByCondition(condition, pars)
  1249. if tmpErr != nil {
  1250. br.Msg = "查询版本名称失败"
  1251. br.ErrMsg = tmpErr.Error()
  1252. return
  1253. }
  1254. if count > 0 {
  1255. br.Msg = "表格版本名称已存在,请重新填写版本名称"
  1256. br.IsSendEmail = false
  1257. return
  1258. }
  1259. }
  1260. excelInfo.ModifyTime = time.Now()
  1261. excelInfo.VersionName = req.VersionName
  1262. updateExcelInfoParams := []string{"ModifyTime", "VersionName"}
  1263. // todo 同步修改静态表中的图表和指标名称
  1264. // ETA表格信息变更
  1265. err = excelInfo.Update(updateExcelInfoParams)
  1266. if err != nil {
  1267. br.Msg = "操作失败"
  1268. br.ErrMsg = "操作失败,Err:" + err.Error()
  1269. return
  1270. }
  1271. br.Ret = 200
  1272. br.Success = true
  1273. br.Msg = "操作成功"
  1274. br.IsAddLog = true
  1275. }
  1276. func downloadBalanceTable(excelInfo *excel.ExcelInfo, lang string) (savePath, zipName string, uploadDir string, err error, errMsg string) {
  1277. dateDir := time.Now().Format("20060102")
  1278. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1279. uploadDir = "static/xls/" + dateDir + "/" + randStr
  1280. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  1281. if err != nil {
  1282. return
  1283. }
  1284. fileList := make([]string, 0)
  1285. if excelInfo.ParentId != 0 && excelInfo.BalanceType != 0 {
  1286. errMsg = "平衡表类型错误"
  1287. err = fmt.Errorf("平衡表类型错误 ")
  1288. return
  1289. }
  1290. //复制静态表
  1291. staticCondition := " AND parent_id = 0 AND balance_type = 1 AND rel_excel_info_id=? "
  1292. var staticPars []interface{}
  1293. staticPars = append(staticPars, excelInfo.ExcelInfoId)
  1294. excelList, err := excel.GetExcelInfoListByCondition(staticCondition, staticPars)
  1295. if err != nil {
  1296. errMsg = "获取表格失败"
  1297. err = fmt.Errorf("获取表格失败 %s", err.Error())
  1298. return
  1299. }
  1300. excelList = append(excelList, excelInfo)
  1301. for _, staticExcelInfo := range excelList {
  1302. cCondition := " AND parent_id = ?"
  1303. var cPars []interface{}
  1304. cPars = append(cPars, staticExcelInfo.ExcelInfoId)
  1305. childList, e := excel.GetExcelInfoListByCondition(cCondition, cPars)
  1306. if e != nil {
  1307. errMsg = "获取子表失败"
  1308. err = fmt.Errorf("获取子表失败 %s", err.Error())
  1309. return
  1310. }
  1311. xlsxFile := xlsx.NewFile()
  1312. fileName := staticExcelInfo.ExcelName + ".xlsx"
  1313. fpath := uploadDir + "/" + fileName
  1314. for _, childExcelInfo := range childList {
  1315. var result request.MixedTableReq
  1316. err = json.Unmarshal([]byte(childExcelInfo.Content), &result)
  1317. if err != nil {
  1318. errMsg = "获取失败"
  1319. err = fmt.Errorf("表格json转结构体失败,Err:" + err.Error())
  1320. return
  1321. }
  1322. newResult, er, msg := excelService.GetMixedTableCellData(result, lang)
  1323. if er != nil {
  1324. err = er
  1325. errMsg = msg
  1326. return
  1327. }
  1328. tableData, er := excel2.GetTableDataByMixedTableData(newResult, false, childExcelInfo.ExcelInfoId)
  1329. if er != nil {
  1330. errMsg = "获取失败"
  1331. err = fmt.Errorf("转换成table失败,Err:" + err.Error())
  1332. return
  1333. }
  1334. // tableData, err = excel2.HandleRuleToTableCell(childExcelInfo.ExcelInfoId, tableData)
  1335. // if err != nil {
  1336. // errMsg = "获取失败"
  1337. // err = fmt.Errorf("处理条件格式管理规则失败,Err:%w", err)
  1338. // return
  1339. // }
  1340. // 将单个sheet的数据写入到excel
  1341. err = tableData.WriteExcelSheetData(xlsxFile, childExcelInfo.ExcelName)
  1342. if err != nil {
  1343. return
  1344. }
  1345. }
  1346. //处理excel文件
  1347. //return
  1348. err = xlsxFile.Save(fpath)
  1349. if err != nil {
  1350. return
  1351. }
  1352. fileList = append(fileList, fileName)
  1353. }
  1354. // 创建zip
  1355. zipName = excelInfo.ExcelName + ".zip"
  1356. savePath = uploadDir + "/" + zipName
  1357. fmt.Println(savePath)
  1358. zipFile, err := os.Create(savePath)
  1359. if err != nil {
  1360. return
  1361. }
  1362. zipWriter := zip.NewWriter(zipFile)
  1363. // 生成zip过程中报错关闭
  1364. defer func() {
  1365. if err != nil {
  1366. zipWriter.Close()
  1367. zipFile.Close()
  1368. }
  1369. //os.Remove(savePath)
  1370. }()
  1371. //写入zip
  1372. for i := 0; i < len(fileList); i++ {
  1373. ioWriter, e := zipWriter.Create(fileList[i])
  1374. if e != nil {
  1375. err = fmt.Errorf("创建zip失败,Err:" + e.Error())
  1376. if os.IsPermission(e) {
  1377. fmt.Println("权限不足: ", e)
  1378. return
  1379. }
  1380. return
  1381. }
  1382. fullPath := uploadDir + "/" + fileList[i]
  1383. content, e := ioutil.ReadFile(fullPath)
  1384. if e != nil {
  1385. err = fmt.Errorf("读取文件失败,Err:" + e.Error())
  1386. return
  1387. }
  1388. ioWriter.Write(content)
  1389. }
  1390. // 生成zip后关闭,否则下载文件会损坏
  1391. zipWriter.Close()
  1392. zipFile.Close()
  1393. //this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1394. return
  1395. }
  1396. func refreshBalanceTable(excelDetail response.ExcelInfoDetail, lang string) (err error) {
  1397. edbInfoIds := make([]int, 0)
  1398. edbInfoIdExist := make(map[int]bool)
  1399. if excelDetail.ParentId > 0 {
  1400. newResult := excelDetail.TableData.(request.MixedTableReq)
  1401. newData := newResult.Data
  1402. if len(newData) > 0 {
  1403. for _, t := range newData {
  1404. for _, v := range t {
  1405. if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
  1406. edbInfoIdExist[v.EdbInfoId] = true
  1407. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  1408. }
  1409. }
  1410. }
  1411. }
  1412. // 清除缓存
  1413. key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelDetail.UniqueCode
  1414. if utils.Re == nil {
  1415. _ = utils.Rc.Delete(key)
  1416. }
  1417. } else {
  1418. //查询父表和子表
  1419. cCondition := " AND parent_id = ? AND balance_type=0"
  1420. var cPars []interface{}
  1421. cPars = append(cPars, excelDetail.ExcelInfoId)
  1422. childList, e := excel.GetExcelInfoListByCondition(cCondition, cPars)
  1423. if e != nil {
  1424. err = fmt.Errorf("获取子表失败 %s", err.Error())
  1425. return
  1426. }
  1427. // 遍历
  1428. for _, child := range childList {
  1429. var result request.MixedTableReq
  1430. err = json.Unmarshal([]byte(child.Content), &result)
  1431. if err != nil {
  1432. err = errors.New("表格json转结构体失败,Err:" + err.Error())
  1433. return
  1434. }
  1435. var newData [][]request.MixedTableCellDataReq
  1436. newData, err, _ = excelService.GetMixedTableCellData(result, lang)
  1437. if err != nil {
  1438. return
  1439. }
  1440. if len(newData) > 0 {
  1441. for _, t := range newData {
  1442. for _, v := range t {
  1443. if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
  1444. edbInfoIdExist[v.EdbInfoId] = true
  1445. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  1446. }
  1447. }
  1448. }
  1449. }
  1450. // 清除缓存
  1451. key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + child.UniqueCode
  1452. if utils.Re == nil {
  1453. _ = utils.Rc.Delete(key)
  1454. }
  1455. }
  1456. }
  1457. if len(edbInfoIds) > 0 {
  1458. err, _ = data.EdbInfoRefreshAllFromBaseV3(edbInfoIds, false, true, false)
  1459. if err != nil {
  1460. err = fmt.Errorf("刷新混合表格数据失败, Err: " + err.Error())
  1461. return
  1462. }
  1463. }
  1464. return
  1465. }
  1466. // BalanceChartInfoBaseEdit
  1467. // @Title 编辑图表基础信息接口
  1468. // @Description 编辑图表基础信息接口
  1469. // @Param request body data_manage.EditChartEnInfoBaseReq true "type json string"
  1470. // @Success Ret=200 编辑成功
  1471. // @router /excel_info/balance/chart_base_edit [post]
  1472. func (this *ExcelInfoController) BalanceChartInfoBaseEdit() {
  1473. br := new(models.BaseResponse).Init()
  1474. defer func() {
  1475. this.Data["json"] = br
  1476. this.ServeJSON()
  1477. }()
  1478. sysUser := this.SysUser
  1479. if sysUser == nil {
  1480. br.Msg = "请登录"
  1481. br.ErrMsg = "请登录,SysUser Is Empty"
  1482. br.Ret = 408
  1483. return
  1484. }
  1485. var req data_manage.EditChartInfoBaseReq
  1486. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1487. if err != nil {
  1488. br.Msg = "参数解析异常!"
  1489. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1490. return
  1491. }
  1492. req.ChartName = strings.Trim(req.ChartName, " ")
  1493. if req.ChartInfoId <= 0 {
  1494. br.Msg = "请选择图表"
  1495. return
  1496. }
  1497. //判断指标名称是否存在
  1498. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1499. if err != nil {
  1500. if err.Error() == utils.ErrNoRow() {
  1501. br.Msg = "图表已被删除,请刷新页面"
  1502. br.ErrMsg = "图表已被删除,请刷新页面"
  1503. return
  1504. }
  1505. br.Msg = "获取图表信息失败"
  1506. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1507. return
  1508. }
  1509. // 判断是否有传入对应的指标配置
  1510. noEdbInfoType := []int{10}
  1511. if len(req.ChartEdbInfoList) <= 0 && !utils.InArrayByInt(noEdbInfoType, chartItem.ChartType) {
  1512. br.Msg = "请选择指标!"
  1513. return
  1514. }
  1515. var edbCondition string
  1516. var edbPars []interface{}
  1517. for _, v := range req.ChartEdbInfoList {
  1518. edbInfoId := v.EdbInfoId
  1519. edbInfo, err := excel.GetExcelChartEdbById(edbInfoId)
  1520. if err != nil {
  1521. if err.Error() == utils.ErrNoRow() {
  1522. br.Msg = "图表不存在!"
  1523. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  1524. return
  1525. } else {
  1526. br.Msg = "获取图表信息失败!"
  1527. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  1528. return
  1529. }
  1530. }
  1531. if edbInfo == nil {
  1532. br.Msg = "指标不存在!"
  1533. br.ErrMsg = "指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  1534. return
  1535. }
  1536. //判断指标名称是否重复
  1537. if v.EdbName != "" {
  1538. edbCondition = ""
  1539. edbPars = make([]interface{}, 0)
  1540. edbCondition += " AND excel_chart_edb_id<>? AND chart_info_id=?"
  1541. edbPars = append(edbPars, edbInfo.ExcelChartEdbId, chartItem.ChartInfoId)
  1542. switch this.Lang {
  1543. case utils.EnLangVersion:
  1544. edbCondition += " AND edb_name_en =? "
  1545. default:
  1546. edbCondition += " AND edb_name =? "
  1547. }
  1548. edbPars = append(edbPars, v.EdbName)
  1549. edbExist, err := excel.GetBalanceChartEdbByCondition(edbCondition, edbPars)
  1550. if err != nil {
  1551. if err.Error() != utils.ErrNoRow() {
  1552. br.Msg = "判断英文指标名称是否存在失败"
  1553. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  1554. return
  1555. }
  1556. }
  1557. if err == nil && edbExist.ExcelChartEdbId > 0 {
  1558. br.Msg = edbExist.EdbName + ":" + v.EdbName + "指标名称已存在"
  1559. br.ErrMsg = "指标名称已存在,请重新填写"
  1560. br.IsSendEmail = false
  1561. return
  1562. }
  1563. }
  1564. }
  1565. if req.ChartName != "" || req.ExtraConfig != `` {
  1566. var condition string
  1567. var pars []interface{}
  1568. condition += " AND chart_info_id<>? "
  1569. pars = append(pars, req.ChartInfoId)
  1570. switch this.Lang {
  1571. case utils.EnLangVersion:
  1572. condition += " AND chart_name_en = ? "
  1573. default:
  1574. condition += " AND chart_name = ? "
  1575. }
  1576. pars = append(pars, req.ChartName)
  1577. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  1578. if err != nil {
  1579. if err.Error() != utils.ErrNoRow() {
  1580. br.Msg = "判断英文图表名称是否存在失败"
  1581. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  1582. return
  1583. }
  1584. }
  1585. if err == nil && existItem.ChartInfoId > 0 {
  1586. br.Msg = existItem.ChartName + ":" + req.ChartName + "图表名称已存在"
  1587. return
  1588. }
  1589. }
  1590. err = excel.EditBalanceChartBaseInfoAndEdbEnInfo(&req, chartItem, this.Lang)
  1591. if err != nil {
  1592. br.Msg = "保存失败"
  1593. br.ErrMsg = "保存失败,Err:" + err.Error()
  1594. return
  1595. }
  1596. //添加es数据
  1597. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  1598. //修改my eta es数据
  1599. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  1600. //新增操作日志
  1601. {
  1602. chartLog := new(data_manage.ChartInfoLog)
  1603. chartLog.ChartName = chartItem.ChartName
  1604. chartLog.ChartInfoId = req.ChartInfoId
  1605. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  1606. chartLog.SysUserId = sysUser.AdminId
  1607. chartLog.SysUserRealName = sysUser.RealName
  1608. chartLog.UniqueCode = chartItem.UniqueCode
  1609. chartLog.CreateTime = time.Now()
  1610. chartLog.Content = string(this.Ctx.Input.RequestBody)
  1611. chartLog.Status = "编辑图表英文信息"
  1612. chartLog.Method = this.Ctx.Input.URL()
  1613. go data_manage.AddChartInfoLog(chartLog)
  1614. }
  1615. //清除缓存
  1616. if utils.Re == nil && utils.Rc != nil {
  1617. utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  1618. utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  1619. }
  1620. br.Ret = 200
  1621. br.Success = true
  1622. br.Msg = "编辑成功"
  1623. br.IsAddLog = true
  1624. }