初始
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
|
||||
}
|
Reference in New Issue
Block a user