12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657 |
- package excel
- import (
- "archive/zip"
- "encoding/json"
- "eta/eta_mobile/controllers"
- "eta/eta_mobile/models"
- "eta/eta_mobile/models/data_manage"
- excel3 "eta/eta_mobile/models/data_manage/excel"
- "eta/eta_mobile/models/data_manage/excel/request"
- "eta/eta_mobile/models/data_manage/excel/response"
- "eta/eta_mobile/services"
- "eta/eta_mobile/services/data"
- "eta/eta_mobile/services/data/data_manage_permission"
- excel2 "eta/eta_mobile/services/data/excel"
- "eta/eta_mobile/services/excel"
- "eta/eta_mobile/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/shopspring/decimal"
- "github.com/yidane/formula"
- "io"
- "os"
- "path/filepath"
- "strconv"
- "strings"
- "time"
- )
- // ExcelInfoController ETA表格管理
- type ExcelInfoController struct {
- controllers.BaseAuthController
- }
- // Add
- // @Title 新增表格接口
- // @Description 新增表格接口
- // @Param request body request.AddExcelInfoReq true "type json string"
- // @Success 200 {object} response.AddExcelInfoResp
- // @router /excel_info/add [post]
- func (c *ExcelInfoController) Add() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- cacheKey := "CACHE_EXCEL_TABLE_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- _ = utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!"
- return
- }
- var req request.AddExcelInfoReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.ExcelName = strings.Trim(req.ExcelName, " ")
- if req.ExcelName == "" {
- br.Msg = "请填写表格名称!"
- br.IsSendEmail = false
- return
- }
- if req.ExcelClassifyId <= 0 {
- br.Msg = "分类参数错误!"
- br.IsSendEmail = false
- return
- }
- excelClassify, err := excel3.GetExcelClassifyById(req.ExcelClassifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "分类不存在"
- br.ErrMsg = "分类不存在"
- br.IsSendEmail = false
- return
- }
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- if excelClassify == nil {
- br.Msg = "分类不存在"
- br.ErrMsg = "分类不存在"
- br.IsSendEmail = false
- return
- }
- var condition string
- var pars []interface{}
- condition += " AND excel_classify_id=? "
- pars = append(pars, req.ExcelClassifyId)
- condition += " AND excel_name=? "
- pars = append(pars, req.ExcelName)
- // 获取分类下是否存在该表格名称
- count, err := excel3.GetExcelInfoCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "判断表格名称是否存在失败"
- br.ErrMsg = "判断表格名称是否存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "表格名称已存在,请重新填写表格名称"
- br.IsSendEmail = false
- return
- }
- // 默认的excel类型是1
- if req.Source == 0 {
- req.Source = 1
- }
- content := req.Content
- // 引用的指标id
- edbInfoIdList := make([]int, 0)
- // 自定义表格
- if req.Source == 2 {
- jsonStrByte, err := json.Marshal(req.TableData)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,转json失败,Err:" + err.Error()
- return
- }
- var tableData request.TableDataReq
- err = json.Unmarshal(jsonStrByte, &tableData)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,json转结构体失败,Err:" + err.Error()
- return
- }
- tableDataConfig, err := excel2.GetTableDataConfig(tableData)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
- return
- }
- edbInfoIdList = tableDataConfig.EdbInfoIdList
- contentByte, err := json.Marshal(tableDataConfig)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取后,转json失败,Err:" + err.Error()
- return
- }
- content = string(contentByte)
- }
- // 混合表格
- if req.Source == 3 {
- contentByte, err := json.Marshal(req.TableData)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取后,转json失败,Err:" + err.Error()
- return
- }
- content = string(contentByte)
- var result request.MixedTableReq
- err = json.Unmarshal(contentByte, &result)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
- return
- }
- newResult, err, errMsg := excel2.GetMixedTableCellData(result, c.Lang)
- if err != nil {
- br.Msg = "获取失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
- return
- }
- edbInfoIdMap := make(map[int]int)
- for _, tmpV := range newResult {
- for _, v := range tmpV {
- if v.EdbInfoId > 0 {
- if _, ok := edbInfoIdMap[v.EdbInfoId]; !ok {
- edbInfoIdMap[v.EdbInfoId] = v.EdbInfoId
- edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
- }
- }
- }
- }
- }
- //获取该层级下最大的排序数
- maxSort, err := excel2.GetExcelClassifyMaxSort(req.ExcelClassifyId, req.Source)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "查询排序信息失败,Err:" + err.Error()
- return
- }
- timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
- excelInfo := &excel3.ExcelInfo{
- //ExcelInfoId: 0,
- ExcelName: req.ExcelName,
- Source: req.Source,
- ExcelType: req.ExcelType,
- UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + timestamp),
- ExcelClassifyId: req.ExcelClassifyId,
- SysUserId: sysUser.AdminId,
- SysUserRealName: sysUser.RealName,
- Content: content,
- ExcelImage: req.ExcelImage,
- Sort: maxSort + 1,
- IsDelete: 0,
- ModifyTime: time.Now(),
- CreateTime: time.Now(),
- SourcesFrom: req.SourcesFrom,
- }
- excelEdbMappingList := make([]*excel3.ExcelEdbMapping, 0)
- if len(edbInfoIdList) > 0 {
- for _, edbInfoId := range edbInfoIdList {
- excelEdbMappingList = append(excelEdbMappingList, &excel3.ExcelEdbMapping{
- //ExcelEdbMappingId: 0,
- //ExcelInfoId: 0,
- Source: excelInfo.Source,
- EdbInfoId: edbInfoId,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- })
- }
- }
- err = excel3.AddExcelInfo(excelInfo, excelEdbMappingList)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- // 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
- if req.Source == 1 {
- go excel2.UpdateExcelInfoFileUrl(excelInfo)
- }
- _, err = services.UpdateExcelEditMark(excelInfo.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
- if err != nil {
- br.Msg = "查询标记状态失败"
- br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
- return
- }
- resp := new(response.AddExcelInfoResp)
- resp.ExcelInfoId = excelInfo.ExcelInfoId
- resp.UniqueCode = excelInfo.UniqueCode
- //新增操作日志
- //{
- // excelLog := &data_manage.ExcelInfoLog{
- // //ExcelInfoLogId: 0,
- // ExcelInfoId: excelInfo.ExcelInfoId,
- // ExcelName: req.ExcelName,
- // ExcelClassifyId: req.ExcelClassifyId,
- // SysUserId: sysUser.AdminId,
- // SysUserRealName: sysUser.RealName,
- // UniqueCode: excelInfo.UniqueCode,
- // CreateTime: time.Now(),
- // Content: string(c.Ctx.Input.RequestBody),
- // Status: "新增表格",
- // Method: c.Ctx.Input.URI(),
- // }
- // go data_manage.AddExcelInfoLog(excelLog)
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // List
- // @Title ETA表格列表接口
- // @Description ETA表格列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ExcelClassifyId query int true "分类id"
- // @Param Keyword query string true "搜索关键词"
- // @Param AdminId query int false "创建人id"
- // @Param Source query int true "格来源,1:excel插件的表格,2:自定义表格,3:混合表格,默认:1"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} response.ExcelListResp
- // @router /excel_info/list [get]
- func (c *ExcelInfoController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- excelClassifyId, _ := c.GetInt("ExcelClassifyId")
- pageSize, _ := c.GetInt("PageSize")
- currentIndex, _ := c.GetInt("CurrentIndex")
- keyword := c.GetString("Keyword")
- adminId, _ := c.GetInt("AdminId")
- source, _ := c.GetInt("Source")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- // 如果没有传的话,那就是代表前三种表格
- if source <= 0 {
- condition += " AND source in (?,?,?) "
- pars = append(pars, utils.EXCEL_DEFAULT, utils.TIME_TABLE, utils.MIXED_TABLE)
- } else {
- condition += " AND source = ? "
- pars = append(pars, source)
- if source == utils.BALANCE_TABLE { //平衡表的列表只显示动态表的一级表(不显示子表和静态表)
- condition += " AND parent_id = 0 AND balance_type=0 "
- }
- }
- // 筛选分类
- if excelClassifyId > 0 {
- _, err := excel3.GetExcelClassifyById(excelClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取表格信息失败"
- br.ErrMsg = "获取信息失败,GetExcelClassify,Err:" + err.Error()
- return
- }
- childClassify, e, _ := excel2.GetChildClassifyByClassifyId(excelClassifyId, source)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
- return
- }
- if len(childClassify) == 0 {
- condition += " AND excel_classify_id = ? "
- pars = append(pars, excelClassifyId)
- } else {
- classifyIds := []int{excelClassifyId}
- for _, v := range childClassify {
- classifyIds = append(classifyIds, v.ExcelClassifyId)
- }
- condition += fmt.Sprintf(` AND excel_classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
- pars = append(pars, classifyIds)
- }
- }
- if keyword != "" {
- condition += ` AND ( excel_name LIKE ? )`
- pars = utils.GetLikeKeywordPars(pars, keyword, 1)
- }
- if adminId > 0 {
- condition += " AND sys_user_id = ? "
- pars = append(pars, adminId)
- }
- //只看我的
- isShowMe, _ := c.GetBool("IsShowMe")
- if isShowMe {
- condition += " AND sys_user_id = ? "
- pars = append(pars, sysUser.AdminId)
- }
- //获取表格信息
- list, err := excel3.GetNoContentExcelListByCondition(condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取表格信息失败"
- br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
- return
- }
- lenList := len(list)
- if list == nil || lenList <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- list = make([]*excel3.MyExcelInfoList, 0)
- }
- if lenList > 0 {
- classifyIdList := make([]int, 0)
- for _, v := range list {
- classifyIdList = append(classifyIdList, v.ExcelClassifyId)
- }
- classifyMap := make(map[int]*excel3.ExcelClassify)
- // 分类信息
- {
- classifyList, err := excel3.GetClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取表格列表信息失败"
- br.ErrMsg = "获取表格分类列表数据失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ExcelClassifyId] = v
- }
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserExcelAndClassifyPermissionList(c.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- for _, v := range list {
- // 数据权限
- if classifyInfo, ok := classifyMap[v.ExcelClassifyId]; ok {
- v.HaveOperaAuth = data_manage_permission.CheckExcelPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.ExcelInfoId, v.ExcelClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- }
- }
- // 总数据量
- dataCount, err := excel3.GetExcelListCountByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取表格列表信息失败"
- br.ErrMsg = "获取表格列表数据总数失败,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- resp := response.ExcelListResp{
- Paging: page,
- List: list,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Detail
- // @Title 获取表格详情
- // @Description 获取表格详情接口
- // @Param ExcelInfoId query int true "表格id"
- // @Success 200 {object} data_manage.ExcelInfo
- // @router /excel_info/detail [get]
- func (c *ExcelInfoController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- excelInfoId, _ := c.GetInt("ExcelInfoId")
- if excelInfoId <= 0 {
- br.Msg = "请选择表格"
- br.ErrMsg = "ExcelInfoId未传"
- br.IsSendEmail = false
- return
- }
- // 获取数据详情
- excelDetail, errMsg, err := excel2.GetExcelDetailInfoByExcelInfoId(excelInfoId, c.SysUser.AdminId, c.Lang)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- // 编辑状态
- markStatus, err := services.UpdateExcelEditMark(excelInfoId, sysUser.AdminId, 2, sysUser.RealName)
- if err != nil {
- br.Msg = "查询标记状态失败"
- br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
- return
- }
- if markStatus.Status == 0 {
- excelDetail.CanEdit = true
- } else {
- excelDetail.Editor = markStatus.Editor
- }
- // excel表格按钮权限
- excelDetail.Button = excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source, excelDetail.HaveOperaAuth)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = excelDetail
- }
- // Edit
- // @Title 编辑表格接口
- // @Description 新增表格接口
- // @Param request body request.EditExcelInfoReq true "type json string"
- // @Success 200 {object} response.AddExcelInfoResp
- // @router /excel_info/edit [post]
- func (c *ExcelInfoController) Edit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- var req request.EditExcelInfoReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ExcelInfoId <= 0 {
- br.Msg = "请传入ETA表格标识!"
- return
- }
- cacheKey := "CACHE_TABLE_INFO_EDIT_" + strconv.Itoa(req.ExcelInfoId)
- defer func() {
- if deleteCache {
- _ = utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!"
- return
- }
- req.ExcelName = strings.Trim(req.ExcelName, " ")
- if req.ExcelName == "" {
- br.Msg = "请填写表格名称!"
- br.IsSendEmail = false
- return
- }
- if req.ExcelClassifyId <= 0 {
- br.Msg = "分类参数错误!"
- br.IsSendEmail = false
- return
- }
- // 标记编辑状态
- markRet, err := services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
- if err != nil {
- br.Msg = "查询标记状态失败"
- br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
- return
- }
- if markRet.Status == 1 {
- br.Ret = 200
- br.Success = true
- br.Data = markRet
- return
- }
- excelClassify, err := excel3.GetExcelClassifyById(req.ExcelClassifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "分类不存在"
- br.ErrMsg = "分类不存在"
- br.IsSendEmail = false
- return
- }
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- if excelClassify == nil {
- br.Msg = "分类不存在"
- br.ErrMsg = "分类不存在"
- br.IsSendEmail = false
- return
- }
- //判断表格是否存在
- var condition string
- var pars []interface{}
- condition += " AND excel_info_id != ? "
- pars = append(pars, req.ExcelInfoId)
- condition += " AND excel_classify_id=? "
- pars = append(pars, req.ExcelClassifyId)
- condition += " AND excel_name=? "
- pars = append(pars, req.ExcelName)
- // 获取分类下是否存在该表格名称
- count, err := excel3.GetExcelInfoCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "ETA判断表格名称是否存在失败"
- br.ErrMsg = "判断ETA表格名称是否存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "ETA表格名称已存在,请重新填写"
- br.IsSendEmail = false
- return
- }
- excelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
- if err != nil {
- br.Msg = "获取ETA表格失败"
- br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
- return
- }
- // 操作权限校验
- {
- // 数据权限
- haveOperaAuth, err := data_manage_permission.CheckExcelPermissionByExcelInfoId(excelInfo.ExcelInfoId, excelInfo.ExcelClassifyId, excelInfo.IsJoinPermission, c.SysUser.AdminId)
- if err != nil {
- br.Msg = "获取ETA表格失败"
- br.ErrMsg = "获取ETA表格权限失败,Err:" + err.Error()
- return
- }
- button := excel2.GetExcelInfoOpButton(sysUser, excelInfo.SysUserId, excelInfo.Source, haveOperaAuth)
- if !button.OpButton {
- br.Msg = "无操作权限"
- br.Msg = "无操作权限"
- br.IsSendEmail = false
- return
- }
- }
- // 引用的指标id
- edbInfoIdList := make([]int, 0)
- content := req.Content
- switch excelInfo.Source {
- case utils.TIME_TABLE: // 自定义表格
- jsonStrByte, err := json.Marshal(req.TableData)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,转json失败,Err:" + err.Error()
- return
- }
- var tableData request.TableDataReq
- err = json.Unmarshal(jsonStrByte, &tableData)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,json转结构体失败,Err:" + err.Error()
- return
- }
- edbInfoIdList = tableData.EdbInfoIdList
- tableDataConfig, err := excel2.GetTableDataConfig(tableData)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
- return
- }
- contentByte, err := json.Marshal(tableDataConfig)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取后,转json失败,Err:" + err.Error()
- return
- }
- content = string(contentByte)
- case utils.MIXED_TABLE: // 混合表格
- contentByte, err := json.Marshal(req.TableData)
- if err != nil {
- br.Msg = "混合表格数据获取失败"
- br.ErrMsg = "混合表格数据获取后,转json失败,Err:" + err.Error()
- return
- }
- content = string(contentByte)
- var result request.MixedTableReq
- err = json.Unmarshal(contentByte, &result)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
- return
- }
- newResult, err, errMsg := excel2.GetMixedTableCellData(result, c.Lang)
- if err != nil {
- br.Msg = "获取失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
- return
- }
- edbInfoIdMap := make(map[int]int)
- for _, tmpV := range newResult {
- for _, v := range tmpV {
- if v.EdbInfoId > 0 {
- if _, ok := edbInfoIdMap[v.EdbInfoId]; !ok {
- edbInfoIdMap[v.EdbInfoId] = v.EdbInfoId
- edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
- }
- }
- }
- }
- }
- excelInfo.ModifyTime = time.Now()
- excelInfo.ExcelName = req.ExcelName
- excelInfo.ExcelType = req.ExcelType
- excelInfo.ExcelClassifyId = req.ExcelClassifyId
- excelInfo.ExcelImage = req.ExcelImage
- excelInfo.Content = content
- excelInfo.SourcesFrom = req.SourcesFrom
- // 自动保存时不会传缩略图,也就不更新这个字段
- var updateExcelInfoParams []string
- if req.ExcelImage != "" {
- updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "ExcelImage", "Content", "SourcesFrom"}
- } else {
- updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "Content", "SourcesFrom"}
- }
- excelEdbMappingList := make([]*excel3.ExcelEdbMapping, 0)
- if len(edbInfoIdList) > 0 {
- for _, edbInfoId := range edbInfoIdList {
- excelEdbMappingList = append(excelEdbMappingList, &excel3.ExcelEdbMapping{
- //ExcelEdbMappingId: 0,
- ExcelInfoId: excelInfo.ExcelInfoId,
- Source: excelInfo.Source,
- EdbInfoId: edbInfoId,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- })
- }
- }
- err = excel3.EditExcelInfo(excelInfo, updateExcelInfoParams, excelEdbMappingList)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- // 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
- if excelInfo.Source == 1 {
- go excel2.UpdateExcelInfoFileUrl(excelInfo)
- }
- // 加入草稿
- {
- excelDraftInfo := &excel3.ExcelDraft{
- //ExcelDraftId: 0,
- ExcelId: req.ExcelInfoId,
- Name: req.ExcelName,
- Content: content,
- OpUserId: sysUser.AdminId,
- OpUserName: sysUser.RealName,
- CreateTime: time.Now(),
- }
- err = excel3.AddExcelDraft(excelDraftInfo)
- }
- resp := response.AddExcelInfoResp{
- ExcelInfoId: excelInfo.ExcelInfoId,
- UniqueCode: excelInfo.UniqueCode,
- }
- //删除公共图库那边的缓存
- _ = utils.Rc.Delete(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelInfo.UniqueCode)
- br.Ret = 200
- br.Success = true
- br.Msg = "修改成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // Move
- // @Title 移动表格接口
- // @Description 移动表格接口
- // @Param request body request.MoveExcelInfoReq true "type json string"
- // @Success Ret=200 移动成功
- // @router /excel_info/move [post]
- func (c *ExcelInfoController) Move() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- /*
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.MoveExcelInfoReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ExcelInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "表格id小于等于0"
- br.IsSendEmail = false
- return
- }
- if req.ExcelClassifyId <= 0 {
- br.Msg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- //判断分类是否存在
- _, err = excel3.GetExcelClassifyById(req.ExcelClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取分类信息失败" + err.Error()
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "分类已被删除,不可移动,请刷新页面"
- br.ErrMsg = "分类已被删除,不可移动,请刷新页面"
- br.IsSendEmail = false
- }
- return
- }
- // 获取表格信息
- excelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
- return
- }
- //如果改变了分类,那么移动该表格数据
- if excelInfo.ExcelClassifyId != req.ExcelClassifyId {
- //查询需要修改的分类下是否存在同一个表格名称
- tmpExcelInfo, tmpErr := excel3.GetExcelInfoByClassifyIdAndName(req.ExcelClassifyId, excelInfo.ExcelName)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- br.Msg = "移动失败"
- br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
- return
- }
- if tmpExcelInfo != nil {
- br.Msg = "移动失败,同一个分类下表格名称不允许重复"
- br.ErrMsg = "移动失败,同一个分类下表格名称不允许重复"
- br.IsSendEmail = false
- return
- }
- // 变更表格的所属分类
- excelInfo.ExcelClassifyId = req.ExcelClassifyId
- err = excelInfo.Update([]string{"ExcelClassifyId"})
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "移动失败,Err:" + err.Error()
- return
- }
- }
- //移动排序
- updateCol := make([]string, 0)
- //如果有传入 上一个兄弟节点分类id
- if req.PrevExcelInfoId > 0 {
- prevExcelInfo, err := excel3.GetExcelInfoById(req.PrevExcelInfoId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果是移动在两个兄弟节点之间
- if req.NextExcelInfoId > 0 {
- //下一个兄弟节点
- nextExcelInfo, err := excel3.GetExcelInfoById(req.NextExcelInfoId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
- if prevExcelInfo.Sort == nextExcelInfo.Sort || prevExcelInfo.Sort == excelInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = excel3.UpdateExcelInfoSortByClassifyId(prevExcelInfo.ExcelClassifyId, prevExcelInfo.Sort, prevExcelInfo.ExcelInfoId, updateSortStr)
- } else {
- //如果下一个兄弟的排序权重正好是上个兄弟节点下一层,那么需要再加一层了
- if nextExcelInfo.Sort-prevExcelInfo.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = excel3.UpdateExcelInfoSortByClassifyId(prevExcelInfo.ExcelClassifyId, prevExcelInfo.Sort, prevExcelInfo.ExcelInfoId, updateSortStr, source)
- }
- }
- }
- // 变更表格在当前分类下的排序
- excelInfo.Sort = prevExcelInfo.Sort + 1
- excelInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
- firstClassify, err := excel3.GetFirstExcelInfoByClassifyId(req.ExcelClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "移动失败"
- br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
- return
- }
- //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
- if firstClassify != nil && firstClassify.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = excel3.UpdateExcelInfoSortByClassifyId(firstClassify.ExcelClassifyId, 0, firstClassify.ExcelInfoId+1, updateSortStr)
- }
- // 变更表格在当前分类下的排序
- excelInfo.Sort = 0 //那就是排在第一位
- excelInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
- //更新
- if len(updateCol) > 0 {
- err = excelInfo.Update(updateCol)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- }
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- //{
- // ExcelLog := new(data_manage.ExcelInfoLog)
- // ExcelLog.ExcelName = ExcelInfo.ExcelName
- // ExcelLog.ExcelInfoId = req.ExcelInfoId
- // ExcelLog.ExcelClassifyId = ExcelInfo.ExcelClassifyId
- // ExcelLog.SysUserId = sysUser.AdminId
- // ExcelLog.SysUserRealName = sysUser.RealName
- // ExcelLog.UniqueCode = ExcelInfo.UniqueCode
- // ExcelLog.CreateTime = time.Now()
- // ExcelLog.Content = string(c.Ctx.Input.RequestBody)
- // ExcelLog.Status = "移动表格"
- // ExcelLog.Method = c.Ctx.Input.URL()
- // go data_manage.AddExcelInfoLog(ExcelLog)
- //}
- */
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "移动成功"
- }
- // Delete
- // @Title 删除表格接口
- // @Description 删除表格接口
- // @Param request body request.DeleteExcelInfoReq true "type json string"
- // @Success Ret=200 删除成功
- // @router /excel_info/delete [post]
- func (c *ExcelInfoController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- resp := response.AddExcelInfoResp{}
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.DeleteExcelInfoReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ExcelInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "表格id小于等于0"
- br.IsSendEmail = false
- return
- }
- // 获取表格信息
- excelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
- return
- }
- // 删除excel
- err, errMsg, isSendEmail := excel2.Delete(excelInfo, sysUser)
- if err != nil {
- br.Msg = "删除失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "删除失败,Err:" + err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- // 返回下一个表格的信息
- {
- var nextItem *excel3.ExcelInfo
- var condition string
- var pars []interface{}
- condition += " AND excel_classify_id=? "
- pars = append(pars, excelInfo.ExcelClassifyId)
- condition += " AND sort>=? "
- pars = append(pars, excelInfo.Sort)
- nextItem, err = excel3.GetNextExcelInfoByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "删除失败"
- br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
- return
- }
- // 如果没找到,那么查找下一个分类的第一个表格
- if nextItem == nil {
- currClassifyInfo, err := excel3.GetExcelClassifyById(excelInfo.ExcelClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "删除失败"
- br.ErrMsg = "获取当前表格分类信息失败,Err:" + err.Error()
- return
- }
- //condition += " AND level=3 "
- //pars = append(pars, chartInfo.ExcelClassifyId)
- //var condition string
- //var pars []interface{}
- //condition += " AND sort>=? ORDER BY excel_classify_id ASC LIMIT 1 "
- //pars = append(pars, currClassifyInfo.Sort)
- //
- //classifyItem, err := data_manage.GetNextExcelClassifyByCondition(condition, pars)
- //if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "删除失败"
- // br.ErrMsg = "获取下一级表格分类信息失败,Err:" + err.Error()
- // return
- //}
- //if classifyItem != nil {
- // nextItem, err = data_manage.GetNextExcelInfo(excelInfo.ExcelClassifyId,)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "删除失败"
- // br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
- // return
- // }
- //}
- nextItem, err = excel3.GetNextExcelInfo(excelInfo.ExcelClassifyId, currClassifyInfo.Sort, currClassifyInfo.Source)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "删除失败"
- br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
- return
- }
- }
- // 如果找到下一个表格了,那么就返回
- if nextItem != nil {
- resp = response.AddExcelInfoResp{
- ExcelInfoId: nextItem.ExcelInfoId,
- UniqueCode: nextItem.UniqueCode,
- }
- }
- }
- //删除公共图库那边的缓存
- _ = utils.Rc.Delete(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL)
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Data = resp
- br.Msg = "删除成功"
- }
- // AddDraft
- // @Title 新增表格草稿接口
- // @Description 新增表格草稿接口
- // @Param request body request.AddExcelDraftReq true "type json string"
- // @Success Ret=200 添加成功
- // @router /excel_info/draft/add [post]
- func (c *ExcelInfoController) AddDraft() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.AddExcelDraftReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.ExcelName = strings.Trim(req.ExcelName, " ")
- if req.ExcelName == "" {
- br.Msg = "请填写表格名称!"
- br.IsSendEmail = false
- return
- }
- if req.ExcelClassifyId <= 0 {
- br.Msg = "分类参数错误!"
- br.IsSendEmail = false
- return
- }
- excelClassify, err := excel3.GetExcelClassifyById(req.ExcelClassifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "分类不存在"
- br.ErrMsg = "分类不存在"
- br.IsSendEmail = false
- return
- }
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- if excelClassify == nil {
- br.Msg = "分类不存在"
- br.ErrMsg = "分类不存在"
- br.IsSendEmail = false
- return
- }
- var condition string
- var pars []interface{}
- condition += " AND excel_classify_id=? "
- pars = append(pars, req.ExcelClassifyId)
- condition += " AND excel_name=? "
- pars = append(pars, req.ExcelName)
- // 获取分类下是否存在该表格名称
- _, err = excel3.GetExcelInfoById(req.ExcelInfoId)
- if err != nil {
- br.Msg = "判断表格名称是否存在失败"
- br.ErrMsg = "判断表格名称是否存在失败,Err:" + err.Error()
- return
- }
- excelDraftInfo := &excel3.ExcelDraft{
- //ExcelDraftId: 0,
- ExcelId: req.ExcelInfoId,
- Name: req.ExcelName,
- Content: req.Content,
- OpUserId: sysUser.AdminId,
- OpUserName: sysUser.RealName,
- CreateTime: time.Now(),
- }
- err = excel3.AddExcelDraft(excelDraftInfo)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- _, err = services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
- if err != nil {
- br.Msg = "查询标记状态失败"
- br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "添加成功"
- }
- // GetExcelTableData
- // @Title 获取excel表格的table数据
- // @Description 获取excel表格的table数据接口
- // @Param UniqueCode query string true "表格code"
- // @Param FromScene query int true "场景来源,1:智能研报,2:研报列表;3:英文研报;4:中文PPT;5:英文PPT"
- // @Success 200 {object} response.ExcelTableDetailResp
- // @router /excel_info/table_data [get]
- func (c *ExcelInfoController) GetExcelTableData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- uniqueCode := c.GetString("UniqueCode")
- fromScene, _ := c.GetInt("FromScene", 0)
- var err error
- if uniqueCode == `` {
- br.Msg = "请选择表格"
- br.ErrMsg = "UniqueCode未传"
- br.IsSendEmail = false
- return
- }
- //获取eta表格信息
- excelInfo, err := excel3.GetExcelInfoByUniqueCode(uniqueCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取ETA表格信息失败,Err:" + err.Error()
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "ETA表格被删除,请刷新页面"
- br.ErrMsg = "ETA表格被删除,请刷新页面,Err:" + err.Error()
- br.IsSendEmail = false
- }
- return
- }
- var tableData excel.TableData
- var excelSource, excelSourceEn string
- switch excelInfo.Source {
- case utils.EXCEL_DEFAULT:
- luckySheetData, err := excel.GetLuckySheetData(excelInfo.Content)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取excel数据失败,Err:" + err.Error()
- return
- }
- tableData, err = luckySheetData.GetTableDataByLuckySheetDataStr(true)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "转换成table失败,Err:" + err.Error()
- return
- }
- case utils.TIME_TABLE:
- var tableDataConfig excel2.TableDataConfig
- err = json.Unmarshal([]byte(excelInfo.Content), &tableDataConfig)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
- return
- }
- result, err := excel2.GetDataByTableDataConfig(tableDataConfig)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取最新的表格数据失败,Err:" + err.Error()
- return
- }
- tableData, err = excel.GetTableDataByCustomData(excelInfo.ExcelType, result)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "转换成table失败,Err:" + err.Error()
- return
- }
- sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList(result.EdbInfoIdList)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
- return
- }
- excelSource = strings.Join(sourceNameList, ",")
- excelSourceEn = strings.Join(sourceNameEnList, ",")
- case utils.MIXED_TABLE:
- var result request.MixedTableReq
- err = json.Unmarshal([]byte(excelInfo.Content), &result)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
- return
- }
- newResult, err, errMsg := excel2.GetMixedTableCellData(result, c.Lang)
- if err != nil {
- br.Msg = "获取失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
- return
- }
- tableData, err = excel.GetTableDataByMixedTableData(newResult, true)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "转换成table失败,Err:" + err.Error()
- return
- }
- edbInfoIds := make([]int, 0)
- edbInfoIdExist := make(map[int]bool)
- if len(newResult) > 0 {
- for _, t := range newResult {
- for _, v := range t {
- if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
- edbInfoIdExist[v.EdbInfoId] = true
- edbInfoIds = append(edbInfoIds, v.EdbInfoId)
- }
- }
- }
- }
- sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList(edbInfoIds)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
- return
- }
- excelSource = strings.Join(sourceNameList, ",")
- excelSourceEn = strings.Join(sourceNameEnList, ",")
- }
- tableData = excel.HandleTableCell(tableData)
- config := response.ExcelTableDetailConfigResp{
- FontSize: 9,
- }
- // 获取配置的字体大小
- confName := models.FromSceneMap[fromScene]
- if confName != `` {
- busConf, err := models.GetBusinessConfByKey(confName)
- if err == nil {
- sizeDeci, err := decimal.NewFromString(busConf.ConfVal)
- if err == nil {
- config.FontSize = int(sizeDeci.IntPart())
- }
- }
- }
- resp := response.ExcelTableDetailResp{
- UniqueCode: excelInfo.UniqueCode,
- ExcelImage: excelInfo.ExcelImage,
- ExcelName: excelInfo.ExcelName,
- TableInfo: tableData,
- Config: config,
- SourcesFrom: excelInfo.SourcesFrom,
- ExcelSource: excelSource,
- ExcelSourceEn: excelSourceEn,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- //func init() {
- //
- // excelInfo, err := data_manage.GetExcelInfoById(52)
- // if err != nil {
- // fmt.Println("err:", err)
- // return
- // }
- //
- // luckySheetData, err := excel.GetLuckySheetData(excelInfo.Content)
- // if err != nil {
- // fmt.Println("err:", err)
- // return
- // }
- // //_, err = luckySheetData.GetTableDataByLuckySheetDataStr()
- // downloadFilePath, err := luckySheetData.ToExcel()
- // if err != nil {
- // fmt.Println("err:", err)
- // return
- // }
- // fmt.Println(downloadFilePath)
- //
- // //fmt.Println(excel.GetColumnName(988, 283))
- //}
- // Calculate
- // @Title 公式计算接口
- // @Description 公式计算接口
- // @Param request body request.CalculateReq true "type json string"
- // @router /excel_info/table/calculate [post]
- func (c *ExcelInfoController) Calculate() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.CalculateReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CalculateFormula == "" {
- br.Msg = "请填写公式"
- return
- }
- calculateFormula := req.CalculateFormula
- calculateFormula = strings.TrimPrefix(calculateFormula, "=")
- calculateFormula = strings.Replace(calculateFormula, "(", "(", -1)
- calculateFormula = strings.Replace(calculateFormula, ")", ")", -1)
- calculateFormula = strings.Replace(calculateFormula, ",", ",", -1)
- calculateFormula = strings.Replace(calculateFormula, "。", ".", -1)
- calculateFormula = strings.Replace(calculateFormula, "%", "*0.01", -1)
- formulaFormStr := utils.ReplaceFormula(req.TagMap, calculateFormula)
- //计算公式异常,那么就移除该指标
- if formulaFormStr == `` {
- //removeDateList = append(removeDateList, sk)
- //fmt.Println("异常了")
- br.Msg = "公式异常"
- br.ErrMsg = "公式异常"
- return
- }
- expression := formula.NewExpression(formulaFormStr)
- calResult, err := expression.Evaluate()
- if err != nil {
- br.Msg = "计算失败"
- br.ErrMsg = "计算失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr
- // 分母为0的报错
- if strings.Contains(err.Error(), "divide by zero") {
- br.Msg = "分母不能为0"
- br.ErrMsg = "分母不能为空,计算公式:" + formulaFormStr
- br.IsSendEmail = false
- }
- return
- }
- // 如果计算结果是NAN,那么就提示报错
- if calResult.IsNan() {
- br.Msg = "计算失败"
- br.ErrMsg = "计算失败:计算结果是:NAN;formulaStr:" + formulaFormStr
- return
- }
- // 计算结果格式化
- calFloat, e := calResult.Float64()
- if e != nil {
- br.Msg = "计算失败"
- br.ErrMsg = "计算失败, Err: " + e.Error()
- return
- }
- calVal := utils.FormatTableDataShowValue(calFloat)
- //calVal := calResult.String()
- //if err != nil {
- // br.Msg = "计算失败"
- // br.ErrMsg = "计算失败,结果转 string 失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr
- // return
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "计算成功"
- br.Data = calVal
- }
- // GetFirstEdbData
- // @Title 获取未来日期数据接口
- // @Description 获取未来日期数据接口
- // @Param EdbInfoId query int true "指标id"
- // @Param Num query int true "默认期数"
- // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒序`,不传默认倒序"
- // @router /excel_info/table/first_edb_data_list [get]
- func (c *ExcelInfoController) GetFirstEdbData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := c.GetInt("EdbInfoId")
- num, _ := c.GetInt("Num")
- sortType := c.GetString("SortType")
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- if num <= 0 {
- br.Msg = "期数必须大于0"
- br.IsSendEmail = false
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
- return
- }
- dataList, err := excel2.GetFirstEdbDataList(edbInfo, num, []string{})
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
- return
- }
- // 默认是倒序返回的数据,如果要正序的话,那么翻转下就好了
- if sortType == "asc" {
- for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
- dataList[i], dataList[j] = dataList[j], dataList[i]
- }
- }
- sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList([]int{edbInfoId})
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
- return
- }
- excelSource := strings.Join(sourceNameList, ",")
- excelSourceEn := strings.Join(sourceNameEnList, ",")
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = response.TableDataItem{
- EdbInfoId: edbInfoId,
- Data: dataList,
- ExcelSource: excelSource,
- ExcelSourceEn: excelSourceEn,
- }
- }
- // GetOtherEdbData
- // @Title 获取指定日期数据接口
- // @Description 获取未来日期数据接口
- // @Param request body request.GetOtherEdbDateDataReq true "type json string"
- // @router /excel_info/table/other_edb_data_list [post]
- func (c *ExcelInfoController) GetOtherEdbData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.GetOtherEdbDateDataReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.EdbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- if len(req.DateList) <= 0 {
- br.Msg = "请选择日期"
- br.IsSendEmail = false
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
- return
- }
- dataList, err := excel2.GetOtherEdbDataList(edbInfo, req.DateList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
- return
- }
- // 默认是倒序返回的数据,如果要正序的话,那么翻转下就好了
- if req.SortType == "asc" {
- for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
- dataList[i], dataList[j] = dataList[j], dataList[i]
- }
- }
- sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList([]int{req.EdbInfoId})
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
- return
- }
- excelSource := strings.Join(sourceNameList, ",")
- excelSourceEn := strings.Join(sourceNameEnList, ",")
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = response.TableDataItem{
- EdbInfoId: req.EdbInfoId,
- Data: dataList,
- ExcelSource: excelSource,
- ExcelSourceEn: excelSourceEn,
- }
- }
- // GetFutureDateData
- // @Title 获取未来日期数据接口
- // @Description 获取未来日期数据接口
- // @Param request body request.GetFutureDateDataReq true "type json string"
- // @router /excel_info/table/future_date_list [post]
- func (c *ExcelInfoController) GetFutureDateData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.GetFutureDateDataReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.StartDate == `` {
- br.Msg = "开始日期未传"
- br.IsSendEmail = false
- return
- }
- startDate, err := time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
- if err != nil {
- br.Msg = "开始日期异常"
- br.ErrMsg = fmt.Sprint("开始日期异常,startDate:", req.StartDate, ";err:", err.Error())
- return
- }
- if len(req.EdbInfoIdList) <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- baseEdbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoIdList[0])
- if err != nil {
- br.Msg = "查找指标失败"
- br.Msg = "查找指标失败,err:" + err.Error()
- return
- }
- // 第一个指标的数据列表
- var firstEdbDataList []*data_manage.EdbDataList
- {
- switch baseEdbInfo.EdbInfoType {
- case 0:
- firstEdbDataList, err = data_manage.GetEdbDataList(baseEdbInfo.Source, baseEdbInfo.SubSource, baseEdbInfo.EdbInfoId, req.StartDate, ``)
- case 1:
- _, firstEdbDataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(baseEdbInfo.EdbInfoId, req.StartDate, ``, false)
- default:
- br.Msg = "指标类型异常"
- br.ErrMsg = fmt.Sprint("获取失败,指标类型异常", baseEdbInfo.EdbInfoType)
- br.IsSendEmail = false
- return
- }
- }
- dateList := make([]time.Time, 0)
- if req.DateType == 1 {
- num := req.Num
- i := 0 // 数据中有的日期数
- for _, v := range firstEdbDataList {
- tmpDate, err := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
- if err != nil {
- br.Msg = "结束日期异常"
- br.ErrMsg = fmt.Sprint("结束日期异常,startDate:", req.EndDate, ";err:", err.Error())
- return
- }
- if tmpDate.After(startDate) {
- dateList = append(dateList, tmpDate)
- startDate = tmpDate
- i++
- }
- if i >= num {
- break
- }
- }
- num = num - i
- if num > 0 {
- tmpDateList := utils.GetPredictEdbDayListByNum(startDate, num, baseEdbInfo.Frequency)
- dateList = append(dateList, tmpDateList...)
- }
- } else {
- if req.EndDate == `` {
- br.Msg = "结束日期未传"
- br.IsSendEmail = false
- return
- }
- endDate, err := time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
- if err != nil {
- br.Msg = "结束日期异常"
- br.ErrMsg = fmt.Sprint("结束日期异常,startDate:", req.EndDate, ";err:", err.Error())
- return
- }
- for _, v := range firstEdbDataList {
- tmpDate, err := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
- if err != nil {
- br.Msg = "结束日期异常"
- br.ErrMsg = fmt.Sprint("结束日期异常,startDate:", req.EndDate, ";err:", err.Error())
- return
- }
- if tmpDate.Equal(endDate) || (tmpDate.Before(endDate) && tmpDate.After(startDate)) {
- dateList = append(dateList, tmpDate)
- startDate = tmpDate
- }
- }
- if startDate.Before(endDate) {
- tmpDateList := utils.GetPredictEdbDayListByEndDate(startDate, endDate, baseEdbInfo.Frequency)
- dateList = append(dateList, tmpDateList...)
- }
- }
- // 获取所有的指标信息
- edbInfoMap := make(map[int]*data_manage.EdbInfo)
- {
- edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,err:" + err.Error()
- return
- }
- for _, v := range edbInfoList {
- edbInfoMap[v.EdbInfoId] = v
- }
- }
- result := make([]response.TableDataItem, 0)
- dateStrList := make([]string, 0)
- lenDate := len(dateList)
- if lenDate > 0 {
- for i := lenDate - 1; i >= 0; i-- {
- dateStrList = append(dateStrList, dateList[i].Format(utils.FormatDate))
- }
- for _, v := range req.EdbInfoIdList {
- tmpEdbInfo, ok := edbInfoMap[v]
- if !ok {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,err:" + err.Error()
- return
- }
- dataList, err := excel2.GetOtherEdbDataList(tmpEdbInfo, dateStrList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
- return
- }
- result = append(result, response.TableDataItem{
- EdbInfoId: v,
- Data: dataList,
- })
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = result
- }
- // GetHistoryDateData
- // @Title 获取历史日期数据接口
- // @Description 获取历史日期数据接口
- // @Param request body request.GetFutureDateDataReq true "type json string"
- // @router /excel_info/table/history_date_list [post]
- func (c *ExcelInfoController) GetHistoryDateData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.GetHistoryDateDataReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.EndDate == `` {
- br.Msg = "结束日期未传"
- br.IsSendEmail = false
- return
- }
- if len(req.EdbInfoIdList) <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- // 获取所有的指标信息
- edbInfoMap := make(map[int]*data_manage.EdbInfo)
- {
- edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,err:" + err.Error()
- return
- }
- for _, v := range edbInfoList {
- edbInfoMap[v.EdbInfoId] = v
- }
- }
- result := make([]response.TableDataItem, 0)
- dateStrList := make([]string, 0)
- // 获取A列指标的历史数据
- {
- tmpEdbInfo, ok := edbInfoMap[req.EdbInfoIdList[0]]
- if !ok {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,err:" + err.Error()
- return
- }
- firstDataList, err := excel2.GetFirstHistoryEdbDataList(tmpEdbInfo, req.Num, req.EndDate)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
- return
- }
- result = append(result, response.TableDataItem{
- EdbInfoId: req.EdbInfoIdList[0],
- Data: firstDataList,
- })
- for _, v := range firstDataList {
- dateStrList = append(dateStrList, v.DataTime)
- }
- }
- if len(dateStrList) > 0 {
- for k, v := range req.EdbInfoIdList {
- if k == 0 {
- continue
- }
- tmpEdbInfo, ok := edbInfoMap[v]
- if !ok {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,err:" + err.Error()
- return
- }
- dataList, err := excel2.GetOtherEdbDataList(tmpEdbInfo, dateStrList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
- return
- }
- result = append(result, response.TableDataItem{
- EdbInfoId: v,
- Data: dataList,
- })
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = result
- }
- // Refresh
- // @Title 刷新
- // @Description 刷新接口
- // @Param ExcelInfoId query int true "表格id"
- // @router /excel_info/table/refresh [get]
- func (c *ExcelInfoController) Refresh() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- excelInfoId, _ := c.GetInt("ExcelInfoId")
- chartInfoId, _ := c.GetInt("ChartInfoId")
- if excelInfoId <= 0 && chartInfoId <= 0 {
- br.Msg = "请选择表格"
- br.ErrMsg = "ExcelInfoId未传"
- br.IsSendEmail = false
- return
- }
- // todo 如果请求入参是chart_info_id,则需要获取excel_info_id
- if chartInfoId > 0 && excelInfoId == 0 {
- excelInfo, err := excel3.GetExcelInfoByChartInfoId(chartInfoId)
- if err != nil {
- br.Msg = "请选择表格"
- br.ErrMsg = "未找到对应的表格"
- br.IsSendEmail = false
- return
- }
- excelInfoId = excelInfo.ExcelInfoId
- }
- // 获取数据详情
- excelDetail, errMsg, err := excel2.GetExcelDetailInfoByExcelInfoId(excelInfoId, c.SysUser.AdminId, c.Lang)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- // 操作权限校验
- {
- button := excelDetail.Button
- if excelDetail.Source != utils.BALANCE_TABLE {
- button = excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source, excelDetail.HaveOperaAuth)
- }
- if !button.RefreshButton {
- br.Msg = "无操作权限"
- br.IsSendEmail = false
- return
- }
- }
- // 数据刷新(只有自定义表格有刷新)
- if excelDetail.Source == utils.TIME_TABLE {
- jsonStrByte, err := json.Marshal(excelDetail.TableData)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,转json失败,Err:" + err.Error()
- return
- }
- var tableData request.TableDataReq
- err = json.Unmarshal(jsonStrByte, &tableData)
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,json转结构体失败,Err:" + err.Error()
- return
- }
- if len(tableData.EdbInfoIdList) > 0 {
- err, _ = data.EdbInfoRefreshAllFromBaseV3(tableData.EdbInfoIdList, false, true, false)
- if err != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "刷新失败,Err:" + err.Error()
- return
- }
- }
- }
- // 数据刷新-混合表格
- if excelDetail.Source == utils.MIXED_TABLE {
- // todo 刷新动态表的所有子表中关联的指标数据
- jsonByte, e := json.Marshal(excelDetail.TableData)
- if e != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "JSON格式化混合表格数据失败, Err: " + e.Error()
- return
- }
- var tableData request.MixedTableReq
- if e = json.Unmarshal(jsonByte, &tableData); e != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "解析混合表格数据失败, Err: " + e.Error()
- return
- }
- edbInfoIds := make([]int, 0)
- edbInfoIdExist := make(map[int]bool)
- if len(tableData.Data) > 0 {
- for _, t := range tableData.Data {
- for _, v := range t {
- if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
- edbInfoIdExist[v.EdbInfoId] = true
- edbInfoIds = append(edbInfoIds, v.EdbInfoId)
- }
- }
- }
- }
- if len(edbInfoIds) > 0 {
- e, _ = data.EdbInfoRefreshAllFromBaseV3(edbInfoIds, false, true, false)
- if e != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "刷新混合表格数据失败, Err: " + err.Error()
- return
- }
- }
- }
- if excelDetail.Source == utils.BALANCE_TABLE {
- err = refreshBalanceTable(excelDetail, c.Lang)
- if err != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "刷新失败,Err:" + err.Error()
- return
- }
- }
- // 清除缓存
- key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelDetail.UniqueCode
- if utils.Re == nil {
- _ = utils.Rc.Delete(key)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "刷新成功"
- }
- // Download
- // @Title 获取表格详情
- // @Description 获取表格详情接口
- // @Param UniqueCode query string true "表格code"
- // @Param ExcelInfoId query int true "表格id"
- // @Success 200 {object} data_manage.ExcelInfo
- // @router /excel_info/table/download [get]
- func (c *ExcelInfoController) Download() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- excelInfoId, _ := c.GetInt("ExcelInfoId")
- uniqueCode := c.GetString("UniqueCode")
- if excelInfoId <= 0 && uniqueCode == `` {
- br.Msg = "请选择表格"
- br.ErrMsg = "ExcelInfoId和UniqueCode都未传"
- br.IsSendEmail = false
- return
- }
- var excelInfo *excel3.ExcelInfo
- var err error
- //获取eta表格信息
- if excelInfoId > 0 {
- excelInfo, err = excel3.GetExcelInfoById(excelInfoId)
- } else {
- excelInfo, err = excel3.GetExcelInfoByUniqueCode(uniqueCode)
- }
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取ETA表格信息失败,Err:" + err.Error()
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "ETA表格被删除,请刷新页面"
- br.ErrMsg = "ETA表格被删除,请刷新页面,Err:" + err.Error()
- br.IsSendEmail = false
- }
- return
- }
- if excelInfo.Source == 1 {
- br.Msg = "不是自定义表格"
- br.IsSendEmail = false
- return
- }
- var tableData excel.TableData
- switch excelInfo.Source {
- case utils.EXCEL_DEFAULT:
- br.Msg = "表格类型异常"
- case utils.TIME_TABLE: // 自定义表格
- var tableDataConfig excel2.TableDataConfig
- err = json.Unmarshal([]byte(excelInfo.Content), &tableDataConfig)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
- return
- }
- result, err := excel2.GetDataByTableDataConfig(tableDataConfig)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取最新的表格数据失败,Err:" + err.Error()
- return
- }
- tableData, err = excel.GetTableDataByCustomData(excelInfo.ExcelType, result)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "转换成table失败,Err:" + err.Error()
- return
- }
- case utils.MIXED_TABLE: // 混合表格
- var result request.MixedTableReq
- err = json.Unmarshal([]byte(excelInfo.Content), &result)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
- return
- }
- newResult, err, errMsg := excel2.GetMixedTableCellData(result, c.Lang)
- if err != nil {
- br.Msg = "获取失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
- return
- }
- tableData, err = excel.GetTableDataByMixedTableData(newResult, false)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "转换成table失败,Err:" + err.Error()
- return
- }
- case utils.BALANCE_TABLE: // 混合表格
- savePath, fileName, uploadDir, err, errMsg := downloadBalanceTable(excelInfo, c.Lang)
- if err != nil {
- br.Msg = "下载失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
- return
- }
- defer func() {
- _ = os.RemoveAll(uploadDir)
- }()
- // todo 删除文件
- c.Ctx.Output.Download(savePath, fileName)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = excelInfo
- return
- }
- downloadFilePath, err := tableData.ToExcel()
- if err != nil {
- fmt.Println("err:", err)
- return
- }
- defer func() {
- _ = os.Remove(downloadFilePath)
- }()
- downloadFileName := excelInfo.ExcelName + ".xlsx"
- c.Ctx.Output.Download(downloadFilePath, downloadFileName)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = excelInfo
- }
- // Copy
- // @Title 复制表格
- // @Description 复制表格接口
- // @Param request body request.EditExcelInfoReq true "type json string"
- // @Success 200 {object} response.AddExcelInfoResp
- // @router /excel_info/copy [post]
- func (c *ExcelInfoController) Copy() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.CopyExcelInfoReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ExcelInfoId <= 0 {
- br.Msg = "请传入ETA表格标识!"
- return
- }
- cacheKey := "CACHE_TABLE_INFO_EDIT_" + strconv.Itoa(req.ExcelInfoId)
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!"
- return
- }
- defer func() {
- _ = utils.Rc.Delete(cacheKey)
- }()
- req.ExcelName = strings.Trim(req.ExcelName, " ")
- if req.ExcelName == "" {
- br.Msg = "请填写表格名称!"
- br.IsSendEmail = false
- return
- }
- if req.ExcelClassifyId <= 0 {
- br.Msg = "分类参数错误!"
- br.IsSendEmail = false
- return
- }
- excelInfo, err, errMsg, isSendEmail := excel2.Copy(req.ExcelInfoId, req.ExcelClassifyId, req.ExcelName, sysUser)
- if err != nil {
- br.Msg = "复制失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "复制失败,Err:" + err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- resp := new(response.AddExcelInfoResp)
- resp.ExcelInfoId = excelInfo.ExcelInfoId
- resp.UniqueCode = excelInfo.UniqueCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- //func init() {
- // //list, err := data.GetFirstEdbDataList(102739, 12)
- // list, err := data.GetFirstEdbDataList(101323, 12)
- // if err != nil {
- // fmt.Println(err)
- // return
- // }
- //
- // fmt.Println("START")
- // dateList := make([]string, 0)
- // for _, v := range list {
- // fmt.Println(v)
- // dateList = append(dateList, v.DataTime)
- // }
- //
- // fmt.Println("End")
- //
- // {
- // list, err := data.GetOtherEdbDataList(102227, dateList)
- // if err != nil {
- // fmt.Println(err)
- // return
- // }
- //
- // for _, v := range list {
- // fmt.Println(v)
- // }
- // }
- //}
- //func init() {
- // 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":[]}]]}`
- // 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":[]}]]}`
- //
- // //var req request.TableDataReq
- // //err := json.Unmarshal([]byte(str), &req)
- // //if err != nil {
- // // fmt.Println(err)
- // // return
- // //}
- // //tableDataConfig, err := data.GetTableDataConfig(req)
- // //if err != nil {
- // // fmt.Println(err)
- // // return
- // //}
- // var tableDataConfig data.TableDataConfig
- // err := json.Unmarshal([]byte(str), &tableDataConfig)
- // if err != nil {
- // fmt.Println(err)
- // return
- // }
- //
- // fmt.Println(tableDataConfig)
- //
- // result, err := data.GetDataByTableDataConfig(tableDataConfig)
- // if err != nil {
- // fmt.Println(err)
- // return
- // }
- // fmt.Println(result)
- // //byteStr, _ := json.Marshal(result)
- // //utils.FileLog.Info(string(byteStr))
- //}
- //func init() {
- // startNow := time.Now()
- // fmt.Println(startNow.Format(utils.FormatDateTime))
- // startTime := startNow.Unix()
- // //filePath := `static/tmpFile/test/化工23.05.24.xlsx`
- // filePath := `static/tmpFile/1. TAROUND_202308010201-500.xlsx`
- // //filePath := `static/tmpFile/化工23.05.24.xml`
- // //filePath := `static/tmpFile/化工23.05.24/xl/workbook.xml`
- // //filePath := `static/tmpFile/1. TAROUND_202308010201.xlsx`
- //
- // //filePath := `static/tmpFile/1. TAROUND_202308010201-2.xlsx`
- //
- // //filePath := `static/tmpFile/5. Outage_Values_Daily.xlsx`
- // //filePath := `static/tmpFile/1. TAROUND_202308010201 - 副本.xlsx`
- // excel.ConvToLuckySheet(filePath)
- // cz := time.Now().Unix() - startTime
- // fmt.Printf("处理完需要的时间:%d秒;约耗时:%d分%d秒", cz, cz/60, cz%60)
- // fmt.Println()
- //
- // //sheetName := `日度`
- // //sheetName := `月度`
- // //fmt.Println(excel.GetDefaultSheetIndex(filePath, sheetName))
- //
- // //decompressZip(filePath)
- //}
- // src: 需要解压的zip文件
- func decompressZip(src string) error {
- archive, err := zip.OpenReader(src)
- if err != nil {
- return err
- }
- dir := filepath.Dir(src) + "/zip"
- defer archive.Close()
- for _, f := range archive.File {
- filePath := filepath.Join(dir, f.Name)
- if f.FileInfo().IsDir() {
- os.MkdirAll(filePath, os.ModePerm)
- continue
- }
- if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
- return fmt.Errorf("failed to make directory (%v)", err)
- }
- dstFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
- if err != nil {
- return fmt.Errorf("failed to create file (%v)", err)
- }
- fileInArchive, err := f.Open()
- if err != nil {
- return fmt.Errorf("failed to open file in zip (%v)", err)
- }
- if _, err := io.Copy(dstFile, fileInArchive); err != nil {
- return fmt.Errorf("failed to copy file in zip (%v)", err)
- }
- dstFile.Close()
- fileInArchive.Close()
- }
- return nil
- }
- // MarkEditStatus
- // @Title 标记沙盘编辑状态
- // @Description 标记沙盘编辑状态接口
- // @Param request body request.MarkEditSandbox true "type json string"
- // @Success 200 标记成功 ;202 标记成功
- // @router /excel_info/mark [post]
- func (c *ExcelInfoController) MarkEditStatus() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.MarkEditExcel
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ExcelInfoId <= 0 {
- br.Msg = "缺少表格编号"
- return
- }
- if req.Status <= 0 {
- br.Msg = "标记状态异常"
- return
- }
- status := 1
- if req.Status == 2 {
- status = 0
- }
- //更新标记key
- data, err := services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, status, sysUser.RealName)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- msg := "标记成功"
- br.Ret = 200
- br.Success = true
- br.Msg = msg
- br.Data = data
- }
- // BatchRefresh
- // @Title 批量刷新表格接口
- // @Description 批量刷新图表接口
- // @Param request body excel3.BatchRefreshExcelReq true "type json string"
- // @Success Ret=200 刷新成功
- // @router /excel_info/table/batch_refresh [post]
- func (c *ExcelInfoController) BatchRefresh() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req excel3.BatchRefreshExcelReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if len(req.ExcelCodes) == 0 {
- br.Ret = 200
- br.Success = true
- br.Msg = "刷新成功"
- return
- }
- // 获取表格关联的指标IDs
- edbIds, e := excel2.GetEdbIdsFromExcelCodes(req.ExcelCodes, sysUser.AdminId, c.Lang)
- if e != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "获取表格关联的指标IDs失败, Err: " + e.Error()
- return
- }
- redisKey := data.GetBatchChartRefreshKey(req.Source, req.ReportId, req.ReportChapterId)
- refreshKeys := make([]string, 0)
- for _, v := range req.ExcelCodes {
- refreshKeys = append(refreshKeys, fmt.Sprint(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL, v))
- }
- // 刷新相关指标
- syncing, e := data.BatchRefreshEdbByEdbIds(edbIds, redisKey, refreshKeys)
- if e != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "刷新表格关联指标信息失败,Err:" + err.Error()
- return
- }
- br.Msg = "刷新成功"
- if syncing {
- br.Msg = "表格关联指标较多,请10分钟后刷新页面查看最新数据"
- }
- br.Ret = 200
- br.Success = true
- }
- // GetBatchChartRefreshResult
- // @Title 获取批量刷新表格结果
- // @Description 获取批量刷新表格结果
- // @Param request body excel3.BatchRefreshExcelReq true "type json string"
- // @Success Ret=200 刷新成功
- // @router /excel_info/table/batch_refresh/result [post]
- func (c *ExcelInfoController) GetBatchChartRefreshResult() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req excel3.BatchRefreshExcelReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- // 校验缓存是否存在, 存在说明还在刷新中
- result := true
- redisKey := excel2.GetExcelEdbBatchRefreshKey(req.Source, req.ReportId, req.ReportChapterId)
- if redisKey != `` {
- // 如果找到了key,那么就是还在更新中
- ok := utils.Rc.IsExist(redisKey)
- if ok {
- result = false
- }
- }
- resp := struct {
- RefreshResult bool `description:"刷新结果"`
- }{
- RefreshResult: result,
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- }
- // GetBatchChartRefreshResult
- // @Title 获取批量刷新表格结果
- // @Description 获取批量刷新表格结果
- // @Param EdbInfoId query int true "edb id"
- // @Success Ret=200 刷新成功
- // @router /excel_info/get_edb_source [get]
- func (c *ExcelInfoController) GetEdbSource() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := c.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.ErrMsg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- sourceNameList, sourceNameEnList, err := excel2.GetEdbSourceByEdbInfoIdList([]int{edbInfoId})
- if err != nil {
- br.Msg = "自定义表格数据获取失败"
- br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
- return
- }
- excelSource := strings.Join(sourceNameList, ",")
- excelSourceEn := strings.Join(sourceNameEnList, ",")
- var resp struct {
- ExcelSource string `description:"表格来源"`
- ExcelSourceEn string `description:"表格来源(英文)"`
- }
- resp.ExcelSource = excelSource
- resp.ExcelSourceEn = excelSourceEn
- br.Data = resp
- br.Ret = 200
- br.Success = true
- }
|