1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138 |
- package data_manage
- import (
- "encoding/json"
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/data_manage/request"
- "eta/eta_api/services/alarm_msg"
- "eta/eta_api/services/data"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/tealeg/xlsx"
- "os"
- "path/filepath"
- "strings"
- "time"
- )
- // @Title 百川盈孚数据分类
- // @Description 百川盈孚数据分类接口
- // @Success 200 {object} data_manage.BaiinfoClassify
- // @router /baiinfo/classify [get]
- func (this *EdbInfoController) BaiinfoClassify() {
- 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
- }
- rootList, err := data_manage.GetBaseFromBaiinfoClassifyByParentId(0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := data_manage.GetAllBaseFromBaiinfoClassify()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- baseFromBaiinfoIndexMap := make(map[int][]*data_manage.BaseFromBaiinfoClassifyItems)
- allBaseFromBaiinfoIndex, err := data_manage.GetBaiinfoIndexAll()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- for _, v := range allBaseFromBaiinfoIndex {
- baseFromBaiinfoIndexMap[v.ClassifyId] = append(baseFromBaiinfoIndexMap[v.ClassifyId], v)
- }
- rootChildMap := make(map[int][]*data_manage.BaseFromBaiinfoClassifyItems)
- for _, v := range classifyAll {
- rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
- if existItems, ok := baseFromBaiinfoIndexMap[v.ClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.BaseFromBaiinfoClassifyItems, 0)
- v.Children = items
- }
- }
- var ret data_manage.BaseFromBaiinfoClassifyResp
- nodeAll := make([]*data_manage.BaseFromBaiinfoClassifyItems, 0)
- for _, v := range rootList {
- if existItems, ok := rootChildMap[v.ClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.BaseFromBaiinfoClassifyItems, 0)
- v.Children = items
- }
- nodeAll = append(nodeAll, v)
- }
- //查询未分类的指标列表
- initClassify := &data_manage.BaseFromBaiinfoClassifyItems{
- ClassifyId: 0,
- BaseFromBaiinfoIndexId: 0,
- ClassifyName: "未分类",
- ClassifyNameEn: "Unclassified",
- ParentId: 0,
- Level: 1,
- Sort: 0,
- Children: nil,
- }
- initIndexList, err := data_manage.GetBaseFromBaiinfoIndexByClassifyId(initClassify.ClassifyId)
- if err != nil {
- br.Msg = "获取未分类指标失败"
- br.ErrMsg = "获取未分类指标失败,Err:" + err.Error()
- return
- }
- for _, v := range initIndexList {
- tmp := &data_manage.BaseFromBaiinfoClassifyItems{
- ClassifyId: v.ClassifyId,
- BaseFromBaiinfoIndexId: v.BaseFromBaiinfoIndexId,
- BaseFromBaiinfoIndexCode: v.IndexCode,
- ClassifyName: v.IndexName,
- ParentId: 0,
- Level: 0,
- Sort: 0,
- Children: nil,
- }
- initClassify.Children = append(initClassify.Children, tmp)
- }
- finalList := make([]*data_manage.BaseFromBaiinfoClassifyItems, 0)
- finalList = append(finalList, initClassify)
- finalList = append(finalList, nodeAll...)
- ret.List = finalList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ret
- }
- // BaiinfoClassifyName
- // @Title 百川盈孚数据分类名称查询
- // @Description 百川盈孚数据分类名称查询接口
- // @Success 200 {object} data_manage.BaiinfoClassify
- // @router /baiinfo/classify/name [get]
- func (this *EdbInfoController) BaiinfoClassifyName() {
- 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
- }
- rootList, err := data_manage.GetBaseFromBaiinfoClassifyByParentId(0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := data_manage.GetAllBaseFromBaiinfoClassify()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- rootChildMap := make(map[int][]*data_manage.BaseFromBaiinfoClassifyNameItems)
- for _, v := range classifyAll {
- tmp := &data_manage.BaseFromBaiinfoClassifyNameItems{
- ClassifyId: v.ClassifyId,
- ClassifyName: v.ClassifyName,
- ParentId: v.ParentId,
- Children: nil,
- }
- rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], tmp)
- }
- var ret data_manage.BaseFromBaiinfoClassifyNameResp
- nodeAll := make([]*data_manage.BaseFromBaiinfoClassifyNameItems, 0)
- for _, v := range rootList {
- tmp := &data_manage.BaseFromBaiinfoClassifyNameItems{
- ClassifyId: v.ClassifyId,
- ClassifyName: v.ClassifyName,
- ParentId: v.ParentId,
- Children: nil,
- }
- if existItems, ok := rootChildMap[v.ClassifyId]; ok {
- tmp.Children = existItems
- } else {
- items := make([]*data_manage.BaseFromBaiinfoClassifyNameItems, 0)
- tmp.Children = items
- }
- nodeAll = append(nodeAll, tmp)
- }
- ret.List = nodeAll
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ret
- }
- // AddBaiinfoClassify
- // @Title 新增分类
- // @Description 新增分类接口
- // @Param request body data_manage.AddBaseFromBaiinfoClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /baiinfo/classify/add [post]
- func (this *EdbInfoController) AddBaiinfoClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.AddBaseFromBaiinfoClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- req.ClassifyName = utils.TrimStr(req.ClassifyName)
- req.ClassifyName = strings.Replace(req.ClassifyName, "/t", "", -1)
- //添加指标
- baiinfoClassifyInfo, err, errMsg := data.AddBaiinfoClassify(req.ClassifyName, req.ParentId, this.SysUser.AdminId, this.SysUser.RealName, this.Lang)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = errMsg + ";Err:" + err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- // 如果是添加一级分类,那么默认加上 价格、供应、需求、库存 四个二级分类
- if baiinfoClassifyInfo.ParentId == 0 {
- secondClassifyList := []string{"价格", "供应", "需求", "库存"}
- for _, v := range secondClassifyList {
- _, _, tmpErrMsg := data.AddBaiinfoClassify(v, baiinfoClassifyInfo.ClassifyId, this.SysUser.AdminId, this.SysUser.RealName, this.Lang)
- if tmpErrMsg != `` {
- go alarm_msg.SendAlarmMsg("SCI原始数据-添加一级分类时,默认添加二级分类失败,一级分类名称:"+req.ClassifyName+",二级分类名称:"+v+", Err:"+tmpErrMsg, 3)
- return
- }
- }
- }
- resp := data_manage.AddBaiinfoClassifyResp{
- ClassifyId: baiinfoClassifyInfo.ClassifyId,
- //UniqueCode: fmt.Sprint(BaiinfoClassifyInfo.BaseFromBaiinfoClassifyId),
- }
- br.Data = resp
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // EditBaiinfoClassify
- // @Title 修改分类
- // @Description 修改分类接口
- // @Param request body data_manage.EditBaseFromMysteelChemicalClassifyReq true "type json string"
- // @Success 200 Ret=200 修改成功
- // @router /baiinfo/classify/edit [post]
- func (this *EdbInfoController) EditBaiinfoClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.EditBaseFromBaiinfoClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.EditBaiinfoClassify(req.ClassifyId, req.ClassifyName, this.Lang, this.SysUser)
- 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
- }
- // @Title 百川盈孚数据频度
- // @Description 百川盈孚数据频度接口
- // @Param ClassifyId query string true "分类Id"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /baiinfo/frequency [get]
- func (this *EdbInfoController) BaiinfoFrequency() {
- 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")
- if classifyId < 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- return
- }
- frequencyList, err := data_manage.GetBaiinfoFrequencyByClassifyId(classifyId)
- if err != nil {
- br.Msg = "获取频度失败"
- br.ErrMsg = "获取频度失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = frequencyList
- }
- // MoveBaiinfoClassify
- // @Title 分类移动接口
- // @Description 分类移动接口
- // @Success 200 {object} data_manage.MoveBaseFromMysteelChemicalClassifyReq
- // @router /baiinfo/classify/move [post]
- func (this *EdbInfoController) MoveBaiinfoClassify() {
- 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.MoveBaseFromBaiinfoClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "分类id小于等于0"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.MoveBaiinfoClassify(req.ClassifyId, 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 = "移动成功"
- }
- // DeleteBaiinfoClassify
- // @Title 删除分类
- // @Description 删除分类接口
- // @Param request body data_manage.DelBaseFromBaiinfoClassifyReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /baiinfo/classify/del [post]
- func (this *EdbInfoController) DeleteBaiinfoClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.DelBaseFromBaiinfoClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.DelBaiinfoClassify(req.ClassifyId, this.SysUser)
- 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
- }
- // MoveBaiinfoData
- // @Title SCI指标移动接口
- // @Description SCI指标移动接口
- // @Success 200 {object} data_manage.MoveBaseFromBaiinfoReq
- // @router /baiinfo/move [post]
- func (this *EdbInfoController) MoveBaiinfoData() {
- 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.MoveBaseFromBaiinfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromBaiinfoIndexId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- br.IsSendEmail = false
- return
- }
- if req.ClassifyId < 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.MoveBaiinfoData2(req.BaseFromBaiinfoIndexId, req.ClassifyId, req.PrevBaseFromBaiinfoIndexId, req.NextBaseFromBaiinfoIndexId)
- 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 = "移动成功"
- }
- // EditBaiinfo
- // @Title 编辑百川盈孚指标
- // @Description 编辑百川盈孚指标接口
- // @Param request body data_manage.AddEdbClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /baiinfo/edit [post]
- func (this *EdbInfoController) EditBaiinfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.EditBaseFromBaiinfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromBaiinfoIndexId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- if req.ClassifyId < 0 {
- br.Msg = "请选择分类"
- br.IsSendEmail = false
- return
- }
- //百川数据可能没有频度和单位
- //if req.Frequency == "" {
- // br.Msg = "请输入频度名称"
- // br.IsSendEmail = false
- // return
- //}
- //
- //if req.Unit == "" {
- // br.Msg = "请输入单位名称"
- // br.IsSendEmail = false
- // return
- //}
- //编辑指标
- baiinfoIndexInfo, err, errMsg := data.EditBaiinfoIndex(req.BaseFromBaiinfoIndexId, req.ClassifyId, req.Frequency, req.Unit, this.SysUser)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = errMsg + ";Err:" + err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- resp := data_manage.EditBaiinfoIndexInfoResp{
- BaseFromBaiinfoIndexId: baiinfoIndexInfo.BaseFromBaiinfoIndexId,
- IndexCode: baiinfoIndexInfo.IndexCode,
- }
- br.Data = resp
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // @Title 获取钢联数据
- // @Description 获取钢联数据接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyId query string true "分类id"
- // @Param Frequency query string true "频度名称"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /baiinfo/data [get]
- func (this *EdbInfoController) BaiinfoData() {
- 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)
- classifyId, _ := this.GetInt("ClassifyId")
- if classifyId < 0 {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- return
- }
- frequency := this.GetString("Frequency")
- //if frequency == "" {
- // br.Msg = "请选择频度"
- // br.ErrMsg = "请选择频度"
- // return
- //}
- //获取指标
- var condition string
- var pars []interface{}
- if classifyId >= 0 {
- condition += ` AND classify_id=? `
- pars = append(pars, classifyId)
- }
- if frequency != "" {
- condition += ` AND frequency=? `
- pars = append(pars, frequency)
- }
- baiinfoList, err := data_manage.GetBaiinfoIndex(condition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resultList := make([]*data_manage.BaiinfoIndexList, 0)
- for _, v := range baiinfoList {
- product := new(data_manage.BaiinfoIndexList)
- product.BaseFromBaiinfoIndexId = v.BaseFromBaiinfoIndexId
- product.Unit = v.Unit
- product.IndexCode = v.IndexCode
- product.IndexName = v.IndexName
- product.Frequency = v.Frequency
- product.ModifyTime = v.ModifyTime
- total, err := data_manage.GetBaiinfoIndexDataCount(v.IndexCode)
- page := paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := data_manage.GetBaiinfoIndexData(v.IndexCode, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- if dataList == nil {
- dataList = make([]*data_manage.BaiinfoIndexData, 0)
- }
- product.DataList = dataList
- product.Paging = page
- resultList = append(resultList, product)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resultList
- }
- // BaiinfoSearchList
- // @Title SCI模糊搜索
- // @Description SCI模糊搜索
- // @Param Keyword query string ture "关键字搜索"
- // @Success 200 {object} models.BaseResponse
- // @router /baiinfo/search_list [get]
- func (this *EdbInfoController) BaiinfoSearchList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- //关键字
- keyword := this.GetString("Keyword")
- list, err := data_manage.GetBaiinfoItemList(keyword)
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // BaiinfoSingleData
- // @Title 获取Baiinfo数据
- // @Description 获取baiinfo单条数据接口
- // @Param IndexCode query string true "指标唯一编码"
- // @Success 200 {object} models.BaseResponse
- // @router /baiinfo/single_data [get]
- func (this *EdbInfoController) BaiinfoSingleData() {
- 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
- }
- indexCode := this.GetString("IndexCode")
- indexInfo, err := data_manage.GetBaseFromBaiinfoIndexByIndexCode(indexCode)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- dataList, err := data_manage.GetBaiinfoIndexDataByCode(indexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- var ret data_manage.BaiinfoSingleDataResp
- ret.ClassifyId = indexInfo.ClassifyId
- ret.BaseFromBaiinfoIndexId = indexInfo.BaseFromBaiinfoIndexId
- ret.IndexCode = indexInfo.IndexCode
- ret.IndexName = indexInfo.IndexName
- ret.Frequency = indexInfo.Frequency
- ret.Interface = indexInfo.Interface
- 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
- }
- // DeleteBaiinfoData
- // @Title 删除指标
- // @Description 删除指标接口
- // @Param request body data_manage.DelBaseFromBaiinfoReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /baiinfo/del [post]
- func (this *EdbInfoController) DeleteBaiinfoData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.DelBaseFromBaiinfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromBaiinfoIndexId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.DelBaiinfoData(req.BaseFromBaiinfoIndexId)
- 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
- }
- // ResetBaiinfoData
- // @Title 指标数据清除分类
- // @Description 指标数据清除分类
- // @Param request body data_manage.DelBaseFromBaiinfoReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /baiinfo/reset [post]
- func (this *EdbInfoController) ResetBaiinfoData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.DelBaseFromBaiinfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.BaseFromBaiinfoIndexId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.ResetBaiinfoData(req.BaseFromBaiinfoIndexId)
- 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
- }
- // ExportBaiinfoList
- // @Title 导出Baiinfo数据
- // @Description 导出Baiinfo数据
- // @Param IndexName query string false "名称关键词"
- // @Param IndexCode query string false "指标唯一编码"
- // @Param ClassifyId query string true "分类"
- // @Param Frequency query string true "频度"
- // @Param UnitName query string false "单位"
- // @Param ModifyTime query string false "更新时间"
- // @Success 200 导出成功
- // @router /export/baiinfoList [get]
- func (this *EdbInfoController) ExportBaiinfoList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- //typeName := this.GetString("TypeName") //分类
- //frequency := this.GetString("Frequency")
- indexCode := this.GetString("IndexCode") //指标唯一编码
- classifyId, _ := this.GetInt("ClassifyId")
- secNameList := make([]*models.EdbdataExportList, 0)
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if classifyId >= 0 && indexCode == "" {
- frequencies, err := data_manage.GetBaiinfoFrequency(classifyId)
- if err != nil {
- fmt.Println("GetBaiinfoFrequency err:", err.Error())
- utils.FileLog.Info("GetBaiinfoFrequency err:" + err.Error())
- return
- }
- for _, frequency := range frequencies {
- //获取指标
- var pars []interface{}
- pars = append(pars, classifyId)
- pars = append(pars, frequency)
- condition := " AND classify_id=? AND frequency=? "
- secNameList, err := data_manage.GetBaiinfoIndex(condition, pars)
- if err != nil {
- fmt.Println("获取数据失败,Err:" + err.Error())
- return
- }
- if len(secNameList) <= 0 {
- fmt.Println("secNameList长度为0")
- return
- }
- var sheetNew *xlsx.Sheet
- if *frequency == "" {
- newFrequency := "无频度"
- sheetNew, err = xlsxFile.AddSheet(newFrequency)
- } else {
- sheetNew, err = xlsxFile.AddSheet(*frequency)
- }
- if err != nil {
- fmt.Println("新增Sheet失败", err.Error())
- return
- }
- //sheetNew.SetColWidth()
- //获取指标数据
- windRow := sheetNew.AddRow()
- secNameRow := sheetNew.AddRow()
- indexCodeRow := sheetNew.AddRow()
- frequencyRow := sheetNew.AddRow()
- unitRow := sheetNew.AddRow()
- lastModifyDateRow := sheetNew.AddRow()
- //获取分类下指标最大数据量
- dataMax, err := data_manage.GetBaiinfoDataMaxCount(classifyId)
- if err != nil {
- fmt.Println("获取指标最大数据量失败", err.Error())
- return
- }
- fmt.Println("dataMax:", dataMax)
- setRowIndex := 6
- for k, sv := range secNameList {
- //获取数据
- dataList, err := data_manage.GetBaiinfoIndexDataByCode(sv.IndexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if len(dataList) > 0 {
- windRow.AddCell().SetValue("Baiinfo")
- secNameRow.AddCell().SetValue("指标名称")
- indexCodeRow.AddCell().SetValue("指标ID")
- frequencyRow.AddCell().SetValue("频率")
- unitRow.AddCell().SetValue("单位")
- lastModifyDateRow.AddCell().SetValue("更新时间")
- secNameRow.AddCell().SetValue(sv.IndexName)
- indexCodeRow.AddCell().SetValue(sv.IndexCode)
- frequencyRow.AddCell().SetValue(sv.Frequency)
- unitRow.AddCell().SetValue(sv.Unit)
- lastModifyDateRow.AddCell().SetValue(sv.ModifyTime)
- windRow.AddCell()
- windRow.AddCell()
- secNameRow.AddCell()
- indexCodeRow.AddCell()
- frequencyRow.AddCell()
- unitRow.AddCell()
- lastModifyDateRow.AddCell()
- min := k * 3
- sheetNew.SetColWidth(min, min, 15)
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := setRowIndex + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- row.AddCell().SetValue(dv.Value)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- }
- }
- } else {
- frequencies, err := data_manage.GetBaiinfoFrequencyByCode(indexCode)
- if err != nil {
- fmt.Println("GetBaiinfoFrequencyByCode err:", err.Error())
- utils.FileLog.Info("GetBaiinfoFrequencyByCode err:" + err.Error())
- return
- }
- for _, frequency := range frequencies {
- //获取数据
- dataList, err := data_manage.GetBaiinfoIndexDataByCode(indexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if len(dataList) > 0 {
- name := this.GetString("IndexName")
- unit := this.GetString("UnitName")
- modifyTime := this.GetString("ModifyTime")
- var sheet *xlsx.Sheet
- if *frequency == "" {
- newFrequency := "无频度"
- sheet, err = xlsxFile.AddSheet(newFrequency)
- } else {
- sheet, err = xlsxFile.AddSheet(*frequency)
- }
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- //获取指标数据
- windRow := sheet.AddRow()
- windRow.AddCell().SetValue("Baiinfo")
- rowSecName := sheet.AddRow()
- celSecName := rowSecName.AddCell()
- celSecName.SetValue("指标名称")
- cellSenName := rowSecName.AddCell()
- cellSenName.SetValue(name)
- indexCodeRow := sheet.AddRow()
- indexCodeRow.AddCell().SetValue("指标ID")
- indexCodeRow.AddCell().SetValue(indexCode)
- rowFrequency := sheet.AddRow()
- celFrequency := rowFrequency.AddCell()
- celFrequency.SetValue("频率")
- cellFrequency := rowFrequency.AddCell()
- cellFrequency.SetValue(*frequency)
- rowUnit := sheet.AddRow()
- celUnit := rowUnit.AddCell()
- celUnit.SetValue("单位")
- cellUnit := rowUnit.AddCell()
- cellUnit.SetValue(unit)
- rowModifyDate := sheet.AddRow()
- rowModifyCell := rowModifyDate.AddCell()
- rowModifyCell.SetValue("更新时间")
- rowModifyCell = rowModifyDate.AddCell()
- rowModifyCell.SetValue(modifyTime)
- dataMax, err := data_manage.GetBaiinfoIndexDataCount(indexCode)
- if err != nil {
- br.Msg = "查询数量失败"
- br.ErrMsg = "GetBaiinfoIndexDataCount,Err:" + err.Error()
- return
- }
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := 6 + n
- row := sheet.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := 6 + rk
- row := sheet.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- row.AddCell().SetValue(dv.Value)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheet.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- }
- }
- 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 := `Baiinfo数据`
- if len(secNameList) > 0 {
- fileName = secNameList[0].ClassifyName
- }
- fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
- this.Ctx.Output.Download(downLoadnFilePath, fileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
|