12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394 |
- package data_manage
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/system"
- "eta/eta_api/services/data"
- etaTrialService "eta/eta_api/services/eta_trial"
- "eta/eta_api/utils"
- "fmt"
- "os"
- "path/filepath"
- "strconv"
- "strings"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/tealeg/xlsx"
- )
- type BaseFromUsdaFasController struct {
- controllers.BaseAuthController
- }
- // UsdaFasClassify
- // @Title 美国农业部数据分类
- // @Description 美国农业部数据分类接口
- // @Success 200 {object} data_manage.BaseFromUsdaFasClassify
- // @router /usda_fas/classify [get]
- func (this *BaseFromUsdaFasController) UsdaFasClassify() {
- 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
- }
- classifyAll, err := data_manage.GetAllBaseFromUsdaFasClassify()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- //组装一级分类
- rootMap := make(map[int][]*data_manage.BaseFromUsdaFasClassifyItems)
- list := make([]*data_manage.BaseFromUsdaFasClassifyItems, 0)
- for _, classify := range classifyAll {
- classify.UniqueCode = strconv.Itoa(classify.ClassifyId)
- if classify.ParentId == 0 {
- if _, ok := rootMap[classify.ClassifyId]; !ok {
- rootMap[classify.ClassifyId] = make([]*data_manage.BaseFromUsdaFasClassifyItems, 0)
- list = append(list, classify)
- }
- } else {
- child, ok := rootMap[classify.ParentId]
- if ok {
- child = append(child, classify)
- rootMap[classify.ParentId] = child
- }
- }
- }
- for k, v := range list {
- child, ok := rootMap[v.ClassifyId]
- if ok {
- list[k].Children = child
- }
- }
- //组装二级分类
- var ret data_manage.BaseFromUsdaFasClassifyResp
- ret.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ret
- }
- // UsdaFasIndexData
- // @Title 获取美国农业部数据
- // @Description 获取美国农业部数据接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyId query string true "分类id"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /usda_fas/index/data [get]
- func (this *BaseFromUsdaFasController) UsdaFasIndexData() {
- 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")
- //获取指标
- var condition string
- var pars []interface{}
- if classifyId >= 0 {
- classifyInfo, err := data_manage.GetBaseFromUsdaFasClassifyById(classifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "分类不存在"
- return
- }
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- if classifyInfo.Level == 2 || classifyInfo.ParentId > 0 {
- condition += ` AND classify_id=? `
- pars = append(pars, classifyId)
- } else if classifyInfo.Level == 1 {
- childClassify, err := data_manage.GetBaseFromUsdaFasClassifyByParentId(classifyId)
- if err != nil {
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取子分类信息失败,Err:" + err.Error()
- return
- }
- var classifyList []int
- for _, v := range childClassify {
- classifyList = append(classifyList, v.ClassifyId)
- }
- condition += ` AND classify_id IN (` + utils.GetOrmInReplace(len(classifyList)) + `) `
- pars = append(pars, classifyList)
- }
- }
- if frequency != "" {
- condition += ` AND frequency=? `
- pars = append(pars, frequency)
- }
- UsdaFasList, err := data_manage.GetUsdaFasIndex(condition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- edbCodeList := make([]string, 0)
- for _, v := range UsdaFasList {
- edbCodeList = append(edbCodeList, v.IndexCode)
- }
- edbInfoMap := make(map[string]*data_manage.EdbInfo)
- dataMap := make(map[string][]*data_manage.BaseFromUsdaFasData)
- total := 0
- if len(edbCodeList) > 0 {
- edbInfoList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_USDA_FAS, edbCodeList)
- if err != nil {
- br.Msg = "获取数据源失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- for _, v := range edbInfoList {
- edbInfoMap[v.EdbCode] = v
- }
- // 首先对分类下的指标按照日期进行分页,再针对日期,进行排序
- dataTimes, err := data_manage.GetUsdaFasIndexDataTimePageByCodes(edbCodeList, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据日期信息失败,Err:" + err.Error()
- return
- }
- if len(dataTimes) > 0 {
- startDate := dataTimes[len(dataTimes)-1]
- endDate := dataTimes[0]
- // 把截止日往后加1天
- endDateT, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
- endDate = endDateT.AddDate(0, 0, 1).Format(utils.FormatDate)
- dataList, e := data_manage.GetUsdaFasIndexDataByDataTime(edbCodeList, startDate, endDate)
- if e != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + e.Error()
- return
- }
- //将数据按照指标进行分类
- for _, v := range dataList {
- dataMap[v.IndexCode] = append(dataMap[v.IndexCode], v)
- }
- }
- total, err = data_manage.GetUsdaFasIndexDataTimePageCount(edbCodeList)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resultList := make([]*data_manage.BaseFromUsdaFasIndexList, 0)
- for _, v := range UsdaFasList {
- product := new(data_manage.BaseFromUsdaFasIndexList)
- product.BaseFromUsdaFasIndexId = v.BaseFromUsdaFasIndexId
- product.Unit = v.Unit
- product.IndexCode = v.IndexCode
- product.IndexName = v.IndexName
- product.Frequency = v.Frequency
- product.ModifyTime = v.ModifyTime
- if edb, ok := edbInfoMap[v.IndexCode]; ok {
- product.EdbInfoId = edb.EdbInfoId
- product.EdbExist = 1
- }
- /*total, err := data_manage.GetUsdaFasIndexDataCount(v.IndexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := data_manage.GetUsdaFasIndexData(v.IndexCode, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }*/
- dataListTmp, ok := dataMap[v.IndexCode]
- if !ok {
- dataListTmp = make([]*data_manage.BaseFromUsdaFasData, 0)
- }
- product.DataList = dataListTmp
- product.Paging = page
- resultList = append(resultList, product)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resultList
- }
- // UsdaFasSearchList
- // @Title UsdaFas模糊搜索
- // @Description UsdaFas模糊搜索
- // @Param Keyword query string ture "关键字搜索"
- // @Success 200 {object} models.BaseResponse
- // @router /usda_fas/search_list [get]
- func (this *BaseFromUsdaFasController) UsdaFasSearchList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- list := make([]*data_manage.BaseFromUsdaFasIndexSearchItem, 0)
- var err error
- //关键字
- keyword := this.GetString("Keyword")
- if keyword != "" {
- keyWordArr := strings.Split(keyword, " ")
- if len(keyWordArr) > 0 {
- condition := ""
- for _, v := range keyWordArr {
- condition += ` AND CONCAT(index_name,index_code) LIKE '%` + v + `%'`
- }
- list, err = data_manage.GetUsdaFasItemList(condition)
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- }
- } else {
- // todo es 模糊搜索
- list, err = data_manage.GetUsdaFasItemList("")
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- }
- classifyIds := make([]int, 0)
- for _, v := range list {
- classifyIds = append(classifyIds, v.ClassifyId)
- }
- classifyList, err := data_manage.GetBaseFromUsdaFasClassifyByIds(classifyIds)
- if err != nil {
- br.Msg = "搜索失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- classifyMap := make(map[int]int)
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v.ParentId
- }
- for _, v := range list {
- v.ParentClassifyId = classifyMap[v.ClassifyId]
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // UsdaFasSingleData
- // @Title 获取UsdaFas数据
- // @Description 获取UsdaFas单条数据接口
- // @Param IndexCode query string true "指标唯一编码"
- // @Success 200 {object} models.BaseResponse
- // @router /usda_fas/single_data [get]
- func (this *BaseFromUsdaFasController) UsdaFasSingleData() {
- 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.GetBaseFromUsdaFasIndexByIndexCode(indexCode)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- dataTmpList, err := data_manage.GetUsdaFasIndexDataByCode(indexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- edbInfo, err := data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_USDA_FAS, indexCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取数据源失败"
- br.ErrMsg = "获取数据源失败,Err:" + err.Error()
- return
- }
- var ret data_manage.UsdaFasSingleDataResp
- var dataList []*data_manage.UsdaFasSingleData
- if edbInfo != nil {
- ret.EdbInfoId = edbInfo.EdbInfoId
- ret.EdbExist = 1
- }
- ret.ClassifyId = indexInfo.ClassifyId
- ret.BaseFromUsdaFasIndexId = indexInfo.BaseFromUsdaFasIndexId
- ret.IndexCode = indexInfo.IndexCode
- 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
- for _, v := range dataTmpList {
- tmp := &data_manage.UsdaFasSingleData{
- Value: v.Value,
- DataTime: v.DataTime,
- }
- dataList = append(dataList, tmp)
- }
- ret.Data = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ret
- }
- // UsdaFasIndexList
- // @Title 美国农业部指标列表
- // @Description 美国农业部指标列表
- // @Param ClassifyId query int true "分类id"
- // @Success 200 {object} data_manage.BaseFromUsdaFasClassifyResp
- // @router /usda_fas/classify/index/list [get]
- func (this *BaseFromUsdaFasController) UsdaFasIndexList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyId, _ := this.GetInt("ClassifyId", 0)
- indexList, err := data_manage.GetUsdaFasIndexByClassifyId(classifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- var ret data_manage.BaseFromUsdaFasClassifyResp
- list := make([]*data_manage.BaseFromUsdaFasClassifyItems, 0)
- for _, v := range indexList {
- classify := new(data_manage.BaseFromUsdaFasClassifyItems)
- classify.ClassifyId = classifyId
- classify.BaseFromUsdaFasIndexId = v.BaseFromUsdaFasIndexId
- classify.IndexCode = v.IndexCode
- classify.ClassifyName = v.IndexName
- classify.UniqueCode = fmt.Sprintf("%d_%d", classifyId, v.BaseFromUsdaFasIndexId)
- list = append(list, classify)
- }
- ret.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ret
- }
- // UsdaFasBatchSearch
- // @Title 美国农业部指标查询
- // @Description 美国农业部指标查询
- // @Param ClassifyIds query string true "分类id, 多个分类用英文"
- // @Param Keyword query string true "关键词, 指标ID/指标名称"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /usda_fas/batch_search [get]
- func (this *BaseFromUsdaFasController) UsdaFasBatchSearch() {
- 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
- }
- classifyIdStr := this.GetString("ClassifyIds")
- 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)
- resp := data_manage.BaseFromUsdaFasIndexSearchList{}
- total := 0
- page := paging.GetPaging(currentIndex, pageSize, total)
- var list = make([]*data_manage.BaseFromUsdaFasIndexList, 0)
- var condition string
- var pars []interface{}
- classifyIds := strings.Split(classifyIdStr, ",")
- if len(classifyIds) > 0 && classifyIds[0] != `` {
- condition += " AND classify_id IN (" + utils.GetOrmInReplace(len(classifyIds)) + " ) "
- pars = append(pars, classifyIds)
- }
- keyword := this.GetString("Keyword")
- if keyword != `` {
- condition += " AND (index_name like ? OR index_code like ?) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- frequencies := this.GetString("Frequencies")
- if frequencies != "" {
- frequencyList := strings.Split(frequencies, ",")
- condition += " AND frequency IN (" + utils.GetOrmInReplace(len(frequencyList)) + " ) "
- pars = append(pars, frequencyList)
- }
- /*if classifyIdStr == `` && keyword == `` && frequencies == `` {
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }*/
- condition += ` AND index_code not in (SELECT edb_code FROM edb_info WHERE source=?) `
- pars = append(pars, utils.DATA_SOURCE_USDA_FAS)
- list, err := data_manage.GetUsdaFasIndexPage(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- total, err = data_manage.GetUsdaFasIndexPageCount(condition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // UsdaFasBatchAdd
- // @Title 美国农业部批量新增
- // @Description 美国农业部批量新增
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /usda_fas/batch_add [post]
- func (this *BaseFromUsdaFasController) UsdaFasBatchAdd() {
- 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_UsdaFas_" + 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_manage.UsdaFasIndexSource2EdbReq
- 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, e, errMsg, skip := data.UsdaFasIndexSource2Edb(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
- }
- // UsdaFasNameCheck
- // @Title 加入指标库的重名检测
- // @Description 加入指标库的重名检测
- // @Param ClassifyIds query string true "分类id, 多个分类用英文"
- // @Param Keyword query string true "关键词, 指标ID/指标名称"
- // @Success 200 {object} NameCheckResult
- // @router /usda_fas/edb_info/name_check [post]
- func (this *BaseFromUsdaFasController) UsdaFasNameCheck() {
- 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 []*data_manage.NameCheckEdbInfoReq
- 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
- }
- codeMaxT := 30
- codeLen := len(req)
- if codeLen > codeMaxT {
- br.Msg = "批量添加指标数量不得超过30个"
- return
- }
- indexNames := make([]string, 0)
- resp := make([]*data_manage.EdbNameCheckResult, 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, &data_manage.EdbNameCheckResult{
- EdbCode: v.EdbCode,
- EdbName: v.EdbName,
- })
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(v.EdbCode, utils.DATA_SOURCE_USDA_FAS, 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_USDA_FAS, 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
- }
- // UsdaFasAddCheck
- // @Title 加入指标库指标Id检测
- // @Description 加入指标库指标Id检测
- // @Param request body request.BatchAddCheckReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /usda_fas/edb_info/add_check [post]
- func (c *BaseFromUsdaFasController) UsdaFasAddCheck() {
- 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.BatchAddCheckReq
- if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- codeMaxT := 30
- codeLen := len(req.IndexCodes)
- // 获取指标库已有指标
- existsEdb, e := data_manage.GetEdbCodesBySource(utils.DATA_SOURCE_USDA_FAS)
- 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
- }
- if codeLen == 0 {
- br.Msg = "请选择指标"
- return
- }
- if codeLen > codeMaxT {
- br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMaxT)
- return
- }
- // 查询选中的指标
- cond := fmt.Sprintf(` AND index_code IN (%s)`, utils.GetOrmInReplace(codeLen))
- pars := make([]interface{}, 0)
- pars = append(pars, req.IndexCodes)
- list, err := data_manage.GetUsdaFasIndex(cond, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(list) > codeMaxT {
- br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMaxT)
- return
- }
- resp := make([]*data_manage.BaseFromUsdaFasIndexList, 0)
- for _, v := range list {
- if edb, ok := existMap[v.IndexCode]; ok {
- v.EdbInfoId = edb.EdbInfoId
- v.EdbClassifyId = edb.ClassifyId
- v.EdbUniqueCode = edb.UniqueCode
- v.EdbExist = 1
- }
- resp = append(resp, v)
- }
- br.Data = resp
- br.Msg = "校验成功"
- br.Ret = 200
- br.Success = true
- }
- // UsdaFasEdbInfoAdd
- // @Title 新增指标接口
- // @Description 新增指标接口
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /usda_fas/edb_info/add [post]
- func (this *BaseFromUsdaFasController) UsdaFasEdbInfoAdd() {
- 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
- }
- count, err := data_manage.GetUsdaFasIndexDataCount(req.EdbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if count == 0 {
- br.Msg = "指标不存在"
- }
- // 指标入库
- edbInfo, err, errMsg, isSendEmail := data.EdbInfoAdd(utils.DATA_SOURCE_USDA_FAS, 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)
- }()
- }
- //新增操作日志
- {
- 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
- }
- // ExportUsdaFasList
- // @Title 导出美国农业部数据
- // @Description 导出美国农业部数据
- // @Param ClassifyId query int true "关键字搜索"
- // @Param IndexCode query string true "指标编码"
- // @Success 200 导出成功
- // @router /usda_fas/export [get]
- func (this *BaseFromUsdaFasController) ExportUsdaFasList() {
- 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("ClassifyId")
- indexCode := this.GetString("IndexCode")
- if classifyId <= 0 && indexCode == "" {
- br.Msg = "请选择分类或者指标"
- return
- }
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- var condition string
- var pars []interface{}
- var classifyName string
- if classifyId > 0 {
- classifyInfo, err := data_manage.GetBaseFromUsdaFasClassifyById(classifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "分类不存在"
- return
- }
- br.Msg = "下载失败"
- br.ErrMsg = "获取分类失败,Err:" + err.Error()
- return
- }
- classifyName = classifyInfo.ClassifyName
- childClassify, err := data_manage.GetBaseFromUsdaFasClassifyByParentId(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.ClassifyId)
- }
- } else {
- condition += ` AND classify_id=?`
- pars = append(pars, classifyId)
- }
- }
- if indexCode != "" {
- condition += ` AND index_code=? `
- pars = append(pars, indexCode)
- }
- indexList, err := data_manage.GetUsdaFasIndex(condition, pars)
- if err != nil {
- br.Msg = "下载失败"
- br.ErrMsg = "获取指标失败,Err:" + err.Error()
- fmt.Println("获取数据失败,Err:" + err.Error())
- return
- }
- if len(indexList) <= 0 {
- fmt.Println("indexList 为空")
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- return
- }
- codeList := make([]string, 0)
- frequenciesMap := make(map[string][]*data_manage.BaseFromUsdaFasIndexList)
- for _, v := range indexList {
- codeList = append(codeList, v.IndexCode)
- frequenciesMap[v.Frequency] = append(frequenciesMap[v.Frequency], v)
- }
- dataListMap := make(map[string][]*data_manage.BaseFromUsdaFasData)
- if len(indexList) > 0 {
- allDataList, e := data_manage.GetUsdaFasIndexDataByCodes(codeList)
- if e != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + e.Error()
- return
- }
- for _, v := range allDataList {
- dataListMap[v.IndexCode] = append(dataListMap[v.IndexCode], v)
- }
- }
- // 按照频率分组排序
- frequencies := []string{
- "日度", "周度", "旬度", "月度", "季度", "半年度", "年度",
- }
- for _, frequency := range frequencies {
- //获取指标
- indexCodeList, ok := frequenciesMap[frequency]
- if !ok {
- continue
- }
- if len(indexCodeList) <= 0 {
- fmt.Printf("sheet:%s, 不存在指标", frequency)
- return
- }
- var sheetName string
- switch frequency {
- case "日度":
- sheetName = "日度(Daily)"
- case "周度":
- sheetName = "周度(Weekly)"
- case "旬度":
- sheetName = "旬度(ten-day)"
- case "月度":
- sheetName = "月度(Monthly)"
- case "季度":
- sheetName = "季度(Quarterly)"
- case "半年度":
- sheetName = "半年度(Semi-annual)"
- case "年度":
- sheetName = "年度(Annual)"
- default:
- sheetName = "其他数据"
- }
- sheetNew, err := xlsxFile.AddSheet(sheetName)
- 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 _, idx := range frequenciesMap[frequency] {
- indexIdList = append(indexIdList, idx.BaseFromUsdaFasIndexId)
- }
- dataTimeList, err := data_manage.GetUsdaFasDataDataTimeByIndexId(indexIdList)
- if err != nil {
- br.Msg = "下载失败"
- br.ErrMsg = "获取数据时间失败,Err:" + err.Error()
- 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, icl := range indexCodeList {
- // 获取数据
- dataList, ok := dataListMap[icl.IndexCode]
- if !ok {
- continue
- }
- if k == 0 {
- secNameRow.AddCell().SetValue("指标名称/Metric Name")
- frequencyRow.AddCell().SetValue("频度/Frequency")
- unitRow.AddCell().SetValue("单位/Unit")
- lastModifyDateRow.AddCell().SetValue("更新时间/Update Time")
- min := k * 3
- sheetNew.SetColWidth(min, min, 15)
- }
- if len(dataList) == 0 {
- continue
- }
- secNameRow.AddCell().SetValue(icl.IndexName)
- frequencyRow.AddCell().SetValue(icl.Frequency)
- unitRow.AddCell().SetValue(icl.Unit)
- timeDate, err := time.Parse(utils.FormatDateTime, dataList[0].ModifyTime)
- if err != nil {
- continue
- }
- lastModifyDateRow.AddCell().SetValue(timeDate.Format(utils.FormatDate))
- dataInfoMap := make(map[string]*data_manage.BaseFromUsdaFasData)
- 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("")
- e := xlsxFile.Save(downLoadnFilePath)
- if e != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- }
- fileName := classifyName
- if indexCode != "" && len(indexList) == 1 {
- fileName = indexList[0].IndexName
- }
- fileName = strings.Replace(fileName, ": ", "_", -1)
- fileName = strings.Replace(fileName, ", ", "_", -1)
- fileName = strings.Replace(fileName, " ", "_", -1)
- fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
- fmt.Println(fileName)
- this.Ctx.Output.Download(downLoadnFilePath, fileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
- // GetFrequency
- // @Title 美国农业部数据频度
- // @Description 美国农业部数据频度接口
- // @Param ClassifyId query string true "分类Id"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /usda_fas/frequency [get]
- func (this *BaseFromUsdaFasController) GetFrequency() {
- 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.GetUsdaFasFrequencyByClassifyId(classifyId)
- if err != nil {
- br.Msg = "获取频度失败"
- br.ErrMsg = "获取频度失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = frequencyList
- }
- // BatchAddEdbCheck
- // @Title 新增校验
- // @Description 新增校验
- // @Param request body data_manage.BatchManualEdbReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /usda_fas/batch/add/check [post]
- func (c *BaseFromUsdaFasController) BatchAddEdbCheck() {
- 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
- }
- // 最大批量添加的数量
- codeMaxT := 31
- var req data_manage.BatchCheckUsdaFasEdbReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,Err:" + err.Error()
- return
- }
- req.Keyword = strings.TrimSpace(req.Keyword)
- classifyIdStr := req.ClassifyIds
- var list = make([]*data_manage.BaseFromUsdaFasIndexList, 0)
- var condition string
- var pars []interface{}
- if req.ListAll {
- classifyIds := strings.Split(classifyIdStr, ",")
- if len(classifyIds) > 0 && classifyIds[0] != `` {
- condition += " AND classify_id IN (" + utils.GetOrmInReplace(len(classifyIds)) + " ) "
- pars = append(pars, classifyIds)
- }
- keyword := req.Keyword
- if keyword != `` {
- condition += " AND (index_name like ? OR index_code like ?) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- frequencies := req.Frequencies
- if frequencies != "" {
- frequencyList := strings.Split(frequencies, ",")
- condition += " AND frequency IN (" + utils.GetOrmInReplace(len(frequencyList)) + " ) "
- pars = append(pars, frequencyList)
- }
- codes := req.TradeCodeList
- codeList := make([]string, 0)
- if codes != "" {
- codeList = strings.Split(codes, ",")
- }
- if len(codeList) > 0 {
- condition += ` AND index_code not in (` + utils.GetOrmInReplace(len(codeList)) + `) `
- pars = append(pars, codeList)
- }
- } else {
- codes := req.TradeCodeList
- codeList := make([]string, 0)
- if codes != "" {
- codeList = strings.Split(codes, ",")
- }
- if len(codeList) <= 0 {
- br.Msg = "请选择指标"
- br.ErrMsg = "请选择指标"
- return
- }
- // 指标
- condition += ` AND index_code in (` + utils.GetOrmInReplace(len(codeList)) + `) `
- pars = append(pars, codeList)
- }
- condition += ` AND index_code not in (SELECT edb_code FROM edb_info WHERE source=?) `
- pars = append(pars, utils.DATA_SOURCE_USDA_FAS)
- list, err = data_manage.GetUsdaFasIndexPage(condition, pars, 0, codeMaxT)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if len(list) >= codeMaxT {
- br.Msg = "批量添加指标数量不得超过30个"
- return
- }
- br.Data = list
- br.Msg = "校验成功"
- br.Ret = 200
- br.Success = true
- }
|