123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- package trade_analysis
- import (
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- tradeAnalysisModel "eta/eta_api/models/data_manage/trade_analysis"
- "eta/eta_api/services/data/trade_analysis"
- "eta/eta_api/utils"
- "fmt"
- "strings"
- )
- // TradeAnalysisController 供应分析
- type TradeAnalysisController struct {
- controllers.BaseAuthController
- }
- // GetClassifyName
- // @Title 获取交易所合约列表
- // @Description 获取交易所合约列表
- // @Param request body saModel.SaCompareSaveReq true "type json string"
- // @Success 200 {object} trade_analysis.TradeClassifyNameListSort
- // @router /classify [get]
- func (c *TradeAnalysisController) GetClassifyName() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- c.Data["json"] = br
- c.ServeJSON()
- }()
- //userinfo := userService.GetInfoByClaims(c)
- list, err, errMsg := trade_analysis.GetClassifyName(c.Lang)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "获取失败, ErrMsg: " + err.Error()
- return
- }
- br.Data = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // GetPositionTop
- // @Title 获取合约榜单详情
- // @Description 获取合约榜单详情
- // @Param Exchange query string false "交易所"
- // @Param ClassifyName query string false "分类名称"
- // @Param ClassifyType query string false "具体合约名称"
- // @Param DataTime query string false "请求日期,如果为空,则返回最新的榜单日期"
- // @Success 200 {object} trade_analysis.GetPositionTopResp
- // @Success 200 Ret=200 操作成功
- // @router /top [get]
- func (c *TradeAnalysisController) GetPositionTop() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- c.Data["json"] = br
- c.ServeJSON()
- }()
- req := tradeAnalysisModel.GetPositionTopReq{
- Exchange: c.GetString("Exchange"),
- ClassifyName: c.GetString("ClassifyName"),
- ClassifyType: c.GetString("ClassifyType"),
- DataTime: c.GetString("DataTime"),
- }
- if req.ClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- if req.ClassifyType == "" {
- br.Msg = "请输入合约名称"
- br.IsSendEmail = false
- return
- }
- list, err, errMsg := trade_analysis.GetPositionTopDetail(req)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- br.Data = list
- br.Ret = 200
- br.Success = true
- return
- }
- // GetTradeExchangeList
- // @Title 获取交易所列表
- // @Description 获取交易所列表
- // @Param IsTotal query bool false "是否显示全部"
- // @Success 200 {object} data_manage.BaseFromTradeExchangeItem
- // @router /exchange_list [get]
- func (this *TradeAnalysisController) GetTradeExchangeList() {
- 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
- }
- isTotal, _ := this.GetBool("IsTotal", false)
- var cond string
- var pars []interface{}
- exchangeOb := new(tradeAnalysisModel.BaseFromTradeExchange)
- if !isTotal {
- cond += fmt.Sprintf(` AND %s = ?`, exchangeOb.Cols().AnalysisState)
- pars = append(pars, 1)
- }
- list, e := exchangeOb.GetItemsByCondition(cond, pars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取交易所列表失败, %v", e)
- return
- }
- resp := make([]*tradeAnalysisModel.BaseFromTradeExchangeItem, 0)
- for _, v := range list {
- resp = append(resp, v.Format2Item())
- }
- br.Data = resp
- br.Msg = "获取成功"
- br.Ret = 200
- br.Success = true
- }
- // GetTradeClassifyList
- // @Title 获取品种列表
- // @Description 获取品种列表
- // @Param Exchange query string false "交易所标识"
- // @Param ClassifyName query string false "品种名称"
- // @Success 200 {object} tradeAnalysisModel.BaseFromTradeClassifyItem
- // @router /classify_list [get]
- func (this *TradeAnalysisController) GetTradeClassifyList() {
- 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
- }
- exchange := this.GetString("Exchange")
- exchange = strings.TrimSpace(exchange)
- classifyName := this.GetString("ClassifyName")
- classifyName = strings.TrimSpace(classifyName)
- // 交易所名称
- exchangeName := make(map[string]string)
- {
- var cond string
- var pars []interface{}
- exchangeOb := new(tradeAnalysisModel.BaseFromTradeExchange)
- if exchange != "" {
- cond += fmt.Sprintf(` AND %s = ?`, exchangeOb.Cols().Exchange)
- pars = append(pars, exchange)
- item, e := exchangeOb.GetItemByCondition(cond, pars, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取交易所信息失败, %v", e)
- return
- }
- exchangeName[item.Exchange] = item.ExchangeName
- } else {
- list, e := exchangeOb.GetItemsByCondition(cond, pars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取交易所列表失败, %v", e)
- return
- }
- for _, v := range list {
- exchangeName[v.Exchange] = v.ExchangeName
- }
- }
- }
- // 搜索品种
- var cond string
- var pars []interface{}
- classifyOb := new(tradeAnalysisModel.BaseFromTradeClassify)
- if exchange != "" {
- cond += fmt.Sprintf(` AND %s = ?`, classifyOb.Cols().Exchange)
- pars = append(pars, exchange)
- }
- if classifyName != "" {
- cond += fmt.Sprintf(` AND %s LIKE ?`, classifyOb.Cols().ClassifyName)
- pars = append(pars, fmt.Sprint("%", classifyName, "%"))
- }
- fields := []string{classifyOb.Cols().ClassifyName, classifyOb.Cols().Exchange}
- list, e := classifyOb.GetClassifyItemsByCondition(cond, pars, fields, "id ASC")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取品种列表失败, %v", e)
- return
- }
- resp := make([]*tradeAnalysisModel.BaseFromTradeClassifyItem, 0)
- classifyExist := make(map[string]bool)
- for _, v := range list {
- // 郑商所
- if v.Exchange == tradeAnalysisModel.TradeExchangeZhengzhou {
- name := trade_analysis.GetZhengzhouClassifyName(v.ClassifyName)
- if name == "" {
- continue
- }
- if classifyExist[name] {
- continue
- }
- classifyExist[name] = true
- resp = append(resp, &tradeAnalysisModel.BaseFromTradeClassifyItem{
- ClassifyName: name,
- Exchange: v.Exchange,
- ExchangeName: exchangeName[v.Exchange],
- })
- continue
- }
- resp = append(resp, &tradeAnalysisModel.BaseFromTradeClassifyItem{
- ClassifyName: v.ClassifyName,
- Exchange: v.Exchange,
- ExchangeName: exchangeName[v.Exchange],
- })
- }
- br.Data = resp
- br.Msg = "获取成功"
- br.Ret = 200
- br.Success = true
- }
- // GetTradeContractList
- // @Title 获取合约列表
- // @Description 获取合约列表
- // @Param Exchange query string false "交易所标识"
- // @Param ClassifyName query string false "品种名称"
- // @Param ContractName query string false "合约名称"
- // @Param ExceptTop query bool false "排除TOP20: true-不包含; false-包含(默认)"
- // @Success 200 {object} tradeAnalysisModel.BaseFromTradeContractItem
- // @router /contract_list [get]
- func (this *TradeAnalysisController) GetTradeContractList() {
- 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
- }
- exchange := this.GetString("Exchange")
- exchange = strings.TrimSpace(exchange)
- classifyName := this.GetString("ClassifyName")
- classifyName = strings.TrimSpace(classifyName)
- contractName := this.GetString("ContractName")
- contractName = strings.TrimSpace(contractName)
- exceptTop, _ := this.GetBool("ExceptTop")
- // 交易所名称
- exchangeName := make(map[string]string)
- {
- var cond string
- var pars []interface{}
- exchangeOb := new(tradeAnalysisModel.BaseFromTradeExchange)
- if exchange != "" {
- cond += fmt.Sprintf(` AND %s = ?`, exchangeOb.Cols().Exchange)
- pars = append(pars, exchange)
- item, e := exchangeOb.GetItemByCondition(cond, pars, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取交易所信息失败, %v", e)
- return
- }
- exchangeName[item.Exchange] = item.ExchangeName
- } else {
- list, e := exchangeOb.GetItemsByCondition(cond, pars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取交易所列表失败, %v", e)
- return
- }
- for _, v := range list {
- exchangeName[v.Exchange] = v.ExchangeName
- }
- }
- }
- // 搜索合约
- var cond string
- var pars []interface{}
- classifyOb := new(tradeAnalysisModel.BaseFromTradeClassify)
- if exchange != "" {
- cond += fmt.Sprintf(` AND %s = ?`, classifyOb.Cols().Exchange)
- pars = append(pars, exchange)
- }
- // 郑商所品种名称在列表中过滤
- if classifyName != "" {
- cond += fmt.Sprintf(` AND ((%s = ? AND %s <> ?) OR %s = ?)`, classifyOb.Cols().ClassifyName, classifyOb.Cols().Exchange, classifyOb.Cols().Exchange)
- pars = append(pars, classifyName, tradeAnalysisModel.TradeExchangeZhengzhou, tradeAnalysisModel.TradeExchangeZhengzhou)
- }
- if contractName != "" {
- cond += fmt.Sprintf(` AND %s LIKE ?`, classifyOb.Cols().ClassifyType)
- pars = append(pars, fmt.Sprint("%", contractName, "%"))
- }
- list, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC, %s DESC", classifyOb.Cols().Exchange, classifyOb.Cols().LatestDate))
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取合约列表失败, %v", e)
- return
- }
- resp := make([]*tradeAnalysisModel.BaseFromTradeContractItem, 0)
- if !exceptTop && contractName == "" {
- resp = append(resp, &tradeAnalysisModel.BaseFromTradeContractItem{
- ClassifyType: tradeAnalysisModel.TradeFuturesCompanyTop20,
- })
- }
- for _, v := range list {
- // 郑商所
- classifyType := v.ClassifyType
- if classifyName != "" && v.Exchange == tradeAnalysisModel.TradeExchangeZhengzhou {
- name := trade_analysis.GetZhengzhouClassifyName(v.ClassifyName)
- if classifyName != name {
- continue
- }
- classifyType = v.ClassifyName
- }
- resp = append(resp, &tradeAnalysisModel.BaseFromTradeContractItem{
- ClassifyName: v.ClassifyName,
- ClassifyType: classifyType,
- Exchange: v.Exchange,
- ExchangeName: exchangeName[v.Exchange],
- LatestDate: v.LatestDate.Format(utils.FormatDate),
- CreateTime: v.CreateTime.Format(utils.FormatDateTime),
- })
- }
- br.Data = resp
- br.Msg = "获取成功"
- br.Ret = 200
- br.Success = true
- }
- // GetTradeFuturesCompanyList
- // @Title 获取期货公司列表
- // @Description 获取期货公司列表
- // @Param CompanyName query string false "公司名称"
- // @Success 200 {object} tradeAnalysisModel.BaseFromTradeContractItem
- // @router /company_list [get]
- func (this *TradeAnalysisController) GetTradeFuturesCompanyList() {
- 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
- }
- companyName := this.GetString("CompanyName")
- companyName = strings.TrimSpace(companyName)
- var cond string
- var pars []interface{}
- companyOb := new(tradeAnalysisModel.TradeFuturesCompany)
- if companyName != "" {
- cond += fmt.Sprintf(` AND %s LIKE ?`, companyOb.Cols().CompanyName)
- pars = append(pars, fmt.Sprint("%", companyName, "%"))
- }
- list, e := companyOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC", companyOb.Cols().Sort))
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取期货公司列表失败, %v", e)
- return
- }
- resp := make([]*tradeAnalysisModel.TradeFuturesCompanyItem, 0)
- for _, v := range list {
- resp = append(resp, &tradeAnalysisModel.TradeFuturesCompanyItem{
- CompanyId: v.TradeFuturesCompanyId,
- CompanyName: v.CompanyName,
- Sort: v.Sort,
- })
- }
- br.Data = resp
- br.Msg = "获取成功"
- br.Ret = 200
- br.Success = true
- }
|