excel_info.go 96 KB

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