excel_info.go 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352
  1. package excel
  2. import (
  3. "archive/zip"
  4. "encoding/json"
  5. "eta_gn/eta_api/controllers"
  6. "eta_gn/eta_api/models"
  7. "eta_gn/eta_api/models/data_manage"
  8. excel3 "eta_gn/eta_api/models/data_manage/excel"
  9. "eta_gn/eta_api/models/data_manage/excel/request"
  10. "eta_gn/eta_api/models/data_manage/excel/response"
  11. "eta_gn/eta_api/services"
  12. "eta_gn/eta_api/services/data"
  13. "eta_gn/eta_api/services/data/data_manage_permission"
  14. excel2 "eta_gn/eta_api/services/data/excel"
  15. "eta_gn/eta_api/services/excel"
  16. "eta_gn/eta_api/utils"
  17. "fmt"
  18. "io"
  19. "os"
  20. "path/filepath"
  21. "strconv"
  22. "strings"
  23. "time"
  24. "github.com/rdlucklib/rdluck_tools/paging"
  25. "github.com/shopspring/decimal"
  26. "github.com/yidane/formula"
  27. )
  28. // ExcelInfoController ETA表格管理
  29. type ExcelInfoController struct {
  30. controllers.BaseAuthController
  31. }
  32. // Add
  33. // @Title 新增表格接口
  34. // @Description 新增表格接口
  35. // @Param request body request.AddExcelInfoReq true "type json string"
  36. // @Success 200 {object} response.AddExcelInfoResp
  37. // @router /excel_info/add [post]
  38. func (c *ExcelInfoController) Add() {
  39. br := new(models.BaseResponse).Init()
  40. defer func() {
  41. c.Data["json"] = br
  42. c.ServeJSON()
  43. }()
  44. sysUser := c.SysUser
  45. if sysUser == nil {
  46. br.Msg = "请登录"
  47. br.ErrMsg = "请登录,SysUser Is Empty"
  48. br.Ret = 408
  49. return
  50. }
  51. deleteCache := true
  52. cacheKey := "CACHE_EXCEL_TABLE_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  53. defer func() {
  54. if deleteCache {
  55. _ = utils.Rc.Delete(cacheKey)
  56. }
  57. }()
  58. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  59. deleteCache = false
  60. br.Msg = "系统处理中,请稍后重试!"
  61. br.ErrMsg = "系统处理中,请稍后重试!"
  62. return
  63. }
  64. var req request.AddExcelInfoReq
  65. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  66. if err != nil {
  67. br.Msg = "参数解析异常!"
  68. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  69. return
  70. }
  71. req.ExcelName = strings.Trim(req.ExcelName, " ")
  72. if req.ExcelName == "" {
  73. br.Msg = "请填写表格名称!"
  74. br.IsSendEmail = false
  75. return
  76. }
  77. if req.ExcelClassifyId <= 0 && req.ParentId == 0 {
  78. br.Msg = "分类参数错误!"
  79. br.IsSendEmail = false
  80. return
  81. }
  82. if req.ExcelClassifyId > 0 {
  83. excelClassify, e := excel3.GetExcelClassifyById(req.ExcelClassifyId)
  84. if e != nil {
  85. if utils.IsErrNoRow(e) {
  86. br.Msg = "分类不存在"
  87. br.ErrMsg = "分类不存在"
  88. br.IsSendEmail = false
  89. return
  90. }
  91. br.Msg = "获取分类信息失败"
  92. br.ErrMsg = "获取分类信息失败,Err:" + e.Error()
  93. return
  94. }
  95. if excelClassify == nil {
  96. br.Msg = "分类不存在"
  97. br.ErrMsg = "分类不存在"
  98. br.IsSendEmail = false
  99. return
  100. }
  101. }
  102. if req.ParentId > 0 {
  103. parentExcelInfo, e := excel3.GetExcelInfoById(req.ParentId)
  104. if e != nil {
  105. if utils.IsErrNoRow(e) {
  106. br.Msg = "父级ETA表格被删除,请刷新页面"
  107. return
  108. }
  109. br.Msg = "获取父级ETA表格信息失败"
  110. br.ErrMsg = "获取父级ETA表格信息失败,Err:" + e.Error()
  111. return
  112. }
  113. req.ExcelClassifyId = parentExcelInfo.ExcelClassifyId
  114. }
  115. var condition string
  116. var pars []interface{}
  117. condition += " AND excel_classify_id=? AND parent_id=?"
  118. pars = append(pars, req.ExcelClassifyId, req.ParentId)
  119. condition += " AND excel_name=? "
  120. pars = append(pars, req.ExcelName)
  121. // 自定义分析私有化了
  122. if req.Source == utils.CUSTOM_ANALYSIS_TABLE {
  123. condition += ` AND sys_user_id = ? `
  124. pars = append(pars, sysUser.AdminId)
  125. }
  126. // 获取分类下是否存在该表格名称
  127. count, err := excel3.GetExcelInfoCountByCondition(condition, pars)
  128. if err != nil {
  129. br.Msg = "判断表格名称是否存在失败"
  130. br.ErrMsg = "判断表格名称是否存在失败,Err:" + err.Error()
  131. return
  132. }
  133. if count > 0 {
  134. br.Msg = "表格名称已存在,请重新填写表格名称"
  135. br.IsSendEmail = false
  136. return
  137. }
  138. // 默认的excel类型是1
  139. if req.Source == 0 {
  140. req.Source = 1
  141. }
  142. content := req.Content
  143. // 引用的指标id
  144. edbInfoIdList := make([]int, 0)
  145. // 自定义表格
  146. if req.Source == utils.TIME_TABLE {
  147. jsonStrByte, err := json.Marshal(req.TableData)
  148. if err != nil {
  149. br.Msg = "时间序列表格数据获取失败"
  150. br.ErrMsg = "时间序列表格数据获取失败,Err:" + err.Error()
  151. return
  152. }
  153. var tableData request.TableDataReq
  154. err = json.Unmarshal(jsonStrByte, &tableData)
  155. if err != nil {
  156. br.Msg = "时间序列表格数据获取失败"
  157. br.ErrMsg = "时间序列表格数据获取失败,Err:" + err.Error()
  158. return
  159. }
  160. tableDataConfig, err := excel2.GetTableDataConfig(tableData)
  161. if err != nil {
  162. br.Msg = "时间序列表格数据获取失败"
  163. br.ErrMsg = "时间序列表格数据获取失败,Err:" + err.Error()
  164. return
  165. }
  166. edbInfoIdList = tableDataConfig.EdbInfoIdList
  167. tableDataConfig.DecimalConfig = tableData.DecimalConfig
  168. contentByte, err := json.Marshal(tableDataConfig)
  169. if err != nil {
  170. br.Msg = "时间序列表格数据获取失败"
  171. br.ErrMsg = "时间序列表格数据获取失败,Err:" + err.Error()
  172. return
  173. }
  174. content = string(contentByte)
  175. }
  176. // 混合表格
  177. if req.Source == 3 || req.Source == 5 {
  178. contentByte, err := json.Marshal(req.TableData)
  179. if err != nil {
  180. br.Msg = "自定义表格数据获取失败"
  181. br.ErrMsg = "自定义表格数据获取后,转json失败,Err:" + err.Error()
  182. return
  183. }
  184. content = string(contentByte)
  185. var result request.MixedTableReq
  186. err = json.Unmarshal(contentByte, &result)
  187. if err != nil {
  188. br.Msg = "获取失败"
  189. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  190. return
  191. }
  192. newResult, err, errMsg := excel2.GetMixedTableCellData(result, c.Lang)
  193. if err != nil {
  194. br.Msg = "获取失败"
  195. if errMsg != `` {
  196. br.Msg = errMsg
  197. }
  198. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  199. return
  200. }
  201. edbInfoIdMap := make(map[int]int)
  202. for _, tmpV := range newResult {
  203. for _, v := range tmpV {
  204. if v.EdbInfoId > 0 {
  205. if _, ok := edbInfoIdMap[v.EdbInfoId]; !ok {
  206. edbInfoIdMap[v.EdbInfoId] = v.EdbInfoId
  207. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  208. }
  209. }
  210. }
  211. }
  212. }
  213. //获取该层级下最大的排序数
  214. maxSort, err := excel2.GetExcelClassifyMaxSort(req.ExcelClassifyId, req.Source)
  215. if err != nil {
  216. br.Msg = "获取失败"
  217. br.ErrMsg = "查询排序信息失败,Err:" + err.Error()
  218. return
  219. }
  220. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  221. excelInfo := &excel3.ExcelInfo{
  222. //ExcelInfoId: 0,
  223. ExcelName: req.ExcelName,
  224. Source: req.Source,
  225. ExcelType: req.ExcelType,
  226. UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + timestamp),
  227. ExcelClassifyId: req.ExcelClassifyId,
  228. SysUserId: sysUser.AdminId,
  229. SysUserRealName: sysUser.RealName,
  230. Content: content,
  231. ExcelImage: req.ExcelImage,
  232. Sort: maxSort + 1,
  233. IsDelete: 0,
  234. ModifyTime: time.Now(),
  235. CreateTime: time.Now(),
  236. ParentId: req.ParentId,
  237. UpdateUserId: sysUser.AdminId,
  238. UpdateUserRealName: sysUser.RealName,
  239. SourcesFrom: req.SourcesFrom,
  240. }
  241. excelEdbMappingList := make([]*excel3.ExcelEdbMapping, 0)
  242. if len(edbInfoIdList) > 0 {
  243. for _, edbInfoId := range edbInfoIdList {
  244. excelEdbMappingList = append(excelEdbMappingList, &excel3.ExcelEdbMapping{
  245. //ExcelEdbMappingId: 0,
  246. //ExcelInfoId: 0,
  247. Source: excelInfo.Source,
  248. EdbInfoId: edbInfoId,
  249. CreateTime: time.Now(),
  250. ModifyTime: time.Now(),
  251. })
  252. }
  253. }
  254. var childExcel *excel3.ExcelInfo
  255. if excelInfo.Source == utils.BALANCE_TABLE && req.ParentId == 0 && excelInfo.BalanceType == 0 { //首次创建平衡表时需要添加一个默认的子表
  256. timestamp = strconv.FormatInt(time.Now().UnixNano(), 10) + "_" + utils.GetRandString(10)
  257. childExcel = &excel3.ExcelInfo{
  258. //ExcelInfoId: 0,
  259. ExcelName: "平衡表",
  260. Source: excelInfo.Source,
  261. ExcelType: excelInfo.ExcelType,
  262. UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + timestamp),
  263. ExcelClassifyId: req.ExcelClassifyId,
  264. SysUserId: sysUser.AdminId,
  265. SysUserRealName: sysUser.RealName,
  266. Content: excelInfo.Content,
  267. //ExcelImage: req.ExcelImage,
  268. Sort: excelInfo.Sort + 1,
  269. IsDelete: 0,
  270. ModifyTime: time.Now(),
  271. CreateTime: time.Now(),
  272. //ParentId: req.ParentId,
  273. UpdateUserId: sysUser.AdminId,
  274. UpdateUserRealName: sysUser.RealName,
  275. }
  276. }
  277. err = excel3.AddExcelInfo(excelInfo, excelEdbMappingList, childExcel)
  278. if err != nil {
  279. br.Msg = "保存失败"
  280. br.ErrMsg = "保存失败,Err:" + err.Error()
  281. return
  282. }
  283. // 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
  284. if req.Source == 1 {
  285. go excel2.UpdateExcelInfoFileUrl(excelInfo)
  286. }
  287. _, err = services.UpdateExcelEditMark(excelInfo.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
  288. if err != nil {
  289. br.Msg = "查询标记状态失败"
  290. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  291. return
  292. }
  293. resp := new(response.AddExcelInfoResp)
  294. resp.ExcelInfoId = excelInfo.ExcelInfoId
  295. resp.UniqueCode = excelInfo.UniqueCode
  296. //新增指标引用记录
  297. _ = data.SaveExcelEdbInfoRelation(excelInfo.ExcelInfoId, excelInfo.Source, false)
  298. //新增操作日志
  299. //{
  300. // excelLog := &data_manage.ExcelInfoLog{
  301. // //ExcelInfoLogId: 0,
  302. // ExcelInfoId: excelInfo.ExcelInfoId,
  303. // ExcelName: req.ExcelName,
  304. // ExcelClassifyId: req.ExcelClassifyId,
  305. // SysUserId: sysUser.AdminId,
  306. // SysUserRealName: sysUser.RealName,
  307. // UniqueCode: excelInfo.UniqueCode,
  308. // CreateTime: time.Now(),
  309. // Content: string(c.Ctx.Input.RequestBody),
  310. // Status: "新增表格",
  311. // Method: c.Ctx.Input.URI(),
  312. // }
  313. // go data_manage.AddExcelInfoLog(excelLog)
  314. //}
  315. br.Ret = 200
  316. br.Success = true
  317. br.Msg = "保存成功"
  318. br.Data = resp
  319. br.IsAddLog = true
  320. }
  321. // List
  322. // @Title ETA表格列表接口
  323. // @Description ETA表格列表接口
  324. // @Param PageSize query int true "每页数据条数"
  325. // @Param CurrentIndex query int true "当前页页码,从1开始"
  326. // @Param ExcelClassifyId query int true "分类id"
  327. // @Param Keyword query string true "搜索关键词"
  328. // @Param AdminId query int false "创建人id"
  329. // @Param Source query int true "格来源,1:excel插件的表格,2:自定义表格,3:混合表格,默认:1"
  330. // @Param IsShowMe query bool true "是否只看我的,true、false"
  331. // @Success 200 {object} response.ExcelListResp
  332. // @router /excel_info/list [get]
  333. func (c *ExcelInfoController) List() {
  334. br := new(models.BaseResponse).Init()
  335. defer func() {
  336. c.Data["json"] = br
  337. c.ServeJSON()
  338. }()
  339. sysUser := c.SysUser
  340. if sysUser == nil {
  341. br.Msg = "请登录"
  342. br.ErrMsg = "请登录,SysUser Is Empty"
  343. br.Ret = 408
  344. return
  345. }
  346. excelClassifyId, _ := c.GetInt("ExcelClassifyId")
  347. pageSize, _ := c.GetInt("PageSize")
  348. currentIndex, _ := c.GetInt("CurrentIndex")
  349. keyword := c.GetString("Keyword")
  350. adminId, _ := c.GetInt("AdminId")
  351. source, _ := c.GetInt("Source")
  352. var total int
  353. page := paging.GetPaging(currentIndex, pageSize, total)
  354. var startSize int
  355. if pageSize <= 0 {
  356. pageSize = utils.PageSize20
  357. }
  358. if currentIndex <= 0 {
  359. currentIndex = 1
  360. }
  361. startSize = paging.StartIndex(currentIndex, pageSize)
  362. var condition string
  363. var pars []interface{}
  364. // 如果没有传的话,那就是代表前三种表格
  365. if source <= 0 {
  366. condition += " AND source in (?,?,?) "
  367. pars = append(pars, utils.EXCEL_DEFAULT, utils.TIME_TABLE, utils.MIXED_TABLE)
  368. } else {
  369. condition += " AND source = ? "
  370. pars = append(pars, source)
  371. if source == utils.BALANCE_TABLE { //平衡表的列表只显示动态表的一级表(不显示子表和静态表)
  372. condition += " AND parent_id = 0 AND balance_type=0 "
  373. }
  374. }
  375. // 筛选分类
  376. if excelClassifyId > 0 {
  377. _, err := excel3.GetExcelClassifyById(excelClassifyId)
  378. if err != nil && !utils.IsErrNoRow(err) {
  379. br.Msg = "获取表格信息失败"
  380. br.ErrMsg = "获取信息失败,GetExcelClassify,Err:" + err.Error()
  381. return
  382. }
  383. childClassify, e, _ := excel2.GetChildClassifyByClassifyId(excelClassifyId, source)
  384. if e != nil && !utils.IsErrNoRow(e) {
  385. br.Msg = "获取失败"
  386. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  387. return
  388. }
  389. if len(childClassify) == 0 {
  390. condition += " AND excel_classify_id = ? "
  391. pars = append(pars, excelClassifyId)
  392. } else {
  393. classifyIds := []int{excelClassifyId}
  394. for _, v := range childClassify {
  395. classifyIds = append(classifyIds, v.ExcelClassifyId)
  396. }
  397. condition += fmt.Sprintf(` AND excel_classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  398. pars = append(pars, classifyIds)
  399. }
  400. }
  401. if keyword != "" {
  402. condition += ` AND ( excel_name LIKE ? )`
  403. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  404. }
  405. if adminId > 0 {
  406. condition += " AND sys_user_id = ? "
  407. pars = append(pars, adminId)
  408. }
  409. //只看我的
  410. isShowMe, _ := c.GetBool("IsShowMe")
  411. // 获取所有有权限的指标和分类
  412. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserExcelAndClassifyPermissionList(c.SysUser.AdminId, 0, 0)
  413. if err != nil {
  414. br.Msg = "获取失败"
  415. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  416. return
  417. }
  418. hasCheck := make(map[int]bool)
  419. if isShowMe {
  420. if source == utils.BALANCE_TABLE { //平衡表的,显示同时需要显示协作人相关的图表
  421. //找到当前协作人相关的表格ID
  422. obj := new(excel3.ExcelWorker)
  423. existList, err := obj.GetBySysUserId(sysUser.AdminId)
  424. if err != nil {
  425. br.Msg = "获取表格协作人失败!"
  426. br.ErrMsg = "获取表格协作人失败,Err:" + err.Error()
  427. return
  428. }
  429. var excelIds []int
  430. newCondition := condition
  431. newPars := pars
  432. if len(existList) > 0 {
  433. for _, v := range existList {
  434. excelIds = append(excelIds, v.ExcelInfoId)
  435. }
  436. newCondition += fmt.Sprintf(` AND ( excel_info_id IN (%s) or sys_user_id = ?)`, utils.GetOrmInReplace(len(excelIds)))
  437. newPars = append(newPars, excelIds, sysUser.AdminId)
  438. } else {
  439. newCondition += ` AND sys_user_id = ? `
  440. newPars = append(newPars, sysUser.AdminId)
  441. }
  442. //获取表格信息
  443. tmpList, e := excel3.GetNoContentExcelListByConditionNoPage(newCondition, newPars)
  444. if e != nil && !utils.IsErrNoRow(e) {
  445. br.Success = true
  446. br.Msg = "获取表格信息失败"
  447. br.ErrMsg = "获取表格信息失败,Err:" + e.Error()
  448. return
  449. }
  450. classifyIdListTmp := make([]int, 0)
  451. for _, v := range tmpList {
  452. classifyIdListTmp = append(classifyIdListTmp, v.ExcelClassifyId)
  453. }
  454. classifyMap := make(map[int]*excel3.ExcelClassify)
  455. // 分类信息
  456. if len(classifyIdListTmp) > 0 {
  457. classifyListTmp, e := excel3.GetClassifyByIdList(classifyIdListTmp)
  458. if e != nil {
  459. br.Msg = "获取表格分类信息失败"
  460. br.ErrMsg = "获取表格分类列表数据失败,Err:" + e.Error()
  461. return
  462. }
  463. for _, v := range classifyListTmp {
  464. classifyMap[v.ExcelClassifyId] = v
  465. }
  466. }
  467. excelIds = make([]int, 0)
  468. for _, v := range tmpList {
  469. // 数据权限
  470. if classifyInfo, ok := classifyMap[v.ExcelClassifyId]; ok {
  471. v.HaveOperaAuth = data_manage_permission.CheckExcelPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.ExcelInfoId, v.ExcelClassifyId, permissionEdbIdList, permissionClassifyIdList)
  472. if v.HaveOperaAuth {
  473. excelIds = append(excelIds, v.ExcelInfoId)
  474. }
  475. hasCheck[v.ExcelInfoId] = v.HaveOperaAuth
  476. }
  477. }
  478. if len(excelIds) > 0 {
  479. condition += fmt.Sprintf(` AND excel_info_id IN (%s)`, utils.GetOrmInReplace(len(excelIds)))
  480. pars = append(pars, excelIds)
  481. } else {
  482. list := make([]*excel3.MyExcelInfoList, 0)
  483. resp := response.ExcelListResp{
  484. Paging: page,
  485. List: list,
  486. }
  487. br.Ret = 200
  488. br.Success = true
  489. br.Msg = "获取成功"
  490. br.Data = resp
  491. return
  492. }
  493. } else {
  494. condition += " AND sys_user_id = ? "
  495. pars = append(pars, sysUser.AdminId)
  496. }
  497. }
  498. //获取表格信息
  499. list, err := excel3.GetNoContentExcelListByCondition(condition, pars, startSize, pageSize)
  500. if err != nil && !utils.IsErrNoRow(err) {
  501. br.Success = true
  502. br.Msg = "获取表格信息失败"
  503. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  504. return
  505. }
  506. lenList := len(list)
  507. if list == nil || lenList <= 0 || (err != nil && utils.IsErrNoRow(err)) {
  508. list = make([]*excel3.MyExcelInfoList, 0)
  509. }
  510. if lenList > 0 {
  511. classifyIdList := make([]int, 0)
  512. for _, v := range list {
  513. classifyIdList = append(classifyIdList, v.ExcelClassifyId)
  514. }
  515. classifyMap := make(map[int]*excel3.ExcelClassify)
  516. // 分类信息
  517. {
  518. classifyList, err := excel3.GetClassifyByIdList(classifyIdList)
  519. if err != nil {
  520. br.Msg = "获取表格列表信息失败"
  521. br.ErrMsg = "获取表格分类列表数据失败,Err:" + err.Error()
  522. return
  523. }
  524. for _, v := range classifyList {
  525. classifyMap[v.ExcelClassifyId] = v
  526. }
  527. }
  528. for k, v := range list {
  529. // 数据权限
  530. if authCheck, ok1 := hasCheck[v.ExcelInfoId]; ok1 {
  531. v.HaveOperaAuth = authCheck
  532. } else {
  533. if classifyInfo, ok := classifyMap[v.ExcelClassifyId]; ok {
  534. v.HaveOperaAuth = data_manage_permission.CheckExcelPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.ExcelInfoId, v.ExcelClassifyId, permissionEdbIdList, permissionClassifyIdList)
  535. }
  536. }
  537. if v.Source == utils.BALANCE_TABLE {
  538. //处理按钮权限和编辑状态
  539. markStatus, err := services.UpdateExcelEditMark(v.ExcelInfoId, sysUser.AdminId, 2, sysUser.RealName)
  540. if err != nil {
  541. br.Msg = "查询标记状态失败"
  542. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  543. return
  544. }
  545. if markStatus.Status == 0 {
  546. list[k].CanEdit = true
  547. } else {
  548. list[k].Editor = markStatus.Editor
  549. }
  550. // excel表格按钮权限
  551. list[k].Button = excel2.GetBalanceExcelInfoOpButton(sysUser.AdminId, v.SysUserId, v.HaveOperaAuth, v.ExcelInfoId)
  552. }
  553. }
  554. }
  555. // 总数据量
  556. dataCount, err := excel3.GetExcelListCountByCondition(condition, pars)
  557. if err != nil && !utils.IsErrNoRow(err) {
  558. br.Msg = "获取表格列表信息失败"
  559. br.ErrMsg = "获取表格列表数据总数失败,Err:" + err.Error()
  560. return
  561. }
  562. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  563. resp := response.ExcelListResp{
  564. Paging: page,
  565. List: list,
  566. }
  567. br.Ret = 200
  568. br.Success = true
  569. br.Msg = "获取成功"
  570. br.Data = resp
  571. }
  572. // Detail
  573. // @Title 获取表格详情
  574. // @Description 获取表格详情接口
  575. // @Param ExcelInfoId query int true "表格id"
  576. // @Success 200 {object} data_manage.ExcelInfo
  577. // @router /excel_info/detail [get]
  578. func (c *ExcelInfoController) Detail() {
  579. br := new(models.BaseResponse).Init()
  580. defer func() {
  581. c.Data["json"] = br
  582. c.ServeJSON()
  583. }()
  584. sysUser := c.SysUser
  585. if sysUser == nil {
  586. br.Msg = "请登录"
  587. br.ErrMsg = "请登录,SysUser Is Empty"
  588. br.Ret = 408
  589. return
  590. }
  591. excelInfoId, _ := c.GetInt("ExcelInfoId")
  592. if excelInfoId <= 0 {
  593. br.Msg = "请选择表格"
  594. br.ErrMsg = "ExcelInfoId未传"
  595. br.IsSendEmail = false
  596. return
  597. }
  598. // 获取数据详情
  599. excelDetail, errMsg, err := excel2.GetExcelDetailInfoByExcelInfoId(excelInfoId, c.SysUser.AdminId, c.Lang)
  600. if err != nil {
  601. br.Msg = errMsg
  602. br.ErrMsg = err.Error()
  603. return
  604. }
  605. checkExcelInfoId := excelInfoId
  606. if excelDetail.Source == utils.BALANCE_TABLE {
  607. if excelDetail.BalanceType == 1 { // 平衡表静态表编辑状态以动态表的编辑状态为准
  608. checkExcelInfoId = excelDetail.RelExcelInfoId
  609. } else {
  610. if excelDetail.ParentId > 0 { // 子表编辑状态以父表的编辑状态为准
  611. checkExcelInfoId = excelDetail.ParentId
  612. }
  613. }
  614. }
  615. // 编辑状态
  616. markStatus, err := services.UpdateExcelEditMark(checkExcelInfoId, sysUser.AdminId, 2, sysUser.RealName)
  617. if err != nil {
  618. br.Msg = "查询标记状态失败"
  619. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  620. return
  621. }
  622. if markStatus.Status == 0 {
  623. excelDetail.CanEdit = true
  624. } else {
  625. excelDetail.Editor = markStatus.Editor
  626. }
  627. // 图表的指标来源
  628. if excelDetail.Source == utils.TIME_TABLE {
  629. jsonStrByte, err := json.Marshal(excelDetail.TableData)
  630. if err != nil {
  631. br.Msg = "时间序列表格数据获取失败"
  632. br.ErrMsg = "时间序列表格数据获取失败,Err:" + err.Error()
  633. return
  634. }
  635. var tableData request.TableDataReq
  636. err = json.Unmarshal(jsonStrByte, &tableData)
  637. if err != nil {
  638. br.Msg = "时间序列表格数据获取失败"
  639. br.ErrMsg = "时间序列表格数据获取失败,Err:" + err.Error()
  640. return
  641. }
  642. sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList(tableData.EdbInfoIdList)
  643. if err != nil {
  644. br.Msg = "时间序列表格数据获取失败"
  645. br.ErrMsg = "时间序列表格数据获取失败,Err:" + err.Error()
  646. return
  647. }
  648. excelDetail.ExcelSource = strings.Join(sourceNameList, ",")
  649. excelDetail.ExcelSourceEn = strings.Join(sourceNameEnList, ",")
  650. }
  651. // 数据刷新-混合表格
  652. if excelDetail.Source == utils.MIXED_TABLE {
  653. // todo 刷新动态表的所有子表中关联的指标数据
  654. jsonByte, e := json.Marshal(excelDetail.TableData)
  655. if e != nil {
  656. br.Msg = "刷新失败"
  657. br.ErrMsg = "JSON格式化混合表格数据失败, Err: " + e.Error()
  658. return
  659. }
  660. var tableData request.MixedTableReq
  661. if e = json.Unmarshal(jsonByte, &tableData); e != nil {
  662. br.Msg = "刷新失败"
  663. br.ErrMsg = "解析混合表格数据失败, Err: " + e.Error()
  664. return
  665. }
  666. edbInfoIds := make([]int, 0)
  667. edbInfoIdExist := make(map[int]bool)
  668. if len(tableData.Data) > 0 {
  669. for _, t := range tableData.Data {
  670. for _, v := range t {
  671. if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
  672. edbInfoIdExist[v.EdbInfoId] = true
  673. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  674. }
  675. }
  676. }
  677. }
  678. sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList(edbInfoIds)
  679. if err != nil {
  680. br.Msg = "自定义表格数据获取失败"
  681. br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
  682. return
  683. }
  684. excelDetail.ExcelSource = strings.Join(sourceNameList, ",")
  685. excelDetail.ExcelSourceEn = strings.Join(sourceNameEnList, ",")
  686. }
  687. // excel表格按钮权限
  688. if excelDetail.Source != utils.BALANCE_TABLE {
  689. excelDetail.Button = excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source, excelDetail.HaveOperaAuth)
  690. }
  691. br.Ret = 200
  692. br.Success = true
  693. br.Msg = "获取成功"
  694. br.Data = excelDetail
  695. }
  696. // Edit
  697. // @Title 编辑表格接口
  698. // @Description 新增表格接口
  699. // @Param request body request.EditExcelInfoReq true "type json string"
  700. // @Success 200 {object} response.AddExcelInfoResp
  701. // @router /excel_info/edit [post]
  702. func (c *ExcelInfoController) Edit() {
  703. br := new(models.BaseResponse).Init()
  704. defer func() {
  705. c.Data["json"] = br
  706. c.ServeJSON()
  707. }()
  708. sysUser := c.SysUser
  709. if sysUser == nil {
  710. br.Msg = "请登录"
  711. br.ErrMsg = "请登录,SysUser Is Empty"
  712. br.Ret = 408
  713. return
  714. }
  715. deleteCache := true
  716. var req request.EditExcelInfoReq
  717. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  718. if err != nil {
  719. br.Msg = "参数解析异常!"
  720. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  721. return
  722. }
  723. if req.ExcelInfoId <= 0 {
  724. br.Msg = "请传入ETA表格标识!"
  725. return
  726. }
  727. cacheKey := "CACHE_TABLE_INFO_EDIT_" + strconv.Itoa(req.ExcelInfoId)
  728. defer func() {
  729. if deleteCache {
  730. _ = utils.Rc.Delete(cacheKey)
  731. }
  732. }()
  733. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  734. deleteCache = false
  735. br.Msg = "系统处理中,请稍后重试!"
  736. br.ErrMsg = "系统处理中,请稍后重试!"
  737. return
  738. }
  739. req.ExcelName = strings.Trim(req.ExcelName, " ")
  740. if req.ExcelName == "" {
  741. br.Msg = "请填写表格名称!"
  742. br.IsSendEmail = false
  743. return
  744. }
  745. excelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
  746. if err != nil {
  747. br.Msg = "获取ETA表格失败"
  748. br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
  749. return
  750. }
  751. if req.ExcelClassifyId <= 0 && excelInfo.ParentId == 0 {
  752. br.Msg = "分类参数错误!"
  753. br.IsSendEmail = false
  754. return
  755. }
  756. checkExcelInfoId := excelInfo.ExcelInfoId
  757. checkExcelInfo := excelInfo
  758. if excelInfo.Source == utils.BALANCE_TABLE {
  759. checkExcelInfoId = excelInfo.ExcelInfoId
  760. if excelInfo.BalanceType == 1 {
  761. checkExcelInfoId = excelInfo.RelExcelInfoId
  762. } else {
  763. if excelInfo.ParentId > 0 {
  764. checkExcelInfoId = excelInfo.ParentId
  765. }
  766. }
  767. if checkExcelInfoId != excelInfo.ExcelInfoId {
  768. checkExcelInfo, err = excel3.GetExcelInfoById(checkExcelInfoId)
  769. if err != nil {
  770. br.Msg = "获取平衡表格信息失败"
  771. br.ErrMsg = "获取平衡表格信息失败,Err:" + err.Error()
  772. return
  773. }
  774. }
  775. }
  776. // 标记编辑状态
  777. markRet, err := services.UpdateExcelEditMark(checkExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
  778. if err != nil {
  779. br.Msg = "查询标记状态失败"
  780. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  781. return
  782. }
  783. if markRet.Status == 1 {
  784. br.Ret = 200
  785. br.Success = true
  786. br.Data = markRet
  787. return
  788. }
  789. if req.ExcelClassifyId > 0 {
  790. excelClassify, e := excel3.GetExcelClassifyById(req.ExcelClassifyId)
  791. if e != nil {
  792. if utils.IsErrNoRow(e) {
  793. br.Msg = "分类不存在"
  794. br.ErrMsg = "分类不存在"
  795. br.IsSendEmail = false
  796. return
  797. }
  798. br.Msg = "获取分类信息失败"
  799. br.ErrMsg = "获取分类信息失败,Err:" + e.Error()
  800. return
  801. }
  802. if excelClassify == nil {
  803. br.Msg = "分类不存在"
  804. br.ErrMsg = "分类不存在"
  805. br.IsSendEmail = false
  806. return
  807. }
  808. }
  809. if excelInfo.ParentId > 0 {
  810. parentExcelInfo, e := excel3.GetExcelInfoById(excelInfo.ParentId)
  811. if e != nil {
  812. if utils.IsErrNoRow(e) {
  813. br.Msg = "父级ETA表格被删除,请刷新页面"
  814. return
  815. }
  816. br.Msg = "获取父级ETA表格信息失败"
  817. br.ErrMsg = "获取父级ETA表格信息失败,Err:" + e.Error()
  818. return
  819. }
  820. req.ExcelClassifyId = parentExcelInfo.ExcelClassifyId
  821. }
  822. //判断表格是否存在
  823. var condition string
  824. var pars []interface{}
  825. condition += " AND excel_info_id != ? "
  826. pars = append(pars, req.ExcelInfoId)
  827. condition += " AND excel_classify_id=? AND parent_id=?"
  828. pars = append(pars, req.ExcelClassifyId, excelInfo.ParentId)
  829. condition += " AND excel_name=? "
  830. pars = append(pars, req.ExcelName)
  831. // 获取分类下是否存在该表格名称
  832. count, err := excel3.GetExcelInfoCountByCondition(condition, pars)
  833. if err != nil {
  834. br.Msg = "ETA判断表格名称是否存在失败"
  835. br.ErrMsg = "判断ETA表格名称是否存在失败,Err:" + err.Error()
  836. return
  837. }
  838. if count > 0 {
  839. br.Msg = "ETA表格名称已存在,请重新填写"
  840. br.IsSendEmail = false
  841. return
  842. }
  843. // 操作权限校验
  844. {
  845. // 数据权限
  846. haveOperaAuth, err := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, c.SysUser.AdminId)
  847. if err != nil {
  848. br.Msg = "获取ETA表格失败"
  849. br.ErrMsg = "获取ETA表格权限失败,Err:" + err.Error()
  850. return
  851. }
  852. var button excel3.ExcelInfoDetailButton
  853. if checkExcelInfo.Source == utils.BALANCE_TABLE {
  854. button = excel2.GetBalanceExcelInfoOpButton(sysUser.AdminId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
  855. } else {
  856. button = excel2.GetExcelInfoOpButton(sysUser, excelInfo.SysUserId, excelInfo.Source, haveOperaAuth)
  857. }
  858. if !button.OpButton {
  859. br.Msg = "无操作权限"
  860. br.IsSendEmail = false
  861. return
  862. }
  863. }
  864. // 引用的指标id
  865. edbInfoIdList := make([]int, 0)
  866. content := req.Content
  867. contentFlag := false
  868. if req.Content != excelInfo.Content {
  869. contentFlag = true
  870. }
  871. balanceTableData := make([][]request.MixedTableCellDataReq, 0)
  872. switch excelInfo.Source {
  873. case utils.TIME_TABLE: // 自定义表格
  874. jsonStrByte, err := json.Marshal(req.TableData)
  875. if err != nil {
  876. br.Msg = "时间序列表格数据获取失败"
  877. br.ErrMsg = "时间序列表格数据获取失败,Err:" + err.Error()
  878. return
  879. }
  880. var tableData request.TableDataReq
  881. err = json.Unmarshal(jsonStrByte, &tableData)
  882. if err != nil {
  883. br.Msg = "时间序列表格数据获取失败"
  884. br.ErrMsg = "时间序列表格数据获取失败,Err:" + err.Error()
  885. return
  886. }
  887. edbInfoIdList = tableData.EdbInfoIdList
  888. tableDataConfig, err := excel2.GetTableDataConfig(tableData)
  889. if err != nil {
  890. br.Msg = "时间序列表格数据获取失败"
  891. br.ErrMsg = "时间序列表格数据获取失败,Err:" + err.Error()
  892. return
  893. }
  894. tableDataConfig.DecimalConfig = tableData.DecimalConfig
  895. contentByte, err := json.Marshal(tableDataConfig)
  896. if err != nil {
  897. br.Msg = "时间序列表格数据获取失败"
  898. br.ErrMsg = "时间序列表格数据获取失败,Err:" + err.Error()
  899. return
  900. }
  901. content = string(contentByte)
  902. case utils.MIXED_TABLE, utils.BALANCE_TABLE: // 混合表格, 平衡表
  903. contentByte, err := json.Marshal(req.TableData)
  904. if err != nil {
  905. br.Msg = "混合表格数据获取失败"
  906. br.ErrMsg = "混合表格数据获取后,转json失败,Err:" + err.Error()
  907. return
  908. }
  909. content = string(contentByte)
  910. var result request.MixedTableReq
  911. err = json.Unmarshal(contentByte, &result)
  912. if err != nil {
  913. br.Msg = "获取失败"
  914. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  915. return
  916. }
  917. newResult, err, errMsg := excel2.GetMixedTableCellData(result, c.Lang)
  918. if err != nil {
  919. br.Msg = "获取失败"
  920. if errMsg != `` {
  921. br.Msg = errMsg
  922. }
  923. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  924. return
  925. }
  926. balanceTableData = newResult
  927. edbInfoIdMap := make(map[int]int)
  928. for _, tmpV := range newResult {
  929. for _, v := range tmpV {
  930. if v.EdbInfoId > 0 {
  931. if _, ok := edbInfoIdMap[v.EdbInfoId]; !ok {
  932. edbInfoIdMap[v.EdbInfoId] = v.EdbInfoId
  933. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  934. }
  935. }
  936. }
  937. }
  938. }
  939. excelInfo.ModifyTime = time.Now()
  940. excelInfo.ExcelName = req.ExcelName
  941. excelInfo.ExcelType = req.ExcelType
  942. excelInfo.ExcelClassifyId = req.ExcelClassifyId
  943. excelInfo.ExcelImage = req.ExcelImage
  944. excelInfo.UpdateUserId = sysUser.AdminId
  945. excelInfo.UpdateUserRealName = sysUser.RealName
  946. excelInfo.Content = content
  947. excelInfo.SourcesFrom = req.SourcesFrom
  948. // 自动保存时不会传缩略图,也就不更新这个字段
  949. var updateExcelInfoParams []string
  950. if req.ExcelImage != "" {
  951. updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "ExcelImage", "Content", "SourcesFrom"}
  952. } else {
  953. updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "Content", "SourcesFrom"}
  954. }
  955. excelEdbMappingList := make([]*excel3.ExcelEdbMapping, 0)
  956. if len(edbInfoIdList) > 0 {
  957. for _, edbInfoId := range edbInfoIdList {
  958. excelEdbMappingList = append(excelEdbMappingList, &excel3.ExcelEdbMapping{
  959. //ExcelEdbMappingId: 0,
  960. ExcelInfoId: excelInfo.ExcelInfoId,
  961. Source: excelInfo.Source,
  962. EdbInfoId: edbInfoId,
  963. CreateTime: time.Now(),
  964. ModifyTime: time.Now(),
  965. })
  966. }
  967. }
  968. err = excel3.EditExcelInfo(excelInfo, updateExcelInfoParams, excelEdbMappingList)
  969. if err != nil {
  970. br.Msg = "保存失败"
  971. br.ErrMsg = "保存失败,Err:" + err.Error()
  972. return
  973. }
  974. // 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
  975. if excelInfo.Source == 1 {
  976. go excel2.UpdateExcelInfoFileUrl(excelInfo)
  977. }
  978. // 更新平衡表图表指标
  979. if excelInfo.Source == utils.BALANCE_TABLE && excelInfo.BalanceType == 1 && contentFlag == true { //静态表更新表数据
  980. err = excel2.SyncBalanceEdbData(excelInfo, balanceTableData)
  981. if err != nil {
  982. br.Msg = "操作失败"
  983. br.ErrMsg = err.Error()
  984. return
  985. }
  986. }
  987. // 加入草稿
  988. {
  989. excelDraftInfo := &excel3.ExcelDraft{
  990. //ExcelDraftId: 0,
  991. ExcelId: req.ExcelInfoId,
  992. Name: req.ExcelName,
  993. Content: content,
  994. OpUserId: sysUser.AdminId,
  995. OpUserName: sysUser.RealName,
  996. CreateTime: time.Now(),
  997. }
  998. err = excel3.AddExcelDraft(excelDraftInfo)
  999. }
  1000. resp := response.AddExcelInfoResp{
  1001. ExcelInfoId: excelInfo.ExcelInfoId,
  1002. UniqueCode: excelInfo.UniqueCode,
  1003. }
  1004. //新增指标引用记录
  1005. _ = data.SaveExcelEdbInfoRelation(excelInfo.ExcelInfoId, excelInfo.Source, false)
  1006. //删除公共图库那边的缓存
  1007. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelInfo.UniqueCode)
  1008. br.Ret = 200
  1009. br.Success = true
  1010. br.Msg = "修改成功"
  1011. br.Data = resp
  1012. br.IsAddLog = true
  1013. }
  1014. // Move
  1015. // @Title 移动表格接口
  1016. // @Description 移动表格接口
  1017. // @Param request body request.MoveExcelInfoReq true "type json string"
  1018. // @Success Ret=200 移动成功
  1019. // @router /excel_info/move [post]
  1020. func (c *ExcelInfoController) Move() {
  1021. br := new(models.BaseResponse).Init()
  1022. defer func() {
  1023. c.Data["json"] = br
  1024. c.ServeJSON()
  1025. }()
  1026. /*
  1027. sysUser := c.SysUser
  1028. if sysUser == nil {
  1029. br.Msg = "请登录"
  1030. br.ErrMsg = "请登录,SysUser Is Empty"
  1031. br.Ret = 408
  1032. return
  1033. }
  1034. var req request.MoveExcelInfoReq
  1035. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1036. if err != nil {
  1037. br.Msg = "参数解析异常!"
  1038. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1039. return
  1040. }
  1041. if req.ExcelInfoId <= 0 {
  1042. br.Msg = "参数错误"
  1043. br.ErrMsg = "表格id小于等于0"
  1044. br.IsSendEmail = false
  1045. return
  1046. }
  1047. if req.ExcelClassifyId <= 0 {
  1048. br.Msg = "请选择分类"
  1049. br.IsSendEmail = false
  1050. return
  1051. }
  1052. //判断分类是否存在
  1053. _, err = excel3.GetExcelClassifyById(req.ExcelClassifyId)
  1054. if err != nil {
  1055. br.Msg = "移动失败"
  1056. br.ErrMsg = "获取分类信息失败" + err.Error()
  1057. if utils.IsErrNoRow(err) {
  1058. br.Msg = "分类已被删除,不可移动,请刷新页面"
  1059. br.ErrMsg = "分类已被删除,不可移动,请刷新页面"
  1060. br.IsSendEmail = false
  1061. }
  1062. return
  1063. }
  1064. // 获取表格信息
  1065. excelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
  1066. if err != nil {
  1067. br.Msg = "移动失败"
  1068. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  1069. return
  1070. }
  1071. //如果改变了分类,那么移动该表格数据
  1072. if excelInfo.ExcelClassifyId != req.ExcelClassifyId {
  1073. //查询需要修改的分类下是否存在同一个表格名称
  1074. tmpExcelInfo, tmpErr := excel3.GetExcelInfoByClassifyIdAndName(req.ExcelClassifyId, excelInfo.ExcelName)
  1075. if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
  1076. br.Msg = "移动失败"
  1077. br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  1078. return
  1079. }
  1080. if tmpExcelInfo != nil {
  1081. br.Msg = "移动失败,同一个分类下表格名称不允许重复"
  1082. br.ErrMsg = "移动失败,同一个分类下表格名称不允许重复"
  1083. br.IsSendEmail = false
  1084. return
  1085. }
  1086. // 变更表格的所属分类
  1087. excelInfo.ExcelClassifyId = req.ExcelClassifyId
  1088. err = excelInfo.Update([]string{"ExcelClassifyId"})
  1089. if err != nil {
  1090. br.Msg = "移动失败"
  1091. br.ErrMsg = "移动失败,Err:" + err.Error()
  1092. return
  1093. }
  1094. }
  1095. //移动排序
  1096. updateCol := make([]string, 0)
  1097. //如果有传入 上一个兄弟节点分类id
  1098. if req.PrevExcelInfoId > 0 {
  1099. prevExcelInfo, err := excel3.GetExcelInfoById(req.PrevExcelInfoId)
  1100. if err != nil {
  1101. br.Msg = "移动失败"
  1102. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1103. return
  1104. }
  1105. //如果是移动在两个兄弟节点之间
  1106. if req.NextExcelInfoId > 0 {
  1107. //下一个兄弟节点
  1108. nextExcelInfo, err := excel3.GetExcelInfoById(req.NextExcelInfoId)
  1109. if err != nil {
  1110. br.Msg = "移动失败"
  1111. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1112. return
  1113. }
  1114. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1115. if prevExcelInfo.Sort == nextExcelInfo.Sort || prevExcelInfo.Sort == excelInfo.Sort {
  1116. //变更兄弟节点的排序
  1117. updateSortStr := `sort + 2`
  1118. _ = excel3.UpdateExcelInfoSortByClassifyId(prevExcelInfo.ExcelClassifyId, prevExcelInfo.Sort, prevExcelInfo.ExcelInfoId, updateSortStr)
  1119. } else {
  1120. //如果下一个兄弟的排序权重正好是上个兄弟节点下一层,那么需要再加一层了
  1121. if nextExcelInfo.Sort-prevExcelInfo.Sort == 1 {
  1122. //变更兄弟节点的排序
  1123. updateSortStr := `sort + 1`
  1124. _ = excel3.UpdateExcelInfoSortByClassifyId(prevExcelInfo.ExcelClassifyId, prevExcelInfo.Sort, prevExcelInfo.ExcelInfoId, updateSortStr, source)
  1125. }
  1126. }
  1127. }
  1128. // 变更表格在当前分类下的排序
  1129. excelInfo.Sort = prevExcelInfo.Sort + 1
  1130. excelInfo.ModifyTime = time.Now()
  1131. updateCol = append(updateCol, "Sort", "ModifyTime")
  1132. } else {
  1133. firstClassify, err := excel3.GetFirstExcelInfoByClassifyId(req.ExcelClassifyId)
  1134. if err != nil && !utils.IsErrNoRow(err) {
  1135. br.Msg = "移动失败"
  1136. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  1137. return
  1138. }
  1139. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1140. if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
  1141. updateSortStr := ` sort + 1 `
  1142. _ = excel3.UpdateExcelInfoSortByClassifyId(firstClassify.ExcelClassifyId, 0, firstClassify.ExcelInfoId+1, updateSortStr)
  1143. }
  1144. // 变更表格在当前分类下的排序
  1145. excelInfo.Sort = 0 //那就是排在第一位
  1146. excelInfo.ModifyTime = time.Now()
  1147. updateCol = append(updateCol, "Sort", "ModifyTime")
  1148. }
  1149. //更新
  1150. if len(updateCol) > 0 {
  1151. err = excelInfo.Update(updateCol)
  1152. if err != nil {
  1153. br.Msg = "移动失败"
  1154. br.ErrMsg = "修改失败,Err:" + err.Error()
  1155. return
  1156. }
  1157. }
  1158. if err != nil {
  1159. br.Msg = "移动失败"
  1160. br.ErrMsg = "修改失败,Err:" + err.Error()
  1161. return
  1162. }
  1163. //新增操作日志
  1164. //{
  1165. // ExcelLog := new(data_manage.ExcelInfoLog)
  1166. // ExcelLog.ExcelName = ExcelInfo.ExcelName
  1167. // ExcelLog.ExcelInfoId = req.ExcelInfoId
  1168. // ExcelLog.ExcelClassifyId = ExcelInfo.ExcelClassifyId
  1169. // ExcelLog.SysUserId = sysUser.AdminId
  1170. // ExcelLog.SysUserRealName = sysUser.RealName
  1171. // ExcelLog.UniqueCode = ExcelInfo.UniqueCode
  1172. // ExcelLog.CreateTime = time.Now()
  1173. // ExcelLog.Content = string(c.Ctx.Input.RequestBody)
  1174. // ExcelLog.Status = "移动表格"
  1175. // ExcelLog.Method = c.Ctx.Input.URL()
  1176. // go data_manage.AddExcelInfoLog(ExcelLog)
  1177. //}
  1178. */
  1179. br.Ret = 200
  1180. br.Success = true
  1181. br.IsAddLog = true
  1182. br.Msg = "移动成功"
  1183. }
  1184. // Delete
  1185. // @Title 删除表格接口
  1186. // @Description 删除表格接口
  1187. // @Param request body request.DeleteExcelInfoReq true "type json string"
  1188. // @Success Ret=200 删除成功
  1189. // @router /excel_info/delete [post]
  1190. func (c *ExcelInfoController) Delete() {
  1191. br := new(models.BaseResponse).Init()
  1192. defer func() {
  1193. c.Data["json"] = br
  1194. c.ServeJSON()
  1195. }()
  1196. resp := response.AddExcelInfoResp{}
  1197. sysUser := c.SysUser
  1198. if sysUser == nil {
  1199. br.Msg = "请登录"
  1200. br.ErrMsg = "请登录,SysUser Is Empty"
  1201. br.Ret = 408
  1202. return
  1203. }
  1204. var req request.DeleteExcelInfoReq
  1205. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1206. if err != nil {
  1207. br.Msg = "参数解析异常!"
  1208. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1209. return
  1210. }
  1211. if req.ExcelInfoId <= 0 {
  1212. br.Msg = "参数错误"
  1213. br.ErrMsg = "表格id小于等于0"
  1214. br.IsSendEmail = false
  1215. return
  1216. }
  1217. // 获取表格信息
  1218. excelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
  1219. if err != nil {
  1220. br.Msg = "删除失败"
  1221. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  1222. return
  1223. }
  1224. // 删除excel
  1225. err, errMsg, isSendEmail := excel2.Delete(excelInfo, sysUser)
  1226. if err != nil {
  1227. br.Msg = "删除失败"
  1228. if errMsg != `` {
  1229. br.Msg = errMsg
  1230. }
  1231. br.ErrMsg = "删除失败,Err:" + err.Error()
  1232. br.IsSendEmail = isSendEmail
  1233. return
  1234. }
  1235. // 返回下一个表格的信息
  1236. {
  1237. var nextItem *excel3.ExcelInfo
  1238. var condition string
  1239. var pars []interface{}
  1240. condition += " AND excel_classify_id=? AND parent_id=0"
  1241. pars = append(pars, excelInfo.ExcelClassifyId)
  1242. condition += " AND sort>=? "
  1243. pars = append(pars, excelInfo.Sort)
  1244. nextItem, err = excel3.GetNextExcelInfoByCondition(condition, pars)
  1245. if err != nil && !utils.IsErrNoRow(err) {
  1246. br.Msg = "删除失败"
  1247. br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  1248. return
  1249. }
  1250. // 如果没找到,那么查找下一个分类的第一个表格
  1251. if nextItem == nil {
  1252. currClassifyInfo, err := excel3.GetExcelClassifyById(excelInfo.ExcelClassifyId)
  1253. if err != nil && !utils.IsErrNoRow(err) {
  1254. br.Msg = "删除失败"
  1255. br.ErrMsg = "获取当前表格分类信息失败,Err:" + err.Error()
  1256. return
  1257. }
  1258. //condition += " AND level=3 "
  1259. //pars = append(pars, chartInfo.ExcelClassifyId)
  1260. //var condition string
  1261. //var pars []interface{}
  1262. //condition += " AND sort>=? ORDER BY excel_classify_id ASC LIMIT 1 "
  1263. //pars = append(pars, currClassifyInfo.Sort)
  1264. //
  1265. //classifyItem, err := data_manage.GetNextExcelClassifyByCondition(condition, pars)
  1266. //if err != nil && !utils.IsErrNoRow(err) {
  1267. // br.Msg = "删除失败"
  1268. // br.ErrMsg = "获取下一级表格分类信息失败,Err:" + err.Error()
  1269. // return
  1270. //}
  1271. //if classifyItem != nil {
  1272. // nextItem, err = data_manage.GetNextExcelInfo(excelInfo.ExcelClassifyId,)
  1273. // if err != nil && !utils.IsErrNoRow(err) {
  1274. // br.Msg = "删除失败"
  1275. // br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  1276. // return
  1277. // }
  1278. //}
  1279. nextItem, err = excel3.GetNextExcelInfo(excelInfo.ExcelClassifyId, currClassifyInfo.Sort, currClassifyInfo.Source)
  1280. if err != nil && !utils.IsErrNoRow(err) {
  1281. br.Msg = "删除失败"
  1282. br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  1283. return
  1284. }
  1285. }
  1286. // 如果找到下一个表格了,那么就返回
  1287. if nextItem != nil {
  1288. resp = response.AddExcelInfoResp{
  1289. ExcelInfoId: nextItem.ExcelInfoId,
  1290. UniqueCode: nextItem.UniqueCode,
  1291. }
  1292. }
  1293. }
  1294. //删除公共图库那边的缓存
  1295. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL)
  1296. br.Ret = 200
  1297. br.Success = true
  1298. br.IsAddLog = true
  1299. br.Data = resp
  1300. br.Msg = "删除成功"
  1301. }
  1302. // AddDraft
  1303. // @Title 新增表格草稿接口
  1304. // @Description 新增表格草稿接口
  1305. // @Param request body request.AddExcelDraftReq true "type json string"
  1306. // @Success Ret=200 添加成功
  1307. // @router /excel_info/draft/add [post]
  1308. func (c *ExcelInfoController) AddDraft() {
  1309. br := new(models.BaseResponse).Init()
  1310. defer func() {
  1311. c.Data["json"] = br
  1312. c.ServeJSON()
  1313. }()
  1314. sysUser := c.SysUser
  1315. if sysUser == nil {
  1316. br.Msg = "请登录"
  1317. br.ErrMsg = "请登录,SysUser Is Empty"
  1318. br.Ret = 408
  1319. return
  1320. }
  1321. var req request.AddExcelDraftReq
  1322. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1323. if err != nil {
  1324. br.Msg = "参数解析异常!"
  1325. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1326. return
  1327. }
  1328. req.ExcelName = strings.Trim(req.ExcelName, " ")
  1329. if req.ExcelName == "" {
  1330. br.Msg = "请填写表格名称!"
  1331. br.IsSendEmail = false
  1332. return
  1333. }
  1334. if req.ExcelClassifyId <= 0 {
  1335. br.Msg = "分类参数错误!"
  1336. br.IsSendEmail = false
  1337. return
  1338. }
  1339. excelClassify, err := excel3.GetExcelClassifyById(req.ExcelClassifyId)
  1340. if err != nil {
  1341. if utils.IsErrNoRow(err) {
  1342. br.Msg = "分类不存在"
  1343. br.ErrMsg = "分类不存在"
  1344. br.IsSendEmail = false
  1345. return
  1346. }
  1347. br.Msg = "获取分类信息失败"
  1348. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1349. return
  1350. }
  1351. if excelClassify == nil {
  1352. br.Msg = "分类不存在"
  1353. br.ErrMsg = "分类不存在"
  1354. br.IsSendEmail = false
  1355. return
  1356. }
  1357. var condition string
  1358. var pars []interface{}
  1359. condition += " AND excel_classify_id=? "
  1360. pars = append(pars, req.ExcelClassifyId)
  1361. condition += " AND excel_name=? "
  1362. pars = append(pars, req.ExcelName)
  1363. // 获取分类下是否存在该表格名称
  1364. _, err = excel3.GetExcelInfoById(req.ExcelInfoId)
  1365. if err != nil {
  1366. br.Msg = "判断表格名称是否存在失败"
  1367. br.ErrMsg = "判断表格名称是否存在失败,Err:" + err.Error()
  1368. return
  1369. }
  1370. excelDraftInfo := &excel3.ExcelDraft{
  1371. //ExcelDraftId: 0,
  1372. ExcelId: req.ExcelInfoId,
  1373. Name: req.ExcelName,
  1374. Content: req.Content,
  1375. OpUserId: sysUser.AdminId,
  1376. OpUserName: sysUser.RealName,
  1377. CreateTime: time.Now(),
  1378. }
  1379. err = excel3.AddExcelDraft(excelDraftInfo)
  1380. if err != nil {
  1381. br.Msg = "保存失败"
  1382. br.ErrMsg = "保存失败,Err:" + err.Error()
  1383. return
  1384. }
  1385. _, err = services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
  1386. if err != nil {
  1387. br.Msg = "查询标记状态失败"
  1388. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  1389. return
  1390. }
  1391. br.Ret = 200
  1392. br.Success = true
  1393. br.Msg = "添加成功"
  1394. }
  1395. // GetExcelTableData
  1396. // @Title 获取excel表格的table数据
  1397. // @Description 获取excel表格的table数据接口
  1398. // @Param UniqueCode query string true "表格code"
  1399. // @Param FromScene query int true "场景来源,1:智能研报,2:研报列表;3:英文研报;4:中文PPT;5:英文PPT"
  1400. // @Success 200 {object} response.ExcelTableDetailResp
  1401. // @router /excel_info/table_data [get]
  1402. func (c *ExcelInfoController) GetExcelTableData() {
  1403. br := new(models.BaseResponse).Init()
  1404. defer func() {
  1405. c.Data["json"] = br
  1406. c.ServeJSON()
  1407. }()
  1408. sysUser := c.SysUser
  1409. if sysUser == nil {
  1410. br.Msg = "请登录"
  1411. br.ErrMsg = "请登录,SysUser Is Empty"
  1412. br.Ret = 408
  1413. return
  1414. }
  1415. uniqueCode := c.GetString("UniqueCode")
  1416. fromScene, _ := c.GetInt("FromScene", 0)
  1417. var err error
  1418. if uniqueCode == `` {
  1419. br.Msg = "请选择表格"
  1420. br.ErrMsg = "UniqueCode未传"
  1421. br.IsSendEmail = false
  1422. return
  1423. }
  1424. //获取eta表格信息
  1425. excelInfo, err := excel3.GetExcelInfoByUniqueCode(uniqueCode)
  1426. if err != nil {
  1427. br.Msg = "获取失败"
  1428. br.ErrMsg = "获取ETA表格信息失败,Err:" + err.Error()
  1429. if utils.IsErrNoRow(err) {
  1430. br.Msg = "ETA表格被删除,请刷新页面"
  1431. br.ErrMsg = "ETA表格被删除,请刷新页面,Err:" + err.Error()
  1432. br.IsSendEmail = false
  1433. }
  1434. return
  1435. }
  1436. var tableData excel.TableData
  1437. var excelSource, excelSourceEn string
  1438. switch excelInfo.Source {
  1439. case utils.EXCEL_DEFAULT:
  1440. luckySheetData, err := excel.GetLuckySheetData(excelInfo.Content)
  1441. if err != nil {
  1442. br.Msg = "获取失败"
  1443. br.ErrMsg = "获取excel数据失败,Err:" + err.Error()
  1444. return
  1445. }
  1446. tableData, err = luckySheetData.GetTableDataByLuckySheetDataStr(true)
  1447. if err != nil {
  1448. br.Msg = "获取失败"
  1449. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1450. return
  1451. }
  1452. case utils.TIME_TABLE:
  1453. var tableDataConfig excel2.TableDataConfig
  1454. err = json.Unmarshal([]byte(excelInfo.Content), &tableDataConfig)
  1455. if err != nil {
  1456. br.Msg = "获取失败"
  1457. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  1458. return
  1459. }
  1460. result, err := excel2.GetDataByTableDataConfig(tableDataConfig)
  1461. if err != nil {
  1462. br.Msg = "获取失败"
  1463. br.ErrMsg = "获取最新的表格数据失败,Err:" + err.Error()
  1464. return
  1465. }
  1466. tableData, err = excel.GetTableDataByCustomData(excelInfo.ExcelType, result, c.Lang)
  1467. if err != nil {
  1468. br.Msg = "获取失败"
  1469. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1470. return
  1471. }
  1472. sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList(result.EdbInfoIdList)
  1473. if err != nil {
  1474. br.Msg = "自定义表格数据获取失败"
  1475. br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
  1476. return
  1477. }
  1478. excelSource = strings.Join(sourceNameList, ",")
  1479. excelSourceEn = strings.Join(sourceNameEnList, ",")
  1480. case utils.MIXED_TABLE:
  1481. var result request.MixedTableReq
  1482. err = json.Unmarshal([]byte(excelInfo.Content), &result)
  1483. if err != nil {
  1484. br.Msg = "获取失败"
  1485. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  1486. return
  1487. }
  1488. newResult, err, errMsg := excel2.GetMixedTableCellData(result, c.Lang)
  1489. if err != nil {
  1490. br.Msg = "获取失败"
  1491. if errMsg != `` {
  1492. br.Msg = errMsg
  1493. }
  1494. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  1495. return
  1496. }
  1497. tableData, err = excel.GetTableDataByMixedTableData(newResult, true)
  1498. if err != nil {
  1499. br.Msg = "获取失败"
  1500. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1501. return
  1502. }
  1503. edbInfoIds := make([]int, 0)
  1504. edbInfoIdExist := make(map[int]bool)
  1505. if len(newResult) > 0 {
  1506. for _, t := range newResult {
  1507. for _, v := range t {
  1508. if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
  1509. edbInfoIdExist[v.EdbInfoId] = true
  1510. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  1511. }
  1512. }
  1513. }
  1514. }
  1515. sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList(edbInfoIds)
  1516. if err != nil {
  1517. br.Msg = "自定义表格数据获取失败"
  1518. br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
  1519. return
  1520. }
  1521. excelSource = strings.Join(sourceNameList, ",")
  1522. excelSourceEn = strings.Join(sourceNameEnList, ",")
  1523. }
  1524. tableData = excel.HandleTableCell(tableData)
  1525. tableData, err = excel.HandleRuleToTableCell(excelInfo.ExcelInfoId, tableData)
  1526. if err != nil {
  1527. utils.FileLog.Info("表格管理规则处理失败,HandleRuleToTableCell err:", err.Error())
  1528. }
  1529. config := response.ExcelTableDetailConfigResp{
  1530. FontSize: 9,
  1531. }
  1532. // 获取配置的字体大小
  1533. confName := models.FromSceneMap[fromScene]
  1534. if confName != `` {
  1535. busConf, err := models.GetBusinessConfByKey(confName)
  1536. if err == nil {
  1537. sizeDeci, err := decimal.NewFromString(busConf.ConfVal)
  1538. if err == nil {
  1539. config.FontSize = int(sizeDeci.IntPart())
  1540. }
  1541. }
  1542. }
  1543. resp := response.ExcelTableDetailResp{
  1544. UniqueCode: excelInfo.UniqueCode,
  1545. ExcelImage: excelInfo.ExcelImage,
  1546. ExcelName: excelInfo.ExcelName,
  1547. TableInfo: tableData,
  1548. Config: config,
  1549. SourcesFrom: excelInfo.SourcesFrom,
  1550. ExcelSource: excelSource,
  1551. ExcelSourceEn: excelSourceEn,
  1552. ExcelInfoId: excelInfo.ExcelInfoId,
  1553. Source: excelInfo.Source,
  1554. }
  1555. br.Ret = 200
  1556. br.Success = true
  1557. br.Msg = "获取成功"
  1558. br.Data = resp
  1559. }
  1560. //func init() {
  1561. //
  1562. // excelInfo, err := data_manage.GetExcelInfoById(52)
  1563. // if err != nil {
  1564. // fmt.Println("err:", err)
  1565. // return
  1566. // }
  1567. //
  1568. // luckySheetData, err := excel.GetLuckySheetData(excelInfo.Content)
  1569. // if err != nil {
  1570. // fmt.Println("err:", err)
  1571. // return
  1572. // }
  1573. // //_, err = luckySheetData.GetTableDataByLuckySheetDataStr()
  1574. // downloadFilePath, err := luckySheetData.ToExcel()
  1575. // if err != nil {
  1576. // fmt.Println("err:", err)
  1577. // return
  1578. // }
  1579. // fmt.Println(downloadFilePath)
  1580. //
  1581. // //fmt.Println(excel.GetColumnName(988, 283))
  1582. //}
  1583. // Calculate
  1584. // @Title 公式计算接口
  1585. // @Description 公式计算接口
  1586. // @Param request body request.CalculateReq true "type json string"
  1587. // @router /excel_info/table/calculate [post]
  1588. func (c *ExcelInfoController) Calculate() {
  1589. br := new(models.BaseResponse).Init()
  1590. defer func() {
  1591. c.Data["json"] = br
  1592. c.ServeJSON()
  1593. }()
  1594. sysUser := c.SysUser
  1595. if sysUser == nil {
  1596. br.Msg = "请登录"
  1597. br.ErrMsg = "请登录,SysUser Is Empty"
  1598. br.Ret = 408
  1599. return
  1600. }
  1601. var req request.CalculateReq
  1602. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1603. if err != nil {
  1604. br.Msg = "参数解析异常!"
  1605. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1606. return
  1607. }
  1608. if req.CalculateFormula == "" {
  1609. br.Msg = "请填写公式"
  1610. return
  1611. }
  1612. calculateFormula := req.CalculateFormula
  1613. calculateFormula = strings.TrimPrefix(calculateFormula, "=")
  1614. calculateFormula = strings.Replace(calculateFormula, "(", "(", -1)
  1615. calculateFormula = strings.Replace(calculateFormula, ")", ")", -1)
  1616. calculateFormula = strings.Replace(calculateFormula, ",", ",", -1)
  1617. calculateFormula = strings.Replace(calculateFormula, "。", ".", -1)
  1618. calculateFormula = strings.Replace(calculateFormula, "%", "*0.01", -1)
  1619. formulaFormStr := utils.ReplaceFormula(req.TagMap, calculateFormula)
  1620. //计算公式异常,那么就移除该指标
  1621. if formulaFormStr == `` {
  1622. //removeDateList = append(removeDateList, sk)
  1623. //fmt.Println("异常了")
  1624. br.Msg = "公式异常"
  1625. br.ErrMsg = "公式异常"
  1626. return
  1627. }
  1628. expression := formula.NewExpression(formulaFormStr)
  1629. calResult, err := expression.Evaluate()
  1630. if err != nil {
  1631. br.Msg = "计算失败"
  1632. br.ErrMsg = "计算失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr
  1633. // 分母为0的报错
  1634. if strings.Contains(err.Error(), "divide by zero") {
  1635. br.Msg = "分母不能为0"
  1636. br.ErrMsg = "分母不能为空,计算公式:" + formulaFormStr
  1637. br.IsSendEmail = false
  1638. }
  1639. return
  1640. }
  1641. // 如果计算结果是NAN,那么就提示报错
  1642. if calResult.IsNan() {
  1643. br.Msg = "计算失败"
  1644. br.ErrMsg = "计算失败:计算结果是:NAN;formulaStr:" + formulaFormStr
  1645. return
  1646. }
  1647. // 计算结果格式化
  1648. calFloat, e := calResult.Float64()
  1649. if e != nil {
  1650. br.Msg = "计算失败"
  1651. br.ErrMsg = "计算失败, Err: " + e.Error()
  1652. return
  1653. }
  1654. calVal := utils.FormatTableDataShowValue(calFloat)
  1655. //calVal := calResult.String()
  1656. //if err != nil {
  1657. // br.Msg = "计算失败"
  1658. // br.ErrMsg = "计算失败,结果转 string 失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr
  1659. // return
  1660. //}
  1661. br.Ret = 200
  1662. br.Success = true
  1663. br.Msg = "计算成功"
  1664. br.Data = calVal
  1665. }
  1666. // GetFirstEdbData
  1667. // @Title 获取未来日期数据接口
  1668. // @Description 获取未来日期数据接口
  1669. // @Param EdbInfoId query int true "指标id"
  1670. // @Param Num query int true "默认期数"
  1671. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒序`,不传默认倒序"
  1672. // @router /excel_info/table/first_edb_data_list [get]
  1673. func (c *ExcelInfoController) GetFirstEdbData() {
  1674. br := new(models.BaseResponse).Init()
  1675. defer func() {
  1676. c.Data["json"] = br
  1677. c.ServeJSON()
  1678. }()
  1679. sysUser := c.SysUser
  1680. if sysUser == nil {
  1681. br.Msg = "请登录"
  1682. br.ErrMsg = "请登录,SysUser Is Empty"
  1683. br.Ret = 408
  1684. return
  1685. }
  1686. edbInfoId, _ := c.GetInt("EdbInfoId")
  1687. num, _ := c.GetInt("Num")
  1688. sortType := c.GetString("SortType")
  1689. if edbInfoId <= 0 {
  1690. br.Msg = "请选择指标"
  1691. br.IsSendEmail = false
  1692. return
  1693. }
  1694. if num <= 0 {
  1695. br.Msg = "期数必须大于0"
  1696. br.IsSendEmail = false
  1697. return
  1698. }
  1699. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  1700. if err != nil {
  1701. br.Msg = "获取失败"
  1702. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  1703. return
  1704. }
  1705. dataList, err := excel2.GetFirstEdbDataList(edbInfo, num, []string{}, -1)
  1706. if err != nil {
  1707. br.Msg = "获取失败"
  1708. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1709. return
  1710. }
  1711. // 默认是倒序返回的数据,如果要正序的话,那么翻转下就好了
  1712. if sortType == "asc" {
  1713. for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
  1714. dataList[i], dataList[j] = dataList[j], dataList[i]
  1715. }
  1716. }
  1717. sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList([]int{edbInfoId})
  1718. if err != nil {
  1719. br.Msg = "自定义表格数据获取失败"
  1720. br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
  1721. return
  1722. }
  1723. excelSource := strings.Join(sourceNameList, ",")
  1724. excelSourceEn := strings.Join(sourceNameEnList, ",")
  1725. if len(dataList) == 0 {
  1726. br.Msg = "指标数据异常,请检查"
  1727. return
  1728. }
  1729. br.Ret = 200
  1730. br.Success = true
  1731. br.Msg = "获取成功"
  1732. br.Data = response.TableDataItem{
  1733. EdbInfoId: edbInfoId,
  1734. Data: dataList,
  1735. Decimal: -1,
  1736. ExcelSource: excelSource,
  1737. ExcelSourceEn: excelSourceEn,
  1738. }
  1739. }
  1740. // GetOtherEdbData
  1741. // @Title 获取指定日期数据接口
  1742. // @Description 获取未来日期数据接口
  1743. // @Param request body request.GetOtherEdbDateDataReq true "type json string"
  1744. // @router /excel_info/table/other_edb_data_list [post]
  1745. func (c *ExcelInfoController) GetOtherEdbData() {
  1746. br := new(models.BaseResponse).Init()
  1747. defer func() {
  1748. c.Data["json"] = br
  1749. c.ServeJSON()
  1750. }()
  1751. sysUser := c.SysUser
  1752. if sysUser == nil {
  1753. br.Msg = "请登录"
  1754. br.ErrMsg = "请登录,SysUser Is Empty"
  1755. br.Ret = 408
  1756. return
  1757. }
  1758. var req request.GetOtherEdbDateDataReq
  1759. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1760. if err != nil {
  1761. br.Msg = "参数解析异常!"
  1762. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1763. return
  1764. }
  1765. if req.EdbInfoId <= 0 {
  1766. br.Msg = "请选择指标"
  1767. br.IsSendEmail = false
  1768. return
  1769. }
  1770. if len(req.DateList) <= 0 {
  1771. br.Msg = "请选择日期"
  1772. br.IsSendEmail = false
  1773. return
  1774. }
  1775. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  1776. if err != nil {
  1777. br.Msg = "获取失败"
  1778. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  1779. return
  1780. }
  1781. dataList, err := excel2.GetOtherEdbDataListFollowDate(edbInfo, req.DateList, req.DateDecimal)
  1782. if err != nil {
  1783. br.Msg = "获取失败"
  1784. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1785. return
  1786. }
  1787. // 默认是倒序返回的数据,如果要正序的话,那么翻转下就好了
  1788. if req.SortType == "asc" {
  1789. for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
  1790. dataList[i], dataList[j] = dataList[j], dataList[i]
  1791. }
  1792. }
  1793. sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList([]int{req.EdbInfoId})
  1794. if err != nil {
  1795. br.Msg = "自定义表格数据获取失败"
  1796. br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
  1797. return
  1798. }
  1799. excelSource := strings.Join(sourceNameList, ",")
  1800. excelSourceEn := strings.Join(sourceNameEnList, ",")
  1801. br.Ret = 200
  1802. br.Success = true
  1803. br.Msg = "获取成功"
  1804. br.Data = response.TableDataItem{
  1805. EdbInfoId: req.EdbInfoId,
  1806. Data: dataList,
  1807. Decimal: -1,
  1808. ExcelSource: excelSource,
  1809. ExcelSourceEn: excelSourceEn,
  1810. }
  1811. }
  1812. // GetBatchEdbData
  1813. // @Title 批量获取指定日期数据接口
  1814. // @Description 批量获取未来日期数据接口
  1815. // @Param request body request.GetBatchEdbDateDataReq true "type json string"
  1816. // @router /excel_info/table/batch_edb_data_list [post]
  1817. func (c *ExcelInfoController) GetBatchEdbData() {
  1818. br := new(models.BaseResponse).Init()
  1819. defer func() {
  1820. c.Data["json"] = br
  1821. c.ServeJSON()
  1822. }()
  1823. sysUser := c.SysUser
  1824. if sysUser == nil {
  1825. br.Msg = "请登录"
  1826. br.ErrMsg = "请登录,SysUser Is Empty"
  1827. br.Ret = 408
  1828. return
  1829. }
  1830. var req request.GetBatchEdbDateDataReq
  1831. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1832. if err != nil {
  1833. br.Msg = "参数解析异常!"
  1834. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1835. return
  1836. }
  1837. if len(req.EdbInfoId) == 0 {
  1838. br.Msg = "请选择指标"
  1839. br.IsSendEmail = false
  1840. return
  1841. }
  1842. tableList := make([]*response.TableDataItem, 0)
  1843. var firstDataList []string
  1844. for i, v := range req.EdbInfoId {
  1845. if req.Num <= 0 {
  1846. br.Msg = "期数必须大于0"
  1847. br.IsSendEmail = false
  1848. return
  1849. }
  1850. edbInfo, err := data_manage.GetEdbInfoById(v)
  1851. if err != nil {
  1852. br.Msg = "获取失败"
  1853. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  1854. return
  1855. }
  1856. if len(req.DateList) == 0 {
  1857. req.Num = 12
  1858. }
  1859. if len(firstDataList) == 0 {
  1860. firstDataList = req.DateList
  1861. }
  1862. if len(firstDataList) != 0 && len(firstDataList) != req.Num {
  1863. req.Num = len(firstDataList)
  1864. }
  1865. if i == 0 {
  1866. dataList, err := excel2.GetFirstEdbDataList(edbInfo, req.Num, firstDataList, req.Decimal[i])
  1867. if err != nil {
  1868. br.Msg = "获取失败"
  1869. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1870. return
  1871. }
  1872. // 默认是倒序返回的数据,如果要正序的话,那么翻转下就好了
  1873. if req.SortType == "asc" {
  1874. for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
  1875. dataList[i], dataList[j] = dataList[j], dataList[i]
  1876. }
  1877. }
  1878. dataList = excel2.PadFirstEdbDataList(dataList, req.DateList, req.SortType, req.Decimal[i])
  1879. sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList([]int{v})
  1880. if err != nil {
  1881. br.Msg = "时间序列表格数据获取失败"
  1882. br.ErrMsg = "时间序列表格数据获取失败,Err:" + err.Error()
  1883. return
  1884. }
  1885. excelSource := strings.Join(sourceNameList, ",")
  1886. excelSourceEn := strings.Join(sourceNameEnList, ",")
  1887. if len(dataList) == 0 {
  1888. br.Msg = "指标数据异常,请检查"
  1889. return
  1890. }
  1891. tableList = append(tableList, &response.TableDataItem{
  1892. EdbInfoId: v,
  1893. Data: dataList,
  1894. Decimal: req.Decimal[i],
  1895. ExcelSource: excelSource,
  1896. ExcelSourceEn: excelSourceEn,
  1897. })
  1898. if len(firstDataList) == 0 {
  1899. tmpDataList := make([]string, 0)
  1900. for _, v := range dataList {
  1901. tmpDataList = append(tmpDataList, v.DataTime)
  1902. }
  1903. firstDataList = tmpDataList
  1904. }
  1905. } else {
  1906. dataList, err := excel2.GetOtherEdbDataList(edbInfo, firstDataList, req.Decimal[i])
  1907. if err != nil {
  1908. br.Msg = "获取失败"
  1909. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1910. return
  1911. }
  1912. // 默认是倒序返回的数据,如果要正序的话,那么翻转下就好了
  1913. if req.SortType == "asc" {
  1914. for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
  1915. dataList[i], dataList[j] = dataList[j], dataList[i]
  1916. }
  1917. }
  1918. sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList([]int{v})
  1919. if err != nil {
  1920. br.Msg = "自定义表格数据获取失败"
  1921. br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
  1922. return
  1923. }
  1924. excelSource := strings.Join(sourceNameList, ",")
  1925. excelSourceEn := strings.Join(sourceNameEnList, ",")
  1926. tableList = append(tableList, &response.TableDataItem{
  1927. EdbInfoId: v,
  1928. Decimal: req.Decimal[i],
  1929. Data: dataList,
  1930. ExcelSource: excelSource,
  1931. ExcelSourceEn: excelSourceEn,
  1932. })
  1933. }
  1934. }
  1935. br.Ret = 200
  1936. br.Success = true
  1937. br.Msg = "获取成功"
  1938. br.Data = tableList
  1939. }
  1940. // GetFutureDateData
  1941. // @Title 获取未来日期数据接口
  1942. // @Description 获取未来日期数据接口
  1943. // @Param request body request.GetFutureDateDataReq true "type json string"
  1944. // @router /excel_info/table/future_date_list [post]
  1945. func (c *ExcelInfoController) GetFutureDateData() {
  1946. br := new(models.BaseResponse).Init()
  1947. defer func() {
  1948. c.Data["json"] = br
  1949. c.ServeJSON()
  1950. }()
  1951. sysUser := c.SysUser
  1952. if sysUser == nil {
  1953. br.Msg = "请登录"
  1954. br.ErrMsg = "请登录,SysUser Is Empty"
  1955. br.Ret = 408
  1956. return
  1957. }
  1958. var req request.GetFutureDateDataReq
  1959. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1960. if err != nil {
  1961. br.Msg = "参数解析异常!"
  1962. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1963. return
  1964. }
  1965. if req.StartDate == `` {
  1966. br.Msg = "开始日期未传"
  1967. br.IsSendEmail = false
  1968. return
  1969. }
  1970. startDate, err := time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
  1971. if err != nil {
  1972. br.Msg = "开始日期异常"
  1973. br.ErrMsg = fmt.Sprint("开始日期异常,startDate:", req.StartDate, ";err:", err.Error())
  1974. return
  1975. }
  1976. if len(req.EdbInfoIdList) <= 0 {
  1977. br.Msg = "请选择指标"
  1978. br.IsSendEmail = false
  1979. return
  1980. }
  1981. baseEdbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoIdList[0])
  1982. if err != nil {
  1983. br.Msg = "查找指标失败"
  1984. br.Msg = "查找指标失败,err:" + err.Error()
  1985. return
  1986. }
  1987. // 第一个指标的数据列表
  1988. var firstEdbDataList []*data_manage.EdbDataList
  1989. {
  1990. switch baseEdbInfo.EdbInfoType {
  1991. case 0:
  1992. firstEdbDataList, err = data_manage.GetEdbDataList(baseEdbInfo.Source, baseEdbInfo.SubSource, baseEdbInfo.EdbInfoId, req.StartDate, ``)
  1993. case 1:
  1994. _, firstEdbDataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(baseEdbInfo.EdbInfoId, req.StartDate, ``, false)
  1995. default:
  1996. br.Msg = "指标类型异常"
  1997. br.ErrMsg = fmt.Sprint("获取失败,指标类型异常", baseEdbInfo.EdbInfoType)
  1998. br.IsSendEmail = false
  1999. return
  2000. }
  2001. }
  2002. dateList := make([]time.Time, 0)
  2003. if req.DateType == 1 {
  2004. num := req.Num
  2005. i := 0 // 数据中有的日期数
  2006. for _, v := range firstEdbDataList {
  2007. tmpDate, err := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
  2008. if err != nil {
  2009. br.Msg = "结束日期异常"
  2010. br.ErrMsg = fmt.Sprint("结束日期异常,startDate:", req.EndDate, ";err:", err.Error())
  2011. return
  2012. }
  2013. if tmpDate.After(startDate) {
  2014. dateList = append(dateList, tmpDate)
  2015. startDate = tmpDate
  2016. i++
  2017. }
  2018. if i >= num {
  2019. break
  2020. }
  2021. }
  2022. num = num - i
  2023. if num > 0 {
  2024. tmpDateList := utils.GetPredictEdbDayListByNum(startDate, num, baseEdbInfo.Frequency)
  2025. dateList = append(dateList, tmpDateList...)
  2026. }
  2027. } else {
  2028. if req.EndDate == `` {
  2029. br.Msg = "结束日期未传"
  2030. br.IsSendEmail = false
  2031. return
  2032. }
  2033. endDate, err := time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
  2034. if err != nil {
  2035. br.Msg = "结束日期异常"
  2036. br.ErrMsg = fmt.Sprint("结束日期异常,startDate:", req.EndDate, ";err:", err.Error())
  2037. return
  2038. }
  2039. for _, v := range firstEdbDataList {
  2040. tmpDate, err := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
  2041. if err != nil {
  2042. br.Msg = "结束日期异常"
  2043. br.ErrMsg = fmt.Sprint("结束日期异常,startDate:", req.EndDate, ";err:", err.Error())
  2044. return
  2045. }
  2046. if tmpDate.Equal(endDate) || (tmpDate.Before(endDate) && tmpDate.After(startDate)) {
  2047. dateList = append(dateList, tmpDate)
  2048. startDate = tmpDate
  2049. }
  2050. }
  2051. if startDate.Before(endDate) {
  2052. tmpDateList := utils.GetPredictEdbDayListByEndDate(startDate, endDate, baseEdbInfo.Frequency)
  2053. dateList = append(dateList, tmpDateList...)
  2054. }
  2055. }
  2056. // 获取所有的指标信息
  2057. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  2058. {
  2059. edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList)
  2060. if err != nil {
  2061. br.Msg = "获取指标信息失败"
  2062. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  2063. return
  2064. }
  2065. for _, v := range edbInfoList {
  2066. edbInfoMap[v.EdbInfoId] = v
  2067. }
  2068. }
  2069. result := make([]response.TableDataItem, 0)
  2070. dateStrList := make([]string, 0)
  2071. lenDate := len(dateList)
  2072. if lenDate > 0 {
  2073. for i := lenDate - 1; i >= 0; i-- {
  2074. dateStrList = append(dateStrList, dateList[i].Format(utils.FormatDate))
  2075. }
  2076. for j, v := range req.EdbInfoIdList {
  2077. tmpEdbInfo, ok := edbInfoMap[v]
  2078. if !ok {
  2079. br.Msg = "获取指标信息失败"
  2080. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  2081. return
  2082. }
  2083. dataList, err := excel2.GetOtherEdbDataList(tmpEdbInfo, dateStrList, req.Decimal[j])
  2084. if err != nil {
  2085. br.Msg = "获取失败"
  2086. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  2087. return
  2088. }
  2089. result = append(result, response.TableDataItem{
  2090. EdbInfoId: v,
  2091. Decimal: req.Decimal[j],
  2092. Data: dataList,
  2093. })
  2094. }
  2095. }
  2096. br.Ret = 200
  2097. br.Success = true
  2098. br.Msg = "获取成功"
  2099. br.Data = result
  2100. }
  2101. // GetHistoryDateData
  2102. // @Title 获取历史日期数据接口
  2103. // @Description 获取历史日期数据接口
  2104. // @Param request body request.GetFutureDateDataReq true "type json string"
  2105. // @router /excel_info/table/history_date_list [post]
  2106. func (c *ExcelInfoController) GetHistoryDateData() {
  2107. br := new(models.BaseResponse).Init()
  2108. defer func() {
  2109. c.Data["json"] = br
  2110. c.ServeJSON()
  2111. }()
  2112. sysUser := c.SysUser
  2113. if sysUser == nil {
  2114. br.Msg = "请登录"
  2115. br.ErrMsg = "请登录,SysUser Is Empty"
  2116. br.Ret = 408
  2117. return
  2118. }
  2119. var req request.GetHistoryDateDataReq
  2120. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  2121. if err != nil {
  2122. br.Msg = "参数解析异常!"
  2123. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2124. return
  2125. }
  2126. if req.EndDate == `` {
  2127. br.Msg = "结束日期未传"
  2128. br.IsSendEmail = false
  2129. return
  2130. }
  2131. if len(req.EdbInfoIdList) <= 0 {
  2132. br.Msg = "请选择指标"
  2133. br.IsSendEmail = false
  2134. return
  2135. }
  2136. // 获取所有的指标信息
  2137. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  2138. {
  2139. edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList)
  2140. if err != nil {
  2141. br.Msg = "获取指标信息失败"
  2142. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  2143. return
  2144. }
  2145. for _, v := range edbInfoList {
  2146. edbInfoMap[v.EdbInfoId] = v
  2147. }
  2148. }
  2149. result := make([]response.TableDataItem, 0)
  2150. dateStrList := make([]string, 0)
  2151. // 获取A列指标的历史数据
  2152. {
  2153. tmpEdbInfo, ok := edbInfoMap[req.EdbInfoIdList[0]]
  2154. if !ok {
  2155. br.Msg = "获取指标信息失败"
  2156. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  2157. return
  2158. }
  2159. firstDataList, err := excel2.GetFirstHistoryEdbDataList(tmpEdbInfo, req.Num, req.EndDate, req.Decimal[0])
  2160. if err != nil {
  2161. br.Msg = "获取失败"
  2162. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  2163. return
  2164. }
  2165. result = append(result, response.TableDataItem{
  2166. EdbInfoId: req.EdbInfoIdList[0],
  2167. Decimal: req.Decimal[0],
  2168. Data: firstDataList,
  2169. })
  2170. for _, v := range firstDataList {
  2171. dateStrList = append(dateStrList, v.DataTime)
  2172. }
  2173. }
  2174. if len(dateStrList) > 0 {
  2175. for k, v := range req.EdbInfoIdList {
  2176. if k == 0 {
  2177. continue
  2178. }
  2179. tmpEdbInfo, ok := edbInfoMap[v]
  2180. if !ok {
  2181. br.Msg = "获取指标信息失败"
  2182. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  2183. return
  2184. }
  2185. dataList, err := excel2.GetOtherEdbDataList(tmpEdbInfo, dateStrList, req.Decimal[k])
  2186. if err != nil {
  2187. br.Msg = "获取失败"
  2188. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  2189. return
  2190. }
  2191. result = append(result, response.TableDataItem{
  2192. EdbInfoId: v,
  2193. Decimal: req.Decimal[k],
  2194. Data: dataList,
  2195. })
  2196. }
  2197. }
  2198. br.Ret = 200
  2199. br.Success = true
  2200. br.Msg = "获取成功"
  2201. br.Data = result
  2202. }
  2203. // Refresh
  2204. // @Title 刷新
  2205. // @Description 刷新接口
  2206. // @Param ExcelInfoId query int true "表格id"
  2207. // @router /excel_info/table/refresh [get]
  2208. func (c *ExcelInfoController) Refresh() {
  2209. br := new(models.BaseResponse).Init()
  2210. defer func() {
  2211. if br.ErrMsg == "" {
  2212. br.IsSendEmail = false
  2213. }
  2214. c.Data["json"] = br
  2215. c.ServeJSON()
  2216. }()
  2217. sysUser := c.SysUser
  2218. if sysUser == nil {
  2219. br.Msg = "请登录"
  2220. br.ErrMsg = "请登录,SysUser Is Empty"
  2221. br.Ret = 408
  2222. return
  2223. }
  2224. excelInfoId, _ := c.GetInt("ExcelInfoId")
  2225. chartInfoId, _ := c.GetInt("ChartInfoId")
  2226. if excelInfoId <= 0 && chartInfoId <= 0 {
  2227. br.Msg = "请选择表格"
  2228. br.ErrMsg = "ExcelInfoId未传"
  2229. br.IsSendEmail = false
  2230. return
  2231. }
  2232. // todo 如果请求入参是chart_info_id,则需要获取excel_info_id
  2233. if chartInfoId > 0 && excelInfoId == 0 {
  2234. excelInfo, err := excel3.GetExcelInfoByChartInfoId(chartInfoId)
  2235. if err != nil {
  2236. br.Msg = "请选择表格"
  2237. br.ErrMsg = "未找到对应的表格"
  2238. br.IsSendEmail = false
  2239. return
  2240. }
  2241. excelInfoId = excelInfo.ExcelInfoId
  2242. }
  2243. // 获取数据详情
  2244. excelDetail, errMsg, err := excel2.GetExcelDetailInfoByExcelInfoId(excelInfoId, c.SysUser.AdminId, c.Lang)
  2245. if err != nil {
  2246. br.Msg = errMsg
  2247. br.ErrMsg = err.Error()
  2248. return
  2249. }
  2250. // 操作权限校验
  2251. {
  2252. button := excelDetail.Button
  2253. if excelDetail.Source != utils.BALANCE_TABLE {
  2254. button = excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source, excelDetail.HaveOperaAuth)
  2255. }
  2256. if !button.RefreshButton {
  2257. br.Msg = "无操作权限"
  2258. br.IsSendEmail = false
  2259. return
  2260. }
  2261. }
  2262. // 数据刷新(只有自定义表格有刷新)
  2263. if excelDetail.Source == utils.TIME_TABLE {
  2264. jsonStrByte, err := json.Marshal(excelDetail.TableData)
  2265. if err != nil {
  2266. br.Msg = "自定义表格数据获取失败"
  2267. br.ErrMsg = "自定义表格数据获取失败,转json失败,Err:" + err.Error()
  2268. return
  2269. }
  2270. var tableData request.TableDataReq
  2271. err = json.Unmarshal(jsonStrByte, &tableData)
  2272. if err != nil {
  2273. br.Msg = "自定义表格数据获取失败"
  2274. br.ErrMsg = "自定义表格数据获取失败,json转结构体失败,Err:" + err.Error()
  2275. return
  2276. }
  2277. if len(tableData.EdbInfoIdList) > 0 {
  2278. err, _ = data.EdbInfoRefreshAllFromBaseV3(tableData.EdbInfoIdList, false, true, false)
  2279. if err != nil {
  2280. br.Msg = "刷新失败"
  2281. br.ErrMsg = "刷新失败,Err:" + err.Error()
  2282. return
  2283. }
  2284. }
  2285. }
  2286. // 数据刷新-混合表格
  2287. if excelDetail.Source == utils.MIXED_TABLE {
  2288. // todo 刷新动态表的所有子表中关联的指标数据
  2289. jsonByte, e := json.Marshal(excelDetail.TableData)
  2290. if e != nil {
  2291. br.Msg = "刷新失败"
  2292. br.ErrMsg = "JSON格式化混合表格数据失败, Err: " + e.Error()
  2293. return
  2294. }
  2295. var tableData request.MixedTableReq
  2296. if e = json.Unmarshal(jsonByte, &tableData); e != nil {
  2297. br.Msg = "刷新失败"
  2298. br.ErrMsg = "解析混合表格数据失败, Err: " + e.Error()
  2299. return
  2300. }
  2301. edbInfoIds := make([]int, 0)
  2302. edbInfoIdExist := make(map[int]bool)
  2303. if len(tableData.Data) > 0 {
  2304. for _, t := range tableData.Data {
  2305. for _, v := range t {
  2306. if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
  2307. edbInfoIdExist[v.EdbInfoId] = true
  2308. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  2309. }
  2310. }
  2311. }
  2312. }
  2313. if len(edbInfoIds) > 0 {
  2314. e, _ = data.EdbInfoRefreshAllFromBaseV3(edbInfoIds, false, true, false)
  2315. if e != nil {
  2316. br.Msg = "刷新失败"
  2317. br.ErrMsg = "刷新混合表格数据失败, Err: " + err.Error()
  2318. return
  2319. }
  2320. }
  2321. }
  2322. if excelDetail.Source == utils.BALANCE_TABLE {
  2323. err = refreshBalanceTable(excelDetail, c.Lang)
  2324. if err != nil {
  2325. br.Msg = "刷新失败"
  2326. br.ErrMsg = "刷新失败,Err:" + err.Error()
  2327. return
  2328. }
  2329. }
  2330. // 清除缓存
  2331. key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelDetail.UniqueCode
  2332. if utils.Re == nil {
  2333. _ = utils.Rc.Delete(key)
  2334. }
  2335. br.Ret = 200
  2336. br.Success = true
  2337. br.Msg = "刷新成功"
  2338. }
  2339. // Download
  2340. // @Title 获取表格详情
  2341. // @Description 获取表格详情接口
  2342. // @Param UniqueCode query string true "表格code"
  2343. // @Param ExcelInfoId query int true "表格id"
  2344. // @Success 200 {object} data_manage.ExcelInfo
  2345. // @router /excel_info/table/download [get]
  2346. func (c *ExcelInfoController) Download() {
  2347. br := new(models.BaseResponse).Init()
  2348. defer func() {
  2349. c.Data["json"] = br
  2350. c.ServeJSON()
  2351. }()
  2352. sysUser := c.SysUser
  2353. if sysUser == nil {
  2354. br.Msg = "请登录"
  2355. br.ErrMsg = "请登录,SysUser Is Empty"
  2356. br.Ret = 408
  2357. return
  2358. }
  2359. excelInfoId, _ := c.GetInt("ExcelInfoId")
  2360. uniqueCode := c.GetString("UniqueCode")
  2361. if excelInfoId <= 0 && uniqueCode == `` {
  2362. br.Msg = "请选择表格"
  2363. br.ErrMsg = "ExcelInfoId和UniqueCode都未传"
  2364. br.IsSendEmail = false
  2365. return
  2366. }
  2367. var excelInfo *excel3.ExcelInfo
  2368. var err error
  2369. //获取eta表格信息
  2370. if excelInfoId > 0 {
  2371. excelInfo, err = excel3.GetExcelInfoById(excelInfoId)
  2372. } else {
  2373. excelInfo, err = excel3.GetExcelInfoByUniqueCode(uniqueCode)
  2374. }
  2375. if err != nil {
  2376. br.Msg = "获取失败"
  2377. br.ErrMsg = "获取ETA表格信息失败,Err:" + err.Error()
  2378. if utils.IsErrNoRow(err) {
  2379. br.Msg = "ETA表格被删除,请刷新页面"
  2380. br.ErrMsg = "ETA表格被删除,请刷新页面,Err:" + err.Error()
  2381. br.IsSendEmail = false
  2382. }
  2383. return
  2384. }
  2385. if excelInfo.Source == 1 {
  2386. br.Msg = "不是自定义表格"
  2387. br.IsSendEmail = false
  2388. return
  2389. }
  2390. var tableData excel.TableData
  2391. switch excelInfo.Source {
  2392. case utils.EXCEL_DEFAULT:
  2393. br.Msg = "表格类型异常"
  2394. case utils.TIME_TABLE: // 自定义表格
  2395. var tableDataConfig excel2.TableDataConfig
  2396. err = json.Unmarshal([]byte(excelInfo.Content), &tableDataConfig)
  2397. if err != nil {
  2398. br.Msg = "获取失败"
  2399. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  2400. return
  2401. }
  2402. result, err := excel2.GetDataByTableDataConfig(tableDataConfig)
  2403. if err != nil {
  2404. br.Msg = "获取失败"
  2405. br.ErrMsg = "获取最新的表格数据失败,Err:" + err.Error()
  2406. return
  2407. }
  2408. tableData, err = excel.GetTableDataByCustomData(excelInfo.ExcelType, result, c.Lang)
  2409. if err != nil {
  2410. br.Msg = "获取失败"
  2411. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  2412. return
  2413. }
  2414. case utils.MIXED_TABLE: // 混合表格
  2415. var result request.MixedTableReq
  2416. err = json.Unmarshal([]byte(excelInfo.Content), &result)
  2417. if err != nil {
  2418. br.Msg = "获取失败"
  2419. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  2420. return
  2421. }
  2422. newResult, err, errMsg := excel2.GetMixedTableCellData(result, c.Lang)
  2423. if err != nil {
  2424. br.Msg = "获取失败"
  2425. if errMsg != `` {
  2426. br.Msg = errMsg
  2427. }
  2428. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  2429. return
  2430. }
  2431. tableData, err = excel.GetTableDataByMixedTableData(newResult, false)
  2432. if err != nil {
  2433. br.Msg = "获取失败"
  2434. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  2435. return
  2436. }
  2437. case utils.BALANCE_TABLE: // 混合表格
  2438. savePath, fileName, uploadDir, err, errMsg := downloadBalanceTable(excelInfo, c.Lang)
  2439. if err != nil {
  2440. br.Msg = "下载失败"
  2441. if errMsg != `` {
  2442. br.Msg = errMsg
  2443. }
  2444. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  2445. return
  2446. }
  2447. defer func() {
  2448. _ = os.RemoveAll(uploadDir)
  2449. }()
  2450. // todo 删除文件
  2451. c.Ctx.Output.Download(savePath, fileName)
  2452. br.Ret = 200
  2453. br.Success = true
  2454. br.Msg = "获取成功"
  2455. br.Data = excelInfo
  2456. return
  2457. }
  2458. downloadFilePath, err := tableData.ToExcel()
  2459. if err != nil {
  2460. fmt.Println("err:", err)
  2461. return
  2462. }
  2463. defer func() {
  2464. _ = os.Remove(downloadFilePath)
  2465. }()
  2466. downloadFileName := excelInfo.ExcelName + ".xlsx"
  2467. c.Ctx.Output.Download(downloadFilePath, downloadFileName)
  2468. br.Ret = 200
  2469. br.Success = true
  2470. br.Msg = "获取成功"
  2471. br.Data = excelInfo
  2472. }
  2473. // Copy
  2474. // @Title 复制表格
  2475. // @Description 复制表格接口
  2476. // @Param request body request.EditExcelInfoReq true "type json string"
  2477. // @Success 200 {object} response.AddExcelInfoResp
  2478. // @router /excel_info/copy [post]
  2479. func (c *ExcelInfoController) Copy() {
  2480. br := new(models.BaseResponse).Init()
  2481. defer func() {
  2482. c.Data["json"] = br
  2483. c.ServeJSON()
  2484. }()
  2485. sysUser := c.SysUser
  2486. if sysUser == nil {
  2487. br.Msg = "请登录"
  2488. br.ErrMsg = "请登录,SysUser Is Empty"
  2489. br.Ret = 408
  2490. return
  2491. }
  2492. var req request.CopyExcelInfoReq
  2493. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  2494. if err != nil {
  2495. br.Msg = "参数解析异常!"
  2496. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2497. return
  2498. }
  2499. if req.ExcelInfoId <= 0 {
  2500. br.Msg = "请传入ETA表格标识!"
  2501. return
  2502. }
  2503. cacheKey := "CACHE_TABLE_INFO_EDIT_" + strconv.Itoa(req.ExcelInfoId)
  2504. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  2505. br.Msg = "系统处理中,请稍后重试!"
  2506. br.ErrMsg = "系统处理中,请稍后重试!"
  2507. return
  2508. }
  2509. defer func() {
  2510. _ = utils.Rc.Delete(cacheKey)
  2511. }()
  2512. req.ExcelName = strings.Trim(req.ExcelName, " ")
  2513. if req.ExcelName == "" {
  2514. br.Msg = "请填写表格名称!"
  2515. br.IsSendEmail = false
  2516. return
  2517. }
  2518. if req.ExcelClassifyId <= 0 {
  2519. br.Msg = "分类参数错误!"
  2520. br.IsSendEmail = false
  2521. return
  2522. }
  2523. // 获取原ETA表格信息
  2524. oldExcelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
  2525. if err != nil {
  2526. br.Msg = "获取ETA表格失败"
  2527. return
  2528. }
  2529. var (
  2530. excelInfo *excel3.ExcelInfo
  2531. errMsg string
  2532. isSendEmail bool
  2533. )
  2534. if oldExcelInfo.Source == utils.BALANCE_TABLE {
  2535. excelInfo, err, errMsg, isSendEmail = data.CopyBalanceExcel(oldExcelInfo, req.ExcelClassifyId, req.ExcelName, sysUser)
  2536. } else {
  2537. excelInfo, err, errMsg, isSendEmail = excel2.Copy(oldExcelInfo, req.ExcelClassifyId, req.ExcelName, sysUser)
  2538. }
  2539. if err != nil {
  2540. br.Msg = "复制失败"
  2541. if errMsg != `` {
  2542. br.Msg = errMsg
  2543. }
  2544. br.ErrMsg = "复制失败,Err:" + err.Error()
  2545. br.IsSendEmail = isSendEmail
  2546. return
  2547. }
  2548. //新增指标引用记录
  2549. _ = data.SaveExcelEdbInfoRelation(excelInfo.ExcelInfoId, excelInfo.Source, true)
  2550. resp := new(response.AddExcelInfoResp)
  2551. resp.ExcelInfoId = excelInfo.ExcelInfoId
  2552. resp.UniqueCode = excelInfo.UniqueCode
  2553. br.Ret = 200
  2554. br.Success = true
  2555. br.Msg = "保存成功"
  2556. br.Data = resp
  2557. br.IsAddLog = true
  2558. }
  2559. //func init() {
  2560. // //list, err := data.GetFirstEdbDataList(102739, 12)
  2561. // list, err := data.GetFirstEdbDataList(101323, 12)
  2562. // if err != nil {
  2563. // fmt.Println(err)
  2564. // return
  2565. // }
  2566. //
  2567. // fmt.Println("START")
  2568. // dateList := make([]string, 0)
  2569. // for _, v := range list {
  2570. // fmt.Println(v)
  2571. // dateList = append(dateList, v.DataTime)
  2572. // }
  2573. //
  2574. // fmt.Println("End")
  2575. //
  2576. // {
  2577. // list, err := data.GetOtherEdbDataList(102227, dateList)
  2578. // if err != nil {
  2579. // fmt.Println(err)
  2580. // return
  2581. // }
  2582. //
  2583. // for _, v := range list {
  2584. // fmt.Println(v)
  2585. // }
  2586. // }
  2587. //}
  2588. //func init() {
  2589. // 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":[]}]]}`
  2590. // 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":[]}]]}`
  2591. //
  2592. // //var req request.TableDataReq
  2593. // //err := json.Unmarshal([]byte(str), &req)
  2594. // //if err != nil {
  2595. // // fmt.Println(err)
  2596. // // return
  2597. // //}
  2598. // //tableDataConfig, err := data.GetTableDataConfig(req)
  2599. // //if err != nil {
  2600. // // fmt.Println(err)
  2601. // // return
  2602. // //}
  2603. // var tableDataConfig data.TableDataConfig
  2604. // err := json.Unmarshal([]byte(str), &tableDataConfig)
  2605. // if err != nil {
  2606. // fmt.Println(err)
  2607. // return
  2608. // }
  2609. //
  2610. // fmt.Println(tableDataConfig)
  2611. //
  2612. // result, err := data.GetDataByTableDataConfig(tableDataConfig)
  2613. // if err != nil {
  2614. // fmt.Println(err)
  2615. // return
  2616. // }
  2617. // fmt.Println(result)
  2618. // //byteStr, _ := json.Marshal(result)
  2619. // //utils.FileLog.Info(string(byteStr))
  2620. //}
  2621. //func init() {
  2622. // startNow := time.Now()
  2623. // fmt.Println(startNow.Format(utils.FormatDateTime))
  2624. // startTime := startNow.Unix()
  2625. // //filePath := `static/tmpFile/test/化工23.05.24.xlsx`
  2626. // filePath := `static/tmpFile/1. TAROUND_202308010201-500.xlsx`
  2627. // //filePath := `static/tmpFile/化工23.05.24.xml`
  2628. // //filePath := `static/tmpFile/化工23.05.24/xl/workbook.xml`
  2629. // //filePath := `static/tmpFile/1. TAROUND_202308010201.xlsx`
  2630. //
  2631. // //filePath := `static/tmpFile/1. TAROUND_202308010201-2.xlsx`
  2632. //
  2633. // //filePath := `static/tmpFile/5. Outage_Values_Daily.xlsx`
  2634. // //filePath := `static/tmpFile/1. TAROUND_202308010201 - 副本.xlsx`
  2635. // excel.ConvToLuckySheet(filePath)
  2636. // cz := time.Now().Unix() - startTime
  2637. // fmt.Printf("处理完需要的时间:%d秒;约耗时:%d分%d秒", cz, cz/60, cz%60)
  2638. // fmt.Println()
  2639. //
  2640. // //sheetName := `日度`
  2641. // //sheetName := `月度`
  2642. // //fmt.Println(excel.GetDefaultSheetIndex(filePath, sheetName))
  2643. //
  2644. // //decompressZip(filePath)
  2645. //}
  2646. // src: 需要解压的zip文件
  2647. func decompressZip(src string) error {
  2648. archive, err := zip.OpenReader(src)
  2649. if err != nil {
  2650. return err
  2651. }
  2652. dir := filepath.Dir(src) + "/zip"
  2653. defer archive.Close()
  2654. for _, f := range archive.File {
  2655. filePath := filepath.Join(dir, f.Name)
  2656. if f.FileInfo().IsDir() {
  2657. os.MkdirAll(filePath, os.ModePerm)
  2658. continue
  2659. }
  2660. if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
  2661. return fmt.Errorf("failed to make directory (%v)", err)
  2662. }
  2663. dstFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
  2664. if err != nil {
  2665. return fmt.Errorf("failed to create file (%v)", err)
  2666. }
  2667. fileInArchive, err := f.Open()
  2668. if err != nil {
  2669. return fmt.Errorf("failed to open file in zip (%v)", err)
  2670. }
  2671. if _, err := io.Copy(dstFile, fileInArchive); err != nil {
  2672. return fmt.Errorf("failed to copy file in zip (%v)", err)
  2673. }
  2674. dstFile.Close()
  2675. fileInArchive.Close()
  2676. }
  2677. return nil
  2678. }
  2679. // MarkEditStatus
  2680. // @Title 标记沙盘编辑状态
  2681. // @Description 标记沙盘编辑状态接口
  2682. // @Param request body request.MarkEditSandbox true "type json string"
  2683. // @Success 200 标记成功 ;202 标记成功
  2684. // @router /excel_info/mark [post]
  2685. func (c *ExcelInfoController) MarkEditStatus() {
  2686. br := new(models.BaseResponse).Init()
  2687. defer func() {
  2688. c.Data["json"] = br
  2689. c.ServeJSON()
  2690. }()
  2691. sysUser := c.SysUser
  2692. if sysUser == nil {
  2693. br.Msg = "请登录"
  2694. br.ErrMsg = "请登录,SysUser Is Empty"
  2695. br.Ret = 408
  2696. return
  2697. }
  2698. var req request.MarkEditExcel
  2699. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  2700. if err != nil {
  2701. br.Msg = "参数解析异常!"
  2702. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2703. return
  2704. }
  2705. if req.ExcelInfoId <= 0 {
  2706. br.Msg = "缺少表格编号"
  2707. return
  2708. }
  2709. if req.Status <= 0 {
  2710. br.Msg = "标记状态异常"
  2711. return
  2712. }
  2713. status := 1
  2714. if req.Status == 2 {
  2715. status = 0
  2716. }
  2717. //更新标记key
  2718. data, err := services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, status, sysUser.RealName)
  2719. if err != nil {
  2720. br.Msg = err.Error()
  2721. return
  2722. }
  2723. msg := "标记成功"
  2724. br.Ret = 200
  2725. br.Success = true
  2726. br.Msg = msg
  2727. br.Data = data
  2728. }
  2729. // BatchRefresh
  2730. // @Title 批量刷新表格接口
  2731. // @Description 批量刷新图表接口
  2732. // @Param request body excel3.BatchRefreshExcelReq true "type json string"
  2733. // @Success Ret=200 刷新成功
  2734. // @router /excel_info/table/batch_refresh [post]
  2735. func (c *ExcelInfoController) BatchRefresh() {
  2736. br := new(models.BaseResponse).Init()
  2737. defer func() {
  2738. if br.ErrMsg == "" {
  2739. br.IsSendEmail = false
  2740. }
  2741. c.Data["json"] = br
  2742. c.ServeJSON()
  2743. }()
  2744. sysUser := c.SysUser
  2745. if sysUser == nil {
  2746. br.Msg = "请登录"
  2747. br.ErrMsg = "请登录,SysUser Is Empty"
  2748. br.Ret = 408
  2749. return
  2750. }
  2751. var req excel3.BatchRefreshExcelReq
  2752. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  2753. if err != nil {
  2754. br.Msg = "参数解析异常!"
  2755. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2756. return
  2757. }
  2758. if len(req.ExcelCodes) == 0 {
  2759. br.Ret = 200
  2760. br.Success = true
  2761. br.Msg = "刷新成功"
  2762. return
  2763. }
  2764. if req.Source == "" {
  2765. br.Msg = "刷新来源有误"
  2766. return
  2767. }
  2768. if req.PrimaryId <= 0 {
  2769. br.Msg = "刷新对象有误"
  2770. return
  2771. }
  2772. // 获取表格关联的指标IDs
  2773. edbIds, e := excel2.GetEdbIdsFromExcelCodes(req.ExcelCodes, sysUser.AdminId, c.Lang)
  2774. if e != nil {
  2775. br.Msg = "刷新失败"
  2776. br.ErrMsg = "获取表格关联的指标IDs失败, Err: " + e.Error()
  2777. return
  2778. }
  2779. redisKey := data.GetBatchChartRefreshKey(req.Source, req.PrimaryId, req.SubId)
  2780. refreshKeys := make([]string, 0)
  2781. for _, v := range req.ExcelCodes {
  2782. refreshKeys = append(refreshKeys, fmt.Sprint(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL, v))
  2783. }
  2784. // 刷新相关指标
  2785. syncing, e := data.BatchRefreshEdbByEdbIds(edbIds, redisKey, refreshKeys)
  2786. if e != nil {
  2787. br.Msg = "刷新失败"
  2788. br.ErrMsg = "刷新表格关联指标信息失败,Err:" + err.Error()
  2789. return
  2790. }
  2791. br.Msg = "刷新成功"
  2792. if syncing {
  2793. br.Msg = "表格关联指标较多,请10分钟后刷新页面查看最新数据"
  2794. }
  2795. br.Ret = 200
  2796. br.Success = true
  2797. }
  2798. // GetBatchChartRefreshResult
  2799. // @Title 获取批量刷新表格结果
  2800. // @Description 获取批量刷新表格结果
  2801. // @Param request body excel3.BatchRefreshExcelReq true "type json string"
  2802. // @Success Ret=200 刷新成功
  2803. // @router /excel_info/table/batch_refresh/result [post]
  2804. func (c *ExcelInfoController) GetBatchChartRefreshResult() {
  2805. br := new(models.BaseResponse).Init()
  2806. defer func() {
  2807. c.Data["json"] = br
  2808. c.ServeJSON()
  2809. }()
  2810. sysUser := c.SysUser
  2811. if sysUser == nil {
  2812. br.Msg = "请登录"
  2813. br.ErrMsg = "请登录,SysUser Is Empty"
  2814. br.Ret = 408
  2815. return
  2816. }
  2817. var req excel3.BatchRefreshExcelReq
  2818. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  2819. if err != nil {
  2820. br.Msg = "参数解析异常!"
  2821. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2822. return
  2823. }
  2824. if req.Source == "" {
  2825. br.Msg = "刷新来源有误"
  2826. return
  2827. }
  2828. if req.PrimaryId <= 0 {
  2829. br.Msg = "刷新对象有误"
  2830. return
  2831. }
  2832. // 校验缓存是否存在, 存在说明还在刷新中
  2833. result := true
  2834. redisKey := excel2.GetExcelEdbBatchRefreshKey(req.Source, req.PrimaryId, req.SubId)
  2835. if redisKey != `` {
  2836. // 如果找到了key,那么就是还在更新中
  2837. ok := utils.Rc.IsExist(redisKey)
  2838. if ok {
  2839. result = false
  2840. }
  2841. }
  2842. resp := struct {
  2843. RefreshResult bool `description:"刷新结果"`
  2844. }{
  2845. RefreshResult: result,
  2846. }
  2847. br.Data = resp
  2848. br.Ret = 200
  2849. br.Success = true
  2850. }
  2851. // GetBatchChartRefreshResult
  2852. // @Title 获取批量刷新表格结果
  2853. // @Description 获取批量刷新表格结果
  2854. // @Param EdbInfoId query int true "edb id"
  2855. // @Success Ret=200 刷新成功
  2856. // @router /excel_info/get_edb_source [get]
  2857. func (c *ExcelInfoController) GetEdbSource() {
  2858. br := new(models.BaseResponse).Init()
  2859. defer func() {
  2860. c.Data["json"] = br
  2861. c.ServeJSON()
  2862. }()
  2863. sysUser := c.SysUser
  2864. if sysUser == nil {
  2865. br.Msg = "请登录"
  2866. br.ErrMsg = "请登录,SysUser Is Empty"
  2867. br.Ret = 408
  2868. return
  2869. }
  2870. edbInfoId, _ := c.GetInt("EdbInfoId")
  2871. if edbInfoId <= 0 {
  2872. br.Msg = "请选择指标"
  2873. br.ErrMsg = "请选择指标"
  2874. br.IsSendEmail = false
  2875. return
  2876. }
  2877. sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList([]int{edbInfoId})
  2878. if err != nil {
  2879. br.Msg = "自定义表格数据获取失败"
  2880. br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
  2881. return
  2882. }
  2883. excelSource := strings.Join(sourceNameList, ",")
  2884. excelSourceEn := strings.Join(sourceNameEnList, ",")
  2885. var resp struct {
  2886. ExcelSource string `description:"表格来源"`
  2887. ExcelSourceEn string `description:"表格来源(英文)"`
  2888. }
  2889. resp.ExcelSource = excelSource
  2890. resp.ExcelSourceEn = excelSourceEn
  2891. br.Data = resp
  2892. br.Ret = 200
  2893. br.Success = true
  2894. }
  2895. // ExcelRule
  2896. // @Title 添加表格规则
  2897. // @Description 添加表格规则
  2898. // @Param request body excel3.BatchRefreshExcelReq true "type json string"
  2899. // @Success Ret=200 刷新成功
  2900. // @router /excel_info/rule/add [post]
  2901. func (c *ExcelInfoController) AddExcelRule() {
  2902. br := new(models.BaseResponse).Init()
  2903. defer func() {
  2904. c.Data["json"] = br
  2905. c.ServeJSON()
  2906. }()
  2907. sysUser := c.SysUser
  2908. if sysUser == nil {
  2909. br.Msg = "请登录"
  2910. br.ErrMsg = "请登录,SysUser Is Empty"
  2911. br.Ret = 408
  2912. return
  2913. }
  2914. var req *request.ExcelRuleMappingReq
  2915. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  2916. if err != nil {
  2917. br.Msg = "参数解析异常!"
  2918. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2919. return
  2920. }
  2921. if req.LeftValue == "" {
  2922. br.Msg = "条件值不能为空"
  2923. return
  2924. }
  2925. if req.Scope == "" {
  2926. br.Msg = "应用选区不能为空"
  2927. return
  2928. }
  2929. if req.FontColor == "" && req.BackgroundColor == "" {
  2930. br.Msg = "字体颜色和背景颜色不能同时为空"
  2931. return
  2932. }
  2933. if req.RuleType == 3 && req.RightValue == "" {
  2934. br.Msg = "条件值不能为空"
  2935. return
  2936. }
  2937. err = excel2.AddExcelRule(req, c.Lang)
  2938. if err != nil {
  2939. br.Msg = "规则添加失败"
  2940. br.ErrMsg = "规则添加失败,Err:" + err.Error()
  2941. return
  2942. }
  2943. br.Msg = "添加成功"
  2944. br.Ret = 200
  2945. br.Success = true
  2946. }
  2947. // EditExcelRule
  2948. // @Title 编辑表格规则
  2949. // @Description 编辑表格规则
  2950. // @Param request body request.ExcelRuleMappingReq true "type json string"
  2951. // @Success Ret=200 刷新成功
  2952. // @router /excel_info/rule/edit [post]
  2953. func (c *ExcelInfoController) EditExcelRule() {
  2954. br := new(models.BaseResponse).Init()
  2955. defer func() {
  2956. c.Data["json"] = br
  2957. c.ServeJSON()
  2958. }()
  2959. sysUser := c.SysUser
  2960. if sysUser == nil {
  2961. br.Msg = "请登录"
  2962. br.ErrMsg = "请登录,SysUser Is Empty"
  2963. br.Ret = 408
  2964. return
  2965. }
  2966. var req *request.ExcelRuleMappingReq
  2967. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  2968. if err != nil {
  2969. br.Msg = "参数解析异常!"
  2970. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2971. return
  2972. }
  2973. if req.LeftValue == "" {
  2974. br.Msg = "条件值不能为空"
  2975. return
  2976. }
  2977. if req.Scope == "" {
  2978. br.Msg = "应用选区不能为空"
  2979. return
  2980. }
  2981. if req.FontColor == "" {
  2982. br.Msg = "字体颜色不能为空"
  2983. return
  2984. }
  2985. if req.BackgroundColor == "" {
  2986. br.Msg = "背景颜色不能为空"
  2987. return
  2988. }
  2989. if req.RuleType == 3 && req.RightValue == "" {
  2990. br.Msg = "条件值不能为空"
  2991. return
  2992. }
  2993. if req.ExcelRuleMappingId <= 0 {
  2994. br.Msg = "非法的管理规则ID"
  2995. return
  2996. }
  2997. err = excel2.ModifyExcelRule(req, c.Lang)
  2998. if err != nil {
  2999. br.Msg = "规则编辑失败"
  3000. br.ErrMsg = "规则编辑失败,Err:" + err.Error()
  3001. return
  3002. }
  3003. br.Msg = "编辑成功"
  3004. br.Ret = 200
  3005. br.Success = true
  3006. }
  3007. // DeleteExcelRule
  3008. // @Title 删除表格规则
  3009. // @Description 删除表格规则
  3010. // @Param request body request.ExcelRuleMappingReq true "type json string"
  3011. // @Success Ret=200 刷新成功
  3012. // @router /excel_info/rule/delete [post]
  3013. func (c *ExcelInfoController) DeleteExcelRule() {
  3014. br := new(models.BaseResponse).Init()
  3015. defer func() {
  3016. c.Data["json"] = br
  3017. c.ServeJSON()
  3018. }()
  3019. sysUser := c.SysUser
  3020. if sysUser == nil {
  3021. br.Msg = "请登录"
  3022. br.ErrMsg = "请登录,SysUser Is Empty"
  3023. br.Ret = 408
  3024. return
  3025. }
  3026. var req request.DeleteExcelRuleMappingReq
  3027. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  3028. if err != nil {
  3029. br.Msg = "参数解析异常!"
  3030. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3031. return
  3032. }
  3033. if req.ExcelRuleMappingId <= 0 {
  3034. br.Msg = "非法的管理规则ID"
  3035. return
  3036. }
  3037. err = excel3.DeleteExcelRuleMappingById(req.ExcelRuleMappingId)
  3038. if err != nil {
  3039. br.Msg = "规则删除失败"
  3040. br.ErrMsg = "规则删除失败,Err:" + err.Error()
  3041. return
  3042. }
  3043. br.Msg = "删除成功"
  3044. br.Ret = 200
  3045. br.Success = true
  3046. }
  3047. // GetExcelRuleList
  3048. // @Title 表格规则列表
  3049. // @Description 表格规则列表
  3050. // @Param ExcelInfoId query int true "id"
  3051. // @Success Ret=200 获取成功
  3052. // @router /excel_info/rule/list [get]
  3053. func (c *ExcelInfoController) GetExcelRuleList() {
  3054. br := new(models.BaseResponse).Init()
  3055. defer func() {
  3056. c.Data["json"] = br
  3057. c.ServeJSON()
  3058. }()
  3059. sysUser := c.SysUser
  3060. if sysUser == nil {
  3061. br.Msg = "请登录"
  3062. br.ErrMsg = "请登录,SysUser Is Empty"
  3063. br.Ret = 408
  3064. return
  3065. }
  3066. ExcelInfoId, _ := c.GetInt("ExcelInfoId")
  3067. if ExcelInfoId <= 0 {
  3068. br.Msg = "请选择表格"
  3069. return
  3070. }
  3071. items, err := excel2.GetExcelRuleList(ExcelInfoId)
  3072. if err != nil {
  3073. br.Msg = "管理规则编辑失败"
  3074. br.ErrMsg = "管理规则添加失败,Err:" + err.Error()
  3075. return
  3076. }
  3077. if items.List == nil {
  3078. items.List = []*excel3.ExcelInfoRuleMappingView{}
  3079. }
  3080. br.Data = items
  3081. br.Msg = "获取成功"
  3082. br.Ret = 200
  3083. br.Success = true
  3084. }
  3085. // GetExcelRuleDetail
  3086. // @Title 表格规则详情
  3087. // @Description 表格规则详情
  3088. // @Param ExcelInfoRuleMappingId query int true "id"
  3089. // @Success Ret=200 获取成功
  3090. // @router /excel_info/rule/detail [get]
  3091. func (c *ExcelInfoController) GetExcelRuleDetail() {
  3092. br := new(models.BaseResponse).Init()
  3093. defer func() {
  3094. c.Data["json"] = br
  3095. c.ServeJSON()
  3096. }()
  3097. sysUser := c.SysUser
  3098. if sysUser == nil {
  3099. br.Msg = "请登录"
  3100. br.ErrMsg = "请登录,SysUser Is Empty"
  3101. br.Ret = 408
  3102. return
  3103. }
  3104. excelInfoRuleMappingId, _ := c.GetInt("ExcelInfoRuleMappingId")
  3105. items, err := excel2.GetExcelRuleDetail(excelInfoRuleMappingId)
  3106. if err != nil {
  3107. br.Msg = "管理规则编辑失败"
  3108. br.ErrMsg = "管理规则添加失败,Err:" + err.Error()
  3109. return
  3110. }
  3111. br.Data = items
  3112. br.Msg = "获取成功"
  3113. br.Ret = 200
  3114. br.Success = true
  3115. }