excel_info.go 96 KB

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