excel_info.go 96 KB

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