excel_info.go 96 KB

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