excel_info.go 100 KB

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