excel_info.go 96 KB

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