Przeglądaj źródła

Merge branch 'feature/eta1.2.2_edb_source' into debug

xyxie 1 rok temu
rodzic
commit
95d60c39c3

+ 88 - 2
controllers/data_stat/edb_source_stat.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"eta/eta_api/controllers"
 	"eta/eta_api/models"
+	"eta/eta_api/models/data_manage"
 	"eta/eta_api/models/data_stat"
 	"eta/eta_api/utils"
 	"fmt"
@@ -691,8 +692,8 @@ func (this *EdbSourceStatController) EdbSourceStat() {
 	total, err := data_stat.GetEdbSourceStatCount(condition, pars)
 	if err != nil {
 		if err.Error() != utils.ErrNoRow() {
-			br.Msg = "获取指标删除列表总数失败"
-			br.ErrMsg = "获取指标删除列表总数失败,Err:" + err.Error()
+			br.Msg = "获取数据源统计列表总数失败"
+			br.ErrMsg = "获取数据源统计列表总数失败,Err:" + err.Error()
 			return
 		} else {
 			err = nil
@@ -743,3 +744,88 @@ func (this *EdbSourceStatController) EdbSourceStat() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// EdbUpdateFailedList
+// @Title 查询指标刷新失败详情列表
+// @Description 查询指标刷新失败详情列表
+// @Success 200 {object} data_stat.GetEdbUpdateLogResp
+// @router /edb_update_stat/failed [get]
+func (this *EdbSourceStatController) EdbUpdateFailedList() {
+	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
+	}
+
+	terminalCode := this.GetString("TerminalCode", "")
+	createTime := this.GetString("CreateTime", "")
+
+	if terminalCode == "" {
+		br.Msg = "请选择对应的终端信息"
+		return
+	}
+	terminalInfo, err := data_manage.GetEdbTerminalByTerminalCode(terminalCode)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "终端不存在"
+			return
+		}
+		br.Msg = "查询终端信息出错"
+		br.ErrMsg = "查询终端信息出错 Err:" + err.Error()
+		return
+	}
+	condition := " and source = ? and terminal_code = ?"
+	var pars []interface{}
+	pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, terminalCode)
+
+	if createTime != "" {
+		startT, err := time.ParseInLocation(utils.FormatDate, createTime, time.Local)
+		if err != nil {
+			br.Msg = "请求时间格式错误"
+			return
+		}
+		endT := startT.AddDate(0, 0, 1)
+		condition += " AND create_time >= ? AND create_time < ?"
+		pars = append(pars, createTime, endT.Format(utils.FormatDate))
+	}
+
+	tmpList, err := data_stat.GetEdbUpdateStatFailedGroupByCondition(condition, pars)
+	if err != nil {
+		br.Msg = "获取指标更新失败详情列表 失败"
+		br.ErrMsg = "获取指标更新失败详情列表 失败,Err:" + err.Error()
+		return
+	}
+
+	list := make([]*data_stat.EdbUpdateFailedList, 0)
+	successNum := 0
+	failedNum := 0
+	if len(tmpList) > 0 {
+		for _, v := range tmpList {
+			if v.SourceUpdateResult == 1 {
+				successNum += v.Num
+			} else {
+				failedNum += v.Num
+				list = append(list, v)
+			}
+		}
+	}
+	resp := data_stat.GetEdbUpdateFailedResp{
+		List:             list,
+		Name:             terminalInfo.Name,
+		TerminalCode:     terminalCode,
+		DirPath:          terminalInfo.DirPath,
+		UpdateSuccessNum: successNum,
+		UpdateFailedNum:  failedNum,
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 7 - 0
models/data_manage/edb_terminal.go

@@ -94,6 +94,13 @@ func GetEdbTerminalById(id int) (item *EdbTerminal, err error) {
 	return
 }
 
+func GetEdbTerminalByTerminalCode(terminalCode string) (item *EdbTerminal, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM edb_terminal WHERE terminal_code = ? LIMIT 1`
+	err = o.Raw(sql, terminalCode).QueryRow(&item)
+	return
+}
+
 func GetEdbTerminalList() (item []*EdbTerminalItem, err error) {
 	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT * FROM edb_terminal ORDER BY terminal_id ASC`

+ 42 - 0
models/data_stat/edb_info_update_stat.go

@@ -103,3 +103,45 @@ func GetEdbUpdateStatCount(condition string, pars []interface{}) (count int, err
 	err = o.Raw(sql, pars).QueryRow(&count)
 	return
 }
+
+type EdbUpdateFailedList struct {
+	TerminalCode             string `description:"终端编码,用于配置在机器上"`
+	SourceUpdateFailedReason string `description:"从终端刷新到数据源的数据未正常刷新原因"`
+	Frequency                string `description:"频率"`
+	SourceUpdateResult       int    `description:"从终端刷新到数据源的刷新结果:1成功,2失败"`
+	Num                      int
+}
+
+type GetEdbUpdateFailedResp struct {
+	List             []*EdbUpdateFailedList
+	Name             string `description:"终端名称"`
+	TerminalCode     string `description:"终端编码,用于配置在机器上"`
+	DirPath          string `description:"终端存放的文件夹路径"`
+	UpdateSuccessNum int    `description:"今日已刷新成功指标数"`
+	UpdateFailedNum  int    `description:"今日已刷新失败指标数"`
+}
+
+func GetEdbUpdateStatFailedGroupByCondition(condition string, pars []interface{}) (item []*EdbUpdateFailedList, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT
+	terminal_code,
+	source_update_result,
+	frequency,
+	IF(source_update_failed_reason !="" && source_update_failed_reason="未刷新到数据",source_update_failed_reason,"服务异常") as source_update_failed_reason,
+	count(*) as num
+FROM
+	edb_info_update_stat 
+WHERE
+    source_update_result != 0 
+	`
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` GROUP BY
+	source_update_result,
+	frequency,
+	update_failed_reason
+	ORDER BY count(*) desc`
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}

+ 9 - 0
routers/commentsRouter.go

@@ -3688,6 +3688,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_stat:EdbSourceStatController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_stat:EdbSourceStatController"],
+        beego.ControllerComments{
+            Method: "EdbUpdateFailedList",
+            Router: `/edb_update_stat/failed`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_stat:EdbSourceStatController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_stat:EdbSourceStatController"],
         beego.ControllerComments{
             Method: "Column",