hpds_jkw_web/internal/handler/report.go

48 lines
1.5 KiB
Go
Raw Normal View History

package handler
import (
"fmt"
"github.com/gin-gonic/gin"
"hpds-iot-web/internal/proto"
"hpds-iot-web/internal/service"
"hpds-iot-web/model"
e "hpds-iot-web/pkg/err"
)
func (s HandlerService) ReportList(c *gin.Context) (data interface{}, err error) {
repo := service.NewReportService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ReportRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("ReportList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.ReportList(c, req)
go s.SaveLog("报表列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) GenerateReport(c *gin.Context) (data interface{}, err error) {
repo := service.NewReportService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.ReportRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("GenerateReport", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
xlsx, err := repo.GenerateReport(c, req)
if err != nil {
}
c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
c.Header("Content-Disposition", "attachment; filename=模型报表.xlsx")
//c.Header("")
c.Header("Content-Transfer-Encoding", "binary")
err = xlsx.Write(c.Writer)
return nil, err
}