1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038 |
- package data_manage
- import (
- "encoding/json"
- "eta_gn/eta_api/controllers"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/models/data_manage/request"
- "eta_gn/eta_api/models/data_manage/response"
- "eta_gn/eta_api/services"
- "eta_gn/eta_api/services/data"
- "eta_gn/eta_api/services/data/data_manage_permission"
- "eta_gn/eta_api/services/elastic"
- "eta_gn/eta_api/utils"
- "fmt"
- "sort"
- "strconv"
- "strings"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/shopspring/decimal"
- )
- // PredictEdbInfoController 预测指标
- type PredictEdbInfoController struct {
- controllers.BaseAuthController
- }
- // EdbChartList
- // @Title 预测指标列表接口
- // @Description 预测指标列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyId query int true "分类id"
- // @Param AdminId query int false "创建人id"
- // @Param IsOnlyMe query bool false "是否只看我的"
- // @Success 200 {object} response.PredictEdbInfoListResp
- // @router /predict_edb_info/chart/list [get]
- func (this *PredictEdbInfoController) EdbChartList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- classifyId, _ := this.GetInt("ClassifyId")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- adminId, _ := this.GetInt("AdminId")
- isOnlyMe, _ := this.GetBool("IsOnlyMe")
- 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{}
- // 预测指标
- condition += ` AND edb_info_type = ? `
- pars = append(pars, 1)
- // 筛选分类
- if classifyId > 0 {
- childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
- if e != nil && !utils.IsErrNoRow(e) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
- return
- }
- var classifyIds []int
- for _, v := range childClassify {
- classifyIds = append(classifyIds, v.ClassifyId)
- }
- condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
- pars = append(pars, classifyIds)
- }
- if adminId > 0 {
- condition += " AND sys_user_id = ? "
- pars = append(pars, adminId)
- }
- if isOnlyMe {
- condition += " AND sys_user_id = ? "
- pars = append(pars, sysUser.AdminId)
- }
- // 获取当前账号的不可见指标
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- noPermissionEdbInfoIdList := make([]int, 0)
- for _, v := range confList {
- noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
- }
- noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
- if noPermissionEdbInfoIdNum > 0 {
- condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
- pars = append(pars, noPermissionEdbInfoIdList)
- }
- //获取指标信息
- dataCount, list, err := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Success = true
- br.Msg = "获取预测指标列表失败"
- br.ErrMsg = "获取预测指标列表失败,Err:" + err.Error()
- return
- }
- respList := make([]*data_manage.EdbInfoList, 0)
- if len(list) > 0 {
- classifyIdList := make([]int, 0)
- for _, v := range list {
- v.ConvertToResp()
- classifyIdList = append(classifyIdList, v.ClassifyId)
- }
- // 指标权限
- {
- // 当前的分类
- classifyMap := make(map[int]*data_manage.EdbClassify)
- classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if err != nil {
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- }
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- for _, v := range list {
- if currClassify, ok := classifyMap[v.ClassifyId]; ok {
- v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- // 不展示无权限的
- if !v.HaveOperaAuth {
- continue
- }
- v.Button = data.GetEdbOpButton(sysUser, v.SysUserId, v.EdbType, v.EdbInfoType, v.HaveOperaAuth)
- respList = append(respList, v)
- }
- }
- }
- page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
- }
- resp := response.PredictEdbInfoListResp{
- Paging: page,
- List: respList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // List
- // @Title 指标数据列表接口
- // @Description 指标数据列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EdbInfoId query int true "指标id"
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Success 200 {object} data_manage.EdbInfoListResp
- // @router /predict_edb_info/list [get]
- func (this *PredictEdbInfoController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- edbInfoId, _ := this.GetInt("EdbInfoId")
- keyWord := this.GetString("KeyWord")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- 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{}
- // 指标类型,0:普通指标,1:预测指标
- condition += " AND edb_info_type=? "
- pars = append(pars, 1)
- if edbInfoId > 0 {
- condition += " AND edb_info_id=? "
- pars = append(pars, edbInfoId)
- }
- if keyWord != "" {
- condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
- //pars = append(pars, keyWord)
- //pars = append(pars, keyWord)
- }
- resp := data_manage.EdbInfoListResp{}
- if condition == "" {
- item := new(data_manage.EdbInfoList)
- resp.Paging = page
- resp.Item = item
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- //获取指标信息
- edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Success = true
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- if edbInfoItem == nil || (err != nil && utils.IsErrNoRow(err)) || edbInfoItem.EdbInfoId <= 0 {
- item := new(data_manage.EdbInfoList)
- resp.Paging = page
- resp.Item = item
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- edbInfoItem.ConvertToResp()
- //获取英文频度
- edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency)
- // 未来的指标预测数据
- predictDataList := make([]*data_manage.EdbData, 0)
- var existCondition string
- var existPars []interface{}
- existCondition += " AND edb_info_id=? "
- existPars = append(existPars, edbInfoId)
- //查询出所有的关联指标
- sourceEdbInfoCalculateMappingList, err := data_manage.GetEdbInfoCalculateListByCondition(existCondition, existPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取预测指标关联信息失败,Err:" + err.Error()
- return
- }
- if len(sourceEdbInfoCalculateMappingList) <= 0 {
- br.Msg = "获取失败"
- br.ErrMsg = "查找预测指标关联信息失败"
- return
- }
- //获取指标数据(实际已生成)
- {
- dataCount, dataList, err := data.GetPageData(edbInfoItem.EdbInfoId, edbInfoItem.Source, edbInfoItem.SubSource, edbInfoItem.LatestDate, startSize, pageSize)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- edbInfoItem.DataList = dataList
- }
- // 第一页才需要 获取预测指标未来的数据
- if currentIndex == 1 {
- predictDataList, err = data_manage.GetAllEdbDataListData(edbInfoItem.EdbInfoId, edbInfoItem.Source, edbInfoItem.SubSource, edbInfoItem.LatestDate)
- if err != nil {
- br.Msg = "获取预测指标数据失败"
- br.ErrMsg = "获取预测指标数据失败" + err.Error()
- return
- }
- }
- // 如果预测数据没有,那么返回空数组
- if predictDataList == nil {
- predictDataList = make([]*data_manage.EdbData, 0)
- }
- edbInfoItem.PredictDataList = predictDataList
- // 如果实际数据没有,那么返回空数组
- if edbInfoItem.DataList == nil {
- edbInfoItem.DataList = make([]*data_manage.EdbData, 0)
- }
- //查询目录
- classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfoItem.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- // 权限校验
- {
- classifyMap := make(map[int]*data_manage.EdbClassifyIdItems)
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- if currClassify, ok := classifyMap[edbInfoItem.ClassifyId]; ok {
- haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfoItem.EdbInfoId, edbInfoItem.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- edbInfoItem.HaveOperaAuth = haveOperaAuth
- }
- }
- resp.Paging = page
- resp.Item = edbInfoItem
- resp.ClassifyList = classifyList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Add
- // @Title 新增指标接口
- // @Description 新增指标接口
- // @Param request body request.AddPredictEdbInfoReq true "type json string"
- // @Success 200 {object} response.AddEdbInfoResp
- // @router /predict_edb_info/add [post]
- func (this *PredictEdbInfoController) Add() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- cacheKey := "CACHE_EDB_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 = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req request.AddPredictEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- sourceEdbInfoId := req.SourceEdbInfoId
- if sourceEdbInfoId <= 0 {
- br.Msg = "请选择来源指标"
- br.IsSendEmail = false
- return
- }
- if req.EdbName == "" {
- br.Msg = "指标名称不能为空"
- br.IsSendEmail = false
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- if len(req.RuleList) <= 0 {
- br.Msg = "请填写预测规则"
- br.IsSendEmail = false
- return
- }
- // 根据截止日期重新排序
- ruleList := make([]request.RuleConfig, 0)
- {
- ruleMap := make(map[string]request.RuleConfig)
- dateIntList := make([]int64, 0)
- for _, v := range req.RuleList {
- confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
- if err != nil {
- br.Msg = "配置项中时间异常,请重新选择"
- br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
- br.IsSendEmail = false
- return
- }
- dateIntList = append(dateIntList, confEndDate.Unix())
- ruleMap[v.EndDate] = v
- }
- sort.Slice(dateIntList, func(i, j int) bool {
- return dateIntList[i] < dateIntList[j]
- })
- for _, dateInt := range dateIntList {
- currDateTime := time.Unix(dateInt, 0)
- item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
- if !ok {
- br.Msg = "配置项中时间异常,请重新选择"
- br.ErrMsg = "配置项中时间异常,请重新选择"
- br.IsSendEmail = false
- return
- }
- ruleList = append(ruleList, item)
- }
- }
- req.RuleList = ruleList
- //传入操作人
- req.AdminId = sysUser.AdminId
- req.AdminName = sysUser.RealName
- // 添加计算指标
- reqJson, err := json.Marshal(req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- respItem, err := data.SaveBasePredictEdbData(string(reqJson), this.Lang)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = respItem.Msg
- br.ErrMsg = respItem.ErrMsg
- return
- }
- resp := respItem.Data
- //添加es
- data.AddOrEditEdbInfoToEs(resp.EdbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // ChartImageSet
- // @Title 设置指标的图表图片
- // @Description 设置指标的图表图片接口
- // @Param request body data_manage.SetChartInfoImageReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /predict_edb_info/image/set [post]
- func (this *PredictEdbInfoController) ChartImageSet() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.SetEdbInfoImageReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.EdbInfoId > 0 && req.ImageUrl != "" {
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- if utils.IsErrNoRow(err) {
- br.Msg = "找不到该指标"
- br.ErrMsg = "找不到该指标"
- br.IsSendEmail = false
- }
- return
- }
- edbInfo.ChartImage = req.ImageUrl
- err = edbInfo.Update([]string{"ChartImage"})
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- //修改es数据
- go data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // Edit
- // @Title 编辑指标接口
- // @Description 编辑指标接口
- // @Success 200 {object} request.EditEdbInfoReq
- // @router /predict_edb_info/edit [post]
- func (this *PredictEdbInfoController) Edit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.AddPredictEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- edbInfoId := req.EdbInfoId
- if edbInfoId <= 0 {
- br.Msg = "请选择预测指标"
- br.IsSendEmail = false
- return
- }
- if req.EdbName == "" {
- br.Msg = "指标名称不能为空"
- br.IsSendEmail = false
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- if len(req.RuleList) <= 0 {
- br.Msg = "请填写预测规则"
- br.IsSendEmail = false
- return
- }
- // 根据截止日期重新排序
- ruleList := make([]request.RuleConfig, 0)
- {
- ruleMap := make(map[string]request.RuleConfig)
- dateIntList := make([]int64, 0)
- for _, v := range req.RuleList {
- confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
- if err != nil {
- br.Msg = "配置项中时间异常,请重新选择"
- br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
- br.IsSendEmail = false
- return
- }
- dateIntList = append(dateIntList, confEndDate.Unix())
- ruleMap[v.EndDate] = v
- }
- sort.Slice(dateIntList, func(i, j int) bool {
- return dateIntList[i] < dateIntList[j]
- })
- for _, dateInt := range dateIntList {
- currDateTime := time.Unix(dateInt, 0)
- item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
- if !ok {
- br.Msg = "配置项中时间异常,请重新选择"
- br.ErrMsg = "配置项中时间异常,请重新选择"
- br.IsSendEmail = false
- return
- }
- ruleList = append(ruleList, item)
- }
- }
- req.RuleList = ruleList
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "修改失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- var haveOperaAuth bool
- // 数据权限校验
- {
- haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- }
- // 编辑权限校验
- button := data.GetPredictEdbOpButton(this.SysUser, edbInfo.SysUserId, haveOperaAuth)
- if !button.OpButton {
- br.Msg = "无权限操作"
- br.IsSendEmail = false
- return
- }
- //传入操作人
- req.AdminId = sysUser.AdminId
- req.AdminName = sysUser.RealName
- // 添加计算指标
- reqJson, err := json.Marshal(req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- respItem, err := data.SaveBasePredictEdbData(string(reqJson), this.Lang)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = respItem.Msg
- br.ErrMsg = respItem.ErrMsg
- return
- }
- resp := respItem.Data
- //修改es
- data.AddOrEditEdbInfoToEs(resp.EdbInfoId)
- // 添加操作日志
- newEdbRecord := new(data_manage.EdbInfoEditRecord)
- newEdbRecord.EdbName = req.EdbName
- // 频度和单位在此接口不处理
- newEdbRecord.Frequency = edbInfo.Frequency
- newEdbRecord.Unit = edbInfo.Unit
- newEdbRecord.OperateUserId = sysUser.AdminId
- newEdbRecord.OperateUserRealName = sysUser.RealName
- go data.AddEditEdbInfoRcord(edbInfo, newEdbRecord)
- // 刷新关联指标
- go data.EdbInfoRefreshAllFromBaseV2(resp.EdbInfoId, true, false)
- br.Ret = 200
- br.Success = true
- br.Msg = "修改成功"
- br.IsAddLog = true
- }
- // Refresh
- // @Title 指标刷新接口
- // @Description 指标刷新接口
- // @Param EdbInfoId query int true "指标id"
- // @Success Ret=200 刷新成功
- // @router /predict_edb_info/refresh [get]
- func (this *PredictEdbInfoController) Refresh() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- _, isAsync, err, errMsg := data.RefreshPredictEdbInfo(edbInfoId, false)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "刷新成功"
- if isAsync {
- br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
- }
- }
- // Move
- // @Title 移动指标接口
- // @Description 移动指标接口
- // @Success 200 {object} data_manage.MoveEdbInfoReq
- // @router /predict_edb_info/move [post]
- func (this *PredictEdbInfoController) Move() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.MoveEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- // 移动预测指标
- err, errMsg := data.MovePredictEdbInfo(req.EdbInfoId, req.ClassifyId, req.PrevEdbInfoId, req.NextEdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = errMsg + ";Err:" + err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "移动成功"
- }
- // Detail
- // @Title 获取指标详情
- // @Description 获取指标详情接口
- // @Param EdbInfoId query int true "指标id"
- // @Success 200 {object} response.PredictEdbInfo
- // @router /predict_edb_info/detail [get]
- func (this *PredictEdbInfoController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- var ruleType int
- var fixedValue float64
- calculateList := make([]*data_manage.EdbInfoCalculateDetail, 0)
- predictEdbConfList := make([]data_manage.PredictEdbConfDetail, 0)
- calculateList, err = data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if edbInfo.EdbType == 1 {
- // 获取所有的指标预测规则配置
- tmpPredictEdbConfList, err := data_manage.GetPredictEdbConfListById(edbInfoId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取预测指标配置信息失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpPredictEdbConfList {
- var tmpPredictEdbConfCalculateMappingDetail []*data_manage.PredictEdbConfCalculateMappingDetail
- if v.RuleType == 9 || v.RuleType == 14 {
- tmpPredictEdbConfCalculateMappingDetail, err = data_manage.GetPredictEdbConfCalculateMappingDetailListByConfigId(v.PredictEdbInfoId, v.ConfigId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取预测指标配置与关联指标信息失败,Err:" + err.Error()
- return
- }
- }
- if len(tmpPredictEdbConfCalculateMappingDetail) <= 0 {
- tmpPredictEdbConfCalculateMappingDetail = make([]*data_manage.PredictEdbConfCalculateMappingDetail, 0)
- }
- tmp := data_manage.PredictEdbConfDetail{
- ConfigId: v.ConfigId,
- PredictEdbInfoId: v.PredictEdbInfoId,
- SourceEdbInfoId: v.SourceEdbInfoId,
- RuleType: v.RuleType,
- FixedValue: v.FixedValue,
- Value: v.Value,
- EmptyType: v.EmptyType,
- MaxEmptyType: v.MaxEmptyType,
- EndDate: v.EndDate.Format(utils.FormatDate),
- ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
- CreateTime: v.CreateTime.Format(utils.FormatDateTime),
- CalculateList: tmpPredictEdbConfCalculateMappingDetail,
- }
- predictEdbConfList = append(predictEdbConfList, tmp)
- }
- //calculateList, err = data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- if len(predictEdbConfList) == 0 {
- br.Msg = "找不到该预测指标配置"
- br.ErrMsg = "找不到该预测指标配置"
- return
- }
- predictEdbConf := predictEdbConfList[0]
- ruleType = predictEdbConf.RuleType
- fixedValue = predictEdbConf.FixedValue
- }
- findEdbInfoIdList := make([]int, 0)
- for k, v := range calculateList {
- if v.LatestDate != v.EndDate && v.LatestDate != `` && v.EndDate != `` {
- tmpLatestDate, _ := time.ParseInLocation(utils.FormatDate, v.LatestDate, time.Local)
- tmpEndDate, _ := time.ParseInLocation(utils.FormatDate, v.EndDate, time.Local)
- if tmpEndDate.After(tmpLatestDate) {
- findEdbInfoIdList = append(findEdbInfoIdList, v.FromEdbInfoId)
- }
- }
- v.EndValue = v.LatestValue
- calculateList[k] = v
- }
- if len(findEdbInfoIdList) > 0 {
- edbDataInsertConfigList, err := data_manage.GetEdbDataInsertConfigByEdbIdList(findEdbInfoIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败插入值失败,Err:" + err.Error()
- return
- }
- edbDataInsertConfigMap := make(map[int]*data_manage.EdbDataInsertConfig)
- for _, v := range edbDataInsertConfigList {
- edbDataInsertConfigMap[v.EdbInfoId] = v
- }
- for k, v := range calculateList {
- edbDataInsertConfig, ok := edbDataInsertConfigMap[v.FromEdbInfoId]
- if !ok {
- continue
- }
- if v.EndDate != `` && v.EndDate == edbDataInsertConfig.Date.Format(utils.FormatDate) {
- t, tmpErr := decimal.NewFromString(edbDataInsertConfig.Value)
- if tmpErr != nil {
- continue
- }
- v.EndValue, _ = t.Float64()
- }
- calculateList[k] = v
- }
- }
- classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- edbInfoResp, err := edbInfo.ConvertToResp()
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- edbInfoFull := new(response.EdbInfoFull)
- edbInfoFull.EdbInfoResp = edbInfoResp
- // 权限校验
- {
- classifyMap := make(map[int]*data_manage.EdbClassifyIdItems)
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- if currClassify, ok := classifyMap[edbInfo.ClassifyId]; ok {
- haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- edbInfoFull.HaveOperaAuth = haveOperaAuth
- }
- }
- // 拟合残差计算相关系数
- var correlationStr string
- if edbInfo.Source == utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC {
- var aEdbInfo, bEdbInfo *data_manage.EdbInfoCalculateDetail
- for _, v := range calculateList {
- if v.FromTag == "A" {
- aEdbInfo = v
- continue
- }
- if v.FromTag == "B" {
- bEdbInfo = v
- continue
- }
- }
- if aEdbInfo != nil && bEdbInfo != nil {
- edbInfoFromTagList := []data_manage.EdbInfoFromTag{
- {
- EdbInfoId: aEdbInfo.FromEdbInfoId,
- FromTag: aEdbInfo.FromTag,
- MoveValue: aEdbInfo.MoveValue,
- }, {
- EdbInfoId: bEdbInfo.FromEdbInfoId,
- FromTag: bEdbInfo.FromTag,
- MoveValue: bEdbInfo.MoveValue,
- },
- }
- req2 := &data_manage.EdbInfoCalculateBatchSaveReqByEdbLib{
- AdminId: sysUser.AdminId,
- AdminName: sysUser.RealName,
- Formula: edbInfo.CalculateFormula,
- EdbInfoIdArr: edbInfoFromTagList,
- }
- // 计算
- val, err, _ := data.CallCalculateComputeCorrelation(req2, this.Lang)
- if err == nil {
- correlationStr = val
- }
- }
- }
- resp := response.PredictEdbInfo{
- EdbInfoFull: edbInfoFull,
- RuleType: ruleType,
- FixedValue: fixedValue,
- CalculateList: calculateList,
- RuleList: predictEdbConfList,
- CorrelationStr: correlationStr,
- ClassifyList: classifyList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // FilterByEs
- // @Title 指标筛选接口
- // @Description 指标筛选接口
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
- // @Param Frequency query string false "频度"
- // @Param IsOnlyMe query bool false "是否只看我的"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /predict_edb_info/filter_by_es [get]
- func (this *PredictEdbInfoController) FilterByEs() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int64
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyWord := this.GetString("Keyword")
- keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
- //兼容前端
- if keyWord == `` {
- keyWord = this.GetString("KeyWord")
- keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
- }
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- //指标来源
- source, _ := this.GetInt("Source")
- frequency := this.GetString("Frequency") //频度
- isOnlyMe, _ := this.GetBool("IsOnlyMe")
- var edbInfoList []*data_manage.EdbInfoList
- var err error
- // 无权限指标 和 无权限指标分类id
- noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err := data_manage_permission.GetUserAllEdbAndClassifyNoPermissionList(this.SysUser.AdminId, utils.PREDICT_EDB_INFO_TYPE, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- // 是否走ES
- isEs := false
- if keyWord != "" {
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- if isOnlyMe {
- total, edbInfoList, err = elastic.SearchEdbInfoDataByAdminId(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 1, frequency, this.SysUser.AdminId)
- } else {
- total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 1, frequency, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, 0)
- }
- isEs = true
- } else {
- var condition string
- var pars []interface{}
- // 预测指标
- condition += ` AND edb_info_type = ? `
- pars = append(pars, 1)
- // 无权限指标id
- lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
- if lenNoPermissionEdbInfoIdList > 0 {
- condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
- pars = append(pars, noPermissionEdbInfoIdList)
- }
- // 无权限指标分类id
- lenNoPermissionEdbClassifyIdList := len(noPermissionEdbClassifyIdList)
- if lenNoPermissionEdbClassifyIdList > 0 {
- condition += ` AND classify_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbClassifyIdList) + `) `
- pars = append(pars, noPermissionEdbClassifyIdList)
- }
- switch filterSource {
- case 2:
- condition += ` AND frequency='月度' `
- case 3:
- condition += ` AND frequency <> '日度' `
- case 4:
- condition += ` AND edb_type = 1 `
- case 5:
- condition += ` AND source = 32 ` //来源(预测同比值)
- case 6:
- condition += ` AND frequency != ? `
- pars = append(pars, "年度")
- }
- //频度
- if frequency != "" {
- condition += ` AND frequency = ? `
- pars = append(pars, frequency)
- }
- if isOnlyMe {
- condition += " AND sys_user_id = ? "
- pars = append(pars, this.SysUser.AdminId)
- }
- total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
- }
- if err != nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- edbInfoListLen := len(edbInfoList)
- classifyIdList := make([]int, 0)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].ConvertToResp()
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
- }
- // 当前列表中的分类map
- classifyMap := make(map[int]*data_manage.EdbClassify)
- if edbInfoListLen > 0 {
- classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
- if isEs {
- edbInfoIdList := make([]int, 0)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
- tmpEdbInfo := edbInfoList[i]
- if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
- edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- }
- tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- edbInfoMap := make(map[int]*data_manage.EdbInfo)
- for _, v := range tmpEdbList {
- edbInfoMap[v.EdbInfoId] = v
- }
- for i := 0; i < edbInfoListLen; i++ {
- tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
- if !ok {
- continue
- }
- edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
- }
- }
- // 权限校验
- for i := 0; i < edbInfoListLen; i++ {
- tmpEdbInfo := edbInfoList[i]
- if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
- edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- }
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- resp := data_manage.EdbInfoFilterDataResp{
- Paging: page,
- List: edbInfoList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // RefreshAll
- // @Title 指标全部刷新接口
- // @Description 指标全部刷新接口
- // @Param EdbInfoId query int true "指标id"
- // @Success Ret=200 全部刷新成功
- // @router /predict_edb_info/refresh/all [get]
- func (this *PredictEdbInfoController) RefreshAll() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- _, isAsync, err, errMsg := data.RefreshPredictEdbInfo(edbInfoId, true)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "刷新成功"
- if isAsync {
- br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
- }
- }
- // DataList
- // @Title 获取指标数据
- // @Description 获取指标数据
- // @Param EdbInfoId query int true "指标ID"
- // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
- // @Param StartDate query string true "自定义开始日期"
- // @Param EndDate query string true "自定义结束日期"
- // @Param Calendar query string true "公历/农历"
- // @Param SeasonStartDate query string true "季节性图开始日期"
- // @Param SeasonEndDate query string true "季节性图结束日期"
- // @Param ChartType query int true "生成样式:1:曲线图,2:季节性图"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /predict_edb_info/data [get]
- func (this *PredictEdbInfoController) DataList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- return
- }
- dateType, _ := this.GetInt("DateType")
- if dateType <= 0 {
- dateType = 3
- }
- edbInfoType, _ := this.GetInt("EdbInfoType")
- if edbInfoType < 0 {
- edbInfoType = 1
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- startYear, _ := this.GetInt("StartYear")
- chartType, _ := this.GetInt("ChartType")
- if chartType <= 0 {
- chartType = 1
- }
- calendar := this.GetString("Calendar")
- if calendar == "" {
- calendar = "公历"
- }
- isTimeBetween := false //是否是时间区间
- if chartType == 2 {
- dateType = 0
- isTimeBetween = true
- }
- if dateType == 5 {
- isTimeBetween = true
- }
- fullEdb := new(response.EdbInfoFull)
- // 获取预测指标信息
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取预测指标信息失败"
- br.ErrMsg = "获取预测指标信息失败,Err:" + err.Error()
- return
- }
- edbInfoResp, err := edbInfo.ConvertToResp()
- if err != nil {
- br.Msg = "获取预测指标信息失败"
- br.ErrMsg = "获取预测指标信息失败,Err:" + err.Error()
- return
- }
- fullEdb.EdbInfoResp = edbInfoResp
- classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- var currClassifyItem *data_manage.EdbClassifyIdItems
- for _, v := range classifyList {
- if v.ClassifyId == edbInfo.ClassifyId {
- currClassifyItem = v
- break
- }
- }
- if currClassifyItem != nil {
- fullEdb.HaveOperaAuth, err = data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassifyItem.IsJoinPermission, sysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- }
- maxYear := 0
- if edbInfo.LatestDate != "" {
- latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
- maxYear = latestDateT.Year()
- }
- startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
- if endDate == "" {
- endDate = time.Now().Format(utils.FormatDate)
- }
- if dateType == 10 {
- startDate = ""
- endDate = ""
- }
- // 按钮校验
- button := data.GetPredictEdbOpButton(this.SysUser, edbInfo.SysUserId, fullEdb.HaveOperaAuth)
- button.AddButton = false
- resp := response.PredictEdbInfoDataResp{
- EdbInfo: fullEdb,
- Button: button,
- ClassifyList: classifyList,
- }
- if fullEdb.HaveOperaAuth {
- dataList, _, _, err, _ := data.GetPredictDataListByPredictEdbInfo(edbInfo, startDate, endDate, isTimeBetween)
- //lenDataList := len(dataList)
- //if lenDataList > 0 {
- // tmpValue := dataList[lenDataList-1]
- //
- // // 如果最大值 小于 预测值,那么将预测值作为最大值数据返回
- // if edbInfo.MaxValue < tmpValue.Value {
- // edbInfo.MaxValue = tmpValue.Value
- // }
- //
- // // 如果最小值 大于 预测值,那么将预测值作为最小值数据返回
- // if edbInfo.MinValue > tmpValue.Value {
- // edbInfo.MinValue = tmpValue.Value
- // }
- //}
- // 季节性图、公历、农历处理
- resultDataList, err := data.GetChartDataList(dataList, chartType, calendar, edbInfo.LatestDate, startDate)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp.DataList = resultDataList
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ChartDataList
- // @Title 获取指标数据
- // @Description 获取指标数据
- // @Param request body data_manage.AddPredictEdbInfoReq true "type json string"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /predict_edb_info/chart/data/list [post]
- func (this *PredictEdbInfoController) ChartDataList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.PredictEdbInfoChartDataReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if req.SourceEdbInfoId <= 0 {
- br.Msg = "参数错误"
- return
- }
- dateType := req.DateType
- startDate := req.StartDate
- endDate := req.EndDate
- //seasonStartDate := req.SeasonStartDate
- //seasonEndDate := req.SeasonEndDate
- startYear := req.StartYear
- calendar := req.Calendar
- if calendar == "" {
- calendar = "公历"
- }
- isTimeBetween := false //是否是时间区间
- if req.ChartType == 2 {
- dateType = 0
- isTimeBetween = true
- }
- if dateType == 5 {
- isTimeBetween = true
- }
- // 规则列表
- // 根据截止日期重新排序
- ruleList := make([]request.RuleConfig, 0)
- {
- ruleMap := make(map[string]request.RuleConfig)
- dateIntList := make([]int64, 0)
- for _, v := range req.RuleList {
- confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
- if err != nil {
- br.Msg = "配置项中时间异常,请重新选择"
- br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
- br.IsSendEmail = false
- return
- }
- dateIntList = append(dateIntList, confEndDate.Unix())
- ruleMap[v.EndDate] = v
- }
- sort.Slice(dateIntList, func(i, j int) bool {
- return dateIntList[i] < dateIntList[j]
- })
- for _, dateInt := range dateIntList {
- currDateTime := time.Unix(dateInt, 0)
- item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
- if !ok {
- br.Msg = "配置项中时间异常,请重新选择"
- br.ErrMsg = "配置项中时间异常,请重新选择"
- br.IsSendEmail = false
- return
- }
- ruleList = append(ruleList, item)
- }
- }
- // 预测指标配置
- predictEdbConfAndDataList := make([]data_manage.PredictEdbConfAndData, 0)
- endDateStr := `` //数据的结束日期
- for _, v := range ruleList {
- endDateStr = v.EndDate //预测指标的结束日期
- confEndDate, err := time.ParseInLocation(utils.FormatDate, v.EndDate, time.Local)
- if err != nil {
- br.Msg = "配置项中时间异常,请重新选择"
- br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
- return
- }
- // 没有数据,自己瞎测试
- //switch v.RuleType {
- //case 3: //3:同比
- // v.Value = "0.1"
- //case 4: //4:同差
- // v.Value = "10"
- //case 5: //5:环比
- // v.Value = "0.1"
- //case 6: //6:环差
- // v.Value = "0.1"
- //case 7: //7:N期移动均值
- // v.Value = "5"
- //case 8: //8:N期段线性外推值
- // v.Value = "5"
- //}
- tmpDataList := make([]*data_manage.EdbDataList, 0)
- switch v.RuleType {
- case 9:
- // 获取计算参数
- /*formula, edbInfoList, edbInfoIdBytes, err, errMsg := data.GetCalculateByRuleByNineParams(v)
- if err != nil {
- br.Msg = "计算失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- br.Msg = err.Error()
- br.IsSendEmail = false
- return
- }
- // 获取计算数据
- tmpDataList, err = data.CalculateByRuleByNine(formula, edbInfoList, edbInfoIdBytes, v.EmptyType, v.MaxEmptyType)
- if err != nil {
- br.Msg = "计算失败"
- br.ErrMsg = err.Error()
- br.IsSendEmail = false
- return
- }*/
- reqJson, err := json.Marshal(v)
- respItem, err := data.PredictCalculateByNinePreview(string(reqJson), this.Lang)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = respItem.Msg
- br.ErrMsg = respItem.ErrMsg
- return
- }
- tmpDataList = respItem.Data.DataList
- }
- tmpPredictEdbConfAndData := data_manage.PredictEdbConfAndData{
- ConfigId: 0,
- PredictEdbInfoId: 0,
- SourceEdbInfoId: req.SourceEdbInfoId,
- RuleType: v.RuleType,
- FixedValue: 0,
- Value: v.Value,
- EndDate: confEndDate,
- ModifyTime: time.Now(),
- CreateTime: time.Now(),
- DataList: tmpDataList,
- }
- predictEdbConfAndDataList = append(predictEdbConfAndDataList, tmpPredictEdbConfAndData)
- }
- // 来源指标
- sourceEdbInfoItem, err := data_manage.GetEdbInfoById(req.SourceEdbInfoId)
- if err != nil {
- br.Msg = "获取来源指标信息失败"
- br.ErrMsg = "获取来源指标信息失败"
- if !utils.IsErrNoRow(err) {
- br.ErrMsg = "获取来源指标信息失败,Err:" + err.Error()
- }
- br.Success = true
- return
- }
- // todo 确认预测指标是否用的是来源指标的最新日期
- maxYear := 0
- if sourceEdbInfoItem.LatestDate != "" {
- latestDateT, _ := time.Parse(utils.FormatDate, sourceEdbInfoItem.LatestDate)
- maxYear = latestDateT.Year()
- }
- startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
- if endDate == "" {
- endDate = time.Now().Format(utils.FormatDate)
- }
- if dateType == 10 {
- startDate = ""
- endDate = ""
- }
- minValue := sourceEdbInfoItem.MinValue
- maxValue := sourceEdbInfoItem.MaxValue
- allDataList := make([]*data_manage.EdbDataList, 0)
- //获取指标数据(实际已生成)
- dataList, err := data_manage.GetEdbDataList(sourceEdbInfoItem.Source, sourceEdbInfoItem.SubSource, sourceEdbInfoItem.EdbInfoId, startDate, endDate)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- // 如果选择了日期,那么需要筛选所有的数据,用于未来指标的生成
- if startDate != `` {
- allDataList, err = data_manage.GetEdbDataList(sourceEdbInfoItem.Source, sourceEdbInfoItem.SubSource, sourceEdbInfoItem.EdbInfoId, "", "")
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- } else {
- allDataList = dataList
- }
- // 获取预测指标未来的数据
- if len(predictEdbConfAndDataList) > 0 {
- predictDataList := make([]*data_manage.EdbDataList, 0)
- if isTimeBetween { //如果是时间区间,那么
- reqEndDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
- endDateTime, _ := time.ParseInLocation(utils.FormatDate, req.PredictEndDate, time.Local)
- // 如果选择的时间区间结束日期 晚于 当天,那么预测数据截止到当天
- if reqEndDateTime.Before(endDateTime) {
- endDateStr = endDate
- }
- }
- // 获取预测数据
- var predictMinValue, predictMaxValue float64
- predictDataList, predictMinValue, predictMaxValue, err, errMsg := data.GetChartPredictEdbInfoDataListByConfList(predictEdbConfAndDataList, startDate, sourceEdbInfoItem.LatestDate, endDateStr, sourceEdbInfoItem.Frequency, req.DataDateType, allDataList)
- if err != nil {
- br.Msg = "获取预测指标数据失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "获取预测指标数据失败:" + err.Error()
- return
- }
- dataList = append(dataList, predictDataList...)
- if len(predictDataList) > 0 {
- // 如果最小值 大于 预测值,那么将预测值作为最小值数据返回
- if minValue > predictMinValue {
- minValue = predictMinValue
- }
- // 如果最大值 小于 预测值,那么将预测值作为最大值数据返回
- if maxValue < predictMaxValue {
- maxValue = predictMaxValue
- }
- }
- }
- // 季节性图、公历、农历处理
- resultDataList, err := data.GetChartDataList(dataList, req.ChartType, calendar, sourceEdbInfoItem.LatestDate, startDate)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp := response.PredictEdbInfoChartDataResp{
- MinValue: minValue,
- MaxValue: maxValue,
- DataList: resultDataList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // PredictRuleCalculateByNine
- // @Title 根据预测规则9来计算数据
- // @Description 获取指标数据
- // @Param request body data_manage.RuleConfig true "type json string"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /predict_edb_info/rule/calculate_by_nine [post]
- func (this *PredictEdbInfoController) PredictRuleCalculateByNine() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.RuleConfig
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- // 添加计算指标
- reqJson, err := json.Marshal(req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- respItem, err := data.PredictCalculateByNinePreview(string(reqJson), this.Lang)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = respItem.Msg
- br.ErrMsg = respItem.ErrMsg
- return
- }
- resp := respItem.Data
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Modify
- // @Title 修改指标信息接口
- // @Description 编辑指标接口
- // @Success 200 {object} request.EditEdbInfoReq
- // @router /predict_edb_info/modify [post]
- func (this *PredictEdbInfoController) Modify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.ModifyPredictEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- edbInfoId := req.EdbInfoId
- if edbInfoId <= 0 {
- br.Msg = "请选择预测指标"
- br.IsSendEmail = false
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "修改失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- var haveOperaAuth bool
- // 数据权限校验
- {
- haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- }
- // 编辑权限校验
- button := data.GetPredictEdbOpButton(this.SysUser, edbInfo.SysUserId, haveOperaAuth)
- if !button.OpButton {
- br.Msg = "无权限操作"
- br.IsSendEmail = false
- return
- }
- edbInfo.MaxValue = req.MaxValue
- edbInfo.MinValue = req.MinValue
- edbInfo.ModifyTime = time.Now()
- err = edbInfo.Update([]string{"MaxValue", "MinValue", "ModifyTime"})
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //修改es
- data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "修改成功"
- br.IsAddLog = true
- }
- // ClassifyEdbInfoItems
- // @Title 获取分类下指标接口
- // @Description 获取分类下指标接口
- // @Param ClassifyId query int true "分类id"
- // @Param IsShowMe query bool false "是否只看我的"
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /predict_edb_info/items [get]
- func (this *PredictEdbInfoController) ClassifyEdbInfoItems() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyId, _ := this.GetInt("ClassifyId")
- if classifyId <= 0 {
- br.Msg = "参数错误,请刷新页面"
- return
- }
- // 是否只看我的
- isShowMe, _ := this.GetBool("IsShowMe")
- // 如果选择了只看我的,那么只查询归属于我的账号
- sysUserId := 0
- if isShowMe {
- sysUserId = this.SysUser.AdminId
- }
- // 无权限指标 和 无权限指标分类id
- noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err := data_manage_permission.GetUserAllEdbAndClassifyNoPermissionList(this.SysUser.AdminId, utils.PREDICT_EDB_INFO_TYPE, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(classifyId, utils.PREDICT_EDB_INFO_TYPE, 0, sysUserId, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- list := make([]*data_manage.EdbClassifyItems, 0)
- edbInfoNum := len(allEdbInfo)
- if edbInfoNum > 0 {
- classifyIdList := make([]int, 0)
- for _, v := range allEdbInfo {
- classifyIdList = append(classifyIdList, v.ClassifyId)
- }
- classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类数据失败,Err:" + err.Error()
- return
- }
- // 分类map
- classifyMap := make(map[int]*data_manage.EdbClassify)
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- for _, v := range allEdbInfo {
- // 数据权限
- if classifyInfo, ok := classifyMap[v.ClassifyId]; ok {
- v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
- button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
- v.Button = button
- list = append(list, v)
- }
- }
- resp := new(data_manage.ClassifyEdbInfoListResp)
- resp.EdbInfoList = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ChartImageSetBySvg
- // @Title 设置指标的图表图片
- // @Description 设置指标的图表图片接口
- // @Param request body data_manage.SetChartInfoImageReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /predict_edb_info/image/set_by_svg [post]
- func (this *PredictEdbInfoController) ChartImageSetBySvg() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- imgData := this.GetString("Img")
- if imgData == "" {
- br.Msg = "图片参数错误"
- br.ErrMsg = "图片参数错误,Img Is Empty"
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId", 0)
- if edbInfoId <= 0 {
- br.Msg = "指标参数错误"
- br.ErrMsg = "指标参数错误,EdbInfoId Is Empty"
- return
- }
- // 通过svg图片生成图片资源地址
- resourceUrl, err, errMsg := services.GetResourceUrlBySvgImg(imgData)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- if edbInfoId <= 0 || resourceUrl == "" {
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- if utils.IsErrNoRow(err) {
- br.Msg = "找不到该指标"
- br.ErrMsg = "找不到该指标"
- br.IsSendEmail = false
- }
- return
- }
- edbInfo.ChartImage = resourceUrl
- err = edbInfo.Update([]string{"ChartImage"})
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- //修改es数据
- go data.AddOrEditEdbInfoToEs(edbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
|