初始
This commit is contained in:
217
api/hwy/plant/plant.go
Normal file
217
api/hwy/plant/plant.go
Normal file
@ -0,0 +1,217 @@
|
||||
package plant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/tiger1103/gfast/v3/api/hwy/client"
|
||||
"github.com/tiger1103/gfast/v3/api/hwy/sign"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type PlantApi struct {
|
||||
}
|
||||
|
||||
// 禾望云电站列表请求
|
||||
type PlantListReq struct {
|
||||
g.Meta `path:"/plant/list" method:"get" tags:"禾望云相关" summary:"获取电站列表"`
|
||||
PageNum int `json:"pageNum" dc:"分页数" v:"required"`
|
||||
PageSize int `json:"pageSize" dc:"分页大小" v:"required"`
|
||||
UserId string `json:"userId" dc:"用户ID"`
|
||||
}
|
||||
|
||||
func (p PlantApi) GetPlantList(ctx context.Context, req *PlantListReq) (res *PlantListRes, err error) {
|
||||
res = new(PlantListRes)
|
||||
data := make(map[string]string)
|
||||
data["pageIndex"] = strconv.Itoa(req.PageNum)
|
||||
data["pageSize"] = strconv.Itoa(req.PageSize)
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/powerPlant/getPowerPlantList", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
model := g.Model("plant")
|
||||
for _, record := range res.Result.Records {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
// 尝试查找记录
|
||||
exists, _ := model.Where("id", record.Id).One()
|
||||
// 准备数据
|
||||
data := map[string]interface{}{
|
||||
"id": record.Id,
|
||||
"name": record.Name,
|
||||
"address": record.Address,
|
||||
"city": record.City,
|
||||
"district": record.District,
|
||||
"province": record.Province,
|
||||
"latitude": record.Latitude,
|
||||
"longitude": record.Longitude,
|
||||
"kwp": record.Kwp,
|
||||
"monKwh": record.MonKwh,
|
||||
"nowKw": record.NowKw,
|
||||
"sumKwh": record.SumKwh,
|
||||
"todayKwh": record.TodayKwh,
|
||||
"yearKwh": record.YearKwh,
|
||||
"networkTime": record.NetworkTime,
|
||||
"updateTime": record.UpdateTime,
|
||||
"companyId": record.CompanyId,
|
||||
"companyName": record.CompanyName,
|
||||
"ownerId": record.OwnerId,
|
||||
"ownerName": record.OwnerName,
|
||||
"serviceProviderName": record.ServiceProviderName,
|
||||
"serviceProviderPhone": record.ServiceProviderPhone,
|
||||
"networkType": record.NetworkType,
|
||||
"powerPlantType": record.PowerPlantType,
|
||||
"status": record.Status,
|
||||
"paymentType": record.PaymentType,
|
||||
"plantContact": record.PlantContact,
|
||||
"plantContactPhone": record.PlantContactPhone,
|
||||
"plantImg": record.PlantImg,
|
||||
"remark": record.Remark,
|
||||
"dipAngle": record.DipAngle,
|
||||
"orientationAngle": record.OrientationAngle,
|
||||
"subassemblyNumber": record.SubassemblyNumber,
|
||||
}
|
||||
// 根据是否存在来决定是更新还是插入
|
||||
if exists.IsEmpty() {
|
||||
model.Insert(data)
|
||||
} else {
|
||||
model.Where("id", record.Id).Data(data).Update()
|
||||
}
|
||||
})
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
// 获取电站详情
|
||||
type PlantAddReq struct {
|
||||
g.Meta `path:"/plant/deatil" method:"get" tags:"禾望云相关" summary:"获取电站详情"`
|
||||
PlantId string `json:"plantId" dc:"电站ID" v:"required"`
|
||||
}
|
||||
|
||||
func (p PlantApi) PlanAdd(ctx context.Context, req *PlantAddReq) (res *PlantAddRes, err error) {
|
||||
res = new(PlantAddRes)
|
||||
data := make(map[string]string)
|
||||
data["plantId"] = req.PlantId
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/powerPlant/getPowerPlantDetailById", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
g.Dump(res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 禾望云电站实时数据
|
||||
type RealDataReq struct {
|
||||
g.Meta `path:"/plant/real/data" method:"get" tags:"禾望云相关" summary:"获取电站实时数据"`
|
||||
PlantId string `json:"plantId" dc:"电站ID" v:"required"`
|
||||
}
|
||||
|
||||
func (p PlantApi) RealData(ctx context.Context, req *RealDataReq) (res *RealDataRes, err error) {
|
||||
res = new(RealDataRes)
|
||||
data := make(map[string]string)
|
||||
data["plantId"] = req.PlantId
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/powerPlant/getPowerPlantRealData", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 禾望云电站日统计信息
|
||||
type DayStaticReq struct {
|
||||
g.Meta `path:"/plant/static/day" method:"get" tags:"禾望云相关" summary:"获取电站日统计信息"`
|
||||
StartTime string `json:"startTime" dc:"开始日期 yyyy-MM-dd" v:"required"`
|
||||
PlantId string `json:"plantId" dc:"电站ID" v:"required"`
|
||||
EndTime string `json:"endTime" dc:"结束日期 yyyy-MM-dd" v:"required"`
|
||||
}
|
||||
|
||||
func (p PlantApi) DayStatic(ctx context.Context, req *DayStaticReq) (res *DayStaticRes, err error) {
|
||||
res = new(DayStaticRes)
|
||||
data := make(map[string]string)
|
||||
data["startTime"] = req.StartTime
|
||||
data["plantId"] = req.PlantId
|
||||
data["endTime"] = req.EndTime
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/powerPlant/getPowerPlantDayStatisticsData", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 禾望云电站月统计信息
|
||||
type MonthStaticReq struct {
|
||||
g.Meta `path:"/plant/static/month" method:"get" tags:"禾望云相关" summary:"获取电站月统计信息"`
|
||||
StartTime string `json:"startTime" dc:"开始日期 yyyy-MM" v:"required"`
|
||||
PlantId string `json:"plantId" dc:"电站ID" v:"required"`
|
||||
EndTime string `json:"endTime" dc:"结束日期 yyyy-MM" v:"required"`
|
||||
}
|
||||
|
||||
func (p PlantApi) MonthStatic(ctx context.Context, req *MonthStaticReq) (res *MonthStaticRes, err error) {
|
||||
res = new(MonthStaticRes)
|
||||
data := make(map[string]string)
|
||||
data["startTime"] = req.StartTime
|
||||
data["plantId"] = req.PlantId
|
||||
data["endTime"] = req.EndTime
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/powerPlant/getPowerPlantMonthStatisticsData", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 禾望云电站年统计信息
|
||||
type YearStaticReq struct {
|
||||
g.Meta `path:"/plant/static/year" method:"get" tags:"禾望云相关" summary:"获取电站年统计信息"`
|
||||
StartTime string `json:"startTime" dc:"开始日期 yyyy" v:"required"`
|
||||
PlantId string `json:"plantId" dc:"电站ID" v:"required"`
|
||||
EndTime string `json:"endTime" dc:"结束日期 yyyy" v:"required"`
|
||||
}
|
||||
|
||||
func (p PlantApi) YearStatic(ctx context.Context, req *YearStaticReq) (res *YearStaticRes, err error) {
|
||||
res = new(YearStaticRes)
|
||||
data := make(map[string]string)
|
||||
data["startTime"] = req.StartTime
|
||||
data["plantId"] = req.PlantId
|
||||
data["endTime"] = req.EndTime
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/powerPlant/getPowerPlantYearStatisticsData", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 禾望云电站历史记录
|
||||
type HistoryStaticReq struct {
|
||||
g.Meta `path:"/plant/static/history" method:"get" tags:"禾望云相关" summary:"获取电站历史数据"`
|
||||
PlantId string `json:"plantId" dc:"电站ID" v:"required"`
|
||||
Time string `json:"time" dc:"日期字符 yyyy-MM-dd" v:"required"`
|
||||
}
|
||||
|
||||
func (p PlantApi) HistoryStatic(ctx context.Context, req *HistoryStaticReq) (res *HistoryStaticRes, err error) {
|
||||
res = new(HistoryStaticRes)
|
||||
data := make(map[string]string)
|
||||
data["plantId"] = req.PlantId
|
||||
data["time"] = req.Time
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/powerPlant/getPowerPlantHistoryPower", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
return res, nil
|
||||
}
|
189
api/hwy/plant/res.go
Normal file
189
api/hwy/plant/res.go
Normal file
@ -0,0 +1,189 @@
|
||||
package plant
|
||||
|
||||
// 电站详情
|
||||
type PlantAddRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct {
|
||||
} `json:"obj"`
|
||||
Result struct {
|
||||
Address string `json:"address"`
|
||||
City string `json:"city"`
|
||||
CompanyId string `json:"companyId"`
|
||||
CompanyName string `json:"companyName"`
|
||||
DipAngle int `json:"dipAngle"`
|
||||
District string `json:"district"`
|
||||
Earnings int `json:"earnings"`
|
||||
Id string `json:"id"`
|
||||
Kwp int `json:"kwp"`
|
||||
Latitude string `json:"latitude"`
|
||||
Longitude string `json:"longitude"`
|
||||
MonEarnings int `json:"monEarnings"`
|
||||
MonKwh float64 `json:"monKwh"`
|
||||
Name string `json:"name"`
|
||||
NetworkType string `json:"networkType"`
|
||||
NowKw int `json:"nowKw"`
|
||||
OrientationAngle int `json:"orientationAngle"`
|
||||
OwnerId string `json:"ownerId"`
|
||||
PaymentType string `json:"paymentType"`
|
||||
PlantContact string `json:"plantContact"`
|
||||
PlantContactPhone string `json:"plantContactPhone"`
|
||||
PlantImg string `json:"plantImg"`
|
||||
PowerPlantType string `json:"powerPlantType"`
|
||||
Province string `json:"province"`
|
||||
Remark string `json:"remark"`
|
||||
ServiceProviderEmail string `json:"serviceProviderEmail"`
|
||||
ServiceProviderPhone string `json:"serviceProviderPhone"`
|
||||
Status int `json:"status"`
|
||||
SubassemblyNumber int `json:"subassemblyNumber"`
|
||||
SumEarnings int `json:"sumEarnings"`
|
||||
SumKwh float64 `json:"sumKwh"`
|
||||
TodayEarnings int `json:"todayEarnings"`
|
||||
TodayKwh float64 `json:"todayKwh"`
|
||||
UpdateTime string `json:"updateTime"`
|
||||
UserName string `json:"userName"`
|
||||
YearEarnings int `json:"yearEarnings"`
|
||||
YearKwh int `json:"yearKwh"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
||||
|
||||
// 电站列表
|
||||
type PlantListRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct {
|
||||
} `json:"obj"`
|
||||
Result struct {
|
||||
Page struct {
|
||||
PageIndex int `json:"pageIndex"`
|
||||
PageSize int `json:"pageSize"`
|
||||
Total int `json:"total"`
|
||||
} `json:"page"`
|
||||
Records []struct {
|
||||
Address string `json:"address"`
|
||||
City string `json:"city"`
|
||||
CompanyId string `json:"companyId"`
|
||||
CompanyName string `json:"companyName"`
|
||||
DipAngle int `json:"dipAngle"`
|
||||
District string `json:"district"`
|
||||
Id string `json:"id"`
|
||||
Kwp float64 `json:"kwp"`
|
||||
Latitude string `json:"latitude"`
|
||||
Longitude string `json:"longitude"`
|
||||
MonKwh float64 `json:"monKwh"`
|
||||
Name string `json:"name"`
|
||||
NetworkTime string `json:"networkTime"`
|
||||
NetworkType string `json:"networkType"`
|
||||
NowKw float64 `json:"nowKw"`
|
||||
OrientationAngle int `json:"orientationAngle"`
|
||||
OwnerId string `json:"ownerId"`
|
||||
OwnerName string `json:"ownerName"`
|
||||
PaymentType string `json:"paymentType"`
|
||||
PlantContact string `json:"plantContact"`
|
||||
PlantContactPhone string `json:"plantContactPhone"`
|
||||
PlantImg string `json:"plantImg"`
|
||||
PowerPlantType string `json:"powerPlantType"`
|
||||
Province string `json:"province"`
|
||||
Remark string `json:"remark"`
|
||||
ServiceProviderName string `json:"serviceProviderName"`
|
||||
ServiceProviderPhone string `json:"serviceProviderPhone"`
|
||||
Status int `json:"status"`
|
||||
SubassemblyNumber int `json:"subassemblyNumber"`
|
||||
SumKwh float64 `json:"sumKwh"`
|
||||
TodayKwh float64 `json:"todayKwh"`
|
||||
UpdateTime string `json:"updateTime"`
|
||||
YearKwh float64 `json:"yearKwh"`
|
||||
} `json:"records"`
|
||||
Statistics struct {
|
||||
AlarmNumber int `json:"alarmNumber"`
|
||||
OfflineNumber int `json:"offlineNumber"`
|
||||
OnlineNumber int `json:"onlineNumber"`
|
||||
SumNumber int `json:"sumNumber"`
|
||||
} `json:"statistics"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
||||
|
||||
// 电站实时数据
|
||||
type RealDataRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct {
|
||||
} `json:"obj"`
|
||||
Result struct {
|
||||
NowKw int `json:"nowKw"`
|
||||
PowerUnit string `json:"powerUnit"`
|
||||
Time string `json:"time"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
||||
|
||||
// 电站日统计信息
|
||||
type DayStaticRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct {
|
||||
} `json:"obj"`
|
||||
Result []struct {
|
||||
Earnings int `json:"earnings"`
|
||||
EarningsUnit string `json:"earningsUnit"`
|
||||
Kwh int `json:"kwh"`
|
||||
KwhUnit string `json:"kwhUnit"`
|
||||
Time string `json:"time"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
||||
|
||||
// 电站月统计信息
|
||||
type MonthStaticRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct {
|
||||
} `json:"obj"`
|
||||
Result []struct {
|
||||
Earnings int `json:"earnings"`
|
||||
EarningsUnit string `json:"earningsUnit"`
|
||||
Kwh int `json:"kwh"`
|
||||
KwhUnit string `json:"kwhUnit"`
|
||||
Time string `json:"time"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
||||
|
||||
// 电站年统计信息
|
||||
type YearStaticRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct {
|
||||
} `json:"obj"`
|
||||
Result []struct {
|
||||
Earnings int `json:"earnings"`
|
||||
EarningsUnit string `json:"earningsUnit"`
|
||||
Kwh int `json:"kwh"`
|
||||
KwhUnit string `json:"kwhUnit"`
|
||||
Time string `json:"time"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
||||
|
||||
// 电站历史记录
|
||||
type HistoryStaticRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct {
|
||||
} `json:"obj"`
|
||||
Result []struct {
|
||||
NowKw int `json:"nowKw"`
|
||||
PowerUnit string `json:"powerUnit"`
|
||||
Time string `json:"time"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
Reference in New Issue
Block a user