// @Title Get Error Time detail // @Description get a period of time error detail // @Param starttime query string "service starttime" // @Param endtime query string "service endtime" // @Param ns query string "ns name" // @Success 200 {object} models.FaultData // @Failure 403 body is empty // @router /errtime/detail/ func (c *FaultDataController) GetErrDetail() { var starttime int64 var endtime int64 var ns string var detail interface{} var err error var result models.Result //获取ns ns = c.GetString("ns") nslist := strings.Split(ns, ".") if nslist[len(nslist)-1] != "com" { result.Success = false result.Data = "ns is not correct! len is too short or .com should be at the end of ns" c.Data["json"] = result c.Abort("400") } now := time.Now() days := time.Date(now.Year(), now.Month()+1, 0, 0, 0, 0, 0, time.UTC).Day() next_time := now.AddDate(0, 0, days) start_month := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local) end_month := time.Date(next_time.Year(), next_time.Month(), 1, 0, 0, 0, 0, time.Local) //获取starttime starttime, err = c.GetInt64("starttime") if err != nil { //如果为空,设置初始值为当月第一天 starttime = start_month.Unix() } //获取endtime endtime, err = c.GetInt64("endtime") if err != nil { //如果为空,设置截止时间为当前时间 endtime = end_month.Unix() } //获取故障详情 detail, err = models.GetErrTimeDetail(starttime, endtime, ns) if err != nil { result.Success = false result.Data = err.Error() c.Data["json"] = result c.Abort("400") } else { result.Success = true result.Data = detail c.Data["json"] = result } c.ServeJson() }
// @Title Get Error Time Percent // @Description get rangetime to caculate errtime percent // @Param starttime query string "service starttime" // @Param endtime query string "service endtime" // @Param ns query string "ns name" // @Success 200 {object} models.FaultData // @Failure 403 body is empty // @router / func (c *DownController) GetErrPercent() { var starttime int64 var endtime int64 var ns string var err error var result models.Result ns = c.GetString("ns") nslist := strings.Split(ns, ".") if nslist[len(nslist)-1] != "com" { result.Success = false result.Data = "ns is not correct" c.Data["json"] = result c.Abort("400") } now := time.Now() days := time.Date(now.Year(), now.Month()+1, 0, 0, 0, 0, 0, time.UTC).Day() next_time := now.AddDate(0, 0, days) start_month := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local) end_month := time.Date(next_time.Year(), next_time.Month(), 1, 0, 0, 0, 0, time.Local) starttime, err = c.GetInt64("starttime") if err != nil { starttime = start_month.Unix() } endtime, err = c.GetInt64("endtime") if err != nil { endtime = end_month.Unix() } detail, err := models.GetErrTimeDetail(starttime, endtime, ns) c.Ctx.Output.Header("Content-Disposition", "attachment;filename=myfilename.csv") c.Ctx.Output.Header("Content-Type", "application/CSV") result2 := bytes.NewBufferString("") csvResult := csv.NewWriter(result2) csvResult.Write([]string{"影响业务", "发生时间", "事故内容", "影响面", "影响时长(min)", "事故原因", "对应方案", "未来对策", "定级"}) for _, oneDetail := range detail { csvResult.Write(oneDetail.GenCsv()) } csvResult.Flush() enc := mahonia.NewEncoder("gbk") output := enc.ConvertString(result2.String()) c.Ctx.Output.Body([]byte(output)) c.ServeJson() }