excel_info.go 96 KB

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