excel_info.go 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413
  1. package excel
  2. import (
  3. "archive/zip"
  4. "encoding/json"
  5. "eta/eta_api/controllers"
  6. "eta/eta_api/models"
  7. "eta/eta_api/models/data_manage"
  8. excel3 "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/services"
  12. "eta/eta_api/services/data"
  13. excel2 "eta/eta_api/services/data/excel"
  14. "eta/eta_api/services/excel"
  15. "eta/eta_api/utils"
  16. "fmt"
  17. "github.com/rdlucklib/rdluck_tools/paging"
  18. "github.com/yidane/formula"
  19. "io"
  20. "os"
  21. "path/filepath"
  22. "strconv"
  23. "strings"
  24. "time"
  25. )
  26. // ExcelInfoController ETA表格管理
  27. type ExcelInfoController struct {
  28. controllers.BaseAuthController
  29. }
  30. // Add
  31. // @Title 新增表格接口
  32. // @Description 新增表格接口
  33. // @Param request body request.AddExcelInfoReq true "type json string"
  34. // @Success 200 {object} response.AddExcelInfoResp
  35. // @router /excel_info/add [post]
  36. func (c *ExcelInfoController) Add() {
  37. br := new(models.BaseResponse).Init()
  38. defer func() {
  39. c.Data["json"] = br
  40. c.ServeJSON()
  41. }()
  42. sysUser := c.SysUser
  43. if sysUser == nil {
  44. br.Msg = "请登录"
  45. br.ErrMsg = "请登录,SysUser Is Empty"
  46. br.Ret = 408
  47. return
  48. }
  49. deleteCache := true
  50. cacheKey := "CACHE_EXCEL_TABLE_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  51. defer func() {
  52. if deleteCache {
  53. _ = utils.Rc.Delete(cacheKey)
  54. }
  55. }()
  56. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  57. deleteCache = false
  58. br.Msg = "系统处理中,请稍后重试!"
  59. br.ErrMsg = "系统处理中,请稍后重试!"
  60. return
  61. }
  62. var req request.AddExcelInfoReq
  63. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  64. if err != nil {
  65. br.Msg = "参数解析异常!"
  66. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  67. return
  68. }
  69. req.ExcelName = strings.Trim(req.ExcelName, " ")
  70. if req.ExcelName == "" {
  71. br.Msg = "请填写表格名称!"
  72. br.IsSendEmail = false
  73. return
  74. }
  75. if req.ExcelClassifyId <= 0 {
  76. br.Msg = "分类参数错误!"
  77. br.IsSendEmail = false
  78. return
  79. }
  80. excelClassify, err := excel3.GetExcelClassifyById(req.ExcelClassifyId)
  81. if err != nil {
  82. if err.Error() == utils.ErrNoRow() {
  83. br.Msg = "分类不存在"
  84. br.ErrMsg = "分类不存在"
  85. br.IsSendEmail = false
  86. return
  87. }
  88. br.Msg = "获取分类信息失败"
  89. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  90. return
  91. }
  92. if excelClassify == nil {
  93. br.Msg = "分类不存在"
  94. br.ErrMsg = "分类不存在"
  95. br.IsSendEmail = false
  96. return
  97. }
  98. var condition string
  99. var pars []interface{}
  100. condition += " AND excel_classify_id=? "
  101. pars = append(pars, req.ExcelClassifyId)
  102. condition += " AND excel_name=? "
  103. pars = append(pars, req.ExcelName)
  104. // 获取分类下是否存在该表格名称
  105. count, err := excel3.GetExcelInfoCountByCondition(condition, pars)
  106. if err != nil {
  107. br.Msg = "判断表格名称是否存在失败"
  108. br.ErrMsg = "判断表格名称是否存在失败,Err:" + err.Error()
  109. return
  110. }
  111. if count > 0 {
  112. br.Msg = "表格名称已存在,请重新填写表格名称"
  113. br.IsSendEmail = false
  114. return
  115. }
  116. // 默认的excel类型是1
  117. if req.Source == 0 {
  118. req.Source = 1
  119. }
  120. content := req.Content
  121. // 引用的指标id
  122. edbInfoIdList := make([]int, 0)
  123. // 自定义表格
  124. if req.Source == 2 {
  125. jsonStrByte, err := json.Marshal(req.TableData)
  126. if err != nil {
  127. br.Msg = "自定义表格数据获取失败"
  128. br.ErrMsg = "自定义表格数据获取失败,转json失败,Err:" + err.Error()
  129. return
  130. }
  131. var tableData request.TableDataReq
  132. err = json.Unmarshal(jsonStrByte, &tableData)
  133. if err != nil {
  134. br.Msg = "自定义表格数据获取失败"
  135. br.ErrMsg = "自定义表格数据获取失败,json转结构体失败,Err:" + err.Error()
  136. return
  137. }
  138. tableDataConfig, err := excel2.GetTableDataConfig(tableData)
  139. if err != nil {
  140. br.Msg = "自定义表格数据获取失败"
  141. br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
  142. return
  143. }
  144. edbInfoIdList = tableDataConfig.EdbInfoIdList
  145. contentByte, err := json.Marshal(tableDataConfig)
  146. if err != nil {
  147. br.Msg = "自定义表格数据获取失败"
  148. br.ErrMsg = "自定义表格数据获取后,转json失败,Err:" + err.Error()
  149. return
  150. }
  151. content = string(contentByte)
  152. }
  153. // 混合表格
  154. if req.Source == 3 {
  155. contentByte, err := json.Marshal(req.TableData)
  156. if err != nil {
  157. br.Msg = "自定义表格数据获取失败"
  158. br.ErrMsg = "自定义表格数据获取后,转json失败,Err:" + err.Error()
  159. return
  160. }
  161. content = string(contentByte)
  162. var result request.MixedTableReq
  163. err = json.Unmarshal(contentByte, &result)
  164. if err != nil {
  165. br.Msg = "获取失败"
  166. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  167. return
  168. }
  169. newResult, err, errMsg := excel2.GetMixedTableCellData(result)
  170. if err != nil {
  171. br.Msg = "获取失败"
  172. if errMsg != `` {
  173. br.Msg = errMsg
  174. }
  175. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  176. return
  177. }
  178. edbInfoIdMap := make(map[int]int)
  179. for _, tmpV := range newResult {
  180. for _, v := range tmpV {
  181. if v.EdbInfoId > 0 {
  182. if _, ok := edbInfoIdMap[v.EdbInfoId]; !ok {
  183. edbInfoIdMap[v.EdbInfoId] = v.EdbInfoId
  184. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  185. }
  186. }
  187. }
  188. }
  189. }
  190. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  191. excelInfo := &excel3.ExcelInfo{
  192. //ExcelInfoId: 0,
  193. ExcelName: req.ExcelName,
  194. Source: req.Source,
  195. ExcelType: req.ExcelType,
  196. UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + timestamp),
  197. ExcelClassifyId: req.ExcelClassifyId,
  198. SysUserId: sysUser.AdminId,
  199. SysUserRealName: sysUser.RealName,
  200. Content: content,
  201. ExcelImage: req.ExcelImage,
  202. Sort: 0,
  203. IsDelete: 0,
  204. ModifyTime: time.Now(),
  205. CreateTime: time.Now(),
  206. }
  207. excelEdbMappingList := make([]*excel3.ExcelEdbMapping, 0)
  208. if len(edbInfoIdList) > 0 {
  209. for _, edbInfoId := range edbInfoIdList {
  210. excelEdbMappingList = append(excelEdbMappingList, &excel3.ExcelEdbMapping{
  211. //ExcelEdbMappingId: 0,
  212. //ExcelInfoId: 0,
  213. Source: excelInfo.Source,
  214. EdbInfoId: edbInfoId,
  215. CreateTime: time.Now(),
  216. ModifyTime: time.Now(),
  217. })
  218. }
  219. }
  220. err = excel3.AddExcelInfo(excelInfo, excelEdbMappingList)
  221. if err != nil {
  222. br.Msg = "保存失败"
  223. br.ErrMsg = "保存失败,Err:" + err.Error()
  224. return
  225. }
  226. // 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
  227. if req.Source == 1 {
  228. go excel2.UpdateExcelInfoFileUrl(excelInfo)
  229. }
  230. _, err = services.UpdateExcelEditMark(excelInfo.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
  231. if err != nil {
  232. br.Msg = "查询标记状态失败"
  233. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  234. return
  235. }
  236. resp := new(response.AddExcelInfoResp)
  237. resp.ExcelInfoId = excelInfo.ExcelInfoId
  238. resp.UniqueCode = excelInfo.UniqueCode
  239. //新增操作日志
  240. //{
  241. // excelLog := &data_manage.ExcelInfoLog{
  242. // //ExcelInfoLogId: 0,
  243. // ExcelInfoId: excelInfo.ExcelInfoId,
  244. // ExcelName: req.ExcelName,
  245. // ExcelClassifyId: req.ExcelClassifyId,
  246. // SysUserId: sysUser.AdminId,
  247. // SysUserRealName: sysUser.RealName,
  248. // UniqueCode: excelInfo.UniqueCode,
  249. // CreateTime: time.Now(),
  250. // Content: string(c.Ctx.Input.RequestBody),
  251. // Status: "新增表格",
  252. // Method: c.Ctx.Input.URI(),
  253. // }
  254. // go data_manage.AddExcelInfoLog(excelLog)
  255. //}
  256. br.Ret = 200
  257. br.Success = true
  258. br.Msg = "保存成功"
  259. br.Data = resp
  260. br.IsAddLog = true
  261. }
  262. // List
  263. // @Title ETA表格列表接口
  264. // @Description ETA表格列表接口
  265. // @Param PageSize query int true "每页数据条数"
  266. // @Param CurrentIndex query int true "当前页页码,从1开始"
  267. // @Param ExcelClassifyId query int true "分类id"
  268. // @Param Keyword query string true "搜索关键词"
  269. // @Param AdminId query int false "创建人id"
  270. // @Param Source query int true "格来源,1:excel插件的表格,2:自定义表格,3:混合表格,默认:1"
  271. // @Param IsShowMe query bool true "是否只看我的,true、false"
  272. // @Success 200 {object} response.ExcelListResp
  273. // @router /excel_info/list [get]
  274. func (c *ExcelInfoController) List() {
  275. br := new(models.BaseResponse).Init()
  276. defer func() {
  277. c.Data["json"] = br
  278. c.ServeJSON()
  279. }()
  280. sysUser := c.SysUser
  281. if sysUser == nil {
  282. br.Msg = "请登录"
  283. br.ErrMsg = "请登录,SysUser Is Empty"
  284. br.Ret = 408
  285. return
  286. }
  287. excelClassifyId, _ := c.GetInt("ExcelClassifyId")
  288. pageSize, _ := c.GetInt("PageSize")
  289. currentIndex, _ := c.GetInt("CurrentIndex")
  290. keyword := c.GetString("Keyword")
  291. adminId, _ := c.GetInt("AdminId")
  292. source, _ := c.GetInt("Source")
  293. var total int
  294. page := paging.GetPaging(currentIndex, pageSize, total)
  295. var startSize int
  296. if pageSize <= 0 {
  297. pageSize = utils.PageSize20
  298. }
  299. if currentIndex <= 0 {
  300. currentIndex = 1
  301. }
  302. startSize = paging.StartIndex(currentIndex, pageSize)
  303. var condition string
  304. var pars []interface{}
  305. // 如果没有传的话,那就是代表前三种表格
  306. if source <= 0 {
  307. condition += " AND source in (?,?,?) "
  308. pars = append(pars, utils.EXCEL_DEFAULT, utils.TIME_TABLE, utils.MIXED_TABLE)
  309. } else {
  310. condition += " AND source = ? "
  311. pars = append(pars, source)
  312. }
  313. // 筛选分类
  314. if excelClassifyId > 0 {
  315. _, err := excel3.GetExcelClassifyById(excelClassifyId)
  316. if err != nil && err.Error() != utils.ErrNoRow() {
  317. br.Msg = "获取表格信息失败"
  318. br.ErrMsg = "获取信息失败,GetExcelClassify,Err:" + err.Error()
  319. return
  320. }
  321. condition += " AND excel_classify_id = ? "
  322. pars = append(pars, excelClassifyId)
  323. }
  324. if keyword != "" {
  325. condition += ` AND ( excel_name LIKE ? )`
  326. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  327. }
  328. if adminId > 0 {
  329. condition += " AND sys_user_id = ? "
  330. pars = append(pars, adminId)
  331. }
  332. //只看我的
  333. isShowMe, _ := c.GetBool("IsShowMe")
  334. if isShowMe {
  335. condition += " AND sys_user_id = ? "
  336. pars = append(pars, sysUser.AdminId)
  337. }
  338. //获取表格信息
  339. list, err := excel3.GetNoContentExcelListByCondition(condition, pars, startSize, pageSize)
  340. if err != nil && err.Error() != utils.ErrNoRow() {
  341. br.Success = true
  342. br.Msg = "获取表格信息失败"
  343. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  344. return
  345. }
  346. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  347. list = make([]*excel3.MyExcelInfoList, 0)
  348. }
  349. // 总数据量
  350. dataCount, err := excel3.GetExcelListCountByCondition(condition, pars)
  351. if err != nil && err.Error() != utils.ErrNoRow() {
  352. br.Msg = "获取表格列表信息失败"
  353. br.ErrMsg = "获取表格列表数据总数失败,Err:" + err.Error()
  354. return
  355. }
  356. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  357. resp := response.ExcelListResp{
  358. Paging: page,
  359. List: list,
  360. }
  361. br.Ret = 200
  362. br.Success = true
  363. br.Msg = "获取成功"
  364. br.Data = resp
  365. }
  366. // Detail
  367. // @Title 获取表格详情
  368. // @Description 获取表格详情接口
  369. // @Param ExcelInfoId query int true "表格id"
  370. // @Success 200 {object} data_manage.ExcelInfo
  371. // @router /excel_info/detail [get]
  372. func (c *ExcelInfoController) Detail() {
  373. br := new(models.BaseResponse).Init()
  374. defer func() {
  375. c.Data["json"] = br
  376. c.ServeJSON()
  377. }()
  378. sysUser := c.SysUser
  379. if sysUser == nil {
  380. br.Msg = "请登录"
  381. br.ErrMsg = "请登录,SysUser Is Empty"
  382. br.Ret = 408
  383. return
  384. }
  385. excelInfoId, _ := c.GetInt("ExcelInfoId")
  386. if excelInfoId <= 0 {
  387. br.Msg = "请选择表格"
  388. br.ErrMsg = "ExcelInfoId未传"
  389. br.IsSendEmail = false
  390. return
  391. }
  392. // 获取数据详情
  393. excelDetail, errMsg, err := excel2.GetExcelDetailInfoByExcelInfoId(excelInfoId)
  394. if err != nil {
  395. br.Msg = errMsg
  396. br.ErrMsg = err.Error()
  397. return
  398. }
  399. // 编辑状态
  400. markStatus, err := services.UpdateExcelEditMark(excelInfoId, sysUser.AdminId, 2, sysUser.RealName)
  401. if err != nil {
  402. br.Msg = "查询标记状态失败"
  403. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  404. return
  405. }
  406. if markStatus.Status == 0 {
  407. excelDetail.CanEdit = true
  408. } else {
  409. excelDetail.Editor = markStatus.Editor
  410. }
  411. // excel表格按钮权限
  412. excelDetail.Button = excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source)
  413. br.Ret = 200
  414. br.Success = true
  415. br.Msg = "获取成功"
  416. br.Data = excelDetail
  417. }
  418. // Edit
  419. // @Title 编辑表格接口
  420. // @Description 新增表格接口
  421. // @Param request body request.EditExcelInfoReq true "type json string"
  422. // @Success 200 {object} response.AddExcelInfoResp
  423. // @router /excel_info/edit [post]
  424. func (c *ExcelInfoController) Edit() {
  425. br := new(models.BaseResponse).Init()
  426. defer func() {
  427. c.Data["json"] = br
  428. c.ServeJSON()
  429. }()
  430. sysUser := c.SysUser
  431. if sysUser == nil {
  432. br.Msg = "请登录"
  433. br.ErrMsg = "请登录,SysUser Is Empty"
  434. br.Ret = 408
  435. return
  436. }
  437. deleteCache := true
  438. var req request.EditExcelInfoReq
  439. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  440. if err != nil {
  441. br.Msg = "参数解析异常!"
  442. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  443. return
  444. }
  445. if req.ExcelInfoId <= 0 {
  446. br.Msg = "请传入ETA表格标识!"
  447. return
  448. }
  449. cacheKey := "CACHE_TABLE_INFO_EDIT_" + strconv.Itoa(req.ExcelInfoId)
  450. defer func() {
  451. if deleteCache {
  452. _ = utils.Rc.Delete(cacheKey)
  453. }
  454. }()
  455. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  456. deleteCache = false
  457. br.Msg = "系统处理中,请稍后重试!"
  458. br.ErrMsg = "系统处理中,请稍后重试!"
  459. return
  460. }
  461. req.ExcelName = strings.Trim(req.ExcelName, " ")
  462. if req.ExcelName == "" {
  463. br.Msg = "请填写表格名称!"
  464. br.IsSendEmail = false
  465. return
  466. }
  467. if req.ExcelClassifyId <= 0 {
  468. br.Msg = "分类参数错误!"
  469. br.IsSendEmail = false
  470. return
  471. }
  472. // 标记编辑状态
  473. markRet, err := services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
  474. if err != nil {
  475. br.Msg = "查询标记状态失败"
  476. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  477. return
  478. }
  479. if markRet.Status == 1 {
  480. br.Data = markRet
  481. return
  482. }
  483. excelClassify, err := excel3.GetExcelClassifyById(req.ExcelClassifyId)
  484. if err != nil {
  485. if err.Error() == utils.ErrNoRow() {
  486. br.Msg = "分类不存在"
  487. br.ErrMsg = "分类不存在"
  488. br.IsSendEmail = false
  489. return
  490. }
  491. br.Msg = "获取分类信息失败"
  492. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  493. return
  494. }
  495. if excelClassify == nil {
  496. br.Msg = "分类不存在"
  497. br.ErrMsg = "分类不存在"
  498. br.IsSendEmail = false
  499. return
  500. }
  501. //判断表格是否存在
  502. var condition string
  503. var pars []interface{}
  504. condition += " AND excel_info_id != ? "
  505. pars = append(pars, req.ExcelInfoId)
  506. condition += " AND excel_classify_id=? "
  507. pars = append(pars, req.ExcelClassifyId)
  508. condition += " AND excel_name=? "
  509. pars = append(pars, req.ExcelName)
  510. // 获取分类下是否存在该表格名称
  511. count, err := excel3.GetExcelInfoCountByCondition(condition, pars)
  512. if err != nil {
  513. br.Msg = "ETA判断表格名称是否存在失败"
  514. br.ErrMsg = "判断ETA表格名称是否存在失败,Err:" + err.Error()
  515. return
  516. }
  517. if count > 0 {
  518. br.Msg = "ETA表格名称已存在,请重新填写"
  519. br.IsSendEmail = false
  520. return
  521. }
  522. excelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
  523. if err != nil {
  524. br.Msg = "获取ETA表格失败"
  525. br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
  526. return
  527. }
  528. // 操作权限校验
  529. {
  530. button := excel2.GetExcelInfoOpButton(sysUser, excelInfo.SysUserId, excelInfo.Source)
  531. if !button.OpButton {
  532. br.Msg = "无操作权限"
  533. br.Msg = "无操作权限"
  534. br.IsSendEmail = false
  535. return
  536. }
  537. }
  538. // 引用的指标id
  539. edbInfoIdList := make([]int, 0)
  540. content := req.Content
  541. switch excelInfo.Source {
  542. case utils.TIME_TABLE: // 自定义表格
  543. jsonStrByte, err := json.Marshal(req.TableData)
  544. if err != nil {
  545. br.Msg = "自定义表格数据获取失败"
  546. br.ErrMsg = "自定义表格数据获取失败,转json失败,Err:" + err.Error()
  547. return
  548. }
  549. var tableData request.TableDataReq
  550. err = json.Unmarshal(jsonStrByte, &tableData)
  551. if err != nil {
  552. br.Msg = "自定义表格数据获取失败"
  553. br.ErrMsg = "自定义表格数据获取失败,json转结构体失败,Err:" + err.Error()
  554. return
  555. }
  556. edbInfoIdList = tableData.EdbInfoIdList
  557. tableDataConfig, err := excel2.GetTableDataConfig(tableData)
  558. if err != nil {
  559. br.Msg = "自定义表格数据获取失败"
  560. br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
  561. return
  562. }
  563. contentByte, err := json.Marshal(tableDataConfig)
  564. if err != nil {
  565. br.Msg = "自定义表格数据获取失败"
  566. br.ErrMsg = "自定义表格数据获取后,转json失败,Err:" + err.Error()
  567. return
  568. }
  569. content = string(contentByte)
  570. case utils.MIXED_TABLE: // 混合表格
  571. contentByte, err := json.Marshal(req.TableData)
  572. if err != nil {
  573. br.Msg = "混合表格数据获取失败"
  574. br.ErrMsg = "混合表格数据获取后,转json失败,Err:" + err.Error()
  575. return
  576. }
  577. content = string(contentByte)
  578. var result request.MixedTableReq
  579. err = json.Unmarshal(contentByte, &result)
  580. if err != nil {
  581. br.Msg = "获取失败"
  582. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  583. return
  584. }
  585. newResult, err, errMsg := excel2.GetMixedTableCellData(result)
  586. if err != nil {
  587. br.Msg = "获取失败"
  588. if errMsg != `` {
  589. br.Msg = errMsg
  590. }
  591. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  592. return
  593. }
  594. edbInfoIdMap := make(map[int]int)
  595. for _, tmpV := range newResult {
  596. for _, v := range tmpV {
  597. if v.EdbInfoId > 0 {
  598. if _, ok := edbInfoIdMap[v.EdbInfoId]; !ok {
  599. edbInfoIdMap[v.EdbInfoId] = v.EdbInfoId
  600. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  601. }
  602. }
  603. }
  604. }
  605. }
  606. excelInfo.ModifyTime = time.Now()
  607. excelInfo.ExcelName = req.ExcelName
  608. excelInfo.ExcelType = req.ExcelType
  609. excelInfo.ExcelClassifyId = req.ExcelClassifyId
  610. excelInfo.ExcelImage = req.ExcelImage
  611. excelInfo.Content = content
  612. // 自动保存时不会传缩略图,也就不更新这个字段
  613. var updateExcelInfoParams []string
  614. if req.ExcelImage != "" {
  615. updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "ExcelImage", "Content"}
  616. } else {
  617. updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "Content"}
  618. }
  619. excelEdbMappingList := make([]*excel3.ExcelEdbMapping, 0)
  620. if len(edbInfoIdList) > 0 {
  621. for _, edbInfoId := range edbInfoIdList {
  622. excelEdbMappingList = append(excelEdbMappingList, &excel3.ExcelEdbMapping{
  623. //ExcelEdbMappingId: 0,
  624. ExcelInfoId: excelInfo.ExcelInfoId,
  625. Source: excelInfo.Source,
  626. EdbInfoId: edbInfoId,
  627. CreateTime: time.Now(),
  628. ModifyTime: time.Now(),
  629. })
  630. }
  631. }
  632. err = excel3.EditExcelInfo(excelInfo, updateExcelInfoParams, excelEdbMappingList)
  633. if err != nil {
  634. br.Msg = "保存失败"
  635. br.ErrMsg = "保存失败,Err:" + err.Error()
  636. return
  637. }
  638. // 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
  639. if excelInfo.Source == 1 {
  640. go excel2.UpdateExcelInfoFileUrl(excelInfo)
  641. }
  642. // 加入草稿
  643. {
  644. excelDraftInfo := &excel3.ExcelDraft{
  645. //ExcelDraftId: 0,
  646. ExcelId: req.ExcelInfoId,
  647. Name: req.ExcelName,
  648. Content: content,
  649. OpUserId: sysUser.AdminId,
  650. OpUserName: sysUser.RealName,
  651. CreateTime: time.Now(),
  652. }
  653. err = excel3.AddExcelDraft(excelDraftInfo)
  654. }
  655. resp := response.AddExcelInfoResp{
  656. ExcelInfoId: excelInfo.ExcelInfoId,
  657. UniqueCode: excelInfo.UniqueCode,
  658. }
  659. //删除公共图库那边的缓存
  660. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelInfo.UniqueCode)
  661. br.Ret = 200
  662. br.Success = true
  663. br.Msg = "修改成功"
  664. br.Data = resp
  665. br.IsAddLog = true
  666. }
  667. // Move
  668. // @Title 移动表格接口
  669. // @Description 移动表格接口
  670. // @Param request body request.MoveExcelInfoReq true "type json string"
  671. // @Success Ret=200 移动成功
  672. // @router /excel_info/move [post]
  673. func (c *ExcelInfoController) Move() {
  674. br := new(models.BaseResponse).Init()
  675. defer func() {
  676. c.Data["json"] = br
  677. c.ServeJSON()
  678. }()
  679. sysUser := c.SysUser
  680. if sysUser == nil {
  681. br.Msg = "请登录"
  682. br.ErrMsg = "请登录,SysUser Is Empty"
  683. br.Ret = 408
  684. return
  685. }
  686. var req request.MoveExcelInfoReq
  687. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  688. if err != nil {
  689. br.Msg = "参数解析异常!"
  690. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  691. return
  692. }
  693. if req.ExcelInfoId <= 0 {
  694. br.Msg = "参数错误"
  695. br.ErrMsg = "表格id小于等于0"
  696. br.IsSendEmail = false
  697. return
  698. }
  699. if req.ExcelClassifyId <= 0 {
  700. br.Msg = "请选择分类"
  701. br.IsSendEmail = false
  702. return
  703. }
  704. //判断分类是否存在
  705. _, err = excel3.GetExcelClassifyById(req.ExcelClassifyId)
  706. if err != nil {
  707. br.Msg = "移动失败"
  708. br.ErrMsg = "获取分类信息失败" + err.Error()
  709. if err.Error() == utils.ErrNoRow() {
  710. br.Msg = "分类已被删除,不可移动,请刷新页面"
  711. br.ErrMsg = "分类已被删除,不可移动,请刷新页面"
  712. br.IsSendEmail = false
  713. }
  714. return
  715. }
  716. // 获取表格信息
  717. excelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
  718. if err != nil {
  719. br.Msg = "移动失败"
  720. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  721. return
  722. }
  723. //如果改变了分类,那么移动该表格数据
  724. if excelInfo.ExcelClassifyId != req.ExcelClassifyId {
  725. //查询需要修改的分类下是否存在同一个表格名称
  726. tmpExcelInfo, tmpErr := excel3.GetExcelInfoByClassifyIdAndName(req.ExcelClassifyId, excelInfo.ExcelName)
  727. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  728. br.Msg = "移动失败"
  729. br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  730. return
  731. }
  732. if tmpExcelInfo != nil {
  733. br.Msg = "移动失败,同一个分类下表格名称不允许重复"
  734. br.ErrMsg = "移动失败,同一个分类下表格名称不允许重复"
  735. br.IsSendEmail = false
  736. return
  737. }
  738. // 变更表格的所属分类
  739. excelInfo.ExcelClassifyId = req.ExcelClassifyId
  740. err = excelInfo.Update([]string{"ExcelClassifyId"})
  741. if err != nil {
  742. br.Msg = "移动失败"
  743. br.ErrMsg = "移动失败,Err:" + err.Error()
  744. return
  745. }
  746. }
  747. //移动排序
  748. updateCol := make([]string, 0)
  749. //如果有传入 上一个兄弟节点分类id
  750. if req.PrevExcelInfoId > 0 {
  751. prevExcelInfo, err := excel3.GetExcelInfoById(req.PrevExcelInfoId)
  752. if err != nil {
  753. br.Msg = "移动失败"
  754. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  755. return
  756. }
  757. //如果是移动在两个兄弟节点之间
  758. if req.NextExcelInfoId > 0 {
  759. //下一个兄弟节点
  760. nextExcelInfo, err := excel3.GetExcelInfoById(req.NextExcelInfoId)
  761. if err != nil {
  762. br.Msg = "移动失败"
  763. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  764. return
  765. }
  766. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  767. if prevExcelInfo.Sort == nextExcelInfo.Sort || prevExcelInfo.Sort == excelInfo.Sort {
  768. //变更兄弟节点的排序
  769. updateSortStr := `sort + 2`
  770. _ = excel3.UpdateExcelInfoSortByClassifyId(prevExcelInfo.ExcelClassifyId, prevExcelInfo.Sort, prevExcelInfo.ExcelInfoId, updateSortStr)
  771. } else {
  772. //如果下一个兄弟的排序权重正好是上个兄弟节点下一层,那么需要再加一层了
  773. if nextExcelInfo.Sort-prevExcelInfo.Sort == 1 {
  774. //变更兄弟节点的排序
  775. updateSortStr := `sort + 1`
  776. _ = excel3.UpdateExcelInfoSortByClassifyId(prevExcelInfo.ExcelClassifyId, prevExcelInfo.Sort, prevExcelInfo.ExcelInfoId, updateSortStr)
  777. }
  778. }
  779. }
  780. // 变更表格在当前分类下的排序
  781. excelInfo.Sort = prevExcelInfo.Sort + 1
  782. excelInfo.ModifyTime = time.Now()
  783. updateCol = append(updateCol, "Sort", "ModifyTime")
  784. } else {
  785. firstClassify, err := excel3.GetFirstExcelInfoByClassifyId(req.ExcelClassifyId)
  786. if err != nil && err.Error() != utils.ErrNoRow() {
  787. br.Msg = "移动失败"
  788. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  789. return
  790. }
  791. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  792. if firstClassify != nil && firstClassify.Sort == 0 {
  793. updateSortStr := ` sort + 1 `
  794. _ = excel3.UpdateExcelInfoSortByClassifyId(firstClassify.ExcelClassifyId, 0, firstClassify.ExcelInfoId+1, updateSortStr)
  795. }
  796. // 变更表格在当前分类下的排序
  797. excelInfo.Sort = 0 //那就是排在第一位
  798. excelInfo.ModifyTime = time.Now()
  799. updateCol = append(updateCol, "Sort", "ModifyTime")
  800. }
  801. //更新
  802. if len(updateCol) > 0 {
  803. err = excelInfo.Update(updateCol)
  804. if err != nil {
  805. br.Msg = "移动失败"
  806. br.ErrMsg = "修改失败,Err:" + err.Error()
  807. return
  808. }
  809. }
  810. if err != nil {
  811. br.Msg = "移动失败"
  812. br.ErrMsg = "修改失败,Err:" + err.Error()
  813. return
  814. }
  815. //新增操作日志
  816. //{
  817. // ExcelLog := new(data_manage.ExcelInfoLog)
  818. // ExcelLog.ExcelName = ExcelInfo.ExcelName
  819. // ExcelLog.ExcelInfoId = req.ExcelInfoId
  820. // ExcelLog.ExcelClassifyId = ExcelInfo.ExcelClassifyId
  821. // ExcelLog.SysUserId = sysUser.AdminId
  822. // ExcelLog.SysUserRealName = sysUser.RealName
  823. // ExcelLog.UniqueCode = ExcelInfo.UniqueCode
  824. // ExcelLog.CreateTime = time.Now()
  825. // ExcelLog.Content = string(c.Ctx.Input.RequestBody)
  826. // ExcelLog.Status = "移动表格"
  827. // ExcelLog.Method = c.Ctx.Input.URL()
  828. // go data_manage.AddExcelInfoLog(ExcelLog)
  829. //}
  830. br.Ret = 200
  831. br.Success = true
  832. br.IsAddLog = true
  833. br.Msg = "移动成功"
  834. }
  835. // Delete
  836. // @Title 删除表格接口
  837. // @Description 删除表格接口
  838. // @Param request body request.DeleteExcelInfoReq true "type json string"
  839. // @Success Ret=200 删除成功
  840. // @router /excel_info/delete [post]
  841. func (c *ExcelInfoController) Delete() {
  842. br := new(models.BaseResponse).Init()
  843. defer func() {
  844. c.Data["json"] = br
  845. c.ServeJSON()
  846. }()
  847. resp := response.AddExcelInfoResp{}
  848. sysUser := c.SysUser
  849. if sysUser == nil {
  850. br.Msg = "请登录"
  851. br.ErrMsg = "请登录,SysUser Is Empty"
  852. br.Ret = 408
  853. return
  854. }
  855. var req request.DeleteExcelInfoReq
  856. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  857. if err != nil {
  858. br.Msg = "参数解析异常!"
  859. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  860. return
  861. }
  862. if req.ExcelInfoId <= 0 {
  863. br.Msg = "参数错误"
  864. br.ErrMsg = "表格id小于等于0"
  865. br.IsSendEmail = false
  866. return
  867. }
  868. // 获取表格信息
  869. excelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
  870. if err != nil {
  871. br.Msg = "删除失败"
  872. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  873. return
  874. }
  875. // 删除excel
  876. err, errMsg, isSendEmail := excel2.Delete(excelInfo, sysUser)
  877. if err != nil {
  878. br.Msg = "删除失败"
  879. if errMsg != `` {
  880. br.Msg = errMsg
  881. }
  882. br.ErrMsg = "删除失败,Err:" + err.Error()
  883. br.IsSendEmail = isSendEmail
  884. return
  885. }
  886. // 返回下一个表格的信息
  887. {
  888. var nextItem *excel3.ExcelInfo
  889. var condition string
  890. var pars []interface{}
  891. condition += " AND excel_classify_id=? "
  892. pars = append(pars, excelInfo.ExcelClassifyId)
  893. condition += " AND sort>=? "
  894. pars = append(pars, excelInfo.Sort)
  895. nextItem, err = excel3.GetNextExcelInfoByCondition(condition, pars)
  896. if err != nil && err.Error() != utils.ErrNoRow() {
  897. br.Msg = "删除失败"
  898. br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  899. return
  900. }
  901. // 如果没找到,那么查找下一个分类的第一个表格
  902. if nextItem == nil {
  903. currClassifyInfo, err := excel3.GetExcelClassifyById(excelInfo.ExcelClassifyId)
  904. if err != nil && err.Error() != utils.ErrNoRow() {
  905. br.Msg = "删除失败"
  906. br.ErrMsg = "获取当前表格分类信息失败,Err:" + err.Error()
  907. return
  908. }
  909. //condition += " AND level=3 "
  910. //pars = append(pars, chartInfo.ExcelClassifyId)
  911. //var condition string
  912. //var pars []interface{}
  913. //condition += " AND sort>=? ORDER BY excel_classify_id ASC LIMIT 1 "
  914. //pars = append(pars, currClassifyInfo.Sort)
  915. //
  916. //classifyItem, err := data_manage.GetNextExcelClassifyByCondition(condition, pars)
  917. //if err != nil && err.Error() != utils.ErrNoRow() {
  918. // br.Msg = "删除失败"
  919. // br.ErrMsg = "获取下一级表格分类信息失败,Err:" + err.Error()
  920. // return
  921. //}
  922. //if classifyItem != nil {
  923. // nextItem, err = data_manage.GetNextExcelInfo(excelInfo.ExcelClassifyId,)
  924. // if err != nil && err.Error() != utils.ErrNoRow() {
  925. // br.Msg = "删除失败"
  926. // br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  927. // return
  928. // }
  929. //}
  930. nextItem, err = excel3.GetNextExcelInfo(excelInfo.ExcelClassifyId, currClassifyInfo.Sort, currClassifyInfo.Source)
  931. if err != nil && err.Error() != utils.ErrNoRow() {
  932. br.Msg = "删除失败"
  933. br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  934. return
  935. }
  936. }
  937. // 如果找到下一个表格了,那么就返回
  938. if nextItem != nil {
  939. resp = response.AddExcelInfoResp{
  940. ExcelInfoId: nextItem.ExcelInfoId,
  941. UniqueCode: nextItem.UniqueCode,
  942. }
  943. }
  944. }
  945. //删除公共图库那边的缓存
  946. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL)
  947. br.Ret = 200
  948. br.Success = true
  949. br.IsAddLog = true
  950. br.Data = resp
  951. br.Msg = "删除成功"
  952. }
  953. // AddDraft
  954. // @Title 新增表格草稿接口
  955. // @Description 新增表格草稿接口
  956. // @Param request body request.AddExcelDraftReq true "type json string"
  957. // @Success Ret=200 添加成功
  958. // @router /excel_info/draft/add [post]
  959. func (c *ExcelInfoController) AddDraft() {
  960. br := new(models.BaseResponse).Init()
  961. defer func() {
  962. c.Data["json"] = br
  963. c.ServeJSON()
  964. }()
  965. sysUser := c.SysUser
  966. if sysUser == nil {
  967. br.Msg = "请登录"
  968. br.ErrMsg = "请登录,SysUser Is Empty"
  969. br.Ret = 408
  970. return
  971. }
  972. var req request.AddExcelDraftReq
  973. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  974. if err != nil {
  975. br.Msg = "参数解析异常!"
  976. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  977. return
  978. }
  979. req.ExcelName = strings.Trim(req.ExcelName, " ")
  980. if req.ExcelName == "" {
  981. br.Msg = "请填写表格名称!"
  982. br.IsSendEmail = false
  983. return
  984. }
  985. if req.ExcelClassifyId <= 0 {
  986. br.Msg = "分类参数错误!"
  987. br.IsSendEmail = false
  988. return
  989. }
  990. excelClassify, err := excel3.GetExcelClassifyById(req.ExcelClassifyId)
  991. if err != nil {
  992. if err.Error() == utils.ErrNoRow() {
  993. br.Msg = "分类不存在"
  994. br.ErrMsg = "分类不存在"
  995. br.IsSendEmail = false
  996. return
  997. }
  998. br.Msg = "获取分类信息失败"
  999. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1000. return
  1001. }
  1002. if excelClassify == nil {
  1003. br.Msg = "分类不存在"
  1004. br.ErrMsg = "分类不存在"
  1005. br.IsSendEmail = false
  1006. return
  1007. }
  1008. var condition string
  1009. var pars []interface{}
  1010. condition += " AND excel_classify_id=? "
  1011. pars = append(pars, req.ExcelClassifyId)
  1012. condition += " AND excel_name=? "
  1013. pars = append(pars, req.ExcelName)
  1014. // 获取分类下是否存在该表格名称
  1015. _, err = excel3.GetExcelInfoById(req.ExcelInfoId)
  1016. if err != nil {
  1017. br.Msg = "判断表格名称是否存在失败"
  1018. br.ErrMsg = "判断表格名称是否存在失败,Err:" + err.Error()
  1019. return
  1020. }
  1021. excelDraftInfo := &excel3.ExcelDraft{
  1022. //ExcelDraftId: 0,
  1023. ExcelId: req.ExcelInfoId,
  1024. Name: req.ExcelName,
  1025. Content: req.Content,
  1026. OpUserId: sysUser.AdminId,
  1027. OpUserName: sysUser.RealName,
  1028. CreateTime: time.Now(),
  1029. }
  1030. err = excel3.AddExcelDraft(excelDraftInfo)
  1031. if err != nil {
  1032. br.Msg = "保存失败"
  1033. br.ErrMsg = "保存失败,Err:" + err.Error()
  1034. return
  1035. }
  1036. _, err = services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
  1037. if err != nil {
  1038. br.Msg = "查询标记状态失败"
  1039. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  1040. return
  1041. }
  1042. br.Ret = 200
  1043. br.Success = true
  1044. br.Msg = "添加成功"
  1045. }
  1046. // GetExcelTableData
  1047. // @Title 获取excel表格的table数据
  1048. // @Description 获取excel表格的table数据接口
  1049. // @Param UniqueCode query string true "表格code"
  1050. // @Success 200 {object} response.ExcelTableDetailResp
  1051. // @router /excel_info/table_data [get]
  1052. func (c *ExcelInfoController) GetExcelTableData() {
  1053. br := new(models.BaseResponse).Init()
  1054. defer func() {
  1055. c.Data["json"] = br
  1056. c.ServeJSON()
  1057. }()
  1058. sysUser := c.SysUser
  1059. if sysUser == nil {
  1060. br.Msg = "请登录"
  1061. br.ErrMsg = "请登录,SysUser Is Empty"
  1062. br.Ret = 408
  1063. return
  1064. }
  1065. uniqueCode := c.GetString("UniqueCode")
  1066. var err error
  1067. if uniqueCode == `` {
  1068. br.Msg = "请选择表格"
  1069. br.ErrMsg = "UniqueCode未传"
  1070. br.IsSendEmail = false
  1071. return
  1072. }
  1073. //获取eta表格信息
  1074. excelInfo, err := excel3.GetExcelInfoByUniqueCode(uniqueCode)
  1075. if err != nil {
  1076. br.Msg = "获取失败"
  1077. br.ErrMsg = "获取ETA表格信息失败,Err:" + err.Error()
  1078. if err.Error() == utils.ErrNoRow() {
  1079. br.Msg = "ETA表格被删除,请刷新页面"
  1080. br.ErrMsg = "ETA表格被删除,请刷新页面,Err:" + err.Error()
  1081. br.IsSendEmail = false
  1082. }
  1083. return
  1084. }
  1085. var tableData excel.TableData
  1086. switch excelInfo.Source {
  1087. case utils.EXCEL_DEFAULT:
  1088. luckySheetData, err := excel.GetLuckySheetData(excelInfo.Content)
  1089. if err != nil {
  1090. br.Msg = "获取失败"
  1091. br.ErrMsg = "获取excel数据失败,Err:" + err.Error()
  1092. return
  1093. }
  1094. tableData, err = luckySheetData.GetTableDataByLuckySheetDataStr(true)
  1095. if err != nil {
  1096. br.Msg = "获取失败"
  1097. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1098. return
  1099. }
  1100. case utils.TIME_TABLE:
  1101. var tableDataConfig excel2.TableDataConfig
  1102. err = json.Unmarshal([]byte(excelInfo.Content), &tableDataConfig)
  1103. if err != nil {
  1104. br.Msg = "获取失败"
  1105. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  1106. return
  1107. }
  1108. result, err := excel2.GetDataByTableDataConfig(tableDataConfig)
  1109. if err != nil {
  1110. br.Msg = "获取失败"
  1111. br.ErrMsg = "获取最新的表格数据失败,Err:" + err.Error()
  1112. return
  1113. }
  1114. tableData, err = excel.GetTableDataByCustomData(excelInfo.ExcelType, result)
  1115. if err != nil {
  1116. br.Msg = "获取失败"
  1117. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1118. return
  1119. }
  1120. case utils.MIXED_TABLE:
  1121. var result request.MixedTableReq
  1122. err = json.Unmarshal([]byte(excelInfo.Content), &result)
  1123. if err != nil {
  1124. br.Msg = "获取失败"
  1125. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  1126. return
  1127. }
  1128. newResult, err, errMsg := excel2.GetMixedTableCellData(result)
  1129. if err != nil {
  1130. br.Msg = "获取失败"
  1131. if errMsg != `` {
  1132. br.Msg = errMsg
  1133. }
  1134. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  1135. return
  1136. }
  1137. tableData, err = excel.GetTableDataByMixedTableData(newResult)
  1138. if err != nil {
  1139. br.Msg = "获取失败"
  1140. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1141. return
  1142. }
  1143. }
  1144. tableData = excel.HandleTableCell(tableData)
  1145. resp := response.ExcelTableDetailResp{
  1146. UniqueCode: excelInfo.UniqueCode,
  1147. ExcelImage: excelInfo.ExcelImage,
  1148. ExcelName: excelInfo.ExcelName,
  1149. TableInfo: tableData,
  1150. }
  1151. br.Ret = 200
  1152. br.Success = true
  1153. br.Msg = "获取成功"
  1154. br.Data = resp
  1155. }
  1156. //func init() {
  1157. //
  1158. // excelInfo, err := data_manage.GetExcelInfoById(52)
  1159. // if err != nil {
  1160. // fmt.Println("err:", err)
  1161. // return
  1162. // }
  1163. //
  1164. // luckySheetData, err := excel.GetLuckySheetData(excelInfo.Content)
  1165. // if err != nil {
  1166. // fmt.Println("err:", err)
  1167. // return
  1168. // }
  1169. // //_, err = luckySheetData.GetTableDataByLuckySheetDataStr()
  1170. // downloadFilePath, err := luckySheetData.ToExcel()
  1171. // if err != nil {
  1172. // fmt.Println("err:", err)
  1173. // return
  1174. // }
  1175. // fmt.Println(downloadFilePath)
  1176. //
  1177. // //fmt.Println(excel.GetColumnName(988, 283))
  1178. //}
  1179. // Calculate
  1180. // @Title 公式计算接口
  1181. // @Description 公式计算接口
  1182. // @Param request body request.CalculateReq true "type json string"
  1183. // @router /excel_info/table/calculate [post]
  1184. func (c *ExcelInfoController) Calculate() {
  1185. br := new(models.BaseResponse).Init()
  1186. defer func() {
  1187. c.Data["json"] = br
  1188. c.ServeJSON()
  1189. }()
  1190. sysUser := c.SysUser
  1191. if sysUser == nil {
  1192. br.Msg = "请登录"
  1193. br.ErrMsg = "请登录,SysUser Is Empty"
  1194. br.Ret = 408
  1195. return
  1196. }
  1197. var req request.CalculateReq
  1198. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1199. if err != nil {
  1200. br.Msg = "参数解析异常!"
  1201. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1202. return
  1203. }
  1204. if req.CalculateFormula == "" {
  1205. br.Msg = "请填写公式"
  1206. return
  1207. }
  1208. calculateFormula := req.CalculateFormula
  1209. calculateFormula = strings.TrimPrefix(calculateFormula, "=")
  1210. calculateFormula = strings.Replace(calculateFormula, "(", "(", -1)
  1211. calculateFormula = strings.Replace(calculateFormula, ")", ")", -1)
  1212. calculateFormula = strings.Replace(calculateFormula, ",", ",", -1)
  1213. calculateFormula = strings.Replace(calculateFormula, "。", ".", -1)
  1214. calculateFormula = strings.Replace(calculateFormula, "%", "*0.01", -1)
  1215. formulaFormStr := utils.ReplaceFormula(req.TagMap, calculateFormula)
  1216. //计算公式异常,那么就移除该指标
  1217. if formulaFormStr == `` {
  1218. //removeDateList = append(removeDateList, sk)
  1219. //fmt.Println("异常了")
  1220. br.Msg = "公式异常"
  1221. br.ErrMsg = "公式异常"
  1222. return
  1223. }
  1224. expression := formula.NewExpression(formulaFormStr)
  1225. calResult, err := expression.Evaluate()
  1226. if err != nil {
  1227. br.Msg = "计算失败"
  1228. br.ErrMsg = "计算失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr
  1229. // 分母为0的报错
  1230. if strings.Contains(err.Error(), "divide by zero") {
  1231. br.Msg = "分母不能为0"
  1232. br.ErrMsg = "分母不能为空,计算公式:" + formulaFormStr
  1233. br.IsSendEmail = false
  1234. }
  1235. return
  1236. }
  1237. // 如果计算结果是NAN,那么就提示报错
  1238. if calResult.IsNan() {
  1239. br.Msg = "计算失败"
  1240. br.ErrMsg = "计算失败:计算结果是:NAN;formulaStr:" + formulaFormStr
  1241. return
  1242. }
  1243. // 计算结果格式化
  1244. calFloat, e := calResult.Float64()
  1245. if e != nil {
  1246. br.Msg = "计算失败"
  1247. br.ErrMsg = "计算失败, Err: " + e.Error()
  1248. return
  1249. }
  1250. calVal := utils.FormatTableDataShowValue(calFloat)
  1251. //calVal := calResult.String()
  1252. //if err != nil {
  1253. // br.Msg = "计算失败"
  1254. // br.ErrMsg = "计算失败,结果转 string 失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr
  1255. // return
  1256. //}
  1257. br.Ret = 200
  1258. br.Success = true
  1259. br.Msg = "计算成功"
  1260. br.Data = calVal
  1261. }
  1262. // GetFirstEdbData
  1263. // @Title 获取未来日期数据接口
  1264. // @Description 获取未来日期数据接口
  1265. // @Param EdbInfoId query int true "指标id"
  1266. // @Param Num query int true "默认期数"
  1267. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒序`,不传默认倒序"
  1268. // @router /excel_info/table/first_edb_data_list [get]
  1269. func (c *ExcelInfoController) GetFirstEdbData() {
  1270. br := new(models.BaseResponse).Init()
  1271. defer func() {
  1272. c.Data["json"] = br
  1273. c.ServeJSON()
  1274. }()
  1275. sysUser := c.SysUser
  1276. if sysUser == nil {
  1277. br.Msg = "请登录"
  1278. br.ErrMsg = "请登录,SysUser Is Empty"
  1279. br.Ret = 408
  1280. return
  1281. }
  1282. edbInfoId, _ := c.GetInt("EdbInfoId")
  1283. num, _ := c.GetInt("Num")
  1284. sortType := c.GetString("SortType")
  1285. if edbInfoId <= 0 {
  1286. br.Msg = "请选择指标"
  1287. br.IsSendEmail = false
  1288. return
  1289. }
  1290. if num <= 0 {
  1291. br.Msg = "期数必须大于0"
  1292. br.IsSendEmail = false
  1293. return
  1294. }
  1295. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  1296. if err != nil {
  1297. br.Msg = "获取失败"
  1298. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  1299. return
  1300. }
  1301. dataList, err := excel2.GetFirstEdbDataList(edbInfo, num, []string{})
  1302. if err != nil {
  1303. br.Msg = "获取失败"
  1304. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1305. return
  1306. }
  1307. // 默认是倒序返回的数据,如果要正序的话,那么翻转下就好了
  1308. if sortType == "asc" {
  1309. for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
  1310. dataList[i], dataList[j] = dataList[j], dataList[i]
  1311. }
  1312. }
  1313. br.Ret = 200
  1314. br.Success = true
  1315. br.Msg = "获取成功"
  1316. br.Data = response.TableDataItem{
  1317. EdbInfoId: edbInfoId,
  1318. Data: dataList,
  1319. }
  1320. }
  1321. // GetOtherEdbData
  1322. // @Title 获取指定日期数据接口
  1323. // @Description 获取未来日期数据接口
  1324. // @Param request body request.GetOtherEdbDateDataReq true "type json string"
  1325. // @router /excel_info/table/other_edb_data_list [post]
  1326. func (c *ExcelInfoController) GetOtherEdbData() {
  1327. br := new(models.BaseResponse).Init()
  1328. defer func() {
  1329. c.Data["json"] = br
  1330. c.ServeJSON()
  1331. }()
  1332. sysUser := c.SysUser
  1333. if sysUser == nil {
  1334. br.Msg = "请登录"
  1335. br.ErrMsg = "请登录,SysUser Is Empty"
  1336. br.Ret = 408
  1337. return
  1338. }
  1339. var req request.GetOtherEdbDateDataReq
  1340. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1341. if err != nil {
  1342. br.Msg = "参数解析异常!"
  1343. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1344. return
  1345. }
  1346. if req.EdbInfoId <= 0 {
  1347. br.Msg = "请选择指标"
  1348. br.IsSendEmail = false
  1349. return
  1350. }
  1351. if len(req.DateList) <= 0 {
  1352. br.Msg = "请选择日期"
  1353. br.IsSendEmail = false
  1354. return
  1355. }
  1356. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  1357. if err != nil {
  1358. br.Msg = "获取失败"
  1359. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  1360. return
  1361. }
  1362. dataList, err := excel2.GetOtherEdbDataList(edbInfo, req.DateList)
  1363. if err != nil {
  1364. br.Msg = "获取失败"
  1365. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1366. return
  1367. }
  1368. // 默认是倒序返回的数据,如果要正序的话,那么翻转下就好了
  1369. if req.SortType == "asc" {
  1370. for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
  1371. dataList[i], dataList[j] = dataList[j], dataList[i]
  1372. }
  1373. }
  1374. br.Ret = 200
  1375. br.Success = true
  1376. br.Msg = "获取成功"
  1377. br.Data = response.TableDataItem{
  1378. EdbInfoId: req.EdbInfoId,
  1379. Data: dataList,
  1380. }
  1381. }
  1382. // GetFutureDateData
  1383. // @Title 获取未来日期数据接口
  1384. // @Description 获取未来日期数据接口
  1385. // @Param request body request.GetFutureDateDataReq true "type json string"
  1386. // @router /excel_info/table/future_date_list [post]
  1387. func (c *ExcelInfoController) GetFutureDateData() {
  1388. br := new(models.BaseResponse).Init()
  1389. defer func() {
  1390. c.Data["json"] = br
  1391. c.ServeJSON()
  1392. }()
  1393. sysUser := c.SysUser
  1394. if sysUser == nil {
  1395. br.Msg = "请登录"
  1396. br.ErrMsg = "请登录,SysUser Is Empty"
  1397. br.Ret = 408
  1398. return
  1399. }
  1400. var req request.GetFutureDateDataReq
  1401. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1402. if err != nil {
  1403. br.Msg = "参数解析异常!"
  1404. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1405. return
  1406. }
  1407. if req.StartDate == `` {
  1408. br.Msg = "开始日期未传"
  1409. br.IsSendEmail = false
  1410. return
  1411. }
  1412. startDate, err := time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
  1413. if err != nil {
  1414. br.Msg = "开始日期异常"
  1415. br.ErrMsg = fmt.Sprint("开始日期异常,startDate:", req.StartDate, ";err:", err.Error())
  1416. return
  1417. }
  1418. if len(req.EdbInfoIdList) <= 0 {
  1419. br.Msg = "请选择指标"
  1420. br.IsSendEmail = false
  1421. return
  1422. }
  1423. baseEdbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoIdList[0])
  1424. if err != nil {
  1425. br.Msg = "查找指标失败"
  1426. br.Msg = "查找指标失败,err:" + err.Error()
  1427. return
  1428. }
  1429. // 第一个指标的数据列表
  1430. var firstEdbDataList []*data_manage.EdbDataList
  1431. {
  1432. switch baseEdbInfo.EdbInfoType {
  1433. case 0:
  1434. firstEdbDataList, err = data_manage.GetEdbDataList(baseEdbInfo.Source, baseEdbInfo.SubSource, baseEdbInfo.EdbInfoId, req.StartDate, ``)
  1435. case 1:
  1436. _, firstEdbDataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(baseEdbInfo.EdbInfoId, req.StartDate, ``, false)
  1437. default:
  1438. br.Msg = "指标类型异常"
  1439. br.ErrMsg = fmt.Sprint("获取失败,指标类型异常", baseEdbInfo.EdbInfoType)
  1440. br.IsSendEmail = false
  1441. return
  1442. }
  1443. }
  1444. dateList := make([]time.Time, 0)
  1445. if req.DateType == 1 {
  1446. num := req.Num
  1447. i := 0 // 数据中有的日期数
  1448. for _, v := range firstEdbDataList {
  1449. tmpDate, err := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
  1450. if err != nil {
  1451. br.Msg = "结束日期异常"
  1452. br.ErrMsg = fmt.Sprint("结束日期异常,startDate:", req.EndDate, ";err:", err.Error())
  1453. return
  1454. }
  1455. if tmpDate.After(startDate) {
  1456. dateList = append(dateList, tmpDate)
  1457. startDate = tmpDate
  1458. i++
  1459. }
  1460. if i >= num {
  1461. break
  1462. }
  1463. }
  1464. num = num - i
  1465. if num > 0 {
  1466. tmpDateList := utils.GetPredictEdbDayListByNum(startDate, num, baseEdbInfo.Frequency)
  1467. dateList = append(dateList, tmpDateList...)
  1468. }
  1469. } else {
  1470. if req.EndDate == `` {
  1471. br.Msg = "结束日期未传"
  1472. br.IsSendEmail = false
  1473. return
  1474. }
  1475. endDate, err := time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
  1476. if err != nil {
  1477. br.Msg = "结束日期异常"
  1478. br.ErrMsg = fmt.Sprint("结束日期异常,startDate:", req.EndDate, ";err:", err.Error())
  1479. return
  1480. }
  1481. for _, v := range firstEdbDataList {
  1482. tmpDate, err := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
  1483. if err != nil {
  1484. br.Msg = "结束日期异常"
  1485. br.ErrMsg = fmt.Sprint("结束日期异常,startDate:", req.EndDate, ";err:", err.Error())
  1486. return
  1487. }
  1488. if tmpDate.Equal(endDate) || (tmpDate.Before(endDate) && tmpDate.After(startDate)) {
  1489. dateList = append(dateList, tmpDate)
  1490. startDate = tmpDate
  1491. }
  1492. }
  1493. if startDate.Before(endDate) {
  1494. tmpDateList := utils.GetPredictEdbDayListByEndDate(startDate, endDate, baseEdbInfo.Frequency)
  1495. dateList = append(dateList, tmpDateList...)
  1496. }
  1497. }
  1498. // 获取所有的指标信息
  1499. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  1500. {
  1501. edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList)
  1502. if err != nil {
  1503. br.Msg = "获取指标信息失败"
  1504. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  1505. return
  1506. }
  1507. for _, v := range edbInfoList {
  1508. edbInfoMap[v.EdbInfoId] = v
  1509. }
  1510. }
  1511. result := make([]response.TableDataItem, 0)
  1512. dateStrList := make([]string, 0)
  1513. lenDate := len(dateList)
  1514. if lenDate > 0 {
  1515. for i := lenDate - 1; i >= 0; i-- {
  1516. dateStrList = append(dateStrList, dateList[i].Format(utils.FormatDate))
  1517. }
  1518. for _, v := range req.EdbInfoIdList {
  1519. tmpEdbInfo, ok := edbInfoMap[v]
  1520. if !ok {
  1521. br.Msg = "获取指标信息失败"
  1522. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  1523. return
  1524. }
  1525. dataList, err := excel2.GetOtherEdbDataList(tmpEdbInfo, dateStrList)
  1526. if err != nil {
  1527. br.Msg = "获取失败"
  1528. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1529. return
  1530. }
  1531. result = append(result, response.TableDataItem{
  1532. EdbInfoId: v,
  1533. Data: dataList,
  1534. })
  1535. }
  1536. }
  1537. br.Ret = 200
  1538. br.Success = true
  1539. br.Msg = "获取成功"
  1540. br.Data = result
  1541. }
  1542. // GetHistoryDateData
  1543. // @Title 获取历史日期数据接口
  1544. // @Description 获取历史日期数据接口
  1545. // @Param request body request.GetFutureDateDataReq true "type json string"
  1546. // @router /excel_info/table/history_date_list [post]
  1547. func (c *ExcelInfoController) GetHistoryDateData() {
  1548. br := new(models.BaseResponse).Init()
  1549. defer func() {
  1550. c.Data["json"] = br
  1551. c.ServeJSON()
  1552. }()
  1553. sysUser := c.SysUser
  1554. if sysUser == nil {
  1555. br.Msg = "请登录"
  1556. br.ErrMsg = "请登录,SysUser Is Empty"
  1557. br.Ret = 408
  1558. return
  1559. }
  1560. var req request.GetHistoryDateDataReq
  1561. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1562. if err != nil {
  1563. br.Msg = "参数解析异常!"
  1564. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1565. return
  1566. }
  1567. if req.EndDate == `` {
  1568. br.Msg = "结束日期未传"
  1569. br.IsSendEmail = false
  1570. return
  1571. }
  1572. if len(req.EdbInfoIdList) <= 0 {
  1573. br.Msg = "请选择指标"
  1574. br.IsSendEmail = false
  1575. return
  1576. }
  1577. // 获取所有的指标信息
  1578. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  1579. {
  1580. edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList)
  1581. if err != nil {
  1582. br.Msg = "获取指标信息失败"
  1583. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  1584. return
  1585. }
  1586. for _, v := range edbInfoList {
  1587. edbInfoMap[v.EdbInfoId] = v
  1588. }
  1589. }
  1590. result := make([]response.TableDataItem, 0)
  1591. dateStrList := make([]string, 0)
  1592. // 获取A列指标的历史数据
  1593. {
  1594. tmpEdbInfo, ok := edbInfoMap[req.EdbInfoIdList[0]]
  1595. if !ok {
  1596. br.Msg = "获取指标信息失败"
  1597. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  1598. return
  1599. }
  1600. firstDataList, err := excel2.GetFirstHistoryEdbDataList(tmpEdbInfo, req.Num, req.EndDate)
  1601. if err != nil {
  1602. br.Msg = "获取失败"
  1603. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1604. return
  1605. }
  1606. result = append(result, response.TableDataItem{
  1607. EdbInfoId: req.EdbInfoIdList[0],
  1608. Data: firstDataList,
  1609. })
  1610. for _, v := range firstDataList {
  1611. dateStrList = append(dateStrList, v.DataTime)
  1612. }
  1613. }
  1614. if len(dateStrList) > 0 {
  1615. for k, v := range req.EdbInfoIdList {
  1616. if k == 0 {
  1617. continue
  1618. }
  1619. tmpEdbInfo, ok := edbInfoMap[v]
  1620. if !ok {
  1621. br.Msg = "获取指标信息失败"
  1622. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  1623. return
  1624. }
  1625. dataList, err := excel2.GetOtherEdbDataList(tmpEdbInfo, dateStrList)
  1626. if err != nil {
  1627. br.Msg = "获取失败"
  1628. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1629. return
  1630. }
  1631. result = append(result, response.TableDataItem{
  1632. EdbInfoId: v,
  1633. Data: dataList,
  1634. })
  1635. }
  1636. }
  1637. br.Ret = 200
  1638. br.Success = true
  1639. br.Msg = "获取成功"
  1640. br.Data = result
  1641. }
  1642. // Refresh
  1643. // @Title 刷新
  1644. // @Description 刷新接口
  1645. // @Param ExcelInfoId query int true "表格id"
  1646. // @router /excel_info/table/refresh [get]
  1647. func (c *ExcelInfoController) Refresh() {
  1648. br := new(models.BaseResponse).Init()
  1649. defer func() {
  1650. if br.ErrMsg == "" {
  1651. br.IsSendEmail = false
  1652. }
  1653. c.Data["json"] = br
  1654. c.ServeJSON()
  1655. }()
  1656. sysUser := c.SysUser
  1657. if sysUser == nil {
  1658. br.Msg = "请登录"
  1659. br.ErrMsg = "请登录,SysUser Is Empty"
  1660. br.Ret = 408
  1661. return
  1662. }
  1663. excelInfoId, _ := c.GetInt("ExcelInfoId")
  1664. if excelInfoId <= 0 {
  1665. br.Msg = "请选择表格"
  1666. br.ErrMsg = "ExcelInfoId未传"
  1667. br.IsSendEmail = false
  1668. return
  1669. }
  1670. // 获取数据详情
  1671. excelDetail, errMsg, err := excel2.GetExcelDetailInfoByExcelInfoId(excelInfoId)
  1672. if err != nil {
  1673. br.Msg = errMsg
  1674. br.ErrMsg = err.Error()
  1675. return
  1676. }
  1677. // 操作权限校验
  1678. {
  1679. button := excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source)
  1680. if !button.RefreshButton {
  1681. br.Msg = "无操作权限"
  1682. br.Msg = "无操作权限"
  1683. br.IsSendEmail = false
  1684. return
  1685. }
  1686. }
  1687. // 数据刷新(只有自定义表格有刷新)
  1688. if excelDetail.Source == utils.TIME_TABLE {
  1689. jsonStrByte, err := json.Marshal(excelDetail.TableData)
  1690. if err != nil {
  1691. br.Msg = "自定义表格数据获取失败"
  1692. br.ErrMsg = "自定义表格数据获取失败,转json失败,Err:" + err.Error()
  1693. return
  1694. }
  1695. var tableData request.TableDataReq
  1696. err = json.Unmarshal(jsonStrByte, &tableData)
  1697. if err != nil {
  1698. br.Msg = "自定义表格数据获取失败"
  1699. br.ErrMsg = "自定义表格数据获取失败,json转结构体失败,Err:" + err.Error()
  1700. return
  1701. }
  1702. if len(tableData.EdbInfoIdList) > 0 {
  1703. err, _ = data.EdbInfoRefreshAllFromBaseV3(tableData.EdbInfoIdList, false, true, false)
  1704. if err != nil {
  1705. br.Msg = "刷新失败"
  1706. br.ErrMsg = "刷新失败,Err:" + err.Error()
  1707. return
  1708. }
  1709. }
  1710. }
  1711. // 数据刷新-混合表格
  1712. if excelDetail.Source == utils.MIXED_TABLE {
  1713. jsonByte, e := json.Marshal(excelDetail.TableData)
  1714. if e != nil {
  1715. br.Msg = "刷新失败"
  1716. br.ErrMsg = "JSON格式化混合表格数据失败, Err: " + e.Error()
  1717. return
  1718. }
  1719. var tableData request.MixedTableReq
  1720. if e = json.Unmarshal(jsonByte, &tableData); e != nil {
  1721. br.Msg = "刷新失败"
  1722. br.ErrMsg = "解析混合表格数据失败, Err: " + e.Error()
  1723. return
  1724. }
  1725. edbInfoIds := make([]int, 0)
  1726. edbInfoIdExist := make(map[int]bool)
  1727. if len(tableData.Data) > 0 {
  1728. for _, t := range tableData.Data {
  1729. for _, v := range t {
  1730. if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
  1731. edbInfoIdExist[v.EdbInfoId] = true
  1732. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  1733. }
  1734. }
  1735. }
  1736. }
  1737. if len(edbInfoIds) > 0 {
  1738. e, _ = data.EdbInfoRefreshAllFromBaseV3(edbInfoIds, false, true, false)
  1739. if e != nil {
  1740. br.Msg = "刷新失败"
  1741. br.ErrMsg = "刷新混合表格数据失败, Err: " + err.Error()
  1742. return
  1743. }
  1744. }
  1745. }
  1746. // 清除缓存
  1747. key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelDetail.UniqueCode
  1748. if utils.Re == nil {
  1749. _ = utils.Rc.Delete(key)
  1750. }
  1751. br.Ret = 200
  1752. br.Success = true
  1753. br.Msg = "刷新成功"
  1754. }
  1755. // Download
  1756. // @Title 获取表格详情
  1757. // @Description 获取表格详情接口
  1758. // @Param UniqueCode query string true "表格code"
  1759. // @Param ExcelInfoId query int true "表格id"
  1760. // @Success 200 {object} data_manage.ExcelInfo
  1761. // @router /excel_info/table/download [get]
  1762. func (c *ExcelInfoController) Download() {
  1763. br := new(models.BaseResponse).Init()
  1764. defer func() {
  1765. c.Data["json"] = br
  1766. c.ServeJSON()
  1767. }()
  1768. sysUser := c.SysUser
  1769. if sysUser == nil {
  1770. br.Msg = "请登录"
  1771. br.ErrMsg = "请登录,SysUser Is Empty"
  1772. br.Ret = 408
  1773. return
  1774. }
  1775. excelInfoId, _ := c.GetInt("ExcelInfoId")
  1776. uniqueCode := c.GetString("UniqueCode")
  1777. if excelInfoId <= 0 && uniqueCode == `` {
  1778. br.Msg = "请选择表格"
  1779. br.ErrMsg = "ExcelInfoId和UniqueCode都未传"
  1780. br.IsSendEmail = false
  1781. return
  1782. }
  1783. var excelInfo *excel3.ExcelInfo
  1784. var err error
  1785. //获取eta表格信息
  1786. if excelInfoId > 0 {
  1787. excelInfo, err = excel3.GetExcelInfoById(excelInfoId)
  1788. } else {
  1789. excelInfo, err = excel3.GetExcelInfoByUniqueCode(uniqueCode)
  1790. }
  1791. if err != nil {
  1792. br.Msg = "获取失败"
  1793. br.ErrMsg = "获取ETA表格信息失败,Err:" + err.Error()
  1794. if err.Error() == utils.ErrNoRow() {
  1795. br.Msg = "ETA表格被删除,请刷新页面"
  1796. br.ErrMsg = "ETA表格被删除,请刷新页面,Err:" + err.Error()
  1797. br.IsSendEmail = false
  1798. }
  1799. return
  1800. }
  1801. if excelInfo.Source == 1 {
  1802. br.Msg = "不是自定义表格"
  1803. br.IsSendEmail = false
  1804. return
  1805. }
  1806. var tableData excel.TableData
  1807. switch excelInfo.Source {
  1808. case utils.EXCEL_DEFAULT:
  1809. br.Msg = "表格类型异常"
  1810. case utils.TIME_TABLE: // 自定义表格
  1811. var tableDataConfig excel2.TableDataConfig
  1812. err = json.Unmarshal([]byte(excelInfo.Content), &tableDataConfig)
  1813. if err != nil {
  1814. br.Msg = "获取失败"
  1815. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  1816. return
  1817. }
  1818. result, err := excel2.GetDataByTableDataConfig(tableDataConfig)
  1819. if err != nil {
  1820. br.Msg = "获取失败"
  1821. br.ErrMsg = "获取最新的表格数据失败,Err:" + err.Error()
  1822. return
  1823. }
  1824. tableData, err = excel.GetTableDataByCustomData(excelInfo.ExcelType, result)
  1825. if err != nil {
  1826. br.Msg = "获取失败"
  1827. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1828. return
  1829. }
  1830. case utils.MIXED_TABLE: // 混合表格
  1831. var result request.MixedTableReq
  1832. err = json.Unmarshal([]byte(excelInfo.Content), &result)
  1833. if err != nil {
  1834. br.Msg = "获取失败"
  1835. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  1836. return
  1837. }
  1838. newResult, err, errMsg := excel2.GetMixedTableCellData(result)
  1839. if err != nil {
  1840. br.Msg = "获取失败"
  1841. if errMsg != `` {
  1842. br.Msg = errMsg
  1843. }
  1844. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  1845. return
  1846. }
  1847. tableData, err = excel.GetTableDataByMixedTableData(newResult)
  1848. if err != nil {
  1849. br.Msg = "获取失败"
  1850. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1851. return
  1852. }
  1853. }
  1854. downloadFilePath, err := tableData.ToExcel()
  1855. if err != nil {
  1856. fmt.Println("err:", err)
  1857. return
  1858. }
  1859. defer func() {
  1860. _ = os.Remove(downloadFilePath)
  1861. }()
  1862. downloadFileName := excelInfo.ExcelName + ".xlsx"
  1863. c.Ctx.Output.Download(downloadFilePath, downloadFileName)
  1864. br.Ret = 200
  1865. br.Success = true
  1866. br.Msg = "获取成功"
  1867. br.Data = excelInfo
  1868. }
  1869. // Copy
  1870. // @Title 复制表格
  1871. // @Description 复制表格接口
  1872. // @Param request body request.EditExcelInfoReq true "type json string"
  1873. // @Success 200 {object} response.AddExcelInfoResp
  1874. // @router /excel_info/copy [post]
  1875. func (c *ExcelInfoController) Copy() {
  1876. br := new(models.BaseResponse).Init()
  1877. defer func() {
  1878. c.Data["json"] = br
  1879. c.ServeJSON()
  1880. }()
  1881. sysUser := c.SysUser
  1882. if sysUser == nil {
  1883. br.Msg = "请登录"
  1884. br.ErrMsg = "请登录,SysUser Is Empty"
  1885. br.Ret = 408
  1886. return
  1887. }
  1888. var req request.CopyExcelInfoReq
  1889. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1890. if err != nil {
  1891. br.Msg = "参数解析异常!"
  1892. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1893. return
  1894. }
  1895. if req.ExcelInfoId <= 0 {
  1896. br.Msg = "请传入ETA表格标识!"
  1897. return
  1898. }
  1899. cacheKey := "CACHE_TABLE_INFO_EDIT_" + strconv.Itoa(req.ExcelInfoId)
  1900. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1901. br.Msg = "系统处理中,请稍后重试!"
  1902. br.ErrMsg = "系统处理中,请稍后重试!"
  1903. return
  1904. }
  1905. defer func() {
  1906. _ = utils.Rc.Delete(cacheKey)
  1907. }()
  1908. req.ExcelName = strings.Trim(req.ExcelName, " ")
  1909. if req.ExcelName == "" {
  1910. br.Msg = "请填写表格名称!"
  1911. br.IsSendEmail = false
  1912. return
  1913. }
  1914. if req.ExcelClassifyId <= 0 {
  1915. br.Msg = "分类参数错误!"
  1916. br.IsSendEmail = false
  1917. return
  1918. }
  1919. excelInfo, err, errMsg, isSendEmail := excel2.Copy(req.ExcelInfoId, req.ExcelClassifyId, req.ExcelName, sysUser)
  1920. if err != nil {
  1921. br.Msg = "复制失败"
  1922. if errMsg != `` {
  1923. br.Msg = errMsg
  1924. }
  1925. br.ErrMsg = "复制失败,Err:" + err.Error()
  1926. br.IsSendEmail = isSendEmail
  1927. return
  1928. }
  1929. resp := new(response.AddExcelInfoResp)
  1930. resp.ExcelInfoId = excelInfo.ExcelInfoId
  1931. resp.UniqueCode = excelInfo.UniqueCode
  1932. br.Ret = 200
  1933. br.Success = true
  1934. br.Msg = "保存成功"
  1935. br.Data = resp
  1936. br.IsAddLog = true
  1937. }
  1938. //func init() {
  1939. // //list, err := data.GetFirstEdbDataList(102739, 12)
  1940. // list, err := data.GetFirstEdbDataList(101323, 12)
  1941. // if err != nil {
  1942. // fmt.Println(err)
  1943. // return
  1944. // }
  1945. //
  1946. // fmt.Println("START")
  1947. // dateList := make([]string, 0)
  1948. // for _, v := range list {
  1949. // fmt.Println(v)
  1950. // dateList = append(dateList, v.DataTime)
  1951. // }
  1952. //
  1953. // fmt.Println("End")
  1954. //
  1955. // {
  1956. // list, err := data.GetOtherEdbDataList(102227, dateList)
  1957. // if err != nil {
  1958. // fmt.Println(err)
  1959. // return
  1960. // }
  1961. //
  1962. // for _, v := range list {
  1963. // fmt.Println(v)
  1964. // }
  1965. // }
  1966. //}
  1967. //func init() {
  1968. // str := `{"EdbInfoIdList":[101323,102227],"Sort":1,"Data":[{"EdbInfoId":101323,"Tag":"A","Data":[{"DataType":4,"DataTime":"2023-06-10","DataTimeType":4,"ShowValue":"318.2726","Value":"=A2-B2","RelationEdbInfoList":[{"Tag":"A","Row":"2"},{"Tag":"B","Row":"2"}]},{"DataType":3,"DataTime":"2023-06-09","DataTimeType":2,"ShowValue":"15","Value":"15","RelationEdbInfoList":[]},{"DataType":1,"DataTime":"2023-06-07","DataTimeType":1,"ShowValue":"16.43","Value":"16.43","RelationEdbInfoList":[]},{"DataType":1,"DataTime":"2023-06-05","DataTimeType":1,"ShowValue":"16.85","Value":"16.85","RelationEdbInfoList":[]},{"DataType":1,"DataTime":"2023-06-02","DataTimeType":1,"ShowValue":"15.88","Value":"15.88","RelationEdbInfoList":[]}]},{"EdbInfoId":102227,"Tag":"B","Data":[{"DataType":4,"DataTime":"2023-06-10","DataTimeType":1,"ShowValue":"318.2726","Value":"=A2+B2","RelationEdbInfoList":[{"Tag":"A","Row":"2"},{"Tag":"B","Row":"2"}]},{"DataType":1,"DataTime":"2023-06-09","DataTimeType":1,"ShowValue":"318.2726","Value":"318.2726","RelationEdbInfoList":[]},{"DataType":2,"DataTime":"2023-06-07","DataTimeType":1,"ShowValue":"100.43","Value":"100.43","RelationEdbInfoList":[]},{"DataType":2,"DataTime":"2023-06-05","DataTimeType":1,"ShowValue":"102.85","Value":"102.85","RelationEdbInfoList":[]},{"DataType":1,"DataTime":"2023-06-02","DataTimeType":1,"ShowValue":"311.5201","Value":"311.5201","RelationEdbInfoList":[]}]}],"TextRowData":[[{"DataType":3,"DataTime":"","ShowValue":"总计","Value":"总计"},{"DataType":4,"DataTime":"","ShowValue":"0","Value":"=A3+B3","RelationEdbInfoList":[{"Tag":"A","Row":"3"},{"Tag":"B","Row":"3"}]},{"DataType":3,"DataTime":"","ShowValue":"","Value":"","RelationEdbInfoList":[]}],[{"DataType":3,"DataTime":"","ShowValue":"垃圾汇总","Value":"垃圾汇总"},{"DataType":4,"DataTime":"","ShowValue":"0","Value":"=A4+B4","RelationEdbInfoList":[{"Tag":"A","Row":"4"},{"Tag":"B","Row":"4"}]},{"DataType":3,"DataTime":"","ShowValue":"这里是文本文案","Value":"这里是文本文案","RelationEdbInfoList":[]}]]}`
  1969. // str = `{"EdbInfoIdList":[102942,102938,102937],"Sort":1,"Data":[],"Num":12,"RemoveDate":["2023-06-05","2023-06-08"],"ManualDate":null,"TableEdbInfoList":[{"EdbInfoId":102942,"Tag":"A","EdbName":"","EdbAliasName":"","Frequency":"","Unit":""},{"EdbInfoId":102938,"Tag":"B","EdbName":"","EdbAliasName":"","Frequency":"","Unit":""},{"EdbInfoId":102937,"Tag":"C","EdbName":"","EdbAliasName":"","Frequency":"","Unit":""}],"TextRowData":[[{"DataType":3,"DataTime":"","DataTimeType":0,"ShowValue":"dwd","Value":"dwd","RelationEdbInfoList":[]},{"DataType":3,"DataTime":"","DataTimeType":0,"ShowValue":"4454","Value":"4454","RelationEdbInfoList":[]},{"DataType":3,"DataTime":"","DataTimeType":0,"ShowValue":"454","Value":"454","RelationEdbInfoList":[]},{"DataType":3,"DataTime":"","DataTimeType":0,"ShowValue":"51","Value":"51","RelationEdbInfoList":[]}],[{"DataType":4,"DataTime":"","DataTimeType":0,"ShowValue":"a1b1","Value":"=a1+b1","RelationEdbInfoList":[{"Tag":"A","Row":"1"},{"Tag":"B","Row":"1"}]},{"DataType":4,"DataTime":"","DataTimeType":0,"ShowValue":"2247.1444","Value":"=a2+b2","RelationEdbInfoList":[{"Tag":"A","Row":"2"},{"Tag":"B","Row":"2"}]},{"DataType":3,"DataTime":"","DataTimeType":0,"ShowValue":"","Value":"","RelationEdbInfoList":[]},{"DataType":3,"DataTime":"","DataTimeType":0,"ShowValue":"","Value":"","RelationEdbInfoList":[]}]]}`
  1970. //
  1971. // //var req request.TableDataReq
  1972. // //err := json.Unmarshal([]byte(str), &req)
  1973. // //if err != nil {
  1974. // // fmt.Println(err)
  1975. // // return
  1976. // //}
  1977. // //tableDataConfig, err := data.GetTableDataConfig(req)
  1978. // //if err != nil {
  1979. // // fmt.Println(err)
  1980. // // return
  1981. // //}
  1982. // var tableDataConfig data.TableDataConfig
  1983. // err := json.Unmarshal([]byte(str), &tableDataConfig)
  1984. // if err != nil {
  1985. // fmt.Println(err)
  1986. // return
  1987. // }
  1988. //
  1989. // fmt.Println(tableDataConfig)
  1990. //
  1991. // result, err := data.GetDataByTableDataConfig(tableDataConfig)
  1992. // if err != nil {
  1993. // fmt.Println(err)
  1994. // return
  1995. // }
  1996. // fmt.Println(result)
  1997. // //byteStr, _ := json.Marshal(result)
  1998. // //utils.FileLog.Info(string(byteStr))
  1999. //}
  2000. //func init() {
  2001. // startNow := time.Now()
  2002. // fmt.Println(startNow.Format(utils.FormatDateTime))
  2003. // startTime := startNow.Unix()
  2004. // //filePath := `static/tmpFile/test/化工23.05.24.xlsx`
  2005. // filePath := `static/tmpFile/1. TAROUND_202308010201-500.xlsx`
  2006. // //filePath := `static/tmpFile/化工23.05.24.xml`
  2007. // //filePath := `static/tmpFile/化工23.05.24/xl/workbook.xml`
  2008. // //filePath := `static/tmpFile/1. TAROUND_202308010201.xlsx`
  2009. //
  2010. // //filePath := `static/tmpFile/1. TAROUND_202308010201-2.xlsx`
  2011. //
  2012. // //filePath := `static/tmpFile/5. Outage_Values_Daily.xlsx`
  2013. // //filePath := `static/tmpFile/1. TAROUND_202308010201 - 副本.xlsx`
  2014. // excel.ConvToLuckySheet(filePath)
  2015. // cz := time.Now().Unix() - startTime
  2016. // fmt.Printf("处理完需要的时间:%d秒;约耗时:%d分%d秒", cz, cz/60, cz%60)
  2017. // fmt.Println()
  2018. //
  2019. // //sheetName := `日度`
  2020. // //sheetName := `月度`
  2021. // //fmt.Println(excel.GetDefaultSheetIndex(filePath, sheetName))
  2022. //
  2023. // //decompressZip(filePath)
  2024. //}
  2025. // src: 需要解压的zip文件
  2026. func decompressZip(src string) error {
  2027. archive, err := zip.OpenReader(src)
  2028. if err != nil {
  2029. return err
  2030. }
  2031. dir := filepath.Dir(src) + "/zip"
  2032. defer archive.Close()
  2033. for _, f := range archive.File {
  2034. filePath := filepath.Join(dir, f.Name)
  2035. if f.FileInfo().IsDir() {
  2036. os.MkdirAll(filePath, os.ModePerm)
  2037. continue
  2038. }
  2039. if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
  2040. return fmt.Errorf("failed to make directory (%v)", err)
  2041. }
  2042. dstFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
  2043. if err != nil {
  2044. return fmt.Errorf("failed to create file (%v)", err)
  2045. }
  2046. fileInArchive, err := f.Open()
  2047. if err != nil {
  2048. return fmt.Errorf("failed to open file in zip (%v)", err)
  2049. }
  2050. if _, err := io.Copy(dstFile, fileInArchive); err != nil {
  2051. return fmt.Errorf("failed to copy file in zip (%v)", err)
  2052. }
  2053. dstFile.Close()
  2054. fileInArchive.Close()
  2055. }
  2056. return nil
  2057. }
  2058. // MarkEditStatus
  2059. // @Title 标记沙盘编辑状态
  2060. // @Description 标记沙盘编辑状态接口
  2061. // @Param request body request.MarkEditSandbox true "type json string"
  2062. // @Success 200 标记成功 ;202 标记成功
  2063. // @router /excel_info/mark [post]
  2064. func (this *ExcelInfoController) MarkEditStatus() {
  2065. br := new(models.BaseResponse).Init()
  2066. defer func() {
  2067. this.Data["json"] = br
  2068. this.ServeJSON()
  2069. }()
  2070. sysUser := this.SysUser
  2071. if sysUser == nil {
  2072. br.Msg = "请登录"
  2073. br.ErrMsg = "请登录,SysUser Is Empty"
  2074. br.Ret = 408
  2075. return
  2076. }
  2077. var req request.MarkEditExcel
  2078. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2079. if err != nil {
  2080. br.Msg = "参数解析异常!"
  2081. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2082. return
  2083. }
  2084. if req.ExcelInfoId <= 0 {
  2085. br.Msg = "缺少表格编号"
  2086. return
  2087. }
  2088. if req.Status <= 0 {
  2089. br.Msg = "标记状态异常"
  2090. return
  2091. }
  2092. status := 1
  2093. if req.Status == 2 {
  2094. status = 0
  2095. }
  2096. //更新标记key
  2097. data, err := services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, status, sysUser.RealName)
  2098. if err != nil {
  2099. br.Msg = err.Error()
  2100. return
  2101. }
  2102. msg := "标记成功"
  2103. br.Ret = 200
  2104. br.Success = true
  2105. br.Msg = msg
  2106. br.Data = data
  2107. }
  2108. // BatchRefresh
  2109. // @Title 批量刷新表格接口
  2110. // @Description 批量刷新图表接口
  2111. // @Param request body excel3.BatchRefreshExcelReq true "type json string"
  2112. // @Success Ret=200 刷新成功
  2113. // @router /excel_info/table/batch_refresh [post]
  2114. func (this *ExcelInfoController) BatchRefresh() {
  2115. br := new(models.BaseResponse).Init()
  2116. defer func() {
  2117. if br.ErrMsg == "" {
  2118. br.IsSendEmail = false
  2119. }
  2120. this.Data["json"] = br
  2121. this.ServeJSON()
  2122. }()
  2123. sysUser := this.SysUser
  2124. if sysUser == nil {
  2125. br.Msg = "请登录"
  2126. br.ErrMsg = "请登录,SysUser Is Empty"
  2127. br.Ret = 408
  2128. return
  2129. }
  2130. var req excel3.BatchRefreshExcelReq
  2131. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2132. if err != nil {
  2133. br.Msg = "参数解析异常!"
  2134. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2135. return
  2136. }
  2137. if len(req.ExcelCodes) == 0 {
  2138. br.Ret = 200
  2139. br.Success = true
  2140. br.Msg = "刷新成功"
  2141. return
  2142. }
  2143. // 获取表格关联的指标IDs
  2144. edbIds, e := excel2.GetEdbIdsFromExcelCodes(req.ExcelCodes)
  2145. if e != nil {
  2146. br.Msg = "刷新失败"
  2147. br.ErrMsg = "获取表格关联的指标IDs失败, Err: " + e.Error()
  2148. return
  2149. }
  2150. redisKey := data.GetBatchChartRefreshKey(req.Source, req.ReportId, req.ReportChapterId)
  2151. refreshKeys := make([]string, 0)
  2152. for _, v := range req.ExcelCodes {
  2153. refreshKeys = append(refreshKeys, fmt.Sprint(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL, v))
  2154. }
  2155. // 刷新相关指标
  2156. syncing, e := data.BatchRefreshEdbByEdbIds(edbIds, redisKey, refreshKeys)
  2157. if e != nil {
  2158. br.Msg = "刷新失败"
  2159. br.ErrMsg = "刷新表格关联指标信息失败,Err:" + err.Error()
  2160. return
  2161. }
  2162. br.Msg = "刷新成功"
  2163. if syncing {
  2164. br.Msg = "表格关联指标较多,请10分钟后刷新页面查看最新数据"
  2165. }
  2166. br.Ret = 200
  2167. br.Success = true
  2168. }
  2169. // GetBatchChartRefreshResult
  2170. // @Title 获取批量刷新表格结果
  2171. // @Description 获取批量刷新表格结果
  2172. // @Param request body excel3.BatchRefreshExcelReq true "type json string"
  2173. // @Success Ret=200 刷新成功
  2174. // @router /excel_info/table/batch_refresh/result [post]
  2175. func (this *ExcelInfoController) GetBatchChartRefreshResult() {
  2176. br := new(models.BaseResponse).Init()
  2177. defer func() {
  2178. this.Data["json"] = br
  2179. this.ServeJSON()
  2180. }()
  2181. sysUser := this.SysUser
  2182. if sysUser == nil {
  2183. br.Msg = "请登录"
  2184. br.ErrMsg = "请登录,SysUser Is Empty"
  2185. br.Ret = 408
  2186. return
  2187. }
  2188. var req excel3.BatchRefreshExcelReq
  2189. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2190. if err != nil {
  2191. br.Msg = "参数解析异常!"
  2192. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2193. return
  2194. }
  2195. // 校验缓存是否存在, 存在说明还在刷新中
  2196. result := true
  2197. redisKey := excel2.GetExcelEdbBatchRefreshKey(req.Source, req.ReportId, req.ReportChapterId)
  2198. if redisKey != `` {
  2199. // 如果找到了key,那么就是还在更新中
  2200. ok := utils.Rc.IsExist(redisKey)
  2201. if ok {
  2202. result = false
  2203. }
  2204. }
  2205. resp := struct {
  2206. RefreshResult bool `description:"刷新结果"`
  2207. }{
  2208. RefreshResult: result,
  2209. }
  2210. br.Data = resp
  2211. br.Ret = 200
  2212. br.Success = true
  2213. }