balance_table.go 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733
  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. 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, childExcelInfo.ExcelInfoId)
  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. }