初始
This commit is contained in:
48
api/hwy/client/client.go
Normal file
48
api/hwy/client/client.go
Normal file
@ -0,0 +1,48 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/tiger1103/gfast/v3/api/hwy/sign"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// 封装 Get 请求
|
||||
func Get(uri string, params map[string]string) (error, []byte) {
|
||||
joinPath, _ := url.JoinPath(sign.HOST, uri)
|
||||
url := joinPath + "?" + sign.CreateLinkString(params)
|
||||
response, err := g.Client().ContentJson().Get(gctx.New(), url)
|
||||
if err != nil {
|
||||
return err, []byte{}
|
||||
}
|
||||
bt := response.ReadAll()
|
||||
return nil, bt
|
||||
}
|
||||
|
||||
// 封装 Post 请求
|
||||
func Post(uri string, params map[string]string) (error, []byte) {
|
||||
// 把 map 转为 json
|
||||
jsonData, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
|
||||
// 使用http包发送POST请求
|
||||
response, err := http.Post(sign.HOST+uri, "application/json", bytes.NewBuffer(jsonData))
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
// 读取响应体
|
||||
body, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
|
||||
return nil, body
|
||||
}
|
74
api/hwy/detail/detail.go
Normal file
74
api/hwy/detail/detail.go
Normal file
@ -0,0 +1,74 @@
|
||||
package detail
|
||||
|
||||
type Pub struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct {
|
||||
} `json:"obj"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
||||
|
||||
/*逆变器设备详情*/
|
||||
type EquipmentDetail struct {
|
||||
DivertorId string `json:"divertorId"`
|
||||
DivertorName string `json:"divertorName"`
|
||||
EquipmentName string `json:"equipmentName"`
|
||||
EquipmentPn string `json:"equipmentPn"`
|
||||
EquipmentSn string `json:"equipmentSn"`
|
||||
Id string `json:"id"`
|
||||
Kwp float64 `json:"kwp"`
|
||||
MonKwh float64 `json:"monKwh"`
|
||||
NowKw float64 `json:"nowKw"`
|
||||
ParamDcacCode string `json:"paramDcacCode"`
|
||||
ParamDcdcCode string `json:"paramDcdcCode"`
|
||||
PowerPlantId string `json:"powerPlantId"`
|
||||
PowerPlantName string `json:"powerPlantName"`
|
||||
RatedPower float64 `json:"ratedPower"`
|
||||
SoftDcacCode string `json:"softDcacCode"`
|
||||
SoftDcdcCode string `json:"softDcdcCode"`
|
||||
Status int `json:"status"`
|
||||
SumKwh float64 `json:"sumKwh"`
|
||||
TodayKwh float64 `json:"todayKwh"`
|
||||
UpdateTime string `json:"updateTime"`
|
||||
UserId string `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
YearKwh float64 `json:"yearKwh"`
|
||||
}
|
||||
|
||||
/*电站详情*/
|
||||
type PlantDetail struct {
|
||||
Address string `json:"address"`
|
||||
City string `json:"city"`
|
||||
CompanyId string `json:"companyId"`
|
||||
CompanyName string `json:"companyName"`
|
||||
DipAngle float64 `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 float64 `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"`
|
||||
}
|
335
api/hwy/equipment/equipment.go
Normal file
335
api/hwy/equipment/equipment.go
Normal file
@ -0,0 +1,335 @@
|
||||
package equipment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/tiger1103/gfast/v3/api/hwy/client"
|
||||
"github.com/tiger1103/gfast/v3/api/hwy/sign"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
)
|
||||
|
||||
type EquipmentApi struct{}
|
||||
|
||||
// 从数据库中获取逆变器列表
|
||||
type EquipmentListQueryReq struct {
|
||||
g.Meta `path:"/equipment/query" method:"get" tags:"禾望云相关" summary:"从数据库中获取逆变器列表【实时数据不一样准确】"`
|
||||
PageNum int `json:"pageNum" dc:"分页数" v:"required"`
|
||||
PageSize int `json:"pageSize" dc:"分页大小" v:"required"`
|
||||
}
|
||||
|
||||
func (e EquipmentApi) GetEquipmentListFromDB(ctx context.Context, req *EquipmentListQueryReq) (res *EquipmentListQueryRes, err error) {
|
||||
res = new(EquipmentListQueryRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
// 从数据库中查询逆变器列表
|
||||
m := dao.Equipment.Ctx(ctx).WithAll()
|
||||
|
||||
res.Total, err = m.Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
|
||||
res.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 10
|
||||
}
|
||||
|
||||
err = m.Page(req.PageNum, req.PageSize).Scan(&res.List)
|
||||
liberr.ErrIsNil(ctx, err, "获取逆变器列表失败")
|
||||
})
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
// 禾望云逆变器列表请求
|
||||
type EquipmentListReq struct {
|
||||
g.Meta `path:"/equipment/list" method:"get" tags:"禾望云相关" summary:"从平台获取逆变器列表【实时数据准确】"`
|
||||
PageNum int `json:"pageNum" dc:"分页数" v:"required"`
|
||||
PageSize int `json:"pageSize" dc:"分页大小" v:"required"`
|
||||
PlantId int `json:"plantId" dc:"电站ID" v:"required"`
|
||||
}
|
||||
|
||||
func (e EquipmentApi) GetEquipmentListAndSave(ctx context.Context, req *EquipmentListReq) (res *EquipmentListRes, err error) {
|
||||
res = new(EquipmentListRes)
|
||||
data := make(map[string]string)
|
||||
data["pageIndex"] = strconv.Itoa(req.PageNum)
|
||||
data["pageSize"] = strconv.Itoa(req.PageSize)
|
||||
data["plantId"] = strconv.Itoa(req.PlantId)
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/equipment/getEquipmentListByPlantId", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
// 处理响应并存储数据
|
||||
model := g.Model("equipment")
|
||||
for _, record := range res.Result.Records {
|
||||
_, err = model.Data(map[string]interface{}{
|
||||
"plantId": req.PlantId,
|
||||
"divertorId": record.DivertorId,
|
||||
"divertorName": record.DivertorName,
|
||||
"equipmentName": record.EquipmentName,
|
||||
"equipmentPn": record.EquipmentPn,
|
||||
"equipmentSn": record.EquipmentSn,
|
||||
"id": record.Id,
|
||||
"kwp": record.Kwp,
|
||||
"monKwh": record.MonKwh,
|
||||
"nowKw": record.NowKw,
|
||||
"paramDcacCode": record.ParamDcacCode,
|
||||
"paramDcdcCode": record.ParamDcdcCode,
|
||||
"powerPlantId": record.PowerPlantId, // 确保这个字段已经是字符串,或者在数据库中正确处理类型转换
|
||||
"powerPlantName": record.PowerPlantName,
|
||||
"ratedPower": record.RatedPower,
|
||||
"softDcacCode": record.SoftDcacCode,
|
||||
"softDcdcCode": record.SoftDcdcCode,
|
||||
"status": record.Status,
|
||||
"sumKwh": record.SumKwh,
|
||||
"todayKwh": record.TodayKwh,
|
||||
"updateTime": record.UpdateTime, // 确保转换为适合数据库的日期时间格式
|
||||
"userId": record.UserId,
|
||||
"userName": record.UserName,
|
||||
"yearKwh": record.YearKwh,
|
||||
}).Save()
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 获取逆变器详情
|
||||
type EquipmentDetailReq struct {
|
||||
g.Meta `path:"/equipment/detail" method:"get" tags:"禾望云相关" summary:"获取逆变器详情"`
|
||||
Id string `json:"id" dc:"逆变器ID" v:"required"`
|
||||
Sn string `json:"sn" dc:"逆变器SN" v:"required"`
|
||||
}
|
||||
|
||||
func (e EquipmentApi) EquipmentDetail(ctx context.Context, req *EquipmentDetailReq) (res *EquipmentDetailRes, err error) {
|
||||
res = new(EquipmentDetailRes)
|
||||
data := make(map[string]string)
|
||||
data["id"] = req.Id
|
||||
data["sn"] = req.Sn
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/equipment/getEquipmentDetail", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
|
||||
var Address struct {
|
||||
PlantAddress string `json:"plantAddress"`
|
||||
}
|
||||
|
||||
name := res.Result.PowerPlantName
|
||||
g.Model("plant").Fields("address AS plantAddress").Where("name = ?", name).Scan(&Address)
|
||||
|
||||
res.PlantAddress = Address.PlantAddress
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 获取逆变器实时数据
|
||||
type EquipmentRealDataReq struct {
|
||||
g.Meta `path:"/equipment/real/data" method:"get" tags:"禾望云相关" summary:"获取逆变器实时数据"`
|
||||
Id string `json:"id" dc:"逆变器ID" v:"required"`
|
||||
Sn string `json:"sn" dc:"逆变器SN" v:"required"`
|
||||
}
|
||||
|
||||
func (e EquipmentApi) EquipmentRealData(ctx context.Context, req *EquipmentRealDataReq) (res *EquipmentRealDataRes, err error) {
|
||||
res = new(EquipmentRealDataRes)
|
||||
data := make(map[string]string)
|
||||
data["id"] = req.Id
|
||||
data["sn"] = req.Sn
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/equipment/getEquipmentData", data)
|
||||
g.Dump(string(bytes))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 获取逆变器历史数据
|
||||
type EquipmentHistoryReq struct {
|
||||
g.Meta `path:"/equipment/history" method:"get" tags:"禾望云相关" summary:"获取逆变器历史数据"`
|
||||
Time string `json:"time" dc:"日期字符 yyyy-MM-dd" v:"required"`
|
||||
Id string `json:"id" dc:"逆变器ID" v:"required"`
|
||||
Sn string `json:"sn" dc:"逆变器SN" v:"required"`
|
||||
}
|
||||
|
||||
func (e EquipmentApi) EquipmentHistory(ctx context.Context, req *EquipmentHistoryReq) (*EquipmentHistoryRes, error) {
|
||||
res := new(EquipmentHistoryRes)
|
||||
data := map[string]string{
|
||||
"id": req.Id,
|
||||
"sn": req.Sn,
|
||||
"time": req.Time,
|
||||
}
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/equipment/getEquipmentHistoryData", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
requiredKeys := map[string]bool{
|
||||
"ACActivePower": true,
|
||||
"ACReactivePower": true,
|
||||
"DCInputPower": true,
|
||||
"internalTemperature": true,
|
||||
"gridFrequency": true,
|
||||
"dayElectricity": true,
|
||||
"inverterEfficiency": true,
|
||||
}
|
||||
|
||||
for i := range res.Result {
|
||||
var filteredParams []struct {
|
||||
Key string `json:"key"`
|
||||
Name string `json:"name"`
|
||||
Unit string `json:"unit"`
|
||||
Value interface{} `json:"value"`
|
||||
}
|
||||
for _, param := range res.Result[i].ParamList {
|
||||
if _, ok := requiredKeys[param.Key]; ok {
|
||||
filteredParams = append(filteredParams, param)
|
||||
}
|
||||
}
|
||||
res.Result[i].ParamList = filteredParams
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 获取逆变器日统计数据
|
||||
type EquipmentStaticDayReq struct {
|
||||
g.Meta `path:"/equipment/static/day" method:"get" tags:"禾望云相关" summary:"获取逆变器日统计数据"`
|
||||
StartTime string `json:"startTime" dc:"开始日期字符 yyyy-MM-dd" v:"required"`
|
||||
EndTime string `json:"endTime" dc:"开始日期字符 yyyy-MM-dd" v:"required"`
|
||||
Id string `json:"id" dc:"逆变器ID" v:"required"`
|
||||
Sn string `json:"sn" dc:"逆变器SN" v:"required"`
|
||||
}
|
||||
|
||||
func (e EquipmentApi) EquipmentStaticDay(ctx context.Context, req *EquipmentStaticDayReq) (res *EquipmentStaticDayRes, err error) {
|
||||
res = new(EquipmentStaticDayRes)
|
||||
data := make(map[string]string)
|
||||
data["id"] = req.Id
|
||||
data["sn"] = req.Sn
|
||||
data["startTime"] = req.StartTime
|
||||
data["endTime"] = req.EndTime
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/equipment/getEquipmentDayStatisticsData", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 获取逆变器月统计数据
|
||||
type EquipmentStaticMonthReq struct {
|
||||
g.Meta `path:"/equipment/static/month" method:"get" tags:"禾望云相关" summary:"获取逆变器月统计数据"`
|
||||
StartTime string `json:"startTime" dc:"开始日期字符 yyyy-MM" v:"required"`
|
||||
EndTime string `json:"endTime" dc:"开始日期字符 yyyy-MM" v:"required"`
|
||||
Id string `json:"id" dc:"逆变器ID" v:"required"`
|
||||
Sn string `json:"sn" dc:"逆变器SN" v:"required"`
|
||||
}
|
||||
|
||||
func (e EquipmentApi) EquipmentStaticMonth(ctx context.Context, req *EquipmentStaticMonthReq) (res *EquipmentStaticMonthRes, err error) {
|
||||
res = new(EquipmentStaticMonthRes)
|
||||
data := make(map[string]string)
|
||||
data["id"] = req.Id
|
||||
data["sn"] = req.Sn
|
||||
data["startTime"] = req.StartTime
|
||||
data["endTime"] = req.EndTime
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/equipment/getEquipmentMonthStatisticsData", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 获取逆变器年统计数据
|
||||
type EquipmentStaticYearReq struct {
|
||||
g.Meta `path:"/equipment/static/year" method:"get" tags:"禾望云相关" summary:"获取逆变器年统计数据"`
|
||||
StartTime string `json:"startTime" dc:"开始日期字符 yyyy" v:"required"`
|
||||
EndTime string `json:"endTime" dc:"开始日期字符 yyyy" v:"required"`
|
||||
Id string `json:"id" dc:"逆变器ID" v:"required"`
|
||||
Sn string `json:"sn" dc:"逆变器SN" v:"required"`
|
||||
}
|
||||
|
||||
func (e EquipmentApi) EquipmentStaticYear(ctx context.Context, req *EquipmentStaticYearReq) (res *EquipmentStaticYearRes, err error) {
|
||||
res = new(EquipmentStaticYearRes)
|
||||
data := make(map[string]string)
|
||||
data["id"] = req.Id
|
||||
data["sn"] = req.Sn
|
||||
data["startTime"] = req.StartTime
|
||||
data["endTime"] = req.EndTime
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/equipment/getEquipmentYearStatisticsData", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 获取逆变器报警列表数据
|
||||
type EquipmentAlarmListReq struct {
|
||||
g.Meta `path:"/equipment/alarm/list" method:"get" tags:"禾望云相关" summary:"获取逆变器报警数据列表"`
|
||||
StartTime string `json:"startTime" dc:"开始日期字符 yyyy-MM-dd" v:"required"`
|
||||
EndTime string `json:"endTime" dc:"开始日期字符 yyyy-MM-dd" v:"required"`
|
||||
Pn string `json:"pn" dc:"逆变器PN" v:"required"`
|
||||
Sn string `json:"sn" dc:"逆变器SN" v:"required"`
|
||||
}
|
||||
|
||||
func (e EquipmentApi) EquipmentAlarmList(ctx context.Context, req *EquipmentAlarmListReq) (res *EquipmentAlarmListRes, err error) {
|
||||
res = new(EquipmentAlarmListRes)
|
||||
data := make(map[string]string)
|
||||
data["pn"] = req.Pn
|
||||
data["sn"] = req.Sn
|
||||
data["startTime"] = req.StartTime
|
||||
data["endTime"] = req.EndTime
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Get("/openApi/equipment/getEquipmentFaultData", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 获取逆变器报警相关数据
|
||||
type EquipmentAlarmDetailDataReq struct {
|
||||
g.Meta `path:"/equipment/alarm/detail" method:"get" tags:"禾望云相关" summary:"获取逆变器报警数据详情"`
|
||||
AlarmId string `json:"alarmId" dc:"报警ID" v:"required"`
|
||||
}
|
||||
|
||||
// 获取设备报警详情数据
|
||||
func (e EquipmentApi) EquipmentAlarmDetailData(ctx context.Context, req *EquipmentAlarmDetailDataReq) (res *EquipmentAlarmDetailDataRes, err error) {
|
||||
res = new(EquipmentAlarmDetailDataRes)
|
||||
data := make(map[string]string)
|
||||
data["alarmId"] = req.AlarmId
|
||||
sign.SignByRSA(data)
|
||||
err, bytes := client.Post("openApi/equipment/getAlarmDetailDataById", data)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &res)
|
||||
return res, nil
|
||||
}
|
296
api/hwy/equipment/res.go
Normal file
296
api/hwy/equipment/res.go
Normal file
@ -0,0 +1,296 @@
|
||||
package equipment
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
|
||||
)
|
||||
|
||||
// 逆变器列表响应
|
||||
type EquipmentListRes 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 {
|
||||
DivertorId string `json:"divertorId"`
|
||||
DivertorName string `json:"divertorName"`
|
||||
EquipmentName string `json:"equipmentName"`
|
||||
EquipmentPn string `json:"equipmentPn"`
|
||||
EquipmentSn string `json:"equipmentSn"`
|
||||
Id string `json:"id"`
|
||||
Kwp float64 `json:"kwp"`
|
||||
MonKwh float64 `json:"monKwh"`
|
||||
NowKw float64 `json:"nowKw"`
|
||||
ParamDcacCode string `json:"paramDcacCode"`
|
||||
ParamDcdcCode string `json:"paramDcdcCode"`
|
||||
PowerPlantId string `json:"powerPlantId"`
|
||||
PowerPlantName string `json:"powerPlantName"`
|
||||
RatedPower float64 `json:"ratedPower"`
|
||||
SoftDcacCode string `json:"softDcacCode"`
|
||||
SoftDcdcCode string `json:"softDcdcCode"`
|
||||
Status int `json:"status"`
|
||||
SumKwh float64 `json:"sumKwh"`
|
||||
TodayKwh float64 `json:"todayKwh"`
|
||||
UpdateTime string `json:"updateTime"`
|
||||
UserId string `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
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 EquipmentDetailRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct{} `json:"obj"`
|
||||
PlantAddress string `json:"plantAddress"`
|
||||
Result struct {
|
||||
DivertorId string `json:"divertorId"`
|
||||
DivertorName string `json:"divertorName"`
|
||||
EquipmentName string `json:"equipmentName"`
|
||||
EquipmentPn string `json:"equipmentPn"`
|
||||
EquipmentSn string `json:"equipmentSn"`
|
||||
Id string `json:"id"`
|
||||
Kwp float64 `json:"kwp"`
|
||||
MonKwh float64 `json:"monKwh"`
|
||||
NowKw float64 `json:"nowKw"`
|
||||
ParamDcacCode string `json:"paramDcacCode"`
|
||||
ParamDcdcCode string `json:"paramDcdcCode"`
|
||||
PowerPlantId string `json:"powerPlantId"`
|
||||
PowerPlantName string `json:"powerPlantName"`
|
||||
RatedPower float64 `json:"ratedPower"`
|
||||
SoftDcacCode string `json:"softDcacCode"`
|
||||
SoftDcdcCode string `json:"softDcdcCode"`
|
||||
Status int `json:"status"`
|
||||
SumKwh float64 `json:"sumKwh"`
|
||||
TodayKwh float64 `json:"todayKwh"`
|
||||
UpdateTime string `json:"updateTime"`
|
||||
UserId string `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
YearKwh float64 `json:"yearKwh"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
||||
|
||||
// 逆变器实时数据
|
||||
type EquipmentRealDataRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct{} `json:"obj"`
|
||||
Result struct {
|
||||
EquipmentModel string `json:"equipmentModel"`
|
||||
FullHours float64 `json:"fullHours"`
|
||||
InternalTemperature float64 `json:"internalTemperature"`
|
||||
MonKwh float64 `json:"monKwh"`
|
||||
NowKw float64 `json:"nowKw"`
|
||||
ParamData struct {
|
||||
ParamList []struct {
|
||||
Key string `json:"key"`
|
||||
Name string `json:"name"`
|
||||
Unit string `json:"unit"`
|
||||
Value interface{} `json:"value"`
|
||||
} `json:"paramList"`
|
||||
Time string `json:"time"`
|
||||
} `json:"paramData"`
|
||||
PowerFactor float64 `json:"powerFactor"`
|
||||
PowerPercentage float64 `json:"powerPercentage"`
|
||||
PowerUnit string `json:"powerUnit"`
|
||||
RatedPower float64 `json:"ratedPower"`
|
||||
RatedVoltage float64 `json:"ratedVoltage"`
|
||||
SumKwh float64 `json:"sumKwh"`
|
||||
TodayKwh float64 `json:"todayKwh"`
|
||||
YearKwh float64 `json:"yearKwh"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
||||
|
||||
// 逆变器历史数据
|
||||
type EquipmentHistoryRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct{} `json:"obj"`
|
||||
Result []struct {
|
||||
ParamList []struct {
|
||||
Key string `json:"key"`
|
||||
Name string `json:"name"`
|
||||
Unit string `json:"unit"`
|
||||
Value interface{} `json:"value"`
|
||||
} `json:"paramList"`
|
||||
Time string `json:"time"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
||||
|
||||
// 逆变器日统计数据
|
||||
type EquipmentStaticDayRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct{} `json:"obj"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Result []struct {
|
||||
Time string `json:"time"`
|
||||
Kwh float64 `json:"kwh"`
|
||||
KwhUnit string `json:"kwhUnit"`
|
||||
Earnings float64 `json:"earnings"`
|
||||
EarningsUnit string `json:"earningsUnit"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
// 逆变器月统计数据
|
||||
type EquipmentStaticMonthRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct{} `json:"obj"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Result []struct {
|
||||
Time string `json:"time"`
|
||||
Kwh float64 `json:"kwh"`
|
||||
KwhUnit string `json:"kwhUnit"`
|
||||
Earnings float64 `json:"earnings"`
|
||||
EarningsUnit string `json:"earningsUnit"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
// 逆变器年统计数据
|
||||
type EquipmentStaticYearRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct{} `json:"obj"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Result []struct {
|
||||
Time string `json:"time"`
|
||||
Kwh float64 `json:"kwh"`
|
||||
KwhUnit string `json:"kwhUnit"`
|
||||
Earnings float64 `json:"earnings"`
|
||||
EarningsUnit string `json:"earningsUnit"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
// 逆变器报警列表数据
|
||||
type EquipmentAlarmListRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Obj struct{} `json:"obj"`
|
||||
Result []struct {
|
||||
AlarmCode string `json:"alarmCode"`
|
||||
AlarmContent string `json:"alarmContent"`
|
||||
AlarmGrade string `json:"alarmGrade"`
|
||||
AlarmType string `json:"alarmType"`
|
||||
CausesAnalysis string `json:"causesAnalysis"`
|
||||
DiagnosticAdvice string `json:"diagnosticAdvice"`
|
||||
EquipmentPn string `json:"equipmentPn"`
|
||||
EquipmentSn string `json:"equipmentSn"`
|
||||
Id string `json:"id"`
|
||||
PlantContactPhone string `json:"plantContactPhone"`
|
||||
PowerPlantId string `json:"powerPlantId"`
|
||||
PowerPlantName string `json:"powerPlantName"`
|
||||
ReportedTime string `json:"reportedTime"`
|
||||
UserId string `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
||||
|
||||
// 逆变器报警数据
|
||||
type EquipmentAlarmDetailRes 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 {
|
||||
AlarmCode string `json:"alarmCode"`
|
||||
AlarmContent string `json:"alarmContent"`
|
||||
AlarmGrade string `json:"alarmGrade"`
|
||||
AlarmType string `json:"alarmType"`
|
||||
CausesAnalysis string `json:"causesAnalysis"`
|
||||
DiagnosticAdvice string `json:"diagnosticAdvice"`
|
||||
EquipmentPn string `json:"equipmentPn"`
|
||||
EquipmentSn string `json:"equipmentSn"`
|
||||
Id string `json:"id"`
|
||||
Phone string `json:"phone"`
|
||||
PowerPlantAddress string `json:"powerPlantAddress"`
|
||||
PowerPlantId string `json:"powerPlantId"`
|
||||
PowerPlantName string `json:"powerPlantName"`
|
||||
ReportedTime string `json:"reportedTime"`
|
||||
RestoreTime string `json:"restoreTime"`
|
||||
Status string `json:"status"`
|
||||
UserId string `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
} `json:"records"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
}
|
||||
|
||||
// 逆变器报警详情
|
||||
type EquipmentAlarmDetailDataRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Result struct {
|
||||
Address string `json:"address"`
|
||||
AlarmCode string `json:"alarmCode"`
|
||||
AlarmContent string `json:"alarmContent"`
|
||||
AlarmGrade int `json:"alarmGrade"`
|
||||
AlarmGradeName string `json:"alarmGradeName"`
|
||||
AlarmSource int `json:"alarmSource"`
|
||||
AlarmSourceName string `json:"alarmSourceName"`
|
||||
CausesAnalysis string `json:"causesAnalysis"`
|
||||
ContactName string `json:"contactName"`
|
||||
DeviceModel string `json:"deviceModel"`
|
||||
DiagnosticAdvice string `json:"diagnosticAdvice"`
|
||||
Email string `json:"email"`
|
||||
Id string `json:"id"`
|
||||
IgnoreStatus int `json:"ignoreStatus"`
|
||||
IgnoreStatusName string `json:"ignoreStatusName"`
|
||||
OrganizationId string `json:"organizationId"`
|
||||
OrganizationName string `json:"organizationName"`
|
||||
Phone string `json:"phone"`
|
||||
Pn string `json:"pn"`
|
||||
PowerPlantId string `json:"powerPlantId"`
|
||||
PowerPlantName string `json:"powerPlantName"`
|
||||
ProductTypeName string `json:"productTypeName"`
|
||||
ReportedTime string `json:"reportedTime"`
|
||||
RestoreTime string `json:"restoreTime"`
|
||||
Sn string `json:"sn"`
|
||||
Status int `json:"status"`
|
||||
StatusName string `json:"statusName"`
|
||||
UserId string `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
} `json:"result"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
|
||||
// EquipmentListQueryRes 数据库查询返回
|
||||
type EquipmentListQueryRes struct {
|
||||
g.Meta `mime:"application/json"`
|
||||
common.ListRes
|
||||
List []entity.Equipment `json:"list"`
|
||||
}
|
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"`
|
||||
}
|
17
api/hwy/router/router.go
Normal file
17
api/hwy/router/router.go
Normal file
@ -0,0 +1,17 @@
|
||||
package hwy
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/tiger1103/gfast/v3/api/hwy/equipment"
|
||||
"github.com/tiger1103/gfast/v3/api/hwy/plant"
|
||||
)
|
||||
|
||||
func InitHwyAPI(group *ghttp.RouterGroup) {
|
||||
group.Middleware(ghttp.MiddlewareCORS)
|
||||
group.Group("/manage", func(group *ghttp.RouterGroup) {
|
||||
group.Group("/api/v1", func(group *ghttp.RouterGroup) {
|
||||
group.Bind(new(plant.PlantApi))
|
||||
group.Bind(new(equipment.EquipmentApi))
|
||||
})
|
||||
})
|
||||
}
|
92
api/hwy/sign/sign.go
Normal file
92
api/hwy/sign/sign.go
Normal file
@ -0,0 +1,92 @@
|
||||
package sign
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/sha1"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const APPID = "a23b2d45b0214f7ebbe167cd2e490435"
|
||||
const PRI_KEY = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAOAoyk5ot2KHo3hFga+ozeSO6XORk6wd4MkyETSGCDrha8klXfTukAJfYz3eS/PpkdLJTGrd34D21BkKzJ7Pc+ExMwTEc4xTaWU9vVJWlshVgHUsfbRhVps3IivtK9e268j+7xHf0I6j0zJ7zOLO6aADf76e/GqVfA+rz0DPPR3jAgMBAAECgYEA3blbSy2nX42dM6VE/zTw28hEwOzZbiFrrHearyJ4140MKb2Nb23eAorJxnOxG0YI2MAGl5p5rr331AFrnxbCnb4JZ5fnT1uBNtmH4uEnHhIhQm3CsSukFWvnO5KRD+9Zl3BKUSor2ynCs5/EO0hcKlKCYtHiXKzkkUi65rLuH4kCQQD2tlELA8YDMGgKNOF3ZpvRrTqKxGb4wwg+jUX4ns4oXutc57EfG4R96MWG5gu4x/3ZVrHPMHsmPClnK7hAyXP/AkEA6JkfBiLkhlCmkCn5F3qDwuQNzTHqdm/Ql71Hogk6+2itVgJ9ua+Eegw5cVynPqrEWW2e7VbNjuiVlkMLJE0GHQJBAKFCOCTf+YzaFhcdy4X1DsJ13T8Y80mEiZ4BT4wbmRswN92JH+/6V5bJEFuFgIHuTxHBpgWMZeJvDoz+Obg3NVcCQE+tdFUzyrjAE+66khua2lv+p0OtX7Xmo7v3GPzG0K+isg4OmGbtWyI74cmVha0P7mb8CD8hRxU3U1a/7Kcow3kCQQCky3My+Qr+offSBqBE1cuFbkJ09G6nlotlPlO0pVnXOHMsUBCkfocv6QJ25KooppU1C1Cktgf9BYJ9b/r+r1Lu"
|
||||
const HOST = "http://openapi.hopewindcloud.com/"
|
||||
|
||||
// 对参数进行签名,并为 Map 添加 appid 和 sign 参数
|
||||
func SignByRSA(params map[string]string) string {
|
||||
params["appid"] = APPID
|
||||
content := CreateLinkString(params)
|
||||
privateKeyBytes, err := base64.StdEncoding.DecodeString(PRI_KEY)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
pkcs8PrivateKey, err := x509.ParsePKCS8PrivateKey(privateKeyBytes)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse PKCS#8 private key: %v", err)
|
||||
}
|
||||
privateKey, ok := pkcs8PrivateKey.(*rsa.PrivateKey)
|
||||
if !ok {
|
||||
log.Fatal("Private key is not of type RSA")
|
||||
}
|
||||
h := sha1.New()
|
||||
_, err = h.Write([]byte(content))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return ""
|
||||
}
|
||||
hashed := h.Sum(nil)
|
||||
signed, err := rsa.SignPKCS1v15(rand.Reader, privateKey, crypto.SHA1, hashed)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return ""
|
||||
}
|
||||
sign := url.QueryEscape(base64.StdEncoding.EncodeToString(signed))
|
||||
params["sign"] = sign
|
||||
return sign
|
||||
}
|
||||
|
||||
// paramsFilter 过滤参数
|
||||
func paramsFilter(params map[string]interface{}) map[string]string {
|
||||
result := make(map[string]string)
|
||||
if params == nil || len(params) == 0 {
|
||||
return result
|
||||
}
|
||||
for key, value := range params {
|
||||
if value == nil || key == "sign" {
|
||||
continue
|
||||
}
|
||||
result[key] = value.(string)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// createLinkString 创建链接字符串
|
||||
func CreateLinkString(params map[string]string) string {
|
||||
if params == nil {
|
||||
return ""
|
||||
}
|
||||
// 排序键
|
||||
keys := make([]string, 0, len(params))
|
||||
for key := range params {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
sb := strings.Builder{}
|
||||
keyLastNum := len(keys) - 1
|
||||
for i, key := range keys {
|
||||
value := params[key]
|
||||
sb.WriteString(key)
|
||||
sb.WriteString("=")
|
||||
sb.WriteString(value)
|
||||
if i != keyLastNum {
|
||||
sb.WriteString("&")
|
||||
}
|
||||
}
|
||||
return sb.String()
|
||||
}
|
Reference in New Issue
Block a user