forked from free-lancers/electricity_bill_calc_service
feat(report):完成峰谷用户抄表Excel导出功能。
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/excel"
|
||||
"electricity_bill_calc/response"
|
||||
"electricity_bill_calc/security"
|
||||
"electricity_bill_calc/service"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
|
||||
func InitializeEndUserController(router *gin.Engine) {
|
||||
router.GET("/report/:rid/submeter", security.EnterpriseAuthorize, fetchEndUserInReport)
|
||||
router.GET("/report/:rid/meter/template", security.EnterpriseAuthorize, downloadEndUserRegisterTemplate)
|
||||
}
|
||||
|
||||
func fetchEndUserInReport(c *gin.Context) {
|
||||
@@ -38,3 +40,24 @@ func fetchEndUserInReport(c *gin.Context) {
|
||||
gin.H{"meters": endUsers},
|
||||
)
|
||||
}
|
||||
|
||||
func downloadEndUserRegisterTemplate(c *gin.Context) {
|
||||
result := response.NewResult(c)
|
||||
requestReportId := c.Param("rid")
|
||||
if !ensureReportBelongs(c, result, requestReportId) {
|
||||
return
|
||||
}
|
||||
users, err := service.EndUserService.AllEndUserRecord(requestReportId)
|
||||
if err != nil {
|
||||
result.NotFound(err.Error())
|
||||
return
|
||||
}
|
||||
gen := excel.NewMeterPVExcelTemplateGenerator()
|
||||
defer gen.Close()
|
||||
gen.WriteMeterData(users)
|
||||
c.Status(http.StatusOK)
|
||||
c.Header("Content-Type", "application/octet-stream")
|
||||
c.Header("Content-Transfer-Encoding", "binary")
|
||||
c.Header("Content-Disposition", "attachment; filename=抄表记录.xslx")
|
||||
gen.WriteTo(c.Writer)
|
||||
}
|
||||
|
Reference in New Issue
Block a user