excel_info.go 96 KB

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