balance_table.go 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. package excel
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/data_manage/excel"
  7. "eta/eta_api/models/data_manage/excel/request"
  8. "eta/eta_api/models/data_manage/excel/response"
  9. "eta/eta_api/models/system"
  10. "eta/eta_api/services/data"
  11. "eta/eta_api/services/data/data_manage_permission"
  12. excelService "eta/eta_api/services/data/excel"
  13. etaTrialService "eta/eta_api/services/eta_trial"
  14. "eta/eta_api/utils"
  15. "fmt"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // GetChildTable
  21. // @Title 获取子表
  22. // @Description 获取子表
  23. // @Param request body request.MixedTableCellDataReq true "type json string"
  24. // @router /excel_info/child_table [get]
  25. func (c *ExcelInfoController) GetChildTable() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. c.Data["json"] = br
  29. c.ServeJSON()
  30. }()
  31. sysUser := c.SysUser
  32. if sysUser == nil {
  33. br.Msg = "请登录"
  34. br.ErrMsg = "请登录,SysUser Is Empty"
  35. br.Ret = 408
  36. return
  37. }
  38. parentId, _ := c.GetInt("ParentId")
  39. if parentId <= 0 {
  40. br.Msg = "请选择父表"
  41. return
  42. }
  43. list := make([]*excel.ExcelInfo, 0)
  44. // 查询所有子表
  45. childList, err := excel.GetChildExcelInfoByParentId(parentId)
  46. if err != nil {
  47. br.Msg = "查询子表失败"
  48. return
  49. }
  50. if len(childList) > 0 {
  51. list = childList
  52. }
  53. resp := &response.BalanceChildTableResp{List: list}
  54. br.Ret = 200
  55. br.Success = true
  56. br.Msg = "查询成功"
  57. br.Data = resp
  58. }
  59. // Rename
  60. // @Title 表格重命名接口
  61. // @Description 表格重命名接口
  62. // @Param request body request.EditExcelInfoReq true "type json string"
  63. // @Success 200 {object} response.AddExcelInfoResp
  64. // @router /excel_info/rename [post]
  65. func (c *ExcelInfoController) Rename() {
  66. br := new(models.BaseResponse).Init()
  67. defer func() {
  68. c.Data["json"] = br
  69. c.ServeJSON()
  70. }()
  71. sysUser := c.SysUser
  72. if sysUser == nil {
  73. br.Msg = "请登录"
  74. br.ErrMsg = "请登录,SysUser Is Empty"
  75. br.Ret = 408
  76. return
  77. }
  78. var req request.RenameExcelInfoReq
  79. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  80. if err != nil {
  81. br.Msg = "参数解析异常!"
  82. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  83. return
  84. }
  85. if req.ExcelInfoId <= 0 {
  86. br.Msg = "请传入ETA表格标识!"
  87. return
  88. }
  89. req.ExcelName = strings.Trim(req.ExcelName, " ")
  90. if req.ExcelName == "" {
  91. br.Msg = "请填写表格名称!"
  92. br.IsSendEmail = false
  93. return
  94. }
  95. excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  96. if err != nil {
  97. br.Msg = "获取ETA表格失败"
  98. br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
  99. return
  100. }
  101. //判断表格是否存在
  102. var condition string
  103. var pars []interface{}
  104. condition += " AND excel_info_id != ? AND excel_classify_id=? AND excel_name=? AND parent_id=?"
  105. pars = append(pars, req.ExcelInfoId, excelInfo.ExcelClassifyId, req.ExcelName, excelInfo.ParentId)
  106. // 获取分类下是否存在该表格名称
  107. count, err := excel.GetExcelInfoCountByCondition(condition, pars)
  108. if err != nil {
  109. br.Msg = "ETA判断表格名称是否存在失败"
  110. br.ErrMsg = "判断ETA表格名称是否存在失败,Err:" + err.Error()
  111. return
  112. }
  113. if count > 0 {
  114. br.Msg = "ETA表格名称已存在,请重新填写"
  115. br.IsSendEmail = false
  116. return
  117. }
  118. // 操作权限校验, 增加协作人判断
  119. {
  120. checkExcelInfo := excelInfo
  121. if excelInfo.Source == utils.BALANCE_TABLE {
  122. checkExcelInfoId := excelInfo.ExcelInfoId
  123. if excelInfo.BalanceType == 1 {
  124. checkExcelInfoId = excelInfo.RelExcelInfoId
  125. } else {
  126. if excelInfo.ParentId > 0 {
  127. checkExcelInfoId = excelInfo.ParentId
  128. }
  129. }
  130. if checkExcelInfoId != excelInfo.ExcelInfoId {
  131. checkExcelInfo, err = excel.GetExcelInfoById(checkExcelInfoId)
  132. if err != nil {
  133. br.Msg = "获取平衡表格信息失败"
  134. br.ErrMsg = "获取平衡表格信息失败,Err:" + err.Error()
  135. return
  136. }
  137. }
  138. }
  139. // 数据权限
  140. haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  141. if e != nil {
  142. br.Msg = "获取ETA表格权限失败"
  143. br.ErrMsg = "获取表格权限信息失败,Err" + e.Error()
  144. return
  145. }
  146. button := excelService.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
  147. if !button.OpButton {
  148. br.Msg = "无操作权限"
  149. br.IsSendEmail = false
  150. return
  151. }
  152. }
  153. excelInfo.ModifyTime = time.Now()
  154. excelInfo.ExcelName = req.ExcelName
  155. excelInfo.UpdateUserId = sysUser.AdminId
  156. excelInfo.UpdateUserRealName = sysUser.RealName
  157. // 自动保存时不会传缩略图,也就不更新这个字段
  158. updateExcelInfoParams := []string{"ModifyTime", "ExcelName", "UpdateUserId", "UpdateUserRealName"}
  159. err = excelInfo.Update(updateExcelInfoParams)
  160. if err != nil {
  161. br.Msg = "保存失败"
  162. br.ErrMsg = "保存失败,Err:" + err.Error()
  163. return
  164. }
  165. resp := response.AddExcelInfoResp{
  166. ExcelInfoId: excelInfo.ExcelInfoId,
  167. UniqueCode: excelInfo.UniqueCode,
  168. }
  169. //删除公共图库那边的缓存
  170. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelInfo.UniqueCode)
  171. br.Ret = 200
  172. br.Success = true
  173. br.Msg = "修改成功"
  174. br.Data = resp
  175. br.IsAddLog = true
  176. }
  177. // SaveExcelWorker
  178. // @Title 新增编辑表格协作人接口
  179. // @Description 新增编辑表格协作人接口
  180. // @Param request body request.EditExcelInfoReq true "type json string"
  181. // @Success 200 {object} response.AddExcelInfoResp
  182. // @router /excel_info/worker/save [post]
  183. func (c *ExcelInfoController) SaveExcelWorker() {
  184. br := new(models.BaseResponse).Init()
  185. defer func() {
  186. c.Data["json"] = br
  187. c.ServeJSON()
  188. }()
  189. sysUser := c.SysUser
  190. if sysUser == nil {
  191. br.Msg = "请登录"
  192. br.ErrMsg = "请登录,SysUser Is Empty"
  193. br.Ret = 408
  194. return
  195. }
  196. var req request.SaveExcelInfoWorkerReq
  197. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  198. if err != nil {
  199. br.Msg = "参数解析异常!"
  200. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  201. return
  202. }
  203. if req.ExcelInfoId <= 0 {
  204. br.Msg = "请传入ETA表格标识!"
  205. return
  206. }
  207. excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  208. if err != nil {
  209. br.Msg = "获取ETA表格失败"
  210. br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
  211. return
  212. }
  213. if excelInfo.SysUserId != sysUser.AdminId {
  214. br.Msg = "您没有权限操作!"
  215. br.ErrMsg = "您没有权限操作!"
  216. return
  217. }
  218. // 操作权限校验, 增加协作人判断
  219. {
  220. // 数据权限
  221. haveOperaAuth, err := data_manage_permission.CheckExcelPermissionByExcelInfoId(excelInfo.ExcelInfoId, excelInfo.ExcelClassifyId, excelInfo.IsJoinPermission, c.SysUser.AdminId)
  222. if err != nil {
  223. br.Msg = "获取ETA表格失败"
  224. br.ErrMsg = "获取ETA表格权限失败,Err:" + err.Error()
  225. return
  226. }
  227. button := excelService.GetExcelInfoOpButton(sysUser, excelInfo.SysUserId, excelInfo.Source, haveOperaAuth)
  228. if !button.OpButton {
  229. br.Msg = "无操作权限"
  230. br.IsSendEmail = false
  231. return
  232. }
  233. }
  234. obj := new(excel.ExcelWorker)
  235. notDeleteWorkerIds := make([]string, 0)
  236. workerMap := make(map[int]struct{})
  237. if req.SysUserIds != "" {
  238. notDeleteWorkerIds = strings.Split(req.SysUserIds, ",")
  239. }
  240. existList, err := obj.GetByExcelInfoId(req.ExcelInfoId)
  241. if err != nil {
  242. br.Msg = "获取表格协作人失败!"
  243. br.ErrMsg = "获取表格协作人失败,Err:" + err.Error()
  244. return
  245. }
  246. for _, v := range existList {
  247. workerMap[v.SysUserId] = struct{}{}
  248. }
  249. addIds := make([]int, 0)
  250. for _, v := range notDeleteWorkerIds {
  251. id, _ := strconv.Atoi(v)
  252. if _, ok := workerMap[id]; !ok {
  253. addIds = append(addIds, id)
  254. }
  255. }
  256. // 查询协作人姓名
  257. adminList, err := system.GetAdminListByIdListWithoutEnable(addIds)
  258. addList := make([]*excel.ExcelWorker, 0)
  259. for _, v := range adminList {
  260. addList = append(addList, &excel.ExcelWorker{
  261. ExcelInfoId: req.ExcelInfoId,
  262. SysUserId: v.AdminId,
  263. SysUserRealName: v.RealName,
  264. CreateTime: time.Now(),
  265. ModifyTime: time.Now(),
  266. })
  267. }
  268. // 保存协作人
  269. err = obj.AddWorker(req.ExcelInfoId, addList, notDeleteWorkerIds)
  270. if err != nil {
  271. br.Msg = "保存失败"
  272. br.ErrMsg = "保存失败,Err:" + err.Error()
  273. return
  274. }
  275. br.Ret = 200
  276. br.Success = true
  277. br.Msg = "操作成功"
  278. }
  279. // GetWorker
  280. // @Title 查询协作人接口
  281. // @Description 新增编辑表格协作人接口
  282. // @Param request body request.EditExcelInfoReq true "type json string"
  283. // @Success 200 {object} response.AddExcelInfoResp
  284. // @router /excel_info/worker [get]
  285. func (c *ExcelInfoController) GetWorker() {
  286. br := new(models.BaseResponse).Init()
  287. defer func() {
  288. c.Data["json"] = br
  289. c.ServeJSON()
  290. }()
  291. sysUser := c.SysUser
  292. if sysUser == nil {
  293. br.Msg = "请登录"
  294. br.ErrMsg = "请登录,SysUser Is Empty"
  295. br.Ret = 408
  296. return
  297. }
  298. excelInfoId, _ := c.GetInt("ExcelInfoId")
  299. if excelInfoId <= 0 {
  300. br.Msg = "请选择表格"
  301. br.ErrMsg = "ExcelInfoId未传"
  302. br.IsSendEmail = false
  303. return
  304. }
  305. obj := new(excel.ExcelWorker)
  306. list, err := obj.GetByExcelInfoId(excelInfoId)
  307. if err != nil {
  308. br.Msg = "获取表格协作人失败!"
  309. br.ErrMsg = "获取表格协作人失败,Err:" + err.Error()
  310. return
  311. }
  312. ret := &response.BalanceTableWorkerResp{List: list}
  313. br.Data = ret
  314. br.Ret = 200
  315. br.Success = true
  316. br.Msg = "操作成功"
  317. }
  318. // BalanceChartInfoAdd
  319. // @Title 新增图表接口
  320. // @Description 新增图表接口
  321. // @Param request body data_manage.AddChartInfoReq true "type json string"
  322. // @Success 200 {object} data_manage.AddChartInfoResp
  323. // @router /excel_info/balance/chart_add [post]
  324. func (c *ExcelInfoController) BalanceChartInfoAdd() {
  325. br := new(models.BaseResponse).Init()
  326. defer func() {
  327. c.Data["json"] = br
  328. c.ServeJSON()
  329. }()
  330. sysUser := c.SysUser
  331. if sysUser == nil {
  332. br.Msg = "请登录"
  333. br.ErrMsg = "请登录,SysUser Is Empty"
  334. br.Ret = 408
  335. return
  336. }
  337. deleteCache := true
  338. cacheKey := "CACHE_EXCEL_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  339. defer func() {
  340. if deleteCache {
  341. utils.Rc.Delete(cacheKey)
  342. }
  343. }()
  344. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  345. deleteCache = false
  346. br.Msg = "系统处理中,请稍后重试!"
  347. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  348. return
  349. }
  350. var req request.AddBalanceTableChartReq
  351. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  352. if err != nil {
  353. br.Msg = "参数解析异常!"
  354. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  355. return
  356. }
  357. req.ChartName = strings.Trim(req.ChartName, " ")
  358. if req.ChartName == "" {
  359. br.Msg = "请填写图表名称!"
  360. return
  361. }
  362. // 获取表格信息
  363. excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  364. if err != nil {
  365. br.Msg = "获取ETA表格失败"
  366. return
  367. }
  368. if excelInfo.Source != utils.BALANCE_TABLE {
  369. br.Msg = "EXCEL类型错误!"
  370. return
  371. }
  372. // 操作权限校验, 增加协作人判断
  373. {
  374. checkExcelInfo := excelInfo
  375. if excelInfo.Source == utils.BALANCE_TABLE {
  376. checkExcelInfoId := excelInfo.ExcelInfoId
  377. if excelInfo.BalanceType == 1 {
  378. checkExcelInfoId = excelInfo.RelExcelInfoId
  379. } else {
  380. if excelInfo.ParentId > 0 {
  381. checkExcelInfoId = excelInfo.ParentId
  382. }
  383. }
  384. if checkExcelInfoId != excelInfo.ExcelInfoId {
  385. checkExcelInfo, err = excel.GetExcelInfoById(checkExcelInfoId)
  386. if err != nil {
  387. br.Msg = "获取平衡表格信息失败"
  388. br.ErrMsg = "获取平衡表格信息失败,Err:" + err.Error()
  389. return
  390. }
  391. }
  392. }
  393. // 数据权限
  394. haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  395. if e != nil {
  396. br.Msg = "获取ETA表格权限失败"
  397. br.ErrMsg = "获取表格权限信息失败,Err" + e.Error()
  398. return
  399. }
  400. button := excelService.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
  401. if !button.OpButton {
  402. br.Msg = "无操作权限"
  403. br.IsSendEmail = false
  404. return
  405. }
  406. }
  407. chartInfo, err, errMsg, isSendEmail := data.AddBalanceExcelChart(excelInfo, req, sysUser)
  408. if err != nil {
  409. br.Msg = "保存失败"
  410. if errMsg != `` {
  411. br.Msg = errMsg
  412. }
  413. br.ErrMsg = err.Error()
  414. br.IsSendEmail = isSendEmail
  415. return
  416. }
  417. resp := new(data_manage.AddChartInfoResp)
  418. resp.ChartInfoId = chartInfo.ChartInfoId
  419. resp.UniqueCode = chartInfo.UniqueCode
  420. resp.ChartType = req.ChartType
  421. //新增操作日志
  422. {
  423. chartLog := new(data_manage.ChartInfoLog)
  424. chartLog.ChartInfoId = chartInfo.ChartInfoId
  425. chartLog.ChartName = req.ChartName
  426. chartLog.ChartClassifyId = 0
  427. chartLog.SysUserId = sysUser.AdminId
  428. chartLog.SysUserRealName = sysUser.RealName
  429. chartLog.UniqueCode = chartInfo.UniqueCode
  430. chartLog.CreateTime = time.Now()
  431. chartLog.Content = string(c.Ctx.Input.RequestBody)
  432. chartLog.Status = "新增图表"
  433. chartLog.Method = c.Ctx.Input.URI()
  434. go data_manage.AddChartInfoLog(chartLog)
  435. }
  436. // 试用平台更新用户累计新增图表数
  437. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  438. if e != nil {
  439. br.Msg = "操作失败"
  440. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  441. return
  442. }
  443. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  444. go func() {
  445. var r etaTrialService.EtaTrialUserReq
  446. r.Mobile = adminItem.Mobile
  447. _, _ = etaTrialService.UpdateUserChartNum(r)
  448. }()
  449. }
  450. br.Ret = 200
  451. br.Success = true
  452. br.Msg = "保存成功"
  453. br.Data = resp
  454. br.IsAddLog = true
  455. }
  456. // BalanceChartInfoEdit
  457. // @Title 编辑图表接口
  458. // @Description 新增图表接口
  459. // @Param request body data_manage.AddChartInfoReq true "type json string"
  460. // @Success 200 {object} data_manage.AddChartInfoResp
  461. // @router /excel_info/balance/chart_edit [post]
  462. func (c *ExcelInfoController) BalanceChartInfoEdit() {
  463. br := new(models.BaseResponse).Init()
  464. defer func() {
  465. c.Data["json"] = br
  466. c.ServeJSON()
  467. }()
  468. sysUser := c.SysUser
  469. if sysUser == nil {
  470. br.Msg = "请登录"
  471. br.ErrMsg = "请登录,SysUser Is Empty"
  472. br.Ret = 408
  473. return
  474. }
  475. deleteCache := true
  476. cacheKey := "CACHE_EXCEL_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  477. defer func() {
  478. if deleteCache {
  479. utils.Rc.Delete(cacheKey)
  480. }
  481. }()
  482. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  483. deleteCache = false
  484. br.Msg = "系统处理中,请稍后重试!"
  485. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  486. return
  487. }
  488. var req request.AddBalanceTableChartReq
  489. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  490. if err != nil {
  491. br.Msg = "参数解析异常!"
  492. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  493. return
  494. }
  495. req.ChartName = strings.Trim(req.ChartName, " ")
  496. if req.ChartName == "" {
  497. br.Msg = "请填写图表名称!"
  498. return
  499. }
  500. if req.ChartInfoId <= 0 {
  501. br.Msg = "请选择图表"
  502. return
  503. }
  504. // 获取表格信息
  505. excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  506. if err != nil {
  507. br.Msg = "获取ETA表格失败"
  508. return
  509. }
  510. if excelInfo.Source != utils.BALANCE_TABLE {
  511. br.Msg = "EXCEL类型错误!"
  512. return
  513. }
  514. // 操作权限校验, 增加协作人判断
  515. {
  516. checkExcelInfo := excelInfo
  517. if excelInfo.Source == utils.BALANCE_TABLE {
  518. checkExcelInfoId := excelInfo.ExcelInfoId
  519. if excelInfo.BalanceType == 1 {
  520. checkExcelInfoId = excelInfo.RelExcelInfoId
  521. } else {
  522. if excelInfo.ParentId > 0 {
  523. checkExcelInfoId = excelInfo.ParentId
  524. }
  525. }
  526. if checkExcelInfoId != excelInfo.ExcelInfoId {
  527. checkExcelInfo, err = excel.GetExcelInfoById(checkExcelInfoId)
  528. if err != nil {
  529. br.Msg = "获取平衡表格信息失败"
  530. br.ErrMsg = "获取平衡表格信息失败,Err:" + err.Error()
  531. return
  532. }
  533. }
  534. }
  535. // 数据权限
  536. haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  537. if e != nil {
  538. br.Msg = "获取ETA表格权限失败"
  539. br.ErrMsg = "获取表格权限信息失败,Err" + e.Error()
  540. return
  541. }
  542. button := excelService.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
  543. if !button.OpButton {
  544. br.Msg = "无操作权限"
  545. br.IsSendEmail = false
  546. return
  547. }
  548. }
  549. chartItem, err, errMsg, isSendEmail := data.EditBalanceExcelChart(excelInfo, req, sysUser)
  550. if err != nil {
  551. br.Msg = "保存失败"
  552. if errMsg != `` {
  553. br.Msg = errMsg
  554. }
  555. br.ErrMsg = err.Error()
  556. br.IsSendEmail = isSendEmail
  557. return
  558. }
  559. resp := new(data_manage.AddChartInfoResp)
  560. resp.ChartInfoId = chartItem.ChartInfoId
  561. resp.UniqueCode = chartItem.UniqueCode
  562. resp.ChartType = req.ChartType
  563. //新增操作日志
  564. {
  565. chartLog := new(data_manage.ChartInfoLog)
  566. chartLog.ChartName = chartItem.ChartName
  567. chartLog.ChartInfoId = req.ChartInfoId
  568. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  569. chartLog.SysUserId = sysUser.AdminId
  570. chartLog.SysUserRealName = sysUser.RealName
  571. chartLog.UniqueCode = chartItem.UniqueCode
  572. chartLog.CreateTime = time.Now()
  573. chartLog.Content = string(c.Ctx.Input.RequestBody)
  574. chartLog.Status = "编辑图表"
  575. chartLog.Method = c.Ctx.Input.URL()
  576. go data_manage.AddChartInfoLog(chartLog)
  577. }
  578. br.Ret = 200
  579. br.Success = true
  580. br.Msg = "保存成功"
  581. br.Data = resp
  582. br.IsAddLog = true
  583. }
  584. // GetBalanceChartList
  585. // @Title 获取平衡表表关联的图表
  586. // @Description 获取平衡表表关联的图表
  587. // @Param request body request.MixedTableCellDataReq true "type json string"
  588. // @router /excel_info/balance/chart_list [get]
  589. func (c *ExcelInfoController) GetBalanceChartList() {
  590. br := new(models.BaseResponse).Init()
  591. defer func() {
  592. c.Data["json"] = br
  593. c.ServeJSON()
  594. }()
  595. sysUser := c.SysUser
  596. if sysUser == nil {
  597. br.Msg = "请登录"
  598. br.ErrMsg = "请登录,SysUser Is Empty"
  599. br.Ret = 408
  600. return
  601. }
  602. excelInfoId, _ := c.GetInt("ExcelInfoId")
  603. if excelInfoId <= 0 {
  604. br.Msg = "请选择平衡表"
  605. return
  606. }
  607. // 查询所有子表
  608. excelInfo, err := excel.GetExcelInfoById(excelInfoId)
  609. if err != nil {
  610. if err.Error() == utils.ErrNoRow() {
  611. br.Msg = "表格不存在"
  612. return
  613. }
  614. br.Msg = "查询子表失败"
  615. br.ErrMsg = "查询子表失败,Err:" + err.Error()
  616. return
  617. }
  618. list := make([]*data_manage.BalanceChartInfoDetailResp, 0)
  619. chartInfoList, mappingListMap, dataListMap, err, errMsg := excelService.GetBalanceExcelChartList(excelInfo, "")
  620. if err != nil {
  621. if errMsg != "" {
  622. br.Msg = errMsg
  623. br.ErrMsg = err.Error()
  624. return
  625. } else {
  626. br.Msg = "查询图表失败"
  627. br.ErrMsg = "查询图表失败,Err:" + err.Error()
  628. }
  629. return
  630. }
  631. for _, chartInfo := range chartInfoList {
  632. mappingList, ok := mappingListMap[chartInfo.ChartInfoId]
  633. if !ok {
  634. br.Msg = "未找到图表关联的指标信息"
  635. return
  636. }
  637. var chartInfoResp *data_manage.ChartInfoDetailResp
  638. chartInfoResp, err, errMsg = data.GetBalanceExcelChartDetail(chartInfo, mappingList, sysUser, dataListMap)
  639. if err != nil {
  640. br.Msg = "查询图表详情失败"
  641. br.ErrMsg = "查询图表详情失败,Err:" + err.Error()
  642. return
  643. }
  644. chartEdbList := make([]*data_manage.ExcelChartEdbView, 0)
  645. for _, v := range mappingList {
  646. tmp := &data_manage.ExcelChartEdbView{
  647. ExcelChartEdbId: v.ExcelChartEdbId,
  648. DateSequenceStr: v.DateSequence,
  649. DataSequenceStr: v.DataSequence,
  650. FromTag: v.FromTag,
  651. }
  652. chartEdbList = append(chartEdbList, tmp)
  653. }
  654. balanceChartInfoResp := &data_manage.BalanceChartInfoDetailResp{
  655. ChartInfoDetailResp: chartInfoResp,
  656. ExcelEdbList: chartEdbList,
  657. }
  658. list = append(list, balanceChartInfoResp)
  659. }
  660. ret := &data_manage.BalanceTableChartListResp{List: list}
  661. br.Ret = 200
  662. br.Success = true
  663. br.Msg = "查询成功"
  664. br.Data = ret
  665. }
  666. // DeleteBalanceChart
  667. // @Title 删除平衡表图表
  668. // @Description 删除平衡表图表
  669. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  670. // @Success 200 Ret=200 删除成功
  671. // @router /excel_info/balance/chart_del [post]
  672. func (c *ExcelInfoController) DeleteBalanceChart() {
  673. br := new(models.BaseResponse).Init()
  674. defer func() {
  675. c.Data["json"] = br
  676. c.ServeJSON()
  677. }()
  678. sysUser := c.SysUser
  679. if sysUser == nil {
  680. br.Msg = "请登录"
  681. br.ErrMsg = "请登录,SysUser Is Empty"
  682. br.Ret = 408
  683. return
  684. }
  685. var req data_manage.DeleteChartClassifyReq
  686. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  687. if err != nil {
  688. br.Msg = "参数解析异常!"
  689. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  690. return
  691. }
  692. if req.ChartInfoId <= 0 {
  693. br.Msg = "参数错误"
  694. br.IsSendEmail = false
  695. return
  696. }
  697. //删除图表
  698. if req.ChartInfoId > 0 {
  699. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  700. if err != nil {
  701. if err.Error() == utils.ErrNoRow() {
  702. br.Msg = "图表已删除,请刷新页面"
  703. br.ErrMsg = "指标不存在,Err:" + err.Error()
  704. return
  705. } else {
  706. br.Msg = "删除失败"
  707. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  708. return
  709. }
  710. }
  711. if chartInfo == nil {
  712. br.Msg = "图表已删除,请刷新页面"
  713. return
  714. }
  715. // 操作权限校验, 增加协作人判断
  716. {
  717. // 获取表格信息
  718. excelInfo, e := excel.GetExcelInfoByChartInfoId(req.ChartInfoId)
  719. if e != nil {
  720. br.Msg = "获取ETA表格失败"
  721. return
  722. }
  723. checkExcelInfo := excelInfo
  724. if excelInfo.Source == utils.BALANCE_TABLE {
  725. checkExcelInfoId := excelInfo.ExcelInfoId
  726. if excelInfo.BalanceType == 1 {
  727. checkExcelInfoId = excelInfo.RelExcelInfoId
  728. } else {
  729. if excelInfo.ParentId > 0 {
  730. checkExcelInfoId = excelInfo.ParentId
  731. }
  732. }
  733. if checkExcelInfoId != excelInfo.ExcelInfoId {
  734. checkExcelInfo, e = excel.GetExcelInfoById(checkExcelInfoId)
  735. if e != nil {
  736. br.Msg = "获取平衡表格信息失败"
  737. br.ErrMsg = "获取平衡表格信息失败,Err:" + e.Error()
  738. return
  739. }
  740. }
  741. }
  742. // 数据权限
  743. haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  744. if e != nil {
  745. br.Msg = "获取ETA表格权限失败"
  746. br.ErrMsg = "获取表格权限信息失败,Err" + e.Error()
  747. return
  748. }
  749. button := excelService.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
  750. if !button.OpButton {
  751. br.Msg = "无操作权限"
  752. br.IsSendEmail = false
  753. return
  754. }
  755. }
  756. // 获取引用该图表的MyCharts, 用于ES删除
  757. var myCond string
  758. var myPars []interface{}
  759. myCond += ` AND a.chart_info_id = ? `
  760. myPars = append(myPars, req.ChartInfoId)
  761. myCharts, e := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(myCond, myPars)
  762. if e != nil {
  763. br.Msg = "删除失败"
  764. br.ErrMsg = "获取引用图表的MyChats失败, Err: " + e.Error()
  765. return
  766. }
  767. myIds := make([]int, 0)
  768. for _, m := range myCharts {
  769. myIds = append(myIds, m.MyChartId)
  770. }
  771. // 查询图表相关联的数据
  772. edbIds := make([]int, 0)
  773. // 查询图表相关联的指标
  774. edbList, e := excel.GetExcelChartEdbMappingByChartInfoId(req.ChartInfoId)
  775. if e != nil {
  776. br.Msg = "删除失败"
  777. br.ErrMsg = "获取图表相关联的指标失败, Err: " + e.Error()
  778. return
  779. }
  780. for _, v := range edbList {
  781. edbIds = append(edbIds, v.ExcelChartEdbId)
  782. }
  783. //删除图表及关联指标
  784. e = data_manage.DeleteBalanceExcelChartInfoAndData(req.ChartInfoId, edbIds)
  785. if e != nil {
  786. br.Msg = "删除失败"
  787. br.ErrMsg = "删除失败,Err:" + e.Error()
  788. return
  789. }
  790. //删除ES
  791. {
  792. go data.EsDeleteChartInfo(req.ChartInfoId)
  793. // 删除MY ETA 图表 es数据
  794. //go data.EsDeleteMyChartInfoByChartInfoId(req.ChartInfoId)
  795. go data.EsDeleteMyChartInfoByMyChartIds(myIds)
  796. }
  797. //新增操作日志
  798. {
  799. chartLog := new(data_manage.ChartInfoLog)
  800. chartLog.ChartName = chartInfo.ChartName
  801. chartLog.ChartInfoId = req.ChartInfoId
  802. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  803. chartLog.SysUserId = sysUser.AdminId
  804. chartLog.SysUserRealName = sysUser.RealName
  805. chartLog.UniqueCode = chartInfo.UniqueCode
  806. chartLog.CreateTime = time.Now()
  807. chartLog.Content = string(c.Ctx.Input.RequestBody)
  808. chartLog.Status = "删除图表"
  809. chartLog.Method = c.Ctx.Input.URI()
  810. go data_manage.AddChartInfoLog(chartLog)
  811. }
  812. }
  813. br.Ret = 200
  814. br.Msg = "删除成功"
  815. br.Success = true
  816. br.IsAddLog = true
  817. }
  818. // BalanceSeasonChartLegendPreview
  819. // @Title 季节性图例预览接口
  820. // @Description 季节性图例预览接口
  821. // @Param request body request.BalanceSeasonChartLegendPreviewReq true "type json string"
  822. // @Success 200 {object} data_manage.BalanceSeasonChartLegendPreviewResp
  823. // @router /excel_info/balance/chartLegend/preview [post]
  824. func (c *ExcelInfoController) BalanceSeasonChartLegendPreview() {
  825. br := new(models.BaseResponse).Init()
  826. defer func() {
  827. c.Data["json"] = br
  828. c.ServeJSON()
  829. }()
  830. sysUser := c.SysUser
  831. if sysUser == nil {
  832. br.Msg = "请登录"
  833. br.ErrMsg = "请登录,SysUser Is Empty"
  834. br.Ret = 408
  835. return
  836. }
  837. var req request.BalanceSeasonChartLegendPreviewReq
  838. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  839. if err != nil {
  840. br.Msg = "参数解析异常!"
  841. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  842. return
  843. }
  844. if len(req.DateArr) == 0 || len(req.DateArr) == 0 || len(req.DateArr) != len(req.DataArr) {
  845. br.Msg = "请输入正确的日期和数据"
  846. return
  847. }
  848. newDataMap := make(map[int]float64)
  849. for i, v := range req.DataArr {
  850. fv, e := strconv.ParseFloat(v, 64)
  851. if e != nil {
  852. br.Msg = "数据格式错误"
  853. return
  854. }
  855. newDataMap[i] = fv
  856. }
  857. //组装成excelEdbData
  858. dataList := make([]*data_manage.EdbDataList, 0)
  859. for i, v := range req.DateArr {
  860. dataTime, e := time.ParseInLocation(utils.FormatDate, v, time.Local)
  861. if e != nil {
  862. br.Msg = "日期格式错误"
  863. br.ErrMsg = v + "日期格式错误,Err:" + e.Error()
  864. return
  865. }
  866. timestamp := dataTime.UnixNano() / 1e6
  867. tmp := &data_manage.EdbDataList{
  868. EdbDataId: i,
  869. DataTime: v,
  870. DataTimestamp: timestamp,
  871. Value: newDataMap[i],
  872. }
  873. dataList = append(dataList, tmp)
  874. }
  875. list, err, errMsg := data.GetBalanceExcelSeasonChartLegendPreview(dataList, req.Calendar, req.SeasonExtraConfig)
  876. if err != nil {
  877. if errMsg != "" {
  878. br.Msg = errMsg
  879. } else {
  880. br.Msg = "预览失败"
  881. }
  882. br.ErrMsg = err.Error()
  883. return
  884. }
  885. ret := &data_manage.BalanceSeasonChartLegendPreviewResp{List: list}
  886. br.Data = ret
  887. br.Ret = 200
  888. br.Success = true
  889. br.Msg = "操作成功"
  890. }
  891. // AddStaticExcel
  892. // @Title 新增静态表
  893. // @Description 新增静态表
  894. // @Param request body request.EditExcelInfoReq true "type json string"
  895. // @Success 200 {object} response.AddExcelInfoResp
  896. // @router /excel_info/balance/static/add [post]
  897. func (c *ExcelInfoController) AddStaticExcel() {
  898. br := new(models.BaseResponse).Init()
  899. defer func() {
  900. c.Data["json"] = br
  901. c.ServeJSON()
  902. }()
  903. sysUser := c.SysUser
  904. if sysUser == nil {
  905. br.Msg = "请登录"
  906. br.ErrMsg = "请登录,SysUser Is Empty"
  907. br.Ret = 408
  908. return
  909. }
  910. var req request.AddBalanceStaticExcelInfoReq
  911. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  912. if err != nil {
  913. br.Msg = "参数解析异常!"
  914. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  915. return
  916. }
  917. if req.ExcelInfoId <= 0 {
  918. br.Msg = "请传入ETA表格标识!"
  919. return
  920. }
  921. cacheKey := "CACHE_TABLE_INFO_BALANCE_STATIC_ADD_" + strconv.Itoa(req.ExcelInfoId)
  922. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  923. br.Msg = "系统处理中,请稍后重试!"
  924. br.ErrMsg = "系统处理中,请稍后重试!"
  925. return
  926. }
  927. defer func() {
  928. _ = utils.Rc.Delete(cacheKey)
  929. }()
  930. req.VersionName = strings.Trim(req.VersionName, " ")
  931. if req.VersionName == "" {
  932. br.Msg = "请填写版本名称!"
  933. br.IsSendEmail = false
  934. return
  935. }
  936. // 获取原ETA表格信息
  937. oldExcelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  938. if err != nil {
  939. br.Msg = "获取ETA表格失败"
  940. return
  941. }
  942. // 操作权限校验, 增加协作人判断
  943. {
  944. // 数据权限
  945. haveOperaAuth, err := data_manage_permission.CheckExcelPermissionByExcelInfoId(oldExcelInfo.ExcelInfoId, oldExcelInfo.ExcelClassifyId, oldExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  946. if err != nil {
  947. br.Msg = "获取ETA表格失败"
  948. br.ErrMsg = "获取ETA表格权限失败,Err:" + err.Error()
  949. return
  950. }
  951. button := excelService.GetExcelInfoOpButton(sysUser, oldExcelInfo.SysUserId, oldExcelInfo.Source, haveOperaAuth)
  952. if !button.OpButton {
  953. br.Msg = "无操作权限"
  954. br.IsSendEmail = false
  955. return
  956. }
  957. }
  958. // 查询出每个子表的内容,并将内容转为静态版本
  959. //查询动态表所有的子表,并复制为静态表
  960. condition := " AND parent_id = ? AND balance_type = 0 "
  961. var pars []interface{}
  962. pars = append(pars, req.ExcelInfoId)
  963. childExcelList, err := excel.GetExcelInfoListByCondition(condition, pars)
  964. if err != nil {
  965. br.Msg = "获取子表失败"
  966. br.ErrMsg = fmt.Sprintf("获取子表失败 %s", err.Error())
  967. return
  968. }
  969. for k, childExcelInfo := range childExcelList {
  970. content, e := excelService.TransferBalanceExcelContentToStatic(childExcelInfo, "")
  971. if e != nil {
  972. br.Msg = "动态内容转成静态失败"
  973. br.ErrMsg = fmt.Sprintf("动态内容转成静态失败 %s", e.Error())
  974. return
  975. }
  976. childExcelList[k].Content = content
  977. }
  978. excelInfo, err, errMsg, isSendEmail := data.AddBalanceStaticExcel(oldExcelInfo, req.VersionName, sysUser, 0, req.ExcelInfoId, 1, childExcelList, true)
  979. if err != nil {
  980. br.Msg = "复制失败"
  981. if errMsg != `` {
  982. br.Msg = errMsg
  983. }
  984. br.ErrMsg = "复制失败,Err:" + err.Error()
  985. br.IsSendEmail = isSendEmail
  986. return
  987. }
  988. resp := new(response.AddExcelInfoResp)
  989. resp.ExcelInfoId = excelInfo.ExcelInfoId
  990. resp.UniqueCode = excelInfo.UniqueCode
  991. br.Ret = 200
  992. br.Success = true
  993. br.Msg = "保存成功"
  994. br.Data = resp
  995. br.IsAddLog = true
  996. }
  997. // BalanceVersionList
  998. // @Title 查询平衡表版本号列表
  999. // @Description 查询平衡表版本号列表
  1000. // @Param request body request.EditExcelInfoReq true "type json string"
  1001. // @Success 200 {object} response.AddExcelInfoResp
  1002. // @router /excel_info/balance/version [get]
  1003. func (c *ExcelInfoController) BalanceVersionList() {
  1004. br := new(models.BaseResponse).Init()
  1005. defer func() {
  1006. c.Data["json"] = br
  1007. c.ServeJSON()
  1008. }()
  1009. sysUser := c.SysUser
  1010. if sysUser == nil {
  1011. br.Msg = "请登录"
  1012. br.ErrMsg = "请登录,SysUser Is Empty"
  1013. br.Ret = 408
  1014. return
  1015. }
  1016. excelInfoId, _ := c.GetInt("ExcelInfoId")
  1017. if excelInfoId <= 0 {
  1018. br.Msg = "请选择表格"
  1019. br.ErrMsg = "ExcelInfoId未传"
  1020. br.IsSendEmail = false
  1021. return
  1022. }
  1023. excelInfo, err := excel.GetExcelInfoById(excelInfoId)
  1024. if err != nil {
  1025. br.Msg = "获取ETA表格失败"
  1026. br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
  1027. return
  1028. }
  1029. if excelInfo.Source != utils.BALANCE_TABLE {
  1030. br.Msg = "请选择平衡表"
  1031. return
  1032. }
  1033. if excelInfo.BalanceType != 0 && excelInfo.ParentId != 0 {
  1034. br.Msg = "请选择动态平衡表"
  1035. return
  1036. }
  1037. list := make([]*response.BalanceTableVersionListItem, 0)
  1038. list = append(list, &response.BalanceTableVersionListItem{
  1039. ExcelInfoId: excelInfo.ExcelInfoId,
  1040. UniqueCode: excelInfo.UniqueCode,
  1041. BalanceType: excelInfo.BalanceType,
  1042. RelExcelInfoId: excelInfo.RelExcelInfoId,
  1043. VersionName: "动态表", //todo 有个默认的版本名称
  1044. })
  1045. //查询动态表所有的子表,并复制为静态表
  1046. condition := " AND rel_excel_info_id=? AND parent_id = 0 AND balance_type = 1 "
  1047. var pars []interface{}
  1048. pars = append(pars, excelInfoId)
  1049. staticList, err := excel.GetNoContentExcelInfoListByConditionNoPage(condition, pars)
  1050. if err != nil {
  1051. br.Msg = "获取子表失败"
  1052. br.ErrMsg = fmt.Sprintf("获取子表失败 %s", err.Error())
  1053. return
  1054. }
  1055. for _, staticInfo := range staticList {
  1056. tmp := &response.BalanceTableVersionListItem{
  1057. ExcelInfoId: staticInfo.ExcelInfoId,
  1058. UniqueCode: staticInfo.UniqueCode,
  1059. BalanceType: staticInfo.BalanceType,
  1060. RelExcelInfoId: staticInfo.RelExcelInfoId,
  1061. VersionName: staticInfo.VersionName,
  1062. }
  1063. list = append(list, tmp)
  1064. }
  1065. ret := &response.BalanceTableVersionListResp{List: list}
  1066. br.Data = ret
  1067. br.Ret = 200
  1068. br.Success = true
  1069. br.Msg = "操作成功"
  1070. }
  1071. // ModifyBalanceExcelVersion
  1072. // @Title 版本号重命名
  1073. // @Description 版本号重命名
  1074. // @Param request body request.AddBalanceStaticExcelInfoReq true "type json string"
  1075. // @Success 200 {object} response.AddExcelInfoResp
  1076. // @router /excel_info/balance/version/modify [post]
  1077. func (c *ExcelInfoController) ModifyBalanceExcelVersion() {
  1078. br := new(models.BaseResponse).Init()
  1079. defer func() {
  1080. c.Data["json"] = br
  1081. c.ServeJSON()
  1082. }()
  1083. sysUser := c.SysUser
  1084. if sysUser == nil {
  1085. br.Msg = "请登录"
  1086. br.ErrMsg = "请登录,SysUser Is Empty"
  1087. br.Ret = 408
  1088. return
  1089. }
  1090. var req request.AddBalanceStaticExcelInfoReq
  1091. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1092. if err != nil {
  1093. br.Msg = "参数解析异常!"
  1094. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1095. return
  1096. }
  1097. if req.ExcelInfoId <= 0 {
  1098. br.Msg = "请传入ETA表格标识!"
  1099. return
  1100. }
  1101. req.VersionName = strings.Trim(req.VersionName, " ")
  1102. if req.VersionName == "" {
  1103. br.Msg = "请填写版本名称!"
  1104. br.IsSendEmail = false
  1105. return
  1106. }
  1107. excelInfo, err := excel.GetExcelInfoById(req.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 != 1 && excelInfo.ParentId != 0 {
  1118. br.Msg = "请选择静态表"
  1119. return
  1120. }
  1121. // 操作权限校验, 增加协作人判断
  1122. {
  1123. checkExcelInfo := excelInfo
  1124. if excelInfo.Source == utils.BALANCE_TABLE {
  1125. checkExcelInfoId := excelInfo.ExcelInfoId
  1126. if excelInfo.BalanceType == 1 {
  1127. checkExcelInfoId = excelInfo.RelExcelInfoId
  1128. } else {
  1129. if excelInfo.ParentId > 0 {
  1130. checkExcelInfoId = excelInfo.ParentId
  1131. }
  1132. }
  1133. if checkExcelInfoId != excelInfo.ExcelInfoId {
  1134. checkExcelInfo, err = excel.GetExcelInfoById(checkExcelInfoId)
  1135. if err != nil {
  1136. br.Msg = "获取平衡表格信息失败"
  1137. br.ErrMsg = "获取平衡表格信息失败,Err:" + err.Error()
  1138. return
  1139. }
  1140. }
  1141. }
  1142. // 数据权限
  1143. haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  1144. if e != nil {
  1145. br.Msg = "获取ETA表格权限失败"
  1146. br.ErrMsg = "获取表格权限信息失败,Err" + e.Error()
  1147. return
  1148. }
  1149. button := excelService.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
  1150. if !button.OpButton {
  1151. br.Msg = "无操作权限"
  1152. br.IsSendEmail = false
  1153. return
  1154. }
  1155. }
  1156. // 检验分类下是否存在该版本号
  1157. {
  1158. var condition string
  1159. var pars []interface{}
  1160. condition += " AND rel_excel_info_id=? "
  1161. pars = append(pars, req.ExcelInfoId)
  1162. condition += " AND version_name=? "
  1163. pars = append(pars, req.VersionName)
  1164. count, tmpErr := excel.GetExcelInfoCountByCondition(condition, pars)
  1165. if tmpErr != nil {
  1166. br.Msg = "查询版本号失败"
  1167. br.ErrMsg = tmpErr.Error()
  1168. return
  1169. }
  1170. if count > 0 {
  1171. br.Msg = "表格版本号已存在,请重新填写表格名称"
  1172. br.IsSendEmail = false
  1173. return
  1174. }
  1175. }
  1176. excelInfo.ModifyTime = time.Now()
  1177. excelInfo.VersionName = req.VersionName
  1178. updateExcelInfoParams := []string{"ModifyTime", "VersionName"}
  1179. // todo 同步修改静态表中的图表和指标名称
  1180. // ETA表格信息变更
  1181. err = excelInfo.Update(updateExcelInfoParams)
  1182. if err != nil {
  1183. br.Msg = "操作失败"
  1184. br.ErrMsg = "操作失败,Err:" + err.Error()
  1185. return
  1186. }
  1187. br.Ret = 200
  1188. br.Success = true
  1189. br.Msg = "操作成功"
  1190. br.IsAddLog = true
  1191. }