excel_info.go 96 KB

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