1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651 |
- package data_manage
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/data_manage/request"
- "eta/eta_api/models/data_manage/response"
- "eta/eta_api/models/system"
- "eta/eta_api/services/data"
- etaTrialService "eta/eta_api/services/eta_trial"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "os"
- "path/filepath"
- "strconv"
- "strings"
- "time"
- "github.com/tealeg/xlsx"
- )
- type ClarksonsDataController struct {
- controllers.BaseAuthController
- }
- // @Title 克拉克森数据分类
- // @Description 克拉克森数据分类接口
- // @Success 200 {object} data_manage.SciClassify
- // @router /clarksons/classify [get]
- func (this *ClarksonsDataController) Classify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyList, err := data_manage.GetClarksonsClassifyAll()
- if err != nil {
- br.Msg = "查询失败"
- br.ErrMsg = "查询失败, Err:" + err.Error()
- return
- }
- initClassify := &data_manage.BaseFromClarksonsClassifyItem{
- BaseFromClassifyId: 0,
- ClassifyName: "未分类",
- ClassifyNameEn: "Unclassified",
- UniqueCode: "0",
- ParentId: 0,
- Level: 1,
- Sort: 0,
- Children: nil,
- }
- finalList := make([]*data_manage.BaseFromClarksonsClassifyItem, 0)
- classifyTree := getClarksonsClassifyTree(classifyList, 0)
- finalList = append(finalList, initClassify)
- finalList = append(finalList, classifyTree...)
- br.Msg = "查询成功"
- br.Data = finalList
- br.Success = true
- br.Ret = 200
- }
- // AddSciClassify
- // @Title 新增分类
- // @Description 新增分类接口
- // @Param request body data_manage.AddBaseFromSciClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /clarksons/classify/add [post]
- func (this *ClarksonsDataController) AddClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.AddBaseFromClarksonsClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "请输入分类名称"
- return
- }
- if req.ParentId < 0 {
- br.Msg = "操作异常"
- return
- }
- ok, msg, err := data.AddClarksonsClassify(req.ClassifyName, req.ParentId)
- if err != nil {
- br.Msg = "添加失败"
- br.ErrMsg = "添加失败,Err:" + err.Error()
- return
- }
- if !ok {
- if msg != "" {
- br.Msg = msg
- return
- }
- br.Msg = "添加失败"
- return
- }
- br.Msg = "添加成功"
- br.Success = true
- br.Ret = 200
- }
- // DelClassify
- // @Title 新增分类
- // @Description 新增分类接口
- // @Param request body data_manage.AddBaseFromSciClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /clarksons/classify/del [post]
- func (this *ClarksonsDataController) DelClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.DelBaseFromClarksonsClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromClassifyId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err = data.DelClarksonsClassify(req.BaseFromClassifyId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Msg = "删除成功"
- br.Success = true
- br.IsAddLog = true
- }
- // EditClassify
- // @Title 修改分类
- // @Description 修改分类接口
- // @Param request body data_manage.EditBaseFromMysteelChemicalClassifyReq true "type json string"
- // @Success 200 Ret=200 修改成功
- // @router /clarksons/classify/edit [post]
- func (this *ClarksonsDataController) EditClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.EditBaseFromClarksonsClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromClassifyId <= 0 {
- br.Msg = "参数错误"
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "请输入分类名称"
- return
- }
- classify, err := data_manage.GetClarksonsClassifyById(req.BaseFromClassifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "分类不存在"
- return
- }
- br.Msg = "编辑失败"
- br.ErrMsg = "获取分类失败,Err:" + err.Error()
- return
- }
- if classify.ClassifyName != req.ClassifyName {
- count, err := data_manage.GetClarksonsClassifyCountByName(req.ClassifyName)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "获取分类失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "分类名称已存在"
- return
- }
- classify.ClassifyName = req.ClassifyName
- classify.ModifyTime = time.Now()
- err = classify.Update([]string{"classify_name", "modify_time"})
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- }
- br.Msg = "编辑成功"
- br.Success = true
- br.Ret = 200
- br.IsAddLog = true
- }
- // MoveClassify
- // @Title 分类移动接口
- // @Description 分类移动接口
- // @Success 200 {object} data_manage.MoveBaseFromMysteelChemicalClassifyReq
- // @router /clarksons/classify/move [post]
- func (this *ClarksonsDataController) MoveClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.MoveBaseFromClarksonsClassifyReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromClassifyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "分类id小于等于0"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.MoveClarksonsClassify(req.BaseFromClassifyId, req.ParentId, req.PrevClassifyId, req.NextClassifyId)
- 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.IsAddLog = true
- br.Msg = "移动成功"
- }
- // IndexList
- // @Title 克拉克森指标列表
- // @Description 克拉克森数据指标列表接口
- // @Param BaseFromClassifyId query int true "分类id"
- // @Success 200 {object} data_manage.BaseFromMysteelChemicalIndexResp
- // @router /clarksons/index/list [get]
- func (this *ClarksonsDataController) IndexList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyId, _ := this.GetInt("BaseFromClassifyId", 0)
- indexList, err := data_manage.GetClarksonsIndexBaseInfoByClassifyId(classifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = indexList
- }
- // GetClarksonsIndexInfo
- // @Title 添加指标-根据条件获取指标信息
- // @Description 添加指标-根据条件获取指标信息
- // @Param KeyWord query string false "关键字"
- // @Param ClassifyIds query string false "分类id"
- // @Param Frequencies query string false "频率"
- // @Param PageSize query int false "每页数据条数"
- // @Param CurrentIndex query int false "当前页页码,从1开始"
- // @Success 200 {object} data_manage.BaseFromRzdIndexPage
- // @router /clarksons/get/index/info [post]
- func (this *ClarksonsDataController) GetClarksonsIndexInfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- 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.ClarksonsDataBatchListReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- keyWord := req.KeyWord
- classifyIds := req.ClassifyIds
- frequencies := req.Frequencies
- pageSize := req.PageSize
- currentIndex := req.CurrentIndex
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var classifyIdList []string
- var frequencyList []string
- if classifyIds != "" {
- classifyIdList = strings.Split(classifyIds, ",")
- }
- if frequencies != "" {
- frequencyList = strings.Split(frequencies, ",")
- }
- indexInfoPage, err := data.GetClarksonsIndexInfo(keyWord, classifyIdList, frequencyList, currentIndex, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = indexInfoPage
- }
- // SearchList
- // @Title 克拉克森模糊搜索
- // @Description 克拉克森模糊搜索
- // @Param Keyword query string true "关键字搜索"
- // @Success 200 {object} models.BaseResponse
- // @router /clarksons/search_list [get]
- func (this *ClarksonsDataController) SearchList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- //关键字
- keyword := this.GetString("Keyword")
- var condition string
- var pars []interface{}
- if keyword != "" {
- condition += ` AND (index_code LIKE ? OR index_name LIKE ?)`
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- } else {
- br.Msg = "请输入指标ID/指标名称"
- return
- }
- list, err := data_manage.GetClarksonsIndexBaseInfoByCondition(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // SingleData
- // @Title 获取克拉克森据
- // @Description 获取克拉克森单条数据接口
- // @Param BaseFromClarksonsIndexId query string true "指标唯一编码"
- // @Success 200 {object} models.BaseResponse
- // @router /clarksons/single_data [get]
- func (this *ClarksonsDataController) SingleData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- baseFromClarksonsIndexId, _ := this.GetInt("BaseFromClarksonsIndexId")
- indexInfo, err := data_manage.GetClarksonsIndexByIndexId(baseFromClarksonsIndexId)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- edbInfo, err := data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_CLARKSONS, indexInfo.IndexCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标数据失败"
- br.ErrMsg = "获取指标库数据失败,Err:" + err.Error()
- return
- }
- var edbInfoId int
- if edbInfo != nil {
- edbInfoId = edbInfo.EdbInfoId
- }
- dataList, err := data_manage.GetClarksonsDataByIndexId(baseFromClarksonsIndexId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- var ret response.ClarksonsSingleDataResp
- ret.ClassifyId = indexInfo.ClassifyId
- ret.BaseFromClarksonsIndexId = indexInfo.BaseFromClarksonsIndexId
- ret.IndexCode = indexInfo.IndexCode
- ret.EdbInfoId = edbInfoId
- ret.IndexName = indexInfo.IndexName
- ret.Frequency = indexInfo.Frequency
- ret.CreateTime = indexInfo.CreateTime.Format(utils.FormatDateTime)
- ret.ModifyTime = indexInfo.ModifyTime.Format(utils.FormatDateTime)
- ret.Unit = indexInfo.Unit
- ret.Data = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ret
- }
- // MoveClarksonsData
- // @Title 克拉克森指标移动接口
- // @Description 克拉克森指标移动接口
- // @Success 200 {object} request.MoveBaseFromClarksonsReq
- // @router /clarksons/move [post]
- func (this *ClarksonsDataController) MoveClarksonsData() {
- 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.MoveBaseFromClarksonsReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromClarksonsIndexId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- br.IsSendEmail = false
- return
- }
- if req.BaseFromClassifyId < 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.MoveClarksonsData(req.BaseFromClarksonsIndexId, req.BaseFromClassifyId, req.PrevBaseFromClarksonsIndexId, req.NextBaseFromClarksonsIndexId)
- 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.IsAddLog = true
- br.Msg = "移动成功"
- }
- // ResetClarksonsIndex
- // @Title 指标数据清除分类
- // @Description 指标数据清除分类
- // @Param request body data_manage.DelBaseFromSciReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /clarksons/reset [post]
- //func (this *ClarksonsDataController) ResetClarksonsIndex() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // this.Data["json"] = br
- // this.ServeJSON()
- // }()
- // var req request.ResetBaseFromClarksonsReq
- // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- // if err != nil {
- // br.Msg = "参数解析异常!"
- // br.ErrMsg = "参数解析失败,Err:" + err.Error()
- // return
- // }
- //
- // if req.BaseFromClarksonsIndexId < 0 {
- // br.Msg = "参数错误"
- // br.IsSendEmail = false
- // return
- // }
- //
- // err = data.ResetClarksonsIndex(req.BaseFromClarksonsIndexId)
- // if err != nil {
- // br.Msg = "移动失败"
- // br.ErrMsg = "移动失败,Err:" + err.Error()
- // return
- // }
- //
- // br.Ret = 200
- // br.Msg = "操作成功"
- // br.Success = true
- // br.IsAddLog = true
- //}
- // AddEdbInfo
- // @Title 新增指标接口
- // @Description 新增指标接口
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /clarksons/edb_info/add [post]
- //func (this *ClarksonsDataController) AddEdbInfo() {
- // 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 data_manage.AddEdbInfoReq
- // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- // if err != nil {
- // br.Msg = "参数解析异常!"
- // br.ErrMsg = "参数解析失败,Err:" + err.Error()
- // return
- // }
- //
- // req.EdbName = strings.Trim(req.EdbName, " ")
- // req.EdbCode = strings.Trim(req.EdbCode, " ")
- //
- // if req.EdbCode == "" {
- // br.Msg = "指标ID不能为空"
- // return
- // }
- //
- // if req.EdbName == "" {
- // br.Msg = "指标名称不能为空"
- // return
- // }
- //
- // if req.Frequency == "" {
- // br.Msg = "频率不能为空"
- // return
- // }
- //
- // if req.Unit == "" {
- // br.Msg = "单位不能为空"
- // return
- // }
- //
- // if req.ClassifyId <= 0 {
- // br.Msg = "请选择分类"
- // return
- // }
- //
- // _, err = data_manage.GetClarksonsIndexByIndexCode(req.EdbCode)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // br.Msg = "指标不存在"
- // return
- // }
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- // }
- // source := utils.DATA_SOURCE_CLARKSONS
- // // 指标入库
- // edbInfo, err, errMsg, isSendEmail := data.EdbInfoAdd(source, utils.DATA_SUB_SOURCE_EDB, req.ClassifyId, req.EdbCode, req.EdbName, req.Frequency, req.Unit, req.StartDate, req.EndDate, sysUser.AdminId, sysUser.RealName, this.Lang)
- // if err != nil {
- // br.Msg = "保存失败"
- // if errMsg != `` {
- // br.Msg = errMsg
- // }
- // br.ErrMsg = err.Error()
- // br.IsSendEmail = isSendEmail
- // return
- // }
- //
- // // 试用平台更新用户累计新增指标数
- // adminItem, e := system.GetSysAdminById(sysUser.AdminId)
- // if e != nil {
- // br.Msg = "操作失败"
- // br.ErrMsg = "获取系统用户数据失败,Err:" + e.Error()
- // return
- // }
- // if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
- // go func() {
- // var r etaTrialService.EtaTrialUserReq
- // r.Mobile = adminItem.Mobile
- // _, _ = etaTrialService.UpdateUserIndexNum(r)
- // }()
- // }
- //
- // //新增操作日志
- // {
- // // 添加钢联指标更新日志
- // if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- // go data_stat.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", sysUser, 2)
- // }
- //
- // edbLog := new(data_manage.EdbInfoLog)
- // edbLog.EdbInfoId = edbInfo.EdbInfoId
- // edbLog.SourceName = edbInfo.SourceName
- // edbLog.Source = edbInfo.Source
- // edbLog.EdbCode = edbInfo.EdbCode
- // edbLog.EdbName = edbInfo.EdbName
- // edbLog.ClassifyId = edbInfo.ClassifyId
- // edbLog.SysUserId = sysUser.AdminId
- // edbLog.SysUserRealName = sysUser.RealName
- // edbLog.CreateTime = time.Now()
- // edbLog.Content = string(this.Ctx.Input.RequestBody)
- // edbLog.Status = "新增指标"
- // edbLog.Method = this.Ctx.Input.URI()
- // go data_manage.AddEdbInfoLog(edbLog)
- // }
- //
- // // 更新es
- // go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
- //
- // resp := new(data_manage.AddEdbInfoResp)
- // resp.EdbInfoId = edbInfo.EdbInfoId
- // resp.UniqueCode = edbInfo.UniqueCode
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "保存成功"
- // br.Data = resp
- // br.IsAddLog = true
- //}
- // AddCheck
- // @Title 新增校验
- // @Description 新增校验
- // @Param request body request.BusinessDataBatchAddCheckReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /clarksons/edb_info/add_check [post]
- func (this *ClarksonsDataController) AddCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- 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.ClarksonsDataBatchAddCheckReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- codeMax := 30
- codeLen := len(req.IndexCodes)
- if len(req.IndexCodes) == 0 {
- br.Msg = "请选择指标"
- return
- }
- if codeLen > codeMax {
- br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
- return
- }
- // 获取指标库已有指标
- existsEdb, e := data_manage.GetEdbCodesBySource(utils.DATA_SOURCE_CLARKSONS)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取自有数据已添加的指标失败, Err: " + e.Error()
- return
- }
- existMap := make(map[string]*data_manage.EdbInfo)
- for _, v := range existsEdb {
- existMap[v.EdbCode] = v
- }
- // 查询选中的指标
- cond := fmt.Sprintf(` AND index_code IN (%s)`, utils.GetOrmInReplace(codeLen))
- pars := make([]interface{}, 0)
- pars = append(pars, req.IndexCodes)
- list, err := data_manage.GetClarksonsIndexAndEdbInfoByCondition(cond, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取克拉克森原始指标列表失败, Err: " + err.Error()
- return
- }
- resp := make([]*data_manage.BaseFromClarksonsIndexView, 0)
- for _, v := range list {
- if v.EdbInfoId > 0 {
- v.EdbExist = 1
- }
- resp = append(resp, v)
- }
- br.Data = resp
- br.Msg = "校验成功"
- br.Ret = 200
- br.Success = true
- }
- // NameCheck
- // @Title 重名校验
- // @Description 批量新增
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /clarksons/edb_info/name_check [post]
- func (c *ClarksonsDataController) NameCheck() {
- 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 []*data_manage.NameCheckEdbInfoReq
- if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if len(req) == 0 {
- br.Msg = "请选择指标"
- return
- }
- codeMax := 30
- codeLen := len(req)
- if codeLen > codeMax {
- br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
- return
- }
- type NameCheckResult struct {
- EdbCode string
- EdbName string
- Exist bool
- }
- indexNames := make([]string, 0)
- resp := make([]*NameCheckResult, 0)
- for _, v := range req {
- v.EdbCode = strings.TrimSpace(v.EdbCode)
- if v.EdbCode == "" {
- br.Msg = "指标ID不可为空"
- return
- }
- v.EdbName = strings.TrimSpace(v.EdbName)
- if v.EdbName == "" {
- br.Msg = "请输入指标名称"
- return
- }
- indexNames = append(indexNames, v.EdbName)
- resp = append(resp, &NameCheckResult{
- EdbCode: v.EdbCode,
- EdbName: v.EdbName,
- })
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(v.EdbCode, utils.DATA_SOURCE_CLARKSONS, 0, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取克拉克森已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) <= 0 {
- respItem, err := data.AddEdbData(utils.DATA_SOURCE_CLARKSONS, v.EdbCode, v.Frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + v.EdbCode
- return
- }
- }
- }
- // 重名校验
- edbList, e := data_manage.GetEdbInfoByNameArr(indexNames, utils.EDB_INFO_TYPE)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取重名指标失败, Err: " + e.Error()
- return
- }
- nameExists := make(map[string]bool)
- for _, v := range edbList {
- nameExists[v.EdbName] = true
- }
- if len(nameExists) > 0 {
- for _, v := range resp {
- v.Exist = nameExists[v.EdbName]
- }
- }
- br.Data = resp
- br.Msg = "校验成功"
- br.Ret = 200
- br.Success = true
- }
- // BatchAdd
- // @Title 批量新增
- // @Description 批量新增
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /clarksons/edb_info/batch_add [post]
- func (this *ClarksonsDataController) BatchAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- 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_BATCH_ADD_CLARKSONS_" + 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 []*data_manage.AddEdbInfoReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if len(req) == 0 {
- br.Msg = "请选择指标"
- return
- }
- if len(req) > 30 {
- br.Msg = "批量添加指标数量不得超过30个"
- return
- }
- for _, v := range req {
- v.EdbCode = strings.TrimSpace(v.EdbCode)
- if v.EdbCode == "" {
- br.Msg = "指标ID不可为空"
- return
- }
- v.EdbName = strings.TrimSpace(v.EdbName)
- if v.EdbName == "" {
- br.Msg = "请输入指标名称"
- return
- }
- v.Frequency = strings.TrimSpace(v.Frequency)
- if v.Frequency == "" {
- br.Msg = "请选择频度"
- return
- }
- v.Unit = strings.TrimSpace(v.Unit)
- if v.Unit == "" {
- br.Msg = "请输入单位"
- return
- }
- if v.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- }
- // 限定同一时间最多批量新增30个指标
- for _, v := range req {
- var r data.ClarksonsIndexSource2EdbReq
- r.EdbCode = v.EdbCode
- r.EdbName = v.EdbName
- r.Frequency = v.Frequency
- r.Unit = v.Unit
- r.ClassifyId = v.ClassifyId
- r.AdminId = sysUser.AdminId
- r.AdminRealName = sysUser.RealName
- edbInfo, errMsg, skip, e := data.ClarksonsIndexSource2Edb(r, this.Lang)
- if e != nil {
- br.Msg = "操作失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- br.ErrMsg = e.Error()
- return
- }
- if skip {
- continue
- }
- // 试用平台更新用户累计新增指标数
- if utils.BusinessCode == utils.BusinessCodeSandbox {
- go func() {
- adminItem, e := system.GetSysAdminById(sysUser.AdminId)
- if e != nil {
- tips := fmt.Sprintf("试用平台更新用户累计新增指标数-获取用户失败, Err: " + e.Error())
- utils.FileLog.Info(tips)
- return
- }
- if adminItem.DepartmentName != "ETA试用客户" {
- return
- }
- var ur etaTrialService.EtaTrialUserReq
- ur.Mobile = adminItem.Mobile
- _, _ = etaTrialService.UpdateUserIndexNum(ur)
- }()
- }
- // 新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- }
- br.Msg = "操作成功"
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- }
- // BatchDelete
- // @Title 批量删除
- // @Description 批量删除
- // @Param request body []*request.DelBaseFromClarksonsReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /clarksons/edb_info/batch_delete [post]
- func (this *ClarksonsDataController) BatchDelete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req []*request.DelBaseFromClarksonsReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if len(req) == 0 {
- br.Msg = "请选择指标"
- return
- }
- if len(req) > 30 {
- br.Msg = "批量添加指标数量不得超过30个"
- return
- }
- var deleteIds []int
- for _, v := range req {
- if v.BaseFromClarksonsIndexId <= 0 {
- continue
- }
- deleteIds = append(deleteIds, v.BaseFromClarksonsIndexId)
- }
- existList, err := data.BatchDelClarksonsData(deleteIds)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Data = existList
- br.Msg = "操作成功"
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- }
- // BatchEdit
- // @Title 批量编辑
- // @Description 批量编辑
- // @Param request body []*request.DelBaseFromClarksonsReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /clarksons/edb_info/batch_edit [post]
- func (this *ClarksonsDataController) BatchEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req []*request.EditBaseFromClarksonsReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if len(req) == 0 {
- br.Msg = "请选择指标"
- return
- }
- indexIds := make([]int, 0)
- classifyIds := make([]int, 0)
- indexIdToclassifyId := make(map[int]int)
- for _, v := range req {
- if v.BaseFromClarksonsIndexId <= 0 {
- continue
- }
- if v.BaseFromClassifyId <= 0 {
- continue
- }
- indexIds = append(indexIds, v.BaseFromClarksonsIndexId)
- classifyIds = append(classifyIds, v.BaseFromClassifyId)
- indexIdToclassifyId[v.BaseFromClarksonsIndexId] = v.BaseFromClassifyId
- }
- if len(indexIds) == 0 {
- br.Msg = "请选择指标或指定正确的分类"
- return
- }
- indexList, err := data_manage.GetClarksonsIndexListByIndexIds(indexIds)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "获取指标失败,Err:" + err.Error()
- return
- }
- classifySort, err := data_manage.GetClarksonsClassifyMaxSortByClassifyIds(classifyIds)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "获取分类最大排序失败,Err:" + err.Error()
- return
- }
- classifySortMap := make(map[int]int)
- for _, v := range classifySort {
- classifySortMap[v.BaseFromClassifyId] = v.MaxSort
- }
- classifyList, err := data_manage.GetClarksonsClassifyListByIds(classifyIds)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "获取分类失败,Err:" + err.Error()
- return
- }
- existClassifyList := make(map[int]struct{})
- for _, v := range classifyList {
- existClassifyList[v.BaseFromClassifyId] = struct{}{}
- }
- //编辑指标
- updateIndexList := make([]*data_manage.BaseFromClarksonsIndex, 0)
- for _, v := range indexList {
- tmpClassifyId := indexIdToclassifyId[v.BaseFromClarksonsIndexId]
- if _, ok := existClassifyList[tmpClassifyId]; ok {
- v.ClassifyId = tmpClassifyId
- v.Sort = classifySortMap[tmpClassifyId] + 1
- classifySortMap[tmpClassifyId] += 1
- updateIndexList = append(updateIndexList, v)
- }
- }
- err = data_manage.BatchModifyClarksonsIndexClassify(updateIndexList)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑指标失败,Err:" + err.Error()
- return
- }
- br.Msg = "操作成功"
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- }
- // EditClarksons
- // @Title 编辑克拉克森指标
- // @Description 编辑克拉克森指标接口
- // @Param request body data_manage.AddEdbClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /clarksons/edit [post]
- func (this *ClarksonsDataController) EditClarksons() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.EditBaseFromClarksonsReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromClarksonsIndexId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- if req.BaseFromClassifyId <= 0 {
- br.Msg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- //编辑指标
- sciIndexInfo, errMsg, err := data.EditClarksonsIndex(req.BaseFromClarksonsIndexId, req.BaseFromClassifyId)
- if errMsg != `` {
- br.Msg = errMsg
- return
- }
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑指标失败,Err:" + err.Error()
- return
- }
- resp := response.EditClarksonsIndexInfoResp{
- BaseFromClarksonsIndexId: sciIndexInfo.BaseFromClarksonsIndexId,
- IndexCode: sciIndexInfo.IndexCode,
- }
- br.Data = resp
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // DeleteClarksonsData
- // @Title 删除指标
- // @Description 删除指标接口
- // @Param request body data_manage.DelBaseFromSciReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /clarksons/del [post]
- func (this *ClarksonsDataController) DeleteClarksonsData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.DelBaseFromClarksonsReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromClarksonsIndexId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.DelClarksonsData(req.BaseFromClarksonsIndexId)
- 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.Msg = "删除成功"
- br.Success = true
- br.IsAddLog = true
- }
- // ExportClarksonsList
- // @Title 导出Sci数据
- // @Description 导出Sci数据
- // @Param BaseFromClassifyId query int true "关键字搜索"
- // @Param IndexCode query string true "指标编码"
- // @Success 200 导出成功
- // @router /export/clarksonsList [get]
- func (this *ClarksonsDataController) ExportClarksonsList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- classifyId, _ := this.GetInt("BaseFromClassifyId")
- indexCode := this.GetString("IndexCode")
- if classifyId < 0 {
- br.Msg = "请选择分类"
- return
- }
- secNameList := make([]*data_manage.BaseFromClarksonsIndex, 0)
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- var condition string
- var pars []interface{}
- if classifyId > 0 {
- childClassify, err := data_manage.GetChildClarksonsClassifyListById(classifyId)
- if err != nil {
- br.Msg = "下载失败"
- br.ErrMsg = "获取分类失败,Err:" + err.Error()
- return
- }
- if len(childClassify) > 0 {
- condition += `AND classify_id IN (` + utils.GetOrmInReplace(len(childClassify)) + `)`
- for _, child := range childClassify {
- pars = append(pars, child.BaseFromClassifyId)
- }
- } else {
- condition += ` AND classify_id=?`
- pars = append(pars, classifyId)
- }
- } else {
- condition += ` AND classify_id=?`
- pars = append(pars, classifyId)
- }
- if indexCode != "" {
- condition += ` AND index_code=? `
- pars = append(pars, indexCode)
- }
- frequencies, err := data_manage.GetClarksonsFrequencyByCondition(condition, pars)
- if err != nil {
- fmt.Println("GetSciFrequency err:", err.Error())
- utils.FileLog.Info("GetSciFrequency err:" + err.Error())
- return
- }
- for _, frequency := range frequencies {
- //获取指标
- secNameList, err = data_manage.GetClarksonsIndexByConditionAndFrequency(condition, *frequency, pars)
- if err != nil {
- fmt.Println("获取数据失败,Err:" + err.Error())
- return
- }
- if len(secNameList) <= 0 {
- fmt.Println("secNameList长度为0")
- return
- }
- sheetNew, err := xlsxFile.AddSheet(*frequency)
- if err != nil {
- fmt.Println("新增Sheet失败", err.Error())
- return
- }
- secNameRow := sheetNew.AddRow()
- frequencyRow := sheetNew.AddRow()
- unitRow := sheetNew.AddRow()
- lastModifyDateRow := sheetNew.AddRow()
- var indexIdList []int
- for _, sv := range secNameList {
- indexIdList = append(indexIdList, sv.BaseFromClarksonsIndexId)
- }
- dataTimeList, err := data_manage.GetClarksonsDataDataTimeByIndexId(indexIdList)
- if err != nil {
- fmt.Println("获取数据时间失败", err.Error())
- return
- }
- // 添加excel左侧指标日期
- setRowIndex := 4
- for rk, dv := range dataTimeList {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- }
- for k, sv := range secNameList {
- //获取数据
- dataList, err := data_manage.GetClarksonsIndexDataByCode(sv.IndexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if k == 0 {
- secNameRow.AddCell().SetValue("指标名称")
- frequencyRow.AddCell().SetValue("频率")
- unitRow.AddCell().SetValue("单位")
- lastModifyDateRow.AddCell().SetValue("更新时间")
- min := k * 3
- sheetNew.SetColWidth(min, min, 15)
- }
- if len(dataList) == 0 {
- continue
- }
- secNameRow.AddCell().SetValue(sv.IndexName)
- frequencyRow.AddCell().SetValue(sv.Frequency)
- unitRow.AddCell().SetValue(sv.Unit)
- lastModifyDateRow.AddCell().SetValue(sv.ModifyTime.Format(utils.FormatDate))
- dataInfoMap := make(map[string]*data_manage.BaseFromClarksonsData)
- for _, v := range dataList {
- dataInfoMap[v.DataTime] = v
- }
- for rk, dtv := range dataTimeList {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- displayDateCell := row.AddCell()
- tmpData, ok := dataInfoMap[dtv]
- if ok {
- displayDateCell.SetValue(tmpData.Value)
- }
- }
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- //有指标无数据时先导出一遍空表
- sheet, err := xlsxFile.AddSheet("无数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- rowSecName := sheet.AddRow()
- celSecName := rowSecName.AddCell()
- celSecName.SetValue("")
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- }
- fileName := `克拉克森`
- if indexCode != "" && len(secNameList) == 1 {
- fileName = secNameList[0].IndexName
- }
- fileName += time.Now().Format("2006.01.02") + `.xlsx` //文件名称
- this.Ctx.Output.Download(downLoadnFilePath, fileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
- // getClarksonsClassifyTree 返回卓创红旗的树形结构
- func getClarksonsClassifyTree(items []*data_manage.BaseFromClarksonsClassifyItem, parentId int) []*data_manage.BaseFromClarksonsClassifyItem {
- res := make([]*data_manage.BaseFromClarksonsClassifyItem, 0)
- for _, item := range items {
- if item.ParentId == parentId {
- t := new(data_manage.BaseFromClarksonsClassifyItem)
- t.BaseFromClassifyId = item.BaseFromClassifyId
- t.ClassifyName = item.ClassifyName
- t.ParentId = item.ParentId
- t.Level = item.Level
- t.Sort = item.Sort
- t.ModifyTime = item.ModifyTime
- t.CreateTime = item.CreateTime
- t.ClassifyNameEn = item.ClassifyNameEn
- if item.UniqueCode == "" {
- t.UniqueCode = strconv.Itoa(item.BaseFromClassifyId)
- }
- t.Children = getClarksonsClassifyTree(items, item.BaseFromClassifyId)
- res = append(res, t)
- }
- }
- return res
- }
- // @Title 获取克拉克森数据
- // @Description 获取克拉克森数据接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param BaseFromSci99ClassifyId query int true "分类id"
- // @Param KeyWord query string true "关键词"
- // @Success 200 {object} data_source.BaseFromSci99IndexView
- // @router /clarksons/index/data [get]
- func (this *ClarksonsDataController) ClarksonsData() {
- 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
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- baseFromClarksonsClassifyId, _ := this.GetInt("BaseFromClarksonsClassifyId")
- if baseFromClarksonsClassifyId < 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- return
- }
- keyword := this.GetString("KeyWord")
- //获取指标
- var condition string
- var pars []interface{}
- if baseFromClarksonsClassifyId > 0 {
- condition += ` AND classify_id=? `
- pars = append(pars, baseFromClarksonsClassifyId)
- }
- if keyword != "" {
- condition += ` AND (index_code =? OR index_name LIKE ?) `
- pars = append(pars, keyword)
- pars = append(pars, "%"+keyword+"%")
- }
- sci99List, err := data_manage.GetClarksonsIndex(condition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resultList := make([]*data_manage.BaseFromClarksonsIndexList, 0)
- for _, v := range sci99List {
- product := new(data_manage.BaseFromClarksonsIndexList)
- product.BaseFromClarksonsIndexId = v.BaseFromClarksonsIndexId
- product.ClassifyId = v.ClassifyId
- product.IndexCode = v.IndexCode
- product.IndexName = v.IndexName
- product.Frequency = v.Frequency
- product.Unit = v.Unit
- product.ModifyTime = v.ModifyTime
- modifyTime, err := data_manage.GetClarksonsIndexLatestDate(v.IndexCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取更新时间失败"
- br.ErrMsg = "获取更新时间失败,Err:" + err.Error()
- return
- }
- product.ModifyTime = modifyTime
- total, err := data_manage.GetClarksonsIndexDataCount(v.IndexCode)
- page := paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := data_manage.GetClarksonsIndexData(v.IndexCode, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- if dataList == nil {
- dataList = make([]*data_manage.BaseFromClarksonsData, 0)
- }
- product.DataList = dataList
- product.Paging = page
- resultList = append(resultList, product)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resultList
- }
- // IndexPageList
- // @Title 克拉克森指标列表
- // @Description 克拉克森数据指标列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyId query int true "分类id"
- // @Param IsListAll query int true "是否展示全部"
- // @Success 200 {object} data_manage.BaseFromMysteelChemicalIndexResp
- // @router /clarksons/index/page/list [get]
- func (this *ClarksonsDataController) IndexPageList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyId, _ := this.GetInt("ClassifyId", 0)
- pageSize, _ := this.GetInt("PageSize")
- currrentIndex, _ := this.GetInt("CurrentIndex")
- isListAll, _ := this.GetBool("IsListAll")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currrentIndex <= 0 {
- currrentIndex = 1
- }
- startSize = utils.StartIndex(currrentIndex, pageSize)
- var total int
- var indexList []*data_manage.BaseFromClarksonsIndexView
- if isListAll {
- tmpTotal, err := data_manage.GetClarksonsIndexCount()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- total = tmpTotal
- tmpIndexList, err := data_manage.GetClarksonsIndexByPage(startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- indexList = tmpIndexList
- } else {
- var classifyIds []int
- if classifyId > 0 {
- tmpClassifyIds, err := data_manage.GetClarksonsChildClassifyIdsById(classifyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- if len(tmpClassifyIds) > 0 {
- classifyIds = append(classifyIds, tmpClassifyIds...)
- }
- }
- classifyIds = append(classifyIds, classifyId)
- tmpTotal, err := data_manage.GetClarksonsIndexCountByClassifyId(classifyIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- total = tmpTotal
- tmpIndexList, err := data_manage.GetClarksonsIndexByClassifyId(classifyIds, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- indexList = tmpIndexList
- }
- page := paging.GetPaging(currrentIndex, pageSize, total)
- resp := new(response.ClarksonsIndexPageListResp)
- resp.List = indexList
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|