feat(meter):增加获取户表详细信息功能。
This commit is contained in:
parent
c1350d63af
commit
4c71f5f205
|
@ -24,6 +24,7 @@ func InitializeMeter04kVController(router *gin.Engine) {
|
||||||
|
|
||||||
Meter04kVController.Router.GET("/park/:pid/meter/template", security.EnterpriseAuthorize, download04kvMeterArchiveTemplate)
|
Meter04kVController.Router.GET("/park/:pid/meter/template", security.EnterpriseAuthorize, download04kvMeterArchiveTemplate)
|
||||||
Meter04kVController.Router.GET("/park/:pid/meters", security.EnterpriseAuthorize, ListPaged04kVMeter)
|
Meter04kVController.Router.GET("/park/:pid/meters", security.EnterpriseAuthorize, ListPaged04kVMeter)
|
||||||
|
Meter04kVController.Router.GET("/park/:pid/meter/:code", security.EnterpriseAuthorize, fetch04kVMeterDetail)
|
||||||
}
|
}
|
||||||
|
|
||||||
func download04kvMeterArchiveTemplate(c *gin.Context) {
|
func download04kvMeterArchiveTemplate(c *gin.Context) {
|
||||||
|
@ -89,3 +90,33 @@ func ListPaged04kVMeter(c *gin.Context) {
|
||||||
gin.H{"meters": meters},
|
gin.H{"meters": meters},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetch04kVMeterDetail(c *gin.Context) {
|
||||||
|
result := response.NewResult(c)
|
||||||
|
requestParkId := c.Param("pid")
|
||||||
|
userSession, err := _retreiveSession(c)
|
||||||
|
if err != nil {
|
||||||
|
result.Unauthorized(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sure, err := service.ParkService.EnsurePark(userSession.Uid, requestParkId)
|
||||||
|
if err != nil {
|
||||||
|
result.Error(http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !sure {
|
||||||
|
result.Unauthorized("不能访问不属于自己的园区。")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
requestMeterCode := c.Param("code")
|
||||||
|
meter, err := service.Meter04kVService.Get04kVMeterDetail(requestParkId, requestMeterCode)
|
||||||
|
if err != nil {
|
||||||
|
result.NotFound(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if meter == nil {
|
||||||
|
result.Json(http.StatusNotFound, "指定的表计信息未能找到。", gin.H{"meter": nil})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result.Json(http.StatusOK, "指定的表计信息已找到。", gin.H{"meter": meter})
|
||||||
|
}
|
||||||
|
|
|
@ -34,3 +34,15 @@ func (_Meter04kVService) ListMeterDetail(park, keyword string, page int) ([]mode
|
||||||
Find(&meters)
|
Find(&meters)
|
||||||
return meters, total, err
|
return meters, total, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_Meter04kVService) Get04kVMeterDetail(park, code string) (*model.Meter04KV, error) {
|
||||||
|
var meter = new(model.Meter04KV)
|
||||||
|
has, err := global.DBConn.Where(builder.Eq{"code": code, "park_id": park}).NoAutoCondition().Get(meter)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !has {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return meter, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user