123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- package data_stat
- import (
- "encoding/json"
- "eta_gn/eta_api/controllers"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/services/data_stat"
- "eta_gn/eta_api/utils"
- )
- // EdbTerminalController 数据源终端管理
- type EdbTerminalController struct {
- controllers.BaseAuthController
- }
- // Save
- // @Title 保存数据源终端
- // @Description 保存数据源终端接口
- // @Param request body true data_manage.AddEdbTerminalListReq "type json string"
- // @Success 200 string "操作成功"
- // @router /terminal/save [post]
- func (this *EdbTerminalController) Save() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req *data_manage.AddEdbTerminalListReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Name == "" {
- br.Msg = "请输入终端名称"
- return
- }
- /*if req.ServerUrl == "" && req.Value == "" {
- br.Msg = "请输入终端地址或者token"
- return
- }*/
- if req.Num <= 0 {
- br.Msg = "请输入指标数据量"
- return
- }
- if req.Source == 0 {
- br.Msg = "请输入终端类型"
- return
- }
- // todo 校验终端数据
- errMsg, err := data_stat.SaveEdbTerminal(req)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "SaveEnglishVideoCover ErrMsg:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- // SetStatus
- // @Title 启用/禁用数据源终端
- // @Description 启用/禁用数据源终端
- // @Param request body true data_manage.SetEdbTerminalStatusReq "type json string"
- // @Success 200 string "操作成功"
- // @router /terminal/status/set [post]
- func (this *EdbTerminalController) SetStatus() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req *data_manage.SetEdbTerminalStatusReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.TerminalId <= 0 {
- br.Msg = "请选择要操作的终端"
- return
- }
- if req.Status != 1 && req.Status != 2 {
- br.Msg = "请选择正确的终端状态"
- return
- }
- errMsg, err := data_stat.SetEdbTerminalStatus(req.TerminalId, req.Status)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "SetEdbTerminalStatus ErrMsg:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- // List
- // @Title 数据源终端列表
- // @Description 数据源终端列表接口
- // @Success 200 {object} data_manage.EdbTerminalLisResp
- // @router /terminal/list [get]
- func (this *EdbTerminalController) List() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- 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
- }
- list, err := data_manage.GetEdbTerminalList()
- if err != nil {
- br.Msg = "获取终端列表失败"
- br.ErrMsg = "获取终端列表失败 ErrMsg:" + err.Error()
- return
- }
- resp := &data_manage.EdbTerminalListResp{
- List: list,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // TerminalCodeList
- // @Title 数据源终端列表
- // @Description 数据源终端列表接口
- // @Success 200 {object} data_manage.EdbTerminalCodeResp
- // @router /terminal/code [get]
- func (this *EdbTerminalController) TerminalCodeList() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- 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
- }
- source, _ := this.GetInt("Source", utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
- list, err := data_manage.GetEdbTerminalBySource(source)
- if err != nil {
- br.Msg = "获取终端列表失败"
- br.ErrMsg = "获取终端列表失败 ErrMsg:" + err.Error()
- return
- }
- codeList := make([]*data_manage.EdbTerminalCode, 0)
- if len(list) > 0 {
- for _, v := range list {
- tmp := new(data_manage.EdbTerminalCode)
- tmp.TerminalCode = v.TerminalCode
- tmp.Source = v.Source
- tmp.Name = v.Name
- codeList = append(codeList, tmp)
- }
- }
- resp := &data_manage.EdbTerminalCodeResp{
- List: codeList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|